mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-01 23:52:51 +00:00
Compare commits
60 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
dc798d2b9f
|
|||
|
c2ec460c8c
|
|||
|
c51bcc8ff0
|
|||
|
63b7f8ab18
|
|||
|
eaf8028538
|
|||
|
2ad0ef3b6d
|
|||
|
20705de069
|
|||
|
64b519d5b1
|
|||
|
fb490b3db6
|
|||
|
c37ae7da7b
|
|||
|
5c06c2206c
|
|||
|
f9cdf70bdb
|
|||
|
3a6483aa61
|
|||
|
|
018c7a5eac | ||
|
f73b8c1453
|
|||
|
e38d952e1d
|
|||
|
8e5692ca59
|
|||
|
a0fe925ea9
|
|||
|
e84470d577
|
|||
|
683561dc06
|
|||
|
2fd2dad6f7
|
|||
|
e2f9f87b13
|
|||
|
623d895aea
|
|||
|
561300de64
|
|||
|
c5d9defc9d
|
|||
|
acd58646f6
|
|||
|
3634264af3
|
|||
|
3515994a5a
|
|||
|
bdebe238ae
|
|||
|
ebf7d73d20
|
|||
|
e19a57efac
|
|||
|
034436f93e
|
|||
|
2710f7fc25
|
|||
|
d2276a53d0
|
|||
|
8701d7a40d
|
|||
|
94cfaf40e5
|
|||
|
c661a4b30b
|
|||
|
9b95e1d67a
|
|||
|
f7bf93fcfc
|
|||
|
08df049170
|
|||
|
65a536cdea
|
|||
|
d2fd84a6b5
|
|||
|
88429412b9
|
|||
|
ef309d603e
|
|||
|
fade2f978e
|
|||
|
a1760d518c
|
|||
|
9d33565081
|
|||
|
|
11fe12f095 | ||
|
aba390839b
|
|||
|
|
a6e7df55ff | ||
|
|
7e5e7b8f5f | ||
|
|
a34ba35889 | ||
|
|
616d15b6bd | ||
|
|
283444f0be | ||
|
|
e5e56c04a2 | ||
|
|
a34c176bcc | ||
|
e4d51cd51d
|
|||
|
a7b49de6ac
|
|||
|
fc86b31337
|
|||
|
d8f0679233
|
35
.github/workflows/build.yml
vendored
35
.github/workflows/build.yml
vendored
@@ -7,8 +7,8 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: 🔨 Build
|
||||
CI:
|
||||
name: 🔨🚀 Build and deploy
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 🚚 Checkout
|
||||
@@ -39,25 +39,12 @@ jobs:
|
||||
with:
|
||||
name: build
|
||||
path: build
|
||||
deploy:
|
||||
name: 🚀 Deploy
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
environment:
|
||||
name: Website
|
||||
url: https://dotio.theaninova.de
|
||||
steps:
|
||||
- name: 📦 Download build artifacts
|
||||
uses: actions/download-artifact@v2.1.1
|
||||
with:
|
||||
name: build
|
||||
path: build
|
||||
- name: 🚀 Deploy
|
||||
uses: SamKirkland/web-deploy@v1
|
||||
with:
|
||||
target-server: ${{ secrets.SSH_SERVER }}
|
||||
destination-path: ~/public_html/
|
||||
source-path: ./build/
|
||||
remote-user: ${{ secrets.SSH_USER }}
|
||||
private-ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
ssh-port: ${{ secrets.SSH_PORT }}
|
||||
- name: Disable jekyll
|
||||
run: touch build/.nojekyll
|
||||
- name: Custom domain
|
||||
run: echo 'manager.charachorder.com' > build/CNAME
|
||||
- run: git config user.name github-actions
|
||||
- run: git config user.email github-actions@github.com
|
||||
- run: git --work-tree build add --all
|
||||
- run: git commit -m "Automatic Deploy action run by github-actions"
|
||||
- run: git push origin HEAD:gh-pages --force
|
||||
|
||||
15
README.md
15
README.md
@@ -1,15 +1,12 @@
|
||||
# amaCC1ng
|
||||
# CharaChorder Device Manager
|
||||
|
||||

|
||||

