@svelte-lean/core 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/runtime.js +5 -2
- package/dist/runtime.js.map +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @svelte-lean/core
|
|
2
2
|
|
|
3
|
+
## 0.7.1
|
|
4
|
+
|
|
5
|
+
No changes in this release.
|
|
6
|
+
|
|
7
|
+
## 0.7.0
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- 3bb9f7d: `beforematch` joins the routed event types (`EVENT_TYPES`, `SleanEventType`), in the bubble phase:
|
|
12
|
+
the event bubbles, and the browser removes `hidden="until-found"` only after its dispatch. The
|
|
13
|
+
kernel grows by 3 B brotli.
|
|
14
|
+
|
|
3
15
|
## 0.6.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/runtime.js
CHANGED
|
@@ -20,11 +20,14 @@ export const EVENT_TYPES = [
|
|
|
20
20
|
'dragleave',
|
|
21
21
|
'drop',
|
|
22
22
|
'toggle',
|
|
23
|
-
'beforetoggle'
|
|
23
|
+
'beforetoggle',
|
|
24
|
+
'beforematch'
|
|
24
25
|
];
|
|
25
26
|
// `toggle` and `beforetoggle` do not bubble; a root listener only observes them in the capture
|
|
26
27
|
// phase. Every other routed type bubbles, so it stays in the bubble phase and element-level
|
|
27
|
-
// listeners keep their normal ordering.
|
|
28
|
+
// listeners keep their normal ordering. `beforematch` bubbles too (HTML: fired with `bubbles`
|
|
29
|
+
// 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.
|
|
28
31
|
const CAPTURE = { toggle: true, beforetoggle: true };
|
|
29
32
|
/** Development check, run once per registration: every handled event type must be routable. */
|
|
30
33
|
function checkEventTypes(name, definition) {
|
package/dist/runtime.js.map
CHANGED
|
@@ -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;IACX,aAAa;IACb,YAAY;IACZ,aAAa;IACb,WAAW;IACX,WAAW;IACX,MAAM;IACN,QAAQ;IACR,cAAc;CACd,CAAC;AAEF,+FAA+F;AAC/F,4FAA4F;AAC5F,wCAAwC;AACxC,MAAM,OAAO,GAA0C,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;AAE5F,+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,EAAE,CAAC;YACxD,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,8DAA8D,CAAC,CAAC;QACpF,CAAC;IACF,CAAC;AACF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,UAA0B,EAAE;IACzD,OAAO,qBAAqB,CAAC,OAAO,CAAC,IAAI,IAAI,QAAQ,CAAC,CAAC;AACxD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,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];\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.\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\tconst route = (event: Event): 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\tfor (let i = 0; i < path.length; 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) return;\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) return;\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\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\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,G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I,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\tconst route = (event: Event): 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\tfor (let i = 0; i < path.length; 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) return;\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) return;\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\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\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
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
* toast). `contextmenu` is routed for the context menu: it bubbles and fires once per request
|
|
7
7
|
* (secondary click, long press, the context-menu key or Shift+F10). `dragenter`, `dragleave` and
|
|
8
8
|
* `drop` are routed for the file drop area; `dragover`, which fires continuously, is not.
|
|
9
|
+
* `beforematch` is routed for the findable primitive: the browser fires it, bubbling, at a
|
|
10
|
+
* `hidden="until-found"` element that find-in-page or a fragment navigation is about to reveal.
|
|
9
11
|
*/
|
|
10
|
-
export type SleanEventType = 'click' | 'dblclick' | 'keydown' | 'keyup' | 'focusin' | 'focusout' | 'input' | 'change' | 'pointerdown' | 'pointerup' | 'pointerover' | 'pointerout' | 'contextmenu' | 'dragenter' | 'dragleave' | 'drop' | 'toggle' | 'beforetoggle';
|
|
12
|
+
export type SleanEventType = 'click' | 'dblclick' | 'keydown' | 'keyup' | 'focusin' | 'focusout' | 'input' | 'change' | 'pointerdown' | 'pointerup' | 'pointerover' | 'pointerout' | 'contextmenu' | 'dragenter' | 'dragleave' | 'drop' | 'toggle' | 'beforetoggle' | 'beforematch';
|
|
11
13
|
/** Native event class per routed event type. */
|
|
12
14
|
export type SleanEventMap = Pick<HTMLElementEventMap, SleanEventType>;
|
|
13
15
|
/** What a behavior handler receives. `target` is the deepest element of the composed path. */
|
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 */\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\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 (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"]}
|