@microsoft/fast-element 1.10.1 → 2.0.0-beta.2

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