@gyral/core 0.3.0 → 0.3.2
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 +57 -0
- package/NOTICE +19 -0
- package/README.md +36 -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 +25 -3
- package/dist/children.js +18 -1
- 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 +25 -11
- package/dist/command.js.map +1 -1
- package/dist/compiler/ast.d.ts +2 -0
- package/dist/compiler/ast.js +5 -1
- package/dist/compiler/ast.js.map +1 -1
- package/dist/compiler/compile.d.ts +5 -2
- package/dist/compiler/compile.js +36 -17
- package/dist/compiler/compile.js.map +1 -1
- 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 +190 -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 +4 -0
- package/dist/compiler/hooks.js +144 -89
- package/dist/compiler/hooks.js.map +1 -1
- 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 +90 -0
- package/dist/compiler/locate.js.map +1 -0
- package/dist/compiler/parse5-check.d.ts +1 -1
- package/dist/compiler/parse5-check.js +8 -3
- package/dist/compiler/parse5-check.js.map +1 -1
- 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 +13 -3
- package/dist/compiler/scan.js +21 -13
- package/dist/compiler/scan.js.map +1 -1
- 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/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 +12 -4
- package/dist/define.js +8 -12
- package/dist/define.js.map +1 -1
- package/dist/devtools-events.d.ts +8 -0
- package/dist/devtools-events.js.map +1 -1
- package/dist/devtools-off.d.ts +1 -0
- package/dist/devtools-off.js +1 -0
- package/dist/devtools-off.js.map +1 -1
- package/dist/devtools.d.ts +3 -0
- package/dist/devtools.js +14 -0
- package/dist/devtools.js.map +1 -1
- 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 +7 -4
- package/dist/element-types.js.map +1 -1
- package/dist/element.js +80 -27
- package/dist/element.js.map +1 -1
- 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 +2 -0
- package/dist/eslint/imports.js +2 -2
- package/dist/eslint/imports.js.map +1 -1
- package/dist/eslint/index.d.ts +2 -1
- package/dist/eslint/index.js +11 -3
- package/dist/eslint/index.js.map +1 -1
- package/dist/eslint/template-rule.d.ts +1 -0
- package/dist/eslint/template-rule.js +15 -5
- package/dist/eslint/template-rule.js.map +1 -1
- 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 +2 -2
- package/dist/features.js.map +1 -1
- package/dist/focus.d.ts +6 -0
- package/dist/focus.js +32 -2
- 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/host-model.d.ts +34 -5
- package/dist/host-model.js +146 -23
- package/dist/host-model.js.map +1 -1
- package/dist/hydration-client.js +2 -2
- package/dist/hydration-client.js.map +1 -1
- 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 +0 -12
- package/dist/hydration.js +3 -52
- package/dist/hydration.js.map +1 -1
- package/dist/index.d.ts +21 -24
- package/dist/index.js +10 -19
- 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 +42 -20
- package/dist/intent.js +145 -107
- 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 +12 -4
- package/dist/internal/interpreter.js +36 -48
- 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/light-dom.d.ts +1 -1
- package/dist/light-dom.js.map +1 -1
- package/dist/prop.d.ts +30 -7
- package/dist/prop.js +19 -0
- package/dist/prop.js.map +1 -1
- package/dist/props.d.ts +8 -3
- package/dist/props.js +22 -15
- 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 +7 -3
- package/dist/scheduler.js +38 -56
- package/dist/scheduler.js.map +1 -1
- 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 +1 -1
- package/dist/server-component.js +45 -14
- package/dist/server-component.js.map +1 -1
- package/dist/server.d.ts +9 -3
- package/dist/server.js +12 -3
- package/dist/server.js.map +1 -1
- package/dist/settled.d.ts +4 -3
- package/dist/settled.js +48 -26
- package/dist/settled.js.map +1 -1
- 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 -8
- 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.js +2 -2
- package/dist/store-binding.js.map +1 -1
- package/dist/store-scope.d.ts +2 -4
- package/dist/store-scope.js +6 -16
- package/dist/store-scope.js.map +1 -1
- package/dist/store.d.ts +2 -6
- package/dist/store.js +36 -8
- package/dist/store.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 +4 -5
- package/dist/transitions.js +10 -4
- package/dist/transitions.js.map +1 -1
- package/dist/types.d.ts +141 -32
- 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 +5 -0
- package/dist/view/attributes.js +5 -0
- package/dist/view/attributes.js.map +1 -1
- package/dist/view/compiled.d.ts +1 -1
- package/dist/view/compiled.js +1 -1
- package/dist/view/compiled.js.map +1 -1
- package/dist/view/index.d.ts +9 -4
- package/dist/view/index.js +9 -3
- package/dist/view/index.js.map +1 -1
- 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 +5 -2
- package/dist/view/normalize/check.js +6 -3
- package/dist/view/normalize/check.js.map +1 -1
- package/dist/view/normalize/emit.d.ts +2 -0
- package/dist/view/normalize/emit.js +40 -11
- package/dist/view/normalize/emit.js.map +1 -1
- package/dist/view/normalize/errors.js +1 -1
- package/dist/view/normalize/errors.js.map +1 -1
- package/dist/view/normalize/id.d.ts +5 -2
- package/dist/view/normalize/id.js +9 -2
- package/dist/view/normalize/id.js.map +1 -1
- package/dist/view/normalize/normalize.d.ts +7 -4
- package/dist/view/normalize/normalize.js +15 -9
- package/dist/view/normalize/normalize.js.map +1 -1
- package/dist/view/normalize/rules.d.ts +9 -0
- package/dist/view/normalize/rules.js +35 -5
- package/dist/view/normalize/rules.js.map +1 -1
- 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/tokens.d.ts +5 -1
- package/dist/view/normalize/tokens.js.map +1 -1
- package/dist/view/normalize/tree.d.ts +8 -2
- package/dist/view/normalize/tree.js +58 -13
- package/dist/view/normalize/tree.js.map +1 -1
- package/dist/view/normalize/types.d.ts +24 -4
- package/dist/view/normalize/types.js +4 -1
- package/dist/view/normalize/types.js.map +1 -1
- package/dist/view/normalize/whitespace.js +4 -3
- package/dist/view/normalize/whitespace.js.map +1 -1
- package/dist/view/prepare-stub.js +2 -2
- package/dist/view/prepare-stub.js.map +1 -1
- package/dist/view/prepare.d.ts +5 -2
- package/dist/view/prepare.js +9 -3
- package/dist/view/prepare.js.map +1 -1
- package/dist/view/registry.d.ts +15 -0
- package/dist/view/registry.js +10 -2
- package/dist/view/registry.js.map +1 -1
- package/dist/view/render/adopt-attr.js +7 -1
- package/dist/view/render/adopt-attr.js.map +1 -1
- package/dist/view/render/adopt.js +21 -4
- package/dist/view/render/adopt.js.map +1 -1
- package/dist/view/render/attr-parts.d.ts +12 -1
- package/dist/view/render/attr-parts.js +38 -5
- package/dist/view/render/attr-parts.js.map +1 -1
- package/dist/view/render/child-part.js +5 -2
- package/dist/view/render/child-part.js.map +1 -1
- 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 +3 -1
- package/dist/view/render/hook-part.js +21 -5
- package/dist/view/render/hook-part.js.map +1 -1
- 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 +74 -6
- package/dist/view/render/hooks.js +79 -17
- package/dist/view/render/hooks.js.map +1 -1
- package/dist/view/render/hydrate.js +2 -2
- package/dist/view/render/hydrate.js.map +1 -1
- 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 +1 -1
- package/dist/view/render/list.js.map +1 -1
- package/dist/view/render/mismatch.js +5 -3
- package/dist/view/render/mismatch.js.map +1 -1
- 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/raw.d.ts +4 -1
- package/dist/view/render/raw.js +6 -2
- package/dist/view/render/raw.js.map +1 -1
- package/dist/view/render/render.d.ts +4 -1
- package/dist/view/render/render.js +17 -12
- package/dist/view/render/render.js.map +1 -1
- 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 +1 -1
- package/dist/view/render/values.js.map +1 -1
- package/dist/view/render/warn.d.ts +14 -0
- package/dist/view/render/warn.js +45 -0
- package/dist/view/render/warn.js.map +1 -1
- package/dist/view/server/component.d.ts +6 -3
- package/dist/view/server/component.js +29 -7
- package/dist/view/server/component.js.map +1 -1
- package/dist/view/server/index.d.ts +20 -0
- package/dist/view/server/index.js +12 -4
- package/dist/view/server/index.js.map +1 -1
- package/dist/view/server/tags.d.ts +13 -2
- package/dist/view/server/tags.js +13 -2
- package/dist/view/server/tags.js.map +1 -1
- package/dist/view/server/values.d.ts +2 -0
- package/dist/view/server/values.js +8 -0
- package/dist/view/server/values.js.map +1 -1
- package/dist/view/server/writer.d.ts +9 -4
- package/dist/view/server/writer.js +33 -18
- package/dist/view/server/writer.js.map +1 -1
- package/dist/view/template-element.d.ts +7 -0
- package/dist/view/template-element.js +25 -5
- package/dist/view/template-element.js.map +1 -1
- package/dist/view/template.d.ts +9 -2
- package/dist/view/template.js +61 -8
- package/dist/view/template.js.map +1 -1
- 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 +38 -31
- package/dist/vite.js +206 -31
- package/dist/vite.js.map +1 -1
- package/package.json +34 -3
- package/dist/hooks/labelled-by.d.ts +0 -13
- package/dist/hooks/labelled-by.js +0 -51
- package/dist/hooks/labelled-by.js.map +0 -1
- package/dist/random.d.ts +0 -13
- package/dist/random.js +0 -19
- package/dist/random.js.map +0 -1
|
@@ -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,IAAY,EAAE,IAAY;IACrD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,EAAE,CAAC;IACxC,MAAM,GAAG,GAAiB,EAAE,CAAC;IAC7B,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1C,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC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AC,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,17 @@
|
|
|
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. Guide: https://gyral.dev/docs/components/
|
|
8
15
|
*/
|
|
9
|
-
export declare function define<S, M extends Tagged, P extends object = object,
|
|
16
|
+
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>;
|
|
17
|
+
export declare function define<S, M extends Tagged = never, P extends object = object, O extends Tagged = never>(): Definer<S, M, P, O>;
|
package/dist/define.js
CHANGED
|
@@ -3,7 +3,7 @@ import { markGyralHost } from './intent.js';
|
|
|
3
3
|
import { isLight } from './light-dom.js';
|
|
4
4
|
import { features } from './features.js';
|
|
5
5
|
import { recordSpec } from './server-specs.js';
|
|
6
|
-
import { DEV } from './view/index.js';
|
|
6
|
+
import { DEV, message } from './view/index.js';
|
|
7
7
|
function checkSpec(tag, spec) {
|
|
8
8
|
const names = Object.keys(spec.props ?? {});
|
|
9
9
|
// The prop builders registered the prop feature (features.ts) if there are props.
|
|
@@ -13,22 +13,19 @@ function checkSpec(tag, spec) {
|
|
|
13
13
|
console.warn(`<${tag}> has shadow: false, so its styles are ignored; use document CSS.`);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export function define(tag, spec) {
|
|
16
|
+
// One function serves both call forms; the overloads type the result.
|
|
17
|
+
export function define() {
|
|
18
|
+
return defineElement;
|
|
19
|
+
}
|
|
20
|
+
function defineElement(tag, spec) {
|
|
22
21
|
checkSpec(tag, spec);
|
|
23
22
|
if (typeof HTMLElement === 'undefined') {
|
|
24
23
|
// No DOM (Node, Workers): the server renderer renders the spec itself (Phase 4). Only the
|
|
25
24
|
// spec is recorded here, so the server registry code never reaches client bundles.
|
|
26
25
|
recordSpec(tag, spec);
|
|
27
|
-
|
|
28
|
-
throw new Error(
|
|
26
|
+
return Object.assign(function Placeholder() {
|
|
27
|
+
throw new Error(message(1, tag));
|
|
29
28
|
}, { spec, tagName: tag });
|
|
30
|
-
// Sound enough: outside the browser the class only carries `spec` and `tagName`.
|
|
31
|
-
return Placeholder;
|
|
32
29
|
}
|
|
33
30
|
const existing = customElements.get(tag);
|
|
34
31
|
if (existing !== undefined) {
|
|
@@ -40,7 +37,6 @@ export function define(tag, spec) {
|
|
|
40
37
|
const Element = elementClass(tag, spec);
|
|
41
38
|
markGyralHost(Element);
|
|
42
39
|
customElements.define(tag, Element);
|
|
43
|
-
// Sound: every declared prop is an accessor on the prototype.
|
|
44
40
|
return Element;
|
|
45
41
|
}
|
|
46
42
|
//# sourceMappingURL=define.js.map
|
package/dist/define.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.js","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAU/C,SAAS,SAAS,CAAC,GAAW,EAAE,IAAe;IAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IAC5C,kFAAkF;IAClF,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAChE,IAAI,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACtD,OAAO,CAAC,IAAI,CAAC,IAAI,GAAG,mEAAmE,CAAC,CAAC;IAC3F,CAAC;AACH,CAAC;AAoCD,sEAAsE;AACtE,MAAM,UAAU,MAAM;IACpB,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,SAAS,aAAa,CAAC,GAAW,EAAE,IAA4C;IAC9E,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACrB,IAAI,OAAO,WAAW,KAAK,WAAW,EAAE,CAAC;QACvC,0FAA0F;QAC1F,mFAAmF;QACnF,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACtB,OAAO,MAAM,CAAC,MAAM,CAClB,SAAS,WAAW;YAClB,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QACnC,CAAC,EACD,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CACvB,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,IAAI,GAAG,IAAK,QAAwC,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YACnE,OAAO,CAAC,IAAI,CAAC,IAAI,GAAG,gEAAgE,CAAC,CAAC;QACxF,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,MAAM,OAAO,GAAG,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACxC,aAAa,CAAC,OAAO,CAAC,CAAC;IACvB,cAAc,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACpC,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["// `define<S, M>()(tag, spec)` (docs/design-docs/view/05-element.md, ADR 0023): compiles a\n// Model-View-Intent spec into a custom element and registers it. Outside the browser it\n// records the spec in the server registry instead (view/06-server.md) and returns a\n// placeholder class.\nimport type { GyralElementClass } from './element-types.js';\nimport { elementClass } from './element.js';\nimport { markGyralHost } from './intent.js';\nimport { isLight } from './light-dom.js';\nimport { features } from './features.js';\nimport { recordSpec } from './server-specs.js';\nimport type { ComponentSpec, ShadowOption, Tagged } from './types.js';\nimport { DEV, message } from './view/index.js';\n\nexport type { GyralElement, GyralElementClass } from './element-types.js';\n\ninterface SpecShape {\n readonly props?: object;\n readonly shadow?: ShadowOption;\n readonly styles?: unknown;\n}\n\nfunction checkSpec(tag: string, spec: SpecShape): void {\n const names = Object.keys(spec.props ?? {});\n // The prop builders registered the prop feature (features.ts) if there are props.\n if (names.length > 0) features.props?.checkShadowed(tag, names);\n if (DEV && isLight(spec) && spec.styles !== undefined) {\n console.warn(`<${tag}> has shadow: false, so its styles are ignored; use document CSS.`);\n }\n}\n\n/** The second call of `define()`: takes the tag and the spec, infers the intent names. */\nexport type Definer<S, M extends Tagged, P extends object, O extends Tagged> = <\n N extends string = never,\n>(\n tag: string,\n spec: ComponentSpec<S, M, P, N>,\n) => GyralElementClass<S, M, P, O, N>;\n\n/**\n * Compiles a Model-View-Intent spec into a custom element and registers it under `tag`. Two\n * calls (ADR 0023): the first takes the types, the second the tag and spec, from whose\n * `intent` keys it infers the component's intent names.\n *\n * define<State, Msg>()('x-counter', { init, intent: { Increment: … }, update, view })\n *\n * With no type arguments, `define()('x-badge', spec)` infers the state, messages, props and\n * intent names from the spec. Guide: https://gyral.dev/docs/components/\n */\nexport function define(): <\n S,\n M extends Tagged = never,\n P extends object = object,\n N extends string = never,\n>(\n tag: string,\n spec: ComponentSpec<S, M, P, N>,\n) => GyralElementClass<S, M, P, never, N>;\nexport function define<\n S,\n // No messages: `define<State>()` for a pure view (intent and update optional).\n M extends Tagged = never,\n P extends object = object,\n O extends Tagged = never,\n>(): Definer<S, M, P, O>;\n// One function serves both call forms; the overloads type the result.\nexport function define(): (tag: string, spec: never) => unknown {\n return defineElement;\n}\n\nfunction defineElement(tag: string, spec: ComponentSpec<unknown, Tagged, object>): unknown {\n checkSpec(tag, spec);\n if (typeof HTMLElement === 'undefined') {\n // No DOM (Node, Workers): the server renderer renders the spec itself (Phase 4). Only the\n // spec is recorded here, so the server registry code never reaches client bundles.\n recordSpec(tag, spec);\n return Object.assign(\n function Placeholder(): never {\n throw new Error(message(1, tag));\n },\n { spec, tagName: tag },\n );\n }\n const existing = customElements.get(tag);\n if (existing !== undefined) {\n if (DEV && (existing as { readonly spec?: unknown }).spec !== spec) {\n console.warn(`<${tag}> is already defined with a different spec; keeping the first.`);\n }\n return existing;\n }\n const Element = elementClass(tag, spec);\n markGyralHost(Element);\n customElements.define(tag, Element);\n return Element;\n}\n"]}
|
|
@@ -44,6 +44,14 @@ export type DevEvent = {
|
|
|
44
44
|
readonly kind: 'command';
|
|
45
45
|
readonly owner: string;
|
|
46
46
|
} & CommandTraceEvent) | {
|
|
47
|
+
/** A failure Gyral caught (ADR 0024): `component` is absent for stores and shared work. */
|
|
48
|
+
readonly kind: 'error';
|
|
49
|
+
readonly component?: DevComponentRef;
|
|
50
|
+
readonly phase: string;
|
|
51
|
+
readonly msg?: string;
|
|
52
|
+
readonly message: string;
|
|
53
|
+
readonly error: unknown;
|
|
54
|
+
} | {
|
|
47
55
|
readonly kind: 'store';
|
|
48
56
|
readonly store: string;
|
|
49
57
|
readonly msg: Tagged;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools-events.js","sourceRoot":"","sources":["../src/devtools-events.ts"],"names":[],"mappings":"AAKA,oFAAoF;AACpF,MAAM,CAAC,MAAM,eAAe,GAAG,oBAAoB,CAAC","sourcesContent":["// The devtools event stream (ADR 0017). Types and the global hook name only: the emitting code\n// lives in devtools.ts (development builds) and devtools-off.ts (production builds).\nimport type { Concurrency } from './command.js';\nimport type { Tagged } from './types.js';\n\n/** Where a listener installs itself: `globalThis.__GYRAL_DEVTOOLS__ = { emit }`. */\nexport const DEVTOOLS_GLOBAL = '__GYRAL_DEVTOOLS__';\n\n/** A live component, identified for the timeline. `element` gives the panel its state. */\nexport interface DevComponentRef {\n readonly tag: string;\n readonly id: number;\n readonly element: Element;\n}\n\nexport type CommandPhase = 'issued' | 'dropped' | 'settled' | 'failed' | 'interrupted';\n\n/** What the interpreter reports about one command (ADR 0006 lanes and policies). */\nexport interface CommandTraceEvent {\n readonly phase: CommandPhase;\n readonly driver: string;\n readonly lane: string;\n readonly policy: Concurrency;\n readonly input: unknown;\n /** Driver output (`settled`) or error (`failed`). */\n readonly result?: unknown;\n}\n\nexport type CommandTrace = (event: CommandTraceEvent) => void;\n\nexport type DevEvent = { readonly at: number } & (\n | { readonly kind: 'connect' | 'disconnect'; readonly component: DevComponentRef }\n | {\n readonly kind: 'update';\n readonly component: DevComponentRef;\n readonly msg: Tagged;\n readonly prev: unknown;\n readonly next: unknown;\n }\n | {\n readonly kind: 'hydrated';\n readonly component: DevComponentRef;\n readonly serverRendered: boolean;\n }\n | {\n /** The server DOM didn't match the first render (view/07-hydration.md \"Mismatches\"). */\n readonly kind: 'mismatch';\n readonly component: DevComponentRef;\n readonly message: string;\n }\n | ({ readonly kind: 'command'; readonly owner: string } & CommandTraceEvent)\n | {\n readonly kind: 'store';\n readonly store: string;\n readonly msg: Tagged;\n readonly prev: unknown;\n readonly next: unknown;\n }\n);\n\n/** Installed by a devtools panel (or a test) on `globalThis[DEVTOOLS_GLOBAL]`. */\nexport interface DevtoolsHook {\n emit(event: DevEvent): void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"devtools-events.js","sourceRoot":"","sources":["../src/devtools-events.ts"],"names":[],"mappings":"AAKA,oFAAoF;AACpF,MAAM,CAAC,MAAM,eAAe,GAAG,oBAAoB,CAAC","sourcesContent":["// The devtools event stream (ADR 0017). Types and the global hook name only: the emitting code\n// lives in devtools.ts (development builds) and devtools-off.ts (production builds).\nimport type { Concurrency } from './command.js';\nimport type { Tagged } from './types.js';\n\n/** Where a listener installs itself: `globalThis.__GYRAL_DEVTOOLS__ = { emit }`. */\nexport const DEVTOOLS_GLOBAL = '__GYRAL_DEVTOOLS__';\n\n/** A live component, identified for the timeline. `element` gives the panel its state. */\nexport interface DevComponentRef {\n readonly tag: string;\n readonly id: number;\n readonly element: Element;\n}\n\nexport type CommandPhase = 'issued' | 'dropped' | 'settled' | 'failed' | 'interrupted';\n\n/** What the interpreter reports about one command (ADR 0006 lanes and policies). */\nexport interface CommandTraceEvent {\n readonly phase: CommandPhase;\n readonly driver: string;\n readonly lane: string;\n readonly policy: Concurrency;\n readonly input: unknown;\n /** Driver output (`settled`) or error (`failed`). */\n readonly result?: unknown;\n}\n\nexport type CommandTrace = (event: CommandTraceEvent) => void;\n\nexport type DevEvent = { readonly at: number } & (\n | { readonly kind: 'connect' | 'disconnect'; readonly component: DevComponentRef }\n | {\n readonly kind: 'update';\n readonly component: DevComponentRef;\n readonly msg: Tagged;\n readonly prev: unknown;\n readonly next: unknown;\n }\n | {\n readonly kind: 'hydrated';\n readonly component: DevComponentRef;\n readonly serverRendered: boolean;\n }\n | {\n /** The server DOM didn't match the first render (view/07-hydration.md \"Mismatches\"). */\n readonly kind: 'mismatch';\n readonly component: DevComponentRef;\n readonly message: string;\n }\n | ({ readonly kind: 'command'; readonly owner: string } & CommandTraceEvent)\n | {\n /** A failure Gyral caught (ADR 0024): `component` is absent for stores and shared work. */\n readonly kind: 'error';\n readonly component?: DevComponentRef;\n readonly phase: string;\n readonly msg?: string;\n readonly message: string;\n readonly error: unknown;\n }\n | {\n readonly kind: 'store';\n readonly store: string;\n readonly msg: Tagged;\n readonly prev: unknown;\n readonly next: unknown;\n }\n);\n\n/** Installed by a devtools panel (or a test) on `globalThis[DEVTOOLS_GLOBAL]`. */\nexport interface DevtoolsHook {\n emit(event: DevEvent): void;\n}\n"]}
|
package/dist/devtools-off.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const devUpdate: typeof Dev.devUpdate;
|
|
|
5
5
|
export declare const devHydrated: typeof Dev.devHydrated;
|
|
6
6
|
export declare const devMismatch: typeof Dev.devMismatch;
|
|
7
7
|
export declare const devStore: typeof Dev.devStore;
|
|
8
|
+
export declare const devError: typeof Dev.devError;
|
|
8
9
|
export declare const devCommands: typeof Dev.devCommands;
|
|
9
10
|
export declare const devOwner: typeof Dev.devOwner;
|
|
10
11
|
export declare const devLiveComponents: typeof Dev.devLiveComponents;
|
package/dist/devtools-off.js
CHANGED
|
@@ -5,6 +5,7 @@ export const devUpdate = noop;
|
|
|
5
5
|
export const devHydrated = noop;
|
|
6
6
|
export const devMismatch = noop;
|
|
7
7
|
export const devStore = noop;
|
|
8
|
+
export const devError = noop;
|
|
8
9
|
export const devCommands = () => noop;
|
|
9
10
|
export const devOwner = () => '';
|
|
10
11
|
export const devLiveComponents = () => [];
|
package/dist/devtools-off.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools-off.js","sourceRoot":"","sources":["../src/devtools-off.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,gBAAgB,GAAY,KAAK,CAAC;AAE/C,MAAM,IAAI,GAAG,GAAS,EAAE,CAAC,SAAS,CAAC;AAEnC,MAAM,CAAC,MAAM,UAAU,GAA0B,IAAI,CAAC;AACtD,MAAM,CAAC,MAAM,SAAS,GAAyB,IAAI,CAAC;AACpD,MAAM,CAAC,MAAM,WAAW,GAA2B,IAAI,CAAC;AACxD,MAAM,CAAC,MAAM,WAAW,GAA2B,IAAI,CAAC;AACxD,MAAM,CAAC,MAAM,QAAQ,GAAwB,IAAI,CAAC;AAClD,MAAM,CAAC,MAAM,WAAW,GAA2B,GAAG,EAAE,CAAC,IAAI,CAAC;AAC9D,MAAM,CAAC,MAAM,QAAQ,GAAwB,GAAG,EAAE,CAAC,EAAE,CAAC;AACtD,MAAM,CAAC,MAAM,iBAAiB,GAAiC,GAAG,EAAE,CAAC,EAAE,CAAC","sourcesContent":["// Production build of the devtools hook (ADR 0017): the same names as devtools.ts, doing\n// nothing. Call sites guard with DEVTOOLS_ENABLED, a literal `false` here, so bundlers drop\n// them entirely. The `typeof Dev.x` annotations keep both modules' signatures in sync.\nimport type * as Dev from './devtools.js';\n\nexport const DEVTOOLS_ENABLED: boolean = false;\n\nconst noop = (): void => undefined;\n\nexport const devConnect: typeof Dev.devConnect = noop;\nexport const devUpdate: typeof Dev.devUpdate = noop;\nexport const devHydrated: typeof Dev.devHydrated = noop;\nexport const devMismatch: typeof Dev.devMismatch = noop;\nexport const devStore: typeof Dev.devStore = noop;\nexport const devCommands: typeof Dev.devCommands = () => noop;\nexport const devOwner: typeof Dev.devOwner = () => '';\nexport const devLiveComponents: typeof Dev.devLiveComponents = () => [];\n"]}
|
|
1
|
+
{"version":3,"file":"devtools-off.js","sourceRoot":"","sources":["../src/devtools-off.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,gBAAgB,GAAY,KAAK,CAAC;AAE/C,MAAM,IAAI,GAAG,GAAS,EAAE,CAAC,SAAS,CAAC;AAEnC,MAAM,CAAC,MAAM,UAAU,GAA0B,IAAI,CAAC;AACtD,MAAM,CAAC,MAAM,SAAS,GAAyB,IAAI,CAAC;AACpD,MAAM,CAAC,MAAM,WAAW,GAA2B,IAAI,CAAC;AACxD,MAAM,CAAC,MAAM,WAAW,GAA2B,IAAI,CAAC;AACxD,MAAM,CAAC,MAAM,QAAQ,GAAwB,IAAI,CAAC;AAClD,MAAM,CAAC,MAAM,QAAQ,GAAwB,IAAI,CAAC;AAClD,MAAM,CAAC,MAAM,WAAW,GAA2B,GAAG,EAAE,CAAC,IAAI,CAAC;AAC9D,MAAM,CAAC,MAAM,QAAQ,GAAwB,GAAG,EAAE,CAAC,EAAE,CAAC;AACtD,MAAM,CAAC,MAAM,iBAAiB,GAAiC,GAAG,EAAE,CAAC,EAAE,CAAC","sourcesContent":["// Production build of the devtools hook (ADR 0017): the same names as devtools.ts, doing\n// nothing. Call sites guard with DEVTOOLS_ENABLED, a literal `false` here, so bundlers drop\n// them entirely. The `typeof Dev.x` annotations keep both modules' signatures in sync.\nimport type * as Dev from './devtools.js';\n\nexport const DEVTOOLS_ENABLED: boolean = false;\n\nconst noop = (): void => undefined;\n\nexport const devConnect: typeof Dev.devConnect = noop;\nexport const devUpdate: typeof Dev.devUpdate = noop;\nexport const devHydrated: typeof Dev.devHydrated = noop;\nexport const devMismatch: typeof Dev.devMismatch = noop;\nexport const devStore: typeof Dev.devStore = noop;\nexport const devError: typeof Dev.devError = noop;\nexport const devCommands: typeof Dev.devCommands = () => noop;\nexport const devOwner: typeof Dev.devOwner = () => '';\nexport const devLiveComponents: typeof Dev.devLiveComponents = () => [];\n"]}
|
package/dist/devtools.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type CommandTrace, type DevComponentRef } from './devtools-events.js';
|
|
2
|
+
import type { GyralError } from './errors.js';
|
|
2
3
|
import type { Tagged } from './types.js';
|
|
3
4
|
export declare const DEVTOOLS_ENABLED: boolean;
|
|
4
5
|
/** Components connected right now, for a panel that starts after they did. */
|
|
@@ -8,6 +9,8 @@ export declare function devUpdate(element: Element, tag: string, msg: Tagged, pr
|
|
|
8
9
|
export declare function devHydrated(element: Element, tag: string, serverRendered: boolean): void;
|
|
9
10
|
export declare function devMismatch(element: Element, tag: string, message: string): void;
|
|
10
11
|
export declare function devStore(store: string, msg: Tagged, prev: unknown, next: unknown): void;
|
|
12
|
+
/** A failure `fail()` reported (ADR 0024); `element` is the failing host, if any. */
|
|
13
|
+
export declare function devError(element: Element | undefined, error: GyralError): void;
|
|
11
14
|
/** A command tracer for one owner (`<tag>#id` or `store:name`). */
|
|
12
15
|
export declare function devCommands(owner: () => string): CommandTrace;
|
|
13
16
|
/** The label the panel shows for a component's commands. */
|
package/dist/devtools.js
CHANGED
|
@@ -56,6 +56,20 @@ export function devMismatch(element, tag, message) {
|
|
|
56
56
|
export function devStore(store, msg, prev, next) {
|
|
57
57
|
emit(() => ({ kind: 'store', store, msg, prev, next, at: now() }));
|
|
58
58
|
}
|
|
59
|
+
/** A failure `fail()` reported (ADR 0024); `element` is the failing host, if any. */
|
|
60
|
+
export function devError(element, error) {
|
|
61
|
+
emit(() => ({
|
|
62
|
+
kind: 'error',
|
|
63
|
+
...(element === undefined
|
|
64
|
+
? {}
|
|
65
|
+
: { component: ref(element, error.component ?? element.localName) }),
|
|
66
|
+
phase: error.phase,
|
|
67
|
+
...(error.msg === undefined ? {} : { msg: error.msg }),
|
|
68
|
+
message: error.message,
|
|
69
|
+
error: error.cause,
|
|
70
|
+
at: now(),
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
59
73
|
/** A command tracer for one owner (`<tag>#id` or `store:name`). */
|
|
60
74
|
export function devCommands(owner) {
|
|
61
75
|
return (event) => {
|
package/dist/devtools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools.js","sourceRoot":"","sources":["../src/devtools.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,0FAA0F;AAC1F,4EAA4E;AAC5E,OAAO,EACL,eAAe,GAKhB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"devtools.js","sourceRoot":"","sources":["../src/devtools.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,0FAA0F;AAC1F,4EAA4E;AAC5E,OAAO,EACL,eAAe,GAKhB,MAAM,sBAAsB,CAAC;AAI9B,MAAM,CAAC,MAAM,gBAAgB,GAAY,IAAI,CAAC;AAE9C,MAAM,IAAI,GAAG,GAA6B,EAAE,CACzC,UAAsC,CAAC,eAAe,CAA6B,CAAC;AAEvF,MAAM,GAAG,GAAG,IAAI,OAAO,EAAmB,CAAC;AAC3C,IAAI,MAAM,GAAG,CAAC,CAAC;AAEf,SAAS,GAAG,CAAC,OAAgB,EAAE,GAAW;IACxC,IAAI,EAAE,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC1B,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;QACrB,EAAE,GAAG,MAAM,EAAE,CAAC;QACd,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,EAAE,GAA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,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACtE,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,GAAG,CAAC,KAAK,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC;QACtD,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,EAAE,EAAE,GAAG,EAAE;KACV,CAAC,CAAC,CAAC;AACN,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,WAAW,CAAC,KAAmB;IAC7C,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC;IACzE,CAAC,CAAC;AACJ,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,QAAQ,CAAC,OAAgB,EAAE,GAAW;IACpD,OAAO,IAAI,GAAG,KAAK,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AACpD,CAAC","sourcesContent":["// Development build of the devtools hook (ADR 0017). Resolved through the `#devtools` import\n// with the `development` condition; production builds get devtools-off.ts instead, so the\n// guarded call sites (`if (DEVTOOLS_ENABLED) …`) disappear from the bundle.\nimport {\n DEVTOOLS_GLOBAL,\n type CommandTrace,\n type DevComponentRef,\n type DevEvent,\n type DevtoolsHook,\n} from './devtools-events.js';\nimport type { GyralError } from './errors.js';\nimport type { Tagged } from './types.js';\n\nexport const DEVTOOLS_ENABLED: boolean = true;\n\nconst hook = (): DevtoolsHook | undefined =>\n (globalThis as Record<string, unknown>)[DEVTOOLS_GLOBAL] as DevtoolsHook | undefined;\n\nconst ids = new WeakMap<Element, number>();\nlet nextId = 1;\n\nfunction ref(element: Element, tag: string): DevComponentRef {\n let id = ids.get(element);\n if (id === undefined) {\n id = nextId++;\n ids.set(element, id);\n }\n return { tag, id, element };\n}\n\n// Builds nothing unless a listener is installed: zero cost in dev without devtools.\nfunction emit(make: () => DevEvent): void {\n const listener = hook();\n if (listener === undefined) return;\n try {\n listener.emit(make());\n } catch (error) {\n console.error('gyral devtools listener threw', error);\n }\n}\n\nconst now = (): number => performance.now();\n\n/** Connected components, so a panel loaded later still lists them (dev builds only). */\nconst live = new Map<Element, string>();\n\n/** Components connected right now, for a panel that starts after they did. */\nexport function devLiveComponents(): readonly DevComponentRef[] {\n return [...live].map(([element, tag]) => ref(element, tag));\n}\n\nexport function devConnect(element: Element, tag: string, connected: boolean): void {\n if (connected) live.set(element, tag);\n else live.delete(element);\n emit(() => ({\n kind: connected ? 'connect' : 'disconnect',\n component: ref(element, tag),\n at: now(),\n }));\n}\n\nexport function devUpdate(\n element: Element,\n tag: string,\n msg: Tagged,\n prev: unknown,\n next: unknown,\n) {\n emit(() => ({ kind: 'update', component: ref(element, tag), msg, prev, next, at: now() }));\n}\n\nexport function devHydrated(element: Element, tag: string, serverRendered: boolean): void {\n emit(() => ({ kind: 'hydrated', component: ref(element, tag), serverRendered, at: now() }));\n}\n\nexport function devMismatch(element: Element, tag: string, message: string): void {\n emit(() => ({ kind: 'mismatch', component: ref(element, tag), message, at: now() }));\n}\n\nexport function devStore(store: string, msg: Tagged, prev: unknown, next: unknown): void {\n emit(() => ({ kind: 'store', store, msg, prev, next, at: now() }));\n}\n\n/** A failure `fail()` reported (ADR 0024); `element` is the failing host, if any. */\nexport function devError(element: Element | undefined, error: GyralError): void {\n emit(() => ({\n kind: 'error',\n ...(element === undefined\n ? {}\n : { component: ref(element, error.component ?? element.localName) }),\n phase: error.phase,\n ...(error.msg === undefined ? {} : { msg: error.msg }),\n message: error.message,\n error: error.cause,\n at: now(),\n }));\n}\n\n/** A command tracer for one owner (`<tag>#id` or `store:name`). */\nexport function devCommands(owner: () => string): CommandTrace {\n return (event) => {\n emit(() => ({ kind: 'command', owner: owner(), ...event, at: now() }));\n };\n}\n\n/** The label the panel shows for a component's commands. */\nexport function devOwner(element: Element, tag: string): string {\n return `<${tag}>#${String(ref(element, tag).id)}`;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drivers-scope.js","sourceRoot":"","sources":["../src/drivers-scope.ts"],"names":[],"mappings":"AAKA,4FAA4F;AAC5F,MAAM,CAAC,MAAM,eAAe,GAAG,eAAe,CAAC;AAE/C,iFAAiF;AACjF,MAAM,QAAQ,GAAG,IAAI,OAAO,EAA4B,CAAC;AAEzD;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAgB,EAAE,OAAwB;IACvE,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,GAAG,EAAE;QACV,IAAI,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,OAAO;YAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAClE,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,IAAa;IAChC,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,UAAU,CAAC;IAChD,IAAI,IAAI,CAAC,SAAS,KAAK,eAAe;QAAE,OAAO,SAAS,CAAC;IACzD,OAAQ,IAAgD,CAAC,OAAO,CAAC;AACnE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,IAAa,EAAE,IAAY;IACxD,KAAK,IAAI,IAAI,GAAgB,IAAI,CAAC,UAAU,EAAE,IAAI,KAAK,IAAI,GAAG,CAAC;QAC7D,IAAI,IAAI,YAAY,OAAO,EAAE,CAAC;YAC5B,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;YACzC,IAAI,MAAM,KAAK,SAAS;gBAAE,OAAO,MAAM,CAAC;QAC1C,CAAC;QACD,IAAI,GAAG,IAAI,YAAY,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;IAClE,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Tree-scoped driver overrides (gyral-czi.35, ADR 0006 addendum): which driver a command uses.\n// Resolution: el.drivers → nearest driver provider (across shadow roots) →
|
|
1
|
+
{"version":3,"file":"drivers-scope.js","sourceRoot":"","sources":["../src/drivers-scope.ts"],"names":[],"mappings":"AAKA,4FAA4F;AAC5F,MAAM,CAAC,MAAM,eAAe,GAAG,eAAe,CAAC;AAE/C,iFAAiF;AACjF,MAAM,QAAQ,GAAG,IAAI,OAAO,EAA4B,CAAC;AAEzD;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAgB,EAAE,OAAwB;IACvE,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,GAAG,EAAE;QACV,IAAI,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,OAAO;YAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAClE,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,IAAa;IAChC,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,UAAU,CAAC;IAChD,IAAI,IAAI,CAAC,SAAS,KAAK,eAAe;QAAE,OAAO,SAAS,CAAC;IACzD,OAAQ,IAAgD,CAAC,OAAO,CAAC;AACnE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,IAAa,EAAE,IAAY;IACxD,KAAK,IAAI,IAAI,GAAgB,IAAI,CAAC,UAAU,EAAE,IAAI,KAAK,IAAI,GAAG,CAAC;QAC7D,IAAI,IAAI,YAAY,OAAO,EAAE,CAAC;YAC5B,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;YACzC,IAAI,MAAM,KAAK,SAAS;gBAAE,OAAO,MAAM,CAAC;QAC1C,CAAC;QACD,IAAI,GAAG,IAAI,YAAY,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;IAClE,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Tree-scoped driver overrides (gyral-czi.35, ADR 0006 addendum): which driver a command uses.\n// Resolution: el.drivers → nearest driver provider (across shadow roots) → the command's own\n// driver; a driver token (defineDriver('name')) has no own implementation. Mirrors <gyral-stores> (ADR 0013) for stores.\nimport type { AnyDriver, DriverOverrides } from './command.js';\n\n/** Provider element name: `<gyral-drivers .drivers=${{ http: fake }}>…</gyral-drivers>`. */\nexport const DRIVERS_ELEMENT = 'gyral-drivers';\n\n// Elements registered with provideDrivers() (any element can act as a provider).\nconst provided = new WeakMap<Element, DriverOverrides>();\n\n/**\n * Makes `element` a driver provider for every Gyral component below it (including inside\n * shadow roots). Returns a function that removes the overrides. Use it on a test container\n * or an app root; a `<gyral-drivers>` element with a `.drivers` property works the same way.\n */\nexport function provideDrivers(element: Element, drivers: DriverOverrides): () => void {\n provided.set(element, drivers);\n return () => {\n if (provided.get(element) === drivers) provided.delete(element);\n };\n}\n\nfunction overridesOf(node: Element): DriverOverrides | undefined {\n const registered = provided.get(node);\n if (registered !== undefined) return registered;\n if (node.localName !== DRIVERS_ELEMENT) return undefined;\n return (node as Element & { drivers?: DriverOverrides }).drivers;\n}\n\n/**\n * The override for `name` from the nearest provider that has one. Providers nest: an inner\n * provider without that driver lets an outer one supply it. Commands never run on the server,\n * so only the browser calls this.\n */\nexport function providedDriver(host: Element, name: string): AnyDriver | undefined {\n for (let node: Node | null = host.parentNode; node !== null;) {\n if (node instanceof Element) {\n const driver = overridesOf(node)?.[name];\n if (driver !== undefined) return driver;\n }\n node = node instanceof ShadowRoot ? node.host : node.parentNode;\n }\n return undefined;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function internalsOf(host: HTMLElement): ElementInternals;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Native features share one attachment: attachInternals() may only be called once per host.
|
|
2
|
+
const internals = new WeakMap();
|
|
3
|
+
export function internalsOf(host) {
|
|
4
|
+
let value = internals.get(host);
|
|
5
|
+
if (value === undefined) {
|
|
6
|
+
value = host.attachInternals();
|
|
7
|
+
internals.set(host, value);
|
|
8
|
+
}
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=element-internals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element-internals.js","sourceRoot":"","sources":["../src/element-internals.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,MAAM,SAAS,GAAG,IAAI,OAAO,EAAiC,CAAC;AAE/D,MAAM,UAAU,WAAW,CAAC,IAAiB;IAC3C,IAAI,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,KAAK,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QAC/B,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// Native features share one attachment: attachInternals() may only be called once per host.\nconst internals = new WeakMap<HTMLElement, ElementInternals>();\n\nexport function internalsOf(host: HTMLElement): ElementInternals {\n let value = internals.get(host);\n if (value === undefined) {\n value = host.attachInternals();\n internals.set(host, value);\n }\n return value;\n}\n"]}
|
package/dist/element-types.d.ts
CHANGED
|
@@ -2,8 +2,7 @@ import type { DriverOverrides } from './command.js';
|
|
|
2
2
|
import type { StoreOverrides } from './store.js';
|
|
3
3
|
import type { ComponentSpec, Tagged } from './types.js';
|
|
4
4
|
/**
|
|
5
|
-
* The custom element `define()` produces: a plain `HTMLElement`
|
|
6
|
-
* instance API"). Tests wait for rendering with `settled()`.
|
|
5
|
+
* The custom element `define()` produces: a plain `HTMLElement`. Tests wait for rendering with `settled()`.
|
|
7
6
|
*/
|
|
8
7
|
export interface GyralElement<S, M extends Tagged> extends HTMLElement {
|
|
9
8
|
/** Current model state. */
|
|
@@ -24,13 +23,17 @@ export interface GyralElement<S, M extends Tagged> extends HTMLElement {
|
|
|
24
23
|
*/
|
|
25
24
|
initialMessages: readonly Tagged[];
|
|
26
25
|
}
|
|
27
|
-
export interface GyralElementClass<S, M extends Tagged, P, O extends Tagged = never> {
|
|
26
|
+
export interface GyralElementClass<S, M extends Tagged, P, O extends Tagged = never, N extends string = string> {
|
|
28
27
|
/** Instances expose their declared props as settable properties. */
|
|
29
28
|
new (): GyralElement<S, M> & {
|
|
30
29
|
-readonly [K in keyof P]: P[K];
|
|
31
30
|
};
|
|
32
|
-
readonly spec: ComponentSpec<S, M, P>;
|
|
31
|
+
readonly spec: ComponentSpec<S, M, P, N>;
|
|
33
32
|
readonly tagName: string;
|
|
33
|
+
/** Native custom-element registration flag, true when the spec opts into forms. */
|
|
34
|
+
readonly formAssociated?: boolean;
|
|
34
35
|
/** Type-only: the outputs this component emits (read by `child()`). */
|
|
35
36
|
readonly outputs?: O;
|
|
37
|
+
/** Type-only: the component's intent names, the keys of `intent` (read by `intentsOf()`). */
|
|
38
|
+
readonly intentNames?: N;
|
|
36
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element-types.js","sourceRoot":"","sources":["../src/element-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DriverOverrides } from './command.js';\nimport type { StoreOverrides } from './store.js';\nimport type { ComponentSpec, Tagged } from './types.js';\n\n/**\n * The custom element `define()` produces: a plain `HTMLElement
|
|
1
|
+
{"version":3,"file":"element-types.js","sourceRoot":"","sources":["../src/element-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DriverOverrides } from './command.js';\nimport type { StoreOverrides } from './store.js';\nimport type { ComponentSpec, Tagged } from './types.js';\n\n/**\n * The custom element `define()` produces: a plain `HTMLElement`. Tests wait for rendering with `settled()`.\n */\nexport interface GyralElement<S, M extends Tagged> extends HTMLElement {\n /** Current model state. */\n readonly state: S;\n /** Feeds a message through `update`, as if an intent had produced it. */\n send(msg: M): void;\n /** Per-instance driver substitutions by name (test fakes). Checked before the spec's. */\n drivers: DriverOverrides;\n /**\n * Per-instance store instances by store name (tests, islands). Checked before the nearest\n * `<gyral-stores>` provider and the document default (ADR 0013).\n */\n stores: StoreOverrides;\n /**\n * Messages applied through `update` right after `init`, before the first render. The server\n * uses it to render a rejected form with the same reducer as the JS path (ADR 0008). Ignored\n * when the element resumes from a hydration seed (the seed already contains their effect).\n */\n initialMessages: readonly Tagged[];\n}\n\nexport interface GyralElementClass<\n S,\n M extends Tagged,\n P,\n O extends Tagged = never,\n N extends string = string,\n> {\n /** Instances expose their declared props as settable properties. */\n new (): GyralElement<S, M> & { -readonly [K in keyof P]: P[K] };\n readonly spec: ComponentSpec<S, M, P, N>;\n readonly tagName: string;\n /** Native custom-element registration flag, true when the spec opts into forms. */\n readonly formAssociated?: boolean;\n /** Type-only: the outputs this component emits (read by `child()`). */\n readonly outputs?: O;\n /** Type-only: the component's intent names, the keys of `intent` (read by `intentsOf()`). */\n readonly intentNames?: N;\n}\n"]}
|