@microsoft/fast-element 1.10.2 → 2.0.0-beta.3

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 (104) hide show
  1. package/.eslintrc.json +1 -12
  2. package/CHANGELOG.json +387 -1
  3. package/CHANGELOG.md +74 -2
  4. package/README.md +2 -2
  5. package/dist/dts/components/attributes.d.ts +4 -1
  6. package/dist/dts/components/controller.d.ts +12 -11
  7. package/dist/dts/components/fast-definitions.d.ts +10 -2
  8. package/dist/dts/components/fast-element.d.ts +12 -5
  9. package/dist/dts/context.d.ts +157 -0
  10. package/dist/dts/debug.d.ts +1 -0
  11. package/dist/dts/hooks.d.ts +20 -0
  12. package/dist/dts/index.d.ts +16 -15
  13. package/dist/dts/index.debug.d.ts +2 -0
  14. package/dist/dts/index.rollup.d.ts +2 -0
  15. package/dist/dts/index.rollup.debug.d.ts +3 -0
  16. package/dist/dts/interfaces.d.ts +145 -0
  17. package/dist/dts/metadata.d.ts +25 -0
  18. package/dist/dts/observation/arrays.d.ts +207 -0
  19. package/dist/dts/observation/behavior.d.ts +4 -4
  20. package/dist/dts/observation/notifier.d.ts +18 -18
  21. package/dist/dts/observation/observable.d.ts +56 -18
  22. package/dist/dts/observation/splice-strategies.d.ts +13 -0
  23. package/dist/dts/observation/update-queue.d.ts +40 -0
  24. package/dist/dts/platform.d.ts +18 -67
  25. package/dist/dts/polyfills.d.ts +8 -0
  26. package/dist/dts/styles/css-directive.d.ts +43 -5
  27. package/dist/dts/styles/css.d.ts +19 -3
  28. package/dist/dts/styles/element-styles.d.ts +42 -62
  29. package/dist/dts/templating/binding-signal.d.ts +38 -0
  30. package/dist/dts/templating/binding-two-way.d.ts +56 -0
  31. package/dist/dts/templating/binding.d.ts +233 -65
  32. package/dist/dts/templating/children.d.ts +18 -15
  33. package/dist/dts/templating/compiler.d.ts +46 -28
  34. package/dist/dts/templating/dom.d.ts +41 -0
  35. package/dist/dts/templating/html-directive.d.ts +181 -43
  36. package/dist/dts/templating/markup.d.ts +48 -0
  37. package/dist/dts/templating/node-observation.d.ts +45 -29
  38. package/dist/dts/templating/ref.d.ts +6 -12
  39. package/dist/dts/templating/repeat.d.ts +26 -14
  40. package/dist/dts/templating/slotted.d.ts +13 -14
  41. package/dist/dts/templating/template.d.ts +27 -21
  42. package/dist/dts/templating/view.d.ts +15 -22
  43. package/dist/{tsdoc-metadata.json → dts/tsdoc-metadata.json} +1 -1
  44. package/dist/dts/utilities.d.ts +40 -0
  45. package/dist/esm/components/attributes.js +25 -24
  46. package/dist/esm/components/controller.js +77 -57
  47. package/dist/esm/components/fast-definitions.js +16 -22
  48. package/dist/esm/components/fast-element.js +10 -2
  49. package/dist/esm/context.js +159 -0
  50. package/dist/esm/debug.js +30 -0
  51. package/dist/esm/hooks.js +32 -0
  52. package/dist/esm/index.debug.js +2 -0
  53. package/dist/esm/index.js +19 -14
  54. package/dist/esm/index.rollup.debug.js +3 -0
  55. package/dist/esm/index.rollup.js +2 -0
  56. package/dist/esm/interfaces.js +8 -1
  57. package/dist/esm/metadata.js +60 -0
  58. package/dist/esm/observation/arrays.js +269 -0
  59. package/dist/esm/observation/notifier.js +27 -35
  60. package/dist/esm/observation/observable.js +93 -68
  61. package/dist/esm/observation/{array-change-records.js → splice-strategies.js} +136 -62
  62. package/dist/esm/observation/update-queue.js +67 -0
  63. package/dist/esm/platform.js +36 -42
  64. package/dist/esm/polyfills.js +85 -0
  65. package/dist/esm/styles/css-directive.js +29 -13
  66. package/dist/esm/styles/css.js +27 -40
  67. package/dist/esm/styles/element-styles.js +65 -104
  68. package/dist/esm/templating/binding-signal.js +84 -0
  69. package/dist/esm/templating/binding-two-way.js +82 -0
  70. package/dist/esm/templating/binding.js +306 -153
  71. package/dist/esm/templating/children.js +33 -23
  72. package/dist/esm/templating/compiler.js +236 -152
  73. package/dist/esm/templating/dom.js +49 -0
  74. package/dist/esm/templating/html-directive.js +128 -40
  75. package/dist/esm/templating/markup.js +75 -0
  76. package/dist/esm/templating/node-observation.js +50 -45
  77. package/dist/esm/templating/ref.js +7 -16
  78. package/dist/esm/templating/repeat.js +39 -36
  79. package/dist/esm/templating/slotted.js +23 -20
  80. package/dist/esm/templating/template.js +51 -95
  81. package/dist/esm/templating/view.js +44 -43
  82. package/dist/esm/templating/when.js +2 -1
  83. package/dist/esm/utilities.js +139 -0
  84. package/dist/fast-element.api.json +11789 -5377
  85. package/dist/fast-element.d.ts +1178 -530
  86. package/dist/fast-element.debug.js +3722 -0
  87. package/dist/fast-element.debug.min.js +1 -0
  88. package/dist/fast-element.js +3484 -4033
  89. package/dist/fast-element.min.js +1 -1
  90. package/dist/fast-element.untrimmed.d.ts +2699 -0
  91. package/docs/api-report.md +472 -219
  92. package/docs/fast-element-2-changes.md +15 -0
  93. package/docs/guide/declaring-templates.md +4 -4
  94. package/docs/guide/defining-elements.md +2 -2
  95. package/docs/guide/next-steps.md +2 -2
  96. package/docs/guide/observables-and-state.md +1 -1
  97. package/docs/guide/using-directives.md +1 -1
  98. package/karma.conf.cjs +6 -17
  99. package/package.json +63 -15
  100. package/dist/dts/dom.d.ts +0 -112
  101. package/dist/dts/observation/array-change-records.d.ts +0 -48
  102. package/dist/dts/observation/array-observer.d.ts +0 -9
  103. package/dist/esm/dom.js +0 -207
  104. package/dist/esm/observation/array-observer.js +0 -177
