@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,116 @@
|
|
|
1
|
+
// Which modules the build-time feature scan reads (features.ts, view/05-element.md "Features
|
|
2
|
+
// register themselves"): only those that can affect Gyral components. A module outside
|
|
3
|
+
// node_modules (the app's own source, a workspace or `link:` package) always can. An installed
|
|
4
|
+
// package can only if it is a Gyral package or depends on one, directly or through its own
|
|
5
|
+
// dependencies (a design system, a component library): a package that never reaches
|
|
6
|
+
// `@gyral/*` can't import `define`, `html` or `raw`, so it can't define a component, render a
|
|
7
|
+
// template or set a spec field (effect, three and the like). The manifests are read from disk
|
|
8
|
+
// the way Node finds packages (no exports map), once per build.
|
|
9
|
+
import { readFileSync, realpathSync } from 'node:fs';
|
|
10
|
+
import { dirname, join } from 'node:path';
|
|
11
|
+
/** Gyral's packages (vite.ts has the same pattern for the dev server's dependents). */
|
|
12
|
+
const GYRAL_PACKAGES = /^@gyral\//;
|
|
13
|
+
/** The last `node_modules` directory in a path, and what follows it. */
|
|
14
|
+
const IN_NODE_MODULES = /^(.*[\\/]node_modules[\\/])((?:@[^\\/]+[\\/])?[^\\/]+)[\\/]/;
|
|
15
|
+
function read(file) {
|
|
16
|
+
try {
|
|
17
|
+
const value = JSON.parse(readFileSync(file, 'utf8'));
|
|
18
|
+
return typeof value === 'object' && value !== null ? value : undefined;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** The installed package `name` as seen from `dir` (Node's lookup), as a real path. */
|
|
25
|
+
function locate(dir, name) {
|
|
26
|
+
for (let d = dir;; d = dirname(d)) {
|
|
27
|
+
const candidate = join(d, 'node_modules', name);
|
|
28
|
+
if (read(join(candidate, 'package.json')) !== undefined) {
|
|
29
|
+
try {
|
|
30
|
+
return realpathSync(candidate);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return candidate;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (dirname(d) === d)
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const dependencyNames = (m) => Object.keys({ ...m.dependencies, ...m.peerDependencies, ...m.optionalDependencies });
|
|
41
|
+
/** A scope for one build: manifests and answers are cached per package directory. */
|
|
42
|
+
export function createScope() {
|
|
43
|
+
const reaches = new Map();
|
|
44
|
+
const names = new Map();
|
|
45
|
+
/** Whether the package in `dir`, or any package it depends on, is a Gyral package. */
|
|
46
|
+
function reachesGyral(dir) {
|
|
47
|
+
const known = reaches.get(dir);
|
|
48
|
+
if (known !== undefined)
|
|
49
|
+
return known;
|
|
50
|
+
// A walk of the dependency graph from `dir` (cycles are fine: each package is read once).
|
|
51
|
+
const seen = new Set([dir]);
|
|
52
|
+
const queue = [dir];
|
|
53
|
+
let found = false;
|
|
54
|
+
for (let next = queue.pop(); next !== undefined && !found; next = queue.pop()) {
|
|
55
|
+
const m = read(join(next, 'package.json'));
|
|
56
|
+
if (m === undefined) {
|
|
57
|
+
found = next === dir; // the module's own package can't be read: scan it
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const deps = dependencyNames(m);
|
|
61
|
+
if ((typeof m.name === 'string' && GYRAL_PACKAGES.test(m.name)) ||
|
|
62
|
+
deps.some((d) => GYRAL_PACKAGES.test(d))) {
|
|
63
|
+
found = true;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
for (const d of deps) {
|
|
67
|
+
const at = locate(next, d);
|
|
68
|
+
if (at === undefined || seen.has(at))
|
|
69
|
+
continue;
|
|
70
|
+
if (reaches.get(at) === true) {
|
|
71
|
+
found = true;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
seen.add(at);
|
|
75
|
+
queue.push(at);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Not found: the whole graph from `dir` was read, and no package in it reaches Gyral.
|
|
79
|
+
if (!found)
|
|
80
|
+
for (const s of seen)
|
|
81
|
+
reaches.set(s, false);
|
|
82
|
+
reaches.set(dir, found);
|
|
83
|
+
return found;
|
|
84
|
+
}
|
|
85
|
+
/** The `name` of the nearest package.json above `file` that has one. */
|
|
86
|
+
function nameAbove(file) {
|
|
87
|
+
const dir = dirname(file);
|
|
88
|
+
if (names.has(dir))
|
|
89
|
+
return names.get(dir);
|
|
90
|
+
const name = read(join(dir, 'package.json'))?.name;
|
|
91
|
+
const result = typeof name === 'string' ? name : dirname(dir) === dir ? undefined : nameAbove(dir);
|
|
92
|
+
names.set(dir, result);
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
inScope(id) {
|
|
97
|
+
const installed = IN_NODE_MODULES.exec(id);
|
|
98
|
+
if (installed === null)
|
|
99
|
+
return true;
|
|
100
|
+
const dir = (installed[1] ?? '') + (installed[2] ?? '');
|
|
101
|
+
let real = dir;
|
|
102
|
+
try {
|
|
103
|
+
real = realpathSync(dir);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// keep the path as given
|
|
107
|
+
}
|
|
108
|
+
return reachesGyral(real);
|
|
109
|
+
},
|
|
110
|
+
packageOf(id) {
|
|
111
|
+
const installed = IN_NODE_MODULES.exec(id);
|
|
112
|
+
return installed === null ? nameAbove(id) : installed[2]?.replace(/\\/g, '/');
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/compiler/scope.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,uFAAuF;AACvF,+FAA+F;AAC/F,2FAA2F;AAC3F,oFAAoF;AACpF,8FAA8F;AAC9F,8FAA8F;AAC9F,gEAAgE;AAChE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,uFAAuF;AACvF,MAAM,cAAc,GAAG,WAAW,CAAC;AACnC,wEAAwE;AACxE,MAAM,eAAe,GAAG,6DAA6D,CAAC;AAStF,SAAS,IAAI,CAAC,IAAY;IACxB,IAAI,CAAC;QACH,MAAM,KAAK,GAAY,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC9D,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACzE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH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C;QACD,SAAS,CAAC,EAAE;YACV,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC3C,OAAO,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAChF,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Which modules the build-time feature scan reads (features.ts, view/05-element.md \"Features\n// register themselves\"): only those that can affect Gyral components. A module outside\n// node_modules (the app's own source, a workspace or `link:` package) always can. An installed\n// package can only if it is a Gyral package or depends on one, directly or through its own\n// dependencies (a design system, a component library): a package that never reaches\n// `@gyral/*` can't import `define`, `html` or `raw`, so it can't define a component, render a\n// template or set a spec field (effect, three and the like). The manifests are read from disk\n// the way Node finds packages (no exports map), once per build.\nimport { readFileSync, realpathSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\n\n/** Gyral's packages (vite.ts has the same pattern for the dev server's dependents). */\nconst GYRAL_PACKAGES = /^@gyral\\//;\n/** The last `node_modules` directory in a path, and what follows it. */\nconst IN_NODE_MODULES = /^(.*[\\\\/]node_modules[\\\\/])((?:@[^\\\\/]+[\\\\/])?[^\\\\/]+)[\\\\/]/;\n\ninterface Manifest {\n readonly name?: unknown;\n readonly dependencies?: object;\n readonly peerDependencies?: object;\n readonly optionalDependencies?: object;\n}\n\nfunction read(file: string): Manifest | undefined {\n try {\n const value: unknown = JSON.parse(readFileSync(file, 'utf8'));\n return typeof value === 'object' && value !== null ? value : undefined;\n } catch {\n return undefined;\n }\n}\n\n/** The installed package `name` as seen from `dir` (Node's lookup), as a real path. */\nfunction locate(dir: string, name: string): string | undefined {\n for (let d = dir; ; d = dirname(d)) {\n const candidate = join(d, 'node_modules', name);\n if (read(join(candidate, 'package.json')) !== undefined) {\n try {\n return realpathSync(candidate);\n } catch {\n return candidate;\n }\n }\n if (dirname(d) === d) return undefined;\n }\n}\n\nconst dependencyNames = (m: Manifest): string[] =>\n Object.keys({ ...m.dependencies, ...m.peerDependencies, ...m.optionalDependencies });\n\nexport interface Scope {\n /** Whether module `id` can affect Gyral components, so the scan must read it. */\n inScope(id: string): boolean;\n /** The name of the package module `id` belongs to (`@gyral/core` is where `raw` comes from). */\n packageOf(id: string): string | undefined;\n}\n\n/** A scope for one build: manifests and answers are cached per package directory. */\nexport function createScope(): Scope {\n const reaches = new Map<string, boolean>();\n const names = new Map<string, string | undefined>();\n\n /** Whether the package in `dir`, or any package it depends on, is a Gyral package. */\n function reachesGyral(dir: string): boolean {\n const known = reaches.get(dir);\n if (known !== undefined) return known;\n // A walk of the dependency graph from `dir` (cycles are fine: each package is read once).\n const seen = new Set([dir]);\n const queue = [dir];\n let found = false;\n for (let next = queue.pop(); next !== undefined && !found; next = queue.pop()) {\n const m = read(join(next, 'package.json'));\n if (m === undefined) {\n found = next === dir; // the module's own package can't be read: scan it\n continue;\n }\n const deps = dependencyNames(m);\n if (\n (typeof m.name === 'string' && GYRAL_PACKAGES.test(m.name)) ||\n deps.some((d) => GYRAL_PACKAGES.test(d))\n ) {\n found = true;\n break;\n }\n for (const d of deps) {\n const at = locate(next, d);\n if (at === undefined || seen.has(at)) continue;\n if (reaches.get(at) === true) {\n found = true;\n break;\n }\n seen.add(at);\n queue.push(at);\n }\n }\n // Not found: the whole graph from `dir` was read, and no package in it reaches Gyral.\n if (!found) for (const s of seen) reaches.set(s, false);\n reaches.set(dir, found);\n return found;\n }\n\n /** The `name` of the nearest package.json above `file` that has one. */\n function nameAbove(file: string): string | undefined {\n const dir = dirname(file);\n if (names.has(dir)) return names.get(dir);\n const name = read(join(dir, 'package.json'))?.name;\n const result =\n typeof name === 'string' ? name : dirname(dir) === dir ? undefined : nameAbove(dir);\n names.set(dir, result);\n return result;\n }\n\n return {\n inScope(id) {\n const installed = IN_NODE_MODULES.exec(id);\n if (installed === null) return true;\n const dir = (installed[1] ?? '') + (installed[2] ?? '');\n let real = dir;\n try {\n real = realpathSync(dir);\n } catch {\n // keep the path as given\n }\n return reachesGyral(real);\n },\n packageOf(id) {\n const installed = IN_NODE_MODULES.exec(id);\n return installed === null ? nameAbove(id) : installed[2]?.replace(/\\\\/g, '/');\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface Position {
|
|
2
|
+
/** 1-based. */
|
|
3
|
+
readonly line: number;
|
|
4
|
+
/** 0-based. */
|
|
5
|
+
readonly column: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class Lines {
|
|
8
|
+
readonly code: string;
|
|
9
|
+
private readonly starts;
|
|
10
|
+
constructor(code: string);
|
|
11
|
+
position(offset: number): Position;
|
|
12
|
+
/** Two lines of context around `offset`, with a caret under it (Vite prints it). */
|
|
13
|
+
frame(offset: number, end?: number): string;
|
|
14
|
+
}
|
|
15
|
+
export interface Edit {
|
|
16
|
+
readonly start: number;
|
|
17
|
+
readonly end: number;
|
|
18
|
+
readonly text: string;
|
|
19
|
+
}
|
|
20
|
+
export interface SourceMap {
|
|
21
|
+
readonly version: 3;
|
|
22
|
+
readonly sources: string[];
|
|
23
|
+
readonly names: string[];
|
|
24
|
+
readonly mappings: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Applies non-overlapping `edits` to `lines.code` and maps the result back to it: a segment at
|
|
28
|
+
* the start of every output line and at every edit boundary (line-level precision, like
|
|
29
|
+
* magic-string without `hires`).
|
|
30
|
+
*/
|
|
31
|
+
export declare function splice(lines: Lines, edits: readonly Edit[], file: string): {
|
|
32
|
+
code: string;
|
|
33
|
+
map: SourceMap;
|
|
34
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Module text helpers for the template compiler: offsets to line/column, code frames for build
|
|
2
|
+
// errors, and string splicing with a source map (no magic-string: @gyral/core has no runtime
|
|
3
|
+
// dependencies, and Vite doesn't expose one to plugins).
|
|
4
|
+
export class Lines {
|
|
5
|
+
constructor(code) {
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.starts = [0];
|
|
8
|
+
for (let k = code.indexOf('\n'); k !== -1; k = code.indexOf('\n', k + 1)) {
|
|
9
|
+
this.starts.push(k + 1);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
position(offset) {
|
|
13
|
+
let lo = 0;
|
|
14
|
+
let hi = this.starts.length - 1;
|
|
15
|
+
while (lo < hi) {
|
|
16
|
+
const mid = (lo + hi + 1) >> 1;
|
|
17
|
+
if ((this.starts[mid] ?? 0) <= offset)
|
|
18
|
+
lo = mid;
|
|
19
|
+
else
|
|
20
|
+
hi = mid - 1;
|
|
21
|
+
}
|
|
22
|
+
return { line: lo + 1, column: offset - (this.starts[lo] ?? 0) };
|
|
23
|
+
}
|
|
24
|
+
/** Two lines of context around `offset`, with a caret under it (Vite prints it). */
|
|
25
|
+
frame(offset, end = offset + 1) {
|
|
26
|
+
const { line, column } = this.position(offset);
|
|
27
|
+
const lines = this.code.split('\n');
|
|
28
|
+
const first = Math.max(1, line - 2);
|
|
29
|
+
const last = Math.min(lines.length, line + 2);
|
|
30
|
+
const width = String(last).length;
|
|
31
|
+
const out = [];
|
|
32
|
+
for (let n = first; n <= last; n++) {
|
|
33
|
+
const text = lines[n - 1] ?? '';
|
|
34
|
+
out.push(`${n === line ? '>' : ' '} ${String(n).padStart(width)} | ${text}`);
|
|
35
|
+
if (n === line) {
|
|
36
|
+
const span = Math.max(1, Math.min(end - offset, text.length - column));
|
|
37
|
+
out.push(` ${' '.repeat(width)} | ${' '.repeat(column)}${'^'.repeat(span)}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return out.join('\n');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
44
|
+
function vlq(value) {
|
|
45
|
+
let v = value < 0 ? (-value << 1) | 1 : value << 1;
|
|
46
|
+
let out = '';
|
|
47
|
+
do {
|
|
48
|
+
let digit = v & 31;
|
|
49
|
+
v >>>= 5;
|
|
50
|
+
if (v > 0)
|
|
51
|
+
digit |= 32;
|
|
52
|
+
out += B64[digit] ?? '';
|
|
53
|
+
} while (v > 0);
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Applies non-overlapping `edits` to `lines.code` and maps the result back to it: a segment at
|
|
58
|
+
* the start of every output line and at every edit boundary (line-level precision, like
|
|
59
|
+
* magic-string without `hires`).
|
|
60
|
+
*/
|
|
61
|
+
export function splice(lines, edits, file) {
|
|
62
|
+
const { code } = lines;
|
|
63
|
+
const sorted = [...edits].sort((a, b) => a.start - b.start);
|
|
64
|
+
let out = '';
|
|
65
|
+
const mapLines = [[]];
|
|
66
|
+
let genCol = 0;
|
|
67
|
+
let prev = { line: 0, column: 0 };
|
|
68
|
+
let prevGenCol = 0;
|
|
69
|
+
const mark = (offset) => {
|
|
70
|
+
const { line, column } = lines.position(offset);
|
|
71
|
+
const at = { line: line - 1, column };
|
|
72
|
+
const row = mapLines.at(-1);
|
|
73
|
+
if (row === undefined)
|
|
74
|
+
return;
|
|
75
|
+
if (row.length === 0)
|
|
76
|
+
prevGenCol = 0;
|
|
77
|
+
row.push(vlq(genCol - prevGenCol) + 'A' + vlq(at.line - prev.line) + vlq(at.column - prev.column));
|
|
78
|
+
prevGenCol = genCol;
|
|
79
|
+
prev = at;
|
|
80
|
+
};
|
|
81
|
+
const write = (text, origin, original) => {
|
|
82
|
+
let from = 0;
|
|
83
|
+
mark(origin);
|
|
84
|
+
for (let nl = text.indexOf('\n'); nl !== -1; nl = text.indexOf('\n', from)) {
|
|
85
|
+
out += text.slice(from, nl + 1);
|
|
86
|
+
from = nl + 1;
|
|
87
|
+
mapLines.push([]);
|
|
88
|
+
genCol = 0;
|
|
89
|
+
mark(original ? origin + from : origin);
|
|
90
|
+
}
|
|
91
|
+
out += text.slice(from);
|
|
92
|
+
genCol += text.length - from;
|
|
93
|
+
};
|
|
94
|
+
let pos = 0;
|
|
95
|
+
for (const edit of sorted) {
|
|
96
|
+
if (edit.start > pos)
|
|
97
|
+
write(code.slice(pos, edit.start), pos, true);
|
|
98
|
+
if (edit.text !== '')
|
|
99
|
+
write(edit.text, edit.start, false);
|
|
100
|
+
pos = Math.max(pos, edit.end);
|
|
101
|
+
}
|
|
102
|
+
if (pos < code.length)
|
|
103
|
+
write(code.slice(pos), pos, true);
|
|
104
|
+
return {
|
|
105
|
+
code: out,
|
|
106
|
+
map: {
|
|
107
|
+
version: 3,
|
|
108
|
+
sources: [file],
|
|
109
|
+
names: [],
|
|
110
|
+
mappings: mapLines.map((r) => r.join(',')).join(';'),
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../../src/compiler/source.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,6FAA6F;AAC7F,yDAAyD;AASzD,MAAM,OAAO,KAAK;IAGhB,YAAqB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAFhB,WAAM,GAAa,CAAC,CAAC,CAAC,CAAC;QAGtC,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YACzE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,MAAc;QACrB,IAAI,EAAE,GAAG,CAAC,CAAC;QACX,IAAI,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAChC,OAAO,EAAE,GAAG,EAAE,EAAE,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E,IAAI,CAAC,CAAC;IACzD,OAAO;QACL,IAAI,EAAE,GAAG;QACT,GAAG,EAAE;YACH,OAAO,EAAE,CAAC;YACV,OAAO,EAAE,CAAC,IAAI,CAAC;YACf,KAAK,EAAE,EAAE;YACT,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;SACrD;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Module text helpers for the template compiler: offsets to line/column, code frames for build\n// errors, and string splicing with a source map (no magic-string: @gyral/core has no runtime\n// dependencies, and Vite doesn't expose one to plugins).\n\nexport interface Position {\n /** 1-based. */\n readonly line: number;\n /** 0-based. */\n readonly column: number;\n}\n\nexport class Lines {\n private readonly starts: number[] = [0];\n\n constructor(readonly code: string) {\n for (let k = code.indexOf('\\n'); k !== -1; k = code.indexOf('\\n', k + 1)) {\n this.starts.push(k + 1);\n }\n }\n\n position(offset: number): Position {\n let lo = 0;\n let hi = this.starts.length - 1;\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1;\n if ((this.starts[mid] ?? 0) <= offset) lo = mid;\n else hi = mid - 1;\n }\n return { line: lo + 1, column: offset - (this.starts[lo] ?? 0) };\n }\n\n /** Two lines of context around `offset`, with a caret under it (Vite prints it). */\n frame(offset: number, end = offset + 1): string {\n const { line, column } = this.position(offset);\n const lines = this.code.split('\\n');\n const first = Math.max(1, line - 2);\n const last = Math.min(lines.length, line + 2);\n const width = String(last).length;\n const out: string[] = [];\n for (let n = first; n <= last; n++) {\n const text = lines[n - 1] ?? '';\n out.push(`${n === line ? '>' : ' '} ${String(n).padStart(width)} | ${text}`);\n if (n === line) {\n const span = Math.max(1, Math.min(end - offset, text.length - column));\n out.push(` ${' '.repeat(width)} | ${' '.repeat(column)}${'^'.repeat(span)}`);\n }\n }\n return out.join('\\n');\n }\n}\n\nexport interface Edit {\n readonly start: number;\n readonly end: number;\n readonly text: string;\n}\n\nexport interface SourceMap {\n readonly version: 3;\n readonly sources: string[];\n readonly names: string[];\n readonly mappings: string;\n}\n\nconst B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\nfunction vlq(value: number): string {\n let v = value < 0 ? (-value << 1) | 1 : value << 1;\n let out = '';\n do {\n let digit = v & 31;\n v >>>= 5;\n if (v > 0) digit |= 32;\n out += B64[digit] ?? '';\n } while (v > 0);\n return out;\n}\n\n/**\n * Applies non-overlapping `edits` to `lines.code` and maps the result back to it: a segment at\n * the start of every output line and at every edit boundary (line-level precision, like\n * magic-string without `hires`).\n */\nexport function splice(\n lines: Lines,\n edits: readonly Edit[],\n file: string,\n): { code: string; map: SourceMap } {\n const { code } = lines;\n const sorted = [...edits].sort((a, b) => a.start - b.start);\n let out = '';\n const mapLines: string[][] = [[]];\n let genCol = 0;\n let prev = { line: 0, column: 0 };\n let prevGenCol = 0;\n\n const mark = (offset: number): void => {\n const { line, column } = lines.position(offset);\n const at = { line: line - 1, column };\n const row = mapLines.at(-1);\n if (row === undefined) return;\n if (row.length === 0) prevGenCol = 0;\n row.push(\n vlq(genCol - prevGenCol) + 'A' + vlq(at.line - prev.line) + vlq(at.column - prev.column),\n );\n prevGenCol = genCol;\n prev = at;\n };\n\n const write = (text: string, origin: number, original: boolean): void => {\n let from = 0;\n mark(origin);\n for (let nl = text.indexOf('\\n'); nl !== -1; nl = text.indexOf('\\n', from)) {\n out += text.slice(from, nl + 1);\n from = nl + 1;\n mapLines.push([]);\n genCol = 0;\n mark(original ? origin + from : origin);\n }\n out += text.slice(from);\n genCol += text.length - from;\n };\n\n let pos = 0;\n for (const edit of sorted) {\n if (edit.start > pos) write(code.slice(pos, edit.start), pos, true);\n if (edit.text !== '') write(edit.text, edit.start, false);\n pos = Math.max(pos, edit.end);\n }\n if (pos < code.length) write(code.slice(pos), pos, true);\n return {\n code: out,\n map: {\n version: 3,\n sources: [file],\n names: [],\n mappings: mapLines.map((r) => r.join(',')).join(';'),\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
import type { ElementTypesOptions } from '../vite.js';
|
|
3
|
+
export interface TagMapOptions {
|
|
4
|
+
/** Project root; `dirs` and `out` are relative to it. */
|
|
5
|
+
readonly root: string;
|
|
6
|
+
/** Source directories to scan, recursively. Default `['src']`. */
|
|
7
|
+
readonly dirs?: readonly string[];
|
|
8
|
+
/** The declaration file to write. Default `.gyral/elements.d.ts`. */
|
|
9
|
+
readonly out?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface TagEntry {
|
|
12
|
+
readonly tag: string;
|
|
13
|
+
readonly file: string;
|
|
14
|
+
readonly name: string;
|
|
15
|
+
}
|
|
16
|
+
/** One `define()`d component: its tag, the file defining it and, if exported, its binding. */
|
|
17
|
+
export interface Discovered {
|
|
18
|
+
readonly tag: string;
|
|
19
|
+
/** Absolute path of the defining module. */
|
|
20
|
+
readonly file: string;
|
|
21
|
+
/** `X` in `export const X = define…`; undefined for a component that isn't exported. */
|
|
22
|
+
readonly name: string | undefined;
|
|
23
|
+
}
|
|
24
|
+
/** The components defined in one module's source text. */
|
|
25
|
+
export declare function componentsIn(code: string, file: string): Discovered[];
|
|
26
|
+
/** Every component under `dirs` (relative to `root`), in file then source order. */
|
|
27
|
+
export declare function discoverComponents(root: string, dirs: readonly string[]): Discovered[];
|
|
28
|
+
/** Every exported component under `dirs` (default `['src']`), sorted by tag. */
|
|
29
|
+
export declare function scanTags(options: TagMapOptions): TagEntry[];
|
|
30
|
+
/** The declaration file's text for `entries`, written to `outFile`. */
|
|
31
|
+
export declare function tagMapSource(entries: readonly TagEntry[], outFile: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Scans the sources and writes the declaration file when its content changed. Returns the
|
|
34
|
+
* entries and whether the file was written.
|
|
35
|
+
*/
|
|
36
|
+
export declare function writeTagMap(options: TagMapOptions): {
|
|
37
|
+
entries: TagEntry[];
|
|
38
|
+
written: boolean;
|
|
39
|
+
};
|
|
40
|
+
/** The preset's `gyral:element-types` plugin (`gyralVitePreset({ types })`). */
|
|
41
|
+
export declare function elementTypesPlugin(options: ElementTypesOptions): Plugin;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Component discovery and generated element typings (gyral-1zd.22, gyral-1zd.25). One scan of
|
|
2
|
+
// an app's sources for two-call `define<…>()('tag', …)` calls, read from the source text (not a
|
|
3
|
+
// type check), shared by automatic component loading (./components.ts) and the typings: every
|
|
4
|
+
// exported component becomes an `HTMLElementTagNameMap` entry, so apps stop hand-writing
|
|
5
|
+
// `declare global { interface HTMLElementTagNameMap { … } }` blocks. Node built-ins only, so
|
|
6
|
+
// ../vite.ts loads it with Node's require, from TypeScript source too.
|
|
7
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
8
|
+
import { dirname, join, relative, resolve, sep } from 'node:path';
|
|
9
|
+
/**
|
|
10
|
+
* A two-call `define<…>()('tag'`, optionally as `export const Name = …`: the generics (lazy,
|
|
11
|
+
* so nested `<…>` extend it), the empty call, then a string tag with a hyphen.
|
|
12
|
+
* `customElements.define(` doesn't match.
|
|
13
|
+
*/
|
|
14
|
+
const DEFINE_TAG = /(?:export\s+const\s+([A-Za-z_$][\w$]*)\s*(?::[^=;]+)?=\s*)?(?<![.\w$])define\s*(?:<[\s\S]*?>)?\s*\(\s*\)\s*\(\s*(['"`])([a-z][a-z0-9._-]*-[a-z0-9._-]*)\2/g;
|
|
15
|
+
const SOURCE_FILE = /\.[cm]?[jt]sx?$/;
|
|
16
|
+
const SKIPPED = /\.(?:test|spec|d)\.[cm]?[jt]sx?$/;
|
|
17
|
+
/** The components defined in one module's source text. */
|
|
18
|
+
export function componentsIn(code, file) {
|
|
19
|
+
if (!code.includes('define'))
|
|
20
|
+
return [];
|
|
21
|
+
const out = [];
|
|
22
|
+
for (const m of code.matchAll(DEFINE_TAG)) {
|
|
23
|
+
out.push({ tag: m[3], file, name: m[1] });
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
/** Every component under `dirs` (relative to `root`), in file then source order. */
|
|
28
|
+
export function discoverComponents(root, dirs) {
|
|
29
|
+
const found = [];
|
|
30
|
+
const walk = (dir) => {
|
|
31
|
+
let entries;
|
|
32
|
+
try {
|
|
33
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
for (const entry of entries) {
|
|
39
|
+
const path = join(dir, entry.name);
|
|
40
|
+
if (entry.isDirectory()) {
|
|
41
|
+
if (entry.name !== 'node_modules' && !entry.name.startsWith('.'))
|
|
42
|
+
walk(path);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (!SOURCE_FILE.test(entry.name) || SKIPPED.test(entry.name))
|
|
46
|
+
continue;
|
|
47
|
+
found.push(...componentsIn(readFileSync(path, 'utf8'), path));
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
for (const dir of dirs)
|
|
51
|
+
walk(resolve(root, dir));
|
|
52
|
+
return found;
|
|
53
|
+
}
|
|
54
|
+
/** Every exported component under `dirs` (default `['src']`), sorted by tag. */
|
|
55
|
+
export function scanTags(options) {
|
|
56
|
+
const entries = discoverComponents(options.root, options.dirs ?? ['src']).flatMap((c) => c.name === undefined ? [] : [{ tag: c.tag, file: c.file, name: c.name }]);
|
|
57
|
+
return entries.sort((x, y) => (x.tag < y.tag ? -1 : x.tag > y.tag ? 1 : 0));
|
|
58
|
+
}
|
|
59
|
+
/** The import specifier for `file` from `outFile`: relative, `.js` for TypeScript sources. */
|
|
60
|
+
function specifier(outFile, file) {
|
|
61
|
+
const path = relative(dirname(outFile), file).split(sep).join('/');
|
|
62
|
+
const js = path.replace(/\.tsx?$/, '.js').replace(/\.mts$/, '.mjs');
|
|
63
|
+
return js.startsWith('.') ? js : `./${js}`;
|
|
64
|
+
}
|
|
65
|
+
/** The declaration file's text for `entries`, written to `outFile`. */
|
|
66
|
+
export function tagMapSource(entries, outFile) {
|
|
67
|
+
const lines = entries.map((e) => ` ${JSON.stringify(e.tag)}: InstanceType<typeof import(${JSON.stringify(specifier(outFile, e.file))}).${e.name}>;`);
|
|
68
|
+
return ('/* eslint-disable */\n' +
|
|
69
|
+
'// Generated by @gyral/core (gyralVitePreset / gyral-types) from the define() calls in your\n' +
|
|
70
|
+
'// sources. Do not edit; gitignore .gyral/ and add ".gyral/elements.d.ts" to tsconfig "include".\n' +
|
|
71
|
+
'export {};\n\n' +
|
|
72
|
+
'declare global {\n' +
|
|
73
|
+
' interface HTMLElementTagNameMap {\n' +
|
|
74
|
+
(lines.length === 0 ? '' : `${lines.join('\n')}\n`) +
|
|
75
|
+
' }\n' +
|
|
76
|
+
'}\n');
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Scans the sources and writes the declaration file when its content changed. Returns the
|
|
80
|
+
* entries and whether the file was written.
|
|
81
|
+
*/
|
|
82
|
+
export function writeTagMap(options) {
|
|
83
|
+
const outFile = join(options.root, options.out ?? '.gyral/elements.d.ts');
|
|
84
|
+
const entries = scanTags(options);
|
|
85
|
+
const text = tagMapSource(entries, outFile);
|
|
86
|
+
if (existsSync(outFile) && readFileSync(outFile, 'utf8') === text)
|
|
87
|
+
return { entries, written: false };
|
|
88
|
+
mkdirSync(dirname(outFile), { recursive: true });
|
|
89
|
+
writeFileSync(outFile, text);
|
|
90
|
+
return { entries, written: true };
|
|
91
|
+
}
|
|
92
|
+
/** The preset's `gyral:element-types` plugin (`gyralVitePreset({ types })`). */
|
|
93
|
+
export function elementTypesPlugin(options) {
|
|
94
|
+
let root = process.cwd();
|
|
95
|
+
const regenerate = () => {
|
|
96
|
+
const settings = { root, ...options };
|
|
97
|
+
const out = join(root, options.out ?? '.gyral/elements.d.ts');
|
|
98
|
+
// A project without components gets no file.
|
|
99
|
+
if (scanTags(settings).length === 0 && !existsSync(out))
|
|
100
|
+
return;
|
|
101
|
+
writeTagMap(settings);
|
|
102
|
+
};
|
|
103
|
+
const isSource = (file) => /\.(?:ts|tsx|mts)$/.test(file) &&
|
|
104
|
+
(options.dirs ?? ['src']).some((dir) => file.startsWith(join(root, dir)));
|
|
105
|
+
return {
|
|
106
|
+
name: 'gyral:element-types',
|
|
107
|
+
configResolved(config) {
|
|
108
|
+
root = config.root;
|
|
109
|
+
},
|
|
110
|
+
buildStart() {
|
|
111
|
+
regenerate();
|
|
112
|
+
},
|
|
113
|
+
watchChange(id) {
|
|
114
|
+
if (isSource(id))
|
|
115
|
+
regenerate();
|
|
116
|
+
},
|
|
117
|
+
configureServer(server) {
|
|
118
|
+
const changed = (file) => {
|
|
119
|
+
if (isSource(file))
|
|
120
|
+
regenerate();
|
|
121
|
+
};
|
|
122
|
+
server.watcher.on('add', changed).on('change', changed).on('unlink', changed);
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=tag-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag-map.js","sourceRoot":"","sources":["../../src/compiler/tag-map.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,gGAAgG;AAChG,8FAA8F;AAC9F,yFAAyF;AACzF,6FAA6F;AAC7F,uEAAuE;AACvE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC1F,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AA4BlE;;;;GAIG;AACH,MAAM,UAAU,GACd,4JAA4J,CAAC;AAC/J,MAAM,WAAW,GAAG,iBAAiB,CAAC;AACtC,MAAM,OAAO,GAAG,kCAAkC,CAAC;AAEnD,0DAA0D;AAC1D,MAAM,UAAU,YAAY,CAAC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,CAAC;QACD,eAAe,CAAC,MAAM;YACpB,MAAM,OAAO,GAAG,CAAC,IAAY,EAAQ,EAAE;gBACrC,IAAI,QAAQ,CAAC,IAAI,CAAC;oBAAE,UAAU,EAAE,CAAC;YACnC,CAAC,CAAC;YACF,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAChF,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Component discovery and generated element typings (gyral-1zd.22, gyral-1zd.25). One scan of\n// an app's sources for two-call `define<…>()('tag', …)` calls, read from the source text (not a\n// type check), shared by automatic component loading (./components.ts) and the typings: every\n// exported component becomes an `HTMLElementTagNameMap` entry, so apps stop hand-writing\n// `declare global { interface HTMLElementTagNameMap { … } }` blocks. Node built-ins only, so\n// ../vite.ts loads it with Node's require, from TypeScript source too.\nimport { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport type { Plugin } from 'vite';\nimport type { ElementTypesOptions } from '../vite.js';\n\nexport interface TagMapOptions {\n /** Project root; `dirs` and `out` are relative to it. */\n readonly root: string;\n /** Source directories to scan, recursively. Default `['src']`. */\n readonly dirs?: readonly string[];\n /** The declaration file to write. Default `.gyral/elements.d.ts`. */\n readonly out?: string;\n}\n\nexport interface TagEntry {\n readonly tag: string;\n readonly file: string;\n readonly name: string;\n}\n\n/** One `define()`d component: its tag, the file defining it and, if exported, its binding. */\nexport interface Discovered {\n readonly tag: string;\n /** Absolute path of the defining module. */\n readonly file: string;\n /** `X` in `export const X = define…`; undefined for a component that isn't exported. */\n readonly name: string | undefined;\n}\n\n/**\n * A two-call `define<…>()('tag'`, optionally as `export const Name = …`: the generics (lazy,\n * so nested `<…>` extend it), the empty call, then a string tag with a hyphen.\n * `customElements.define(` doesn't match.\n */\nconst DEFINE_TAG =\n /(?:export\\s+const\\s+([A-Za-z_$][\\w$]*)\\s*(?::[^=;]+)?=\\s*)?(?<![.\\w$])define\\s*(?:<[\\s\\S]*?>)?\\s*\\(\\s*\\)\\s*\\(\\s*(['\"`])([a-z][a-z0-9._-]*-[a-z0-9._-]*)\\2/g;\nconst SOURCE_FILE = /\\.[cm]?[jt]sx?$/;\nconst SKIPPED = /\\.(?:test|spec|d)\\.[cm]?[jt]sx?$/;\n\n/** The components defined in one module's source text. */\nexport function componentsIn(code: string, file: string): Discovered[] {\n if (!code.includes('define')) return [];\n const out: Discovered[] = [];\n for (const m of code.matchAll(DEFINE_TAG)) {\n out.push({ tag: m[3] as string, file, name: m[1] });\n }\n return out;\n}\n\n/** Every component under `dirs` (relative to `root`), in file then source order. */\nexport function discoverComponents(root: string, dirs: readonly string[]): Discovered[] {\n const found: Discovered[] = [];\n const walk = (dir: string): void => {\n let entries;\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n return;\n }\n for (const entry of entries) {\n const path = join(dir, entry.name);\n if (entry.isDirectory()) {\n if (entry.name !== 'node_modules' && !entry.name.startsWith('.')) walk(path);\n continue;\n }\n if (!SOURCE_FILE.test(entry.name) || SKIPPED.test(entry.name)) continue;\n found.push(...componentsIn(readFileSync(path, 'utf8'), path));\n }\n };\n for (const dir of dirs) walk(resolve(root, dir));\n return found;\n}\n\n/** Every exported component under `dirs` (default `['src']`), sorted by tag. */\nexport function scanTags(options: TagMapOptions): TagEntry[] {\n const entries = discoverComponents(options.root, options.dirs ?? ['src']).flatMap((c) =>\n c.name === undefined ? [] : [{ tag: c.tag, file: c.file, name: c.name }],\n );\n return entries.sort((x, y) => (x.tag < y.tag ? -1 : x.tag > y.tag ? 1 : 0));\n}\n\n/** The import specifier for `file` from `outFile`: relative, `.js` for TypeScript sources. */\nfunction specifier(outFile: string, file: string): string {\n const path = relative(dirname(outFile), file).split(sep).join('/');\n const js = path.replace(/\\.tsx?$/, '.js').replace(/\\.mts$/, '.mjs');\n return js.startsWith('.') ? js : `./${js}`;\n}\n\n/** The declaration file's text for `entries`, written to `outFile`. */\nexport function tagMapSource(entries: readonly TagEntry[], outFile: string): string {\n const lines = entries.map(\n (e) =>\n ` ${JSON.stringify(e.tag)}: InstanceType<typeof import(${JSON.stringify(specifier(outFile, e.file))}).${e.name}>;`,\n );\n return (\n '/* eslint-disable */\\n' +\n '// Generated by @gyral/core (gyralVitePreset / gyral-types) from the define() calls in your\\n' +\n '// sources. Do not edit; gitignore .gyral/ and add \".gyral/elements.d.ts\" to tsconfig \"include\".\\n' +\n 'export {};\\n\\n' +\n 'declare global {\\n' +\n ' interface HTMLElementTagNameMap {\\n' +\n (lines.length === 0 ? '' : `${lines.join('\\n')}\\n`) +\n ' }\\n' +\n '}\\n'\n );\n}\n\n/**\n * Scans the sources and writes the declaration file when its content changed. Returns the\n * entries and whether the file was written.\n */\nexport function writeTagMap(options: TagMapOptions): { entries: TagEntry[]; written: boolean } {\n const outFile = join(options.root, options.out ?? '.gyral/elements.d.ts');\n const entries = scanTags(options);\n const text = tagMapSource(entries, outFile);\n if (existsSync(outFile) && readFileSync(outFile, 'utf8') === text)\n return { entries, written: false };\n mkdirSync(dirname(outFile), { recursive: true });\n writeFileSync(outFile, text);\n return { entries, written: true };\n}\n\n/** The preset's `gyral:element-types` plugin (`gyralVitePreset({ types })`). */\nexport function elementTypesPlugin(options: ElementTypesOptions): Plugin {\n let root = process.cwd();\n const regenerate = (): void => {\n const settings = { root, ...options };\n const out = join(root, options.out ?? '.gyral/elements.d.ts');\n // A project without components gets no file.\n if (scanTags(settings).length === 0 && !existsSync(out)) return;\n writeTagMap(settings);\n };\n const isSource = (file: string): boolean =>\n /\\.(?:ts|tsx|mts)$/.test(file) &&\n (options.dirs ?? ['src']).some((dir) => file.startsWith(join(root, dir)));\n return {\n name: 'gyral:element-types',\n configResolved(config) {\n root = config.root;\n },\n buildStart() {\n regenerate();\n },\n watchChange(id) {\n if (isSource(id)) regenerate();\n },\n configureServer(server) {\n const changed = (file: string): void => {\n if (isSource(file)) regenerate();\n };\n server.watcher.on('add', changed).on('change', changed).on('unlink', changed);\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves once every rendered tag the component loader knows (in the document and in the
|
|
3
|
+
* shadow roots of components it defined) is defined, and the page has settled. Await it in
|
|
4
|
+
* browser tests and page scripts after the loader has run (page scripts placed after it; in
|
|
5
|
+
* tests, import `virtual:gyral/components` first).
|
|
6
|
+
*/
|
|
7
|
+
export declare function componentsReady(): Promise<void>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// `componentsReady()` (ADR 0016 "Automatic components"): wait until the components the page
|
|
2
|
+
// renders are defined and have rendered. The loader that gyralVitePreset({ components: true })
|
|
3
|
+
// generates registers itself under a well-known symbol; without it (no automatic components,
|
|
4
|
+
// or a server render) this is just `settled()`.
|
|
5
|
+
import { settled } from './settled.js';
|
|
6
|
+
const KEY = Symbol.for('gyral.components');
|
|
7
|
+
/**
|
|
8
|
+
* Resolves once every rendered tag the component loader knows (in the document and in the
|
|
9
|
+
* shadow roots of components it defined) is defined, and the page has settled. Await it in
|
|
10
|
+
* browser tests and page scripts after the loader has run (page scripts placed after it; in
|
|
11
|
+
* tests, import `virtual:gyral/components` first).
|
|
12
|
+
*/
|
|
13
|
+
export async function componentsReady() {
|
|
14
|
+
const loader = globalThis[KEY];
|
|
15
|
+
if (loader !== undefined)
|
|
16
|
+
await loader.ready();
|
|
17
|
+
await settled();
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=components-ready.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components-ready.js","sourceRoot":"","sources":["../src/components-ready.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,+FAA+F;AAC/F,6FAA6F;AAC7F,gDAAgD;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAMvC,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,MAAM,MAAM,GAAI,UAA0C,CAAC,GAAG,CAAC,CAAC;IAChE,IAAI,MAAM,KAAK,SAAS;QAAE,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IAC/C,MAAM,OAAO,EAAE,CAAC;AAClB,CAAC","sourcesContent":["// `componentsReady()` (ADR 0016 \"Automatic components\"): wait until the components the page\n// renders are defined and have rendered. The loader that gyralVitePreset({ components: true })\n// generates registers itself under a well-known symbol; without it (no automatic components,\n// or a server render) this is just `settled()`.\nimport { settled } from './settled.js';\n\ninterface ComponentLoader {\n readonly ready: () => Promise<void>;\n}\n\nconst KEY = Symbol.for('gyral.components');\n\n/**\n * Resolves once every rendered tag the component loader knows (in the document and in the\n * shadow roots of components it defined) is defined, and the page has settled. Await it in\n * browser tests and page scripts after the loader has run (page scripts placed after it; in\n * tests, import `virtual:gyral/components` first).\n */\nexport async function componentsReady(): Promise<void> {\n const loader = (globalThis as { [KEY]?: ComponentLoader })[KEY];\n if (loader !== undefined) await loader.ready();\n await settled();\n}\n"]}
|
package/dist/define.d.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import type { GyralElementClass } from './element-types.js';
|
|
2
2
|
import type { ComponentSpec, Tagged } from './types.js';
|
|
3
3
|
export type { GyralElement, GyralElementClass } from './element-types.js';
|
|
4
|
+
/** The second call of `define()`: takes the tag and the spec, infers the intent names. */
|
|
5
|
+
export type Definer<S, M extends Tagged, P extends object, O extends Tagged> = <N extends string = never>(tag: string, spec: ComponentSpec<S, M, P, N>) => GyralElementClass<S, M, P, O, N>;
|
|
4
6
|
/**
|
|
5
|
-
* Compiles a Model-View-Intent spec into a custom element and registers it under `tag`.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
7
|
+
* Compiles a Model-View-Intent spec into a custom element and registers it under `tag`. Two
|
|
8
|
+
* calls (ADR 0023): the first takes the types, the second the tag and spec, from whose
|
|
9
|
+
* `intent` keys it infers the component's intent names.
|
|
10
|
+
*
|
|
11
|
+
* define<State, Msg>()('x-counter', { init, intent: { Increment: … }, update, view })
|
|
12
|
+
*
|
|
13
|
+
* With no type arguments, `define()('x-badge', spec)` infers the state, messages, props and
|
|
14
|
+
* intent names from the spec. See docs/design-docs/0001-mvi-parsed-intent.md,
|
|
15
|
+
* 0006-effects-and-drivers.md, 0007-props.md, 0008-forms.md and view/05-element.md.
|
|
8
16
|
*/
|
|
9
|
-
export declare function define<S, M extends Tagged, P extends object = object,
|
|
17
|
+
export declare function define(): <S, M extends Tagged = never, P extends object = object, N extends string = never>(tag: string, spec: ComponentSpec<S, M, P, N>) => GyralElementClass<S, M, P, never, N>;
|
|
18
|
+
export declare function define<S, M extends Tagged = never, P extends object = object, O extends Tagged = never>(): Definer<S, M, P, O>;
|