@es-joy/jsoe 0.24.3 → 0.25.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/.claude/settings.local.json +9 -0
- package/.ncurc.cjs +2 -2
- package/CHANGES.md +51 -0
- package/README.md +23 -13
- package/badges/coverage-badge.svg +1 -1
- package/dist/eslint.config.d.ts +3 -0
- package/dist/eslint.config.d.ts.map +1 -0
- package/dist/formatAndTypeChoices.d.ts +28 -30
- package/dist/formatAndTypeChoices.d.ts.map +1 -1
- package/dist/formats/indexedDBKey.d.ts.map +1 -1
- package/dist/formats/schema.d.ts +46 -3
- package/dist/formats/schema.d.ts.map +1 -1
- package/dist/formats/structuredCloning.d.ts +3 -0
- package/dist/formats/structuredCloning.d.ts.map +1 -1
- package/dist/formats.d.ts +24 -6
- package/dist/formats.d.ts.map +1 -1
- package/dist/fundamentalTypes/BooleanObjectType.d.ts.map +1 -1
- package/dist/fundamentalTypes/NumberObjectType.d.ts.map +1 -1
- package/dist/fundamentalTypes/StringObjectType.d.ts.map +1 -1
- package/dist/fundamentalTypes/arrayReferenceType.d.ts.map +1 -1
- package/dist/fundamentalTypes/arrayType.d.ts +7 -0
- package/dist/fundamentalTypes/arrayType.d.ts.map +1 -1
- package/dist/fundamentalTypes/bigintObjectType.d.ts.map +1 -1
- package/dist/fundamentalTypes/bigintType.d.ts +10 -0
- package/dist/fundamentalTypes/bigintType.d.ts.map +1 -1
- package/dist/fundamentalTypes/blobType.d.ts.map +1 -1
- package/dist/fundamentalTypes/booleanType.d.ts.map +1 -1
- package/dist/fundamentalTypes/catchType.d.ts +2 -2
- package/dist/fundamentalTypes/catchType.d.ts.map +1 -1
- package/dist/fundamentalTypes/dateType.d.ts.map +1 -1
- package/dist/fundamentalTypes/domexceptionType.d.ts.map +1 -1
- package/dist/fundamentalTypes/enumType.d.ts +2 -2
- package/dist/fundamentalTypes/enumType.d.ts.map +1 -1
- package/dist/fundamentalTypes/errorType.d.ts.map +1 -1
- package/dist/fundamentalTypes/fileType.d.ts +6 -0
- package/dist/fundamentalTypes/fileType.d.ts.map +1 -1
- package/dist/fundamentalTypes/functionType.d.ts.map +1 -1
- package/dist/fundamentalTypes/literalType.d.ts +3 -2
- package/dist/fundamentalTypes/literalType.d.ts.map +1 -1
- package/dist/fundamentalTypes/looseRecordType.d.ts +6 -0
- package/dist/fundamentalTypes/looseRecordType.d.ts.map +1 -0
- package/dist/fundamentalTypes/nanType.d.ts.map +1 -1
- package/dist/fundamentalTypes/neverType.d.ts +2 -2
- package/dist/fundamentalTypes/neverType.d.ts.map +1 -1
- package/dist/fundamentalTypes/noneditableType.d.ts.map +1 -1
- package/dist/fundamentalTypes/nullType.d.ts.map +1 -1
- package/dist/fundamentalTypes/numberType.d.ts.map +1 -1
- package/dist/fundamentalTypes/promiseType.d.ts.map +1 -1
- package/dist/fundamentalTypes/regexpType.d.ts.map +1 -1
- package/dist/fundamentalTypes/stringType.d.ts.map +1 -1
- package/dist/fundamentalTypes/symbolType.d.ts.map +1 -1
- package/dist/fundamentalTypes/undefinedType.d.ts.map +1 -1
- package/dist/fundamentalTypes/voidType.d.ts +2 -2
- package/dist/fundamentalTypes/voidType.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/rollup.config.d.ts +30 -0
- package/dist/rollup.config.d.ts.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/src/formatAndTypeChoices.d.ts +108 -0
- package/dist/src/formatAndTypeChoices.d.ts.map +1 -0
- package/dist/src/formats/arbitraryJS.d.ts +4 -0
- package/dist/src/formats/arbitraryJS.d.ts.map +1 -0
- package/dist/src/formats/indexedDBKey.d.ts +4 -0
- package/dist/src/formats/indexedDBKey.d.ts.map +1 -0
- package/dist/src/formats/json.d.ts +4 -0
- package/dist/src/formats/json.d.ts.map +1 -0
- package/dist/src/formats/schema.d.ts +17 -0
- package/dist/src/formats/schema.d.ts.map +1 -0
- package/dist/src/formats/structuredCloning.d.ts +19 -0
- package/dist/src/formats/structuredCloning.d.ts.map +1 -0
- package/dist/src/formats.d.ts +135 -0
- package/dist/src/formats.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/BooleanObjectType.d.ts +8 -0
- package/dist/src/fundamentalTypes/BooleanObjectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/NumberObjectType.d.ts +6 -0
- package/dist/src/fundamentalTypes/NumberObjectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/StringObjectType.d.ts +6 -0
- package/dist/src/fundamentalTypes/StringObjectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/arrayReferenceType.d.ts +8 -0
- package/dist/src/fundamentalTypes/arrayReferenceType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/arrayType.d.ts +29 -0
- package/dist/src/fundamentalTypes/arrayType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/bigintObjectType.d.ts +6 -0
- package/dist/src/fundamentalTypes/bigintObjectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/bigintType.d.ts +6 -0
- package/dist/src/fundamentalTypes/bigintType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/blobType.d.ts +11 -0
- package/dist/src/fundamentalTypes/blobType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/booleanType.d.ts +8 -0
- package/dist/src/fundamentalTypes/booleanType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/catchType.d.ts +6 -0
- package/dist/src/fundamentalTypes/catchType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/dateType.d.ts +26 -0
- package/dist/src/fundamentalTypes/dateType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/domexceptionType.d.ts +6 -0
- package/dist/src/fundamentalTypes/domexceptionType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/enumType.d.ts +6 -0
- package/dist/src/fundamentalTypes/enumType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/errorType.d.ts +6 -0
- package/dist/src/fundamentalTypes/errorType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/fileType.d.ts +13 -0
- package/dist/src/fundamentalTypes/fileType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/filelistType.d.ts +6 -0
- package/dist/src/fundamentalTypes/filelistType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/functionType.d.ts +7 -0
- package/dist/src/fundamentalTypes/functionType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/literalType.d.ts +6 -0
- package/dist/src/fundamentalTypes/literalType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/mapType.d.ts +6 -0
- package/dist/src/fundamentalTypes/mapType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/nanType.d.ts +6 -0
- package/dist/src/fundamentalTypes/nanType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/neverType.d.ts +6 -0
- package/dist/src/fundamentalTypes/neverType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/noneditableType.d.ts +6 -0
- package/dist/src/fundamentalTypes/noneditableType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/nullType.d.ts +6 -0
- package/dist/src/fundamentalTypes/nullType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/numberType.d.ts +6 -0
- package/dist/src/fundamentalTypes/numberType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/objectReferenceType.d.ts +8 -0
- package/dist/src/fundamentalTypes/objectReferenceType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/objectType.d.ts +6 -0
- package/dist/src/fundamentalTypes/objectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/promiseType.d.ts +6 -0
- package/dist/src/fundamentalTypes/promiseType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/recordType.d.ts +6 -0
- package/dist/src/fundamentalTypes/recordType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/regexpType.d.ts +8 -0
- package/dist/src/fundamentalTypes/regexpType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/setType.d.ts +6 -0
- package/dist/src/fundamentalTypes/setType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/sparseUndefinedType.d.ts +6 -0
- package/dist/src/fundamentalTypes/sparseUndefinedType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/stringType.d.ts +6 -0
- package/dist/src/fundamentalTypes/stringType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/symbolType.d.ts +8 -0
- package/dist/src/fundamentalTypes/symbolType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/tupleType.d.ts +6 -0
- package/dist/src/fundamentalTypes/tupleType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/undefinedType.d.ts +6 -0
- package/dist/src/fundamentalTypes/undefinedType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/voidType.d.ts +6 -0
- package/dist/src/fundamentalTypes/voidType.d.ts.map +1 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/subTypes/blobHTMLType.d.ts +20 -0
- package/dist/src/subTypes/blobHTMLType.d.ts.map +1 -0
- package/dist/src/subTypes/falseType.d.ts +8 -0
- package/dist/src/subTypes/falseType.d.ts.map +1 -0
- package/dist/src/subTypes/trueType.d.ts +8 -0
- package/dist/src/subTypes/trueType.d.ts.map +1 -0
- package/dist/src/superTypes/SpecialNumberType.d.ts +6 -0
- package/dist/src/superTypes/SpecialNumberType.d.ts.map +1 -0
- package/dist/src/superTypes/SpecialRealNumberType.d.ts +6 -0
- package/dist/src/superTypes/SpecialRealNumberType.d.ts.map +1 -0
- package/dist/src/superTypes/buffersourceType.d.ts +8 -0
- package/dist/src/superTypes/buffersourceType.d.ts.map +1 -0
- package/dist/src/superTypes/dommatrixType.d.ts +6 -0
- package/dist/src/superTypes/dommatrixType.d.ts.map +1 -0
- package/dist/src/superTypes/dompointType.d.ts +6 -0
- package/dist/src/superTypes/dompointType.d.ts.map +1 -0
- package/dist/src/superTypes/domrectType.d.ts +6 -0
- package/dist/src/superTypes/domrectType.d.ts.map +1 -0
- package/dist/src/superTypes/errorsSpecialType.d.ts +8 -0
- package/dist/src/superTypes/errorsSpecialType.d.ts.map +1 -0
- package/dist/src/typeChoices.d.ts +140 -0
- package/dist/src/typeChoices.d.ts.map +1 -0
- package/dist/src/types.d.ts +758 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/utils/FileList.d.ts +26 -0
- package/dist/src/utils/FileList.d.ts.map +1 -0
- package/dist/src/utils/dialogs.d.ts +111 -0
- package/dist/src/utils/dialogs.d.ts.map +1 -0
- package/dist/src/utils/jsonPointer.d.ts +46 -0
- package/dist/src/utils/jsonPointer.d.ts.map +1 -0
- package/dist/src/utils/media.d.ts +18 -0
- package/dist/src/utils/media.d.ts.map +1 -0
- package/dist/src/utils/objects.d.ts +16 -0
- package/dist/src/utils/objects.d.ts.map +1 -0
- package/dist/src/utils/templateUtils.d.ts +59 -0
- package/dist/src/utils/templateUtils.d.ts.map +1 -0
- package/dist/src/utils/types.d.ts +2 -0
- package/dist/src/utils/types.d.ts.map +1 -0
- package/dist/src/vendor-imports.d.ts +4 -0
- package/dist/src/vendor-imports.d.ts.map +1 -0
- package/dist/subTypes/blobHTMLType.d.ts.map +1 -1
- package/dist/superTypes/SpecialRealNumberType.d.ts.map +1 -1
- package/dist/superTypes/buffersourceType.d.ts.map +1 -1
- package/dist/superTypes/dommatrixType.d.ts.map +1 -1
- package/dist/superTypes/dompointType.d.ts.map +1 -1
- package/dist/superTypes/domrectType.d.ts.map +1 -1
- package/dist/superTypes/errorsSpecialType.d.ts.map +1 -1
- package/dist/typeChoices.d.ts +21 -87
- package/dist/typeChoices.d.ts.map +1 -1
- package/dist/types.d.ts +90 -64
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/FileList.d.ts +4 -3
- package/dist/utils/FileList.d.ts.map +1 -1
- package/dist/utils/dialogs.d.ts +4 -4
- package/dist/utils/dialogs.d.ts.map +1 -1
- package/dist/utils/media.d.ts.map +1 -1
- package/dist/utils/schemaMeta.d.ts +92 -0
- package/dist/utils/schemaMeta.d.ts.map +1 -0
- package/dist/utils/templateUtils.d.ts +3 -3
- package/dist/utils/templateUtils.d.ts.map +1 -1
- package/dist/utils/timing.d.ts +2 -0
- package/dist/utils/timing.d.ts.map +1 -0
- package/dist/utils/types.d.ts +1 -0
- package/dist/utils/types.d.ts.map +1 -1
- package/dist/vendor-imports.d.ts +3 -1
- package/docs/proposals/schema-meta.md +233 -0
- package/eslint.config.js +51 -4
- package/licenseInfo.json +1 -1
- package/package.json +52 -42
- package/pnpm-workspace.yaml +57 -0
- package/rollup.config.js +20 -18
- package/server.js +3 -3
- package/src/deepEqual.js.map +1 -1
- package/src/formatAndTypeChoices.js +62 -58
- package/src/formats/indexedDBKey.js +3 -4
- package/src/formats/schema.js +824 -475
- package/src/formats/structuredCloning.js +189 -79
- package/src/formats.js +17 -5
- package/src/fundamentalTypes/BooleanObjectType.js +4 -5
- package/src/fundamentalTypes/NumberObjectType.js +4 -4
- package/src/fundamentalTypes/StringObjectType.js +3 -4
- package/src/fundamentalTypes/arrayReferenceType.js +0 -2
- package/src/fundamentalTypes/arrayType.js +624 -389
- package/src/fundamentalTypes/bigintObjectType.js +3 -2
- package/src/fundamentalTypes/bigintType.js +79 -17
- package/src/fundamentalTypes/blobType.js +35 -35
- package/src/fundamentalTypes/booleanType.js +16 -8
- package/src/fundamentalTypes/dateType.js +6 -8
- package/src/fundamentalTypes/domexceptionType.js +5 -4
- package/src/fundamentalTypes/errorType.js +39 -32
- package/src/fundamentalTypes/fileType.js +238 -52
- package/src/fundamentalTypes/functionType.js +61 -41
- package/src/fundamentalTypes/nanType.js +5 -4
- package/src/fundamentalTypes/noneditableType.js +4 -3
- package/src/fundamentalTypes/nullType.js +3 -2
- package/src/fundamentalTypes/numberType.js +72 -20
- package/src/fundamentalTypes/promiseType.js +16 -40
- package/src/fundamentalTypes/regexpType.js +7 -13
- package/src/fundamentalTypes/stringType.js +176 -110
- package/src/fundamentalTypes/symbolType.js +3 -2
- package/src/fundamentalTypes/undefinedType.js +3 -2
- package/src/index.js +6 -5
- package/src/jsoe.css +107 -8
- package/src/subTypes/blobHTMLType.js +23 -10
- package/src/superTypes/SpecialNumberType.js +6 -6
- package/src/superTypes/SpecialRealNumberType.js +10 -9
- package/src/superTypes/buffersourceType.js +86 -75
- package/src/superTypes/dommatrixType.js +6 -5
- package/src/superTypes/dompointType.js +6 -5
- package/src/superTypes/domrectType.js +6 -5
- package/src/superTypes/errorsSpecialType.js +54 -35
- package/src/typeChoices.js +399 -54
- package/src/types.js +157 -97
- package/src/utils/FileList.js +3 -3
- package/src/utils/dialogs.js +5 -7
- package/src/utils/jsonPointer.js +1 -1
- package/src/utils/media.js +1 -0
- package/src/utils/schemaMeta.js +257 -0
- package/src/utils/templateUtils.js +3 -3
- package/src/utils/timing.js +12 -0
- package/src/utils/types.js +19 -0
- package/src/vendor-imports.js +10 -2
- package/tsconfig.json +2 -0
- package/vendor/acorn/dist/acorn.d.mts +46 -5
- package/vendor/acorn/dist/acorn.d.ts +46 -5
- package/vendor/acorn/dist/acorn.js +394 -117
- package/vendor/acorn/dist/acorn.mjs +394 -117
- package/vendor/acorn/dist/bin.js +1 -1
- package/vendor/jamilih/dist/{jml-es.js → jml.mjs} +590 -312
- package/vendor/jamilih/package.json +1 -1
- package/vendor/mime/dist/types/other.js +719 -0
- package/vendor/mime/dist/types/standard.js +366 -0
- package/vendor/typeson-registry/dist/index.js +519 -99
- package/vendor/zod/classic/checks.d.ts +1 -0
- package/vendor/zod/classic/checks.js +1 -0
- package/vendor/zod/classic/coerce.d.ts +17 -0
- package/vendor/zod/classic/coerce.js +17 -0
- package/vendor/zod/classic/compat.d.ts +48 -0
- package/vendor/zod/classic/compat.js +31 -0
- package/vendor/zod/classic/deep-partial.d.ts +14 -0
- package/vendor/zod/classic/deep-partial.js +13 -0
- package/vendor/zod/classic/errors.d.ts +29 -0
- package/vendor/zod/classic/errors.js +57 -0
- package/vendor/zod/classic/external.d.ts +19 -0
- package/vendor/zod/classic/external.js +17 -0
- package/vendor/zod/classic/from-json-schema.d.ts +12 -0
- package/vendor/zod/classic/from-json-schema.js +660 -0
- package/vendor/zod/classic/in-out.d.ts +8 -0
- package/vendor/zod/classic/in-out.js +36 -0
- package/vendor/zod/classic/index.d.ts +3 -0
- package/vendor/zod/classic/index.js +4 -0
- package/vendor/zod/classic/iso.d.ts +7 -0
- package/vendor/zod/classic/iso.js +15 -0
- package/vendor/zod/classic/package.json +7 -0
- package/vendor/zod/classic/parse.d.ts +44 -0
- package/vendor/zod/classic/parse.js +16 -0
- package/vendor/zod/classic/schemas.d.ts +802 -0
- package/vendor/zod/classic/schemas.js +1491 -0
- package/vendor/zod/core/api.d.ts +329 -0
- package/vendor/zod/core/api.js +1104 -0
- package/vendor/zod/core/checks.d.ts +278 -0
- package/vendor/zod/core/checks.js +581 -0
- package/vendor/zod/core/compile.d.ts +51 -0
- package/vendor/zod/core/compile.js +1783 -0
- package/vendor/zod/core/core.d.ts +82 -0
- package/vendor/zod/core/core.js +141 -0
- package/vendor/zod/core/doc.d.ts +16 -0
- package/vendor/zod/core/doc.js +33 -0
- package/vendor/zod/core/errors.d.ts +225 -0
- package/vendor/zod/core/errors.js +270 -0
- package/vendor/zod/core/index.d.ts +19 -0
- package/vendor/zod/core/index.js +19 -0
- package/vendor/zod/core/json-schema-generator.d.ts +65 -0
- package/vendor/zod/core/json-schema-generator.js +99 -0
- package/vendor/zod/core/json-schema-processors.d.ts +49 -0
- package/vendor/zod/core/json-schema-processors.js +747 -0
- package/vendor/zod/core/json-schema.d.ts +89 -0
- package/vendor/zod/core/memoizer.d.ts +15 -0
- package/vendor/zod/core/memoizer.js +265 -0
- package/vendor/zod/core/package.json +7 -0
- package/vendor/zod/core/parse.d.ts +52 -0
- package/vendor/zod/core/parse.js +154 -0
- package/vendor/zod/core/regexes.d.ts +87 -0
- package/vendor/zod/core/regexes.js +150 -0
- package/vendor/zod/core/registries.d.ts +35 -0
- package/vendor/zod/core/registries.js +51 -0
- package/vendor/zod/core/schemas.d.ts +1253 -0
- package/vendor/zod/core/schemas.js +2440 -0
- package/vendor/zod/core/standard-schema.d.ts +126 -0
- package/vendor/zod/core/to-json-schema.d.ts +153 -0
- package/vendor/zod/core/to-json-schema.js +650 -0
- package/vendor/zod/core/util.d.ts +257 -0
- package/vendor/zod/core/util.js +846 -0
- package/vendor/zod/core/versions.d.ts +5 -0
- package/vendor/zod/core/versions.js +5 -0
- package/vendor/zod/core/visit.d.ts +30 -0
- package/vendor/zod/core/visit.js +169 -0
- package/vendor/zod/index.d.ts +3 -0
- package/vendor/zod/index.js +4 -0
- package/vendor/zod/locales/ar.d.ts +4 -0
- package/vendor/zod/locales/ar.js +109 -0
- package/vendor/zod/locales/az.d.ts +4 -0
- package/vendor/zod/locales/az.js +108 -0
- package/vendor/zod/locales/be.d.ts +4 -0
- package/vendor/zod/locales/be.js +166 -0
- package/vendor/zod/locales/bg.d.ts +4 -0
- package/vendor/zod/locales/bg.js +123 -0
- package/vendor/zod/locales/bn.d.ts +4 -0
- package/vendor/zod/locales/bn.js +111 -0
- package/vendor/zod/locales/ca.d.ts +4 -0
- package/vendor/zod/locales/ca.js +110 -0
- package/vendor/zod/locales/ckb.d.ts +4 -0
- package/vendor/zod/locales/ckb.js +131 -0
- package/vendor/zod/locales/cs.d.ts +4 -0
- package/vendor/zod/locales/cs.js +114 -0
- package/vendor/zod/locales/da.d.ts +4 -0
- package/vendor/zod/locales/da.js +118 -0
- package/vendor/zod/locales/de.d.ts +4 -0
- package/vendor/zod/locales/de.js +111 -0
- package/vendor/zod/locales/el.d.ts +4 -0
- package/vendor/zod/locales/el.js +110 -0
- package/vendor/zod/locales/en.d.ts +4 -0
- package/vendor/zod/locales/en.js +123 -0
- package/vendor/zod/locales/eo.d.ts +4 -0
- package/vendor/zod/locales/eo.js +112 -0
- package/vendor/zod/locales/es.d.ts +4 -0
- package/vendor/zod/locales/es.js +134 -0
- package/vendor/zod/locales/fa.d.ts +4 -0
- package/vendor/zod/locales/fa.js +117 -0
- package/vendor/zod/locales/fi.d.ts +4 -0
- package/vendor/zod/locales/fi.js +115 -0
- package/vendor/zod/locales/fr-CA.d.ts +4 -0
- package/vendor/zod/locales/fr-CA.js +110 -0
- package/vendor/zod/locales/fr.d.ts +4 -0
- package/vendor/zod/locales/fr.js +127 -0
- package/vendor/zod/locales/gu.d.ts +4 -0
- package/vendor/zod/locales/gu.js +111 -0
- package/vendor/zod/locales/he.d.ts +4 -0
- package/vendor/zod/locales/he.js +219 -0
- package/vendor/zod/locales/hi.d.ts +4 -0
- package/vendor/zod/locales/hi.js +109 -0
- package/vendor/zod/locales/hr.d.ts +4 -0
- package/vendor/zod/locales/hr.js +124 -0
- package/vendor/zod/locales/hu.d.ts +4 -0
- package/vendor/zod/locales/hu.js +111 -0
- package/vendor/zod/locales/hy.d.ts +4 -0
- package/vendor/zod/locales/hy.js +156 -0
- package/vendor/zod/locales/id.d.ts +4 -0
- package/vendor/zod/locales/id.js +109 -0
- package/vendor/zod/locales/index.d.ts +62 -0
- package/vendor/zod/locales/index.js +62 -0
- package/vendor/zod/locales/is.d.ts +4 -0
- package/vendor/zod/locales/is.js +112 -0
- package/vendor/zod/locales/it.d.ts +4 -0
- package/vendor/zod/locales/it.js +111 -0
- package/vendor/zod/locales/ja.d.ts +4 -0
- package/vendor/zod/locales/ja.js +110 -0
- package/vendor/zod/locales/ka.d.ts +4 -0
- package/vendor/zod/locales/ka.js +115 -0
- package/vendor/zod/locales/kh.d.ts +5 -0
- package/vendor/zod/locales/kh.js +5 -0
- package/vendor/zod/locales/km.d.ts +4 -0
- package/vendor/zod/locales/km.js +113 -0
- package/vendor/zod/locales/kn.d.ts +4 -0
- package/vendor/zod/locales/kn.js +114 -0
- package/vendor/zod/locales/ko.d.ts +4 -0
- package/vendor/zod/locales/ko.js +114 -0
- package/vendor/zod/locales/lt.d.ts +4 -0
- package/vendor/zod/locales/lt.js +205 -0
- package/vendor/zod/locales/mk.d.ts +4 -0
- package/vendor/zod/locales/mk.js +112 -0
- package/vendor/zod/locales/ms.d.ts +4 -0
- package/vendor/zod/locales/ms.js +110 -0
- package/vendor/zod/locales/ne.d.ts +4 -0
- package/vendor/zod/locales/ne.js +109 -0
- package/vendor/zod/locales/nl.d.ts +4 -0
- package/vendor/zod/locales/nl.js +113 -0
- package/vendor/zod/locales/nn.d.ts +4 -0
- package/vendor/zod/locales/nn.js +111 -0
- package/vendor/zod/locales/no.d.ts +4 -0
- package/vendor/zod/locales/no.js +111 -0
- package/vendor/zod/locales/ota.d.ts +4 -0
- package/vendor/zod/locales/ota.js +112 -0
- package/vendor/zod/locales/package.json +7 -0
- package/vendor/zod/locales/pl.d.ts +4 -0
- package/vendor/zod/locales/pl.js +112 -0
- package/vendor/zod/locales/ps.d.ts +4 -0
- package/vendor/zod/locales/ps.js +117 -0
- package/vendor/zod/locales/pt-BR.d.ts +4 -0
- package/vendor/zod/locales/pt-BR.js +141 -0
- package/vendor/zod/locales/pt.d.ts +4 -0
- package/vendor/zod/locales/pt.js +140 -0
- package/vendor/zod/locales/ro.d.ts +4 -0
- package/vendor/zod/locales/ro.js +120 -0
- package/vendor/zod/locales/ru.d.ts +4 -0
- package/vendor/zod/locales/ru.js +166 -0
- package/vendor/zod/locales/sk.d.ts +4 -0
- package/vendor/zod/locales/sk.js +114 -0
- package/vendor/zod/locales/sl.d.ts +4 -0
- package/vendor/zod/locales/sl.js +112 -0
- package/vendor/zod/locales/sv.d.ts +4 -0
- package/vendor/zod/locales/sv.js +113 -0
- package/vendor/zod/locales/ta.d.ts +4 -0
- package/vendor/zod/locales/ta.js +113 -0
- package/vendor/zod/locales/th.d.ts +4 -0
- package/vendor/zod/locales/th.js +113 -0
- package/vendor/zod/locales/tk.d.ts +4 -0
- package/vendor/zod/locales/tk.js +105 -0
- package/vendor/zod/locales/tr.d.ts +4 -0
- package/vendor/zod/locales/tr.js +108 -0
- package/vendor/zod/locales/ua.d.ts +5 -0
- package/vendor/zod/locales/ua.js +5 -0
- package/vendor/zod/locales/uk.d.ts +4 -0
- package/vendor/zod/locales/uk.js +111 -0
- package/vendor/zod/locales/ur.d.ts +4 -0
- package/vendor/zod/locales/ur.js +113 -0
- package/vendor/zod/locales/uz.d.ts +4 -0
- package/vendor/zod/locales/uz.js +111 -0
- package/vendor/zod/locales/vi.d.ts +4 -0
- package/vendor/zod/locales/vi.js +111 -0
- package/vendor/zod/locales/yo.d.ts +4 -0
- package/vendor/zod/locales/yo.js +110 -0
- package/vendor/zod/locales/zh-CN.d.ts +4 -0
- package/vendor/zod/locales/zh-CN.js +112 -0
- package/vendor/zod/locales/zh-TW.d.ts +4 -0
- package/vendor/zod/locales/zh-TW.js +110 -0
- package/vendor/zod/mini/checks.d.ts +1 -0
- package/vendor/zod/mini/checks.js +1 -0
- package/vendor/zod/mini/coerce.d.ts +7 -0
- package/vendor/zod/mini/coerce.js +22 -0
- package/vendor/zod/mini/deep-partial.d.ts +14 -0
- package/vendor/zod/mini/deep-partial.js +13 -0
- package/vendor/zod/mini/external.d.ts +16 -0
- package/vendor/zod/mini/external.js +16 -0
- package/vendor/zod/mini/in-out.d.ts +8 -0
- package/vendor/zod/mini/in-out.js +36 -0
- package/vendor/zod/mini/index.d.ts +3 -0
- package/vendor/zod/mini/index.js +3 -0
- package/vendor/zod/mini/iso.d.ts +22 -0
- package/vendor/zod/mini/iso.js +34 -0
- package/vendor/zod/mini/package.json +7 -0
- package/vendor/zod/mini/parse.d.ts +1 -0
- package/vendor/zod/mini/parse.js +1 -0
- package/vendor/zod/mini/schemas.d.ts +475 -0
- package/vendor/zod/mini/schemas.js +987 -0
- package/vendor/zod/package.json +7 -0
- package/vendor/zodexy/dist/esm/index.js +1274 -0
- package/vendor/zodexy/dist/index.js +1088 -0
- package/vendor/zodexy/dist/schema.zodexy.json +1036 -0
- package/dist/fundamentalTypes/nativeEnumType.d.ts +0 -6
- package/dist/fundamentalTypes/nativeEnumType.d.ts.map +0 -1
- package/src/fundamentalTypes/catchType.js +0 -140
- package/src/fundamentalTypes/enumType.js +0 -52
- package/src/fundamentalTypes/literalType.js +0 -81
- package/src/fundamentalTypes/nativeEnumType.js +0 -157
- package/src/fundamentalTypes/neverType.js +0 -49
- package/src/fundamentalTypes/recordType.js +0 -42
- package/src/fundamentalTypes/tupleType.js +0 -39
- package/src/fundamentalTypes/voidType.js +0 -48
- package/vendor/zod/lib/index.mjs +0 -4236
- package/vendor/zodex/dist/esm/dezerialize.d.ts +0 -26
- package/vendor/zodex/dist/esm/dezerialize.js +0 -393
- package/vendor/zodex/dist/esm/index.d.ts +0 -9
- package/vendor/zodex/dist/esm/index.js +0 -4
- package/vendor/zodex/dist/esm/infer.d.ts +0 -29
- package/vendor/zodex/dist/esm/package.json +0 -1
- package/vendor/zodex/dist/esm/types.d.ts +0 -201
- package/vendor/zodex/dist/esm/types.js +0 -13
- package/vendor/zodex/dist/esm/ui.d.ts +0 -23
- package/vendor/zodex/dist/esm/ui.js +0 -10
- package/vendor/zodex/dist/esm/zerialize.d.ts +0 -50
- package/vendor/zodex/dist/esm/zerialize.js +0 -417
- package/vendor/zodex/dist/esm/zod-types.d.ts +0 -11
- /package/vendor/{zodex/dist/esm/infer.js → zod/core/json-schema.js} +0 -0
- /package/vendor/{zodex/dist/esm/zod-types.js → zod/core/standard-schema.js} +0 -0
|
@@ -1,39 +1,51 @@
|
|
|
1
|
+
/* eslint-disable unicorn/prefer-global-this -- Easier */
|
|
2
|
+
/* eslint-disable unicorn/no-break-in-nested-loop -- Performance to avoid function? */
|
|
3
|
+
/* eslint-disable sonarjs/no-control-regex -- Intentional */
|
|
4
|
+
/* eslint-disable unicorn/no-top-level-assignment-in-function -- Only need module level */
|
|
1
5
|
/*
|
|
2
6
|
Possible todos:
|
|
3
7
|
0. Add XSLT to JML-string stylesheet (or even vice versa)
|
|
4
|
-
0. IE problem: Add JsonML code to handle name attribute (during element creation)
|
|
5
|
-
0. Element-specific: IE object-param handling
|
|
6
8
|
|
|
7
9
|
Todos inspired by JsonML: https://github.com/mckamey/jsonml/blob/master/jsonml-html.js
|
|
8
|
-
|
|
9
|
-
0. duplicate attributes?
|
|
10
10
|
0. expand ATTR_MAP
|
|
11
|
-
0. equivalent of markup, to allow strings to be embedded within an object (e.g., {$value: '<div>id</div>'}); advantage over innerHTML in that it wouldn't need to work as the entire contents (nor destroy any existing content or handlers)
|
|
12
|
-
0. More validation?
|
|
13
|
-
0. JsonML DOM Level 0 listener
|
|
14
|
-
0. Whitespace trimming?
|
|
15
|
-
|
|
16
|
-
JsonML element-specific:
|
|
17
|
-
0. table appending
|
|
18
|
-
0. canHaveChildren necessary? (attempts to append to script and img)
|
|
19
11
|
|
|
20
12
|
Other Todos:
|
|
21
13
|
0. Note to self: Integrate research from other jml notes
|
|
22
|
-
0. Allow Jamilih to be seeded with an existing element, so as to be able to
|
|
14
|
+
0. Allow Jamilih to be seeded with an existing element, so as to be able to
|
|
15
|
+
add/modify attributes and children
|
|
23
16
|
0. Allow array as single first argument
|
|
24
|
-
0. Settle on whether need to use null as last argument to return array (or
|
|
17
|
+
0. Settle on whether need to use null as last argument to return array (or
|
|
18
|
+
fragment) or other way to allow appending? Options object at end instead
|
|
19
|
+
to indicate whether returning array, fragment, first element, etc.?
|
|
25
20
|
0. Allow building of generic XML (pass configuration object)
|
|
26
21
|
0. Allow building content internally as a string (though allowing DOM methods, etc.?)
|
|
27
22
|
0. Support JsonML empty string element name to represent fragments?
|
|
28
|
-
0. Redo browser testing of jml
|
|
23
|
+
0. Redo browser testing of jml
|
|
29
24
|
*/
|
|
30
25
|
|
|
31
26
|
/**
|
|
32
|
-
* @typedef {Window & {DocumentFragment:
|
|
27
|
+
* @typedef {Window & {DocumentFragment: typeof DocumentFragment}} HTMLWindow
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {unknown} ArbitraryValue
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {unknown} StoredValue
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/* eslint-disable jsdoc/reject-any-type -- user-defined callback arguments */
|
|
39
|
+
/**
|
|
40
|
+
* @typedef {any} UserArg
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* @typedef {any} ElementExpando
|
|
33
44
|
*/
|
|
45
|
+
/* eslint-enable jsdoc/reject-any-type */
|
|
34
46
|
|
|
35
47
|
/**
|
|
36
|
-
* @typedef {
|
|
48
|
+
* @typedef {HTMLElement & {[key: string]: ElementExpando}} ExpandoHTMLElement
|
|
37
49
|
*/
|
|
38
50
|
|
|
39
51
|
/**
|
|
@@ -55,7 +67,7 @@ Other Todos:
|
|
|
55
67
|
*/
|
|
56
68
|
|
|
57
69
|
/**
|
|
58
|
-
* @type {import('jsdom').DOMWindow|HTMLWindow|undefined}
|
|
70
|
+
* @type {import('jsdom').DOMWindow|HTMLWindow|typeof globalThis|undefined}
|
|
59
71
|
*/
|
|
60
72
|
let win;
|
|
61
73
|
|
|
@@ -74,7 +86,6 @@ const possibleOptions = ['$plugins',
|
|
|
74
86
|
// '$state', // Used internally
|
|
75
87
|
'$map' // Add any other options here
|
|
76
88
|
];
|
|
77
|
-
|
|
78
89
|
const NS_HTML = 'http://www.w3.org/1999/xhtml',
|
|
79
90
|
hyphenForCamelCase = /-([a-z])/gu;
|
|
80
91
|
const ATTR_MAP = new Map([['maxlength', 'maxLength'], ['minlength', 'minLength'], ['readonly', 'readOnly']]);
|
|
@@ -87,7 +98,7 @@ const BOOL_ATTS = ['checked', 'defaultChecked', 'defaultSelected', 'disabled', '
|
|
|
87
98
|
'readOnly', 'selected'];
|
|
88
99
|
|
|
89
100
|
// From JsonML
|
|
90
|
-
const ATTR_DOM = [...BOOL_ATTS, 'accessKey',
|
|
101
|
+
const ATTR_DOM = new Set([...BOOL_ATTS, 'accessKey',
|
|
91
102
|
// HTMLElement
|
|
92
103
|
'async', 'autocapitalize',
|
|
93
104
|
// HTMLElement
|
|
@@ -105,17 +116,17 @@ const ATTR_DOM = [...BOOL_ATTS, 'accessKey',
|
|
|
105
116
|
// HTMLElement
|
|
106
117
|
'translate',
|
|
107
118
|
// HTMLElement
|
|
108
|
-
'value', 'willvalidate'];
|
|
119
|
+
'value', 'willvalidate']);
|
|
109
120
|
// Todo: Add more to this as useful for templating
|
|
110
121
|
// to avoid setting through nullish value
|
|
111
|
-
const NULLABLES = ['autocomplete', 'dir',
|
|
122
|
+
const NULLABLES = new Set(['autocomplete', 'dir',
|
|
112
123
|
// HTMLElement
|
|
113
124
|
'integrity',
|
|
114
125
|
// script, link
|
|
115
126
|
'lang',
|
|
116
127
|
// HTMLElement
|
|
117
128
|
'max', 'min', 'minLength', 'maxLength', 'title' // HTMLElement
|
|
118
|
-
];
|
|
129
|
+
]);
|
|
119
130
|
|
|
120
131
|
/**
|
|
121
132
|
* @param {string} sel
|
|
@@ -136,19 +147,9 @@ const $$ = sel => {
|
|
|
136
147
|
if (!doc) {
|
|
137
148
|
throw new Error('No document object');
|
|
138
149
|
}
|
|
139
|
-
return [...
|
|
150
|
+
return [...(/** @type {NodeListOf<HTMLElement>} */doc.querySelectorAll(sel))];
|
|
140
151
|
};
|
|
141
152
|
|
|
142
|
-
/**
|
|
143
|
-
* Retrieve the (lower-cased) HTML name of a node.
|
|
144
|
-
* @static
|
|
145
|
-
* @param {Node} node The HTML node
|
|
146
|
-
* @returns {string} The lower-cased node name
|
|
147
|
-
*/
|
|
148
|
-
function _getHTMLNodeName(node) {
|
|
149
|
-
return node.nodeName && node.nodeName.toLowerCase();
|
|
150
|
-
}
|
|
151
|
-
|
|
152
153
|
/**
|
|
153
154
|
* @private
|
|
154
155
|
* @static
|
|
@@ -158,7 +159,7 @@ function _getHTMLNodeName(node) {
|
|
|
158
159
|
* @returns {void}
|
|
159
160
|
*/
|
|
160
161
|
function _appendNode(parent, child) {
|
|
161
|
-
const parentName =
|
|
162
|
+
const parentName = parent.nodeName?.toLowerCase();
|
|
162
163
|
if (parentName === 'template') {
|
|
163
164
|
/** @type {HTMLTemplateElement} */parent.content.append(child);
|
|
164
165
|
return;
|
|
@@ -169,9 +170,10 @@ function _appendNode(parent, child) {
|
|
|
169
170
|
/**
|
|
170
171
|
* Attach event in a cross-browser fashion.
|
|
171
172
|
* @static
|
|
172
|
-
* @
|
|
173
|
+
* @template {HTMLElement} T
|
|
174
|
+
* @param {T} el DOM element to which to attach the event
|
|
173
175
|
* @param {string} type The DOM event (without 'on') to attach to the element
|
|
174
|
-
* @param {(evt: Event & {target:
|
|
176
|
+
* @param {(evt: Event & {target: T}) => void} handler The event handler to attach to the element
|
|
175
177
|
* @param {boolean} [capturing] Whether or not the event should be
|
|
176
178
|
* capturing (W3C-browsers only); default is false; NOT IN USE
|
|
177
179
|
* @returns {void}
|
|
@@ -182,13 +184,13 @@ function _addEvent(el, type, handler, capturing) {
|
|
|
182
184
|
}
|
|
183
185
|
|
|
184
186
|
/**
|
|
185
|
-
* Creates a text node of the result of resolving an entity or character reference.
|
|
186
|
-
* @param {'entity'|'decimal'|'hexadecimal'} type Type of reference
|
|
187
|
-
* @param {string} prefix Text to prefix immediately after the "&"
|
|
188
|
-
* @param {string} arg The body of the reference
|
|
189
|
-
* @throws {TypeError}
|
|
190
|
-
* @returns {Text} The text node of the resolved reference
|
|
191
|
-
*/
|
|
187
|
+
* Creates a text node of the result of resolving an entity or character reference.
|
|
188
|
+
* @param {'entity'|'decimal'|'hexadecimal'} type Type of reference
|
|
189
|
+
* @param {string} prefix Text to prefix immediately after the "&"
|
|
190
|
+
* @param {string} arg The body of the reference
|
|
191
|
+
* @throws {TypeError}
|
|
192
|
+
* @returns {Text} The text node of the resolved reference
|
|
193
|
+
*/
|
|
192
194
|
function _createSafeReference(type, prefix, arg) {
|
|
193
195
|
/* c8 ignore next 3 */
|
|
194
196
|
if (!doc) {
|
|
@@ -203,14 +205,15 @@ function _createSafeReference(type, prefix, arg) {
|
|
|
203
205
|
// Todo: No workaround for XML?
|
|
204
206
|
// eslint-disable-next-line no-unsanitized/property
|
|
205
207
|
elContainer.innerHTML = '&' + prefix + arg + ';';
|
|
208
|
+
// eslint-disable-next-line unicorn/prefer-dom-node-html-methods -- No Safari support
|
|
206
209
|
return doc.createTextNode(elContainer.innerHTML);
|
|
207
210
|
}
|
|
208
211
|
|
|
209
212
|
/**
|
|
210
|
-
* @param {string} n0 Whole expression match (including "-")
|
|
211
|
-
* @param {string} n1 Lower-case letter match
|
|
212
|
-
* @returns {string} Uppercased letter
|
|
213
|
-
*/
|
|
213
|
+
* @param {string} n0 Whole expression match (including "-")
|
|
214
|
+
* @param {string} n1 Lower-case letter match
|
|
215
|
+
* @returns {string} Uppercased letter
|
|
216
|
+
*/
|
|
214
217
|
function _upperCase(n0, n1) {
|
|
215
218
|
return n1.toUpperCase();
|
|
216
219
|
}
|
|
@@ -224,24 +227,31 @@ function _isNullish(o) {
|
|
|
224
227
|
return o === null || o === undefined;
|
|
225
228
|
}
|
|
226
229
|
|
|
230
|
+
/**
|
|
231
|
+
* @param {unknown} item
|
|
232
|
+
* @returns {item is HTMLElement}
|
|
233
|
+
*/
|
|
234
|
+
function _isHTMLElement(item) {
|
|
235
|
+
return Boolean(item && typeof item === 'object' && 'nodeType' in item && item.nodeType === 1);
|
|
236
|
+
}
|
|
237
|
+
|
|
227
238
|
// Todo: Make as public utility, but also return types for undefined, boolean, number, document, etc.
|
|
228
239
|
/**
|
|
229
|
-
* @private
|
|
230
|
-
* @static
|
|
231
|
-
* @param {string|JamilihAttributes|JamilihArray|JamilihChildren|
|
|
232
|
-
* JamilihDocumentFragment|JamilihAttributeNode|
|
|
233
|
-
* JamilihOptions|HTMLElement|Document|DocumentFragment|null|undefined} item
|
|
234
|
-
* @returns {"string"|"null"|"array"|"element"|"fragment"|"object"|
|
|
235
|
-
* "symbol"|"bigint"|"function"|"number"|"boolean"|"undefined"|
|
|
236
|
-
* "document"|"non-container node"}
|
|
237
|
-
*/
|
|
240
|
+
* @private
|
|
241
|
+
* @static
|
|
242
|
+
* @param {string|JamilihAttributes|JamilihArray|JamilihChildren|
|
|
243
|
+
* JamilihDocumentFragment|JamilihAttributeNode|
|
|
244
|
+
* JamilihOptions|HTMLElement|Document|DocumentFragment|null|undefined} item
|
|
245
|
+
* @returns {"string"|"null"|"array"|"element"|"fragment"|"object"|
|
|
246
|
+
* "symbol"|"bigint"|"function"|"number"|"boolean"|"undefined"|
|
|
247
|
+
* "document"|"processing-instruction"|"non-container node"}
|
|
248
|
+
*/
|
|
238
249
|
function _getType(item) {
|
|
239
|
-
const type = typeof item;
|
|
240
|
-
|
|
241
250
|
// Appease TS
|
|
242
251
|
if (typeof item === 'string' || typeof item === 'undefined') {
|
|
243
252
|
return 'string';
|
|
244
253
|
}
|
|
254
|
+
const type = typeof item;
|
|
245
255
|
switch (type) {
|
|
246
256
|
case 'object':
|
|
247
257
|
if (item === null) {
|
|
@@ -254,6 +264,8 @@ function _getType(item) {
|
|
|
254
264
|
switch (item.nodeType) {
|
|
255
265
|
case 1:
|
|
256
266
|
return 'element';
|
|
267
|
+
case 7:
|
|
268
|
+
return 'processing-instruction';
|
|
257
269
|
case 9:
|
|
258
270
|
return 'document';
|
|
259
271
|
case 11:
|
|
@@ -269,23 +281,31 @@ function _getType(item) {
|
|
|
269
281
|
}
|
|
270
282
|
|
|
271
283
|
/**
|
|
272
|
-
* @private
|
|
273
|
-
* @static
|
|
274
|
-
* @param {DocumentFragment} frag
|
|
275
|
-
* @param {Node} node
|
|
276
|
-
* @returns {DocumentFragment}
|
|
277
|
-
*/
|
|
284
|
+
* @private
|
|
285
|
+
* @static
|
|
286
|
+
* @param {DocumentFragment} frag
|
|
287
|
+
* @param {Node} node
|
|
288
|
+
* @returns {DocumentFragment}
|
|
289
|
+
*/
|
|
278
290
|
function _fragReducer(frag, node) {
|
|
279
291
|
frag.append(node);
|
|
280
292
|
return frag;
|
|
281
293
|
}
|
|
282
294
|
|
|
283
295
|
/**
|
|
284
|
-
* @
|
|
285
|
-
* @
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
296
|
+
* @param {string} str
|
|
297
|
+
* @returns {string}
|
|
298
|
+
*/
|
|
299
|
+
function escapeReplacer(str) {
|
|
300
|
+
return str.replaceAll('$', '$$$$');
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* @private
|
|
305
|
+
* @static
|
|
306
|
+
* @param {Object<string, string>} xmlnsObj
|
|
307
|
+
* @returns {(...n: string[]) => string}
|
|
308
|
+
*/
|
|
289
309
|
function _replaceDefiner(xmlnsObj) {
|
|
290
310
|
/**
|
|
291
311
|
* @param {string[]} n
|
|
@@ -293,10 +313,10 @@ function _replaceDefiner(xmlnsObj) {
|
|
|
293
313
|
*/
|
|
294
314
|
return function (...n) {
|
|
295
315
|
const n0 = n[0];
|
|
296
|
-
let retStr = xmlnsObj[''] ? ' xmlns="' + xmlnsObj[''] + '"' : n0; // Preserve XHTML
|
|
316
|
+
let retStr = xmlnsObj[''] ? ' xmlns="' + escapeReplacer(xmlnsObj['']) + '"' : n0; // Preserve XHTML
|
|
297
317
|
for (const [ns, xmlnsVal] of Object.entries(xmlnsObj)) {
|
|
298
318
|
if (ns !== '') {
|
|
299
|
-
retStr += ' xmlns:' + ns + '="' + xmlnsVal + '"';
|
|
319
|
+
retStr += ' xmlns:' + ns + '="' + escapeReplacer(xmlnsVal) + '"';
|
|
300
320
|
}
|
|
301
321
|
}
|
|
302
322
|
return retStr;
|
|
@@ -319,7 +339,7 @@ function _replaceDefiner(xmlnsObj) {
|
|
|
319
339
|
function _childrenToJML(node) {
|
|
320
340
|
return function (childNodeJML, i) {
|
|
321
341
|
const cn = node.childNodes[i];
|
|
322
|
-
const j = Array.isArray(childNodeJML) ? jml(...
|
|
342
|
+
const j = Array.isArray(childNodeJML) ? jml(...(/** @type {JamilihArray} */childNodeJML)) : jml(childNodeJML);
|
|
323
343
|
cn.replaceWith(j);
|
|
324
344
|
};
|
|
325
345
|
}
|
|
@@ -327,30 +347,30 @@ function _childrenToJML(node) {
|
|
|
327
347
|
/**
|
|
328
348
|
* Keep this in sync with `JamilihArray`'s first argument (minus `Document`).
|
|
329
349
|
* @typedef {JamilihDoc|JamilihDoctype|JamilihTextNode|
|
|
330
|
-
* JamilihAttributeNode|JamilihOptions|ElementName|HTMLElement|
|
|
331
|
-
* JamilihDocumentFragment
|
|
332
|
-
* } JamilihFirstArg
|
|
333
|
-
*/
|
|
350
|
+
* JamilihAttributeNode|JamilihOptions|ElementName|HTMLElement|
|
|
351
|
+
* JamilihDocumentFragment
|
|
352
|
+
* } JamilihFirstArg
|
|
353
|
+
*/
|
|
334
354
|
|
|
335
355
|
/**
|
|
336
|
-
* @callback JamilihAppender
|
|
337
|
-
* @param {JamilihArray|JamilihFirstArg|Node|TextNodeString} childJML
|
|
338
|
-
* @returns {void}
|
|
339
|
-
*/
|
|
356
|
+
* @callback JamilihAppender
|
|
357
|
+
* @param {JamilihArray|JamilihArrayLike|JamilihFirstArg|Node|TextNodeString} childJML
|
|
358
|
+
* @returns {void}
|
|
359
|
+
*/
|
|
340
360
|
|
|
341
361
|
/**
|
|
342
|
-
* @private
|
|
343
|
-
* @static
|
|
344
|
-
* @param {ParentNode} node
|
|
345
|
-
* @returns {JamilihAppender}
|
|
346
|
-
*/
|
|
362
|
+
* @private
|
|
363
|
+
* @static
|
|
364
|
+
* @param {ParentNode} node
|
|
365
|
+
* @returns {JamilihAppender}
|
|
366
|
+
*/
|
|
347
367
|
function _appendJML(node) {
|
|
348
368
|
return function (childJML) {
|
|
349
369
|
if (typeof childJML === 'string' || typeof childJML === 'number') {
|
|
350
370
|
throw new TypeError('Unexpected text string/number in the head');
|
|
351
371
|
}
|
|
352
372
|
if (Array.isArray(childJML)) {
|
|
353
|
-
node.append(jml(...childJML));
|
|
373
|
+
node.append(jml(...(/** @type {JamilihArray} */childJML)));
|
|
354
374
|
} else if (typeof childJML === 'object' && 'nodeType' in childJML) {
|
|
355
375
|
node.append(childJML);
|
|
356
376
|
} else {
|
|
@@ -360,23 +380,23 @@ function _appendJML(node) {
|
|
|
360
380
|
}
|
|
361
381
|
|
|
362
382
|
/**
|
|
363
|
-
* @callback appender
|
|
364
|
-
* @param {JamilihArray|JamilihFirstArg|Node|TextNodeString} childJML
|
|
365
|
-
* @returns {void}
|
|
366
|
-
*/
|
|
383
|
+
* @callback appender
|
|
384
|
+
* @param {JamilihArray|JamilihArrayLike|JamilihFirstArg|Node|TextNodeString} childJML
|
|
385
|
+
* @returns {void}
|
|
386
|
+
*/
|
|
367
387
|
|
|
368
388
|
/**
|
|
369
|
-
* @private
|
|
370
|
-
* @static
|
|
371
|
-
* @param {ParentNode} node
|
|
372
|
-
* @returns {appender}
|
|
373
|
-
*/
|
|
389
|
+
* @private
|
|
390
|
+
* @static
|
|
391
|
+
* @param {ParentNode} node
|
|
392
|
+
* @returns {appender}
|
|
393
|
+
*/
|
|
374
394
|
function _appendJMLOrText(node) {
|
|
375
395
|
return function (childJML) {
|
|
376
396
|
if (typeof childJML === 'string' || typeof childJML === 'number') {
|
|
377
397
|
node.append(String(childJML));
|
|
378
398
|
} else if (Array.isArray(childJML)) {
|
|
379
|
-
node.append(jml(...childJML));
|
|
399
|
+
node.append(jml(...(/** @type {JamilihArray} */childJML)));
|
|
380
400
|
} else if (typeof childJML === 'object' && 'nodeType' in childJML) {
|
|
381
401
|
node.append(childJML);
|
|
382
402
|
} else {
|
|
@@ -386,9 +406,9 @@ function _appendJMLOrText(node) {
|
|
|
386
406
|
}
|
|
387
407
|
|
|
388
408
|
/**
|
|
389
|
-
* @private
|
|
390
|
-
* @static
|
|
391
|
-
*/
|
|
409
|
+
* @private
|
|
410
|
+
* @static
|
|
411
|
+
*/
|
|
392
412
|
/*
|
|
393
413
|
function _DOMfromJMLOrString (childNodeJML) {
|
|
394
414
|
if (typeof childNodeJML === 'string') {
|
|
@@ -399,9 +419,9 @@ function _DOMfromJMLOrString (childNodeJML) {
|
|
|
399
419
|
*/
|
|
400
420
|
|
|
401
421
|
/**
|
|
402
|
-
* @typedef {HTMLElement|DocumentFragment|Comment|Attr|
|
|
403
|
-
* Text|Document|DocumentType|ProcessingInstruction|CDATASection} JamilihReturn
|
|
404
|
-
*/
|
|
422
|
+
* @typedef {HTMLElement|DocumentFragment|Comment|Attr|
|
|
423
|
+
* Text|Document|DocumentType|ProcessingInstruction|CDATASection} JamilihReturn
|
|
424
|
+
*/
|
|
405
425
|
// 'string|JamilihOptions|JamilihDocumentFragment|JamilihAttributes|(string|JamilihArray)[]
|
|
406
426
|
|
|
407
427
|
/**
|
|
@@ -418,11 +438,11 @@ function _DOMfromJMLOrString (childNodeJML) {
|
|
|
418
438
|
|
|
419
439
|
/**
|
|
420
440
|
* @typedef {{
|
|
421
|
-
* open?: boolean|ShadowRootJamilihArrayContainer,
|
|
422
|
-
* closed?: boolean|ShadowRootJamilihArrayContainer,
|
|
423
|
-
* template?: string|HTMLTemplateElement|TemplateJamilihArray,
|
|
424
|
-
* content?: ShadowRootJamilihArrayContainer|DocumentFragment
|
|
425
|
-
* }} JamilihShadowRootObject
|
|
441
|
+
* open?: boolean|ShadowRootJamilihArrayContainer,
|
|
442
|
+
* closed?: boolean|ShadowRootJamilihArrayContainer,
|
|
443
|
+
* template?: string|HTMLTemplateElement|TemplateJamilihArray,
|
|
444
|
+
* content?: ShadowRootJamilihArrayContainer|DocumentFragment
|
|
445
|
+
* }} JamilihShadowRootObject
|
|
426
446
|
*/
|
|
427
447
|
|
|
428
448
|
/**
|
|
@@ -444,18 +464,21 @@ function _DOMfromJMLOrString (childNodeJML) {
|
|
|
444
464
|
*/
|
|
445
465
|
|
|
446
466
|
/**
|
|
447
|
-
* @
|
|
467
|
+
* @template {HTMLElement} [T=HTMLElement]
|
|
468
|
+
* @typedef {(this: T, event: Event & {target: T}) => void} EventHandler
|
|
448
469
|
*/
|
|
449
470
|
|
|
450
471
|
/**
|
|
472
|
+
* @template {HTMLElement} [T=HTMLElement]
|
|
451
473
|
* @typedef {{
|
|
452
|
-
* [key: string]: EventHandler
|
|
474
|
+
* [key: string]: EventHandler<T>|[EventHandler<T>, boolean]
|
|
453
475
|
* }} OnAttributeObject
|
|
454
476
|
*/
|
|
455
477
|
|
|
456
478
|
/**
|
|
479
|
+
* @template {HTMLElement} [T=HTMLElement]
|
|
457
480
|
* @typedef {{
|
|
458
|
-
* $on?: OnAttributeObject
|
|
481
|
+
* $on?: OnAttributeObject<T>|null
|
|
459
482
|
* }} OnAttribute
|
|
460
483
|
*/
|
|
461
484
|
|
|
@@ -467,7 +490,6 @@ function _DOMfromJMLOrString (childNodeJML) {
|
|
|
467
490
|
* @typedef {((this: HTMLElement, event?: Event) => void)} HandlerAttributeValue
|
|
468
491
|
*/
|
|
469
492
|
|
|
470
|
-
/* eslint-disable jsdoc/valid-types -- jsdoc-type-pratt-parser Bug */
|
|
471
493
|
/**
|
|
472
494
|
* @typedef {{
|
|
473
495
|
* [key: string]: HandlerAttributeValue
|
|
@@ -491,23 +513,22 @@ function _DOMfromJMLOrString (childNodeJML) {
|
|
|
491
513
|
*/
|
|
492
514
|
|
|
493
515
|
/**
|
|
494
|
-
* @typedef {{[key: string]:
|
|
516
|
+
* @typedef {{[key: string]: unknown}} DefineMixin
|
|
495
517
|
*/
|
|
496
518
|
|
|
497
519
|
/**
|
|
498
520
|
* @typedef {{
|
|
499
521
|
* new (): HTMLElement;
|
|
500
|
-
* prototype: HTMLElement
|
|
522
|
+
* prototype: HTMLElement
|
|
501
523
|
* }} DefineConstructor
|
|
502
524
|
*/
|
|
503
|
-
/* eslint-enable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/131 */
|
|
504
525
|
|
|
505
526
|
/**
|
|
506
527
|
* @typedef {(this: HTMLElement) => void} DefineUserConstructor
|
|
507
528
|
*/
|
|
508
529
|
|
|
509
530
|
/**
|
|
510
|
-
* @typedef {[DefineConstructor|DefineUserConstructor|DefineMixin, DefineOptions?]|[DefineConstructor|DefineUserConstructor, DefineMixin?, DefineOptions?]} DefineObjectArray
|
|
531
|
+
* @typedef {[DefineConstructor|DefineUserConstructor|DefineMixin, DefineOptions?]|[DefineMixin, DefineConstructor]|[DefineConstructor|DefineUserConstructor, DefineMixin?, DefineOptions?]} DefineObjectArray
|
|
511
532
|
*/
|
|
512
533
|
|
|
513
534
|
/**
|
|
@@ -515,11 +536,27 @@ function _DOMfromJMLOrString (childNodeJML) {
|
|
|
515
536
|
*/
|
|
516
537
|
|
|
517
538
|
/**
|
|
518
|
-
* @
|
|
539
|
+
* @template [T=ArbitraryValue]
|
|
540
|
+
* @template {HTMLElement} [U=HTMLElement]
|
|
541
|
+
* @typedef {T & {elem?: U}} SymbolObject
|
|
542
|
+
*/
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* @template {HTMLElement} [T=HTMLElement]
|
|
546
|
+
* @typedef {(this: T, ...args: UserArg[]) => UserArg} SymbolMethod
|
|
547
|
+
*/
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* @typedef {(...args: UserArg[]) => UserArg} BoundSymbolMethod
|
|
551
|
+
*/
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* @template {HTMLElement} [T=HTMLElement]
|
|
555
|
+
* @typedef {[symbol|string, SymbolMethod<T>|SymbolObject<ArbitraryValue, T>]} SymbolArray
|
|
519
556
|
*/
|
|
520
557
|
|
|
521
558
|
/**
|
|
522
|
-
* @typedef {
|
|
559
|
+
* @typedef {BoundSymbolMethod|SymbolObject|ArbitraryValue} SymbolResult
|
|
523
560
|
*/
|
|
524
561
|
|
|
525
562
|
/**
|
|
@@ -527,7 +564,7 @@ function _DOMfromJMLOrString (childNodeJML) {
|
|
|
527
564
|
*/
|
|
528
565
|
|
|
529
566
|
/**
|
|
530
|
-
* @typedef {[string, object]|string|
|
|
567
|
+
* @typedef {[string, object]|string|object} PluginValue
|
|
531
568
|
*/
|
|
532
569
|
|
|
533
570
|
/**
|
|
@@ -542,15 +579,15 @@ function _DOMfromJMLOrString (childNodeJML) {
|
|
|
542
579
|
|
|
543
580
|
/**
|
|
544
581
|
* @typedef {{
|
|
545
|
-
* [key: string]: string|number|((this: HTMLElement, ...args:
|
|
546
|
-
* }} DataAttributeObject
|
|
547
|
-
*/
|
|
582
|
+
* [key: string]: string|number|((this: HTMLElement, ...args: UserArg[]) => UserArg)
|
|
583
|
+
* }} DataAttributeObject
|
|
584
|
+
*/
|
|
548
585
|
|
|
549
586
|
/**
|
|
550
587
|
* @typedef {{
|
|
551
|
-
* $data?: true|string[]|Map<
|
|
588
|
+
* $data?: true|string[]|Map<HTMLElement, UserArg>|WeakMap<HTMLElement, UserArg>|DataAttributeObject|
|
|
552
589
|
* [undefined, DataAttributeObject]|
|
|
553
|
-
* [Map<
|
|
590
|
+
* [Map<HTMLElement, UserArg>|WeakMap<HTMLElement, UserArg>|undefined, DataAttributeObject]
|
|
554
591
|
* }} DataAttribute
|
|
555
592
|
*/
|
|
556
593
|
|
|
@@ -572,18 +609,16 @@ function _DOMfromJMLOrString (childNodeJML) {
|
|
|
572
609
|
* }} JamilihShadowRootAttribute
|
|
573
610
|
*/
|
|
574
611
|
|
|
575
|
-
/* eslint-disable jsdoc/valid-types -- jsdoc-type-pratt-parser Bug */
|
|
576
612
|
/**
|
|
577
613
|
* @typedef {{
|
|
578
614
|
* is?: string|null,
|
|
579
615
|
* $define?: DefineObject
|
|
580
616
|
* }} DefineAttribute
|
|
581
617
|
*/
|
|
582
|
-
/* eslint-enable jsdoc/valid-types -- jsdoc-type-pratt-parser Bug */
|
|
583
618
|
|
|
584
619
|
/**
|
|
585
620
|
* @typedef {{
|
|
586
|
-
* $custom?: {[key: string]:
|
|
621
|
+
* $custom?: {[key: string]: unknown}
|
|
587
622
|
* }} CustomAttribute
|
|
588
623
|
*/
|
|
589
624
|
|
|
@@ -613,6 +648,11 @@ function _DOMfromJMLOrString (childNodeJML) {
|
|
|
613
648
|
/**
|
|
614
649
|
* @typedef {{
|
|
615
650
|
* title?: string,
|
|
651
|
+
* xmlDeclaration?: {
|
|
652
|
+
* version: string,
|
|
653
|
+
* encoding: string,
|
|
654
|
+
* standalone: boolean
|
|
655
|
+
* },
|
|
616
656
|
* childNodes?: JamilihChildType[],
|
|
617
657
|
* $DOCTYPE?: JamilihDocumentType,
|
|
618
658
|
* head?: JamilihChildren
|
|
@@ -651,21 +691,30 @@ function _DOMfromJMLOrString (childNodeJML) {
|
|
|
651
691
|
*/
|
|
652
692
|
|
|
653
693
|
/**
|
|
694
|
+
* @typedef {Document|ElementName|HTMLElement|DocumentFragment|
|
|
695
|
+
* JamilihDocumentFragment|JamilihDoc|JamilihDoctype|JamilihTextNode|
|
|
696
|
+
* JamilihAttributeNode} JamilihFirstArgument
|
|
697
|
+
*/
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Array-form Jamilih input whose tuple positions were widened by operations
|
|
701
|
+
* such as `Array#map`.
|
|
654
702
|
* @typedef {(
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
*
|
|
658
|
-
* )[]} JamilihChildren
|
|
703
|
+
* JamilihFirstArg|JamilihAttributes|JamilihArrayLike|TextNodeString|
|
|
704
|
+
* ShadowRoot|null
|
|
705
|
+
* )[]} JamilihArrayLike
|
|
659
706
|
*/
|
|
660
707
|
|
|
661
|
-
// Todo: DocumentType, Comment, ProcessingInstruction, Text
|
|
662
|
-
// Todo: JamilihCDATANode, JamilihComment, JamilihProcessingInstruction
|
|
663
708
|
/**
|
|
664
|
-
* @typedef {
|
|
665
|
-
*
|
|
666
|
-
*
|
|
709
|
+
* @typedef {(
|
|
710
|
+
* JamilihArray|JamilihArrayLike|TextNodeString|HTMLElement|Comment|
|
|
711
|
+
* ProcessingInstruction|Text|DocumentFragment|JamilihProcessingInstruction|
|
|
712
|
+
* JamilihDocumentFragment|PluginReference
|
|
713
|
+
* )[]} JamilihChildren
|
|
667
714
|
*/
|
|
668
715
|
|
|
716
|
+
// Todo: DocumentType, Comment, ProcessingInstruction, Text
|
|
717
|
+
// Todo: JamilihCDATANode, JamilihComment, JamilihProcessingInstruction
|
|
669
718
|
/**
|
|
670
719
|
* This would be clearer with overrides, but using as typedef.
|
|
671
720
|
*
|
|
@@ -711,8 +760,8 @@ function _DOMfromJMLOrString (childNodeJML) {
|
|
|
711
760
|
|
|
712
761
|
/**
|
|
713
762
|
* @typedef {{
|
|
714
|
-
* root: [Map<HTMLElement,
|
|
715
|
-
* [key: string]: [Map<HTMLElement,
|
|
763
|
+
* root: [Map<HTMLElement,UserArg>|WeakMap<HTMLElement,UserArg>, UserArg],
|
|
764
|
+
* [key: string]: [Map<HTMLElement,UserArg>|WeakMap<HTMLElement,UserArg>, UserArg]
|
|
716
765
|
* }} MapWithRoot
|
|
717
766
|
*/
|
|
718
767
|
|
|
@@ -724,7 +773,7 @@ function _DOMfromJMLOrString (childNodeJML) {
|
|
|
724
773
|
* @typedef {object} JamilihOptions
|
|
725
774
|
* @property {TraversalState} [$state]
|
|
726
775
|
* @property {JamilihPlugin[]} [$plugins]
|
|
727
|
-
* @property {MapWithRoot|[Map<HTMLElement,
|
|
776
|
+
* @property {MapWithRoot|[Map<HTMLElement,UserArg>|WeakMap<HTMLElement,UserArg>, UserArg]} [$map]
|
|
728
777
|
*/
|
|
729
778
|
|
|
730
779
|
/**
|
|
@@ -750,8 +799,7 @@ function checkPluginValue(elem, att, attVal, opts, state) {
|
|
|
750
799
|
});
|
|
751
800
|
}
|
|
752
801
|
}
|
|
753
|
-
return
|
|
754
|
-
);
|
|
802
|
+
return /** @type {string} */attVal;
|
|
755
803
|
}
|
|
756
804
|
|
|
757
805
|
/**
|
|
@@ -765,27 +813,213 @@ function getMatchingPlugin(opts, pluginName) {
|
|
|
765
813
|
});
|
|
766
814
|
}
|
|
767
815
|
|
|
768
|
-
/* eslint-disable jsdoc/valid-types -- pratt parser bug */
|
|
769
816
|
/**
|
|
770
817
|
* @template T
|
|
771
818
|
* @typedef {T[keyof T]} ValueOf
|
|
772
819
|
*/
|
|
773
|
-
/* eslint-enable jsdoc/valid-types -- pratt parser bug */
|
|
774
820
|
|
|
775
|
-
|
|
821
|
+
/**
|
|
822
|
+
* @template {JamilihArray} T
|
|
823
|
+
* @typedef {Extract<Extract<T[number], {$custom?: {[key: string]: unknown}}>['$custom'], object>} RawCustomFromJamilihArray
|
|
824
|
+
*/
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* @template M
|
|
828
|
+
* @typedef {M extends object
|
|
829
|
+
* ? string extends keyof M
|
|
830
|
+
* ? object
|
|
831
|
+
* : M
|
|
832
|
+
* : object} SpecificDefineMixin
|
|
833
|
+
*/
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* @template D
|
|
837
|
+
* @typedef {D extends [infer First, infer Second, ...ArbitraryValue[]]
|
|
838
|
+
* ? (First extends DefineMixin
|
|
839
|
+
* ? SpecificDefineMixin<First>
|
|
840
|
+
* : Second extends DefineMixin
|
|
841
|
+
* ? SpecificDefineMixin<Second>
|
|
842
|
+
* : object)
|
|
843
|
+
* : D extends [infer First]
|
|
844
|
+
* ? First extends DefineMixin
|
|
845
|
+
* ? SpecificDefineMixin<First>
|
|
846
|
+
* : object
|
|
847
|
+
* : D extends DefineMixin
|
|
848
|
+
* ? SpecificDefineMixin<D>
|
|
849
|
+
* : object} DefineMixinFromValue
|
|
850
|
+
*/
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* @template {JamilihArray} T
|
|
854
|
+
* @typedef {T[number] extends infer Item
|
|
855
|
+
* ? Item extends {$define: infer D}
|
|
856
|
+
* ? DefineMixinFromValue<D>
|
|
857
|
+
* : never
|
|
858
|
+
* : never} RawDefineMixinFromJamilihArray
|
|
859
|
+
*/
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* @template D
|
|
863
|
+
* @typedef {D extends [infer First, infer Second, ...ArbitraryValue[]]
|
|
864
|
+
* ? First extends DefineConstructor
|
|
865
|
+
* ? First['prototype']
|
|
866
|
+
* : Second extends DefineConstructor
|
|
867
|
+
* ? Second['prototype']
|
|
868
|
+
* : never
|
|
869
|
+
* : D extends DefineConstructor
|
|
870
|
+
* ? D['prototype']
|
|
871
|
+
* : never} ElementFromDefineValue
|
|
872
|
+
*/
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* @template {JamilihArray} T
|
|
876
|
+
* @typedef {T[number] extends infer Item
|
|
877
|
+
* ? Item extends {$define: infer D}
|
|
878
|
+
* ? ElementFromDefineValue<D>
|
|
879
|
+
* : never
|
|
880
|
+
* : never} ElementFromJamilihDefine
|
|
881
|
+
*/
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* @template {JamilihArray} T
|
|
885
|
+
* @typedef {Extract<T[number], {xmlns: unknown}> extends never ? false : true} HasXmlnsFromJamilihArray
|
|
886
|
+
*/
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* @template {JamilihArray} T
|
|
890
|
+
* @typedef {T extends [infer K, ...ArbitraryValue[]]
|
|
891
|
+
* ? (HasXmlnsFromJamilihArray<T> extends true
|
|
892
|
+
* ? Element
|
|
893
|
+
* : ElementFromJamilihDefine<T> extends never
|
|
894
|
+
* ? K extends keyof HTMLElementTagNameMap
|
|
895
|
+
* ? HTMLElementTagNameMap[K]
|
|
896
|
+
* : HTMLElement
|
|
897
|
+
* : ElementFromJamilihDefine<T>)
|
|
898
|
+
* : Element} ElementFromJamilihArray
|
|
899
|
+
*/
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* @template A
|
|
903
|
+
* @template {Element} E
|
|
904
|
+
* @template X
|
|
905
|
+
* @typedef {A extends {$custom: infer C}
|
|
906
|
+
* ? (C extends object
|
|
907
|
+
* ? Omit<A, '$custom'> & {$custom?: C & ThisType<E & C & X>}
|
|
908
|
+
* : A)
|
|
909
|
+
* : A} WithCustomThis
|
|
910
|
+
*/
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* @template D
|
|
914
|
+
* @template {Element} E
|
|
915
|
+
* @template X
|
|
916
|
+
* @typedef {D extends [infer First, infer Second, ...infer Rest]
|
|
917
|
+
* ? (First extends DefineMixin
|
|
918
|
+
* ? [First & ThisType<E & First & X>, Second, ...Rest]
|
|
919
|
+
* : Second extends DefineMixin
|
|
920
|
+
* ? [First, Second & ThisType<E & Second & X>, ...Rest]
|
|
921
|
+
* : D)
|
|
922
|
+
* : D extends [infer First]
|
|
923
|
+
* ? First extends DefineMixin
|
|
924
|
+
* ? [First & ThisType<E & First & X>]
|
|
925
|
+
* : D
|
|
926
|
+
* : D extends DefineMixin
|
|
927
|
+
* ? D & ThisType<E & D & X>
|
|
928
|
+
* : D} WithDefineThisValue
|
|
929
|
+
*/
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* @template A
|
|
933
|
+
* @template {Element} E
|
|
934
|
+
* @template X
|
|
935
|
+
* @typedef {A extends {$define: infer D}
|
|
936
|
+
* ? Omit<A, '$define'> & {$define?: WithDefineThisValue<D, E, X>}
|
|
937
|
+
* : A} WithDefineThis
|
|
938
|
+
*/
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* @template A
|
|
942
|
+
* @typedef {A extends {$custom: infer C}
|
|
943
|
+
* ? C extends object ? C : object
|
|
944
|
+
* : object} CustomFromJamilihItem
|
|
945
|
+
*/
|
|
946
|
+
|
|
947
|
+
/**
|
|
948
|
+
* @template A
|
|
949
|
+
* @typedef {A extends {$define: infer D}
|
|
950
|
+
* ? DefineMixinFromValue<D>
|
|
951
|
+
* : object} DefineMixinFromJamilihItem
|
|
952
|
+
*/
|
|
953
|
+
|
|
954
|
+
/**
|
|
955
|
+
* @template {JamilihArray} T
|
|
956
|
+
* @template {Element} E
|
|
957
|
+
* @typedef {{[K in keyof T]: WithCustomThis<
|
|
958
|
+
* WithDefineThis<T[K], E, CustomFromJamilihItem<T[K]>>,
|
|
959
|
+
* E,
|
|
960
|
+
* DefineMixinFromJamilihItem<T[K]>
|
|
961
|
+
* >}} JamilihArrayWithCustomThis
|
|
962
|
+
*/
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* @template A
|
|
966
|
+
* @typedef {A extends (infer Item)[]
|
|
967
|
+
* ? (Extract<Item, JamilihFirstArg> extends never ? never : A)
|
|
968
|
+
* : A} ValidateJamilihArrayLike
|
|
969
|
+
*/
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* @template A
|
|
973
|
+
* @typedef {A extends (infer Child)[]
|
|
974
|
+
* ? A & (Child extends unknown[] ? ValidateJamilihArrayLike<Child> : Child)[]
|
|
975
|
+
* : A} ValidateJamilihChildContainer
|
|
976
|
+
*/
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* @template {JamilihArray} T
|
|
980
|
+
* @typedef {{[K in keyof T]: ValidateJamilihChildContainer<T[K]>}} ValidateJamilihArrayLikes
|
|
981
|
+
*/
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
* @template {JamilihArray} T
|
|
985
|
+
* @typedef {(
|
|
986
|
+
* RawCustomFromJamilihArray<T> extends never
|
|
987
|
+
* ? object
|
|
988
|
+
* : RawCustomFromJamilihArray<T>
|
|
989
|
+
* )} CustomFromJamilihArray
|
|
990
|
+
*/
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* @template {JamilihArray} T
|
|
994
|
+
* @typedef {(
|
|
995
|
+
* RawDefineMixinFromJamilihArray<T> extends never
|
|
996
|
+
* ? object
|
|
997
|
+
* : RawDefineMixinFromJamilihArray<T>
|
|
998
|
+
* )} DefineMixinFromJamilihArray
|
|
999
|
+
*/
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* @template U
|
|
1003
|
+
* @template W
|
|
1004
|
+
* @typedef {U extends void ? (ExpandoHTMLElement & W) : (U & W)} ResolvedElement
|
|
1005
|
+
*/
|
|
1006
|
+
|
|
776
1007
|
/**
|
|
777
1008
|
* Creates an XHTML or HTML element (XHTML is preferred, but only in browsers
|
|
778
1009
|
* that support); any element after element can be omitted, and any subsequent
|
|
779
1010
|
* type or types added afterwards.
|
|
780
1011
|
* @template {JamilihArray} T
|
|
781
|
-
* @
|
|
782
|
-
* @
|
|
783
|
-
*
|
|
1012
|
+
* @template {T extends [infer K, ...ArbitraryValue[]] ? (HasXmlnsFromJamilihArray<T> extends true ? Element : ElementFromJamilihDefine<T> extends never ? K extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[K] : K extends string ? HTMLElement : void : ElementFromJamilihDefine<T>) : void} U
|
|
1013
|
+
* @template {ElementFromJamilihArray<T>} E
|
|
1014
|
+
* @template {CustomFromJamilihArray<T>} W
|
|
1015
|
+
* @template {DefineMixinFromJamilihArray<T>} D
|
|
1016
|
+
* @param {JamilihArrayWithCustomThis<T, E> & ValidateJamilihArrayLikes<T>} args
|
|
1017
|
+
* @returns {U extends void ? JamilihReturn : ResolvedElement<U, W & D>}
|
|
784
1018
|
* The newly created (and possibly already appended)
|
|
785
1019
|
* element or array of elements
|
|
786
1020
|
*/
|
|
1021
|
+
|
|
787
1022
|
const jml = function jml(...args) {
|
|
788
|
-
/* eslint-enable jsdoc/valid-types -- pratt parser bug */
|
|
789
1023
|
if (!win) {
|
|
790
1024
|
throw new Error('No window object');
|
|
791
1025
|
}
|
|
@@ -793,7 +1027,7 @@ const jml = function jml(...args) {
|
|
|
793
1027
|
throw new Error('No document object');
|
|
794
1028
|
}
|
|
795
1029
|
|
|
796
|
-
/** @type {(Document|DocumentFragment|HTMLElement) & {[key: string]:
|
|
1030
|
+
/** @type {(Document|DocumentFragment|HTMLElement) & {[key: string]: ElementExpando}} */
|
|
797
1031
|
let elem = doc.createDocumentFragment();
|
|
798
1032
|
/**
|
|
799
1033
|
*
|
|
@@ -807,21 +1041,16 @@ const jml = function jml(...args) {
|
|
|
807
1041
|
throw new Error('No document object');
|
|
808
1042
|
}
|
|
809
1043
|
for (let [att, attVal] of Object.entries(atts)) {
|
|
810
|
-
att = ATTR_MAP.get(att)
|
|
811
|
-
|
|
812
|
-
/**
|
|
813
|
-
* @typedef {any} ElementExpando
|
|
814
|
-
*/
|
|
815
|
-
|
|
816
|
-
if (NULLABLES.includes(att)) {
|
|
1044
|
+
att = ATTR_MAP.has(att) ? String(ATTR_MAP.get(att)) : att;
|
|
1045
|
+
if (NULLABLES.has(att)) {
|
|
817
1046
|
attVal = checkPluginValue(elem, att, /** @type {string|JamilihArray} */attVal, opts);
|
|
818
1047
|
if (!_isNullish(attVal)) {
|
|
819
|
-
|
|
1048
|
+
elem[att] = attVal;
|
|
820
1049
|
}
|
|
821
1050
|
continue;
|
|
822
|
-
}
|
|
1051
|
+
}
|
|
1052
|
+
if (ATTR_DOM.has(att)) {
|
|
823
1053
|
attVal = checkPluginValue(elem, att, /** @type {string|JamilihArray} */attVal, opts);
|
|
824
|
-
/** @type {ElementExpando} */
|
|
825
1054
|
elem[att] = attVal;
|
|
826
1055
|
continue;
|
|
827
1056
|
}
|
|
@@ -859,13 +1088,13 @@ const jml = function jml(...args) {
|
|
|
859
1088
|
if (template) {
|
|
860
1089
|
if (Array.isArray(template)) {
|
|
861
1090
|
template = /** @type {HTMLTemplateElement} */
|
|
862
|
-
_getType(template[0]) === 'object' ? jml('template', ...
|
|
1091
|
+
_getType(template[0]) === 'object' ? jml('template', ...(
|
|
863
1092
|
/**
|
|
864
1093
|
* @type {[
|
|
865
1094
|
* JamilihAttributes, ...(JamilihArray[]|HTMLElement)[]
|
|
866
1095
|
* ]}
|
|
867
1096
|
*/
|
|
868
|
-
template, doc.body) : jml('template',
|
|
1097
|
+
template), doc.body) : jml('template',
|
|
869
1098
|
/**
|
|
870
1099
|
* @type {JamilihArray[]|HTMLElement}
|
|
871
1100
|
*/
|
|
@@ -873,7 +1102,7 @@ const jml = function jml(...args) {
|
|
|
873
1102
|
} else if (typeof template === 'string') {
|
|
874
1103
|
template = /** @type {HTMLTemplateElement} */$(template);
|
|
875
1104
|
}
|
|
876
|
-
jml(
|
|
1105
|
+
jml(/** @type {HTMLTemplateElement} */
|
|
877
1106
|
/** @type {HTMLTemplateElement} */template.content.cloneNode(true), shadowRoot);
|
|
878
1107
|
} else {
|
|
879
1108
|
if (!content) {
|
|
@@ -906,6 +1135,9 @@ const jml = function jml(...args) {
|
|
|
906
1135
|
}
|
|
907
1136
|
case '$custom':
|
|
908
1137
|
{
|
|
1138
|
+
if (attVal !== null && (typeof attVal === 'object' || typeof attVal === 'function') && Object.prototype.propertyIsEnumerable.call(attVal, '__proto__')) {
|
|
1139
|
+
throw new TypeError('`$custom` may not define `__proto__`');
|
|
1140
|
+
}
|
|
909
1141
|
Object.assign(elem, attVal);
|
|
910
1142
|
break;
|
|
911
1143
|
}
|
|
@@ -934,7 +1166,7 @@ const jml = function jml(...args) {
|
|
|
934
1166
|
} = atts);
|
|
935
1167
|
}
|
|
936
1168
|
}
|
|
937
|
-
const def = customizedBuiltIn ? /** @type {string} */is : localName;
|
|
1169
|
+
const def = customizedBuiltIn ? (/** @type {string} */is) : localName;
|
|
938
1170
|
if (window.customElements.get(def)) {
|
|
939
1171
|
break;
|
|
940
1172
|
}
|
|
@@ -948,7 +1180,7 @@ const jml = function jml(...args) {
|
|
|
948
1180
|
if (!doc) {
|
|
949
1181
|
throw new Error('No document object');
|
|
950
1182
|
}
|
|
951
|
-
const baseClass = typeof options === 'object' && typeof options.extends === 'string' ? /** @type {typeof HTMLElement} */doc.createElement(options.extends).constructor : customizedBuiltIn ? /** @type {typeof HTMLElement} */doc.createElement(localName).constructor : window.HTMLElement;
|
|
1183
|
+
const baseClass = typeof options === 'object' && typeof options.extends === 'string' ? (/** @type {typeof HTMLElement} */doc.createElement(options.extends).constructor) : customizedBuiltIn ? (/** @type {typeof HTMLElement} */doc.createElement(localName).constructor) : window.HTMLElement;
|
|
952
1184
|
|
|
953
1185
|
/**
|
|
954
1186
|
* Class wrapping base class.
|
|
@@ -976,7 +1208,8 @@ const jml = function jml(...args) {
|
|
|
976
1208
|
const defineObj = /** @type {DefineObject} */attVal;
|
|
977
1209
|
if (Array.isArray(defineObj)) {
|
|
978
1210
|
if (defineObj.length <= 2) {
|
|
979
|
-
[cnstrctr
|
|
1211
|
+
[cnstrctr] = defineObj;
|
|
1212
|
+
options = /** @type {DefineOptions|undefined} */defineObj[1];
|
|
980
1213
|
if (typeof options === 'string') {
|
|
981
1214
|
// Todo: Allow creating a definition without using it;
|
|
982
1215
|
// that may be the only reason to have a string here which
|
|
@@ -1006,7 +1239,7 @@ const jml = function jml(...args) {
|
|
|
1006
1239
|
cnstrctr = getConstructor();
|
|
1007
1240
|
}
|
|
1008
1241
|
if (!cnstrctr.toString().startsWith('class')) {
|
|
1009
|
-
cnstrctr = getConstructor(
|
|
1242
|
+
cnstrctr = getConstructor(/** @type {DefineUserConstructor} */cnstrctr);
|
|
1010
1243
|
}
|
|
1011
1244
|
if (!options && customizedBuiltIn) {
|
|
1012
1245
|
options = {
|
|
@@ -1015,7 +1248,7 @@ const jml = function jml(...args) {
|
|
|
1015
1248
|
}
|
|
1016
1249
|
if (mixin) {
|
|
1017
1250
|
Object.entries(mixin).forEach(([methodName, method]) => {
|
|
1018
|
-
/** @type {DefineConstructor} */cnstrctr.prototype
|
|
1251
|
+
Reflect.set(/** @type {DefineConstructor} */cnstrctr.prototype, methodName, method);
|
|
1019
1252
|
});
|
|
1020
1253
|
}
|
|
1021
1254
|
// console.log('def', def, '::', typeof options === 'object' ? options : undefined);
|
|
@@ -1024,9 +1257,13 @@ const jml = function jml(...args) {
|
|
|
1024
1257
|
}
|
|
1025
1258
|
case '$symbol':
|
|
1026
1259
|
{
|
|
1027
|
-
|
|
1260
|
+
if (!_isHTMLElement(elem)) {
|
|
1261
|
+
throw new TypeError('Element expected for `$symbol`');
|
|
1262
|
+
}
|
|
1263
|
+
const symbolElem = /** @type {ResolvedElement<U, W>} */elem;
|
|
1264
|
+
const [symbol, func] = /** @type {SymbolArray<ResolvedElement<U, W>>} */attVal;
|
|
1028
1265
|
if (typeof func === 'function') {
|
|
1029
|
-
const funcBound = func.bind(
|
|
1266
|
+
const funcBound = func.bind(symbolElem);
|
|
1030
1267
|
if (typeof symbol === 'string') {
|
|
1031
1268
|
// @ts-expect-error
|
|
1032
1269
|
elem[Symbol.for(symbol)] = funcBound;
|
|
@@ -1036,7 +1273,7 @@ const jml = function jml(...args) {
|
|
|
1036
1273
|
}
|
|
1037
1274
|
} else {
|
|
1038
1275
|
const obj = func;
|
|
1039
|
-
obj.elem =
|
|
1276
|
+
obj.elem = symbolElem;
|
|
1040
1277
|
if (typeof symbol === 'string') {
|
|
1041
1278
|
// @ts-expect-error
|
|
1042
1279
|
elem[Symbol.for(symbol)] = obj;
|
|
@@ -1049,7 +1286,7 @@ const jml = function jml(...args) {
|
|
|
1049
1286
|
}
|
|
1050
1287
|
case '$data':
|
|
1051
1288
|
{
|
|
1052
|
-
setMap(
|
|
1289
|
+
setMap(/** @type {true|string[]|Map<HTMLElement, unknown>|WeakMap<HTMLElement, unknown>|DataAttributeObject} */
|
|
1053
1290
|
attVal);
|
|
1054
1291
|
break;
|
|
1055
1292
|
}
|
|
@@ -1057,35 +1294,34 @@ const jml = function jml(...args) {
|
|
|
1057
1294
|
{
|
|
1058
1295
|
// Attribute node
|
|
1059
1296
|
const attr = /** @type {JamilihAttributeNodeValue} */attVal;
|
|
1060
|
-
const node = attr.length === 3 ? doc.createAttributeNS(attr[0], attr[1]) : doc.createAttribute(
|
|
1061
|
-
node.value = /** @type {string} */attr
|
|
1297
|
+
const node = attr.length === 3 ? doc.createAttributeNS(attr[0], attr[1]) : doc.createAttribute(/** @type {string} */attr[0]);
|
|
1298
|
+
node.value = /** @type {string} */attr.at(-1);
|
|
1062
1299
|
nodes[nodes.length] = node;
|
|
1063
1300
|
break;
|
|
1064
1301
|
}
|
|
1065
1302
|
case '$text':
|
|
1066
1303
|
{
|
|
1067
1304
|
// Todo: Also allow as jml(['a text node']) (or should that become a fragment)?
|
|
1068
|
-
const node = doc.createTextNode(
|
|
1305
|
+
const node = doc.createTextNode(/** @type {string} */attVal);
|
|
1069
1306
|
nodes[nodes.length] = node;
|
|
1070
1307
|
break;
|
|
1071
1308
|
}
|
|
1072
1309
|
case '$document':
|
|
1073
1310
|
{
|
|
1074
1311
|
// Todo: Conditionally create XML document
|
|
1075
|
-
const docNode = doc.implementation.createHTMLDocument();
|
|
1076
1312
|
if (!attVal) {
|
|
1077
1313
|
throw new Error('Bad attribute value');
|
|
1078
1314
|
}
|
|
1315
|
+
const docNode = doc.implementation.createHTMLDocument();
|
|
1079
1316
|
const jamlihDoc = /** @type {JamilihDocument} */attVal;
|
|
1080
1317
|
if (jamlihDoc.childNodes) {
|
|
1081
1318
|
// Remove any extra nodes created by createHTMLDocument().
|
|
1082
1319
|
const j = jamlihDoc.childNodes.length;
|
|
1083
|
-
while (docNode.childNodes
|
|
1320
|
+
while (Object.hasOwn(docNode.childNodes, j)) {
|
|
1084
1321
|
const cn = docNode.childNodes[j];
|
|
1085
1322
|
cn.remove();
|
|
1086
1323
|
// `j` should stay the same as removing will cause node to be present
|
|
1087
1324
|
}
|
|
1088
|
-
|
|
1089
1325
|
jamlihDoc.childNodes.forEach(_childrenToJML(docNode));
|
|
1090
1326
|
} else {
|
|
1091
1327
|
if (jamlihDoc.$DOCTYPE) {
|
|
@@ -1106,8 +1342,7 @@ const jml = function jml(...args) {
|
|
|
1106
1342
|
if (jamlihDoc.title) {
|
|
1107
1343
|
docNode.title = jamlihDoc.title; // Appends after meta
|
|
1108
1344
|
}
|
|
1109
|
-
|
|
1110
|
-
if (jamlihDoc.head && head) {
|
|
1345
|
+
if (head && jamlihDoc.head) {
|
|
1111
1346
|
// each child of `head` is:
|
|
1112
1347
|
// (JamilihArray|TextNodeString|HTMLElement|Comment|ProcessingInstruction|
|
|
1113
1348
|
// Text|DocumentFragment|JamilihProcessingInstruction|JamilihDocumentFragment)
|
|
@@ -1121,10 +1356,20 @@ const jml = function jml(...args) {
|
|
|
1121
1356
|
jamlihDoc.head.forEach(_appendJML(head));
|
|
1122
1357
|
}
|
|
1123
1358
|
}
|
|
1124
|
-
if (
|
|
1359
|
+
if (body && jamlihDoc.body) {
|
|
1125
1360
|
jamlihDoc.body.forEach(_appendJMLOrText(body));
|
|
1126
1361
|
}
|
|
1127
1362
|
}
|
|
1363
|
+
if (jamlihDoc.xmlDeclaration) {
|
|
1364
|
+
const {
|
|
1365
|
+
version,
|
|
1366
|
+
encoding,
|
|
1367
|
+
standalone
|
|
1368
|
+
} = jamlihDoc.xmlDeclaration;
|
|
1369
|
+
const xmlDeclarationData = `${version ? ` version="${version}"` : ''}${encoding ? ` encoding="${encoding}"` : ''}${standalone ? ` standalone="yes"` : ''}`.slice(1);
|
|
1370
|
+
const xmlDeclaration = doc.createProcessingInstruction('xml', xmlDeclarationData);
|
|
1371
|
+
docNode.insertBefore(xmlDeclaration, docNode.firstChild);
|
|
1372
|
+
}
|
|
1128
1373
|
nodes[nodes.length] = docNode;
|
|
1129
1374
|
break;
|
|
1130
1375
|
}
|
|
@@ -1138,17 +1383,18 @@ const jml = function jml(...args) {
|
|
|
1138
1383
|
case '$on':
|
|
1139
1384
|
{
|
|
1140
1385
|
// Events
|
|
1386
|
+
const onElem = /** @type {ResolvedElement<U, W>} */elem;
|
|
1141
1387
|
// Allow for no-op by defaulting to `{}`
|
|
1142
|
-
|
|
1388
|
+
// eslint-disable-next-line prefer-const, unicorn/no-unreadable-for-of-expression -- Ok as mixed
|
|
1389
|
+
for (let [p2, val] of Object.entries(/** @type {OnAttributeObject<ResolvedElement<U, W>>} */attVal || {})) {
|
|
1143
1390
|
if (typeof val === 'function') {
|
|
1144
1391
|
val = [val, false];
|
|
1145
1392
|
}
|
|
1146
1393
|
if (typeof val[0] !== 'function') {
|
|
1147
1394
|
throw new TypeError(`Expect a function for \`$on\`; args: ${JSON.stringify(args)}`);
|
|
1148
1395
|
}
|
|
1149
|
-
_addEvent(
|
|
1396
|
+
_addEvent(onElem, p2, val[0], val[1]); // element, event name, handler, capturing
|
|
1150
1397
|
}
|
|
1151
|
-
|
|
1152
1398
|
break;
|
|
1153
1399
|
}
|
|
1154
1400
|
case 'className':
|
|
@@ -1171,7 +1417,11 @@ const jml = function jml(...args) {
|
|
|
1171
1417
|
const pastInitialProp = startProp !== '';
|
|
1172
1418
|
Object.keys(atVal).forEach(key => {
|
|
1173
1419
|
const value = atVal[key];
|
|
1174
|
-
prop =
|
|
1420
|
+
prop = startProp + (pastInitialProp
|
|
1421
|
+
// eslint-disable-next-line unicorn/no-unsafe-string-replacement -- Function
|
|
1422
|
+
? key.replaceAll(hyphenForCamelCase, _upperCase).replace(/^([a-z])/u, _upperCase)
|
|
1423
|
+
// eslint-disable-next-line unicorn/no-unsafe-string-replacement -- Function
|
|
1424
|
+
: key.replaceAll(hyphenForCamelCase, _upperCase));
|
|
1175
1425
|
if (value === null || typeof value !== 'object') {
|
|
1176
1426
|
if (!_isNullish(value)) {
|
|
1177
1427
|
elem.dataset[prop] = value;
|
|
@@ -1182,7 +1432,7 @@ const jml = function jml(...args) {
|
|
|
1182
1432
|
recurse(value, prop);
|
|
1183
1433
|
});
|
|
1184
1434
|
};
|
|
1185
|
-
recurse(
|
|
1435
|
+
recurse(/** @type {DatasetAttributeObject} */attVal, '');
|
|
1186
1436
|
break;
|
|
1187
1437
|
// Todo: Disable this by default unless configuration explicitly allows (for security)
|
|
1188
1438
|
}
|
|
@@ -1232,7 +1482,8 @@ const jml = function jml(...args) {
|
|
|
1232
1482
|
elem.style.cssFloat = styleVal;
|
|
1233
1483
|
elem.style.styleFloat = styleVal; // Harmless though we could make conditional on older IE instead
|
|
1234
1484
|
} else {
|
|
1235
|
-
|
|
1485
|
+
// eslint-disable-next-line unicorn/no-unsafe-string-replacement -- Function
|
|
1486
|
+
elem.style[p2.replaceAll(hyphenForCamelCase, _upperCase)] = styleVal;
|
|
1236
1487
|
}
|
|
1237
1488
|
}
|
|
1238
1489
|
}
|
|
@@ -1256,10 +1507,10 @@ const jml = function jml(...args) {
|
|
|
1256
1507
|
if (matchingPlugin) {
|
|
1257
1508
|
matchingPlugin.set({
|
|
1258
1509
|
opts,
|
|
1259
|
-
element: /** @type {HTMLElement} */nodes[0],
|
|
1510
|
+
element: (/** @type {HTMLElement} */nodes[0]),
|
|
1260
1511
|
attribute: {
|
|
1261
1512
|
name: pluginName,
|
|
1262
|
-
value: /** @type {PluginReference} */attVal
|
|
1513
|
+
value: (/** @type {PluginReference} */attVal)
|
|
1263
1514
|
}
|
|
1264
1515
|
});
|
|
1265
1516
|
break;
|
|
@@ -1321,12 +1572,12 @@ const jml = function jml(...args) {
|
|
|
1321
1572
|
const defaultMap = opts.$map && /** @type {MapWithRoot} */opts.$map.root;
|
|
1322
1573
|
|
|
1323
1574
|
/**
|
|
1324
|
-
* @param {true|string[]|Map<
|
|
1575
|
+
* @param {true|string[]|Map<HTMLElement, UserArg>|WeakMap<HTMLElement, UserArg>|DataAttributeObject|[Map<HTMLElement, UserArg>|WeakMap<HTMLElement, UserArg>|undefined, DataAttributeObject|UserArg]} dataVal
|
|
1325
1576
|
* @returns {void}
|
|
1326
1577
|
*/
|
|
1327
1578
|
const setMap = dataVal => {
|
|
1328
1579
|
let map, obj;
|
|
1329
|
-
const defMap = /** @type {[Map<HTMLElement,
|
|
1580
|
+
const defMap = /** @type {[Map<HTMLElement, UserArg> | WeakMap<HTMLElement, UserArg>, UserArg]} */defaultMap;
|
|
1330
1581
|
// Boolean indicating use of default map and object
|
|
1331
1582
|
if (dataVal === true) {
|
|
1332
1583
|
[map, obj] = defMap;
|
|
@@ -1334,12 +1585,11 @@ const jml = function jml(...args) {
|
|
|
1334
1585
|
// Array of strings mapping to default
|
|
1335
1586
|
if (typeof dataVal[0] === 'string') {
|
|
1336
1587
|
dataVal.forEach(dVal => {
|
|
1337
|
-
setMap(
|
|
1588
|
+
setMap(/** @type {MapWithRoot} */opts.$map[dVal]);
|
|
1338
1589
|
});
|
|
1339
1590
|
return;
|
|
1340
1591
|
// Array of Map and non-map data object
|
|
1341
1592
|
}
|
|
1342
|
-
|
|
1343
1593
|
map = dataVal[0] || defMap[0];
|
|
1344
1594
|
obj = dataVal[1] || defMap[1];
|
|
1345
1595
|
// Map
|
|
@@ -1351,8 +1601,8 @@ const jml = function jml(...args) {
|
|
|
1351
1601
|
map = defMap[0];
|
|
1352
1602
|
obj = dataVal;
|
|
1353
1603
|
}
|
|
1354
|
-
/** @type {Map<HTMLElement,
|
|
1355
|
-
map.set(
|
|
1604
|
+
/** @type {Map<HTMLElement, UserArg> | WeakMap<HTMLElement, UserArg>} */
|
|
1605
|
+
map.set(/** @type {HTMLElement} */
|
|
1356
1606
|
elem, obj);
|
|
1357
1607
|
};
|
|
1358
1608
|
for (let i = argStart; i < argc; i++) {
|
|
@@ -1363,18 +1613,16 @@ const jml = function jml(...args) {
|
|
|
1363
1613
|
// null always indicates a place-holder (only needed for last argument if want array returned)
|
|
1364
1614
|
if (i === argc - 1) {
|
|
1365
1615
|
// Casting needing unless changing `jml()` signature with overloads
|
|
1366
|
-
return
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
); // nodes;
|
|
1616
|
+
return /** @type {U extends void ? JamilihReturn : ResolvedElement<U, W & D>} */nodes.length <= 1 ? nodes[0]
|
|
1617
|
+
// eslint-disable-next-line unicorn/no-array-callback-reference
|
|
1618
|
+
: nodes.reduce(_fragReducer, doc.createDocumentFragment()); // nodes;
|
|
1370
1619
|
}
|
|
1371
|
-
|
|
1372
1620
|
throw new TypeError(`\`null\` values not allowed except as final Jamilih argument; index ${i} on args: ${JSON.stringify(args)}`);
|
|
1373
1621
|
case 'string':
|
|
1374
1622
|
// Strings normally indicate elements
|
|
1375
1623
|
switch (arg) {
|
|
1376
1624
|
case '!':
|
|
1377
|
-
nodes[nodes.length] = doc.createComment(
|
|
1625
|
+
nodes[nodes.length] = doc.createComment(/** @type {string} */args[++i]);
|
|
1378
1626
|
break;
|
|
1379
1627
|
case '?':
|
|
1380
1628
|
{
|
|
@@ -1384,9 +1632,9 @@ const jml = function jml(...args) {
|
|
|
1384
1632
|
if (val && typeof val === 'object') {
|
|
1385
1633
|
const procValues = [];
|
|
1386
1634
|
for (const [p, procInstVal] of Object.entries(val)) {
|
|
1387
|
-
procValues.push(p + '=
|
|
1635
|
+
procValues.push(p + '="' +
|
|
1388
1636
|
// https://www.w3.org/TR/xml-stylesheet/#NT-PseudoAttValue
|
|
1389
|
-
procInstVal.
|
|
1637
|
+
procInstVal.replaceAll('"', '"') + '"');
|
|
1390
1638
|
}
|
|
1391
1639
|
procValue = procValues.join(' ');
|
|
1392
1640
|
}
|
|
@@ -1423,12 +1671,11 @@ const jml = function jml(...args) {
|
|
|
1423
1671
|
// CDATA valid in XML only, so we'll just treat as text for mutual compatibility
|
|
1424
1672
|
// Todo: config (or detection via some kind of doc.documentType property?) of whether in XML
|
|
1425
1673
|
try {
|
|
1426
|
-
nodes[nodes.length] = doc.createCDATASection(
|
|
1674
|
+
nodes[nodes.length] = doc.createCDATASection(/** @type {string} */args[++i]);
|
|
1427
1675
|
} catch (e2) {
|
|
1428
|
-
nodes[nodes.length] = doc.createTextNode(
|
|
1676
|
+
nodes[nodes.length] = doc.createTextNode(/** @type {string} */
|
|
1429
1677
|
args[i]); // i already incremented
|
|
1430
1678
|
}
|
|
1431
|
-
|
|
1432
1679
|
break;
|
|
1433
1680
|
case '':
|
|
1434
1681
|
nodes[nodes.length] = elem = doc.createDocumentFragment();
|
|
@@ -1447,13 +1694,12 @@ const jml = function jml(...args) {
|
|
|
1447
1694
|
/* c8 ignore next 4 */
|
|
1448
1695
|
elem = doc.createElementNS
|
|
1449
1696
|
// Should create separate file for this
|
|
1450
|
-
|
|
1451
|
-
is: /** @type {string} */is
|
|
1697
|
+
? (/** @type {HTMLElement} */doc.createElementNS(NS_HTML, elStr, {
|
|
1698
|
+
is: (/** @type {string} */is)
|
|
1452
1699
|
})
|
|
1453
|
-
/* c8 ignore next 1 */ : doc.createElement(elStr, {
|
|
1454
|
-
is: /** @type {string} */is
|
|
1700
|
+
/* c8 ignore next 1 */) : doc.createElement(elStr, {
|
|
1701
|
+
is: (/** @type {string} */is)
|
|
1455
1702
|
});
|
|
1456
|
-
/* eslint-enable object-shorthand -- Casting */
|
|
1457
1703
|
} else /* c8 ignore next */if (doc.createElementNS) {
|
|
1458
1704
|
elem = doc.createElementNS(NS_HTML, elStr);
|
|
1459
1705
|
/* c8 ignore next 3 */
|
|
@@ -1481,25 +1727,26 @@ const jml = function jml(...args) {
|
|
|
1481
1727
|
// elem.setAttribute('xmlns', atts.xmlns); // Doesn't work
|
|
1482
1728
|
// Can't set namespaceURI dynamically, renameNode() is not supported, and setAttribute() doesn't work to change the namespace, so we resort to this hack
|
|
1483
1729
|
const xmlnsObj = /** @type {XmlnsAttributeObject} */atts;
|
|
1484
|
-
const replacer = xmlnsObj.xmlns && typeof xmlnsObj.xmlns === 'object' ? _replaceDefiner(xmlnsObj.xmlns) : ' xmlns="' + xmlnsObj.xmlns + '"';
|
|
1730
|
+
const replacer = xmlnsObj.xmlns && typeof xmlnsObj.xmlns === 'object' ? _replaceDefiner(xmlnsObj.xmlns) : ' xmlns="' + escapeReplacer(xmlnsObj.xmlns) + '"';
|
|
1485
1731
|
// try {
|
|
1486
1732
|
// Also fix DOMParser to work with text/html
|
|
1487
1733
|
elem = nodes[nodes.length - 1] =
|
|
1488
1734
|
// Why doesn't `HTMLWindow` have `DOMParser`?
|
|
1489
|
-
new /** @type {import('jsdom').DOMWindow} */win.DOMParser().parseFromString(new /** @type {import('jsdom').DOMWindow} */win.XMLSerializer().serializeToString(elem)
|
|
1735
|
+
new /** @type {import('jsdom').DOMWindow} */win.DOMParser().parseFromString(new /** @type {import('jsdom').DOMWindow} */win.XMLSerializer().serializeToString(elem).
|
|
1490
1736
|
// Mozilla adds XHTML namespace
|
|
1491
|
-
|
|
1737
|
+
replace(' xmlns="' + escapeReplacer(NS_HTML) + '"',
|
|
1492
1738
|
// Needed to cast here, despite either overload working
|
|
1739
|
+
// eslint-disable-next-line unicorn/no-unsafe-string-replacement -- Escaped
|
|
1493
1740
|
/** @type {string} */
|
|
1494
1741
|
replacer), 'application/xml').documentElement;
|
|
1495
1742
|
// Todo: Report to plugins
|
|
1496
1743
|
opts.$state = 'element';
|
|
1497
1744
|
// }catch(e) {alert(elem.outerHTML);throw e;}
|
|
1498
1745
|
}
|
|
1499
|
-
|
|
1500
|
-
_checkAtts( /** @type {JamilihAttributes} */atts);
|
|
1746
|
+
_checkAtts(/** @type {JamilihAttributes} */atts);
|
|
1501
1747
|
break;
|
|
1502
1748
|
}
|
|
1749
|
+
case 'processing-instruction':
|
|
1503
1750
|
case 'document':
|
|
1504
1751
|
case 'fragment':
|
|
1505
1752
|
case 'element':
|
|
@@ -1517,7 +1764,7 @@ const jml = function jml(...args) {
|
|
|
1517
1764
|
// parent
|
|
1518
1765
|
const elsl = nodes.length;
|
|
1519
1766
|
for (let k = 0; k < elsl; k++) {
|
|
1520
|
-
_appendNode(
|
|
1767
|
+
_appendNode(/** @type {Document|DocumentFragment|HTMLElement} */arg, nodes[k]);
|
|
1521
1768
|
}
|
|
1522
1769
|
} else {
|
|
1523
1770
|
nodes[nodes.length] = /** @type {Document|DocumentFragment|HTMLElement} */arg;
|
|
@@ -1528,12 +1775,19 @@ const jml = function jml(...args) {
|
|
|
1528
1775
|
// Arrays or arrays of arrays indicate child nodes
|
|
1529
1776
|
const child = /** @type {JamilihChildren} */arg;
|
|
1530
1777
|
const cl = child.length;
|
|
1778
|
+
/**
|
|
1779
|
+
* @param {number} childIndex
|
|
1780
|
+
* @returns {TypeError}
|
|
1781
|
+
*/
|
|
1782
|
+
const getBadChildrenError = childIndex => {
|
|
1783
|
+
return new TypeError(`Bad children (parent array: ${JSON.stringify(args)}; index ${childIndex} of child: ${JSON.stringify(child)})`);
|
|
1784
|
+
};
|
|
1531
1785
|
for (let j = 0; j < cl; j++) {
|
|
1532
1786
|
// Go through children array container to handle elements
|
|
1533
1787
|
const childContent = child[j];
|
|
1534
1788
|
const childContentType = typeof childContent;
|
|
1535
1789
|
if (childContent === null || _isNullish(childContent)) {
|
|
1536
|
-
throw
|
|
1790
|
+
throw getBadChildrenError(j);
|
|
1537
1791
|
}
|
|
1538
1792
|
switch (childContentType) {
|
|
1539
1793
|
// Todo: determine whether null or function should have special handling or be converted to text
|
|
@@ -1545,12 +1799,17 @@ const jml = function jml(...args) {
|
|
|
1545
1799
|
default:
|
|
1546
1800
|
// bigint, symbol, function
|
|
1547
1801
|
if (typeof childContent !== 'object') {
|
|
1548
|
-
throw
|
|
1802
|
+
throw getBadChildrenError(j);
|
|
1549
1803
|
}
|
|
1550
1804
|
if (Array.isArray(childContent)) {
|
|
1551
1805
|
// Arrays representing child elements
|
|
1806
|
+
const childHeadType = typeof childContent[0];
|
|
1807
|
+
if (childContent.length === 0 || childHeadType !== 'string' && childHeadType !== 'object' || childContent[0] === null) {
|
|
1808
|
+
throw getBadChildrenError(j);
|
|
1809
|
+
}
|
|
1552
1810
|
opts.$state = 'children';
|
|
1553
|
-
|
|
1811
|
+
const childArgs = /** @type {JamilihArray} */[opts, ...childContent];
|
|
1812
|
+
_appendNode(elem, jml(...childArgs));
|
|
1554
1813
|
} else if ('#' in childContent) {
|
|
1555
1814
|
// Fragment
|
|
1556
1815
|
opts.$state = 'fragmentChildren';
|
|
@@ -1580,8 +1839,7 @@ const jml = function jml(...args) {
|
|
|
1580
1839
|
}
|
|
1581
1840
|
|
|
1582
1841
|
// Casting needing unless changing `jml()` signature with overloads
|
|
1583
|
-
return
|
|
1584
|
-
);
|
|
1842
|
+
return /** @type {U extends void ? JamilihReturn : ResolvedElement<U, W & D>} */ret;
|
|
1585
1843
|
};
|
|
1586
1844
|
|
|
1587
1845
|
/**
|
|
@@ -1651,8 +1909,8 @@ class DOMException extends Error {
|
|
|
1651
1909
|
|
|
1652
1910
|
/**
|
|
1653
1911
|
* @typedef {JamilihArray|JamilihDoctype|
|
|
1654
|
-
* JamilihCDATANode|JamilihEntityReference|JamilihProcessingInstruction|
|
|
1655
|
-
* JamilihComment|JamilihDocumentFragment} JamilihChildType
|
|
1912
|
+
* JamilihCDATANode|JamilihEntityReference|JamilihProcessingInstruction|
|
|
1913
|
+
* JamilihComment|JamilihDocumentFragment} JamilihChildType
|
|
1656
1914
|
*/
|
|
1657
1915
|
|
|
1658
1916
|
/**
|
|
@@ -1660,15 +1918,15 @@ class DOMException extends Error {
|
|
|
1660
1918
|
*/
|
|
1661
1919
|
|
|
1662
1920
|
/**
|
|
1663
|
-
* Converts a DOM object or a string of HTML into a Jamilih object (or string).
|
|
1664
|
-
* @param {string|HTMLElement|Node|Entity} nde If a string, will parse as document
|
|
1665
|
-
* @param {ToJmlConfig} [config] Configuration object
|
|
1666
|
-
* @throws {TypeError}
|
|
1667
|
-
* @returns {JamilihType|string} Array containing the elements which represent
|
|
1668
|
-
* a Jamilih object, or, if `stringOutput` is true, it will be the stringified
|
|
1669
|
-
* version of such an object
|
|
1670
|
-
*/
|
|
1671
|
-
|
|
1921
|
+
* Converts a DOM object or a string of HTML into a Jamilih object (or string).
|
|
1922
|
+
* @param {string|HTMLElement|Node|Entity} nde If a string, will parse as document
|
|
1923
|
+
* @param {ToJmlConfig} [config] Configuration object
|
|
1924
|
+
* @throws {TypeError}
|
|
1925
|
+
* @returns {JamilihType|string} Array containing the elements which represent
|
|
1926
|
+
* a Jamilih object, or, if `stringOutput` is true, it will be the stringified
|
|
1927
|
+
* version of such an object
|
|
1928
|
+
*/
|
|
1929
|
+
const toJML = function (nde, {
|
|
1672
1930
|
stringOutput = false,
|
|
1673
1931
|
reportInvalidState = true,
|
|
1674
1932
|
stripWhitespace = false
|
|
@@ -1679,12 +1937,11 @@ jml.toJML = function (nde, {
|
|
|
1679
1937
|
if (typeof nde === 'string') {
|
|
1680
1938
|
nde = new /** @type {import('jsdom').DOMWindow} */win.DOMParser().parseFromString(nde, 'text/html'); // todo: Give option for XML once implemented and change JSDoc to allow for Element
|
|
1681
1939
|
}
|
|
1682
|
-
|
|
1683
1940
|
const dom = /** @type {HTMLElement|Node|Entity} */nde;
|
|
1684
1941
|
|
|
1685
1942
|
/**
|
|
1686
1943
|
* @todo Find more specific type than `any`
|
|
1687
|
-
* @typedef {{[key: (number|string)]:
|
|
1944
|
+
* @typedef {{[key: (number|string)]: UserArg}} IndexableObject
|
|
1688
1945
|
*/
|
|
1689
1946
|
|
|
1690
1947
|
const ret = /** @type {IndexableObject} */[];
|
|
@@ -1698,12 +1955,14 @@ jml.toJML = function (nde, {
|
|
|
1698
1955
|
*/
|
|
1699
1956
|
function invalidStateError(msg) {
|
|
1700
1957
|
// These are probably only necessary if working with text/html
|
|
1701
|
-
if (reportInvalidState) {
|
|
1702
|
-
|
|
1703
|
-
const e = new DOMException(msg, 'INVALID_STATE_ERR');
|
|
1704
|
-
e.code = 11;
|
|
1705
|
-
throw e;
|
|
1958
|
+
if (!reportInvalidState) {
|
|
1959
|
+
return;
|
|
1706
1960
|
}
|
|
1961
|
+
|
|
1962
|
+
// INVALID_STATE_ERR per section 9.3 XHTML 5: https://www.w3.org/TR/html5/the-xhtml-syntax.html
|
|
1963
|
+
const e = new DOMException(msg, 'INVALID_STATE_ERR');
|
|
1964
|
+
e.code = 11;
|
|
1965
|
+
throw e;
|
|
1707
1966
|
}
|
|
1708
1967
|
|
|
1709
1968
|
/**
|
|
@@ -1790,8 +2049,13 @@ jml.toJML = function (nde, {
|
|
|
1790
2049
|
namespaces = {
|
|
1791
2050
|
...namespaces
|
|
1792
2051
|
};
|
|
1793
|
-
const xmlChars = /^([\
|
|
1794
|
-
|
|
2052
|
+
const xmlChars = /^([\u{9}\u{A}\u{D}\u{20}-\u{D7FF}\u{E000}-\u{FFFD}]|[\uD800-\uDBFF][\uDC00-\uDFFF])*$/u; // eslint-disable-line no-control-regex
|
|
2053
|
+
|
|
2054
|
+
// eslint-disable-next-line prefer-destructuring -- TS
|
|
2055
|
+
const nodeValue = /** @type {Node} */nodeOrEntity.nodeValue;
|
|
2056
|
+
if ([2, 3, 4, 7, 8].includes(type) &&
|
|
2057
|
+
// eslint-disable-next-line unicorn/prefer-simple-condition-first -- Safer
|
|
2058
|
+
nodeValue && !xmlChars.test(nodeValue)) {
|
|
1795
2059
|
invalidStateError('Node has bad XML character value');
|
|
1796
2060
|
}
|
|
1797
2061
|
|
|
@@ -1820,7 +2084,6 @@ jml.toJML = function (nde, {
|
|
|
1820
2084
|
parentIdx = tmpParentIdx;
|
|
1821
2085
|
parentIdx++; // Increment index in parent container of this element
|
|
1822
2086
|
}
|
|
1823
|
-
|
|
1824
2087
|
switch (type) {
|
|
1825
2088
|
case 1:
|
|
1826
2089
|
{
|
|
@@ -1896,6 +2159,7 @@ jml.toJML = function (nde, {
|
|
|
1896
2159
|
{
|
|
1897
2160
|
// CDATA
|
|
1898
2161
|
const node = /** @type {CDATASection} */nodeOrEntity;
|
|
2162
|
+
// eslint-disable-next-line unicorn/no-useless-concat -- Safer if pasting
|
|
1899
2163
|
if (node.nodeValue?.includes(']]' + '>')) {
|
|
1900
2164
|
invalidStateError('CDATA cannot end with closing ]]>');
|
|
1901
2165
|
}
|
|
@@ -1979,8 +2243,8 @@ jml.toJML = function (nde, {
|
|
|
1979
2243
|
name: /** @type {DocumentType} */node.name
|
|
1980
2244
|
}
|
|
1981
2245
|
};
|
|
1982
|
-
const pubIdChar = /^(\
|
|
1983
|
-
if (!pubIdChar.test(
|
|
2246
|
+
const pubIdChar = /^(\u{20}|\u{D}|\u{A}|[a-zA-Z0-9]|[-'()+,./:=?;!*#@$_%])*$/u; // eslint-disable-line no-control-regex
|
|
2247
|
+
if (!pubIdChar.test(/** @type {DocumentType} */node.publicId)) {
|
|
1984
2248
|
invalidStateError('A publicId must have valid characters.');
|
|
1985
2249
|
}
|
|
1986
2250
|
addExternalID(start.$DOCTYPE, node);
|
|
@@ -2021,36 +2285,37 @@ jml.toJML = function (nde, {
|
|
|
2021
2285
|
}
|
|
2022
2286
|
return ret[0];
|
|
2023
2287
|
};
|
|
2288
|
+
jml.toJML = toJML;
|
|
2024
2289
|
|
|
2025
2290
|
/**
|
|
2026
2291
|
* @param {string|HTMLElement} dom
|
|
2027
2292
|
* @param {ToJmlConfig} [config]
|
|
2028
2293
|
* @returns {string}
|
|
2029
2294
|
*/
|
|
2030
|
-
|
|
2031
|
-
return
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
}))
|
|
2035
|
-
);
|
|
2295
|
+
const toJMLString = function (dom, config) {
|
|
2296
|
+
return /** @type {string} */toJML(dom, Object.assign(config || {}, {
|
|
2297
|
+
stringOutput: true
|
|
2298
|
+
}));
|
|
2036
2299
|
};
|
|
2300
|
+
jml.toJMLString = toJMLString;
|
|
2037
2301
|
|
|
2038
2302
|
/**
|
|
2039
2303
|
*
|
|
2040
2304
|
* @param {JamilihArray} args
|
|
2041
2305
|
* @returns {JamilihReturn}
|
|
2042
2306
|
*/
|
|
2043
|
-
|
|
2307
|
+
const toDOM = function (...args) {
|
|
2044
2308
|
// Alias for jml()
|
|
2045
2309
|
return jml(...args);
|
|
2046
2310
|
};
|
|
2311
|
+
jml.toDOM = toDOM;
|
|
2047
2312
|
|
|
2048
2313
|
/**
|
|
2049
2314
|
*
|
|
2050
2315
|
* @param {JamilihArray} args
|
|
2051
2316
|
* @returns {string}
|
|
2052
2317
|
*/
|
|
2053
|
-
|
|
2318
|
+
const toHTML = function (...args) {
|
|
2054
2319
|
// Todo: Replace this with version of jml() that directly builds a string
|
|
2055
2320
|
const ret = jml(...args);
|
|
2056
2321
|
switch (ret.nodeType) {
|
|
@@ -2060,33 +2325,34 @@ jml.toHTML = function (...args) {
|
|
|
2060
2325
|
// Todo: deal with serialization of properties like 'selected',
|
|
2061
2326
|
// 'checked', 'value', 'defaultValue', 'for', 'dataset', 'on*',
|
|
2062
2327
|
// 'style'! (i.e., need to build a string ourselves)
|
|
2063
|
-
return
|
|
2064
|
-
);
|
|
2328
|
+
return /** @type {HTMLElement} */ret.outerHTML;
|
|
2065
2329
|
}
|
|
2066
2330
|
case 2:
|
|
2067
2331
|
{
|
|
2068
2332
|
// ATTR
|
|
2069
|
-
return `${
|
|
2070
|
-
/** @type {Attr} */ret.name}="${
|
|
2071
|
-
/** @type {Attr} */ret.value.replace(/"/gu, '"')}"`;
|
|
2333
|
+
return `${ /** @type {Attr} */ret.name}="${ /** @type {Attr} */ret.value.replaceAll('"', '"')}"`;
|
|
2072
2334
|
}
|
|
2073
2335
|
case 3:
|
|
2074
2336
|
{
|
|
2075
2337
|
// TEXT
|
|
2076
2338
|
// Fallthrough
|
|
2077
2339
|
// } case 4: { // CDATA
|
|
2340
|
+
// eslint-disable-next-line prefer-destructuring -- TS
|
|
2341
|
+
const nodeValue = /** @type {Text|CDATASection} */ret.nodeValue;
|
|
2078
2342
|
/* c8 ignore next 3 */
|
|
2079
|
-
if (!
|
|
2343
|
+
if (!nodeValue) {
|
|
2080
2344
|
throw new TypeError('Unexpected null Text node');
|
|
2081
2345
|
}
|
|
2082
|
-
return
|
|
2083
|
-
);
|
|
2346
|
+
return nodeValue;
|
|
2084
2347
|
// case 5: // Entity Reference Node
|
|
2085
2348
|
// No 6: Entity Node
|
|
2086
2349
|
// No 12: Notation Node
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2350
|
+
}
|
|
2351
|
+
case 7:
|
|
2352
|
+
{
|
|
2353
|
+
// PROCESSING INSTRUCTION
|
|
2354
|
+
const node = /** @type {ProcessingInstruction} */ret;
|
|
2355
|
+
return `<?${node.target} ${node.data}?>`;
|
|
2090
2356
|
// } case 8: { // Comment
|
|
2091
2357
|
// return `<!--${ret.nodeValue}-->`;
|
|
2092
2358
|
}
|
|
@@ -2096,7 +2362,7 @@ jml.toHTML = function (...args) {
|
|
|
2096
2362
|
// DOCUMENT FRAGMENT
|
|
2097
2363
|
const node = /** @type {DocumentFragment} */ret;
|
|
2098
2364
|
return [...node.childNodes].map(childNode => {
|
|
2099
|
-
return
|
|
2365
|
+
return toHTML(/** @type {JamilihFirstArgument} */childNode);
|
|
2100
2366
|
}).join('');
|
|
2101
2367
|
}
|
|
2102
2368
|
case 10:
|
|
@@ -2110,47 +2376,52 @@ jml.toHTML = function (...args) {
|
|
|
2110
2376
|
throw new Error('Unexpected node type');
|
|
2111
2377
|
}
|
|
2112
2378
|
};
|
|
2379
|
+
jml.toHTML = toHTML;
|
|
2113
2380
|
|
|
2114
2381
|
/**
|
|
2115
2382
|
*
|
|
2116
2383
|
* @param {JamilihArray} args
|
|
2117
2384
|
* @returns {string}
|
|
2118
2385
|
*/
|
|
2119
|
-
|
|
2386
|
+
const toDOMString = function (...args) {
|
|
2120
2387
|
// Alias for jml.toHTML for parity with jml.toJMLString
|
|
2121
|
-
return
|
|
2388
|
+
return toHTML(...args);
|
|
2122
2389
|
};
|
|
2390
|
+
jml.toDOMString = toDOMString;
|
|
2123
2391
|
|
|
2124
2392
|
/**
|
|
2125
2393
|
*
|
|
2126
2394
|
* @param {JamilihArray} args
|
|
2127
2395
|
* @returns {string}
|
|
2128
2396
|
*/
|
|
2129
|
-
|
|
2397
|
+
const toXML = function (...args) {
|
|
2130
2398
|
if (!win) {
|
|
2131
2399
|
throw new Error('No window object set');
|
|
2132
2400
|
}
|
|
2133
2401
|
const ret = jml(...args);
|
|
2134
2402
|
return new /** @type {import('jsdom').DOMWindow} */win.XMLSerializer().serializeToString(ret);
|
|
2135
2403
|
};
|
|
2404
|
+
jml.toXML = toXML;
|
|
2136
2405
|
|
|
2137
2406
|
/**
|
|
2138
2407
|
*
|
|
2139
2408
|
* @param {JamilihArray} args
|
|
2140
2409
|
* @returns {string}
|
|
2141
2410
|
*/
|
|
2142
|
-
|
|
2411
|
+
const toXMLDOMString = function (...args) {
|
|
2143
2412
|
// Alias for jml.toXML for parity with jml.toJMLString
|
|
2144
|
-
return
|
|
2413
|
+
return toXML(...args);
|
|
2145
2414
|
};
|
|
2415
|
+
jml.toXMLDOMString = toXMLDOMString;
|
|
2146
2416
|
|
|
2147
2417
|
/**
|
|
2148
2418
|
* Element-aware wrapper for `Map`.
|
|
2419
|
+
* @template V
|
|
2149
2420
|
*/
|
|
2150
2421
|
class JamilihMap extends Map {
|
|
2151
2422
|
/**
|
|
2152
2423
|
* @param {?(string|HTMLElement)} element
|
|
2153
|
-
* @returns {
|
|
2424
|
+
* @returns {V}
|
|
2154
2425
|
*/
|
|
2155
2426
|
get(element) {
|
|
2156
2427
|
const elem = typeof element === 'string' ? $(element) : element;
|
|
@@ -2158,104 +2429,109 @@ class JamilihMap extends Map {
|
|
|
2158
2429
|
}
|
|
2159
2430
|
/**
|
|
2160
2431
|
* @param {string|HTMLElement} element
|
|
2161
|
-
* @param {
|
|
2162
|
-
* @returns {
|
|
2432
|
+
* @param {V} value
|
|
2433
|
+
* @returns {this}
|
|
2163
2434
|
*/
|
|
2164
2435
|
set(element, value) {
|
|
2165
2436
|
const elem = typeof element === 'string' ? $(element) : element;
|
|
2166
|
-
|
|
2437
|
+
super.set.call(this, elem, value);
|
|
2438
|
+
return this;
|
|
2167
2439
|
}
|
|
2168
2440
|
/**
|
|
2169
2441
|
* @param {string|HTMLElement} element
|
|
2170
2442
|
* @param {string} methodName
|
|
2171
|
-
* @param {...
|
|
2172
|
-
* @returns {
|
|
2443
|
+
* @param {...UserArg} args
|
|
2444
|
+
* @returns {StoredValue}
|
|
2173
2445
|
*/
|
|
2174
2446
|
invoke(element, methodName, ...args) {
|
|
2175
2447
|
const elem = typeof element === 'string' ? $(element) : element;
|
|
2176
|
-
return this.get(elem)[methodName](elem, ...args);
|
|
2448
|
+
return /** @type {UserArg} */this.get(elem)[methodName](elem, ...args);
|
|
2177
2449
|
}
|
|
2178
2450
|
}
|
|
2179
2451
|
|
|
2180
2452
|
/**
|
|
2181
2453
|
* Element-aware wrapper for `WeakMap`.
|
|
2182
|
-
* @
|
|
2454
|
+
* @template V
|
|
2183
2455
|
*/
|
|
2184
2456
|
class JamilihWeakMap extends WeakMap {
|
|
2185
2457
|
/**
|
|
2186
|
-
* @param {
|
|
2187
|
-
* @returns {
|
|
2458
|
+
* @param {?(string|object|symbol)} element
|
|
2459
|
+
* @returns {V}
|
|
2188
2460
|
*/
|
|
2189
2461
|
get(element) {
|
|
2190
2462
|
const elem = typeof element === 'string' ? $(element) : element;
|
|
2191
2463
|
if (!elem) {
|
|
2192
2464
|
throw new Error("Can't find the element");
|
|
2193
2465
|
}
|
|
2194
|
-
return super.get.call(this, elem);
|
|
2466
|
+
return super.get.call(this, /** @type {object} */elem);
|
|
2195
2467
|
}
|
|
2196
2468
|
/**
|
|
2197
|
-
* @param {
|
|
2198
|
-
* @param {
|
|
2199
|
-
* @returns {
|
|
2469
|
+
* @param {?(string|object|symbol)} element
|
|
2470
|
+
* @param {V} value
|
|
2471
|
+
* @returns {this}
|
|
2200
2472
|
*/
|
|
2201
2473
|
set(element, value) {
|
|
2202
2474
|
const elem = typeof element === 'string' ? $(element) : element;
|
|
2203
2475
|
if (!elem) {
|
|
2204
2476
|
throw new Error("Can't find the element");
|
|
2205
2477
|
}
|
|
2206
|
-
|
|
2478
|
+
super.set.call(this, /** @type {object} */elem, value);
|
|
2479
|
+
return this;
|
|
2207
2480
|
}
|
|
2208
2481
|
/**
|
|
2209
2482
|
* @param {string|HTMLElement} element
|
|
2210
2483
|
* @param {string} methodName
|
|
2211
|
-
* @param {...
|
|
2212
|
-
* @returns {
|
|
2484
|
+
* @param {...UserArg} args
|
|
2485
|
+
* @returns {StoredValue}
|
|
2213
2486
|
*/
|
|
2214
2487
|
invoke(element, methodName, ...args) {
|
|
2215
2488
|
const elem = typeof element === 'string' ? $(element) : element;
|
|
2216
2489
|
if (!elem) {
|
|
2217
2490
|
throw new Error("Can't find the element");
|
|
2218
2491
|
}
|
|
2219
|
-
return this.get(elem)[methodName](elem, ...args);
|
|
2492
|
+
return /** @type {UserArg} */this.get(elem)[methodName](elem, ...args);
|
|
2220
2493
|
}
|
|
2221
2494
|
}
|
|
2222
2495
|
jml.Map = JamilihMap;
|
|
2223
2496
|
jml.WeakMap = JamilihWeakMap;
|
|
2224
2497
|
|
|
2225
2498
|
/**
|
|
2226
|
-
* @
|
|
2499
|
+
* @template V
|
|
2500
|
+
* @typedef {[JamilihWeakMap<V>|JamilihMap<V>, HTMLElement]} MapAndElementArray
|
|
2227
2501
|
*/
|
|
2228
2502
|
|
|
2229
2503
|
/**
|
|
2230
|
-
* @
|
|
2504
|
+
* @template V
|
|
2505
|
+
* @param {V} obj
|
|
2231
2506
|
* @param {JamilihArrayPostOptions} args
|
|
2232
|
-
* @returns {MapAndElementArray}
|
|
2507
|
+
* @returns {MapAndElementArray<V>}
|
|
2233
2508
|
*/
|
|
2234
2509
|
jml.weak = function (obj, ...args) {
|
|
2235
2510
|
const map = new JamilihWeakMap();
|
|
2236
2511
|
const elem = jml({
|
|
2237
2512
|
$map: [map, obj]
|
|
2238
2513
|
}, ...args);
|
|
2239
|
-
return [map, /** @type {HTMLElement} */elem];
|
|
2514
|
+
return [map, (/** @type {HTMLElement} */elem)];
|
|
2240
2515
|
};
|
|
2241
2516
|
|
|
2242
2517
|
/**
|
|
2243
|
-
* @
|
|
2518
|
+
* @template V
|
|
2519
|
+
* @param {V} obj
|
|
2244
2520
|
* @param {JamilihArrayPostOptions} args
|
|
2245
|
-
* @returns {MapAndElementArray}
|
|
2521
|
+
* @returns {MapAndElementArray<V>}
|
|
2246
2522
|
*/
|
|
2247
2523
|
jml.strong = function (obj, ...args) {
|
|
2248
2524
|
const map = new JamilihMap();
|
|
2249
2525
|
const elem = jml({
|
|
2250
2526
|
$map: [map, obj]
|
|
2251
2527
|
}, ...args);
|
|
2252
|
-
return [map, /** @type {HTMLElement} */elem];
|
|
2528
|
+
return [map, (/** @type {HTMLElement} */elem)];
|
|
2253
2529
|
};
|
|
2254
2530
|
|
|
2255
2531
|
/**
|
|
2256
2532
|
* @param {string|HTMLElement} element If a string, will be interpreted as a selector
|
|
2257
2533
|
* @param {symbol|string} sym If a string, will be used with `Symbol.for`
|
|
2258
|
-
* @returns {
|
|
2534
|
+
* @returns {SymbolResult} The value associated with the symbol
|
|
2259
2535
|
*/
|
|
2260
2536
|
jml.symbol = jml.sym = jml.for = function (element, sym) {
|
|
2261
2537
|
const elem = typeof element === 'string' ? $(element) : element;
|
|
@@ -2265,16 +2541,16 @@ jml.symbol = jml.sym = jml.for = function (element, sym) {
|
|
|
2265
2541
|
};
|
|
2266
2542
|
|
|
2267
2543
|
/**
|
|
2268
|
-
* @typedef {((elem: HTMLElement, ...args:
|
|
2544
|
+
* @typedef {((elem: HTMLElement, ...args: UserArg[]) => void)|{[key: string]: (elem: HTMLElement, ...args: UserArg[]) => void}} MapCommand
|
|
2269
2545
|
*/
|
|
2270
2546
|
|
|
2271
2547
|
/**
|
|
2272
2548
|
* @param {?(string|HTMLElement)} elem If a string, will be interpreted as a selector
|
|
2273
2549
|
* @param {symbol|string|Map<HTMLElement, MapCommand>|WeakMap<HTMLElement, MapCommand>} symOrMap If a string, will be used with `Symbol.for`
|
|
2274
|
-
* @param {string|
|
|
2550
|
+
* @param {string|UserArg} methodName Can be `UserArg` if the symbol or map directly
|
|
2275
2551
|
* points to a function (it is then used as the first argument).
|
|
2276
|
-
* @param {
|
|
2277
|
-
* @returns {
|
|
2552
|
+
* @param {UserArg[]} args
|
|
2553
|
+
* @returns {StoredValue}
|
|
2278
2554
|
*/
|
|
2279
2555
|
jml.command = function (elem, symOrMap, methodName, ...args) {
|
|
2280
2556
|
elem = typeof elem === 'string' ? $(elem) : elem;
|
|
@@ -2287,8 +2563,7 @@ jml.command = function (elem, symOrMap, methodName, ...args) {
|
|
|
2287
2563
|
if (typeof func === 'function') {
|
|
2288
2564
|
return func(methodName, ...args); // Already has `this` bound to `elem`
|
|
2289
2565
|
}
|
|
2290
|
-
|
|
2291
|
-
return func[methodName](...args);
|
|
2566
|
+
return /** @type {UserArg} */func[methodName](...args);
|
|
2292
2567
|
}
|
|
2293
2568
|
func = /** @type {Map<HTMLElement, MapCommand>|WeakMap<HTMLElement, MapCommand>} */symOrMap.get(elem);
|
|
2294
2569
|
if (!func) {
|
|
@@ -2304,10 +2579,10 @@ jml.command = function (elem, symOrMap, methodName, ...args) {
|
|
|
2304
2579
|
/**
|
|
2305
2580
|
* Expects properties `document`, `XMLSerializer`, and `DOMParser`.
|
|
2306
2581
|
* Also updates `body` with `document.body`.
|
|
2307
|
-
* @param {import('jsdom').DOMWindow|HTMLWindow|undefined} wind
|
|
2582
|
+
* @param {import('jsdom').DOMWindow|HTMLWindow|typeof globalThis|undefined} wind
|
|
2308
2583
|
* @returns {void}
|
|
2309
2584
|
*/
|
|
2310
|
-
|
|
2585
|
+
const setWindow = wind => {
|
|
2311
2586
|
win = wind;
|
|
2312
2587
|
doc = win?.document;
|
|
2313
2588
|
if (doc && doc.body) {
|
|
@@ -2315,40 +2590,43 @@ jml.setWindow = wind => {
|
|
|
2315
2590
|
body = /** @type {HTMLBodyElement} */doc.body;
|
|
2316
2591
|
}
|
|
2317
2592
|
};
|
|
2593
|
+
jml.setWindow = setWindow;
|
|
2318
2594
|
|
|
2319
2595
|
/**
|
|
2320
|
-
* @returns {import('jsdom').DOMWindow|HTMLWindow}
|
|
2596
|
+
* @returns {import('jsdom').DOMWindow|HTMLWindow|typeof globalThis}
|
|
2321
2597
|
*/
|
|
2322
|
-
|
|
2598
|
+
const getWindow = () => {
|
|
2323
2599
|
if (!win) {
|
|
2324
2600
|
throw new Error('No window object set');
|
|
2325
2601
|
}
|
|
2326
2602
|
return win;
|
|
2327
2603
|
};
|
|
2604
|
+
jml.getWindow = getWindow;
|
|
2328
2605
|
|
|
2329
2606
|
/**
|
|
2330
2607
|
* Does not run Jamilih so can be further processed.
|
|
2331
|
-
* @
|
|
2332
|
-
* @param {
|
|
2333
|
-
* @
|
|
2608
|
+
* @template T
|
|
2609
|
+
* @param {T[]} array
|
|
2610
|
+
* @param {T} glu
|
|
2611
|
+
* @returns {T[]}
|
|
2334
2612
|
*/
|
|
2335
2613
|
function glue(array, glu) {
|
|
2336
2614
|
return [...array].reduce((arr, item) => {
|
|
2337
2615
|
arr.push(item, glu);
|
|
2338
2616
|
return arr;
|
|
2339
|
-
}, []).slice(0, -1);
|
|
2617
|
+
}, /** @type {T[]} */[]).slice(0, -1);
|
|
2340
2618
|
}
|
|
2341
2619
|
|
|
2342
2620
|
/**
|
|
2343
2621
|
* @type {HTMLBodyElement}
|
|
2344
2622
|
*/
|
|
2345
|
-
let body; // eslint-disable-line import/no-mutable-exports
|
|
2623
|
+
let body; // // eslint-disable-line import/no-mutable-exports
|
|
2346
2624
|
|
|
2347
2625
|
/* c8 ignore next 4 */
|
|
2348
2626
|
if (doc && doc.body) {
|
|
2349
2627
|
// eslint-disable-next-line prefer-destructuring -- Needed for type
|
|
2350
2628
|
body = /** @type {HTMLBodyElement} */doc.body;
|
|
2351
2629
|
}
|
|
2352
|
-
const nbsp = '\
|
|
2630
|
+
const nbsp = '\u{A0}'; // Very commonly needed in templates
|
|
2353
2631
|
|
|
2354
|
-
export { $, $$, DOMException, body,
|
|
2632
|
+
export { $, $$, DOMException, body, getWindow, glue, jml, nbsp, setWindow, toDOM, toDOMString, toHTML, toJML, toJMLString, toXML, toXMLDOMString };
|