|
||||
[](https://dotio.theaninova.de/)
|
||||
The official device manager and configuration tool for CharaChorder devices.
|
||||
|
||||
_This project is not affiliated or endorsed with neither the original [dot i/o](https://www.iq-eq.io/) site, nor [CharaChorder](https://www.charachorder.com/)_
|
||||

|
||||

|
||||
[](https://manager.charachorder.com/)
|
||||
|
||||
Get the latest desktop release [here](https://github.com/Theaninova/dotio/releases).
|
||||
|
||||
I aim to create a new site that offers an easier, visually pleasing
|
||||
and more complete way to configure and learn CharaChorder devices.
|
||||
Get the latest desktop release [here](https://github.com/CharaChorder/DeviceManager/releases).
|
||||
|
||||
## Deployment
|
||||
|
||||
|
||||
64
docs/BACKUP.md
Normal file
64
docs/BACKUP.md
Normal file
@@ -0,0 +1,64 @@
|
||||
# Chara Backup Format, Version 1
|
||||
|
||||
JSON Schema files: TBD
|
||||
|
||||
Chara backups are serialized using JSON, in this general format:
|
||||
|
||||
```json
|
||||
{
|
||||
"charaVersion": 1,
|
||||
"type": "..."
|
||||
}
|
||||
```
|
||||
|
||||
The presence of the key `charaVersion` uniquely identifies the JSON file as a chara backup file and serves
|
||||
as a discriminator against other generic JSON files. This key is mandatory for that reason.
|
||||
|
||||
## Type `layout`
|
||||
|
||||
```json
|
||||
{
|
||||
"charaVersion": 1,
|
||||
"type": "layout",
|
||||
"device": "one",
|
||||
"layers": [[], [], []]
|
||||
}
|
||||
```
|
||||
|
||||
Devices at the current point in time may be identified as either `lite` or `one`, more to come in the future.
|
||||
|
||||
Layers are serialized as an array of `[layer1, layer2, layer3]` in the internal order of the key, each specifying
|
||||
an action code. Action codes of `0` are considered unassigned.
|
||||
|
||||
## Type `chords`
|
||||
|
||||
```json
|
||||
{
|
||||
"charaVersion": 1,
|
||||
"type": "chords",
|
||||
"chords": [
|
||||
[
|
||||
[1, 2, 3],
|
||||
[3, 4, 5]
|
||||
],
|
||||
[
|
||||
[6, 7, 8],
|
||||
[9, 10, 11]
|
||||
]
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Chords are serialized using a key-value mapping of chord action codes to actions.
|
||||
|
||||
## Type `settings`
|
||||
|
||||
```json
|
||||
{
|
||||
"charaVersion": 1,
|
||||
"type": "settings",
|
||||
"settings": [0, 1, 3, 6]
|
||||
}
|
||||
```
|
||||
|
||||
Settings are serialized as an array of the values in the way they appear on the device.
|
||||
71
flake.nix
71
flake.nix
@@ -4,31 +4,37 @@
|
||||
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
overlays = [ (import rust-overlay) ];
|
||||
pkgs = import nixpkgs { inherit system overlays; };
|
||||
rust-bin = pkgs.rust-bin.stable.latest.default.override {
|
||||
extensions = [ "rust-src" "rust-std" "clippy" "rust-analyzer" ];
|
||||
};
|
||||
fontMin = (pkgs.python311.withPackages(ps: with ps; [ brotli fonttools ] ++ (with fonttools.optional-dependencies; [ woff ])));
|
||||
tauriPkgs = nixpkgs.legacyPackages.${system};
|
||||
libraries = with tauriPkgs; [
|
||||
webkitgtk
|
||||
gtk3
|
||||
cairo
|
||||
gdk-pixbuf
|
||||
glib
|
||||
dbus
|
||||
openssl_3
|
||||
librsvg
|
||||
];
|
||||
packages = (with pkgs; [
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
rust-overlay,
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (system: let
|
||||
overlays = [(import rust-overlay)];
|
||||
pkgs = import nixpkgs {inherit system overlays;};
|
||||
rust-bin = pkgs.rust-bin.stable.latest.default.override {
|
||||
extensions = ["rust-src" "rust-std" "clippy" "rust-analyzer"];
|
||||
};
|
||||
fontMin = pkgs.python311.withPackages (ps: with ps; [brotli fonttools] ++ (with fonttools.optional-dependencies; [woff]));
|
||||
tauriPkgs = nixpkgs.legacyPackages.${system};
|
||||
libraries = with tauriPkgs; [
|
||||
webkitgtk
|
||||
gtk3
|
||||
cairo
|
||||
gdk-pixbuf
|
||||
glib
|
||||
dbus
|
||||
openssl_3
|
||||
librsvg
|
||||
];
|
||||
packages =
|
||||
(with pkgs; [
|
||||
nodejs_18
|
||||
rust-bin
|
||||
fontMin
|
||||
]) ++ (with tauriPkgs; [
|
||||
])
|
||||
++ (with tauriPkgs; [
|
||||
curl
|
||||
wget
|
||||
pkg-config
|
||||
@@ -39,16 +45,15 @@
|
||||
libsoup
|
||||
webkitgtk
|
||||
librsvg
|
||||
# serial plugin
|
||||
udev
|
||||
# serial plugin
|
||||
udev
|
||||
]);
|
||||
in
|
||||
{
|
||||
devShell = pkgs.mkShell {
|
||||
buildInputs = packages;
|
||||
shellHook = ''
|
||||
export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath libraries}:$LD_LIBRARY_PATH
|
||||
'';
|
||||
};
|
||||
});
|
||||
in {
|
||||
devShell = pkgs.mkShell {
|
||||
buildInputs = packages;
|
||||
shellHook = ''
|
||||
export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath libraries}:$LD_LIBRARY_PATH
|
||||
'';
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ const config: IconsConfig = {
|
||||
"node_modules/@fontsource-variable/material-symbols-rounded/files/material-symbols-rounded-latin-full-normal.woff2",
|
||||
outputPath: "src/lib/assets/icons.min.woff2",
|
||||
icons: [
|
||||
"add",
|
||||
"piano",
|
||||
"keyboard",
|
||||
"settings",
|
||||
@@ -67,6 +68,28 @@ const config: IconsConfig = {
|
||||
"bolt",
|
||||
"undo",
|
||||
"redo",
|
||||
"navigate_before",
|
||||
"navigate_next",
|
||||
"print",
|
||||
"restore_from_trash",
|
||||
"history",
|
||||
"history_toggle_off",
|
||||
"sentiment_satisfied",
|
||||
"sentiment_dissatisfied",
|
||||
"sentiment_very_satisfied",
|
||||
"sentiment_neutral",
|
||||
"sentiment_very_dissatisfied",
|
||||
"sentiment_excited",
|
||||
"sentiment_frustrated",
|
||||
"sentiment_calm",
|
||||
"sentiment_stressed",
|
||||
"sentiment_extremely_dissatisfied",
|
||||
"sentiment_sad",
|
||||
"sentiment_content",
|
||||
"sentiment_worried",
|
||||
"timer",
|
||||
"target",
|
||||
"download",
|
||||
],
|
||||
codePoints: {
|
||||
speed: "e9e4",
|
||||
@@ -80,6 +103,7 @@ const config: IconsConfig = {
|
||||
light_mode: "e518",
|
||||
upload_file: "e9fc",
|
||||
no_sound: "e710",
|
||||
sentiment_extremely_dissatisfied: "f194",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
11
package-lock.json
generated
11
package-lock.json
generated
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "amacc1ng",
|
||||
"name": "charachorder-device-manager",
|
||||
"version": "0.6.5",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "amacc1ng",
|
||||
"name": "charachorder-device-manager",
|
||||
"version": "0.6.5",
|
||||
"hasInstallScript": true,
|
||||
"license": "AGPL-3.0-or-later",
|
||||
@@ -35,6 +35,7 @@
|
||||
"flexsearch": "^0.7.31",
|
||||
"fontkit": "^2.0.2",
|
||||
"glob": "^10.3.4",
|
||||
"hotkeys-js": "^3.12.0",
|
||||
"jsdom": "^22.1.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"patch-package": "^8.0.0",
|
||||
@@ -6273,6 +6274,12 @@
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/hotkeys-js": {
|
||||
"version": "3.12.0",
|
||||
"resolved": "https://registry.npmjs.org/hotkeys-js/-/hotkeys-js-3.12.0.tgz",
|
||||
"integrity": "sha512-Z+N573ycUKIGwFYS3ID1RzMJiGmtWMGKMiaNLyJS8B1ei+MllF4ZYmKS2T0kMWBktOz+WZLVNikftEgnukOrXg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/html-encoding-sniffer": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-3.0.0.tgz",
|
||||
|
||||
11
package.json
11
package.json
@@ -1,15 +1,15 @@
|
||||
{
|
||||
"name": "amacc1ng",
|
||||
"version": "0.6.5",
|
||||
"name": "charachorder-device-manager",
|
||||
"version": "0.7.0",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"private": true,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Theaninova/amacc1ng.git"
|
||||
"url": "https://github.com/CharaChorder/DeviceManager.git"
|
||||
},
|
||||
"homepage": "https://github.com/Theaninova/amacc1ng",
|
||||
"homepage": "https://github.com/CharaChorder/DeviceManager",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Theaninova/amacc1ng/issues"
|
||||
"url": "https://github.com/CharaChorder/DeviceManager/issues"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "npm-run-all --parallel vite typesafe-i18n",
|
||||
@@ -55,6 +55,7 @@
|
||||
"flexsearch": "^0.7.31",
|
||||
"fontkit": "^2.0.2",
|
||||
"glob": "^10.3.4",
|
||||
"hotkeys-js": "^3.12.0",
|
||||
"jsdom": "^22.1.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"patch-package": "^8.0.0",
|
||||
|
||||
6
src/env.d.ts
vendored
6
src/env.d.ts
vendored
@@ -7,11 +7,11 @@ interface ImportMetaEnv {
|
||||
readonly TAURI_ARCH?: string
|
||||
readonly TAURI_DEBUG?: boolean
|
||||
readonly TAURI_PLATFORM_TYPE?: string
|
||||
|
||||
readonly VITE_HOMEPAGE_URL: string
|
||||
readonly VITE_BUGS_URL: string
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv
|
||||
}
|
||||
|
||||
declare const HOMEPAGE_URL: string
|
||||
declare const BUGS_URL: string
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
import type {Translation} from "../i18n-types"
|
||||
|
||||
const de = {
|
||||
TITLE: "amaCC1ng",
|
||||
TITLE: "CharaChorder Gerätemanager",
|
||||
DESCRIPTION: "Gerätemanager und Konfigurationstool für CharaChorder Geräte.",
|
||||
saveActions: {
|
||||
UNDO: "Rückgängig",
|
||||
UNDO: "Rückgängig (<kbd class='icon'>shift</kbd> halten um alle Änderungen rückgängig zu machen)",
|
||||
REDO: "Wiederholen",
|
||||
APPLY: "Anwenden",
|
||||
SAVE: "Änderungen auf das Gerät schreiben",
|
||||
SAVE: "Speichern",
|
||||
},
|
||||
sync: {
|
||||
TITLE_READ: "Neueste Änderungen werden abgerufen",
|
||||
TITLE_WRITE: "Änderungen werden gespeichert",
|
||||
},
|
||||
backup: {
|
||||
TITLE: "Sicherungskopie",
|
||||
TITLE: "Verlauf speichern",
|
||||
INDIVIDUAL: "Einzeldateien",
|
||||
DISCLAIMER:
|
||||
"Sicherungskopien verlassen unter keinen Umständen diesen Computer und werden nie mit uns geteilt oder auf Server hochgeladen.",
|
||||
DOWNLOAD: "Kopie Speichern",
|
||||
"Der Verlauf wird als Backup in diesem Browser gespeichert. Der Verlauf bleibt auf diesem Computer.",
|
||||
DOWNLOAD: "Alles herunterladen",
|
||||
RESTORE: "Wiederherstellen",
|
||||
},
|
||||
modal: {
|
||||
@@ -22,11 +27,18 @@ const de = {
|
||||
PLACEHOLDER: "Nach Aktionen suchen",
|
||||
CURRENT_ACTION: "Aktuelle Aktion",
|
||||
DELETE: "Entfernen",
|
||||
filter: {
|
||||
ALL: "Alle",
|
||||
},
|
||||
},
|
||||
share: {
|
||||
TITLE: "Teilen",
|
||||
URL_COPIED: "Teilbare URL kopiert!",
|
||||
EXTRA_DOWNLOAD: "Als Datei herunterladen",
|
||||
},
|
||||
print: {
|
||||
TITLE: "Drucken",
|
||||
},
|
||||
profile: {
|
||||
TITLE: "Profil",
|
||||
LANGUAGE: "Sprache",
|
||||
@@ -62,12 +74,38 @@ const de = {
|
||||
INFO_BROWSER_SUFFIX: " sich bewusst dazu entschieden die API zu deaktivieren.",
|
||||
DOWNLOAD_APP: "Desktop-app herunterladen",
|
||||
},
|
||||
changes: {
|
||||
TITLE: "Änderungen importieren",
|
||||
ALL_CHANGES: "Alle Änderungen",
|
||||
layout: {
|
||||
TITLE: "{0} veränderte Belegung{{:|en}}",
|
||||
LAYER: "{changes} Belegung{{changes:|en}} in Ebene {layer} ändern",
|
||||
},
|
||||
settings: {
|
||||
TITLE: "{0} Einstellung{{|en}} anpassen",
|
||||
},
|
||||
chords: {
|
||||
TITLE: "{0} Akkorde",
|
||||
NEW_CHORDS: "{0} neue Akkord{{|e}} hinzufügen",
|
||||
CHANGED_CHORDS: "{0} Akkord{{|e}} ersetzen",
|
||||
DELETED_CHORDS: "{0} Akkord{{|e}} zum löschen markieren",
|
||||
},
|
||||
},
|
||||
configure: {
|
||||
chords: {
|
||||
TITLE: "Akkorde",
|
||||
HOLD_KEYS: "Akkord halten",
|
||||
NEW_CHORD: "Neuer Akkord",
|
||||
search: {
|
||||
PLACEHOLDER: "{0} Akkord{{|e}} durchsuchen",
|
||||
},
|
||||
conflict: {
|
||||
TITLE: "Akkordkonflikt",
|
||||
DESCRIPTION:
|
||||
"Der Akkord {0} würde einen bereits existierenden Akkord überschreiben. Wirklich fortfahren?",
|
||||
CONFIRM: "Überschreiben",
|
||||
ABORT: "Überspringen",
|
||||
},
|
||||
},
|
||||
layout: {
|
||||
TITLE: "Layout",
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
import type {BaseTranslation} from "../i18n-types"
|
||||
|
||||
const en = {
|
||||
TITLE: "amaCC1ng",
|
||||
TITLE: "CharaChorder Device Manager",
|
||||
DESCRIPTION: "The device manager and configuration tool for CharaChorder devices.",
|
||||
saveActions: {
|
||||
UNDO: "Undo",
|
||||
UNDO: "Undo (hold <kbd class='icon'>shift</kbd> to undo all changes)",
|
||||
REDO: "Redo",
|
||||
APPLY: "Apply",
|
||||
SAVE: "Write changes to your device",
|
||||
SAVE: "Save",
|
||||
},
|
||||
backup: {
|
||||
TITLE: "Local Backup",
|
||||
DISCLAIMER: "Backups remain on your computer and are never shared with us or uploaded to our servers.",
|
||||
DOWNLOAD: "Download Backup",
|
||||
TITLE: "Store History",
|
||||
INDIVIDUAL: "Individual backups",
|
||||
DISCLAIMER: "Your history is stored as a backup in this browser. The history remains on your computer.",
|
||||
DOWNLOAD: "Download Everything",
|
||||
RESTORE: "Restore",
|
||||
},
|
||||
sync: {
|
||||
TITLE_READ: "Reading latest changes",
|
||||
TITLE_WRITE: "Saving changes to device",
|
||||
},
|
||||
modal: {
|
||||
CLOSE: "Close",
|
||||
},
|
||||
@@ -21,11 +26,18 @@ const en = {
|
||||
PLACEHOLDER: "Search for actions",
|
||||
CURRENT_ACTION: "Current action",
|
||||
DELETE: "Remove",
|
||||
filter: {
|
||||
ALL: "All",
|
||||
},
|
||||
},
|
||||
share: {
|
||||
TITLE: "Share",
|
||||
URL_COPIED: "Sharable URL copied!",
|
||||
EXTRA_DOWNLOAD: "Download as file",
|
||||
},
|
||||
print: {
|
||||
TITLE: "Print",
|
||||
},
|
||||
profile: {
|
||||
TITLE: "Profile",
|
||||
LANGUAGE: "Language",
|
||||
@@ -60,12 +72,38 @@ const en = {
|
||||
INFO_BROWSER_SUFFIX: ".",
|
||||
DOWNLOAD_APP: "Download the desktop app",
|
||||
},
|
||||
changes: {
|
||||
TITLE: "Import changes",
|
||||
ALL_CHANGES: "All changes",
|
||||
layout: {
|
||||
TITLE: "{0} layout change{{|s}}",
|
||||
LAYER: "Update {changes} key{{changes:|s}} in layer {layer}",
|
||||
},
|
||||
settings: {
|
||||
TITLE: "Update {0} setting{{|s}}",
|
||||
},
|
||||
chords: {
|
||||
TITLE: "{0} chords",
|
||||
NEW_CHORDS: "Add {0} new chord{{|s}}",
|
||||
CHANGED_CHORDS: "Replace {0} chord{{|s}}",
|
||||
DELETED_CHORDS: "Mark {0} chord{{|s}} for deletion",
|
||||
},
|
||||
},
|
||||
configure: {
|
||||
chords: {
|
||||
TITLE: "Chords",
|
||||
HOLD_KEYS: "Hold chord",
|
||||
NEW_CHORD: "New chord",
|
||||
search: {
|
||||
PLACEHOLDER: "Search {0} chord{{|s}}",
|
||||
},
|
||||
conflict: {
|
||||
TITLE: "Chord conflict",
|
||||
DESCRIPTION:
|
||||
"Your chord {0} conflicts with an existing chord. Are you sure you want to overwrite this chord?",
|
||||
CONFIRM: "Overwrite",
|
||||
ABORT: "Skip",
|
||||
},
|
||||
},
|
||||
layout: {
|
||||
TITLE: "Layout",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: Raw Scancodes
|
||||
description: Raw Keyboard Scancodes
|
||||
name: Key codes
|
||||
description: OS-Layout sensitive keycodes
|
||||
actions:
|
||||
256:
|
||||
id: "KSC_00"
|
||||
@@ -15,311 +15,408 @@ actions:
|
||||
title: Keyboard Error Undefined
|
||||
260:
|
||||
id: "KEY_A"
|
||||
keyCode: "KeyA"
|
||||
title: Keyboard a and A (US English)
|
||||
description: Non US English keyboard users may prefer these Raw Scancodes
|
||||
261:
|
||||
id: "KEY_B"
|
||||
keyCode: "KeyB"
|
||||
title: Keyboard b and B (US English)
|
||||
262:
|
||||
id: "KEY_C"
|
||||
keyCode: "KeyC"
|
||||
title: Keyboard c and C (US English)
|
||||
263:
|
||||
id: "KEY_D"
|
||||
keyCode: "KeyD"
|
||||
title: Keyboard d and D (US English)
|
||||
264:
|
||||
id: "KEY_E"
|
||||
keyCode: "KeyE"
|
||||
title: Keyboard e and E (US English)
|
||||
265:
|
||||
id: "KEY_F"
|
||||
keyCode: "KeyF"
|
||||
title: Keyboard f and F (US English)
|
||||
266:
|
||||
id: "KEY_G"
|
||||
keyCode: "KeyG"
|
||||
title: Keyboard g and G (US English)
|
||||
267:
|
||||
id: "KEY_H"
|
||||
keyCode: "KeyH"
|
||||
title: Keyboard h and H (US English)
|
||||
268:
|
||||
id: "KEY_I"
|
||||
keyCode: "KeyI"
|
||||
title: Keyboard i and I (US English)
|
||||
269:
|
||||
id: "KEY_J"
|
||||
keyCode: "KeyJ"
|
||||
title: Keyboard j and J (US English)
|
||||
270:
|
||||
id: "KEY_K"
|
||||
keyCode: "KeyK"
|
||||
title: Keyboard k and K (US English)
|
||||
271:
|
||||
id: "KEY_L"
|
||||
keyCode: "KeyL"
|
||||
title: Keyboard l and L (US English)
|
||||
272:
|
||||
id: "KEY_M"
|
||||
keyCode: "KeyM"
|
||||
title: Keyboard m and M (US English)
|
||||
273:
|
||||
id: "KEY_N"
|
||||
keyCode: "KeyN"
|
||||
title: Keyboard n and N (US English)
|
||||
274:
|
||||
id: "KEY_O"
|
||||
keyCode: "KeyO"
|
||||
title: Keyboard o and O (US English)
|
||||
275:
|
||||
id: "KEY_P"
|
||||
keyCode: "KeyP"
|
||||
title: Keyboard p and P (US English)
|
||||
276:
|
||||
id: "KEY_Q"
|
||||
keyCode: "KeyQ"
|
||||
title: Keyboard q and Q (US English)
|
||||
277:
|
||||
id: "KEY_R"
|
||||
keyCode: "KeyR"
|
||||
title: Keyboard r and R (US English)
|
||||
278:
|
||||
id: "KEY_S"
|
||||
keyCode: "KeyS"
|
||||
title: Keyboard s and S (US English)
|
||||
279:
|
||||
id: "KEY_T"
|
||||
keyCode: "KeyT"
|
||||
title: Keyboard t and T (US English)
|
||||
280:
|
||||
id: "KEY_U"
|
||||
keyCode: "KeyU"
|
||||
title: Keyboard u and U (US English)
|
||||
281:
|
||||
id: "KEY_V"
|
||||
keyCode: "KeyV"
|
||||
title: Keyboard v and V (US English)
|
||||
282:
|
||||
id: "KEY_W"
|
||||
keyCode: "KeyW"
|
||||
title: Keyboard w and W (US English)
|
||||
283:
|
||||
id: "KEY_X"
|
||||
keyCode: "KeyX"
|
||||
title: Keyboard x and X (US English)
|
||||
284:
|
||||
id: "KEY_Y"
|
||||
keyCode: "KeyY"
|
||||
title: Keyboard y and Y (US English)
|
||||
285:
|
||||
id: "KEY_Z"
|
||||
keyCode: "KeyZ"
|
||||
title: Keyboard z and Z (US English)
|
||||
286:
|
||||
id: "KEY_1"
|
||||
keyCode: "Digit1"
|
||||
title: Keyboard 1 and ! (US English)
|
||||
287:
|
||||
id: "KEY_2"
|
||||
keyCode: "Digit2"
|
||||
title: Keyboard 2 and @ (US English)
|
||||
288:
|
||||
id: "KEY_3"
|
||||
keyCode: "Digit3"
|
||||
title: Keyboard 3 and # (US English)
|
||||
289:
|
||||
id: "KEY_4"
|
||||
keyCode: "Digit4"
|
||||
title: Keyboard 4 and $ (US English)
|
||||
290:
|
||||
id: "KEY_5"
|
||||
keyCode: "Digit5"
|
||||
title: Keyboard 5 and % (US English)
|
||||
291:
|
||||
id: "KEY_6"
|
||||
keyCode: "Digit6"
|
||||
title: Keyboard 6 and ^ (US English)
|
||||
292:
|
||||
id: "KEY_7"
|
||||
keyCode: "Digit7"
|
||||
title: Keyboard 7 and & (US English)
|
||||
293:
|
||||
id: "KEY_8"
|
||||
keyCode: "Digit8"
|
||||
title: Keyboard 8 and * (US English)
|
||||
294:
|
||||
id: "KEY_9"
|
||||
keyCode: "Digit9"
|
||||
title: Keyboard 9 and ( (US English)
|
||||
295:
|
||||
id: "KEY_0"
|
||||
keyCode: "Digit0"
|
||||
title: Keyboard 0 and ) (US English)
|
||||
296:
|
||||
id: "ENTER"
|
||||
keyCode: "Enter"
|
||||
title: Keyboard Return (US English)
|
||||
icon: keyboard_return
|
||||
297:
|
||||
id: "ESC"
|
||||
keyCode: "Escape"
|
||||
title: Keyboard Escape (US English)
|
||||
298:
|
||||
id: "BKSP"
|
||||
keyCode: "Backspace"
|
||||
title: Keyboard Backspace (US English)
|
||||
icon: backspace
|
||||
299:
|
||||
id: "TAB"
|
||||
keyCode: "Tab"
|
||||
title: Keyboard Tab (US English)
|
||||
icon: keyboard_tab
|
||||
300:
|
||||
id: "KSC_2C"
|
||||
keyCode: "Space"
|
||||
title: Keyboard Space (US English)
|
||||
description: |
|
||||
The ASCII space is preferred over this raw scancode for the space bar.
|
||||
icon: space_bar
|
||||
301:
|
||||
id: "KSC_2D"
|
||||
keyCode: "Minus"
|
||||
title: Keyboard - and _ (US English)
|
||||
302:
|
||||
id: "KSC_2E"
|
||||
keyCode: "Equal"
|
||||
title: Keyboard = and + (US English)
|
||||
303:
|
||||
id: "KSC_2F"
|
||||
keyCode: "BracketLeft"
|
||||
title: Keyboard [ and { (US English)
|
||||
304:
|
||||
id: "KSC_30"
|
||||
keyCode: "BracketRight"
|
||||
title: Keyboard ] and } (US English)
|
||||
305:
|
||||
id: "KSC_31"
|
||||
keyCode: "Backslash"
|
||||
title: Keyboard \ and | (US English)
|
||||
306:
|
||||
id: "KSC_32"
|
||||
# TODO: also backslash?
|
||||
title: Keyboard Non-US \# and ~ (US English)
|
||||
307:
|
||||
id: "KSC_33"
|
||||
keyCode: "Semicolon"
|
||||
title: "Keyboard ; and : (US English)"
|
||||
308:
|
||||
id: "KSC_34"
|
||||
keyCode: "Quote"
|
||||
title: Keyboard ' and " (US English)
|
||||
309:
|
||||
id: "KSC_35"
|
||||
keyCode: "Backquote"
|
||||
title: Keyboard ` and ~ (US English)
|
||||
310:
|
||||
id: "KSC_36"
|
||||
keyCode: "Comma"
|
||||
title: Keyboard , and < (US English)
|
||||
311:
|
||||
id: "KSC_37"
|
||||
keyCode: "Period"
|
||||
title: Keyboard . and > (US English)
|
||||
312:
|
||||
id: "KSC_38"
|
||||
keyCode: "Slash"
|
||||
title: Keyboard / and ? (US English)
|
||||
313:
|
||||
id: "CAPSLOCK"
|
||||
keyCode: "CapsLock"
|
||||
title: Keyboard Caps Lock
|
||||
icon: shift_lock
|
||||
314:
|
||||
id: "F1"
|
||||
keyCode: "F1"
|
||||
title: Keyboard F1
|
||||
315:
|
||||
id: "F2"
|
||||
keyCode: "F2"
|
||||
title: Keyboard F2
|
||||
316:
|
||||
id: "F3"
|
||||
keyCode: "F3"
|
||||
title: Keyboard F3
|
||||
317:
|
||||
id: "F4"
|
||||
keyCode: "F4"
|
||||
title: Keyboard F4
|
||||
318:
|
||||
id: "F5"
|
||||
keyCode: "F5"
|
||||
title: Keyboard F5
|
||||
319:
|
||||
id: "F6"
|
||||
keyCode: "F6"
|
||||
title: Keyboard F6
|
||||
320:
|
||||
id: "F7"
|
||||
keyCode: "F7"
|
||||
title: Keyboard F7
|
||||
321:
|
||||
id: "F8"
|
||||
keyCode: "F8"
|
||||
title: Keyboard F8
|
||||
322:
|
||||
id: "F9"
|
||||
keyCode: "F9"
|
||||
title: Keyboard F9
|
||||
323:
|
||||
id: "F10"
|
||||
keyCode: "F10"
|
||||
title: Keyboard F10
|
||||
324:
|
||||
id: "F11"
|
||||
keyCode: "F11"
|
||||
title: Keyboard F11
|
||||
325:
|
||||
id: "F12"
|
||||
keyCode: "F12"
|
||||
title: Keyboard F12
|
||||
326:
|
||||
id: "PRTSCN"
|
||||
keyCode: "PrintScreen"
|
||||
title: Keyboard Print Screen
|
||||
icon: screenshot_monitor
|
||||
327:
|
||||
id: "SCRLK"
|
||||
keyCode: "ScrollLock"
|
||||
title: Keyboard Scroll Lock
|
||||
328:
|
||||
id: "PAUSE"
|
||||
keyCode: "Pause"
|
||||
title: Keyboard Pause
|
||||
329:
|
||||
id: "INSERT"
|
||||
keyCode: "Insert"
|
||||
title: Keyboard Insert
|
||||
icon: insert_text
|
||||
330:
|
||||
id: "HOME"
|
||||
keyCode: "Home"
|
||||
title: Keyboard Home
|
||||
icon: home
|
||||
331:
|
||||
id: "PGUP"
|
||||
keyCode: "PageUp"
|
||||
title: Keyboard Page Up
|
||||
icon: move_up
|
||||
332:
|
||||
id: "DELETE"
|
||||
keyCode: "Delete"
|
||||
title: Keyboard Delete Forward
|
||||
333:
|
||||
id: "END"
|
||||
keyCode: "End"
|
||||
title: Keyboard End
|
||||
334:
|
||||
id: "PGDN"
|
||||
keyCode: "PageDown"
|
||||
title: Keyboard Page Down
|
||||
icon: move_down
|
||||
335:
|
||||
id: "ARROW_RT"
|
||||
keyCode: "ArrowRight"
|
||||
title: Keyboard Right Arrow
|
||||
icon: keyboard_arrow_right
|
||||
336:
|
||||
id: "ARROW_LF"
|
||||
keyCode: "ArrowLeft"
|
||||
title: Keyboard Left Arrow
|
||||
icon: keyboard_arrow_left
|
||||
337:
|
||||
id: "ARROW_DN"
|
||||
keyCode: "ArrowDown"
|
||||
title: Keyboard Down Arrow
|
||||
icon: keyboard_arrow_down
|
||||
338:
|
||||
id: "ARROW_UP"
|
||||
keyCode: "ArrowUp"
|
||||
title: Keyboard Up Arrow
|
||||
icon: keyboard_arrow_up
|
||||
339:
|
||||
id: "NUMLOCK"
|
||||
keyCode: "NumLock"
|
||||
title: Keyboard Num Lock and Clear
|
||||
340:
|
||||
id: "KP_SLASH"
|
||||
keyCode: "NumpadDivide"
|
||||
title: Keypad /
|
||||
341:
|
||||
id: "KP_ASTER"
|
||||
keyCode: "NumpadStar"
|
||||
title: Keypad *
|
||||
342:
|
||||
id: "KP_MINUS"
|
||||
keyCode: "NumpadSubtract"
|
||||
title: Keypad -
|
||||
343:
|
||||
id: "KP_PLUS"
|
||||
keyCode: "NumpadAdd"
|
||||
title: Keypad +
|
||||
344:
|
||||
id: "KP_ENTER"
|
||||
keyCode: "NumpadEnter"
|
||||
title: Keypad Enter
|
||||
345:
|
||||
id: "KP_1"
|
||||
keyCode: "Numpad1"
|
||||
title: Keypad 1 and End
|
||||
346:
|
||||
id: "KP_2"
|
||||
keyCode: "Numpad2"
|
||||
title: Keypad 2 and Down Arrow
|
||||
347:
|
||||
id: "KP_3"
|
||||
keyCode: "Numpad3"
|
||||
title: Keypad 3 and Page Down
|
||||
348:
|
||||
id: "KP_4"
|
||||
keyCode: "Numpad4"
|
||||
title: Keypad 4 and Left Arrow
|
||||
349:
|
||||
id: "KP_5"
|
||||
keyCode: "Numpad5"
|
||||
title: Keypad 5
|
||||
350:
|
||||
id: "KP_6"
|
||||
keyCode: "Numpad6"
|
||||
title: Keypad 6 and Rigth Arrow
|
||||
351:
|
||||
id: "KP_7"
|
||||
keyCode: "Numpad7"
|
||||
title: Keypad 7 and Home
|
||||
352:
|
||||
id: "KP_8"
|
||||
keyCode: "Numpad8"
|
||||
title: Keypad 8 and Up Arrow
|
||||
353:
|
||||
id: "KP_9"
|
||||
keyCode: "Numpad9"
|
||||
title: Keypad 9 and Page Up
|
||||
354:
|
||||
id: "KP_0"
|
||||
keyCode: "Numpad0"
|
||||
title: Keypad 0 and Insert
|
||||
355:
|
||||
id: "KP_DOT"
|
||||
keyCode: "NumpadDecimal"
|
||||
title: Keypad . and Delete
|
||||
356:
|
||||
id: "KSC_64"
|
||||
keyCode: "IntlBackslash"
|
||||
title: Keyboard Non-US \ and | (US English)
|
||||
357:
|
||||
id: "COMPOSE"
|
||||
@@ -327,10 +424,12 @@ actions:
|
||||
description: Officially supported by Win, Unix, and Boot
|
||||
358:
|
||||
id: "POWER"
|
||||
keyCode: "Power"
|
||||
title: Keyboard Power
|
||||
description: Only officially supported by Mac and Unix
|
||||
359:
|
||||
id: "KP_EQUAL"
|
||||
keyCode: "NumpadEqual"
|
||||
title: Keypad =
|
||||
description: Only officially supported by Mac
|
||||
360:
|
||||
@@ -787,10 +886,12 @@ actions:
|
||||
description: Not required to be supported by any OS
|
||||
472:
|
||||
id: "KSC_D8"
|
||||
keyCode: "NumpadClear"
|
||||
title: Keypad Clear
|
||||
description: Not required to be supported by any OS
|
||||
473:
|
||||
id: "KSC_D9"
|
||||
keyCode: "NumpadClearEntry"
|
||||
title: Keypad Clear Entry
|
||||
description: Not required to be supported by any OS
|
||||
474:
|
||||
@@ -817,58 +918,74 @@ actions:
|
||||
description: Not required to be supported by any OS
|
||||
480:
|
||||
id: "KSC_E0"
|
||||
keyCode: "ControlLeft"
|
||||
title: Keyboard Left Control
|
||||
481:
|
||||
id: "KSC_E1"
|
||||
keyCode: "ShiftLeft"
|
||||
title: Keyboard Left Shift
|
||||
482:
|
||||
id: "KSC_E2"
|
||||
keyCode: "AltLeft"
|
||||
title: Keyboard Left Alt
|
||||
483:
|
||||
id: "KSC_E3"
|
||||
keyCode: "MetaLeft"
|
||||
title: Keyboard Left GUI
|
||||
484:
|
||||
id: "KSC_E4"
|
||||
keyCode: "ControlRight"
|
||||
title: Keyboard Right Control
|
||||
485:
|
||||
id: "KSC_E5"
|
||||
keyCode: "ShiftRight"
|
||||
title: Keyboard Right Shift
|
||||
486:
|
||||
id: "KSC_E6"
|
||||
keyCode: "AltRight"
|
||||
title: Keyboard Right Alt
|
||||
487:
|
||||
id: "KSC_E7"
|
||||
keyCode: "MetaRight"
|
||||
title: Keyboard Right GUI
|
||||
488:
|
||||
id: "KSC_E8"
|
||||
keyCode: "MediaPlayPause"
|
||||
title: Media Play Pause
|
||||
description: Not required to be supported by any OS. Possibly deprecated.
|
||||
489:
|
||||
id: "KSC_E9"
|
||||
keyCode: "MediaStop"
|
||||
title: Media Stop CD
|
||||
description: Not required to be supported by any OS. Possibly deprecated.
|
||||
490:
|
||||
id: "KSC_EA"
|
||||
keyCode: "MediaTrackPrevious"
|
||||
title: Media Previous Song
|
||||
description: Not required to be supported by any OS. Possibly deprecated.
|
||||
491:
|
||||
id: "KSC_EB"
|
||||
keyCode: "MediaTrackNext"
|
||||
title: Media Next Song
|
||||
description: Not required to be supported by any OS. Possibly deprecated.
|
||||
492:
|
||||
id: "KSC_EC"
|
||||
keyCode: "Eject"
|
||||
title: Media Eject CD
|
||||
description: Not required to be supported by any OS. Possibly deprecated.
|
||||
493:
|
||||
id: "KSC_ED"
|
||||
keyCode: "AudioVolumeUp"
|
||||
title: Media Volume Up
|
||||
description: Not required to be supported by any OS. Possibly deprecated.
|
||||
494:
|
||||
id: "KSC_EE"
|
||||
keyCode: "AudioVolumeDown"
|
||||
title: Media Volume Down
|
||||
description: Not required to be supported by any OS. Possibly deprecated.
|
||||
495:
|
||||
id: "KSC_EF"
|
||||
keyCode: "AudioVolumeMute"
|
||||
title: Media Mute
|
||||
description: Not required to be supported by any OS. Possibly deprecated.
|
||||
496:
|
||||
@@ -877,18 +994,22 @@ actions:
|
||||
description: Not required to be supported by any OS. Possibly deprecated.
|
||||
497:
|
||||
id: "KSC_F1"
|
||||
keyCode: "BrowserBack"
|
||||
title: Media Back
|
||||
description: Not required to be supported by any OS. Possibly deprecated.
|
||||
498:
|
||||
id: "KSC_F2"
|
||||
keyCode: "BrowserForward"
|
||||
title: Media Forward
|
||||
description: Not required to be supported by any OS. Possibly deprecated.
|
||||
499:
|
||||
id: "KSC_F3"
|
||||
keyCode: "BrowserStop"
|
||||
title: Media Stop
|
||||
description: Not required to be supported by any OS. Possibly deprecated.
|
||||
500:
|
||||
id: "KSC_F4"
|
||||
keyCode: "BrowserSearch"
|
||||
title: Media Find
|
||||
description: Not required to be supported by any OS. Possibly deprecated.
|
||||
501:
|
||||
@@ -905,14 +1026,17 @@ actions:
|
||||
description: Not required to be supported by any OS. Possibly deprecated.
|
||||
504:
|
||||
id: "KSC_F8"
|
||||
keyCode: "Sleep"
|
||||
title: Media Sleep
|
||||
description: Not required to be supported by any OS. Possibly deprecated.
|
||||
505:
|
||||
id: "KSC_F9"
|
||||
keyCode: "WakeUp"
|
||||
title: Media Coffee
|
||||
description: Not required to be supported by any OS. Possibly deprecated.
|
||||
506:
|
||||
id: "KSC_FA"
|
||||
keyCode: "BrowserRefresh"
|
||||
title: Media Refresh
|
||||
description: Not required to be supported by any OS. Possibly deprecated.
|
||||
507:
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
name: CC1
|
||||
col:
|
||||
- gap: 156
|
||||
row:
|
||||
- row:
|
||||
- {d: 30, e: 31, n: 32, w: 33, s: 34}
|
||||
- col:
|
||||
- {d: 25, e: 26, n: 27, w: 28, s: 29}
|
||||
- {d: 40, e: 41, n: 42, w: 43, s: 44}
|
||||
- col:
|
||||
- {d: 20, e: 21, n: 22, w: 23, s: 24}
|
||||
- {d: 35, e: 36, n: 37, w: 38, s: 39}
|
||||
- {d: 15, e: 16, n: 17, w: 18, s: 19}
|
||||
- row:
|
||||
- {d: 60, w: 61, n: 62, e: 63, s: 64}
|
||||
- col:
|
||||
- {d: 65, w: 66, n: 67, e: 68, s: 69}
|
||||
- {d: 80, w: 81, n: 82, e: 83, s: 84}
|
||||
- col:
|
||||
- {d: 70, w: 71, n: 72, e: 73, s: 74}
|
||||
- {d: 85, w: 86, n: 87, e: 88, s: 89}
|
||||
- {d: 75, w: 76, n: 77, e: 78, s: 79}
|
||||
- gap: 48
|
||||
margin-top: -32
|
||||
row:
|
||||
- {d: 10, e: 11, n: 12, w: 13, s: 14}
|
||||
- {d: 55, w: 56, n: 57, e: 58, s: 59}
|
||||
- gap: 160
|
||||
row:
|
||||
- {d: 5, e: 6, n: 7, w: 8, s: 9}
|
||||
- {d: 50, w: 51, n: 52, e: 53, s: 54}
|
||||
- gap: 320
|
||||
margin-top: -12
|
||||
row:
|
||||
- {d: 0, e: 1, n: 2, w: 3, s: 4}
|
||||
- {d: 45, w: 46, n: 47, e: 48, s: 49}
|
||||
143
src/lib/assets/layouts/generic/103-key.yml
Normal file
143
src/lib/assets/layouts/generic/103-key.yml
Normal file
@@ -0,0 +1,143 @@
|
||||
name: Lite
|
||||
col:
|
||||
- row:
|
||||
- key: 110
|
||||
- key: 112
|
||||
offset: [ 1, 0 ]
|
||||
- key: 113
|
||||
- key: 114
|
||||
- key: 115
|
||||
- key: 116
|
||||
offset: [ 0.5, 0 ]
|
||||
- key: 117
|
||||
- key: 118
|
||||
- key: 119
|
||||
- key: 120
|
||||
offset: [ 0.5, 0 ]
|
||||
- key: 121
|
||||
- key: 122
|
||||
- key: 123
|
||||
- key: 124
|
||||
offset: [ 0.25, 0 ]
|
||||
- key: 125
|
||||
- key: 126
|
||||
- offset: [ 0, 0.25 ]
|
||||
row:
|
||||
- key: 1
|
||||
- key: 2
|
||||
- key: 3
|
||||
- key: 4
|
||||
- key: 5
|
||||
- key: 6
|
||||
- key: 7
|
||||
- key: 8
|
||||
- key: 9
|
||||
- key: 10
|
||||
- key: 11
|
||||
- key: 12
|
||||
- key: 13
|
||||
- key: 15
|
||||
size: [ 2, 1 ]
|
||||
- key: 75
|
||||
offset: [ 0.25, 0 ]
|
||||
- key: 80
|
||||
- key: 85
|
||||
- key: 90
|
||||
offset: [ 0.25, 0 ]
|
||||
- key: 95
|
||||
- key: 100
|
||||
- key: 105
|
||||
- row:
|
||||
- key: 16
|
||||
size: [ 1.5, 1 ]
|
||||
- key: 17
|
||||
- key: 18
|
||||
- key: 19
|
||||
- key: 20
|
||||
- key: 21
|
||||
- key: 22
|
||||
- key: 23
|
||||
- key: 24
|
||||
- key: 25
|
||||
- key: 26
|
||||
- key: 27
|
||||
- key: 28
|
||||
- key: 29
|
||||
size: [ 1.5, 1 ]
|
||||
- key: 76
|
||||
offset: [ 0.25, 0 ]
|
||||
- key: 81
|
||||
- key: 86
|
||||
- key: 91
|
||||
offset: [ 0.25, 0 ]
|
||||
- key: 96
|
||||
- key: 101
|
||||
- key: 106
|
||||
size: [ 1, 2 ]
|
||||
- offset: [ 0, -1 ]
|
||||
row:
|
||||
- key: 30
|
||||
size: [ 2, 1 ]
|
||||
- key: 31
|
||||
- key: 32
|
||||
- key: 33
|
||||
- key: 34
|
||||
- key: 35
|
||||
- key: 36
|
||||
- key: 37
|
||||
- key: 38
|
||||
- key: 39
|
||||
- key: 40
|
||||
- key: 41
|
||||
- key: 43
|
||||
size: [ 2, 1 ]
|
||||
- key: 92
|
||||
offset: [ 3.5, 0 ]
|
||||
- key: 97
|
||||
- key: 102
|
||||
- row:
|
||||
- key: 44
|
||||
size: [ 2.5, 1 ]
|
||||
- key: 46
|
||||
- key: 47
|
||||
- key: 48
|
||||
- key: 49
|
||||
- key: 50
|
||||
- key: 51
|
||||
- key: 52
|
||||
- key: 53
|
||||
- key: 54
|
||||
- key: 55
|
||||
- key: 57
|
||||
size: [ 2.5, 1 ]
|
||||
- key: 83
|
||||
offset: [ 1.25, 0 ]
|
||||
- key: 93
|
||||
offset: [ 1.25, 0 ]
|
||||
- key: 98
|
||||
- key: 103
|
||||
- key: 108
|
||||
size: [ 1, 2 ]
|
||||
- offset: [ 0, -1 ]
|
||||
row:
|
||||
- key: 58
|
||||
size: [ 1.5, 1 ]
|
||||
- key: 59
|
||||
- key: 60
|
||||
size: [ 1.5, 1 ]
|
||||
- key: 61
|
||||
size: [ 7, 1 ]
|
||||
- key: 62
|
||||
size: [ 1.5, 1 ]
|
||||
- key: 63
|
||||
- key: 64
|
||||
size: [ 1.5, 1 ]
|
||||
- key: 79
|
||||
offset: [ 0.25, 0 ]
|
||||
- key: 84
|
||||
- key: 89
|
||||
- key: 99
|
||||
offset: [ 0.25, 0 ]
|
||||
size: [ 2, 1 ]
|
||||
- key: 104
|
||||
|
||||
87
src/lib/assets/layouts/lite.yml
Normal file
87
src/lib/assets/layouts/lite.yml
Normal file
@@ -0,0 +1,87 @@
|
||||
name: Lite
|
||||
col:
|
||||
- row:
|
||||
- key: 53
|
||||
- key: 54
|
||||
- key: 55
|
||||
- key: 56
|
||||
- key: 57
|
||||
- key: 58
|
||||
- key: 59
|
||||
- key: 60
|
||||
- key: 61
|
||||
- key: 62
|
||||
- key: 63
|
||||
- key: 64
|
||||
- key: 65
|
||||
- key: 66
|
||||
size: [ 2, 1 ]
|
||||
- row:
|
||||
- key: 39
|
||||
size: [ 1.5, 1 ]
|
||||
- key: 40
|
||||
- key: 41
|
||||
- key: 42
|
||||
- key: 43
|
||||
- key: 44
|
||||
- key: 45
|
||||
- key: 46
|
||||
- key: 47
|
||||
- key: 48
|
||||
- key: 49
|
||||
- key: 50
|
||||
- key: 51
|
||||
- key: 52
|
||||
size: [ 1.5, 1 ]
|
||||
- row:
|
||||
- key: 26
|
||||
size: [ 1.75, 1 ]
|
||||
- key: 27
|
||||
- key: 28
|
||||
- key: 29
|
||||
- key: 30
|
||||
- key: 31
|
||||
- key: 32
|
||||
- key: 33
|
||||
- key: 34
|
||||
- key: 35
|
||||
- key: 36
|
||||
- key: 37
|
||||
- key: 38
|
||||
size: [ 2.25, 1 ]
|
||||
- row:
|
||||
- key: 12
|
||||
size: [ 2, 1 ]
|
||||
- key: 13
|
||||
- key: 14
|
||||
- key: 15
|
||||
- key: 16
|
||||
- key: 17
|
||||
- key: 18
|
||||
- key: 19
|
||||
- key: 20
|
||||
- key: 21
|
||||
- key: 22
|
||||
- key: 23
|
||||
- key: 24
|
||||
- key: 25
|
||||
- row:
|
||||
- key: 0
|
||||
- key: 1
|
||||
size: [ 1.25, 1 ]
|
||||
- key: 2
|
||||
size: [ 1.25, 1 ]
|
||||
- key: 3
|
||||
size: [ 2, 1 ]
|
||||
- key: 4
|
||||
- key: 5
|
||||
- key: 6
|
||||
size: [ 2, 1 ]
|
||||
- key: 7
|
||||
size: [ 1.25, 1 ]
|
||||
- key: 8
|
||||
size: [ 1.25, 1 ]
|
||||
- key: 9
|
||||
- key: 10
|
||||
- key: 11
|
||||
|
||||
42
src/lib/assets/layouts/one.yml
Normal file
42
src/lib/assets/layouts/one.yml
Normal file
@@ -0,0 +1,42 @@
|
||||
name: CC1
|
||||
col:
|
||||
# Ring / Middle
|
||||
- offset: [2, 0]
|
||||
row:
|
||||
- switch: { d: 25, e: 26, n: 27, w: 28, s: 29 }
|
||||
- switch: { d: 20, e: 21, n: 22, w: 23, s: 24 }
|
||||
- offset: [4, 0]
|
||||
switch: { d: 65, w: 66, n: 67, e: 68, s: 69 }
|
||||
- switch: { d: 70, w: 71, n: 72, e: 73, s: 74 }
|
||||
- offset: [2, 0]
|
||||
row:
|
||||
- switch: { d: 40, e: 41, n: 42, w: 43, s: 44 }
|
||||
- switch: { d: 35, e: 36, n: 37, w: 38, s: 39 }
|
||||
- offset: [4, 0]
|
||||
switch: { d: 80, w: 81, n: 82, e: 83, s: 84 }
|
||||
- switch: { d: 85, w: 86, n: 87, e: 88, s: 89 }
|
||||
# Pinkie / Index
|
||||
- offset: [0, -3]
|
||||
row:
|
||||
- switch: { d: 30, e: 31, n: 32, w: 33, s: 34 }
|
||||
- offset: [4, 0]
|
||||
switch: { d: 15, e: 16, n: 17, w: 18, s: 19 }
|
||||
- switch: { d: 60, w: 61, n: 62, e: 63, s: 64 }
|
||||
- offset: [4, 0]
|
||||
switch: { d: 75, w: 76, n: 77, e: 78, s: 79 }
|
||||
# Thumbs
|
||||
- row:
|
||||
- offset: [5.5, 0.5]
|
||||
switch: { d: 10, e: 11, n: 12, w: 13, s: 14 }
|
||||
- offset: [1, 0.5]
|
||||
switch: { d: 55, w: 56, n: 57, e: 58, s: 59 }
|
||||
- row:
|
||||
- offset: [4.5, -0.25]
|
||||
switch: { d: 5, e: 6, n: 7, w: 8, s: 9 }
|
||||
- offset: [3, -0.25]
|
||||
switch: { d: 50, w: 51, n: 52, e: 53, s: 54 }
|
||||
- row:
|
||||
- offset: [3.5, -0.25]
|
||||
switch: { d: 0, e: 1, n: 2, w: 3, s: 4 }
|
||||
- offset: [5, -0.25]
|
||||
switch: { d: 45, w: 46, n: 47, e: 48, s: 49 }
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
||||
<mask id="cross" maskUnits="userSpaceOnUse">
|
||||
<rect x="0" y="0" width="32" height="32" fill="white" />
|
||||
<path d="M0 0L32 32M0 32L32 0" stroke="black" stroke-width="3" />
|
||||
</mask>
|
||||
<circle cx="16" cy="16" r="11.5" fill="none" stroke="white" stroke-width="9" mask="url(#cross)" />
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 433 B |
118
src/lib/assets/settings.yml
Normal file
118
src/lib/assets/settings.yml
Normal file
@@ -0,0 +1,118 @@
|
||||
settings:
|
||||
1:
|
||||
title: Enable Serial Header
|
||||
description: boolean 0 or 1, default is 0
|
||||
2:
|
||||
title: Enable Serial Logging
|
||||
description: boolean 0 or 1, default is 0
|
||||
3:
|
||||
title: Enable Serial Debugging
|
||||
description: boolean 0 or 1, default is 0
|
||||
4:
|
||||
title: Enable Serial Raw
|
||||
description: boolean 0 or 1, default is 0
|
||||
5:
|
||||
title: Enable Serial Chord
|
||||
description: boolean 0 or 1, default is 0
|
||||
6:
|
||||
title: Enable Serial Keyboard
|
||||
description: boolean 0 or 1, default is 0
|
||||
7:
|
||||
title: Enable Serial Mouse
|
||||
description: boolean 0 or 1, default is 0
|
||||
11:
|
||||
title: Enable USB HID Keyboard
|
||||
description: boolean 0 or 1, default is 1
|
||||
12:
|
||||
title: Enable Character Entry
|
||||
description: boolean 0 or 1
|
||||
13:
|
||||
title: GUI-CTRL Swap Mode
|
||||
description: boolean 0 or 1; 1 swaps keymap 0 and 1. (CCL only)
|
||||
14:
|
||||
title: Key Scan Duration
|
||||
description: scan rate described in milliseconds; default is 2ms = 500Hz
|
||||
15:
|
||||
title: Key Debounce Press Duration
|
||||
description: debounce time in milliseconds; default is 7ms on the One and 20ms on the Lite
|
||||
16:
|
||||
title: Key Debounce Release Duration
|
||||
description: debounce time in milliseconds; default is 7ms on the One and 20ms on the Lite
|
||||
17:
|
||||
title: Keyboard Output Character Microsecond Delays
|
||||
description: delay time in microseconds (one delay for press and again for release); default is 480us; max is 10240us; increments of 40us
|
||||
21:
|
||||
title: Enable USB HID Mouse
|
||||
description: boolean 0 or 1; default is 1
|
||||
22:
|
||||
title: Slow Mouse Speed
|
||||
description: pixels to move at the mouse poll rate; default for CC1 is 5 = 250px/s
|
||||
23:
|
||||
title: Fast Mouse Speed
|
||||
description: pixels to move at the mouse poll rate; default for CC1 is 25 = 1250px/s
|
||||
24:
|
||||
title: Enable Active Mouse
|
||||
description: boolean 0 or 1; moves mouse back and forth every 60s
|
||||
25:
|
||||
title: Mouse Scroll Speed
|
||||
description: default is 1; polls at 1/4th the rate of the mouse move updates
|
||||
26:
|
||||
title: Mouse Poll Duration
|
||||
description: poll rate described in milliseconds; default is 20ms = 50Hz
|
||||
31:
|
||||
title: Enable Chording
|
||||
description: boolean 0 or 1
|
||||
32:
|
||||
title: Enable Chording Character Counter Timeout
|
||||
description: boolean 0 or 1; default is 1
|
||||
33:
|
||||
title: Chording Character Counter Timeout Timer
|
||||
description: 0-255 deciseconds; default is 40 or 4.0 seconds
|
||||
34:
|
||||
title: Chord Detection Press Tolerance(ms)
|
||||
description: 1-50 milliseconds
|
||||
35:
|
||||
title: Chord Detection Release Tolerance(ms)
|
||||
description: 1-50 milliseconds
|
||||
41:
|
||||
title: Enable Spurring
|
||||
description: boolean 0 or 1; default is 1
|
||||
42:
|
||||
title: Enable Spurring Character Counter Timeout
|
||||
description: boolean 0 or 1; default is 1
|
||||
43:
|
||||
title: Spurring Character Counter Timeout Timer
|
||||
description: 0-255 seconds; default is 240
|
||||
51:
|
||||
title: Enable Arpeggiates
|
||||
description: boolean 0 or 1; default is 1
|
||||
54:
|
||||
title: Arpeggiate Tolerance
|
||||
description: in milliseconds; default 800ms
|
||||
61:
|
||||
title: Enable Compound Chording (coming soon)
|
||||
description: boolean 0 or 1; default is 0
|
||||
64:
|
||||
title: Compound Tolerance
|
||||
description: in milliseconds; default 1500ms
|
||||
81:
|
||||
title: LED Brightness
|
||||
description: 0-50 (CCL only); default is 5, which draws around 100 mA of current
|
||||
82:
|
||||
title: LED Color Code
|
||||
description: Color Codes to be listed (CCL only)
|
||||
83:
|
||||
title: Enable LED Key Highlight (coming soon)
|
||||
description: boolean 0 or 1 (CCL only)
|
||||
84:
|
||||
title: Enable LEDs
|
||||
description: boolean 0 or 1; default is 1 (CCL only)
|
||||
91:
|
||||
title: Operating System
|
||||
description: Operating system codes listed below
|
||||
92:
|
||||
title: Enable Realtime Feedback
|
||||
description: boolean 0 or 1; default is 1
|
||||
93:
|
||||
title: Enable CharaChorder Ready on startup
|
||||
description: boolean 0 or 1; default is 1
|
||||
161
src/lib/backup/backup.ts
Normal file
161
src/lib/backup/backup.ts
Normal file
@@ -0,0 +1,161 @@
|
||||
import type {
|
||||
CharaBackupFile,
|
||||
CharaChordFile,
|
||||
CharaFile,
|
||||
CharaLayoutFile,
|
||||
CharaSettingsFile,
|
||||
} from "$lib/share/chara-file.js"
|
||||
import type {Change} from "$lib/undo-redo.js"
|
||||
import {changes, ChangeType, chords, layout, settings} from "$lib/undo-redo.js"
|
||||
import {get} from "svelte/store"
|
||||
import {serialPort} from "../serial/connection"
|
||||
import {csvLayoutToJson, isCsvLayout} from "$lib/backup/compat/legacy-layout"
|
||||
import {isCsvChords, csvChordsToJson} from "./compat/legacy-chords"
|
||||
|
||||
export function downloadFile<T extends CharaFile<string>>(contents: T) {
|
||||
const downloadUrl = URL.createObjectURL(new Blob([JSON.stringify(contents)], {type: "application/json"}))
|
||||
const element = document.createElement("a")
|
||||
element.setAttribute(
|
||||
"download",
|
||||
`${contents.type}-${get(serialPort)?.device}-${new Date().toISOString()}.json`,
|
||||
)
|
||||
element.href = downloadUrl
|
||||
element.setAttribute("target", "_blank")
|
||||
element.click()
|
||||
URL.revokeObjectURL(downloadUrl)
|
||||
}
|
||||
|
||||
export function downloadBackup() {
|
||||
downloadFile<CharaBackupFile>({
|
||||
charaVersion: 1,
|
||||
type: "backup",
|
||||
history: [[createChordBackup(), createLayoutBackup(), createSettingsBackup()]],
|
||||
})
|
||||
}
|
||||
|
||||
export function createLayoutBackup(): CharaLayoutFile {
|
||||
return {
|
||||
charaVersion: 1,
|
||||
type: "layout",
|
||||
device: get(serialPort)?.device,
|
||||
layout: get(layout).map(it => it.map(it => it.action)) as [number[], number[], number[]],
|
||||
}
|
||||
}
|
||||
|
||||
export function createChordBackup(): CharaChordFile {
|
||||
return {charaVersion: 1, type: "chords", chords: get(chords).map(it => [it.actions, it.phrase])}
|
||||
}
|
||||
|
||||
export function createSettingsBackup(): CharaSettingsFile {
|
||||
return {charaVersion: 1, type: "settings", settings: get(settings).map(it => it.value)}
|
||||
}
|
||||
|
||||
export async function restoreBackup(event: Event) {
|
||||
const input = (event.target as HTMLInputElement).files![0]
|
||||
if (!input) return
|
||||
const text = await input.text()
|
||||
if (input.name.endsWith(".json")) {
|
||||
restoreFromFile(JSON.parse(text))
|
||||
} else if (isCsvLayout(text)) {
|
||||
restoreFromFile(csvLayoutToJson(text))
|
||||
} else if (isCsvChords(text)) {
|
||||
restoreFromFile(csvChordsToJson(text))
|
||||
}
|
||||
}
|
||||
|
||||
export function restoreFromFile(
|
||||
file: CharaBackupFile | CharaSettingsFile | CharaLayoutFile | CharaChordFile,
|
||||
) {
|
||||
if (file.charaVersion !== 1) throw new Error("Incompatible backup")
|
||||
switch (file.type) {
|
||||
case "backup": {
|
||||
const recent = file.history[0]
|
||||
if (recent[1].device !== get(serialPort)?.device) {
|
||||
alert("Backup is incompatible with this device")
|
||||
throw new Error("Backup is incompatible with this device")
|
||||
}
|
||||
|
||||
changes.update(changes => {
|
||||
changes.push(
|
||||
...getChangesFromChordFile(recent[0]),
|
||||
...getChangesFromLayoutFile(recent[1]),
|
||||
...getChangesFromSettingsFile(recent[2]),
|
||||
)
|
||||
return changes
|
||||
})
|
||||
break
|
||||
}
|
||||
case "chords": {
|
||||
changes.update(changes => {
|
||||
changes.push(...getChangesFromChordFile(file))
|
||||
return changes
|
||||
})
|
||||
break
|
||||
}
|
||||
case "layout": {
|
||||
changes.update(changes => {
|
||||
changes.push(...getChangesFromLayoutFile(file))
|
||||
return changes
|
||||
})
|
||||
break
|
||||
}
|
||||
case "settings": {
|
||||
changes.update(changes => {
|
||||
changes.push(...getChangesFromSettingsFile(file))
|
||||
return changes
|
||||
})
|
||||
break
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unknown backup type "${(file as CharaFile<string>).type}"`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function getChangesFromChordFile(file: CharaChordFile) {
|
||||
const changes: Change[] = []
|
||||
const existingChords = new Set(get(chords).map(({phrase, actions}) => JSON.stringify([actions, phrase])))
|
||||
for (const [input, output] of file.chords) {
|
||||
if (existingChords.has(JSON.stringify([input, output]))) {
|
||||
continue
|
||||
}
|
||||
changes.push({
|
||||
type: ChangeType.Chord,
|
||||
actions: input,
|
||||
phrase: output,
|
||||
id: input,
|
||||
})
|
||||
}
|
||||
return changes
|
||||
}
|
||||
|
||||
export function getChangesFromSettingsFile(file: CharaSettingsFile) {
|
||||
const changes: Change[] = []
|
||||
for (const [id, value] of file.settings.entries()) {
|
||||
if (get(settings)[id].value !== value) {
|
||||
changes.push({
|
||||
type: ChangeType.Setting,
|
||||
id,
|
||||
setting: value,
|
||||
})
|
||||
}
|
||||
}
|
||||
return changes
|
||||
}
|
||||
|
||||
export function getChangesFromLayoutFile(file: CharaLayoutFile) {
|
||||
const changes: Change[] = []
|
||||
for (const [layer, keys] of file.layout.entries()) {
|
||||
for (const [id, action] of keys.entries()) {
|
||||
if (get(layout)[layer][id].action !== action) {
|
||||
changes.push({
|
||||
type: ChangeType.Layout,
|
||||
layer,
|
||||
id,
|
||||
action,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return changes
|
||||
}
|
||||
26
src/lib/backup/compat/legacy-chords.sample.csv
Normal file
26
src/lib/backup/compat/legacy-chords.sample.csv
Normal file
@@ -0,0 +1,26 @@
|
||||
e + b + a,babe
|
||||
e + c + b,because
|
||||
f + e + c + a,face
|
||||
h + e + c + a,each
|
||||
i + d + ',I'd
|
||||
i + g + b,big
|
||||
i + g + e,give
|
||||
k + b + a,back
|
||||
k + e + a,take
|
||||
l + e + a,late
|
||||
l + e + d + a,lead
|
||||
l + f + e,feel
|
||||
l + g + e + a,large
|
||||
l + h + e,help
|
||||
l + i + a,Lia
|
||||
l + i + f,fill
|
||||
l + i + f + e,life
|
||||
l + i + g + b + a,gitlab
|
||||
l + k + i + e,like
|
||||
m + e + a,make
|
||||
m + i + ',I'm
|
||||
n + c + a,can
|
||||
n + d + a,and
|
||||
n + e + b,been
|
||||
n + e + b + a,enable
|
||||
n + e + d,end
|
||||
|
26
src/lib/backup/compat/legacy-chords.sample.json
Normal file
26
src/lib/backup/compat/legacy-chords.sample.json
Normal file
@@ -0,0 +1,26 @@
|
||||
e + b + a,babe
|
||||
e + c + b,because
|
||||
f + e + c + a,face
|
||||
h + e + c + a,each
|
||||
i + d + ',I'd
|
||||
i + g + b,big
|
||||
i + g + e,give
|
||||
k + b + a,back
|
||||
k + e + a,take
|
||||
l + e + a,late
|
||||
l + e + d + a,lead
|
||||
l + f + e,feel
|
||||
l + g + e + a,large
|
||||
l + h + e,help
|
||||
l + i + a,Lia
|
||||
l + i + f,fill
|
||||
l + i + f + e,life
|
||||
l + i + g + b + a,gitlab
|
||||
l + k + i + e,like
|
||||
m + e + a,make
|
||||
m + i + ',I'm
|
||||
n + c + a,can
|
||||
n + d + a,and
|
||||
n + e + b,been
|
||||
n + e + b + a,enable
|
||||
n + e + d,end
|
||||
20
src/lib/backup/compat/legacy-chords.ts
Normal file
20
src/lib/backup/compat/legacy-chords.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import {KEYMAP_IDS} from "$lib/serial/keymap-codes"
|
||||
import type {CharaChordFile} from "$lib/share/chara-file"
|
||||
|
||||
export function csvChordsToJson(csv: string): CharaChordFile {
|
||||
return {
|
||||
charaVersion: 1,
|
||||
type: "chords",
|
||||
chords: csv.split("\n").map(line => {
|
||||
const [input, output] = line.split(",", 2)
|
||||
return [
|
||||
input.split("+").map(it => KEYMAP_IDS.get(it.trim())?.code ?? 0),
|
||||
output.split("").map(it => KEYMAP_IDS.get(it.trim())?.code ?? 0),
|
||||
]
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
export function isCsvChords(csv: string): boolean {
|
||||
return /^([^+,\s]( *\+ *[^+,\s]+)* *, *[^+,\s]+ *(\n|(?=$)))+$/.test(csv)
|
||||
}
|
||||
40
src/lib/components/Action.svelte
Normal file
40
src/lib/components/Action.svelte
Normal file
@@ -0,0 +1,40 @@
|
||||
<script lang="ts">
|
||||
import {KEYMAP_CODES} from "$lib/serial/keymap-codes"
|
||||
import type {KeyInfo} from "$lib/serial/keymap-codes"
|
||||
import {action as title} from "$lib/title"
|
||||
|
||||
export let action: number | KeyInfo
|
||||
export let display: "inline-keys" | "keys" = "inline-keys"
|
||||
|
||||
$: info = typeof action === "number" ? KEYMAP_CODES[action] ?? {code: action} : action
|
||||
</script>
|
||||
|
||||
{#if display === "keys"}
|
||||
<kbd class:icon={!!info.icon} use:title={{title: info.title ?? info.id}}>
|
||||
{info.icon ?? info.id ?? `0x${info.code.toString(16)}`}
|
||||
</kbd>
|
||||
{:else if display === "inline-keys"}
|
||||
{#if !info.icon && info.id?.length === 1}
|
||||
<span>{info.id}</span>
|
||||
{:else}
|
||||
<kbd class="inline-kbd" class:icon={!!info.icon} use:title={{title: info.title ?? info.id}}>
|
||||
{info.icon ?? info.id ?? `0x${info.code.toString(16)}`}</kbd
|
||||
>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<style lang="scss">
|
||||
kbd:not(.inline-kbd) {
|
||||
height: 24px;
|
||||
padding-block: auto;
|
||||
transition: color 250ms ease;
|
||||
}
|
||||
|
||||
.inline-kbd {
|
||||
margin-inline-end: 2px;
|
||||
}
|
||||
|
||||
:global(span) + .inline-kbd {
|
||||
margin-inline-start: 2px;
|
||||
}
|
||||
</style>
|
||||
@@ -22,7 +22,7 @@
|
||||
<i>{key.description}</i>
|
||||
{/if}
|
||||
</div>
|
||||
<span class:icon={!!key.icon} class="key">{key.icon || key.id || `0x${key.code.toString(16)}`}</span>
|
||||
<kbd class:icon={!!key.icon}>{key.icon || key.id || `0x${key.code.toString(16)}`}</kbd>
|
||||
{:else}
|
||||
<span class="key">0x{key.toString(16)}</span>
|
||||
{/if}
|
||||
@@ -35,6 +35,7 @@
|
||||
align-items: center;
|
||||
|
||||
width: 100%;
|
||||
height: auto;
|
||||
margin: 0;
|
||||
padding: 8px;
|
||||
|
||||
@@ -62,17 +63,7 @@
|
||||
text-align: start;
|
||||
}
|
||||
|
||||
.key {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
min-width: 32px;
|
||||
padding: 4px;
|
||||
|
||||
font-weight: 600;
|
||||
|
||||
border: 1px solid currentcolor;
|
||||
border-radius: 4px;
|
||||
kbd {
|
||||
height: 24px;
|
||||
}
|
||||
</style>
|
||||
|
||||
11
src/lib/components/ActionString.svelte
Normal file
11
src/lib/components/ActionString.svelte
Normal file
@@ -0,0 +1,11 @@
|
||||
<script lang="ts">
|
||||
import Action from "$lib/components/Action.svelte"
|
||||
import type {KeyInfo} from "$lib/serial/keymap-codes"
|
||||
|
||||
export let actions: Array<number | KeyInfo>
|
||||
export let display: "keys" | "inline-keys" = "inline-keys"
|
||||
</script>
|
||||
|
||||
{#each actions as action, i (`${typeof action === "number" ? action : action.code}:${i}`)}
|
||||
<Action {action} {display} />
|
||||
{/each}
|
||||
@@ -16,7 +16,13 @@
|
||||
<form on:submit={submit}>
|
||||
<div bind:this={io} class="io">
|
||||
{#each $serialLog as { type, value }}
|
||||
<p class={type} transition:slide>{value}</p>
|
||||
{#if type === "input"}
|
||||
<code transition:slide>{value}</code>
|
||||
{:else if type === "output"}
|
||||
<samp transition:slide>{value}</samp>
|
||||
{:else}
|
||||
<p transition:slide>{value}</p>
|
||||
{/if}
|
||||
{/each}
|
||||
<div class="anchor" />
|
||||
</div>
|
||||
@@ -111,17 +117,15 @@
|
||||
height: 1px;
|
||||
}
|
||||
|
||||
code,
|
||||
samp,
|
||||
p {
|
||||
display: block;
|
||||
overflow-anchor: none;
|
||||
margin-block: 0.15rem;
|
||||
}
|
||||
|
||||
p.input {
|
||||
margin-block-end: 0.25rem;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
p.system {
|
||||
p {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
|
||||
@@ -134,8 +138,9 @@
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
p.input::before {
|
||||
code::before {
|
||||
content: "> ";
|
||||
margin-block-end: 0.25rem;
|
||||
font-weight: 900;
|
||||
color: var(--md-sys-color-primary);
|
||||
}
|
||||
|
||||
22
src/lib/components/Tooltip.svelte
Normal file
22
src/lib/components/Tooltip.svelte
Normal file
@@ -0,0 +1,22 @@
|
||||
<script lang="ts">
|
||||
export let title: string | undefined
|
||||
export let shortcut: string | undefined
|
||||
</script>
|
||||
|
||||
{#if title}
|
||||
<p>{@html title}</p>
|
||||
{/if}
|
||||
|
||||
{#if shortcut}
|
||||
<kbd>
|
||||
{#each shortcut.split("+") as key}
|
||||
<kbd>{key}</kbd>
|
||||
{/each}
|
||||
</kbd>
|
||||
{/if}
|
||||
|
||||
<style lang="scss">
|
||||
p {
|
||||
margin-block: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -1,12 +1,13 @@
|
||||
<script lang="ts">
|
||||
import {KEYMAP_CODES} from "$lib/serial/keymap-codes"
|
||||
import {KEYMAP_CATEGORIES, KEYMAP_CODES} from "$lib/serial/keymap-codes"
|
||||
import type {KeyInfo} from "$lib/serial/keymap-codes"
|
||||
import Index from "flexsearch"
|
||||
import {createEventDispatcher} from "svelte"
|
||||
import ActionListItem from "$lib/components/ActionListItem.svelte"
|
||||
import LL from "../../../i18n/i18n-svelte"
|
||||
import {action} from "$lib/title"
|
||||
|
||||
export let currentAction: number
|
||||
export let currentAction: number | undefined = undefined
|
||||
|
||||
const index = new Index({tokenize: "full"})
|
||||
for (const action of Object.values(KEYMAP_CODES)) {
|
||||
@@ -38,10 +39,6 @@
|
||||
function keyboardNavigation(event: KeyboardEvent) {
|
||||
if (event.shiftKey && event.key === "Enter") {
|
||||
dispatch("select", exact)
|
||||
} else if (event.shiftKey && event.key === "Escape") {
|
||||
dispatch("select", 0)
|
||||
} else if (event.key === "Escape") {
|
||||
dispatch("close")
|
||||
} else if (event.key === "ArrowDown") {
|
||||
const element =
|
||||
resultList.querySelector("li:focus-within")?.nextSibling ?? resultList.querySelector("li:not(.exact)")
|
||||
@@ -62,24 +59,25 @@
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
let results: number[] = []
|
||||
let results: number[] = Object.keys(KEYMAP_CODES).map(Number)
|
||||
let exact: number | undefined = undefined
|
||||
let code: number = Number.NaN
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
let searchBox: HTMLInputElement
|
||||
let resultList: HTMLUListElement
|
||||
let filter: Set<number>
|
||||
</script>
|
||||
|
||||
<svelte:window on:keydown={keyboardNavigation} />
|
||||
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events a11y-no-noninteractive-element-interactions -->
|
||||
<dialog open on:click|self={() => dispatch("close")}>
|
||||
<div class="content">
|
||||
<div class="search-row">
|
||||
<input
|
||||
type="search"
|
||||
bind:this={searchBox}
|
||||
autofocus
|
||||
on:input={search}
|
||||
on:keypress={event => {
|
||||
if (event.key === "Enter") {
|
||||
@@ -88,24 +86,46 @@
|
||||
}}
|
||||
placeholder={$LL.actionSearch.PLACEHOLDER()}
|
||||
/>
|
||||
<button on:click={() => select(0)}
|
||||
><div><span class="icon key-hint">shift</span>+<span class="key-hint">ESC</span></div>
|
||||
{$LL.actionSearch.DELETE()}</button
|
||||
<button on:click={() => select(0)} use:action={{shortcut: "shift+esc"}}
|
||||
>{$LL.actionSearch.DELETE()}</button
|
||||
>
|
||||
<button
|
||||
use:action={{title: $LL.modal.CLOSE(), shortcut: "esc"}}
|
||||
class="icon"
|
||||
on:click={() => dispatch("close")}>close</button
|
||||
>
|
||||
<button title={$LL.modal.CLOSE()} class="icon" on:click={() => dispatch("close")}>close</button>
|
||||
</div>
|
||||
<aside>
|
||||
<h3>{$LL.actionSearch.CURRENT_ACTION()}</h3>
|
||||
<ActionListItem id={currentAction} />
|
||||
</aside>
|
||||
<fieldset class="filters">
|
||||
<label
|
||||
>{$LL.actionSearch.filter.ALL()}<input
|
||||
checked
|
||||
name="category"
|
||||
type="radio"
|
||||
value={undefined}
|
||||
bind:group={filter}
|
||||
/></label
|
||||
>
|
||||
{#each KEYMAP_CATEGORIES as category}
|
||||
<label
|
||||
>{category.name}<input
|
||||
name="category"
|
||||
type="radio"
|
||||
value={new Set(Object.keys(category.actions).map(Number))}
|
||||
bind:group={filter}
|
||||
/></label
|
||||
>
|
||||
{/each}
|
||||
</fieldset>
|
||||
{#if currentAction !== undefined}
|
||||
<aside>
|
||||
<h3>{$LL.actionSearch.CURRENT_ACTION()}</h3>
|
||||
<ActionListItem id={currentAction} />
|
||||
</aside>
|
||||
{/if}
|
||||
<ul bind:this={resultList}>
|
||||
{#if exact !== undefined}
|
||||
<li class="exact">
|
||||
<i
|
||||
>Exact match <span class="icon key-hint">shift</span>+<span class="icon key-hint"
|
||||
>keyboard_return</span
|
||||
></i
|
||||
>
|
||||
<i>Exact match</i>
|
||||
<ActionListItem id={exact} on:click={() => select(exact)} />
|
||||
</li>
|
||||
{/if}
|
||||
@@ -116,7 +136,7 @@
|
||||
<li>Action code is out of range</li>
|
||||
{/if}
|
||||
{/if}
|
||||
{#each results as id (id)}
|
||||
{#each filter ? results.filter(it => filter.has(it)) : results as id (id)}
|
||||
<li><ActionListItem {id} on:click={() => select(id)} /></li>
|
||||
{/each}
|
||||
</ul>
|
||||
@@ -124,6 +144,32 @@
|
||||
</dialog>
|
||||
|
||||
<style lang="scss">
|
||||
.filters {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
border: none;
|
||||
|
||||
label {
|
||||
height: unset;
|
||||
padding-block: 2px;
|
||||
padding-inline: 4px;
|
||||
|
||||
font-size: 14px;
|
||||
|
||||
border: 1px solid currentcolor;
|
||||
border-radius: 6px;
|
||||
|
||||
&:has(:checked) {
|
||||
color: var(--md-sys-color-on-secondary);
|
||||
background: var(--md-sys-color-secondary);
|
||||
}
|
||||
|
||||
input {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dialog {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -156,51 +202,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin-inline: 16px;
|
||||
}
|
||||
|
||||
.search-row {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
align-items: center;
|
||||
margin-inline: 16px;
|
||||
|
||||
> button {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
height: fit-content;
|
||||
|
||||
color: currentcolor;
|
||||
|
||||
background: none;
|
||||
border: none;
|
||||
border-radius: 100%;
|
||||
|
||||
&:not(.icon) {
|
||||
font-family: inherit;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
& > div {
|
||||
display: flex;
|
||||
gap: 2px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
aspect-ratio: 1;
|
||||
color: var(--md-sys-color-on-surface-variant);
|
||||
background: var(--md-sys-color-surface-variant);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.content {
|
||||
position: relative;
|
||||
transform-origin: top left;
|
||||
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
@@ -281,26 +292,4 @@
|
||||
border-radius: 0 0 8px 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.key-hint {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
height: 20px;
|
||||
margin-block: 6px;
|
||||
padding: 2px;
|
||||
|
||||
font-size: 14px;
|
||||
font-weight: normal;
|
||||
color: currentcolor;
|
||||
|
||||
border: 1px solid currentcolor;
|
||||
border-radius: 4px;
|
||||
|
||||
&.icon {
|
||||
padding: 0;
|
||||
font-size: 18px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
201
src/lib/components/layout/GenericLayout.svelte
Normal file
201
src/lib/components/layout/GenericLayout.svelte
Normal file
@@ -0,0 +1,201 @@
|
||||
<script lang="ts">
|
||||
import {compileLayout} from "$lib/serialization/visual-layout"
|
||||
import type {VisualLayout, CompiledLayoutKey} from "$lib/serialization/visual-layout"
|
||||
import {deviceLayout} from "$lib/serial/connection"
|
||||
import {dev} from "$app/environment"
|
||||
import ActionSelector from "$lib/components/layout/ActionSelector.svelte"
|
||||
import {get} from "svelte/store"
|
||||
import type {Writable} from "svelte/store"
|
||||
import KeyboardKey from "$lib/components/layout/KeyboardKey.svelte"
|
||||
import {getContext} from "svelte"
|
||||
import type {VisualLayoutConfig} from "./visual-layout.js"
|
||||
import {changes, ChangeType} from "$lib/undo-redo"
|
||||
|
||||
const {scale, margin, strokeWidth, fontSize, iconFontSize} =
|
||||
getContext<VisualLayoutConfig>("visual-layout-config")
|
||||
const activeLayer = getContext<Writable<number>>("active-layer")
|
||||
|
||||
if (dev) {
|
||||
// you have absolutely no idea what a difference this makes for performance
|
||||
console.assert(scale % 1 === 0, "Scale must be an integer")
|
||||
console.assert((scale / 2) % 1 === 0, "Scale must be divisible by 2")
|
||||
console.assert(strokeWidth % 1 === 0, "Stroke must be an integer")
|
||||
console.assert(margin % 1 === 0, "Margin must be an integer")
|
||||
console.assert(fontSize % 1 === 0, "Font size must be an integer")
|
||||
console.assert(iconFontSize % 1 === 0, "Icon font size must be an integer")
|
||||
}
|
||||
|
||||
export let visualLayout: VisualLayout
|
||||
$: layoutInfo = compileLayout(visualLayout)
|
||||
|
||||
function getCenter(key: CompiledLayoutKey): [x: number, y: number] {
|
||||
return [key.pos[0] + key.size[0] / 2, key.pos[1] + key.size[1] / 2]
|
||||
}
|
||||
|
||||
function getDistance(a: CompiledLayoutKey, b: CompiledLayoutKey) {
|
||||
const x1 = a.pos[0] + margin
|
||||
const y1 = a.pos[1] + margin
|
||||
const x1b = x1 + a.size[0] - margin
|
||||
const y1b = y1 + a.size[1] - margin
|
||||
const x2 = b.pos[0] + margin
|
||||
const y2 = b.pos[1] + margin
|
||||
const x2b = x2 + b.size[0] - margin
|
||||
const y2b = y2 + b.size[1] - margin
|
||||
|
||||
const left = x2b < x1
|
||||
const right = x1b < x2
|
||||
const bottom = y2b < y1
|
||||
const top = y1b < y2
|
||||
|
||||
return top && left
|
||||
? Math.sqrt((x1 - x2b) ** 2 + (y1b - y2) ** 2)
|
||||
: left && bottom
|
||||
? Math.sqrt((x1 - x2b) ** 2 + (y1 - y2b) ** 2)
|
||||
: bottom && right
|
||||
? Math.sqrt((x1b - x2) ** 2 + (y1 - y2b) ** 2)
|
||||
: right && top
|
||||
? Math.sqrt((x1b - x2) ** 2 + (y1b - y2) ** 2)
|
||||
: left
|
||||
? x1 - x2b
|
||||
: right
|
||||
? x2 - x1b
|
||||
: bottom
|
||||
? y1 - y2b
|
||||
: top
|
||||
? y2 - y1b
|
||||
: 0
|
||||
}
|
||||
|
||||
function navigate(event: KeyboardEvent) {
|
||||
if (event.altKey || event.ctrlKey || event.shiftKey || event.metaKey) return
|
||||
|
||||
let wantedAngle: number
|
||||
const angleThreshold = Math.PI
|
||||
|
||||
if (event.key === "ArrowUp") wantedAngle = Math.PI
|
||||
else if (event.key === "ArrowDown") wantedAngle = 0
|
||||
else if (event.key === "ArrowRight") wantedAngle = Math.PI / 2
|
||||
else if (event.key === "ArrowLeft") wantedAngle = -Math.PI / 2
|
||||
else return
|
||||
|
||||
event.preventDefault()
|
||||
if (!focusKey) (groupParent.firstChild as SVGGElement).focus()
|
||||
const [focusX, focusY] = getCenter(focusKey)
|
||||
|
||||
let bestDistance = Infinity
|
||||
let bestCandidate = 0
|
||||
let isOptimalAngle = false
|
||||
|
||||
for (const [i, key] of layoutInfo.keys.entries()) {
|
||||
if (key === focusKey) continue
|
||||
const [keyX, keyY] = getCenter(key)
|
||||
const deltaX = keyX - focusX
|
||||
const deltaY = keyY - focusY
|
||||
const angle = Math.atan2(deltaX, deltaY)
|
||||
const distance = getDistance(key, focusKey)
|
||||
|
||||
const angleDelta = Math.abs(wantedAngle - angle)
|
||||
|
||||
if (isOptimalAngle ? angleDelta > Number.EPSILON : angleDelta >= angleThreshold) continue
|
||||
if (distance > bestDistance) continue
|
||||
|
||||
bestDistance = distance
|
||||
bestCandidate = i
|
||||
isOptimalAngle = angleDelta <= Number.EPSILON
|
||||
}
|
||||
|
||||
const node = groupParent.children.item(bestCandidate)
|
||||
if (node instanceof SVGGElement) {
|
||||
node.focus()
|
||||
}
|
||||
}
|
||||
|
||||
function edit(index: number) {
|
||||
const keyInfo = layoutInfo.keys[index]
|
||||
const clickedGroup = groupParent.children.item(index) as SVGGElement
|
||||
const component = new ActionSelector({
|
||||
target: document.body,
|
||||
props: {currentAction: get(deviceLayout)[get(activeLayer)][keyInfo.id]},
|
||||
})
|
||||
const dialog = document.querySelector("dialog > div") as HTMLDivElement
|
||||
const backdrop = document.querySelector("dialog") as HTMLDialogElement
|
||||
const dialogRect = dialog.getBoundingClientRect()
|
||||
const groupRect = clickedGroup.getBoundingClientRect()
|
||||
|
||||
const scale = 0.5
|
||||
const dialogScale = `${1 - scale * (1 - groupRect.width / dialogRect.width)} ${
|
||||
1 - scale * (1 - groupRect.height / dialogRect.height)
|
||||
}`
|
||||
const dialogTranslate = `${scale * (groupRect.x - dialogRect.x)}px ${
|
||||
scale * (groupRect.y - dialogRect.y)
|
||||
}px`
|
||||
|
||||
const duration = 150
|
||||
const options = {duration, easing: "ease"}
|
||||
const dialogAnimation = dialog.animate(
|
||||
[
|
||||
{scale: dialogScale, translate: dialogTranslate},
|
||||
{translate: "0 0", scale: "1"},
|
||||
],
|
||||
options,
|
||||
)
|
||||
const backdropAnimation = backdrop.animate([{opacity: 0}, {opacity: 1}], options)
|
||||
|
||||
async function closed() {
|
||||
dialogAnimation.reverse()
|
||||
backdropAnimation.reverse()
|
||||
|
||||
await dialogAnimation.finished
|
||||
|
||||
component.$destroy()
|
||||
}
|
||||
|
||||
component.$on("close", closed)
|
||||
component.$on("select", ({detail}) => {
|
||||
changes.update(changes => {
|
||||
changes.push({
|
||||
type: ChangeType.Layout,
|
||||
id: keyInfo.id,
|
||||
layer: get(activeLayer),
|
||||
action: detail,
|
||||
})
|
||||
return changes
|
||||
})
|
||||
closed()
|
||||
})
|
||||
}
|
||||
|
||||
let focusKey: CompiledLayoutKey
|
||||
let groupParent: SVGElement
|
||||
</script>
|
||||
|
||||
<svelte:window on:keydown={navigate} />
|
||||
|
||||
<svg
|
||||
class="print"
|
||||
viewBox="0 0 {layoutInfo.size[0] * scale} {layoutInfo.size[1] * scale}"
|
||||
bind:this={groupParent}
|
||||
>
|
||||
{#each layoutInfo.keys as key, i}
|
||||
<KeyboardKey
|
||||
{i}
|
||||
{key}
|
||||
on:focusin={() => (focusKey = key)}
|
||||
on:click={() => edit(i)}
|
||||
on:keypress={({key}) => {
|
||||
if (key === "Enter") {
|
||||
edit(i)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{/each}
|
||||
</svg>
|
||||
|
||||
<style lang="scss">
|
||||
svg {
|
||||
overflow: visible;
|
||||
grid-area: "d";
|
||||
width: calc(min(100%, 35cm));
|
||||
max-height: calc(100% - 170px);
|
||||
}
|
||||
</style>
|
||||
@@ -1,18 +0,0 @@
|
||||
<script lang="ts">
|
||||
import {layout} from "$lib/serial/connection"
|
||||
import {KEYMAP_CODES} from "$lib/serial/keymap-codes"
|
||||
import ActionSelector from "$lib/components/layout/ActionSelector.svelte"
|
||||
import {popup} from "$lib/popup"
|
||||
import ActionListItem from "$lib/components/ActionListItem.svelte"
|
||||
|
||||
export let id: number = 0
|
||||
</script>
|
||||
|
||||
<table>
|
||||
{#each $layout as layer, i}
|
||||
<tr>
|
||||
<th class="icon">counter_{i + 1}</th>
|
||||
<ActionListItem id={layer[id]} />
|
||||
</tr>
|
||||
{/each}
|
||||
</table>
|
||||
67
src/lib/components/layout/KeyText.svelte
Normal file
67
src/lib/components/layout/KeyText.svelte
Normal file
@@ -0,0 +1,67 @@
|
||||
<script lang="ts">
|
||||
import {getContext} from "svelte"
|
||||
import type {Writable} from "svelte/store"
|
||||
import type {VisualLayoutConfig} from "$lib/components/layout/visual-layout"
|
||||
import type {CompiledLayoutKey} from "$lib/serialization/visual-layout"
|
||||
import {layout} from "$lib/undo-redo.js"
|
||||
import {KEYMAP_CODES} from "$lib/serial/keymap-codes"
|
||||
import {action} from "$lib/title"
|
||||
|
||||
const {fontSize, margin, inactiveOpacity, inactiveScale, iconFontSize} =
|
||||
getContext<VisualLayoutConfig>("visual-layout-config")
|
||||
const activeLayer = getContext<Writable<number>>("active-layer")
|
||||
|
||||
export let key: CompiledLayoutKey
|
||||
export let fontSizeMultiplier = 1
|
||||
|
||||
export let middle: [number, number]
|
||||
export let pos: [number, number]
|
||||
export let rotate: number
|
||||
|
||||
export let positions: [[number, number], [number, number], [number, number]]
|
||||
</script>
|
||||
|
||||
{#each positions as position, layer}
|
||||
{@const {action: actionId, isApplied} = $layout[layer][key.id] ?? {action: 0, isApplied: true}}
|
||||
{@const {code, icon, id, title} = KEYMAP_CODES[actionId] ?? {code: actionId}}
|
||||
{@const isActive = layer === $activeLayer}
|
||||
{@const direction = [(middle[0] - margin * 3) / position[0], (middle[1] - margin * 3) / position[1]]}
|
||||
<text
|
||||
fill={isApplied ? "currentcolor" : "var(--md-sys-color-primary)"}
|
||||
font-weight={isApplied ? "" : "bold"}
|
||||
text-anchor="middle"
|
||||
alignment-baseline="central"
|
||||
x={pos[0] + middle[0] + (isApplied ? 0 : fontSize / 3)}
|
||||
y={pos[1] + middle[1]}
|
||||
font-size={fontSizeMultiplier * (icon ? iconFontSize : fontSize)}
|
||||
font-family={icon ? "Material Symbols Rounded" : undefined}
|
||||
opacity={isActive ? 1 : inactiveOpacity}
|
||||
style:scale={isActive ? 1 : inactiveScale}
|
||||
style:translate={isActive ? "0 0 0" : `${direction[0]}px ${direction[1]}px 0`}
|
||||
style:rotate="{rotate}deg"
|
||||
use:action={{title: title ?? id}}
|
||||
>
|
||||
{#if code !== 0}
|
||||
{icon || id || `0x${code.toString(16)}`}
|
||||
{/if}
|
||||
{#if !isApplied}
|
||||
<tspan>•</tspan>
|
||||
{/if}
|
||||
</text>
|
||||
{/each}
|
||||
|
||||
<style lang="scss">
|
||||
$focus-transition: 10ms;
|
||||
$transition: 200ms;
|
||||
|
||||
text {
|
||||
will-change: translate, scale;
|
||||
transform-origin: center;
|
||||
transform-box: fill-box;
|
||||
transition:
|
||||
fill #{$focus-transition} ease,
|
||||
opacity #{$transition} ease,
|
||||
translate #{$transition} ease,
|
||||
scale #{$transition} ease;
|
||||
}
|
||||
</style>
|
||||
108
src/lib/components/layout/KeyboardKey.svelte
Normal file
108
src/lib/components/layout/KeyboardKey.svelte
Normal file
@@ -0,0 +1,108 @@
|
||||
<script lang="ts">
|
||||
import type {CompiledLayoutKey} from "$lib/serialization/visual-layout"
|
||||
import {getContext} from "svelte"
|
||||
import type {VisualLayoutConfig} from "./visual-layout.js"
|
||||
import KeyText from "$lib/components/layout/KeyText.svelte"
|
||||
|
||||
const {scale, margin, strokeWidth} = getContext<VisualLayoutConfig>("visual-layout-config")
|
||||
export let i: number
|
||||
export let key: CompiledLayoutKey
|
||||
|
||||
$: posX = key.pos[0] * scale
|
||||
$: posY = key.pos[1] * scale
|
||||
$: sizeX = key.size[0] * scale
|
||||
$: sizeY = key.size[1] * scale
|
||||
</script>
|
||||
|
||||
<g class="key-group" on:click on:keypress on:focusin role="button" tabindex={i + 1}>
|
||||
{#if key.shape === "square"}
|
||||
<rect
|
||||
x={posX + margin}
|
||||
y={posY + margin}
|
||||
rx={key.cornerRadius * scale}
|
||||
width={sizeX - margin * 2}
|
||||
height={sizeY - margin * 2}
|
||||
stroke-width={strokeWidth}
|
||||
/>
|
||||
<KeyText
|
||||
{key}
|
||||
middle={[sizeX / 2, sizeY / 2]}
|
||||
pos={[posX, posY]}
|
||||
rotate={-key.rotate}
|
||||
positions={[
|
||||
[-1, 1],
|
||||
[-1, -1],
|
||||
[1, -1],
|
||||
]}
|
||||
/>
|
||||
{:else if key.shape === "quarter-circle"}
|
||||
{@const innerMargin = margin / 2}
|
||||
{@const r1 = sizeX / 2 - margin}
|
||||
{@const p1 = r1 - innerMargin}
|
||||
{@const r2 = r1 - sizeY + innerMargin * 2}
|
||||
{@const p2 = r2 - innerMargin}
|
||||
{@const multiplier = 1.25}
|
||||
<g style:transform="rotateZ({key.rotate}deg) translate({innerMargin}px, {innerMargin}px)">
|
||||
<path
|
||||
d="M{posX + p1},{posY} a{r1},{r1} 0 0,1 {-p1},{p1} l0,{-(p1 - p2)} a{r2},{r2} 0 0,0 {p2},{-p2}z"
|
||||
/>
|
||||
<KeyText
|
||||
{key}
|
||||
middle={[sizeY - margin * 2, sizeY - margin * 2]}
|
||||
pos={[posX, posY]}
|
||||
rotate={-key.rotate}
|
||||
fontSizeMultiplier={multiplier}
|
||||
positions={[
|
||||
[-0.5, -0.5],
|
||||
[0.5, -0.5],
|
||||
[-0.5, 0.5],
|
||||
]}
|
||||
/>
|
||||
</g>
|
||||
{/if}
|
||||
</g>
|
||||
|
||||
<style lang="scss">
|
||||
$focus-transition: 10ms;
|
||||
$transition: 200ms;
|
||||
|
||||
rect {
|
||||
transform-origin: center;
|
||||
transform-box: fill-box;
|
||||
}
|
||||
|
||||
g {
|
||||
transform-origin: top left;
|
||||
transform-box: fill-box;
|
||||
}
|
||||
|
||||
path,
|
||||
rect {
|
||||
fill: var(--md-sys-color-background);
|
||||
fill-opacity: 0;
|
||||
stroke: currentcolor;
|
||||
}
|
||||
|
||||
path {
|
||||
fill: currentcolor;
|
||||
fill-opacity: 0;
|
||||
stroke-opacity: 0.3;
|
||||
}
|
||||
|
||||
g:hover {
|
||||
cursor: default;
|
||||
opacity: 0.6;
|
||||
transition: opacity #{$transition} ease;
|
||||
}
|
||||
|
||||
g:focus-within {
|
||||
color: var(--md-sys-color-primary);
|
||||
outline: none;
|
||||
|
||||
> path,
|
||||
> rect {
|
||||
fill: currentcolor;
|
||||
fill-opacity: 0.2;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,39 +1,58 @@
|
||||
<script lang="ts">
|
||||
import {serialPort} from "$lib/serial/connection"
|
||||
import LayoutCC1 from "$lib/components/layout/LayoutCC1.svelte"
|
||||
import {action} from "$lib/title"
|
||||
import GenericLayout from "$lib/components/layout/GenericLayout.svelte"
|
||||
import {getContext} from "svelte"
|
||||
import type {Writable} from "svelte/store"
|
||||
import type {VisualLayout} from "$lib/serialization/visual-layout"
|
||||
|
||||
$: device = $serialPort?.device ?? "ONE"
|
||||
let activeLayer = 0
|
||||
const activeLayer = getContext<Writable<number>>("active-layer")
|
||||
|
||||
const layers = [
|
||||
["Numeric Layer", "123", 1],
|
||||
["Primary Layer", "abc", 0],
|
||||
["Function Layer", "function", 2],
|
||||
] as const
|
||||
|
||||
const layouts = {
|
||||
ONE: () => import("$lib/assets/layouts/one.yml").then(it => it.default as VisualLayout),
|
||||
LITE: () => import("$lib/assets/layouts/lite.yml").then(it => it.default as VisualLayout),
|
||||
X: () => import("$lib/assets/layouts/generic/103-key.yml").then(it => it.default as VisualLayout),
|
||||
}
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<div class="container">
|
||||
<fieldset>
|
||||
{#each layers as [title, icon, value]}
|
||||
<button
|
||||
{title}
|
||||
class="icon"
|
||||
on:click={() => (activeLayer = value)}
|
||||
class:active={activeLayer === value}
|
||||
use:action={{title, shortcut: `alt+${value + 1}`}}
|
||||
on:click={() => ($activeLayer = value)}
|
||||
class:active={$activeLayer === value}
|
||||
>
|
||||
{icon}
|
||||
</button>
|
||||
{/each}
|
||||
</fieldset>
|
||||
|
||||
{#if device === "ONE"}
|
||||
<LayoutCC1 bind:activeLayer />
|
||||
{:else}
|
||||
<p>Unsupported device ({$serialPort?.device})</p>
|
||||
{/if}
|
||||
{#await layouts[device]() then visualLayout}
|
||||
<GenericLayout {visualLayout} />
|
||||
{/await}
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin-bottom: 96px;
|
||||
}
|
||||
|
||||
fieldset {
|
||||
position: relative;
|
||||
|
||||
@@ -41,7 +60,6 @@
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
margin-block-end: -36px;
|
||||
padding: 0;
|
||||
|
||||
border: none;
|
||||
@@ -71,13 +89,19 @@
|
||||
outline: 8px solid var(--md-sys-color-background);
|
||||
}
|
||||
|
||||
&:first-child,
|
||||
&:last-child {
|
||||
aspect-ratio: unset;
|
||||
height: unset;
|
||||
}
|
||||
|
||||
&:first-child {
|
||||
padding-inline-end: 16px;
|
||||
padding-inline: 4px 16px;
|
||||
border-radius: 16px 0 0 16px;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
padding-inline-start: 16px;
|
||||
padding-inline: 16px 4px;
|
||||
border-radius: 0 16px 16px 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
<script>
|
||||
import RingInput from "$lib/components/layout/RingInput.svelte"
|
||||
|
||||
export let activeLayer = 0
|
||||
</script>
|
||||
|
||||
<div class="col layout" style="gap: 0">
|
||||
<div class="row" style="gap: 156px">
|
||||
<div class="row">
|
||||
<RingInput {activeLayer} keys={{d: 30, e: 31, n: 32, w: 33, s: 34}} />
|
||||
<div class="col">
|
||||
<RingInput {activeLayer} keys={{d: 25, e: 26, n: 27, w: 28, s: 29}} />
|
||||
<RingInput {activeLayer} keys={{d: 40, e: 41, n: 42, w: 43, s: 44}} />
|
||||
</div>
|
||||
<div class="col">
|
||||
<RingInput {activeLayer} keys={{d: 20, e: 21, n: 22, w: 23, s: 24}} />
|
||||
<RingInput {activeLayer} keys={{d: 35, e: 36, n: 37, w: 38, s: 39}} />
|
||||
</div>
|
||||
<RingInput {activeLayer} keys={{d: 15, e: 16, n: 17, w: 18, s: 19}} />
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<RingInput {activeLayer} keys={{d: 60, w: 61, n: 62, e: 63, s: 64}} />
|
||||
<div class="col">
|
||||
<RingInput {activeLayer} keys={{d: 65, w: 66, n: 67, e: 68, s: 69}} />
|
||||
<RingInput {activeLayer} keys={{d: 80, w: 81, n: 82, e: 83, s: 84}} />
|
||||
</div>
|
||||
<div class="col">
|
||||
<RingInput {activeLayer} keys={{d: 70, w: 71, n: 72, e: 73, s: 74}} />
|
||||
<RingInput {activeLayer} keys={{d: 85, w: 86, n: 87, e: 88, s: 89}} />
|
||||
</div>
|
||||
<RingInput {activeLayer} keys={{d: 75, w: 76, n: 77, e: 78, s: 79}} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" style="gap: 48px; margin-top: -32px">
|
||||
<RingInput {activeLayer} keys={{d: 10, e: 11, n: 12, w: 13, s: 14}} />
|
||||
<RingInput {activeLayer} keys={{d: 55, w: 56, n: 57, e: 58, s: 59}} />
|
||||
</div>
|
||||
<div class="row" style="gap: 160px">
|
||||
<RingInput {activeLayer} keys={{d: 5, e: 6, n: 7, w: 8, s: 9}} />
|
||||
<RingInput {activeLayer} keys={{d: 50, w: 51, n: 52, e: 53, s: 54}} />
|
||||
</div>
|
||||
<div class="row" style="gap: 320px; margin-top: -12px">
|
||||
<RingInput {activeLayer} keys={{d: 0, e: 1, n: 2, w: 3, s: 4}} />
|
||||
<RingInput {activeLayer} keys={{d: 45, w: 46, n: 47, e: 48, s: 49}} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.row,
|
||||
.col {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.row {
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.col {
|
||||
flex-direction: column;
|
||||
}
|
||||
</style>
|
||||
@@ -1,184 +0,0 @@
|
||||
<script lang="ts">
|
||||
import {changes, highlightActions, layout} from "$lib/serial/connection"
|
||||
import type {Change} from "$lib/serial/connection"
|
||||
import type {CharaLayout} from "$lib/serialization/layout"
|
||||
import {KEYMAP_CODES} from "$lib/serial/keymap-codes"
|
||||
import type {KeyInfo} from "$lib/serial/keymap-codes"
|
||||
import {editableLayout} from "$lib/editable-layout"
|
||||
|
||||
export let activeLayer = 0
|
||||
export let keys: Record<"d" | "s" | "n" | "w" | "e", number>
|
||||
|
||||
const virtualLayerMap = [1, 0, 2]
|
||||
const characterOffset = 8
|
||||
|
||||
function offsetDistance(quadrant: number, layer: number, activeLayer: number): number {
|
||||
const layerOffsetIndex = virtualLayerMap[layer] - virtualLayerMap[activeLayer]
|
||||
const layerOffset = quadrant > 2 ? -characterOffset : characterOffset
|
||||
return 25 * quadrant + layerOffsetIndex * layerOffset
|
||||
}
|
||||
|
||||
function getActions(id: number, layout: CharaLayout, changes: Change[]): [KeyInfo, KeyInfo | undefined][] {
|
||||
return Array.from({length: 3}).map((_, i) => {
|
||||
const actionId = layout?.[i][id]
|
||||
const changedId = changes.findLast(it => it?.layout?.[i]?.[id] !== undefined)?.layout![i]![id]
|
||||
if (changedId !== undefined) {
|
||||
return [KEYMAP_CODES[changedId], KEYMAP_CODES[actionId]]
|
||||
} else {
|
||||
return [KEYMAP_CODES[actionId], undefined]
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="radial">
|
||||
{#each [keys.n, keys.e, keys.s, keys.w, keys.d] as id, quadrant}
|
||||
{@const actions = getActions(id, $layout, $changes)}
|
||||
<button
|
||||
use:editableLayout={{activeLayer, id}}
|
||||
class:active={actions.some(([it]) => it && $highlightActions?.includes(it.code))}
|
||||
>
|
||||
{#each actions as [keyInfo, old], layer}
|
||||
{#if keyInfo}
|
||||
<span
|
||||
class:active={virtualLayerMap[activeLayer] === virtualLayerMap[layer]}
|
||||
class:icon={!!keyInfo.icon}
|
||||
class:changed={!!old}
|
||||
style="offset-distance: {offsetDistance(quadrant, layer, activeLayer)}%"
|
||||
>{keyInfo.icon || keyInfo.id || keyInfo.code}</span
|
||||
>
|
||||
{/if}
|
||||
{/each}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
@use "sass:math";
|
||||
|
||||
$border-width: 18px;
|
||||
$gap: 6px;
|
||||
$size: 96;
|
||||
$offset: 14;
|
||||
$scale-difference: 0.2;
|
||||
$transition-time: 750ms;
|
||||
|
||||
.radial {
|
||||
position: relative;
|
||||
|
||||
container: radial / size;
|
||||
|
||||
width: #{$size * 1px};
|
||||
height: #{$size * 1px};
|
||||
|
||||
transition: all 250ms ease;
|
||||
}
|
||||
|
||||
span {
|
||||
$cr: math.div($size, 2) - 2 * $offset;
|
||||
|
||||
will-change: scale, offset-distance;
|
||||
user-select: none;
|
||||
|
||||
scale: 0.9;
|
||||
offset-path: path(
|
||||
"M#{math.div($size, 2)} #{$offset}A#{$cr} #{$cr} 0 1 1 #{math.div($size, 2)} #{$size - $offset}A#{$cr} #{$cr} 0 1 1 #{math.div($size, 2)} #{$offset}Z"
|
||||
);
|
||||
offset-rotate: 0deg;
|
||||
|
||||
display: flex;
|
||||
grid-column: 1;
|
||||
grid-row: 1;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
font-size: 16px;
|
||||
|
||||
opacity: 0.2;
|
||||
|
||||
transition:
|
||||
scale $transition-time ease,
|
||||
opacity $transition-time ease,
|
||||
offset-distance $transition-time ease;
|
||||
|
||||
&.active {
|
||||
scale: 1;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
&.icon {
|
||||
font-size: 20px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
&.changed {
|
||||
color: var(--md-sys-color-on-secondary-container);
|
||||
background: var(--md-sys-color-secondary-container);
|
||||
}
|
||||
}
|
||||
|
||||
button {
|
||||
cursor: pointer;
|
||||
|
||||
position: absolute;
|
||||
|
||||
display: grid;
|
||||
|
||||
width: 100cqw;
|
||||
height: 100cqh;
|
||||
padding: 0;
|
||||
|
||||
font-family: "Noto Sans Mono", monospace;
|
||||
font-size: 16px;
|
||||
font-weight: 900;
|
||||
color: var(--md-sys-color-on-surface-variant);
|
||||
|
||||
background: var(--md-sys-color-surface-variant);
|
||||
border: none;
|
||||
|
||||
transition: all 250ms ease;
|
||||
|
||||
mask-image: url("$lib/assets/quater-ring.svg");
|
||||
mask-size: 100% 100%;
|
||||
|
||||
&.active,
|
||||
&:active {
|
||||
color: var(--md-sys-color-on-tertiary);
|
||||
background: var(--md-sys-color-tertiary);
|
||||
}
|
||||
|
||||
&:nth-child(1) {
|
||||
clip-path: polygon(50% 50%, 0 0, 100% 0);
|
||||
}
|
||||
|
||||
&:nth-child(2) {
|
||||
clip-path: polygon(50% 50%, 100% 0, 100% 100%);
|
||||
}
|
||||
|
||||
&:nth-child(3) {
|
||||
clip-path: polygon(50% 50%, 0 100%, 100% 100%);
|
||||
}
|
||||
|
||||
&:nth-child(4) {
|
||||
clip-path: polygon(50% 50%, 0 0, 0 100%);
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
translate: -50% -50%;
|
||||
|
||||
overflow: hidden;
|
||||
|
||||
width: 25cqw;
|
||||
height: 25cqh;
|
||||
|
||||
border-radius: 50%;
|
||||
|
||||
mask-image: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
9
src/lib/components/layout/visual-layout.ts
Normal file
9
src/lib/components/layout/visual-layout.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export interface VisualLayoutConfig {
|
||||
scale: number
|
||||
inactiveScale: number
|
||||
inactiveOpacity: number
|
||||
strokeWidth: number
|
||||
margin: number
|
||||
fontSize: number
|
||||
iconFontSize: number
|
||||
}
|
||||
35
src/lib/dialogs/ConfirmDialog.svelte
Normal file
35
src/lib/dialogs/ConfirmDialog.svelte
Normal file
@@ -0,0 +1,35 @@
|
||||
<script lang="ts">
|
||||
import {createEventDispatcher} from "svelte"
|
||||
import Dialog from "$lib/dialogs/Dialog.svelte"
|
||||
|
||||
export let title: string
|
||||
export let message: string | undefined
|
||||
export let abortTitle: string
|
||||
export let confirmTitle: string
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
</script>
|
||||
|
||||
<Dialog>
|
||||
<h1>{@html title}</h1>
|
||||
{#if message}
|
||||
<p>{@html message}</p>
|
||||
{/if}
|
||||
<div class="buttons">
|
||||
<button on:click={() => dispatch("abort")}>{abortTitle}</button>
|
||||
<button class="primary" on:click={() => dispatch("confirm")}>{confirmTitle}</button>
|
||||
</div>
|
||||
</Dialog>
|
||||
|
||||
<style lang="scss">
|
||||
h1 {
|
||||
font-size: 2em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
32
src/lib/dialogs/Dialog.svelte
Normal file
32
src/lib/dialogs/Dialog.svelte
Normal file
@@ -0,0 +1,32 @@
|
||||
<script lang="ts">
|
||||
import {onMount} from "svelte"
|
||||
|
||||
onMount(() => {
|
||||
modal.showModal()
|
||||
})
|
||||
|
||||
let modal: HTMLDialogElement
|
||||
</script>
|
||||
|
||||
<dialog bind:this={modal}>
|
||||
<slot />
|
||||
</dialog>
|
||||
|
||||
<style lang="scss">
|
||||
dialog {
|
||||
min-width: 300px;
|
||||
max-width: 512px;
|
||||
|
||||
color: var(--md-sys-color-on-background);
|
||||
|
||||
background: var(--md-sys-color-background);
|
||||
border: none;
|
||||
border-radius: 38px;
|
||||
box-shadow: 0 0 48px rgba(0 0 0 / 60%);
|
||||
}
|
||||
|
||||
dialog::backdrop {
|
||||
opacity: 0.5;
|
||||
background: black;
|
||||
}
|
||||
</style>
|
||||
161
src/lib/dialogs/PickChangesDialog.svelte
Normal file
161
src/lib/dialogs/PickChangesDialog.svelte
Normal file
@@ -0,0 +1,161 @@
|
||||
<script lang="ts">
|
||||
import Dialog from "$lib/dialogs/Dialog.svelte"
|
||||
import type {Change, ChordChange, LayoutChange, SettingChange} from "$lib/undo-redo"
|
||||
import {ChangeType, chords} from "$lib/undo-redo"
|
||||
import ActionString from "$lib/components/ActionString.svelte"
|
||||
import LL from "../../i18n/i18n-svelte"
|
||||
import {KEYMAP_IDS} from "$lib/serial/keymap-codes"
|
||||
|
||||
export let changes: Change[] = [
|
||||
{type: ChangeType.Layout, layer: 0, id: 1, action: 1},
|
||||
{type: ChangeType.Layout, layer: 1, id: 1, action: 1},
|
||||
{type: ChangeType.Layout, layer: 1, id: 1, action: 1},
|
||||
{type: ChangeType.Layout, layer: 1, id: 1, action: 1},
|
||||
{type: ChangeType.Layout, layer: 1, id: 1, action: 1},
|
||||
{type: ChangeType.Layout, layer: 1, id: 1, action: 1},
|
||||
{type: ChangeType.Layout, layer: 1, id: 1, action: 1},
|
||||
{type: ChangeType.Layout, layer: 1, id: 1, action: 1},
|
||||
{type: ChangeType.Layout, layer: 1, id: 1, action: 1},
|
||||
{type: ChangeType.Layout, layer: 1, id: 1, action: 1},
|
||||
{type: ChangeType.Setting, id: 0, setting: 2},
|
||||
{type: ChangeType.Setting, id: 0, setting: 2},
|
||||
{type: ChangeType.Setting, id: 0, setting: 2},
|
||||
{type: ChangeType.Setting, id: 0, setting: 2},
|
||||
{type: ChangeType.Chord, id: [1], actions: [55], phrase: [55, 63, 37, 36]},
|
||||
{
|
||||
type: ChangeType.Chord,
|
||||
id: [KEYMAP_IDS.get("y")!.code, KEYMAP_IDS.get("r")!.code, KEYMAP_IDS.get("t")!.code],
|
||||
actions: [KEYMAP_IDS.get("y")!.code, KEYMAP_IDS.get("r")!.code, KEYMAP_IDS.get("t")!.code],
|
||||
phrase: [55, 63, 37, 36],
|
||||
},
|
||||
{
|
||||
type: ChangeType.Chord,
|
||||
id: [KEYMAP_IDS.get("y")!.code, KEYMAP_IDS.get("r")!.code, KEYMAP_IDS.get("t")!.code],
|
||||
actions: [KEYMAP_IDS.get("y")!.code, KEYMAP_IDS.get("r")!.code, KEYMAP_IDS.get("t")!.code],
|
||||
phrase: [],
|
||||
},
|
||||
]
|
||||
|
||||
$: existingChords = new Set($chords.map(it => JSON.stringify(it.id)))
|
||||
|
||||
$: layoutChanges = Array.from(
|
||||
{length: 3},
|
||||
(_, i) => changes.filter(it => it.type === ChangeType.Layout && it.layer === i) as LayoutChange[],
|
||||
)
|
||||
$: settingChanges = changes.filter(it => it.type === ChangeType.Setting) as SettingChange[]
|
||||
$: chordChanges = {
|
||||
added: changes.filter(
|
||||
it =>
|
||||
it.type === ChangeType.Chord && it.phrase.length > 0 && !existingChords.has(JSON.stringify(it.id)),
|
||||
) as ChordChange[],
|
||||
changed: changes.filter(
|
||||
it => it.type === ChangeType.Chord && it.phrase.length > 0 && existingChords.has(JSON.stringify(it.id)),
|
||||
) as ChordChange[],
|
||||
deleted: changes.filter(it => it.type === ChangeType.Chord && it.phrase.length === 0) as ChordChange[],
|
||||
}
|
||||
$: totalChordChanges = Object.values(chordChanges).reduce((acc, curr) => acc + curr.length, 0)
|
||||
</script>
|
||||
|
||||
<Dialog>
|
||||
<h1>{$LL.changes.TITLE()}</h1>
|
||||
<h2>
|
||||
<label><input type="checkbox" class="checkbox" />{$LL.changes.ALL_CHANGES()}</label>
|
||||
</h2>
|
||||
<ul>
|
||||
{#if layoutChanges.some(it => it.length > 0)}
|
||||
<li>
|
||||
<h3>
|
||||
<label>
|
||||
<input type="checkbox" class="checkbox" />
|
||||
{$LL.changes.layout.TITLE(layoutChanges.reduce((acc, curr) => acc + curr.length, 0))}
|
||||
</label>
|
||||
</h3>
|
||||
<ul>
|
||||
{#each layoutChanges
|
||||
.map((it, i) => /** @type {const} */ ([it, i + 1]))
|
||||
.filter(([it]) => it.length > 0) as [changes, layer]}
|
||||
<li>
|
||||
<h4>
|
||||
<label>
|
||||
<input type="checkbox" class="checkbox" />
|
||||
{$LL.changes.layout.LAYER({changes: changes.length, layer})}
|
||||
</label>
|
||||
</h4>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</li>
|
||||
{/if}
|
||||
{#if settingChanges.length > 0}
|
||||
<li>
|
||||
<h3>
|
||||
<label
|
||||
><input type="checkbox" class="checkbox" />{$LL.changes.settings.TITLE(
|
||||
settingChanges.length,
|
||||
)}</label
|
||||
>
|
||||
</h3>
|
||||
</li>
|
||||
{/if}
|
||||
{#if totalChordChanges > 0}
|
||||
<li>
|
||||
<h3>
|
||||
<label
|
||||
><input type="checkbox" class="checkbox" />{$LL.changes.chords.TITLE(totalChordChanges)}</label
|
||||
>
|
||||
</h3>
|
||||
<ul>
|
||||
{#each Object.entries(chordChanges) as [category, changes]}
|
||||
{#if changes.length > 0}
|
||||
<li>
|
||||
<h4>
|
||||
<label
|
||||
><input type="checkbox" class="checkbox" />
|
||||
{#if category === "added"}
|
||||
{$LL.changes.chords.NEW_CHORDS(changes.length)}
|
||||
{:else if category === "changed"}
|
||||
{$LL.changes.chords.CHANGED_CHORDS(changes.length)}
|
||||
{:else if category === "deleted"}
|
||||
{$LL.changes.chords.DELETED_CHORDS(changes.length)}
|
||||
{/if}
|
||||
</label>
|
||||
</h4>
|
||||
<ul>
|
||||
{#each changes as change}
|
||||
<li>
|
||||
<label>
|
||||
<input type="checkbox" class="checkbox" />
|
||||
<ActionString display="keys" actions={change.actions} />
|
||||
<ActionString actions={change.phrase} />
|
||||
</label>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</li>
|
||||
{/if}
|
||||
{/each}
|
||||
</ul>
|
||||
</li>
|
||||
{/if}
|
||||
</ul>
|
||||
</Dialog>
|
||||
|
||||
<style lang="scss">
|
||||
h1 {
|
||||
font-size: 2em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
ul {
|
||||
padding-inline-start: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
li {
|
||||
margin-inline-start: 24px;
|
||||
}
|
||||
</style>
|
||||
31
src/lib/dialogs/confirm-dialog.ts
Normal file
31
src/lib/dialogs/confirm-dialog.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import ConfirmDialog from "$lib/dialogs/ConfirmDialog.svelte"
|
||||
|
||||
export async function askForConfirmation(
|
||||
title: string,
|
||||
message: string,
|
||||
confirmTitle: string,
|
||||
abortTitle: string,
|
||||
): Promise<boolean> {
|
||||
const dialog = new ConfirmDialog({
|
||||
target: document.body,
|
||||
props: {
|
||||
title,
|
||||
message,
|
||||
confirmTitle,
|
||||
abortTitle,
|
||||
},
|
||||
})
|
||||
|
||||
let resolvePromise: (value: boolean) => void
|
||||
const resultPromise = new Promise<boolean>(resolve => {
|
||||
resolvePromise = resolve
|
||||
})
|
||||
|
||||
dialog.$on("abort", () => resolvePromise(false))
|
||||
dialog.$on("confirm", () => resolvePromise(true))
|
||||
|
||||
const result = await resultPromise
|
||||
dialog.$destroy()
|
||||
|
||||
return result
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
import type {Action} from "svelte/action"
|
||||
import ActionSelector from "$lib/components/layout/ActionSelector.svelte"
|
||||
import {changes, layout} from "$lib/serial/connection"
|
||||
import {get} from "svelte/store"
|
||||
|
||||
export const editableLayout: Action<HTMLButtonElement, {activeLayer: number; id: number}> = (
|
||||
node,
|
||||
{id, activeLayer},
|
||||
) => {
|
||||
let component: ActionSelector | undefined
|
||||
function present() {
|
||||
component?.$destroy()
|
||||
component = new ActionSelector({
|
||||
target: document.body,
|
||||
props: {currentAction: get(layout)[activeLayer][id]},
|
||||
})
|
||||
component.$on("close", () => {
|
||||
component!.$destroy()
|
||||
})
|
||||
component.$on("select", ({detail}) => {
|
||||
changes.update(changes => {
|
||||
changes.push({layout: {[activeLayer]: {[id]: detail}}})
|
||||
return changes
|
||||
})
|
||||
component!.$destroy()
|
||||
})
|
||||
}
|
||||
|
||||
node.addEventListener("click", present)
|
||||
return {
|
||||
destroy() {
|
||||
node.removeEventListener("click", present)
|
||||
},
|
||||
}
|
||||
}
|
||||
39
src/lib/os-layout.ts
Normal file
39
src/lib/os-layout.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import {persistentWritable} from "$lib/storage"
|
||||
import {get} from "svelte/store"
|
||||
|
||||
export const osLayout = persistentWritable<Record<string, string>>("os-layout", {})
|
||||
|
||||
const keysCurrentlyDown = new Set<string>()
|
||||
|
||||
function keydown({code, key}: KeyboardEvent) {
|
||||
const keys = [...keysCurrentlyDown]
|
||||
keysCurrentlyDown.add(code)
|
||||
|
||||
const keyString = JSON.stringify([...keys.sort(), code])
|
||||
if (keyString in get(osLayout) || get(osLayout)[JSON.stringify([code])] === key) return
|
||||
|
||||
osLayout.update(layout => {
|
||||
layout[keyString] = key
|
||||
return layout
|
||||
})
|
||||
}
|
||||
|
||||
function keyup({code}: KeyboardEvent) {
|
||||
keysCurrentlyDown.delete(code)
|
||||
}
|
||||
|
||||
export function runLayoutDetection() {
|
||||
if ("keyboard" in navigator) {
|
||||
;(navigator.keyboard as any).getLayoutMap().then((layout: Map<string, string>) => {
|
||||
osLayout.update(osLayout => {
|
||||
Object.assign(
|
||||
osLayout,
|
||||
Object.fromEntries([...layout.entries()].map(([key, value]) => [JSON.stringify([key]), value])),
|
||||
)
|
||||
return osLayout
|
||||
})
|
||||
})
|
||||
}
|
||||
window.addEventListener("keydown", keydown)
|
||||
window.addEventListener("keyup", keyup)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import type {Action} from "svelte/action"
|
||||
import {persistentWritable} from "$lib/storage"
|
||||
import type { Action } from "svelte/action"
|
||||
import { persistentWritable } from "$lib/storage"
|
||||
|
||||
export interface UserPreferences {
|
||||
backup: boolean
|
||||
@@ -13,7 +13,7 @@ export const theme = persistentWritable("user-theme", {
|
||||
|
||||
export const userPreferences = persistentWritable<UserPreferences>("user-preferences", {
|
||||
backup: false,
|
||||
autoConnect: true,
|
||||
autoConnect: false,
|
||||
})
|
||||
|
||||
export const preference: Action<HTMLInputElement, keyof UserPreferences> = (node, key) => {
|
||||
|
||||
@@ -5,6 +5,7 @@ import type {Writable} from "svelte/store"
|
||||
import type {CharaLayout} from "$lib/serialization/layout"
|
||||
import {persistentWritable} from "$lib/storage"
|
||||
import {userPreferences} from "$lib/preferences"
|
||||
import settingInfo from "$lib/assets/settings.yml"
|
||||
|
||||
export const serialPort = writable<CharaDevice | undefined>()
|
||||
|
||||
@@ -15,49 +16,80 @@ export interface SerialLogEntry {
|
||||
|
||||
export const serialLog = writable<SerialLogEntry[]>([])
|
||||
|
||||
export const chords = persistentWritable<Chord[]>("chord-library", [], () => get(userPreferences).backup)
|
||||
/**
|
||||
* Chords as read from the device
|
||||
*/
|
||||
export const deviceChords = persistentWritable<Chord[]>(
|
||||
"chord-library",
|
||||
[],
|
||||
() => get(userPreferences).backup,
|
||||
)
|
||||
|
||||
export const layout = persistentWritable<CharaLayout>(
|
||||
/**
|
||||
* Layout as read from the device
|
||||
*/
|
||||
export const deviceLayout = persistentWritable<CharaLayout>(
|
||||
"layout",
|
||||
[[], [], []],
|
||||
() => get(userPreferences).backup,
|
||||
)
|
||||
|
||||
export interface Change {
|
||||
layout?: Record<number, Record<number, number>>
|
||||
chords?: never
|
||||
settings?: Record<number, number>
|
||||
}
|
||||
|
||||
export const changes = persistentWritable<Change[]>("changes", [])
|
||||
|
||||
export const settings = writable({})
|
||||
|
||||
export const unsavedChanges = writable(new Map<number, number>())
|
||||
|
||||
export const highlightActions: Writable<number[]> = writable([])
|
||||
/**
|
||||
* Settings as read from the device
|
||||
*/
|
||||
export const deviceSettings = persistentWritable<number[]>(
|
||||
"device-settings",
|
||||
[],
|
||||
() => get(userPreferences).backup,
|
||||
)
|
||||
|
||||
export const syncStatus: Writable<"done" | "error" | "downloading" | "uploading"> = writable("done")
|
||||
|
||||
export interface ProgressInfo {
|
||||
max: number
|
||||
current: number
|
||||
}
|
||||
export const syncProgress = writable<ProgressInfo | undefined>(undefined)
|
||||
|
||||
export async function initSerial(manual = false) {
|
||||
const device = get(serialPort) ?? new CharaDevice()
|
||||
await device.init(manual)
|
||||
serialPort.set(device)
|
||||
|
||||
const chordCount = await device.getChordCount()
|
||||
syncStatus.set("downloading")
|
||||
|
||||
const max = Object.keys(settingInfo.settings).length + device.keyCount * 3 + chordCount
|
||||
let current = 0
|
||||
syncProgress.set({max, current})
|
||||
function progressTick() {
|
||||
current++
|
||||
syncProgress.set({max, current})
|
||||
}
|
||||
|
||||
const parsedSettings: number[] = []
|
||||
for (const key in settingInfo.settings) {
|
||||
try {
|
||||
parsedSettings[Number.parseInt(key)] = await device.getSetting(Number.parseInt(key))
|
||||
} catch {}
|
||||
progressTick()
|
||||
}
|
||||
deviceSettings.set(parsedSettings)
|
||||
|
||||
const parsedLayout: CharaLayout = [[], [], []]
|
||||
for (let layer = 1; layer <= 3; layer++) {
|
||||
for (let i = 0; i < 90; i++) {
|
||||
for (let i = 0; i < device.keyCount; i++) {
|
||||
parsedLayout[layer - 1][i] = await device.getLayoutKey(layer, i)
|
||||
progressTick()
|
||||
}
|
||||
}
|
||||
layout.set(parsedLayout)
|
||||
deviceLayout.set(parsedLayout)
|
||||
|
||||
const chordCount = await device.getChordCount()
|
||||
const chordInfo = []
|
||||
for (let i = 0; i < chordCount; i++) {
|
||||
chordInfo.push(await device.getChord(i))
|
||||
progressTick()
|
||||
}
|
||||
chords.set(chordInfo)
|
||||
deviceChords.set(chordInfo)
|
||||
syncStatus.set("done")
|
||||
syncProgress.set(undefined)
|
||||
}
|
||||
|
||||
@@ -1,17 +1,33 @@
|
||||
import {LineBreakTransformer} from "$lib/serial/line-break-transformer"
|
||||
import {serialLog} from "$lib/serial/connection"
|
||||
import type {Chord} from "$lib/serial/chord"
|
||||
import {SemVer} from "$lib/serial/sem-ver"
|
||||
import {parseChordActions, parsePhrase, stringifyChordActions, stringifyPhrase} from "$lib/serial/chord"
|
||||
import {browser} from "$app/environment"
|
||||
|
||||
export const VENDOR_ID = 0x239a
|
||||
const PORT_FILTERS: Map<string, SerialPortFilter> = new Map([
|
||||
["ONE M0", {usbProductId: 32783, usbVendorId: 9114}],
|
||||
["LITE S2", {usbProductId: 33070, usbVendorId: 12346}],
|
||||
["LITE M0", {usbProductId: 32796, usbVendorId: 9114}],
|
||||
["X", {usbProductId: 33163, usbVendorId: 12346}],
|
||||
])
|
||||
|
||||
if (browser && navigator.serial === undefined && import.meta.env.TAURI_FAMILY !== undefined) {
|
||||
await import("./tauri-serial")
|
||||
}
|
||||
|
||||
export async function getViablePorts(): Promise<SerialPort[]> {
|
||||
return navigator.serial.getPorts().then(ports => ports.filter(it => it.getInfo().usbVendorId === VENDOR_ID))
|
||||
return navigator.serial.getPorts().then(ports =>
|
||||
ports.filter(it => {
|
||||
const {usbProductId, usbVendorId} = it.getInfo()
|
||||
for (const filter of PORT_FILTERS.values()) {
|
||||
if (filter.usbProductId === usbProductId && filter.usbVendorId === usbVendorId) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
export async function canAutoConnect() {
|
||||
@@ -29,31 +45,59 @@ export class CharaDevice {
|
||||
|
||||
private lock?: Promise<true>
|
||||
|
||||
version!: [number, number, number]
|
||||
version!: SemVer
|
||||
company!: "CHARACHORDER"
|
||||
device!: "ONE" | "LITE"
|
||||
chipset!: "M0" | "S2"
|
||||
keyCount!: 90 | 67
|
||||
|
||||
constructor(private readonly baudRate = 115200) {}
|
||||
|
||||
async init(manual = false) {
|
||||
const ports = await getViablePorts()
|
||||
this.port =
|
||||
!manual && ports.length === 1
|
||||
? ports[0]
|
||||
: await navigator.serial.requestPort({filters: [{usbVendorId: VENDOR_ID}]})
|
||||
await this.port.open({baudRate: this.baudRate})
|
||||
const info = this.port.getInfo()
|
||||
serialLog.update(it => {
|
||||
it.push({
|
||||
type: "system",
|
||||
value: `Connected; ID: 0x${info.usbProductId?.toString(16)}; Vendor: 0x${info.usbVendorId?.toString(
|
||||
16,
|
||||
)}`,
|
||||
})
|
||||
return it
|
||||
})
|
||||
try {
|
||||
const ports = await getViablePorts()
|
||||
this.port =
|
||||
!manual && ports.length === 1
|
||||
? ports[0]
|
||||
: await navigator.serial.requestPort({filters: [...PORT_FILTERS.values()]})
|
||||
|
||||
await this.port.open({baudRate: this.baudRate})
|
||||
const info = this.port.getInfo()
|
||||
serialLog.update(it => {
|
||||
it.push({
|
||||
type: "system",
|
||||
value: `Connected; ID: 0x${info.usbProductId?.toString(16)}; Vendor: 0x${info.usbVendorId?.toString(
|
||||
16,
|
||||
)}`,
|
||||
})
|
||||
return it
|
||||
})
|
||||
await this.port.close()
|
||||
|
||||
this.version = new SemVer(await this.send("VERSION").then(([version]) => version))
|
||||
const [company, device, chipset] = await this.send("ID")
|
||||
this.company = company as "CHARACHORDER"
|
||||
this.device = device as "ONE" | "LITE"
|
||||
this.chipset = chipset as "M0" | "S2"
|
||||
this.keyCount = this.device === "ONE" ? 90 : 67
|
||||
} catch (e) {
|
||||
alert(e)
|
||||
console.error(e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
private async suspend() {
|
||||
await this.reader.cancel()
|
||||
await this.streamClosed.catch(() => {
|
||||
/** noop */
|
||||
})
|
||||
this.reader.releaseLock()
|
||||
await this.port.close()
|
||||
}
|
||||
|
||||
private async wake() {
|
||||
await this.port.open({baudRate: this.baudRate})
|
||||
const decoderStream = new TextDecoderStream()
|
||||
this.streamClosed = this.port.readable!.pipeTo(decoderStream.writable, {
|
||||
signal: this.abortController1.signal,
|
||||
@@ -64,13 +108,6 @@ export class CharaDevice {
|
||||
signal: this.abortController2.signal,
|
||||
})
|
||||
.getReader()
|
||||
|
||||
const [version] = await this.send("VERSION")
|
||||
this.version = version.split(".").map(Number) as [number, number, number]
|
||||
const [company, device, chipset] = await this.send("ID")
|
||||
this.company = company as "CHARACHORDER"
|
||||
this.device = device as "ONE" | "LITE"
|
||||
this.chipset = chipset as "M0" | "S2"
|
||||
}
|
||||
|
||||
private async internalRead() {
|
||||
@@ -105,19 +142,9 @@ export class CharaDevice {
|
||||
}
|
||||
|
||||
async forget() {
|
||||
await this.disconnect()
|
||||
await this.port.forget()
|
||||
}
|
||||
|
||||
async disconnect() {
|
||||
await this.reader.cancel()
|
||||
await this.streamClosed.catch(() => {
|
||||
/** noop */
|
||||
})
|
||||
this.reader.releaseLock()
|
||||
await this.port.close()
|
||||
}
|
||||
|
||||
/**
|
||||
* Read/write to serial port
|
||||
*/
|
||||
@@ -132,8 +159,10 @@ export class CharaDevice {
|
||||
const exec = new Promise<T>(async resolve => {
|
||||
let result!: T
|
||||
try {
|
||||
await this.wake()
|
||||
result = await callback(send, read)
|
||||
} finally {
|
||||
await this.suspend()
|
||||
this.lock = undefined
|
||||
resolve(result)
|
||||
}
|
||||
@@ -174,7 +203,7 @@ export class CharaDevice {
|
||||
*/
|
||||
async getChordPhrase(actions: number[]): Promise<number[] | undefined> {
|
||||
const [phrase] = await this.send(`CML C2 ${stringifyChordActions(actions)}`)
|
||||
return phrase === "0" ? undefined : parsePhrase(phrase)
|
||||
return phrase === "2" ? undefined : parsePhrase(phrase)
|
||||
}
|
||||
|
||||
async setChord(chord: Chord) {
|
||||
@@ -184,12 +213,13 @@ export class CharaDevice {
|
||||
stringifyChordActions(chord.actions),
|
||||
stringifyPhrase(chord.phrase),
|
||||
)
|
||||
if (status !== "0") throw new Error(`Failed with status ${status}`)
|
||||
if (status !== "0") console.error(`Failed with status ${status}`)
|
||||
}
|
||||
|
||||
async deleteChord(chord: Chord) {
|
||||
async deleteChord(chord: Pick<Chord, "actions">) {
|
||||
const status = await this.send(`CML C4 ${stringifyChordActions(chord.actions)}`)
|
||||
if (status.at(-1) !== "0") throw new Error(`Failed with status ${status}`)
|
||||
console.log(status)
|
||||
if (status.at(-1) !== "2") throw new Error(`Failed with status ${status}`)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,7 +229,8 @@ export class CharaDevice {
|
||||
* @param action the assigned action id
|
||||
*/
|
||||
async setLayoutKey(layer: number, id: number, action: number) {
|
||||
const [status] = await this.send(`VAR B3 A${layer} ${id} ${action}`)
|
||||
const [status] = await this.send(`VAR B4 A${layer} ${id} ${action}`)
|
||||
console.log(status)
|
||||
if (status !== "0") throw new Error(`Failed with status ${status}`)
|
||||
}
|
||||
|
||||
@@ -252,7 +283,6 @@ export class CharaDevice {
|
||||
*/
|
||||
async reboot() {
|
||||
await this.send("RST")
|
||||
await this.disconnect()
|
||||
// TODO: reconnect
|
||||
}
|
||||
|
||||
@@ -261,7 +291,6 @@ export class CharaDevice {
|
||||
*/
|
||||
async bootloader() {
|
||||
await this.send("RST BOOTLOADER")
|
||||
await this.disconnect()
|
||||
// TODO: more...
|
||||
}
|
||||
|
||||
|
||||
@@ -5,17 +5,29 @@ export interface KeyInfo extends Partial<ActionInfo> {
|
||||
category: KeymapCategory
|
||||
}
|
||||
|
||||
const keymaps = (await Promise.all(
|
||||
export const KEYMAP_CATEGORIES = (await Promise.all(
|
||||
Object.values(import.meta.glob("$lib/assets/keymaps/*.yml")).map(async load =>
|
||||
load().then(it => (it as any).default),
|
||||
),
|
||||
)) as KeymapCategory[]
|
||||
|
||||
export const KEYMAP_CODES: Record<number, KeyInfo> = Object.fromEntries(
|
||||
keymaps.flatMap(category =>
|
||||
KEYMAP_CATEGORIES.flatMap(category =>
|
||||
Object.entries(category.actions).map(([code, action]) => [
|
||||
Number(code),
|
||||
{...action, code: Number(code), category},
|
||||
]),
|
||||
),
|
||||
)
|
||||
|
||||
export const KEYMAP_IDS: Map<string, KeyInfo> = new Map(
|
||||
KEYMAP_CATEGORIES.flatMap(category =>
|
||||
Object.entries(category.actions).map(
|
||||
([code, action]) => [action.id!, {...action, code: Number(code), category}] as const,
|
||||
),
|
||||
).filter(([id]) => id !== undefined),
|
||||
)
|
||||
|
||||
export const specialKeycodes = new Map([
|
||||
[" ", 32], // Space
|
||||
])
|
||||
|
||||
27
src/lib/serial/sem-ver.ts
Normal file
27
src/lib/serial/sem-ver.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
export class SemVer {
|
||||
major: number
|
||||
minor: number
|
||||
patch: number
|
||||
preRelease?: string
|
||||
meta?: string
|
||||
|
||||
constructor(versionString: string) {
|
||||
const [, major, minor, patch, preRelease, meta] =
|
||||
/^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+))?$/.exec(
|
||||
versionString,
|
||||
)!
|
||||
this.major = Number.parseInt(major)
|
||||
this.minor = Number.parseInt(minor)
|
||||
this.patch = Number.parseInt(patch)
|
||||
if (preRelease) this.preRelease = preRelease
|
||||
if (meta) this.meta = meta
|
||||
}
|
||||
|
||||
toString() {
|
||||
return (
|
||||
`${this.major}.${this.minor}.${this.patch}` +
|
||||
(this.preRelease ? `-${this.preRelease}` : "") +
|
||||
(this.meta ? `+${this.meta}` : "")
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ export function decompressActions(raw: Uint8Array): number[] {
|
||||
const actions: number[] = []
|
||||
for (let i = 0; i < raw.length; i++) {
|
||||
let action = raw[i]
|
||||
if (action < 32) {
|
||||
if (action > 0 && action < 32) {
|
||||
action = (action << 8) | raw[++i]
|
||||
}
|
||||
actions.push(action)
|
||||
|
||||
@@ -20,7 +20,7 @@ export async function toBase64(blob: Blob): Promise<string> {
|
||||
})
|
||||
}
|
||||
|
||||
export async function fromBase64(base64: string): Promise<Blob> {
|
||||
export async function fromBase64(base64: string, fetch = window.fetch): Promise<Blob> {
|
||||
return fetch(
|
||||
`data:application/octet-stream;base64,${base64
|
||||
.replaceAll(".", "+")
|
||||
|
||||
106
src/lib/serialization/visual-layout.ts
Normal file
106
src/lib/serialization/visual-layout.ts
Normal file
@@ -0,0 +1,106 @@
|
||||
export interface VisualLayout {
|
||||
name: string
|
||||
col: VisualLayoutRow[]
|
||||
}
|
||||
|
||||
interface Positionable {
|
||||
offset: [number, number]
|
||||
rotate: number
|
||||
}
|
||||
|
||||
export interface VisualLayoutRow extends Positionable {
|
||||
row: Array<VisualLayoutKey | VisualLayoutSwitch>
|
||||
}
|
||||
|
||||
export interface VisualLayoutKey extends Positionable {
|
||||
key: number
|
||||
size?: [number, number]
|
||||
}
|
||||
|
||||
export interface VisualLayoutSwitch extends Positionable {
|
||||
switch: {
|
||||
n: number
|
||||
e: number
|
||||
w: number
|
||||
s: number
|
||||
d: number
|
||||
}
|
||||
}
|
||||
|
||||
export interface CompiledLayout {
|
||||
name: string
|
||||
size: [number, number]
|
||||
keys: CompiledLayoutKey[]
|
||||
}
|
||||
|
||||
export interface CompiledLayoutKey {
|
||||
id: number
|
||||
shape: "quarter-circle" | "square"
|
||||
cornerRadius: number
|
||||
size: [number, number]
|
||||
pos: [number, number]
|
||||
rotate: number
|
||||
}
|
||||
|
||||
export function compileLayout(layout: VisualLayout): CompiledLayout {
|
||||
const compiled: CompiledLayout = {
|
||||
name: layout.name,
|
||||
size: [0, 0],
|
||||
keys: [],
|
||||
}
|
||||
|
||||
let y = 0
|
||||
for (const {row, offset} of layout.col) {
|
||||
let x = offset?.[0] ?? 0
|
||||
y += offset?.[1] ?? 0
|
||||
let maxHeight = 0
|
||||
for (const info of row) {
|
||||
const [ox, oy] = info.offset || [0, 0]
|
||||
const rotate = info.rotate || 0
|
||||
if ("key" in info) {
|
||||
const [width, height] = info.size ?? [1, 1]
|
||||
|
||||
compiled.keys.push({
|
||||
id: info.key,
|
||||
shape: "square",
|
||||
size: [width, height],
|
||||
pos: [x + ox, y + oy],
|
||||
cornerRadius: 0.1,
|
||||
rotate,
|
||||
})
|
||||
|
||||
x += width + ox
|
||||
maxHeight = Math.max(maxHeight, height + oy)
|
||||
} else if ("switch" in info) {
|
||||
const cx = x + ox + 1
|
||||
const cy = y + oy + 1
|
||||
for (const [i, id] of [info.switch.s, info.switch.w, info.switch.n, info.switch.e].entries()) {
|
||||
compiled.keys.push({
|
||||
id,
|
||||
shape: "quarter-circle",
|
||||
cornerRadius: 0,
|
||||
size: [2, 0.6],
|
||||
pos: [cx, cy],
|
||||
rotate: 90 * i + 45,
|
||||
})
|
||||
}
|
||||
compiled.keys.push({
|
||||
id: info.switch.d,
|
||||
shape: "square",
|
||||
cornerRadius: 0.5,
|
||||
size: [0.8, 0.8],
|
||||
pos: [x + 0.6 + ox, y + 0.6 + oy],
|
||||
rotate: 0,
|
||||
})
|
||||
|
||||
x += 2 + ox
|
||||
maxHeight = Math.max(maxHeight, 2 + oy)
|
||||
}
|
||||
}
|
||||
y += maxHeight
|
||||
compiled.size[0] = Math.max(compiled.size[0], x)
|
||||
}
|
||||
compiled.size[1] = y
|
||||
|
||||
return compiled
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import type {Action} from "svelte/action"
|
||||
import {serialPort, unsavedChanges} from "$lib/serial/connection"
|
||||
import {get} from "svelte/store"
|
||||
import {changes, ChangeType, settings} from "$lib/undo-redo"
|
||||
|
||||
export const setting: Action<HTMLInputElement, {id: number; inverse?: number; scale?: number}> = function (
|
||||
node: HTMLInputElement,
|
||||
@@ -9,15 +8,20 @@ export const setting: Action<HTMLInputElement, {id: number; inverse?: number; sc
|
||||
node.setAttribute("disabled", "")
|
||||
const type = node.getAttribute("type") as "number" | "checkbox"
|
||||
|
||||
const unsubscribe = serialPort.subscribe(async port => {
|
||||
if (port) {
|
||||
const unsubscribe = settings.subscribe(async settings => {
|
||||
if (id in settings) {
|
||||
const {value, isApplied} = settings[id]
|
||||
if (type === "number") {
|
||||
const value = Number(await port.getSetting(id).then(it => it.toString()))
|
||||
node.value = (
|
||||
inverse !== undefined ? inverse / value : scale !== undefined ? scale * value : value
|
||||
).toString()
|
||||
} else {
|
||||
node.checked = await port.getSetting(id).then(it => it !== 0)
|
||||
node.checked = value !== 0
|
||||
}
|
||||
if (isApplied) {
|
||||
node.classList.remove("pending-changes")
|
||||
} else {
|
||||
node.classList.add("pending-changes")
|
||||
}
|
||||
node.removeAttribute("disabled")
|
||||
} else {
|
||||
@@ -25,26 +29,23 @@ export const setting: Action<HTMLInputElement, {id: number; inverse?: number; sc
|
||||
}
|
||||
})
|
||||
|
||||
async function listener(event: Event) {
|
||||
const currentValue = await get(serialPort)!.getSetting(id)
|
||||
let value = 0
|
||||
async function listener() {
|
||||
let value: number
|
||||
if (type === "number") {
|
||||
value = Number((event as InputEvent).data)
|
||||
value = Number.parseInt(node.value)
|
||||
if (Number.isNaN(value)) return
|
||||
value = inverse !== undefined ? inverse / value : scale !== undefined ? value / scale : value
|
||||
} else {
|
||||
value = node.checked ? 1 : 0
|
||||
}
|
||||
await get(serialPort)!.setSetting(id, value)
|
||||
|
||||
const originalValue = get(unsavedChanges).get(id)
|
||||
unsavedChanges.update(it => {
|
||||
if (originalValue === value) {
|
||||
it.delete(id)
|
||||
} else if (!it.has(id)) {
|
||||
it.set(id, currentValue)
|
||||
}
|
||||
return it
|
||||
changes.update(changes => {
|
||||
changes.push({
|
||||
type: ChangeType.Setting,
|
||||
id: id,
|
||||
setting: value,
|
||||
})
|
||||
return changes
|
||||
})
|
||||
}
|
||||
node.addEventListener("input", listener)
|
||||
|
||||
53
src/lib/share/action-array.spec.ts
Normal file
53
src/lib/share/action-array.spec.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import {describe, it, expect} from "vitest"
|
||||
import {deserializeActionArray, serializeActionArray} from "./action-array"
|
||||
|
||||
describe("action array", () => {
|
||||
it("should work with number arrays", () => {
|
||||
expect(deserializeActionArray(serializeActionArray([62, 256, 1235]))).toEqual([62, 256, 1235])
|
||||
})
|
||||
|
||||
it("should work with nested arrays", () => {
|
||||
expect(deserializeActionArray(serializeActionArray([[], [[]]]))).toEqual([[], [[]]])
|
||||
})
|
||||
|
||||
it("should compress back and forth", () => {
|
||||
expect(
|
||||
deserializeActionArray(
|
||||
serializeActionArray([
|
||||
[43, 746, 634],
|
||||
[34, 63],
|
||||
[332, 34],
|
||||
]),
|
||||
),
|
||||
).toEqual([
|
||||
[43, 746, 634],
|
||||
[34, 63],
|
||||
[332, 34],
|
||||
])
|
||||
})
|
||||
|
||||
it("should compress a full layout", () => {
|
||||
const layout = Object.freeze([
|
||||
Object.freeze([
|
||||
0, 0, 0, 0, 0, 53, 119, 45, 103, 122, 52, 107, 118, 109, 99, 51, 114, 36, 59, 101, 50, 105, 34, 46,
|
||||
111, 49, 39, 515, 44, 117, 0, 512, 514, 513, 550, 0, 319, 318, 321, 320, 326, 315, 314, 317, 316, 0,
|
||||
0, 0, 0, 0, 54, 98, 120, 536, 113, 55, 102, 112, 104, 100, 56, 97, 296, 544, 116, 57, 108, 299, 106,
|
||||
110, 48, 121, 297, 61, 115, 0, 518, 516, 517, 553, 0, 336, 338, 335, 337, 0, 325, 322, 323, 324,
|
||||
]),
|
||||
Object.freeze([
|
||||
0, 0, 0, 0, 0, 0, 91, 0, 0, 0, 0, 53, 0, 47, 52, 0, 51, 298, 0, 50, 0, 0, 127, 0, 49, 0, 0, 515, 0, 0,
|
||||
0, 512, 514, 513, 550, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 93, 0, 536, 0, 0, 54, 0, 92,
|
||||
55, 0, 56, 296, 544, 57, 0, 96, 299, 0, 48, 0, 0, 297, 0, 0, 0, 518, 516, 517, 553, 0, 336, 338, 335,
|
||||
337, 0, 0, 0, 0, 0,
|
||||
]),
|
||||
Object.freeze([
|
||||
0, 0, 0, 0, 0, 0, 64, 95, 43, 0, 0, 126, 38, 63, 40, 0, 35, 298, 36, 123, 0, 33, 127, 37, 60, 0, 34,
|
||||
515, 0, 0, 0, 512, 514, 513, 550, 0, 333, 331, 330, 334, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 536,
|
||||
0, 0, 94, 58, 124, 41, 0, 42, 296, 544, 125, 0, 126, 299, 0, 62, 0, 0, 297, 0, 0, 0, 518, 516, 517,
|
||||
553, 0, 336, 338, 335, 337, 0, 0, 0, 0, 0,
|
||||
]),
|
||||
])
|
||||
|
||||
expect(deserializeActionArray(serializeActionArray(layout as number[][]))).toEqual(layout)
|
||||
})
|
||||
})
|
||||
@@ -1,5 +1,5 @@
|
||||
import {compressActions, decompressActions} from "$lib/serialization/actions"
|
||||
import {CHARA_FILE_TYPES} from "$lib/share/share-url"
|
||||
import {compressActions, decompressActions} from "../serialization/actions"
|
||||
import {CHARA_FILE_TYPES} from "../share/share-url"
|
||||
|
||||
export type ActionArray = number[] | ActionArray[]
|
||||
export function serializeActionArray(array: ActionArray): Uint8Array {
|
||||
@@ -11,7 +11,9 @@ export function serializeActionArray(array: ActionArray): Uint8Array {
|
||||
return out
|
||||
} else if (typeof array[0] === "number") {
|
||||
writer.setUint8(4, CHARA_FILE_TYPES.indexOf("number"))
|
||||
return concatUint8Arrays(out, compressActions(array as number[]))
|
||||
const compressed = compressActions(array as number[])
|
||||
writer.setUint32(0, compressed.length)
|
||||
return concatUint8Arrays(out, compressed)
|
||||
} else if (Array.isArray(array[0])) {
|
||||
writer.setUint8(4, CHARA_FILE_TYPES.indexOf("array"))
|
||||
return concatUint8Arrays(out, ...(array as ActionArray[]).map(serializeActionArray))
|
||||
@@ -20,20 +22,21 @@ export function serializeActionArray(array: ActionArray): Uint8Array {
|
||||
}
|
||||
}
|
||||
|
||||
export function deserializeActionArray(raw: Uint8Array): ActionArray {
|
||||
export function deserializeActionArray(raw: Uint8Array, cursor = {pos: 0}): ActionArray {
|
||||
const reader = new DataView(raw.buffer)
|
||||
const length = reader.getUint32(0)
|
||||
const type = CHARA_FILE_TYPES[reader.getUint8(4)]
|
||||
const length = reader.getUint32(cursor.pos)
|
||||
cursor.pos += 4
|
||||
const type = CHARA_FILE_TYPES[reader.getUint8(cursor.pos)]
|
||||
cursor.pos++
|
||||
|
||||
if (type === "number") {
|
||||
return decompressActions(raw.slice(5, 5 + length))
|
||||
const decompressed = decompressActions(raw.slice(cursor.pos, cursor.pos + length))
|
||||
cursor.pos += length
|
||||
return decompressed
|
||||
} else if (type === "array") {
|
||||
const innerLength = reader.getUint32(5)
|
||||
const out = []
|
||||
let cursor = 5
|
||||
for (let i = 0; i < length; i++) {
|
||||
out.push(deserializeActionArray(raw.slice(cursor, cursor + innerLength)))
|
||||
cursor += innerLength
|
||||
out.push(deserializeActionArray(raw, cursor))
|
||||
}
|
||||
return out
|
||||
} else {
|
||||
|
||||
@@ -4,12 +4,20 @@ export interface CharaFile<T extends string> {
|
||||
}
|
||||
|
||||
export interface CharaLayoutFile extends CharaFile<"layout"> {
|
||||
device: "one" | "lite" | string
|
||||
device?: "ONE" | "LITE" | string
|
||||
layout: [number[], number[], number[]]
|
||||
}
|
||||
|
||||
export interface CharaChordFile extends CharaFile<"chords"> {
|
||||
chords: [number[], number[]]
|
||||
chords: [number[], number[]][]
|
||||
}
|
||||
|
||||
export type CharaFiles = CharaLayoutFile | CharaChordFile
|
||||
export interface CharaSettingsFile extends CharaFile<"settings"> {
|
||||
settings: number[]
|
||||
}
|
||||
|
||||
export interface CharaBackupFile extends CharaFile<"backup"> {
|
||||
history: [CharaChordFile, CharaLayoutFile, CharaSettingsFile][]
|
||||
}
|
||||
|
||||
export type CharaFiles = CharaLayoutFile | CharaChordFile | CharaSettingsFile
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type {CharaFile, CharaFiles} from "$lib/share/chara-file"
|
||||
import type {ActionArray} from "$lib/share/action-array"
|
||||
import {deserializeActionArray, serializeActionArray} from "$lib/share/action-array"
|
||||
import {fromBase64, toBase64} from "$lib/serialization/base64"
|
||||
import type {CharaFile, CharaFiles} from "../share/chara-file"
|
||||
import type {ActionArray} from "../share/action-array"
|
||||
import {deserializeActionArray, serializeActionArray} from "../share/action-array"
|
||||
import {fromBase64, toBase64} from "../serialization/base64"
|
||||
|
||||
type CharaLayoutOrder = {
|
||||
[K in CharaFiles["type"]]: Array<
|
||||
@@ -15,6 +15,7 @@ const keys: CharaLayoutOrder = {
|
||||
["device", "string"],
|
||||
],
|
||||
chords: [["chords", "array"]],
|
||||
settings: [["settings", "array"]],
|
||||
}
|
||||
|
||||
export const CHARA_FILE_TYPES = ["unknown", "number", "string", "array"] as const
|
||||
@@ -42,17 +43,21 @@ export async function charaFileToUriComponent<T extends CharaFiles>(file: T): Pr
|
||||
return url
|
||||
}
|
||||
|
||||
export async function charaFileFromUriComponent<T extends CharaFiles>(uriComponent: string): Promise<T> {
|
||||
export async function charaFileFromUriComponent<T extends CharaFiles>(
|
||||
uriComponent: string,
|
||||
fetch = window.fetch,
|
||||
): Promise<T> {
|
||||
const [fileType, version, ...values] = uriComponent.split(sep)
|
||||
const file: any = {type: fileType, version: Number(version)}
|
||||
const file: any = {type: fileType, charaVersion: Number(version)}
|
||||
|
||||
for (const [key, type] of keys[fileType as keyof typeof keys]) {
|
||||
const value = values.pop()!
|
||||
const value = values.shift()!
|
||||
if (type === "string") {
|
||||
file[key] = value
|
||||
} else if (type === "array") {
|
||||
const stream = (await fromBase64(value)).stream().pipeThrough(new DecompressionStream("deflate"))
|
||||
const stream = (await fromBase64(value, fetch)).stream().pipeThrough(new DecompressionStream("deflate"))
|
||||
const actions = new Uint8Array(await new Response(stream).arrayBuffer())
|
||||
console.log(actions)
|
||||
file[key] = deserializeActionArray(actions)
|
||||
}
|
||||
}
|
||||
|
||||
35
src/lib/style/_kbd.scss
Normal file
35
src/lib/style/_kbd.scss
Normal file
@@ -0,0 +1,35 @@
|
||||
kbd {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
height: 20px;
|
||||
margin-block: 6px;
|
||||
padding: 4px;
|
||||
|
||||
font-size: 14px;
|
||||
font-weight: normal;
|
||||
color: currentcolor;
|
||||
|
||||
border: 1px solid currentcolor;
|
||||
border-radius: 4px;
|
||||
|
||||
&.icon {
|
||||
padding: 2px;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
&:has(> kbd) {
|
||||
gap: 4px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
}
|
||||
|
||||
> kbd {
|
||||
padding: 2px;
|
||||
|
||||
&.icon {
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
75
src/lib/style/form/_button.scss
Normal file
75
src/lib/style/form/_button.scss
Normal file
@@ -0,0 +1,75 @@
|
||||
a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a,
|
||||
label:has(input),
|
||||
button {
|
||||
cursor: pointer;
|
||||
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
width: max-content;
|
||||
height: 48px;
|
||||
padding-block: 8px;
|
||||
padding-inline: 16px;
|
||||
|
||||
font-family: inherit;
|
||||
font-weight: 600;
|
||||
color: currentcolor;
|
||||
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: 32px;
|
||||
|
||||
transition: all 250ms ease;
|
||||
|
||||
&.icon {
|
||||
display: inline-flex;
|
||||
|
||||
aspect-ratio: 1;
|
||||
padding-block: 0;
|
||||
padding-inline: 0;
|
||||
|
||||
font-size: 24px;
|
||||
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
&.primary {
|
||||
color: var(--md-sys-color-on-primary);
|
||||
background: var(--md-sys-color-primary);
|
||||
}
|
||||
|
||||
&.compact {
|
||||
height: 32px;
|
||||
}
|
||||
}
|
||||
|
||||
label:has(input):hover,
|
||||
.button:hover:not(:active),
|
||||
a:hover:not(:active),
|
||||
button:hover:not(:active) {
|
||||
filter: brightness(70%);
|
||||
transition: filter 250ms ease;
|
||||
|
||||
&:has(:checked),
|
||||
&.active {
|
||||
filter: brightness(120%);
|
||||
}
|
||||
|
||||
&:disabled,
|
||||
&.disabled {
|
||||
opacity: 0.5;
|
||||
filter: none;
|
||||
}
|
||||
}
|
||||
|
||||
.disabled,
|
||||
:disabled {
|
||||
pointer-events: none;
|
||||
opacity: 0.5;
|
||||
}
|
||||
16
src/lib/style/print.scss
Normal file
16
src/lib/style/print.scss
Normal file
@@ -0,0 +1,16 @@
|
||||
@media print {
|
||||
.print {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
nav {
|
||||
display: none;
|
||||
}
|
||||
|
||||
body {
|
||||
--md-sys-color-background: white !important;
|
||||
--md-sys-color-on-background: black !important;
|
||||
|
||||
visibility: hidden;
|
||||
}
|
||||
}
|
||||
10
src/lib/style/theme.scss
Normal file
10
src/lib/style/theme.scss
Normal file
@@ -0,0 +1,10 @@
|
||||
@import "./form/button";
|
||||
@import "./form/toggle";
|
||||
@import "./form/checkbox";
|
||||
@import "./kbd";
|
||||
@import "./print";
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
appearance: none;
|
||||
}
|
||||
@@ -24,6 +24,13 @@ $padding: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.tippy-box[data-theme~="tooltip"] {
|
||||
color: var(--md-sys-color-on-background);
|
||||
background-color: var(--md-sys-color-background);
|
||||
border: 1px solid var(--md-sys-color-outline);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.tippy-box[data-theme~="search-completion"] {
|
||||
overflow: hidden;
|
||||
filter: none;
|
||||
|
||||
41
src/lib/title.ts
Normal file
41
src/lib/title.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import type {Action} from "svelte/action"
|
||||
import tippy from "tippy.js"
|
||||
import type {SvelteComponent} from "svelte"
|
||||
import Tooltip from "$lib/components/Tooltip.svelte"
|
||||
import hotkeys from "hotkeys-js"
|
||||
|
||||
export const action: Action<Element, {title?: string; shortcut?: string}> = (
|
||||
node: Element,
|
||||
{title, shortcut},
|
||||
) => {
|
||||
let component: SvelteComponent | undefined
|
||||
const tooltip = tippy(node, {
|
||||
arrow: false,
|
||||
theme: "tooltip",
|
||||
animation: "fade",
|
||||
onShow(instance) {
|
||||
component ??= new Tooltip({
|
||||
target: instance.popper.querySelector(".tippy-content") as Element,
|
||||
props: {title, shortcut},
|
||||
})
|
||||
},
|
||||
onHidden() {
|
||||
component?.$destroy()
|
||||
component = undefined
|
||||
},
|
||||
})
|
||||
|
||||
if (shortcut && node instanceof HTMLElement) {
|
||||
hotkeys(shortcut, function (keyboardEvent) {
|
||||
keyboardEvent.preventDefault()
|
||||
node.click()
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
destroy() {
|
||||
tooltip.destroy()
|
||||
hotkeys.unbind(shortcut)
|
||||
},
|
||||
}
|
||||
}
|
||||
136
src/lib/undo-redo.ts
Normal file
136
src/lib/undo-redo.ts
Normal file
@@ -0,0 +1,136 @@
|
||||
import {persistentWritable} from "$lib/storage"
|
||||
import {derived} from "svelte/store"
|
||||
import type {Chord} from "$lib/serial/chord"
|
||||
import {deviceChords, deviceLayout, deviceSettings} from "$lib/serial/connection"
|
||||
import {KEYMAP_CODES} from "$lib/serial/keymap-codes"
|
||||
|
||||
export enum ChangeType {
|
||||
Layout,
|
||||
Chord,
|
||||
Setting,
|
||||
}
|
||||
|
||||
export interface LayoutChange {
|
||||
type: ChangeType.Layout
|
||||
id: number
|
||||
layer: number
|
||||
action: number
|
||||
}
|
||||
|
||||
export interface ChordChange {
|
||||
type: ChangeType.Chord
|
||||
id: number[]
|
||||
actions: number[]
|
||||
phrase: number[]
|
||||
}
|
||||
|
||||
export interface SettingChange {
|
||||
type: ChangeType.Setting
|
||||
id: number
|
||||
setting: number
|
||||
}
|
||||
|
||||
export interface ChangeInfo {
|
||||
isApplied: boolean
|
||||
isCommitted?: boolean
|
||||
}
|
||||
|
||||
export type Change = LayoutChange | ChordChange | SettingChange
|
||||
|
||||
export const changes = persistentWritable<Change[]>("changes", [])
|
||||
|
||||
export interface Overlay {
|
||||
layout: [Map<number, number>, Map<number, number>, Map<number, number>]
|
||||
chords: Map<string, Chord>
|
||||
settings: Map<number, number>
|
||||
}
|
||||
|
||||
export const overlay = derived(changes, changes => {
|
||||
const overlay: Overlay = {
|
||||
layout: [new Map(), new Map(), new Map()],
|
||||
chords: new Map(),
|
||||
settings: new Map(),
|
||||
}
|
||||
|
||||
for (const change of changes) {
|
||||
switch (change.type) {
|
||||
case ChangeType.Layout:
|
||||
overlay.layout[change.layer].set(change.id, change.action)
|
||||
break
|
||||
case ChangeType.Chord:
|
||||
overlay.chords.set(JSON.stringify(change.id), {actions: change.actions, phrase: change.phrase})
|
||||
break
|
||||
case ChangeType.Setting:
|
||||
overlay.settings.set(change.id, change.setting)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return overlay
|
||||
})
|
||||
|
||||
export const settings = derived([overlay, deviceSettings], ([overlay, settings]) =>
|
||||
settings.map<{value: number} & ChangeInfo>((value, id) => ({
|
||||
value: overlay.settings.get(id) ?? value,
|
||||
isApplied: !overlay.settings.has(id),
|
||||
})),
|
||||
)
|
||||
|
||||
export type KeyInfo = {action: number} & ChangeInfo
|
||||
export const layout = derived([overlay, deviceLayout], ([overlay, layout]) =>
|
||||
layout.map(
|
||||
(actions, layer) =>
|
||||
actions.map<KeyInfo>((action, id) => ({
|
||||
action: overlay.layout[layer].get(id) ?? action,
|
||||
isApplied: !overlay.layout[layer].has(id),
|
||||
})) as [KeyInfo, KeyInfo, KeyInfo],
|
||||
),
|
||||
)
|
||||
|
||||
export type ChordInfo = Chord &
|
||||
ChangeInfo & {phraseChanged: boolean; actionsChanged: boolean; sortBy: string} & {id: number[]}
|
||||
export const chords = derived([overlay, deviceChords], ([overlay, chords]) => {
|
||||
const newChords = new Set(overlay.chords.keys())
|
||||
|
||||
const changedChords = chords.map<ChordInfo>(chord => {
|
||||
const id = JSON.stringify(chord.actions)
|
||||
if (overlay.chords.has(id)) {
|
||||
newChords.delete(id)
|
||||
const changedChord = overlay.chords.get(id)!
|
||||
return {
|
||||
id: chord.actions,
|
||||
// use the old phrase for stable editing
|
||||
sortBy: chord.phrase.map(it => KEYMAP_CODES[it]?.id ?? it).join(),
|
||||
actions: changedChord.actions,
|
||||
phrase: changedChord.phrase,
|
||||
actionsChanged: id !== JSON.stringify(changedChord.actions),
|
||||
phraseChanged: JSON.stringify(chord.phrase) !== JSON.stringify(changedChord.phrase),
|
||||
isApplied: false,
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
id: chord.actions,
|
||||
sortBy: chord.phrase.map(it => KEYMAP_CODES[it]?.id ?? it).join(),
|
||||
actions: chord.actions,
|
||||
phrase: chord.phrase,
|
||||
phraseChanged: false,
|
||||
actionsChanged: false,
|
||||
isApplied: true,
|
||||
}
|
||||
}
|
||||
})
|
||||
for (const id of newChords) {
|
||||
const chord = overlay.chords.get(id)!
|
||||
changedChords.push({
|
||||
sortBy: "",
|
||||
isApplied: false,
|
||||
actionsChanged: true,
|
||||
phraseChanged: false,
|
||||
id: JSON.parse(id),
|
||||
phrase: chord.phrase,
|
||||
actions: chord.actions,
|
||||
})
|
||||
}
|
||||
|
||||
return changedChords.sort(({sortBy: a}, {sortBy: b}) => a.localeCompare(b))
|
||||
})
|
||||
1
src/lib/versioning.ts
Normal file
1
src/lib/versioning.ts
Normal file
@@ -0,0 +1 @@
|
||||
// TODO
|
||||
@@ -3,30 +3,36 @@
|
||||
import "$lib/fonts/material-symbols-rounded.scss"
|
||||
import "$lib/style/scrollbar.scss"
|
||||
import "$lib/style/tippy.scss"
|
||||
import "$lib/style/toggle.scss"
|
||||
import "$lib/style/theme.scss"
|
||||
import {onMount} from "svelte"
|
||||
import {applyTheme, argbFromHex, themeFromSourceColor} from "@material/material-color-utilities"
|
||||
import Navigation from "./Navigation.svelte"
|
||||
import {canAutoConnect} from "$lib/serial/device"
|
||||
import {initSerial} from "$lib/serial/connection"
|
||||
import type {LayoutServerData} from "./$types"
|
||||
import type {LayoutData} from "./$types"
|
||||
import {browser} from "$app/environment"
|
||||
import BrowserWarning from "./BrowserWarning.svelte"
|
||||
import "tippy.js/animations/shift-away.css"
|
||||
import "tippy.js/dist/tippy.css"
|
||||
import tippy from "tippy.js"
|
||||
import {theme, userPreferences} from "$lib/preferences.js"
|
||||
import {setLocale} from "../i18n/i18n-svelte"
|
||||
import {LL, setLocale} from "../i18n/i18n-svelte"
|
||||
import {loadLocale} from "../i18n/i18n-util.sync"
|
||||
import {detectLocale} from "../i18n/i18n-util"
|
||||
import type {Locales} from "../i18n/i18n-types"
|
||||
import Footer from "./Footer.svelte"
|
||||
import {runLayoutDetection} from "$lib/os-layout.js"
|
||||
import PageTransition from "./PageTransition.svelte"
|
||||
import SyncOverlay from "./SyncOverlay.svelte"
|
||||
import {restoreFromFile} from "$lib/backup/backup"
|
||||
import {goto} from "$app/navigation"
|
||||
|
||||
const locale = ((browser && localStorage.getItem("locale")) as Locales) || detectLocale()
|
||||
loadLocale(locale)
|
||||
setLocale(locale)
|
||||
|
||||
if (browser) {
|
||||
runLayoutDetection()
|
||||
tippy.setDefaultProps({
|
||||
animation: "shift-away",
|
||||
theme: "surface-variant",
|
||||
@@ -37,7 +43,7 @@
|
||||
})
|
||||
}
|
||||
|
||||
export let data: LayoutServerData
|
||||
export let data: LayoutData
|
||||
|
||||
onMount(async () => {
|
||||
theme.subscribe(it => {
|
||||
@@ -50,7 +56,15 @@
|
||||
await initPwa()
|
||||
}
|
||||
|
||||
if (browser && $userPreferences.autoConnect && (await canAutoConnect())) await initSerial()
|
||||
if (browser && $userPreferences.autoConnect && (await canAutoConnect())) {
|
||||
await initSerial()
|
||||
}
|
||||
if (data.importFile) {
|
||||
restoreFromFile(data.importFile)
|
||||
const url = new URL(location.href)
|
||||
url.searchParams.delete("import")
|
||||
await goto(url.href, {replaceState: true})
|
||||
}
|
||||
})
|
||||
|
||||
let webManifestLink = ""
|
||||
@@ -58,16 +72,20 @@
|
||||
|
||||
<svelte:head>
|
||||
{@html webManifestLink}
|
||||
<title>amaCC1ng</title>
|
||||
<meta name="description" content="Tool for CharaChorder devices" />
|
||||
<title>{$LL.TITLE()}</title>
|
||||
<meta name="description" content={$LL.DESCRIPTION()} />
|
||||
<meta name="theme-color" content={data.themeColor} />
|
||||
</svelte:head>
|
||||
|
||||
<SyncOverlay />
|
||||
|
||||
<Navigation />
|
||||
|
||||
<main>
|
||||
<!-- <PickChangesDialog /> -->
|
||||
|
||||
<PageTransition>
|
||||
<slot />
|
||||
</main>
|
||||
</PageTransition>
|
||||
|
||||
<Footer />
|
||||
|
||||
@@ -76,34 +94,6 @@
|
||||
{/if}
|
||||
|
||||
<style lang="scss" global>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
appearance: none;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--md-sys-color-tertiary);
|
||||
}
|
||||
|
||||
label:has(input):hover,
|
||||
.button:hover:not(:active),
|
||||
a:hover:not(:active),
|
||||
button:hover:not(:active) {
|
||||
filter: brightness(70%);
|
||||
transition: filter 250ms ease;
|
||||
|
||||
&:has(:checked),
|
||||
&.active {
|
||||
filter: brightness(120%);
|
||||
}
|
||||
|
||||
&:disabled,
|
||||
&.disabled {
|
||||
opacity: 0.5;
|
||||
filter: none;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
|
||||
@@ -1,2 +1,14 @@
|
||||
import type {LayoutLoad} from "./$types"
|
||||
import {browser} from "$app/environment"
|
||||
import {charaFileFromUriComponent} from "$lib/share/share-url"
|
||||
|
||||
export const prerender = true
|
||||
export const trailingSlash = "always"
|
||||
|
||||
export const load = (async ({url, data, fetch}) => {
|
||||
const importFile = browser && new URLSearchParams(url.search).get("import")
|
||||
return {
|
||||
...data,
|
||||
importFile: importFile ? await charaFileFromUriComponent(importFile, fetch) : undefined,
|
||||
}
|
||||
}) satisfies LayoutLoad
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
<script>
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>dot i/o</title>
|
||||
</svelte:head>
|
||||
|
||||
<h1>dot i/o V2</h1>
|
||||
|
||||
<section>
|
||||
<h2>Layout</h2>
|
||||
</section>
|
||||
@@ -2,5 +2,5 @@ import {redirect} from "@sveltejs/kit"
|
||||
import type {PageLoad} from "./$types"
|
||||
|
||||
export const load = (() => {
|
||||
throw redirect(302, "/config/")
|
||||
throw redirect(302, "/config")
|
||||
}) satisfies PageLoad
|
||||
|
||||
@@ -1,45 +1,14 @@
|
||||
<script lang="ts">
|
||||
import {parseCompressed, stringifyCompressed} from "$lib/serial/serialization"
|
||||
import {chords, layout} from "$lib/serial/connection"
|
||||
import {preference} from "$lib/preferences"
|
||||
import type {Chord} from "$lib/serial/chord"
|
||||
import type {CharaLayout} from "$lib/serialization/layout"
|
||||
import LL from "../i18n/i18n-svelte"
|
||||
|
||||
interface Backup {
|
||||
isCharaBackup: string
|
||||
chords: Chord[]
|
||||
layout: CharaLayout
|
||||
}
|
||||
|
||||
async function downloadBackup() {
|
||||
const downloadUrl = URL.createObjectURL(
|
||||
await stringifyCompressed({
|
||||
isCharaBackup: "v1.0",
|
||||
chords: $chords,
|
||||
layout: $layout,
|
||||
}),
|
||||
)
|
||||
const element = document.createElement("a")
|
||||
element.setAttribute("download", "chords.chb")
|
||||
element.href = downloadUrl
|
||||
element.setAttribute("target", "_blank")
|
||||
element.click()
|
||||
URL.revokeObjectURL(downloadUrl)
|
||||
}
|
||||
|
||||
async function restoreBackup(event: Event) {
|
||||
const input = (event.target as HTMLInputElement).files![0]
|
||||
if (!input) return
|
||||
const backup = await parseCompressed<Backup>(input)
|
||||
if (backup.isCharaBackup !== "v1.0") throw new Error("Invalid Backup")
|
||||
if (backup.chords) {
|
||||
$chords = backup.chords
|
||||
}
|
||||
if (backup.layout) {
|
||||
$layout = backup.layout
|
||||
}
|
||||
}
|
||||
import {
|
||||
createChordBackup,
|
||||
createLayoutBackup,
|
||||
createSettingsBackup,
|
||||
downloadBackup,
|
||||
downloadFile,
|
||||
restoreBackup,
|
||||
} from "$lib/backup/backup"
|
||||
</script>
|
||||
|
||||
<section>
|
||||
@@ -47,9 +16,24 @@
|
||||
<p class="disclaimer">
|
||||
<i>{$LL.backup.DISCLAIMER()}</i>
|
||||
</p>
|
||||
<fieldset>
|
||||
<legend>{$LL.backup.INDIVIDUAL()}</legend>
|
||||
<button on:click={() => downloadFile(createChordBackup())}>
|
||||
<span class="icon">piano</span>
|
||||
{$LL.configure.chords.TITLE()}
|
||||
</button>
|
||||
<button on:click={() => downloadFile(createLayoutBackup())}>
|
||||
<span class="icon">keyboard</span>
|
||||
{$LL.configure.layout.TITLE()}
|
||||
</button>
|
||||
<button on:click={() => downloadFile(createSettingsBackup())}>
|
||||
<span class="icon">settings</span>
|
||||
{$LL.configure.settings.TITLE()}
|
||||
</button>
|
||||
</fieldset>
|
||||
<div class="save">
|
||||
<button class="primary" on:click={downloadBackup}
|
||||
><span class="icon">save</span>{$LL.backup.DOWNLOAD()}</button
|
||||
><span class="icon">download</span>{$LL.backup.DOWNLOAD()}</button
|
||||
>
|
||||
<label class="button"
|
||||
><input on:input={restoreBackup} type="file" /><span class="icon">settings_backup_restore</span
|
||||
@@ -72,6 +56,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
fieldset {
|
||||
display: flex;
|
||||
margin-block: 16px;
|
||||
border: 1px solid currentcolor;
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -95,34 +86,4 @@
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.button,
|
||||
button {
|
||||
cursor: pointer;
|
||||
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
width: max-content;
|
||||
height: 48px;
|
||||
padding-block: 8px;
|
||||
padding-inline: 16px;
|
||||
|
||||
font-family: "Noto Sans Mono", monospace;
|
||||
font-weight: 600;
|
||||
color: var(--md-sys-color-on-background);
|
||||
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: 32px;
|
||||
|
||||
transition: all 250ms ease;
|
||||
}
|
||||
|
||||
button.primary {
|
||||
color: var(--md-sys-color-on-primary);
|
||||
background: var(--md-sys-color-primary);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
>{$LL.browserWarning.INFO_BROWSER_SUFFIX()}
|
||||
</p>
|
||||
<div>
|
||||
<a href="https://github.com/Theaninova/dotio/releases" target="_blank"
|
||||
<a href="https://github.com/CharaChorder/DeviceManager/releases" target="_blank"
|
||||
>{$LL.browserWarning.DOWNLOAD_APP()}</a
|
||||
>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script>
|
||||
import {page} from "$app/stores"
|
||||
import {action} from "$lib/title"
|
||||
import LL from "../i18n/i18n-svelte"
|
||||
|
||||
$: paths = [
|
||||
@@ -10,8 +11,8 @@
|
||||
</script>
|
||||
|
||||
<nav>
|
||||
{#each paths as { href, title, icon }}
|
||||
<a {href} class:active={$page.url.pathname.startsWith(href)}>
|
||||
{#each paths as { href, title, icon }, i}
|
||||
<a {href} class:active={$page.url.pathname.startsWith(href)} use:action={{shortcut: `shift+${i + 1}`}}>
|
||||
<span class="icon">{icon}</span>
|
||||
{title}
|
||||
</a>
|
||||
@@ -27,30 +28,13 @@
|
||||
|
||||
padding: 8px;
|
||||
|
||||
color: var(--md-sys-color-on-surface-variant);
|
||||
|
||||
background: var(--md-sys-color-surface-variant);
|
||||
border: none;
|
||||
border-radius: 32px;
|
||||
}
|
||||
|
||||
a {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
margin: 0;
|
||||
padding: 8px;
|
||||
padding-inline: 16px;
|
||||
|
||||
font-weight: 600;
|
||||
color: var(--md-sys-color-on-surface-variant);
|
||||
text-decoration: none;
|
||||
|
||||
border-radius: 24px;
|
||||
|
||||
transition: all 250ms ease;
|
||||
}
|
||||
|
||||
a.active {
|
||||
--icon-fill: 1;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
{$serialPort.device}
|
||||
{$serialPort.chipset}
|
||||
<br />
|
||||
Version {$serialPort.version.map(it => it.toString()).join(".")}
|
||||
Version {$serialPort.version}
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
@@ -57,7 +57,16 @@
|
||||
</div>
|
||||
</div>
|
||||
{#if powerDialog}
|
||||
<div class="backdrop" transition:fade={{duration: 250}} on:click={() => (powerDialog = !powerDialog)} />
|
||||
<div
|
||||
class="backdrop"
|
||||
role="button"
|
||||
tabindex="-1"
|
||||
transition:fade={{duration: 250}}
|
||||
on:click={() => (powerDialog = !powerDialog)}
|
||||
on:keypress={event => {
|
||||
if (event.key === "Enter") powerDialog = !powerDialog
|
||||
}}
|
||||
/>
|
||||
<dialog open transition:slide={{duration: 250}}>
|
||||
<h3>{$LL.deviceManager.bootMenu.TITLE()}</h3>
|
||||
<button
|
||||
@@ -153,43 +162,6 @@
|
||||
background: var(--md-sys-color-secondary);
|
||||
}
|
||||
|
||||
a,
|
||||
button {
|
||||
cursor: pointer;
|
||||
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
height: 48px;
|
||||
padding: 8px;
|
||||
padding-inline-end: 16px;
|
||||
|
||||
font-size: 1rem;
|
||||
color: var(--md-sys-color-on-background);
|
||||
text-decoration: none;
|
||||
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: 32px;
|
||||
|
||||
transition: all 250ms ease;
|
||||
|
||||
&.icon {
|
||||
aspect-ratio: 1;
|
||||
padding-inline-end: 8px;
|
||||
font-size: 24px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
}
|
||||
|
||||
a.disabled,
|
||||
button:disabled {
|
||||
cursor: default;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
button:active:not(:disabled) {
|
||||
color: var(--md-sys-color-on-surface-variant);
|
||||
background: var(--md-sys-color-surface-variant);
|
||||
|
||||
@@ -1,12 +1,27 @@
|
||||
<script lang="ts">
|
||||
import LL from "../i18n/i18n-svelte"
|
||||
import {changes} from "$lib/serial/connection"
|
||||
import type {Change} from "$lib/serial/connection"
|
||||
import {fly} from "svelte/transition"
|
||||
import {changes, ChangeType, chords, layout, overlay, settings} from "$lib/undo-redo"
|
||||
import type {Change} from "$lib/undo-redo"
|
||||
import {fly, slide} from "svelte/transition"
|
||||
import {action} from "$lib/title"
|
||||
import {
|
||||
deviceChords,
|
||||
deviceLayout,
|
||||
deviceSettings,
|
||||
serialPort,
|
||||
syncProgress,
|
||||
syncStatus,
|
||||
} from "$lib/serial/connection"
|
||||
import {askForConfirmation} from "$lib/dialogs/confirm-dialog"
|
||||
import {KEYMAP_CODES} from "$lib/serial/keymap-codes"
|
||||
|
||||
function undo() {
|
||||
redoQueue = [$changes.pop()!, ...redoQueue]
|
||||
changes.update(it => it)
|
||||
function undo(event: MouseEvent) {
|
||||
if (event.shiftKey) {
|
||||
changes.set([])
|
||||
} else {
|
||||
redoQueue = [$changes.pop()!, ...redoQueue]
|
||||
changes.update(it => it)
|
||||
}
|
||||
}
|
||||
|
||||
function redo() {
|
||||
@@ -19,67 +34,128 @@
|
||||
}
|
||||
let redoQueue: Change[] = []
|
||||
|
||||
function apply() {
|
||||
// TODO
|
||||
async function save() {
|
||||
const port = $serialPort
|
||||
if (!port) return
|
||||
$syncStatus = "uploading"
|
||||
|
||||
for (const [id, {actions, phrase}] of $overlay.chords) {
|
||||
if (phrase.length > 0) {
|
||||
if (id !== JSON.stringify(actions)) {
|
||||
const existingChord = await port.getChordPhrase(actions)
|
||||
if (
|
||||
existingChord !== undefined &&
|
||||
!(await askForConfirmation(
|
||||
$LL.configure.chords.conflict.TITLE(),
|
||||
$LL.configure.chords.conflict.DESCRIPTION(
|
||||
actions.map(it => `<kbd>${KEYMAP_CODES[it].id}</kbd>`).join(" "),
|
||||
),
|
||||
$LL.configure.chords.conflict.CONFIRM(),
|
||||
$LL.configure.chords.conflict.ABORT(),
|
||||
))
|
||||
) {
|
||||
changes.update(changes =>
|
||||
changes.filter(it => !(it.type === ChangeType.Chord && JSON.stringify(it.id) === id)),
|
||||
)
|
||||
continue
|
||||
}
|
||||
|
||||
await port.deleteChord({actions: JSON.parse(id)})
|
||||
}
|
||||
await port.setChord({actions, phrase})
|
||||
} else {
|
||||
await port.deleteChord({actions})
|
||||
}
|
||||
}
|
||||
|
||||
for (const [layer, actions] of $overlay.layout.entries()) {
|
||||
for (const [id, action] of actions) {
|
||||
await port.setLayoutKey(layer + 1, id, action)
|
||||
}
|
||||
}
|
||||
|
||||
for (const [id, setting] of $overlay.settings) {
|
||||
await port.setSetting(id, setting)
|
||||
}
|
||||
|
||||
|
||||
// Yes, this is a completely arbitrary and unnecessary delay.
|
||||
// The only purpose of it is to create a sense of weight,
|
||||
// aka make it more "energy intensive" to click.
|
||||
// The only conceivable way users could reach the commit limit in this case
|
||||
// would be if they click it every time they change a setting.
|
||||
// Because of that, we don't need to show a fearmongering message such as
|
||||
// "Your device will break after you click this 10,000 times!"
|
||||
const virtualWriteTime = 1000
|
||||
const startStamp = performance.now()
|
||||
await new Promise<void>(resolve => {
|
||||
function animate() {
|
||||
const delta = performance.now() - startStamp
|
||||
syncProgress.set({
|
||||
max: virtualWriteTime,
|
||||
current: delta,
|
||||
})
|
||||
if (delta >= virtualWriteTime) {
|
||||
resolve()
|
||||
} else {
|
||||
requestAnimationFrame(animate)
|
||||
}
|
||||
}
|
||||
requestAnimationFrame(animate)
|
||||
})
|
||||
await port.commit()
|
||||
|
||||
$deviceLayout = $layout.map(layer => layer.map<number>(({action}) => action)) as [
|
||||
number[],
|
||||
number[],
|
||||
number[],
|
||||
]
|
||||
$deviceChords = $chords
|
||||
.map(({actions, phrase}) => ({actions, phrase}))
|
||||
.filter(({phrase}) => phrase.length > 1)
|
||||
$deviceSettings = $settings.map(({value}) => value)
|
||||
$changes = []
|
||||
$syncStatus = "done"
|
||||
}
|
||||
</script>
|
||||
|
||||
<button title={$LL.saveActions.UNDO()} class="icon" disabled={$changes.length === 0} on:click={undo}
|
||||
>undo</button
|
||||
<button
|
||||
use:action={{title: $LL.saveActions.UNDO(), shortcut: "ctrl+z"}}
|
||||
class="icon"
|
||||
disabled={$changes.length === 0}
|
||||
on:click={undo}>undo</button
|
||||
>
|
||||
<button title={$LL.saveActions.REDO()} class="icon" disabled={redoQueue.length === 0} on:click={redo}
|
||||
>redo</button
|
||||
<button
|
||||
use:action={{title: $LL.saveActions.REDO(), shortcut: "ctrl+y"}}
|
||||
class="icon"
|
||||
disabled={redoQueue.length === 0}
|
||||
on:click={redo}>redo</button
|
||||
>
|
||||
<div class="separator" />
|
||||
<button title={$LL.saveActions.SAVE()} class="icon">save</button>
|
||||
{#if $changes.length !== 0}
|
||||
<button class="click-me" transition:fly={{x: 8}}
|
||||
><span class="icon">bolt</span>{$LL.saveActions.APPLY()}</button
|
||||
<button
|
||||
transition:fly={{x: 10}}
|
||||
use:action={{title: $LL.saveActions.SAVE(), shortcut: "ctrl+shift+s"}}
|
||||
on:click={save}
|
||||
class="click-me"><span class="icon">save</span>{$LL.saveActions.SAVE()}</button
|
||||
>
|
||||
{/if}
|
||||
|
||||
<style lang="scss">
|
||||
button {
|
||||
cursor: pointer;
|
||||
|
||||
padding: 0;
|
||||
|
||||
color: currentcolor;
|
||||
|
||||
background: none;
|
||||
border: none;
|
||||
|
||||
transition: all 250ms ease;
|
||||
}
|
||||
|
||||
:disabled {
|
||||
pointer-events: none;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.click-me {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
height: fit-content;
|
||||
margin-inline: 8px;
|
||||
padding-block: 2px;
|
||||
padding-inline-start: 4px;
|
||||
padding-inline-end: 8px;
|
||||
|
||||
padding-inline-start: 8px;
|
||||
padding-inline-end: 12px;
|
||||
font-family: inherit;
|
||||
font-weight: bold;
|
||||
color: var(--md-sys-color-primary);
|
||||
|
||||
border: 2px solid var(--md-sys-color-primary);
|
||||
border-radius: 18px;
|
||||
outline: 2px dashed var(--md-sys-color-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.separator {
|
||||
width: 1px;
|
||||
height: 24px;
|
||||
background: var(--md-sys-color-outline-variant);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,34 +1,151 @@
|
||||
<script>
|
||||
import {version} from "$app/environment"
|
||||
<script lang="ts">
|
||||
import {browser, version} from "$app/environment"
|
||||
import {action} from "$lib/title"
|
||||
import LL, {setLocale} from "../i18n/i18n-svelte"
|
||||
import {theme} from "$lib/preferences.js"
|
||||
import type {Locales} from "../i18n/i18n-types"
|
||||
import {detectLocale, locales} from "../i18n/i18n-util"
|
||||
import {loadLocaleAsync} from "../i18n/i18n-util.async"
|
||||
import {tick} from "svelte"
|
||||
|
||||
let locale = (browser && (localStorage.getItem("locale") as Locales)) || detectLocale()
|
||||
$: if (browser)
|
||||
(async () => {
|
||||
localStorage.setItem("locale", locale)
|
||||
await loadLocaleAsync(locale)
|
||||
setLocale(locale)
|
||||
})()
|
||||
|
||||
function switchTheme() {
|
||||
const mode = $theme.mode === "light" ? "dark" : "light"
|
||||
if (document.startViewTransition) {
|
||||
document.startViewTransition(async () => {
|
||||
$theme.mode = mode
|
||||
await tick()
|
||||
})
|
||||
} else {
|
||||
$theme.mode = mode
|
||||
}
|
||||
}
|
||||
|
||||
let languageSelect: HTMLSelectElement
|
||||
</script>
|
||||
|
||||
<footer>
|
||||
<ul>
|
||||
<li>
|
||||
<a href={HOMEPAGE_URL} rel="noreferrer" target="_blank"><span class="icon">commit</span> v{version}</a>
|
||||
<!-- svelte-ignore not-defined -->
|
||||
<a href={import.meta.env.VITE_HOMEPAGE_URL} rel="noreferrer" target="_blank"
|
||||
><span class="icon">commit</span> v{version}</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a href={BUGS_URL} rel="noreferrer" target="_blank"
|
||||
<a href={import.meta.env.VITE_BUGS_URL} rel="noreferrer" target="_blank"
|
||||
><span class="icon">bug_report</span> File an issue</a
|
||||
>
|
||||
</li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li>
|
||||
<input use:action={{title: $LL.profile.theme.COLOR_SCHEME()}} type="color" bind:value={$theme.color} />
|
||||
</li>
|
||||
<li>
|
||||
{#if $theme.mode === "light"}
|
||||
<button use:action={{title: $LL.profile.theme.DARK_MODE()}} class="icon" on:click={switchTheme}>
|
||||
dark_mode
|
||||
</button>
|
||||
{:else if $theme.mode === "dark"}
|
||||
<button use:action={{title: $LL.profile.theme.LIGHT_MODE()}} class="icon" on:click={switchTheme}>
|
||||
light_mode
|
||||
</button>
|
||||
{/if}
|
||||
</li>
|
||||
<li>
|
||||
<button
|
||||
class="icon"
|
||||
use:action={{title: $LL.profile.LANGUAGE()}}
|
||||
on:click={() => languageSelect.click()}
|
||||
>translate
|
||||
|
||||
<select bind:value={locale} bind:this={languageSelect}>
|
||||
{#each locales as code}
|
||||
<option value={code}>{code}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</footer>
|
||||
|
||||
<style>
|
||||
<style lang="scss">
|
||||
select {
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
input[type="color"] {
|
||||
cursor: pointer;
|
||||
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
inline-size: 20px;
|
||||
block-size: 20px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
||||
color: inherit;
|
||||
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
|
||||
&::-webkit-color-swatch-wrapper {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
&::-webkit-color-swatch {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
width: 100%;
|
||||
padding: 16px;
|
||||
|
||||
opacity: 0.4;
|
||||
}
|
||||
|
||||
ul {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
align-items: center;
|
||||
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
ul:last-child {
|
||||
gap: 12px;
|
||||
|
||||
button {
|
||||
height: 24px;
|
||||
font-size: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
a {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -1,39 +1,23 @@
|
||||
<script lang="ts">
|
||||
import {serialPort, syncStatus, unsavedChanges} from "$lib/serial/connection"
|
||||
import {serialPort, syncStatus} from "$lib/serial/connection"
|
||||
import {slide, fly} from "svelte/transition"
|
||||
import {canShare, triggerShare} from "$lib/share"
|
||||
import {popup} from "$lib/popup"
|
||||
import BackupPopup from "./BackupPopup.svelte"
|
||||
import ConnectionPopup from "./ConnectionPopup.svelte"
|
||||
import {canAutoConnect} from "$lib/serial/device"
|
||||
import {browser} from "$app/environment"
|
||||
import {userPreferences} from "$lib/preferences"
|
||||
import {action} from "$lib/title"
|
||||
import LL from "../i18n/i18n-svelte"
|
||||
import Profile from "./Profile.svelte"
|
||||
import ConfigTabs from "./ConfigTabs.svelte"
|
||||
import EditActions from "./EditActions.svelte"
|
||||
import {onMount} from "svelte"
|
||||
|
||||
async function flashChanges() {
|
||||
$syncStatus = "uploading"
|
||||
// Yes, this is a completely arbitrary and unnecessary delay.
|
||||
// The only purpose of it is to create a sense of weight,
|
||||
// aka make it more "energy intensive" to click.
|
||||
// The only conceivable way users could reach the commit limit in this case
|
||||
// would be if they click it every time they change a setting.
|
||||
// Because of that, we don't need to show a fearmongering message such as
|
||||
// "Your device will break after you click this 10,000 times!"
|
||||
await new Promise(resolve => setTimeout(resolve, 6000))
|
||||
$serialPort.commit()
|
||||
unsavedChanges.update(it => {
|
||||
it.clear()
|
||||
return it
|
||||
})
|
||||
$syncStatus = "done"
|
||||
}
|
||||
|
||||
$: if (browser && !canAutoConnect()) {
|
||||
connectButton?.click()
|
||||
}
|
||||
onMount(async () => {
|
||||
if (browser && !$userPreferences.autoConnect) {
|
||||
connectButton.click()
|
||||
}
|
||||
})
|
||||
|
||||
let connectButton: HTMLButtonElement
|
||||
</script>
|
||||
@@ -47,7 +31,18 @@
|
||||
|
||||
<div class="actions">
|
||||
{#if $canShare}
|
||||
<button transition:fly={{x: -8}} class="icon" on:click={triggerShare}>share</button>
|
||||
<button
|
||||
use:action={{title: $LL.share.TITLE()}}
|
||||
transition:fly={{x: -8}}
|
||||
class="icon"
|
||||
on:click={triggerShare}>share</button
|
||||
>
|
||||
<button
|
||||
use:action={{title: $LL.print.TITLE()}}
|
||||
transition:fly={{x: -8}}
|
||||
class="icon"
|
||||
on:click={() => print()}>print</button
|
||||
>
|
||||
<div transition:slide class="separator" />
|
||||
{/if}
|
||||
{#if import.meta.env.TAURI_FAMILY === undefined}
|
||||
@@ -55,109 +50,38 @@
|
||||
<PwaStatus />
|
||||
{/await}
|
||||
{/if}
|
||||
{#if $unsavedChanges.size > 0}
|
||||
<button
|
||||
disabled={$syncStatus === "uploading"}
|
||||
on:click={flashChanges}
|
||||
transition:fly={{x: -8}}
|
||||
title={$LL.deviceManager.APPLY_SETTINGS()}
|
||||
class="icon"
|
||||
>save
|
||||
</button>
|
||||
<div transition:slide class="separator" />
|
||||
{/if}
|
||||
{#if $serialPort}
|
||||
<button title={$LL.backup.TITLE()} use:popup={BackupPopup} class="icon {$syncStatus}">
|
||||
{#if $syncStatus === "downloading"}
|
||||
backup
|
||||
{:else if $syncStatus === "uploading"}
|
||||
cloud_download
|
||||
{:else if $userPreferences.backup}
|
||||
cloud_done
|
||||
<button use:action={{title: $LL.backup.TITLE()}} use:popup={BackupPopup} class="icon {$syncStatus}">
|
||||
{#if $userPreferences.backup}
|
||||
history
|
||||
{:else}
|
||||
cloud_off
|
||||
history_toggle_off
|
||||
{/if}
|
||||
</button>
|
||||
{/if}
|
||||
<button
|
||||
bind:this={connectButton}
|
||||
title="Devices"
|
||||
use:action={{title: $LL.deviceManager.TITLE()}}
|
||||
use:popup={ConnectionPopup}
|
||||
class="icon connect"
|
||||
class:error={$serialPort === undefined}
|
||||
>
|
||||
cable
|
||||
</button>
|
||||
<button title={$LL.profile.TITLE()} use:popup={Profile} class="icon account">person</button>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<style lang="scss">
|
||||
@keyframes sync {
|
||||
0% {
|
||||
scale: 1 1;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
85% {
|
||||
scale: 1 0;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
86% {
|
||||
scale: 1 1;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
100% {
|
||||
scale: 1 1;
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.uploading::after,
|
||||
.downloading::after {
|
||||
content: "";
|
||||
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
left: 50%;
|
||||
transform-origin: top;
|
||||
translate: -50% 0;
|
||||
|
||||
width: 8px;
|
||||
height: 10px;
|
||||
|
||||
background: var(--md-sys-color-background);
|
||||
|
||||
animation: sync 1s linear infinite;
|
||||
}
|
||||
|
||||
.uploading::after {
|
||||
transform-origin: bottom;
|
||||
}
|
||||
|
||||
.downloading.active::after,
|
||||
.uploading.active::after {
|
||||
background: var(--md-sys-color-primary);
|
||||
}
|
||||
|
||||
.sync.downloading::after {
|
||||
top: 10px;
|
||||
transform-origin: bottom;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.separator {
|
||||
width: 1px;
|
||||
height: 24px;
|
||||
margin-inline: 4px;
|
||||
background: var(--md-sys-color-outline-variant);
|
||||
}
|
||||
|
||||
nav {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto 1fr;
|
||||
gap: 4px;
|
||||
|
||||
width: calc(min(100%, 28cm));
|
||||
margin-block: 8px;
|
||||
@@ -187,7 +111,7 @@
|
||||
justify-content: center;
|
||||
|
||||
aspect-ratio: 1;
|
||||
padding: 2px;
|
||||
padding: 0;
|
||||
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
@@ -206,7 +130,6 @@
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
|
||||
&:last-child {
|
||||
@@ -214,12 +137,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
.icon.account {
|
||||
font-size: 32px;
|
||||
color: var(--md-sys-color-on-secondary-container);
|
||||
background: var(--md-sys-color-secondary-container);
|
||||
}
|
||||
|
||||
:disabled {
|
||||
pointer-events: none;
|
||||
opacity: 0.5;
|
||||
|
||||
50
src/routes/PageTransition.svelte
Normal file
50
src/routes/PageTransition.svelte
Normal file
@@ -0,0 +1,50 @@
|
||||
<script lang="ts">
|
||||
import {fly} from "svelte/transition"
|
||||
import {afterNavigate, beforeNavigate} from "$app/navigation"
|
||||
import {expoIn, expoOut} from "svelte/easing"
|
||||
|
||||
let inDirection = 0
|
||||
let outDirection = 0
|
||||
let outroEnd: undefined | (() => void) = undefined
|
||||
let animationDone: Promise<void>
|
||||
|
||||
let isNavigating = false
|
||||
|
||||
const routeOrder = ["/config/chords/", "/config/layout/", "/config/settings/"]
|
||||
|
||||
beforeNavigate(navigation => {
|
||||
const from = navigation.from?.url.pathname
|
||||
const to = navigation.to?.url.pathname
|
||||
isNavigating = true
|
||||
|
||||
if (!(from && to && routeOrder.includes(from) && routeOrder.includes(to))) {
|
||||
inDirection = 0
|
||||
outDirection = 0
|
||||
} else {
|
||||
const fromIndex = routeOrder.indexOf(from)
|
||||
const toIndex = routeOrder.indexOf(to)
|
||||
|
||||
inDirection = fromIndex > toIndex ? -1 : 1
|
||||
outDirection = fromIndex > toIndex ? 1 : -1
|
||||
}
|
||||
|
||||
animationDone = new Promise(resolve => {
|
||||
outroEnd = resolve
|
||||
})
|
||||
})
|
||||
|
||||
afterNavigate(async () => {
|
||||
await animationDone
|
||||
isNavigating = false
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if !isNavigating}
|
||||
<main
|
||||
in:fly={{x: inDirection * 24, duration: 150, easing: expoOut}}
|
||||
out:fly={{x: outDirection * 24, duration: 150, easing: expoIn}}
|
||||
on:outroend={outroEnd}
|
||||
>
|
||||
<slot />
|
||||
</main>
|
||||
{/if}
|
||||
@@ -1,116 +0,0 @@
|
||||
<script lang="ts">
|
||||
import LL, {setLocale} from "../i18n/i18n-svelte"
|
||||
import {theme} from "$lib/preferences"
|
||||
import {tick} from "svelte"
|
||||
import {detectLocale, locales} from "../i18n/i18n-util"
|
||||
import {loadLocaleAsync} from "../i18n/i18n-util.async"
|
||||
import type {Locales} from "../i18n/i18n-types"
|
||||
|
||||
let locale = (localStorage.getItem("locale") as Locales) || detectLocale()
|
||||
$: (async () => {
|
||||
localStorage.setItem("locale", locale)
|
||||
await loadLocaleAsync(locale)
|
||||
setLocale(locale)
|
||||
})()
|
||||
|
||||
function switchTheme() {
|
||||
const mode = $theme.mode === "light" ? "dark" : "light"
|
||||
if (document.startViewTransition) {
|
||||
document.startViewTransition(async () => {
|
||||
$theme.mode = mode
|
||||
await tick()
|
||||
})
|
||||
} else {
|
||||
$theme.mode = mode
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<section>
|
||||
<h2>{$LL.profile.TITLE()}</h2>
|
||||
<fieldset>
|
||||
<legend>
|
||||
<span class="icon">format_paint</span>
|
||||
{$LL.profile.theme.TITLE()}
|
||||
</legend>
|
||||
|
||||
<input title={$LL.profile.theme.COLOR_SCHEME()} type="color" bind:value={$theme.color} />
|
||||
<button
|
||||
title={$theme.mode === "light" ? $LL.profile.theme.LIGHT_MODE() : $LL.profile.theme.DARK_MODE()}
|
||||
class="icon"
|
||||
on:click={switchTheme}
|
||||
>
|
||||
{#if $theme.mode === "light"}
|
||||
light_mode
|
||||
{:else if $theme.mode === "dark"}
|
||||
dark_mode
|
||||
{:else}
|
||||
TODO
|
||||
{/if}
|
||||
</button>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>
|
||||
<span class="icon">translate</span>
|
||||
{$LL.profile.LANGUAGE()}
|
||||
</legend>
|
||||
{#each locales as code}
|
||||
<label>{code}<input bind:group={locale} type="radio" value={code} name="language" /></label>
|
||||
{/each}
|
||||
</fieldset>
|
||||
</section>
|
||||
|
||||
<style lang="scss">
|
||||
h2 {
|
||||
grid-column: 1 / span 2;
|
||||
}
|
||||
|
||||
section {
|
||||
display: grid;
|
||||
grid-template-columns: auto auto;
|
||||
min-width: 300px;
|
||||
}
|
||||
|
||||
fieldset {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
border: 1px solid var(--md-sys-color-outline);
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
legend {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
button,
|
||||
input[type="color"] {
|
||||
cursor: pointer;
|
||||
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
inline-size: 24px;
|
||||
block-size: 24px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
||||
color: inherit;
|
||||
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
|
||||
&::-webkit-color-swatch-wrapper {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
&::-webkit-color-swatch {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
67
src/routes/SyncOverlay.svelte
Normal file
67
src/routes/SyncOverlay.svelte
Normal file
@@ -0,0 +1,67 @@
|
||||
<script lang="ts">
|
||||
import {syncProgress, syncStatus} from "$lib/serial/connection"
|
||||
import LL from "../i18n/i18n-svelte"
|
||||
|
||||
$: if (dialog) toggleDialog($syncStatus)
|
||||
|
||||
async function toggleDialog(status: "uploading" | "downloading" | string) {
|
||||
// debounce
|
||||
await new Promise(resolve => setTimeout(resolve, 150))
|
||||
if ($syncStatus !== status) return
|
||||
|
||||
if (!dialog.open && ($syncStatus === "uploading" || $syncStatus === "downloading")) {
|
||||
message = $syncStatus
|
||||
dialog.showModal()
|
||||
dialog.animate([{opacity: 0}, {opacity: 1}], {duration: 250, easing: "ease"})
|
||||
} else if (dialog.open) {
|
||||
const animation = dialog.animate([{opacity: 1}, {opacity: 0}], {duration: 250, easing: "ease"})
|
||||
animation.addEventListener("finish", () => {
|
||||
dialog.close()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
let message: "downloading" | "uploading"
|
||||
let dialog: HTMLDialogElement
|
||||
</script>
|
||||
|
||||
<dialog bind:this={dialog}>
|
||||
{#if message === "downloading"}
|
||||
<h2>{$LL.sync.TITLE_READ()}</h2>
|
||||
{:else}
|
||||
<h2>{$LL.sync.TITLE_WRITE()}</h2>
|
||||
{/if}
|
||||
<progress max={$syncProgress?.max ?? 1} value={$syncProgress?.current ?? 1}></progress>
|
||||
</dialog>
|
||||
|
||||
<style lang="scss">
|
||||
dialog::backdrop {
|
||||
background: rgba(0 0 0 / 70%);
|
||||
}
|
||||
|
||||
progress {
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
height: 16px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
progress::-webkit-progress-bar {
|
||||
background: var(--md-sys-color-background);
|
||||
}
|
||||
|
||||
progress::-webkit-progress-value {
|
||||
background: var(--md-sys-color-primary);
|
||||
}
|
||||
|
||||
dialog {
|
||||
max-width: 14cm;
|
||||
padding: 2cm;
|
||||
|
||||
color: white;
|
||||
|
||||
background: none;
|
||||
border: none;
|
||||
outline: none;
|
||||
}
|
||||
</style>
|
||||
1
src/routes/bootcamp/+page.svelte
Normal file
1
src/routes/bootcamp/+page.svelte
Normal file
@@ -0,0 +1 @@
|
||||
<h1>Layout Bootcamp</h1>
|
||||
@@ -2,5 +2,5 @@ import {redirect} from "@sveltejs/kit"
|
||||
import type {PageLoad} from "./$types"
|
||||
|
||||
export const load = (() => {
|
||||
throw redirect(302, "/config/chords/")
|
||||
throw redirect(302, "/config/layout/")
|
||||
}) satisfies PageLoad
|
||||
|
||||
@@ -2,5 +2,4 @@
|
||||
import LL from "../../i18n/i18n-svelte"
|
||||
</script>
|
||||
|
||||
<h4>{$LL.share.URL_COPIED()}</h4>
|
||||
<button>{$LL.share.EXTRA_DOWNLOAD()}</button>
|
||||
{$LL.share.URL_COPIED()}
|
||||
|
||||
@@ -1,76 +1,141 @@
|
||||
<script lang="ts">
|
||||
import {chords} from "$lib/serial/connection"
|
||||
import {KEYMAP_CODES} from "$lib/serial/keymap-codes"
|
||||
import Index from "flexsearch"
|
||||
import type {Chord} from "$lib/serial/chord"
|
||||
import LL from "../../../i18n/i18n-svelte"
|
||||
import {action} from "$lib/title"
|
||||
import {onDestroy, onMount, setContext} from "svelte"
|
||||
import {changes, ChangeType, chords} from "$lib/undo-redo"
|
||||
import type {ChordInfo} from "$lib/undo-redo"
|
||||
import {derived, writable} from "svelte/store"
|
||||
import ChordEdit from "./ChordEdit.svelte"
|
||||
import {crossfade} from "svelte/transition"
|
||||
import ChordActionEdit from "./ChordActionEdit.svelte"
|
||||
|
||||
const resultSize = 38
|
||||
let results: HTMLElement
|
||||
const pageSize = writable(0)
|
||||
let resizeObserver: ResizeObserver
|
||||
|
||||
onMount(() => {
|
||||
resizeObserver = new ResizeObserver(() => {
|
||||
pageSize.set(Math.floor(results.clientHeight / resultSize))
|
||||
})
|
||||
pageSize.set(Math.floor(results.clientHeight / resultSize))
|
||||
resizeObserver.observe(results)
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
resizeObserver?.disconnect()
|
||||
})
|
||||
|
||||
$: searchIndex = $chords?.length > 0 ? buildIndex($chords) : undefined
|
||||
|
||||
function buildIndex(chords: Chord[]): Index {
|
||||
function buildIndex(chords: ChordInfo[]): Index {
|
||||
const index = new Index({tokenize: "full"})
|
||||
chords.forEach((chord, i) => {
|
||||
index.add(i, chord.phrase.map(it => KEYMAP_CODES[it].id).join(""))
|
||||
if ("phrase" in chord) {
|
||||
index.add(i, chord.phrase.map(it => KEYMAP_CODES[it].id).join(""))
|
||||
}
|
||||
})
|
||||
return index
|
||||
}
|
||||
|
||||
let searchFilter: number[] | undefined
|
||||
const searchFilter = writable<number[] | undefined>(undefined)
|
||||
|
||||
function search(event: Event) {
|
||||
const query = (event.target as HTMLInputElement).value
|
||||
searchFilter = query && searchIndex ? searchIndex.search(query) : undefined
|
||||
searchFilter.set(query && searchIndex ? searchIndex.search(query) : undefined)
|
||||
page = 0
|
||||
}
|
||||
|
||||
$: items = searchFilter?.map(it => [$chords[it], it] as const) ?? $chords.map((it, i) => [it, i] as const)
|
||||
function insertChord(actions: number[]) {
|
||||
changes.update(changes => {
|
||||
changes.push({
|
||||
type: ChangeType.Chord,
|
||||
id: actions,
|
||||
actions,
|
||||
phrase: [],
|
||||
})
|
||||
return changes
|
||||
})
|
||||
}
|
||||
|
||||
const items = derived(
|
||||
[searchFilter, chords],
|
||||
([filter, chords]) =>
|
||||
filter?.map(it => [chords[it], it] as const) ?? chords.map((it, i) => [it, i] as const),
|
||||
)
|
||||
const lastPage = derived(
|
||||
[items, pageSize],
|
||||
([items, pageSize]) => Math.ceil((items.length + 1) / pageSize) - 1,
|
||||
)
|
||||
|
||||
setContext("cursor-crossfade", crossfade({}))
|
||||
|
||||
let page = 0
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Chord Manager</title>
|
||||
</svelte:head>
|
||||
|
||||
<div>
|
||||
<div class="search-container">
|
||||
<input
|
||||
type="search"
|
||||
placeholder={$LL.configure.chords.search.PLACEHOLDER($chords.length)}
|
||||
on:input={search}
|
||||
/>
|
||||
<div class="paginator">
|
||||
{#if $lastPage !== -1}
|
||||
{page + 1} / {$lastPage + 1}
|
||||
{:else}
|
||||
- / -
|
||||
{/if}
|
||||
</div>
|
||||
<button class="icon" on:click={() => (page = Math.max(page - 1, 0))} use:action={{shortcut: "ctrl+left"}}
|
||||
>navigate_before</button
|
||||
>
|
||||
<button
|
||||
class="icon"
|
||||
on:click={() => (page = Math.min(page + 1, $lastPage))}
|
||||
use:action={{shortcut: "ctrl+right"}}>navigate_next</button
|
||||
>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
{#if searchIndex}
|
||||
<input
|
||||
on:input={search}
|
||||
type="search"
|
||||
|
||||
/>
|
||||
{/if}-->
|
||||
|
||||
<section>
|
||||
<section bind:this={results}>
|
||||
<table>
|
||||
{#each items.slice(0, 50) as [{ phrase, actions }, i]}
|
||||
<tr style="view-transition-name: chord-{i}">
|
||||
<th>
|
||||
{#each phrase as char}
|
||||
{KEYMAP_CODES[char].id}
|
||||
{/each}
|
||||
</th>
|
||||
<td>
|
||||
{#each actions as action}
|
||||
{@const keyInfo = KEYMAP_CODES[action]}
|
||||
{#if keyInfo}
|
||||
<abbr title={keyInfo.title} class:icon={!!keyInfo.icon}>{keyInfo.icon || keyInfo.id}</abbr>
|
||||
{:else}
|
||||
<pre>{action}</pre>
|
||||
{/if}
|
||||
{/each}
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
{#if page === 0}
|
||||
<tr><th><ChordActionEdit on:submit={({detail}) => insertChord(detail)} /></th><td /><td /></tr>
|
||||
{/if}
|
||||
{#if $lastPage !== -1}
|
||||
{#each $items.slice(page * $pageSize - (page === 0 ? 0 : 1), (page + 1) * $pageSize - 1) as [chord] (JSON.stringify(chord.id))}
|
||||
<tr>
|
||||
<ChordEdit {chord} />
|
||||
</tr>
|
||||
{/each}
|
||||
{:else}
|
||||
<caption> No Results </caption>
|
||||
{/if}
|
||||
</table>
|
||||
</section>
|
||||
|
||||
<style lang="scss">
|
||||
.search-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.paginator {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
min-width: 8ch;
|
||||
}
|
||||
|
||||
caption {
|
||||
margin-top: 156px;
|
||||
}
|
||||
|
||||
input[type="search"] {
|
||||
width: 512px;
|
||||
margin-block-start: 16px;
|
||||
@@ -98,16 +163,11 @@
|
||||
}
|
||||
|
||||
section {
|
||||
--scrollbar-color: var(--md-sys-color-surface-variant);
|
||||
|
||||
scrollbar-gutter: stable;
|
||||
|
||||
position: relative;
|
||||
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
|
||||
height: 100%;
|
||||
padding-inline: 8px;
|
||||
|
||||
border-radius: 16px;
|
||||
@@ -118,35 +178,4 @@
|
||||
min-width: min(90vw, 16.5cm);
|
||||
transition: all 1s ease;
|
||||
}
|
||||
|
||||
table abbr {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
padding-block: 4px;
|
||||
padding-inline: 8px;
|
||||
|
||||
font-size: 16px;
|
||||
font-style: normal;
|
||||
text-decoration: none;
|
||||
|
||||
border: 1px solid var(--md-sys-color-outline);
|
||||
border-radius: 8px;
|
||||
|
||||
&.icon {
|
||||
font-size: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
th {
|
||||
text-align: start;
|
||||
}
|
||||
|
||||
td {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
align-items: stretch;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
</style>
|
||||
|
||||
129
src/routes/config/chords/ChordActionEdit.svelte
Normal file
129
src/routes/config/chords/ChordActionEdit.svelte
Normal file
@@ -0,0 +1,129 @@
|
||||
<script lang="ts">
|
||||
import {KEYMAP_IDS} from "$lib/serial/keymap-codes"
|
||||
import type {ChordInfo} from "$lib/undo-redo"
|
||||
import {changes, ChangeType} from "$lib/undo-redo"
|
||||
import {createEventDispatcher} from "svelte"
|
||||
import LL from "../../../i18n/i18n-svelte"
|
||||
import ActionString from "$lib/components/ActionString.svelte"
|
||||
|
||||
export let chord: ChordInfo | undefined = undefined
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
let pressedKeys = new Set<number>()
|
||||
let editing = false
|
||||
|
||||
function compare(a: number, b: number) {
|
||||
return a - b
|
||||
}
|
||||
|
||||
function edit() {
|
||||
pressedKeys = new Set()
|
||||
editing = true
|
||||
}
|
||||
|
||||
function keydown(event: KeyboardEvent) {
|
||||
if (!editing) return
|
||||
event.preventDefault()
|
||||
pressedKeys.add(KEYMAP_IDS.get(event.key)!.code)
|
||||
pressedKeys = pressedKeys
|
||||
}
|
||||
|
||||
function keyup() {
|
||||
if (!editing) return
|
||||
editing = false
|
||||
if (pressedKeys.size < 2) return
|
||||
if (!chord) return dispatch("submit", [...pressedKeys].sort(compare))
|
||||
changes.update(changes => {
|
||||
changes.push({
|
||||
type: ChangeType.Chord,
|
||||
id: chord!.id,
|
||||
actions: [...pressedKeys].sort(compare),
|
||||
phrase: chord!.phrase,
|
||||
})
|
||||
return changes
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<button
|
||||
class:deleted={chord && chord.phrase.length === 0}
|
||||
class:edited={chord && chord.actionsChanged}
|
||||
class:invalid={chord && chord.actions.toSorted(compare).some((it, i) => chord?.actions[i] !== it)}
|
||||
on:click={edit}
|
||||
on:keydown={keydown}
|
||||
on:keyup={keyup}
|
||||
>
|
||||
{#if editing && pressedKeys.size === 0}
|
||||
<span>{$LL.configure.chords.HOLD_KEYS()}</span>
|
||||
{:else if !editing && !chord}
|
||||
<span>{$LL.configure.chords.NEW_CHORD()}</span>
|
||||
{/if}
|
||||
<ActionString display="keys" actions={editing ? [...pressedKeys].sort(compare) : chord?.actions ?? []} />
|
||||
<sup>•</sup>
|
||||
</button>
|
||||
|
||||
<style lang="scss">
|
||||
span {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
sup {
|
||||
translate: 0 -60%;
|
||||
opacity: 0;
|
||||
transition: opacity 250ms ease;
|
||||
}
|
||||
|
||||
button {
|
||||
position: relative;
|
||||
|
||||
display: inline-flex;
|
||||
gap: 4px;
|
||||
|
||||
height: 32px;
|
||||
margin-inline: 4px;
|
||||
|
||||
&:focus-within {
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
|
||||
button::after {
|
||||
content: "";
|
||||
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform-origin: center left;
|
||||
translate: -6px 0;
|
||||
scale: 0 1;
|
||||
|
||||
width: calc(100% - 32px);
|
||||
height: 1px;
|
||||
|
||||
background: currentcolor;
|
||||
|
||||
transition:
|
||||
scale 250ms ease,
|
||||
color 250ms ease;
|
||||
}
|
||||
|
||||
.edited {
|
||||
color: var(--md-sys-color-primary);
|
||||
|
||||
& > sup {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.invalid {
|
||||
color: var(--md-sys-color-error);
|
||||
}
|
||||
|
||||
.deleted {
|
||||
color: var(--md-sys-color-error);
|
||||
|
||||
&::after {
|
||||
scale: 1;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
97
src/routes/config/chords/ChordEdit.svelte
Normal file
97
src/routes/config/chords/ChordEdit.svelte
Normal file
@@ -0,0 +1,97 @@
|
||||
<script lang="ts">
|
||||
import {changes, ChangeType} from "$lib/undo-redo.js"
|
||||
import type {ChordInfo} from "$lib/undo-redo.js"
|
||||
import ChordPhraseEdit from "./ChordPhraseEdit.svelte"
|
||||
import ChordActionEdit from "./ChordActionEdit.svelte"
|
||||
import type {Chord} from "$lib/serial/chord"
|
||||
import {slide} from "svelte/transition"
|
||||
import {charaFileToUriComponent} from "$lib/share/share-url"
|
||||
import SharePopup from "../SharePopup.svelte"
|
||||
import tippy from "tippy.js"
|
||||
|
||||
export let chord: ChordInfo
|
||||
|
||||
function remove() {
|
||||
changes.update(changes => {
|
||||
changes.push({type: ChangeType.Chord, id: chord.id, actions: chord.actions, phrase: []})
|
||||
return changes
|
||||
})
|
||||
}
|
||||
|
||||
function isSameChord(a: Chord, b: Chord) {
|
||||
return a.actions.length === b.actions.length && a.actions.every((it, i) => it === b.actions[i])
|
||||
}
|
||||
|
||||
function restore() {
|
||||
changes.update(changes => changes.filter(it => !(it.type === ChangeType.Chord && isSameChord(it, chord))))
|
||||
}
|
||||
|
||||
async function share(event: Event) {
|
||||
const url = new URL(window.location.href)
|
||||
url.searchParams.set(
|
||||
"import",
|
||||
await charaFileToUriComponent({
|
||||
charaVersion: 1,
|
||||
type: "chords",
|
||||
chords: [[chord.actions, chord.phrase]],
|
||||
}),
|
||||
)
|
||||
await navigator.clipboard.writeText(url.toString())
|
||||
let shareComponent: SharePopup
|
||||
tippy(event.target as HTMLElement, {
|
||||
onCreate(instance) {
|
||||
const target = instance.popper.querySelector(".tippy-content")!
|
||||
shareComponent = new SharePopup({target})
|
||||
},
|
||||
onHidden(instance) {
|
||||
instance.destroy()
|
||||
},
|
||||
onDestroy(instance) {
|
||||
shareComponent.$destroy()
|
||||
},
|
||||
}).show()
|
||||
}
|
||||
</script>
|
||||
|
||||
<th>
|
||||
<ChordActionEdit {chord} />
|
||||
</th>
|
||||
<td>
|
||||
<ChordPhraseEdit {chord} />
|
||||
</td>
|
||||
<td class="table-buttons">
|
||||
{#if chord.phrase.length !== 0}
|
||||
<button transition:slide class="icon compact" on:click={remove}>delete</button>
|
||||
{:else if chord.phraseChanged}
|
||||
<button transition:slide class="icon compact" on:click={restore}>restore_from_trash</button>
|
||||
{/if}
|
||||
<button class="icon compact" class:disabled={chord.isApplied} on:click={restore}>undo</button>
|
||||
<div class="separator" />
|
||||
<button class="icon compact" on:click={share}>share</button>
|
||||
</td>
|
||||
|
||||
<style lang="scss">
|
||||
.separator {
|
||||
display: inline-flex;
|
||||
|
||||
width: 1px;
|
||||
height: 24px;
|
||||
|
||||
opacity: 0.2;
|
||||
background: currentcolor;
|
||||
}
|
||||
|
||||
td {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.table-buttons {
|
||||
opacity: 0;
|
||||
transition: opacity 75ms ease;
|
||||
}
|
||||
|
||||
:global(tr):focus-within > .table-buttons,
|
||||
:global(tr):hover > .table-buttons {
|
||||
opacity: 1;
|
||||
}
|
||||
</style>
|
||||
247
src/routes/config/chords/ChordPhraseEdit.svelte
Normal file
247
src/routes/config/chords/ChordPhraseEdit.svelte
Normal file
@@ -0,0 +1,247 @@
|
||||
<script lang="ts">
|
||||
import {KEYMAP_IDS, specialKeycodes} from "$lib/serial/keymap-codes"
|
||||
import {tick} from "svelte"
|
||||
import ActionSelector from "$lib/components/layout/ActionSelector.svelte"
|
||||
import {changes, ChangeType} from "$lib/undo-redo"
|
||||
import type {ChordInfo} from "$lib/undo-redo"
|
||||
import {scale} from "svelte/transition"
|
||||
import ActionString from "$lib/components/ActionString.svelte"
|
||||
|
||||
export let chord: ChordInfo
|
||||
|
||||
function keypress(event: KeyboardEvent) {
|
||||
if (event.key === "ArrowUp") {
|
||||
selectAction()
|
||||
} else if (event.key === "ArrowLeft") {
|
||||
moveCursor(cursorPosition - 1)
|
||||
} else if (event.key === "ArrowRight") {
|
||||
moveCursor(cursorPosition + 1)
|
||||
} else if (event.key === "Backspace") {
|
||||
deleteAction(cursorPosition - 1)
|
||||
moveCursor(cursorPosition - 1)
|
||||
} else if (event.key === "Delete") {
|
||||
deleteAction(cursorPosition)
|
||||
} else if (KEYMAP_IDS.has(event.key)) {
|
||||
insertAction(cursorPosition, KEYMAP_IDS.get(event.key)!.code)
|
||||
tick().then(() => moveCursor(cursorPosition + 1))
|
||||
} else if (specialKeycodes.has(event.key)) {
|
||||
insertAction(cursorPosition, specialKeycodes.get(event.key)!)
|
||||
tick().then(() => moveCursor(cursorPosition + 1))
|
||||
}
|
||||
}
|
||||
|
||||
function moveCursor(to: number) {
|
||||
cursorPosition = Math.max(0, Math.min(to, chord.phrase.length))
|
||||
const item = box.children.item(cursorPosition) as HTMLElement
|
||||
cursorOffset = item.offsetLeft + item.offsetWidth
|
||||
}
|
||||
|
||||
function deleteAction(at: number, count = 1) {
|
||||
if (!(at in chord.phrase)) return
|
||||
changes.update(changes => {
|
||||
changes.push({
|
||||
type: ChangeType.Chord,
|
||||
id: chord.id,
|
||||
actions: chord.actions,
|
||||
phrase: chord.phrase.toSpliced(at, count),
|
||||
})
|
||||
return changes
|
||||
})
|
||||
}
|
||||
|
||||
function insertAction(at: number, action: number) {
|
||||
changes.update(changes => {
|
||||
changes.push({
|
||||
type: ChangeType.Chord,
|
||||
id: chord.id,
|
||||
actions: chord.actions,
|
||||
phrase: chord.phrase.toSpliced(at, 0, action),
|
||||
})
|
||||
return changes
|
||||
})
|
||||
}
|
||||
|
||||
function clickCursor(event: MouseEvent) {
|
||||
if (event.target === button) return
|
||||
const distance = (event as unknown as {layerX: number}).layerX
|
||||
|
||||
let i = 0
|
||||
for (const child of box.children) {
|
||||
const {offsetLeft, offsetWidth} = child as HTMLElement
|
||||
if (distance < offsetLeft + offsetWidth / 2) {
|
||||
moveCursor(i - 1)
|
||||
return
|
||||
}
|
||||
i++
|
||||
}
|
||||
moveCursor(i - 1)
|
||||
}
|
||||
|
||||
function selectAction() {
|
||||
const component = new ActionSelector({target: document.body})
|
||||
const dialog = document.querySelector("dialog > div") as HTMLDivElement
|
||||
const backdrop = document.querySelector("dialog") as HTMLDialogElement
|
||||
const dialogRect = dialog.getBoundingClientRect()
|
||||
const groupRect = button.getBoundingClientRect()
|
||||
|
||||
const scale = 0.5
|
||||
const dialogScale = `${1 - scale * (1 - groupRect.width / dialogRect.width)} ${
|
||||
1 - scale * (1 - groupRect.height / dialogRect.height)
|
||||
}`
|
||||
const dialogTranslate = `${scale * (groupRect.x - dialogRect.x)}px ${
|
||||
scale * (groupRect.y - dialogRect.y)
|
||||
}px`
|
||||
|
||||
const duration = 150
|
||||
const options = {duration, easing: "ease"}
|
||||
const dialogAnimation = dialog.animate(
|
||||
[
|
||||
{scale: dialogScale, translate: dialogTranslate},
|
||||
{translate: "0 0", scale: "1"},
|
||||
],
|
||||
options,
|
||||
)
|
||||
const backdropAnimation = backdrop.animate([{opacity: 0}, {opacity: 1}], options)
|
||||
|
||||
async function closed() {
|
||||
dialogAnimation.reverse()
|
||||
backdropAnimation.reverse()
|
||||
|
||||
await dialogAnimation.finished
|
||||
|
||||
component.$destroy()
|
||||
await tick()
|
||||
box.focus()
|
||||
}
|
||||
|
||||
component.$on("close", closed)
|
||||
component.$on("select", ({detail}) => {
|
||||
insertAction(cursorPosition, detail)
|
||||
tick().then(() => moveCursor(cursorPosition + 1))
|
||||
closed()
|
||||
})
|
||||
}
|
||||
|
||||
let button: HTMLButtonElement
|
||||
let box: HTMLDivElement
|
||||
let cursorPosition = 0
|
||||
let cursorOffset = 0
|
||||
|
||||
let hasFocus = false
|
||||
</script>
|
||||
|
||||
<div
|
||||
on:keydown={keypress}
|
||||
on:mousedown={clickCursor}
|
||||
role="textbox"
|
||||
tabindex="0"
|
||||
bind:this={box}
|
||||
class:edited={chord.phrase.length !== 0 && chord.phraseChanged}
|
||||
on:focusin={() => (hasFocus = true)}
|
||||
on:focusout={event => {
|
||||
if (event.relatedTarget !== button) hasFocus = false
|
||||
}}
|
||||
>
|
||||
{#if hasFocus}
|
||||
<div transition:scale class="cursor" style:translate="{cursorOffset}px 0">
|
||||
<button class="icon" bind:this={button} on:click={selectAction}>add</button>
|
||||
</div>
|
||||
{:else}
|
||||
<div />
|
||||
<!-- placeholder for cursor placement -->
|
||||
{/if}
|
||||
<ActionString actions={chord.phrase} />
|
||||
<sup>•</sup>
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
sup {
|
||||
translate: 0 -40%;
|
||||
opacity: 0;
|
||||
transition: opacity 250ms ease;
|
||||
}
|
||||
|
||||
.cursor {
|
||||
position: absolute;
|
||||
transform: translateX(-50%);
|
||||
translate: 0 0;
|
||||
|
||||
width: 2px;
|
||||
height: 100%;
|
||||
|
||||
background: var(--md-sys-color-on-secondary-container);
|
||||
|
||||
transition: translate 50ms ease;
|
||||
|
||||
button {
|
||||
position: absolute;
|
||||
top: -24px;
|
||||
left: 0;
|
||||
|
||||
height: 24px;
|
||||
padding: 0;
|
||||
|
||||
color: var(--md-sys-color-on-secondary-container);
|
||||
|
||||
background: var(--md-sys-color-secondary-container);
|
||||
border: 2px solid currentcolor;
|
||||
border-radius: 12px 12px 12px 0;
|
||||
}
|
||||
}
|
||||
|
||||
.edited {
|
||||
color: var(--md-sys-color-primary);
|
||||
|
||||
sup {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
[role="textbox"] {
|
||||
cursor: text;
|
||||
|
||||
position: relative;
|
||||
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
height: 1em;
|
||||
padding-block: 4px;
|
||||
|
||||
&::after,
|
||||
&::before {
|
||||
content: "";
|
||||
|
||||
position: absolute;
|
||||
bottom: -4px;
|
||||
|
||||
width: 100%;
|
||||
height: 1px;
|
||||
|
||||
opacity: 0;
|
||||
background: currentcolor;
|
||||
|
||||
transition:
|
||||
opacity 150ms ease,
|
||||
scale 250ms ease;
|
||||
}
|
||||
|
||||
&::after {
|
||||
scale: 0 1;
|
||||
transition-duration: 250ms;
|
||||
}
|
||||
|
||||
&:hover::before {
|
||||
opacity: 0.3;
|
||||
}
|
||||
|
||||
&:focus-within {
|
||||
outline: none;
|
||||
|
||||
&::after {
|
||||
scale: 1;
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,23 +1,13 @@
|
||||
<script lang="ts">
|
||||
import {share} from "$lib/share"
|
||||
import {layout} from "$lib/serial/connection"
|
||||
import tippy from "tippy.js"
|
||||
import {onMount} from "svelte"
|
||||
import {setContext} from "svelte"
|
||||
import Layout from "$lib/components/layout/Layout.svelte"
|
||||
import {csvLayoutToJson, isCsvLayout} from "$lib/compat/legacy-layout"
|
||||
import {charaFileFromUriComponent, charaFileToUriComponent} from "$lib/share/share-url"
|
||||
import type {CharaLayoutFile} from "$lib/share/chara-file"
|
||||
import {charaFileToUriComponent} from "$lib/share/share-url"
|
||||
import SharePopup from "../SharePopup.svelte"
|
||||
|
||||
onMount(async () => {
|
||||
const url = new URL(window.location.href)
|
||||
if (url.searchParams.has("import")) {
|
||||
const file = await charaFileFromUriComponent(url.searchParams.get("import")!)
|
||||
if (file.type === "layout") {
|
||||
$layout = file.layout
|
||||
}
|
||||
}
|
||||
})
|
||||
import type {VisualLayoutConfig} from "$lib/components/layout/visual-layout"
|
||||
import {writable} from "svelte/store"
|
||||
import {layout} from "$lib/undo-redo"
|
||||
|
||||
async function shareLayout(event: Event) {
|
||||
const url = new URL(window.location.href)
|
||||
@@ -27,7 +17,7 @@
|
||||
charaVersion: 1,
|
||||
type: "layout",
|
||||
device: "one",
|
||||
layout: $layout,
|
||||
layout: $layout.map(it => it.map(it => it.action)) as [number[], number[], number[]],
|
||||
}),
|
||||
)
|
||||
await navigator.clipboard.writeText(url.toString())
|
||||
@@ -46,36 +36,32 @@
|
||||
}).show()
|
||||
}
|
||||
|
||||
async function importLayout() {
|
||||
const file = await fileInput.files?.item(0)?.text()
|
||||
if (!file) return
|
||||
const importedLayout = isCsvLayout(file) ? csvLayoutToJson(file) : (JSON.parse(file) as CharaLayoutFile)
|
||||
if (importedLayout.type === "layout" && importedLayout.charaVersion === 1) $layout = importedLayout.layout
|
||||
}
|
||||
setContext<VisualLayoutConfig>("visual-layout-config", {
|
||||
scale: 50,
|
||||
inactiveScale: 0.5,
|
||||
inactiveOpacity: 0.4,
|
||||
strokeWidth: 1,
|
||||
margin: 5,
|
||||
fontSize: 9,
|
||||
iconFontSize: 14,
|
||||
})
|
||||
|
||||
let fileInput: HTMLInputElement
|
||||
setContext("active-layer", writable(0))
|
||||
</script>
|
||||
|
||||
<svelte:window use:share={shareLayout} />
|
||||
|
||||
<section>
|
||||
<label class="icon"
|
||||
>upload_file<input
|
||||
bind:this={fileInput}
|
||||
on:input={importLayout}
|
||||
type="file"
|
||||
accept="text/csv, application/json"
|
||||
/></label
|
||||
>
|
||||
<Layout />
|
||||
</section>
|
||||
|
||||
<style lang="scss">
|
||||
section {
|
||||
margin: auto;
|
||||
}
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
input[type="file"] {
|
||||
display: none;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -28,22 +28,36 @@
|
||||
A quick, single key press and release used to indicate a suffix, prefix, or modifier to be associated
|
||||
with a chord.
|
||||
</p>
|
||||
<p>The following keys have special behavior when arpeggiates are enabled:</p>
|
||||
<ul>
|
||||
<li><kbd>,</kbd>, <kbd>;</kbd> and <kbd>:</kbd> will be placed before the auto-inserted space</li>
|
||||
<li>
|
||||
<kbd>.</kbd>, <kbd>?</kbd> and <kbd>!</kbd> will be placed before the auto-inserted space and capitalize
|
||||
the next word
|
||||
</li>
|
||||
<li><kbd>-</kbd> will replace the auto-inserted space</li>
|
||||
</ul>
|
||||
<label
|
||||
>Tolerance<span class="unit"><input type="number" step="1" use:setting={{id: 54}} />ms</span></label
|
||||
>Timeout After Chord<span class="unit"><input type="number" step="1" use:setting={{id: 54}} />ms</span
|
||||
></label
|
||||
>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend><label><input type="checkbox" use:setting={{id: 12}} />Character Entry</label></legend>
|
||||
<legend>Character Entry</legend>
|
||||
{#if $serialPort.device === "LITE"}
|
||||
<label>Swap Keymap 0 and 1<input type="checkbox" use:setting={{id: 13}} /></label>
|
||||
{/if}
|
||||
<label
|
||||
>Key Scan Rate<span class="unit"><input type="number" use:setting={{id: 14, inverse: 1000}} />Hz</span
|
||||
></label
|
||||
<label>
|
||||
Character Entry (chentry)
|
||||
<input type="checkbox" use:setting={{id: 12}} />
|
||||
</label>
|
||||
<label>
|
||||
Key Scan Rate
|
||||
<span class="unit"><input type="number" use:setting={{id: 14, inverse: 1000}} />Hz</span></label
|
||||
>
|
||||
<label
|
||||
>Key Debounce Press<span class="unit"><input type="number" use:setting={{id: 15}} />ms</span></label
|
||||
<label>
|
||||
Key Debounce Press<span class="unit"><input type="number" use:setting={{id: 15}} />ms</span></label
|
||||
>
|
||||
<label
|
||||
>Key Debounce Release<span class="unit"><input type="number" use:setting={{id: 16}} />ms</span></label
|
||||
@@ -93,9 +107,9 @@
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend><label>Device</label></legend>
|
||||
<legend>Device</legend>
|
||||
<label>Boot message<input type="checkbox" use:setting={{id: 93}} /></label>
|
||||
<label>Realtime Feedback<input type="checkbox" use:setting={{id: 92}} /></label>
|
||||
<label>GTM Realtime Feedback<input type="checkbox" use:setting={{id: 92}} /></label>
|
||||
<label>
|
||||
Operating System
|
||||
<select>
|
||||
@@ -114,7 +128,7 @@
|
||||
<fieldset>
|
||||
<legend><label><input type="checkbox" />RGB</label></legend>
|
||||
<label>Brightness<input type="range" min="0" max="50" step="1" /></label>
|
||||
<label>Color</label>
|
||||
Color
|
||||
<label>Reactive Keys<input type="checkbox" /></label>
|
||||
</fieldset>
|
||||
{/if}
|
||||
@@ -123,24 +137,24 @@
|
||||
|
||||
<style lang="scss">
|
||||
form {
|
||||
overflow: hidden;
|
||||
overflow-y: auto;
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
gap: 16px;
|
||||
justify-content: center;
|
||||
|
||||
max-width: 30cm;
|
||||
margin-block: auto;
|
||||
padding-block-end: 48px;
|
||||
}
|
||||
|
||||
legend,
|
||||
legend > label {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
> input {
|
||||
font-size: 12px;
|
||||
}
|
||||
input[type="checkbox"] {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
fieldset {
|
||||
@@ -170,10 +184,6 @@
|
||||
filter: none;
|
||||
}
|
||||
}
|
||||
|
||||
input[type="checkbox"] {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.unit {
|
||||
@@ -221,8 +231,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
ul,
|
||||
p {
|
||||
font-size: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
// stylelint-disable-next-line
|
||||
form label:has(:global(.pending-changes)) {
|
||||
color: var(--md-sys-color-tertiary);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -17,5 +17,6 @@
|
||||
|
||||
width: calc(min(100%, 28cm));
|
||||
height: 100%;
|
||||
margin-block-end: 48px;
|
||||
}
|
||||
</style>
|
||||
|
||||
155
src/routes/vocabulary/+page.svelte
Normal file
155
src/routes/vocabulary/+page.svelte
Normal file
@@ -0,0 +1,155 @@
|
||||
<script lang="ts">
|
||||
import {chords} from "$lib/undo-redo"
|
||||
import Action from "$lib/components/Action.svelte"
|
||||
import {onDestroy, onMount} from "svelte"
|
||||
import {KEYMAP_CODES} from "$lib/serial/keymap-codes"
|
||||
import {fly} from "svelte/transition"
|
||||
import type {Chord} from "$lib/serial/chord"
|
||||
|
||||
const speedRating = [
|
||||
[400, "+100", "excited", true],
|
||||
[700, "+50", "satisfied", true],
|
||||
[1400, "+25", "neutral", true],
|
||||
[3000, "0", "dissatisfied", false],
|
||||
[Infinity, "-50", "sad", false],
|
||||
] as const
|
||||
const accuracyRating = [
|
||||
[2, "+100", "calm", true],
|
||||
[3, "+50", "content", false],
|
||||
[5, "+25", "stressed", false],
|
||||
[7, "0", "frustrated", false],
|
||||
[14, "-25", "very_dissatisfied", false],
|
||||
[Infinity, "-50", "extremely_dissatisfied", false],
|
||||
] as const
|
||||
|
||||
let next: Chord[] = []
|
||||
let nextHandle: number
|
||||
let took: number | undefined
|
||||
let delta = 0
|
||||
|
||||
let speed: readonly [number, string, string, boolean] | undefined
|
||||
let accuracy: readonly [number, string, string, boolean] | undefined
|
||||
let progress = 0
|
||||
|
||||
let attempts = 0
|
||||
|
||||
let userInput = ""
|
||||
|
||||
onMount(() => {
|
||||
runTest()
|
||||
})
|
||||
|
||||
function runTest() {
|
||||
if (took === undefined) {
|
||||
took = performance.now()
|
||||
delta = 0
|
||||
attempts = 0
|
||||
userInput = ""
|
||||
if (next.length === 0) {
|
||||
next = Array.from({length: 5}, () => $chords[Math.floor(Math.random() * $chords.length)])
|
||||
} else {
|
||||
next.shift()
|
||||
next.push($chords[Math.floor(Math.random() * $chords.length)])
|
||||
next = next
|
||||
}
|
||||
}
|
||||
if (userInput === next[0].phrase.map(it => (it === 32 ? " " : KEYMAP_CODES[it]!.id)).join("") + " ") {
|
||||
took = undefined
|
||||
speed = speedRating.find(([max]) => delta <= max)
|
||||
accuracy = accuracyRating.find(([max]) => attempts <= max)
|
||||
progress++
|
||||
} else {
|
||||
delta = performance.now() - took
|
||||
}
|
||||
|
||||
nextHandle = requestAnimationFrame(runTest)
|
||||
}
|
||||
|
||||
let debounceTimer = 0
|
||||
|
||||
function backspace(event: KeyboardEvent) {
|
||||
if (event.code === "Backspace") {
|
||||
userInput = userInput.slice(0, -1)
|
||||
}
|
||||
}
|
||||
|
||||
function input(event: KeyboardEvent) {
|
||||
const stamp = performance.now()
|
||||
if (stamp - debounceTimer > 50) {
|
||||
attempts++
|
||||
}
|
||||
debounceTimer = stamp
|
||||
userInput += event.key
|
||||
}
|
||||
|
||||
onDestroy(() => {
|
||||
if (nextHandle) {
|
||||
cancelAnimationFrame(nextHandle)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<svelte:window on:keydown={backspace} on:keypress={input} />
|
||||
|
||||
<h1>Vocabulary Trainer</h1>
|
||||
|
||||
{#if next[0]}
|
||||
<div class="row">
|
||||
{#key progress}
|
||||
<div in:fly={{duration: 300, x: -48}} out:fly={{duration: 1000, x: 128}} class="rating">
|
||||
{#if speed}
|
||||
<span class="rating-item">
|
||||
<span style:color="var(--md-sys-color-{speed[3] ? `primary` : `error`})" class="icon">timer</span>
|
||||
{speed[1]}
|
||||
<span class="icon">sentiment_{speed[2]}</span>
|
||||
</span>
|
||||
{/if}
|
||||
{#if accuracy}
|
||||
<span class="rating-item">
|
||||
<span style:color="var(--md-sys-color-{accuracy[3] ? `primary` : `error`})" class="icon"
|
||||
>target</span
|
||||
>
|
||||
{accuracy[1]}
|
||||
<span class="icon">sentiment_{accuracy[2]}</span>
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/key}
|
||||
</div>
|
||||
<div class="hint" style:opacity={delta > 3000 ? 1 : 0}>
|
||||
{#each next[0].actions as action}
|
||||
<Action {action} display="keys" />
|
||||
{/each}
|
||||
</div>
|
||||
<div>
|
||||
{userInput}
|
||||
</div>
|
||||
{#each next as chord, i}
|
||||
<div class="words" style:opacity={1 - i / next.length}>
|
||||
{#each chord.phrase as action}
|
||||
<Action {action} />
|
||||
{/each}
|
||||
</div>
|
||||
{/each}
|
||||
{:else}
|
||||
<p>You don't have any chords</p>
|
||||
{/if}
|
||||
|
||||
<style lang="scss">
|
||||
.row {
|
||||
position: relative;
|
||||
height: 48px;
|
||||
}
|
||||
|
||||
.rating-item {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.rating {
|
||||
position: absolute;
|
||||
left: -48px;
|
||||
width: max-content;
|
||||
}
|
||||
</style>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
@@ -13,6 +13,9 @@ const {homepage, bugs} = JSON.parse(
|
||||
await readFile(fileURLToPath(new URL("package.json", import.meta.url)), "utf8"),
|
||||
)
|
||||
|
||||
process.env.VITE_HOMEPAGE_URL = homepage
|
||||
process.env.VITE_BUGS_URL = bugs.url
|
||||
|
||||
export default defineConfig({
|
||||
build: {
|
||||
// we rely on the serial api, so just chrome is fine
|
||||
@@ -21,11 +24,7 @@ export default defineConfig({
|
||||
external: isTauri ? [/virtual:pwa.*/] : [],
|
||||
},
|
||||
},
|
||||
define: {
|
||||
HOMEPAGE_URL: `"${homepage}"`,
|
||||
BUGS_URL: `"${bugs.url}"`,
|
||||
},
|
||||
envPrefix: "TAURI_",
|
||||
envPrefix: ["TAURI_", "VITE_"],
|
||||
plugins: [
|
||||
ViteYaml(),
|
||||
sveltekit(),
|
||||
|
||||
Reference in New Issue
Block a user