@amazon/vinyl-tsx 3.2.3-next.20261013174635 → 3.2.3-next.20261013210532

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/dist/index.cjs CHANGED
@@ -110,7 +110,26 @@ function walkDomDepthFirst(node, callback) {
110
110
  }
111
111
 
112
112
  // src/extensions/connectedObserver.ts
113
- function initializeConnectedObserver() {
113
+ var CONNECTION_CALLBACKS = /* @__PURE__ */ Symbol.for(
114
+ "@amazon/vinyl-tsx/connectionCallbacks"
115
+ );
116
+ function callbacksOf(node) {
117
+ const observed = node;
118
+ let callbacks = observed[CONNECTION_CALLBACKS];
119
+ if (!callbacks) {
120
+ callbacks = { connect: /* @__PURE__ */ new Set(), disconnect: /* @__PURE__ */ new Set() };
121
+ observed[CONNECTION_CALLBACKS] = callbacks;
122
+ }
123
+ return callbacks;
124
+ }
125
+ function notify(node, type) {
126
+ var _a;
127
+ const callbacks = (_a = node[CONNECTION_CALLBACKS]) == null ? void 0 : _a[type];
128
+ if (callbacks == null ? void 0 : callbacks.size) for (const callback of [...callbacks]) callback();
129
+ }
130
+ function initializeConnectedObserver(options = {}) {
131
+ var _a;
132
+ const events = (_a = options.events) != null ? _a : true;
114
133
  const observer = new MutationObserver((mutations) => {
115
134
  const removed = /* @__PURE__ */ new Set();
116
135
  const added = /* @__PURE__ */ new Set();
@@ -122,17 +141,23 @@ function initializeConnectedObserver() {
122
141
  for (const node of mutation.addedNodes) {
123
142
  if (removed.has(node)) continue;
124
143
  walkDomDepthFirst(node, (iNode) => {
125
- iNode.dispatchEvent(
126
- new CustomEvent("connect", { bubbles: false })
127
- );
144
+ notify(iNode, "connect");
145
+ if (events) {
146
+ iNode.dispatchEvent(
147
+ new CustomEvent("connect", { bubbles: false })
148
+ );
149
+ }
128
150
  });
129
151
  }
130
152
  for (const node of mutation.removedNodes) {
131
153
  if (added.has(node)) continue;
132
154
  walkDomDepthFirst(node, (iNode) => {
133
- iNode.dispatchEvent(
134
- new CustomEvent("disconnect", { bubbles: false })
135
- );
155
+ notify(iNode, "disconnect");
156
+ if (events) {
157
+ iNode.dispatchEvent(
158
+ new CustomEvent("disconnect", { bubbles: false })
159
+ );
160
+ }
136
161
  });
137
162
  }
138
163
  }
@@ -155,10 +180,15 @@ function onConnect(target, callback) {
155
180
  sub == null ? void 0 : sub();
156
181
  sub = null;
157
182
  };
183
+ const callbacks = callbacksOf(target);
184
+ callbacks.connect.add(onConnect2);
185
+ callbacks.disconnect.add(onDisconnect);
158
186
  target.addEventListener("connect", onConnect2);
159
187
  target.addEventListener("disconnect", onDisconnect);
160
188
  if (target.isConnected) onConnect2();
161
189
  return () => {
190
+ callbacks.connect.delete(onConnect2);
191
+ callbacks.disconnect.delete(onDisconnect);
162
192
  target.removeEventListener("connect", onConnect2);
163
193
  target.removeEventListener("disconnect", onDisconnect);
164
194
  onDisconnect();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts", "../src/domUtil.ts", "../src/extensions/connectedObserver.ts", "../src/ActiveText.ts", "../src/extensions/applyClassList.ts", "../src/extensions/applyPassiveHandler.ts", "../src/extensions/applyStyles.ts", "../src/extensions/applyVisibility.ts", "../src/jsx.ts"],
4
- "sourcesContent": ["/** Auto-generated from build scripts */\nexport * from './ActiveText'\nexport * from './domUtil'\nexport * from './extensions/applyClassList'\nexport * from './extensions/applyPassiveHandler'\nexport * from './extensions/applyStyles'\nexport * from './extensions/applyVisibility'\nexport * from './extensions/connectedObserver'\nexport * from './extensions/HookExtension'\nexport * from './jsx'\nexport * from './type'\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport function el<K extends keyof HTMLElementTagNameMap>(\n selectors: K,\n parentNode?: ParentNode\n): HTMLElementTagNameMap[K]\nexport function el(selectors: string, parentNode?: ParentNode): HTMLElement\nexport function el<E extends Element = Element>(\n selectors: string,\n parentNode: ParentNode = document\n): E {\n const element = parentNode.querySelector(selectors)\n if (!element) throw new Error(`${selectors} must be a DOM element`)\n return element as E\n}\n\nexport interface QuerySelector {\n <K extends keyof HTMLElementTagNameMap>(\n selectors: K,\n parentNode?: ParentNode\n ): HTMLElementTagNameMap[K]\n (selectors: string): HTMLElement\n}\n\nexport function bindQuerySelector(parentNode: ParentNode): QuerySelector {\n return (selectors: string) => el(selectors, parentNode)\n}\n\nexport function hide(element: HTMLElement) {\n element.style.display = 'none'\n}\n\nexport function show(element: HTMLElement) {\n element.style.removeProperty('display')\n}\n\nexport function getVisible(element: HTMLElement): boolean {\n return element.style.display !== 'none'\n}\n\nexport function setVisible(element: HTMLElement, value: boolean) {\n if (getVisible(element) === value) return\n if (value) show(element)\n else hide(element)\n}\n\nexport function isHidden(element: HTMLElement) {\n let node: HTMLElement | null = element\n while (node) {\n if (getComputedStyle(node).display === 'none') return true\n node = node.parentElement\n }\n return false\n}\n\nexport function isInputElement(\n value: Element | null\n): value is HTMLInputElement {\n return value?.tagName.toLowerCase() === 'input'\n}\n\n/**\n * Adds or removes a class token to an element.\n *\n * @param value The element whose classList to modify.\n * @param token The class token.\n * @param toggled If true, the token is added, if false, removed.\n */\nexport function setClassToken(\n value: HTMLElement,\n token: string,\n toggled: boolean\n) {\n if (toggled) {\n value.classList.add(token)\n } else {\n value.classList.remove(token)\n }\n}\n\nexport type ElementInitOptions = {\n readonly parent?: HTMLElement\n readonly className?: string\n}\n\n/**\n * Recursively walks a node hierarchy, invoking a callback for every node, depth first.\n *\n * @param node\n * @param callback\n */\nexport function walkDomDepthFirst(\n node: Node | undefined | null,\n callback: (node: Node) => void\n) {\n if (!node) return\n let next = node.firstChild\n while (next) {\n // Snapshot the sibling before recursing so a callback that moves\n // `next` can't sever the chain and skip the rest of the row.\n const after = next.nextSibling\n walkDomDepthFirst(next, callback)\n next = after\n }\n callback(node)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { walkDomDepthFirst } from '../domUtil'\nimport type { Maybe, Unsubscribe } from '@amazon/vinyl-util'\n\n/**\n * Dispatches a 'connected' event on nodes attached to the dom, dispatches 'disconnected' when removed.\n * Allows nodes to observe connected changes without creating a memory leak.\n */\nexport function initializeConnectedObserver(): Unsubscribe {\n const observer = new MutationObserver((mutations) => {\n const removed = new Set<Node>()\n const added = new Set<Node>()\n\n // First pass: flatten removed and added nodes so we can detect nodes re-ordered.\n for (const mutation of mutations) {\n mutation.removedNodes.forEach((node) => removed.add(node))\n mutation.addedNodes.forEach((node) => added.add(node))\n }\n\n // Second pass: handle added/removed, skipping reorders\n for (const mutation of mutations) {\n for (const node of mutation.addedNodes) {\n if (removed.has(node)) continue\n walkDomDepthFirst(node, (iNode) => {\n iNode.dispatchEvent(\n new CustomEvent('connect', { bubbles: false })\n )\n })\n }\n\n for (const node of mutation.removedNodes) {\n if (added.has(node)) continue\n walkDomDepthFirst(node, (iNode) => {\n iNode.dispatchEvent(\n new CustomEvent('disconnect', { bubbles: false })\n )\n })\n }\n }\n })\n\n observer.observe(document, { childList: true, subtree: true })\n\n return () => {\n observer.disconnect()\n }\n}\n\n/**\n * Invokes a callback when the given target is connected to the DOM.\n * If the callback returns a function, that function will be invoked when disconnected.\n *\n * @param target\n * @param callback\n */\nexport function onConnect<T extends Node>(\n target: T,\n callback: (node: T) => Maybe<Unsubscribe> | void\n): Unsubscribe {\n let sub: Maybe<Unsubscribe> | void = null\n let connected = false\n const onConnect = () => {\n if (connected) return\n connected = true\n sub = callback(target)\n }\n const onDisconnect = () => {\n connected = false\n sub?.()\n sub = null\n }\n target.addEventListener('connect', onConnect)\n target.addEventListener('disconnect', onDisconnect)\n if (target.isConnected) onConnect()\n return () => {\n target.removeEventListener('connect', onConnect)\n target.removeEventListener('disconnect', onDisconnect)\n onDisconnect()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { onConnect } from './extensions/connectedObserver'\n\n/**\n * A Text node bound to a data provider.\n * Created automatically when a child is a ObservableValue.\n * textContent will only be updated when the node is on the DOM.\n */\nexport function ActiveText<T>(data: ObservableValue<T>): Text {\n const text = document.createTextNode(String(data.value ?? ''))\n onConnect(text, () => {\n return data.onData((value) => {\n text.textContent = String(value ?? '')\n })\n })\n return text\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n isObservableValue,\n type ObservableValue,\n} from '@amazon/vinyl-observable'\nimport { onConnect } from './connectedObserver'\nimport {\n createDisposer,\n noop,\n type Maybe,\n type Unsubscribe,\n} from '@amazon/vinyl-util'\n\nexport function applyClassList(\n element: HTMLElement,\n classList: readonly (Maybe<string> | ObservableValue<Maybe<string>>)[]\n): Unsubscribe {\n const strings = classList.filter((s) => typeof s === 'string')\n // The empty string is not a valid class token \u2014 `add` rejects it \u2014 so it is\n // dropped here as `bindClass` drops it for an observable token.\n const tokens = strings.filter((s) => s !== '')\n if (tokens.length) element.classList.add(...tokens)\n if (strings.length < classList.length) {\n return onConnect(element, () => {\n const { add, dispose } = createDisposer()\n for (const dP of classList.filter(isObservableValue)) {\n add(bindClass(element, dP))\n }\n return dispose\n })\n }\n return noop\n}\n\nfunction bindClass(\n element: HTMLElement,\n tokenProvider: ObservableValue<Maybe<string>>\n): Unsubscribe {\n let current: string | null = null\n const dataSub = tokenProvider.onData((className) => {\n if (current) element.classList.remove(current)\n if (className) {\n current = className\n element.classList.add(className)\n } else {\n current = null\n }\n })\n return () => {\n if (current != null) element.classList.remove(current)\n dataSub()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { HookExtension } from './HookExtension'\n\nexport const passiveEventHandlers = {\n ontouchstart: /* @__PURE__ */ applyPassiveHandler('ontouchstart'),\n ontouchmove: /* @__PURE__ */ applyPassiveHandler('ontouchmove'),\n onwheel: /* @__PURE__ */ applyPassiveHandler('onwheel'),\n} as const\n\nfunction applyPassiveHandler<K extends keyof GlobalEventHandlers>(\n key: K\n): HookExtension<GlobalEventHandlers[K]> {\n const eventName = key.substring(2)\n return (element: HTMLElement, handler: GlobalEventHandlers[K]) => {\n element.addEventListener(eventName, handler as any, { passive: true })\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { onConnect } from './connectedObserver'\nimport { toKebabCase } from '@amazon/vinyl-util'\nimport {\n isObservableValue,\n type MaybeObservableValue,\n} from '@amazon/vinyl-observable'\nimport type { Maybe } from '@amazon/vinyl-util'\n\n/**\n * The shape accepted by the `style` jsx prop. Allows the typed CSSStyleDeclaration\n * fields plus any CSS custom property key (must start with `--`). Null / undefined\n * clear the CSS property (via setProperty(name, null)), so values are Maybe-wrapped\n * here even though bindable IDL props reject null.\n */\nexport type StyleProp = {\n [K in keyof Partial<CSSStyleDeclaration>]: MaybeObservableValue<\n Maybe<CSSStyleDeclaration[K]>\n >\n} & {\n readonly [customProperty: `--${string}`]: MaybeObservableValue<\n Maybe<string>\n >\n}\n\nexport function applyStyles(element: HTMLElement, style: StyleProp) {\n // noinspection SuspiciousTypeOfGuard\n if (typeof style === 'string') {\n // A Partial style declaration type does not prohibit a string type.\n throw new Error('expected style property to be type object')\n }\n for (const k in style) {\n const v = (style as Record<string, unknown>)[k]\n // Custom properties (starting with `--`) are passed through as-is so\n // they aren't kebab-cased a second time, and so they remain valid keys\n // for setProperty.\n const property = k.startsWith('--') ? k : toKebabCase(k)\n if (isObservableValue(v)) {\n onConnect(element, () => {\n return v.onData((value) => {\n element.style.setProperty(\n property,\n (value ?? null) as string | null\n )\n })\n })\n } else {\n element.style.setProperty(property, (v ?? null) as string | null)\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { onConnect } from './connectedObserver'\n\nexport function applyVisibility(\n element: HTMLElement,\n visible: boolean | ObservableValue<boolean>\n): void {\n if (typeof visible === 'boolean') {\n if (!visible) element.style.display = 'none'\n } else {\n onConnect(element, () => {\n return visible.onData((value) => {\n if (value) element.style.removeProperty('display')\n else element.style.display = 'none'\n })\n })\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { onConnect } from './extensions/connectedObserver'\nimport type { Writable } from './type'\nimport { applyStyles } from './extensions/applyStyles'\nimport {\n isObservableValue,\n type MaybeObservableValue,\n type ObservableValue,\n} from '@amazon/vinyl-observable'\nimport { ActiveText } from './ActiveText'\nimport { applyVisibility } from './extensions/applyVisibility'\nimport { applyClassList } from './extensions/applyClassList'\nimport type { HookExtension } from './extensions/HookExtension'\nimport { passiveEventHandlers } from './extensions/applyPassiveHandler'\nimport type { AnyRecord } from '@amazon/vinyl-util'\n\n/**\n * Names like `aria-label` / `role` / `data-*` / any hyphenated prop are DOM\n * attributes with no matching IDL property \u2014 assigning them via `element[k]`\n * creates an inert expando and the a11y tree / CSS attribute selectors never\n * see the value. Route those through setAttribute so JSX like\n * `<div aria-label=\"foo\" />` actually reaches the DOM.\n */\nfunction isAttributeOnlyName(k: string): boolean {\n return k === 'role' || k.indexOf('-') >= 0\n}\n\n/**\n * Sets a property on an element. Hyphenated / aria / role / data names are\n * assigned as HTML attributes; everything else stays on the property path so\n * camelCase IDL props (className, tabIndex, onClick, \u2026) keep their existing\n * fast-path semantics.\n */\nfunction setProp(element: HTMLElement, k: string, value: unknown): void {\n if (isAttributeOnlyName(k)) {\n if (value == null) element.removeAttribute(k)\n else element.setAttribute(k, String(value))\n } else {\n ;(element as any)[k] = value\n }\n}\n\nexport type JsxFactory = (props: any, children: any[]) => any\n\n/**\n * A map of custom jsx properties to be used in hook extensions.\n */\nexport const hookExtensions = {\n onConnect: onConnect<HTMLElement>,\n style: applyStyles,\n visible: applyVisibility,\n classList: applyClassList,\n ...passiveEventHandlers,\n} as const satisfies Record<keyof any, HookExtension<any>>\n\nexport type AllowBindable<T> = {\n [K in keyof T]: MaybeObservableValue<T[K]>\n}\n\n/**\n * A type map of the jsx extended properties to the type provided to the hook.\n */\nexport type HookExtensions = {\n [p in keyof typeof hookExtensions]?: Parameters<\n (typeof hookExtensions)[p]\n >[1]\n}\n\nexport type ElementProps<K extends keyof HTMLElementTagNameMap> = Omit<\n Partial<Writable<HTMLElementTagNameMap[K]>>,\n keyof HookExtensions\n>\n\nexport type BindableElementProps<K extends keyof HTMLElementTagNameMap> =\n AllowBindable<ElementProps<K>>\n\n/**\n * Allowed properties for intrinsic elements when writing jsx declarative markup.\n */\nexport type JsxElementProps<K extends keyof HTMLElementTagNameMap> =\n BindableElementProps<K> & HookExtensions\n\nexport type DomIntrinsicElements = {\n [K in keyof HTMLElementTagNameMap]: JsxElementProps<K>\n}\n\nexport type JsxChild = Node | string | ObservableValue<Node | string>\n\nexport function jsx<K extends keyof HTMLElementTagNameMap>(\n type: K,\n props: JsxElementProps<K>,\n ...children: JsxChild[]\n): HTMLElementTagNameMap[K]\n\nexport function jsx<Factory extends JsxFactory>(\n type: Factory,\n props: Parameters<Factory>[0],\n ...children: Parameters<Factory>[1]\n): ReturnType<Factory>\n\nexport function jsx(type: any, props: any, ...children: any) {\n if (typeof type === 'string') {\n const element = document.createElement(type)\n for (const k in props) {\n const v = props[k]\n if (k in hookExtensions) {\n hookExtensions[k as keyof typeof hookExtensions](element, v)\n continue\n }\n if (isObservableValue(v)) {\n onConnect(element, () => {\n return v.onData((data$) => setProp(element, k, data$))\n })\n } else {\n setProp(element, k, v)\n }\n }\n element.append(\n ...children\n .filter((child: JsxChild | null) => child != null)\n .map((child: JsxChild) => {\n return isObservableValue(child) ? ActiveText(child) : child\n })\n )\n return element\n } else {\n return type(props ?? {}, children)\n }\n}\n\nexport function Fragment(_props: AnyRecord, children: (Node | string)[]) {\n return jsx(\n 'div',\n {\n style: {\n display: 'contents',\n },\n },\n ...children\n )\n}\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n type IntrinsicElements = DomIntrinsicElements\n type Element = HTMLElement\n type Fragment = HTMLElement\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUO,SAAS,GACZ,WACA,aAAyB,UACxB;AACD,QAAM,UAAU,WAAW,cAAc,SAAS;AAClD,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,GAAG,SAAS,wBAAwB;AAClE,SAAO;AACX;AAUO,SAAS,kBAAkB,YAAuC;AACrE,SAAO,CAAC,cAAsB,GAAG,WAAW,UAAU;AAC1D;AAEO,SAAS,KAAK,SAAsB;AACvC,UAAQ,MAAM,UAAU;AAC5B;AAEO,SAAS,KAAK,SAAsB;AACvC,UAAQ,MAAM,eAAe,SAAS;AAC1C;AAEO,SAAS,WAAW,SAA+B;AACtD,SAAO,QAAQ,MAAM,YAAY;AACrC;AAEO,SAAS,WAAW,SAAsB,OAAgB;AAC7D,MAAI,WAAW,OAAO,MAAM,MAAO;AACnC,MAAI,MAAO,MAAK,OAAO;AAAA,MAClB,MAAK,OAAO;AACrB;AAEO,SAAS,SAAS,SAAsB;AAC3C,MAAI,OAA2B;AAC/B,SAAO,MAAM;AACT,QAAI,iBAAiB,IAAI,EAAE,YAAY,OAAQ,QAAO;AACtD,WAAO,KAAK;AAAA,EAChB;AACA,SAAO;AACX;AAEO,SAAS,eACZ,OACyB;AACzB,UAAO,+BAAO,QAAQ,mBAAkB;AAC5C;AASO,SAAS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AkB,KAAK,IAAI,WAAW,KAAK,IAAI;AAAA,MAC1D,CAAC;AAAA,IACT;AACA,WAAO;AAAA,EACX,OAAO;AACH,WAAO,KAAK,wBAAS,CAAC,GAAG,QAAQ;AAAA,EACrC;AACJ;AAEO,SAAS,SAAS,QAAmB,UAA6B;AACrE,SAAO;AAAA,IACH;AAAA,IACA;AAAA,MACI,OAAO;AAAA,QACH,SAAS;AAAA,MACb;AAAA,IACJ;AAAA,IACA,GAAG;AAAA,EACP;AACJ;",
4
+ "sourcesContent": ["/** Auto-generated from build scripts */\nexport * from './ActiveText'\nexport * from './domUtil'\nexport * from './extensions/applyClassList'\nexport * from './extensions/applyPassiveHandler'\nexport * from './extensions/applyStyles'\nexport * from './extensions/applyVisibility'\nexport * from './extensions/connectedObserver'\nexport * from './extensions/HookExtension'\nexport * from './jsx'\nexport * from './type'\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport function el<K extends keyof HTMLElementTagNameMap>(\n selectors: K,\n parentNode?: ParentNode\n): HTMLElementTagNameMap[K]\nexport function el(selectors: string, parentNode?: ParentNode): HTMLElement\nexport function el<E extends Element = Element>(\n selectors: string,\n parentNode: ParentNode = document\n): E {\n const element = parentNode.querySelector(selectors)\n if (!element) throw new Error(`${selectors} must be a DOM element`)\n return element as E\n}\n\nexport interface QuerySelector {\n <K extends keyof HTMLElementTagNameMap>(\n selectors: K,\n parentNode?: ParentNode\n ): HTMLElementTagNameMap[K]\n (selectors: string): HTMLElement\n}\n\nexport function bindQuerySelector(parentNode: ParentNode): QuerySelector {\n return (selectors: string) => el(selectors, parentNode)\n}\n\nexport function hide(element: HTMLElement) {\n element.style.display = 'none'\n}\n\nexport function show(element: HTMLElement) {\n element.style.removeProperty('display')\n}\n\nexport function getVisible(element: HTMLElement): boolean {\n return element.style.display !== 'none'\n}\n\nexport function setVisible(element: HTMLElement, value: boolean) {\n if (getVisible(element) === value) return\n if (value) show(element)\n else hide(element)\n}\n\nexport function isHidden(element: HTMLElement) {\n let node: HTMLElement | null = element\n while (node) {\n if (getComputedStyle(node).display === 'none') return true\n node = node.parentElement\n }\n return false\n}\n\nexport function isInputElement(\n value: Element | null\n): value is HTMLInputElement {\n return value?.tagName.toLowerCase() === 'input'\n}\n\n/**\n * Adds or removes a class token to an element.\n *\n * @param value The element whose classList to modify.\n * @param token The class token.\n * @param toggled If true, the token is added, if false, removed.\n */\nexport function setClassToken(\n value: HTMLElement,\n token: string,\n toggled: boolean\n) {\n if (toggled) {\n value.classList.add(token)\n } else {\n value.classList.remove(token)\n }\n}\n\nexport type ElementInitOptions = {\n readonly parent?: HTMLElement\n readonly className?: string\n}\n\n/**\n * Recursively walks a node hierarchy, invoking a callback for every node, depth first.\n *\n * @param node\n * @param callback\n */\nexport function walkDomDepthFirst(\n node: Node | undefined | null,\n callback: (node: Node) => void\n) {\n if (!node) return\n let next = node.firstChild\n while (next) {\n // Snapshot the sibling before recursing so a callback that moves\n // `next` can't sever the chain and skip the rest of the row.\n const after = next.nextSibling\n walkDomDepthFirst(next, callback)\n next = after\n }\n callback(node)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { walkDomDepthFirst } from '../domUtil'\nimport type { Maybe, Unsubscribe } from '@amazon/vinyl-util'\n\n/**\n * Where {@link onConnect} keeps a node's callbacks, so the observer can call them without an event\n * dispatch. A registered symbol, so every copy of this library on a page shares it.\n */\nconst CONNECTION_CALLBACKS: unique symbol = /* @__PURE__ */ Symbol.for(\n '@amazon/vinyl-tsx/connectionCallbacks'\n)\n\ninterface ConnectionCallbacks {\n readonly connect: Set<() => void>\n readonly disconnect: Set<() => void>\n}\n\ntype ObservedNode = Node & { [CONNECTION_CALLBACKS]?: ConnectionCallbacks }\n\nfunction callbacksOf(node: Node): ConnectionCallbacks {\n const observed = node as ObservedNode\n let callbacks = observed[CONNECTION_CALLBACKS]\n if (!callbacks) {\n callbacks = { connect: new Set(), disconnect: new Set() }\n observed[CONNECTION_CALLBACKS] = callbacks\n }\n return callbacks\n}\n\nfunction notify(node: Node, type: keyof ConnectionCallbacks): void {\n const callbacks = (node as ObservedNode)[CONNECTION_CALLBACKS]?.[type]\n if (callbacks?.size) for (const callback of [...callbacks]) callback()\n}\n\nexport interface ConnectedObserverOptions {\n /**\n * Whether to dispatch a `connect` / `disconnect` DOM event on every node of an added or removed\n * subtree, for listeners added with `addEventListener` (default true). {@link onConnect}\n * callbacks run either way. Without the events, mounting or removing a large tree skips one\n * event dispatch per node, which otherwise dominates the observer's cost.\n */\n readonly events?: boolean\n}\n\n/**\n * Dispatches a 'connected' event on nodes attached to the dom, dispatches 'disconnected' when removed.\n * Allows nodes to observe connected changes without creating a memory leak.\n */\nexport function initializeConnectedObserver(\n options: ConnectedObserverOptions = {}\n): Unsubscribe {\n const events = options.events ?? true\n const observer = new MutationObserver((mutations) => {\n const removed = new Set<Node>()\n const added = new Set<Node>()\n\n // First pass: flatten removed and added nodes so we can detect nodes re-ordered.\n for (const mutation of mutations) {\n mutation.removedNodes.forEach((node) => removed.add(node))\n mutation.addedNodes.forEach((node) => added.add(node))\n }\n\n // Second pass: handle added/removed, skipping reorders\n for (const mutation of mutations) {\n for (const node of mutation.addedNodes) {\n if (removed.has(node)) continue\n walkDomDepthFirst(node, (iNode) => {\n notify(iNode, 'connect')\n if (events) {\n iNode.dispatchEvent(\n new CustomEvent('connect', { bubbles: false })\n )\n }\n })\n }\n\n for (const node of mutation.removedNodes) {\n if (added.has(node)) continue\n walkDomDepthFirst(node, (iNode) => {\n notify(iNode, 'disconnect')\n if (events) {\n iNode.dispatchEvent(\n new CustomEvent('disconnect', { bubbles: false })\n )\n }\n })\n }\n }\n })\n\n observer.observe(document, { childList: true, subtree: true })\n\n return () => {\n observer.disconnect()\n }\n}\n\n/**\n * Invokes a callback when the given target is connected to the DOM.\n * If the callback returns a function, that function will be invoked when disconnected.\n *\n * @param target\n * @param callback\n */\nexport function onConnect<T extends Node>(\n target: T,\n callback: (node: T) => Maybe<Unsubscribe> | void\n): Unsubscribe {\n let sub: Maybe<Unsubscribe> | void = null\n let connected = false\n const onConnect = () => {\n if (connected) return\n connected = true\n sub = callback(target)\n }\n const onDisconnect = () => {\n connected = false\n sub?.()\n sub = null\n }\n const callbacks = callbacksOf(target)\n callbacks.connect.add(onConnect)\n callbacks.disconnect.add(onDisconnect)\n // Still listening for the events, for an observer from an older copy of this library.\n target.addEventListener('connect', onConnect)\n target.addEventListener('disconnect', onDisconnect)\n if (target.isConnected) onConnect()\n return () => {\n callbacks.connect.delete(onConnect)\n callbacks.disconnect.delete(onDisconnect)\n target.removeEventListener('connect', onConnect)\n target.removeEventListener('disconnect', onDisconnect)\n onDisconnect()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { onConnect } from './extensions/connectedObserver'\n\n/**\n * A Text node bound to a data provider.\n * Created automatically when a child is a ObservableValue.\n * textContent will only be updated when the node is on the DOM.\n */\nexport function ActiveText<T>(data: ObservableValue<T>): Text {\n const text = document.createTextNode(String(data.value ?? ''))\n onConnect(text, () => {\n return data.onData((value) => {\n text.textContent = String(value ?? '')\n })\n })\n return text\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n isObservableValue,\n type ObservableValue,\n} from '@amazon/vinyl-observable'\nimport { onConnect } from './connectedObserver'\nimport {\n createDisposer,\n noop,\n type Maybe,\n type Unsubscribe,\n} from '@amazon/vinyl-util'\n\nexport function applyClassList(\n element: HTMLElement,\n classList: readonly (Maybe<string> | ObservableValue<Maybe<string>>)[]\n): Unsubscribe {\n const strings = classList.filter((s) => typeof s === 'string')\n // The empty string is not a valid class token \u2014 `add` rejects it \u2014 so it is\n // dropped here as `bindClass` drops it for an observable token.\n const tokens = strings.filter((s) => s !== '')\n if (tokens.length) element.classList.add(...tokens)\n if (strings.length < classList.length) {\n return onConnect(element, () => {\n const { add, dispose } = createDisposer()\n for (const dP of classList.filter(isObservableValue)) {\n add(bindClass(element, dP))\n }\n return dispose\n })\n }\n return noop\n}\n\nfunction bindClass(\n element: HTMLElement,\n tokenProvider: ObservableValue<Maybe<string>>\n): Unsubscribe {\n let current: string | null = null\n const dataSub = tokenProvider.onData((className) => {\n if (current) element.classList.remove(current)\n if (className) {\n current = className\n element.classList.add(className)\n } else {\n current = null\n }\n })\n return () => {\n if (current != null) element.classList.remove(current)\n dataSub()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { HookExtension } from './HookExtension'\n\nexport const passiveEventHandlers = {\n ontouchstart: /* @__PURE__ */ applyPassiveHandler('ontouchstart'),\n ontouchmove: /* @__PURE__ */ applyPassiveHandler('ontouchmove'),\n onwheel: /* @__PURE__ */ applyPassiveHandler('onwheel'),\n} as const\n\nfunction applyPassiveHandler<K extends keyof GlobalEventHandlers>(\n key: K\n): HookExtension<GlobalEventHandlers[K]> {\n const eventName = key.substring(2)\n return (element: HTMLElement, handler: GlobalEventHandlers[K]) => {\n element.addEventListener(eventName, handler as any, { passive: true })\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { onConnect } from './connectedObserver'\nimport { toKebabCase } from '@amazon/vinyl-util'\nimport {\n isObservableValue,\n type MaybeObservableValue,\n} from '@amazon/vinyl-observable'\nimport type { Maybe } from '@amazon/vinyl-util'\n\n/**\n * The shape accepted by the `style` jsx prop. Allows the typed CSSStyleDeclaration\n * fields plus any CSS custom property key (must start with `--`). Null / undefined\n * clear the CSS property (via setProperty(name, null)), so values are Maybe-wrapped\n * here even though bindable IDL props reject null.\n */\nexport type StyleProp = {\n [K in keyof Partial<CSSStyleDeclaration>]: MaybeObservableValue<\n Maybe<CSSStyleDeclaration[K]>\n >\n} & {\n readonly [customProperty: `--${string}`]: MaybeObservableValue<\n Maybe<string>\n >\n}\n\nexport function applyStyles(element: HTMLElement, style: StyleProp) {\n // noinspection SuspiciousTypeOfGuard\n if (typeof style === 'string') {\n // A Partial style declaration type does not prohibit a string type.\n throw new Error('expected style property to be type object')\n }\n for (const k in style) {\n const v = (style as Record<string, unknown>)[k]\n // Custom properties (starting with `--`) are passed through as-is so\n // they aren't kebab-cased a second time, and so they remain valid keys\n // for setProperty.\n const property = k.startsWith('--') ? k : toKebabCase(k)\n if (isObservableValue(v)) {\n onConnect(element, () => {\n return v.onData((value) => {\n element.style.setProperty(\n property,\n (value ?? null) as string | null\n )\n })\n })\n } else {\n element.style.setProperty(property, (v ?? null) as string | null)\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { onConnect } from './connectedObserver'\n\nexport function applyVisibility(\n element: HTMLElement,\n visible: boolean | ObservableValue<boolean>\n): void {\n if (typeof visible === 'boolean') {\n if (!visible) element.style.display = 'none'\n } else {\n onConnect(element, () => {\n return visible.onData((value) => {\n if (value) element.style.removeProperty('display')\n else element.style.display = 'none'\n })\n })\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { onConnect } from './extensions/connectedObserver'\nimport type { Writable } from './type'\nimport { applyStyles } from './extensions/applyStyles'\nimport {\n isObservableValue,\n type MaybeObservableValue,\n type ObservableValue,\n} from '@amazon/vinyl-observable'\nimport { ActiveText } from './ActiveText'\nimport { applyVisibility } from './extensions/applyVisibility'\nimport { applyClassList } from './extensions/applyClassList'\nimport type { HookExtension } from './extensions/HookExtension'\nimport { passiveEventHandlers } from './extensions/applyPassiveHandler'\nimport type { AnyRecord } from '@amazon/vinyl-util'\n\n/**\n * Names like `aria-label` / `role` / `data-*` / any hyphenated prop are DOM\n * attributes with no matching IDL property \u2014 assigning them via `element[k]`\n * creates an inert expando and the a11y tree / CSS attribute selectors never\n * see the value. Route those through setAttribute so JSX like\n * `<div aria-label=\"foo\" />` actually reaches the DOM.\n */\nfunction isAttributeOnlyName(k: string): boolean {\n return k === 'role' || k.indexOf('-') >= 0\n}\n\n/**\n * Sets a property on an element. Hyphenated / aria / role / data names are\n * assigned as HTML attributes; everything else stays on the property path so\n * camelCase IDL props (className, tabIndex, onClick, \u2026) keep their existing\n * fast-path semantics.\n */\nfunction setProp(element: HTMLElement, k: string, value: unknown): void {\n if (isAttributeOnlyName(k)) {\n if (value == null) element.removeAttribute(k)\n else element.setAttribute(k, String(value))\n } else {\n ;(element as any)[k] = value\n }\n}\n\nexport type JsxFactory = (props: any, children: any[]) => any\n\n/**\n * A map of custom jsx properties to be used in hook extensions.\n */\nexport const hookExtensions = {\n onConnect: onConnect<HTMLElement>,\n style: applyStyles,\n visible: applyVisibility,\n classList: applyClassList,\n ...passiveEventHandlers,\n} as const satisfies Record<keyof any, HookExtension<any>>\n\nexport type AllowBindable<T> = {\n [K in keyof T]: MaybeObservableValue<T[K]>\n}\n\n/**\n * A type map of the jsx extended properties to the type provided to the hook.\n */\nexport type HookExtensions = {\n [p in keyof typeof hookExtensions]?: Parameters<\n (typeof hookExtensions)[p]\n >[1]\n}\n\nexport type ElementProps<K extends keyof HTMLElementTagNameMap> = Omit<\n Partial<Writable<HTMLElementTagNameMap[K]>>,\n keyof HookExtensions\n>\n\nexport type BindableElementProps<K extends keyof HTMLElementTagNameMap> =\n AllowBindable<ElementProps<K>>\n\n/**\n * Allowed properties for intrinsic elements when writing jsx declarative markup.\n */\nexport type JsxElementProps<K extends keyof HTMLElementTagNameMap> =\n BindableElementProps<K> & HookExtensions\n\nexport type DomIntrinsicElements = {\n [K in keyof HTMLElementTagNameMap]: JsxElementProps<K>\n}\n\nexport type JsxChild = Node | string | ObservableValue<Node | string>\n\nexport function jsx<K extends keyof HTMLElementTagNameMap>(\n type: K,\n props: JsxElementProps<K>,\n ...children: JsxChild[]\n): HTMLElementTagNameMap[K]\n\nexport function jsx<Factory extends JsxFactory>(\n type: Factory,\n props: Parameters<Factory>[0],\n ...children: Parameters<Factory>[1]\n): ReturnType<Factory>\n\nexport function jsx(type: any, props: any, ...children: any) {\n if (typeof type === 'string') {\n const element = document.createElement(type)\n for (const k in props) {\n const v = props[k]\n if (k in hookExtensions) {\n hookExtensions[k as keyof typeof hookExtensions](element, v)\n continue\n }\n if (isObservableValue(v)) {\n onConnect(element, () => {\n return v.onData((data$) => setProp(element, k, data$))\n })\n } else {\n setProp(element, k, v)\n }\n }\n element.append(\n ...children\n .filter((child: JsxChild | null) => child != null)\n .map((child: JsxChild) => {\n return isObservableValue(child) ? ActiveText(child) : child\n })\n )\n return element\n } else {\n return type(props ?? {}, children)\n }\n}\n\nexport function Fragment(_props: AnyRecord, children: (Node | string)[]) {\n return jsx(\n 'div',\n {\n style: {\n display: 'contents',\n },\n },\n ...children\n )\n}\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n type IntrinsicElements = DomIntrinsicElements\n type Element = HTMLElement\n type Fragment = HTMLElement\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUO,SAAS,GACZ,WACA,aAAyB,UACxB;AACD,QAAM,UAAU,WAAW,cAAc,SAAS;AAClD,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,GAAG,SAAS,wBAAwB;AAClE,SAAO;AACX;AAUO,SAAS,kBAAkB,YAAuC;AACrE,SAAO,CAAC,cAAsB,GAAG,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AACA,YAAQ;AAAA,MACJ,GAAG,SACE,OAAO,CAAC,UAA2B,SAAS,IAAI,EAChD,IAAI,CAAC,UAAoB;AACtB,mBAAO,4CAAkB,KAAK,IAAI,WAAW,KAAK,IAAI;AAAA,MAC1D,CAAC;AAAA,IACT;AACA,WAAO;AAAA,EACX,OAAO;AACH,WAAO,KAAK,wBAAS,CAAC,GAAG,QAAQ;AAAA,EACrC;AACJ;AAEO,SAAS,SAAS,QAAmB,UAA6B;AACrE,SAAO;AAAA,IACH;AAAA,IACA;AAAA,MACI,OAAO;AAAA,QACH,SAAS;AAAA,MACb;AAAA,IACJ;AAAA,IACA,GAAG;AAAA,EACP;AACJ;",
6
6
  "names": ["onConnect", "import_vinyl_util", "import_vinyl_observable", "import_vinyl_observable"]
7
7
  }
package/dist/index.js CHANGED
@@ -68,7 +68,26 @@ function walkDomDepthFirst(node, callback) {
68
68
  }
69
69
 
70
70
  // src/extensions/connectedObserver.ts
71
- function initializeConnectedObserver() {
71
+ var CONNECTION_CALLBACKS = /* @__PURE__ */ Symbol.for(
72
+ "@amazon/vinyl-tsx/connectionCallbacks"
73
+ );
74
+ function callbacksOf(node) {
75
+ const observed = node;
76
+ let callbacks = observed[CONNECTION_CALLBACKS];
77
+ if (!callbacks) {
78
+ callbacks = { connect: /* @__PURE__ */ new Set(), disconnect: /* @__PURE__ */ new Set() };
79
+ observed[CONNECTION_CALLBACKS] = callbacks;
80
+ }
81
+ return callbacks;
82
+ }
83
+ function notify(node, type) {
84
+ var _a;
85
+ const callbacks = (_a = node[CONNECTION_CALLBACKS]) == null ? void 0 : _a[type];
86
+ if (callbacks == null ? void 0 : callbacks.size) for (const callback of [...callbacks]) callback();
87
+ }
88
+ function initializeConnectedObserver(options = {}) {
89
+ var _a;
90
+ const events = (_a = options.events) != null ? _a : true;
72
91
  const observer = new MutationObserver((mutations) => {
73
92
  const removed = /* @__PURE__ */ new Set();
74
93
  const added = /* @__PURE__ */ new Set();
@@ -80,17 +99,23 @@ function initializeConnectedObserver() {
80
99
  for (const node of mutation.addedNodes) {
81
100
  if (removed.has(node)) continue;
82
101
  walkDomDepthFirst(node, (iNode) => {
83
- iNode.dispatchEvent(
84
- new CustomEvent("connect", { bubbles: false })
85
- );
102
+ notify(iNode, "connect");
103
+ if (events) {
104
+ iNode.dispatchEvent(
105
+ new CustomEvent("connect", { bubbles: false })
106
+ );
107
+ }
86
108
  });
87
109
  }
88
110
  for (const node of mutation.removedNodes) {
89
111
  if (added.has(node)) continue;
90
112
  walkDomDepthFirst(node, (iNode) => {
91
- iNode.dispatchEvent(
92
- new CustomEvent("disconnect", { bubbles: false })
93
- );
113
+ notify(iNode, "disconnect");
114
+ if (events) {
115
+ iNode.dispatchEvent(
116
+ new CustomEvent("disconnect", { bubbles: false })
117
+ );
118
+ }
94
119
  });
95
120
  }
96
121
  }
@@ -113,10 +138,15 @@ function onConnect(target, callback) {
113
138
  sub == null ? void 0 : sub();
114
139
  sub = null;
115
140
  };
141
+ const callbacks = callbacksOf(target);
142
+ callbacks.connect.add(onConnect2);
143
+ callbacks.disconnect.add(onDisconnect);
116
144
  target.addEventListener("connect", onConnect2);
117
145
  target.addEventListener("disconnect", onDisconnect);
118
146
  if (target.isConnected) onConnect2();
119
147
  return () => {
148
+ callbacks.connect.delete(onConnect2);
149
+ callbacks.disconnect.delete(onDisconnect);
120
150
  target.removeEventListener("connect", onConnect2);
121
151
  target.removeEventListener("disconnect", onDisconnect);
122
152
  onDisconnect();
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/domUtil.ts", "../src/extensions/connectedObserver.ts", "../src/ActiveText.ts", "../src/extensions/applyClassList.ts", "../src/extensions/applyPassiveHandler.ts", "../src/extensions/applyStyles.ts", "../src/extensions/applyVisibility.ts", "../src/jsx.ts"],
4
- "sourcesContent": ["/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport function el<K extends keyof HTMLElementTagNameMap>(\n selectors: K,\n parentNode?: ParentNode\n): HTMLElementTagNameMap[K]\nexport function el(selectors: string, parentNode?: ParentNode): HTMLElement\nexport function el<E extends Element = Element>(\n selectors: string,\n parentNode: ParentNode = document\n): E {\n const element = parentNode.querySelector(selectors)\n if (!element) throw new Error(`${selectors} must be a DOM element`)\n return element as E\n}\n\nexport interface QuerySelector {\n <K extends keyof HTMLElementTagNameMap>(\n selectors: K,\n parentNode?: ParentNode\n ): HTMLElementTagNameMap[K]\n (selectors: string): HTMLElement\n}\n\nexport function bindQuerySelector(parentNode: ParentNode): QuerySelector {\n return (selectors: string) => el(selectors, parentNode)\n}\n\nexport function hide(element: HTMLElement) {\n element.style.display = 'none'\n}\n\nexport function show(element: HTMLElement) {\n element.style.removeProperty('display')\n}\n\nexport function getVisible(element: HTMLElement): boolean {\n return element.style.display !== 'none'\n}\n\nexport function setVisible(element: HTMLElement, value: boolean) {\n if (getVisible(element) === value) return\n if (value) show(element)\n else hide(element)\n}\n\nexport function isHidden(element: HTMLElement) {\n let node: HTMLElement | null = element\n while (node) {\n if (getComputedStyle(node).display === 'none') return true\n node = node.parentElement\n }\n return false\n}\n\nexport function isInputElement(\n value: Element | null\n): value is HTMLInputElement {\n return value?.tagName.toLowerCase() === 'input'\n}\n\n/**\n * Adds or removes a class token to an element.\n *\n * @param value The element whose classList to modify.\n * @param token The class token.\n * @param toggled If true, the token is added, if false, removed.\n */\nexport function setClassToken(\n value: HTMLElement,\n token: string,\n toggled: boolean\n) {\n if (toggled) {\n value.classList.add(token)\n } else {\n value.classList.remove(token)\n }\n}\n\nexport type ElementInitOptions = {\n readonly parent?: HTMLElement\n readonly className?: string\n}\n\n/**\n * Recursively walks a node hierarchy, invoking a callback for every node, depth first.\n *\n * @param node\n * @param callback\n */\nexport function walkDomDepthFirst(\n node: Node | undefined | null,\n callback: (node: Node) => void\n) {\n if (!node) return\n let next = node.firstChild\n while (next) {\n // Snapshot the sibling before recursing so a callback that moves\n // `next` can't sever the chain and skip the rest of the row.\n const after = next.nextSibling\n walkDomDepthFirst(next, callback)\n next = after\n }\n callback(node)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { walkDomDepthFirst } from '../domUtil'\nimport type { Maybe, Unsubscribe } from '@amazon/vinyl-util'\n\n/**\n * Dispatches a 'connected' event on nodes attached to the dom, dispatches 'disconnected' when removed.\n * Allows nodes to observe connected changes without creating a memory leak.\n */\nexport function initializeConnectedObserver(): Unsubscribe {\n const observer = new MutationObserver((mutations) => {\n const removed = new Set<Node>()\n const added = new Set<Node>()\n\n // First pass: flatten removed and added nodes so we can detect nodes re-ordered.\n for (const mutation of mutations) {\n mutation.removedNodes.forEach((node) => removed.add(node))\n mutation.addedNodes.forEach((node) => added.add(node))\n }\n\n // Second pass: handle added/removed, skipping reorders\n for (const mutation of mutations) {\n for (const node of mutation.addedNodes) {\n if (removed.has(node)) continue\n walkDomDepthFirst(node, (iNode) => {\n iNode.dispatchEvent(\n new CustomEvent('connect', { bubbles: false })\n )\n })\n }\n\n for (const node of mutation.removedNodes) {\n if (added.has(node)) continue\n walkDomDepthFirst(node, (iNode) => {\n iNode.dispatchEvent(\n new CustomEvent('disconnect', { bubbles: false })\n )\n })\n }\n }\n })\n\n observer.observe(document, { childList: true, subtree: true })\n\n return () => {\n observer.disconnect()\n }\n}\n\n/**\n * Invokes a callback when the given target is connected to the DOM.\n * If the callback returns a function, that function will be invoked when disconnected.\n *\n * @param target\n * @param callback\n */\nexport function onConnect<T extends Node>(\n target: T,\n callback: (node: T) => Maybe<Unsubscribe> | void\n): Unsubscribe {\n let sub: Maybe<Unsubscribe> | void = null\n let connected = false\n const onConnect = () => {\n if (connected) return\n connected = true\n sub = callback(target)\n }\n const onDisconnect = () => {\n connected = false\n sub?.()\n sub = null\n }\n target.addEventListener('connect', onConnect)\n target.addEventListener('disconnect', onDisconnect)\n if (target.isConnected) onConnect()\n return () => {\n target.removeEventListener('connect', onConnect)\n target.removeEventListener('disconnect', onDisconnect)\n onDisconnect()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { onConnect } from './extensions/connectedObserver'\n\n/**\n * A Text node bound to a data provider.\n * Created automatically when a child is a ObservableValue.\n * textContent will only be updated when the node is on the DOM.\n */\nexport function ActiveText<T>(data: ObservableValue<T>): Text {\n const text = document.createTextNode(String(data.value ?? ''))\n onConnect(text, () => {\n return data.onData((value) => {\n text.textContent = String(value ?? '')\n })\n })\n return text\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n isObservableValue,\n type ObservableValue,\n} from '@amazon/vinyl-observable'\nimport { onConnect } from './connectedObserver'\nimport {\n createDisposer,\n noop,\n type Maybe,\n type Unsubscribe,\n} from '@amazon/vinyl-util'\n\nexport function applyClassList(\n element: HTMLElement,\n classList: readonly (Maybe<string> | ObservableValue<Maybe<string>>)[]\n): Unsubscribe {\n const strings = classList.filter((s) => typeof s === 'string')\n // The empty string is not a valid class token \u2014 `add` rejects it \u2014 so it is\n // dropped here as `bindClass` drops it for an observable token.\n const tokens = strings.filter((s) => s !== '')\n if (tokens.length) element.classList.add(...tokens)\n if (strings.length < classList.length) {\n return onConnect(element, () => {\n const { add, dispose } = createDisposer()\n for (const dP of classList.filter(isObservableValue)) {\n add(bindClass(element, dP))\n }\n return dispose\n })\n }\n return noop\n}\n\nfunction bindClass(\n element: HTMLElement,\n tokenProvider: ObservableValue<Maybe<string>>\n): Unsubscribe {\n let current: string | null = null\n const dataSub = tokenProvider.onData((className) => {\n if (current) element.classList.remove(current)\n if (className) {\n current = className\n element.classList.add(className)\n } else {\n current = null\n }\n })\n return () => {\n if (current != null) element.classList.remove(current)\n dataSub()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { HookExtension } from './HookExtension'\n\nexport const passiveEventHandlers = {\n ontouchstart: /* @__PURE__ */ applyPassiveHandler('ontouchstart'),\n ontouchmove: /* @__PURE__ */ applyPassiveHandler('ontouchmove'),\n onwheel: /* @__PURE__ */ applyPassiveHandler('onwheel'),\n} as const\n\nfunction applyPassiveHandler<K extends keyof GlobalEventHandlers>(\n key: K\n): HookExtension<GlobalEventHandlers[K]> {\n const eventName = key.substring(2)\n return (element: HTMLElement, handler: GlobalEventHandlers[K]) => {\n element.addEventListener(eventName, handler as any, { passive: true })\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { onConnect } from './connectedObserver'\nimport { toKebabCase } from '@amazon/vinyl-util'\nimport {\n isObservableValue,\n type MaybeObservableValue,\n} from '@amazon/vinyl-observable'\nimport type { Maybe } from '@amazon/vinyl-util'\n\n/**\n * The shape accepted by the `style` jsx prop. Allows the typed CSSStyleDeclaration\n * fields plus any CSS custom property key (must start with `--`). Null / undefined\n * clear the CSS property (via setProperty(name, null)), so values are Maybe-wrapped\n * here even though bindable IDL props reject null.\n */\nexport type StyleProp = {\n [K in keyof Partial<CSSStyleDeclaration>]: MaybeObservableValue<\n Maybe<CSSStyleDeclaration[K]>\n >\n} & {\n readonly [customProperty: `--${string}`]: MaybeObservableValue<\n Maybe<string>\n >\n}\n\nexport function applyStyles(element: HTMLElement, style: StyleProp) {\n // noinspection SuspiciousTypeOfGuard\n if (typeof style === 'string') {\n // A Partial style declaration type does not prohibit a string type.\n throw new Error('expected style property to be type object')\n }\n for (const k in style) {\n const v = (style as Record<string, unknown>)[k]\n // Custom properties (starting with `--`) are passed through as-is so\n // they aren't kebab-cased a second time, and so they remain valid keys\n // for setProperty.\n const property = k.startsWith('--') ? k : toKebabCase(k)\n if (isObservableValue(v)) {\n onConnect(element, () => {\n return v.onData((value) => {\n element.style.setProperty(\n property,\n (value ?? null) as string | null\n )\n })\n })\n } else {\n element.style.setProperty(property, (v ?? null) as string | null)\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { onConnect } from './connectedObserver'\n\nexport function applyVisibility(\n element: HTMLElement,\n visible: boolean | ObservableValue<boolean>\n): void {\n if (typeof visible === 'boolean') {\n if (!visible) element.style.display = 'none'\n } else {\n onConnect(element, () => {\n return visible.onData((value) => {\n if (value) element.style.removeProperty('display')\n else element.style.display = 'none'\n })\n })\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { onConnect } from './extensions/connectedObserver'\nimport type { Writable } from './type'\nimport { applyStyles } from './extensions/applyStyles'\nimport {\n isObservableValue,\n type MaybeObservableValue,\n type ObservableValue,\n} from '@amazon/vinyl-observable'\nimport { ActiveText } from './ActiveText'\nimport { applyVisibility } from './extensions/applyVisibility'\nimport { applyClassList } from './extensions/applyClassList'\nimport type { HookExtension } from './extensions/HookExtension'\nimport { passiveEventHandlers } from './extensions/applyPassiveHandler'\nimport type { AnyRecord } from '@amazon/vinyl-util'\n\n/**\n * Names like `aria-label` / `role` / `data-*` / any hyphenated prop are DOM\n * attributes with no matching IDL property \u2014 assigning them via `element[k]`\n * creates an inert expando and the a11y tree / CSS attribute selectors never\n * see the value. Route those through setAttribute so JSX like\n * `<div aria-label=\"foo\" />` actually reaches the DOM.\n */\nfunction isAttributeOnlyName(k: string): boolean {\n return k === 'role' || k.indexOf('-') >= 0\n}\n\n/**\n * Sets a property on an element. Hyphenated / aria / role / data names are\n * assigned as HTML attributes; everything else stays on the property path so\n * camelCase IDL props (className, tabIndex, onClick, \u2026) keep their existing\n * fast-path semantics.\n */\nfunction setProp(element: HTMLElement, k: string, value: unknown): void {\n if (isAttributeOnlyName(k)) {\n if (value == null) element.removeAttribute(k)\n else element.setAttribute(k, String(value))\n } else {\n ;(element as any)[k] = value\n }\n}\n\nexport type JsxFactory = (props: any, children: any[]) => any\n\n/**\n * A map of custom jsx properties to be used in hook extensions.\n */\nexport const hookExtensions = {\n onConnect: onConnect<HTMLElement>,\n style: applyStyles,\n visible: applyVisibility,\n classList: applyClassList,\n ...passiveEventHandlers,\n} as const satisfies Record<keyof any, HookExtension<any>>\n\nexport type AllowBindable<T> = {\n [K in keyof T]: MaybeObservableValue<T[K]>\n}\n\n/**\n * A type map of the jsx extended properties to the type provided to the hook.\n */\nexport type HookExtensions = {\n [p in keyof typeof hookExtensions]?: Parameters<\n (typeof hookExtensions)[p]\n >[1]\n}\n\nexport type ElementProps<K extends keyof HTMLElementTagNameMap> = Omit<\n Partial<Writable<HTMLElementTagNameMap[K]>>,\n keyof HookExtensions\n>\n\nexport type BindableElementProps<K extends keyof HTMLElementTagNameMap> =\n AllowBindable<ElementProps<K>>\n\n/**\n * Allowed properties for intrinsic elements when writing jsx declarative markup.\n */\nexport type JsxElementProps<K extends keyof HTMLElementTagNameMap> =\n BindableElementProps<K> & HookExtensions\n\nexport type DomIntrinsicElements = {\n [K in keyof HTMLElementTagNameMap]: JsxElementProps<K>\n}\n\nexport type JsxChild = Node | string | ObservableValue<Node | string>\n\nexport function jsx<K extends keyof HTMLElementTagNameMap>(\n type: K,\n props: JsxElementProps<K>,\n ...children: JsxChild[]\n): HTMLElementTagNameMap[K]\n\nexport function jsx<Factory extends JsxFactory>(\n type: Factory,\n props: Parameters<Factory>[0],\n ...children: Parameters<Factory>[1]\n): ReturnType<Factory>\n\nexport function jsx(type: any, props: any, ...children: any) {\n if (typeof type === 'string') {\n const element = document.createElement(type)\n for (const k in props) {\n const v = props[k]\n if (k in hookExtensions) {\n hookExtensions[k as keyof typeof hookExtensions](element, v)\n continue\n }\n if (isObservableValue(v)) {\n onConnect(element, () => {\n return v.onData((data$) => setProp(element, k, data$))\n })\n } else {\n setProp(element, k, v)\n }\n }\n element.append(\n ...children\n .filter((child: JsxChild | null) => child != null)\n .map((child: JsxChild) => {\n return isObservableValue(child) ? ActiveText(child) : child\n })\n )\n return element\n } else {\n return type(props ?? {}, children)\n }\n}\n\nexport function Fragment(_props: AnyRecord, children: (Node | string)[]) {\n return jsx(\n 'div',\n {\n style: {\n display: 'contents',\n },\n },\n ...children\n )\n}\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n type IntrinsicElements = DomIntrinsicElements\n type Element = HTMLElement\n type Fragment = HTMLElement\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAUO,SAAS,GACZ,WACA,aAAyB,UACxB;AACD,QAAM,UAAU,WAAW,cAAc,SAAS;AAClD,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,GAAG,SAAS,wBAAwB;AAClE,SAAO;AACX;AAUO,SAAS,kBAAkB,YAAuC;AACrE,SAAO,CAAC,cAAsB,GAAG,WAAW,UAAU;AAC1D;AAEO,SAAS,KAAK,SAAsB;AACvC,UAAQ,MAAM,UAAU;AAC5B;AAEO,SAAS,KAAK,SAAsB;AACvC,UAAQ,MAAM,eAAe,SAAS;AAC1C;AAEO,SAAS,WAAW,SAA+B;AACtD,SAAO,QAAQ,MAAM,YAAY;AACrC;AAEO,SAAS,WAAW,SAAsB,OAAgB;AAC7D,MAAI,WAAW,OAAO,MAAM,MAAO;AACnC,MAAI,MAAO,MAAK,OAAO;AAAA,MAClB,MAAK,OAAO;AACrB;AAEO,SAAS,SAAS,SAAsB;AAC3C,MAAI,OAA2B;AAC/B,SAAO,MAAM;AACT,QAAI,iBAAiB,IAAI,EAAE,YAAY,OAAQ,QAAO;AACtD,WAAO,KAAK;AAAA,EAChB;AACA,SAAO;AACX;AAEO,SAAS,eACZ,OACyB;AACzB,UAAO,+BAAO,QAAQ,mBAAkB;AAC5C;AASO,SAAS,cACZ,OACA,O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UAA2B,SAAS,IAAI,EAChD,IAAI,CAAC,UAAoB;AACtB,eAAOA,mBAAkB,KAAK,IAAI,WAAW,KAAK,IAAI;AAAA,MAC1D,CAAC;AAAA,IACT;AACA,WAAO;AAAA,EACX,OAAO;AACH,WAAO,KAAK,wBAAS,CAAC,GAAG,QAAQ;AAAA,EACrC;AACJ;AAEO,SAAS,SAAS,QAAmB,UAA6B;AACrE,SAAO;AAAA,IACH;AAAA,IACA;AAAA,MACI,OAAO;AAAA,QACH,SAAS;AAAA,MACb;AAAA,IACJ;AAAA,IACA,GAAG;AAAA,EACP;AACJ;",
4
+ "sourcesContent": ["/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport function el<K extends keyof HTMLElementTagNameMap>(\n selectors: K,\n parentNode?: ParentNode\n): HTMLElementTagNameMap[K]\nexport function el(selectors: string, parentNode?: ParentNode): HTMLElement\nexport function el<E extends Element = Element>(\n selectors: string,\n parentNode: ParentNode = document\n): E {\n const element = parentNode.querySelector(selectors)\n if (!element) throw new Error(`${selectors} must be a DOM element`)\n return element as E\n}\n\nexport interface QuerySelector {\n <K extends keyof HTMLElementTagNameMap>(\n selectors: K,\n parentNode?: ParentNode\n ): HTMLElementTagNameMap[K]\n (selectors: string): HTMLElement\n}\n\nexport function bindQuerySelector(parentNode: ParentNode): QuerySelector {\n return (selectors: string) => el(selectors, parentNode)\n}\n\nexport function hide(element: HTMLElement) {\n element.style.display = 'none'\n}\n\nexport function show(element: HTMLElement) {\n element.style.removeProperty('display')\n}\n\nexport function getVisible(element: HTMLElement): boolean {\n return element.style.display !== 'none'\n}\n\nexport function setVisible(element: HTMLElement, value: boolean) {\n if (getVisible(element) === value) return\n if (value) show(element)\n else hide(element)\n}\n\nexport function isHidden(element: HTMLElement) {\n let node: HTMLElement | null = element\n while (node) {\n if (getComputedStyle(node).display === 'none') return true\n node = node.parentElement\n }\n return false\n}\n\nexport function isInputElement(\n value: Element | null\n): value is HTMLInputElement {\n return value?.tagName.toLowerCase() === 'input'\n}\n\n/**\n * Adds or removes a class token to an element.\n *\n * @param value The element whose classList to modify.\n * @param token The class token.\n * @param toggled If true, the token is added, if false, removed.\n */\nexport function setClassToken(\n value: HTMLElement,\n token: string,\n toggled: boolean\n) {\n if (toggled) {\n value.classList.add(token)\n } else {\n value.classList.remove(token)\n }\n}\n\nexport type ElementInitOptions = {\n readonly parent?: HTMLElement\n readonly className?: string\n}\n\n/**\n * Recursively walks a node hierarchy, invoking a callback for every node, depth first.\n *\n * @param node\n * @param callback\n */\nexport function walkDomDepthFirst(\n node: Node | undefined | null,\n callback: (node: Node) => void\n) {\n if (!node) return\n let next = node.firstChild\n while (next) {\n // Snapshot the sibling before recursing so a callback that moves\n // `next` can't sever the chain and skip the rest of the row.\n const after = next.nextSibling\n walkDomDepthFirst(next, callback)\n next = after\n }\n callback(node)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { walkDomDepthFirst } from '../domUtil'\nimport type { Maybe, Unsubscribe } from '@amazon/vinyl-util'\n\n/**\n * Where {@link onConnect} keeps a node's callbacks, so the observer can call them without an event\n * dispatch. A registered symbol, so every copy of this library on a page shares it.\n */\nconst CONNECTION_CALLBACKS: unique symbol = /* @__PURE__ */ Symbol.for(\n '@amazon/vinyl-tsx/connectionCallbacks'\n)\n\ninterface ConnectionCallbacks {\n readonly connect: Set<() => void>\n readonly disconnect: Set<() => void>\n}\n\ntype ObservedNode = Node & { [CONNECTION_CALLBACKS]?: ConnectionCallbacks }\n\nfunction callbacksOf(node: Node): ConnectionCallbacks {\n const observed = node as ObservedNode\n let callbacks = observed[CONNECTION_CALLBACKS]\n if (!callbacks) {\n callbacks = { connect: new Set(), disconnect: new Set() }\n observed[CONNECTION_CALLBACKS] = callbacks\n }\n return callbacks\n}\n\nfunction notify(node: Node, type: keyof ConnectionCallbacks): void {\n const callbacks = (node as ObservedNode)[CONNECTION_CALLBACKS]?.[type]\n if (callbacks?.size) for (const callback of [...callbacks]) callback()\n}\n\nexport interface ConnectedObserverOptions {\n /**\n * Whether to dispatch a `connect` / `disconnect` DOM event on every node of an added or removed\n * subtree, for listeners added with `addEventListener` (default true). {@link onConnect}\n * callbacks run either way. Without the events, mounting or removing a large tree skips one\n * event dispatch per node, which otherwise dominates the observer's cost.\n */\n readonly events?: boolean\n}\n\n/**\n * Dispatches a 'connected' event on nodes attached to the dom, dispatches 'disconnected' when removed.\n * Allows nodes to observe connected changes without creating a memory leak.\n */\nexport function initializeConnectedObserver(\n options: ConnectedObserverOptions = {}\n): Unsubscribe {\n const events = options.events ?? true\n const observer = new MutationObserver((mutations) => {\n const removed = new Set<Node>()\n const added = new Set<Node>()\n\n // First pass: flatten removed and added nodes so we can detect nodes re-ordered.\n for (const mutation of mutations) {\n mutation.removedNodes.forEach((node) => removed.add(node))\n mutation.addedNodes.forEach((node) => added.add(node))\n }\n\n // Second pass: handle added/removed, skipping reorders\n for (const mutation of mutations) {\n for (const node of mutation.addedNodes) {\n if (removed.has(node)) continue\n walkDomDepthFirst(node, (iNode) => {\n notify(iNode, 'connect')\n if (events) {\n iNode.dispatchEvent(\n new CustomEvent('connect', { bubbles: false })\n )\n }\n })\n }\n\n for (const node of mutation.removedNodes) {\n if (added.has(node)) continue\n walkDomDepthFirst(node, (iNode) => {\n notify(iNode, 'disconnect')\n if (events) {\n iNode.dispatchEvent(\n new CustomEvent('disconnect', { bubbles: false })\n )\n }\n })\n }\n }\n })\n\n observer.observe(document, { childList: true, subtree: true })\n\n return () => {\n observer.disconnect()\n }\n}\n\n/**\n * Invokes a callback when the given target is connected to the DOM.\n * If the callback returns a function, that function will be invoked when disconnected.\n *\n * @param target\n * @param callback\n */\nexport function onConnect<T extends Node>(\n target: T,\n callback: (node: T) => Maybe<Unsubscribe> | void\n): Unsubscribe {\n let sub: Maybe<Unsubscribe> | void = null\n let connected = false\n const onConnect = () => {\n if (connected) return\n connected = true\n sub = callback(target)\n }\n const onDisconnect = () => {\n connected = false\n sub?.()\n sub = null\n }\n const callbacks = callbacksOf(target)\n callbacks.connect.add(onConnect)\n callbacks.disconnect.add(onDisconnect)\n // Still listening for the events, for an observer from an older copy of this library.\n target.addEventListener('connect', onConnect)\n target.addEventListener('disconnect', onDisconnect)\n if (target.isConnected) onConnect()\n return () => {\n callbacks.connect.delete(onConnect)\n callbacks.disconnect.delete(onDisconnect)\n target.removeEventListener('connect', onConnect)\n target.removeEventListener('disconnect', onDisconnect)\n onDisconnect()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { onConnect } from './extensions/connectedObserver'\n\n/**\n * A Text node bound to a data provider.\n * Created automatically when a child is a ObservableValue.\n * textContent will only be updated when the node is on the DOM.\n */\nexport function ActiveText<T>(data: ObservableValue<T>): Text {\n const text = document.createTextNode(String(data.value ?? ''))\n onConnect(text, () => {\n return data.onData((value) => {\n text.textContent = String(value ?? '')\n })\n })\n return text\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n isObservableValue,\n type ObservableValue,\n} from '@amazon/vinyl-observable'\nimport { onConnect } from './connectedObserver'\nimport {\n createDisposer,\n noop,\n type Maybe,\n type Unsubscribe,\n} from '@amazon/vinyl-util'\n\nexport function applyClassList(\n element: HTMLElement,\n classList: readonly (Maybe<string> | ObservableValue<Maybe<string>>)[]\n): Unsubscribe {\n const strings = classList.filter((s) => typeof s === 'string')\n // The empty string is not a valid class token \u2014 `add` rejects it \u2014 so it is\n // dropped here as `bindClass` drops it for an observable token.\n const tokens = strings.filter((s) => s !== '')\n if (tokens.length) element.classList.add(...tokens)\n if (strings.length < classList.length) {\n return onConnect(element, () => {\n const { add, dispose } = createDisposer()\n for (const dP of classList.filter(isObservableValue)) {\n add(bindClass(element, dP))\n }\n return dispose\n })\n }\n return noop\n}\n\nfunction bindClass(\n element: HTMLElement,\n tokenProvider: ObservableValue<Maybe<string>>\n): Unsubscribe {\n let current: string | null = null\n const dataSub = tokenProvider.onData((className) => {\n if (current) element.classList.remove(current)\n if (className) {\n current = className\n element.classList.add(className)\n } else {\n current = null\n }\n })\n return () => {\n if (current != null) element.classList.remove(current)\n dataSub()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { HookExtension } from './HookExtension'\n\nexport const passiveEventHandlers = {\n ontouchstart: /* @__PURE__ */ applyPassiveHandler('ontouchstart'),\n ontouchmove: /* @__PURE__ */ applyPassiveHandler('ontouchmove'),\n onwheel: /* @__PURE__ */ applyPassiveHandler('onwheel'),\n} as const\n\nfunction applyPassiveHandler<K extends keyof GlobalEventHandlers>(\n key: K\n): HookExtension<GlobalEventHandlers[K]> {\n const eventName = key.substring(2)\n return (element: HTMLElement, handler: GlobalEventHandlers[K]) => {\n element.addEventListener(eventName, handler as any, { passive: true })\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { onConnect } from './connectedObserver'\nimport { toKebabCase } from '@amazon/vinyl-util'\nimport {\n isObservableValue,\n type MaybeObservableValue,\n} from '@amazon/vinyl-observable'\nimport type { Maybe } from '@amazon/vinyl-util'\n\n/**\n * The shape accepted by the `style` jsx prop. Allows the typed CSSStyleDeclaration\n * fields plus any CSS custom property key (must start with `--`). Null / undefined\n * clear the CSS property (via setProperty(name, null)), so values are Maybe-wrapped\n * here even though bindable IDL props reject null.\n */\nexport type StyleProp = {\n [K in keyof Partial<CSSStyleDeclaration>]: MaybeObservableValue<\n Maybe<CSSStyleDeclaration[K]>\n >\n} & {\n readonly [customProperty: `--${string}`]: MaybeObservableValue<\n Maybe<string>\n >\n}\n\nexport function applyStyles(element: HTMLElement, style: StyleProp) {\n // noinspection SuspiciousTypeOfGuard\n if (typeof style === 'string') {\n // A Partial style declaration type does not prohibit a string type.\n throw new Error('expected style property to be type object')\n }\n for (const k in style) {\n const v = (style as Record<string, unknown>)[k]\n // Custom properties (starting with `--`) are passed through as-is so\n // they aren't kebab-cased a second time, and so they remain valid keys\n // for setProperty.\n const property = k.startsWith('--') ? k : toKebabCase(k)\n if (isObservableValue(v)) {\n onConnect(element, () => {\n return v.onData((value) => {\n element.style.setProperty(\n property,\n (value ?? null) as string | null\n )\n })\n })\n } else {\n element.style.setProperty(property, (v ?? null) as string | null)\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { onConnect } from './connectedObserver'\n\nexport function applyVisibility(\n element: HTMLElement,\n visible: boolean | ObservableValue<boolean>\n): void {\n if (typeof visible === 'boolean') {\n if (!visible) element.style.display = 'none'\n } else {\n onConnect(element, () => {\n return visible.onData((value) => {\n if (value) element.style.removeProperty('display')\n else element.style.display = 'none'\n })\n })\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { onConnect } from './extensions/connectedObserver'\nimport type { Writable } from './type'\nimport { applyStyles } from './extensions/applyStyles'\nimport {\n isObservableValue,\n type MaybeObservableValue,\n type ObservableValue,\n} from '@amazon/vinyl-observable'\nimport { ActiveText } from './ActiveText'\nimport { applyVisibility } from './extensions/applyVisibility'\nimport { applyClassList } from './extensions/applyClassList'\nimport type { HookExtension } from './extensions/HookExtension'\nimport { passiveEventHandlers } from './extensions/applyPassiveHandler'\nimport type { AnyRecord } from '@amazon/vinyl-util'\n\n/**\n * Names like `aria-label` / `role` / `data-*` / any hyphenated prop are DOM\n * attributes with no matching IDL property \u2014 assigning them via `element[k]`\n * creates an inert expando and the a11y tree / CSS attribute selectors never\n * see the value. Route those through setAttribute so JSX like\n * `<div aria-label=\"foo\" />` actually reaches the DOM.\n */\nfunction isAttributeOnlyName(k: string): boolean {\n return k === 'role' || k.indexOf('-') >= 0\n}\n\n/**\n * Sets a property on an element. Hyphenated / aria / role / data names are\n * assigned as HTML attributes; everything else stays on the property path so\n * camelCase IDL props (className, tabIndex, onClick, \u2026) keep their existing\n * fast-path semantics.\n */\nfunction setProp(element: HTMLElement, k: string, value: unknown): void {\n if (isAttributeOnlyName(k)) {\n if (value == null) element.removeAttribute(k)\n else element.setAttribute(k, String(value))\n } else {\n ;(element as any)[k] = value\n }\n}\n\nexport type JsxFactory = (props: any, children: any[]) => any\n\n/**\n * A map of custom jsx properties to be used in hook extensions.\n */\nexport const hookExtensions = {\n onConnect: onConnect<HTMLElement>,\n style: applyStyles,\n visible: applyVisibility,\n classList: applyClassList,\n ...passiveEventHandlers,\n} as const satisfies Record<keyof any, HookExtension<any>>\n\nexport type AllowBindable<T> = {\n [K in keyof T]: MaybeObservableValue<T[K]>\n}\n\n/**\n * A type map of the jsx extended properties to the type provided to the hook.\n */\nexport type HookExtensions = {\n [p in keyof typeof hookExtensions]?: Parameters<\n (typeof hookExtensions)[p]\n >[1]\n}\n\nexport type ElementProps<K extends keyof HTMLElementTagNameMap> = Omit<\n Partial<Writable<HTMLElementTagNameMap[K]>>,\n keyof HookExtensions\n>\n\nexport type BindableElementProps<K extends keyof HTMLElementTagNameMap> =\n AllowBindable<ElementProps<K>>\n\n/**\n * Allowed properties for intrinsic elements when writing jsx declarative markup.\n */\nexport type JsxElementProps<K extends keyof HTMLElementTagNameMap> =\n BindableElementProps<K> & HookExtensions\n\nexport type DomIntrinsicElements = {\n [K in keyof HTMLElementTagNameMap]: JsxElementProps<K>\n}\n\nexport type JsxChild = Node | string | ObservableValue<Node | string>\n\nexport function jsx<K extends keyof HTMLElementTagNameMap>(\n type: K,\n props: JsxElementProps<K>,\n ...children: JsxChild[]\n): HTMLElementTagNameMap[K]\n\nexport function jsx<Factory extends JsxFactory>(\n type: Factory,\n props: Parameters<Factory>[0],\n ...children: Parameters<Factory>[1]\n): ReturnType<Factory>\n\nexport function jsx(type: any, props: any, ...children: any) {\n if (typeof type === 'string') {\n const element = document.createElement(type)\n for (const k in props) {\n const v = props[k]\n if (k in hookExtensions) {\n hookExtensions[k as keyof typeof hookExtensions](element, v)\n continue\n }\n if (isObservableValue(v)) {\n onConnect(element, () => {\n return v.onData((data$) => setProp(element, k, data$))\n })\n } else {\n setProp(element, k, v)\n }\n }\n element.append(\n ...children\n .filter((child: JsxChild | null) => child != null)\n .map((child: JsxChild) => {\n return isObservableValue(child) ? ActiveText(child) : child\n })\n )\n return element\n } else {\n return type(props ?? {}, children)\n }\n}\n\nexport function Fragment(_props: AnyRecord, children: (Node | string)[]) {\n return jsx(\n 'div',\n {\n style: {\n display: 'contents',\n },\n },\n ...children\n )\n}\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n type IntrinsicElements = DomIntrinsicElements\n type Element = HTMLElement\n type Fragment = HTMLElement\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAUO,SAAS,GACZ,WACA,aAAyB,UACxB;AACD,QAAM,UAAU,WAAW,cAAc,SAAS;AAClD,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,GAAG,SAAS,wBAAwB;AAClE,SAAO;AACX;AAUO,SAAS,kBAAkB,YAAuC;AACrE,SAAO,CAAC,cAAsB,GAAG,WAAW,UAAU;AAC1D;AAEO,SAAS,KAAK,SAAsB;AACvC,UAAQ,MAAM,UAAU;AAC5B;AAEO,SAAS,KAAK,SAAsB;AACvC,UAAQ,MAAM,eAAe,SAAS;AAC1C;AAEO,SAAS,WAAW,SAA+B;AACtD,SAAO,QAAQ,MAAM,YAAY;AACrC;AAEO,SAAS,WAAW,SAAsB,OAAgB;AAC7D,MAAI,WAAW,OAAO,MAAM,MAAO;AACnC,MAAI,MAAO,MAAK,OAAO;AAAA,M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,QAAQ;AAAA,EACrC;AACJ;AAEO,SAAS,SAAS,QAAmB,UAA6B;AACrE,SAAO;AAAA,IACH;AAAA,IACA;AAAA,MACI,OAAO;AAAA,QACH,SAAS;AAAA,MACb;AAAA,IACJ;AAAA,IACA,GAAG;AAAA,EACP;AACJ;",
6
6
  "names": ["onConnect", "isObservableValue", "isObservableValue", "isObservableValue"]
7
7
  }
@@ -0,0 +1,30 @@
1
+ "use strict";function _regeneratorValues(e){if(null!=e){var t=e["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],r=0;if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return{next:function next(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}throw new TypeError(_typeof(e)+" is not iterable")}function _slicedToArray(r,e){return _arrayWithHoles(r)||_iterableToArrayLimit(r,e)||_unsupportedIterableToArray(r,e)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArrayLimit(r,l){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=t){var e,n,i,u,a=[],f=!0,o=!1;try{if(i=(t=t.call(r)).next,0===l){if(Object(t)!==t)return;f=!1}else for(;!(f=(e=i.call(t)).done)&&(a.push(e.value),a.length!==l);f=!0);}catch(r){o=!0,n=r}finally{try{if(!f&&null!=t["return"]&&(u=t["return"](),Object(u)!==u))return}finally{if(o)throw n}}return a}}function _arrayWithHoles(r){if(Array.isArray(r))return r}function _toConsumableArray(r){return _arrayWithoutHoles(r)||_iterableToArray(r)||_unsupportedIterableToArray(r)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArray(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}function _arrayWithoutHoles(r){if(Array.isArray(r))return _arrayLikeToArray(r)}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e))}function _possibleConstructorReturn(t,e){if(e&&("object"==_typeof(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(t)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t})()}function _getPrototypeOf(t){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},_getPrototypeOf(t)}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&_setPrototypeOf(t,e)}function _setPrototypeOf(t,e){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},_setPrototypeOf(t,e)}function _regenerator(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof Generator?n:Generator,u=Object.create(c.prototype);return _regeneratorDefine2(u,"_invoke",function(r,n,o){var i,c,u,f=0,p=o||[],y=!1,G={p:0,n:0,v:e,a:d,f:d.bind(e,4),d:function d(t,r){return i=t,c=0,u=e,G.n=r,a}};function d(r,n){for(c=r,u=n,t=0;!y&&f&&!o&&t<p.length;t++){var o,i=p[t],d=G.p,l=i[2];r>3?(o=l===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=d&&((o=r<2&&d<i[1])?(c=0,G.v=n,G.n=i[1]):d<l&&(o=r<3||i[0]>n||n>l)&&(i[4]=r,i[5]=n,G.n=l,c=0))}if(o||r>1)return a;throw y=!0,n}return function(o,p,l){if(f>1)throw TypeError("Generator is already running");for(y&&1===p&&d(p,l),c=p,u=l;(t=c<2?e:u)||!y;){i||(c?c<3?(c>1&&(G.n=-1),d(c,u)):G.n=u:G.v=u);try{if(f=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i["return"])&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(y=G.n<0)?u:r.call(n,G))!==a)break}catch(t){i=e,c=1,u=t}finally{f=1}}return{value:t,done:y}}}(r,o,i),!0),u}var a={};function Generator(){}function GeneratorFunction(){}function GeneratorFunctionPrototype(){}t=Object.getPrototypeOf;var c=[][n]?t(t([][n]())):(_regeneratorDefine2(t={},n,function(){return this}),t),u=GeneratorFunctionPrototype.prototype=Generator.prototype=Object.create(c);function f(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,GeneratorFunctionPrototype):(e.__proto__=GeneratorFunctionPrototype,_regeneratorDefine2(e,o,"GeneratorFunction")),e.prototype=Object.create(u),e}return GeneratorFunction.prototype=GeneratorFunctionPrototype,_regeneratorDefine2(u,"constructor",GeneratorFunctionPrototype),_regeneratorDefine2(GeneratorFunctionPrototype,"constructor",GeneratorFunction),GeneratorFunction.displayName="GeneratorFunction",_regeneratorDefine2(GeneratorFunctionPrototype,o,"GeneratorFunction"),_regeneratorDefine2(u),_regeneratorDefine2(u,o,"Generator"),_regeneratorDefine2(u,n,function(){return this}),_regeneratorDefine2(u,"toString",function(){return"[object Generator]"}),(_regenerator=function _regenerator(){return{w:i,m:f}})()}function _regeneratorDefine2(e,r,n,t){var i=Object.defineProperty;try{i({},"",{})}catch(e){i=0}_regeneratorDefine2=function _regeneratorDefine(e,r,n,t){function o(r,n){_regeneratorDefine2(e,r,function(e){return this._invoke(r,n,e)})}r?i?i(e,r,{value:n,enumerable:!t,configurable:!t,writable:!t}):e[r]=n:(o("next",0),o("throw",1),o("return",2))},_regeneratorDefine2(e,r,n,t)}function asyncGeneratorStep(n,t,e,r,o,a,c){try{var i=n[a](c),u=i.value}catch(n){return void e(n)}i.done?t(u):Promise.resolve(u).then(r,o)}function _asyncToGenerator(n){return function(){var t=this,e=arguments;return new Promise(function(r,o){var a=n.apply(t,e);function _next(n){asyncGeneratorStep(a,r,o,_next,_throw,"next",n)}function _throw(n){asyncGeneratorStep(a,r,o,_next,_throw,"throw",n)}_next(void 0)})}}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o)}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+""}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},_typeof(o)}function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var _n=0,F=function F(){};return{s:F,n:function n(){return _n>=r.length?{done:!0}:{done:!1,value:r[_n++]}},e:function e(r){throw r},f:F}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,u=!1;return{s:function s(){t=t.call(r)},n:function n(){var r=t.next();return a=r.done,r},e:function e(r){u=!0,o=r},f:function f(){try{a||null==t["return"]||t["return"]()}finally{if(u)throw o}}}}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n}(function(){var __defProp=Object.defineProperty;var __getOwnPropSymbols=Object.getOwnPropertySymbols;var __hasOwnProp=Object.prototype.hasOwnProperty;var __propIsEnum=Object.prototype.propertyIsEnumerable;var __defNormalProp=function __defNormalProp(obj,key,value){return key in obj?__defProp(obj,key,{enumerable:true,configurable:true,writable:true,value:value}):obj[key]=value};var __spreadValues=function __spreadValues(a,b){for(var prop in b||(b={}))if(__hasOwnProp.call(b,prop))__defNormalProp(a,prop,b[prop]);if(__getOwnPropSymbols){var _iterator=_createForOfIteratorHelper(__getOwnPropSymbols(b)),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var prop=_step.value;if(__propIsEnum.call(b,prop))__defNormalProp(a,prop,b[prop])}}catch(err){_iterator.e(err)}finally{_iterator.f()}}return a};var __objRest=function __objRest(source,exclude){var target={};for(var prop in source)if(__hasOwnProp.call(source,prop)&&exclude.indexOf(prop)<0)target[prop]=source[prop];if(source!=null&&__getOwnPropSymbols){var _iterator2=_createForOfIteratorHelper(__getOwnPropSymbols(source)),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var prop=_step2.value;if(exclude.indexOf(prop)<0&&__propIsEnum.call(source,prop))target[prop]=source[prop]}}catch(err){_iterator2.e(err)}finally{_iterator2.f()}}return target};var __publicField=function __publicField(obj,key,value){return __defNormalProp(obj,_typeof(key)!=="symbol"?key+"":key,value)};// ../vinyl-util/test/browserTestUtil/benchmark/Benchmark.ts
2
+ var now;if(typeof window!=="undefined"&&typeof window.performance!=="undefined"&&typeof window.performance.now!=="undefined"){now=function now(){return window.performance.now()}}else if(typeof self!=="undefined"&&typeof self.performance!=="undefined"&&typeof self.performance.now!=="undefined"){now=function now(){return self.performance.now()}}else{now=function now(){return Date.now()}}var BenchmarkRunResults=/*#__PURE__*/function(){function BenchmarkRunResults(name){_classCallCheck(this,BenchmarkRunResults);__publicField(this,"name",name);__publicField(this,"cycleResults",[]);__publicField(this,"_totalSamples",0)}return _createClass(BenchmarkRunResults,[{key:"totalSamples",get:function get(){return this._totalSamples}},{key:"cycleResultsNoOutliers",get:function get(){var sD=this.standardDeviation;var avg=average(this.cycleResults);return this.cycleResults.filter(function(e){var zScore=(avg-e)/sD;return Math.abs(zScore)<3})}/**
3
+ * Returns the mean ops per second minus outliers of greater than 3 standard deviations.
4
+ */},{key:"meanOpsPerSec",get:function get(){return average(this.cycleResultsNoOutliers)}},{key:"standardDeviation",get:function get(){return standardDeviation(this.cycleResults)}},{key:"variance",get:function get(){return this.standardDeviation/this.meanOpsPerSec}/**
5
+ * Returns the mean ops / s ± variance % as a string.
6
+ */},{key:"meanOpsStr",get:function get(){var mean=this.meanOpsPerSec.toLocaleString(void 0,{maximumSignificantDigits:4});var variance=this.variance.toLocaleString(void 0,{style:"percent"});return"".concat(mean," \xB1").concat(variance)}},{key:"add",value:function add(cycle){var opsPerSecond=cycle.ops/cycle.duration;var index=this.cycleResults.findIndex(function(value){return opsPerSecond<value});if(index<0)index=this.cycleResults.length;this.cycleResults.splice(index,0,opsPerSecond);this._totalSamples+=cycle.ops}},{key:"toString",value:function toString(){if(!this.cycleResults.length)return"No results";return"".concat(this.name,": ").concat(this.meanOpsStr," ops/sec")}}])}();var RunResultsComparison=/*#__PURE__*/function(){function RunResultsComparison(name,results){_classCallCheck(this,RunResultsComparison);__publicField(this,"name",name);/**
7
+ * Sorted by median ops/s from slowest to fastest.
8
+ */__publicField(this,"results");this.results=results.sort(function(a,b){return a.meanOpsPerSec-b.meanOpsPerSec})}return _createClass(RunResultsComparison,[{key:"logToTable",value:function logToTable(){var _this=this;var r=this.results.map(function(run){var variance=run.variance.toLocaleString(void 0,{style:"percent"});var mean=run.meanOpsPerSec.toLocaleString(void 0,{maximumSignificantDigits:4});return{Name:run.name,Mean:"".concat(mean," \xB1").concat(variance),Samples:run.totalSamples,Compare:_this.runComparisonToString(run)}});var table=r.reduce(function(acc,_a){var _b=_a,Name=_b.Name,x=__objRest(_b,["Name"]);acc[Name]=x;return acc},{});console.log("\n"+this.name);console.table(table)}},{key:"runComparisonToString",value:function runComparisonToString(run){var _a,_b;var baseline=(_b=(_a=this.results[0])==null?void 0:_a.meanOpsPerSec)!=null?_b:0;var fasterPercent=run.meanOpsPerSec/baseline-1;return fasterPercent<0.01?"-":fasterPercent.toLocaleString(void 0,{style:"percent"})+" faster"}}])}();function compareResults(name){for(var _len=arguments.length,results=new Array(_len>1?_len-1:0),_key=1;_key<_len;_key++){results[_key-1]=arguments[_key]}return new RunResultsComparison(name,results)}var defaultBenchmarkOptions={warmupTime:0.5,maxCycleDuration:0.5,cycles:9};var _Benchmark=/*#__PURE__*/function(){/**
9
+ * Constructs a new Benchmark.
10
+ *
11
+ * @param name The name of the benchmark, to be used when logging.
12
+ * @param executor The method to execute and measure. If this method returns a promise, the
13
+ * promise will be awaited. The executor should either always return a promise, or never.
14
+ * @param options Optional configuration for the benchmark.
15
+ */function _Benchmark(name,executor,options){_classCallCheck(this,_Benchmark);__publicField(this,"name",name);__publicField(this,"executor",executor);__publicField(this,"options");this.options=__spreadValues(__spreadValues({},defaultBenchmarkOptions),options)}return _createClass(_Benchmark,[{key:"run",value:function(){var _run=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(){var _this2=this;var opts,warmupTimeMs,cycleStart,isAsync,result,resultsPromise;return _regenerator().w(function(_context2){while(1)switch(_context2.n){case 0:opts=this.options;_context2.n=1;return _Benchmark.semaphore;case 1:warmupTimeMs=opts.warmupTime*1e3;cycleStart=now();isAsync=false;case 2:result=this.executor();isAsync=isAsync||result&&typeof result.then==="function";if(!isAsync){_context2.n=3;break}_context2.n=3;return result;case 3:if(now()-cycleStart<warmupTimeMs){_context2.n=2;break}case 4:resultsPromise=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(){var results,i,cycleResults;return _regenerator().w(function(_context){while(1)switch(_context.n){case 0:results=new BenchmarkRunResults(_this2.name);i=0;case 1:if(!(i<opts.cycles)){_context.n=4;break}_context.n=2;return _this2.runCycle(isAsync);case 2:cycleResults=_context.v;results.add(cycleResults);_context.n=3;return nextFrame();case 3:i++;_context.n=1;break;case 4:return _context.a(2,results)}},_callee)}))();_Benchmark.semaphore=resultsPromise;_context2.n=5;return resultsPromise;case 5:return _context2.a(2,_context2.v)}},_callee2,this)}));function run(){return _run.apply(this,arguments)}return run}()/**
16
+ * Runs one cycle. A cycle will repeat the executor approximately `options.maxCycleDuration`
17
+ * seconds.
18
+ *
19
+ * @param isAsync
20
+ * @return Returns the duration (in seconds) and number of operations the cycle repeated.
21
+ */},{key:"runCycle",value:(function(){var _runCycle=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(isAsync){var cycleMs,ops,cycleStart,result,duration;return _regenerator().w(function(_context3){while(1)switch(_context3.n){case 0:cycleMs=this.options.maxCycleDuration*1e3;ops=0;cycleStart=now();case 1:result=this.executor();if(!isAsync){_context3.n=2;break}_context3.n=2;return result;case 2:ops++;case 3:if(now()-cycleStart<cycleMs){_context3.n=1;break}case 4:duration=(now()-cycleStart)/1e3;return _context3.a(2,{duration:duration,ops:ops})}},_callee3,this)}));function runCycle(_x){return _runCycle.apply(this,arguments)}return runCycle}())}])}();__publicField(_Benchmark,"semaphore",nextFrame());var Benchmark=_Benchmark;function benchmark(name,executor,options){var benchmark2=new Benchmark(name,executor,options);return benchmark2.run().then(function(results){console.log(results.toString());return results})}function nextFrame(){return new Promise(function(resolve){setTimeout(resolve)})}function standardDeviation(values){var avg=average(values);var squareDiffs=values.map(function(value){var diff=value-avg;return diff*diff});var avgSquareDiff=average(squareDiffs);return Math.sqrt(avgSquareDiff)}function average(values){var sum=values.reduce(function(acc,value){return acc+value},0);return sum/values.length}// ../vinyl-util/test/browserTestUtil/env/jasmineEnv.ts
22
+ var nextTestTimeoutOverridden=false;function setTestTimeout(timeout){var originalTimeout=null;beforeEach(function(){originalTimeout=jasmine.DEFAULT_TIMEOUT_INTERVAL;if(!nextTestTimeoutOverridden)jasmine.DEFAULT_TIMEOUT_INTERVAL=timeout*1e3});afterEach(function(){if(originalTimeout)jasmine.DEFAULT_TIMEOUT_INTERVAL=originalTimeout;if(nextTestTimeoutOverridden)nextTestTimeoutOverridden=false})}// ../vinyl-util/test/browserTestUtil/expect/expectNothing.ts
23
+ function expectNothing(){expect(true).toBeTruthy()}// ../vinyl-util/test/browserTestUtil/mock/createSpyFactory.ts
24
+ var createSpy=jasmine.createSpy;function createSpy2(key){return createSpy(String(key))}// ../vinyl-util/test/browserTestUtil/mock/dom/lib.dom.ts
25
+ var MockAbortSignal=/*#__PURE__*/_createClass(function MockAbortSignal(){_classCallCheck(this,MockAbortSignal);__publicField(this,"aborted",false);__publicField(this,"onabort",null);__publicField(this,"reason");__publicField(this,"throwIfAborted",createSpy2("throwIfAborted"));__publicField(this,"addEventListener",createSpy2("addEventListener"));__publicField(this,"removeEventListener",createSpy2("removeEventListener"));__publicField(this,"dispatchEvent",createSpy2("dispatchEvent"))});var MockMediaSource=/*#__PURE__*/_createClass(function MockMediaSource(){_classCallCheck(this,MockMediaSource);__publicField(this,"activeSourceBuffers");__publicField(this,"duration",0);__publicField(this,"onsourceclose",null);__publicField(this,"onsourceended",null);__publicField(this,"onsourceopen",null);__publicField(this,"readyState","closed");__publicField(this,"sourceBuffers");__publicField(this,"addSourceBuffer",createSpy2("addSourceBuffer"));__publicField(this,"clearLiveSeekableRange",createSpy2("clearLiveSeekableRange"));__publicField(this,"endOfStream",createSpy2("endOfStream"));__publicField(this,"removeSourceBuffer",createSpy2("removeSourceBuffer"));__publicField(this,"setLiveSeekableRange",createSpy2("setLiveSeekableRange"));__publicField(this,"addEventListener",createSpy2("addEventListener"));__publicField(this,"removeEventListener",createSpy2("removeEventListener"));__publicField(this,"dispatchEvent",createSpy2("dispatchEvent"))});// ../vinyl-util/test/browserTestUtil/mock/dom/globals.ts
26
+ var MockMediaSourceGlobal=/*#__PURE__*/function(_MockMediaSource){function MockMediaSourceGlobal(){_classCallCheck(this,MockMediaSourceGlobal);return _callSuper(this,MockMediaSourceGlobal,arguments)}_inherits(MockMediaSourceGlobal,_MockMediaSource);return _createClass(MockMediaSourceGlobal)}(MockMediaSource);__publicField(MockMediaSourceGlobal,"canConstructInDedicatedWorker",false);__publicField(MockMediaSourceGlobal,"isTypeSupported",createSpy2("isTypeSupported"));var MockAbortSignalGlobal=/*#__PURE__*/function(_MockAbortSignal){function MockAbortSignalGlobal(){_classCallCheck(this,MockAbortSignalGlobal);return _callSuper(this,MockAbortSignalGlobal,arguments)}_inherits(MockAbortSignalGlobal,_MockAbortSignal);return _createClass(MockAbortSignalGlobal)}(MockAbortSignal);__publicField(MockAbortSignalGlobal,"abort",createSpy2("abort"));__publicField(MockAbortSignalGlobal,"any",createSpy2("any"));__publicField(MockAbortSignalGlobal,"timeout",createSpy2("timeout"));// src/domUtil.ts
27
+ function walkDomDepthFirst(node,callback){if(!node)return;var next=node.firstChild;while(next){var after=next.nextSibling;walkDomDepthFirst(next,callback);next=after}callback(node)}// src/extensions/connectedObserver.ts
28
+ var CONNECTION_CALLBACKS=/* @__PURE__ */Symbol["for"]("@amazon/vinyl-tsx/connectionCallbacks");function callbacksOf(node){var observed=node;var callbacks=observed[CONNECTION_CALLBACKS];if(!callbacks){callbacks={connect:/* @__PURE__ */new Set,disconnect:/* @__PURE__ */new Set};observed[CONNECTION_CALLBACKS]=callbacks}return callbacks}function notify(node,type){var _a;var callbacks=(_a=node[CONNECTION_CALLBACKS])==null?void 0:_a[type];if(callbacks==null?void 0:callbacks.size)for(var _i=0,_arr=_toConsumableArray(callbacks);_i<_arr.length;_i++){var callback=_arr[_i];callback()}}function initializeConnectedObserver(){var options=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _a;var events=(_a=options.events)!=null?_a:true;var observer=new MutationObserver(function(mutations){var removed=/* @__PURE__ */new Set;var added=/* @__PURE__ */new Set;var _iterator3=_createForOfIteratorHelper(mutations),_step3;try{for(_iterator3.s();!(_step3=_iterator3.n()).done;){var mutation=_step3.value;mutation.removedNodes.forEach(function(node){return removed.add(node)});mutation.addedNodes.forEach(function(node){return added.add(node)})}}catch(err){_iterator3.e(err)}finally{_iterator3.f()}var _iterator4=_createForOfIteratorHelper(mutations),_step4;try{for(_iterator4.s();!(_step4=_iterator4.n()).done;){var _mutation=_step4.value;var _iterator5=_createForOfIteratorHelper(_mutation.addedNodes),_step5;try{for(_iterator5.s();!(_step5=_iterator5.n()).done;){var node=_step5.value;if(removed.has(node))continue;walkDomDepthFirst(node,function(iNode){notify(iNode,"connect");if(events){iNode.dispatchEvent(new CustomEvent("connect",{bubbles:false}))}})}}catch(err){_iterator5.e(err)}finally{_iterator5.f()}var _iterator6=_createForOfIteratorHelper(_mutation.removedNodes),_step6;try{for(_iterator6.s();!(_step6=_iterator6.n()).done;){var _node=_step6.value;if(added.has(_node))continue;walkDomDepthFirst(_node,function(iNode){notify(iNode,"disconnect");if(events){iNode.dispatchEvent(new CustomEvent("disconnect",{bubbles:false}))}})}}catch(err){_iterator6.e(err)}finally{_iterator6.f()}}}catch(err){_iterator4.e(err)}finally{_iterator4.f()}});observer.observe(document,{childList:true,subtree:true});return function(){observer.disconnect()}}function onConnect(target,callback){var sub=null;var connected=false;var onConnect2=function onConnect2(){if(connected)return;connected=true;sub=callback(target)};var onDisconnect=function onDisconnect(){connected=false;sub==null?void 0:sub();sub=null};var callbacks=callbacksOf(target);callbacks.connect.add(onConnect2);callbacks.disconnect.add(onDisconnect);target.addEventListener("connect",onConnect2);target.addEventListener("disconnect",onDisconnect);if(target.isConnected)onConnect2();return function(){callbacks.connect["delete"](onConnect2);callbacks.disconnect["delete"](onDisconnect);target.removeEventListener("connect",onConnect2);target.removeEventListener("disconnect",onDisconnect);onDisconnect()}}// test/benchmark/setup.ts
29
+ function setupBenchmark(){setTestTimeout(180);afterEach(expectNothing)}var comparisons=[];function addComparison(comparison){comparisons.push(comparison)}function addBenchmarks(name){for(var _len2=arguments.length,results=new Array(_len2>1?_len2-1:0),_key2=1;_key2<_len2;_key2++){results[_key2-1]=arguments[_key2]}var comparison=compareResults.apply(void 0,[name].concat(results));comparison.logToTable();comparisons.push(comparison)}if(typeof document!=="undefined"){jasmine.getEnv().addReporter({jasmineDone:function jasmineDone(){var _a;console.log("Tests complete");var jasmineContainer=document.getElementsByClassName("jasmine_html-reporter")[0];(_a=jasmineContainer.parentElement)==null?void 0:_a.removeChild(jasmineContainer);var container=createEl("div",document.body);container.id="benchmarkResults";var sortedComparisons=[].concat(comparisons).sort(function(a,b){return a.name>b.name?1:-1});var _iterator7=_createForOfIteratorHelper(sortedComparisons),_step7;try{for(_iterator7.s();!(_step7=_iterator7.n()).done;){var comparison=_step7.value;toTableHtml(comparison,container)}}catch(err){_iterator7.e(err)}finally{_iterator7.f()}}})}function toTableHtml(comparison,parent){var container=createEl("div",parent);container.className="benchmarkComparison";var title=createEl("h2",container);title.innerText=comparison.name;var table=createEl("table",container);var head=createEl("thead",table);var headRow=createEl("tr",head);var name=createEl("th",headRow);name.innerText="Name";var median=createEl("th",headRow);median.innerText="Mean ops/s";var samples=createEl("th",headRow);samples.innerText="Samples";var compare=createEl("th",headRow);compare.innerText="% Comparison";var body=createEl("tbody",table);comparison.results.forEach(function(result){var row=createEl("tr",body);createEl("th",row).innerText=result.name;createEl("td",row).innerText=result.meanOpsStr;createEl("td",row).innerText=result.totalSamples.toLocaleString();createEl("td",row).innerText=comparison.runComparisonToString(result)});return container}function createEl(tagName,parent,options){var element=document.createElement(tagName,options);if(parent)parent.appendChild(element);return element}// test/benchmark/extensions/connectedObserver.bench.ts
30
+ describe("connectedObserver",function(){setupBenchmark();var observers={"no observer":function no_observer(){return function(){}},"events on":function events_on(){return initializeConnectedObserver()},"events off":function events_off(){return initializeConnectedObserver({events:false})}};var connections=0;function createPage(cards,listeners){var page=document.createElement("div");var row=page;for(var i=0;i<cards;i++){if(i%10===0)row=append(page,"div");var card=append(row,"div");append(card,"div");var meta=append(card,"div");var title=document.createTextNode("Title ".concat(i));append(meta,"span").appendChild(title);append(meta,"span").appendChild(document.createTextNode("Subtitle ".concat(i)));if(listeners){observe(card);observe(title)}}return page}function append(parent,tagName){return parent.appendChild(document.createElement(tagName))}function observe(node){onConnect(node,function(){connections++;return function(){return connections--}})}function countNodes(root){var count=0;walkDomDepthFirst(root,function(){return count++});return count}function flushMutations(){return Promise.resolve()}function compareObservers(_x2,_x3){return _compareObservers.apply(this,arguments)}function _compareObservers(){_compareObservers=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(name,executor){var results,_loop,_i2,_Object$entries;return _regenerator().w(function(_context1){while(1)switch(_context1.n){case 0:results=[];_loop=/*#__PURE__*/_regenerator().m(function _loop(){var _Object$entries$_i,observerName,initialize,container,unsubscribe,_t;return _regenerator().w(function(_context0){while(1)switch(_context0.p=_context0.n){case 0:_Object$entries$_i=_slicedToArray(_Object$entries[_i2],2),observerName=_Object$entries$_i[0],initialize=_Object$entries$_i[1];container=document.body.appendChild(document.createElement("div"));unsubscribe=initialize();_context0.p=1;_t=results;_context0.n=2;return benchmark(observerName,function(){return executor(container)});case 2:_t.push.call(_t,_context0.v);case 3:_context0.p=3;unsubscribe();container.remove();return _context0.f(3);case 4:return _context0.a(2)}},_loop,null,[[1,,3,4]])});_i2=0,_Object$entries=Object.entries(observers);case 1:if(!(_i2<_Object$entries.length)){_context1.n=3;break}return _context1.d(_regeneratorValues(_loop()),2);case 2:_i2++;_context1.n=1;break;case 3:addBenchmarks.apply(void 0,[name].concat(results));case 4:return _context1.a(2)}},_callee0)}));return _compareObservers.apply(this,arguments)};[1e3,5e3].forEach(function(size){var cards=Math.round(size/7);describe("".concat(size," nodes"),function(){var page=createPage(cards,true);var nodes=countNodes(page);var label="".concat(nodes.toLocaleString()," nodes, ").concat(Math.round(cards*2/nodes*100),"% with listeners");it("mount and unmount",/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(){return _regenerator().w(function(_context5){while(1)switch(_context5.n){case 0:_context5.n=1;return compareObservers("mount and unmount ".concat(label),/*#__PURE__*/function(){var _ref3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(container){return _regenerator().w(function(_context4){while(1)switch(_context4.n){case 0:container.appendChild(page);_context4.n=1;return flushMutations();case 1:page.remove();_context4.n=2;return flushMutations();case 2:return _context4.a(2)}},_callee4)}));return function(_x4){return _ref3.apply(this,arguments)}}());case 1:return _context5.a(2)}},_callee5)})));it("page swap",/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(){var pages,next;return _regenerator().w(function(_context7){while(1)switch(_context7.n){case 0:pages=[page,createPage(cards,true)];next=0;_context7.n=1;return compareObservers("page swap ".concat(label),/*#__PURE__*/function(){var _ref5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(container){return _regenerator().w(function(_context6){while(1)switch(_context6.n){case 0:if(container.firstChild){container.replaceChild(pages[next],container.firstChild)}else{container.appendChild(pages[next])}next=1-next;_context6.n=1;return flushMutations();case 1:return _context6.a(2)}},_callee6)}));return function(_x5){return _ref5.apply(this,arguments)}}());case 1:return _context7.a(2)}},_callee7)})));it("mount and unmount without listeners",/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(){var emptyPage;return _regenerator().w(function(_context9){while(1)switch(_context9.n){case 0:emptyPage=createPage(cards,false);_context9.n=1;return compareObservers("mount and unmount ".concat(nodes.toLocaleString()," nodes, no listeners"),/*#__PURE__*/function(){var _ref7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(container){return _regenerator().w(function(_context8){while(1)switch(_context8.n){case 0:container.appendChild(emptyPage);_context8.n=1;return flushMutations();case 1:emptyPage.remove();_context8.n=2;return flushMutations();case 2:return _context8.a(2)}},_callee8)}));return function(_x6){return _ref7.apply(this,arguments)}}());case 1:return _context9.a(2)}},_callee9)})))})})})})();