@amazon/vinyl-tsx 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/index.cjs +354 -0
  2. package/dist/index.cjs.map +7 -0
  3. package/dist/index.js +340 -0
  4. package/dist/index.js.map +7 -0
  5. package/dist/types/current/ActiveText.d.ts +8 -0
  6. package/dist/types/current/ActiveText.d.ts.map +1 -0
  7. package/dist/types/current/ActiveText.js +19 -0
  8. package/dist/types/current/domUtil.d.ts +33 -0
  9. package/dist/types/current/domUtil.d.ts.map +1 -0
  10. package/dist/types/current/domUtil.js +73 -0
  11. package/dist/types/current/extensions/HookExtension.d.ts +2 -0
  12. package/dist/types/current/extensions/HookExtension.d.ts.map +1 -0
  13. package/dist/types/current/extensions/HookExtension.js +5 -0
  14. package/dist/types/current/extensions/applyClassList.d.ts +4 -0
  15. package/dist/types/current/extensions/applyClassList.d.ts.map +1 -0
  16. package/dist/types/current/extensions/applyClassList.js +40 -0
  17. package/dist/types/current/extensions/applyPassiveHandler.d.ts +7 -0
  18. package/dist/types/current/extensions/applyPassiveHandler.d.ts.map +1 -0
  19. package/dist/types/current/extensions/applyPassiveHandler.js +15 -0
  20. package/dist/types/current/extensions/applyStyles.d.ts +12 -0
  21. package/dist/types/current/extensions/applyStyles.d.ts.map +1 -0
  22. package/dist/types/current/extensions/applyStyles.js +31 -0
  23. package/dist/types/current/extensions/applyVisibility.d.ts +3 -0
  24. package/dist/types/current/extensions/applyVisibility.d.ts.map +1 -0
  25. package/dist/types/current/extensions/applyVisibility.js +21 -0
  26. package/dist/types/current/extensions/connectedObserver.d.ts +15 -0
  27. package/dist/types/current/extensions/connectedObserver.d.ts.map +1 -0
  28. package/dist/types/current/extensions/connectedObserver.js +72 -0
  29. package/dist/types/current/index.d.ts +12 -0
  30. package/dist/types/current/index.d.ts.map +1 -0
  31. package/dist/types/current/index.js +11 -0
  32. package/dist/types/current/jsx.d.ts +55 -0
  33. package/dist/types/current/jsx.d.ts.map +1 -0
  34. package/dist/types/current/jsx.js +106 -0
  35. package/dist/types/current/tsconfig.tsbuildinfo +1 -0
  36. package/dist/types/current/type.d.ts +10 -0
  37. package/dist/types/current/type.d.ts.map +1 -0
  38. package/dist/types/current/type.js +5 -0
  39. package/dist/types/ts3.7/ActiveText.d.ts +8 -0
  40. package/dist/types/ts3.7/domUtil.d.ts +33 -0
  41. package/dist/types/ts3.7/extensions/HookExtension.d.ts +2 -0
  42. package/dist/types/ts3.7/extensions/applyClassList.d.ts +4 -0
  43. package/dist/types/ts3.7/extensions/applyPassiveHandler.d.ts +7 -0
  44. package/dist/types/ts3.7/extensions/applyStyles.d.ts +12 -0
  45. package/dist/types/ts3.7/extensions/applyVisibility.d.ts +3 -0
  46. package/dist/types/ts3.7/extensions/connectedObserver.d.ts +15 -0
  47. package/dist/types/ts3.7/index.d.ts +12 -0
  48. package/dist/types/ts3.7/jsx.d.ts +55 -0
  49. package/dist/types/ts3.7/type.d.ts +10 -0
  50. package/dist/types/ts4.1/ActiveText.d.ts +8 -0
  51. package/dist/types/ts4.1/domUtil.d.ts +33 -0
  52. package/dist/types/ts4.1/extensions/HookExtension.d.ts +2 -0
  53. package/dist/types/ts4.1/extensions/applyClassList.d.ts +4 -0
  54. package/dist/types/ts4.1/extensions/applyPassiveHandler.d.ts +7 -0
  55. package/dist/types/ts4.1/extensions/applyStyles.d.ts +12 -0
  56. package/dist/types/ts4.1/extensions/applyVisibility.d.ts +3 -0
  57. package/dist/types/ts4.1/extensions/connectedObserver.d.ts +15 -0
  58. package/dist/types/ts4.1/index.d.ts +12 -0
  59. package/dist/types/ts4.1/jsx.d.ts +55 -0
  60. package/dist/types/ts4.1/type.d.ts +10 -0
  61. package/dist/types/ts4.7/ActiveText.d.ts +8 -0
  62. package/dist/types/ts4.7/domUtil.d.ts +33 -0
  63. package/dist/types/ts4.7/extensions/HookExtension.d.ts +2 -0
  64. package/dist/types/ts4.7/extensions/applyClassList.d.ts +4 -0
  65. package/dist/types/ts4.7/extensions/applyPassiveHandler.d.ts +7 -0
  66. package/dist/types/ts4.7/extensions/applyStyles.d.ts +12 -0
  67. package/dist/types/ts4.7/extensions/applyVisibility.d.ts +3 -0
  68. package/dist/types/ts4.7/extensions/connectedObserver.d.ts +15 -0
  69. package/dist/types/ts4.7/index.d.ts +12 -0
  70. package/dist/types/ts4.7/jsx.d.ts +55 -0
  71. package/dist/types/ts4.7/type.d.ts +10 -0
  72. package/docs/TSX.md +316 -0
  73. package/package.json +82 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,354 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, { get: all[name], enumerable: true });