@@ -0,0 +1,3722 @@
1
+ (function ensureGlobalThis() {
2
+ if (typeof globalThis !== "undefined") {
3
+ // We're running in a modern environment.
4
+ return;
5
+ }
6
+ if (typeof global !== "undefined") {
7
+ // We're running in NodeJS
8
+ global.globalThis = global;
9
+ }
10
+ else if (typeof self !== "undefined") {
11
+ self.globalThis = self;
12
+ }
13
+ else if (typeof window !== "undefined") {
14
+ // We're running in the browser's main thread.
15
+ window.globalThis = window;
16
+ }
17
+ else {
18
+ // Hopefully we never get here...
19
+ // Not all environments allow eval and Function. Use only as a last resort:
20
+ // eslint-disable-next-line no-new-func
21
+ const result = new Function("return this")();
22
+ result.globalThis = result;
23
+ }
24
+ })();
25
+ // API-only Polyfill for trustedTypes
26
+ if (!globalThis.trustedTypes) {
27
+ globalThis.trustedTypes = {
28
+ createPolicy: (n, r) => r,
29
+ };
30
+ }
31
+ // ensure FAST global - duplicated in platform.ts
32
+ const propConfig$1 = {
33
+ configurable: false,
34
+ enumerable: false,
35
+ writable: false,
36
+ };
37
+ if (globalThis.FAST === void 0) {
38
+ Reflect.defineProperty(globalThis, "FAST", Object.assign({ value: Object.create(null) }, propConfig$1));
39
+ }
40
+ const FAST$2 = globalThis.FAST;
41
+ if (FAST$2.getById === void 0) {
42
+ const storage = Object.create(null);
43
+ Reflect.defineProperty(FAST$2, "getById", Object.assign({ value(id, initialize) {
44
+ let found = storage[id];
45
+ if (found === void 0) {
46
+ found = initialize ? (storage[id] = initialize()) : null;
47
+ }
48
+ return found;
49
+ } }, propConfig$1));
50
+ }
51
+ // duplicated from DOM
52
+ const supportsAdoptedStyleSheets = Array.isArray(document.adoptedStyleSheets) &&
53
+ "replace" in CSSStyleSheet.prototype;
54
+ function usableStyleTarget(target) {
55
+ return target === document ? document.body : target;
56
+ }
57
+ let id$1 = 0;
58
+ const nextStyleId = () => `fast-${++id$1}`;
59
+ class StyleElementStrategy {
60
+ constructor(styles) {
61
+ this.styles = styles;
62
+ this.styleClass = nextStyleId();
63
+ }
64
+ addStylesTo(target) {
65
+ target = usableStyleTarget(target);
66
+ const styles = this.styles;
67
+ const styleClass = this.styleClass;
68
+ for (let i = 0; i < styles.length; i++) {
69
+ const element = document.createElement("style");
70
+ element.innerHTML = styles[i];
71
+ element.className = styleClass;
72
+ target.append(element);
73
+ }
74
+ }
75
+ removeStylesFrom(target) {
76
+ const styles = target.querySelectorAll(`.${this.styleClass}`);
77
+ target = usableStyleTarget(target);
78
+ for (let i = 0, ii = styles.length; i < ii; ++i) {
79
+ target.removeChild(styles[i]);
80
+ }
81
+ }
82
+ }
83
+ if (!supportsAdoptedStyleSheets) {
84
+ FAST$2.getById(/* KernelServiceId.styleSheetStrategy */ 5, () => StyleElementStrategy);
85
+ }
86
+
87
+ if (globalThis.FAST === void 0) {
88
+ Reflect.defineProperty(globalThis, "FAST", {
89
+ value: Object.create(null),
90
+ configurable: false,
91
+ enumerable: false,
92
+ writable: false,
93
+ });
94
+ }
95
+ const FAST$1 = globalThis.FAST;
96
+ const debugMessages = {
97
+ [1101 /* needsArrayObservation */]: "Must call enableArrayObservation before observing arrays.",
98
+ [1201 /* onlySetHTMLPolicyOnce */]: "The HTML policy can only be set once.",
99
+ [1202 /* bindingInnerHTMLRequiresTrustedTypes */]: "To bind innerHTML, you must use a TrustedTypesPolicy.",
100
+ [1203 /* twoWayBindingRequiresObservables */]: "View=>Model update skipped. To use twoWay binding, the target property must be observable.",
101
+ [1401 /* missingElementDefinition */]: "Missing FASTElement definition.",
102
+ };
103
+ Object.assign(FAST$1, {
104
+ addMessages(messages) {
105
+ Object.assign(debugMessages, messages);
106
+ },
107
+ warn(code, ...args) {
108
+ var _a;
109
+ console.warn((_a = debugMessages[code]) !== null && _a !== void 0 ? _a : "Unknown Warning");
110
+ },
111
+ error(code, ...args) {
112
+ var _a;
113
+ return new Error((_a = debugMessages[code]) !== null && _a !== void 0 ? _a : "Unknown Error");
114
+ },
115
+ });
116
+
117
+ // ensure FAST global - duplicated in polyfills.ts and debug.ts
118
+ const propConfig = {
119
+ configurable: false,
120
+ enumerable: false,
121
+ writable: false,
122
+ };
123
+ if (globalThis.FAST === void 0) {
124
+ Reflect.defineProperty(globalThis, "FAST", Object.assign({ value: Object.create(null) }, propConfig));
125
+ }
126
+ /**
127
+ * The FAST global.
128
+ * @internal
129
+ */
130
+ const FAST = globalThis.FAST;
131
+ if (FAST.getById === void 0) {
132
+ const storage = Object.create(null);
133
+ Reflect.defineProperty(FAST, "getById", Object.assign({ value(id, initialize) {
134
+ let found = storage[id];
135
+ if (found === void 0) {
136
+ found = initialize ? (storage[id] = initialize()) : null;
137
+ }
138
+ return found;
139
+ } }, propConfig));
140
+ }
141
+ if (FAST.error === void 0) {
142
+ Object.assign(FAST, {
143
+ warn() { },
144
+ error(code) {
145
+ return new Error(`Code ${code}`);
146
+ },
147
+ addMessages() { },
148
+ });
149
+ }
150
+ /**
151
+ * A readonly, empty array.
152
+ * @remarks
153
+ * Typically returned by APIs that return arrays when there are
154
+ * no actual items to return.
155
+ * @public
156
+ */
157
+ const emptyArray = Object.freeze([]);
158
+ /**
159
+ * Do not change. Part of shared kernel contract.
160
+ * @internal
161
+ */
162
+ function createTypeRegistry() {
163
+ const typeToDefinition = new Map();
164
+ return Object.freeze({
165
+ register(definition) {
166
+ if (typeToDefinition.has(definition.type)) {
167
+ return false;
168
+ }
169
+ typeToDefinition.set(definition.type, definition);
170
+ return true;
171
+ },
172
+ getByType(key) {
173
+ return typeToDefinition.get(key);
174
+ },
175
+ getForInstance(object) {
176
+ return typeToDefinition.get(object.constructor);
177
+ },
178
+ });
179
+ }
180
+
181
+ /**
182
+ * @internal
183
+ */
184
+ const isFunction = (object) => typeof object === "function";
185
+ /**
186
+ * @internal
187
+ */
188
+ const isString = (object) => typeof object === "string";
189
+
190
+ /**
191
+ * The default UpdateQueue.
192
+ * @public
193
+ */
194
+ const Updates = FAST.getById(1 /* KernelServiceId.updateQueue */, () => {
195
+ const tasks = [];
196
+ const pendingErrors = [];
197
+ const rAF = globalThis.requestAnimationFrame;
198
+ let updateAsync = true;
199
+ function throwFirstError() {
200
+ if (pendingErrors.length) {
201
+ throw pendingErrors.shift();
202
+ }
203
+ }
204
+ function tryRunTask(task) {
205
+ try {
206
+ task.call();
207
+ }
208
+ catch (error) {
209
+ if (updateAsync) {
210
+ pendingErrors.push(error);
211
+ setTimeout(throwFirstError, 0);
212
+ }
213
+ else {
214
+ tasks.length = 0;
215
+ throw error;
216
+ }
217
+ }
218
+ }
219
+ function process() {
220
+ const capacity = 1024;
221
+ let index = 0;
222
+ while (index < tasks.length) {
223
+ tryRunTask(tasks[index]);
224
+ index++;
225
+ // Prevent leaking memory for long chains of recursive calls to `enqueue`.
226
+ // If we call `enqueue` within a task scheduled by `enqueue`, the queue will
227
+ // grow, but to avoid an O(n) walk for every task we execute, we don't
228
+ // shift tasks off the queue after they have been executed.
229
+ // Instead, we periodically shift 1024 tasks off the queue.
230
+ if (index > capacity) {
231
+ // Manually shift all values starting at the index back to the
232
+ // beginning of the queue.
233
+ for (let scan = 0, newLength = tasks.length - index; scan < newLength; scan++) {
234
+ tasks[scan] = tasks[scan + index];
235
+ }
236
+ tasks.length -= index;
237
+ index = 0;
238
+ }
239
+ }
240
+ tasks.length = 0;
241
+ }
242
+ function enqueue(callable) {
243
+ tasks.push(callable);
244
+ if (tasks.length < 2) {
245
+ updateAsync ? rAF(process) : process();
246
+ }
247
+ }
248
+ return Object.freeze({
249
+ enqueue,
250
+ next: () => new Promise(enqueue),
251
+ process,
252
+ setMode: (isAsync) => (updateAsync = isAsync),
253
+ });
254
+ });
255
+
256
+ /**
257
+ * An implementation of {@link Notifier} that efficiently keeps track of
258
+ * subscribers interested in a specific change notification on an
259
+ * observable subject.
260
+ *
261
+ * @remarks
262
+ * This set is optimized for the most common scenario of 1 or 2 subscribers.
263
+ * With this in mind, it can store a subscriber in an internal field, allowing it to avoid Array#push operations.
264
+ * If the set ever exceeds two subscribers, it upgrades to an array automatically.
265
+ * @public
266
+ */
267
+ class SubscriberSet {
268
+ /**
269
+ * Creates an instance of SubscriberSet for the specified subject.
270
+ * @param subject - The subject that subscribers will receive notifications from.
271
+ * @param initialSubscriber - An initial subscriber to changes.
272
+ */
273
+ constructor(subject, initialSubscriber) {
274
+ this.sub1 = void 0;
275
+ this.sub2 = void 0;
276
+ this.spillover = void 0;
277
+ this.subject = subject;
278
+ this.sub1 = initialSubscriber;
279
+ }
280
+ /**
281
+ * Checks whether the provided subscriber has been added to this set.
282
+ * @param subscriber - The subscriber to test for inclusion in this set.
283
+ */
284
+ has(subscriber) {
285
+ return this.spillover === void 0
286
+ ? this.sub1 === subscriber || this.sub2 === subscriber
287
+ : this.spillover.indexOf(subscriber) !== -1;
288
+ }
289
+ /**
290
+ * Subscribes to notification of changes in an object's state.
291
+ * @param subscriber - The object that is subscribing for change notification.
292
+ */
293
+ subscribe(subscriber) {
294
+ const spillover = this.spillover;
295
+ if (spillover === void 0) {
296
+ if (this.has(subscriber)) {
297
+ return;
298
+ }
299
+ if (this.sub1 === void 0) {
300
+ this.sub1 = subscriber;
301
+ return;
302
+ }
303
+ if (this.sub2 === void 0) {
304
+ this.sub2 = subscriber;
305
+ return;
306
+ }
307
+ this.spillover = [this.sub1, this.sub2, subscriber];
308
+ this.sub1 = void 0;
309
+ this.sub2 = void 0;
310
+ }
311
+ else {
312
+ const index = spillover.indexOf(subscriber);
313
+ if (index === -1) {
314
+ spillover.push(subscriber);
315
+ }
316
+ }
317
+ }
318
+ /**
319
+ * Unsubscribes from notification of changes in an object's state.
320
+ * @param subscriber - The object that is unsubscribing from change notification.
321
+ */
322
+ unsubscribe(subscriber) {
323
+ const spillover = this.spillover;
324
+ if (spillover === void 0) {
325
+ if (this.sub1 === subscriber) {
326
+ this.sub1 = void 0;
327
+ }
328
+ else if (this.sub2 === subscriber) {
329
+ this.sub2 = void 0;
330
+ }
331
+ }
332
+ else {
333
+ const index = spillover.indexOf(subscriber);
334
+ if (index !== -1) {
335
+ spillover.splice(index, 1);
336
+ }
337
+ }
338
+ }
339
+ /**
340
+ * Notifies all subscribers.
341
+ * @param args - Data passed along to subscribers during notification.
342
+ */
343
+ notify(args) {
344
+ const spillover = this.spillover;
345
+ const subject = this.subject;
346
+ if (spillover === void 0) {
347
+ const sub1 = this.sub1;
348
+ const sub2 = this.sub2;
349
+ if (sub1 !== void 0) {
350
+ sub1.handleChange(subject, args);
351
+ }
352
+ if (sub2 !== void 0) {
353
+ sub2.handleChange(subject, args);
354
+ }
355
+ }
356
+ else {
357
+ for (let i = 0, ii = spillover.length; i < ii; ++i) {
358
+ spillover[i].handleChange(subject, args);
359
+ }
360
+ }
361
+ }
362
+ }
363
+ /**
364
+ * An implementation of Notifier that allows subscribers to be notified
365
+ * of individual property changes on an object.
366
+ * @public
367
+ */
368
+ class PropertyChangeNotifier {
369
+ /**
370
+ * Creates an instance of PropertyChangeNotifier for the specified subject.
371
+ * @param subject - The object that subscribers will receive notifications for.
372
+ */
373
+ constructor(subject) {
374
+ this.subscribers = {};
375
+ this.subjectSubscribers = null;
376
+ this.subject = subject;
377
+ }
378
+ /**
379
+ * Notifies all subscribers, based on the specified property.
380
+ * @param propertyName - The property name, passed along to subscribers during notification.
381
+ */
382
+ notify(propertyName) {
383
+ var _a, _b;
384
+ (_a = this.subscribers[propertyName]) === null || _a === void 0 ? void 0 : _a.notify(propertyName);
385
+ (_b = this.subjectSubscribers) === null || _b === void 0 ? void 0 : _b.notify(propertyName);
386
+ }
387
+ /**
388
+ * Subscribes to notification of changes in an object's state.
389
+ * @param subscriber - The object that is subscribing for change notification.
390
+ * @param propertyToWatch - The name of the property that the subscriber is interested in watching for changes.
391
+ */
392
+ subscribe(subscriber, propertyToWatch) {
393
+ var _a, _b;
394
+ let subscribers;
395
+ if (propertyToWatch) {
396
+ subscribers =
397
+ (_a = this.subscribers[propertyToWatch]) !== null && _a !== void 0 ? _a : (this.subscribers[propertyToWatch] = new SubscriberSet(this.subject));
398
+ }
399
+ else {
400
+ subscribers =
401
+ (_b = this.subjectSubscribers) !== null && _b !== void 0 ? _b : (this.subjectSubscribers = new SubscriberSet(this.subject));
402
+ }
403
+ subscribers.subscribe(subscriber);
404
+ }
405
+ /**
406
+ * Unsubscribes from notification of changes in an object's state.
407
+ * @param subscriber - The object that is unsubscribing from change notification.
408
+ * @param propertyToUnwatch - The name of the property that the subscriber is no longer interested in watching.
409
+ */
410
+ unsubscribe(subscriber, propertyToUnwatch) {
411
+ var _a, _b;
412
+ if (propertyToUnwatch) {
413
+ (_a = this.subscribers[propertyToUnwatch]) === null || _a === void 0 ? void 0 : _a.unsubscribe(subscriber);
414
+ }
415
+ else {
416
+ (_b = this.subjectSubscribers) === null || _b === void 0 ? void 0 : _b.unsubscribe(subscriber);
417
+ }
418
+ }
419
+ }
420
+
421
+ /**
422
+ * Common Observable APIs.
423
+ * @public
424
+ */
425
+ const Observable = FAST.getById(2 /* KernelServiceId.observable */, () => {
426
+ const queueUpdate = Updates.enqueue;
427
+ const volatileRegex = /(:|&&|\|\||if)/;
428
+ const notifierLookup = new WeakMap();
429
+ const accessorLookup = new WeakMap();
430
+ let watcher = void 0;
431
+ let createArrayObserver = (array) => {
432
+ throw FAST.error(1101 /* Message.needsArrayObservation */);
433
+ };
434
+ function getNotifier(source) {
435
+ var _a;
436
+ let found = (_a = source.$fastController) !== null && _a !== void 0 ? _a : notifierLookup.get(source);
437
+ if (found === void 0) {
438
+ Array.isArray(source)
439
+ ? (found = createArrayObserver(source))
440
+ : notifierLookup.set(source, (found = new PropertyChangeNotifier(source)));
441
+ }
442
+ return found;
443
+ }
444
+ function getAccessors(target) {
445
+ let accessors = accessorLookup.get(target);
446
+ if (accessors === void 0) {
447
+ let currentTarget = Reflect.getPrototypeOf(target);
448
+ while (accessors === void 0 && currentTarget !== null) {
449
+ accessors = accessorLookup.get(currentTarget);
450
+ currentTarget = Reflect.getPrototypeOf(currentTarget);
451
+ }
452
+ accessors = accessors === void 0 ? [] : accessors.slice(0);
453
+ accessorLookup.set(target, accessors);
454
+ }
455
+ return accessors;
456
+ }
457
+ class DefaultObservableAccessor {
458
+ constructor(name) {
459
+ this.name = name;
460
+ this.field = `_${name}`;
461
+ this.callback = `${name}Changed`;
462
+ }
463
+ getValue(source) {
464
+ if (watcher !== void 0) {
465
+ watcher.watch(source, this.name);
466
+ }
467
+ return source[this.field];
468
+ }
469
+ setValue(source, newValue) {
470
+ const field = this.field;
471
+ const oldValue = source[field];
472
+ if (oldValue !== newValue) {
473
+ source[field] = newValue;
474
+ const callback = source[this.callback];
475
+ if (isFunction(callback)) {
476
+ callback.call(source, oldValue, newValue);
477
+ }
478
+ getNotifier(source).notify(this.name);
479
+ }
480
+ }
481
+ }
482
+ class BindingObserverImplementation extends SubscriberSet {
483
+ constructor(binding, initialSubscriber, isVolatileBinding = false) {
484
+ super(binding, initialSubscriber);
485
+ this.binding = binding;
486
+ this.isVolatileBinding = isVolatileBinding;
487
+ this.needsRefresh = true;
488
+ this.needsQueue = true;
489
+ this.isAsync = true;
490
+ this.first = this;
491
+ this.last = null;
492
+ this.propertySource = void 0;
493
+ this.propertyName = void 0;
494
+ this.notifier = void 0;
495
+ this.next = void 0;
496
+ }
497
+ setMode(isAsync) {
498
+ this.isAsync = this.needsQueue = isAsync;
499
+ }
500
+ observe(source, context) {
501
+ if (this.needsRefresh && this.last !== null) {
502
+ this.dispose();
503
+ }
504
+ const previousWatcher = watcher;
505
+ watcher = this.needsRefresh ? this : void 0;
506
+ this.needsRefresh = this.isVolatileBinding;
507
+ const result = this.binding(source, context !== null && context !== void 0 ? context : ExecutionContext.default);
508
+ watcher = previousWatcher;
509
+ return result;
510
+ }
511
+ dispose() {
512
+ if (this.last !== null) {
513
+ let current = this.first;
514
+ while (current !== void 0) {
515
+ current.notifier.unsubscribe(this, current.propertyName);
516
+ current = current.next;
517
+ }
518
+ this.last = null;
519
+ this.needsRefresh = this.needsQueue = this.isAsync;
520
+ }
521
+ }
522
+ watch(propertySource, propertyName) {
523
+ const prev = this.last;
524
+ const notifier = getNotifier(propertySource);
525
+ const current = prev === null ? this.first : {};
526
+ current.propertySource = propertySource;
527
+ current.propertyName = propertyName;
528
+ current.notifier = notifier;
529
+ notifier.subscribe(this, propertyName);
530
+ if (prev !== null) {
531
+ if (!this.needsRefresh) {
532
+ // Declaring the variable prior to assignment below circumvents
533
+ // a bug in Angular's optimization process causing infinite recursion
534
+ // of this watch() method. Details https://github.com/microsoft/fast/issues/4969
535
+ let prevValue;
536
+ watcher = void 0;
537
+ /* eslint-disable-next-line */
538
+ prevValue = prev.propertySource[prev.propertyName];
539
+ /* eslint-disable-next-line */
540
+ watcher = this;
541
+ if (propertySource === prevValue) {
542
+ this.needsRefresh = true;
543
+ }
544
+ }
545
+ prev.next = current;
546
+ }
547
+ this.last = current;
548
+ }
549
+ handleChange() {
550
+ if (this.needsQueue) {
551
+ this.needsQueue = false;
552
+ queueUpdate(this);
553
+ }
554
+ else if (!this.isAsync) {
555
+ this.call();
556
+ }
557
+ }
558
+ call() {
559
+ if (this.last !== null) {
560
+ this.needsQueue = this.isAsync;
561
+ this.notify(this);
562
+ }
563
+ }
564
+ *records() {
565
+ let next = this.first;
566
+ while (next !== void 0) {
567
+ yield next;
568
+ next = next.next;
569
+ }
570
+ }
571
+ }
572
+ return Object.freeze({
573
+ /**
574
+ * @internal
575
+ * @param factory - The factory used to create array observers.
576
+ */
577
+ setArrayObserverFactory(factory) {
578
+ createArrayObserver = factory;
579
+ },
580
+ /**
581
+ * Gets a notifier for an object or Array.
582
+ * @param source - The object or Array to get the notifier for.
583
+ */
584
+ getNotifier,
585
+ /**
586
+ * Records a property change for a source object.
587
+ * @param source - The object to record the change against.
588
+ * @param propertyName - The property to track as changed.
589
+ */
590
+ track(source, propertyName) {
591
+ watcher && watcher.watch(source, propertyName);
592
+ },
593
+ /**
594
+ * Notifies watchers that the currently executing property getter or function is volatile
595
+ * with respect to its observable dependencies.
596
+ */
597
+ trackVolatile() {
598
+ watcher && (watcher.needsRefresh = true);
599
+ },
600
+ /**
601
+ * Notifies subscribers of a source object of changes.
602
+ * @param source - the object to notify of changes.
603
+ * @param args - The change args to pass to subscribers.
604
+ */
605
+ notify(source, args) {
606
+ /* eslint-disable-next-line @typescript-eslint/no-use-before-define */
607
+ getNotifier(source).notify(args);
608
+ },
609
+ /**
610
+ * Defines an observable property on an object or prototype.
611
+ * @param target - The target object to define the observable on.
612
+ * @param nameOrAccessor - The name of the property to define as observable;
613
+ * or a custom accessor that specifies the property name and accessor implementation.
614
+ */
615
+ defineProperty(target, nameOrAccessor) {
616
+ if (isString(nameOrAccessor)) {
617
+ nameOrAccessor = new DefaultObservableAccessor(nameOrAccessor);
618
+ }
619
+ getAccessors(target).push(nameOrAccessor);
620
+ Reflect.defineProperty(target, nameOrAccessor.name, {
621
+ enumerable: true,
622
+ get() {
623
+ return nameOrAccessor.getValue(this);
624
+ },
625
+ set(newValue) {
626
+ nameOrAccessor.setValue(this, newValue);
627
+ },
628
+ });
629
+ },
630
+ /**
631
+ * Finds all the observable accessors defined on the target,
632
+ * including its prototype chain.
633
+ * @param target - The target object to search for accessor on.
634
+ */
635
+ getAccessors,
636
+ /**
637
+ * Creates a {@link BindingObserver} that can watch the
638
+ * provided {@link Binding} for changes.
639
+ * @param binding - The binding to observe.
640
+ * @param initialSubscriber - An initial subscriber to changes in the binding value.
641
+ * @param isVolatileBinding - Indicates whether the binding's dependency list must be re-evaluated on every value evaluation.
642
+ */
643
+ binding(binding, initialSubscriber, isVolatileBinding = this.isVolatileBinding(binding)) {
644
+ return new BindingObserverImplementation(binding, initialSubscriber, isVolatileBinding);
645
+ },
646
+ /**
647
+ * Determines whether a binding expression is volatile and needs to have its dependency list re-evaluated
648
+ * on every evaluation of the value.
649
+ * @param binding - The binding to inspect.
650
+ */
651
+ isVolatileBinding(binding) {
652
+ return volatileRegex.test(binding.toString());
653
+ },
654
+ });
655
+ });
656
+ /**
657
+ * Decorator: Defines an observable property on the target.
658
+ * @param target - The target to define the observable on.
659
+ * @param nameOrAccessor - The property name or accessor to define the observable as.
660
+ * @public
661
+ */
662
+ function observable(target, nameOrAccessor) {
663
+ Observable.defineProperty(target, nameOrAccessor);
664
+ }
665
+ /**
666
+ * Decorator: Marks a property getter as having volatile observable dependencies.
667
+ * @param target - The target that the property is defined on.
668
+ * @param name - The property name.
669
+ * @param name - The existing descriptor.
670
+ * @public
671
+ */
672
+ function volatile(target, name, descriptor) {
673
+ return Object.assign({}, descriptor, {
674
+ get() {
675
+ Observable.trackVolatile();
676
+ return descriptor.get.apply(this);
677
+ },
678
+ });
679
+ }
680
+ const contextEvent = FAST.getById(3 /* KernelServiceId.contextEvent */, () => {
681
+ let current = null;
682
+ return {
683
+ get() {
684
+ return current;
685
+ },
686
+ set(event) {
687
+ current = event;
688
+ },
689
+ };
690
+ });
691
+ /**
692
+ * Provides additional contextual information available to behaviors and expressions.
693
+ * @public
694
+ */
695
+ class ExecutionContext {
696
+ constructor(parentSource = null, parentContext = null) {
697
+ /**
698
+ * The index of the current item within a repeat context.
699
+ */
700
+ this.index = 0;
701
+ /**
702
+ * The length of the current collection within a repeat context.
703
+ */
704
+ this.length = 0;
705
+ this.parent = parentSource;
706
+ this.parentContext = parentContext;
707
+ }
708
+ /**
709
+ * The current event within an event handler.
710
+ */
711
+ get event() {
712
+ return contextEvent.get();
713
+ }
714
+ /**
715
+ * Indicates whether the current item within a repeat context
716
+ * has an even index.
717
+ */
718
+ get isEven() {
719
+ return this.index % 2 === 0;
720
+ }
721
+ /**
722
+ * Indicates whether the current item within a repeat context
723
+ * has an odd index.
724
+ */
725
+ get isOdd() {
726
+ return this.index % 2 !== 0;
727
+ }
728
+ /**
729
+ * Indicates whether the current item within a repeat context
730
+ * is the first item in the collection.
731
+ */
732
+ get isFirst() {
733
+ return this.index === 0;
734
+ }
735
+ /**
736
+ * Indicates whether the current item within a repeat context
737
+ * is somewhere in the middle of the collection.
738
+ */
739
+ get isInMiddle() {
740
+ return !this.isFirst && !this.isLast;
741
+ }
742
+ /**
743
+ * Indicates whether the current item within a repeat context
744
+ * is the last item in the collection.
745
+ */
746
+ get isLast() {
747
+ return this.index === this.length - 1;
748
+ }
749
+ /**
750
+ * Returns the typed event detail of a custom event.
751
+ */
752
+ eventDetail() {
753
+ return this.event.detail;
754
+ }
755
+ /**
756
+ * Returns the typed event target of the event.
757
+ */
758
+ eventTarget() {
759
+ return this.event.target;
760
+ }
761
+ /**
762
+ * Updates the position/size on a context associated with a list item.
763
+ * @param index - The new index of the item.
764
+ * @param length - The new length of the list.
765
+ */
766
+ updatePosition(index, length) {
767
+ this.index = index;
768
+ this.length = length;
769
+ }
770
+ /**
771
+ * Creates a new execution context descendent from the current context.
772
+ * @param source - The source for the context if different than the parent.
773
+ * @returns A child execution context.
774
+ */
775
+ createChildContext(parentSource) {
776
+ return new ExecutionContext(parentSource, this);
777
+ }
778
+ /**
779
+ * Creates a new execution context descent suitable for use in list rendering.
780
+ * @param item - The list item to serve as the source.
781
+ * @param index - The index of the item in the list.
782
+ * @param length - The length of the list.
783
+ */
784
+ createItemContext(index, length) {
785
+ const childContext = Object.create(this);
786
+ childContext.index = index;
787
+ childContext.length = length;
788
+ return childContext;
789
+ }
790
+ /**
791
+ * Sets the event for the current execution context.
792
+ * @param event - The event to set.
793
+ * @internal
794
+ */
795
+ static setEvent(event) {
796
+ contextEvent.set(event);
797
+ }
798
+ /**
799
+ * Creates a new root execution context.
800
+ * @returns A new execution context.
801
+ */
802
+ static create() {
803
+ return new ExecutionContext();
804
+ }
805
+ }
806
+ /**
807
+ * The default execution context.
808
+ */
809
+ ExecutionContext.default = new ExecutionContext();
810
+ Observable.defineProperty(ExecutionContext.prototype, "index");
811
+ Observable.defineProperty(ExecutionContext.prototype, "length");
812
+
813
+ /**
814
+ * A splice map is a representation of how a previous array of items
815
+ * was transformed into a new array of items. Conceptually it is a list of
816
+ * tuples of
817
+ *
818
+ * (index, removed, addedCount)
819
+ *
820
+ * which are kept in ascending index order of. The tuple represents that at
821
+ * the |index|, |removed| sequence of items were removed, and counting forward
822
+ * from |index|, |addedCount| items were added.
823
+ * @public
824
+ */
825
+ class Splice {
826
+ /**
827
+ * Creates a splice.
828
+ * @param index - The index that the splice occurs at.
829
+ * @param removed - The items that were removed.
830
+ * @param addedCount - The number of items that were added.
831
+ */
832
+ constructor(index, removed, addedCount) {
833
+ this.index = index;
834
+ this.removed = removed;
835
+ this.addedCount = addedCount;
836
+ }
837
+ /**
838
+ * Adjusts the splice index based on the provided array.
839
+ * @param array - The array to adjust to.
840
+ * @returns The same splice, mutated based on the reference array.
841
+ */
842
+ adjustTo(array) {
843
+ let index = this.index;
844
+ const arrayLength = array.length;
845
+ if (index > arrayLength) {
846
+ index = arrayLength - this.addedCount;
847
+ }
848
+ else if (index < 0) {
849
+ index = arrayLength + this.removed.length + index - this.addedCount;
850
+ }
851
+ this.index = index < 0 ? 0 : index;
852
+ return this;
853
+ }
854
+ }
855
+ /**
856
+ * Indicates what level of feature support the splice
857
+ * strategy provides.
858
+ * @public
859
+ */
860
+ const SpliceStrategySupport = Object.freeze({
861
+ /**
862
+ * Only supports resets.
863
+ */
864
+ reset: 1,
865
+ /**
866
+ * Supports tracking splices and resets.
867
+ */
868
+ splice: 2,
869
+ /**
870
+ * Supports tracking splices and resets, while applying some form
871
+ * of optimization, such as merging, to the splices.
872
+ */
873
+ optimized: 3,
874
+ });
875
+ const reset = new Splice(0, emptyArray, 0);
876
+ reset.reset = true;
877
+ const resetSplices = [reset];
878
+ let defaultSpliceStrategy = Object.freeze({
879
+ support: SpliceStrategySupport.splice,
880
+ normalize(previous, current, changes) {
881
+ return previous === void 0 ? changes !== null && changes !== void 0 ? changes : emptyArray : resetSplices;
882
+ },
883
+ pop(array, observer, pop, args) {
884
+ const notEmpty = array.length > 0;
885
+ const result = pop.apply(array, args);
886
+ if (notEmpty) {
887
+ observer.addSplice(new Splice(array.length, [result], 0));
888
+ }
889
+ return result;
890
+ },
891
+ push(array, observer, push, args) {
892
+ const result = push.apply(array, args);
893
+ observer.addSplice(new Splice(array.length - args.length, [], args.length).adjustTo(array));
894
+ return result;
895
+ },
896
+ reverse(array, observer, reverse, args) {
897
+ const result = reverse.apply(array, args);
898
+ observer.reset(array);
899
+ return result;
900
+ },
901
+ shift(array, observer, shift, args) {
902
+ const notEmpty = array.length > 0;
903
+ const result = shift.apply(array, args);
904
+ if (notEmpty) {
905
+ observer.addSplice(new Splice(0, [result], 0));
906
+ }
907
+ return result;
908
+ },
909
+ sort(array, observer, sort, args) {
910
+ const result = sort.apply(array, args);
911
+ observer.reset(array);
912
+ return result;
913
+ },
914
+ splice(array, observer, splice, args) {
915
+ const result = splice.apply(array, args);
916
+ observer.addSplice(new Splice(+args[0], result, args.length > 2 ? args.length - 2 : 0).adjustTo(array));
917
+ return result;
918
+ },
919
+ unshift(array, observer, unshift, args) {
920
+ const result = unshift.apply(array, args);
921
+ observer.addSplice(new Splice(0, [], args.length).adjustTo(array));
922
+ return result;
923
+ },
924
+ });
925
+ /**
926
+ * Functionality related to tracking changes in arrays.
927
+ * @public
928
+ */
929
+ const SpliceStrategy = Object.freeze({
930
+ /**
931
+ * A set of changes that represent a full array reset.
932
+ */
933
+ reset: resetSplices,
934
+ /**
935
+ * Sets the default strategy to use for array observers.
936
+ * @param strategy - The splice strategy to use.
937
+ */
938
+ setDefaultStrategy(strategy) {
939
+ defaultSpliceStrategy = strategy;
940
+ },
941
+ });
942
+ function setNonEnumerable(target, property, value) {
943
+ Reflect.defineProperty(target, property, {
944
+ value,
945
+ enumerable: false,
946
+ });
947
+ }
948
+ class DefaultArrayObserver extends SubscriberSet {
949
+ constructor(subject) {
950
+ super(subject);
951
+ this.oldCollection = void 0;
952
+ this.splices = void 0;
953
+ this.needsQueue = true;
954
+ this._strategy = null;
955
+ this._lengthObserver = void 0;
956
+ this.call = this.flush;
957
+ setNonEnumerable(subject, "$fastController", this);
958
+ }
959
+ get strategy() {
960
+ return this._strategy;
961
+ }
962
+ set strategy(value) {
963
+ this._strategy = value;
964
+ }
965
+ get lengthObserver() {
966
+ let observer = this._lengthObserver;
967
+ if (observer === void 0) {
968
+ const array = this.subject;
969
+ this._lengthObserver = observer = {
970
+ length: array.length,
971
+ handleChange() {
972
+ if (this.length !== array.length) {
973
+ this.length = array.length;
974
+ Observable.notify(observer, "length");
975
+ }
976
+ },
977
+ };
978
+ this.subscribe(observer);
979
+ }
980
+ return observer;
981
+ }
982
+ subscribe(subscriber) {
983
+ this.flush();
984
+ super.subscribe(subscriber);
985
+ }
986
+ addSplice(splice) {
987
+ if (this.splices === void 0) {
988
+ this.splices = [splice];
989
+ }
990
+ else {
991
+ this.splices.push(splice);
992
+ }
993
+ this.enqueue();
994
+ }
995
+ reset(oldCollection) {
996
+ this.oldCollection = oldCollection;
997
+ this.enqueue();
998
+ }
999
+ flush() {
1000
+ var _a;
1001
+ const splices = this.splices;
1002
+ const oldCollection = this.oldCollection;
1003
+ if (splices === void 0 && oldCollection === void 0) {
1004
+ return;
1005
+ }
1006
+ this.needsQueue = true;
1007
+ this.splices = void 0;
1008
+ this.oldCollection = void 0;
1009
+ this.notify(((_a = this._strategy) !== null && _a !== void 0 ? _a : defaultSpliceStrategy).normalize(oldCollection, this.subject, splices));
1010
+ }
1011
+ enqueue() {
1012
+ if (this.needsQueue) {
1013
+ this.needsQueue = false;
1014
+ Updates.enqueue(this);
1015
+ }
1016
+ }
1017
+ }
1018
+ let enabled = false;
1019
+ /**
1020
+ * An observer for arrays.
1021
+ * @public
1022
+ */
1023
+ const ArrayObserver = Object.freeze({
1024
+ /**
1025
+ * Enables the array observation mechanism.
1026
+ * @remarks
1027
+ * Array observation is enabled automatically when using the
1028
+ * {@link RepeatDirective}, so calling this API manually is
1029
+ * not typically necessary.
1030
+ */
1031
+ enable() {
1032
+ if (enabled) {
1033
+ return;
1034
+ }
1035
+ enabled = true;
1036
+ Observable.setArrayObserverFactory((collection) => new DefaultArrayObserver(collection));
1037
+ const proto = Array.prototype;
1038
+ if (!proto.$fastPatch) {
1039
+ setNonEnumerable(proto, "$fastPatch", 1);
1040
+ [
1041
+ proto.pop,
1042
+ proto.push,
1043
+ proto.reverse,
1044
+ proto.shift,
1045
+ proto.sort,
1046
+ proto.splice,
1047
+ proto.unshift,
1048
+ ].forEach(method => {
1049
+ proto[method.name] = function (...args) {
1050
+ var _a;
1051
+ const o = this.$fastController;
1052
+ return o === void 0
1053
+ ? method.apply(this, args)
1054
+ : ((_a = o.strategy) !== null && _a !== void 0 ? _a : defaultSpliceStrategy)[method.name](this, o, method, args);
1055
+ };
1056
+ });
1057
+ }
1058
+ },
1059
+ });
1060
+ /**
1061
+ * Enables observing the length of an array.
1062
+ * @param array - The array to observe the length of.
1063
+ * @returns The length of the array.
1064
+ * @public
1065
+ */
1066
+ function lengthOf(array) {
1067
+ if (!array) {
1068
+ return 0;
1069
+ }
1070
+ let arrayObserver = array.$fastController;
1071
+ if (arrayObserver === void 0) {
1072
+ ArrayObserver.enable();
1073
+ arrayObserver = Observable.getNotifier(array);
1074
+ }
1075
+ Observable.track(arrayObserver.lengthObserver, "length");
1076
+ return array.length;
1077
+ }
1078
+
1079
+ const styleSheetCache = new Map();
1080
+ let DefaultStyleStrategy;
1081
+ function reduceStyles(styles) {
1082
+ return styles
1083
+ .map((x) => x instanceof ElementStyles ? reduceStyles(x.styles) : [x])
1084
+ .reduce((prev, curr) => prev.concat(curr), []);
1085
+ }
1086
+ /**
1087
+ * Represents styles that can be applied to a custom element.
1088
+ * @public
1089
+ */
1090
+ class ElementStyles {
1091
+ /**
1092
+ * Creates an instance of ElementStyles.
1093
+ * @param styles - The styles that will be associated with elements.
1094
+ */
1095
+ constructor(styles) {
1096
+ this.styles = styles;
1097
+ this.targets = new WeakSet();
1098
+ this._strategy = null;
1099
+ this.behaviors = styles
1100
+ .map((x) => x instanceof ElementStyles ? x.behaviors : null)
1101
+ .reduce((prev, curr) => (curr === null ? prev : prev === null ? curr : prev.concat(curr)), null);
1102
+ }
1103
+ /**
1104
+ * Gets the StyleStrategy associated with these element styles.
1105
+ */
1106
+ get strategy() {
1107
+ if (this._strategy === null) {
1108
+ this.withStrategy(DefaultStyleStrategy);
1109
+ }
1110
+ return this._strategy;
1111
+ }
1112
+ /** @internal */
1113
+ addStylesTo(target) {
1114
+ this.strategy.addStylesTo(target);
1115
+ this.targets.add(target);
1116
+ }
1117
+ /** @internal */
1118
+ removeStylesFrom(target) {
1119
+ this.strategy.removeStylesFrom(target);
1120
+ this.targets.delete(target);
1121
+ }
1122
+ /** @internal */
1123
+ isAttachedTo(target) {
1124
+ return this.targets.has(target);
1125
+ }
1126
+ /**
1127
+ * Associates behaviors with this set of styles.
1128
+ * @param behaviors - The behaviors to associate.
1129
+ */
1130
+ withBehaviors(...behaviors) {
1131
+ this.behaviors =
1132
+ this.behaviors === null ? behaviors : this.behaviors.concat(behaviors);
1133
+ return this;
1134
+ }
1135
+ /**
1136
+ * Sets the strategy that handles adding/removing these styles for an element.
1137
+ * @param strategy - The strategy to use.
1138
+ */
1139
+ withStrategy(Strategy) {
1140
+ this._strategy = new Strategy(reduceStyles(this.styles));
1141
+ return this;
1142
+ }
1143
+ /**
1144
+ * Sets the default strategy type to use when creating style strategies.
1145
+ * @param Strategy - The strategy type to construct.
1146
+ */
1147
+ static setDefaultStrategy(Strategy) {
1148
+ DefaultStyleStrategy = Strategy;
1149
+ }
1150
+ }
1151
+ /**
1152
+ * Indicates whether the DOM supports the adoptedStyleSheets feature.
1153
+ */
1154
+ ElementStyles.supportsAdoptedStyleSheets = Array.isArray(document.adoptedStyleSheets) &&
1155
+ "replace" in CSSStyleSheet.prototype;
1156
+ /**
1157
+ * https://wicg.github.io/construct-stylesheets/
1158
+ * https://developers.google.com/web/updates/2019/02/constructable-stylesheets
1159
+ *
1160
+ * @internal
1161
+ */
1162
+ class AdoptedStyleSheetsStrategy {
1163
+ constructor(styles) {
1164
+ this.sheets = styles.map((x) => {
1165
+ if (x instanceof CSSStyleSheet) {
1166
+ return x;
1167
+ }
1168
+ let sheet = styleSheetCache.get(x);
1169
+ if (sheet === void 0) {
1170
+ sheet = new CSSStyleSheet();
1171
+ sheet.replaceSync(x);
1172
+ styleSheetCache.set(x, sheet);
1173
+ }
1174
+ return sheet;
1175
+ });
1176
+ }
1177
+ addStylesTo(target) {
1178
+ target.adoptedStyleSheets = [...target.adoptedStyleSheets, ...this.sheets];
1179
+ }
1180
+ removeStylesFrom(target) {
1181
+ const sheets = this.sheets;
1182
+ target.adoptedStyleSheets = target.adoptedStyleSheets.filter((x) => sheets.indexOf(x) === -1);
1183
+ }
1184
+ }
1185
+ ElementStyles.setDefaultStrategy(FAST.getById(5 /* KernelServiceId.styleSheetStrategy */, () => AdoptedStyleSheetsStrategy));
1186
+
1187
+ const registry$1 = createTypeRegistry();
1188
+ /**
1189
+ * Instructs the css engine to provide dynamic styles or
1190
+ * associate behaviors with styles.
1191
+ * @public
1192
+ */
1193
+ const CSSDirective = Object.freeze({
1194
+ /**
1195
+ * Gets the directive definition associated with the instance.
1196
+ * @param instance - The directive instance to retrieve the definition for.
1197
+ */
1198
+ getForInstance: registry$1.getForInstance,
1199
+ /**
1200
+ * Gets the directive definition associated with the specified type.
1201
+ * @param type - The directive type to retrieve the definition for.
1202
+ */
1203
+ getByType: registry$1.getByType,
1204
+ /**
1205
+ * Defines a CSSDirective.
1206
+ * @param type - The type to define as a directive.
1207
+ */
1208
+ define(type) {
1209
+ registry$1.register({ type });
1210
+ return type;
1211
+ },
1212
+ });
1213
+ /**
1214
+ * Decorator: Defines a CSSDirective.
1215
+ * @public
1216
+ */
1217
+ function cssDirective() {
1218
+ /* eslint-disable-next-line @typescript-eslint/explicit-function-return-type */
1219
+ return function (type) {
1220
+ CSSDirective.define(type);
1221
+ };
1222
+ }
1223
+
1224
+ function collectStyles(strings, values) {
1225
+ const styles = [];
1226
+ let cssString = "";
1227
+ const behaviors = [];
1228
+ const add = (behavior) => {
1229
+ behaviors.push(behavior);
1230
+ };
1231
+ for (let i = 0, ii = strings.length - 1; i < ii; ++i) {
1232
+ cssString += strings[i];
1233
+ let value = values[i];
1234
+ if (CSSDirective.getForInstance(value) !== void 0) {
1235
+ value = value.createCSS(add);
1236
+ }
1237
+ if (value instanceof ElementStyles || value instanceof CSSStyleSheet) {
1238
+ if (cssString.trim() !== "") {
1239
+ styles.push(cssString);
1240
+ cssString = "";
1241
+ }
1242
+ styles.push(value);
1243
+ }
1244
+ else {
1245
+ cssString += value;
1246
+ }
1247
+ }
1248
+ cssString += strings[strings.length - 1];
1249
+ if (cssString.trim() !== "") {
1250
+ styles.push(cssString);
1251
+ }
1252
+ return {
1253
+ styles,
1254
+ behaviors,
1255
+ };
1256
+ }
1257
+ /**
1258
+ * Transforms a template literal string into styles.
1259
+ * @param strings - The string fragments that are interpolated with the values.
1260
+ * @param values - The values that are interpolated with the string fragments.
1261
+ * @remarks
1262
+ * The css helper supports interpolation of strings and ElementStyle instances.
1263
+ * @public
1264
+ */
1265
+ const css = ((strings, ...values) => {
1266
+ const { styles, behaviors } = collectStyles(strings, values);
1267
+ const elementStyles = new ElementStyles(styles);
1268
+ return behaviors.length ? elementStyles.withBehaviors(...behaviors) : elementStyles;
1269
+ });
1270
+ class CSSPartial {
1271
+ constructor(styles, behaviors) {
1272
+ this.behaviors = behaviors;
1273
+ this.css = "";
1274
+ const stylesheets = styles.reduce((accumulated, current) => {
1275
+ if (isString(current)) {
1276
+ this.css += current;
1277
+ }
1278
+ else {
1279
+ accumulated.push(current);
1280
+ }
1281
+ return accumulated;
1282
+ }, []);
1283
+ if (stylesheets.length) {
1284
+ this.styles = new ElementStyles(stylesheets);
1285
+ }
1286
+ }
1287
+ createCSS(add) {
1288
+ this.behaviors.forEach(add);
1289
+ if (this.styles) {
1290
+ add(this);
1291
+ }
1292
+ return this.css;
1293
+ }
1294
+ bind(el) {
1295
+ el.$fastController.addStyles(this.styles);
1296
+ }
1297
+ unbind(el) {
1298
+ el.$fastController.removeStyles(this.styles);
1299
+ }
1300
+ }
1301
+ CSSDirective.define(CSSPartial);
1302
+ css.partial = (strings, ...values) => {
1303
+ const { styles, behaviors } = collectStyles(strings, values);
1304
+ return new CSSPartial(styles, behaviors);
1305
+ };
1306
+ /**
1307
+ * @deprecated Use css.partial instead.
1308
+ * @public
1309
+ */
1310
+ const cssPartial = css.partial;
1311
+
1312
+ /**
1313
+ * Common DOM APIs.
1314
+ * @public
1315
+ */
1316
+ const DOM = Object.freeze({
1317
+ /**
1318
+ * @deprecated
1319
+ * Use Updates.enqueue().
1320
+ */
1321
+ queueUpdate: Updates.enqueue,
1322
+ /**
1323
+ * @deprecated
1324
+ * Use Updates.next()
1325
+ */
1326
+ nextUpdate: Updates.next,
1327
+ /**
1328
+ * @deprecated
1329
+ * Use Updates.process()
1330
+ */
1331
+ processUpdates: Updates.process,
1332
+ /**
1333
+ * Sets an attribute value on an element.
1334
+ * @param element - The element to set the attribute value on.
1335
+ * @param attributeName - The attribute name to set.
1336
+ * @param value - The value of the attribute to set.
1337
+ * @remarks
1338
+ * If the value is `null` or `undefined`, the attribute is removed, otherwise
1339
+ * it is set to the provided value using the standard `setAttribute` API.
1340
+ */
1341
+ setAttribute(element, attributeName, value) {
1342
+ value === null || value === undefined
1343
+ ? element.removeAttribute(attributeName)
1344
+ : element.setAttribute(attributeName, value);
1345
+ },
1346
+ /**
1347
+ * Sets a boolean attribute value.
1348
+ * @param element - The element to set the boolean attribute value on.
1349
+ * @param attributeName - The attribute name to set.
1350
+ * @param value - The value of the attribute to set.
1351
+ * @remarks
1352
+ * If the value is true, the attribute is added; otherwise it is removed.
1353
+ */
1354
+ setBooleanAttribute(element, attributeName, value) {
1355
+ value
1356
+ ? element.setAttribute(attributeName, "")
1357
+ : element.removeAttribute(attributeName);
1358
+ },
1359
+ });
1360
+
1361
+ const marker = `fast-${Math.random().toString(36).substring(2, 8)}`;
1362
+ const interpolationStart = `${marker}{`;
1363
+ const interpolationEnd = `}${marker}`;
1364
+ const interpolationEndLength = interpolationEnd.length;
1365
+ let id = 0;
1366
+ /** @internal */
1367
+ const nextId = () => `${marker}-${++id}`;
1368
+ /**
1369
+ * Common APIs related to markup generation.
1370
+ * @public
1371
+ */
1372
+ const Markup = Object.freeze({
1373
+ /**
1374
+ * Creates a placeholder string suitable for marking out a location *within*
1375
+ * an attribute value or HTML content.
1376
+ * @param index - The directive index to create the placeholder for.
1377
+ * @remarks
1378
+ * Used internally by binding directives.
1379
+ */
1380
+ interpolation: (id) => `${interpolationStart}${id}${interpolationEnd}`,
1381
+ /**
1382
+ * Creates a placeholder that manifests itself as an attribute on an
1383
+ * element.
1384
+ * @param attributeName - The name of the custom attribute.
1385
+ * @param index - The directive index to create the placeholder for.
1386
+ * @remarks
1387
+ * Used internally by attribute directives such as `ref`, `slotted`, and `children`.
1388
+ */
1389
+ attribute: (id) => `${nextId()}="${interpolationStart}${id}${interpolationEnd}"`,
1390
+ /**
1391
+ * Creates a placeholder that manifests itself as a marker within the DOM structure.
1392
+ * @param index - The directive index to create the placeholder for.
1393
+ * @remarks
1394
+ * Used internally by structural directives such as `repeat`.
1395
+ */
1396
+ comment: (id) => `<!--${interpolationStart}${id}${interpolationEnd}-->`,
1397
+ });
1398
+ /**
1399
+ * Common APIs related to content parsing.
1400
+ * @public
1401
+ */
1402
+ const Parser = Object.freeze({
1403
+ /**
1404
+ * Parses text content or HTML attribute content, separating out the static strings
1405
+ * from the directives.
1406
+ * @param value - The content or attribute string to parse.
1407
+ * @param factories - A list of directives to search for in the string.
1408
+ * @returns A heterogeneous array of static strings interspersed with
1409
+ * directives or null if no directives are found in the string.
1410
+ */
1411
+ parse(value, factories) {
1412
+ const parts = value.split(interpolationStart);
1413
+ if (parts.length === 1) {
1414
+ return null;
1415
+ }
1416
+ const result = [];
1417
+ for (let i = 0, ii = parts.length; i < ii; ++i) {
1418
+ const current = parts[i];
1419
+ const index = current.indexOf(interpolationEnd);
1420
+ let literal;
1421
+ if (index === -1) {
1422
+ literal = current;
1423
+ }
1424
+ else {
1425
+ const factoryId = current.substring(0, index);
1426
+ result.push(factories[factoryId]);
1427
+ literal = current.substring(index + interpolationEndLength);
1428
+ }
1429
+ if (literal !== "") {
1430
+ result.push(literal);
1431
+ }
1432
+ }
1433
+ return result;
1434
+ },
1435
+ });
1436
+
1437
+ const registry = createTypeRegistry();
1438
+ /**
1439
+ * Instructs the template engine to apply behavior to a node.
1440
+ * @public
1441
+ */
1442
+ const HTMLDirective = Object.freeze({
1443
+ /**
1444
+ * Gets the directive definition associated with the instance.
1445
+ * @param instance - The directive instance to retrieve the definition for.
1446
+ */
1447
+ getForInstance: registry.getForInstance,
1448
+ /**
1449
+ * Gets the directive definition associated with the specified type.
1450
+ * @param type - The directive type to retrieve the definition for.
1451
+ */
1452
+ getByType: registry.getByType,
1453
+ /**
1454
+ * Defines an HTMLDirective based on the options.
1455
+ * @param type - The type to define as a directive.
1456
+ * @param options - Options that specify the directive's application.
1457
+ */
1458
+ define(type, options) {
1459
+ options = options || {};
1460
+ options.type = type;
1461
+ registry.register(options);
1462
+ return type;
1463
+ },
1464
+ });
1465
+ /**
1466
+ * Decorator: Defines an HTMLDirective.
1467
+ * @param options - Provides options that specify the directive's application.
1468
+ * @public
1469
+ */
1470
+ function htmlDirective(options) {
1471
+ /* eslint-disable-next-line @typescript-eslint/explicit-function-return-type */
1472
+ return function (type) {
1473
+ HTMLDirective.define(type, options);
1474
+ };
1475
+ }
1476
+ /**
1477
+ * The type of HTML aspect to target.
1478
+ * @public
1479
+ */
1480
+ const Aspect = Object.freeze({
1481
+ /**
1482
+ * Not aspected.
1483
+ */
1484
+ none: 0,
1485
+ /**
1486
+ * An attribute.
1487
+ */
1488
+ attribute: 1,
1489
+ /**
1490
+ * A boolean attribute.
1491
+ */
1492
+ booleanAttribute: 2,
1493
+ /**
1494
+ * A property.
1495
+ */
1496
+ property: 3,
1497
+ /**
1498
+ * Content
1499
+ */
1500
+ content: 4,
1501
+ /**
1502
+ * A token list.
1503
+ */
1504
+ tokenList: 5,
1505
+ /**
1506
+ * An event.
1507
+ */
1508
+ event: 6,
1509
+ /**
1510
+ *
1511
+ * @param directive - The directive to assign the aspect to.
1512
+ * @param value - The value to base the aspect determination on.
1513
+ * @remarks
1514
+ * If a falsy value is provided, then the content aspect will be assigned.
1515
+ */
1516
+ assign(directive, value) {
1517
+ if (!value) {
1518
+ directive.aspectType = Aspect.content;
1519
+ return;
1520
+ }
1521
+ directive.sourceAspect = value;
1522
+ switch (value[0]) {
1523
+ case ":":
1524
+ directive.targetAspect = value.substring(1);
1525
+ switch (directive.targetAspect) {
1526
+ case "innerHTML":
1527
+ directive.aspectType = Aspect.property;
1528
+ break;
1529
+ case "classList":
1530
+ directive.aspectType = Aspect.tokenList;
1531
+ break;
1532
+ default:
1533
+ directive.aspectType = Aspect.property;
1534
+ break;
1535
+ }
1536
+ break;
1537
+ case "?":
1538
+ directive.targetAspect = value.substring(1);
1539
+ directive.aspectType = Aspect.booleanAttribute;
1540
+ break;
1541
+ case "@":
1542
+ directive.targetAspect = value.substring(1);
1543
+ directive.aspectType = Aspect.event;
1544
+ break;
1545
+ default:
1546
+ if (value === "class") {
1547
+ directive.targetAspect = "className";
1548
+ directive.aspectType = Aspect.property;
1549
+ }
1550
+ else {
1551
+ directive.targetAspect = value;
1552
+ directive.aspectType = Aspect.attribute;
1553
+ }
1554
+ break;
1555
+ }
1556
+ },
1557
+ });
1558
+ /**
1559
+ * A base class used for attribute directives that don't need internal state.
1560
+ * @public
1561
+ */
1562
+ class StatelessAttachedAttributeDirective {
1563
+ /**
1564
+ * Creates an instance of RefDirective.
1565
+ * @param options - The options to use in configuring the directive.
1566
+ */
1567
+ constructor(options) {
1568
+ this.options = options;
1569
+ }
1570
+ /**
1571
+ * Creates a behavior.
1572
+ * @param targets - The targets available for behaviors to be attached to.
1573
+ */
1574
+ createBehavior(targets) {
1575
+ return this;
1576
+ }
1577
+ /**
1578
+ * Creates a placeholder string based on the directive's index within the template.
1579
+ * @param index - The index of the directive within the template.
1580
+ * @remarks
1581
+ * Creates a custom attribute placeholder.
1582
+ */
1583
+ createHTML(add) {
1584
+ return Markup.attribute(add(this));
1585
+ }
1586
+ }
1587
+
1588
+ const createInnerHTMLBinding = globalThis.TrustedHTML
1589
+ ? (binding) => (s, c) => {
1590
+ const value = binding(s, c);
1591
+ if (value instanceof TrustedHTML) {
1592
+ return value;
1593
+ }
1594
+ throw FAST.error(1202 /* Message.bindingInnerHTMLRequiresTrustedTypes */);
1595
+ }
1596
+ : (binding) => binding;
1597
+ /**
1598
+ * Describes how aspects of an HTML element will be affected by bindings.
1599
+ * @public
1600
+ */
1601
+ const BindingMode = Object.freeze({
1602
+ /**
1603
+ * Creates a binding mode based on the supplied behavior types.
1604
+ * @param UpdateType - The base behavior type used to update aspects.
1605
+ * @param EventType - The base behavior type used to respond to events.
1606
+ * @returns A new binding mode.
1607
+ */
1608
+ define(UpdateType, EventType = EventBinding) {
1609
+ return Object.freeze({
1610
+ [1]: d => new UpdateType(d, DOM.setAttribute),
1611
+ [2]: d => new UpdateType(d, DOM.setBooleanAttribute),
1612
+ [3]: d => new UpdateType(d, (t, a, v) => (t[a] = v)),
1613
+ [4]: d => new (createContentBinding(UpdateType))(d, updateContentTarget),
1614
+ [5]: d => new UpdateType(d, updateTokenListTarget),
1615
+ [6]: d => new EventType(d),
1616
+ });
1617
+ },
1618
+ });
1619
+ /**
1620
+ * Describes the configuration for a binding expression.
1621
+ * @public
1622
+ */
1623
+ const BindingConfig = Object.freeze({
1624
+ /**
1625
+ * Creates a binding configuration based on the provided mode and options.
1626
+ * @param mode - The mode to use for the configuration.
1627
+ * @param defaultOptions - The default options to use for the configuration.
1628
+ * @returns A new binding configuration.
1629
+ */
1630
+ define(mode, defaultOptions) {
1631
+ const config = (options) => {
1632
+ return {
1633
+ mode: config.mode,
1634
+ options: Object.assign({}, defaultOptions, options),
1635
+ };
1636
+ };
1637
+ config.options = defaultOptions;
1638
+ config.mode = mode;
1639
+ return config;
1640
+ },
1641
+ });
1642
+ /**
1643
+ * A base binding behavior for DOM updates.
1644
+ * @public
1645
+ */
1646
+ class UpdateBinding {
1647
+ /**
1648
+ * Creates an instance of UpdateBinding.
1649
+ * @param directive - The directive that has the configuration for this behavior.
1650
+ * @param updateTarget - The function used to update the target with the latest value.
1651
+ */
1652
+ constructor(directive, updateTarget) {
1653
+ this.directive = directive;
1654
+ this.updateTarget = updateTarget;
1655
+ }
1656
+ /**
1657
+ * Bind this behavior to the source.
1658
+ * @param source - The source to bind to.
1659
+ * @param context - The execution context that the binding is operating within.
1660
+ * @param targets - The targets that behaviors in a view can attach to.
1661
+ */
1662
+ bind(source, context, targets) { }
1663
+ /**
1664
+ * Unbinds this behavior from the source.
1665
+ * @param source - The source to unbind from.
1666
+ * @param context - The execution context that the binding is operating within.
1667
+ * @param targets - The targets that behaviors in a view can attach to.
1668
+ */
1669
+ unbind(source, context, targets) { }
1670
+ /**
1671
+ * Creates a behavior.
1672
+ * @param targets - The targets available for behaviors to be attached to.
1673
+ */
1674
+ createBehavior(targets) {
1675
+ return this;
1676
+ }
1677
+ }
1678
+ function createContentBinding(Type) {
1679
+ return class extends Type {
1680
+ unbind(source, context, targets) {
1681
+ super.unbind(source, context, targets);
1682
+ const target = targets[this.directive.nodeId];
1683
+ const view = target.$fastView;
1684
+ if (view !== void 0 && view.isComposed) {
1685
+ view.unbind();
1686
+ view.needsBindOnly = true;
1687
+ }
1688
+ }
1689
+ };
1690
+ }
1691
+ function updateContentTarget(target, aspect, value, source, context) {
1692
+ // If there's no actual value, then this equates to the
1693
+ // empty string for the purposes of content bindings.
1694
+ if (value === null || value === undefined) {
1695
+ value = "";
1696
+ }
1697
+ // If the value has a "create" method, then it's a template-like.
1698
+ if (value.create) {
1699
+ target.textContent = "";
1700
+ let view = target.$fastView;
1701
+ // If there's no previous view that we might be able to
1702
+ // reuse then create a new view from the template.
1703
+ if (view === void 0) {
1704
+ view = value.create();
1705
+ }
1706
+ else {
1707
+ // If there is a previous view, but it wasn't created
1708
+ // from the same template as the new value, then we
1709
+ // need to remove the old view if it's still in the DOM
1710
+ // and create a new view from the template.
1711
+ if (target.$fastTemplate !== value) {
1712
+ if (view.isComposed) {
1713
+ view.remove();
1714
+ view.unbind();
1715
+ }
1716
+ view = value.create();
1717
+ }
1718
+ }
1719
+ // It's possible that the value is the same as the previous template
1720
+ // and that there's actually no need to compose it.
1721
+ if (!view.isComposed) {
1722
+ view.isComposed = true;
1723
+ view.bind(source, context);
1724
+ view.insertBefore(target);
1725
+ target.$fastView = view;
1726
+ target.$fastTemplate = value;
1727
+ }
1728
+ else if (view.needsBindOnly) {
1729
+ view.needsBindOnly = false;
1730
+ view.bind(source, context);
1731
+ }
1732
+ }
1733
+ else {
1734
+ const view = target.$fastView;
1735
+ // If there is a view and it's currently composed into
1736
+ // the DOM, then we need to remove it.
1737
+ if (view !== void 0 && view.isComposed) {
1738
+ view.isComposed = false;
1739
+ view.remove();
1740
+ if (view.needsBindOnly) {
1741
+ view.needsBindOnly = false;
1742
+ }
1743
+ else {
1744
+ view.unbind();
1745
+ }
1746
+ }
1747
+ target.textContent = value;
1748
+ }
1749
+ }
1750
+ function updateTokenListTarget(target, aspect, value) {
1751
+ var _a;
1752
+ const directive = this.directive;
1753
+ const lookup = `${directive.id}-t`;
1754
+ const state = (_a = target[lookup]) !== null && _a !== void 0 ? _a : (target[lookup] = { c: 0, v: Object.create(null) });
1755
+ const versions = state.v;
1756
+ let currentVersion = state.c;
1757
+ const tokenList = target[aspect];
1758
+ // Add the classes, tracking the version at which they were added.
1759
+ if (value !== null && value !== undefined && value.length) {
1760
+ const names = value.split(/\s+/);
1761
+ for (let i = 0, ii = names.length; i < ii; ++i) {
1762
+ const currentName = names[i];
1763
+ if (currentName === "") {
1764
+ continue;
1765
+ }
1766
+ versions[currentName] = currentVersion;
1767
+ tokenList.add(currentName);
1768
+ }
1769
+ }
1770
+ state.v = currentVersion + 1;
1771
+ // If this is the first call to add classes, there's no need to remove old ones.
1772
+ if (currentVersion === 0) {
1773
+ return;
1774
+ }
1775
+ // Remove classes from the previous version.
1776
+ currentVersion -= 1;
1777
+ for (const name in versions) {
1778
+ if (versions[name] === currentVersion) {
1779
+ tokenList.remove(name);
1780
+ }
1781
+ }
1782
+ }
1783
+ /**
1784
+ * A binding behavior for one-time bindings.
1785
+ * @public
1786
+ */
1787
+ class OneTimeBinding extends UpdateBinding {
1788
+ /**
1789
+ * Bind this behavior to the source.
1790
+ * @param source - The source to bind to.
1791
+ * @param context - The execution context that the binding is operating within.
1792
+ * @param targets - The targets that behaviors in a view can attach to.
1793
+ */
1794
+ bind(source, context, targets) {
1795
+ const directive = this.directive;
1796
+ this.updateTarget(targets[directive.nodeId], directive.targetAspect, directive.binding(source, context), source, context);
1797
+ }
1798
+ }
1799
+ /**
1800
+ * A binding behavior for bindings that change.
1801
+ * @public
1802
+ */
1803
+ class ChangeBinding extends UpdateBinding {
1804
+ /**
1805
+ * Creates an instance of ChangeBinding.
1806
+ * @param directive - The directive that has the configuration for this behavior.
1807
+ * @param updateTarget - The function used to update the target with the latest value.
1808
+ */
1809
+ constructor(directive, updateTarget) {
1810
+ super(directive, updateTarget);
1811
+ this.isBindingVolatile = Observable.isVolatileBinding(directive.binding);
1812
+ this.observerProperty = `${directive.id}-o`;
1813
+ }
1814
+ /**
1815
+ * Returns the binding observer used to update the node.
1816
+ * @param target - The target node.
1817
+ * @returns A BindingObserver.
1818
+ */
1819
+ getObserver(target) {
1820
+ var _a;
1821
+ return ((_a = target[this.observerProperty]) !== null && _a !== void 0 ? _a : (target[this.observerProperty] = Observable.binding(this.directive.binding, this, this.isBindingVolatile)));
1822
+ }
1823
+ /**
1824
+ * Bind this behavior to the source.
1825
+ * @param source - The source to bind to.
1826
+ * @param context - The execution context that the binding is operating within.
1827
+ * @param targets - The targets that behaviors in a view can attach to.
1828
+ */
1829
+ bind(source, context, targets) {
1830
+ const directive = this.directive;
1831
+ const target = targets[directive.nodeId];
1832
+ const observer = this.getObserver(target);
1833
+ observer.target = target;
1834
+ observer.source = source;
1835
+ observer.context = context;
1836
+ this.updateTarget(target, directive.targetAspect, observer.observe(source, context), source, context);
1837
+ }
1838
+ /**
1839
+ * Unbinds this behavior from the source.
1840
+ * @param source - The source to unbind from.
1841
+ * @param context - The execution context that the binding is operating within.
1842
+ * @param targets - The targets that behaviors in a view can attach to.
1843
+ */
1844
+ unbind(source, context, targets) {
1845
+ const target = targets[this.directive.nodeId];
1846
+ const observer = this.getObserver(target);
1847
+ observer.dispose();
1848
+ observer.target = null;
1849
+ observer.source = null;
1850
+ observer.context = null;
1851
+ }
1852
+ /** @internal */
1853
+ handleChange(binding, observer) {
1854
+ const target = observer.target;
1855
+ const source = observer.source;
1856
+ const context = observer.context;
1857
+ this.updateTarget(target, this.directive.targetAspect, observer.observe(source, context), source, context);
1858
+ }
1859
+ }
1860
+ /**
1861
+ * A binding behavior for handling events.
1862
+ * @public
1863
+ */
1864
+ class EventBinding {
1865
+ /**
1866
+ * Creates an instance of EventBinding.
1867
+ * @param directive - The directive that has the configuration for this behavior.
1868
+ */
1869
+ constructor(directive) {
1870
+ this.directive = directive;
1871
+ this.sourceProperty = `${directive.id}-s`;
1872
+ this.contextProperty = `${directive.id}-c`;
1873
+ }
1874
+ /**
1875
+ * Bind this behavior to the source.
1876
+ * @param source - The source to bind to.
1877
+ * @param context - The execution context that the binding is operating within.
1878
+ * @param targets - The targets that behaviors in a view can attach to.
1879
+ */
1880
+ bind(source, context, targets) {
1881
+ const directive = this.directive;
1882
+ const target = targets[directive.nodeId];
1883
+ target[this.sourceProperty] = source;
1884
+ target[this.contextProperty] = context;
1885
+ target.addEventListener(directive.targetAspect, this, directive.options);
1886
+ }
1887
+ /**
1888
+ * Unbinds this behavior from the source.
1889
+ * @param source - The source to unbind from.
1890
+ * @param context - The execution context that the binding is operating within.
1891
+ * @param targets - The targets that behaviors in a view can attach to.
1892
+ */
1893
+ unbind(source, context, targets) {
1894
+ const directive = this.directive;
1895
+ const target = targets[directive.nodeId];
1896
+ target[this.sourceProperty] = target[this.contextProperty] = null;
1897
+ target.removeEventListener(directive.targetAspect, this, directive.options);
1898
+ }
1899
+ /**
1900
+ * Creates a behavior.
1901
+ * @param targets - The targets available for behaviors to be attached to.
1902
+ */
1903
+ createBehavior(targets) {
1904
+ return this;
1905
+ }
1906
+ /**
1907
+ * @internal
1908
+ */
1909
+ handleEvent(event) {
1910
+ const target = event.currentTarget;
1911
+ ExecutionContext.setEvent(event);
1912
+ const result = this.directive.binding(target[this.sourceProperty], target[this.contextProperty]);
1913
+ ExecutionContext.setEvent(null);
1914
+ if (result !== true) {
1915
+ event.preventDefault();
1916
+ }
1917
+ }
1918
+ }
1919
+ /**
1920
+ * The default onChange binding configuration.
1921
+ * @public
1922
+ */
1923
+ const onChange = BindingConfig.define(BindingMode.define(ChangeBinding), {});
1924
+ /**
1925
+ * The default onTime binding configuration.
1926
+ * @public
1927
+ */
1928
+ const oneTime = BindingConfig.define(BindingMode.define(OneTimeBinding), {
1929
+ once: true,
1930
+ });
1931
+ /**
1932
+ * A directive that applies bindings.
1933
+ * @public
1934
+ */
1935
+ class HTMLBindingDirective {
1936
+ /**
1937
+ * Creates an instance of HTMLBindingDirective.
1938
+ * @param binding - The binding to apply.
1939
+ * @param mode - The binding mode to use when applying the binding.
1940
+ * @param options - The options to configure the binding with.
1941
+ */
1942
+ constructor(binding, mode, options) {
1943
+ this.binding = binding;
1944
+ this.mode = mode;
1945
+ this.options = options;
1946
+ this.factory = null;
1947
+ /**
1948
+ * The type of aspect to target.
1949
+ */
1950
+ this.aspectType = Aspect.content;
1951
+ }
1952
+ /**
1953
+ * Creates HTML to be used within a template.
1954
+ * @param add - Can be used to add behavior factories to a template.
1955
+ */
1956
+ createHTML(add) {
1957
+ return Markup.interpolation(add(this));
1958
+ }
1959
+ /**
1960
+ * Creates a behavior.
1961
+ * @param targets - The targets available for behaviors to be attached to.
1962
+ */
1963
+ createBehavior(targets) {
1964
+ if (this.factory == null) {
1965
+ if (this.targetAspect === "innerHTML") {
1966
+ this.binding = createInnerHTMLBinding(this.binding);
1967
+ }
1968
+ this.factory = this.mode[this.aspectType](this);
1969
+ }
1970
+ return this.factory.createBehavior(targets);
1971
+ }
1972
+ }
1973
+ HTMLDirective.define(HTMLBindingDirective, { aspected: true });
1974
+ /**
1975
+ * Creates a binding directive with the specified configuration.
1976
+ * @param binding - The binding expression.
1977
+ * @param config - The binding configuration.
1978
+ * @returns A binding directive.
1979
+ * @public
1980
+ */
1981
+ function bind(binding, config = onChange) {
1982
+ if (!("mode" in config)) {
1983
+ config = onChange(config);
1984
+ }
1985
+ return new HTMLBindingDirective(binding, config.mode, config.options);
1986
+ }
1987
+
1988
+ function removeNodeSequence(firstNode, lastNode) {
1989
+ const parent = firstNode.parentNode;
1990
+ let current = firstNode;
1991
+ let next;
1992
+ while (current !== lastNode) {
1993
+ next = current.nextSibling;
1994
+ parent.removeChild(current);
1995
+ current = next;
1996
+ }
1997
+ parent.removeChild(lastNode);
1998
+ }
1999
+ /**
2000
+ * The standard View implementation, which also implements ElementView and SyntheticView.
2001
+ * @public
2002
+ */
2003
+ class HTMLView {
2004
+ /**
2005
+ * Constructs an instance of HTMLView.
2006
+ * @param fragment - The html fragment that contains the nodes for this view.
2007
+ * @param behaviors - The behaviors to be applied to this view.
2008
+ */
2009
+ constructor(fragment, factories, targets) {
2010
+ this.fragment = fragment;
2011
+ this.factories = factories;
2012
+ this.targets = targets;
2013
+ this.behaviors = null;
2014
+ /**
2015
+ * The data that the view is bound to.
2016
+ */
2017
+ this.source = null;
2018
+ /**
2019
+ * The execution context the view is running within.
2020
+ */
2021
+ this.context = null;
2022
+ this.firstChild = fragment.firstChild;
2023
+ this.lastChild = fragment.lastChild;
2024
+ }
2025
+ /**
2026
+ * Appends the view's DOM nodes to the referenced node.
2027
+ * @param node - The parent node to append the view's DOM nodes to.
2028
+ */
2029
+ appendTo(node) {
2030
+ node.appendChild(this.fragment);
2031
+ }
2032
+ /**
2033
+ * Inserts the view's DOM nodes before the referenced node.
2034
+ * @param node - The node to insert the view's DOM before.
2035
+ */
2036
+ insertBefore(node) {
2037
+ if (this.fragment.hasChildNodes()) {
2038
+ node.parentNode.insertBefore(this.fragment, node);
2039
+ }
2040
+ else {
2041
+ const parentNode = node.parentNode;
2042
+ const end = this.lastChild;
2043
+ let current = this.firstChild;
2044
+ let next;
2045
+ while (current !== end) {
2046
+ next = current.nextSibling;
2047
+ parentNode.insertBefore(current, node);
2048
+ current = next;
2049
+ }
2050
+ parentNode.insertBefore(end, node);
2051
+ }
2052
+ }
2053
+ /**
2054
+ * Removes the view's DOM nodes.
2055
+ * The nodes are not disposed and the view can later be re-inserted.
2056
+ */
2057
+ remove() {
2058
+ const fragment = this.fragment;
2059
+ const end = this.lastChild;
2060
+ let current = this.firstChild;
2061
+ let next;
2062
+ while (current !== end) {
2063
+ next = current.nextSibling;
2064
+ fragment.appendChild(current);
2065
+ current = next;
2066
+ }
2067
+ fragment.appendChild(end);
2068
+ }
2069
+ /**
2070
+ * Removes the view and unbinds its behaviors, disposing of DOM nodes afterward.
2071
+ * Once a view has been disposed, it cannot be inserted or bound again.
2072
+ */
2073
+ dispose() {
2074
+ removeNodeSequence(this.firstChild, this.lastChild);
2075
+ this.unbind();
2076
+ }
2077
+ /**
2078
+ * Binds a view's behaviors to its binding source.
2079
+ * @param source - The binding source for the view's binding behaviors.
2080
+ * @param context - The execution context to run the behaviors within.
2081
+ */
2082
+ bind(source, context) {
2083
+ let behaviors = this.behaviors;
2084
+ const oldSource = this.source;
2085
+ if (oldSource === source) {
2086
+ return;
2087
+ }
2088
+ this.source = source;
2089
+ this.context = context;
2090
+ const targets = this.targets;
2091
+ if (oldSource !== null) {
2092
+ for (let i = 0, ii = behaviors.length; i < ii; ++i) {
2093
+ const current = behaviors[i];
2094
+ current.unbind(oldSource, context, targets);
2095
+ current.bind(source, context, targets);
2096
+ }
2097
+ }
2098
+ else if (behaviors === null) {
2099
+ this.behaviors = behaviors = new Array(this.factories.length);
2100
+ const factories = this.factories;
2101
+ for (let i = 0, ii = factories.length; i < ii; ++i) {
2102
+ const behavior = factories[i].createBehavior(targets);
2103
+ behavior.bind(source, context, targets);
2104
+ behaviors[i] = behavior;
2105
+ }
2106
+ }
2107
+ else {
2108
+ for (let i = 0, ii = behaviors.length; i < ii; ++i) {
2109
+ behaviors[i].bind(source, context, targets);
2110
+ }
2111
+ }
2112
+ }
2113
+ /**
2114
+ * Unbinds a view's behaviors from its binding source.
2115
+ */
2116
+ unbind() {
2117
+ const oldSource = this.source;
2118
+ if (oldSource === null) {
2119
+ return;
2120
+ }
2121
+ const targets = this.targets;
2122
+ const context = this.context;
2123
+ const behaviors = this.behaviors;
2124
+ for (let i = 0, ii = behaviors.length; i < ii; ++i) {
2125
+ behaviors[i].unbind(oldSource, context, targets);
2126
+ }
2127
+ this.source = null;
2128
+ this.context = null;
2129
+ }
2130
+ /**
2131
+ * Efficiently disposes of a contiguous range of synthetic view instances.
2132
+ * @param views - A contiguous range of views to be disposed.
2133
+ */
2134
+ static disposeContiguousBatch(views) {
2135
+ if (views.length === 0) {
2136
+ return;
2137
+ }
2138
+ removeNodeSequence(views[0].firstChild, views[views.length - 1].lastChild);
2139
+ for (let i = 0, ii = views.length; i < ii; ++i) {
2140
+ views[i].unbind();
2141
+ }
2142
+ }
2143
+ }
2144
+
2145
+ const targetIdFrom = (parentId, nodeIndex) => `${parentId}.${nodeIndex}`;
2146
+ const descriptorCache = {};
2147
+ // used to prevent creating lots of objects just to track node and index while compiling
2148
+ const next = {
2149
+ index: 0,
2150
+ node: null,
2151
+ };
2152
+ class CompilationContext {
2153
+ constructor(fragment, directives) {
2154
+ this.fragment = fragment;
2155
+ this.directives = directives;
2156
+ this.proto = null;
2157
+ this.nodeIds = new Set();
2158
+ this.descriptors = {};
2159
+ this.factories = [];
2160
+ }
2161
+ addFactory(factory, parentId, nodeId, targetIndex) {
2162
+ if (!this.nodeIds.has(nodeId)) {
2163
+ this.nodeIds.add(nodeId);
2164
+ this.addTargetDescriptor(parentId, nodeId, targetIndex);
2165
+ }
2166
+ factory.nodeId = nodeId;
2167
+ this.factories.push(factory);
2168
+ }
2169
+ freeze() {
2170
+ this.proto = Object.create(null, this.descriptors);
2171
+ return this;
2172
+ }
2173
+ addTargetDescriptor(parentId, targetId, targetIndex) {
2174
+ const descriptors = this.descriptors;
2175
+ if (targetId === "r" || // root
2176
+ targetId === "h" || // host
2177
+ descriptors[targetId]) {
2178
+ return;
2179
+ }
2180
+ if (!descriptors[parentId]) {
2181
+ const index = parentId.lastIndexOf(".");
2182
+ const grandparentId = parentId.substring(0, index);
2183
+ const childIndex = parseInt(parentId.substring(index + 1));
2184
+ this.addTargetDescriptor(grandparentId, parentId, childIndex);
2185
+ }
2186
+ let descriptor = descriptorCache[targetId];
2187
+ if (!descriptor) {
2188
+ const field = `_${targetId}`;
2189
+ descriptorCache[targetId] = descriptor = {
2190
+ get() {
2191
+ var _a;
2192
+ return ((_a = this[field]) !== null && _a !== void 0 ? _a : (this[field] = this[parentId].childNodes[targetIndex]));
2193
+ },
2194
+ };
2195
+ }
2196
+ descriptors[targetId] = descriptor;
2197
+ }
2198
+ createView(hostBindingTarget) {
2199
+ const fragment = this.fragment.cloneNode(true);
2200
+ const targets = Object.create(this.proto);
2201
+ targets.r = fragment;
2202
+ targets.h = hostBindingTarget !== null && hostBindingTarget !== void 0 ? hostBindingTarget : fragment;
2203
+ for (const id of this.nodeIds) {
2204
+ targets[id]; // trigger locator
2205
+ }
2206
+ return new HTMLView(fragment, this.factories, targets);
2207
+ }
2208
+ }
2209
+ function compileAttributes(context, parentId, node, nodeId, nodeIndex, includeBasicValues = false) {
2210
+ const attributes = node.attributes;
2211
+ const directives = context.directives;
2212
+ for (let i = 0, ii = attributes.length; i < ii; ++i) {
2213
+ const attr = attributes[i];
2214
+ const attrValue = attr.value;
2215
+ const parseResult = Parser.parse(attrValue, directives);
2216
+ let result = null;
2217
+ if (parseResult === null) {
2218
+ if (includeBasicValues) {
2219
+ result = bind(() => attrValue, oneTime);
2220
+ Aspect.assign(result, attr.name);
2221
+ }
2222
+ }
2223
+ else {
2224
+ /* eslint-disable-next-line @typescript-eslint/no-use-before-define */
2225
+ result = Compiler.aggregate(parseResult);
2226
+ }
2227
+ if (result !== null) {
2228
+ node.removeAttributeNode(attr);
2229
+ i--;
2230
+ ii--;
2231
+ context.addFactory(result, parentId, nodeId, nodeIndex);
2232
+ }
2233
+ }
2234
+ }
2235
+ function compileContent(context, node, parentId, nodeId, nodeIndex) {
2236
+ const parseResult = Parser.parse(node.textContent, context.directives);
2237
+ if (parseResult === null) {
2238
+ next.node = node.nextSibling;
2239
+ next.index = nodeIndex + 1;
2240
+ return next;
2241
+ }
2242
+ let currentNode;
2243
+ let lastNode = (currentNode = node);
2244
+ for (let i = 0, ii = parseResult.length; i < ii; ++i) {
2245
+ const currentPart = parseResult[i];
2246
+ if (i !== 0) {
2247
+ nodeIndex++;
2248
+ nodeId = targetIdFrom(parentId, nodeIndex);
2249
+ currentNode = lastNode.parentNode.insertBefore(document.createTextNode(""), lastNode.nextSibling);
2250
+ }
2251
+ if (isString(currentPart)) {
2252
+ currentNode.textContent = currentPart;
2253
+ }
2254
+ else {
2255
+ currentNode.textContent = " ";
2256
+ Aspect.assign(currentPart);
2257
+ context.addFactory(currentPart, parentId, nodeId, nodeIndex);
2258
+ }
2259
+ lastNode = currentNode;
2260
+ }
2261
+ next.index = nodeIndex + 1;
2262
+ next.node = lastNode.nextSibling;
2263
+ return next;
2264
+ }
2265
+ function compileChildren(context, parent, parentId) {
2266
+ let nodeIndex = 0;
2267
+ let childNode = parent.firstChild;
2268
+ while (childNode) {
2269
+ /* eslint-disable-next-line @typescript-eslint/no-use-before-define */
2270
+ const result = compileNode(context, parentId, childNode, nodeIndex);
2271
+ childNode = result.node;
2272
+ nodeIndex = result.index;
2273
+ }
2274
+ }
2275
+ function compileNode(context, parentId, node, nodeIndex) {
2276
+ const nodeId = targetIdFrom(parentId, nodeIndex);
2277
+ switch (node.nodeType) {
2278
+ case 1: // element node
2279
+ compileAttributes(context, parentId, node, nodeId, nodeIndex);
2280
+ compileChildren(context, node, nodeId);
2281
+ break;
2282
+ case 3: // text node
2283
+ return compileContent(context, node, parentId, nodeId, nodeIndex);
2284
+ case 8: // comment
2285
+ const parts = Parser.parse(node.data, context.directives);
2286
+ if (parts !== null) {
2287
+ context.addFactory(
2288
+ /* eslint-disable-next-line @typescript-eslint/no-use-before-define */
2289
+ Compiler.aggregate(parts), parentId, nodeId, nodeIndex);
2290
+ }
2291
+ break;
2292
+ }
2293
+ next.index = nodeIndex + 1;
2294
+ next.node = node.nextSibling;
2295
+ return next;
2296
+ }
2297
+ function isMarker(node, directives) {
2298
+ return (node &&
2299
+ node.nodeType == 8 &&
2300
+ Parser.parse(node.data, directives) !== null);
2301
+ }
2302
+ const templateTag = "TEMPLATE";
2303
+ const policyOptions = { createHTML: html => html };
2304
+ let htmlPolicy = globalThis.trustedTypes
2305
+ ? globalThis.trustedTypes.createPolicy("fast-html", policyOptions)
2306
+ : policyOptions;
2307
+ const fastHTMLPolicy = htmlPolicy;
2308
+ /**
2309
+ * Common APIs related to compilation.
2310
+ * @public
2311
+ */
2312
+ const Compiler = {
2313
+ /**
2314
+ * Sets the HTML trusted types policy used by the compiler.
2315
+ * @param policy - The policy to set for HTML.
2316
+ * @remarks
2317
+ * This API can only be called once, for security reasons. It should be
2318
+ * called by the application developer at the start of their program.
2319
+ */
2320
+ setHTMLPolicy(policy) {
2321
+ if (htmlPolicy !== fastHTMLPolicy) {
2322
+ throw FAST.error(1201 /* Message.onlySetHTMLPolicyOnce */);
2323
+ }
2324
+ htmlPolicy = policy;
2325
+ },
2326
+ /**
2327
+ * Compiles a template and associated directives into a compilation
2328
+ * result which can be used to create views.
2329
+ * @param html - The html string or template element to compile.
2330
+ * @param directives - The directives referenced by the template.
2331
+ * @remarks
2332
+ * The template that is provided for compilation is altered in-place
2333
+ * and cannot be compiled again. If the original template must be preserved,
2334
+ * it is recommended that you clone the original and pass the clone to this API.
2335
+ * @public
2336
+ */
2337
+ compile(html, directives) {
2338
+ let template;
2339
+ if (isString(html)) {
2340
+ template = document.createElement(templateTag);
2341
+ template.innerHTML = htmlPolicy.createHTML(html);
2342
+ const fec = template.content.firstElementChild;
2343
+ if (fec !== null && fec.tagName === templateTag) {
2344
+ template = fec;
2345
+ }
2346
+ }
2347
+ else {
2348
+ template = html;
2349
+ }
2350
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=1111864
2351
+ const fragment = document.adoptNode(template.content);
2352
+ const context = new CompilationContext(fragment, directives);
2353
+ compileAttributes(context, "", template, /* host */ "h", 0, true);
2354
+ if (
2355
+ // If the first node in a fragment is a marker, that means it's an unstable first node,
2356
+ // because something like a when, repeat, etc. could add nodes before the marker.
2357
+ // To mitigate this, we insert a stable first node. However, if we insert a node,
2358
+ // that will alter the result of the TreeWalker. So, we also need to offset the target index.
2359
+ isMarker(fragment.firstChild, directives) ||
2360
+ // Or if there is only one node and a directive, it means the template's content
2361
+ // is *only* the directive. In that case, HTMLView.dispose() misses any nodes inserted by
2362
+ // the directive. Inserting a new node ensures proper disposal of nodes added by the directive.
2363
+ (fragment.childNodes.length === 1 && Object.keys(directives).length > 0)) {
2364
+ fragment.insertBefore(document.createComment(""), fragment.firstChild);
2365
+ }
2366
+ compileChildren(context, fragment, /* root */ "r");
2367
+ next.node = null; // prevent leaks
2368
+ return context.freeze();
2369
+ },
2370
+ /**
2371
+ * Sets the default compilation strategy that will be used by the ViewTemplate whenever
2372
+ * it needs to compile a view preprocessed with the html template function.
2373
+ * @param strategy - The compilation strategy to use when compiling templates.
2374
+ */
2375
+ setDefaultStrategy(strategy) {
2376
+ this.compile = strategy;
2377
+ },
2378
+ /**
2379
+ * Aggregates an array of strings and directives into a single directive.
2380
+ * @param parts - A heterogeneous array of static strings interspersed with
2381
+ * directives.
2382
+ * @returns A single inline directive that aggregates the behavior of all the parts.
2383
+ */
2384
+ aggregate(parts) {
2385
+ if (parts.length === 1) {
2386
+ return parts[0];
2387
+ }
2388
+ let sourceAspect;
2389
+ const partCount = parts.length;
2390
+ const finalParts = parts.map((x) => {
2391
+ if (isString(x)) {
2392
+ return () => x;
2393
+ }
2394
+ sourceAspect = x.sourceAspect || sourceAspect;
2395
+ return x.binding;
2396
+ });
2397
+ const binding = (scope, context) => {
2398
+ let output = "";
2399
+ for (let i = 0; i < partCount; ++i) {
2400
+ output += finalParts[i](scope, context);
2401
+ }
2402
+ return output;
2403
+ };
2404
+ const directive = bind(binding);
2405
+ Aspect.assign(directive, sourceAspect);
2406
+ return directive;
2407
+ },
2408
+ };
2409
+
2410
+ /**
2411
+ * A template capable of creating HTMLView instances or rendering directly to DOM.
2412
+ * @public
2413
+ */
2414
+ class ViewTemplate {
2415
+ /**
2416
+ * Creates an instance of ViewTemplate.
2417
+ * @param html - The html representing what this template will instantiate, including placeholders for directives.
2418
+ * @param factories - The directives that will be connected to placeholders in the html.
2419
+ */
2420
+ constructor(html, factories) {
2421
+ this.result = null;
2422
+ this.html = html;
2423
+ this.factories = factories;
2424
+ }
2425
+ /**
2426
+ * Creates an HTMLView instance based on this template definition.
2427
+ * @param hostBindingTarget - The element that host behaviors will be bound to.
2428
+ */
2429
+ create(hostBindingTarget) {
2430
+ if (this.result === null) {
2431
+ this.result = Compiler.compile(this.html, this.factories);
2432
+ }
2433
+ return this.result.createView(hostBindingTarget);
2434
+ }
2435
+ /**
2436
+ * Creates an HTMLView from this template, binds it to the source, and then appends it to the host.
2437
+ * @param source - The data source to bind the template to.
2438
+ * @param host - The Element where the template will be rendered.
2439
+ * @param hostBindingTarget - An HTML element to target the host bindings at if different from the
2440
+ * host that the template is being attached to.
2441
+ */
2442
+ render(source, host, hostBindingTarget, context) {
2443
+ const view = this.create(hostBindingTarget !== null && hostBindingTarget !== void 0 ? hostBindingTarget : host);
2444
+ view.bind(source, context !== null && context !== void 0 ? context : ExecutionContext.default);
2445
+ view.appendTo(host);
2446
+ return view;
2447
+ }
2448
+ }
2449
+ // Much thanks to LitHTML for working this out!
2450
+ const lastAttributeNameRegex =
2451
+ /* eslint-disable-next-line no-control-regex */
2452
+ /([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F "'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/;
2453
+ function createAspectedHTML(value, prevString, add) {
2454
+ const match = lastAttributeNameRegex.exec(prevString);
2455
+ if (match !== null) {
2456
+ Aspect.assign(value, match[2]);
2457
+ }
2458
+ return value.createHTML(add);
2459
+ }
2460
+ /**
2461
+ * Transforms a template literal string into a ViewTemplate.
2462
+ * @param strings - The string fragments that are interpolated with the values.
2463
+ * @param values - The values that are interpolated with the string fragments.
2464
+ * @remarks
2465
+ * The html helper supports interpolation of strings, numbers, binding expressions,
2466
+ * other template instances, and Directive instances.
2467
+ * @public
2468
+ */
2469
+ function html(strings, ...values) {
2470
+ let html = "";
2471
+ const factories = Object.create(null);
2472
+ const add = (factory) => {
2473
+ var _a;
2474
+ const id = (_a = factory.id) !== null && _a !== void 0 ? _a : (factory.id = nextId());
2475
+ factories[id] = factory;
2476
+ return id;
2477
+ };
2478
+ for (let i = 0, ii = strings.length - 1; i < ii; ++i) {
2479
+ const currentString = strings[i];
2480
+ const currentValue = values[i];
2481
+ let definition;
2482
+ html += currentString;
2483
+ if (isFunction(currentValue)) {
2484
+ html += createAspectedHTML(bind(currentValue), currentString, add);
2485
+ }
2486
+ else if (isString(currentValue)) {
2487
+ const match = lastAttributeNameRegex.exec(currentString);
2488
+ if (match !== null) {
2489
+ const directive = bind(() => currentValue, oneTime);
2490
+ Aspect.assign(directive, match[2]);
2491
+ html += directive.createHTML(add);
2492
+ }
2493
+ else {
2494
+ html += currentValue;
2495
+ }
2496
+ }
2497
+ else if ((definition = HTMLDirective.getForInstance(currentValue)) === void 0) {
2498
+ html += createAspectedHTML(bind(() => currentValue, oneTime), currentString, add);
2499
+ }
2500
+ else {
2501
+ if (definition.aspected) {
2502
+ html += createAspectedHTML(currentValue, currentString, add);
2503
+ }
2504
+ else {
2505
+ html += currentValue.createHTML(add);
2506
+ }
2507
+ }
2508
+ }
2509
+ return new ViewTemplate(html + strings[strings.length - 1], factories);
2510
+ }
2511
+
2512
+ /**
2513
+ * The runtime behavior for template references.
2514
+ * @public
2515
+ */
2516
+ class RefDirective extends StatelessAttachedAttributeDirective {
2517
+ /**
2518
+ * Bind this behavior to the source.
2519
+ * @param source - The source to bind to.
2520
+ * @param context - The execution context that the binding is operating within.
2521
+ * @param targets - The targets that behaviors in a view can attach to.
2522
+ */
2523
+ bind(source, context, targets) {
2524
+ source[this.options] = targets[this.nodeId];
2525
+ }
2526
+ /**
2527
+ * Unbinds this behavior from the source.
2528
+ * @param source - The source to unbind from.
2529
+ */
2530
+ /* eslint-disable-next-line @typescript-eslint/no-empty-function */
2531
+ unbind() { }
2532
+ }
2533
+ HTMLDirective.define(RefDirective);
2534
+ /**
2535
+ * A directive that observes the updates a property with a reference to the element.
2536
+ * @param propertyName - The name of the property to assign the reference to.
2537
+ * @public
2538
+ */
2539
+ const ref = (propertyName) => new RefDirective(propertyName);
2540
+
2541
+ /**
2542
+ * A directive that enables basic conditional rendering in a template.
2543
+ * @param binding - The condition to test for rendering.
2544
+ * @param templateOrTemplateBinding - The template or a binding that gets
2545
+ * the template to render when the condition is true.
2546
+ * @public
2547
+ */
2548
+ function when(binding, templateOrTemplateBinding) {
2549
+ const getTemplate = isFunction(templateOrTemplateBinding)
2550
+ ? templateOrTemplateBinding
2551
+ : () => templateOrTemplateBinding;
2552
+ return (source, context) => binding(source, context) ? getTemplate(source, context) : null;
2553
+ }
2554
+
2555
+ const defaultRepeatOptions = Object.freeze({
2556
+ positioning: false,
2557
+ recycle: true,
2558
+ });
2559
+ function bindWithoutPositioning(view, items, index, context) {
2560
+ view.bind(items[index], context);
2561
+ }
2562
+ function bindWithPositioning(view, items, index, context) {
2563
+ view.bind(items[index], context.createItemContext(index, items.length));
2564
+ }
2565
+ /**
2566
+ * A behavior that renders a template for each item in an array.
2567
+ * @public
2568
+ */
2569
+ class RepeatBehavior {
2570
+ /**
2571
+ * Creates an instance of RepeatBehavior.
2572
+ * @param location - The location in the DOM to render the repeat.
2573
+ * @param itemsBinding - The array to render.
2574
+ * @param isItemsBindingVolatile - Indicates whether the items binding has volatile dependencies.
2575
+ * @param templateBinding - The template to render for each item.
2576
+ * @param isTemplateBindingVolatile - Indicates whether the template binding has volatile dependencies.
2577
+ * @param options - Options used to turn on special repeat features.
2578
+ */
2579
+ constructor(location, itemsBinding, isItemsBindingVolatile, templateBinding, isTemplateBindingVolatile, options) {
2580
+ this.location = location;
2581
+ this.itemsBinding = itemsBinding;
2582
+ this.templateBinding = templateBinding;
2583
+ this.options = options;
2584
+ this.source = null;
2585
+ this.views = [];
2586
+ this.items = null;
2587
+ this.itemsObserver = null;
2588
+ this.context = void 0;
2589
+ this.childContext = void 0;
2590
+ this.bindView = bindWithoutPositioning;
2591
+ this.itemsBindingObserver = Observable.binding(itemsBinding, this, isItemsBindingVolatile);
2592
+ this.templateBindingObserver = Observable.binding(templateBinding, this, isTemplateBindingVolatile);
2593
+ if (options.positioning) {
2594
+ this.bindView = bindWithPositioning;
2595
+ }
2596
+ }
2597
+ /**
2598
+ * Bind this behavior to the source.
2599
+ * @param source - The source to bind to.
2600
+ * @param context - The execution context that the binding is operating within.
2601
+ */
2602
+ bind(source, context) {
2603
+ this.source = source;
2604
+ this.context = context;
2605
+ this.childContext = context.createChildContext(source);
2606
+ this.items = this.itemsBindingObserver.observe(source, this.context);
2607
+ this.template = this.templateBindingObserver.observe(source, this.context);
2608
+ this.observeItems(true);
2609
+ this.refreshAllViews();
2610
+ }
2611
+ /**
2612
+ * Unbinds this behavior from the source.
2613
+ * @param source - The source to unbind from.
2614
+ */
2615
+ unbind() {
2616
+ this.source = null;
2617
+ this.items = null;
2618
+ if (this.itemsObserver !== null) {
2619
+ this.itemsObserver.unsubscribe(this);
2620
+ }
2621
+ this.unbindAllViews();
2622
+ this.itemsBindingObserver.dispose();
2623
+ this.templateBindingObserver.dispose();
2624
+ }
2625
+ /**
2626
+ * Handles changes in the array, its items, and the repeat template.
2627
+ * @param source - The source of the change.
2628
+ * @param args - The details about what was changed.
2629
+ */
2630
+ handleChange(source, args) {
2631
+ if (source === this.itemsBinding) {
2632
+ this.items = this.itemsBindingObserver.observe(this.source, this.context);
2633
+ this.observeItems();
2634
+ this.refreshAllViews();
2635
+ }
2636
+ else if (source === this.templateBinding) {
2637
+ this.template = this.templateBindingObserver.observe(this.source, this.context);
2638
+ this.refreshAllViews(true);
2639
+ }
2640
+ else if (args[0].reset) {
2641
+ this.refreshAllViews();
2642
+ }
2643
+ else {
2644
+ this.updateViews(args);
2645
+ }
2646
+ }
2647
+ observeItems(force = false) {
2648
+ if (!this.items) {
2649
+ this.items = emptyArray;
2650
+ return;
2651
+ }
2652
+ const oldObserver = this.itemsObserver;
2653
+ const newObserver = (this.itemsObserver = Observable.getNotifier(this.items));
2654
+ const hasNewObserver = oldObserver !== newObserver;
2655
+ if (hasNewObserver && oldObserver !== null) {
2656
+ oldObserver.unsubscribe(this);
2657
+ }
2658
+ if (hasNewObserver || force) {
2659
+ newObserver.subscribe(this);
2660
+ }
2661
+ }
2662
+ updateViews(splices) {
2663
+ const views = this.views;
2664
+ const childContext = this.childContext;
2665
+ const totalRemoved = [];
2666
+ const bindView = this.bindView;
2667
+ let removeDelta = 0;
2668
+ for (let i = 0, ii = splices.length; i < ii; ++i) {
2669
+ const splice = splices[i];
2670
+ const removed = splice.removed;
2671
+ totalRemoved.push(...views.splice(splice.index + removeDelta, removed.length));
2672
+ removeDelta -= splice.addedCount;
2673
+ }
2674
+ const items = this.items;
2675
+ const template = this.template;
2676
+ for (let i = 0, ii = splices.length; i < ii; ++i) {
2677
+ const splice = splices[i];
2678
+ let addIndex = splice.index;
2679
+ const end = addIndex + splice.addedCount;
2680
+ for (; addIndex < end; ++addIndex) {
2681
+ const neighbor = views[addIndex];
2682
+ const location = neighbor ? neighbor.firstChild : this.location;
2683
+ const view = this.options.recycle && totalRemoved.length > 0
2684
+ ? totalRemoved.shift()
2685
+ : template.create();
2686
+ views.splice(addIndex, 0, view);
2687
+ bindView(view, items, addIndex, childContext);
2688
+ view.insertBefore(location);
2689
+ }
2690
+ }
2691
+ for (let i = 0, ii = totalRemoved.length; i < ii; ++i) {
2692
+ totalRemoved[i].dispose();
2693
+ }
2694
+ if (this.options.positioning) {
2695
+ for (let i = 0, ii = views.length; i < ii; ++i) {
2696
+ views[i].context.updatePosition(i, ii);
2697
+ }
2698
+ }
2699
+ }
2700
+ refreshAllViews(templateChanged = false) {
2701
+ const items = this.items;
2702
+ const template = this.template;
2703
+ const location = this.location;
2704
+ const bindView = this.bindView;
2705
+ const childContext = this.childContext;
2706
+ let itemsLength = items.length;
2707
+ let views = this.views;
2708
+ let viewsLength = views.length;
2709
+ if (itemsLength === 0 || templateChanged || !this.options.recycle) {
2710
+ // all views need to be removed
2711
+ HTMLView.disposeContiguousBatch(views);
2712
+ viewsLength = 0;
2713
+ }
2714
+ if (viewsLength === 0) {
2715
+ // all views need to be created
2716
+ this.views = views = new Array(itemsLength);
2717
+ for (let i = 0; i < itemsLength; ++i) {
2718
+ const view = template.create();
2719
+ bindView(view, items, i, childContext);
2720
+ views[i] = view;
2721
+ view.insertBefore(location);
2722
+ }
2723
+ }
2724
+ else {
2725
+ // attempt to reuse existing views with new data
2726
+ let i = 0;
2727
+ for (; i < itemsLength; ++i) {
2728
+ if (i < viewsLength) {
2729
+ const view = views[i];
2730
+ bindView(view, items, i, childContext);
2731
+ }
2732
+ else {
2733
+ const view = template.create();
2734
+ bindView(view, items, i, childContext);
2735
+ views.push(view);
2736
+ view.insertBefore(location);
2737
+ }
2738
+ }
2739
+ const removed = views.splice(i, viewsLength - i);
2740
+ for (i = 0, itemsLength = removed.length; i < itemsLength; ++i) {
2741
+ removed[i].dispose();
2742
+ }
2743
+ }
2744
+ }
2745
+ unbindAllViews() {
2746
+ const views = this.views;
2747
+ for (let i = 0, ii = views.length; i < ii; ++i) {
2748
+ views[i].unbind();
2749
+ }
2750
+ }
2751
+ }
2752
+ /**
2753
+ * A directive that configures list rendering.
2754
+ * @public
2755
+ */
2756
+ class RepeatDirective {
2757
+ /**
2758
+ * Creates an instance of RepeatDirective.
2759
+ * @param itemsBinding - The binding that provides the array to render.
2760
+ * @param templateBinding - The template binding used to obtain a template to render for each item in the array.
2761
+ * @param options - Options used to turn on special repeat features.
2762
+ */
2763
+ constructor(itemsBinding, templateBinding, options) {
2764
+ this.itemsBinding = itemsBinding;
2765
+ this.templateBinding = templateBinding;
2766
+ this.options = options;
2767
+ ArrayObserver.enable();
2768
+ this.isItemsBindingVolatile = Observable.isVolatileBinding(itemsBinding);
2769
+ this.isTemplateBindingVolatile = Observable.isVolatileBinding(templateBinding);
2770
+ }
2771
+ /**
2772
+ * Creates a placeholder string based on the directive's index within the template.
2773
+ * @param index - The index of the directive within the template.
2774
+ */
2775
+ createHTML(add) {
2776
+ return Markup.comment(add(this));
2777
+ }
2778
+ /**
2779
+ * Creates a behavior for the provided target node.
2780
+ * @param target - The node instance to create the behavior for.
2781
+ */
2782
+ createBehavior(targets) {
2783
+ return new RepeatBehavior(targets[this.nodeId], this.itemsBinding, this.isItemsBindingVolatile, this.templateBinding, this.isTemplateBindingVolatile, this.options);
2784
+ }
2785
+ }
2786
+ HTMLDirective.define(RepeatDirective);
2787
+ /**
2788
+ * A directive that enables list rendering.
2789
+ * @param itemsBinding - The array to render.
2790
+ * @param templateOrTemplateBinding - The template or a template binding used obtain a template
2791
+ * to render for each item in the array.
2792
+ * @param options - Options used to turn on special repeat features.
2793
+ * @public
2794
+ */
2795
+ function repeat(itemsBinding, templateOrTemplateBinding, options = defaultRepeatOptions) {
2796
+ const templateBinding = isFunction(templateOrTemplateBinding)
2797
+ ? templateOrTemplateBinding
2798
+ : () => templateOrTemplateBinding;
2799
+ return new RepeatDirective(itemsBinding, templateBinding, options);
2800
+ }
2801
+
2802
+ const selectElements = (value) => value.nodeType === 1;
2803
+ /**
2804
+ * Creates a function that can be used to filter a Node array, selecting only elements.
2805
+ * @param selector - An optional selector to restrict the filter to.
2806
+ * @public
2807
+ */
2808
+ const elements = (selector) => selector
2809
+ ? value => value.nodeType === 1 && value.matches(selector)
2810
+ : selectElements;
2811
+ /**
2812
+ * A base class for node observation.
2813
+ * @public
2814
+ * @remarks
2815
+ * Internally used by the SlottedDirective and the ChildrenDirective.
2816
+ */
2817
+ class NodeObservationDirective extends StatelessAttachedAttributeDirective {
2818
+ constructor() {
2819
+ super(...arguments);
2820
+ this.sourceProperty = `${this.id}-s`;
2821
+ }
2822
+ /**
2823
+ * Bind this behavior to the source.
2824
+ * @param source - The source to bind to.
2825
+ * @param context - The execution context that the binding is operating within.
2826
+ * @param targets - The targets that behaviors in a view can attach to.
2827
+ */
2828
+ bind(source, context, targets) {
2829
+ const target = targets[this.nodeId];
2830
+ target[this.sourceProperty] = source;
2831
+ this.updateTarget(source, this.computeNodes(target));
2832
+ this.observe(target);
2833
+ }
2834
+ /**
2835
+ * Unbinds this behavior from the source.
2836
+ * @param source - The source to unbind from.
2837
+ * @param context - The execution context that the binding is operating within.
2838
+ * @param targets - The targets that behaviors in a view can attach to.
2839
+ */
2840
+ unbind(source, context, targets) {
2841
+ const target = targets[this.nodeId];
2842
+ this.updateTarget(source, emptyArray);
2843
+ this.disconnect(target);
2844
+ target[this.sourceProperty] = null;
2845
+ }
2846
+ /**
2847
+ * Gets the data source for the target.
2848
+ * @param target - The target to get the source for.
2849
+ * @returns The source.
2850
+ */
2851
+ getSource(target) {
2852
+ return target[this.sourceProperty];
2853
+ }
2854
+ /**
2855
+ * Updates the source property with the computed nodes.
2856
+ * @param source - The source object to assign the nodes property to.
2857
+ * @param value - The nodes to assign to the source object property.
2858
+ */
2859
+ updateTarget(source, value) {
2860
+ source[this.options.property] = value;
2861
+ }
2862
+ /**
2863
+ * Computes the set of nodes that should be assigned to the source property.
2864
+ * @param target - The target to compute the nodes for.
2865
+ * @returns The computed nodes.
2866
+ * @remarks
2867
+ * Applies filters if provided.
2868
+ */
2869
+ computeNodes(target) {
2870
+ let nodes = this.getNodes(target);
2871
+ if ("filter" in this.options) {
2872
+ nodes = nodes.filter(this.options.filter);
2873
+ }
2874
+ return nodes;
2875
+ }
2876
+ }
2877
+
2878
+ const slotEvent = "slotchange";
2879
+ /**
2880
+ * The runtime behavior for slotted node observation.
2881
+ * @public
2882
+ */
2883
+ class SlottedDirective extends NodeObservationDirective {
2884
+ /**
2885
+ * Begins observation of the nodes.
2886
+ * @param target - The target to observe.
2887
+ */
2888
+ observe(target) {
2889
+ target.addEventListener(slotEvent, this);
2890
+ }
2891
+ /**
2892
+ * Disconnects observation of the nodes.
2893
+ * @param target - The target to unobserve.
2894
+ */
2895
+ disconnect(target) {
2896
+ target.removeEventListener(slotEvent, this);
2897
+ }
2898
+ /**
2899
+ * Retrieves the raw nodes that should be assigned to the source property.
2900
+ * @param target - The target to get the node to.
2901
+ */
2902
+ getNodes(target) {
2903
+ return target.assignedNodes(this.options);
2904
+ }
2905
+ /** @internal */
2906
+ handleEvent(event) {
2907
+ const target = event.currentTarget;
2908
+ this.updateTarget(this.getSource(target), this.computeNodes(target));
2909
+ }
2910
+ }
2911
+ HTMLDirective.define(SlottedDirective);
2912
+ /**
2913
+ * A directive that observes the `assignedNodes()` of a slot and updates a property
2914
+ * whenever they change.
2915
+ * @param propertyOrOptions - The options used to configure slotted node observation.
2916
+ * @public
2917
+ */
2918
+ function slotted(propertyOrOptions) {
2919
+ if (isString(propertyOrOptions)) {
2920
+ propertyOrOptions = { property: propertyOrOptions };
2921
+ }
2922
+ return new SlottedDirective(propertyOrOptions);
2923
+ }
2924
+
2925
+ /**
2926
+ * The runtime behavior for child node observation.
2927
+ * @public
2928
+ */
2929
+ class ChildrenDirective extends NodeObservationDirective {
2930
+ /**
2931
+ * Creates an instance of ChildrenDirective.
2932
+ * @param options - The options to use in configuring the child observation behavior.
2933
+ */
2934
+ constructor(options) {
2935
+ super(options);
2936
+ this.observerProperty = `${this.id}-o`;
2937
+ this.handleEvent = (mutations, observer) => {
2938
+ const target = observer.target;
2939
+ this.updateTarget(this.getSource(target), this.computeNodes(target));
2940
+ };
2941
+ options.childList = true;
2942
+ }
2943
+ /**
2944
+ * Begins observation of the nodes.
2945
+ * @param target - The target to observe.
2946
+ */
2947
+ observe(target) {
2948
+ var _a;
2949
+ const observer = (_a = target[this.observerProperty]) !== null && _a !== void 0 ? _a : (target[this.observerProperty] = new MutationObserver(this.handleEvent));
2950
+ observer.target = target;
2951
+ observer.observe(target, this.options);
2952
+ }
2953
+ /**
2954
+ * Disconnects observation of the nodes.
2955
+ * @param target - The target to unobserve.
2956
+ */
2957
+ disconnect(target) {
2958
+ const observer = target[this.observerProperty];
2959
+ observer.target = null;
2960
+ observer.disconnect();
2961
+ }
2962
+ /**
2963
+ * Retrieves the raw nodes that should be assigned to the source property.
2964
+ * @param target - The target to get the node to.
2965
+ */
2966
+ getNodes(target) {
2967
+ if ("selector" in this.options) {
2968
+ return Array.from(target.querySelectorAll(this.options.selector));
2969
+ }
2970
+ return Array.from(target.childNodes);
2971
+ }
2972
+ }
2973
+ HTMLDirective.define(ChildrenDirective);
2974
+ /**
2975
+ * A directive that observes the `childNodes` of an element and updates a property
2976
+ * whenever they change.
2977
+ * @param propertyOrOptions - The options used to configure child node observation.
2978
+ * @public
2979
+ */
2980
+ function children(propertyOrOptions) {
2981
+ if (isString(propertyOrOptions)) {
2982
+ propertyOrOptions = {
2983
+ property: propertyOrOptions,
2984
+ };
2985
+ }
2986
+ return new ChildrenDirective(propertyOrOptions);
2987
+ }
2988
+
2989
+ const booleanMode = "boolean";
2990
+ const reflectMode = "reflect";
2991
+ /**
2992
+ * A {@link ValueConverter} that converts to and from `boolean` values.
2993
+ * @remarks
2994
+ * Used automatically when the `boolean` {@link AttributeMode} is selected.
2995
+ * @public
2996
+ */
2997
+ const booleanConverter = {
2998
+ toView(value) {
2999
+ return value ? "true" : "false";
3000
+ },
3001
+ fromView(value) {
3002
+ return value === null ||
3003
+ value === void 0 ||
3004
+ value === "false" ||
3005
+ value === false ||
3006
+ value === 0
3007
+ ? false
3008
+ : true;
3009
+ },
3010
+ };
3011
+ function toNumber(value) {
3012
+ if (value === null || value === undefined) {
3013
+ return null;
3014
+ }
3015
+ const number = value * 1;
3016
+ return isNaN(number) ? null : number;
3017
+ }
3018
+ /**
3019
+ * A {@link ValueConverter} that converts to and from `number` values.
3020
+ * @remarks
3021
+ * This converter allows for nullable numbers, returning `null` if the
3022
+ * input was `null`, `undefined`, or `NaN`.
3023
+ * @public
3024
+ */
3025
+ const nullableNumberConverter = {
3026
+ toView(value) {
3027
+ const output = toNumber(value);
3028
+ return output ? output.toString() : output;
3029
+ },
3030
+ fromView: toNumber,
3031
+ };
3032
+ /**
3033
+ * An implementation of {@link Accessor} that supports reactivity,
3034
+ * change callbacks, attribute reflection, and type conversion for
3035
+ * custom elements.
3036
+ * @public
3037
+ */
3038
+ class AttributeDefinition {
3039
+ /**
3040
+ * Creates an instance of AttributeDefinition.
3041
+ * @param Owner - The class constructor that owns this attribute.
3042
+ * @param name - The name of the property associated with the attribute.
3043
+ * @param attribute - The name of the attribute in HTML.
3044
+ * @param mode - The {@link AttributeMode} that describes the behavior of this attribute.
3045
+ * @param converter - A {@link ValueConverter} that integrates with the property getter/setter
3046
+ * to convert values to and from a DOM string.
3047
+ */
3048
+ constructor(Owner, name, attribute = name.toLowerCase(), mode = reflectMode, converter) {
3049
+ this.guards = new Set();
3050
+ this.Owner = Owner;
3051
+ this.name = name;
3052
+ this.attribute = attribute;
3053
+ this.mode = mode;
3054
+ this.converter = converter;
3055
+ this.fieldName = `_${name}`;
3056
+ this.callbackName = `${name}Changed`;
3057
+ this.hasCallback = this.callbackName in Owner.prototype;
3058
+ if (mode === booleanMode && converter === void 0) {
3059
+ this.converter = booleanConverter;
3060
+ }
3061
+ }
3062
+ /**
3063
+ * Sets the value of the attribute/property on the source element.
3064
+ * @param source - The source element to access.
3065
+ * @param value - The value to set the attribute/property to.
3066
+ */
3067
+ setValue(source, newValue) {
3068
+ const oldValue = source[this.fieldName];
3069
+ const converter = this.converter;
3070
+ if (converter !== void 0) {
3071
+ newValue = converter.fromView(newValue);
3072
+ }
3073
+ if (oldValue !== newValue) {
3074
+ source[this.fieldName] = newValue;
3075
+ this.tryReflectToAttribute(source);
3076
+ if (this.hasCallback) {
3077
+ source[this.callbackName](oldValue, newValue);
3078
+ }
3079
+ source.$fastController.notify(this.name);
3080
+ }
3081
+ }
3082
+ /**
3083
+ * Gets the value of the attribute/property on the source element.
3084
+ * @param source - The source element to access.
3085
+ */
3086
+ getValue(source) {
3087
+ Observable.track(source, this.name);
3088
+ return source[this.fieldName];
3089
+ }
3090
+ /** @internal */
3091
+ onAttributeChangedCallback(element, value) {
3092
+ if (this.guards.has(element)) {
3093
+ return;
3094
+ }
3095
+ this.guards.add(element);
3096
+ this.setValue(element, value);
3097
+ this.guards.delete(element);
3098
+ }
3099
+ tryReflectToAttribute(element) {
3100
+ const mode = this.mode;
3101
+ const guards = this.guards;
3102
+ if (guards.has(element) || mode === "fromView") {
3103
+ return;
3104
+ }
3105
+ Updates.enqueue(() => {
3106
+ guards.add(element);
3107
+ const latestValue = element[this.fieldName];
3108
+ switch (mode) {
3109
+ case reflectMode:
3110
+ const converter = this.converter;
3111
+ DOM.setAttribute(element, this.attribute, converter !== void 0 ? converter.toView(latestValue) : latestValue);
3112
+ break;
3113
+ case booleanMode:
3114
+ DOM.setBooleanAttribute(element, this.attribute, latestValue);
3115
+ break;
3116
+ }
3117
+ guards.delete(element);
3118
+ });
3119
+ }
3120
+ /**
3121
+ * Collects all attribute definitions associated with the owner.
3122
+ * @param Owner - The class constructor to collect attribute for.
3123
+ * @param attributeLists - Any existing attributes to collect and merge with those associated with the owner.
3124
+ * @internal
3125
+ */
3126
+ static collect(Owner, ...attributeLists) {
3127
+ const attributes = [];
3128
+ attributeLists.push(Owner.attributes);
3129
+ for (let i = 0, ii = attributeLists.length; i < ii; ++i) {
3130
+ const list = attributeLists[i];
3131
+ if (list === void 0) {
3132
+ continue;
3133
+ }
3134
+ for (let j = 0, jj = list.length; j < jj; ++j) {
3135
+ const config = list[j];
3136
+ if (isString(config)) {
3137
+ attributes.push(new AttributeDefinition(Owner, config));
3138
+ }
3139
+ else {
3140
+ attributes.push(new AttributeDefinition(Owner, config.property, config.attribute, config.mode, config.converter));
3141
+ }
3142
+ }
3143
+ }
3144
+ return attributes;
3145
+ }
3146
+ }
3147
+ function attr(configOrTarget, prop) {
3148
+ let config;
3149
+ function decorator($target, $prop) {
3150
+ if (arguments.length > 1) {
3151
+ // Non invocation:
3152
+ // - @attr
3153
+ // Invocation with or w/o opts:
3154
+ // - @attr()
3155
+ // - @attr({...opts})
3156
+ config.property = $prop;
3157
+ }
3158
+ const attributes = $target.constructor.attributes ||
3159
+ ($target.constructor.attributes = []);
3160
+ attributes.push(config);
3161
+ }
3162
+ if (arguments.length > 1) {
3163
+ // Non invocation:
3164
+ // - @attr
3165
+ config = {};
3166
+ decorator(configOrTarget, prop);
3167
+ return;
3168
+ }
3169
+ // Invocation with or w/o opts:
3170
+ // - @attr()
3171
+ // - @attr({...opts})
3172
+ config = configOrTarget === void 0 ? {} : configOrTarget;
3173
+ return decorator;
3174
+ }
3175
+
3176
+ const defaultShadowOptions = { mode: "open" };
3177
+ const defaultElementOptions = {};
3178
+ const fastElementRegistry = FAST.getById(4 /* KernelServiceId.elementRegistry */, () => createTypeRegistry());
3179
+ /**
3180
+ * Defines metadata for a FASTElement.
3181
+ * @public
3182
+ */
3183
+ class FASTElementDefinition {
3184
+ /**
3185
+ * Creates an instance of FASTElementDefinition.
3186
+ * @param type - The type this definition is being created for.
3187
+ * @param nameOrConfig - The name of the element to define or a config object
3188
+ * that describes the element to define.
3189
+ */
3190
+ constructor(type, nameOrConfig = type.definition) {
3191
+ if (isString(nameOrConfig)) {
3192
+ nameOrConfig = { name: nameOrConfig };
3193
+ }
3194
+ this.type = type;
3195
+ this.name = nameOrConfig.name;
3196
+ this.template = nameOrConfig.template;
3197
+ const attributes = AttributeDefinition.collect(type, nameOrConfig.attributes);
3198
+ const observedAttributes = new Array(attributes.length);
3199
+ const propertyLookup = {};
3200
+ const attributeLookup = {};
3201
+ for (let i = 0, ii = attributes.length; i < ii; ++i) {
3202
+ const current = attributes[i];
3203
+ observedAttributes[i] = current.attribute;
3204
+ propertyLookup[current.name] = current;
3205
+ attributeLookup[current.attribute] = current;
3206
+ }
3207
+ this.attributes = attributes;
3208
+ this.observedAttributes = observedAttributes;
3209
+ this.propertyLookup = propertyLookup;
3210
+ this.attributeLookup = attributeLookup;
3211
+ this.shadowOptions =
3212
+ nameOrConfig.shadowOptions === void 0
3213
+ ? defaultShadowOptions
3214
+ : nameOrConfig.shadowOptions === null
3215
+ ? void 0
3216
+ : Object.assign(Object.assign({}, defaultShadowOptions), nameOrConfig.shadowOptions);
3217
+ this.elementOptions =
3218
+ nameOrConfig.elementOptions === void 0
3219
+ ? defaultElementOptions
3220
+ : Object.assign(Object.assign({}, defaultElementOptions), nameOrConfig.elementOptions);
3221
+ this.styles =
3222
+ nameOrConfig.styles === void 0
3223
+ ? void 0
3224
+ : Array.isArray(nameOrConfig.styles)
3225
+ ? new ElementStyles(nameOrConfig.styles)
3226
+ : nameOrConfig.styles instanceof ElementStyles
3227
+ ? nameOrConfig.styles
3228
+ : new ElementStyles([nameOrConfig.styles]);
3229
+ }
3230
+ /**
3231
+ * Indicates if this element has been defined in at least one registry.
3232
+ */
3233
+ get isDefined() {
3234
+ return !!fastElementRegistry.getByType(this.type);
3235
+ }
3236
+ /**
3237
+ * Defines a custom element based on this definition.
3238
+ * @param registry - The element registry to define the element in.
3239
+ * @remarks
3240
+ * This operation is idempotent per registry.
3241
+ */
3242
+ define(registry = customElements) {
3243
+ const type = this.type;
3244
+ if (fastElementRegistry.register(this)) {
3245
+ const attributes = this.attributes;
3246
+ const proto = type.prototype;
3247
+ for (let i = 0, ii = attributes.length; i < ii; ++i) {
3248
+ Observable.defineProperty(proto, attributes[i]);
3249
+ }
3250
+ Reflect.defineProperty(type, "observedAttributes", {
3251
+ value: this.observedAttributes,
3252
+ enumerable: true,
3253
+ });
3254
+ }
3255
+ if (!registry.get(this.name)) {
3256
+ registry.define(this.name, type, this.elementOptions);
3257
+ }
3258
+ return this;
3259
+ }
3260
+ }
3261
+ /**
3262
+ * Gets the element definition associated with the specified type.
3263
+ * @param type - The custom element type to retrieve the definition for.
3264
+ */
3265
+ FASTElementDefinition.getByType = fastElementRegistry.getByType;
3266
+ /**
3267
+ * Gets the element definition associated with the instance.
3268
+ * @param instance - The custom element instance to retrieve the definition for.
3269
+ */
3270
+ FASTElementDefinition.getForInstance = fastElementRegistry.getForInstance;
3271
+
3272
+ const shadowRoots = new WeakMap();
3273
+ const defaultEventOptions = {
3274
+ bubbles: true,
3275
+ composed: true,
3276
+ cancelable: true,
3277
+ };
3278
+ function getShadowRoot(element) {
3279
+ var _a, _b;
3280
+ return (_b = (_a = element.shadowRoot) !== null && _a !== void 0 ? _a : shadowRoots.get(element)) !== null && _b !== void 0 ? _b : null;
3281
+ }
3282
+ const isConnectedPropertyName = "isConnected";
3283
+ /**
3284
+ * Controls the lifecycle and rendering of a `FASTElement`.
3285
+ * @public
3286
+ */
3287
+ class Controller extends PropertyChangeNotifier {
3288
+ /**
3289
+ * Creates a Controller to control the specified element.
3290
+ * @param element - The element to be controlled by this controller.
3291
+ * @param definition - The element definition metadata that instructs this
3292
+ * controller in how to handle rendering and other platform integrations.
3293
+ * @internal
3294
+ */
3295
+ constructor(element, definition) {
3296
+ super(element);
3297
+ this.boundObservables = null;
3298
+ this.behaviors = null;
3299
+ this.needsInitialization = true;
3300
+ this.hasExistingShadowRoot = false;
3301
+ this._template = null;
3302
+ this._styles = null;
3303
+ this._isConnected = false;
3304
+ /**
3305
+ * This allows Observable.getNotifier(...) to return the Controller
3306
+ * when the notifier for the Controller itself is being requested. The
3307
+ * result is that the Observable system does not need to create a separate
3308
+ * instance of Notifier for observables on the Controller. The component and
3309
+ * the controller will now share the same notifier, removing one-object construct
3310
+ * per web component instance.
3311
+ */
3312
+ this.$fastController = this;
3313
+ /**
3314
+ * The view associated with the custom element.
3315
+ * @remarks
3316
+ * If `null` then the element is managing its own rendering.
3317
+ */
3318
+ this.view = null;
3319
+ this.element = element;
3320
+ this.definition = definition;
3321
+ const shadowOptions = definition.shadowOptions;
3322
+ if (shadowOptions !== void 0) {
3323
+ let shadowRoot = element.shadowRoot;
3324
+ if (shadowRoot) {
3325
+ this.hasExistingShadowRoot = true;
3326
+ }
3327
+ else {
3328
+ shadowRoot = element.attachShadow(shadowOptions);
3329
+ if (shadowOptions.mode === "closed") {
3330
+ shadowRoots.set(element, shadowRoot);
3331
+ }
3332
+ }
3333
+ }
3334
+ // Capture any observable values that were set by the binding engine before
3335
+ // the browser upgraded the element. Then delete the property since it will
3336
+ // shadow the getter/setter that is required to make the observable operate.
3337
+ // Later, in the connect callback, we'll re-apply the values.
3338
+ const accessors = Observable.getAccessors(element);
3339
+ if (accessors.length > 0) {
3340
+ const boundObservables = (this.boundObservables = Object.create(null));
3341
+ for (let i = 0, ii = accessors.length; i < ii; ++i) {
3342
+ const propertyName = accessors[i].name;
3343
+ const value = element[propertyName];
3344
+ if (value !== void 0) {
3345
+ delete element[propertyName];
3346
+ boundObservables[propertyName] = value;
3347
+ }
3348
+ }
3349
+ }
3350
+ }
3351
+ /**
3352
+ * Indicates whether or not the custom element has been
3353
+ * connected to the document.
3354
+ */
3355
+ get isConnected() {
3356
+ Observable.track(this, isConnectedPropertyName);
3357
+ return this._isConnected;
3358
+ }
3359
+ setIsConnected(value) {
3360
+ this._isConnected = value;
3361
+ Observable.notify(this, isConnectedPropertyName);
3362
+ }
3363
+ /**
3364
+ * Gets/sets the template used to render the component.
3365
+ * @remarks
3366
+ * This value can only be accurately read after connect but can be set at any time.
3367
+ */
3368
+ get template() {
3369
+ var _a;
3370
+ // 1. Template overrides take top precedence.
3371
+ if (this._template === null) {
3372
+ const definition = this.definition;
3373
+ if (this.element.resolveTemplate) {
3374
+ // 2. Allow for element instance overrides next.
3375
+ this._template = this.element.resolveTemplate();
3376
+ }
3377
+ else if (definition.template) {
3378
+ // 3. Default to the static definition.
3379
+ this._template = (_a = definition.template) !== null && _a !== void 0 ? _a : null;
3380
+ }
3381
+ }
3382
+ return this._template;
3383
+ }
3384
+ set template(value) {
3385
+ if (this._template === value) {
3386
+ return;
3387
+ }
3388
+ this._template = value;
3389
+ if (!this.needsInitialization) {
3390
+ this.renderTemplate(value);
3391
+ }
3392
+ }
3393
+ /**
3394
+ * Gets/sets the primary styles used for the component.
3395
+ * @remarks
3396
+ * This value can only be accurately read after connect but can be set at any time.
3397
+ */
3398
+ get styles() {
3399
+ var _a;
3400
+ // 1. Styles overrides take top precedence.
3401
+ if (this._styles === null) {
3402
+ const definition = this.definition;
3403
+ if (this.element.resolveStyles) {
3404
+ // 2. Allow for element instance overrides next.
3405
+ this._styles = this.element.resolveStyles();
3406
+ }
3407
+ else if (definition.styles) {
3408
+ // 3. Default to the static definition.
3409
+ this._styles = (_a = definition.styles) !== null && _a !== void 0 ? _a : null;
3410
+ }
3411
+ }
3412
+ return this._styles;
3413
+ }
3414
+ set styles(value) {
3415
+ if (this._styles === value) {
3416
+ return;
3417
+ }
3418
+ if (this._styles !== null) {
3419
+ this.removeStyles(this._styles);
3420
+ }
3421
+ this._styles = value;
3422
+ if (!this.needsInitialization) {
3423
+ this.addStyles(value);
3424
+ }
3425
+ }
3426
+ /**
3427
+ * Adds styles to this element. Providing an HTMLStyleElement will attach the element instance to the shadowRoot.
3428
+ * @param styles - The styles to add.
3429
+ */
3430
+ addStyles(styles) {
3431
+ if (!styles) {
3432
+ return;
3433
+ }
3434
+ const target = getShadowRoot(this.element) ||
3435
+ this.element.getRootNode();
3436
+ if (styles instanceof HTMLElement) {
3437
+ target.append(styles);
3438
+ }
3439
+ else if (!styles.isAttachedTo(target)) {
3440
+ const sourceBehaviors = styles.behaviors;
3441
+ styles.addStylesTo(target);
3442
+ if (sourceBehaviors !== null) {
3443
+ this.addBehaviors(sourceBehaviors);
3444
+ }
3445
+ }
3446
+ }
3447
+ /**
3448
+ * Removes styles from this element. Providing an HTMLStyleElement will detach the element instance from the shadowRoot.
3449
+ * @param styles - the styles to remove.
3450
+ */
3451
+ removeStyles(styles) {
3452
+ if (!styles) {
3453
+ return;
3454
+ }
3455
+ const target = getShadowRoot(this.element) ||
3456
+ this.element.getRootNode();
3457
+ if (styles instanceof HTMLElement) {
3458
+ target.removeChild(styles);
3459
+ }
3460
+ else if (styles.isAttachedTo(target)) {
3461
+ const sourceBehaviors = styles.behaviors;
3462
+ styles.removeStylesFrom(target);
3463
+ if (sourceBehaviors !== null) {
3464
+ this.removeBehaviors(sourceBehaviors);
3465
+ }
3466
+ }
3467
+ }
3468
+ /**
3469
+ * Adds behaviors to this element.
3470
+ * @param behaviors - The behaviors to add.
3471
+ */
3472
+ addBehaviors(behaviors) {
3473
+ var _a;
3474
+ const targetBehaviors = (_a = this.behaviors) !== null && _a !== void 0 ? _a : (this.behaviors = new Map());
3475
+ const length = behaviors.length;
3476
+ const behaviorsToBind = [];
3477
+ for (let i = 0; i < length; ++i) {
3478
+ const behavior = behaviors[i];
3479
+ if (targetBehaviors.has(behavior)) {
3480
+ targetBehaviors.set(behavior, targetBehaviors.get(behavior) + 1);
3481
+ }
3482
+ else {
3483
+ targetBehaviors.set(behavior, 1);
3484
+ behaviorsToBind.push(behavior);
3485
+ }
3486
+ }
3487
+ if (this._isConnected) {
3488
+ const element = this.element;
3489
+ const context = ExecutionContext.default;
3490
+ for (let i = 0; i < behaviorsToBind.length; ++i) {
3491
+ behaviorsToBind[i].bind(element, context);
3492
+ }
3493
+ }
3494
+ }
3495
+ /**
3496
+ * Removes behaviors from this element.
3497
+ * @param behaviors - The behaviors to remove.
3498
+ * @param force - Forces unbinding of behaviors.
3499
+ */
3500
+ removeBehaviors(behaviors, force = false) {
3501
+ const targetBehaviors = this.behaviors;
3502
+ if (targetBehaviors === null) {
3503
+ return;
3504
+ }
3505
+ const length = behaviors.length;
3506
+ const behaviorsToUnbind = [];
3507
+ for (let i = 0; i < length; ++i) {
3508
+ const behavior = behaviors[i];
3509
+ if (targetBehaviors.has(behavior)) {
3510
+ const count = targetBehaviors.get(behavior) - 1;
3511
+ count === 0 || force
3512
+ ? targetBehaviors.delete(behavior) && behaviorsToUnbind.push(behavior)
3513
+ : targetBehaviors.set(behavior, count);
3514
+ }
3515
+ }
3516
+ if (this._isConnected) {
3517
+ const element = this.element;
3518
+ const context = ExecutionContext.default;
3519
+ for (let i = 0; i < behaviorsToUnbind.length; ++i) {
3520
+ behaviorsToUnbind[i].unbind(element, context);
3521
+ }
3522
+ }
3523
+ }
3524
+ /**
3525
+ * Runs connected lifecycle behavior on the associated element.
3526
+ */
3527
+ onConnectedCallback() {
3528
+ if (this._isConnected) {
3529
+ return;
3530
+ }
3531
+ const element = this.element;
3532
+ const context = ExecutionContext.default;
3533
+ if (this.needsInitialization) {
3534
+ this.finishInitialization();
3535
+ }
3536
+ else if (this.view !== null) {
3537
+ this.view.bind(element, context);
3538
+ }
3539
+ const behaviors = this.behaviors;
3540
+ if (behaviors !== null) {
3541
+ for (const behavior of behaviors.keys()) {
3542
+ behavior.bind(element, context);
3543
+ }
3544
+ }
3545
+ this.setIsConnected(true);
3546
+ }
3547
+ /**
3548
+ * Runs disconnected lifecycle behavior on the associated element.
3549
+ */
3550
+ onDisconnectedCallback() {
3551
+ if (!this._isConnected) {
3552
+ return;
3553
+ }
3554
+ this.setIsConnected(false);
3555
+ const view = this.view;
3556
+ if (view !== null) {
3557
+ view.unbind();
3558
+ }
3559
+ const behaviors = this.behaviors;
3560
+ if (behaviors !== null) {
3561
+ const element = this.element;
3562
+ const context = ExecutionContext.default;
3563
+ for (const behavior of behaviors.keys()) {
3564
+ behavior.unbind(element, context);
3565
+ }
3566
+ }
3567
+ }
3568
+ /**
3569
+ * Runs the attribute changed callback for the associated element.
3570
+ * @param name - The name of the attribute that changed.
3571
+ * @param oldValue - The previous value of the attribute.
3572
+ * @param newValue - The new value of the attribute.
3573
+ */
3574
+ onAttributeChangedCallback(name, oldValue, newValue) {
3575
+ const attrDef = this.definition.attributeLookup[name];
3576
+ if (attrDef !== void 0) {
3577
+ attrDef.onAttributeChangedCallback(this.element, newValue);
3578
+ }
3579
+ }
3580
+ /**
3581
+ * Emits a custom HTML event.
3582
+ * @param type - The type name of the event.
3583
+ * @param detail - The event detail object to send with the event.
3584
+ * @param options - The event options. By default bubbles and composed.
3585
+ * @remarks
3586
+ * Only emits events if connected.
3587
+ */
3588
+ emit(type, detail, options) {
3589
+ if (this._isConnected) {
3590
+ return this.element.dispatchEvent(new CustomEvent(type, Object.assign(Object.assign({ detail }, defaultEventOptions), options)));
3591
+ }
3592
+ return false;
3593
+ }
3594
+ finishInitialization() {
3595
+ const element = this.element;
3596
+ const boundObservables = this.boundObservables;
3597
+ // If we have any observables that were bound, re-apply their values.
3598
+ if (boundObservables !== null) {
3599
+ const propertyNames = Object.keys(boundObservables);
3600
+ for (let i = 0, ii = propertyNames.length; i < ii; ++i) {
3601
+ const propertyName = propertyNames[i];
3602
+ element[propertyName] = boundObservables[propertyName];
3603
+ }
3604
+ this.boundObservables = null;
3605
+ }
3606
+ this.renderTemplate(this.template);
3607
+ this.addStyles(this.styles);
3608
+ this.needsInitialization = false;
3609
+ }
3610
+ renderTemplate(template) {
3611
+ var _a;
3612
+ const element = this.element;
3613
+ // When getting the host to render to, we start by looking
3614
+ // up the shadow root. If there isn't one, then that means
3615
+ // we're doing a Light DOM render to the element's direct children.
3616
+ const host = (_a = getShadowRoot(element)) !== null && _a !== void 0 ? _a : element;
3617
+ if (this.view !== null) {
3618
+ // If there's already a view, we need to unbind and remove through dispose.
3619
+ this.view.dispose();
3620
+ this.view = null;
3621
+ }
3622
+ else if (!this.needsInitialization || this.hasExistingShadowRoot) {
3623
+ this.hasExistingShadowRoot = false;
3624
+ // If there was previous custom rendering, we need to clear out the host.
3625
+ for (let child = host.firstChild; child !== null; child = host.firstChild) {
3626
+ host.removeChild(child);
3627
+ }
3628
+ }
3629
+ if (template) {
3630
+ // If a new template was provided, render it.
3631
+ this.view = template.render(element, host, element);
3632
+ }
3633
+ }
3634
+ /**
3635
+ * Locates or creates a controller for the specified element.
3636
+ * @param element - The element to return the controller for.
3637
+ * @remarks
3638
+ * The specified element must have a {@link FASTElementDefinition}
3639
+ * registered either through the use of the {@link customElement}
3640
+ * decorator or a call to `FASTElement.define`.
3641
+ */
3642
+ static forCustomElement(element) {
3643
+ const controller = element.$fastController;
3644
+ if (controller !== void 0) {
3645
+ return controller;
3646
+ }
3647
+ const definition = FASTElementDefinition.getForInstance(element);
3648
+ if (definition === void 0) {
3649
+ throw FAST.error(1401 /* Message.missingElementDefinition */);
3650
+ }
3651
+ return (element.$fastController = new Controller(element, definition));
3652
+ }
3653
+ }
3654
+
3655
+ /* eslint-disable-next-line @typescript-eslint/explicit-function-return-type */
3656
+ function createFASTElement(BaseType) {
3657
+ return class extends BaseType {
3658
+ constructor() {
3659
+ /* eslint-disable-next-line */
3660
+ super();
3661
+ Controller.forCustomElement(this);
3662
+ }
3663
+ $emit(type, detail, options) {
3664
+ return this.$fastController.emit(type, detail, options);
3665
+ }
3666
+ connectedCallback() {
3667
+ this.$fastController.onConnectedCallback();
3668
+ }
3669
+ disconnectedCallback() {
3670
+ this.$fastController.onDisconnectedCallback();
3671
+ }
3672
+ attributeChangedCallback(name, oldValue, newValue) {
3673
+ this.$fastController.onAttributeChangedCallback(name, oldValue, newValue);
3674
+ }
3675
+ };
3676
+ }
3677
+ /**
3678
+ * A minimal base class for FASTElements that also provides
3679
+ * static helpers for working with FASTElements.
3680
+ * @public
3681
+ */
3682
+ const FASTElement = Object.assign(createFASTElement(HTMLElement), {
3683
+ /**
3684
+ * Creates a new FASTElement base class inherited from the
3685
+ * provided base type.
3686
+ * @param BaseType - The base element type to inherit from.
3687
+ */
3688
+ from(BaseType) {
3689
+ return createFASTElement(BaseType);
3690
+ },
3691
+ /**
3692
+ * Defines a platform custom element based on the provided type and definition.
3693
+ * @param type - The custom element type to define.
3694
+ * @param nameOrDef - The name of the element to define or a definition object
3695
+ * that describes the element to define.
3696
+ */
3697
+ define(type, nameOrDef) {
3698
+ return this.metadata(type, nameOrDef).define().type;
3699
+ },
3700
+ /**
3701
+ * Defines metadata for a FASTElement which can be used to later define the element.
3702
+ * IMPORTANT: This API will be renamed to "compose" in a future beta.
3703
+ * @public
3704
+ */
3705
+ metadata(type, nameOrDef) {
3706
+ return new FASTElementDefinition(type, nameOrDef);
3707
+ },
3708
+ });
3709
+ /**
3710
+ * Decorator: Defines a platform custom element based on `FASTElement`.
3711
+ * @param nameOrDef - The name of the element to define or a definition object
3712
+ * that describes the element to define.
3713
+ * @public
3714
+ */
3715
+ function customElement(nameOrDef) {
3716
+ /* eslint-disable-next-line @typescript-eslint/explicit-function-return-type */
3717
+ return function (type) {
3718
+ FASTElement.define(type, nameOrDef);
3719
+ };
3720
+ }
3721
+
3722
+ export { AdoptedStyleSheetsStrategy, ArrayObserver, Aspect, AttributeDefinition, BindingConfig, BindingMode, CSSDirective, ChangeBinding, ChildrenDirective, Compiler, Controller, DOM, ElementStyles, EventBinding, ExecutionContext, FAST, FASTElement, FASTElementDefinition, HTMLBindingDirective, HTMLDirective, HTMLView, Markup, NodeObservationDirective, Observable, OneTimeBinding, Parser, PropertyChangeNotifier, RefDirective, RepeatBehavior, RepeatDirective, SlottedDirective, Splice, SpliceStrategy, SpliceStrategySupport, StatelessAttachedAttributeDirective, SubscriberSet, UpdateBinding, Updates, ViewTemplate, attr, bind, booleanConverter, children, createTypeRegistry, css, cssDirective, cssPartial, customElement, elements, emptyArray, html, htmlDirective, lengthOf, nullableNumberConverter, observable, onChange, oneTime, ref, repeat, slotted, volatile, when };