@metamask/snaps-utils 8.0.1 → 8.1.1
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 +21 -1
- package/dist/array.cjs +17 -0
- package/dist/array.cjs.map +1 -0
- package/dist/array.d.cts +11 -0
- package/dist/array.d.cts.map +1 -0
- package/dist/array.d.mts +11 -0
- package/dist/array.d.mts.map +1 -0
- package/dist/array.mjs +12 -7
- package/dist/array.mjs.map +1 -1
- package/dist/auxiliary-files.cjs +39 -0
- package/dist/auxiliary-files.cjs.map +1 -0
- package/dist/auxiliary-files.d.cts +17 -0
- package/dist/auxiliary-files.d.cts.map +1 -0
- package/dist/auxiliary-files.d.mts +17 -0
- package/dist/auxiliary-files.d.mts.map +1 -0
- package/dist/auxiliary-files.mjs +33 -14
- package/dist/auxiliary-files.mjs.map +1 -1
- package/dist/base64.cjs +38 -0
- package/dist/base64.cjs.map +1 -0
- package/dist/base64.d.cts +16 -0
- package/dist/base64.d.cts.map +1 -0
- package/dist/base64.d.mts +16 -0
- package/dist/base64.d.mts.map +1 -0
- package/dist/base64.mjs +32 -12
- package/dist/base64.mjs.map +1 -1
- package/dist/bytes.cjs +22 -0
- package/dist/bytes.cjs.map +1 -0
- package/dist/bytes.d.cts +9 -0
- package/dist/bytes.d.cts.map +1 -0
- package/dist/bytes.d.mts +9 -0
- package/dist/bytes.d.mts.map +1 -0
- package/dist/bytes.mjs +17 -9
- package/dist/bytes.mjs.map +1 -1
- package/dist/caveats.cjs +51 -0
- package/dist/caveats.cjs.map +1 -0
- package/dist/caveats.d.cts +47 -0
- package/dist/caveats.d.cts.map +1 -0
- package/dist/caveats.d.mts +47 -0
- package/dist/caveats.d.mts.map +1 -0
- package/dist/caveats.mjs +47 -7
- package/dist/caveats.mjs.map +1 -1
- package/dist/checksum.cjs +49 -0
- package/dist/checksum.cjs.map +1 -0
- package/dist/checksum.d.cts +22 -0
- package/dist/checksum.d.cts.map +1 -0
- package/dist/checksum.d.mts +22 -0
- package/dist/checksum.d.mts.map +1 -0
- package/dist/checksum.mjs +43 -12
- package/dist/checksum.mjs.map +1 -1
- package/dist/constants.cjs +8 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +2 -0
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +2 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +4 -7
- package/dist/constants.mjs.map +1 -1
- package/dist/cronjob.cjs +70 -0
- package/dist/cronjob.cjs.map +1 -0
- package/dist/cronjob.d.cts +90 -0
- package/dist/cronjob.d.cts.map +1 -0
- package/dist/cronjob.d.mts +90 -0
- package/dist/cronjob.d.mts.map +1 -0
- package/dist/cronjob.mjs +64 -19
- package/dist/cronjob.mjs.map +1 -1
- package/dist/deep-clone.cjs +9 -0
- package/dist/deep-clone.cjs.map +1 -0
- package/dist/deep-clone.d.cts +2 -0
- package/dist/deep-clone.d.cts.map +1 -0
- package/dist/deep-clone.d.mts +2 -0
- package/dist/deep-clone.d.mts.map +1 -0
- package/dist/deep-clone.mjs +9 -7
- package/dist/deep-clone.mjs.map +1 -1
- package/dist/default-endowments.cjs +42 -0
- package/dist/default-endowments.cjs.map +1 -0
- package/dist/default-endowments.d.cts +5 -0
- package/dist/default-endowments.d.cts.map +1 -0
- package/dist/default-endowments.d.mts +5 -0
- package/dist/default-endowments.d.mts.map +1 -0
- package/dist/default-endowments.mjs +38 -7
- package/dist/default-endowments.mjs.map +1 -1
- package/dist/derivation-paths.cjs +215 -0
- package/dist/derivation-paths.cjs.map +1 -0
- package/dist/derivation-paths.d.cts +25 -0
- package/dist/derivation-paths.d.cts.map +1 -0
- package/dist/derivation-paths.d.mts +25 -0
- package/dist/derivation-paths.d.mts.map +1 -0
- package/dist/derivation-paths.mjs +206 -12
- package/dist/derivation-paths.mjs.map +1 -1
- package/dist/entropy.cjs +8 -0
- package/dist/entropy.cjs.map +1 -0
- package/dist/entropy.d.cts +4 -0
- package/dist/entropy.d.cts.map +1 -0
- package/dist/entropy.d.mts +4 -0
- package/dist/entropy.d.mts.map +1 -0
- package/dist/entropy.mjs +4 -9
- package/dist/entropy.mjs.map +1 -1
- package/dist/errors.cjs +189 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +85 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +85 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +179 -18
- package/dist/errors.mjs.map +1 -1
- package/dist/eval-worker.cjs +42 -0
- package/dist/eval-worker.cjs.map +1 -0
- package/dist/eval-worker.d.cts +2 -0
- package/dist/eval-worker.d.cts.map +1 -0
- package/dist/eval-worker.d.mts +2 -0
- package/dist/eval-worker.d.mts.map +1 -0
- package/dist/eval-worker.mjs +28 -31
- package/dist/eval-worker.mjs.map +1 -1
- package/dist/eval.cjs +54 -0
- package/dist/eval.cjs.map +1 -0
- package/dist/eval.d.cts +17 -0
- package/dist/eval.d.cts.map +1 -0
- package/dist/eval.d.mts +17 -0
- package/dist/eval.d.mts.map +1 -0
- package/dist/eval.mjs +66 -16
- package/dist/eval.mjs.map +1 -1
- package/dist/fs.cjs +159 -0
- package/dist/fs.cjs.map +1 -0
- package/dist/fs.d.cts +70 -0
- package/dist/fs.d.cts.map +1 -0
- package/dist/fs.d.mts +70 -0
- package/dist/fs.d.mts.map +1 -0
- package/dist/fs.mjs +144 -27
- package/dist/fs.mjs.map +1 -1
- package/dist/handler-types.cjs +18 -0
- package/dist/handler-types.cjs.map +1 -0
- package/dist/handler-types.d.cts +35 -0
- package/dist/handler-types.d.cts.map +1 -0
- package/dist/handler-types.d.mts +35 -0
- package/dist/handler-types.d.mts.map +1 -0
- package/dist/handler-types.mjs +14 -9
- package/dist/handler-types.mjs.map +1 -1
- package/dist/handlers.cjs +119 -0
- package/dist/handlers.cjs.map +1 -0
- package/dist/handlers.d.cts +750 -0
- package/dist/handlers.d.cts.map +1 -0
- package/dist/handlers.d.mts +750 -0
- package/dist/handlers.d.mts.map +1 -0
- package/dist/handlers.mjs +114 -33
- package/dist/handlers.mjs.map +1 -1
- package/dist/icon.cjs +58 -0
- package/dist/icon.cjs.map +1 -0
- package/dist/icon.d.cts +20 -0
- package/dist/icon.d.cts.map +1 -0
- package/dist/icon.d.mts +20 -0
- package/dist/icon.d.mts.map +1 -0
- package/dist/icon.mjs +52 -14
- package/dist/icon.mjs.map +1 -1
- package/dist/iframe.cjs +54 -0
- package/dist/iframe.cjs.map +1 -0
- package/dist/iframe.d.cts +12 -0
- package/dist/iframe.d.cts.map +1 -0
- package/dist/iframe.d.mts +12 -0
- package/dist/iframe.d.mts.map +1 -0
- package/dist/iframe.mjs +49 -7
- package/dist/iframe.mjs.map +1 -1
- package/dist/iframe.test.browser.cjs +15 -0
- package/dist/iframe.test.browser.cjs.map +1 -0
- package/dist/iframe.test.browser.d.cts +2 -0
- package/dist/iframe.test.browser.d.cts.map +1 -0
- package/dist/iframe.test.browser.d.mts +2 -0
- package/dist/iframe.test.browser.d.mts.map +1 -0
- package/dist/iframe.test.browser.mjs +13 -0
- package/dist/iframe.test.browser.mjs.map +1 -0
- package/dist/index.cjs +49 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +33 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +33 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.executionenv.cjs +25 -0
- package/dist/index.executionenv.cjs.map +1 -0
- package/dist/index.executionenv.d.cts +8 -0
- package/dist/index.executionenv.d.cts.map +1 -0
- package/dist/index.executionenv.d.mts +8 -0
- package/dist/index.executionenv.d.mts.map +1 -0
- package/dist/index.executionenv.mjs +8 -127
- package/dist/index.executionenv.mjs.map +1 -1
- package/dist/index.mjs +32 -397
- package/dist/index.mjs.map +1 -1
- package/dist/json-rpc.cjs +135 -0
- package/dist/json-rpc.cjs.map +1 -0
- package/dist/json-rpc.d.cts +56 -0
- package/dist/json-rpc.d.cts.map +1 -0
- package/dist/json-rpc.d.mts +56 -0
- package/dist/json-rpc.d.mts.map +1 -0
- package/dist/json-rpc.mjs +127 -17
- package/dist/json-rpc.mjs.map +1 -1
- package/dist/json.cjs +34 -0
- package/dist/json.cjs.map +1 -0
- package/dist/json.d.cts +23 -0
- package/dist/json.d.cts.map +1 -0
- package/dist/json.d.mts +23 -0
- package/dist/json.d.mts.map +1 -0
- package/dist/json.mjs +28 -9
- package/dist/json.mjs.map +1 -1
- package/dist/localization.cjs +128 -0
- package/dist/localization.cjs.map +1 -0
- package/dist/localization.d.cts +146 -0
- package/dist/localization.d.cts.map +1 -0
- package/dist/localization.d.mts +146 -0
- package/dist/localization.d.mts.map +1 -0
- package/dist/localization.mjs +119 -22
- package/dist/localization.mjs.map +1 -1
- package/dist/logging.cjs +67 -0
- package/dist/logging.cjs.map +1 -0
- package/dist/logging.d.cts +50 -0
- package/dist/logging.d.cts.map +1 -0
- package/dist/logging.d.mts +50 -0
- package/dist/logging.d.mts.map +1 -0
- package/dist/logging.mjs +60 -13
- package/dist/logging.mjs.map +1 -1
- package/dist/manifest/index.cjs +18 -0
- package/dist/manifest/index.cjs.map +1 -0
- package/dist/manifest/index.d.cts +2 -0
- package/dist/manifest/index.d.cts.map +1 -0
- package/dist/manifest/index.d.mts +2 -0
- package/dist/manifest/index.d.mts.map +1 -0
- package/dist/manifest/index.mjs +1 -64
- package/dist/manifest/index.mjs.map +1 -1
- package/dist/manifest/manifest.cjs +267 -0
- package/dist/manifest/manifest.cjs.map +1 -0
- package/dist/manifest/manifest.d.cts +100 -0
- package/dist/manifest/manifest.d.cts.map +1 -0
- package/dist/manifest/manifest.d.mts +100 -0
- package/dist/manifest/manifest.d.mts.map +1 -0
- package/dist/manifest/manifest.mjs +252 -57
- package/dist/manifest/manifest.mjs.map +1 -1
- package/dist/manifest/node.cjs +19 -0
- package/dist/manifest/node.cjs.map +1 -0
- package/dist/manifest/node.d.cts +3 -0
- package/dist/manifest/node.d.cts.map +1 -0
- package/dist/manifest/node.d.mts +3 -0
- package/dist/manifest/node.d.mts.map +1 -0
- package/dist/manifest/node.mjs +2 -105
- package/dist/manifest/node.mjs.map +1 -1
- package/dist/manifest/validation.cjs +194 -0
- package/dist/manifest/validation.cjs.map +1 -0
- package/dist/manifest/validation.d.cts +254 -0
- package/dist/manifest/validation.d.cts.map +1 -0
- package/dist/manifest/validation.d.mts +254 -0
- package/dist/manifest/validation.d.mts.map +1 -0
- package/dist/manifest/validation.mjs +186 -63
- package/dist/manifest/validation.mjs.map +1 -1
- package/dist/manifest/validator-types.cjs +3 -0
- package/dist/manifest/validator-types.cjs.map +1 -0
- package/dist/manifest/validator-types.d.cts +35 -0
- package/dist/manifest/validator-types.d.cts.map +1 -0
- package/dist/manifest/validator-types.d.mts +35 -0
- package/dist/manifest/validator-types.d.mts.map +1 -0
- package/dist/manifest/validator-types.mjs +1 -0
- package/dist/manifest/validator-types.mjs.map +1 -1
- package/dist/manifest/validator.cjs +109 -0
- package/dist/manifest/validator.cjs.map +1 -0
- package/dist/manifest/validator.d.cts +24 -0
- package/dist/manifest/validator.d.cts.map +1 -0
- package/dist/manifest/validator.d.mts +24 -0
- package/dist/manifest/validator.d.mts.map +1 -0
- package/dist/manifest/validator.mjs +79 -42
- package/dist/manifest/validator.mjs.map +1 -1
- package/dist/manifest/validators/checksum.cjs +23 -0
- package/dist/manifest/validators/checksum.cjs.map +1 -0
- package/dist/manifest/validators/checksum.d.cts +6 -0
- package/dist/manifest/validators/checksum.d.cts.map +1 -0
- package/dist/manifest/validators/checksum.d.mts +6 -0
- package/dist/manifest/validators/checksum.d.mts.map +1 -0
- package/dist/manifest/validators/checksum.mjs +18 -13
- package/dist/manifest/validators/checksum.mjs.map +1 -1
- package/dist/manifest/validators/expected-files.cjs +24 -0
- package/dist/manifest/validators/expected-files.cjs.map +1 -0
- package/dist/manifest/validators/expected-files.d.cts +6 -0
- package/dist/manifest/validators/expected-files.d.cts.map +1 -0
- package/dist/manifest/validators/expected-files.d.mts +6 -0
- package/dist/manifest/validators/expected-files.d.mts.map +1 -0
- package/dist/manifest/validators/expected-files.mjs +19 -7
- package/dist/manifest/validators/expected-files.mjs.map +1 -1
- package/dist/manifest/validators/icon-declared.cjs +15 -0
- package/dist/manifest/validators/icon-declared.cjs.map +1 -0
- package/dist/manifest/validators/icon-declared.d.cts +6 -0
- package/dist/manifest/validators/icon-declared.d.cts.map +1 -0
- package/dist/manifest/validators/icon-declared.d.mts +6 -0
- package/dist/manifest/validators/icon-declared.d.mts.map +1 -0
- package/dist/manifest/validators/icon-declared.mjs +10 -6
- package/dist/manifest/validators/icon-declared.mjs.map +1 -1
- package/dist/manifest/validators/icon-dimensions.cjs +20 -0
- package/dist/manifest/validators/icon-dimensions.cjs.map +1 -0
- package/dist/manifest/validators/icon-dimensions.d.cts +6 -0
- package/dist/manifest/validators/icon-dimensions.d.cts.map +1 -0
- package/dist/manifest/validators/icon-dimensions.d.mts +6 -0
- package/dist/manifest/validators/icon-dimensions.d.mts.map +1 -0
- package/dist/manifest/validators/icon-dimensions.mjs +15 -8
- package/dist/manifest/validators/icon-dimensions.mjs.map +1 -1
- package/dist/manifest/validators/icon-missing.cjs +16 -0
- package/dist/manifest/validators/icon-missing.cjs.map +1 -0
- package/dist/manifest/validators/icon-missing.d.cts +6 -0
- package/dist/manifest/validators/icon-missing.d.cts.map +1 -0
- package/dist/manifest/validators/icon-missing.d.mts +6 -0
- package/dist/manifest/validators/icon-missing.d.mts.map +1 -0
- package/dist/manifest/validators/icon-missing.mjs +11 -6
- package/dist/manifest/validators/icon-missing.mjs.map +1 -1
- package/dist/manifest/validators/index.cjs +31 -0
- package/dist/manifest/validators/index.cjs.map +1 -0
- package/dist/manifest/validators/index.d.cts +15 -0
- package/dist/manifest/validators/index.d.cts.map +1 -0
- package/dist/manifest/validators/index.d.mts +15 -0
- package/dist/manifest/validators/index.d.mts.map +1 -0
- package/dist/manifest/validators/index.mjs +14 -79
- package/dist/manifest/validators/index.mjs.map +1 -1
- package/dist/manifest/validators/is-localization-file.cjs +23 -0
- package/dist/manifest/validators/is-localization-file.cjs.map +1 -0
- package/dist/manifest/validators/is-localization-file.d.cts +6 -0
- package/dist/manifest/validators/is-localization-file.d.cts.map +1 -0
- package/dist/manifest/validators/is-localization-file.d.mts +6 -0
- package/dist/manifest/validators/is-localization-file.d.mts.map +1 -0
- package/dist/manifest/validators/is-localization-file.mjs +18 -10
- package/dist/manifest/validators/is-localization-file.mjs.map +1 -1
- package/dist/manifest/validators/is-package-json.cjs +24 -0
- package/dist/manifest/validators/is-package-json.cjs.map +1 -0
- package/dist/manifest/validators/is-package-json.d.cts +6 -0
- package/dist/manifest/validators/is-package-json.d.cts.map +1 -0
- package/dist/manifest/validators/is-package-json.d.mts +6 -0
- package/dist/manifest/validators/is-package-json.d.mts.map +1 -0
- package/dist/manifest/validators/is-package-json.mjs +19 -9
- package/dist/manifest/validators/is-package-json.mjs.map +1 -1
- package/dist/manifest/validators/is-snap-icon.cjs +24 -0
- package/dist/manifest/validators/is-snap-icon.cjs.map +1 -0
- package/dist/manifest/validators/is-snap-icon.d.cts +6 -0
- package/dist/manifest/validators/is-snap-icon.d.cts.map +1 -0
- package/dist/manifest/validators/is-snap-icon.d.mts +6 -0
- package/dist/manifest/validators/is-snap-icon.d.mts.map +1 -0
- package/dist/manifest/validators/is-snap-icon.mjs +19 -8
- package/dist/manifest/validators/is-snap-icon.mjs.map +1 -1
- package/dist/manifest/validators/is-snap-manifest.cjs +25 -0
- package/dist/manifest/validators/is-snap-manifest.cjs.map +1 -0
- package/dist/manifest/validators/is-snap-manifest.d.cts +6 -0
- package/dist/manifest/validators/is-snap-manifest.d.cts.map +1 -0
- package/dist/manifest/validators/is-snap-manifest.d.mts +6 -0
- package/dist/manifest/validators/is-snap-manifest.d.mts.map +1 -0
- package/dist/manifest/validators/is-snap-manifest.mjs +20 -21
- package/dist/manifest/validators/is-snap-manifest.mjs.map +1 -1
- package/dist/manifest/validators/manifest-localization.cjs +30 -0
- package/dist/manifest/validators/manifest-localization.cjs.map +1 -0
- package/dist/manifest/validators/manifest-localization.d.cts +6 -0
- package/dist/manifest/validators/manifest-localization.d.cts.map +1 -0
- package/dist/manifest/validators/manifest-localization.d.mts +6 -0
- package/dist/manifest/validators/manifest-localization.d.mts.map +1 -0
- package/dist/manifest/validators/manifest-localization.mjs +25 -8
- package/dist/manifest/validators/manifest-localization.mjs.map +1 -1
- package/dist/manifest/validators/package-json-recommended-fields.cjs +18 -0
- package/dist/manifest/validators/package-json-recommended-fields.cjs.map +1 -0
- package/dist/manifest/validators/package-json-recommended-fields.d.cts +6 -0
- package/dist/manifest/validators/package-json-recommended-fields.d.cts.map +1 -0
- package/dist/manifest/validators/package-json-recommended-fields.d.mts +6 -0
- package/dist/manifest/validators/package-json-recommended-fields.d.mts.map +1 -0
- package/dist/manifest/validators/package-json-recommended-fields.mjs +13 -6
- package/dist/manifest/validators/package-json-recommended-fields.mjs.map +1 -1
- package/dist/manifest/validators/package-name-match.cjs +21 -0
- package/dist/manifest/validators/package-name-match.cjs.map +1 -0
- package/dist/manifest/validators/package-name-match.d.cts +6 -0
- package/dist/manifest/validators/package-name-match.d.cts.map +1 -0
- package/dist/manifest/validators/package-name-match.d.mts +6 -0
- package/dist/manifest/validators/package-name-match.d.mts.map +1 -0
- package/dist/manifest/validators/package-name-match.mjs +16 -7
- package/dist/manifest/validators/package-name-match.mjs.map +1 -1
- package/dist/manifest/validators/repository-match.cjs +29 -0
- package/dist/manifest/validators/repository-match.cjs.map +1 -0
- package/dist/manifest/validators/repository-match.d.cts +6 -0
- package/dist/manifest/validators/repository-match.d.cts.map +1 -0
- package/dist/manifest/validators/repository-match.d.mts +6 -0
- package/dist/manifest/validators/repository-match.d.mts.map +1 -0
- package/dist/manifest/validators/repository-match.mjs +28 -8
- package/dist/manifest/validators/repository-match.mjs.map +1 -1
- package/dist/manifest/validators/version-match.cjs +21 -0
- package/dist/manifest/validators/version-match.cjs.map +1 -0
- package/dist/manifest/validators/version-match.d.cts +6 -0
- package/dist/manifest/validators/version-match.d.cts.map +1 -0
- package/dist/manifest/validators/version-match.d.mts +6 -0
- package/dist/manifest/validators/version-match.d.mts.map +1 -0
- package/dist/manifest/validators/version-match.mjs +16 -7
- package/dist/manifest/validators/version-match.mjs.map +1 -1
- package/dist/mock.cjs +113 -0
- package/dist/mock.cjs.map +1 -0
- package/dist/mock.d.cts +15 -0
- package/dist/mock.d.cts.map +1 -0
- package/dist/mock.d.mts +15 -0
- package/dist/mock.d.mts.map +1 -0
- package/dist/mock.mjs +103 -11
- package/dist/mock.mjs.map +1 -1
- package/dist/namespace.cjs +136 -0
- package/dist/namespace.cjs.map +1 -0
- package/dist/namespace.d.cts +130 -0
- package/dist/namespace.d.cts.map +1 -0
- package/dist/namespace.d.mts +130 -0
- package/dist/namespace.d.mts.map +1 -0
- package/dist/namespace.mjs +125 -43
- package/dist/namespace.mjs.map +1 -1
- package/dist/node.cjs +25 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +8 -0
- package/dist/node.d.cts.map +1 -0
- package/dist/node.d.mts +8 -0
- package/dist/node.d.mts.map +1 -0
- package/dist/node.mjs +8 -475
- package/dist/node.mjs.map +1 -1
- package/dist/path.cjs +21 -0
- package/dist/path.cjs.map +1 -0
- package/dist/path.d.cts +8 -0
- package/dist/path.d.cts.map +1 -0
- package/dist/path.d.mts +8 -0
- package/dist/path.d.mts.map +1 -0
- package/dist/path.mjs +16 -7
- package/dist/path.mjs.map +1 -1
- package/dist/post-process.cjs +339 -0
- package/dist/post-process.cjs.map +1 -0
- package/dist/post-process.d.cts +72 -0
- package/dist/post-process.d.cts.map +1 -0
- package/dist/post-process.d.mts +72 -0
- package/dist/post-process.d.mts.map +1 -0
- package/dist/post-process.mjs +335 -9
- package/dist/post-process.mjs.map +1 -1
- package/dist/promise.cjs +3 -0
- package/dist/promise.cjs.map +1 -0
- package/dist/promise.d.cts +2 -0
- package/dist/promise.d.cts.map +1 -0
- package/dist/promise.d.mts +2 -0
- package/dist/promise.d.mts.map +1 -0
- package/dist/promise.mjs +1 -1
- package/dist/promise.mjs.map +1 -1
- package/dist/snaps.cjs +207 -0
- package/dist/snaps.cjs.map +1 -0
- package/dist/snaps.d.cts +174 -0
- package/dist/snaps.d.cts.map +1 -0
- package/dist/snaps.d.mts +174 -0
- package/dist/snaps.d.mts.map +1 -0
- package/dist/snaps.mjs +200 -45
- package/dist/snaps.mjs.map +1 -1
- package/dist/strings.cjs +15 -0
- package/dist/strings.cjs.map +1 -0
- package/dist/strings.d.cts +9 -0
- package/dist/strings.d.cts.map +1 -0
- package/dist/strings.d.mts +9 -0
- package/dist/strings.d.mts.map +1 -0
- package/dist/strings.mjs +10 -7
- package/dist/strings.mjs.map +1 -1
- package/dist/structs.cjs +316 -0
- package/dist/structs.cjs.map +1 -0
- package/dist/structs.d.cts +181 -0
- package/dist/structs.d.cts.map +1 -0
- package/dist/structs.d.mts +181 -0
- package/dist/structs.d.mts.map +1 -0
- package/dist/structs.mjs +300 -32
- package/dist/structs.mjs.map +1 -1
- package/dist/svg.cjs +49 -0
- package/dist/svg.cjs.map +1 -0
- package/dist/svg.d.cts +15 -0
- package/dist/svg.d.cts.map +1 -0
- package/dist/svg.d.mts +15 -0
- package/dist/svg.d.mts.map +1 -0
- package/dist/svg.mjs +43 -9
- package/dist/svg.mjs.map +1 -1
- package/dist/types.cjs +64 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +104 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +104 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +58 -21
- package/dist/types.mjs.map +1 -1
- package/dist/ui.cjs +405 -0
- package/dist/ui.cjs.map +1 -0
- package/dist/ui.d.cts +93 -0
- package/dist/ui.d.cts.map +1 -0
- package/dist/ui.d.mts +93 -0
- package/dist/ui.d.mts.map +1 -0
- package/dist/ui.mjs +391 -23
- package/dist/ui.mjs.map +1 -1
- package/dist/validation.cjs +23 -0
- package/dist/validation.cjs.map +1 -0
- package/dist/validation.d.cts +9 -0
- package/dist/validation.d.cts.map +1 -0
- package/dist/validation.d.mts +9 -0
- package/dist/validation.d.mts.map +1 -0
- package/dist/validation.mjs +18 -26
- package/dist/validation.mjs.map +1 -1
- package/dist/versions.cjs +44 -0
- package/dist/versions.cjs.map +1 -0
- package/dist/versions.d.cts +22 -0
- package/dist/versions.d.cts.map +1 -0
- package/dist/versions.d.mts +22 -0
- package/dist/versions.d.mts.map +1 -0
- package/dist/versions.mjs +38 -11
- package/dist/versions.mjs.map +1 -1
- package/dist/virtual-file/VirtualFile.cjs +75 -0
- package/dist/virtual-file/VirtualFile.cjs.map +1 -0
- package/dist/virtual-file/VirtualFile.d.cts +35 -0
- package/dist/virtual-file/VirtualFile.d.cts.map +1 -0
- package/dist/virtual-file/VirtualFile.d.mts +35 -0
- package/dist/virtual-file/VirtualFile.d.mts.map +1 -0
- package/dist/virtual-file/VirtualFile.mjs +70 -8
- package/dist/virtual-file/VirtualFile.mjs.map +1 -1
- package/dist/virtual-file/index.cjs +18 -0
- package/dist/virtual-file/index.cjs.map +1 -0
- package/dist/virtual-file/index.d.cts +2 -0
- package/dist/virtual-file/index.d.cts.map +1 -0
- package/dist/virtual-file/index.d.mts +2 -0
- package/dist/virtual-file/index.d.mts.map +1 -0
- package/dist/virtual-file/index.mjs +1 -9
- package/dist/virtual-file/index.mjs.map +1 -1
- package/dist/virtual-file/node.cjs +19 -0
- package/dist/virtual-file/node.cjs.map +1 -0
- package/dist/virtual-file/node.d.cts +3 -0
- package/dist/virtual-file/node.d.cts.map +1 -0
- package/dist/virtual-file/node.d.mts +3 -0
- package/dist/virtual-file/node.d.mts.map +1 -0
- package/dist/virtual-file/node.mjs +2 -16
- package/dist/virtual-file/node.mjs.map +1 -1
- package/dist/virtual-file/toVirtualFile.cjs +31 -0
- package/dist/virtual-file/toVirtualFile.cjs.map +1 -0
- package/dist/virtual-file/toVirtualFile.d.cts +24 -0
- package/dist/virtual-file/toVirtualFile.d.cts.map +1 -0
- package/dist/virtual-file/toVirtualFile.d.mts +24 -0
- package/dist/virtual-file/toVirtualFile.d.mts.map +1 -0
- package/dist/virtual-file/toVirtualFile.mjs +25 -11
- package/dist/virtual-file/toVirtualFile.mjs.map +1 -1
- package/package.json +36 -24
- package/dist/array.js +0 -8
- package/dist/array.js.map +0 -1
- package/dist/auxiliary-files.js +0 -15
- package/dist/auxiliary-files.js.map +0 -1
- package/dist/base64.js +0 -13
- package/dist/base64.js.map +0 -1
- package/dist/bytes.js +0 -10
- package/dist/bytes.js.map +0 -1
- package/dist/caveats.js +0 -8
- package/dist/caveats.js.map +0 -1
- package/dist/checksum.js +0 -13
- package/dist/checksum.js.map +0 -1
- package/dist/chunk-37EUH3KZ.js +0 -293
- package/dist/chunk-37EUH3KZ.js.map +0 -1
- package/dist/chunk-3N27GIUS.mjs +0 -229
- package/dist/chunk-3N27GIUS.mjs.map +0 -1
- package/dist/chunk-3OXW5H4F.js +0 -30
- package/dist/chunk-3OXW5H4F.js.map +0 -1
- package/dist/chunk-3RFGTBEP.js +0 -151
- package/dist/chunk-3RFGTBEP.js.map +0 -1
- package/dist/chunk-3RUWAMJT.mjs +0 -31
- package/dist/chunk-3RUWAMJT.mjs.map +0 -1
- package/dist/chunk-3S4INAGA.mjs +0 -18
- package/dist/chunk-3S4INAGA.mjs.map +0 -1
- package/dist/chunk-44VFHYJO.js +0 -249
- package/dist/chunk-44VFHYJO.js.map +0 -1
- package/dist/chunk-4AA3TKRJ.mjs +0 -153
- package/dist/chunk-4AA3TKRJ.mjs.map +0 -1
- package/dist/chunk-4BGZ2CHC.mjs +0 -22
- package/dist/chunk-4BGZ2CHC.mjs.map +0 -1
- package/dist/chunk-4CMD46B2.js +0 -1
- package/dist/chunk-4CMD46B2.js.map +0 -1
- package/dist/chunk-4RYTYEUQ.mjs +0 -33
- package/dist/chunk-4RYTYEUQ.mjs.map +0 -1
- package/dist/chunk-4ZJOU3LR.js +0 -71
- package/dist/chunk-4ZJOU3LR.js.map +0 -1
- package/dist/chunk-53QXTM77.js +0 -229
- package/dist/chunk-53QXTM77.js.map +0 -1
- package/dist/chunk-5FTBWYCW.mjs +0 -27
- package/dist/chunk-5FTBWYCW.mjs.map +0 -1
- package/dist/chunk-5MABKEV7.mjs +0 -66
- package/dist/chunk-5MABKEV7.mjs.map +0 -1
- package/dist/chunk-5R7UF7KM.mjs +0 -21
- package/dist/chunk-5R7UF7KM.mjs.map +0 -1
- package/dist/chunk-5UAPBOKO.js +0 -37
- package/dist/chunk-5UAPBOKO.js.map +0 -1
- package/dist/chunk-5WKQI22S.js +0 -7
- package/dist/chunk-5WKQI22S.js.map +0 -1
- package/dist/chunk-63OXILAY.mjs +0 -69
- package/dist/chunk-63OXILAY.mjs.map +0 -1
- package/dist/chunk-6ATNGN44.js +0 -300
- package/dist/chunk-6ATNGN44.js.map +0 -1
- package/dist/chunk-6HXIPMBN.js +0 -103
- package/dist/chunk-6HXIPMBN.js.map +0 -1
- package/dist/chunk-6YJWU77L.js +0 -19
- package/dist/chunk-6YJWU77L.js.map +0 -1
- package/dist/chunk-7HLSXEHK.mjs +0 -300
- package/dist/chunk-7HLSXEHK.mjs.map +0 -1
- package/dist/chunk-7LG4D4XA.mjs +0 -20
- package/dist/chunk-7LG4D4XA.mjs.map +0 -1
- package/dist/chunk-7P62OIGX.js +0 -69
- package/dist/chunk-7P62OIGX.js.map +0 -1
- package/dist/chunk-7T7FYH77.mjs +0 -37
- package/dist/chunk-7T7FYH77.mjs.map +0 -1
- package/dist/chunk-7VJ2BOVU.js +0 -15
- package/dist/chunk-7VJ2BOVU.js.map +0 -1
- package/dist/chunk-A3RRMELT.mjs +0 -1
- package/dist/chunk-A3RRMELT.mjs.map +0 -1
- package/dist/chunk-AMW2VJ3N.js +0 -32
- package/dist/chunk-AMW2VJ3N.js.map +0 -1
- package/dist/chunk-ANYNWSCA.mjs +0 -104
- package/dist/chunk-ANYNWSCA.mjs.map +0 -1
- package/dist/chunk-AOGVLPQZ.js +0 -18
- package/dist/chunk-AOGVLPQZ.js.map +0 -1
- package/dist/chunk-AS5P6JRP.mjs +0 -9
- package/dist/chunk-AS5P6JRP.mjs.map +0 -1
- package/dist/chunk-ASZWZ7JT.js +0 -20
- package/dist/chunk-ASZWZ7JT.js.map +0 -1
- package/dist/chunk-B5GNTDE2.js +0 -109
- package/dist/chunk-B5GNTDE2.js.map +0 -1
- package/dist/chunk-BGSO2GQC.mjs +0 -41
- package/dist/chunk-BGSO2GQC.mjs.map +0 -1
- package/dist/chunk-BPK5BH7K.js +0 -27
- package/dist/chunk-BPK5BH7K.js.map +0 -1
- package/dist/chunk-CJK7DDV2.mjs +0 -109
- package/dist/chunk-CJK7DDV2.mjs.map +0 -1
- package/dist/chunk-CPG2UGAA.js +0 -25
- package/dist/chunk-CPG2UGAA.js.map +0 -1
- package/dist/chunk-DE22V5AO.mjs +0 -53
- package/dist/chunk-DE22V5AO.mjs.map +0 -1
- package/dist/chunk-DEQUNIME.js +0 -53
- package/dist/chunk-DEQUNIME.js.map +0 -1
- package/dist/chunk-DKO64Y4H.mjs +0 -27
- package/dist/chunk-DKO64Y4H.mjs.map +0 -1
- package/dist/chunk-E3BDBG6T.js +0 -20
- package/dist/chunk-E3BDBG6T.js.map +0 -1
- package/dist/chunk-EFRPCO3C.js +0 -1
- package/dist/chunk-EFRPCO3C.js.map +0 -1
- package/dist/chunk-EVHDXNOC.mjs +0 -35
- package/dist/chunk-EVHDXNOC.mjs.map +0 -1
- package/dist/chunk-EYWMVDCD.mjs +0 -25
- package/dist/chunk-EYWMVDCD.mjs.map +0 -1
- package/dist/chunk-FA4QIZH6.js +0 -1
- package/dist/chunk-FA4QIZH6.js.map +0 -1
- package/dist/chunk-FBZ5SU7X.js +0 -189
- package/dist/chunk-FBZ5SU7X.js.map +0 -1
- package/dist/chunk-GIVJAZ2Q.mjs +0 -248
- package/dist/chunk-GIVJAZ2Q.mjs.map +0 -1
- package/dist/chunk-GJAVOB7B.js +0 -24
- package/dist/chunk-GJAVOB7B.js.map +0 -1
- package/dist/chunk-GXSTPU7D.mjs +0 -293
- package/dist/chunk-GXSTPU7D.mjs.map +0 -1
- package/dist/chunk-HY4W6BUH.mjs +0 -24
- package/dist/chunk-HY4W6BUH.mjs.map +0 -1
- package/dist/chunk-HYF7Q6VY.mjs +0 -1
- package/dist/chunk-HYF7Q6VY.mjs.map +0 -1
- package/dist/chunk-I2SWLZ34.js +0 -30
- package/dist/chunk-I2SWLZ34.js.map +0 -1
- package/dist/chunk-IELPPZJP.mjs +0 -189
- package/dist/chunk-IELPPZJP.mjs.map +0 -1
- package/dist/chunk-IJX3CXOY.js +0 -9
- package/dist/chunk-IJX3CXOY.js.map +0 -1
- package/dist/chunk-IPUL74MZ.mjs +0 -30
- package/dist/chunk-IPUL74MZ.mjs.map +0 -1
- package/dist/chunk-IV3FSWZ7.mjs +0 -9
- package/dist/chunk-IV3FSWZ7.mjs.map +0 -1
- package/dist/chunk-IVDERT5W.js +0 -22
- package/dist/chunk-IVDERT5W.js.map +0 -1
- package/dist/chunk-JETPRED3.js +0 -248
- package/dist/chunk-JETPRED3.js.map +0 -1
- package/dist/chunk-JI5NQ2C3.mjs +0 -1
- package/dist/chunk-JI5NQ2C3.mjs.map +0 -1
- package/dist/chunk-JJTIVHFX.mjs +0 -38
- package/dist/chunk-JJTIVHFX.mjs.map +0 -1
- package/dist/chunk-L2DHOOBX.js +0 -33
- package/dist/chunk-L2DHOOBX.js.map +0 -1
- package/dist/chunk-LEKZPKS2.js +0 -21
- package/dist/chunk-LEKZPKS2.js.map +0 -1
- package/dist/chunk-LHQP7CUJ.mjs +0 -107
- package/dist/chunk-LHQP7CUJ.mjs.map +0 -1
- package/dist/chunk-LOJA2ZS4.js +0 -107
- package/dist/chunk-LOJA2ZS4.js.map +0 -1
- package/dist/chunk-LQSEBGOX.js +0 -34
- package/dist/chunk-LQSEBGOX.js.map +0 -1
- package/dist/chunk-MDOG3S4V.mjs +0 -34
- package/dist/chunk-MDOG3S4V.mjs.map +0 -1
- package/dist/chunk-MFGLB75H.mjs +0 -22
- package/dist/chunk-MFGLB75H.mjs.map +0 -1
- package/dist/chunk-MKFQAXRF.js +0 -21
- package/dist/chunk-MKFQAXRF.js.map +0 -1
- package/dist/chunk-MQURBEO4.mjs +0 -16
- package/dist/chunk-MQURBEO4.mjs.map +0 -1
- package/dist/chunk-MWAZGSRO.js +0 -75
- package/dist/chunk-MWAZGSRO.js.map +0 -1
- package/dist/chunk-N2JAYIUP.mjs +0 -75
- package/dist/chunk-N2JAYIUP.mjs.map +0 -1
- package/dist/chunk-N4MA537G.js +0 -22
- package/dist/chunk-N4MA537G.js.map +0 -1
- package/dist/chunk-N5HVDE3P.mjs +0 -30
- package/dist/chunk-N5HVDE3P.mjs.map +0 -1
- package/dist/chunk-N722KRZW.js +0 -41
- package/dist/chunk-N722KRZW.js.map +0 -1
- package/dist/chunk-NNYGTNHP.mjs +0 -1
- package/dist/chunk-NNYGTNHP.mjs.map +0 -1
- package/dist/chunk-NSVVZNSD.mjs +0 -183
- package/dist/chunk-NSVVZNSD.mjs.map +0 -1
- package/dist/chunk-NUCLSR2G.js +0 -8
- package/dist/chunk-NUCLSR2G.js.map +0 -1
- package/dist/chunk-OBN2WDFU.js +0 -38
- package/dist/chunk-OBN2WDFU.js.map +0 -1
- package/dist/chunk-P252LKUT.mjs +0 -9
- package/dist/chunk-P252LKUT.mjs.map +0 -1
- package/dist/chunk-PAOTMYIM.mjs +0 -69
- package/dist/chunk-PAOTMYIM.mjs.map +0 -1
- package/dist/chunk-PJMEJVOB.mjs +0 -29
- package/dist/chunk-PJMEJVOB.mjs.map +0 -1
- package/dist/chunk-PLBSSUVY.js +0 -29
- package/dist/chunk-PLBSSUVY.js.map +0 -1
- package/dist/chunk-PLNIERDY.js +0 -34
- package/dist/chunk-PLNIERDY.js.map +0 -1
- package/dist/chunk-PO5BBHHX.mjs +0 -22
- package/dist/chunk-PO5BBHHX.mjs.map +0 -1
- package/dist/chunk-PTOH2SVI.mjs +0 -55
- package/dist/chunk-PTOH2SVI.mjs.map +0 -1
- package/dist/chunk-PZF4KWU2.mjs +0 -151
- package/dist/chunk-PZF4KWU2.mjs.map +0 -1
- package/dist/chunk-QD3LTING.js +0 -34
- package/dist/chunk-QD3LTING.js.map +0 -1
- package/dist/chunk-QGCNQRIQ.js +0 -35
- package/dist/chunk-QGCNQRIQ.js.map +0 -1
- package/dist/chunk-QYPLUMB7.mjs +0 -249
- package/dist/chunk-QYPLUMB7.mjs.map +0 -1
- package/dist/chunk-RAZ7XG4Z.mjs +0 -1
- package/dist/chunk-RAZ7XG4Z.mjs.map +0 -1
- package/dist/chunk-RNMJQSVQ.js +0 -69
- package/dist/chunk-RNMJQSVQ.js.map +0 -1
- package/dist/chunk-RRFKK45V.mjs +0 -15
- package/dist/chunk-RRFKK45V.mjs.map +0 -1
- package/dist/chunk-S3BWTUTZ.js +0 -31
- package/dist/chunk-S3BWTUTZ.js.map +0 -1
- package/dist/chunk-SKKANJ45.mjs +0 -19
- package/dist/chunk-SKKANJ45.mjs.map +0 -1
- package/dist/chunk-SPCIIRSB.mjs +0 -7
- package/dist/chunk-SPCIIRSB.mjs.map +0 -1
- package/dist/chunk-SRMDDOVO.mjs +0 -20
- package/dist/chunk-SRMDDOVO.mjs.map +0 -1
- package/dist/chunk-SYYDKPK3.js +0 -15
- package/dist/chunk-SYYDKPK3.js.map +0 -1
- package/dist/chunk-T2VA4YJE.js +0 -104
- package/dist/chunk-T2VA4YJE.js.map +0 -1
- package/dist/chunk-T3VM5YXY.js +0 -1
- package/dist/chunk-T3VM5YXY.js.map +0 -1
- package/dist/chunk-T3YY4JIJ.js +0 -9
- package/dist/chunk-T3YY4JIJ.js.map +0 -1
- package/dist/chunk-T5ZOOZ46.js +0 -22
- package/dist/chunk-T5ZOOZ46.js.map +0 -1
- package/dist/chunk-TAMKWZ4E.js +0 -183
- package/dist/chunk-TAMKWZ4E.js.map +0 -1
- package/dist/chunk-TFP64TMV.js +0 -1
- package/dist/chunk-TFP64TMV.js.map +0 -1
- package/dist/chunk-TYWGZIOF.mjs +0 -34
- package/dist/chunk-TYWGZIOF.mjs.map +0 -1
- package/dist/chunk-UAINMOUU.js +0 -18
- package/dist/chunk-UAINMOUU.js.map +0 -1
- package/dist/chunk-UNNEBOL4.mjs +0 -15
- package/dist/chunk-UNNEBOL4.mjs.map +0 -1
- package/dist/chunk-UW74NLTC.mjs +0 -18
- package/dist/chunk-UW74NLTC.mjs.map +0 -1
- package/dist/chunk-VBYSWMSU.js +0 -66
- package/dist/chunk-VBYSWMSU.js.map +0 -1
- package/dist/chunk-VEPYH26P.js +0 -27
- package/dist/chunk-VEPYH26P.js.map +0 -1
- package/dist/chunk-VIAHMNTA.mjs +0 -34
- package/dist/chunk-VIAHMNTA.mjs.map +0 -1
- package/dist/chunk-VWLBM7XM.js +0 -1
- package/dist/chunk-VWLBM7XM.js.map +0 -1
- package/dist/chunk-W7A3BYUP.mjs +0 -1
- package/dist/chunk-W7A3BYUP.mjs.map +0 -1
- package/dist/chunk-W7KRIAIX.js +0 -55
- package/dist/chunk-W7KRIAIX.js.map +0 -1
- package/dist/chunk-X2GGUOMY.js +0 -153
- package/dist/chunk-X2GGUOMY.js.map +0 -1
- package/dist/chunk-X3UZCGO5.mjs +0 -103
- package/dist/chunk-X3UZCGO5.mjs.map +0 -1
- package/dist/chunk-XF2AZMWG.mjs +0 -32
- package/dist/chunk-XF2AZMWG.mjs.map +0 -1
- package/dist/chunk-XWYJQWHG.js +0 -56
- package/dist/chunk-XWYJQWHG.js.map +0 -1
- package/dist/chunk-XZ7362GQ.mjs +0 -63
- package/dist/chunk-XZ7362GQ.mjs.map +0 -1
- package/dist/chunk-XZNJFDBF.mjs +0 -21
- package/dist/chunk-XZNJFDBF.mjs.map +0 -1
- package/dist/chunk-YJHQZFR4.mjs +0 -71
- package/dist/chunk-YJHQZFR4.mjs.map +0 -1
- package/dist/chunk-YL2EHYAA.js +0 -16
- package/dist/chunk-YL2EHYAA.js.map +0 -1
- package/dist/chunk-Z2JQNSVL.mjs +0 -8
- package/dist/chunk-Z2JQNSVL.mjs.map +0 -1
- package/dist/chunk-ZT3KKTS2.js +0 -9
- package/dist/chunk-ZT3KKTS2.js.map +0 -1
- package/dist/constants.js +0 -8
- package/dist/constants.js.map +0 -1
- package/dist/cronjob.js +0 -20
- package/dist/cronjob.js.map +0 -1
- package/dist/deep-clone.js +0 -8
- package/dist/deep-clone.js.map +0 -1
- package/dist/default-endowments.js +0 -8
- package/dist/default-endowments.js.map +0 -1
- package/dist/derivation-paths.js +0 -13
- package/dist/derivation-paths.js.map +0 -1
- package/dist/entropy.js +0 -10
- package/dist/entropy.js.map +0 -1
- package/dist/errors.js +0 -20
- package/dist/errors.js.map +0 -1
- package/dist/eval-worker.js +0 -43
- package/dist/eval-worker.js.map +0 -1
- package/dist/eval.js +0 -17
- package/dist/eval.js.map +0 -1
- package/dist/fs.js +0 -28
- package/dist/fs.js.map +0 -1
- package/dist/handler-types.js +0 -10
- package/dist/handler-types.js.map +0 -1
- package/dist/handlers.js +0 -35
- package/dist/handlers.js.map +0 -1
- package/dist/icon.js +0 -15
- package/dist/icon.js.map +0 -1
- package/dist/iframe.js +0 -8
- package/dist/iframe.js.map +0 -1
- package/dist/index.executionenv.js +0 -128
- package/dist/index.executionenv.js.map +0 -1
- package/dist/index.js +0 -398
- package/dist/index.js.map +0 -1
- package/dist/json-rpc.js +0 -18
- package/dist/json-rpc.js.map +0 -1
- package/dist/json.js +0 -10
- package/dist/json.js.map +0 -1
- package/dist/localization.js +0 -23
- package/dist/localization.js.map +0 -1
- package/dist/logging.js +0 -14
- package/dist/logging.js.map +0 -1
- package/dist/manifest/index.js +0 -65
- package/dist/manifest/index.js.map +0 -1
- package/dist/manifest/manifest.js +0 -59
- package/dist/manifest/manifest.js.map +0 -1
- package/dist/manifest/node.js +0 -106
- package/dist/manifest/node.js.map +0 -1
- package/dist/manifest/validation.js +0 -64
- package/dist/manifest/validation.js.map +0 -1
- package/dist/manifest/validator-types.js +0 -1
- package/dist/manifest/validator-types.js.map +0 -1
- package/dist/manifest/validator.js +0 -44
- package/dist/manifest/validator.js.map +0 -1
- package/dist/manifest/validators/checksum.js +0 -15
- package/dist/manifest/validators/checksum.js.map +0 -1
- package/dist/manifest/validators/expected-files.js +0 -9
- package/dist/manifest/validators/expected-files.js.map +0 -1
- package/dist/manifest/validators/icon-declared.js +0 -8
- package/dist/manifest/validators/icon-declared.js.map +0 -1
- package/dist/manifest/validators/icon-dimensions.js +0 -10
- package/dist/manifest/validators/icon-dimensions.js.map +0 -1
- package/dist/manifest/validators/icon-missing.js +0 -8
- package/dist/manifest/validators/icon-missing.js.map +0 -1
- package/dist/manifest/validators/index.js +0 -80
- package/dist/manifest/validators/index.js.map +0 -1
- package/dist/manifest/validators/is-localization-file.js +0 -12
- package/dist/manifest/validators/is-localization-file.js.map +0 -1
- package/dist/manifest/validators/is-package-json.js +0 -11
- package/dist/manifest/validators/is-package-json.js.map +0 -1
- package/dist/manifest/validators/is-snap-icon.js +0 -10
- package/dist/manifest/validators/is-snap-icon.js.map +0 -1
- package/dist/manifest/validators/is-snap-manifest.js +0 -23
- package/dist/manifest/validators/is-snap-manifest.js.map +0 -1
- package/dist/manifest/validators/manifest-localization.js +0 -10
- package/dist/manifest/validators/manifest-localization.js.map +0 -1
- package/dist/manifest/validators/package-json-recommended-fields.js +0 -8
- package/dist/manifest/validators/package-json-recommended-fields.js.map +0 -1
- package/dist/manifest/validators/package-name-match.js +0 -9
- package/dist/manifest/validators/package-name-match.js.map +0 -1
- package/dist/manifest/validators/repository-match.js +0 -10
- package/dist/manifest/validators/repository-match.js.map +0 -1
- package/dist/manifest/validators/version-match.js +0 -9
- package/dist/manifest/validators/version-match.js.map +0 -1
- package/dist/mock.js +0 -13
- package/dist/mock.js.map +0 -1
- package/dist/namespace.js +0 -44
- package/dist/namespace.js.map +0 -1
- package/dist/node.js +0 -476
- package/dist/node.js.map +0 -1
- package/dist/path.js +0 -8
- package/dist/path.js.map +0 -1
- package/dist/post-process.js +0 -10
- package/dist/post-process.js.map +0 -1
- package/dist/promise.js +0 -2
- package/dist/promise.js.map +0 -1
- package/dist/snaps.js +0 -46
- package/dist/snaps.js.map +0 -1
- package/dist/strings.js +0 -8
- package/dist/strings.js.map +0 -1
- package/dist/structs.js +0 -33
- package/dist/structs.js.map +0 -1
- package/dist/svg.js +0 -10
- package/dist/svg.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/array.d.ts +0 -10
- package/dist/types/auxiliary-files.d.ts +0 -16
- package/dist/types/base64.d.ts +0 -15
- package/dist/types/bytes.d.ts +0 -8
- package/dist/types/caveats.d.ts +0 -46
- package/dist/types/checksum.d.ts +0 -21
- package/dist/types/constants.d.ts +0 -1
- package/dist/types/cronjob.d.ts +0 -89
- package/dist/types/deep-clone.d.ts +0 -1
- package/dist/types/default-endowments.d.ts +0 -4
- package/dist/types/derivation-paths.d.ts +0 -24
- package/dist/types/entropy.d.ts +0 -3
- package/dist/types/errors.d.ts +0 -84
- package/dist/types/eval-worker.d.ts +0 -1
- package/dist/types/eval.d.ts +0 -16
- package/dist/types/fs.d.ts +0 -69
- package/dist/types/handler-types.d.ts +0 -34
- package/dist/types/handlers.d.ts +0 -749
- package/dist/types/icon.d.ts +0 -19
- package/dist/types/iframe.d.ts +0 -11
- package/dist/types/iframe.test.browser.d.ts +0 -1
- package/dist/types/index.d.ts +0 -32
- package/dist/types/index.executionenv.d.ts +0 -7
- package/dist/types/json-rpc.d.ts +0 -55
- package/dist/types/json.d.ts +0 -22
- package/dist/types/localization.d.ts +0 -145
- package/dist/types/logging.d.ts +0 -49
- package/dist/types/manifest/index.d.ts +0 -1
- package/dist/types/manifest/manifest.d.ts +0 -98
- package/dist/types/manifest/node.d.ts +0 -2
- package/dist/types/manifest/validation.d.ts +0 -253
- package/dist/types/manifest/validator-types.d.ts +0 -34
- package/dist/types/manifest/validator.d.ts +0 -22
- package/dist/types/manifest/validators/checksum.d.ts +0 -5
- package/dist/types/manifest/validators/expected-files.d.ts +0 -5
- package/dist/types/manifest/validators/icon-declared.d.ts +0 -5
- package/dist/types/manifest/validators/icon-dimensions.d.ts +0 -5
- package/dist/types/manifest/validators/icon-missing.d.ts +0 -5
- package/dist/types/manifest/validators/index.d.ts +0 -14
- package/dist/types/manifest/validators/is-localization-file.d.ts +0 -5
- package/dist/types/manifest/validators/is-package-json.d.ts +0 -5
- package/dist/types/manifest/validators/is-snap-icon.d.ts +0 -5
- package/dist/types/manifest/validators/is-snap-manifest.d.ts +0 -5
- package/dist/types/manifest/validators/manifest-localization.d.ts +0 -5
- package/dist/types/manifest/validators/package-json-recommended-fields.d.ts +0 -5
- package/dist/types/manifest/validators/package-name-match.d.ts +0 -5
- package/dist/types/manifest/validators/repository-match.d.ts +0 -5
- package/dist/types/manifest/validators/version-match.d.ts +0 -5
- package/dist/types/mock.d.ts +0 -14
- package/dist/types/namespace.d.ts +0 -129
- package/dist/types/node.d.ts +0 -7
- package/dist/types/path.d.ts +0 -7
- package/dist/types/post-process.d.ts +0 -71
- package/dist/types/promise.d.ts +0 -1
- package/dist/types/snaps.d.ts +0 -169
- package/dist/types/strings.d.ts +0 -8
- package/dist/types/structs.d.ts +0 -180
- package/dist/types/svg.d.ts +0 -14
- package/dist/types/types.d.ts +0 -103
- package/dist/types/ui.d.ts +0 -84
- package/dist/types/validation.d.ts +0 -8
- package/dist/types/versions.d.ts +0 -21
- package/dist/types/virtual-file/VirtualFile.d.ts +0 -34
- package/dist/types/virtual-file/index.d.ts +0 -1
- package/dist/types/virtual-file/node.d.ts +0 -2
- package/dist/types/virtual-file/toVirtualFile.d.ts +0 -21
- package/dist/types.js +0 -22
- package/dist/types.js.map +0 -1
- package/dist/ui.js +0 -24
- package/dist/ui.js.map +0 -1
- package/dist/validation.js +0 -27
- package/dist/validation.js.map +0 -1
- package/dist/versions.js +0 -12
- package/dist/versions.js.map +0 -1
- package/dist/virtual-file/VirtualFile.js +0 -9
- package/dist/virtual-file/VirtualFile.js.map +0 -1
- package/dist/virtual-file/index.js +0 -10
- package/dist/virtual-file/index.js.map +0 -1
- package/dist/virtual-file/node.js +0 -17
- package/dist/virtual-file/node.js.map +0 -1
- package/dist/virtual-file/toVirtualFile.js +0 -12
- package/dist/virtual-file/toVirtualFile.js.map +0 -1
package/dist/ui.cjs
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serialiseJsx = exports.walkJsx = exports.getJsxChildren = exports.hasChildren = exports.getTotalTextLength = exports.validateJsxLinks = exports.validateTextLinks = exports.validateLink = exports.getJsxElementFromComponent = exports.getTextChildren = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("@metamask/snaps-sdk/jsx-runtime");
|
|
5
|
+
const snaps_sdk_1 = require("@metamask/snaps-sdk");
|
|
6
|
+
const jsx_1 = require("@metamask/snaps-sdk/jsx");
|
|
7
|
+
const utils_1 = require("@metamask/utils");
|
|
8
|
+
const marked_1 = require("marked");
|
|
9
|
+
const MAX_TEXT_LENGTH = 50000; // 50 kb
|
|
10
|
+
const ALLOWED_PROTOCOLS = ['https:', 'mailto:'];
|
|
11
|
+
/**
|
|
12
|
+
* Get the button variant from a legacy button component variant.
|
|
13
|
+
*
|
|
14
|
+
* @param variant - The legacy button component variant.
|
|
15
|
+
* @returns The button variant.
|
|
16
|
+
*/
|
|
17
|
+
function getButtonVariant(variant) {
|
|
18
|
+
switch (variant) {
|
|
19
|
+
case 'primary':
|
|
20
|
+
return 'primary';
|
|
21
|
+
case 'secondary':
|
|
22
|
+
return 'destructive';
|
|
23
|
+
default:
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get the children of a JSX element. If there is only one child, the child is
|
|
29
|
+
* returned directly. Otherwise, the children are returned as an array.
|
|
30
|
+
*
|
|
31
|
+
* @param elements - The JSX elements.
|
|
32
|
+
* @returns The child or children.
|
|
33
|
+
*/
|
|
34
|
+
function getChildren(elements) {
|
|
35
|
+
if (elements.length === 1) {
|
|
36
|
+
return elements[0];
|
|
37
|
+
}
|
|
38
|
+
return elements;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get the text of a link token.
|
|
42
|
+
*
|
|
43
|
+
* @param token - The link token.
|
|
44
|
+
* @returns The text of the link token.
|
|
45
|
+
*/
|
|
46
|
+
function getLinkText(token) {
|
|
47
|
+
if (token.tokens && token.tokens.length > 0) {
|
|
48
|
+
return getChildren(token.tokens.flatMap(getTextChildFromToken));
|
|
49
|
+
}
|
|
50
|
+
return token.href;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get the text child from a list of markdown tokens.
|
|
54
|
+
*
|
|
55
|
+
* @param tokens - The markdown tokens.
|
|
56
|
+
* @returns The text child.
|
|
57
|
+
*/
|
|
58
|
+
function getTextChildFromTokens(tokens) {
|
|
59
|
+
return getChildren(tokens.flatMap(getTextChildFromToken));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get the text child from a markdown token.
|
|
63
|
+
*
|
|
64
|
+
* @param token - The markdown token.
|
|
65
|
+
* @returns The text child.
|
|
66
|
+
*/
|
|
67
|
+
function getTextChildFromToken(token) {
|
|
68
|
+
switch (token.type) {
|
|
69
|
+
case 'link': {
|
|
70
|
+
return (0, jsx_runtime_1.jsx)(jsx_1.Link, { href: token.href, children: getLinkText(token) });
|
|
71
|
+
}
|
|
72
|
+
case 'text':
|
|
73
|
+
return token.text;
|
|
74
|
+
case 'strong':
|
|
75
|
+
return ((0, jsx_runtime_1.jsx)(jsx_1.Bold, { children: getTextChildFromTokens(
|
|
76
|
+
// Due to the way `marked` is typed, `token.tokens` can be
|
|
77
|
+
// `undefined`, but it's a required field of `Tokens.Bold`, so we
|
|
78
|
+
// can safely cast it to `Token[]`.
|
|
79
|
+
token.tokens) }));
|
|
80
|
+
case 'em':
|
|
81
|
+
return ((0, jsx_runtime_1.jsx)(jsx_1.Italic, { children: getTextChildFromTokens(
|
|
82
|
+
// Due to the way `marked` is typed, `token.tokens` can be
|
|
83
|
+
// `undefined`, but it's a required field of `Tokens.Bold`, so we
|
|
84
|
+
// can safely cast it to `Token[]`.
|
|
85
|
+
token.tokens) }));
|
|
86
|
+
default:
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get all text children from a markdown string.
|
|
92
|
+
*
|
|
93
|
+
* @param value - The markdown string.
|
|
94
|
+
* @returns The text children.
|
|
95
|
+
*/
|
|
96
|
+
function getTextChildren(value) {
|
|
97
|
+
const rootTokens = (0, marked_1.lexer)(value, { gfm: false });
|
|
98
|
+
const children = [];
|
|
99
|
+
(0, marked_1.walkTokens)(rootTokens, (token) => {
|
|
100
|
+
if (token.type === 'paragraph') {
|
|
101
|
+
if (children.length > 0) {
|
|
102
|
+
children.push('\n\n');
|
|
103
|
+
}
|
|
104
|
+
const { tokens } = token;
|
|
105
|
+
// We do not need to consider nesting deeper than 1 level here and we can therefore cast.
|
|
106
|
+
children.push(...tokens.flatMap(getTextChildFromToken));
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
110
|
+
return children.filter((child) => child !== null);
|
|
111
|
+
}
|
|
112
|
+
exports.getTextChildren = getTextChildren;
|
|
113
|
+
/**
|
|
114
|
+
* Validate the text size of a component. The text size is the total length of
|
|
115
|
+
* all text in the component.
|
|
116
|
+
*
|
|
117
|
+
* @param component - The component to validate.
|
|
118
|
+
* @throws An error if the text size exceeds the maximum allowed size.
|
|
119
|
+
*/
|
|
120
|
+
function validateComponentTextSize(component) {
|
|
121
|
+
const textSize = getTotalTextLength(component);
|
|
122
|
+
(0, utils_1.assert)(textSize <= MAX_TEXT_LENGTH, `The text in a Snap UI may not be larger than ${MAX_TEXT_LENGTH / 1000} kB.`);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Get a JSX element from a legacy UI component. This supports all legacy UI
|
|
126
|
+
* components, and maps them to their JSX equivalents where possible.
|
|
127
|
+
*
|
|
128
|
+
* This function validates the text size of the component, but does not validate
|
|
129
|
+
* the total size. The total size of the component should be validated before
|
|
130
|
+
* calling this function.
|
|
131
|
+
*
|
|
132
|
+
* @param legacyComponent - The legacy UI component.
|
|
133
|
+
* @returns The JSX element.
|
|
134
|
+
*/
|
|
135
|
+
function getJsxElementFromComponent(legacyComponent) {
|
|
136
|
+
validateComponentTextSize(legacyComponent);
|
|
137
|
+
/**
|
|
138
|
+
* Get the JSX element for a component. This function is recursive and will
|
|
139
|
+
* call itself for child components.
|
|
140
|
+
*
|
|
141
|
+
* @param component - The component to convert to a JSX element.
|
|
142
|
+
* @returns The JSX element.
|
|
143
|
+
*/
|
|
144
|
+
function getElement(component) {
|
|
145
|
+
switch (component.type) {
|
|
146
|
+
case snaps_sdk_1.NodeType.Address:
|
|
147
|
+
return (0, jsx_runtime_1.jsx)(jsx_1.Address, { address: component.value });
|
|
148
|
+
case snaps_sdk_1.NodeType.Button:
|
|
149
|
+
return ((0, jsx_runtime_1.jsx)(jsx_1.Button, { name: component.name, variant: getButtonVariant(component.variant), type: component.buttonType, children: component.value }));
|
|
150
|
+
case snaps_sdk_1.NodeType.Copyable:
|
|
151
|
+
return ((0, jsx_runtime_1.jsx)(jsx_1.Copyable, { value: component.value, sensitive: component.sensitive }));
|
|
152
|
+
case snaps_sdk_1.NodeType.Divider:
|
|
153
|
+
return (0, jsx_runtime_1.jsx)(jsx_1.Divider, {});
|
|
154
|
+
case snaps_sdk_1.NodeType.Form:
|
|
155
|
+
return ((0, jsx_runtime_1.jsx)(jsx_1.Form, { name: component.name, children: getChildren(component.children.map(getElement)) }));
|
|
156
|
+
case snaps_sdk_1.NodeType.Heading:
|
|
157
|
+
return (0, jsx_runtime_1.jsx)(jsx_1.Heading, { children: component.value });
|
|
158
|
+
case snaps_sdk_1.NodeType.Image:
|
|
159
|
+
// `Image` supports `alt`, but the legacy `Image` component does not.
|
|
160
|
+
return (0, jsx_runtime_1.jsx)(jsx_1.Image, { src: component.value });
|
|
161
|
+
case snaps_sdk_1.NodeType.Input:
|
|
162
|
+
return ((0, jsx_runtime_1.jsx)(jsx_1.Field, { label: component.label, error: component.error, children: (0, jsx_runtime_1.jsx)(jsx_1.Input, { name: component.name, type: component.inputType, value: component.value, placeholder: component.placeholder }) }));
|
|
163
|
+
case snaps_sdk_1.NodeType.Panel:
|
|
164
|
+
// `Panel` is renamed to `Box` in JSX.
|
|
165
|
+
return ((0, jsx_runtime_1.jsx)(jsx_1.Box, { children: getChildren(component.children.map(getElement)) }));
|
|
166
|
+
case snaps_sdk_1.NodeType.Row:
|
|
167
|
+
return ((0, jsx_runtime_1.jsx)(jsx_1.Row, { label: component.label, variant: component.variant, children: getElement(component.value) }));
|
|
168
|
+
case snaps_sdk_1.NodeType.Spinner:
|
|
169
|
+
return (0, jsx_runtime_1.jsx)(jsx_1.Spinner, {});
|
|
170
|
+
case snaps_sdk_1.NodeType.Text:
|
|
171
|
+
return (0, jsx_runtime_1.jsx)(jsx_1.Text, { children: getChildren(getTextChildren(component.value)) });
|
|
172
|
+
/* istanbul ignore next 2 */
|
|
173
|
+
default:
|
|
174
|
+
return (0, utils_1.assertExhaustive)(component);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return getElement(legacyComponent);
|
|
178
|
+
}
|
|
179
|
+
exports.getJsxElementFromComponent = getJsxElementFromComponent;
|
|
180
|
+
/**
|
|
181
|
+
* Extract all links from a Markdown text string using the `marked` lexer.
|
|
182
|
+
*
|
|
183
|
+
* @param text - The markdown text string.
|
|
184
|
+
* @returns A list of URLs linked to in the string.
|
|
185
|
+
*/
|
|
186
|
+
function getMarkdownLinks(text) {
|
|
187
|
+
const tokens = (0, marked_1.lexer)(text, { gfm: false });
|
|
188
|
+
const links = [];
|
|
189
|
+
// Walk the lexed tokens and collect all link tokens
|
|
190
|
+
(0, marked_1.walkTokens)(tokens, (token) => {
|
|
191
|
+
if (token.type === 'link') {
|
|
192
|
+
links.push(token);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
return links;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Validate a link against the phishing list.
|
|
199
|
+
*
|
|
200
|
+
* @param link - The link to validate.
|
|
201
|
+
* @param isOnPhishingList - The function that checks the link against the
|
|
202
|
+
* phishing list.
|
|
203
|
+
*/
|
|
204
|
+
function validateLink(link, isOnPhishingList) {
|
|
205
|
+
try {
|
|
206
|
+
const url = new URL(link);
|
|
207
|
+
(0, utils_1.assert)(ALLOWED_PROTOCOLS.includes(url.protocol), `Protocol must be one of: ${ALLOWED_PROTOCOLS.join(', ')}.`);
|
|
208
|
+
const hostname = url.protocol === 'mailto:' ? url.pathname.split('@')[1] : url.hostname;
|
|
209
|
+
(0, utils_1.assert)(!isOnPhishingList(hostname), 'The specified URL is not allowed.');
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
throw new Error(`Invalid URL: ${error?.code === 'ERR_ASSERTION' ? error.message : 'Unable to parse URL.'}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
exports.validateLink = validateLink;
|
|
216
|
+
/**
|
|
217
|
+
* Search for Markdown links in a string and checks them against the phishing
|
|
218
|
+
* list.
|
|
219
|
+
*
|
|
220
|
+
* @param text - The text to verify.
|
|
221
|
+
* @param isOnPhishingList - The function that checks the link against the
|
|
222
|
+
* phishing list.
|
|
223
|
+
* @throws If the text contains a link that is not allowed.
|
|
224
|
+
*/
|
|
225
|
+
function validateTextLinks(text, isOnPhishingList) {
|
|
226
|
+
const links = getMarkdownLinks(text);
|
|
227
|
+
for (const link of links) {
|
|
228
|
+
validateLink(link.href, isOnPhishingList);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
exports.validateTextLinks = validateTextLinks;
|
|
232
|
+
/**
|
|
233
|
+
* Walk a JSX tree and validate each {@link LinkElement} node against the
|
|
234
|
+
* phishing list.
|
|
235
|
+
*
|
|
236
|
+
* @param node - The JSX node to walk.
|
|
237
|
+
* @param isOnPhishingList - The function that checks the link against the
|
|
238
|
+
* phishing list.
|
|
239
|
+
*/
|
|
240
|
+
function validateJsxLinks(node, isOnPhishingList) {
|
|
241
|
+
walkJsx(node, (childNode) => {
|
|
242
|
+
if (childNode.type !== 'Link') {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
validateLink(childNode.props.href, isOnPhishingList);
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
exports.validateJsxLinks = validateJsxLinks;
|
|
249
|
+
/**
|
|
250
|
+
* Calculate the total length of all text in the component.
|
|
251
|
+
*
|
|
252
|
+
* @param component - A custom UI component.
|
|
253
|
+
* @returns The total length of all text components in the component.
|
|
254
|
+
*/
|
|
255
|
+
function getTotalTextLength(component) {
|
|
256
|
+
const { type } = component;
|
|
257
|
+
switch (type) {
|
|
258
|
+
case snaps_sdk_1.NodeType.Panel:
|
|
259
|
+
return component.children.reduce(
|
|
260
|
+
// This is a bug in TypeScript: https://github.com/microsoft/TypeScript/issues/48313
|
|
261
|
+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
262
|
+
(sum, node) => sum + getTotalTextLength(node), 0);
|
|
263
|
+
case snaps_sdk_1.NodeType.Row:
|
|
264
|
+
return getTotalTextLength(component.value);
|
|
265
|
+
case snaps_sdk_1.NodeType.Text:
|
|
266
|
+
return component.value.length;
|
|
267
|
+
default:
|
|
268
|
+
return 0;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
exports.getTotalTextLength = getTotalTextLength;
|
|
272
|
+
/**
|
|
273
|
+
* Check if a JSX element has children.
|
|
274
|
+
*
|
|
275
|
+
* @param element - A JSX element.
|
|
276
|
+
* @returns `true` if the element has children, `false` otherwise.
|
|
277
|
+
*/
|
|
278
|
+
function hasChildren(element) {
|
|
279
|
+
return (0, utils_1.hasProperty)(element.props, 'children');
|
|
280
|
+
}
|
|
281
|
+
exports.hasChildren = hasChildren;
|
|
282
|
+
/**
|
|
283
|
+
* Filter a JSX child to remove `null`, `undefined`, plain booleans, and empty
|
|
284
|
+
* strings.
|
|
285
|
+
*
|
|
286
|
+
* @param child - The JSX child to filter.
|
|
287
|
+
* @returns `true` if the child is not `null`, `undefined`, a plain boolean, or
|
|
288
|
+
* an empty string, `false` otherwise.
|
|
289
|
+
*/
|
|
290
|
+
function filterJsxChild(child) {
|
|
291
|
+
return Boolean(child) && child !== true;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Get the children of a JSX element as an array. If the element has only one
|
|
295
|
+
* child, the child is returned as an array.
|
|
296
|
+
*
|
|
297
|
+
* @param element - A JSX element.
|
|
298
|
+
* @returns The children of the element.
|
|
299
|
+
*/
|
|
300
|
+
function getJsxChildren(element) {
|
|
301
|
+
if (hasChildren(element)) {
|
|
302
|
+
if (Array.isArray(element.props.children)) {
|
|
303
|
+
// @ts-expect-error - Each member of the union type has signatures, but
|
|
304
|
+
// none of those signatures are compatible with each other.
|
|
305
|
+
return element.props.children.filter(filterJsxChild).flat(Infinity);
|
|
306
|
+
}
|
|
307
|
+
if (element.props.children) {
|
|
308
|
+
return [element.props.children];
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return [];
|
|
312
|
+
}
|
|
313
|
+
exports.getJsxChildren = getJsxChildren;
|
|
314
|
+
/**
|
|
315
|
+
* Walk a JSX tree and call a callback on each node.
|
|
316
|
+
*
|
|
317
|
+
* @param node - The JSX node to walk.
|
|
318
|
+
* @param callback - The callback to call on each node.
|
|
319
|
+
* @param depth - The current depth in the JSX tree for a walk.
|
|
320
|
+
* @returns The result of the callback, if any.
|
|
321
|
+
*/
|
|
322
|
+
function walkJsx(node, callback, depth = 0) {
|
|
323
|
+
if (Array.isArray(node)) {
|
|
324
|
+
for (const child of node) {
|
|
325
|
+
const childResult = walkJsx(child, callback, depth);
|
|
326
|
+
if (childResult !== undefined) {
|
|
327
|
+
return childResult;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return undefined;
|
|
331
|
+
}
|
|
332
|
+
const result = callback(node, depth);
|
|
333
|
+
if (result !== undefined) {
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
if ((0, utils_1.hasProperty)(node, 'props') &&
|
|
337
|
+
(0, utils_1.isPlainObject)(node.props) &&
|
|
338
|
+
(0, utils_1.hasProperty)(node.props, 'children')) {
|
|
339
|
+
const children = getJsxChildren(node);
|
|
340
|
+
for (const child of children) {
|
|
341
|
+
if ((0, utils_1.isPlainObject)(child)) {
|
|
342
|
+
const childResult = walkJsx(child, callback, depth + 1);
|
|
343
|
+
if (childResult !== undefined) {
|
|
344
|
+
return childResult;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return undefined;
|
|
350
|
+
}
|
|
351
|
+
exports.walkJsx = walkJsx;
|
|
352
|
+
/**
|
|
353
|
+
* Serialise a JSX prop to a string.
|
|
354
|
+
*
|
|
355
|
+
* @param prop - The JSX prop.
|
|
356
|
+
* @returns The serialised JSX prop.
|
|
357
|
+
*/
|
|
358
|
+
function serialiseProp(prop) {
|
|
359
|
+
if (typeof prop === 'string') {
|
|
360
|
+
return `"${prop}"`;
|
|
361
|
+
}
|
|
362
|
+
return `{${JSON.stringify(prop)}}`;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Serialise JSX props to a string.
|
|
366
|
+
*
|
|
367
|
+
* @param props - The JSX props.
|
|
368
|
+
* @returns The serialised JSX props.
|
|
369
|
+
*/
|
|
370
|
+
function serialiseProps(props) {
|
|
371
|
+
return Object.entries(props)
|
|
372
|
+
.filter(([key]) => key !== 'children')
|
|
373
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
374
|
+
.map(([key, value]) => ` ${key}=${serialiseProp(value)}`)
|
|
375
|
+
.join('');
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Serialise a JSX node to a string.
|
|
379
|
+
*
|
|
380
|
+
* @param node - The JSX node.
|
|
381
|
+
* @param indentation - The indentation level. Defaults to `0`. This should not
|
|
382
|
+
* be set by the caller, as it is used for recursion.
|
|
383
|
+
* @returns The serialised JSX node.
|
|
384
|
+
*/
|
|
385
|
+
function serialiseJsx(node, indentation = 0) {
|
|
386
|
+
if (Array.isArray(node)) {
|
|
387
|
+
return node.map((child) => serialiseJsx(child, indentation)).join('');
|
|
388
|
+
}
|
|
389
|
+
const indent = ' '.repeat(indentation);
|
|
390
|
+
if (typeof node === 'string') {
|
|
391
|
+
return `${indent}${node}\n`;
|
|
392
|
+
}
|
|
393
|
+
if (!node) {
|
|
394
|
+
return '';
|
|
395
|
+
}
|
|
396
|
+
const { type, props } = node;
|
|
397
|
+
const trailingNewline = indentation > 0 ? '\n' : '';
|
|
398
|
+
if ((0, utils_1.hasProperty)(props, 'children')) {
|
|
399
|
+
const children = serialiseJsx(props.children, indentation + 1);
|
|
400
|
+
return `${indent}<${type}${serialiseProps(props)}>\n${children}${indent}</${type}>${trailingNewline}`;
|
|
401
|
+
}
|
|
402
|
+
return `${indent}<${type}${serialiseProps(props)} />${trailingNewline}`;
|
|
403
|
+
}
|
|
404
|
+
exports.serialiseJsx = serialiseJsx;
|
|
405
|
+
//# sourceMappingURL=ui.cjs.map
|
package/dist/ui.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui.cjs","sourceRoot":"","sources":["../src/ui.tsx"],"names":[],"mappings":";;;;AACA,mDAA+C;AAa/C,iDAiBiC;AACjC,2CAKyB;AACzB,mCAA2C;AAG3C,MAAM,eAAe,GAAG,KAAM,CAAC,CAAC,QAAQ;AACxC,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAEhD;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,OAA6C;IACrE,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;Q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CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACxE,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACxC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,GAAG,MAAM,GAAG,IAAI,IAAI,CAAC;IAC9B,CAAC;IAED,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAA0B,CAAC;IACnD,MAAM,eAAe,GAAG,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAEpD,IAAI,IAAA,mBAAW,EAAC,KAAK,EAAE,UAAU,CAAC,EAAE,CAAC;QACnC,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,QAAoB,EAAE,WAAW,GAAG,CAAC,CAAC,CAAC;QAC3E,OAAO,GAAG,MAAM,IAAI,IAAI,GAAG,cAAc,CACvC,KAAK,CACN,MAAM,QAAQ,GAAG,MAAM,KAAK,IAAI,IAAI,eAAe,EAAE,CAAC;IACzD,CAAC;IAED,OAAO,GAAG,MAAM,IAAI,IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,MAAM,eAAe,EAAE,CAAC;AAC1E,CAAC;AAzBD,oCAyBC","sourcesContent":["import type { Component } from '@metamask/snaps-sdk';\nimport { NodeType } from '@metamask/snaps-sdk';\nimport type {\n BoldChildren,\n GenericSnapElement,\n ItalicChildren,\n JSXElement,\n LinkElement,\n Nestable,\n RowChildren,\n SnapNode,\n StandardFormattingElement,\n TextChildren,\n} from '@metamask/snaps-sdk/jsx';\nimport {\n Italic,\n Link,\n Bold,\n Row,\n Text,\n Field,\n Image,\n Input,\n Heading,\n Form,\n Divider,\n Spinner,\n Copyable,\n Box,\n Button,\n Address,\n} from '@metamask/snaps-sdk/jsx';\nimport {\n assert,\n assertExhaustive,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { lexer, walkTokens } from 'marked';\nimport type { Token, Tokens } from 'marked';\n\nconst MAX_TEXT_LENGTH = 50_000; // 50 kb\nconst ALLOWED_PROTOCOLS = ['https:', 'mailto:'];\n\n/**\n * Get the button variant from a legacy button component variant.\n *\n * @param variant - The legacy button component variant.\n * @returns The button variant.\n */\nfunction getButtonVariant(variant?: 'primary' | 'secondary' | undefined) {\n switch (variant) {\n case 'primary':\n return 'primary';\n case 'secondary':\n return 'destructive';\n default:\n return undefined;\n }\n}\n\n/**\n * Get the children of a JSX element. If there is only one child, the child is\n * returned directly. Otherwise, the children are returned as an array.\n *\n * @param elements - The JSX elements.\n * @returns The child or children.\n */\nfunction getChildren<Type>(elements: Type[]) {\n if (elements.length === 1) {\n return elements[0];\n }\n\n return elements;\n}\n\n/**\n * Get the text of a link token.\n *\n * @param token - The link token.\n * @returns The text of the link token.\n */\nfunction getLinkText(token: Tokens.Link | Tokens.Generic) {\n if (token.tokens && token.tokens.length > 0) {\n return getChildren(token.tokens.flatMap(getTextChildFromToken));\n }\n\n return token.href;\n}\n\n/**\n * Get the text child from a list of markdown tokens.\n *\n * @param tokens - The markdown tokens.\n * @returns The text child.\n */\nfunction getTextChildFromTokens(tokens: Token[]) {\n return getChildren(tokens.flatMap(getTextChildFromToken));\n}\n\n/**\n * Get the text child from a markdown token.\n *\n * @param token - The markdown token.\n * @returns The text child.\n */\nfunction getTextChildFromToken(token: Token): TextChildren {\n switch (token.type) {\n case 'link': {\n return <Link href={token.href} children={getLinkText(token)} />;\n }\n\n case 'text':\n return token.text;\n\n case 'strong':\n return (\n <Bold>\n {\n getTextChildFromTokens(\n // Due to the way `marked` is typed, `token.tokens` can be\n // `undefined`, but it's a required field of `Tokens.Bold`, so we\n // can safely cast it to `Token[]`.\n token.tokens as Token[],\n ) as BoldChildren\n }\n </Bold>\n );\n\n case 'em':\n return (\n <Italic>\n {\n getTextChildFromTokens(\n // Due to the way `marked` is typed, `token.tokens` can be\n // `undefined`, but it's a required field of `Tokens.Bold`, so we\n // can safely cast it to `Token[]`.\n token.tokens as Token[],\n ) as ItalicChildren\n }\n </Italic>\n );\n\n default:\n return null;\n }\n}\n\n/**\n * Get all text children from a markdown string.\n *\n * @param value - The markdown string.\n * @returns The text children.\n */\nexport function getTextChildren(\n value: string,\n): (string | StandardFormattingElement | LinkElement)[] {\n const rootTokens = lexer(value, { gfm: false });\n const children: (string | StandardFormattingElement | LinkElement | null)[] =\n [];\n\n walkTokens(rootTokens, (token) => {\n if (token.type === 'paragraph') {\n if (children.length > 0) {\n children.push('\\n\\n');\n }\n\n const { tokens } = token as Tokens.Paragraph;\n // We do not need to consider nesting deeper than 1 level here and we can therefore cast.\n children.push(\n ...(tokens.flatMap(getTextChildFromToken) as (\n | string\n | StandardFormattingElement\n | LinkElement\n | null\n )[]),\n );\n }\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n return children.filter((child) => child !== null) as (\n | string\n | StandardFormattingElement\n | LinkElement\n )[];\n}\n\n/**\n * Validate the text size of a component. The text size is the total length of\n * all text in the component.\n *\n * @param component - The component to validate.\n * @throws An error if the text size exceeds the maximum allowed size.\n */\nfunction validateComponentTextSize(component: Component) {\n const textSize = getTotalTextLength(component);\n assert(\n textSize <= MAX_TEXT_LENGTH,\n `The text in a Snap UI may not be larger than ${\n MAX_TEXT_LENGTH / 1000\n } kB.`,\n );\n}\n\n/**\n * Get a JSX element from a legacy UI component. This supports all legacy UI\n * components, and maps them to their JSX equivalents where possible.\n *\n * This function validates the text size of the component, but does not validate\n * the total size. The total size of the component should be validated before\n * calling this function.\n *\n * @param legacyComponent - The legacy UI component.\n * @returns The JSX element.\n */\nexport function getJsxElementFromComponent(\n legacyComponent: Component,\n): JSXElement {\n validateComponentTextSize(legacyComponent);\n\n /**\n * Get the JSX element for a component. This function is recursive and will\n * call itself for child components.\n *\n * @param component - The component to convert to a JSX element.\n * @returns The JSX element.\n */\n function getElement(component: Component) {\n switch (component.type) {\n case NodeType.Address:\n return <Address address={component.value} />;\n\n case NodeType.Button:\n return (\n <Button\n name={component.name}\n variant={getButtonVariant(component.variant)}\n type={component.buttonType}\n >\n {component.value}\n </Button>\n );\n\n case NodeType.Copyable:\n return (\n <Copyable value={component.value} sensitive={component.sensitive} />\n );\n\n case NodeType.Divider:\n return <Divider />;\n\n case NodeType.Form:\n return (\n <Form name={component.name}>\n {getChildren(component.children.map(getElement))}\n </Form>\n );\n\n case NodeType.Heading:\n return <Heading children={component.value} />;\n\n case NodeType.Image:\n // `Image` supports `alt`, but the legacy `Image` component does not.\n return <Image src={component.value} />;\n\n case NodeType.Input:\n return (\n <Field label={component.label} error={component.error}>\n <Input\n name={component.name}\n type={component.inputType}\n value={component.value}\n placeholder={component.placeholder}\n />\n </Field>\n );\n\n case NodeType.Panel:\n // `Panel` is renamed to `Box` in JSX.\n return (\n <Box children={getChildren(component.children.map(getElement))} />\n );\n\n case NodeType.Row:\n return (\n <Row label={component.label} variant={component.variant}>\n {getElement(component.value) as RowChildren}\n </Row>\n );\n\n case NodeType.Spinner:\n return <Spinner />;\n\n case NodeType.Text:\n return <Text>{getChildren(getTextChildren(component.value))}</Text>;\n\n /* istanbul ignore next 2 */\n default:\n return assertExhaustive(component);\n }\n }\n\n return getElement(legacyComponent);\n}\n\n/**\n * Extract all links from a Markdown text string using the `marked` lexer.\n *\n * @param text - The markdown text string.\n * @returns A list of URLs linked to in the string.\n */\nfunction getMarkdownLinks(text: string) {\n const tokens = lexer(text, { gfm: false });\n const links: Tokens.Link[] = [];\n\n // Walk the lexed tokens and collect all link tokens\n walkTokens(tokens, (token) => {\n if (token.type === 'link') {\n links.push(token as Tokens.Link);\n }\n });\n\n return links;\n}\n\n/**\n * Validate a link against the phishing list.\n *\n * @param link - The link to validate.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n */\nexport function validateLink(\n link: string,\n isOnPhishingList: (url: string) => boolean,\n) {\n try {\n const url = new URL(link);\n assert(\n ALLOWED_PROTOCOLS.includes(url.protocol),\n `Protocol must be one of: ${ALLOWED_PROTOCOLS.join(', ')}.`,\n );\n\n const hostname =\n url.protocol === 'mailto:' ? url.pathname.split('@')[1] : url.hostname;\n\n assert(!isOnPhishingList(hostname), 'The specified URL is not allowed.');\n } catch (error) {\n throw new Error(\n `Invalid URL: ${\n error?.code === 'ERR_ASSERTION' ? error.message : 'Unable to parse URL.'\n }`,\n );\n }\n}\n\n/**\n * Search for Markdown links in a string and checks them against the phishing\n * list.\n *\n * @param text - The text to verify.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n * @throws If the text contains a link that is not allowed.\n */\nexport function validateTextLinks(\n text: string,\n isOnPhishingList: (url: string) => boolean,\n) {\n const links = getMarkdownLinks(text);\n\n for (const link of links) {\n validateLink(link.href, isOnPhishingList);\n }\n}\n\n/**\n * Walk a JSX tree and validate each {@link LinkElement} node against the\n * phishing list.\n *\n * @param node - The JSX node to walk.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n */\nexport function validateJsxLinks(\n node: JSXElement,\n isOnPhishingList: (url: string) => boolean,\n) {\n walkJsx(node, (childNode) => {\n if (childNode.type !== 'Link') {\n return;\n }\n\n validateLink(childNode.props.href, isOnPhishingList);\n });\n}\n\n/**\n * Calculate the total length of all text in the component.\n *\n * @param component - A custom UI component.\n * @returns The total length of all text components in the component.\n */\nexport function getTotalTextLength(component: Component): number {\n const { type } = component;\n\n switch (type) {\n case NodeType.Panel:\n return component.children.reduce<number>(\n // This is a bug in TypeScript: https://github.com/microsoft/TypeScript/issues/48313\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n (sum, node) => sum + getTotalTextLength(node),\n 0,\n );\n\n case NodeType.Row:\n return getTotalTextLength(component.value);\n\n case NodeType.Text:\n return component.value.length;\n\n default:\n return 0;\n }\n}\n\n/**\n * Check if a JSX element has children.\n *\n * @param element - A JSX element.\n * @returns `true` if the element has children, `false` otherwise.\n */\nexport function hasChildren<Element extends JSXElement>(\n element: Element,\n): element is Element & {\n props: { children: Nestable<JSXElement | string> };\n} {\n return hasProperty(element.props, 'children');\n}\n\n/**\n * Filter a JSX child to remove `null`, `undefined`, plain booleans, and empty\n * strings.\n *\n * @param child - The JSX child to filter.\n * @returns `true` if the child is not `null`, `undefined`, a plain boolean, or\n * an empty string, `false` otherwise.\n */\nfunction filterJsxChild(child: JSXElement | string | boolean | null): boolean {\n return Boolean(child) && child !== true;\n}\n\n/**\n * Get the children of a JSX element as an array. If the element has only one\n * child, the child is returned as an array.\n *\n * @param element - A JSX element.\n * @returns The children of the element.\n */\nexport function getJsxChildren(element: JSXElement): (JSXElement | string)[] {\n if (hasChildren(element)) {\n if (Array.isArray(element.props.children)) {\n // @ts-expect-error - Each member of the union type has signatures, but\n // none of those signatures are compatible with each other.\n return element.props.children.filter(filterJsxChild).flat(Infinity);\n }\n\n if (element.props.children) {\n return [element.props.children];\n }\n }\n\n return [];\n}\n\n/**\n * Walk a JSX tree and call a callback on each node.\n *\n * @param node - The JSX node to walk.\n * @param callback - The callback to call on each node.\n * @param depth - The current depth in the JSX tree for a walk.\n * @returns The result of the callback, if any.\n */\nexport function walkJsx<Value>(\n node: JSXElement | JSXElement[],\n callback: (node: JSXElement, depth: number) => Value | undefined,\n depth = 0,\n): Value | undefined {\n if (Array.isArray(node)) {\n for (const child of node) {\n const childResult = walkJsx(child as JSXElement, callback, depth);\n if (childResult !== undefined) {\n return childResult;\n }\n }\n\n return undefined;\n }\n\n const result = callback(node, depth);\n if (result !== undefined) {\n return result;\n }\n\n if (\n hasProperty(node, 'props') &&\n isPlainObject(node.props) &&\n hasProperty(node.props, 'children')\n ) {\n const children = getJsxChildren(node);\n for (const child of children) {\n if (isPlainObject(child)) {\n const childResult = walkJsx(child, callback, depth + 1);\n if (childResult !== undefined) {\n return childResult;\n }\n }\n }\n }\n\n return undefined;\n}\n\n/**\n * Serialise a JSX prop to a string.\n *\n * @param prop - The JSX prop.\n * @returns The serialised JSX prop.\n */\nfunction serialiseProp(prop: unknown): string {\n if (typeof prop === 'string') {\n return `\"${prop}\"`;\n }\n\n return `{${JSON.stringify(prop)}}`;\n}\n\n/**\n * Serialise JSX props to a string.\n *\n * @param props - The JSX props.\n * @returns The serialised JSX props.\n */\nfunction serialiseProps(props: Record<string, unknown>): string {\n return Object.entries(props)\n .filter(([key]) => key !== 'children')\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([key, value]) => ` ${key}=${serialiseProp(value)}`)\n .join('');\n}\n\n/**\n * Serialise a JSX node to a string.\n *\n * @param node - The JSX node.\n * @param indentation - The indentation level. Defaults to `0`. This should not\n * be set by the caller, as it is used for recursion.\n * @returns The serialised JSX node.\n */\nexport function serialiseJsx(node: SnapNode, indentation = 0): string {\n if (Array.isArray(node)) {\n return node.map((child) => serialiseJsx(child, indentation)).join('');\n }\n\n const indent = ' '.repeat(indentation);\n if (typeof node === 'string') {\n return `${indent}${node}\\n`;\n }\n\n if (!node) {\n return '';\n }\n\n const { type, props } = node as GenericSnapElement;\n const trailingNewline = indentation > 0 ? '\\n' : '';\n\n if (hasProperty(props, 'children')) {\n const children = serialiseJsx(props.children as SnapNode, indentation + 1);\n return `${indent}<${type}${serialiseProps(\n props,\n )}>\\n${children}${indent}</${type}>${trailingNewline}`;\n }\n\n return `${indent}<${type}${serialiseProps(props)} />${trailingNewline}`;\n}\n"]}
|
package/dist/ui.d.cts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Component } from "@metamask/snaps-sdk";
|
|
2
|
+
import type { JSXElement, LinkElement, Nestable, SnapNode, StandardFormattingElement } from "@metamask/snaps-sdk/jsx";
|
|
3
|
+
/**
|
|
4
|
+
* Get all text children from a markdown string.
|
|
5
|
+
*
|
|
6
|
+
* @param value - The markdown string.
|
|
7
|
+
* @returns The text children.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getTextChildren(value: string): (string | StandardFormattingElement | LinkElement)[];
|
|
10
|
+
/**
|
|
11
|
+
* Get a JSX element from a legacy UI component. This supports all legacy UI
|
|
12
|
+
* components, and maps them to their JSX equivalents where possible.
|
|
13
|
+
*
|
|
14
|
+
* This function validates the text size of the component, but does not validate
|
|
15
|
+
* the total size. The total size of the component should be validated before
|
|
16
|
+
* calling this function.
|
|
17
|
+
*
|
|
18
|
+
* @param legacyComponent - The legacy UI component.
|
|
19
|
+
* @returns The JSX element.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getJsxElementFromComponent(legacyComponent: Component): JSXElement;
|
|
22
|
+
/**
|
|
23
|
+
* Validate a link against the phishing list.
|
|
24
|
+
*
|
|
25
|
+
* @param link - The link to validate.
|
|
26
|
+
* @param isOnPhishingList - The function that checks the link against the
|
|
27
|
+
* phishing list.
|
|
28
|
+
*/
|
|
29
|
+
export declare function validateLink(link: string, isOnPhishingList: (url: string) => boolean): void;
|
|
30
|
+
/**
|
|
31
|
+
* Search for Markdown links in a string and checks them against the phishing
|
|
32
|
+
* list.
|
|
33
|
+
*
|
|
34
|
+
* @param text - The text to verify.
|
|
35
|
+
* @param isOnPhishingList - The function that checks the link against the
|
|
36
|
+
* phishing list.
|
|
37
|
+
* @throws If the text contains a link that is not allowed.
|
|
38
|
+
*/
|
|
39
|
+
export declare function validateTextLinks(text: string, isOnPhishingList: (url: string) => boolean): void;
|
|
40
|
+
/**
|
|
41
|
+
* Walk a JSX tree and validate each {@link LinkElement} node against the
|
|
42
|
+
* phishing list.
|
|
43
|
+
*
|
|
44
|
+
* @param node - The JSX node to walk.
|
|
45
|
+
* @param isOnPhishingList - The function that checks the link against the
|
|
46
|
+
* phishing list.
|
|
47
|
+
*/
|
|
48
|
+
export declare function validateJsxLinks(node: JSXElement, isOnPhishingList: (url: string) => boolean): void;
|
|
49
|
+
/**
|
|
50
|
+
* Calculate the total length of all text in the component.
|
|
51
|
+
*
|
|
52
|
+
* @param component - A custom UI component.
|
|
53
|
+
* @returns The total length of all text components in the component.
|
|
54
|
+
*/
|
|
55
|
+
export declare function getTotalTextLength(component: Component): number;
|
|
56
|
+
/**
|
|
57
|
+
* Check if a JSX element has children.
|
|
58
|
+
*
|
|
59
|
+
* @param element - A JSX element.
|
|
60
|
+
* @returns `true` if the element has children, `false` otherwise.
|
|
61
|
+
*/
|
|
62
|
+
export declare function hasChildren<Element extends JSXElement>(element: Element): element is Element & {
|
|
63
|
+
props: {
|
|
64
|
+
children: Nestable<JSXElement | string>;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Get the children of a JSX element as an array. If the element has only one
|
|
69
|
+
* child, the child is returned as an array.
|
|
70
|
+
*
|
|
71
|
+
* @param element - A JSX element.
|
|
72
|
+
* @returns The children of the element.
|
|
73
|
+
*/
|
|
74
|
+
export declare function getJsxChildren(element: JSXElement): (JSXElement | string)[];
|
|
75
|
+
/**
|
|
76
|
+
* Walk a JSX tree and call a callback on each node.
|
|
77
|
+
*
|
|
78
|
+
* @param node - The JSX node to walk.
|
|
79
|
+
* @param callback - The callback to call on each node.
|
|
80
|
+
* @param depth - The current depth in the JSX tree for a walk.
|
|
81
|
+
* @returns The result of the callback, if any.
|
|
82
|
+
*/
|
|
83
|
+
export declare function walkJsx<Value>(node: JSXElement | JSXElement[], callback: (node: JSXElement, depth: number) => Value | undefined, depth?: number): Value | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Serialise a JSX node to a string.
|
|
86
|
+
*
|
|
87
|
+
* @param node - The JSX node.
|
|
88
|
+
* @param indentation - The indentation level. Defaults to `0`. This should not
|
|
89
|
+
* be set by the caller, as it is used for recursion.
|
|
90
|
+
* @returns The serialised JSX node.
|
|
91
|
+
*/
|
|
92
|
+
export declare function serialiseJsx(node: SnapNode, indentation?: number): string;
|
|
93
|
+
//# sourceMappingURL=ui.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui.d.cts","sourceRoot":"","sources":["../src/ui.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAA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,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,KAAK,KAAK,GAAG,SAAS,EAChE,KAAK,SAAI,GACR,KAAK,GAAG,SAAS,CAkCnB;AA8BD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,WAAW,SAAI,GAAG,MAAM,CAyBpE"}
|
package/dist/ui.d.mts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Component } from "@metamask/snaps-sdk";
|
|
2
|
+
import type { JSXElement, LinkElement, Nestable, SnapNode, StandardFormattingElement } from "@metamask/snaps-sdk/jsx";
|
|
3
|
+
/**
|
|
4
|
+
* Get all text children from a markdown string.
|
|
5
|
+
*
|
|
6
|
+
* @param value - The markdown string.
|
|
7
|
+
* @returns The text children.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getTextChildren(value: string): (string | StandardFormattingElement | LinkElement)[];
|
|
10
|
+
/**
|
|
11
|
+
* Get a JSX element from a legacy UI component. This supports all legacy UI
|
|
12
|
+
* components, and maps them to their JSX equivalents where possible.
|
|
13
|
+
*
|
|
14
|
+
* This function validates the text size of the component, but does not validate
|
|
15
|
+
* the total size. The total size of the component should be validated before
|
|
16
|
+
* calling this function.
|
|
17
|
+
*
|
|
18
|
+
* @param legacyComponent - The legacy UI component.
|
|
19
|
+
* @returns The JSX element.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getJsxElementFromComponent(legacyComponent: Component): JSXElement;
|
|
22
|
+
/**
|
|
23
|
+
* Validate a link against the phishing list.
|
|
24
|
+
*
|
|
25
|
+
* @param link - The link to validate.
|
|
26
|
+
* @param isOnPhishingList - The function that checks the link against the
|
|
27
|
+
* phishing list.
|
|
28
|
+
*/
|
|
29
|
+
export declare function validateLink(link: string, isOnPhishingList: (url: string) => boolean): void;
|
|
30
|
+
/**
|
|
31
|
+
* Search for Markdown links in a string and checks them against the phishing
|
|
32
|
+
* list.
|
|
33
|
+
*
|
|
34
|
+
* @param text - The text to verify.
|
|
35
|
+
* @param isOnPhishingList - The function that checks the link against the
|
|
36
|
+
* phishing list.
|
|
37
|
+
* @throws If the text contains a link that is not allowed.
|
|
38
|
+
*/
|
|
39
|
+
export declare function validateTextLinks(text: string, isOnPhishingList: (url: string) => boolean): void;
|
|
40
|
+
/**
|
|
41
|
+
* Walk a JSX tree and validate each {@link LinkElement} node against the
|
|
42
|
+
* phishing list.
|
|
43
|
+
*
|
|
44
|
+
* @param node - The JSX node to walk.
|
|
45
|
+
* @param isOnPhishingList - The function that checks the link against the
|
|
46
|
+
* phishing list.
|
|
47
|
+
*/
|
|
48
|
+
export declare function validateJsxLinks(node: JSXElement, isOnPhishingList: (url: string) => boolean): void;
|
|
49
|
+
/**
|
|
50
|
+
* Calculate the total length of all text in the component.
|
|
51
|
+
*
|
|
52
|
+
* @param component - A custom UI component.
|
|
53
|
+
* @returns The total length of all text components in the component.
|
|
54
|
+
*/
|
|
55
|
+
export declare function getTotalTextLength(component: Component): number;
|
|
56
|
+
/**
|
|
57
|
+
* Check if a JSX element has children.
|
|
58
|
+
*
|
|
59
|
+
* @param element - A JSX element.
|
|
60
|
+
* @returns `true` if the element has children, `false` otherwise.
|
|
61
|
+
*/
|
|
62
|
+
export declare function hasChildren<Element extends JSXElement>(element: Element): element is Element & {
|
|
63
|
+
props: {
|
|
64
|
+
children: Nestable<JSXElement | string>;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Get the children of a JSX element as an array. If the element has only one
|
|
69
|
+
* child, the child is returned as an array.
|
|
70
|
+
*
|
|
71
|
+
* @param element - A JSX element.
|
|
72
|
+
* @returns The children of the element.
|
|
73
|
+
*/
|
|
74
|
+
export declare function getJsxChildren(element: JSXElement): (JSXElement | string)[];
|
|
75
|
+
/**
|
|
76
|
+
* Walk a JSX tree and call a callback on each node.
|
|
77
|
+
*
|
|
78
|
+
* @param node - The JSX node to walk.
|
|
79
|
+
* @param callback - The callback to call on each node.
|
|
80
|
+
* @param depth - The current depth in the JSX tree for a walk.
|
|
81
|
+
* @returns The result of the callback, if any.
|
|
82
|
+
*/
|
|
83
|
+
export declare function walkJsx<Value>(node: JSXElement | JSXElement[], callback: (node: JSXElement, depth: number) => Value | undefined, depth?: number): Value | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Serialise a JSX node to a string.
|
|
86
|
+
*
|
|
87
|
+
* @param node - The JSX node.
|
|
88
|
+
* @param indentation - The indentation level. Defaults to `0`. This should not
|
|
89
|
+
* be set by the caller, as it is used for recursion.
|
|
90
|
+
* @returns The serialised JSX node.
|
|
91
|
+
*/
|
|
92
|
+
export declare function serialiseJsx(node: SnapNode, indentation?: number): string;
|
|
93
|
+
//# sourceMappingURL=ui.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui.d.mts","sourceRoot":"","sources":["../src/ui.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAIV,UAAU,EACV,WAAW,EACX,QAAQ,EAER,QAAQ,EACR,yBAAyB,EAE1B,gCAAgC;AAuIjC;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,GACZ,CAAC,MAAM,GAAG,yBAAyB,GAAG,WAAW,CAAC,EAAE,CA8BtD;AAmBD;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,eAAe,EAAE,SAAS,GACzB,UAAU,CAsFZ;AAsBD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,QAoB3C;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,QAO3C;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI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