@awacloud/fw 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +125 -0
- package/NOTICE +8 -0
- package/README.md +163 -31
- package/dist/build/fw.core.pure.meta.json +6 -6
- package/dist/build/fw.core.pure.min.js +15 -12
- package/dist/build/fw.full.pure.meta.json +13 -7
- package/dist/build/fw.full.pure.min.js +45 -42
- package/dist/build/fw.minimal.pure.meta.json +6 -6
- package/dist/build/fw.minimal.pure.min.js +16 -13
- package/dist/build/fw.pack.compress-heavy.pure.meta.json +6 -6
- package/dist/build/fw.pack.compress-heavy.pure.min.js +3 -3
- package/dist/build/fw.pack.crypto-advanced.pure.meta.json +6 -6
- package/dist/build/fw.pack.crypto-advanced.pure.min.js +1 -1
- package/dist/build/fw.pack.crypto-basic.pure.meta.json +6 -6
- package/dist/build/fw.pack.crypto-basic.pure.min.js +1 -1
- package/dist/build/fw.pack.crypto-identity.pure.meta.json +7 -6
- package/dist/build/fw.pack.crypto-identity.pure.min.js +4 -4
- package/dist/build/fw.pwa.pure.meta.json +7 -6
- package/dist/build/fw.pwa.pure.min.js +38 -35
- package/dist/build/fw.site-interactive.pure.meta.json +6 -6
- package/dist/build/fw.site-interactive.pure.min.js +37 -34
- package/dist/build/fw.site.pure.meta.json +6 -6
- package/dist/build/fw.site.pure.min.js +24 -21
- package/dist/build/fw.spa.pure.meta.json +8 -7
- package/dist/build/fw.spa.pure.min.js +41 -38
- package/dist/build/sanity-base-classic.min.js +1 -1
- package/dist/build/sanity.min.js +1 -1
- package/dist/types/core/internal.d.ts +29 -0
- package/dist/types/core/internal.d.ts.map +1 -0
- package/dist/types/core/logger.d.ts +23 -4
- package/dist/types/core/logger.d.ts.map +1 -1
- package/dist/types/core/modules.d.ts +374 -61
- package/dist/types/core/modules.d.ts.map +1 -1
- package/dist/types/core/runtime.d.ts +10 -6
- package/dist/types/core/runtime.d.ts.map +1 -1
- package/dist/types/core/worker-helper.d.ts +35 -0
- package/dist/types/core/worker-helper.d.ts.map +1 -1
- package/dist/types/crypto/cipher/aes.d.ts +1 -7
- package/dist/types/crypto/cipher/aes.d.ts.map +1 -1
- package/dist/types/crypto/cipher/chacha20.d.ts +0 -10
- package/dist/types/crypto/cipher/chacha20.d.ts.map +1 -1
- package/dist/types/crypto/hash/argon2.d.ts +0 -15
- package/dist/types/crypto/hash/argon2.d.ts.map +1 -1
- package/dist/types/crypto/hash/blake2b.d.ts.map +1 -1
- package/dist/types/crypto/hash/hmac.d.ts.map +1 -1
- package/dist/types/crypto/hash/pbkdf2.d.ts.map +1 -1
- package/dist/types/crypto/hash/poly1305.d.ts.map +1 -1
- package/dist/types/crypto/hash/sha224.d.ts +1 -1
- package/dist/types/crypto/hash/sha256.d.ts +4 -13
- package/dist/types/crypto/hash/sha256.d.ts.map +1 -1
- package/dist/types/crypto/hash/sha3.d.ts.map +1 -1
- package/dist/types/crypto/hash/sha384.d.ts +1 -1
- package/dist/types/crypto/hash/sha512.d.ts +4 -13
- package/dist/types/crypto/hash/sha512.d.ts.map +1 -1
- package/dist/types/crypto/mode/cmac.d.ts +0 -6
- package/dist/types/crypto/mode/cmac.d.ts.map +1 -1
- package/dist/types/crypto/mode/ctr.d.ts +0 -6
- package/dist/types/crypto/mode/ctr.d.ts.map +1 -1
- package/dist/types/crypto/mode/gcm.d.ts +0 -9
- package/dist/types/crypto/mode/gcm.d.ts.map +1 -1
- package/dist/types/crypto/pkc/ecc.d.ts +0 -1
- package/dist/types/crypto/pkc/ecc.d.ts.map +1 -1
- package/dist/types/crypto/pkc/ed25519.d.ts +4 -25
- package/dist/types/crypto/pkc/ed25519.d.ts.map +1 -1
- package/dist/types/crypto/pkc/hybridSign.d.ts +25 -5
- package/dist/types/crypto/pkc/hybridSign.d.ts.map +1 -1
- package/dist/types/crypto/pkc/ml_dsa.d.ts +6 -26
- package/dist/types/crypto/pkc/ml_dsa.d.ts.map +1 -1
- package/dist/types/crypto/pkc/ml_kem.d.ts +0 -43
- package/dist/types/crypto/pkc/ml_kem.d.ts.map +1 -1
- package/dist/types/crypto/pkc/rsa.d.ts +0 -24
- package/dist/types/crypto/pkc/rsa.d.ts.map +1 -1
- package/dist/types/crypto/pkc/slh_dsa.d.ts +6 -16
- package/dist/types/crypto/pkc/slh_dsa.d.ts.map +1 -1
- package/dist/types/crypto/pkc/x25519.d.ts +0 -6
- package/dist/types/crypto/pkc/x25519.d.ts.map +1 -1
- package/dist/types/crypto/utils/bitArray.d.ts +0 -8
- package/dist/types/crypto/utils/bitArray.d.ts.map +1 -1
- package/dist/types/crypto/utils/jws.d.ts +6 -14
- package/dist/types/crypto/utils/jws.d.ts.map +1 -1
- package/dist/types/crypto/utils/keyformat.d.ts +52 -0
- package/dist/types/crypto/utils/keyformat.d.ts.map +1 -1
- package/dist/types/crypto/utils/random.d.ts +1 -10
- package/dist/types/crypto/utils/random.d.ts.map +1 -1
- package/dist/types/crypto/utils/rsaKeygen.d.ts +0 -10
- package/dist/types/crypto/utils/rsaKeygen.d.ts.map +1 -1
- package/dist/types/crypto/utils/uuid.d.ts.map +1 -1
- package/dist/types/crypto/utils/x509.d.ts +397 -0
- package/dist/types/crypto/utils/x509.d.ts.map +1 -0
- package/dist/types/crypto/wasm/argon2.d.ts +2 -1
- package/dist/types/crypto/wasm/argon2.d.ts.map +1 -1
- package/dist/types/crypto/wasm/pbkdf2.d.ts +2 -2
- package/dist/types/crypto/wasm/pbkdf2.d.ts.map +1 -1
- package/dist/types/crypto/wasm/rsa.d.ts.map +1 -1
- package/dist/types/crypto/wasm/runtime.d.ts +13 -0
- package/dist/types/crypto/wasm/runtime.d.ts.map +1 -1
- package/dist/types/crypto/webcrypto/aes.d.ts.map +1 -1
- package/dist/types/crypto/webcrypto/aeskw.d.ts.map +1 -1
- package/dist/types/crypto/webcrypto/digest.d.ts +0 -4
- package/dist/types/crypto/webcrypto/digest.d.ts.map +1 -1
- package/dist/types/crypto/webcrypto/rsa.d.ts.map +1 -1
- package/dist/types/dom/fs/fileIntake.d.ts +59 -0
- package/dist/types/dom/fs/fileIntake.d.ts.map +1 -0
- package/dist/types/dom/fs/fsAccess.d.ts.map +1 -1
- package/dist/types/dom/query/dnd.d.ts.map +1 -1
- package/dist/types/dom/query/sound.d.ts +89 -0
- package/dist/types/dom/query/sound.d.ts.map +1 -0
- package/dist/types/dom/rendering/chart.d.ts.map +1 -1
- package/dist/types/dom/rendering/component.d.ts +9 -3
- package/dist/types/dom/rendering/component.d.ts.map +1 -1
- package/dist/types/dom/rendering/parser.d.ts +39 -0
- package/dist/types/dom/rendering/parser.d.ts.map +1 -1
- package/dist/types/dom/rendering/render.d.ts.map +1 -1
- package/dist/types/dom/rendering/sanitize.d.ts +4 -0
- package/dist/types/dom/rendering/sanitize.d.ts.map +1 -1
- package/dist/types/dom/rendering/secPolicy.d.ts.map +1 -1
- package/dist/types/dom/rendering/styleSheet.d.ts +74 -0
- package/dist/types/dom/rendering/styleSheet.d.ts.map +1 -0
- package/dist/types/dom/rendering/template.d.ts +9 -3
- package/dist/types/dom/rendering/template.d.ts.map +1 -1
- package/dist/types/dom/rendering/themeTokens.d.ts +9 -3
- package/dist/types/dom/rendering/themeTokens.d.ts.map +1 -1
- package/dist/types/dom/rendering/uiSession-core.d.ts +9 -3
- package/dist/types/dom/rendering/uiSession-core.d.ts.map +1 -1
- package/dist/types/dom/rendering/uiSession-list.d.ts +9 -3
- package/dist/types/dom/rendering/uiSession-list.d.ts.map +1 -1
- package/dist/types/dom/rendering/uiSession.d.ts +18 -6
- package/dist/types/dom/rendering/uiSession.d.ts.map +1 -1
- package/dist/types/dom/sw/installPrompt.d.ts +89 -0
- package/dist/types/dom/sw/installPrompt.d.ts.map +1 -0
- package/dist/types/dom/sw/precache.d.ts +149 -0
- package/dist/types/dom/sw/precache.d.ts.map +1 -0
- package/dist/types/dom/sw/swUpdate.d.ts +129 -0
- package/dist/types/dom/sw/swUpdate.d.ts.map +1 -0
- package/dist/types/dom/utils/clipboard.d.ts +8 -0
- package/dist/types/dom/utils/clipboard.d.ts.map +1 -1
- package/dist/types/dom/utils/keybindings.d.ts.map +1 -1
- package/dist/types/dom/utils/route.d.ts.map +1 -1
- package/dist/types/dom/utils/ua.d.ts +2 -2
- package/dist/types/dom/utils/ua.d.ts.map +1 -1
- package/dist/types/io/calc/crc32.d.ts.map +1 -1
- package/dist/types/io/codec/b64.d.ts +24 -0
- package/dist/types/io/codec/b64.d.ts.map +1 -1
- package/dist/types/io/codec/cbor.d.ts +1 -0
- package/dist/types/io/codec/cbor.d.ts.map +1 -1
- package/dist/types/io/codec/hex.d.ts.map +1 -1
- package/dist/types/io/codec/msgpack.d.ts +1 -0
- package/dist/types/io/codec/msgpack.d.ts.map +1 -1
- package/dist/types/io/codec/url.d.ts +3 -1
- package/dist/types/io/codec/url.d.ts.map +1 -1
- package/dist/types/io/codec/utf8.d.ts.map +1 -1
- package/dist/types/io/compress/bitstream.d.ts +1 -1
- package/dist/types/io/compress/brotli.d.ts +0 -1
- package/dist/types/io/compress/brotli.d.ts.map +1 -1
- package/dist/types/io/compress/brotli_shared.d.ts +0 -4
- package/dist/types/io/compress/brotli_shared.d.ts.map +1 -1
- package/dist/types/io/compress/deflate.d.ts +14 -1
- package/dist/types/io/compress/deflate.d.ts.map +1 -1
- package/dist/types/io/compress/gzip.d.ts +4 -0
- package/dist/types/io/compress/gzip.d.ts.map +1 -1
- package/dist/types/io/compress/huffman.d.ts +7 -0
- package/dist/types/io/compress/huffman.d.ts.map +1 -1
- package/dist/types/io/compress/lz4.d.ts +4 -2
- package/dist/types/io/compress/lz4.d.ts.map +1 -1
- package/dist/types/io/compress/lz77.d.ts +17 -0
- package/dist/types/io/compress/lz77.d.ts.map +1 -1
- package/dist/types/io/compress/lzw.d.ts +2 -0
- package/dist/types/io/compress/lzw.d.ts.map +1 -1
- package/dist/types/io/compress/zip.d.ts.map +1 -1
- package/dist/types/io/compress/zlib.d.ts +9 -2
- package/dist/types/io/compress/zlib.d.ts.map +1 -1
- package/dist/types/io/math/linalg.d.ts.map +1 -1
- package/dist/types/process/rpc.d.ts.map +1 -1
- package/dist/types/process/workerPool.d.ts.map +1 -1
- package/dist/types/sanity/base.d.ts +12 -2
- package/dist/types/sanity/base.d.ts.map +1 -1
- package/dist/types/sanity/lockdown.d.ts +6 -5
- package/dist/types/sanity/lockdown.d.ts.map +1 -1
- package/dist/types/sanity/wasm-gate.d.ts +1 -1
- package/docs/README.md +17 -10
- package/docs/api/README.md +5 -5
- package/docs/api/core/logger.md +2 -1
- package/docs/api/core/modules.md +3 -3
- package/docs/api/core/runtime.md +9 -9
- package/docs/api/core/worker-helper.md +12 -2
- package/docs/api/crypto/README.md +1 -1
- package/docs/api/crypto/cipher/README.md +2 -2
- package/docs/api/crypto/cipher/aes.md +5 -10
- package/docs/api/crypto/cipher/chacha20.md +3 -8
- package/docs/api/crypto/hash/README.md +5 -5
- package/docs/api/crypto/hash/adf.md +21 -11
- package/docs/api/crypto/hash/argon2.md +3 -12
- package/docs/api/crypto/hash/blake2b.md +12 -14
- package/docs/api/crypto/hash/pbkdf2.md +1 -1
- package/docs/api/crypto/hash/sha224.md +2 -2
- package/docs/api/crypto/hash/sha256.md +4 -4
- package/docs/api/crypto/hash/sha3.md +2 -2
- package/docs/api/crypto/hash/sha384.md +1 -1
- package/docs/api/crypto/hash/sha512.md +5 -5
- package/docs/api/crypto/hash/sha512_224.md +1 -1
- package/docs/api/crypto/hash/sha512_256.md +1 -1
- package/docs/api/crypto/mode/README.md +3 -3
- package/docs/api/crypto/mode/cbc.md +2 -2
- package/docs/api/crypto/mode/chacha20poly1305.md +1 -1
- package/docs/api/crypto/mode/cmac.md +4 -4
- package/docs/api/crypto/mode/ctr.md +2 -3
- package/docs/api/crypto/mode/gcm.md +5 -5
- package/docs/api/crypto/mode/kw.md +4 -4
- package/docs/api/crypto/pkc/README.md +8 -8
- package/docs/api/crypto/pkc/ecc.md +19 -17
- package/docs/api/crypto/pkc/ed25519.md +10 -15
- package/docs/api/crypto/pkc/hybridKem.md +8 -2
- package/docs/api/crypto/pkc/hybridSign.md +34 -7
- package/docs/api/crypto/pkc/ml_dsa.md +20 -19
- package/docs/api/crypto/pkc/ml_kem.md +3 -3
- package/docs/api/crypto/pkc/rsa.md +7 -9
- package/docs/api/crypto/pkc/slh_dsa.md +12 -12
- package/docs/api/crypto/pkc/x25519.md +5 -4
- package/docs/api/crypto/utils/README.md +7 -7
- package/docs/api/crypto/utils/aes_modes.md +2 -5
- package/docs/api/crypto/utils/asn1.md +25 -16
- package/docs/api/crypto/utils/jws.md +6 -4
- package/docs/api/crypto/utils/keyformat.md +24 -15
- package/docs/api/crypto/utils/pad.md +1 -1
- package/docs/api/crypto/utils/pem.md +3 -3
- package/docs/api/crypto/utils/random.md +3 -4
- package/docs/api/crypto/utils/rsaKeygen.md +2 -2
- package/docs/api/crypto/utils/totp.md +2 -2
- package/docs/api/crypto/utils/uuid.md +5 -5
- package/docs/api/crypto/utils/x509.md +124 -0
- package/docs/api/crypto/wasm/aes.md +1 -1
- package/docs/api/crypto/wasm/argon2.md +6 -4
- package/docs/api/crypto/wasm/ml_kem.md +1 -0
- package/docs/api/crypto/wasm/pbkdf2.md +8 -8
- package/docs/api/crypto/wasm/rsa.md +1 -1
- package/docs/api/crypto/wasm/runtime.md +27 -10
- package/docs/api/crypto/webcrypto/aes.md +1 -1
- package/docs/api/crypto/webcrypto/aeskw.md +2 -2
- package/docs/api/crypto/webcrypto/digest.md +3 -5
- package/docs/api/crypto/webcrypto/ecc.md +1 -1
- package/docs/api/crypto/webcrypto/ed25519.md +1 -1
- package/docs/api/crypto/webcrypto/rsa.md +3 -2
- package/docs/api/crypto/webcrypto/x25519.md +1 -1
- package/docs/api/dom/README.md +6 -1
- package/docs/api/dom/fs/README.md +1 -0
- package/docs/api/dom/fs/fileIntake.md +120 -0
- package/docs/api/dom/fs/fsAccess.md +1 -0
- package/docs/api/dom/fs/indexedDB.md +1 -1
- package/docs/api/dom/fs/storage.md +1 -1
- package/docs/api/dom/query/README.md +2 -1
- package/docs/api/dom/query/dnd.md +4 -1
- package/docs/api/dom/query/dom.md +5 -0
- package/docs/api/dom/query/sound.md +103 -0
- package/docs/api/dom/rendering/README.md +4 -3
- package/docs/api/dom/rendering/chart.md +5 -4
- package/docs/api/dom/rendering/component.md +25 -3
- package/docs/api/dom/rendering/parser.md +5 -2
- package/docs/api/dom/rendering/reactiveBind.md +1 -1
- package/docs/api/dom/rendering/render.md +2 -2
- package/docs/api/dom/rendering/sanitize.md +10 -2
- package/docs/api/dom/rendering/secPolicy.md +4 -4
- package/docs/api/dom/rendering/styleSheet.md +85 -0
- package/docs/api/dom/rendering/template.md +20 -5
- package/docs/api/dom/rendering/themeTokens.md +6 -3
- package/docs/api/dom/rendering/uiSession.md +18 -5
- package/docs/api/dom/rendering/virtualScroll.md +2 -2
- package/docs/api/dom/sensors/geolocation.md +1 -1
- package/docs/api/dom/sw/README.md +7 -1
- package/docs/api/dom/sw/cache.md +2 -1
- package/docs/api/dom/sw/installPrompt.md +111 -0
- package/docs/api/dom/sw/precache.md +124 -0
- package/docs/api/dom/sw/serviceWorker.md +4 -2
- package/docs/api/dom/sw/swUpdate.md +112 -0
- package/docs/api/dom/utils/clipboard.md +56 -5
- package/docs/api/dom/utils/entropyCollector.md +1 -1
- package/docs/api/dom/utils/keybindings.md +17 -2
- package/docs/api/dom/utils/leaderElection.md +2 -2
- package/docs/api/dom/utils/route.md +1 -0
- package/docs/api/dom/utils/ua.md +15 -10
- package/docs/api/io/calc/crc32.md +4 -1
- package/docs/api/io/codec/README.md +2 -2
- package/docs/api/io/codec/b64.md +31 -2
- package/docs/api/io/codec/buffer.md +1 -1
- package/docs/api/io/codec/cbor.md +6 -4
- package/docs/api/io/codec/csv.md +178 -178
- package/docs/api/io/codec/hex.md +10 -2
- package/docs/api/io/codec/msgpack.md +4 -3
- package/docs/api/io/codec/url.md +4 -3
- package/docs/api/io/codec/utf8.md +3 -3
- package/docs/api/io/compress/bitstream.md +6 -3
- package/docs/api/io/compress/brotli.md +36 -4
- package/docs/api/io/compress/brotli_shared.md +1 -1
- package/docs/api/io/compress/deflate.md +42 -34
- package/docs/api/io/compress/gzip.md +26 -6
- package/docs/api/io/compress/huffman.md +2 -1
- package/docs/api/io/compress/lz4.md +5 -3
- package/docs/api/io/compress/lz77.md +26 -3
- package/docs/api/io/compress/lzw.md +13 -8
- package/docs/api/io/compress/zip.md +36 -10
- package/docs/api/io/compress/zlib.md +21 -5
- package/docs/api/io/math/linalg.md +1 -1
- package/docs/api/io/utils/valid.md +1 -1
- package/docs/api/process/rpc.md +3 -2
- package/docs/api/process/workerPool.md +1 -1
- package/docs/api/sanity/base.md +9 -5
- package/docs/api/sanity/lockdown.md +7 -6
- package/docs/api/surface.json +12311 -0
- package/docs/api/typed.md +5 -3
- package/docs/dev/README.md +2 -0
- package/docs/dev/bench.md +76 -0
- package/docs/dev/crypto-references.md +54 -0
- package/docs/dev/provenance.md +30 -7
- package/docs/dev/publishing.md +7 -7
- package/docs/dev/runtime.md +1 -1
- package/docs/dev/testing.md +13 -0
- package/docs/evidence/l4-evidence.md +86 -0
- package/docs/evidence/pqc-hybrid-evidence.md +7 -6
- package/docs/guide/README.md +1 -0
- package/docs/guide/_QUICK_REF.md +5 -5
- package/docs/guide/doc-format.md +4 -3
- package/docs/guide/integrations-hmr.md +1 -1
- package/docs/guide/module-creation-workflow.md +8 -8
- package/docs/guide/rendering-pipeline.md +11 -4
- package/docs/guide/security.md +7 -5
- package/docs/guide/stability.md +123 -0
- package/docs/guide/tutorial-todo.md +20 -8
- package/docs/guide/typescript.md +9 -0
- package/docs/guide/worker-confinement.md +30 -17
- package/docs/notes/lz77-deflate-factorization.md +3 -3
- package/docs/tools/README.md +1 -1
- package/docs/tools/bundler.md +3 -3
- package/docs/tools/codegen.md +1 -1
- package/docs/tools/standalone.md +0 -1
- package/fw.config.json +2 -2
- package/integrations/_shared/catalog.generated.json +7 -1
- package/integrations/_shared/core.js +1 -1
- package/integrations/astro/index.js +1 -1
- package/integrations/eslint/README.md +7 -1
- package/integrations/nextjs/index.js +1 -1
- package/integrations/nodejs/README.md +3 -3
- package/integrations/turbopack/index.js +2 -2
- package/integrations/typedoc/categorize.js +1 -1
- package/integrations/typedoc/typedoc.json +2 -1
- package/integrations/vite/index.js +2 -2
- package/integrations/vite/vite-env.d.ts +7 -4
- package/integrations/webpack/index.js +3 -3
- package/package.json +76 -10
- package/src/core/internal.js +31 -0
- package/src/core/logger.js +95 -23
- package/src/core/modules.js +17 -8
- package/src/core/readyState.js +1 -1
- package/src/core/runtime.js +74 -27
- package/src/core/worker-helper.js +83 -4
- package/src/crypto/NIST_CONFORMANCE.md +47 -34
- package/src/crypto/cipher/aes.acvp.md +7 -8
- package/src/crypto/cipher/aes.js +280 -229
- package/src/crypto/cipher/chacha20.acvp.md +6 -7
- package/src/crypto/cipher/chacha20.js +91 -61
- package/src/crypto/hash/adf.js +1 -1
- package/src/crypto/hash/argon2.acvp.md +11 -15
- package/src/crypto/hash/argon2.js +9 -24
- package/src/crypto/hash/blake2b.js +157 -125
- package/src/crypto/hash/hkdf.acvp.md +15 -15
- package/src/crypto/hash/hkdf.js +1 -1
- package/src/crypto/hash/hmac.acvp.md +10 -12
- package/src/crypto/hash/hmac.js +5 -1
- package/src/crypto/hash/pbkdf2.acvp.md +13 -13
- package/src/crypto/hash/pbkdf2.js +36 -8
- package/src/crypto/hash/poly1305.acvp.md +10 -6
- package/src/crypto/hash/poly1305.js +171 -50
- package/src/crypto/hash/sha224.acvp.md +3 -3
- package/src/crypto/hash/sha224.js +4 -4
- package/src/crypto/hash/sha256.acvp.md +2 -2
- package/src/crypto/hash/sha256.js +514 -50
- package/src/crypto/hash/sha3.acvp.md +9 -9
- package/src/crypto/hash/sha3.js +127 -71
- package/src/crypto/hash/sha384.acvp.md +3 -3
- package/src/crypto/hash/sha384.js +4 -4
- package/src/crypto/hash/sha512.acvp.md +7 -8
- package/src/crypto/hash/sha512.js +107 -108
- package/src/crypto/hash/sha512_224.acvp.md +6 -6
- package/src/crypto/hash/sha512_224.js +2 -2
- package/src/crypto/hash/sha512_256.acvp.md +6 -6
- package/src/crypto/hash/sha512_256.js +2 -2
- package/src/crypto/mode/cbc.acvp.md +2 -2
- package/src/crypto/mode/cbc.js +1 -1
- package/src/crypto/mode/chacha20poly1305.acvp.md +6 -6
- package/src/crypto/mode/chacha20poly1305.js +3 -3
- package/src/crypto/mode/cmac.acvp.md +5 -5
- package/src/crypto/mode/cmac.js +8 -8
- package/src/crypto/mode/ctr.acvp.md +2 -2
- package/src/crypto/mode/ctr.js +1 -3
- package/src/crypto/mode/gcm.acvp.md +6 -6
- package/src/crypto/mode/gcm.js +7 -7
- package/src/crypto/mode/kw.acvp.md +4 -4
- package/src/crypto/mode/kw.js +5 -5
- package/src/crypto/pkc/ecc.acvp.md +13 -13
- package/src/crypto/pkc/ecc.js +9 -11
- package/src/crypto/pkc/ed25519.acvp.md +30 -34
- package/src/crypto/pkc/ed25519.js +453 -94
- package/src/crypto/pkc/hybrid-kat.provenance.md +4 -4
- package/src/crypto/pkc/hybridSign.js +103 -24
- package/src/crypto/pkc/ml_dsa.acvp.md +18 -18
- package/src/crypto/pkc/ml_dsa.js +29 -32
- package/src/crypto/pkc/ml_kem.acvp.md +7 -7
- package/src/crypto/pkc/ml_kem.js +15 -21
- package/src/crypto/pkc/rsa.acvp.md +11 -15
- package/src/crypto/pkc/rsa.js +7 -44
- package/src/crypto/pkc/slh_dsa.acvp.md +16 -16
- package/src/crypto/pkc/slh_dsa.js +16 -18
- package/src/crypto/pkc/x25519.acvp.md +13 -10
- package/src/crypto/pkc/x25519.js +273 -29
- package/src/crypto/utils/aes_modes.acvp.md +1 -2
- package/src/crypto/utils/aes_modes.js +2 -2
- package/src/crypto/utils/asn1-oid.js +1 -1
- package/src/crypto/utils/asn1.js +1 -1
- package/src/crypto/utils/bitArray.js +33 -48
- package/src/crypto/utils/bn.js +1 -1
- package/src/crypto/utils/jws.js +37 -41
- package/src/crypto/utils/keyformat.js +181 -2
- package/src/crypto/utils/pem.js +1 -1
- package/src/crypto/utils/random.acvp.md +5 -5
- package/src/crypto/utils/random.js +845 -846
- package/src/crypto/utils/rsaKeygen.acvp.md +3 -2
- package/src/crypto/utils/rsaKeygen.js +6 -6
- package/src/crypto/utils/totp.js +1 -1
- package/src/crypto/utils/uuid.acvp.md +5 -5
- package/src/crypto/utils/uuid.js +11 -10
- package/src/crypto/utils/x509.js +591 -0
- package/src/crypto/wasm/aes.js +1 -1
- package/src/crypto/wasm/aes.scalar.wasm +0 -0
- package/src/crypto/wasm/argon2.js +17 -1
- package/src/crypto/wasm/argon2.scalar.wasm +0 -0
- package/src/crypto/wasm/blake2b.scalar.wasm +0 -0
- package/src/crypto/wasm/blake2b.simd.wasm +0 -0
- package/src/crypto/wasm/chacha20poly1305.scalar.wasm +0 -0
- package/src/crypto/wasm/chacha20poly1305.simd.wasm +0 -0
- package/src/crypto/wasm/cmac.scalar.wasm +0 -0
- package/src/crypto/wasm/ecc.js +3 -3
- package/src/crypto/wasm/ecc.scalar.wasm +0 -0
- package/src/crypto/wasm/ed25519.js +1 -1
- package/src/crypto/wasm/ed25519.scalar.wasm +0 -0
- package/src/crypto/wasm/hkdf.scalar.wasm +0 -0
- package/src/crypto/wasm/hmac.scalar.wasm +0 -0
- package/src/crypto/wasm/ml_dsa.js +2 -2
- package/src/crypto/wasm/ml_dsa.scalar.wasm +0 -0
- package/src/crypto/wasm/ml_dsa.simd.wasm +0 -0
- package/src/crypto/wasm/ml_kem.js +2 -2
- package/src/crypto/wasm/ml_kem.scalar.wasm +0 -0
- package/src/crypto/wasm/ml_kem.simd.wasm +0 -0
- package/src/crypto/wasm/pbkdf2.js +8 -6
- package/src/crypto/wasm/pbkdf2.scalar.wasm +0 -0
- package/src/crypto/wasm/rsa.js +6 -5
- package/src/crypto/wasm/rsa.scalar.wasm +0 -0
- package/src/crypto/wasm/runtime.js +84 -17
- package/src/crypto/wasm/sha2.scalar.wasm +0 -0
- package/src/crypto/wasm/sha3.scalar.wasm +0 -0
- package/src/crypto/wasm/sha3.simd.wasm +0 -0
- package/src/crypto/wasm/slh_dsa.js +1 -1
- package/src/crypto/wasm/slh_dsa.scalar.wasm +0 -0
- package/src/crypto/wasm/x25519.js +1 -1
- package/src/crypto/wasm/x25519.scalar.wasm +0 -0
- package/src/crypto/webcrypto/aes.js +8 -2
- package/src/crypto/webcrypto/aeskw.js +7 -2
- package/src/crypto/webcrypto/digest.js +1 -15
- package/src/crypto/webcrypto/ecc.js +2 -2
- package/src/crypto/webcrypto/ed25519.js +2 -2
- package/src/crypto/webcrypto/hmac.js +2 -2
- package/src/crypto/webcrypto/rsa.js +7 -2
- package/src/crypto/webcrypto/x25519.js +2 -2
- package/src/dom/display/animate.js +1 -1
- package/src/dom/display/fullscreen.js +1 -1
- package/src/dom/fs/download.js +1 -1
- package/src/dom/fs/fileIntake.js +192 -0
- package/src/dom/fs/fsAccess.js +2 -3
- package/src/dom/fs/indexedDB.js +1 -1
- package/src/dom/fs/remoteStore.js +1 -1
- package/src/dom/fs/storage.js +1 -1
- package/src/dom/lifecycle/idle.js +1 -1
- package/src/dom/lifecycle/visibility.js +1 -1
- package/src/dom/lifecycle/wakeLock.js +1 -1
- package/src/dom/net/ajax.js +1 -1
- package/src/dom/net/network.js +1 -1
- package/src/dom/net/sse.js +1 -1
- package/src/dom/net/webrtc.js +1 -1
- package/src/dom/net/ws.js +1 -1
- package/src/dom/query/dnd.js +56 -4
- package/src/dom/query/dom.js +1 -1
- package/src/dom/query/events.js +1 -1
- package/src/dom/query/gesture.js +1 -1
- package/src/dom/query/media.js +1 -1
- package/src/dom/query/sound.js +333 -0
- package/src/dom/rendering/chart.js +736 -663
- package/src/dom/rendering/component.js +25 -14
- package/src/dom/rendering/devtools.js +2 -2
- package/src/dom/rendering/parser.js +155 -12
- package/src/dom/rendering/render.js +14 -4
- package/src/dom/rendering/sanitize.js +11 -4
- package/src/dom/rendering/secPolicy.js +6 -4
- package/src/dom/rendering/styleSheet.js +217 -0
- package/src/dom/rendering/template.js +72 -13
- package/src/dom/rendering/themeTokens.js +542 -522
- package/src/dom/rendering/uiSession-core.js +51 -6
- package/src/dom/rendering/uiSession-direct.js +1 -1
- package/src/dom/rendering/uiSession-list.js +4 -4
- package/src/dom/rendering/uiSession.js +1 -1
- package/src/dom/rendering/virtualScroll.js +341 -341
- package/src/dom/sensors/battery.js +1 -1
- package/src/dom/sensors/geolocation.js +1 -1
- package/src/dom/sensors/networkInfo.js +1 -1
- package/src/dom/sensors/sensors.js +1 -1
- package/src/dom/sw/backgroundSync.js +1 -1
- package/src/dom/sw/cache.js +1 -1
- package/src/dom/sw/installPrompt.js +151 -0
- package/src/dom/sw/precache.js +257 -0
- package/src/dom/sw/push.js +1 -1
- package/src/dom/sw/sharedWorker.js +1 -1
- package/src/dom/sw/swUpdate.js +239 -0
- package/src/dom/utils/a11y.js +1 -1
- package/src/dom/utils/clipboard.js +56 -6
- package/src/dom/utils/entropyCollector.js +1 -1
- package/src/dom/utils/focus.js +1 -1
- package/src/dom/utils/form.js +1 -1
- package/src/dom/utils/keybindings.js +600 -574
- package/src/dom/utils/leaderElection.js +1 -1
- package/src/dom/utils/notifications.js +1 -1
- package/src/dom/utils/permissions.js +107 -107
- package/src/dom/utils/route.js +14 -2
- package/src/dom/utils/ua.js +42 -28
- package/src/dom/utils/webauthn.js +1 -1
- package/src/io/binary/reader.js +1 -1
- package/src/io/binary/writer.js +1 -1
- package/src/io/calc/bigint.js +1 -1
- package/src/io/calc/crc32.js +28 -2
- package/src/io/calc/easing.js +514 -514
- package/src/io/codec/b64.js +189 -52
- package/src/io/codec/base32.js +1 -1
- package/src/io/codec/base58.js +1 -1
- package/src/io/codec/buffer.js +1 -1
- package/src/io/codec/cbor.js +111 -18
- package/src/io/codec/csv.js +1 -1
- package/src/io/codec/hex.js +51 -6
- package/src/io/codec/mime.js +1 -1
- package/src/io/codec/msgpack.js +47 -6
- package/src/io/codec/url.js +24 -7
- package/src/io/codec/utf8.js +5 -3
- package/src/io/codec/xml.js +1 -1
- package/src/io/compress/bitstream.js +2 -2
- package/src/io/compress/brotli.js +663 -163
- package/src/io/compress/brotli_dict.js +1 -1
- package/src/io/compress/brotli_dict_words.js +1 -1
- package/src/io/compress/brotli_frame.js +1 -1
- package/src/io/compress/brotli_shared.js +7 -7
- package/src/io/compress/deflate.js +87 -53
- package/src/io/compress/gzip.js +187 -74
- package/src/io/compress/huffman.js +24 -1
- package/src/io/compress/lz4.js +45 -7
- package/src/io/compress/lz77.js +148 -63
- package/src/io/compress/lzw.js +35 -19
- package/src/io/compress/zip.js +862 -815
- package/src/io/compress/zlib.js +87 -7
- package/src/io/i18n/i18n.js +1 -1
- package/src/io/math/fixed-point.js +1 -1
- package/src/io/math/geom.js +1 -1
- package/src/io/math/interp.js +1 -1
- package/src/io/math/linalg.js +10 -4
- package/src/io/math/stats.js +1 -1
- package/src/io/structures/btree.js +1 -1
- package/src/io/structures/heap.js +1 -1
- package/src/io/structures/lruCache.js +1 -1
- package/src/io/structures/ringBuffer.js +1 -1
- package/src/io/structures/tree-walker.js +1 -1
- package/src/io/structures/trie.js +1 -1
- package/src/io/sync/abort.js +1 -1
- package/src/io/sync/atomics.js +1 -1
- package/src/io/sync/cancellable.js +1 -1
- package/src/io/sync/channel.js +1 -1
- package/src/io/sync/mutex.js +1 -1
- package/src/io/sync/semaphore.js +1 -1
- package/src/io/sync/tokenBucket.js +1 -1
- package/src/io/text/ansi.js +1 -1
- package/src/io/text/html-entities.js +1 -1
- package/src/io/time/date.js +1 -1
- package/src/io/timing/clock.js +1 -1
- package/src/io/timing/rateLimit.js +1 -1
- package/src/io/timing/scheduler.js +1 -1
- package/src/io/utils/errors.js +1 -1
- package/src/io/utils/eventBus.js +1 -1
- package/src/io/utils/signal.js +1 -1
- package/src/io/utils/valid.js +1 -1
- package/src/main.js +1 -1
- package/src/process/message.js +1 -1
- package/src/process/rpc.js +7 -3
- package/src/process/workerPool.js +11 -4
- package/src/sanity/base.js +85 -39
- package/src/sanity/lockdown-apply.js +3 -3
- package/src/sanity/lockdown.js +58 -32
- package/src/sanity/wasm-gate.js +2 -2
- package/src/typed.js +7 -3
- package/third-party/NOTICE-brotli-dictionary.txt +69 -0
- package/third-party/NOTICE-fw-wasm-crypto.txt +576 -0
- package/third-party/NOTICE-whatwg-entities.txt +44 -0
- package/types/registry.generated.d.ts +7 -1
- package/types/typed.d.ts +7 -3
- package/dist/types/crypto/utils/aes_ctr.d.ts +0 -84
- package/dist/types/crypto/utils/aes_ctr.d.ts.map +0 -1
- package/docs/api/crypto/utils/aes_ctr.md +0 -71
- package/src/crypto/utils/aes_ctr.acvp.md +0 -67
- package/src/crypto/utils/aes_ctr.js +0 -134
|
@@ -1,574 +1,600 @@
|
|
|
1
|
-
|
|
2
|
-
// Author: Matthieu Bouilloux
|
|
3
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @description
|
|
7
|
-
* Keyboard shortcut manager supporting simple bindings (`'Ctrl+S'`),
|
|
8
|
-
* chord keys (`'Ctrl+K Ctrl+P'` - two sequential keystrokes),
|
|
9
|
-
* stackable contexts (`pushContext('modal')` → exclusive bindings),
|
|
10
|
-
* per-binding priority (conflict resolution),
|
|
11
|
-
* and inspection (`list`, `match`).
|
|
12
|
-
*
|
|
13
|
-
* Key strategy: `event.code` for alpha-numeric keys (keyboard layout
|
|
14
|
-
* independent, e.g. `KeyA` always maps to the physical A key), and `event.key`
|
|
15
|
-
* for named keys (`'Escape'`, `'F1'`, `'Tab'`, etc.).
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* const
|
|
25
|
-
* kb.
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*
|
|
36
|
-
* @
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* @
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
'
|
|
60
|
-
'
|
|
61
|
-
'
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (
|
|
151
|
-
throw new
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
*
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
//
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
//
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
*
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
return
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
*
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
function
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
//
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
*
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
1
|
+
// Copyright (c) 2026 AwaCloud SAS
|
|
2
|
+
// Author: Matthieu Bouilloux
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* Keyboard shortcut manager supporting simple bindings (`'Ctrl+S'`),
|
|
8
|
+
* chord keys (`'Ctrl+K Ctrl+P'` - two sequential keystrokes),
|
|
9
|
+
* stackable contexts (`pushContext('modal')` → exclusive bindings),
|
|
10
|
+
* per-binding priority (conflict resolution),
|
|
11
|
+
* and inspection (`list`, `match`).
|
|
12
|
+
*
|
|
13
|
+
* Key strategy: `event.code` for alpha-numeric keys (keyboard layout
|
|
14
|
+
* independent, e.g. `KeyA` always maps to the physical A key), and `event.key`
|
|
15
|
+
* for named keys (`'Escape'`, `'F1'`, `'Tab'`, etc.).
|
|
16
|
+
* Punctuation keys (`Plus`, `Minus`, `Equal`) match on `event.key` (the typed
|
|
17
|
+
* character, numpad included) and ignore the Shift modifier.
|
|
18
|
+
*
|
|
19
|
+
* Out of MVP scope: persistent user-side remapping.
|
|
20
|
+
* Worker-safe: no - consumes DOM keyboard events.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const keybindings = runtime.resolve('keybindings');
|
|
24
|
+
* const kb = keybindings.create({ target: document });
|
|
25
|
+
* kb.attach();
|
|
26
|
+
* const unbind = kb.bind('Ctrl+S', () => save(), { preventDefault: true });
|
|
27
|
+
* kb.bind('Ctrl+K Ctrl+P', () => openPalette());
|
|
28
|
+
* // …
|
|
29
|
+
* unbind(); // unregisters
|
|
30
|
+
*/
|
|
31
|
+
import { events } from '../query/events.js';
|
|
32
|
+
import { eventBus } from '../../io/utils/eventBus.js';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Public surface returned by the keybindings factory.
|
|
36
|
+
* @typedef {object} KeybindingsAPI
|
|
37
|
+
* @property {(opts?: { target?: EventTarget, layout?: string, chordTimeout?: number }) => object} create - Create a keybindings manager instance (bind/unbind/contexts/attach/detach/...).
|
|
38
|
+
* @property {(combo: string) => ({ modifiers: object, key: string } | Array<{ modifiers: object, key: string }>)} parse - Parse a combo string into a single segment (simple) or an array of segments (chord).
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
export const keybindings = {
|
|
42
|
+
name: 'keybindings',
|
|
43
|
+
version: '1.0.0',
|
|
44
|
+
type: 'fw.dom.utils',
|
|
45
|
+
dependencies: ['events', 'eventBus'],
|
|
46
|
+
deps: [events, eventBus],
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {Object} events - Module events (fw)
|
|
50
|
+
* @param {Object} eventBus - Module eventBus (fw)
|
|
51
|
+
* @returns {KeybindingsAPI}
|
|
52
|
+
*/
|
|
53
|
+
factory(events, eventBus) {
|
|
54
|
+
|
|
55
|
+
// ── Key mapping constants ────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
/** Special keys → expected event.key */
|
|
58
|
+
const NAMED_KEYS = new Set([
|
|
59
|
+
'Escape', 'Tab', 'Enter', 'Space', 'Backspace', 'Delete', 'Insert',
|
|
60
|
+
'Home', 'End', 'PageUp', 'PageDown',
|
|
61
|
+
'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight',
|
|
62
|
+
'F1', 'F2', 'F3', 'F4', 'F5', 'F6',
|
|
63
|
+
'F7', 'F8', 'F9', 'F10', 'F11', 'F12',
|
|
64
|
+
]);
|
|
65
|
+
|
|
66
|
+
/** Accepted key aliases (case-insensitive) → normalised key */
|
|
67
|
+
const KEY_ALIASES = {
|
|
68
|
+
esc: 'Escape',
|
|
69
|
+
escape: 'Escape',
|
|
70
|
+
return: 'Enter',
|
|
71
|
+
enter: 'Enter',
|
|
72
|
+
tab: 'Tab',
|
|
73
|
+
space: 'Space',
|
|
74
|
+
backspace: 'Backspace',
|
|
75
|
+
del: 'Delete',
|
|
76
|
+
delete: 'Delete',
|
|
77
|
+
insert: 'Insert',
|
|
78
|
+
home: 'Home',
|
|
79
|
+
end: 'End',
|
|
80
|
+
pageup: 'PageUp',
|
|
81
|
+
pagedown: 'PageDown',
|
|
82
|
+
up: 'ArrowUp',
|
|
83
|
+
down: 'ArrowDown',
|
|
84
|
+
left: 'ArrowLeft',
|
|
85
|
+
right: 'ArrowRight',
|
|
86
|
+
arrowup: 'ArrowUp',
|
|
87
|
+
arrowdown: 'ArrowDown',
|
|
88
|
+
arrowleft: 'ArrowLeft',
|
|
89
|
+
arrowright: 'ArrowRight',
|
|
90
|
+
plus: 'Plus',
|
|
91
|
+
minus: 'Minus',
|
|
92
|
+
equal: 'Equal',
|
|
93
|
+
equals: 'Equal',
|
|
94
|
+
'-': 'Minus',
|
|
95
|
+
'=': 'Equal',
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/** Punctuation keys matched on event.key (the typed character, layout-independent by construction). */
|
|
99
|
+
const PUNCTUATION_KEYS = { '+': 'Plus', '-': 'Minus', '=': 'Equal' };
|
|
100
|
+
const PUNCTUATION_NAMES = new Set(Object.values(PUNCTUATION_KEYS));
|
|
101
|
+
|
|
102
|
+
/** Accepted modifier names (lowercase) */
|
|
103
|
+
const MODIFIER_NAMES = new Set(['ctrl', 'shift', 'alt', 'meta', 'cmd', 'super']);
|
|
104
|
+
|
|
105
|
+
// ── Parser ─────────────────────────────────────────────────────────
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Parse a single combo segment (e.g. `'Ctrl+Shift+P'`).
|
|
109
|
+
* @param {string} segment
|
|
110
|
+
* @returns {{ modifiers: {ctrl, shift, alt, meta}, key: string }}
|
|
111
|
+
*/
|
|
112
|
+
function _parseSegment(segment) {
|
|
113
|
+
const parts = segment.split('+');
|
|
114
|
+
const modifiers = { ctrl: false, shift: false, alt: false, meta: false };
|
|
115
|
+
let key = null;
|
|
116
|
+
|
|
117
|
+
for (const raw of parts) {
|
|
118
|
+
const lower = raw.toLowerCase();
|
|
119
|
+
if (MODIFIER_NAMES.has(lower)) {
|
|
120
|
+
if (lower === 'cmd' || lower === 'super') {
|
|
121
|
+
modifiers.meta = true;
|
|
122
|
+
} else {
|
|
123
|
+
modifiers[lower] = true;
|
|
124
|
+
}
|
|
125
|
+
} else if (raw.length === 0) {
|
|
126
|
+
// double `+` (e.g. 'Ctrl++')
|
|
127
|
+
throw new Error('keybindings: invalid combo segment "' + segment + '"');
|
|
128
|
+
} else {
|
|
129
|
+
if (key !== null) {
|
|
130
|
+
throw new Error('keybindings: multiple non-modifier keys in segment "' + segment + '"');
|
|
131
|
+
}
|
|
132
|
+
// Try alias, then NAMED_KEYS, then letter/digit
|
|
133
|
+
const alias = KEY_ALIASES[lower];
|
|
134
|
+
if (alias) {
|
|
135
|
+
key = alias;
|
|
136
|
+
} else if (NAMED_KEYS.has(raw)) {
|
|
137
|
+
key = raw;
|
|
138
|
+
} else if (/^[a-zA-Z0-9]$/.test(raw)) {
|
|
139
|
+
key = raw.toLowerCase();
|
|
140
|
+
} else {
|
|
141
|
+
throw new Error('keybindings: unknown key "' + raw + '" in segment "' + segment + '"');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (modifiers.shift && key !== null && PUNCTUATION_NAMES.has(key)) {
|
|
147
|
+
throw new Error('keybindings: Shift cannot qualify punctuation key "' + key + '" in segment "' + segment + '"');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (key === null) {
|
|
151
|
+
throw new Error('keybindings: no key specified in segment "' + segment + '"');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return { modifiers, key };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Parse a full combo string.
|
|
159
|
+
* - simple (`'Ctrl+S'`) → `{modifiers, key}`
|
|
160
|
+
* - chord (`'Ctrl+K Ctrl+P'`) → `[{modifiers, key}, {modifiers, key}]`
|
|
161
|
+
*
|
|
162
|
+
* @param {string} combo
|
|
163
|
+
* @returns {{ modifiers: Object, key: string } | Array<{ modifiers: Object, key: string }>}
|
|
164
|
+
*/
|
|
165
|
+
function parse(combo) {
|
|
166
|
+
if (typeof combo !== 'string' || combo.trim().length === 0) {
|
|
167
|
+
throw new TypeError('keybindings: combo must be a non-empty string');
|
|
168
|
+
}
|
|
169
|
+
const segments = combo.trim().split(' ').filter(s => s.length > 0);
|
|
170
|
+
if (segments.length === 1) {
|
|
171
|
+
return _parseSegment(segments[0]);
|
|
172
|
+
}
|
|
173
|
+
return segments.map(s => _parseSegment(s));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ── event.key normalisation ──────────────────────────────────────────
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Normalise a KeyboardEvent to a key comparable to the one produced by `parse`.
|
|
180
|
+
* For alpha-numeric keys, uses `event.code` (e.g. 'KeyA' → 'a').
|
|
181
|
+
* For named keys, uses `event.key`.
|
|
182
|
+
* @param {KeyboardEvent} event
|
|
183
|
+
* @returns {string|null}
|
|
184
|
+
*/
|
|
185
|
+
function _normalizeEventKey(event) {
|
|
186
|
+
// Named keys via event.key
|
|
187
|
+
const key = event.key;
|
|
188
|
+
if (NAMED_KEYS.has(key)) return key;
|
|
189
|
+
// Alias via event.key
|
|
190
|
+
const aliased = KEY_ALIASES[key.toLowerCase()];
|
|
191
|
+
if (aliased) return aliased;
|
|
192
|
+
// Punctuation via event.key (typed character, Shift/numpad agnostic)
|
|
193
|
+
if (PUNCTUATION_KEYS[key]) return PUNCTUATION_KEYS[key];
|
|
194
|
+
// Alpha-numeric via event.code (layout-independent)
|
|
195
|
+
const code = event.code;
|
|
196
|
+
if (code && /^Key[A-Z]$/.test(code)) return code.slice(3).toLowerCase();
|
|
197
|
+
if (code && /^Digit[0-9]$/.test(code)) return code.slice(5);
|
|
198
|
+
// Fallback: event.key lowercased if a single character
|
|
199
|
+
if (key.length === 1) return key.toLowerCase();
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Test whether a KeyboardEvent matches a parsed segment.
|
|
205
|
+
* @param {KeyboardEvent} event
|
|
206
|
+
* @param {{ modifiers: Object, key: string }} seg
|
|
207
|
+
* @returns {boolean}
|
|
208
|
+
*/
|
|
209
|
+
function _matchesSegment(event, seg) {
|
|
210
|
+
const { modifiers, key } = seg;
|
|
211
|
+
// Windows merges `Ctrl+Alt` into `AltGr`; Firefox then reports
|
|
212
|
+
// `getModifierState('AltGraph') === true` while `ctrlKey`/`altKey`
|
|
213
|
+
// are `false`. Normalise: AltGr active ⇒ Ctrl and Alt both effective.
|
|
214
|
+
// This makes `Ctrl+Alt+X` match both AltGr (Firefox) and the legacy
|
|
215
|
+
// ctrl+alt (Chrome) without false positives on combos that only
|
|
216
|
+
// require one of the two modifiers.
|
|
217
|
+
const altGr = typeof event.getModifierState === 'function'
|
|
218
|
+
&& event.getModifierState('AltGraph');
|
|
219
|
+
const evCtrl = event.ctrlKey || altGr;
|
|
220
|
+
const evAlt = event.altKey || altGr;
|
|
221
|
+
if (evCtrl !== modifiers.ctrl) return false;
|
|
222
|
+
if (!PUNCTUATION_NAMES.has(key) && event.shiftKey !== modifiers.shift) return false;
|
|
223
|
+
if (evAlt !== modifiers.alt) return false;
|
|
224
|
+
if (event.metaKey !== modifiers.meta) return false;
|
|
225
|
+
return _normalizeEventKey(event) === key;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// ── Instance factory ─────────────────────────────────────────────────
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Create a keyboard shortcut manager instance.
|
|
232
|
+
* @param {Object} [opts={}]
|
|
233
|
+
* @param {EventTarget} [opts.target] - Listening target. Defaults to `document`.
|
|
234
|
+
* @param {string} [opts.layout] - Keyboard layout: 'us'|'fr'|'auto' (reserved for future use).
|
|
235
|
+
* @param {number} [opts.chordTimeout=1500] - Chord timeout in ms.
|
|
236
|
+
* @returns {Object} keybindings instance
|
|
237
|
+
*/
|
|
238
|
+
function create(opts = {}) {
|
|
239
|
+
const target = opts.target || document;
|
|
240
|
+
const chordTimeout = typeof opts.chordTimeout === 'number' ? opts.chordTimeout : 1500;
|
|
241
|
+
|
|
242
|
+
const _bus = eventBus.create();
|
|
243
|
+
|
|
244
|
+
// Bindings list: { combo, parsed, context, priority, preventDefault, repeat, fn }
|
|
245
|
+
const _bindings = [];
|
|
246
|
+
|
|
247
|
+
// Context stack
|
|
248
|
+
const _contextStack = [];
|
|
249
|
+
|
|
250
|
+
// Pending chord state
|
|
251
|
+
let _chordPending = null; // { candidates: Binding[], matched: number, timer: id }
|
|
252
|
+
|
|
253
|
+
let _attached = false;
|
|
254
|
+
|
|
255
|
+
// ── Bindings management ──────────────────────────────────────────
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Registers a keyboard shortcut.
|
|
259
|
+
*
|
|
260
|
+
* **Chord priority tiebreaker.** When multiple chord bindings share
|
|
261
|
+
* the same prefix and identical `priority`, only the first registered
|
|
262
|
+
* candidate fires (deterministic by definition order). Plain
|
|
263
|
+
* (non-chord) bindings at equal max priority all fire - chord
|
|
264
|
+
* arbitration is single-winner by design.
|
|
265
|
+
*
|
|
266
|
+
* @param {string} combo
|
|
267
|
+
* @param {Function} fn
|
|
268
|
+
* @param {Object} [opts2={}]
|
|
269
|
+
* @param {string} [opts2.context]
|
|
270
|
+
* @param {number} [opts2.priority=0]
|
|
271
|
+
* @param {boolean} [opts2.preventDefault=true]
|
|
272
|
+
* @param {boolean} [opts2.repeat=false]
|
|
273
|
+
* @returns {Function} unbind
|
|
274
|
+
*/
|
|
275
|
+
function bind(combo, fn, opts2 = {}) {
|
|
276
|
+
if (typeof combo !== 'string') throw new TypeError('keybindings.bind: combo must be a string');
|
|
277
|
+
if (typeof fn !== 'function') throw new TypeError('keybindings.bind: fn must be a function');
|
|
278
|
+
|
|
279
|
+
const parsed = parse(combo);
|
|
280
|
+
const context = opts2.context || null;
|
|
281
|
+
const priority = typeof opts2.priority === 'number' ? opts2.priority : 0;
|
|
282
|
+
const prev = opts2.preventDefault !== false; // true by default
|
|
283
|
+
const repeat = opts2.repeat === true; // false by default
|
|
284
|
+
|
|
285
|
+
const entry = { combo, parsed, context, priority, preventDefault: prev, repeat, fn };
|
|
286
|
+
_bindings.push(entry);
|
|
287
|
+
|
|
288
|
+
return function unbind() {
|
|
289
|
+
const idx = _bindings.indexOf(entry);
|
|
290
|
+
if (idx !== -1) _bindings.splice(idx, 1);
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Unregister a combo (all handlers when `fn` is omitted).
|
|
296
|
+
* @param {string} combo
|
|
297
|
+
* @param {Function} [fn]
|
|
298
|
+
*/
|
|
299
|
+
function unbind(combo, fn) {
|
|
300
|
+
for (let i = _bindings.length - 1; i >= 0; i--) {
|
|
301
|
+
if (_bindings[i].combo === combo) {
|
|
302
|
+
if (!fn || _bindings[i].fn === fn) {
|
|
303
|
+
_bindings.splice(i, 1);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// ── Context ──────────────────────────────────────────────────────
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Push a context onto the stack.
|
|
313
|
+
* @param {string} name
|
|
314
|
+
*/
|
|
315
|
+
function pushContext(name) {
|
|
316
|
+
_contextStack.push(name);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Pops the current context.
|
|
321
|
+
* @returns {string} Popped context name.
|
|
322
|
+
* @throws {RangeError} If the context stack is empty.
|
|
323
|
+
*/
|
|
324
|
+
function popContext() {
|
|
325
|
+
if (_contextStack.length === 0) {
|
|
326
|
+
throw new RangeError('keybindings: context stack underflow');
|
|
327
|
+
}
|
|
328
|
+
return _contextStack.pop();
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Return a copy of the context stack.
|
|
333
|
+
* @returns {string[]}
|
|
334
|
+
*/
|
|
335
|
+
function currentContext() {
|
|
336
|
+
return [..._contextStack];
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// ── Inspection ───────────────────────────────────────────────────
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Return the list of all registered bindings.
|
|
343
|
+
* @returns {Array<{combo, context, priority, fn}>}
|
|
344
|
+
*/
|
|
345
|
+
function list() {
|
|
346
|
+
return _bindings.map(b => ({
|
|
347
|
+
combo: b.combo,
|
|
348
|
+
context: b.context,
|
|
349
|
+
priority: b.priority,
|
|
350
|
+
fn: b.fn,
|
|
351
|
+
}));
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Return the bindings that would be triggered by this event.
|
|
356
|
+
* @param {KeyboardEvent} event
|
|
357
|
+
* @returns {Array<{combo, context, priority, fn}>}
|
|
358
|
+
*/
|
|
359
|
+
function match(event) {
|
|
360
|
+
return _bindings
|
|
361
|
+
.filter(b => {
|
|
362
|
+
const parsed = b.parsed;
|
|
363
|
+
if (Array.isArray(parsed)) {
|
|
364
|
+
// chord: only the first segment can be matched here
|
|
365
|
+
return _matchesSegment(event, parsed[0]);
|
|
366
|
+
}
|
|
367
|
+
return _matchesSegment(event, parsed);
|
|
368
|
+
})
|
|
369
|
+
.map(b => ({ combo: b.combo, context: b.context, priority: b.priority, fn: b.fn }));
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// ── Dispatch logic ───────────────────────────────────────────────
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Filter bindings by the current context.
|
|
376
|
+
* Rule: when a context is active (non-empty stack), only bindings
|
|
377
|
+
* whose `context === top of stack` are allowed.
|
|
378
|
+
* In practice: when the stack is non-empty, only bindings from the
|
|
379
|
+
* current context fire; context-less bindings are ignored while a
|
|
380
|
+
* context is active.
|
|
381
|
+
*
|
|
382
|
+
* @param {Array} candidates
|
|
383
|
+
* @returns {Array}
|
|
384
|
+
*/
|
|
385
|
+
function _filterByContext(candidates) {
|
|
386
|
+
const ctx = _contextStack.length > 0 ? _contextStack[_contextStack.length - 1] : null;
|
|
387
|
+
if (ctx === null) {
|
|
388
|
+
// No active context: only context-less bindings
|
|
389
|
+
return candidates.filter(b => b.context === null);
|
|
390
|
+
}
|
|
391
|
+
// Active context: only bindings for that context
|
|
392
|
+
return candidates.filter(b => b.context === ctx);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Execute the bindings with the highest priority (ties → all of them).
|
|
397
|
+
* @param {Array} matched - bindings filtered by context
|
|
398
|
+
* @param {KeyboardEvent} event
|
|
399
|
+
*/
|
|
400
|
+
/** The highest-priority binding of `list` (the first registered on a tie). */
|
|
401
|
+
function _highest(list) {
|
|
402
|
+
return list.reduce((a, b) => b.priority > a.priority ? b : a, list[0]);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function _dispatch(matched, event) {
|
|
406
|
+
if (matched.length === 0) return;
|
|
407
|
+
|
|
408
|
+
// Maximum priority
|
|
409
|
+
const maxPriority = matched.reduce((m, b) => Math.max(m, b.priority), -Infinity);
|
|
410
|
+
const toRun = matched.filter(b => b.priority === maxPriority);
|
|
411
|
+
|
|
412
|
+
for (const b of toRun) {
|
|
413
|
+
if (b.preventDefault) event.preventDefault();
|
|
414
|
+
try {
|
|
415
|
+
b.fn(event);
|
|
416
|
+
} catch (e) {
|
|
417
|
+
|
|
418
|
+
console.error('keybindings handler error:', e);
|
|
419
|
+
}
|
|
420
|
+
_bus.emit('keybindings:matched', { combo: b.combo, context: b.context, fn: b.fn });
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Main keydown handler.
|
|
426
|
+
* @param {KeyboardEvent} event
|
|
427
|
+
*/
|
|
428
|
+
function _onKeyDown(event) {
|
|
429
|
+
// Filter event.repeat when binding.repeat === false.
|
|
430
|
+
// Note: filtering happens per binding below, but if all candidates
|
|
431
|
+
// reject repeat we can exit early.
|
|
432
|
+
|
|
433
|
+
// ── Step 1: handle a pending chord ──────────────────────────
|
|
434
|
+
// Every candidate whose segments so far matched is kept, so two
|
|
435
|
+
// chords sharing a prefix (`g a`, `g h`) can both complete.
|
|
436
|
+
if (_chordPending) {
|
|
437
|
+
const { candidates, matched, timer } = _chordPending;
|
|
438
|
+
clearTimeout(timer);
|
|
439
|
+
_chordPending = null;
|
|
440
|
+
|
|
441
|
+
const nextIdx = matched + 1;
|
|
442
|
+
const survivors = candidates.filter(b => _matchesSegment(event, b.parsed[nextIdx]));
|
|
443
|
+
if (survivors.length > 0) {
|
|
444
|
+
const complete = survivors.filter(b => b.parsed.length - 1 === nextIdx);
|
|
445
|
+
if (complete.length > 0) {
|
|
446
|
+
// A chord that completes on this key wins over a longer
|
|
447
|
+
// one sharing its prefix; among them the highest
|
|
448
|
+
// priority fires (the first registered on a tie).
|
|
449
|
+
const b = _highest(complete);
|
|
450
|
+
if (b.repeat || !event.repeat) {
|
|
451
|
+
if (b.preventDefault) event.preventDefault();
|
|
452
|
+
try {
|
|
453
|
+
b.fn(event);
|
|
454
|
+
} catch (e) {
|
|
455
|
+
|
|
456
|
+
console.error('keybindings chord handler error:', e);
|
|
457
|
+
}
|
|
458
|
+
_bus.emit('keybindings:matched', { combo: b.combo, context: b.context, fn: b.fn });
|
|
459
|
+
}
|
|
460
|
+
} else {
|
|
461
|
+
// More segments still to come
|
|
462
|
+
_chordPending = {
|
|
463
|
+
candidates: survivors,
|
|
464
|
+
matched: nextIdx,
|
|
465
|
+
timer: setTimeout(() => { _chordPending = null; }, chordTimeout),
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
return; // Ne pas traiter comme binding simple
|
|
469
|
+
}
|
|
470
|
+
// The key matches no candidate → cancel the chord
|
|
471
|
+
// and continue normal processing
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// ── Step 2: look for chord candidates ───────────────────────
|
|
475
|
+
const chordCandidates = _bindings.filter(b => {
|
|
476
|
+
if (!Array.isArray(b.parsed)) return false;
|
|
477
|
+
if (!_matchesSegment(event, b.parsed[0])) return false;
|
|
478
|
+
// Check context
|
|
479
|
+
const ctx = _contextStack.length > 0 ? _contextStack[_contextStack.length - 1] : null;
|
|
480
|
+
if (ctx === null) return b.context === null;
|
|
481
|
+
return b.context === ctx;
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
if (chordCandidates.length > 0) {
|
|
485
|
+
// Start the chord with every candidate; the next keys narrow the set.
|
|
486
|
+
_chordPending = {
|
|
487
|
+
candidates: chordCandidates,
|
|
488
|
+
matched: 0,
|
|
489
|
+
timer: setTimeout(() => { _chordPending = null; }, chordTimeout),
|
|
490
|
+
};
|
|
491
|
+
// Do not trigger a simple binding immediately
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// ── Step 3: simple bindings ──────────────────────────────────
|
|
496
|
+
const simpleCandidates = _bindings.filter(b => {
|
|
497
|
+
if (Array.isArray(b.parsed)) return false;
|
|
498
|
+
return _matchesSegment(event, b.parsed);
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
const contextFiltered = _filterByContext(simpleCandidates);
|
|
502
|
+
const repeatFiltered = contextFiltered.filter(b => b.repeat || !event.repeat);
|
|
503
|
+
|
|
504
|
+
_dispatch(repeatFiltered, event);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// ── Attach / detach ───────────────────────────────────────────────
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Enable keyboard event listening.
|
|
511
|
+
*/
|
|
512
|
+
function attach() {
|
|
513
|
+
if (_attached) return;
|
|
514
|
+
_attached = true;
|
|
515
|
+
target.addEventListener('keydown', _onKeyDown);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Disable keyboard event listening.
|
|
520
|
+
*/
|
|
521
|
+
function detach() {
|
|
522
|
+
if (!_attached) return;
|
|
523
|
+
_attached = false;
|
|
524
|
+
target.removeEventListener('keydown', _onKeyDown);
|
|
525
|
+
if (_chordPending) {
|
|
526
|
+
clearTimeout(_chordPending.timer);
|
|
527
|
+
_chordPending = null;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Dispose the instance (detach listeners and clear all bindings).
|
|
533
|
+
*/
|
|
534
|
+
function dispose() {
|
|
535
|
+
detach();
|
|
536
|
+
_bindings.length = 0;
|
|
537
|
+
_contextStack.length = 0;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Create a scoped sub-controller. Every `bind(...)` called through
|
|
542
|
+
* the returned scope is tracked ; calling `scope.dispose()` (or
|
|
543
|
+
* `scope.clear()`) unbinds them all at once **without** disposing
|
|
544
|
+
* the parent instance.
|
|
545
|
+
*
|
|
546
|
+
* Intended for `ui.mount(blockId, null, () => kb.scope())` so a
|
|
547
|
+
* modal/component's keybindings are auto-detached when the block
|
|
548
|
+
* is cleared.
|
|
549
|
+
*
|
|
550
|
+
* @returns {{
|
|
551
|
+
* bind: Function, unbind: Function,
|
|
552
|
+
* pushContext: Function, popContext: Function,
|
|
553
|
+
* dispose: Function, clear: Function
|
|
554
|
+
* }}
|
|
555
|
+
*/
|
|
556
|
+
function scope() {
|
|
557
|
+
const unbinders = new Set();
|
|
558
|
+
|
|
559
|
+
function scopeBind(...args) {
|
|
560
|
+
// @ts-ignore - spread forwarding of variadic handler args
|
|
561
|
+
const off = bind(...args);
|
|
562
|
+
unbinders.add(off);
|
|
563
|
+
return off;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function clear() {
|
|
567
|
+
for (const off of unbinders) {
|
|
568
|
+
try { off(); } catch { /* swallow */ }
|
|
569
|
+
}
|
|
570
|
+
unbinders.clear();
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
return {
|
|
574
|
+
bind: scopeBind,
|
|
575
|
+
unbind,
|
|
576
|
+
pushContext,
|
|
577
|
+
popContext,
|
|
578
|
+
dispose: clear,
|
|
579
|
+
clear,
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
return {
|
|
584
|
+
bind,
|
|
585
|
+
unbind,
|
|
586
|
+
pushContext,
|
|
587
|
+
popContext,
|
|
588
|
+
currentContext,
|
|
589
|
+
list,
|
|
590
|
+
match,
|
|
591
|
+
attach,
|
|
592
|
+
detach,
|
|
593
|
+
dispose,
|
|
594
|
+
scope,
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
return { create, parse };
|
|
599
|
+
}
|
|
600
|
+
};
|