23
+ };
24
+ var __copyProps = (to, from, except, desc) => {
25
+ if (from && typeof from === "object" || typeof from === "function") {
26
+ for (let key of __getOwnPropNames(from))
27
+ if (!__hasOwnProp.call(to, key) && key !== except)
28
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
29
+ }
30
+ return to;
31
+ };
32
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
+
34
+ // src/index.ts
35
+ var index_exports = {};
36
+ __export(index_exports, {
37
+ ActiveText: () => ActiveText,
38
+ Fragment: () => Fragment,
39
+ applyClassList: () => applyClassList,
40
+ applyStyles: () => applyStyles,
41
+ applyVisibility: () => applyVisibility,
42
+ bindQuerySelector: () => bindQuerySelector,
43
+ el: () => el,
44
+ getVisible: () => getVisible,
45
+ hide: () => hide,
46
+ hookExtensions: () => hookExtensions,
47
+ initializeConnectedObserver: () => initializeConnectedObserver,
48
+ isHidden: () => isHidden,
49
+ isInputElement: () => isInputElement,
50
+ jsx: () => jsx,
51
+ onConnect: () => onConnect,
52
+ passiveEventHandlers: () => passiveEventHandlers,
53
+ propToAttr: () => propToAttr,
54
+ setClassToken: () => setClassToken,
55
+ setVisible: () => setVisible,
56
+ show: () => show,
57
+ walkDomDepthFirst: () => walkDomDepthFirst
58
+ });
59
+ module.exports = __toCommonJS(index_exports);
60
+
61
+ // src/domUtil.ts
62
+ function el(selectors, parentNode = document) {
63
+ const element = parentNode.querySelector(selectors);
64
+ if (!element) throw new Error(`${selectors} must be a DOM element`);
65
+ return element;
66
+ }
67
+ function bindQuerySelector(parentNode) {
68
+ return (selectors) => el(selectors, parentNode);
69
+ }
70
+ function hide(element) {
71
+ element.style.display = "none";
72
+ }
73
+ function show(element) {
74
+ element.style.removeProperty("display");
75
+ }
76
+ function getVisible(element) {
77
+ return element.style.display !== "none";
78
+ }
79
+ function setVisible(element, value) {
80
+ if (getVisible(element) === value) return;
81
+ if (value) show(element);
82
+ else hide(element);
83
+ }
84
+ function isHidden(element) {
85
+ let node = element;
86
+ while (node) {
87
+ if (getComputedStyle(node).display === "none") return true;
88
+ node = node.parentElement;
89
+ }
90
+ return false;
91
+ }
92
+ function isInputElement(value) {
93
+ return (value == null ? void 0 : value.tagName.toLowerCase()) === "input";
94
+ }
95
+ function setClassToken(value, token, toggled) {
96
+ if (toggled) {
97
+ value.classList.add(token);
98
+ } else {
99
+ value.classList.remove(token);
100
+ }
101
+ }
102
+ function walkDomDepthFirst(node, callback) {
103
+ if (!node) return;
104
+ let next = node.firstChild;
105
+ while (next) {
106
+ walkDomDepthFirst(next, callback);
107
+ next = next.nextSibling;
108
+ }
109
+ callback(node);
110
+ }
111
+
112
+ // src/extensions/connectedObserver.ts
113
+ function initializeConnectedObserver() {
114
+ const observer = new MutationObserver((mutations) => {
115
+ const removed = /* @__PURE__ */ new Set();
116
+ const added = /* @__PURE__ */ new Set();
117
+ for (const mutation of mutations) {
118
+ mutation.removedNodes.forEach((node) => removed.add(node));
119
+ mutation.addedNodes.forEach((node) => added.add(node));
120
+ }
121
+ for (const mutation of mutations) {
122
+ for (const node of mutation.addedNodes) {
123
+ if (removed.has(node)) continue;
124
+ walkDomDepthFirst(node, (iNode) => {
125
+ iNode.dispatchEvent(
126
+ new CustomEvent("connect", { bubbles: false })
127
+ );
128
+ });
129
+ }
130
+ for (const node of mutation.removedNodes) {
131
+ if (added.has(node)) continue;
132
+ walkDomDepthFirst(node, (iNode) => {
133
+ iNode.dispatchEvent(
134
+ new CustomEvent("disconnect", { bubbles: false })
135
+ );
136
+ });
137
+ }
138
+ }
139
+ });
140
+ observer.observe(document, { childList: true, subtree: true });
141
+ return () => {
142
+ observer.disconnect();
143
+ };
144
+ }
145
+ function onConnect(target, callback) {
146
+ let sub = null;
147
+ let connected = false;
148
+ const onConnect2 = () => {
149
+ if (connected) return;
150
+ connected = true;
151
+ sub = callback(target);
152
+ };
153
+ const onDisconnect = () => {
154
+ connected = false;
155
+ sub == null ? void 0 : sub();
156
+ sub = null;
157
+ };
158
+ target.addEventListener("connect", onConnect2);
159
+ target.addEventListener("disconnect", onDisconnect);
160
+ if (target.isConnected) onConnect2();
161
+ return () => {
162
+ target.removeEventListener("connect", onConnect2);
163
+ target.removeEventListener("disconnect", onDisconnect);
164
+ onDisconnect();
165
+ };
166
+ }
167
+
168
+ // src/extensions/applyStyles.ts
169
+ var import_vinyl_util = require("@amazon/vinyl-util");
170
+ var import_vinyl_observable = require("@amazon/vinyl-observable");
171
+ function applyStyles(element, style) {
172
+ if (typeof style === "string") {
173
+ throw new Error("expected style property to be type object");
174
+ }
175
+ for (const k in style) {
176
+ const v = style[k];
177
+ const property = k.startsWith("--") ? k : (0, import_vinyl_util.toKebabCase)(k);
178
+ if ((0, import_vinyl_observable.isObservableValue)(v)) {
179
+ onConnect(element, () => {
180
+ return v.onData((value) => {
181
+ element.style.setProperty(
182
+ property,
183
+ value != null ? value : null
184
+ );
185
+ });
186
+ });
187
+ } else {
188
+ element.style.setProperty(property, v != null ? v : null);
189
+ }
190
+ }
191
+ }
192
+
193
+ // src/jsx.ts
194
+ var import_vinyl_observable3 = require("@amazon/vinyl-observable");
195
+
196
+ // src/ActiveText.ts
197
+ function ActiveText(data) {
198
+ var _a;
199
+ const text = document.createTextNode(String((_a = data.value) != null ? _a : ""));
200
+ onConnect(text, () => {
201
+ return data.onData((value) => {
202
+ text.textContent = String(value != null ? value : "");
203
+ });
204
+ });
205
+ return text;
206
+ }
207
+
208
+ // src/extensions/applyVisibility.ts
209
+ function applyVisibility(element, visible) {
210
+ if (typeof visible === "boolean") {
211
+ if (!visible) element.style.display = "none";
212
+ } else {
213
+ onConnect(element, () => {
214
+ return visible.onData((value) => {
215
+ if (value) element.style.removeProperty("display");
216
+ else element.style.display = "none";
217
+ });
218
+ });
219
+ }
220
+ }
221
+
222
+ // src/extensions/applyClassList.ts
223
+ var import_vinyl_observable2 = require("@amazon/vinyl-observable");
224
+ function applyClassList(element, classList) {
225
+ const tokens = classList.filter((s) => typeof s === "string");
226
+ element.classList.add(...tokens);
227
+ if (tokens.length < classList.length) {
228
+ onConnect(element, () => {
229
+ const subs = [];
230
+ for (const dP of classList.filter(import_vinyl_observable2.isObservableValue)) {
231
+ subs.push(bindClass(element, dP));
232
+ }
233
+ return () => {
234
+ subs.forEach((sub) => sub());
235
+ };
236
+ });
237
+ }
238
+ }
239
+ function bindClass(element, tokenProvider) {
240
+ let current = null;
241
+ const dataSub = tokenProvider.onData((className) => {
242
+ if (current) element.classList.remove(current);
243
+ if (className) {
244
+ current = className;
245
+ element.classList.add(className);
246
+ } else {
247
+ current = null;
248
+ }
249
+ });
250
+ return () => {
251
+ if (current != null) element.classList.remove(current);
252
+ dataSub();
253
+ };
254
+ }
255
+
256
+ // src/extensions/applyPassiveHandler.ts
257
+ var passiveEventHandlers = {
258
+ ontouchstart: /* @__PURE__ */ applyPassiveHandler("ontouchstart"),
259
+ ontouchmove: /* @__PURE__ */ applyPassiveHandler("ontouchmove"),
260
+ onwheel: /* @__PURE__ */ applyPassiveHandler("onwheel")
261
+ };
262
+ function applyPassiveHandler(key) {
263
+ const eventName = key.substring(2);
264
+ return (element, handler) => {
265
+ element.addEventListener(eventName, handler, { passive: true });
266
+ };
267
+ }
268
+
269
+ // src/jsx.ts
270
+ var propToAttr = {
271
+ acceptCharset: "accept-charset",
272
+ accessKey: "accesskey",
273
+ className: "class",
274
+ colSpan: "colspan",
275
+ contentEditable: "contenteditable",
276
+ crossOrigin: "crossorigin",
277
+ dateTime: "datetime",
278
+ dirName: "dirname",
279
+ encType: "enctype",
280
+ formAction: "formaction",
281
+ formEnctype: "formenctype",
282
+ formMethod: "formmethod",
283
+ formNoValidate: "formnovalidate",
284
+ formTarget: "formtarget",
285
+ htmlFor: "for",
286
+ httpEquiv: "http-equiv",
287
+ inputMode: "inputmode",
288
+ maxLength: "maxlength",
289
+ minLength: "minlength",
290
+ noModule: "nomodule",
291
+ noValidate: "novalidate",
292
+ readOnly: "readonly",
293
+ referrerPolicy: "referrerpolicy",
294
+ rowSpan: "rowspan",
295
+ tabIndex: "tabindex",
296
+ useMap: "usemap"
297
+ };
298
+ function setProp(element, k, value) {
299
+ var _a;
300
+ if (value == null) {
301
+ ;
302
+ element[k] = "";
303
+ const attr = (_a = propToAttr[k]) != null ? _a : k;
304
+ element.removeAttribute(attr);
305
+ } else {
306
+ ;
307
+ element[k] = value;
308
+ }
309
+ }
310
+ var hookExtensions = __spreadValues({
311
+ onConnect,
312
+ style: applyStyles,
313
+ visible: applyVisibility,
314
+ classList: applyClassList
315
+ }, passiveEventHandlers);
316
+ function jsx(type, props, ...children) {
317
+ if (typeof type === "string") {
318
+ const element = document.createElement(type);
319
+ for (const k in props) {
320
+ const v = props[k];
321
+ if (k in hookExtensions) {
322
+ hookExtensions[k](element, v);
323
+ continue;
324
+ }
325
+ if ((0, import_vinyl_observable3.isObservableValue)(v)) {
326
+ onConnect(element, () => {
327
+ return v.onData((data$) => setProp(element, k, data$));
328
+ });
329
+ } else {
330
+ setProp(element, k, v);
331
+ }
332
+ }
333
+ element.append(
334
+ ...children.filter((child) => child != null).map((child) => {
335
+ return (0, import_vinyl_observable3.isObservableValue)(child) ? ActiveText(child) : child;
336
+ })
337
+ );
338
+ return element;
339
+ } else {
340
+ return type(props, children);
341
+ }
342
+ }
343
+ function Fragment(_props, children) {
344
+ return jsx(
345
+ "div",
346
+ {
347
+ style: {
348
+ display: "contents"
349
+ }
350
+ },
351
+ ...children
352
+ );
353
+ }
354
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts", "../src/domUtil.ts", "../src/extensions/connectedObserver.ts", "../src/extensions/applyStyles.ts", "../src/jsx.ts", "../src/ActiveText.ts", "../src/extensions/applyVisibility.ts", "../src/extensions/applyClassList.ts", "../src/extensions/applyPassiveHandler.ts"],
4
+ "sourcesContent": ["/** Auto-generated from build scripts */\nexport * from './type'\nexport * from './jsx'\nexport * from './domUtil'\nexport * from './ActiveText'\nexport * from './extensions/connectedObserver'\nexport * from './extensions/applyVisibility'\nexport * from './extensions/applyStyles'\nexport * from './extensions/applyPassiveHandler'\nexport * from './extensions/applyClassList'\nexport * from './extensions/HookExtension'\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 walkDomDepthFirst(next, callback)\n next = next.nextSibling\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 { AllowBindable } from '../jsx'\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 `--`).\n */\nexport type StyleProp = AllowBindable<Partial<CSSStyleDeclaration>> & {\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 { 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, Maybe } from '@amazon/vinyl-util'\n\n/**\n * Maps JS property names to their corresponding HTML attribute names where they differ.\n * Extensible \u2014 add entries for custom elements or non-standard properties.\n */\nexport const propToAttr: Record<string, string> = {\n acceptCharset: 'accept-charset',\n accessKey: 'accesskey',\n className: 'class',\n colSpan: 'colspan',\n contentEditable: 'contenteditable',\n crossOrigin: 'crossorigin',\n dateTime: 'datetime',\n dirName: 'dirname',\n encType: 'enctype',\n formAction: 'formaction',\n formEnctype: 'formenctype',\n formMethod: 'formmethod',\n formNoValidate: 'formnovalidate',\n formTarget: 'formtarget',\n htmlFor: 'for',\n httpEquiv: 'http-equiv',\n inputMode: 'inputmode',\n maxLength: 'maxlength',\n minLength: 'minlength',\n noModule: 'nomodule',\n noValidate: 'novalidate',\n readOnly: 'readonly',\n referrerPolicy: 'referrerpolicy',\n rowSpan: 'rowspan',\n tabIndex: 'tabindex',\n useMap: 'usemap',\n}\n\n/**\n * Sets a property on an element. When value is non-null, assigns directly via\n * property. When null, resets the property to '' and removes the HTML attribute\n * using the mapped name from {@link propToAttr}.\n */\nfunction setProp(element: HTMLElement, k: string, value: unknown): void {\n if (value == null) {\n ;(element as any)[k] = ''\n const attr = propToAttr[k] ?? k\n element.removeAttribute(attr)\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<Maybe<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", "/*\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 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 {\n isObservableValue,\n type ObservableValue,\n} from '@amazon/vinyl-observable'\nimport { onConnect } from './connectedObserver'\nimport type { Maybe, Unsubscribe } from '@amazon/vinyl-util'\n\nexport function applyClassList(\n element: HTMLElement,\n classList: readonly (Maybe<string> | ObservableValue<Maybe<string>>)[]\n): void {\n const tokens = classList.filter((s) => typeof s === 'string')\n element.classList.add(...tokens)\n if (tokens.length < classList.length) {\n onConnect(element, () => {\n const subs: Unsubscribe[] = []\n for (const dP of classList.filter(isObservableValue)) {\n subs.push(bindClass(element, dP))\n }\n return () => {\n subs.forEach((sub) => sub())\n }\n })\n }\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"],
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;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,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