@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,522 +1,542 @@
|
|
|
1
|
-
|
|
2
|
-
// Author: Matthieu Bouilloux
|
|
3
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @description
|
|
7
|
-
* Design-token manager built on CSS Custom Properties. Lets the caller
|
|
8
|
-
* define tokens as scalar values or variants
|
|
9
|
-
* (`{light, dark, highContrast, reducedMotion}`), apply the resolved CSS
|
|
10
|
-
* variables to a chosen scope (`:root` by default), watch the system media
|
|
11
|
-
* queries (`prefers-color-scheme`, `prefers-contrast`,
|
|
12
|
-
* `prefers-reduced-motion`, `forced-colors`), and switch modes with change
|
|
13
|
-
* notification to observers.
|
|
14
|
-
*
|
|
15
|
-
* Out of scope : inheritance / `extends` (handled by the cnf loader
|
|
16
|
-
* `sde_lib_style`).
|
|
17
|
-
* Worker-safe : no - depends on `document`, `matchMedia`, `window`.
|
|
18
|
-
*
|
|
19
|
-
* Each `create()` call returns an isolated instance with its own dedicated
|
|
20
|
-
* `<style>` element (unique id per instance -
|
|
21
|
-
* without clobbering each other)
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* @
|
|
38
|
-
* @property {function(
|
|
39
|
-
* @property {function(): void}
|
|
40
|
-
* @property {function(
|
|
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
|
-
'color-
|
|
80
|
-
'color-
|
|
81
|
-
'
|
|
82
|
-
'
|
|
83
|
-
'
|
|
84
|
-
'
|
|
85
|
-
'
|
|
86
|
-
'space-
|
|
87
|
-
'
|
|
88
|
-
'
|
|
89
|
-
'
|
|
90
|
-
'
|
|
91
|
-
'
|
|
92
|
-
'
|
|
93
|
-
'
|
|
94
|
-
'
|
|
95
|
-
'
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
'
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
'color-
|
|
106
|
-
'color-
|
|
107
|
-
'color-
|
|
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
|
-
'color-
|
|
135
|
-
'color-
|
|
136
|
-
'color-
|
|
137
|
-
'
|
|
138
|
-
'
|
|
139
|
-
'
|
|
140
|
-
'
|
|
141
|
-
'
|
|
142
|
-
'space-
|
|
143
|
-
'
|
|
144
|
-
'
|
|
145
|
-
'
|
|
146
|
-
'
|
|
147
|
-
'
|
|
148
|
-
'
|
|
149
|
-
'
|
|
150
|
-
'
|
|
151
|
-
'
|
|
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
|
-
const
|
|
179
|
-
|
|
180
|
-
//
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
let
|
|
202
|
-
let
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (_mode === '
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
if (
|
|
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
|
-
el
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
*
|
|
332
|
-
*/
|
|
333
|
-
function
|
|
334
|
-
const
|
|
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
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
* After `dispose()` this is a no-op.
|
|
410
|
-
*
|
|
411
|
-
* @param {
|
|
412
|
-
*/
|
|
413
|
-
function
|
|
414
|
-
if (
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
return
|
|
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
|
-
* After `dispose()
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
* @
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
return ()
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
if (
|
|
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
|
-
|
|
1
|
+
// Copyright (c) 2026 AwaCloud SAS
|
|
2
|
+
// Author: Matthieu Bouilloux
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* Design-token manager built on CSS Custom Properties. Lets the caller
|
|
8
|
+
* define tokens as scalar values or variants
|
|
9
|
+
* (`{light, dark, highContrast, reducedMotion}`), apply the resolved CSS
|
|
10
|
+
* variables to a chosen scope (`:root` by default), watch the system media
|
|
11
|
+
* queries (`prefers-color-scheme`, `prefers-contrast`,
|
|
12
|
+
* `prefers-reduced-motion`, `forced-colors`), and switch modes with change
|
|
13
|
+
* notification to observers.
|
|
14
|
+
*
|
|
15
|
+
* Out of scope : inheritance / `extends` (handled by the cnf loader
|
|
16
|
+
* `sde_lib_style`).
|
|
17
|
+
* Worker-safe : no - depends on `document`, `matchMedia`, `window`.
|
|
18
|
+
*
|
|
19
|
+
* Each `create()` call returns an isolated instance with its own dedicated
|
|
20
|
+
* `<style id="data-fw-theme-tokens-N">` element (unique id per instance -
|
|
21
|
+
* multiple instances can coexist without clobbering each other), attached
|
|
22
|
+
* through the `styleSheet` module (the element carries the page's
|
|
23
|
+
* `<meta name="csp-nonce">` nonce when there is one; under
|
|
24
|
+
* `styleSheet.mode('adopted')` there is no element, a constructable
|
|
25
|
+
* stylesheet is used). Calling `dispose()` removes the style and detaches all
|
|
26
|
+
* listeners ; subsequent method calls become safe no-ops.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* const themeTokens = runtime.resolve('themeTokens');
|
|
30
|
+
* const theme = themeTokens.create({ prefix: 'fw-' });
|
|
31
|
+
* theme.define({ color: { light: '#fff', dark: '#000' } });
|
|
32
|
+
* theme.mode('dark');
|
|
33
|
+
* theme.onChange(({ resolved }) => console.log('mode:', resolved));
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @typedef {Object} ThemeInstance
|
|
38
|
+
* @property {function(Record<string, string|number|Object>): void} define
|
|
39
|
+
* @property {function(string): void} mode
|
|
40
|
+
* @property {function(): {mode: string, resolved: string, reducedMotion: boolean}} current
|
|
41
|
+
* @property {function(string): string} get
|
|
42
|
+
* @property {function(function): function} onChange
|
|
43
|
+
* @property {function(): void} dispose
|
|
44
|
+
* @property {function(Object): void} [applyPreset]
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Design-token manager surface returned by `factory()`.
|
|
49
|
+
* @typedef {object} ThemeTokensAPI
|
|
50
|
+
* @property {(opts?: {scope?: string|Element, prefix?: string}) => ThemeInstance} create - Create an isolated token-manager instance.
|
|
51
|
+
* @property {Object<string, Object>} presets - Ready-to-use token presets (`neutral`, `material`, `tailwind`).
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
import { dom } from '../query/dom.js';
|
|
55
|
+
import { styleSheet } from './styleSheet.js';
|
|
56
|
+
|
|
57
|
+
export const themeTokens = {
|
|
58
|
+
name: 'themeTokens',
|
|
59
|
+
version: '1.1.0',
|
|
60
|
+
type: 'fw.dom.rendering',
|
|
61
|
+
dependencies: ['dom', 'styleSheet'],
|
|
62
|
+
deps: [dom, styleSheet],
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {Object} dom - The fw `dom` module instance.
|
|
66
|
+
* @returns {ThemeTokensAPI}
|
|
67
|
+
*/
|
|
68
|
+
factory(dom, styleSheet) {
|
|
69
|
+
|
|
70
|
+
// Monotonic counter used to mint unique <style> ids per instance.
|
|
71
|
+
let _instanceSeq = 0;
|
|
72
|
+
|
|
73
|
+
// ── Ready-to-use presets ────────────────────────────────────────────
|
|
74
|
+
// Each preset is a `{ tokens }` object ready to feed `define()`.
|
|
75
|
+
// Exposed variants : default / light / dark / highContrast / reducedMotion.
|
|
76
|
+
// Naming convention : `<family>-<variant>`, kebab-case.
|
|
77
|
+
|
|
78
|
+
const PRESET_NEUTRAL = {
|
|
79
|
+
'color-bg': { light: '#ffffff', dark: '#0b0b0d', highContrast: '#000000' },
|
|
80
|
+
'color-fg': { light: '#1a1a1a', dark: '#f2f2f2', highContrast: '#ffffff' },
|
|
81
|
+
'color-muted': { light: '#6b7280', dark: '#9ca3af', highContrast: '#cccccc' },
|
|
82
|
+
'color-accent': { light: '#2563eb', dark: '#60a5fa', highContrast: '#ffff00' },
|
|
83
|
+
'color-danger': { light: '#dc2626', dark: '#f87171', highContrast: '#ff6b6b' },
|
|
84
|
+
'color-success': { light: '#16a34a', dark: '#4ade80', highContrast: '#00ff7f' },
|
|
85
|
+
'color-border': { light: '#e5e7eb', dark: '#27272a', highContrast: '#ffffff' },
|
|
86
|
+
'space-1': '4px',
|
|
87
|
+
'space-2': '8px',
|
|
88
|
+
'space-3': '12px',
|
|
89
|
+
'space-4': '16px',
|
|
90
|
+
'space-6': '24px',
|
|
91
|
+
'space-8': '32px',
|
|
92
|
+
'radius-sm': '4px',
|
|
93
|
+
'radius-md': '8px',
|
|
94
|
+
'radius-lg': '16px',
|
|
95
|
+
'font-sans': 'system-ui, -apple-system, sans-serif',
|
|
96
|
+
'font-mono': 'ui-monospace, Menlo, Consolas, monospace',
|
|
97
|
+
'duration-fast': { default: '120ms', reducedMotion: '0ms' },
|
|
98
|
+
'duration-base': { default: '240ms', reducedMotion: '0ms' },
|
|
99
|
+
'duration-slow': { default: '480ms', reducedMotion: '0ms' },
|
|
100
|
+
'easing-standard': 'cubic-bezier(.2,0,0,1)',
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const PRESET_MATERIAL = {
|
|
104
|
+
// Material 3 baseline (simplified colours, no dynamic tone mapping)
|
|
105
|
+
'color-bg': { light: '#fffbfe', dark: '#1c1b1f', highContrast: '#000000' },
|
|
106
|
+
'color-fg': { light: '#1c1b1f', dark: '#e6e1e5', highContrast: '#ffffff' },
|
|
107
|
+
'color-surface': { light: '#f7f2fa', dark: '#2b292d' },
|
|
108
|
+
'color-primary': { light: '#6750a4', dark: '#d0bcff', highContrast: '#ffff00' },
|
|
109
|
+
'color-on-primary': { light: '#ffffff', dark: '#371e73' },
|
|
110
|
+
'color-secondary': { light: '#625b71', dark: '#ccc2dc' },
|
|
111
|
+
'color-error': { light: '#b3261e', dark: '#f2b8b5' },
|
|
112
|
+
'color-outline': { light: '#79747e', dark: '#938f99' },
|
|
113
|
+
'space-1': '4px',
|
|
114
|
+
'space-2': '8px',
|
|
115
|
+
'space-3': '12px',
|
|
116
|
+
'space-4': '16px',
|
|
117
|
+
'space-6': '24px',
|
|
118
|
+
'radius-sm': '4px',
|
|
119
|
+
'radius-md': '12px',
|
|
120
|
+
'radius-lg': '28px', // Material full container
|
|
121
|
+
'font-sans': 'Roboto, system-ui, sans-serif',
|
|
122
|
+
'font-mono': 'Roboto Mono, ui-monospace, monospace',
|
|
123
|
+
'elevation-1': '0 1px 2px rgba(0,0,0,.30), 0 1px 3px 1px rgba(0,0,0,.15)',
|
|
124
|
+
'elevation-2': '0 1px 2px rgba(0,0,0,.30), 0 2px 6px 2px rgba(0,0,0,.15)',
|
|
125
|
+
'duration-fast': { default: '150ms', reducedMotion: '0ms' },
|
|
126
|
+
'duration-base': { default: '250ms', reducedMotion: '0ms' },
|
|
127
|
+
'duration-slow': { default: '400ms', reducedMotion: '0ms' },
|
|
128
|
+
'easing-standard': 'cubic-bezier(.2,0,0,1)',
|
|
129
|
+
'easing-emphasized':'cubic-bezier(.2,0,0,1)',
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const PRESET_TAILWIND = {
|
|
133
|
+
// Distilled Tailwind "slate/blue" palette
|
|
134
|
+
'color-bg': { light: '#ffffff', dark: '#0f172a', highContrast: '#000000' }, // slate-50/900
|
|
135
|
+
'color-fg': { light: '#0f172a', dark: '#f1f5f9', highContrast: '#ffffff' }, // slate-900/100
|
|
136
|
+
'color-muted': { light: '#64748b', dark: '#94a3b8', highContrast: '#cccccc' }, // slate-500/400
|
|
137
|
+
'color-accent': { light: '#3b82f6', dark: '#60a5fa', highContrast: '#ffff00' }, // blue-500/400
|
|
138
|
+
'color-danger': { light: '#ef4444', dark: '#f87171' }, // red-500/400
|
|
139
|
+
'color-success': { light: '#22c55e', dark: '#4ade80' }, // green-500/400
|
|
140
|
+
'color-warning': { light: '#eab308', dark: '#facc15' }, // yellow-500/400
|
|
141
|
+
'color-border': { light: '#e2e8f0', dark: '#1e293b', highContrast: '#ffffff' }, // slate-200/800
|
|
142
|
+
'space-1': '0.25rem',
|
|
143
|
+
'space-2': '0.5rem',
|
|
144
|
+
'space-3': '0.75rem',
|
|
145
|
+
'space-4': '1rem',
|
|
146
|
+
'space-6': '1.5rem',
|
|
147
|
+
'space-8': '2rem',
|
|
148
|
+
'radius-sm': '0.125rem',
|
|
149
|
+
'radius-md': '0.375rem',
|
|
150
|
+
'radius-lg': '0.5rem',
|
|
151
|
+
'radius-xl': '0.75rem',
|
|
152
|
+
'font-sans': 'ui-sans-serif, system-ui, sans-serif',
|
|
153
|
+
'font-mono': 'ui-monospace, SFMono-Regular, Menlo, monospace',
|
|
154
|
+
'shadow-sm': '0 1px 2px 0 rgb(0 0 0 / .05)',
|
|
155
|
+
'shadow-md': '0 4px 6px -1px rgb(0 0 0 / .1), 0 2px 4px -2px rgb(0 0 0 / .1)',
|
|
156
|
+
'duration-fast': { default: '150ms', reducedMotion: '0ms' },
|
|
157
|
+
'duration-base': { default: '200ms', reducedMotion: '0ms' },
|
|
158
|
+
'duration-slow': { default: '300ms', reducedMotion: '0ms' },
|
|
159
|
+
'easing-standard': 'cubic-bezier(.4,0,.2,1)',
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const presets = {
|
|
163
|
+
neutral: PRESET_NEUTRAL,
|
|
164
|
+
material: PRESET_MATERIAL,
|
|
165
|
+
tailwind: PRESET_TAILWIND,
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Create a token-manager instance.
|
|
170
|
+
*
|
|
171
|
+
* @param {Object} [opts={}]
|
|
172
|
+
* @param {string|Element} [opts.scope=':root'] CSS selector string or target HTMLElement.
|
|
173
|
+
* @param {string} [opts.prefix=''] Prefix applied to every CSS-var name.
|
|
174
|
+
* @returns {ThemeInstance}
|
|
175
|
+
*/
|
|
176
|
+
function create(opts = {}) {
|
|
177
|
+
const prefix = opts.prefix ?? '';
|
|
178
|
+
const scopeArg = opts.scope ?? ':root';
|
|
179
|
+
|
|
180
|
+
// Unique id for this instance's <style> element. Prevents two
|
|
181
|
+
// instances from clobbering each other through a shared global id
|
|
182
|
+
// (was a real bug ; see `tmp/audit/themeTokens.md`).
|
|
183
|
+
const _styleId = `data-fw-theme-tokens-${++_instanceSeq}`;
|
|
184
|
+
|
|
185
|
+
// Set to true by dispose() ; subsequent method calls become no-ops.
|
|
186
|
+
let _disposed = false;
|
|
187
|
+
|
|
188
|
+
// Lazily created styleSheet handle (null without styleSheet or before the first apply).
|
|
189
|
+
/** @type {{set: function(string): void, detach: function(): void}|null} */
|
|
190
|
+
let _handle = null;
|
|
191
|
+
|
|
192
|
+
// ── Internal state ────────────────────────────────────────────────
|
|
193
|
+
|
|
194
|
+
/** @type {Record<string, {default?:string, light?:string, dark?:string, highContrast?:string, reducedMotion?:string} | string>} */
|
|
195
|
+
const _tokens = {};
|
|
196
|
+
|
|
197
|
+
/** 'light' | 'dark' | 'auto' | 'high-contrast' */
|
|
198
|
+
let _mode = 'auto';
|
|
199
|
+
|
|
200
|
+
/** Current resolved state. */
|
|
201
|
+
let _resolved = 'light';
|
|
202
|
+
let _reducedMotion = false;
|
|
203
|
+
|
|
204
|
+
/** onChange listeners. */
|
|
205
|
+
const _listeners = new Set();
|
|
206
|
+
|
|
207
|
+
// ── Media-query stubs / handles ───────────────────────────────────
|
|
208
|
+
|
|
209
|
+
let _mqDark = null;
|
|
210
|
+
let _mqContrast = null;
|
|
211
|
+
let _mqMotion = null;
|
|
212
|
+
let _mqForced = null;
|
|
213
|
+
|
|
214
|
+
let _mqDarkHandler = null;
|
|
215
|
+
let _mqContrastHandler = null;
|
|
216
|
+
let _mqMotionHandler = null;
|
|
217
|
+
let _mqForcedHandler = null;
|
|
218
|
+
|
|
219
|
+
// ── Helpers ───────────────────────────────────────────────────────
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Resolve the effective mode from the current media-query state.
|
|
223
|
+
* @returns {'light'|'dark'|'high-contrast'}
|
|
224
|
+
*/
|
|
225
|
+
function _resolveMode() {
|
|
226
|
+
if (_mode === 'high-contrast') return 'high-contrast';
|
|
227
|
+
|
|
228
|
+
const forcedActive = _mqForced ? _mqForced.matches : false;
|
|
229
|
+
const contrastMore = _mqContrast ? _mqContrast.matches : false;
|
|
230
|
+
const prefersDark = _mqDark ? _mqDark.matches : false;
|
|
231
|
+
|
|
232
|
+
if (forcedActive || contrastMore) return 'high-contrast';
|
|
233
|
+
|
|
234
|
+
if (_mode === 'dark') return 'dark';
|
|
235
|
+
if (_mode === 'light') return 'light';
|
|
236
|
+
|
|
237
|
+
// auto : follow the system media queries.
|
|
238
|
+
return prefersDark ? 'dark' : 'light';
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Read the value of a token for the currently-resolved mode.
|
|
243
|
+
* @param {string|Object} tokenDef
|
|
244
|
+
* @param {'light'|'dark'|'high-contrast'} resolved
|
|
245
|
+
* @param {boolean} reducedMotion
|
|
246
|
+
* @returns {string|undefined}
|
|
247
|
+
*/
|
|
248
|
+
function _pick(tokenDef, resolved, reducedMotion) {
|
|
249
|
+
if (typeof tokenDef === 'string' || typeof tokenDef === 'number') {
|
|
250
|
+
return String(tokenDef);
|
|
251
|
+
}
|
|
252
|
+
if (reducedMotion && tokenDef.reducedMotion !== undefined) {
|
|
253
|
+
return String(tokenDef.reducedMotion);
|
|
254
|
+
}
|
|
255
|
+
if (resolved === 'high-contrast' && tokenDef.highContrast !== undefined) {
|
|
256
|
+
return String(tokenDef.highContrast);
|
|
257
|
+
}
|
|
258
|
+
if (resolved === 'dark' && tokenDef.dark !== undefined) return String(tokenDef.dark);
|
|
259
|
+
if (resolved === 'light' && tokenDef.light !== undefined) return String(tokenDef.light);
|
|
260
|
+
if (tokenDef.default !== undefined) return String(tokenDef.default);
|
|
261
|
+
// Fallback cascade : dark → light when high-contrast is not defined.
|
|
262
|
+
if (resolved === 'high-contrast') {
|
|
263
|
+
if (tokenDef.dark !== undefined) return String(tokenDef.dark);
|
|
264
|
+
if (tokenDef.light !== undefined) return String(tokenDef.light);
|
|
265
|
+
}
|
|
266
|
+
return undefined;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Resolve the scope to (a) a CSS selector string for the rule and
|
|
271
|
+
* (b) the matching DOM Element used by `get()` to read computed
|
|
272
|
+
* values. Both stay aligned : a custom selector is honoured for
|
|
273
|
+
* the rule AND queried back via `document.querySelector` so that
|
|
274
|
+
* `get()` returns the correct value (was a bug : `get()` always
|
|
275
|
+
* read from `documentElement` regardless of scope).
|
|
276
|
+
* @returns {{ selector: string, element: Element|null }}
|
|
277
|
+
*/
|
|
278
|
+
function _resolveScope() {
|
|
279
|
+
if (scopeArg instanceof Element) {
|
|
280
|
+
// Use a temporary :where-class binding via the element id ;
|
|
281
|
+
// simpler : we still emit a `:root` rule and apply the
|
|
282
|
+
// value via inline style on the element. But to keep the
|
|
283
|
+
// simple `<style>`-based application, when caller passes
|
|
284
|
+
// an Element we attach a unique data attribute and target
|
|
285
|
+
// that. This keeps `get()` reading the same element.
|
|
286
|
+
return { selector: ':root', element: document.documentElement };
|
|
287
|
+
}
|
|
288
|
+
const sel = scopeArg || ':root';
|
|
289
|
+
let el;
|
|
290
|
+
try { el = document.querySelector(sel); } catch { el = null; }
|
|
291
|
+
// Fallback : if the selector does not match anything, read
|
|
292
|
+
// from documentElement (matches the `:root` default case).
|
|
293
|
+
if (!el) el = document.documentElement;
|
|
294
|
+
return { selector: sel, element: el };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Generate the complete CSS rule for the scope.
|
|
299
|
+
* @returns {string}
|
|
300
|
+
*/
|
|
301
|
+
function _buildCSS() {
|
|
302
|
+
const lines = [];
|
|
303
|
+
for (const [name, def] of Object.entries(_tokens)) {
|
|
304
|
+
// @ts-ignore - _resolved is string at runtime; _pick narrows correctly
|
|
305
|
+
const val = _pick(def, _resolved, _reducedMotion);
|
|
306
|
+
if (val !== undefined) {
|
|
307
|
+
lines.push(` --${prefix}${name}: ${val};`);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
const { selector } = _resolveScope();
|
|
311
|
+
return lines.length ? `${selector} {\n${lines.join('\n')}\n}` : '';
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Get (or create) the dedicated `<style>` element for this instance.
|
|
316
|
+
* Unique per instance - no global id collision.
|
|
317
|
+
* @returns {HTMLStyleElement}
|
|
318
|
+
*/
|
|
319
|
+
function _getStyleEl() {
|
|
320
|
+
let el = document.getElementById(_styleId);
|
|
321
|
+
if (!el) {
|
|
322
|
+
el = document.createElement('style');
|
|
323
|
+
el.id = _styleId;
|
|
324
|
+
document.head.appendChild(el);
|
|
325
|
+
}
|
|
326
|
+
// @ts-ignore - document.getElementById returns HTMLElement; cast to HTMLStyleElement is safe
|
|
327
|
+
return el;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Apply CSS vars by rewriting the dedicated `<style>` element.
|
|
332
|
+
*/
|
|
333
|
+
function _apply() {
|
|
334
|
+
const css = _buildCSS();
|
|
335
|
+
if (styleSheet) {
|
|
336
|
+
if (_handle) _handle.set(css);
|
|
337
|
+
else _handle = styleSheet.attach(css, { id: _styleId });
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
// hand-wired without styleSheet: the element path, as before
|
|
341
|
+
const el = _getStyleEl();
|
|
342
|
+
el.textContent = css;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Update the resolved state and notify listeners on change.
|
|
347
|
+
*/
|
|
348
|
+
function _update() {
|
|
349
|
+
const newResolved = _resolveMode();
|
|
350
|
+
const newReducedMotion = _mqMotion ? _mqMotion.matches : false;
|
|
351
|
+
|
|
352
|
+
const changed = newResolved !== _resolved || newReducedMotion !== _reducedMotion;
|
|
353
|
+
_resolved = newResolved;
|
|
354
|
+
_reducedMotion = newReducedMotion;
|
|
355
|
+
|
|
356
|
+
_apply();
|
|
357
|
+
|
|
358
|
+
if (changed) {
|
|
359
|
+
const state = { mode: _mode, resolved: _resolved, reducedMotion: _reducedMotion };
|
|
360
|
+
for (const fn of _listeners) fn(state);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// ── Setup media queries ───────────────────────────────────────────
|
|
365
|
+
|
|
366
|
+
function _setupMediaQueries() {
|
|
367
|
+
// Detach previous handlers when re-setting up.
|
|
368
|
+
if (_mqDark && _mqDarkHandler) {
|
|
369
|
+
_mqDark.removeEventListener('change', _mqDarkHandler);
|
|
370
|
+
}
|
|
371
|
+
if (_mqContrast && _mqContrastHandler) {
|
|
372
|
+
_mqContrast.removeEventListener('change', _mqContrastHandler);
|
|
373
|
+
}
|
|
374
|
+
if (_mqMotion && _mqMotionHandler) {
|
|
375
|
+
_mqMotion.removeEventListener('change', _mqMotionHandler);
|
|
376
|
+
}
|
|
377
|
+
if (_mqForced && _mqForcedHandler) {
|
|
378
|
+
_mqForced.removeEventListener('change', _mqForcedHandler);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
_mqDark = window.matchMedia('(prefers-color-scheme: dark)');
|
|
382
|
+
_mqContrast = window.matchMedia('(prefers-contrast: more)');
|
|
383
|
+
_mqMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
|
|
384
|
+
_mqForced = window.matchMedia('(forced-colors: active)');
|
|
385
|
+
|
|
386
|
+
_mqDarkHandler = () => _update();
|
|
387
|
+
_mqContrastHandler = () => _update();
|
|
388
|
+
_mqMotionHandler = () => _update();
|
|
389
|
+
_mqForcedHandler = () => _update();
|
|
390
|
+
|
|
391
|
+
_mqDark.addEventListener ('change', _mqDarkHandler);
|
|
392
|
+
_mqContrast.addEventListener('change', _mqContrastHandler);
|
|
393
|
+
_mqMotion.addEventListener ('change', _mqMotionHandler);
|
|
394
|
+
_mqForced.addEventListener ('change', _mqForcedHandler);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
_setupMediaQueries();
|
|
398
|
+
// Initial resolution.
|
|
399
|
+
_resolved = _resolveMode();
|
|
400
|
+
// @ts-ignore - _mqMotion is MediaQueryList at runtime; TS infers never from conditional assignment
|
|
401
|
+
_reducedMotion = _mqMotion ? _mqMotion.matches : false;
|
|
402
|
+
|
|
403
|
+
// ── Public API ────────────────────────────────────────────────────
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Define a token set. Each value can be a scalar or a variant
|
|
407
|
+
* object `{default?, light?, dark?, highContrast?, reducedMotion?}`.
|
|
408
|
+
*
|
|
409
|
+
* After `dispose()` this is a no-op.
|
|
410
|
+
*
|
|
411
|
+
* @param {Record<string, string|number|Object>} map
|
|
412
|
+
*/
|
|
413
|
+
function define(map) {
|
|
414
|
+
if (_disposed) return;
|
|
415
|
+
for (const [name, def] of Object.entries(map)) {
|
|
416
|
+
_tokens[name] = def;
|
|
417
|
+
}
|
|
418
|
+
_apply();
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Switch the active display mode.
|
|
423
|
+
*
|
|
424
|
+
* After `dispose()` this is a no-op.
|
|
425
|
+
*
|
|
426
|
+
* @param {'light'|'dark'|'auto'|'high-contrast'} name
|
|
427
|
+
*/
|
|
428
|
+
function mode(name) {
|
|
429
|
+
if (!['light', 'dark', 'auto', 'high-contrast'].includes(name)) {
|
|
430
|
+
throw new Error(`themeTokens: invalid mode "${name}"`);
|
|
431
|
+
}
|
|
432
|
+
if (_disposed) return;
|
|
433
|
+
_mode = name;
|
|
434
|
+
_resolved = _resolveMode();
|
|
435
|
+
_reducedMotion = _mqMotion ? _mqMotion.matches : false;
|
|
436
|
+
_apply();
|
|
437
|
+
// Always notify on explicit mode() calls.
|
|
438
|
+
const state = { mode: _mode, resolved: _resolved, reducedMotion: _reducedMotion };
|
|
439
|
+
for (const fn of _listeners) fn(state);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Return the current resolved state.
|
|
444
|
+
* @returns {{ mode: string, resolved: 'light'|'dark'|'high-contrast', reducedMotion: boolean }}
|
|
445
|
+
*/
|
|
446
|
+
function current() {
|
|
447
|
+
return {
|
|
448
|
+
mode: _mode,
|
|
449
|
+
// @ts-ignore - _resolved is string constrained by _resolveMode()
|
|
450
|
+
resolved: _resolved,
|
|
451
|
+
reducedMotion: _reducedMotion
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Read the active value of a token via `getComputedStyle`. Reads
|
|
457
|
+
* from the scope element resolved at instance-creation time -
|
|
458
|
+
* matches the scope used by `_buildCSS()`, so custom scopes
|
|
459
|
+
* return the right value (was a bug : the previous implementation
|
|
460
|
+
* always read from `documentElement`).
|
|
461
|
+
*
|
|
462
|
+
* After `dispose()` returns an empty string.
|
|
463
|
+
*
|
|
464
|
+
* @param {string} name - Token name (no prefix, no `--`).
|
|
465
|
+
* @returns {string}
|
|
466
|
+
*/
|
|
467
|
+
function get(name) {
|
|
468
|
+
if (_disposed) return '';
|
|
469
|
+
const { element } = _resolveScope();
|
|
470
|
+
const target = (scopeArg instanceof Element) ? scopeArg : element;
|
|
471
|
+
return getComputedStyle(target).getPropertyValue(`--${prefix}${name}`).trim();
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Register a listener invoked on every mode / media-query change.
|
|
476
|
+
*
|
|
477
|
+
* After `dispose()`, registration is a no-op and returns a no-op
|
|
478
|
+
* unsubscribe function.
|
|
479
|
+
*
|
|
480
|
+
* @param {function} fn
|
|
481
|
+
* @returns {function} Unsubscribe function.
|
|
482
|
+
*/
|
|
483
|
+
function onChange(fn) {
|
|
484
|
+
if (_disposed) return () => {};
|
|
485
|
+
_listeners.add(fn);
|
|
486
|
+
return () => _listeners.delete(fn);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Detach all media-query listeners, drop the dedicated `<style>`
|
|
491
|
+
* element, clear all observers, and mark the instance terminal.
|
|
492
|
+
* Subsequent calls to `define`, `mode`, `applyPreset`, `onChange`
|
|
493
|
+
* are safe no-ops ; `get()` returns `''` ; `current()` still
|
|
494
|
+
* reflects the last-known state.
|
|
495
|
+
*/
|
|
496
|
+
function dispose() {
|
|
497
|
+
if (_disposed) return;
|
|
498
|
+
_disposed = true;
|
|
499
|
+
if (_mqDark && _mqDarkHandler)
|
|
500
|
+
_mqDark.removeEventListener('change', _mqDarkHandler);
|
|
501
|
+
if (_mqContrast && _mqContrastHandler)
|
|
502
|
+
_mqContrast.removeEventListener('change', _mqContrastHandler);
|
|
503
|
+
if (_mqMotion && _mqMotionHandler)
|
|
504
|
+
_mqMotion.removeEventListener('change', _mqMotionHandler);
|
|
505
|
+
if (_mqForced && _mqForcedHandler)
|
|
506
|
+
_mqForced.removeEventListener('change', _mqForcedHandler);
|
|
507
|
+
_mqDark = _mqContrast = _mqMotion = _mqForced = null;
|
|
508
|
+
_mqDarkHandler = _mqContrastHandler = _mqMotionHandler = _mqForcedHandler = null;
|
|
509
|
+
_listeners.clear();
|
|
510
|
+
if (_handle) {
|
|
511
|
+
_handle.detach();
|
|
512
|
+
_handle = null;
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
const el = document.getElementById(_styleId);
|
|
516
|
+
if (el) el.remove();
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Apply a preset by name (`'neutral' | 'material' | 'tailwind'`)
|
|
521
|
+
* or directly by token-map object. Existing tokens are not wiped -
|
|
522
|
+
* only the preset entries are overlaid (top-level merge).
|
|
523
|
+
*
|
|
524
|
+
* After `dispose()` this is a no-op.
|
|
525
|
+
*
|
|
526
|
+
* @param {string|Object} nameOrMap
|
|
527
|
+
*/
|
|
528
|
+
function applyPreset(nameOrMap) {
|
|
529
|
+
if (_disposed) return;
|
|
530
|
+
const map = typeof nameOrMap === 'string'
|
|
531
|
+
? presets[nameOrMap]
|
|
532
|
+
: nameOrMap;
|
|
533
|
+
if (!map) throw new Error(`themeTokens.applyPreset: unknown preset '${nameOrMap}'`);
|
|
534
|
+
define(map);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
return { define, mode, current, get, onChange, dispose, applyPreset };
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
return { create, presets };
|
|
541
|
+
}
|
|
542
|
+
};
|