@gyral/core 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +129 -0
- package/NOTICE +19 -0
- package/README.md +35 -8
- package/dist/call.d.ts +32 -0
- package/dist/call.js +63 -0
- package/dist/call.js.map +1 -0
- package/dist/children.d.ts +30 -5
- package/dist/children.js +26 -4
- package/dist/children.js.map +1 -1
- package/dist/cli/gyral-types.d.ts +2 -0
- package/dist/cli/gyral-types.js +23 -0
- package/dist/cli/gyral-types.js.map +1 -0
- package/dist/command.d.ts +54 -12
- package/dist/command.js +31 -11
- package/dist/command.js.map +1 -1
- package/dist/compiler/ast.d.ts +23 -0
- package/dist/compiler/ast.js +149 -0
- package/dist/compiler/ast.js.map +1 -0
- package/dist/compiler/compile.d.ts +41 -0
- package/dist/compiler/compile.js +148 -0
- package/dist/compiler/compile.js.map +1 -0
- package/dist/compiler/component-entries.d.ts +7 -0
- package/dist/compiler/component-entries.js +42 -0
- package/dist/compiler/component-entries.js.map +1 -0
- package/dist/compiler/components.d.ts +4 -0
- package/dist/compiler/components.js +182 -0
- package/dist/compiler/components.js.map +1 -0
- package/dist/compiler/facts.d.ts +31 -0
- package/dist/compiler/facts.js +285 -0
- package/dist/compiler/facts.js.map +1 -0
- package/dist/compiler/features.d.ts +34 -0
- package/dist/compiler/features.js +158 -0
- package/dist/compiler/features.js.map +1 -0
- package/dist/compiler/hooks.d.ts +22 -0
- package/dist/compiler/hooks.js +241 -0
- package/dist/compiler/hooks.js.map +1 -0
- package/dist/compiler/loader-source.d.ts +14 -0
- package/dist/compiler/loader-source.js +86 -0
- package/dist/compiler/loader-source.js.map +1 -0
- package/dist/compiler/locate.d.ts +14 -0
- package/dist/compiler/locate.js +78 -0
- package/dist/compiler/locate.js.map +1 -0
- package/dist/compiler/parse5-check.d.ts +21 -0
- package/dist/compiler/parse5-check.js +60 -0
- package/dist/compiler/parse5-check.js.map +1 -0
- package/dist/compiler/prop-schemas.d.ts +4 -0
- package/dist/compiler/prop-schemas.js +108 -0
- package/dist/compiler/prop-schemas.js.map +1 -0
- package/dist/compiler/scan.d.ts +41 -0
- package/dist/compiler/scan.js +160 -0
- package/dist/compiler/scan.js.map +1 -0
- package/dist/compiler/scope.d.ts +8 -0
- package/dist/compiler/scope.js +116 -0
- package/dist/compiler/scope.js.map +1 -0
- package/dist/compiler/source.d.ts +34 -0
- package/dist/compiler/source.js +114 -0
- package/dist/compiler/source.js.map +1 -0
- package/dist/compiler/tag-map.d.ts +41 -0
- package/dist/compiler/tag-map.js +126 -0
- package/dist/compiler/tag-map.js.map +1 -0
- package/dist/components-ready.d.ts +7 -0
- package/dist/components-ready.js +19 -0
- package/dist/components-ready.js.map +1 -0
- package/dist/define.d.ts +13 -4
- package/dist/define.js +35 -331
- package/dist/define.js.map +1 -1
- package/dist/devtools-events.d.ts +13 -0
- package/dist/devtools-events.js.map +1 -1
- package/dist/devtools-off.d.ts +2 -0
- package/dist/devtools-off.js +2 -0
- package/dist/devtools-off.js.map +1 -1
- package/dist/devtools.d.ts +4 -0
- package/dist/devtools.js +17 -2
- package/dist/devtools.js.map +1 -1
- package/dist/drivers-scope.d.ts +1 -1
- package/dist/drivers-scope.js +1 -8
- package/dist/drivers-scope.js.map +1 -1
- package/dist/element-internals.d.ts +1 -0
- package/dist/element-internals.js +11 -0
- package/dist/element-internals.js.map +1 -0
- package/dist/element-types.d.ts +11 -5
- package/dist/element-types.js.map +1 -1
- package/dist/element.d.ts +3 -0
- package/dist/element.js +322 -0
- package/dist/element.js.map +1 -0
- package/dist/error-view.d.ts +10 -0
- package/dist/error-view.js +30 -0
- package/dist/error-view.js.map +1 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.js +47 -0
- package/dist/errors.js.map +1 -0
- package/dist/errors.json +289 -0
- package/dist/eslint/imports.d.ts +26 -0
- package/dist/eslint/imports.js +78 -0
- package/dist/eslint/imports.js.map +1 -0
- package/dist/eslint/index.d.ts +16 -0
- package/dist/eslint/index.js +23 -0
- package/dist/eslint/index.js.map +1 -0
- package/dist/eslint/locate.d.ts +33 -0
- package/dist/eslint/locate.js +132 -0
- package/dist/eslint/locate.js.map +1 -0
- package/dist/eslint/row-purity-rule.d.ts +2 -0
- package/dist/eslint/row-purity-rule.js +103 -0
- package/dist/eslint/row-purity-rule.js.map +1 -0
- package/dist/eslint/template-rule.d.ts +6 -0
- package/dist/eslint/template-rule.js +76 -0
- package/dist/eslint/template-rule.js.map +1 -0
- package/dist/eslint/unused-intent-rule.d.ts +2 -0
- package/dist/eslint/unused-intent-rule.js +186 -0
- package/dist/eslint/unused-intent-rule.js.map +1 -0
- package/dist/features.d.ts +39 -0
- package/dist/features.js +2 -0
- package/dist/features.js.map +1 -0
- package/dist/focus.d.ts +13 -12
- package/dist/focus.js +44 -11
- package/dist/focus.js.map +1 -1
- package/dist/form-associated.d.ts +46 -0
- package/dist/form-associated.js +77 -0
- package/dist/form-associated.js.map +1 -0
- package/dist/forms.d.ts +42 -30
- package/dist/forms.js +85 -41
- package/dist/forms.js.map +1 -1
- package/dist/frame-lane.d.ts +11 -0
- package/dist/frame-lane.js +28 -0
- package/dist/frame-lane.js.map +1 -0
- package/dist/head.d.ts +61 -0
- package/dist/head.js +85 -0
- package/dist/head.js.map +1 -0
- package/dist/hooks/invalid.d.ts +14 -0
- package/dist/hooks/invalid.js +72 -0
- package/dist/hooks/invalid.js.map +1 -0
- package/dist/host-model.d.ts +77 -0
- package/dist/host-model.js +278 -0
- package/dist/host-model.js.map +1 -0
- package/dist/hydration-client.d.ts +9 -0
- package/dist/hydration-client.js +35 -0
- package/dist/hydration-client.js.map +1 -0
- package/dist/hydration-loader.d.ts +13 -0
- package/dist/hydration-loader.js +58 -0
- package/dist/hydration-loader.js.map +1 -0
- package/dist/hydration-off.d.ts +8 -0
- package/dist/hydration-off.js +25 -0
- package/dist/hydration-off.js.map +1 -0
- package/dist/hydration.d.ts +3 -21
- package/dist/hydration.js +14 -63
- package/dist/hydration.js.map +1 -1
- package/dist/index.d.ts +24 -36
- package/dist/index.js +14 -32
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-types.d.ts +97 -0
- package/dist/indexeddb-types.js +2 -0
- package/dist/indexeddb-types.js.map +1 -0
- package/dist/indexeddb.d.ts +5 -0
- package/dist/indexeddb.js +118 -0
- package/dist/indexeddb.js.map +1 -0
- package/dist/intent.d.ts +62 -17
- package/dist/intent.js +193 -100
- package/dist/intent.js.map +1 -1
- package/dist/internal/indexeddb-open.d.ts +8 -0
- package/dist/internal/indexeddb-open.js +96 -0
- package/dist/internal/indexeddb-open.js.map +1 -0
- package/dist/internal/indexeddb-transaction.d.ts +4 -0
- package/dist/internal/indexeddb-transaction.js +134 -0
- package/dist/internal/indexeddb-transaction.js.map +1 -0
- package/dist/internal/interpreter.d.ts +15 -1
- package/dist/internal/interpreter.js +42 -47
- package/dist/internal/interpreter.js.map +1 -1
- package/dist/internal/token.d.ts +1 -0
- package/dist/internal/token.js +7 -0
- package/dist/internal/token.js.map +1 -0
- package/dist/internal.d.ts +20 -0
- package/dist/internal.js +22 -0
- package/dist/internal.js.map +1 -0
- package/dist/invoker-fallback-used.d.ts +4 -0
- package/dist/invoker-fallback-used.js +10 -0
- package/dist/invoker-fallback-used.js.map +1 -0
- package/dist/invoker-fallback.d.ts +4 -0
- package/dist/invoker-fallback.js +15 -0
- package/dist/invoker-fallback.js.map +1 -0
- package/dist/invokers-shim.d.ts +6 -0
- package/dist/invokers-shim.js +32 -0
- package/dist/invokers-shim.js.map +1 -0
- package/dist/invokers.d.ts +3 -5
- package/dist/invokers.js +11 -51
- package/dist/invokers.js.map +1 -1
- package/dist/islands.d.ts +0 -2
- package/dist/islands.js +4 -11
- package/dist/islands.js.map +1 -1
- package/dist/light-dom.d.ts +4 -53
- package/dist/light-dom.js +5 -100
- package/dist/light-dom.js.map +1 -1
- package/dist/prop.d.ts +89 -0
- package/dist/prop.js +41 -0
- package/dist/prop.js.map +1 -0
- package/dist/props.d.ts +57 -21
- package/dist/props.js +157 -34
- package/dist/props.js.map +1 -1
- package/dist/retry.d.ts +15 -0
- package/dist/retry.js +48 -0
- package/dist/retry.js.map +1 -0
- package/dist/scheduler.d.ts +43 -0
- package/dist/scheduler.js +212 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/script-json.d.ts +2 -0
- package/dist/script-json.js +13 -0
- package/dist/script-json.js.map +1 -0
- package/dist/server-component.d.ts +10 -0
- package/dist/server-component.js +133 -0
- package/dist/server-component.js.map +1 -0
- package/dist/server-specs.d.ts +6 -0
- package/dist/server-specs.js +13 -0
- package/dist/server-specs.js.map +1 -0
- package/dist/server.d.ts +34 -0
- package/dist/server.js +59 -0
- package/dist/server.js.map +1 -0
- package/dist/settled.d.ts +11 -0
- package/dist/settled.js +62 -0
- package/dist/settled.js.map +1 -0
- package/dist/spec-features-used.d.ts +21 -0
- package/dist/spec-features-used.js +50 -0
- package/dist/spec-features-used.js.map +1 -0
- package/dist/spec-features.d.ts +28 -0
- package/dist/spec-features.js +42 -0
- package/dist/spec-features.js.map +1 -0
- package/dist/states.d.ts +3 -5
- package/dist/states.js +22 -11
- package/dist/states.js.map +1 -1
- package/dist/storage.d.ts +69 -0
- package/dist/storage.js +158 -0
- package/dist/storage.js.map +1 -0
- package/dist/store-binding.d.ts +6 -3
- package/dist/store-binding.js +7 -8
- package/dist/store-binding.js.map +1 -1
- package/dist/store-scope.d.ts +8 -11
- package/dist/store-scope.js +15 -40
- package/dist/store-scope.js.map +1 -1
- package/dist/store.d.ts +3 -0
- package/dist/store.js +45 -10
- package/dist/store.js.map +1 -1
- package/dist/stores-provider.d.ts +2 -6
- package/dist/stores-provider.js +21 -55
- package/dist/stores-provider.js.map +1 -1
- package/dist/subscription.d.ts +35 -0
- package/dist/subscription.js +74 -0
- package/dist/subscription.js.map +1 -0
- package/dist/subscriptions.d.ts +26 -0
- package/dist/subscriptions.js +98 -0
- package/dist/subscriptions.js.map +1 -0
- package/dist/transitions.d.ts +5 -7
- package/dist/transitions.js +17 -20
- package/dist/transitions.js.map +1 -1
- package/dist/types.d.ts +142 -49
- package/dist/types.js.map +1 -1
- package/dist/use-dialogs.d.ts +2 -0
- package/dist/use-dialogs.js +9 -0
- package/dist/use-dialogs.js.map +1 -0
- package/dist/use-disposal.d.ts +2 -0
- package/dist/use-disposal.js +9 -0
- package/dist/use-disposal.js.map +1 -0
- package/dist/use-error-view.d.ts +2 -0
- package/dist/use-error-view.js +9 -0
- package/dist/use-error-view.js.map +1 -0
- package/dist/use-errored.d.ts +2 -0
- package/dist/use-errored.js +9 -0
- package/dist/use-errored.js.map +1 -0
- package/dist/use-form-associated.d.ts +2 -0
- package/dist/use-form-associated.js +7 -0
- package/dist/use-form-associated.js.map +1 -0
- package/dist/use-frame-lane.d.ts +2 -0
- package/dist/use-frame-lane.js +10 -0
- package/dist/use-frame-lane.js.map +1 -0
- package/dist/use-invokers.d.ts +2 -0
- package/dist/use-invokers.js +10 -0
- package/dist/use-invokers.js.map +1 -0
- package/dist/use-states.d.ts +2 -0
- package/dist/use-states.js +10 -0
- package/dist/use-states.js.map +1 -0
- package/dist/use-subscriptions.d.ts +2 -0
- package/dist/use-subscriptions.js +10 -0
- package/dist/use-subscriptions.js.map +1 -0
- package/dist/use-transitions.d.ts +2 -0
- package/dist/use-transitions.js +10 -0
- package/dist/use-transitions.js.map +1 -0
- package/dist/view/attributes.d.ts +11 -0
- package/dist/view/attributes.js +15 -0
- package/dist/view/attributes.js.map +1 -0
- package/dist/view/compiled.d.ts +1 -0
- package/dist/view/compiled.js +6 -0
- package/dist/view/compiled.js.map +1 -0
- package/dist/view/dev-off.d.ts +1 -0
- package/dist/view/dev-off.js +4 -0
- package/dist/view/dev-off.js.map +1 -0
- package/dist/view/dev.d.ts +1 -0
- package/dist/view/dev.js +5 -0
- package/dist/view/dev.js.map +1 -0
- package/dist/view/flags.d.ts +1 -0
- package/dist/view/flags.js +4 -0
- package/dist/view/flags.js.map +1 -0
- package/dist/view/index.d.ts +26 -0
- package/dist/view/index.js +27 -0
- package/dist/view/index.js.map +1 -0
- package/dist/view/loc.d.ts +9 -0
- package/dist/view/loc.js +50 -0
- package/dist/view/loc.js.map +1 -0
- package/dist/view/message.d.ts +17 -0
- package/dist/view/message.js +40 -0
- package/dist/view/message.js.map +1 -0
- package/dist/view/messages.d.ts +43 -0
- package/dist/view/messages.js +84 -0
- package/dist/view/messages.js.map +1 -0
- package/dist/view/normalize/check.d.ts +23 -0
- package/dist/view/normalize/check.js +81 -0
- package/dist/view/normalize/check.js.map +1 -0
- package/dist/view/normalize/emit.d.ts +15 -0
- package/dist/view/normalize/emit.js +165 -0
- package/dist/view/normalize/emit.js.map +1 -0
- package/dist/view/normalize/entities.d.ts +4 -0
- package/dist/view/normalize/entities.js +38 -0
- package/dist/view/normalize/entities.js.map +1 -0
- package/dist/view/normalize/errors.d.ts +9 -0
- package/dist/view/normalize/errors.js +19 -0
- package/dist/view/normalize/errors.js.map +1 -0
- package/dist/view/normalize/id.d.ts +10 -0
- package/dist/view/normalize/id.js +55 -0
- package/dist/view/normalize/id.js.map +1 -0
- package/dist/view/normalize/normalize.d.ts +18 -0
- package/dist/view/normalize/normalize.js +42 -0
- package/dist/view/normalize/normalize.js.map +1 -0
- package/dist/view/normalize/repairs.d.ts +24 -0
- package/dist/view/normalize/repairs.js +166 -0
- package/dist/view/normalize/repairs.js.map +1 -0
- package/dist/view/normalize/rules.d.ts +39 -0
- package/dist/view/normalize/rules.js +120 -0
- package/dist/view/normalize/rules.js.map +1 -0
- package/dist/view/normalize/shape.d.ts +5 -0
- package/dist/view/normalize/shape.js +38 -0
- package/dist/view/normalize/shape.js.map +1 -0
- package/dist/view/normalize/source.d.ts +13 -0
- package/dist/view/normalize/source.js +34 -0
- package/dist/view/normalize/source.js.map +1 -0
- package/dist/view/normalize/svg.d.ts +14 -0
- package/dist/view/normalize/svg.js +40 -0
- package/dist/view/normalize/svg.js.map +1 -0
- package/dist/view/normalize/tag-states.d.ts +23 -0
- package/dist/view/normalize/tag-states.js +192 -0
- package/dist/view/normalize/tag-states.js.map +1 -0
- package/dist/view/normalize/tokenizer.d.ts +5 -0
- package/dist/view/normalize/tokenizer.js +233 -0
- package/dist/view/normalize/tokenizer.js.map +1 -0
- package/dist/view/normalize/tokens.d.ts +55 -0
- package/dist/view/normalize/tokens.js +24 -0
- package/dist/view/normalize/tokens.js.map +1 -0
- package/dist/view/normalize/tree.d.ts +65 -0
- package/dist/view/normalize/tree.js +235 -0
- package/dist/view/normalize/tree.js.map +1 -0
- package/dist/view/normalize/types.d.ts +146 -0
- package/dist/view/normalize/types.js +29 -0
- package/dist/view/normalize/types.js.map +1 -0
- package/dist/view/normalize/whitespace.d.ts +2 -0
- package/dist/{template-whitespace.js → view/normalize/whitespace.js} +27 -36
- package/dist/view/normalize/whitespace.js.map +1 -0
- package/dist/view/prepare-stub.d.ts +3 -0
- package/dist/view/prepare-stub.js +7 -0
- package/dist/view/prepare-stub.js.map +1 -0
- package/dist/view/prepare.d.ts +11 -0
- package/dist/view/prepare.js +63 -0
- package/dist/view/prepare.js.map +1 -0
- package/dist/view/registry.d.ts +78 -0
- package/dist/view/registry.js +27 -0
- package/dist/view/registry.js.map +1 -0
- package/dist/view/render/adopt-attr.d.ts +14 -0
- package/dist/view/render/adopt-attr.js +83 -0
- package/dist/view/render/adopt-attr.js.map +1 -0
- package/dist/view/render/adopt-plan.d.ts +10 -0
- package/dist/view/render/adopt-plan.js +26 -0
- package/dist/view/render/adopt-plan.js.map +1 -0
- package/dist/view/render/adopt.d.ts +3 -0
- package/dist/view/render/adopt.js +286 -0
- package/dist/view/render/adopt.js.map +1 -0
- package/dist/view/render/attr-parts.d.ts +72 -0
- package/dist/view/render/attr-parts.js +262 -0
- package/dist/view/render/attr-parts.js.map +1 -0
- package/dist/view/render/child-part.d.ts +51 -0
- package/dist/view/render/child-part.js +173 -0
- package/dist/view/render/child-part.js.map +1 -0
- package/dist/view/render/dev-check.d.ts +12 -0
- package/dist/view/render/dev-check.js +122 -0
- package/dist/view/render/dev-check.js.map +1 -0
- package/dist/view/render/dispose.d.ts +3 -0
- package/dist/view/render/dispose.js +76 -0
- package/dist/view/render/dispose.js.map +1 -0
- package/dist/view/render/hook-part.d.ts +5 -0
- package/dist/view/render/hook-part.js +36 -0
- package/dist/view/render/hook-part.js.map +1 -0
- package/dist/view/render/hook-run.d.ts +2 -0
- package/dist/view/render/hook-run.js +72 -0
- package/dist/view/render/hook-run.js.map +1 -0
- package/dist/view/render/hooks.d.ts +108 -0
- package/dist/view/render/hooks.js +108 -0
- package/dist/view/render/hooks.js.map +1 -0
- package/dist/view/render/hydrate.d.ts +10 -0
- package/dist/view/render/hydrate.js +33 -0
- package/dist/view/render/hydrate.js.map +1 -0
- package/dist/view/render/instance.d.ts +33 -0
- package/dist/view/render/instance.js +107 -0
- package/dist/view/render/instance.js.map +1 -0
- package/dist/view/render/keyed.d.ts +6 -0
- package/dist/view/render/keyed.js +15 -0
- package/dist/view/render/keyed.js.map +1 -0
- package/dist/view/render/list.d.ts +20 -0
- package/dist/view/render/list.js +156 -0
- package/dist/view/render/list.js.map +1 -0
- package/dist/view/render/mismatch.d.ts +10 -0
- package/dist/view/render/mismatch.js +55 -0
- package/dist/view/render/mismatch.js.map +1 -0
- package/dist/view/render/modal.d.ts +3 -0
- package/dist/view/render/modal.js +39 -0
- package/dist/view/render/modal.js.map +1 -0
- package/dist/view/render/nodes.d.ts +10 -0
- package/dist/view/render/nodes.js +37 -0
- package/dist/view/render/nodes.js.map +1 -0
- package/dist/view/render/place.d.ts +18 -0
- package/dist/view/render/place.js +69 -0
- package/dist/view/render/place.js.map +1 -0
- package/dist/view/render/plan.d.ts +26 -0
- package/dist/view/render/plan.js +124 -0
- package/dist/view/render/plan.js.map +1 -0
- package/dist/view/render/raw.d.ts +21 -0
- package/dist/view/render/raw.js +72 -0
- package/dist/view/render/raw.js.map +1 -0
- package/dist/view/render/render.d.ts +15 -0
- package/dist/view/render/render.js +65 -0
- package/dist/view/render/render.js.map +1 -0
- package/dist/view/render/reorder.d.ts +4 -0
- package/dist/view/render/reorder.js +101 -0
- package/dist/view/render/reorder.js.map +1 -0
- package/dist/view/render/rows.d.ts +23 -0
- package/dist/view/render/rows.js +95 -0
- package/dist/view/render/rows.js.map +1 -0
- package/dist/view/render/seen.d.ts +11 -0
- package/dist/view/render/seen.js +17 -0
- package/dist/view/render/seen.js.map +1 -0
- package/dist/view/render/toggles.d.ts +6 -0
- package/dist/view/render/toggles.js +6 -0
- package/dist/view/render/toggles.js.map +1 -0
- package/dist/view/render/values.d.ts +29 -0
- package/dist/view/render/values.js +13 -0
- package/dist/view/render/values.js.map +1 -0
- package/dist/view/render/warn.d.ts +28 -0
- package/dist/view/render/warn.js +114 -0
- package/dist/view/render/warn.js.map +1 -0
- package/dist/view/server/component.d.ts +12 -0
- package/dist/view/server/component.js +64 -0
- package/dist/view/server/component.js.map +1 -0
- package/dist/view/server/escape.d.ts +10 -0
- package/dist/view/server/escape.js +34 -0
- package/dist/view/server/escape.js.map +1 -0
- package/dist/view/server/index.d.ts +48 -0
- package/dist/view/server/index.js +80 -0
- package/dist/view/server/index.js.map +1 -0
- package/dist/view/server/sha256.d.ts +2 -0
- package/dist/view/server/sha256.js +75 -0
- package/dist/view/server/sha256.js.map +1 -0
- package/dist/view/server/tags.d.ts +68 -0
- package/dist/view/server/tags.js +132 -0
- package/dist/view/server/tags.js.map +1 -0
- package/dist/view/server/values.d.ts +18 -0
- package/dist/view/server/values.js +94 -0
- package/dist/view/server/values.js.map +1 -0
- package/dist/view/server/writer.d.ts +21 -0
- package/dist/view/server/writer.js +170 -0
- package/dist/view/server/writer.js.map +1 -0
- package/dist/view/styles.d.ts +25 -0
- package/dist/view/styles.js +58 -0
- package/dist/view/styles.js.map +1 -0
- package/dist/view/template-element.d.ts +10 -0
- package/dist/view/template-element.js +45 -0
- package/dist/view/template-element.js.map +1 -0
- package/dist/view/template.d.ts +29 -0
- package/dist/view/template.js +84 -0
- package/dist/view/template.js.map +1 -0
- package/dist/view/trusted-html.d.ts +6 -0
- package/dist/view/trusted-html.js +34 -0
- package/dist/view/trusted-html.js.map +1 -0
- package/dist/vite.d.ts +57 -11
- package/dist/vite.js +319 -27
- package/dist/vite.js.map +1 -1
- package/package.json +70 -4
- package/dist/accessible-name.d.ts +0 -19
- package/dist/accessible-name.js +0 -56
- package/dist/accessible-name.js.map +0 -1
- package/dist/element-directive.d.ts +0 -20
- package/dist/element-directive.js +0 -31
- package/dist/element-directive.js.map +0 -1
- package/dist/invalid.d.ts +0 -21
- package/dist/invalid.js +0 -70
- package/dist/invalid.js.map +0 -1
- package/dist/lit-html-check.d.ts +0 -6
- package/dist/lit-html-check.js +0 -48
- package/dist/lit-html-check.js.map +0 -1
- package/dist/live-boolean.d.ts +0 -22
- package/dist/live-boolean.js +0 -34
- package/dist/live-boolean.js.map +0 -1
- package/dist/random.d.ts +0 -13
- package/dist/random.js +0 -19
- package/dist/random.js.map +0 -1
- package/dist/styles.d.ts +0 -12
- package/dist/styles.js +0 -11
- package/dist/styles.js.map +0 -1
- package/dist/template-whitespace.d.ts +0 -7
- package/dist/template-whitespace.js.map +0 -1
- package/dist/templates.d.ts +0 -5
- package/dist/templates.js +0 -15
- package/dist/templates.js.map +0 -1
- package/dist/textarea.d.ts +0 -26
- package/dist/textarea.js +0 -85
- package/dist/textarea.js.map +0 -1
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// Tree builder for the normalizer (view/01-templates.md "Normalization"): turns the tokenizer's
|
|
2
|
+
// tokens into the tree the HTML parser builds for valid markup (WHATWG "tree construction":
|
|
3
|
+
// namespaces, void elements, raw text, the leading newline of <pre>/<listing>/<textarea>), so
|
|
4
|
+
// part paths match the browser's DOM. Markup the parser would repair is an error instead of
|
|
5
|
+
// being modelled (rule 7, repairs.ts), as are rules 3, 4, 6, 10, 12 and 13. An svg template's
|
|
6
|
+
// top level is SVG content, as if inside an <svg> (01 "svg templates", svg.ts).
|
|
7
|
+
import { decodeRefs, unquote } from './entities.js';
|
|
8
|
+
import { breaksOutOfForeign, contextOf, rootContext, startRepair, textRepair, } from './repairs.js';
|
|
9
|
+
import { BOOLEAN_ATTRS, formStateFix, msg, SVG_ONLY, VOID } from './rules.js';
|
|
10
|
+
import { HTML_ONLY, namespacedAttr, SVG_HTML_POINT, svgAttr } from './svg.js';
|
|
11
|
+
const RAWTEXT = new Set('script style xmp iframe noembed noframes noscript plaintext'.split(' '));
|
|
12
|
+
const RCDATA = new Set(['textarea', 'title']);
|
|
13
|
+
const LEADING_NEWLINE = new Set(['pre', 'listing', 'textarea']);
|
|
14
|
+
const DOCUMENT = new Set(['html', 'head', 'body']);
|
|
15
|
+
function integrationPoint(el) {
|
|
16
|
+
if (el.ns === 'svg')
|
|
17
|
+
return SVG_HTML_POINT.test(el.name);
|
|
18
|
+
return el.ns === 'math' && /^(mi|mo|mn|ms|mtext)$/.test(el.name);
|
|
19
|
+
}
|
|
20
|
+
export class TreeBuilder {
|
|
21
|
+
/** `svg`: an svg template, whose top level is SVG content (01 "svg templates"). */
|
|
22
|
+
constructor(src, svg = false) {
|
|
23
|
+
this.src = src;
|
|
24
|
+
this.svg = svg;
|
|
25
|
+
this.root = [];
|
|
26
|
+
this.server = false;
|
|
27
|
+
this.stack = [];
|
|
28
|
+
}
|
|
29
|
+
get children() {
|
|
30
|
+
return this.stack.at(-1)?.children ?? this.root;
|
|
31
|
+
}
|
|
32
|
+
context() {
|
|
33
|
+
const top = this.stack.at(-1);
|
|
34
|
+
if (top === undefined)
|
|
35
|
+
return { ctx: this.rootCtx ?? 'body', atRoot: true };
|
|
36
|
+
if (top.ns !== 'html')
|
|
37
|
+
return { ctx: 'body', atRoot: false };
|
|
38
|
+
if (top.name === 'template')
|
|
39
|
+
return { ctx: top.inner ?? 'body', atRoot: true };
|
|
40
|
+
return { ctx: contextOf(top.name), atRoot: false };
|
|
41
|
+
}
|
|
42
|
+
inTemplate() {
|
|
43
|
+
return this.stack.some((el) => el.ns === 'html' && el.name === 'template');
|
|
44
|
+
}
|
|
45
|
+
text(raw) {
|
|
46
|
+
const text = this.fresh !== undefined && raw.startsWith('\n') ? raw.slice(1) : raw;
|
|
47
|
+
this.fresh = undefined;
|
|
48
|
+
if (text === '')
|
|
49
|
+
return;
|
|
50
|
+
const { ctx, atRoot } = this.context();
|
|
51
|
+
const repair = textRepair(text, ctx, atRoot);
|
|
52
|
+
if (repair !== undefined)
|
|
53
|
+
this.src.fail(7, repair);
|
|
54
|
+
this.children.push({ type: 'text', raw: text });
|
|
55
|
+
}
|
|
56
|
+
comment(raw) {
|
|
57
|
+
this.fresh = undefined;
|
|
58
|
+
this.children.push({ type: 'comment', raw });
|
|
59
|
+
}
|
|
60
|
+
doctype(raw) {
|
|
61
|
+
this.fresh = undefined;
|
|
62
|
+
if (this.svg)
|
|
63
|
+
this.src.fail(10, msg.htmlInSvg('!doctype', true));
|
|
64
|
+
this.server = true;
|
|
65
|
+
this.children.push({ type: 'doctype', raw });
|
|
66
|
+
}
|
|
67
|
+
hole(kind) {
|
|
68
|
+
this.fresh = undefined;
|
|
69
|
+
if (this.inTemplate())
|
|
70
|
+
this.src.fail(3, msg.inTemplate());
|
|
71
|
+
this.children.push({ type: 'hole', kind });
|
|
72
|
+
}
|
|
73
|
+
start(tag) {
|
|
74
|
+
this.fresh = undefined;
|
|
75
|
+
const { name } = tag;
|
|
76
|
+
const ns = this.namespace(tag);
|
|
77
|
+
if (ns === 'html')
|
|
78
|
+
this.checkHtml(tag);
|
|
79
|
+
if (this.inTemplate() && tag.attrs.some((a) => a.kind !== 'static')) {
|
|
80
|
+
this.src.fail(3, msg.inTemplate());
|
|
81
|
+
}
|
|
82
|
+
const empty = ns === 'html' ? VOID.has(name) : tag.selfClosing;
|
|
83
|
+
const custom = ns === 'html' && name.includes('-');
|
|
84
|
+
const el = {
|
|
85
|
+
type: 'el',
|
|
86
|
+
name,
|
|
87
|
+
raw: tag.raw,
|
|
88
|
+
ns,
|
|
89
|
+
attrs: this.attributes(tag, ns),
|
|
90
|
+
props: custom ? this.props(tag) : undefined,
|
|
91
|
+
empty,
|
|
92
|
+
children: [],
|
|
93
|
+
};
|
|
94
|
+
this.children.push(el);
|
|
95
|
+
if (empty)
|
|
96
|
+
return 'data';
|
|
97
|
+
this.stack.push(el);
|
|
98
|
+
if (ns !== 'html')
|
|
99
|
+
return 'data';
|
|
100
|
+
if (LEADING_NEWLINE.has(name))
|
|
101
|
+
this.fresh = el;
|
|
102
|
+
return RAWTEXT.has(name) ? 'rawtext' : RCDATA.has(name) ? 'rcdata' : 'data';
|
|
103
|
+
}
|
|
104
|
+
namespace(tag) {
|
|
105
|
+
const parent = this.stack.at(-1);
|
|
106
|
+
if (parent === undefined ? !this.svg : parent.ns === 'html' || integrationPoint(parent)) {
|
|
107
|
+
return tag.name === 'svg' ? 'svg' : tag.name === 'math' ? 'math' : 'html';
|
|
108
|
+
}
|
|
109
|
+
// An svg template's top level: SVG content, as inside the <svg> it renders in.
|
|
110
|
+
if (parent === undefined) {
|
|
111
|
+
const fontAttr = tag.attrs.some((a) => /^(color|face|size)$/i.test(a.name));
|
|
112
|
+
if (breaksOutOfForeign(tag.name, fontAttr) || HTML_ONLY.has(tag.name)) {
|
|
113
|
+
this.src.fail(10, msg.htmlInSvg(tag.raw, true));
|
|
114
|
+
}
|
|
115
|
+
return 'svg';
|
|
116
|
+
}
|
|
117
|
+
if (parent.name === 'annotation-xml' && tag.name === 'svg')
|
|
118
|
+
return 'svg';
|
|
119
|
+
if (parent.ns === 'svg' && HTML_ONLY.has(tag.name)) {
|
|
120
|
+
this.src.fail(10, msg.htmlInSvg(tag.raw, false));
|
|
121
|
+
}
|
|
122
|
+
const fontAttr = tag.attrs.some((a) => /^(color|face|size)$/i.test(a.name));
|
|
123
|
+
if (breaksOutOfForeign(tag.name, fontAttr)) {
|
|
124
|
+
this.src.fail(7, msg.repaired(`<${tag.name}> inside <${parent.ns}> ends the <${parent.ns}> element`, `Put HTML inside <foreignObject>, or move it out of the <${parent.ns}>.`));
|
|
125
|
+
}
|
|
126
|
+
return parent.ns;
|
|
127
|
+
}
|
|
128
|
+
checkHtml(tag) {
|
|
129
|
+
const { name } = tag;
|
|
130
|
+
if (SVG_ONLY.has(name))
|
|
131
|
+
this.src.fail(10, msg.svgOnly(tag.raw));
|
|
132
|
+
if (DOCUMENT.has(name))
|
|
133
|
+
this.server = true;
|
|
134
|
+
if (tag.selfClosing && !VOID.has(name))
|
|
135
|
+
this.src.fail(6, msg.selfClosing(tag.raw));
|
|
136
|
+
const top = this.stack.at(-1);
|
|
137
|
+
if (top === undefined)
|
|
138
|
+
this.rootCtx ??= rootContext(name);
|
|
139
|
+
else if (top.ns === 'html' && top.name === 'template')
|
|
140
|
+
top.inner ??= rootContext(name);
|
|
141
|
+
const { ctx, atRoot } = this.context();
|
|
142
|
+
const hidden = tag.attrs.some((a) => a.kind === 'static' &&
|
|
143
|
+
a.name.toLowerCase() === 'type' &&
|
|
144
|
+
/^["']?hidden["']?$/i.test(a.value ?? ''));
|
|
145
|
+
const repair = startRepair(name, ctx, atRoot, this.stack, hidden);
|
|
146
|
+
if (repair !== undefined)
|
|
147
|
+
this.src.fail(7, repair);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Bound names as the parser spells them (not properties): lower case on HTML elements, SVG's
|
|
151
|
+
* camelCase on SVG elements (svg.ts); rules 4, 7 (duplicates), 10 (namespaced), 13, 14 (boolean attributes). A
|
|
152
|
+
* static `style` gets its decoded value (`css`): the client applies it as a part (emit.ts).
|
|
153
|
+
*/
|
|
154
|
+
attributes(tag, ns) {
|
|
155
|
+
const seen = new Set();
|
|
156
|
+
// A nested <template>'s content is out of the parts' reach: its static styles stay.
|
|
157
|
+
const reach = !this.inTemplate();
|
|
158
|
+
return tag.attrs.map((a) => {
|
|
159
|
+
const name = a.kind === 'prop' || ns === 'math'
|
|
160
|
+
? a.name
|
|
161
|
+
: ns === 'html'
|
|
162
|
+
? a.name.toLowerCase()
|
|
163
|
+
: svgAttr(a.name);
|
|
164
|
+
if (a.kind === 'prop' && ns === 'html') {
|
|
165
|
+
const fix = formStateFix(tag.name, a.name);
|
|
166
|
+
if (fix !== undefined)
|
|
167
|
+
this.src.fail(4, msg.formState(tag.name, a.name, fix));
|
|
168
|
+
}
|
|
169
|
+
// Dialog and popover state is bound with `?`, on the element that can open (02).
|
|
170
|
+
if (ns === 'html' && (name === 'modal' || name === 'popover-open') && a.kind !== 'prop') {
|
|
171
|
+
const fits = name === 'modal'
|
|
172
|
+
? tag.name === 'dialog'
|
|
173
|
+
: tag.attrs.some((b) => b.name.toLowerCase() === 'popover');
|
|
174
|
+
if (a.kind !== 'bool' || !fits)
|
|
175
|
+
this.src.fail(4, msg.toggle(tag.name, name));
|
|
176
|
+
}
|
|
177
|
+
if (a.kind === 'attr' &&
|
|
178
|
+
ns === 'html' &&
|
|
179
|
+
!tag.name.includes('-') &&
|
|
180
|
+
BOOLEAN_ATTRS.has(name)) {
|
|
181
|
+
this.src.fail(14, msg.booleanAttr(tag.name, name));
|
|
182
|
+
}
|
|
183
|
+
if ((a.kind === 'attr' || a.kind === 'bool') && ns !== 'html' && namespacedAttr(a.name)) {
|
|
184
|
+
this.src.fail(10, msg.namespacedAttr(a.name));
|
|
185
|
+
}
|
|
186
|
+
if (a.kind !== 'prop' && a.kind !== 'hook') {
|
|
187
|
+
const key = ns === 'math' ? a.name : a.name.toLowerCase();
|
|
188
|
+
if (seen.has(key)) {
|
|
189
|
+
this.src.fail(7, msg.repaired(`${key} appears twice on <${tag.raw}>, and the parser keeps only the first`, `Write it once; to mix static and dynamic text, quote one value: ${key}="a \${…}".`));
|
|
190
|
+
}
|
|
191
|
+
seen.add(key);
|
|
192
|
+
}
|
|
193
|
+
if (a.kind === 'static') {
|
|
194
|
+
if (!reach || a.name.toLowerCase() !== 'style')
|
|
195
|
+
return a;
|
|
196
|
+
return { ...a, css: a.value === null ? '' : this.decode(unquote(a.value)) };
|
|
197
|
+
}
|
|
198
|
+
const strings = a.strings?.map((s) => this.decode(s));
|
|
199
|
+
return strings === undefined ? { kind: a.kind, name } : { kind: a.kind, name, strings };
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
props(tag) {
|
|
203
|
+
return tag.attrs.flatMap((a) => a.kind === 'static'
|
|
204
|
+
? [[a.name.toLowerCase(), a.value === null ? '' : this.decode(unquote(a.value))]]
|
|
205
|
+
: []);
|
|
206
|
+
}
|
|
207
|
+
decode(raw) {
|
|
208
|
+
return decodeRefs(raw, (ref) => this.src.fail(13, msg.charRef(ref)));
|
|
209
|
+
}
|
|
210
|
+
end(name) {
|
|
211
|
+
this.fresh = undefined;
|
|
212
|
+
const top = this.stack.at(-1);
|
|
213
|
+
if (top?.name === name) {
|
|
214
|
+
this.close(top);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (VOID.has(name) && name !== 'br')
|
|
218
|
+
return; // ignored by the parser
|
|
219
|
+
const open = this.stack.some((el) => el.name === name);
|
|
220
|
+
this.src.fail(7, open && top !== undefined
|
|
221
|
+
? msg.repaired(`</${name}> while <${top.raw}> is still open`, `Close </${top.raw}> first (end tags must match their start tags).`)
|
|
222
|
+
: msg.repaired(`</${name}> has no matching start tag${name === 'br' || name === 'p' ? `, so the parser creates an empty <${name}>` : ''}`, name === 'br' ? 'Write <br>.' : 'Remove it.'));
|
|
223
|
+
}
|
|
224
|
+
close(el) {
|
|
225
|
+
this.stack.pop();
|
|
226
|
+
const hasText = el.children.some((c) => c.type === 'hole' && c.kind === 'text');
|
|
227
|
+
if (hasText && el.children.length !== 1)
|
|
228
|
+
this.src.fail(12, msg.textContent(el.raw));
|
|
229
|
+
}
|
|
230
|
+
finish() {
|
|
231
|
+
for (let el = this.stack.at(-1); el !== undefined; el = this.stack.at(-1))
|
|
232
|
+
this.close(el);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.js","sourceRoot":"","sources":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I,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QACjB,MAAM,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;QAChF,IAAI,OAAO,IAAI,EAAE,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACtF,CAAC;IAED,MAAM;QACJ,KAAK,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,SAAS,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC5F,CAAC;CACF","sourcesContent":["// Tree builder for the normalizer (view/01-templates.md \"Normalization\"): turns the tokenizer's\n// tokens into the tree the HTML parser builds for valid markup (WHATWG \"tree construction\":\n// namespaces, void elements, raw text, the leading newline of <pre>/<listing>/<textarea>), so\n// part paths match the browser's DOM. Markup the parser would repair is an error instead of\n// being modelled (rule 7, repairs.ts), as are rules 3, 4, 6, 10, 12 and 13. An svg template's\n// top level is SVG content, as if inside an <svg> (01 \"svg templates\", svg.ts).\nimport { decodeRefs, unquote } from './entities.js';\nimport {\n breaksOutOfForeign,\n contextOf,\n rootContext,\n startRepair,\n textRepair,\n type Context,\n type Ns,\n} from './repairs.js';\nimport { BOOLEAN_ATTRS, formStateFix, msg, SVG_ONLY, VOID } from './rules.js';\nimport type { Source } from './source.js';\nimport { HTML_ONLY, namespacedAttr, SVG_HTML_POINT, svgAttr } from './svg.js';\nimport type { AttrToken, ContentMode, Sink, StartTag } from './tokenizer.js';\n\nexport interface ElementNode {\n readonly type: 'el';\n /** Lower-case name, and the name as written. */\n readonly name: string;\n readonly raw: string;\n readonly ns: Ns;\n /** Static and bound attributes; bound names normalized, multi strings decoded. */\n readonly attrs: readonly AttrToken[];\n /** A custom element's static attributes, decoded (server props); undefined otherwise. */\n readonly props: readonly (readonly [string, string])[] | undefined;\n /** No end tag: a void element, or a self-closed SVG/MathML element. */\n readonly empty: boolean;\n readonly children: TreeNode[];\n /** For <template>: the context its first start tag chose. */\n inner?: Context;\n}\n\nexport type TreeNode =\n | ElementNode\n | { readonly type: 'text'; readonly raw: string }\n | { readonly type: 'comment'; readonly raw: string }\n | { readonly type: 'doctype'; readonly raw: string }\n | { readonly type: 'hole'; readonly kind: 'child' | 'text' };\n\nconst RAWTEXT = new Set('script style xmp iframe noembed noframes noscript plaintext'.split(' '));\nconst RCDATA = new Set(['textarea', 'title']);\nconst LEADING_NEWLINE = new Set(['pre', 'listing', 'textarea']);\nconst DOCUMENT = new Set(['html', 'head', 'body']);\n\nfunction integrationPoint(el: ElementNode): boolean {\n if (el.ns === 'svg') return SVG_HTML_POINT.test(el.name);\n return el.ns === 'math' && /^(mi|mo|mn|ms|mtext)$/.test(el.name);\n}\n\nexport class TreeBuilder implements Sink {\n readonly root: TreeNode[] = [];\n server = false;\n private readonly stack: ElementNode[] = [];\n private rootCtx: Context | undefined;\n /** The <pre>/<listing>/<textarea> whose first newline the parser drops, if just opened. */\n private fresh: ElementNode | undefined;\n\n /** `svg`: an svg template, whose top level is SVG content (01 \"svg templates\"). */\n constructor(\n private readonly src: Source,\n private readonly svg = false,\n ) {}\n\n private get children(): TreeNode[] {\n return this.stack.at(-1)?.children ?? this.root;\n }\n\n private context(): { ctx: Context; atRoot: boolean } {\n const top = this.stack.at(-1);\n if (top === undefined) return { ctx: this.rootCtx ?? 'body', atRoot: true };\n if (top.ns !== 'html') return { ctx: 'body', atRoot: false };\n if (top.name === 'template') return { ctx: top.inner ?? 'body', atRoot: true };\n return { ctx: contextOf(top.name), atRoot: false };\n }\n\n private inTemplate(): boolean {\n return this.stack.some((el) => el.ns === 'html' && el.name === 'template');\n }\n\n text(raw: string): void {\n const text = this.fresh !== undefined && raw.startsWith('\\n') ? raw.slice(1) : raw;\n this.fresh = undefined;\n if (text === '') return;\n const { ctx, atRoot } = this.context();\n const repair = textRepair(text, ctx, atRoot);\n if (repair !== undefined) this.src.fail(7, repair);\n this.children.push({ type: 'text', raw: text });\n }\n\n comment(raw: string): void {\n this.fresh = undefined;\n this.children.push({ type: 'comment', raw });\n }\n\n doctype(raw: string): void {\n this.fresh = undefined;\n if (this.svg) this.src.fail(10, msg.htmlInSvg('!doctype', true));\n this.server = true;\n this.children.push({ type: 'doctype', raw });\n }\n\n hole(kind: 'child' | 'text'): void {\n this.fresh = undefined;\n if (this.inTemplate()) this.src.fail(3, msg.inTemplate());\n this.children.push({ type: 'hole', kind });\n }\n\n start(tag: StartTag): ContentMode {\n this.fresh = undefined;\n const { name } = tag;\n const ns = this.namespace(tag);\n if (ns === 'html') this.checkHtml(tag);\n if (this.inTemplate() && tag.attrs.some((a) => a.kind !== 'static')) {\n this.src.fail(3, msg.inTemplate());\n }\n const empty = ns === 'html' ? VOID.has(name) : tag.selfClosing;\n const custom = ns === 'html' && name.includes('-');\n const el: ElementNode = {\n type: 'el',\n name,\n raw: tag.raw,\n ns,\n attrs: this.attributes(tag, ns),\n props: custom ? this.props(tag) : undefined,\n empty,\n children: [],\n };\n this.children.push(el);\n if (empty) return 'data';\n this.stack.push(el);\n if (ns !== 'html') return 'data';\n if (LEADING_NEWLINE.has(name)) this.fresh = el;\n return RAWTEXT.has(name) ? 'rawtext' : RCDATA.has(name) ? 'rcdata' : 'data';\n }\n\n private namespace(tag: StartTag): Ns {\n const parent = this.stack.at(-1);\n if (parent === undefined ? !this.svg : parent.ns === 'html' || integrationPoint(parent)) {\n return tag.name === 'svg' ? 'svg' : tag.name === 'math' ? 'math' : 'html';\n }\n // An svg template's top level: SVG content, as inside the <svg> it renders in.\n if (parent === undefined) {\n const fontAttr = tag.attrs.some((a) => /^(color|face|size)$/i.test(a.name));\n if (breaksOutOfForeign(tag.name, fontAttr) || HTML_ONLY.has(tag.name)) {\n this.src.fail(10, msg.htmlInSvg(tag.raw, true));\n }\n return 'svg';\n }\n if (parent.name === 'annotation-xml' && tag.name === 'svg') return 'svg';\n if (parent.ns === 'svg' && HTML_ONLY.has(tag.name)) {\n this.src.fail(10, msg.htmlInSvg(tag.raw, false));\n }\n const fontAttr = tag.attrs.some((a) => /^(color|face|size)$/i.test(a.name));\n if (breaksOutOfForeign(tag.name, fontAttr)) {\n this.src.fail(\n 7,\n msg.repaired(\n `<${tag.name}> inside <${parent.ns}> ends the <${parent.ns}> element`,\n `Put HTML inside <foreignObject>, or move it out of the <${parent.ns}>.`,\n ),\n );\n }\n return parent.ns;\n }\n\n private checkHtml(tag: StartTag): void {\n const { name } = tag;\n if (SVG_ONLY.has(name)) this.src.fail(10, msg.svgOnly(tag.raw));\n if (DOCUMENT.has(name)) this.server = true;\n if (tag.selfClosing && !VOID.has(name)) this.src.fail(6, msg.selfClosing(tag.raw));\n const top = this.stack.at(-1);\n if (top === undefined) this.rootCtx ??= rootContext(name);\n else if (top.ns === 'html' && top.name === 'template') top.inner ??= rootContext(name);\n const { ctx, atRoot } = this.context();\n const hidden = tag.attrs.some(\n (a) =>\n a.kind === 'static' &&\n a.name.toLowerCase() === 'type' &&\n /^[\"']?hidden[\"']?$/i.test(a.value ?? ''),\n );\n const repair = startRepair(name, ctx, atRoot, this.stack, hidden);\n if (repair !== undefined) this.src.fail(7, repair);\n }\n\n /**\n * Bound names as the parser spells them (not properties): lower case on HTML elements, SVG's\n * camelCase on SVG elements (svg.ts); rules 4, 7 (duplicates), 10 (namespaced), 13, 14 (boolean attributes). A\n * static `style` gets its decoded value (`css`): the client applies it as a part (emit.ts).\n */\n private attributes(tag: StartTag, ns: Ns): AttrToken[] {\n const seen = new Set<string>();\n // A nested <template>'s content is out of the parts' reach: its static styles stay.\n const reach = !this.inTemplate();\n return tag.attrs.map((a) => {\n const name =\n a.kind === 'prop' || ns === 'math'\n ? a.name\n : ns === 'html'\n ? a.name.toLowerCase()\n : svgAttr(a.name);\n if (a.kind === 'prop' && ns === 'html') {\n const fix = formStateFix(tag.name, a.name);\n if (fix !== undefined) this.src.fail(4, msg.formState(tag.name, a.name, fix));\n }\n // Dialog and popover state is bound with `?`, on the element that can open (02).\n if (ns === 'html' && (name === 'modal' || name === 'popover-open') && a.kind !== 'prop') {\n const fits =\n name === 'modal'\n ? tag.name === 'dialog'\n : tag.attrs.some((b) => b.name.toLowerCase() === 'popover');\n if (a.kind !== 'bool' || !fits) this.src.fail(4, msg.toggle(tag.name, name));\n }\n if (\n a.kind === 'attr' &&\n ns === 'html' &&\n !tag.name.includes('-') &&\n BOOLEAN_ATTRS.has(name)\n ) {\n this.src.fail(14, msg.booleanAttr(tag.name, name));\n }\n if ((a.kind === 'attr' || a.kind === 'bool') && ns !== 'html' && namespacedAttr(a.name)) {\n this.src.fail(10, msg.namespacedAttr(a.name));\n }\n if (a.kind !== 'prop' && a.kind !== 'hook') {\n const key = ns === 'math' ? a.name : a.name.toLowerCase();\n if (seen.has(key)) {\n this.src.fail(\n 7,\n msg.repaired(\n `${key} appears twice on <${tag.raw}>, and the parser keeps only the first`,\n `Write it once; to mix static and dynamic text, quote one value: ${key}=\"a \\${…}\".`,\n ),\n );\n }\n seen.add(key);\n }\n if (a.kind === 'static') {\n if (!reach || a.name.toLowerCase() !== 'style') return a;\n return { ...a, css: a.value === null ? '' : this.decode(unquote(a.value)) };\n }\n const strings = a.strings?.map((s) => this.decode(s));\n return strings === undefined ? { kind: a.kind, name } : { kind: a.kind, name, strings };\n });\n }\n\n private props(tag: StartTag): [string, string][] {\n return tag.attrs.flatMap((a) =>\n a.kind === 'static'\n ? [[a.name.toLowerCase(), a.value === null ? '' : this.decode(unquote(a.value))]]\n : [],\n );\n }\n\n private decode(raw: string): string {\n return decodeRefs(raw, (ref) => this.src.fail(13, msg.charRef(ref)));\n }\n\n end(name: string): void {\n this.fresh = undefined;\n const top = this.stack.at(-1);\n if (top?.name === name) {\n this.close(top);\n return;\n }\n if (VOID.has(name) && name !== 'br') return; // ignored by the parser\n const open = this.stack.some((el) => el.name === name);\n this.src.fail(\n 7,\n open && top !== undefined\n ? msg.repaired(\n `</${name}> while <${top.raw}> is still open`,\n `Close </${top.raw}> first (end tags must match their start tags).`,\n )\n : msg.repaired(\n `</${name}> has no matching start tag${name === 'br' || name === 'p' ? `, so the parser creates an empty <${name}>` : ''}`,\n name === 'br' ? 'Write <br>.' : 'Remove it.',\n ),\n );\n }\n\n private close(el: ElementNode): void {\n this.stack.pop();\n const hasText = el.children.some((c) => c.type === 'hole' && c.kind === 'text');\n if (hasText && el.children.length !== 1) this.src.fail(12, msg.textContent(el.raw));\n }\n\n finish(): void {\n for (let el = this.stack.at(-1); el !== undefined; el = this.stack.at(-1)) this.close(el);\n }\n}\n"]}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/** Child-index path from the template's content root (`[]` is the root itself). */
|
|
2
|
+
export type Path = readonly number[];
|
|
3
|
+
/** `[CHILD_END, path]`: a child hole that inserts at the end of its parent. */
|
|
4
|
+
export declare const CHILD_END = 0;
|
|
5
|
+
/** `[CHILD_SOLE, path]`: a child hole that is its parent's only child node (so at its end). */
|
|
6
|
+
export declare const CHILD_SOLE = 1;
|
|
7
|
+
/** `[CHILD_BEFORE, path, ref]`: a child hole that inserts before the parent's child `ref`. */
|
|
8
|
+
export declare const CHILD_BEFORE = 2;
|
|
9
|
+
/** `[ATTR_PART, path, name]`: `name=${v}`. */
|
|
10
|
+
export declare const ATTR_PART = 3;
|
|
11
|
+
/**
|
|
12
|
+
* `[MULTI_PART, path, name, strings]`: `name="a ${x} b"`; with one string and no values, a
|
|
13
|
+
* static `style` attribute the client applies through the CSSOM (01 "Normalization").
|
|
14
|
+
*/
|
|
15
|
+
export declare const MULTI_PART = 4;
|
|
16
|
+
/** `[BOOL_PART, path, name]`: `?name=${v}`. */
|
|
17
|
+
export declare const BOOL_PART = 5;
|
|
18
|
+
/** `[PROP_PART, path, name]`: `.name=${v}`. */
|
|
19
|
+
export declare const PROP_PART = 6;
|
|
20
|
+
/** `[HOOK_PART, path]`: `${hook(…)}` in a start tag. */
|
|
21
|
+
export declare const HOOK_PART = 7;
|
|
22
|
+
/** `[TEXT_PART, path]`: the whole content of a `<textarea>` or `<title>`. */
|
|
23
|
+
export declare const TEXT_PART = 8;
|
|
24
|
+
/**
|
|
25
|
+
* One entry per binding, in source order: a tuple whose first entry is its kind (above), whose
|
|
26
|
+
* second is a path, then the kind's own fields. Multi-attributes take several values.
|
|
27
|
+
*
|
|
28
|
+
* - Child holes: `path` leads to the parent element (`[]`: the template root). `ref` is the
|
|
29
|
+
* index, among the parent's child nodes in the template DOM, of the node the part inserts
|
|
30
|
+
* before: the next static element or comment, or the anchor comment the normalizer emitted.
|
|
31
|
+
* Without `ref` the hole inserts at the end of the parent (CHILD_END, CHILD_SOLE).
|
|
32
|
+
* - Attributes, booleans, properties: `path` leads to the element; `name` is the attribute or
|
|
33
|
+
* property name. A multi-attribute's `strings` are its static pieces (character references
|
|
34
|
+
* already decoded): `strings.length - 1` values are joined with them.
|
|
35
|
+
* - Hooks: `path` leads to the element. Text: `path` leads to the `<textarea>`/`<title>`.
|
|
36
|
+
*/
|
|
37
|
+
export type PartSpec = readonly [
|
|
38
|
+
kind: typeof CHILD_END | typeof CHILD_SOLE | typeof HOOK_PART | typeof TEXT_PART,
|
|
39
|
+
path: Path
|
|
40
|
+
] | readonly [kind: typeof CHILD_BEFORE, path: Path, ref: number] | readonly [
|
|
41
|
+
kind: typeof ATTR_PART | typeof BOOL_PART | typeof PROP_PART,
|
|
42
|
+
path: Path,
|
|
43
|
+
name: string
|
|
44
|
+
] | readonly [kind: typeof MULTI_PART, path: Path, name: string, strings: readonly string[]];
|
|
45
|
+
/**
|
|
46
|
+
* What the server renderer writes (view/06-server.md), in order, with no tokenizing. Strings
|
|
47
|
+
* are static markup, written verbatim. Each hole op takes the next value(s); the custom-element
|
|
48
|
+
* ops take none and mark where a component's start tag ends and its end tag begins.
|
|
49
|
+
*
|
|
50
|
+
* - `child`: the value per 02's child table. Anchors are already in the next static string.
|
|
51
|
+
* `in` is the parent element's local name (absent at the template root, where the parent is
|
|
52
|
+
* wherever the instance is written): the development check for text the parser would move
|
|
53
|
+
* out of table structure needs it. `svg` is set when the parent is SVG content (an SVG
|
|
54
|
+
* element other than <foreignObject>, <desc>, <title>), where svg templates may render.
|
|
55
|
+
* - `text`: the value as escaped text (`<textarea>`, `<title>` content).
|
|
56
|
+
* - `attr`: ` name="escaped"`, or nothing for null/undefined/nothing. With `strings`, the
|
|
57
|
+
* pieces and `strings.length - 1` values are joined first (`nothing` in any piece: nothing).
|
|
58
|
+
* - `bool`: ` name` when the value is truthy.
|
|
59
|
+
* - `prop`: nothing in markup; a prop when the element is a Gyral component.
|
|
60
|
+
* - `hook`: the hook's `server(args)` attributes.
|
|
61
|
+
* - `open`: a custom element's start tag begins. `html` is `<tag` plus its static attributes,
|
|
62
|
+
* written verbatim; `attrs` are the same static attributes, decoded (props for a component).
|
|
63
|
+
* The element's attribute ops follow.
|
|
64
|
+
* - `openEnd`: write `>`. A component writes its seed attribute first, and its shadow root
|
|
65
|
+
* after.
|
|
66
|
+
* - `close`: write `</tag>`. Everything between `openEnd` and `close` is the element's children.
|
|
67
|
+
*
|
|
68
|
+
* Joining the strings with every op written empty (`open` as `html`, `openEnd` as `>`, `close`
|
|
69
|
+
* as `</tag>`) gives exactly the template's `html`, plus its static `style` attributes, which
|
|
70
|
+
* the client's `html` leaves to the part table.
|
|
71
|
+
*/
|
|
72
|
+
export type Segment = string | {
|
|
73
|
+
readonly k: 'child';
|
|
74
|
+
readonly in?: string;
|
|
75
|
+
readonly svg?: true;
|
|
76
|
+
} | {
|
|
77
|
+
readonly k: 'text';
|
|
78
|
+
} | {
|
|
79
|
+
readonly k: 'attr';
|
|
80
|
+
readonly name: string;
|
|
81
|
+
readonly strings?: readonly string[];
|
|
82
|
+
} | {
|
|
83
|
+
readonly k: 'bool';
|
|
84
|
+
readonly name: string;
|
|
85
|
+
} | {
|
|
86
|
+
readonly k: 'prop';
|
|
87
|
+
readonly name: string;
|
|
88
|
+
} | {
|
|
89
|
+
readonly k: 'hook';
|
|
90
|
+
} | {
|
|
91
|
+
readonly k: 'open';
|
|
92
|
+
readonly tag: string;
|
|
93
|
+
readonly html: string;
|
|
94
|
+
readonly attrs: readonly (readonly [name: string, value: string])[];
|
|
95
|
+
} | {
|
|
96
|
+
readonly k: 'openEnd';
|
|
97
|
+
} | {
|
|
98
|
+
readonly k: 'close';
|
|
99
|
+
readonly tag: string;
|
|
100
|
+
};
|
|
101
|
+
export interface TemplateObject {
|
|
102
|
+
/**
|
|
103
|
+
* Deterministic id of the normalized strings (id.ts). Absent from objects compiled for a
|
|
104
|
+
* production client (01 "Template ids"): there the renderer compares templates by identity.
|
|
105
|
+
*/
|
|
106
|
+
readonly id?: string;
|
|
107
|
+
/**
|
|
108
|
+
* Normalized template HTML for the client: bound attributes and static `style` attributes
|
|
109
|
+
* (zero-hole multi-attribute parts) removed, anchors added.
|
|
110
|
+
*/
|
|
111
|
+
readonly html: string;
|
|
112
|
+
readonly parts: readonly PartSpec[];
|
|
113
|
+
/**
|
|
114
|
+
* `true` when it contains document-level tags (<!doctype>, <html>, <head>, <body>):
|
|
115
|
+
* server-only. Absent otherwise.
|
|
116
|
+
*/
|
|
117
|
+
readonly server?: true;
|
|
118
|
+
/**
|
|
119
|
+
* `true` for an svg template (`` svg`…` ``, 01 "svg templates"): its HTML is SVG content,
|
|
120
|
+
* parsed inside an <svg>. Absent otherwise.
|
|
121
|
+
*/
|
|
122
|
+
readonly svg?: true;
|
|
123
|
+
/**
|
|
124
|
+
* Server writing plan. Absent from client-compiled template objects (the compiler drops it),
|
|
125
|
+
* so the client renderer never reads it; the runtime preparer and server builds keep it.
|
|
126
|
+
*/
|
|
127
|
+
readonly segments?: readonly Segment[];
|
|
128
|
+
/**
|
|
129
|
+
* Server only, like `segments`: the decoded values of the template's non-empty static
|
|
130
|
+
* `style` attributes, deduplicated, so a server render can collect every `style` value it
|
|
131
|
+
* writes for a CSP (ADR 0020) without parsing its string segments. Absent when there are none.
|
|
132
|
+
*/
|
|
133
|
+
readonly staticStyles?: readonly string[];
|
|
134
|
+
/** Development only: file:line:column of the call site. */
|
|
135
|
+
readonly loc?: string;
|
|
136
|
+
}
|
|
137
|
+
/** What the normalizer returns: a template object that always has its id. */
|
|
138
|
+
export type NormalizedTemplate = TemplateObject & {
|
|
139
|
+
readonly id: string;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* The DOM the browser must build from `html`, for the runtime preparer's check (prepare.ts):
|
|
143
|
+
* `'#text'`, `'#comment'`, or `[localName (lower case), children]`.
|
|
144
|
+
*/
|
|
145
|
+
export type ShapeNode = '#text' | '#comment' | readonly [name: string, children: Shape];
|
|
146
|
+
export type Shape = readonly ShapeNode[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// The template object (view/01-templates.md "The template object") and its part table
|
|
2
|
+
// (view/02-bindings.md "Hole kinds"). Plain JSON data, no functions: the Vite compiler (Phase 6)
|
|
3
|
+
// emits it as code, the browser instantiates from it, and the server writes from it. Compact
|
|
4
|
+
// on purpose (numeric part kinds, tuples, `server` only when true), so the code compiled
|
|
5
|
+
// client builds carry stays small with nothing to decode.
|
|
6
|
+
// Part kinds: the first entry of a PartSpec tuple. Small numbers, because compiled client
|
|
7
|
+
// builds carry every template's part table as code (view/01-templates.md "Compiled").
|
|
8
|
+
/** `[CHILD_END, path]`: a child hole that inserts at the end of its parent. */
|
|
9
|
+
export const CHILD_END = 0;
|
|
10
|
+
/** `[CHILD_SOLE, path]`: a child hole that is its parent's only child node (so at its end). */
|
|
11
|
+
export const CHILD_SOLE = 1;
|
|
12
|
+
/** `[CHILD_BEFORE, path, ref]`: a child hole that inserts before the parent's child `ref`. */
|
|
13
|
+
export const CHILD_BEFORE = 2;
|
|
14
|
+
/** `[ATTR_PART, path, name]`: `name=${v}`. */
|
|
15
|
+
export const ATTR_PART = 3;
|
|
16
|
+
/**
|
|
17
|
+
* `[MULTI_PART, path, name, strings]`: `name="a ${x} b"`; with one string and no values, a
|
|
18
|
+
* static `style` attribute the client applies through the CSSOM (01 "Normalization").
|
|
19
|
+
*/
|
|
20
|
+
export const MULTI_PART = 4;
|
|
21
|
+
/** `[BOOL_PART, path, name]`: `?name=${v}`. */
|
|
22
|
+
export const BOOL_PART = 5;
|
|
23
|
+
/** `[PROP_PART, path, name]`: `.name=${v}`. */
|
|
24
|
+
export const PROP_PART = 6;
|
|
25
|
+
/** `[HOOK_PART, path]`: `${hook(…)}` in a start tag. */
|
|
26
|
+
export const HOOK_PART = 7;
|
|
27
|
+
/** `[TEXT_PART, path]`: the whole content of a `<textarea>` or `<title>`. */
|
|
28
|
+
export const TEXT_PART = 8;
|
|
29
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/view/normalize/types.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,iGAAiG;AACjG,6FAA6F;AAC7F,yFAAyF;AACzF,0DAA0D;AAK1D,0FAA0F;AAC1F,sFAAsF;AACtF,+EAA+E;AAC/E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,+FAA+F;AAC/F,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC;AAC5B,8FAA8F;AAC9F,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC;AAC9B,8CAA8C;AAC9C,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC;AAC5B,+CAA+C;AAC/C,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,+CAA+C;AAC/C,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,wDAAwD;AACxD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,6EAA6E;AAC7E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC","sourcesContent":["// The template object (view/01-templates.md \"The template object\") and its part table\n// (view/02-bindings.md \"Hole kinds\"). Plain JSON data, no functions: the Vite compiler (Phase 6)\n// emits it as code, the browser instantiates from it, and the server writes from it. Compact\n// on purpose (numeric part kinds, tuples, `server` only when true), so the code compiled\n// client builds carry stays small with nothing to decode.\n\n/** Child-index path from the template's content root (`[]` is the root itself). */\nexport type Path = readonly number[];\n\n// Part kinds: the first entry of a PartSpec tuple. Small numbers, because compiled client\n// builds carry every template's part table as code (view/01-templates.md \"Compiled\").\n/** `[CHILD_END, path]`: a child hole that inserts at the end of its parent. */\nexport const CHILD_END = 0;\n/** `[CHILD_SOLE, path]`: a child hole that is its parent's only child node (so at its end). */\nexport const CHILD_SOLE = 1;\n/** `[CHILD_BEFORE, path, ref]`: a child hole that inserts before the parent's child `ref`. */\nexport const CHILD_BEFORE = 2;\n/** `[ATTR_PART, path, name]`: `name=${v}`. */\nexport const ATTR_PART = 3;\n/**\n * `[MULTI_PART, path, name, strings]`: `name=\"a ${x} b\"`; with one string and no values, a\n * static `style` attribute the client applies through the CSSOM (01 \"Normalization\").\n */\nexport const MULTI_PART = 4;\n/** `[BOOL_PART, path, name]`: `?name=${v}`. */\nexport const BOOL_PART = 5;\n/** `[PROP_PART, path, name]`: `.name=${v}`. */\nexport const PROP_PART = 6;\n/** `[HOOK_PART, path]`: `${hook(…)}` in a start tag. */\nexport const HOOK_PART = 7;\n/** `[TEXT_PART, path]`: the whole content of a `<textarea>` or `<title>`. */\nexport const TEXT_PART = 8;\n\n/**\n * One entry per binding, in source order: a tuple whose first entry is its kind (above), whose\n * second is a path, then the kind's own fields. Multi-attributes take several values.\n *\n * - Child holes: `path` leads to the parent element (`[]`: the template root). `ref` is the\n * index, among the parent's child nodes in the template DOM, of the node the part inserts\n * before: the next static element or comment, or the anchor comment the normalizer emitted.\n * Without `ref` the hole inserts at the end of the parent (CHILD_END, CHILD_SOLE).\n * - Attributes, booleans, properties: `path` leads to the element; `name` is the attribute or\n * property name. A multi-attribute's `strings` are its static pieces (character references\n * already decoded): `strings.length - 1` values are joined with them.\n * - Hooks: `path` leads to the element. Text: `path` leads to the `<textarea>`/`<title>`.\n */\nexport type PartSpec =\n | readonly [\n kind: typeof CHILD_END | typeof CHILD_SOLE | typeof HOOK_PART | typeof TEXT_PART,\n path: Path,\n ]\n | readonly [kind: typeof CHILD_BEFORE, path: Path, ref: number]\n | readonly [\n kind: typeof ATTR_PART | typeof BOOL_PART | typeof PROP_PART,\n path: Path,\n name: string,\n ]\n | readonly [kind: typeof MULTI_PART, path: Path, name: string, strings: readonly string[]];\n\n/**\n * What the server renderer writes (view/06-server.md), in order, with no tokenizing. Strings\n * are static markup, written verbatim. Each hole op takes the next value(s); the custom-element\n * ops take none and mark where a component's start tag ends and its end tag begins.\n *\n * - `child`: the value per 02's child table. Anchors are already in the next static string.\n * `in` is the parent element's local name (absent at the template root, where the parent is\n * wherever the instance is written): the development check for text the parser would move\n * out of table structure needs it. `svg` is set when the parent is SVG content (an SVG\n * element other than <foreignObject>, <desc>, <title>), where svg templates may render.\n * - `text`: the value as escaped text (`<textarea>`, `<title>` content).\n * - `attr`: ` name=\"escaped\"`, or nothing for null/undefined/nothing. With `strings`, the\n * pieces and `strings.length - 1` values are joined first (`nothing` in any piece: nothing).\n * - `bool`: ` name` when the value is truthy.\n * - `prop`: nothing in markup; a prop when the element is a Gyral component.\n * - `hook`: the hook's `server(args)` attributes.\n * - `open`: a custom element's start tag begins. `html` is `<tag` plus its static attributes,\n * written verbatim; `attrs` are the same static attributes, decoded (props for a component).\n * The element's attribute ops follow.\n * - `openEnd`: write `>`. A component writes its seed attribute first, and its shadow root\n * after.\n * - `close`: write `</tag>`. Everything between `openEnd` and `close` is the element's children.\n *\n * Joining the strings with every op written empty (`open` as `html`, `openEnd` as `>`, `close`\n * as `</tag>`) gives exactly the template's `html`, plus its static `style` attributes, which\n * the client's `html` leaves to the part table.\n */\nexport type Segment =\n | string\n | { readonly k: 'child'; readonly in?: string; readonly svg?: true }\n | { readonly k: 'text' }\n | { readonly k: 'attr'; readonly name: string; readonly strings?: readonly string[] }\n | { readonly k: 'bool'; readonly name: string }\n | { readonly k: 'prop'; readonly name: string }\n | { readonly k: 'hook' }\n | {\n readonly k: 'open';\n readonly tag: string;\n readonly html: string;\n readonly attrs: readonly (readonly [name: string, value: string])[];\n }\n | { readonly k: 'openEnd' }\n | { readonly k: 'close'; readonly tag: string };\n\nexport interface TemplateObject {\n /**\n * Deterministic id of the normalized strings (id.ts). Absent from objects compiled for a\n * production client (01 \"Template ids\"): there the renderer compares templates by identity.\n */\n readonly id?: string;\n /**\n * Normalized template HTML for the client: bound attributes and static `style` attributes\n * (zero-hole multi-attribute parts) removed, anchors added.\n */\n readonly html: string;\n readonly parts: readonly PartSpec[];\n /**\n * `true` when it contains document-level tags (<!doctype>, <html>, <head>, <body>):\n * server-only. Absent otherwise.\n */\n readonly server?: true;\n /**\n * `true` for an svg template (`` svg`…` ``, 01 \"svg templates\"): its HTML is SVG content,\n * parsed inside an <svg>. Absent otherwise.\n */\n readonly svg?: true;\n /**\n * Server writing plan. Absent from client-compiled template objects (the compiler drops it),\n * so the client renderer never reads it; the runtime preparer and server builds keep it.\n */\n readonly segments?: readonly Segment[];\n /**\n * Server only, like `segments`: the decoded values of the template's non-empty static\n * `style` attributes, deduplicated, so a server render can collect every `style` value it\n * writes for a CSP (ADR 0020) without parsing its string segments. Absent when there are none.\n */\n readonly staticStyles?: readonly string[];\n /** Development only: file:line:column of the call site. */\n readonly loc?: string;\n}\n\n/** What the normalizer returns: a template object that always has its id. */\nexport type NormalizedTemplate = TemplateObject & { readonly id: string };\n\n/**\n * The DOM the browser must build from `html`, for the runtime preparer's check (prepare.ts):\n * `'#text'`, `'#comment'`, or `[localName (lower case), children]`.\n */\nexport type ShapeNode = '#text' | '#comment' | readonly [name: string, children: Shape];\nexport type Shape = readonly ShapeNode[];\n"]}
|
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Whitespace minification for templates (view/01-templates.md "Whitespace", ADR 0016 addendum).
|
|
2
|
+
// Moved from core's template-whitespace.ts (Gyral's own design) into the view layer's
|
|
3
|
+
// normalizer, so the compiler, the runtime preparer and the server minify identically.
|
|
2
4
|
//
|
|
3
|
-
//
|
|
4
|
-
// Solid, JSX) drop them. In a benchmark table row that is 12 extra nodes out of 25, and removing
|
|
5
|
-
// them made create/replace/clear 11-24% faster (gyral-1kq). Gyral's `html` and `svg` tags run the
|
|
6
|
-
// template strings through `minifyTemplate()` once per call site (cached by strings identity),
|
|
7
|
-
// so the server and the browser always build the same template: hydration digests match in any
|
|
8
|
-
// toolchain (Vite, tsx, plain Node), with no build step.
|
|
9
|
-
//
|
|
10
|
-
// Rules (the same text everywhere, documented in docs/references/consumer-setup.md):
|
|
5
|
+
// Rules:
|
|
11
6
|
// - Whitespace-only text that contains a newline is removed when it sits next to a template
|
|
12
|
-
// edge, a block-level tag
|
|
13
|
-
//
|
|
7
|
+
// edge, a block-level tag (head-only tags count: <head>, <meta>, <link>, <base>, <title>),
|
|
8
|
+
// or the inside edge of a <button>/<select>/<svg> (never rendered there). Inside <head>,
|
|
9
|
+
// whitespace-only text is always removed, newline or not, between holes too: nothing there
|
|
10
|
+
// renders. Between two inline neighbours (phrasing elements, custom elements, holes,
|
|
14
11
|
// comments) it collapses to one space.
|
|
15
12
|
// - Other runs of whitespace in text collapse to one space; a leading or trailing run with a
|
|
16
13
|
// newline next to one of those edges is removed.
|
|
17
14
|
// - <pre>, <textarea>, <script>, <style> and <title> contents, tags and attribute values,
|
|
18
|
-
// and comments are copied unchanged.
|
|
19
|
-
//
|
|
15
|
+
// and comments are copied unchanged. Holes never move: the result has the same number of
|
|
16
|
+
// strings.
|
|
20
17
|
// The function is idempotent: minifying minified strings changes nothing.
|
|
21
18
|
/** Elements whose box is block-level (or never laid out inline) by default. */
|
|
22
19
|
const BLOCK = new Set(('address article aside blockquote body caption col colgroup datalist dd details dialog div ' +
|
|
23
20
|
'dl dt fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup hr html ' +
|
|
24
21
|
'legend li main menu nav ol optgroup option p pre search section select summary table tbody ' +
|
|
25
22
|
'td tfoot th thead tr ul ' +
|
|
23
|
+
// Head-only elements: never rendered at all, so never inline.
|
|
24
|
+
'base link meta title ' +
|
|
26
25
|
// SVG containers and shapes: whitespace between them is never rendered.
|
|
27
26
|
'circle clippath defs ellipse g line lineargradient marker mask path pattern polygon ' +
|
|
28
27
|
'polyline radialgradient rect stop symbol use').split(' '));
|
|
@@ -31,9 +30,10 @@ const RAW_TEXT = new Set(['script', 'style', 'textarea', 'title']);
|
|
|
31
30
|
const PRESERVE = 'pre';
|
|
32
31
|
/**
|
|
33
32
|
* Inline-block controls: they sit inline among their neighbours, but whitespace at the start or
|
|
34
|
-
* end of their own content is never rendered (it is at the edge of their own line box).
|
|
33
|
+
* end of their own content is never rendered (it is at the edge of their own line box). Same
|
|
34
|
+
* for <svg>: SVG content renders no text outside its text elements.
|
|
35
35
|
*/
|
|
36
|
-
const INLINE_BOX = new Set(['button', 'select']);
|
|
36
|
+
const INLINE_BOX = new Set(['button', 'select', 'svg']);
|
|
37
37
|
/**
|
|
38
38
|
* The edge a tag makes for the text next to it. `inside` is true when the text is inside the
|
|
39
39
|
* element (after its start tag, or before its end tag).
|
|
@@ -46,12 +46,14 @@ function edgeOfTag(name, inside) {
|
|
|
46
46
|
}
|
|
47
47
|
const WS = /^[ \t\n\r\f]*$/;
|
|
48
48
|
const RUN = /[ \t\n\r\f]+/g;
|
|
49
|
-
|
|
49
|
+
/** `head`: the text is inside `<head>`, which is never rendered. */
|
|
50
|
+
function minifyChunk(text, left, right, head) {
|
|
50
51
|
if (text === '')
|
|
51
52
|
return text;
|
|
52
53
|
if (WS.test(text)) {
|
|
53
|
-
const removable =
|
|
54
|
-
(
|
|
54
|
+
const removable = head ||
|
|
55
|
+
(/[\n\r]/.test(text) &&
|
|
56
|
+
(left === 'template' || right === 'template' || left === 'block' || right === 'block'));
|
|
55
57
|
return removable ? '' : ' ';
|
|
56
58
|
}
|
|
57
59
|
// Mixed text: a leading or trailing run with a newline next to a removable edge goes too.
|
|
@@ -71,7 +73,7 @@ function minifySegment(segment, state, last) {
|
|
|
71
73
|
let out = '';
|
|
72
74
|
let chunk = '';
|
|
73
75
|
const flushText = (right) => {
|
|
74
|
-
out += state.preDepth > 0 ? chunk : minifyChunk(chunk, state.left, right);
|
|
76
|
+
out += state.preDepth > 0 ? chunk : minifyChunk(chunk, state.left, right, state.head);
|
|
75
77
|
chunk = '';
|
|
76
78
|
};
|
|
77
79
|
let i = 0;
|
|
@@ -149,6 +151,10 @@ function endTag(state, selfClosing) {
|
|
|
149
151
|
const name = state.tagName;
|
|
150
152
|
state.mode = Mode.Text;
|
|
151
153
|
state.left = edgeOfTag(name, !state.closing && !selfClosing);
|
|
154
|
+
if (name === 'head' && !selfClosing)
|
|
155
|
+
state.head = !state.closing;
|
|
156
|
+
if (name === 'body')
|
|
157
|
+
state.head = false;
|
|
152
158
|
if (name === PRESERVE) {
|
|
153
159
|
if (state.closing)
|
|
154
160
|
state.preDepth = Math.max(0, state.preDepth - 1);
|
|
@@ -169,24 +175,9 @@ export function minifyStrings(strings) {
|
|
|
169
175
|
closing: false,
|
|
170
176
|
rawName: '',
|
|
171
177
|
preDepth: 0,
|
|
178
|
+
head: false,
|
|
172
179
|
left: 'template',
|
|
173
180
|
};
|
|
174
181
|
return strings.map((segment, index) => minifySegment(segment, state, index === strings.length - 1));
|
|
175
182
|
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* The minified TemplateStringsArray for a call site. Cached by identity, so Lit's own template
|
|
179
|
-
* cache (keyed by the strings array) still hits once per call site.
|
|
180
|
-
*/
|
|
181
|
-
export function minifyTemplate(strings) {
|
|
182
|
-
const cached = cache.get(strings);
|
|
183
|
-
if (cached !== undefined)
|
|
184
|
-
return cached;
|
|
185
|
-
const minified = minifyStrings(strings);
|
|
186
|
-
// Lit accepts only arrays with an own `raw` field (its anti-spoofing check), as lit/static-html
|
|
187
|
-
// builds them. Cooked strings are what Lit reads; `raw` mirrors them.
|
|
188
|
-
const result = Object.freeze(Object.assign(minified, { raw: Object.freeze([...minified]) }));
|
|
189
|
-
cache.set(strings, result);
|
|
190
|
-
return result;
|
|
191
|
-
}
|
|
192
|
-
//# sourceMappingURL=template-whitespace.js.map
|
|
183
|
+
//# sourceMappingURL=whitespace.js.map
|