@svelte-lean/core 0.13.4 → 0.14.0

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # @svelte-lean/core
2
2
 
3
+ ## 0.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c8bd752: The router routes `invalid` (in the capture phase: it does not bubble) for field validation (ADR 0011 §4): a behavior can list `invalid` in its events and receives the event the browser fires at each control that fails constraint validation.
8
+ - 3bd376f: ADR 0011 §1.1: `BehaviorDefinition.attribute` also accepts `interestfor`, the platform attribute with which a link or a button names its hover card, so the hover card behavior hears its triggers through the router as well as its `data-slean` cards.
9
+ - ec14149: ADR 0011 rules and infrastructure. `isDisabled()` and the router honour `disabled` and `aria-disabled="true"` only: `data-slean-disabled` is removed and disables nothing. New `reset` routed event type with an opt-in route, `routeResets()`, which a behavior that follows form resets calls before registering: the router hands a form `reset` to the roots around the form's controls one task after the event (a microtask still sees the old values when a reset button triggers it), so pages without such a behavior carry only a one-line hand-over (+28 B brotli in the consumer bundle). New pure helpers: `partId(rootId, part, index?)`, the one derived-id convention (`fruit-trigger`, `fruit-option-3`), and `ensurePart(root, name, create)`, which returns an authored part or creates it on first use as the root's last child, marked `data-slean-generated`, with the derived id. Size budget 2500 → 2750 B gzip for the every-export bundle, with the reason in `scripts/size.mjs`.
10
+ - 6e9ed18: The router routes `animationstart` (bubbling, one shared listener when a behavior handles it). The select behavior uses it to write a multiple select's tags when `select.css` first draws the field.
11
+
3
12
  ## 0.13.4
4
13
 
5
14
  No changes in this release.
package/README.md CHANGED
@@ -57,14 +57,16 @@ iframe document).
57
57
 
58
58
  ## API
59
59
 
60
- | Export | Purpose |
61
- | ------------------------------------------------------------------ | ------------------------------------------------------------------ |
62
- | `registerBehavior`, `unregisterBehavior` | Register on the document runtime; SSR-safe |
63
- | `getDefaultRuntime`, `createRuntime`, `EVENT_TYPES` | Runtimes; `listeners()` reports one entry per installed event type |
64
- | `parts`, `part`, `closestRoot`, `isDisabled`, `readOption`, `emit` | DOM protocol helpers |
65
- | `nextIndex`, `isTypeaheadKey`, `createTypeahead` | Keyboard navigation (arrows, Home, End, RTL, loop) and typeahead |
66
- | `lazyState` | `WeakMap` state created on first access (Tier 2 behaviors) |
67
- | `DEV`, `warn`, `scopedControllers`, `report` | Development diagnostics; `window.__SLEAN_DEBUG__` in development |
60
+ | Export | Purpose |
61
+ | ------------------------------------------------------------------ | -------------------------------------------------------------------------------------- |
62
+ | `registerBehavior`, `unregisterBehavior` | Register on the document runtime; SSR-safe |
63
+ | `getDefaultRuntime`, `createRuntime`, `EVENT_TYPES` | Runtimes; `listeners()` reports one entry per installed event type |
64
+ | `parts`, `part`, `closestRoot`, `isDisabled`, `readOption`, `emit` | DOM protocol helpers (`isDisabled`: `disabled` or `aria-disabled`) |
65
+ | `partId`, `ensurePart` | Derived part ids (`<id>-trigger`) and parts created on first use (ADR 0011 §2.2, §2.5) |
66
+ | `routeResets` | Opt-in routing of form `reset` to the roots around the form's controls (ADR 0011 §3.5) |
67
+ | `nextIndex`, `isTypeaheadKey`, `createTypeahead` | Keyboard navigation (arrows, Home, End, RTL, loop) and typeahead |
68
+ | `lazyState` | `WeakMap` state created on first access (Tier 2 behaviors) |
69
+ | `DEV`, `warn`, `scopedControllers`, `report` | Development diagnostics; `window.__SLEAN_DEBUG__` in development |
68
70
 
69
71
  Types: `BehaviorDefinition`, `BehaviorContext`, `BehaviorHandler`, `SleanEventType`, `Runtime`.
70
72
 
@@ -72,13 +74,10 @@ Types: `BehaviorDefinition`, `BehaviorContext`, `BehaviorHandler`, `SleanEventTy
72
74
 
73
75
  Measured by `scripts/size.mjs` in the repository (esbuild 0.25 bundle + minify for the entry, Vite 7
74
76
  production build for the consumer case; gzip level 9, brotli quality 11); `artifacts/size.json`
75
- holds the latest run.
76
-
77
- | Bundle | raw | gzip | brotli |
78
- | ---------------------------------------------------------- | ------ | ------ | ------ |
79
- | Entry, every export, `production` condition | 4357 B | 2087 B | 1907 B |
80
- | Entry, every export, runtime-detected env | 4560 B | 2169 B | 1960 B |
81
- | Consumer: one Tier 1 behavior with `parts` + `emit` (Vite) | 1864 B | 965 B | 852 B |
77
+ holds the latest run and the [performance page](https://svelte-lean.vercel.app/performance) shows
78
+ it. The script measures the entry with every export under the `production` condition and with the
79
+ runtime-detected env module, both against a gzip budget, and a consumer bundle of one Tier 1
80
+ behavior using `parts` and `emit`.
82
81
 
83
82
  Diagnostics (`warn`, `validate`, `__SLEAN_DEBUG__`, `report`) are gated on `DEV`, which a bundler
84
83
  resolves through the `#env` import conditions (`development`, `production`, `default`); the consumer
package/dist/dom.d.ts CHANGED
@@ -7,8 +7,27 @@ export declare function parts(root: HTMLElement, part: string): HTMLElement[];
7
7
  export declare function part(root: HTMLElement, part: string): HTMLElement | null;
8
8
  /** Nearest ancestor-or-self with `data-slean` (optionally a specific behavior). Light DOM only. */
9
9
  export declare function closestRoot(el: Element, behavior?: string): HTMLElement | null;
10
- /** `disabled` property, `aria-disabled="true"` or the `data-slean-disabled` attribute. */
10
+ /**
11
+ * The `disabled` property or `aria-disabled="true"` (ADR 0011 §3.6: `disabled` on a native
12
+ * element, `aria-disabled` where none exists; there is no third spelling).
13
+ */
11
14
  export declare function isDisabled(el: Element): boolean;
15
+ /**
16
+ * Id of a part derived from its root's author id (ADR 0011 §2.5): `<rootId>-<part>`, or
17
+ * `<rootId>-<part>-<index>` for one of several (`fruit-option-3`). The attribute helpers
18
+ * (`tabsParts()`, …) and the behaviors that generate a part use this one convention, so server
19
+ * markup and generated parts agree without a second id.
20
+ */
21
+ export declare function partId(rootId: string, part: string, index?: number | string): string;
22
+ /**
23
+ * The part `name` of `root`, created when the author wrote none (ADR 0011 §2.2). Only for parts
24
+ * assistive technology cannot reach before the first interaction (a closed popup, a pointer-only
25
+ * button). `create` is a tag name or a function that builds the element; the result is marked
26
+ * `data-slean-part="<name>"` and `data-slean-generated`, gets the derived id `partId(root.id,
27
+ * name)` when the root has an id and the element none, and is appended as the root's last child,
28
+ * after the framework's own nodes, so a re-render never moves it. An authored part always wins.
29
+ */
30
+ export declare function ensurePart(root: HTMLElement, name: string, create: string | ((document: Document) => HTMLElement)): HTMLElement;
12
31
  /** Reads the static option `data-slean-<name>` from a root. */
13
32
  export declare function readOption(root: HTMLElement, name: string): string | undefined;
14
33
  export declare function readOption(root: HTMLElement, name: string, fallback: string): string;
