@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
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
// Copyright (c) 2026 AwaCloud SAS
|
|
2
|
+
// Author: Matthieu Bouilloux
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview Short sound clips in memory: record from a microphone stream,
|
|
7
|
+
* shape, encode, and play back at any rate (Web Audio + MediaRecorder).
|
|
8
|
+
*
|
|
9
|
+
* Built for clips of a second or two (a voice tag, a sound effect): a clip is
|
|
10
|
+
* an `AudioBuffer` held in memory. Nothing is written to storage and nothing
|
|
11
|
+
* is sent anywhere — moving a clip is the caller's business, through
|
|
12
|
+
* `clip.bytes()` (a 16-bit PCM WAV) and `fromBytes` on the other side.
|
|
13
|
+
*
|
|
14
|
+
* ```
|
|
15
|
+
* support() → { context, recorder, mimeTypes }
|
|
16
|
+
* unlock() → Promise<void> create / resume the AudioContext (in a user gesture)
|
|
17
|
+
* record(handle, { maxMs, mimeType }) → Recording { level(), stop(), cancel() }
|
|
18
|
+
* fromBytes(arrayBuffer) → Promise<Clip> decodeAudioData (WAV, Ogg, WebM …)
|
|
19
|
+
* fromBuffer(audioBuffer) → Clip a synthesised sound
|
|
20
|
+
* trim(clip, { thresholdDb }) → Clip drop leading / trailing silence
|
|
21
|
+
* normalize(clip, { peak }) → Clip scale to a peak
|
|
22
|
+
* play(clip, { rate, gain, when }) → Voice { stop(), ended }
|
|
23
|
+
* rate(semitones) → number 2^(s/12)
|
|
24
|
+
* disposeAll() → Promise<void> stop voices, drop clips, close the context
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* `record` takes a `StreamHandle` from the `media` module (`media.audio.start()`)
|
|
28
|
+
* or a bare `MediaStream`. The context is created lazily; browsers start it
|
|
29
|
+
* suspended until a user gesture, so call `unlock()` from a click before the
|
|
30
|
+
* first `play`. Main thread only: Web Audio and MediaRecorder do not exist in
|
|
31
|
+
* workers. Compatible with sanity `base` (no `Math.random`, no timing APIs —
|
|
32
|
+
* clip ids are a counter, durations come from the buffers).
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A clip held in memory.
|
|
37
|
+
* @typedef {object} SoundClip
|
|
38
|
+
* @property {string} id
|
|
39
|
+
* @property {number} durationMs
|
|
40
|
+
* @property {number} sampleRate
|
|
41
|
+
* @property {number} channels
|
|
42
|
+
* @property {AudioBuffer} buffer
|
|
43
|
+
* @property {() => Promise<ArrayBuffer>} bytes A 16-bit PCM WAV of the current buffer.
|
|
44
|
+
* @property {() => void} dispose Release the buffer; any later use throws `TypeError`.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A recording in progress.
|
|
49
|
+
* @typedef {object} SoundRecording
|
|
50
|
+
* @property {() => number} level Live RMS level, 0..1 (0 once stopped).
|
|
51
|
+
* @property {() => Promise<SoundClip>} stop Stop and decode; idempotent (the auto-stop at `maxMs` included).
|
|
52
|
+
* @property {() => void} cancel Drop it; `stop()` then rejects.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A clip playing.
|
|
57
|
+
* @typedef {object} SoundVoice
|
|
58
|
+
* @property {() => void} stop
|
|
59
|
+
* @property {Promise<void>} ended Resolves when the voice ends or is stopped.
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Public API returned by `sound.factory()`.
|
|
64
|
+
* @typedef {object} SoundAPI
|
|
65
|
+
* @property {() => {context: boolean, recorder: boolean, mimeTypes: string[]}} support
|
|
66
|
+
* @property {() => Promise<void>} unlock
|
|
67
|
+
* @property {(source: object, opts?: {maxMs?: number, mimeType?: string}) => SoundRecording} record
|
|
68
|
+
* @property {(bytes: ArrayBuffer) => Promise<SoundClip>} fromBytes
|
|
69
|
+
* @property {(buffer: AudioBuffer) => SoundClip} fromBuffer
|
|
70
|
+
* @property {(clip: SoundClip, opts?: {thresholdDb?: number}) => SoundClip} trim
|
|
71
|
+
* @property {(clip: SoundClip, opts?: {peak?: number}) => SoundClip} normalize
|
|
72
|
+
* @property {(clip: SoundClip, opts?: {rate?: number, gain?: number, when?: number}) => SoundVoice} play
|
|
73
|
+
* @property {(semitones: number) => number} rate
|
|
74
|
+
* @property {() => Promise<void>} disposeAll
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
export const sound = {
|
|
78
|
+
name: 'sound',
|
|
79
|
+
version: '1.0.0',
|
|
80
|
+
type: 'fw.dom.query',
|
|
81
|
+
dependencies: [],
|
|
82
|
+
|
|
83
|
+
/** @returns {SoundAPI} */
|
|
84
|
+
factory() {
|
|
85
|
+
const MIME_CANDIDATES = ['audio/webm;codecs=opus', 'audio/ogg;codecs=opus', 'audio/mp4', 'audio/webm', 'audio/ogg'];
|
|
86
|
+
|
|
87
|
+
/** @type {AudioContext|null} */
|
|
88
|
+
let _ctx = null;
|
|
89
|
+
let _seq = 0;
|
|
90
|
+
/** @type {Set<SoundClip>} */
|
|
91
|
+
const _clips = new Set();
|
|
92
|
+
/** @type {Set<{source: AudioBufferSourceNode}>} */
|
|
93
|
+
const _voices = new Set();
|
|
94
|
+
|
|
95
|
+
const _Ctx = () => (typeof AudioContext !== 'undefined' ? AudioContext
|
|
96
|
+
// @ts-ignore - the prefixed constructor of older Safari
|
|
97
|
+
: (globalThis.webkitAudioContext || null));
|
|
98
|
+
const _Rec = () => (typeof MediaRecorder !== 'undefined' ? MediaRecorder : null);
|
|
99
|
+
|
|
100
|
+
/** The context, created on first need. */
|
|
101
|
+
function _context() {
|
|
102
|
+
if (_ctx) return _ctx;
|
|
103
|
+
const C = _Ctx();
|
|
104
|
+
if (!C) throw new TypeError('sound: Web Audio is not available here');
|
|
105
|
+
_ctx = new C();
|
|
106
|
+
return _ctx;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function support() {
|
|
110
|
+
const R = _Rec();
|
|
111
|
+
return {
|
|
112
|
+
context: !!_Ctx(),
|
|
113
|
+
recorder: !!R,
|
|
114
|
+
mimeTypes: R && typeof R.isTypeSupported === 'function' ? MIME_CANDIDATES.filter((t) => R.isTypeSupported(t)) : [],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async function unlock() {
|
|
119
|
+
const ctx = _context();
|
|
120
|
+
if (ctx.state !== 'running') await ctx.resume();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Wrap an AudioBuffer of the current context as a clip. */
|
|
124
|
+
function _clip(buffer) {
|
|
125
|
+
let alive = true;
|
|
126
|
+
const live = () => { if (!alive) throw new TypeError('sound: the clip was disposed'); };
|
|
127
|
+
/** @type {SoundClip} */
|
|
128
|
+
const clip = {
|
|
129
|
+
id: 'clip-' + (++_seq),
|
|
130
|
+
durationMs: buffer.length * 1000 / buffer.sampleRate,
|
|
131
|
+
sampleRate: buffer.sampleRate,
|
|
132
|
+
channels: buffer.numberOfChannels,
|
|
133
|
+
buffer,
|
|
134
|
+
bytes: async () => { live(); return _wav(buffer); },
|
|
135
|
+
dispose: () => { alive = false; _clips.delete(clip); },
|
|
136
|
+
};
|
|
137
|
+
Object.defineProperty(clip, '_live', { value: live });
|
|
138
|
+
_clips.add(clip);
|
|
139
|
+
return clip;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** @param {SoundClip} clip */
|
|
143
|
+
function _check(clip) {
|
|
144
|
+
// @ts-ignore - the private liveness probe set by _clip
|
|
145
|
+
if (!clip || typeof clip._live !== 'function') throw new TypeError('sound: not a clip');
|
|
146
|
+
// @ts-ignore
|
|
147
|
+
clip._live();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** A fresh buffer of the context holding `channels` arrays. */
|
|
151
|
+
function _bufferFrom(arrays, sampleRate) {
|
|
152
|
+
const out = _context().createBuffer(arrays.length, Math.max(1, arrays[0].length), sampleRate);
|
|
153
|
+
arrays.forEach((a, c) => out.getChannelData(c).set(a));
|
|
154
|
+
return out;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const _channels = (buffer) => Array.from({ length: buffer.numberOfChannels }, (_, c) => buffer.getChannelData(c));
|
|
158
|
+
|
|
159
|
+
function fromBuffer(buffer) {
|
|
160
|
+
if (!buffer || typeof buffer.getChannelData !== 'function' || !(buffer.length > 0)) {
|
|
161
|
+
throw new TypeError('sound: fromBuffer needs a non-empty AudioBuffer');
|
|
162
|
+
}
|
|
163
|
+
return _clip(_bufferFrom(_channels(buffer), buffer.sampleRate));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async function fromBytes(bytes) {
|
|
167
|
+
if (!(bytes instanceof ArrayBuffer)) throw new TypeError('sound: fromBytes needs an ArrayBuffer');
|
|
168
|
+
// decodeAudioData detaches its input in some engines: decode a copy
|
|
169
|
+
const buffer = await _context().decodeAudioData(bytes.slice(0));
|
|
170
|
+
return _clip(buffer);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function trim(clip, opts) {
|
|
174
|
+
_check(clip);
|
|
175
|
+
const db = opts && opts.thresholdDb !== undefined ? opts.thresholdDb : -45;
|
|
176
|
+
if (typeof db !== 'number' || !Number.isFinite(db) || db > 0) throw new TypeError('sound: thresholdDb must be a finite number <= 0');
|
|
177
|
+
const thr = 10 ** (db / 20);
|
|
178
|
+
const ch = _channels(clip.buffer);
|
|
179
|
+
const loud = (i) => ch.some((a) => Math.abs(a[i]) > thr);
|
|
180
|
+
let first = 0;
|
|
181
|
+
while (first < clip.buffer.length && !loud(first)) first++;
|
|
182
|
+
if (first === clip.buffer.length) return _clip(_bufferFrom(ch.map(() => new Float32Array(1)), clip.sampleRate));
|
|
183
|
+
let last = clip.buffer.length - 1;
|
|
184
|
+
while (last > first && !loud(last)) last--;
|
|
185
|
+
return _clip(_bufferFrom(ch.map((a) => a.slice(first, last + 1)), clip.sampleRate));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function normalize(clip, opts) {
|
|
189
|
+
_check(clip);
|
|
190
|
+
const peak = opts && opts.peak !== undefined ? opts.peak : 0.9;
|
|
191
|
+
if (typeof peak !== 'number' || !(peak > 0 && peak <= 1)) throw new TypeError('sound: peak must be in (0, 1]');
|
|
192
|
+
const ch = _channels(clip.buffer);
|
|
193
|
+
let max = 0;
|
|
194
|
+
for (const a of ch) for (const x of a) max = Math.max(max, Math.abs(x));
|
|
195
|
+
const k = max === 0 ? 1 : peak / max;
|
|
196
|
+
return _clip(_bufferFrom(ch.map((a) => a.map((x) => x * k)), clip.sampleRate));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function play(clip, opts) {
|
|
200
|
+
_check(clip);
|
|
201
|
+
const o = opts || {};
|
|
202
|
+
const r = o.rate === undefined ? 1 : o.rate;
|
|
203
|
+
const g = o.gain === undefined ? 1 : o.gain;
|
|
204
|
+
if (typeof r !== 'number' || !(r > 0) || !Number.isFinite(r)) throw new TypeError('sound: rate must be a positive number');
|
|
205
|
+
if (typeof g !== 'number' || !(g >= 0) || !Number.isFinite(g)) throw new TypeError('sound: gain must be a non-negative number');
|
|
206
|
+
if (o.when !== undefined && (typeof o.when !== 'number' || !(o.when >= 0))) throw new TypeError('sound: when must be a time >= 0');
|
|
207
|
+
const ctx = _context();
|
|
208
|
+
const source = ctx.createBufferSource();
|
|
209
|
+
source.buffer = clip.buffer;
|
|
210
|
+
source.playbackRate.value = r;
|
|
211
|
+
const gain = ctx.createGain();
|
|
212
|
+
gain.gain.value = g;
|
|
213
|
+
source.connect(gain).connect(ctx.destination);
|
|
214
|
+
const voice = { source };
|
|
215
|
+
let done;
|
|
216
|
+
const ended = new Promise((res) => { done = res; });
|
|
217
|
+
source.onended = () => {
|
|
218
|
+
_voices.delete(voice);
|
|
219
|
+
try { source.disconnect(); gain.disconnect(); } catch (_e) { /* already disconnected */ }
|
|
220
|
+
done();
|
|
221
|
+
};
|
|
222
|
+
_voices.add(voice);
|
|
223
|
+
source.start(o.when);
|
|
224
|
+
return {
|
|
225
|
+
stop() { try { source.stop(); } catch (_e) { /* not started or already stopped */ } },
|
|
226
|
+
ended,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const rate = (semitones) => 2 ** (semitones / 12);
|
|
231
|
+
|
|
232
|
+
function record(source, opts) {
|
|
233
|
+
const stream = source && source.stream ? source.stream : source;
|
|
234
|
+
if (!stream || typeof stream.getAudioTracks !== 'function') throw new TypeError('sound: record needs a StreamHandle or a MediaStream');
|
|
235
|
+
const o = opts || {};
|
|
236
|
+
const maxMs = o.maxMs === undefined ? 1500 : o.maxMs;
|
|
237
|
+
if (typeof maxMs !== 'number' || !(maxMs > 0) || !Number.isFinite(maxMs)) throw new TypeError('sound: maxMs must be a positive number');
|
|
238
|
+
const R = _Rec();
|
|
239
|
+
if (!R) throw new TypeError('sound: MediaRecorder is not available here');
|
|
240
|
+
let mimeType = o.mimeType;
|
|
241
|
+
if (mimeType !== undefined && !(typeof R.isTypeSupported === 'function' && R.isTypeSupported(mimeType))) {
|
|
242
|
+
throw new TypeError('sound: the recorder cannot write ' + mimeType);
|
|
243
|
+
}
|
|
244
|
+
if (mimeType === undefined) mimeType = support().mimeTypes[0];
|
|
245
|
+
|
|
246
|
+
const ctx = _context();
|
|
247
|
+
const input = ctx.createMediaStreamSource(stream);
|
|
248
|
+
const analyser = ctx.createAnalyser();
|
|
249
|
+
analyser.fftSize = 2048;
|
|
250
|
+
input.connect(analyser);
|
|
251
|
+
const frame = new Float32Array(analyser.fftSize);
|
|
252
|
+
const recorder = mimeType ? new R(stream, { mimeType }) : new R(stream);
|
|
253
|
+
const chunks = [];
|
|
254
|
+
let state = 'recording';
|
|
255
|
+
/** @type {Promise<SoundClip>|null} */
|
|
256
|
+
let result = null;
|
|
257
|
+
let settle;
|
|
258
|
+
const release = () => { try { input.disconnect(); analyser.disconnect(); } catch (_e) { /* gone */ } };
|
|
259
|
+
|
|
260
|
+
recorder.ondataavailable = (e) => { if (e.data && e.data.size) chunks.push(e.data); };
|
|
261
|
+
recorder.onstop = () => { if (settle) settle(); };
|
|
262
|
+
recorder.start();
|
|
263
|
+
const timer = setTimeout(() => { finish(); }, maxMs);
|
|
264
|
+
|
|
265
|
+
function finish() {
|
|
266
|
+
if (result) return result;
|
|
267
|
+
if (state === 'cancelled') return Promise.reject(new Error('sound: recording cancelled'));
|
|
268
|
+
state = 'stopping';
|
|
269
|
+
clearTimeout(timer);
|
|
270
|
+
result = new Promise((res) => { settle = res; })
|
|
271
|
+
.then(() => new Blob(chunks, { type: recorder.mimeType }).arrayBuffer())
|
|
272
|
+
.then((ab) => ctx.decodeAudioData(ab))
|
|
273
|
+
.then((buffer) => { state = 'stopped'; release(); return _clip(buffer); });
|
|
274
|
+
if (recorder.state !== 'inactive') recorder.stop(); else settle();
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return {
|
|
279
|
+
level() {
|
|
280
|
+
if (state !== 'recording') return 0;
|
|
281
|
+
analyser.getFloatTimeDomainData(frame);
|
|
282
|
+
let sum = 0;
|
|
283
|
+
for (const x of frame) sum += x * x;
|
|
284
|
+
return Math.min(1, Math.sqrt(sum / frame.length));
|
|
285
|
+
},
|
|
286
|
+
stop: finish,
|
|
287
|
+
cancel() {
|
|
288
|
+
if (state !== 'recording') return;
|
|
289
|
+
state = 'cancelled';
|
|
290
|
+
clearTimeout(timer);
|
|
291
|
+
recorder.ondataavailable = null;
|
|
292
|
+
recorder.onstop = null;
|
|
293
|
+
if (recorder.state !== 'inactive') recorder.stop();
|
|
294
|
+
release();
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async function disposeAll() {
|
|
300
|
+
for (const v of Array.from(_voices)) { try { v.source.stop(); } catch (_e) { /* not playing */ } }
|
|
301
|
+
_voices.clear();
|
|
302
|
+
for (const c of Array.from(_clips)) c.dispose();
|
|
303
|
+
const ctx = _ctx;
|
|
304
|
+
_ctx = null;
|
|
305
|
+
if (ctx && ctx.state !== 'closed') await ctx.close();
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** A 16-bit PCM WAV (RIFF) of an AudioBuffer, channels interleaved. */
|
|
309
|
+
function _wav(buffer) {
|
|
310
|
+
const ch = _channels(buffer);
|
|
311
|
+
const n = buffer.length;
|
|
312
|
+
const out = new ArrayBuffer(44 + n * ch.length * 2);
|
|
313
|
+
const v = new DataView(out);
|
|
314
|
+
const tag = (o, s) => { for (let i = 0; i < 4; i++) v.setUint8(o + i, s.charCodeAt(i)); };
|
|
315
|
+
tag(0, 'RIFF'); v.setUint32(4, 36 + n * ch.length * 2, true); tag(8, 'WAVE');
|
|
316
|
+
tag(12, 'fmt '); v.setUint32(16, 16, true); v.setUint16(20, 1, true); v.setUint16(22, ch.length, true);
|
|
317
|
+
v.setUint32(24, buffer.sampleRate, true); v.setUint32(28, buffer.sampleRate * ch.length * 2, true);
|
|
318
|
+
v.setUint16(32, ch.length * 2, true); v.setUint16(34, 16, true);
|
|
319
|
+
tag(36, 'data'); v.setUint32(40, n * ch.length * 2, true);
|
|
320
|
+
let o = 44;
|
|
321
|
+
for (let i = 0; i < n; i++) {
|
|
322
|
+
for (const a of ch) {
|
|
323
|
+
// x 32768 then clamp: the scale decoders divide by
|
|
324
|
+
v.setInt16(o, Math.max(-32768, Math.min(32767, Math.round(a[i] * 32768))), true);
|
|
325
|
+
o += 2;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return out;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return { support, unlock, record, fromBytes, fromBuffer, trim, normalize, play, rate, disposeAll };
|
|
332
|
+
}
|
|
333
|
+
};
|