@svelte-lean/core 0.12.0 → 0.13.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 +16 -0
- package/dist/runtime.js +36 -4
- package/dist/runtime.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @svelte-lean/core
|
|
2
2
|
|
|
3
|
+
## 0.13.1
|
|
4
|
+
|
|
5
|
+
No changes in this release.
|
|
6
|
+
|
|
7
|
+
## 0.13.0
|
|
8
|
+
|
|
9
|
+
No changes in this release.
|
|
10
|
+
|
|
11
|
+
## 0.12.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- c178475: An event that application code stops on its way up still reaches the primitives inside the element that stopped it. The router listens on the document; a popover whose content stops clicks (so the table header behind it does not sort) cut every primitive inside it off — a select in the popover would not open. The router now watches each routed event from the capture phase: when application code stops it at an element, the roots between the target and that element get it first, as they would natively, and only then does it stop. Roots above the stop are left out, as the stop intends; a stop in the capture phase keeps everything out, as natively.
|
|
16
|
+
|
|
17
|
+
The kernel grows by about 70 B (brotli) in every primitive bundle; the size budgets of tabs, menu, listbox, tooltip, range-slider, number-field, toggle, hover-card and hint are raised by the methodology's rule (measured + 10 %, to the next 100 B).
|
|
18
|
+
|
|
3
19
|
## 0.12.0
|
|
4
20
|
|
|
5
21
|
No changes in this release.
|
package/dist/runtime.js
CHANGED
|
@@ -53,12 +53,20 @@ export function createRuntimeInternal(root, onDestroy) {
|
|
|
53
53
|
// Attribute behaviors (ADR 0009) as [name, definition]: few (usually none), checked on each
|
|
54
54
|
// path element.
|
|
55
55
|
let attributes = [];
|
|
56
|
-
|
|
56
|
+
// True while a behavior handler runs: its own stopPropagation is the router's business.
|
|
57
|
+
let routing = false;
|
|
58
|
+
/**
|
|
59
|
+
* 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.
|
|
61
|
+
*/
|
|
62
|
+
const route = (event, stop = null) => {
|
|
57
63
|
const type = event.type;
|
|
58
64
|
const path = event.composedPath();
|
|
59
65
|
const first = path[0];
|
|
60
66
|
const target = (first && first.nodeType === 1 ? first : event.target);
|
|
61
|
-
|
|
67
|
+
// No try/finally: Rollup keeps everything inside a try block, development checks included.
|
|
68
|
+
routing = true;
|
|
69
|
+
walk: for (let i = 0; i < path.length && path[i - 1] !== stop; i++) {
|
|
62
70
|
const node = path[i];
|
|
63
71
|
if (node.nodeType !== 1)
|
|
64
72
|
continue;
|
|
@@ -73,7 +81,7 @@ export function createRuntimeInternal(root, onDestroy) {
|
|
|
73
81
|
validateRoot(behavior, definition, node);
|
|
74
82
|
handler({ root: node, target, event, runtime });
|
|
75
83
|
if (event.cancelBubble)
|
|
76
|
-
|
|
84
|
+
break walk;
|
|
77
85
|
}
|
|
78
86
|
const name = node.getAttribute('data-slean');
|
|
79
87
|
if (!name)
|
|
@@ -86,8 +94,28 @@ export function createRuntimeInternal(root, onDestroy) {
|
|
|
86
94
|
validateRoot(name, definition, node);
|
|
87
95
|
handler({ root: node, target, event, runtime });
|
|
88
96
|
if (event.cancelBubble)
|
|
89
|
-
|
|
97
|
+
break walk;
|
|
90
98
|
}
|
|
99
|
+
routing = false;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Application code may stop an event on its way up — a popover's content stops clicks so the
|
|
103
|
+
* table header behind it does not sort — and the router listens on the root, above it: the
|
|
104
|
+
* primitives inside that element (a select in the popover) would never hear the click. So
|
|
105
|
+
* every bubbling routed event is watched from the capture phase: when application code stops
|
|
106
|
+
* it at an element below the root, the roots between the target and that element get it
|
|
107
|
+
* first, as they would have natively, and only then does it stop. Roots above it are left
|
|
108
|
+
* out, as the stop intends; a stop in the capture phase keeps everything out, as natively; a
|
|
109
|
+
* behavior's own stop is the router's.
|
|
110
|
+
*/
|
|
111
|
+
const guard = (event) => {
|
|
112
|
+
const native = event.stopPropagation;
|
|
113
|
+
event.stopPropagation = () => {
|
|
114
|
+
const at = event.currentTarget;
|
|
115
|
+
if (!routing && !event.cancelBubble && event.eventPhase > 1 && at !== root)
|
|
116
|
+
route(event, at);
|
|
117
|
+
native.call(event);
|
|
118
|
+
};
|
|
91
119
|
};
|
|
92
120
|
// Makes the installed set equal to the set of routed event types some registered behavior
|
|
93
121
|
// handles. Unroutable types were reported once, at registration.
|
|
@@ -107,12 +135,16 @@ export function createRuntimeInternal(root, onDestroy) {
|
|
|
107
135
|
if (installed.has(type))
|
|
108
136
|
continue;
|
|
109
137
|
root.addEventListener(type, route, CAPTURE[type] === true);
|
|
138
|
+
if (!CAPTURE[type])
|
|
139
|
+
root.addEventListener(type, guard, true);
|
|
110
140
|
installed.add(type);
|
|
111
141
|
}
|
|
112
142
|
for (const type of installed) {
|
|
113
143
|
if (needed.has(type))
|
|
114
144
|
continue;
|
|
115
145
|
root.removeEventListener(type, route, CAPTURE[type] === true);
|
|
146
|
+
if (!CAPTURE[type])
|
|
147
|
+
root.removeEventListener(type, guard, true);
|
|
116
148
|
installed.delete(type);
|
|
117
149
|
}
|
|
118
150
|
};
|
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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\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"]}
|
|
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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AC,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"]}
|