package/dist/dom.js CHANGED
@@ -19,11 +19,42 @@ export function part(root, part) {
19
19
  export function closestRoot(el, behavior) {
20
20
  return el.closest(behavior ? `[data-slean="${behavior}"]` : '[data-slean]');
21
21
  }
22
- /** `disabled` property, `aria-disabled="true"` or the `data-slean-disabled` attribute. */
22
+ /**
23
+ * The `disabled` property or `aria-disabled="true"` (ADR 0011 §3.6: `disabled` on a native
24
+ * element, `aria-disabled` where none exists; there is no third spelling).
25
+ */
23
26
  export function isDisabled(el) {
24
- return (el.disabled === true ||
25
- el.getAttribute('aria-disabled') === 'true' ||
26
- el.hasAttribute('data-slean-disabled'));
27
+ return el.disabled === true || el.getAttribute('aria-disabled') === 'true';
28
+ }
29
+ /**
30
+ * Id of a part derived from its root's author id (ADR 0011 §2.5): `<rootId>-<part>`, or
31
+ * `<rootId>-<part>-<index>` for one of several (`fruit-option-3`). The attribute helpers
32
+ * (`tabsParts()`, …) and the behaviors that generate a part use this one convention, so server
33
+ * markup and generated parts agree without a second id.
34
+ */
35
+ export function partId(rootId, part, index) {
36
+ return index === undefined ? `${rootId}-${part}` : `${rootId}-${part}-${index}`;
37
+ }
38
+ /**
39
+ * The part `name` of `root`, created when the author wrote none (ADR 0011 §2.2). Only for parts
40
+ * assistive technology cannot reach before the first interaction (a closed popup, a pointer-only
41
+ * button). `create` is a tag name or a function that builds the element; the result is marked
42
+ * `data-slean-part="<name>"` and `data-slean-generated`, gets the derived id `partId(root.id,
43
+ * name)` when the root has an id and the element none, and is appended as the root's last child,
44
+ * after the framework's own nodes, so a re-render never moves it. An authored part always wins.
45
+ */
46
+ export function ensurePart(root, name, create) {
47
+ let el = part(root, name);
48
+ if (el)
49
+ return el;
50
+ const doc = root.ownerDocument;
51
+ el = typeof create === 'string' ? doc.createElement(create) : create(doc);
52
+ el.setAttribute('data-slean-part', name);
53
+ el.setAttribute('data-slean-generated', '');
54
+ if (root.id && !el.id)
55
+ el.id = partId(root.id, name);
56
+ root.append(el);
57
+ return el;
27
58
  }
28
59
  export function readOption(root, name, fallback) {
29
60
  return root.getAttribute(`data-slean-${name}`) ?? fallback;
package/dist/dom.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"dom.js","sourceRoot":"","sources":["../src/dom.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,KAAK,CAAC,IAAiB,EAAE,IAAY;IACpD,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;IACjD,MAAM,GAAG,GAAkB,EAAE,CAAC;IAC9B,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,gBAAgB,CAAc,qBAAqB,IAAI,IAAI,CAAC,EAAE,CAAC;QACpF,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,gBAAgB,QAAQ,IAAI,CAAC,KAAK,IAAI;YAAE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjG,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,IAAI,CAAC,IAAiB,EAAE,IAAY;IACnD,OAAO,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AACrC,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,WAAW,CAAC,EAAW,EAAE,QAAiB;IACzD,OAAO,EAAE,CAAC,OAAO,CAAc,QAAQ,CAAC,CAAC,CAAC,gBAAgB,QAAQ,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;AAC1F,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,UAAU,CAAC,EAAW;IACrC,OAAO,CACL,EAAwB,CAAC,QAAQ,KAAK,IAAI;QAC3C,EAAE,CAAC,YAAY,CAAC,eAAe,CAAC,KAAK,MAAM;QAC3C,EAAE,CAAC,YAAY,CAAC,qBAAqB,CAAC,CACtC,CAAC;AACH,CAAC;AAKD,MAAM,UAAU,UAAU,CAAC,IAAiB,EAAE,IAAY,EAAE,QAAiB;IAC5E,OAAO,IAAI,CAAC,YAAY,CAAC,cAAc,IAAI,EAAE,CAAC,IAAI,QAAQ,CAAC;AAC5D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,IAAI,CAAc,IAAiB,EAAE,IAAY,EAAE,MAAU;IAC5E,OAAO,IAAI,CAAC,aAAa,CACxB,IAAI,WAAW,CAAC,SAAS,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAC7E,CAAC;AACH,CAAC","sourcesContent":["/**\n * Elements with `data-slean-part=\"<part>\"` inside `root`, excluding parts that belong to a nested\n * root of the same behavior. Light DOM only; part names must be plain identifiers.\n */\nexport function parts(root: HTMLElement, part: string): HTMLElement[] {\n\tconst behavior = root.getAttribute('data-slean');\n\tconst out: HTMLElement[] = [];\n\tfor (const el of root.querySelectorAll<HTMLElement>(`[data-slean-part=\"${part}\"]`)) {\n\t\tif (!behavior || el.parentElement?.closest(`[data-slean=\"${behavior}\"]`) === root) out.push(el);\n\t}\n\treturn out;\n}\n\n/** First element `parts()` would return, or null. */\nexport function part(root: HTMLElement, part: string): HTMLElement | null {\n\treturn parts(root, part)[0] ?? null;\n}\n\n/** Nearest ancestor-or-self with `data-slean` (optionally a specific behavior). Light DOM only. */\nexport function closestRoot(el: Element, behavior?: string): HTMLElement | null {\n\treturn el.closest<HTMLElement>(behavior ? `[data-slean=\"${behavior}\"]` : '[data-slean]');\n}\n\n/** `disabled` property, `aria-disabled=\"true\"` or the `data-slean-disabled` attribute. */\nexport function isDisabled(el: Element): boolean {\n\treturn (\n\t\t(el as HTMLButtonElement).disabled === true ||\n\t\tel.getAttribute('aria-disabled') === 'true' ||\n\t\tel.hasAttribute('data-slean-disabled')\n\t);\n}\n\n/** Reads the static option `data-slean-<name>` from a root. */\nexport function readOption(root: HTMLElement, name: string): string | undefined;\nexport function readOption(root: HTMLElement, name: string, fallback: string): string;\nexport function readOption(root: HTMLElement, name: string, fallback?: string): string | undefined {\n\treturn root.getAttribute(`data-slean-${name}`) ?? fallback;\n}\n\n/**\n * Dispatches `slean:<name>` from `root` (bubbling, cancelable). Returns false when a listener\n * called `preventDefault()`.\n */\nexport function emit<T = unknown>(root: HTMLElement, name: string, detail?: T): boolean {\n\treturn root.dispatchEvent(\n\t\tnew CustomEvent(`slean:${name}`, { bubbles: true, cancelable: true, detail })\n\t);\n}\n"]}
1
+ {"version":3,"file":"dom.js","sourceRoot":"","sources":["../src/dom.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,KAAK,CAAC,IAAiB,EAAE,IAAY;IACpD,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;IACjD,MAAM,GAAG,GAAkB,EAAE,CAAC;IAC9B,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,gBAAgB,CAAc,qBAAqB,IAAI,IAAI,CAAC,EAAE,CAAC;QACpF,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,gBAAgB,QAAQ,IAAI,CAAC,KAAK,IAAI;YAAE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjG,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,IAAI,CAAC,IAAiB,EAAE,IAAY;IACnD,OAAO,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,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,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACrD,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,EAAE,CAAC;AACX,CAAC;AAKD,MAAM,UAAU,UAAU,CAAC,IAAiB,EAAE,IAAY,EAAE,QAAiB;IAC5E,OAAO,IAAI,CAAC,YAAY,CAAC,cAAc,IAAI,EAAE,CAAC,IAAI,QAAQ,CAAC;AAC5D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,IAAI,CAAc,IAAiB,EAAE,IAAY,EAAE,MAAU;IAC5E,OAAO,IAAI,CAAC,aAAa,CACxB,IAAI,WAAW,CAAC,SAAS,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAC7E,CAAC;AACH,CAAC","sourcesContent":["/**\n * Elements with `data-slean-part=\"<part>\"` inside `root`, excluding parts that belong to a nested\n * root of the same behavior. Light DOM only; part names must be plain identifiers.\n */\nexport function parts(root: HTMLElement, part: string): HTMLElement[] {\n\tconst behavior = root.getAttribute('data-slean');\n\tconst out: HTMLElement[] = [];\n\tfor (const el of root.querySelectorAll<HTMLElement>(`[data-slean-part=\"${part}\"]`)) {\n\t\tif (!behavior || el.parentElement?.closest(`[data-slean=\"${behavior}\"]`) === root) out.push(el);\n\t}\n\treturn out;\n}\n\n/** First element `parts()` would return, or null. */\nexport function part(root: HTMLElement, part: string): HTMLElement | null {\n\treturn parts(root, part)[0] ?? null;\n}\n\n/** Nearest ancestor-or-self with `data-slean` (optionally a specific behavior). Light DOM only. */\nexport function closestRoot(el: Element, behavior?: string): HTMLElement | null {\n\treturn el.closest<HTMLElement>(behavior ? `[data-slean=\"${behavior}\"]` : '[data-slean]');\n}\n\n/**\n * The `disabled` property or `aria-disabled=\"true\"` (ADR 0011 §3.6: `disabled` on a native\n * element, `aria-disabled` where none exists; there is no third spelling).\n */\nexport function isDisabled(el: Element): boolean {\n\treturn (el as HTMLButtonElement).disabled === true || el.getAttribute('aria-disabled') === 'true';\n}\n\n/**\n * Id of a part derived from its root's author id (ADR 0011 §2.5): `<rootId>-<part>`, or\n * `<rootId>-<part>-<index>` for one of several (`fruit-option-3`). The attribute helpers\n * (`tabsParts()`, …) and the behaviors that generate a part use this one convention, so server\n * markup and generated parts agree without a second id.\n */\nexport function partId(rootId: string, part: string, index?: number | string): string {\n\treturn index === undefined ? `${rootId}-${part}` : `${rootId}-${part}-${index}`;\n}\n\n/**\n * The part `name` of `root`, created when the author wrote none (ADR 0011 §2.2). Only for parts\n * assistive technology cannot reach before the first interaction (a closed popup, a pointer-only\n * button). `create` is a tag name or a function that builds the element; the result is marked\n * `data-slean-part=\"<name>\"` and `data-slean-generated`, gets the derived id `partId(root.id,\n * name)` when the root has an id and the element none, and is appended as the root's last child,\n * after the framework's own nodes, so a re-render never moves it. An authored part always wins.\n */\nexport function ensurePart(\n\troot: HTMLElement,\n\tname: string,\n\tcreate: string | ((document: Document) => HTMLElement)\n): HTMLElement {\n\tlet el = part(root, name);\n\tif (el) return el;\n\tconst doc = root.ownerDocument;\n\tel = typeof create === 'string' ? doc.createElement(create) : create(doc);\n\tel.setAttribute('data-slean-part', name);\n\tel.setAttribute('data-slean-generated', '');\n\tif (root.id && !el.id) el.id = partId(root.id, name);\n\troot.append(el);\n\treturn el;\n}\n\n/** Reads the static option `data-slean-<name>` from a root. */\nexport function readOption(root: HTMLElement, name: string): string | undefined;\nexport function readOption(root: HTMLElement, name: string, fallback: string): string;\nexport function readOption(root: HTMLElement, name: string, fallback?: string): string | undefined {\n\treturn root.getAttribute(`data-slean-${name}`) ?? fallback;\n}\n\n/**\n * Dispatches `slean:<name>` from `root` (bubbling, cancelable). Returns false when a listener\n * called `preventDefault()`.\n */\nexport function emit<T = unknown>(root: HTMLElement, name: string, detail?: T): boolean {\n\treturn root.dispatchEvent(\n\t\tnew CustomEvent(`slean:${name}`, { bubbles: true, cancelable: true, detail })\n\t);\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export type { BehaviorContext, BehaviorDefinition, BehaviorEvents, BehaviorHandler, Runtime, RuntimeOptions, RuntimeRoot, SleanEventMap, SleanEventType } from './types.js';
2
2
  export { createRuntime, EVENT_TYPES } from './runtime.js';
3
+ export { routeResets } from './reset.js';
3
4
  export { getDefaultRuntime, registerBehavior, unregisterBehavior } from './registry.js';
4
- export { closestRoot, emit, isDisabled, part, parts, readOption } from './dom.js';
5
+ export { closestRoot, emit, ensurePart, isDisabled, part, partId, parts, readOption } from './dom.js';
5
6
  export { createTypeahead, isTypeaheadKey, nextIndex } from './keyboard.js';
6
7
  export type { NavigationOptions, Typeahead } from './keyboard.js';
7
8
  export { lazyState } from './state.js';
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export { createRuntime, EVENT_TYPES } from './runtime.js';
2
+ export { routeResets } from './reset.js';
2
3
  export { getDefaultRuntime, registerBehavior, unregisterBehavior } from './registry.js';
3
- export { closestRoot, emit, isDisabled, part, parts, readOption } from './dom.js';
4
+ export { closestRoot, emit, ensurePart, isDisabled, part, partId, parts, readOption } from './dom.js';
4
5
  export { createTypeahead, isTypeaheadKey, nextIndex } from './keyboard.js';
5
6
  export { lazyState } from './state.js';
6
7
  import { DEV as env } from '#env';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,GAAG,IAAI,GAAG,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEnE;;;;GAIG;AACH,MAAM,CAAC,MAAM,GAAG,GAAY,GAAG,CAAC","sourcesContent":["export type {\n\tBehaviorContext,\n\tBehaviorDefinition,\n\tBehaviorEvents,\n\tBehaviorHandler,\n\tRuntime,\n\tRuntimeOptions,\n\tRuntimeRoot,\n\tSleanEventMap,\n\tSleanEventType\n} from './types.js';\nexport { createRuntime, EVENT_TYPES } from './runtime.js';\nexport { getDefaultRuntime, registerBehavior, unregisterBehavior } from './registry.js';\nexport { closestRoot, emit, isDisabled, part, parts, readOption } from './dom.js';\nexport { createTypeahead, isTypeaheadKey, nextIndex } from './keyboard.js';\nexport type { NavigationOptions, Typeahead } from './keyboard.js';\nexport { lazyState } from './state.js';\nexport type { LazyState } from './state.js';\nimport { DEV as env } from '#env';\nexport { report, scopedControllers, warn } from './diagnostics.js';\n\n/**\n * True in development builds; see `AGENTS.md` for how the `#env` conditions select it. Re-exported\n * through a typed constant so the public declaration file never references the `#env` specifier,\n * which legacy `moduleResolution: node` cannot follow.\n */\nexport const DEV: boolean = env;\nexport type { SleanDebug } from './diagnostics.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,EACN,WAAW,EACX,IAAI,EACJ,UAAU,EACV,UAAU,EACV,IAAI,EACJ,MAAM,EACN,KAAK,EACL,UAAU,EACV,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,GAAG,IAAI,GAAG,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEnE;;;;GAIG;AACH,MAAM,CAAC,MAAM,GAAG,GAAY,GAAG,CAAC","sourcesContent":["export type {\n\tBehaviorContext,\n\tBehaviorDefinition,\n\tBehaviorEvents,\n\tBehaviorHandler,\n\tRuntime,\n\tRuntimeOptions,\n\tRuntimeRoot,\n\tSleanEventMap,\n\tSleanEventType\n} from './types.js';\nexport { createRuntime, EVENT_TYPES } from './runtime.js';\nexport { routeResets } from './reset.js';\nexport { getDefaultRuntime, registerBehavior, unregisterBehavior } from './registry.js';\nexport {\n\tclosestRoot,\n\temit,\n\tensurePart,\n\tisDisabled,\n\tpart,\n\tpartId,\n\tparts,\n\treadOption\n} from './dom.js';\nexport { createTypeahead, isTypeaheadKey, nextIndex } from './keyboard.js';\nexport type { NavigationOptions, Typeahead } from './keyboard.js';\nexport { lazyState } from './state.js';\nexport type { LazyState } from './state.js';\nimport { DEV as env } from '#env';\nexport { report, scopedControllers, warn } from './diagnostics.js';\n\n/**\n * True in development builds; see `AGENTS.md` for how the `#env` conditions select it. Re-exported\n * through a typed constant so the public declaration file never references the `#env` specifier,\n * which legacy `moduleResolution: node` cannot follow.\n */\nexport const DEV: boolean = env;\nexport type { SleanDebug } from './diagnostics.js';\n"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Lets the router deliver form `reset` events to behaviors that handle `reset` (ADR 0011 §3.5).
3
+ * The register module of such a behavior calls it before `registerBehavior()`; pages without one
4
+ * carry none of this code. Idempotent.
5
+ *
6
+ * A `reset` targets the form, while the roots that draw a control's value (an owned select over
7
+ * its native `<select>`) sit inside it, off the event's path. Its path is therefore the nearest
8
+ * root of each of the form's controls (`form.elements`, which includes controls associated with
9
+ * `form="…"`; a root with several controls is called once per control), walked one task after the
10
+ * event: the form resets its controls only after the dispatch, and a microtask would still see the
11
+ * old values when a reset button triggers it (measured in Chromium and Firefox). Handlers re-read
12
+ * their native parts, which is harmless when a listener cancelled the reset, so that is not
13
+ * checked. The walked path is the form followed by those roots; the context's `target` is the form.
14
+ */
15
+ export declare function routeResets(): void;
package/dist/reset.js ADDED
@@ -0,0 +1,27 @@
1
+ import { setResetRoute } from './runtime.js';
2
+ /**
3
+ * Lets the router deliver form `reset` events to behaviors that handle `reset` (ADR 0011 §3.5).
4
+ * The register module of such a behavior calls it before `registerBehavior()`; pages without one
5
+ * carry none of this code. Idempotent.
6
+ *
7
+ * A `reset` targets the form, while the roots that draw a control's value (an owned select over
8
+ * its native `<select>`) sit inside it, off the event's path. Its path is therefore the nearest
9
+ * root of each of the form's controls (`form.elements`, which includes controls associated with
10
+ * `form="…"`; a root with several controls is called once per control), walked one task after the
11
+ * event: the form resets its controls only after the dispatch, and a microtask would still see the
12
+ * old values when a reset button triggers it (measured in Chromium and Firefox). Handlers re-read
13
+ * their native parts, which is harmless when a listener cancelled the reset, so that is not
14
+ * checked. The walked path is the form followed by those roots; the context's `target` is the form.
15
+ */
16
+ export function routeResets() {
17
+ // The path starts at the form, so handlers receive it as `target` and an attribute behavior on
18
+ // the form itself (or a root on it) hears the reset too.
19
+ setResetRoute((event, walk) => {
20
+ const form = event.target;
21
+ setTimeout(() => {
22
+ const roots = [...form.elements].map((control) => control.closest('[data-slean]'));
23
+ walk([form, ...roots.filter(Boolean)]);
24
+ });
25
+ });
26
+ }
27
+ //# sourceMappingURL=reset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reset.js","sourceRoot":"","sources":["../src/reset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW;IAC1B,+FAA+F;IAC/F,yDAAyD;IACzD,aAAa,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QAC7B,MAAM,IAAI,GAAG,KAAK,CAAC,MAAyB,CAAC;QAC7C,UAAU,CAAC,GAAG,EAAE;YACf,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;YACnF,IAAI,CAAC,CAAC,IAAI,EAAE,GAAI,KAAK,CAAC,MAAM,CAAC,OAAO,CAAe,CAAC,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { setResetRoute } from './runtime.js';\n\n/**\n * Lets the router deliver form `reset` events to behaviors that handle `reset` (ADR 0011 §3.5).\n * The register module of such a behavior calls it before `registerBehavior()`; pages without one\n * carry none of this code. Idempotent.\n *\n * A `reset` targets the form, while the roots that draw a control's value (an owned select over\n * its native `<select>`) sit inside it, off the event's path. Its path is therefore the nearest\n * root of each of the form's controls (`form.elements`, which includes controls associated with\n * `form=\"…\"`; a root with several controls is called once per control), walked one task after the\n * event: the form resets its controls only after the dispatch, and a microtask would still see the\n * old values when a reset button triggers it (measured in Chromium and Firefox). Handlers re-read\n * their native parts, which is harmless when a listener cancelled the reset, so that is not\n * checked. The walked path is the form followed by those roots; the context's `target` is the form.\n */\nexport function routeResets(): void {\n\t// The path starts at the form, so handlers receive it as `target` and an attribute behavior on\n\t// the form itself (or a root on it) hears the reset too.\n\tsetResetRoute((event, walk) => {\n\t\tconst form = event.target as HTMLFormElement;\n\t\tsetTimeout(() => {\n\t\t\tconst roots = [...form.elements].map((control) => control.closest('[data-slean]'));\n\t\t\twalk([form, ...(roots.filter(Boolean) as Element[])]);\n\t\t});\n\t});\n}\n"]}
package/dist/runtime.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import type { Runtime, RuntimeOptions, RuntimeRoot, SleanEventType } from './types.js';
2
2
  /** Every event type the router can install, in report order. */
3
3
  export declare const EVENT_TYPES: readonly SleanEventType[];
4
+ /** Routes an event along a path of elements of the caller's choosing (see `routeResets`). */
5
+ export type Walk = (path: EventTarget[]) => void;
6
+ /** @internal Used by `routeResets()`. */
7
+ export declare function setResetRoute(route: (event: Event, walk: Walk) => void): void;
4
8
  /**
5
9
  * Creates a runtime whose shared listeners attach to `root` (`document` by default).
6
10
  * Nothing is installed until a behavior that needs an event type is registered.
package/dist/runtime.js CHANGED
@@ -21,14 +21,34 @@ export const EVENT_TYPES = [
21
21
  'drop',
22
22
  'toggle',
23
23
  'beforetoggle',
24
- 'beforematch'
24
+ 'beforematch',
25
+ 'reset',
26
+ 'invalid',
27
+ 'animationstart'
25
28
  ];
26
29
  // `toggle` and `beforetoggle` do not bubble; a root listener only observes them in the capture
27
30
  // phase. Every other routed type bubbles, so it stays in the bubble phase and element-level
28
31
  // listeners keep their normal ordering. `beforematch` bubbles too (HTML: fired with `bubbles`
29
32
  // true), and the browser removes `hidden="until-found"` only after the dispatch has finished, so
30
- // the bubble phase sees it before the reveal like the capture phase would.
31
- const CAPTURE = { toggle: true, beforetoggle: true };
33
+ // the bubble phase sees it before the reveal like the capture phase would. `reset` is watched in
34
+ // the capture phase so that application code stopping it cannot hide it (see `routeResets`).
35
+ // `invalid` does not bubble either: it is seen in the capture phase on its way to the control.
36
+ const CAPTURE = {
37
+ toggle: true,
38
+ beforetoggle: true,
39
+ reset: true,
40
+ invalid: true
41
+ };
42
+ /**
43
+ * How a form `reset` is routed, installed by `routeResets()` (`./reset.ts`). A `reset` targets the
44
+ * form while the roots that follow it sit inside the form, off the event's path, so it needs a
45
+ * path of its own; only behaviors that handle `reset` import that code.
46
+ */
47
+ let resetRoute;
48
+ /** @internal Used by `routeResets()`. */
49
+ export function setResetRoute(route) {
50
+ resetRoute = route;
51
+ }
32
52
  /** Development check, run once per registration: every handled event type must be routable. */
33
53
  function checkEventTypes(name, definition) {
34
54
  for (const type in definition.events) {
@@ -37,6 +57,9 @@ function checkEventTypes(name, definition) {
37
57
  if (!EVENT_TYPES.includes(type)) {
38
58
  warn(name, `"${type}" is not a routed event type; use a scoped listener instead.`);
39
59
  }
60
+ else if (type === 'reset' && !resetRoute) {
61
+ warn(name, 'handles "reset" but routeResets() was not called before registering it.');
62
+ }
40
63
  }
41
64
  }
42
65
  /**
@@ -57,11 +80,16 @@ export function createRuntimeInternal(root, onDestroy) {
57
80
  let routing = false;
58
81
  /**
59
82
  * Routes `event` to the roots on its path; up to `stop` when application code stopped it
60
- * there (`guard`). Also the root's own listener, where `stop` is never given.
83
+ * there (`guard`). Also the root's own listener, where `stop` is never given. A form `reset`
84
+ * goes to the route `routeResets()` installed, which calls back with the path to walk.
61
85
  */
62
- const route = (event, stop = null) => {
86
+ const route = (event, stop = null, path) => {
87
+ if (!path) {
88
+ if (event.type === 'reset')
89
+ return resetRoute?.(event, (roots) => route(event, null, roots));
90
+ path = event.composedPath();
91
+ }
63
92
  const type = event.type;
64
- const path = event.composedPath();
65
93
  const first = path[0];
66
94
  const target = (first && first.nodeType === 1 ? first : event.target);
67
95
  // No try/finally: Rollup keeps everything inside a try block, development checks included.
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAC3B,OAAO,EACN,eAAe,EACf,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,IAAI,EACJ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,gEAAgE;AAChE,MAAM,CAAC,MAAM,WAAW,GAA8B;IACrD,OAAO;IACP,UAAU;IACV,SAAS;IACT,OAAO;IACP,SAAS;IACT,UAAU;IACV,OAAO;IACP,QAAQ;IACR,aAAa;IACb,WAAW;IAC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,IAAI,EAAE,UAAU;YACxB,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;YAChC,IAAI,GAAG;gBAAE,eAAe,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;YAC3C,IAAI,GAAG;gBAAE,eAAe,EAAE,CAAC;YAC3B,IAAI,EAAE,CAAC;QACR,CAAC;QACD,UAAU,CAAC,IAAI;YACd,IAAI,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;gBAAE,IAAI,EAAE,CAAC;QACpC,CAAC;QACD,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC;QAClC,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;QACtC,SAAS;YACR,MAAM,GAAG,GAA2B,EAAE,CAAC;YACvC,KAAK,MAAM,IAAI,IAAI,SAAS;gBAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC5C,OAAO,GAAG,CAAC;QACZ,CAAC;QACD,OAAO;YACN,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,IAAI,EAAE,CAAC;YACP,cAAc,CAAC,OAAO,CAAC,CAAC;YACxB,SAAS,EAAE,EAAE,CAAC;QACf,CAAC;KACD,CAAC;IACF,YAAY,CAAC,OAAO,CAAC,CAAC;IACtB,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import type {\n\tBehaviorDefinition,\n\tBehaviorHandler,\n\tRuntime,\n\tRuntimeOptions,\n\tRuntimeRoot,\n\tSleanEventType\n} from './types.js';\nimport { DEV } from '#env';\nimport {\n\tresetValidation,\n\ttrackRuntime,\n\tuntrackRuntime,\n\tvalidateRoot,\n\twarn\n} from './diagnostics.js';\nimport { isDisabled } from './dom.js';\n\n/** Every event type the router can install, in report order. */\nexport const EVENT_TYPES: readonly SleanEventType[] = [\n\t'click',\n\t'dblclick',\n\t'keydown',\n\t'keyup',\n\t'focusin',\n\t'focusout',\n\t'input',\n\t'change',\n\t'pointerdown',\n\t'pointerup',\n\t'pointerover',\n\t'pointerout',\n\t'contextmenu',\n\t'dragenter',\n\t'dragleave',\n\t'drop',\n\t'toggle',\n\t'beforetoggle',\n\t'beforematch'\n];\n\n// `toggle` and `beforetoggle` do not bubble; a root listener only observes them in the capture\n// phase. Every other routed type bubbles, so it stays in the bubble phase and element-level\n// listeners keep their normal ordering. `beforematch` bubbles too (HTML: fired with `bubbles`\n// true), and the browser removes `hidden=\"until-found\"` only after the dispatch has finished, so\n// the bubble phase sees it before the reveal like the capture phase would.\nconst CAPTURE: Partial<Record<SleanEventType, true>> = { toggle: true, beforetoggle: true };\n\n/** Development check, run once per registration: every handled event type must be routable. */\nfunction checkEventTypes(name: string, definition: BehaviorDefinition): void {\n\tfor (const type in definition.events) {\n\t\tif (!definition.events[type as SleanEventType]) continue;\n\t\tif (!(EVENT_TYPES as readonly string[]).includes(type)) {\n\t\t\twarn(name, `\"${type}\" is not a routed event type; use a scoped listener instead.`);\n\t\t}\n\t}\n}\n\n/**\n * Creates a runtime whose shared listeners attach to `root` (`document` by default).\n * Nothing is installed until a behavior that needs an event type is registered.\n */\nexport function createRuntime(options: RuntimeOptions = {}): Runtime {\n\treturn createRuntimeInternal(options.root ?? document);\n}\n\n/** @internal `onDestroy` lets the default-runtime module forget a destroyed instance. */\nexport function createRuntimeInternal(root: RuntimeRoot, onDestroy?: () => void): Runtime {\n\tconst behaviors = new Map<string, BehaviorDefinition>();\n\tconst installed = new Set<SleanEventType>();\n\t// Attribute behaviors (ADR 0009) as [name, definition]: few (usually none), checked on each\n\t// path element.\n\tlet attributes: [string, BehaviorDefinition][] = [];\n\n\t// True while a behavior handler runs: its own stopPropagation is the router's business.\n\tlet routing = false;\n\n\t/**\n\t * Routes `event` to the roots on its path; up to `stop` when application code stopped it\n\t * there (`guard`). Also the root's own listener, where `stop` is never given.\n\t */\n\tconst route = (event: Event, stop: EventTarget | null = null): void => {\n\t\tconst type = event.type as SleanEventType;\n\t\tconst path = event.composedPath();\n\t\tconst first = path[0] as Node | undefined;\n\t\tconst target = (first && first.nodeType === 1 ? first : event.target) as Element;\n\t\t// No try/finally: Rollup keeps everything inside a try block, development checks included.\n\t\trouting = true;\n\t\twalk: for (let i = 0; i < path.length && path[i - 1] !== stop; i++) {\n\t\t\tconst node = path[i] as HTMLElement;\n\t\t\tif (node.nodeType !== 1) continue;\n\t\t\tfor (let a = 0; a < attributes.length; a++) {\n\t\t\t\tconst [behavior, definition] = attributes[a]!;\n\t\t\t\tconst handler = definition.events?.[type];\n\t\t\t\tif (!handler || !node.hasAttribute(definition.attribute!)) continue;\n\t\t\t\t// Not skipped when disabled: a hint explains a disabled control, and a behavior that\n\t\t\t\t// must not act on one (copy) checks `isDisabled()` itself.\n\t\t\t\tif (DEV) validateRoot(behavior, definition, node);\n\t\t\t\t(handler as BehaviorHandler)({ root: node, target, event, runtime });\n\t\t\t\tif (event.cancelBubble) break walk;\n\t\t\t}\n\t\t\tconst name = node.getAttribute('data-slean');\n\t\t\tif (!name) continue;\n\t\t\tconst definition = behaviors.get(name);\n\t\t\tconst handler = definition?.events?.[type];\n\t\t\tif (!handler || isDisabled(node)) continue;\n\t\t\tif (DEV) validateRoot(name, definition as BehaviorDefinition, node);\n\t\t\t(handler as BehaviorHandler)({ root: node, target, event, runtime });\n\t\t\tif (event.cancelBubble) break walk;\n\t\t}\n\t\trouting = false;\n\t};\n\n\t/**\n\t * Application code may stop an event on its way up — a popover's content stops clicks so the\n\t * table header behind it does not sort — and the router listens on the root, above it: the\n\t * primitives inside that element (a select in the popover) would never hear the click. So\n\t * every bubbling routed event is watched from the capture phase: when application code stops\n\t * it at an element below the root, the roots between the target and that element get it\n\t * first, as they would have natively, and only then does it stop. Roots above it are left\n\t * out, as the stop intends; a stop in the capture phase keeps everything out, as natively; a\n\t * behavior's own stop is the router's.\n\t */\n\tconst guard = (event: Event): void => {\n\t\tconst native = event.stopPropagation;\n\t\tevent.stopPropagation = () => {\n\t\t\tconst at = event.currentTarget;\n\t\t\tif (!routing && !event.cancelBubble && event.eventPhase > 1 && at !== root) route(event, at);\n\t\t\tnative.call(event);\n\t\t};\n\t};\n\n\t// Makes the installed set equal to the set of routed event types some registered behavior\n\t// handles. Unroutable types were reported once, at registration.\n\tconst sync = (): void => {\n\t\tattributes = [...behaviors].filter(([, definition]) => definition.attribute);\n\t\tconst needed = new Set<SleanEventType>();\n\t\tfor (const definition of behaviors.values()) {\n\t\t\tconst events = definition.events;\n\t\t\tfor (const type in events) {\n\t\t\t\tif (!events[type as SleanEventType]) continue;\n\t\t\t\tif ((EVENT_TYPES as readonly string[]).includes(type)) needed.add(type as SleanEventType);\n\t\t\t}\n\t\t}\n\t\tfor (const type of needed) {\n\t\t\tif (installed.has(type)) continue;\n\t\t\troot.addEventListener(type, route, CAPTURE[type] === true);\n\t\t\tif (!CAPTURE[type]) root.addEventListener(type, guard, true);\n\t\t\tinstalled.add(type);\n\t\t}\n\t\tfor (const type of installed) {\n\t\t\tif (needed.has(type)) continue;\n\t\t\troot.removeEventListener(type, route, CAPTURE[type] === true);\n\t\t\tif (!CAPTURE[type]) root.removeEventListener(type, guard, true);\n\t\t\tinstalled.delete(type);\n\t\t}\n\t};\n\n\tconst runtime: Runtime = {\n\t\troot,\n\t\tregister(name, definition) {\n\t\t\tbehaviors.set(name, definition);\n\t\t\tif (DEV) checkEventTypes(name, definition);\n\t\t\tif (DEV) resetValidation();\n\t\t\tsync();\n\t\t},\n\t\tunregister(name) {\n\t\t\tif (behaviors.delete(name)) sync();\n\t\t},\n\t\thas: (name) => behaviors.has(name),\n\t\tbehaviors: () => [...behaviors.keys()],\n\t\tlisteners() {\n\t\t\tconst out: Record<string, number> = {};\n\t\t\tfor (const type of installed) out[type] = 1;\n\t\t\treturn out;\n\t\t},\n\t\tdestroy() {\n\t\t\tbehaviors.clear();\n\t\t\tsync();\n\t\t\tuntrackRuntime(runtime);\n\t\t\tonDestroy?.();\n\t\t}\n\t};\n\ttrackRuntime(runtime);\n\treturn runtime;\n}\n"]}
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAC3B,OAAO,EACN,eAAe,EACf,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,IAAI,EACJ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,gEAAgE;AAChE,MAAM,CAAC,MAAM,WAAW,GAA8B;IACrD,OAAO;IACP,UAAU;IACV,SAAS;IACT,OAAO;IACP,SAAS;IACT,UAAU;IACV,OAAO;IACP,QAAQ;IACR,aAAa;IACb,WAAW;IACX,aAAa;IACb,YAAY;IACZ,aAAa;IACb,WAAW;IACX,WAAW;IACX,MAAM;IACN,QAAQ;IACR,cAAc;IACd,aAAa;IACb,OAAO;IACP,SAAS;IACT,gBAAgB;CAChB,CAAC;AAEF,+FAA+F;AAC/F,4FAA4F;AAC5F,8FAA8F;AAC9F,iGAAiG;AACjG,iGAAiG;AACjG,6FAA6F;AAC7F,+FAA+F;AAC/F,MAAM,OAAO,GAA0C;IACtD,MAAM,EAAE,IAAI;IACZ,YAAY,EAAE,IAAI;IAClB,KAAK,EAAE,IAAI;IACX,OAAO,EAAE,IAAI;CACb,CAAC;AAKF;;;;GAIG;AACH,IAAI,UAA4D,CAAC;AAEjE,yCAAyC;AACzC,MAAM,UAAU,aAAa,CAAC,KAAyC;IACtE,UAAU,GAAG,KAAK,CAAC;AACpB,CAAC;AAED,+FAA+F;AAC/F,SAAS,eAAe,CAAC,IAAY,EAAE,UAA8B;IACpE,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC;QACtC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAsB,CAAC;YAAE,SAAS;QACzD,IAAI,CAAE,WAAiC,CAAC,QAAQ,CAAC,IAAI,CAAC,E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,GAAG;gBAAE,eAAe,EAAE,CAAC;YAC3B,IAAI,EAAE,CAAC;QACR,CAAC;QACD,UAAU,CAAC,IAAI;YACd,IAAI,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;gBAAE,IAAI,EAAE,CAAC;QACpC,CAAC;QACD,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC;QAClC,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;QACtC,SAAS;YACR,MAAM,GAAG,GAA2B,EAAE,CAAC;YACvC,KAAK,MAAM,IAAI,IAAI,SAAS;gBAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC5C,OAAO,GAAG,CAAC;QACZ,CAAC;QACD,OAAO;YACN,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,IAAI,EAAE,CAAC;YACP,cAAc,CAAC,OAAO,CAAC,CAAC;YACxB,SAAS,EAAE,EAAE,CAAC;QACf,CAAC;KACD,CAAC;IACF,YAAY,CAAC,OAAO,CAAC,CAAC;IACtB,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import type {\n\tBehaviorDefinition,\n\tBehaviorHandler,\n\tRuntime,\n\tRuntimeOptions,\n\tRuntimeRoot,\n\tSleanEventType\n} from './types.js';\nimport { DEV } from '#env';\nimport {\n\tresetValidation,\n\ttrackRuntime,\n\tuntrackRuntime,\n\tvalidateRoot,\n\twarn\n} from './diagnostics.js';\nimport { isDisabled } from './dom.js';\n\n/** Every event type the router can install, in report order. */\nexport const EVENT_TYPES: readonly SleanEventType[] = [\n\t'click',\n\t'dblclick',\n\t'keydown',\n\t'keyup',\n\t'focusin',\n\t'focusout',\n\t'input',\n\t'change',\n\t'pointerdown',\n\t'pointerup',\n\t'pointerover',\n\t'pointerout',\n\t'contextmenu',\n\t'dragenter',\n\t'dragleave',\n\t'drop',\n\t'toggle',\n\t'beforetoggle',\n\t'beforematch',\n\t'reset',\n\t'invalid',\n\t'animationstart'\n];\n\n// `toggle` and `beforetoggle` do not bubble; a root listener only observes them in the capture\n// phase. Every other routed type bubbles, so it stays in the bubble phase and element-level\n// listeners keep their normal ordering. `beforematch` bubbles too (HTML: fired with `bubbles`\n// true), and the browser removes `hidden=\"until-found\"` only after the dispatch has finished, so\n// the bubble phase sees it before the reveal like the capture phase would. `reset` is watched in\n// the capture phase so that application code stopping it cannot hide it (see `routeResets`).\n// `invalid` does not bubble either: it is seen in the capture phase on its way to the control.\nconst CAPTURE: Partial<Record<SleanEventType, true>> = {\n\ttoggle: true,\n\tbeforetoggle: true,\n\treset: true,\n\tinvalid: true\n};\n\n/** Routes an event along a path of elements of the caller's choosing (see `routeResets`). */\nexport type Walk = (path: EventTarget[]) => void;\n\n/**\n * How a form `reset` is routed, installed by `routeResets()` (`./reset.ts`). A `reset` targets the\n * form while the roots that follow it sit inside the form, off the event's path, so it needs a\n * path of its own; only behaviors that handle `reset` import that code.\n */\nlet resetRoute: ((event: Event, walk: Walk) => void) | undefined;\n\n/** @internal Used by `routeResets()`. */\nexport function setResetRoute(route: (event: Event, walk: Walk) => void): void {\n\tresetRoute = route;\n}\n\n/** Development check, run once per registration: every handled event type must be routable. */\nfunction checkEventTypes(name: string, definition: BehaviorDefinition): void {\n\tfor (const type in definition.events) {\n\t\tif (!definition.events[type as SleanEventType]) continue;\n\t\tif (!(EVENT_TYPES as readonly string[]).includes(type)) {\n\t\t\twarn(name, `\"${type}\" is not a routed event type; use a scoped listener instead.`);\n\t\t} else if (type === 'reset' && !resetRoute) {\n\t\t\twarn(name, 'handles \"reset\" but routeResets() was not called before registering it.');\n\t\t}\n\t}\n}\n\n/**\n * Creates a runtime whose shared listeners attach to `root` (`document` by default).\n * Nothing is installed until a behavior that needs an event type is registered.\n */\nexport function createRuntime(options: RuntimeOptions = {}): Runtime {\n\treturn createRuntimeInternal(options.root ?? document);\n}\n\n/** @internal `onDestroy` lets the default-runtime module forget a destroyed instance. */\nexport function createRuntimeInternal(root: RuntimeRoot, onDestroy?: () => void): Runtime {\n\tconst behaviors = new Map<string, BehaviorDefinition>();\n\tconst installed = new Set<SleanEventType>();\n\t// Attribute behaviors (ADR 0009) as [name, definition]: few (usually none), checked on each\n\t// path element.\n\tlet attributes: [string, BehaviorDefinition][] = [];\n\n\t// True while a behavior handler runs: its own stopPropagation is the router's business.\n\tlet routing = false;\n\n\t/**\n\t * Routes `event` to the roots on its path; up to `stop` when application code stopped it\n\t * there (`guard`). Also the root's own listener, where `stop` is never given. A form `reset`\n\t * goes to the route `routeResets()` installed, which calls back with the path to walk.\n\t */\n\tconst route = (event: Event, stop: EventTarget | null = null, path?: EventTarget[]): void => {\n\t\tif (!path) {\n\t\t\tif (event.type === 'reset') return resetRoute?.(event, (roots) => route(event, null, roots));\n\t\t\tpath = event.composedPath();\n\t\t}\n\t\tconst type = event.type as SleanEventType;\n\t\tconst first = path[0] as Node | undefined;\n\t\tconst target = (first && first.nodeType === 1 ? first : event.target) as Element;\n\t\t// No try/finally: Rollup keeps everything inside a try block, development checks included.\n\t\trouting = true;\n\t\twalk: for (let i = 0; i < path.length && path[i - 1] !== stop; i++) {\n\t\t\tconst node = path[i] as HTMLElement;\n\t\t\tif (node.nodeType !== 1) continue;\n\t\t\tfor (let a = 0; a < attributes.length; a++) {\n\t\t\t\tconst [behavior, definition] = attributes[a]!;\n\t\t\t\tconst handler = definition.events?.[type];\n\t\t\t\tif (!handler || !node.hasAttribute(definition.attribute!)) continue;\n\t\t\t\t// Not skipped when disabled: a hint explains a disabled control, and a behavior that\n\t\t\t\t// must not act on one (copy) checks `isDisabled()` itself.\n\t\t\t\tif (DEV) validateRoot(behavior, definition, node);\n\t\t\t\t(handler as BehaviorHandler)({ root: node, target, event, runtime });\n\t\t\t\tif (event.cancelBubble) break walk;\n\t\t\t}\n\t\t\tconst name = node.getAttribute('data-slean');\n\t\t\tif (!name) continue;\n\t\t\tconst definition = behaviors.get(name);\n\t\t\tconst handler = definition?.events?.[type];\n\t\t\tif (!handler || isDisabled(node)) continue;\n\t\t\tif (DEV) validateRoot(name, definition as BehaviorDefinition, node);\n\t\t\t(handler as BehaviorHandler)({ root: node, target, event, runtime });\n\t\t\tif (event.cancelBubble) break walk;\n\t\t}\n\t\trouting = false;\n\t};\n\n\t/**\n\t * Application code may stop an event on its way up — a popover's content stops clicks so the\n\t * table header behind it does not sort — and the router listens on the root, above it: the\n\t * primitives inside that element (a select in the popover) would never hear the click. So\n\t * every bubbling routed event is watched from the capture phase: when application code stops\n\t * it at an element below the root, the roots between the target and that element get it\n\t * first, as they would have natively, and only then does it stop. Roots above it are left\n\t * out, as the stop intends; a stop in the capture phase keeps everything out, as natively; a\n\t * behavior's own stop is the router's.\n\t */\n\tconst guard = (event: Event): void => {\n\t\tconst native = event.stopPropagation;\n\t\tevent.stopPropagation = () => {\n\t\t\tconst at = event.currentTarget;\n\t\t\tif (!routing && !event.cancelBubble && event.eventPhase > 1 && at !== root) route(event, at);\n\t\t\tnative.call(event);\n\t\t};\n\t};\n\n\t// Makes the installed set equal to the set of routed event types some registered behavior\n\t// handles. Unroutable types were reported once, at registration.\n\tconst sync = (): void => {\n\t\tattributes = [...behaviors].filter(([, definition]) => definition.attribute);\n\t\tconst needed = new Set<SleanEventType>();\n\t\tfor (const definition of behaviors.values()) {\n\t\t\tconst events = definition.events;\n\t\t\tfor (const type in events) {\n\t\t\t\tif (!events[type as SleanEventType]) continue;\n\t\t\t\tif ((EVENT_TYPES as readonly string[]).includes(type)) needed.add(type as SleanEventType);\n\t\t\t}\n\t\t}\n\t\tfor (const type of needed) {\n\t\t\tif (installed.has(type)) continue;\n\t\t\troot.addEventListener(type, route, CAPTURE[type] === true);\n\t\t\tif (!CAPTURE[type]) root.addEventListener(type, guard, true);\n\t\t\tinstalled.add(type);\n\t\t}\n\t\tfor (const type of installed) {\n\t\t\tif (needed.has(type)) continue;\n\t\t\troot.removeEventListener(type, route, CAPTURE[type] === true);\n\t\t\tif (!CAPTURE[type]) root.removeEventListener(type, guard, true);\n\t\t\tinstalled.delete(type);\n\t\t}\n\t};\n\n\tconst runtime: Runtime = {\n\t\troot,\n\t\tregister(name, definition) {\n\t\t\tbehaviors.set(name, definition);\n\t\t\tif (DEV) checkEventTypes(name, definition);\n\t\t\tif (DEV) resetValidation();\n\t\t\tsync();\n\t\t},\n\t\tunregister(name) {\n\t\t\tif (behaviors.delete(name)) sync();\n\t\t},\n\t\thas: (name) => behaviors.has(name),\n\t\tbehaviors: () => [...behaviors.keys()],\n\t\tlisteners() {\n\t\t\tconst out: Record<string, number> = {};\n\t\t\tfor (const type of installed) out[type] = 1;\n\t\t\treturn out;\n\t\t},\n\t\tdestroy() {\n\t\t\tbehaviors.clear();\n\t\t\tsync();\n\t\t\tuntrackRuntime(runtime);\n\t\t\tonDestroy?.();\n\t\t}\n\t};\n\ttrackRuntime(runtime);\n\treturn runtime;\n}\n"]}
package/dist/types.d.ts CHANGED
@@ -2,14 +2,21 @@
2
2
  * Event types the shared router is allowed to install. Nothing outside this list is ever
3
3
  * installed generically; in particular `pointermove`, `scroll` and `resize` belong to scoped
4
4
  * controllers (Tier 2) with an explicit lifetime. `pointerover` and `pointerout` are routed: they
5
- * bubble and fire when the pointer crosses an element boundary, not on every movement (tooltip,
6
- * toast). `contextmenu` is routed for the context menu: it bubbles and fires once per request
7
- * (secondary click, long press, the context-menu key or Shift+F10). `dragenter`, `dragleave` and
8
- * `drop` are routed for the file drop area; `dragover`, which fires continuously, is not.
5
+ * bubble and fire when the pointer crosses an element boundary, not on every movement (hint,
6
+ * hover card, toast). `contextmenu` is routed for the menu's context-menu module: it bubbles and
7
+ * fires once per request (secondary click, long press, the context-menu key or Shift+F10).
8
+ * `dragenter`, `dragleave` and `drop` are routed for the file drop area; `dragover`, which fires
9
+ * continuously, is not.
9
10
  * `beforematch` is routed for the findable primitive: the browser fires it, bubbling, at a
10
11
  * `hidden="until-found"` element that find-in-page or a fragment navigation is about to reveal.
12
+ * `reset` is routed for owned interfaces that draw a native element's value (ADR 0011 §3.5): its
13
+ * target is the form, so the router calls the handlers of the roots that contain the form's
14
+ * controls, one task after the event, when the form has reset them (`routeResets()`).
15
+ * `invalid` is routed for field validation (ADR 0011 §4): the browser fires it, not bubbling and
16
+ * cancelable, at each control that fails constraint validation on submit, `checkValidity()` or
17
+ * `reportValidity()`; the capture phase sees it on the way to the control.
11
18
  */
12
- export type SleanEventType = 'click' | 'dblclick' | 'keydown' | 'keyup' | 'focusin' | 'focusout' | 'input' | 'change' | 'pointerdown' | 'pointerup' | 'pointerover' | 'pointerout' | 'contextmenu' | 'dragenter' | 'dragleave' | 'drop' | 'toggle' | 'beforetoggle' | 'beforematch';
19
+ export type SleanEventType = 'click' | 'dblclick' | 'keydown' | 'keyup' | 'focusin' | 'focusout' | 'input' | 'change' | 'pointerdown' | 'pointerup' | 'pointerover' | 'pointerout' | 'contextmenu' | 'dragenter' | 'dragleave' | 'drop' | 'toggle' | 'beforetoggle' | 'beforematch' | 'reset' | 'invalid' | 'animationstart';
13
20
  /** Native event class per routed event type. */
14
21
  export type SleanEventMap = Pick<HTMLElementEventMap, SleanEventType>;
15
22
  /** What a behavior handler receives. `target` is the deepest element of the composed path. */
@@ -31,10 +38,12 @@ export interface BehaviorDefinition {
31
38
  /**
32
39
  * An attribute behavior (ADR 0009): its roots are the elements that carry this attribute
33
40
  * (`data-slean-hint`, `data-slean-copy`) rather than `data-slean="<name>"`, so it can sit on
34
- * any element, a root of another behavior included. Must start with `data-slean-`. The router
35
- * checks it on each element of the event path, beside the `data-slean` marker.
41
+ * any element, a root of another behavior included. Starts with `data-slean-`, or is
42
+ * `interestfor`: the platform attribute with which a trigger names its hover card (ADR 0011
43
+ * §1.1), so the hover card behavior hears its triggers as well as its `data-slean` cards. The
44
+ * router checks it on each element of the event path, beside the `data-slean` marker.
36
45
  */
37
- attribute?: `data-slean-${string}`;
46
+ attribute?: `data-slean-${string}` | 'interestfor';
38
47
  /**
39
48
  * Development-only markup validation. Called once per root on the first routed event, in
40
49
  * development builds only; each returned string is printed through `warn()`. Primitives may
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Event types the shared router is allowed to install. Nothing outside this list is ever\n * installed generically; in particular `pointermove`, `scroll` and `resize` belong to scoped\n * controllers (Tier 2) with an explicit lifetime. `pointerover` and `pointerout` are routed: they\n * bubble and fire when the pointer crosses an element boundary, not on every movement (tooltip,\n * toast). `contextmenu` is routed for the context menu: it bubbles and fires once per request\n * (secondary click, long press, the context-menu key or Shift+F10). `dragenter`, `dragleave` and\n * `drop` are routed for the file drop area; `dragover`, which fires continuously, is not.\n * `beforematch` is routed for the findable primitive: the browser fires it, bubbling, at a\n * `hidden=\"until-found\"` element that find-in-page or a fragment navigation is about to reveal.\n */\nexport type SleanEventType =\n\t| 'click'\n\t| 'dblclick'\n\t| 'keydown'\n\t| 'keyup'\n\t| 'focusin'\n\t| 'focusout'\n\t| 'input'\n\t| 'change'\n\t| 'pointerdown'\n\t| 'pointerup'\n\t| 'pointerover'\n\t| 'pointerout'\n\t| 'contextmenu'\n\t| 'dragenter'\n\t| 'dragleave'\n\t| 'drop'\n\t| 'toggle'\n\t| 'beforetoggle'\n\t| 'beforematch';\n\n/** Native event class per routed event type. */\nexport type SleanEventMap = Pick<HTMLElementEventMap, SleanEventType>;\n\n/** What a behavior handler receives. `target` is the deepest element of the composed path. */\nexport interface BehaviorContext<E extends Event = Event> {\n\troot: HTMLElement;\n\ttarget: Element;\n\tevent: E;\n\truntime: Runtime;\n}\n\nexport type BehaviorHandler<E extends Event = Event> = (context: BehaviorContext<E>) => void;\n\nexport type BehaviorEvents = {\n\t[K in SleanEventType]?: BehaviorHandler<SleanEventMap[K]>;\n};\n\nexport interface BehaviorDefinition {\n\t/** Runtime tier as declared in the primitive's contract (ADR 0003). Tier 0 never registers. */\n\ttier: 1 | 2;\n\t/** Handlers keyed by event type. Only the listed types get a shared listener. */\n\tevents?: BehaviorEvents;\n\t/**\n\t * An attribute behavior (ADR 0009): its roots are the elements that carry this attribute\n\t * (`data-slean-hint`, `data-slean-copy`) rather than `data-slean=\"<name>\"`, so it can sit on\n\t * any element, a root of another behavior included. Must start with `data-slean-`. The router\n\t * checks it on each element of the event path, beside the `data-slean` marker.\n\t */\n\tattribute?: `data-slean-${string}`;\n\t/**\n\t * Development-only markup validation. Called once per root on the first routed event, in\n\t * development builds only; each returned string is printed through `warn()`. Primitives may\n\t * strip it from production definitions.\n\t */\n\tvalidate?: (root: HTMLElement) => string[];\n}\n\nexport type RuntimeRoot = Document | ShadowRoot | HTMLElement;\n\nexport interface RuntimeOptions {\n\t/** Event target the shared listeners attach to. Defaults to `document`. */\n\troot?: RuntimeRoot;\n}\n\nexport interface Runtime {\n\treadonly root: RuntimeRoot;\n\t/** Idempotent: registering the same name again replaces the definition without adding listeners. */\n\tregister(name: string, definition: BehaviorDefinition): void;\n\tunregister(name: string): void;\n\thas(name: string): boolean;\n\tbehaviors(): string[];\n\t/** Installed shared listeners per event type; every installed type maps to exactly 1. */\n\tlisteners(): Record<string, number>;\n\t/** Removes every listener and definition. A destroyed runtime must not be reused. */\n\tdestroy(): void;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Event types the shared router is allowed to install. Nothing outside this list is ever\n * installed generically; in particular `pointermove`, `scroll` and `resize` belong to scoped\n * controllers (Tier 2) with an explicit lifetime. `pointerover` and `pointerout` are routed: they\n * bubble and fire when the pointer crosses an element boundary, not on every movement (hint,\n * hover card, toast). `contextmenu` is routed for the menu's context-menu module: it bubbles and\n * fires once per request (secondary click, long press, the context-menu key or Shift+F10).\n * `dragenter`, `dragleave` and `drop` are routed for the file drop area; `dragover`, which fires\n * continuously, is not.\n * `beforematch` is routed for the findable primitive: the browser fires it, bubbling, at a\n * `hidden=\"until-found\"` element that find-in-page or a fragment navigation is about to reveal.\n * `reset` is routed for owned interfaces that draw a native element's value (ADR 0011 §3.5): its\n * target is the form, so the router calls the handlers of the roots that contain the form's\n * controls, one task after the event, when the form has reset them (`routeResets()`).\n * `invalid` is routed for field validation (ADR 0011 §4): the browser fires it, not bubbling and\n * cancelable, at each control that fails constraint validation on submit, `checkValidity()` or\n * `reportValidity()`; the capture phase sees it on the way to the control.\n */\nexport type SleanEventType =\n\t| 'click'\n\t| 'dblclick'\n\t| 'keydown'\n\t| 'keyup'\n\t| 'focusin'\n\t| 'focusout'\n\t| 'input'\n\t| 'change'\n\t| 'pointerdown'\n\t| 'pointerup'\n\t| 'pointerover'\n\t| 'pointerout'\n\t| 'contextmenu'\n\t| 'dragenter'\n\t| 'dragleave'\n\t| 'drop'\n\t| 'toggle'\n\t| 'beforetoggle'\n\t| 'beforematch'\n\t| 'reset'\n\t| 'invalid'\n\t| 'animationstart';\n\n/** Native event class per routed event type. */\nexport type SleanEventMap = Pick<HTMLElementEventMap, SleanEventType>;\n\n/** What a behavior handler receives. `target` is the deepest element of the composed path. */\nexport interface BehaviorContext<E extends Event = Event> {\n\troot: HTMLElement;\n\ttarget: Element;\n\tevent: E;\n\truntime: Runtime;\n}\n\nexport type BehaviorHandler<E extends Event = Event> = (context: BehaviorContext<E>) => void;\n\nexport type BehaviorEvents = {\n\t[K in SleanEventType]?: BehaviorHandler<SleanEventMap[K]>;\n};\n\nexport interface BehaviorDefinition {\n\t/** Runtime tier as declared in the primitive's contract (ADR 0003). Tier 0 never registers. */\n\ttier: 1 | 2;\n\t/** Handlers keyed by event type. Only the listed types get a shared listener. */\n\tevents?: BehaviorEvents;\n\t/**\n\t * An attribute behavior (ADR 0009): its roots are the elements that carry this attribute\n\t * (`data-slean-hint`, `data-slean-copy`) rather than `data-slean=\"<name>\"`, so it can sit on\n\t * any element, a root of another behavior included. Starts with `data-slean-`, or is\n\t * `interestfor`: the platform attribute with which a trigger names its hover card (ADR 0011\n\t * §1.1), so the hover card behavior hears its triggers as well as its `data-slean` cards. The\n\t * router checks it on each element of the event path, beside the `data-slean` marker.\n\t */\n\tattribute?: `data-slean-${string}` | 'interestfor';\n\t/**\n\t * Development-only markup validation. Called once per root on the first routed event, in\n\t * development builds only; each returned string is printed through `warn()`. Primitives may\n\t * strip it from production definitions.\n\t */\n\tvalidate?: (root: HTMLElement) => string[];\n}\n\nexport type RuntimeRoot = Document | ShadowRoot | HTMLElement;\n\nexport interface RuntimeOptions {\n\t/** Event target the shared listeners attach to. Defaults to `document`. */\n\troot?: RuntimeRoot;\n}\n\nexport interface Runtime {\n\treadonly root: RuntimeRoot;\n\t/** Idempotent: registering the same name again replaces the definition without adding listeners. */\n\tregister(name: string, definition: BehaviorDefinition): void;\n\tunregister(name: string): void;\n\thas(name: string): boolean;\n\tbehaviors(): string[];\n\t/** Installed shared listeners per event type; every installed type maps to exactly 1. */\n\tlisteners(): Record<string, number>;\n\t/** Removes every listener and definition. A destroyed runtime must not be reused. */\n\tdestroy(): void;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svelte-lean/core",
3
- "version": "0.13.4",
3
+ "version": "0.14.0",
4
4
  "description": "Svelte Lean runtime kernel: behavior registry, shared event router, DOM and keyboard helpers.",
5
5
  "license": "MIT",
6
6
  "author": "Ömer Say",