@lushly-dev/fast-element 3.0.1-preview.0 → 3.0.1-preview.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 (250) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/command/command.api.json +7857 -0
  3. package/dist/context/context.api.json +1084 -0
  4. package/dist/declarative/declarative.api.json +8130 -0
  5. package/dist/definition-schema/definition-schema.api.json +2689 -0
  6. package/dist/di/di.api.json +4945 -0
  7. package/dist/dts/arrays.d.ts +2 -0
  8. package/dist/dts/binding/binding.d.ts +59 -0
  9. package/dist/dts/binding/exports.d.ts +9 -0
  10. package/dist/dts/binding/normalize.d.ts +9 -0
  11. package/dist/dts/binding/one-time.d.ts +11 -0
  12. package/dist/dts/binding/one-way.d.ts +20 -0
  13. package/dist/dts/binding/signal.d.ts +36 -0
  14. package/dist/dts/binding/two-way.d.ts +44 -0
  15. package/dist/dts/command/behavior.d.ts +94 -0
  16. package/dist/dts/command/behaviors/confirm-behavior.d.ts +139 -0
  17. package/dist/dts/command/behaviors/undo-behavior.d.ts +178 -0
  18. package/dist/dts/command/command.d.ts +79 -0
  19. package/dist/dts/command/component-registry.d.ts +50 -0
  20. package/dist/dts/command/components/confirm-dialog.d.ts +117 -0
  21. package/dist/dts/command/index.d.ts +21 -0
  22. package/dist/dts/command/registry.d.ts +201 -0
  23. package/dist/dts/command/schema-validation.d.ts +45 -0
  24. package/dist/dts/command/types.d.ts +332 -0
  25. package/dist/dts/command/validation.d.ts +116 -0
  26. package/dist/dts/command/weak-ref.d.ts +11 -0
  27. package/dist/dts/components/attributes.d.ts +153 -0
  28. package/dist/dts/components/definition-schema-transforms.d.ts +9 -0
  29. package/dist/dts/components/element-controller.d.ts +349 -0
  30. package/dist/dts/components/element-hydration.d.ts +2 -0
  31. package/dist/dts/components/enable-hydration.d.ts +66 -0
  32. package/dist/dts/components/fast-definitions.d.ts +211 -0
  33. package/dist/dts/components/fast-element-registry.d.ts +23 -0
  34. package/dist/dts/components/fast-element.d.ts +91 -0
  35. package/dist/dts/components/hydration-tracker.d.ts +110 -0
  36. package/dist/dts/components/hydration.d.ts +52 -0
  37. package/dist/dts/components/schema.d.ts +205 -0
  38. package/dist/dts/context.d.ts +171 -0
  39. package/dist/dts/debug.d.ts +5 -0
  40. package/dist/dts/declarative/attribute-map.d.ts +58 -0
  41. package/dist/dts/declarative/debug.d.ts +4 -0
  42. package/dist/dts/declarative/index.d.ts +14 -0
  43. package/dist/dts/declarative/interfaces.d.ts +8 -0
  44. package/dist/dts/declarative/observer-map-utilities.d.ts +58 -0
  45. package/dist/dts/declarative/observer-map.d.ts +89 -0
  46. package/dist/dts/declarative/runtime.d.ts +5 -0
  47. package/dist/dts/declarative/syntax.d.ts +21 -0
  48. package/dist/dts/declarative/template-bridge.d.ts +33 -0
  49. package/dist/dts/declarative/template-parser.d.ts +98 -0
  50. package/dist/dts/declarative/template.d.ts +9 -0
  51. package/dist/dts/declarative/utilities.d.ts +358 -0
  52. package/dist/dts/definition-schema/api.d.ts +42 -0
  53. package/dist/dts/definition-schema/cem.d.ts +78 -0
  54. package/dist/dts/definition-schema/extension.d.ts +18 -0
  55. package/dist/dts/definition-schema/extract.d.ts +38 -0
  56. package/dist/dts/definition-schema/index.d.ts +9 -0
  57. package/dist/dts/definition-schema/storage.d.ts +35 -0
  58. package/dist/dts/definition-schema/types.d.ts +176 -0
  59. package/dist/dts/dev-mode.d.ts +13 -0
  60. package/dist/dts/di/di.d.ts +894 -0
  61. package/dist/dts/dom-policy.d.ts +101 -0
  62. package/dist/dts/dom.d.ts +88 -0
  63. package/dist/dts/hydration/diagnostics.d.ts +93 -0
  64. package/dist/dts/hydration/exports.d.ts +18 -0
  65. package/dist/dts/hydration/hydration-debugger.d.ts +35 -0
  66. package/dist/dts/hydration/messages.d.ts +62 -0
  67. package/dist/dts/hydration/runtime.d.ts +7 -0
  68. package/dist/dts/hydration/target-builder.d.ts +107 -0
  69. package/dist/dts/index.d.ts +51 -0
  70. package/dist/dts/index.debug.d.ts +1 -0
  71. package/dist/dts/index.rollup.d.ts +1 -0
  72. package/dist/dts/index.rollup.debug.d.ts +1 -0
  73. package/dist/dts/interfaces.d.ts +106 -0
  74. package/dist/dts/metadata.d.ts +26 -0
  75. package/dist/dts/observation/arrays.d.ts +248 -0
  76. package/dist/dts/observation/notifier.d.ts +127 -0
  77. package/dist/dts/observation/observable.d.ts +276 -0
  78. package/dist/dts/observation/update-queue.d.ts +40 -0
  79. package/dist/dts/observation/volatile.d.ts +9 -0
  80. package/dist/dts/platform.d.ts +87 -0
  81. package/dist/dts/registry.d.ts +2 -0
  82. package/dist/dts/render.d.ts +7 -0
  83. package/dist/dts/schema.d.ts +1 -0
  84. package/dist/dts/scoped/detection.d.ts +55 -0
  85. package/dist/dts/scoped/index.d.ts +68 -0
  86. package/dist/dts/scoped/mixin.d.ts +118 -0
  87. package/dist/dts/scoped/registry.d.ts +76 -0
  88. package/dist/dts/scoped/types.d.ts +48 -0
  89. package/dist/dts/state/exports.d.ts +3 -0
  90. package/dist/dts/state/reactive.d.ts +8 -0
  91. package/dist/dts/state/state.d.ts +141 -0
  92. package/dist/dts/state/visitor.d.ts +6 -0
  93. package/dist/dts/state/watch.d.ts +10 -0
  94. package/dist/dts/styles/css-directive.d.ts +50 -0
  95. package/dist/dts/styles/css.d.ts +34 -0
  96. package/dist/dts/styles/element-styles.d.ts +61 -0
  97. package/dist/dts/styles/host.d.ts +65 -0
  98. package/dist/dts/styles/style-strategy.d.ts +42 -0
  99. package/dist/dts/templating/children.d.ts +62 -0
  100. package/dist/dts/templating/compiler.d.ts +54 -0
  101. package/dist/dts/templating/html-binding-directive.d.ts +155 -0
  102. package/dist/dts/templating/html-directive.d.ts +218 -0
  103. package/dist/dts/templating/html.d.ts +1 -0
  104. package/dist/dts/templating/hydration-view.d.ts +130 -0
  105. package/dist/dts/templating/markup.d.ts +48 -0
  106. package/dist/dts/templating/node-observation.d.ts +99 -0
  107. package/dist/dts/templating/ref.d.ts +23 -0
  108. package/dist/dts/templating/render.d.ts +318 -0
  109. package/dist/dts/templating/repeat.d.ts +131 -0
  110. package/dist/dts/templating/slotted.d.ts +38 -0
  111. package/dist/dts/templating/template.d.ts +221 -0
  112. package/dist/dts/templating/view.d.ts +268 -0
  113. package/dist/dts/templating/when.d.ts +12 -0
  114. package/dist/dts/testing/exports.d.ts +3 -0
  115. package/dist/dts/testing/fakes.d.ts +16 -0
  116. package/dist/dts/testing/fixture.d.ts +84 -0
  117. package/dist/dts/testing/models.d.ts +20 -0
  118. package/dist/dts/testing/timeout.d.ts +7 -0
  119. package/dist/dts/trust/index.d.ts +8 -0
  120. package/dist/dts/trust/types.d.ts +48 -0
  121. package/dist/dts/trust/utils.d.ts +26 -0
  122. package/dist/dts/tsdoc-metadata.json +11 -0
  123. package/dist/dts/utilities.d.ts +76 -0
  124. package/dist/esm/arrays.js +1 -0
  125. package/dist/esm/binding/binding.js +18 -0
  126. package/dist/esm/binding/exports.js +6 -0
  127. package/dist/esm/binding/normalize.js +17 -0
  128. package/dist/esm/binding/one-time.js +21 -0
  129. package/dist/esm/binding/one-way.js +30 -0
  130. package/dist/esm/binding/signal.js +99 -0
  131. package/dist/esm/binding/two-way.js +109 -0
  132. package/dist/esm/command/behavior.js +155 -0
  133. package/dist/esm/command/behaviors/confirm-behavior.js +225 -0
  134. package/dist/esm/command/behaviors/undo-behavior.js +313 -0
  135. package/dist/esm/command/command.js +104 -0
  136. package/dist/esm/command/component-registry.js +107 -0
  137. package/dist/esm/command/components/confirm-dialog.js +370 -0
  138. package/dist/esm/command/index.js +22 -0
  139. package/dist/esm/command/registry.js +755 -0
  140. package/dist/esm/command/schema-validation.js +194 -0
  141. package/dist/esm/command/types.js +86 -0
  142. package/dist/esm/command/validation.js +508 -0
  143. package/dist/esm/command/weak-ref.js +5 -0
  144. package/dist/esm/components/attributes.js +219 -0
  145. package/dist/esm/components/definition-schema-transforms.js +23 -0
  146. package/dist/esm/components/element-controller.js +840 -0
  147. package/dist/esm/components/element-hydration.js +2 -0
  148. package/dist/esm/components/enable-hydration.js +123 -0
  149. package/dist/esm/components/fast-definitions.js +294 -0
  150. package/dist/esm/components/fast-element-registry.js +67 -0
  151. package/dist/esm/components/fast-element.js +82 -0
  152. package/dist/esm/components/hydration-tracker.js +211 -0
  153. package/dist/esm/components/hydration.js +187 -0
  154. package/dist/esm/components/schema.js +253 -0
  155. package/dist/esm/context.js +185 -0
  156. package/dist/esm/debug.js +71 -0
  157. package/dist/esm/declarative/attribute-map.js +122 -0
  158. package/dist/esm/declarative/debug.js +4 -0
  159. package/dist/esm/declarative/index.js +10 -0
  160. package/dist/esm/declarative/interfaces.js +9 -0
  161. package/dist/esm/declarative/observer-map-utilities.js +565 -0
  162. package/dist/esm/declarative/observer-map.js +216 -0
  163. package/dist/esm/declarative/runtime.js +14 -0
  164. package/dist/esm/declarative/syntax.js +36 -0
  165. package/dist/esm/declarative/template-bridge.js +160 -0
  166. package/dist/esm/declarative/template-parser.js +306 -0
  167. package/dist/esm/declarative/template.js +116 -0
  168. package/dist/esm/declarative/utilities.js +1069 -0
  169. package/dist/esm/definition-schema/api.js +129 -0
  170. package/dist/esm/definition-schema/cem.js +89 -0
  171. package/dist/esm/definition-schema/extension.js +53 -0
  172. package/dist/esm/definition-schema/extract.js +167 -0
  173. package/dist/esm/definition-schema/index.js +8 -0
  174. package/dist/esm/definition-schema/storage.js +58 -0
  175. package/dist/esm/definition-schema/types.js +8 -0
  176. package/dist/esm/dev-mode.js +22 -0
  177. package/dist/esm/di/di.js +1441 -0
  178. package/dist/esm/dom-policy.js +374 -0
  179. package/dist/esm/dom.js +101 -0
  180. package/dist/esm/hydration/diagnostics.js +50 -0
  181. package/dist/esm/hydration/exports.js +6 -0
  182. package/dist/esm/hydration/hydration-debugger.js +112 -0
  183. package/dist/esm/hydration/messages.js +84 -0
  184. package/dist/esm/hydration/runtime.js +33 -0
  185. package/dist/esm/hydration/target-builder.js +264 -0
  186. package/dist/esm/index.debug.js +3 -0
  187. package/dist/esm/index.js +49 -0
  188. package/dist/esm/index.rollup.debug.js +6 -0
  189. package/dist/esm/index.rollup.js +4 -0
  190. package/dist/esm/interfaces.js +55 -0
  191. package/dist/esm/metadata.js +57 -0
  192. package/dist/esm/observation/arrays.js +661 -0
  193. package/dist/esm/observation/notifier.js +162 -0
  194. package/dist/esm/observation/observable.js +324 -0
  195. package/dist/esm/observation/update-queue.js +56 -0
  196. package/dist/esm/observation/volatile.js +16 -0
  197. package/dist/esm/platform.js +98 -0
  198. package/dist/esm/registry.js +2 -0
  199. package/dist/esm/render.js +1 -0
  200. package/dist/esm/schema.js +1 -0
  201. package/dist/esm/scoped/detection.js +102 -0
  202. package/dist/esm/scoped/index.js +69 -0
  203. package/dist/esm/scoped/mixin.js +127 -0
  204. package/dist/esm/scoped/registry.js +125 -0
  205. package/dist/esm/scoped/types.js +4 -0
  206. package/dist/esm/state/exports.js +3 -0
  207. package/dist/esm/state/reactive.js +34 -0
  208. package/dist/esm/state/state.js +148 -0
  209. package/dist/esm/state/visitor.js +28 -0
  210. package/dist/esm/state/watch.js +36 -0
  211. package/dist/esm/styles/css-directive.js +36 -0
  212. package/dist/esm/styles/css.js +56 -0
  213. package/dist/esm/styles/element-styles.js +144 -0
  214. package/dist/esm/styles/host.js +1 -0
  215. package/dist/esm/styles/style-strategy.js +1 -0
  216. package/dist/esm/templating/children.js +67 -0
  217. package/dist/esm/templating/compiler.js +359 -0
  218. package/dist/esm/templating/html-binding-directive.js +288 -0
  219. package/dist/esm/templating/html-directive.js +113 -0
  220. package/dist/esm/templating/html.js +1 -0
  221. package/dist/esm/templating/hydration-view.js +228 -0
  222. package/dist/esm/templating/markup.js +83 -0
  223. package/dist/esm/templating/node-observation.js +84 -0
  224. package/dist/esm/templating/ref.js +21 -0
  225. package/dist/esm/templating/render.js +468 -0
  226. package/dist/esm/templating/repeat.js +434 -0
  227. package/dist/esm/templating/slotted.js +49 -0
  228. package/dist/esm/templating/template.js +206 -0
  229. package/dist/esm/templating/view.js +298 -0
  230. package/dist/esm/templating/when.js +22 -0
  231. package/dist/esm/testing/exports.js +3 -0
  232. package/dist/esm/testing/fakes.js +107 -0
  233. package/dist/esm/testing/fixture.js +86 -0
  234. package/dist/esm/testing/models.js +58 -0
  235. package/dist/esm/testing/timeout.js +24 -0
  236. package/dist/esm/trust/index.js +7 -0
  237. package/dist/esm/trust/types.js +6 -0
  238. package/dist/esm/trust/utils.js +126 -0
  239. package/dist/esm/utilities.js +140 -0
  240. package/dist/fast-element.api.json +26798 -0
  241. package/dist/fast-element.d.ts +3985 -0
  242. package/dist/fast-element.debug.js +7604 -0
  243. package/dist/fast-element.debug.min.js +3 -0
  244. package/dist/fast-element.js +7603 -0
  245. package/dist/fast-element.min.js +3 -0
  246. package/dist/fast-element.untrimmed.d.ts +4103 -0
  247. package/dist/observation/arrays/arrays.api.json +2621 -0
  248. package/dist/scoped/scoped.api.json +891 -0
  249. package/dist/trust/trust.api.json +629 -0
  250. package/package.json +21 -23
@@ -0,0 +1,840 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { Message } from "../interfaces.js";
13
+ import { PropertyChangeNotifier } from "../observation/notifier.js";
14
+ import { ExecutionContext, Observable, SourceLifetime, } from "../observation/observable.js";
15
+ import { FAST, makeSerializationNoop } from "../platform.js";
16
+ import { ElementStyles } from "../styles/element-styles.js";
17
+ import { wrapDetailWithTrust } from "../trust/utils.js";
18
+ import { FASTElementDefinition, getLateAttributeLookup, } from "./fast-definitions.js";
19
+ const defaultEventOptions = {
20
+ bubbles: true,
21
+ composed: true,
22
+ cancelable: true,
23
+ };
24
+ const isConnectedPropertyName = "isConnected";
25
+ const shadowRoots = new WeakMap();
26
+ const lateAttributeObserver = Symbol("fast-late-attribute-observer");
27
+ const behaviorFactories = new Set();
28
+ /**
29
+ * Registers a focused integration hook for optional element behaviors.
30
+ * @param factory - Factory invoked for each new element controller.
31
+ * @returns A callback that removes the factory.
32
+ * @internal
33
+ */
34
+ export function registerElementControllerBehaviorFactory(factory) {
35
+ behaviorFactories.add(factory);
36
+ return () => behaviorFactories.delete(factory);
37
+ }
38
+ function getShadowRoot(element) {
39
+ var _a, _b;
40
+ return (_b = (_a = element.shadowRoot) !== null && _a !== void 0 ? _a : shadowRoots.get(element)) !== null && _b !== void 0 ? _b : null;
41
+ }
42
+ let elementControllerStrategy;
43
+ /**
44
+ * The various lifecycle stages of an ElementController.
45
+ * @public
46
+ */
47
+ export var Stages;
48
+ (function (Stages) {
49
+ /** The element is in the process of connecting. */
50
+ Stages[Stages["connecting"] = 0] = "connecting";
51
+ /** The element is connected. */
52
+ Stages[Stages["connected"] = 1] = "connected";
53
+ /** The element is in the process of disconnecting. */
54
+ Stages[Stages["disconnecting"] = 2] = "disconnecting";
55
+ /** The element is disconnected. */
56
+ Stages[Stages["disconnected"] = 3] = "disconnected";
57
+ })(Stages || (Stages = {}));
58
+ /**
59
+ * Controls the lifecycle and rendering of a `FASTElement`.
60
+ * @public
61
+ */
62
+ export class ElementController {
63
+ /**
64
+ * Indicates whether or not the custom element has been
65
+ * connected to the document.
66
+ */
67
+ get isConnected() {
68
+ Observable.track(this, isConnectedPropertyName);
69
+ return this.stage === Stages.connected;
70
+ }
71
+ /**
72
+ * The context the expression is evaluated against.
73
+ */
74
+ get context() {
75
+ var _a;
76
+ var _b;
77
+ return (_b = (_a = this.view) === null || _a === void 0 ? void 0 : _a.context) !== null && _b !== void 0 ? _b : ExecutionContext.default;
78
+ }
79
+ /**
80
+ * Indicates whether the controller is bound.
81
+ */
82
+ get isBound() {
83
+ var _a;
84
+ var _b;
85
+ return (_b = (_a = this.view) === null || _a === void 0 ? void 0 : _a.isBound) !== null && _b !== void 0 ? _b : false;
86
+ }
87
+ /**
88
+ * Indicates how the source's lifetime relates to the controller's lifetime.
89
+ */
90
+ get sourceLifetime() {
91
+ var _a;
92
+ return (_a = this.view) === null || _a === void 0 ? void 0 : _a.sourceLifetime;
93
+ }
94
+ /**
95
+ * Gets/sets the template used to render the component.
96
+ * @remarks
97
+ * This value can only be accurately read after connect but can be set at any time.
98
+ */
99
+ get template() {
100
+ var _a;
101
+ // 1. Template overrides take top precedence.
102
+ if (this._template === null) {
103
+ const definition = this.definition;
104
+ if (this.source.resolveTemplate) {
105
+ // 2. Allow for element instance overrides next.
106
+ this._template = this.source.resolveTemplate();
107
+ }
108
+ else if (definition.template) {
109
+ // 3. Default to the static definition.
110
+ this._template = (_a = definition.template) !== null && _a !== void 0 ? _a : null;
111
+ }
112
+ }
113
+ return this._template;
114
+ }
115
+ set template(value) {
116
+ if (this._template === value) {
117
+ return;
118
+ }
119
+ this._template = value;
120
+ if (!this.needsInitialization) {
121
+ this.renderTemplate(value);
122
+ }
123
+ }
124
+ /**
125
+ * The shadow root options for the component.
126
+ */
127
+ get shadowOptions() {
128
+ return this._shadowRootOptions;
129
+ }
130
+ set shadowOptions(value) {
131
+ // options on the shadowRoot can only be set once
132
+ if (this._shadowRootOptions === void 0 && value !== void 0) {
133
+ this._shadowRootOptions = value;
134
+ let shadowRoot = this.source.shadowRoot;
135
+ if (shadowRoot) {
136
+ this.hasExistingShadowRoot = true;
137
+ }
138
+ else {
139
+ shadowRoot = this.source.attachShadow(value);
140
+ if (value.mode === "closed") {
141
+ shadowRoots.set(this.source, shadowRoot);
142
+ }
143
+ }
144
+ }
145
+ }
146
+ /**
147
+ * The main set of styles used for the component, independent
148
+ * of any dynamically added styles.
149
+ */
150
+ get mainStyles() {
151
+ var _a;
152
+ // 1. Styles overrides take top precedence.
153
+ if (this._mainStyles === null) {
154
+ const definition = this.definition;
155
+ if (this.source.resolveStyles) {
156
+ // 2. Allow for element instance overrides next.
157
+ this._mainStyles = this.source.resolveStyles();
158
+ }
159
+ else if (definition.styles) {
160
+ // 3. Default to the static definition.
161
+ this._mainStyles = (_a = definition.styles) !== null && _a !== void 0 ? _a : null;
162
+ }
163
+ }
164
+ return this._mainStyles;
165
+ }
166
+ set mainStyles(value) {
167
+ if (this._mainStyles === value) {
168
+ return;
169
+ }
170
+ if (this._mainStyles !== null) {
171
+ this.removeStyles(this._mainStyles);
172
+ }
173
+ this._mainStyles = value;
174
+ if (!this.needsInitialization) {
175
+ this.addStyles(value);
176
+ }
177
+ }
178
+ /**
179
+ * Creates a Controller to control the specified element.
180
+ * @param element - The element to be controlled by this controller.
181
+ * @param definition - The element definition metadata that instructs this
182
+ * controller in how to handle rendering and other platform integrations.
183
+ * @internal
184
+ */
185
+ constructor(element, definition) {
186
+ /**
187
+ * A map of observable properties that were set on the element before upgrade.
188
+ */
189
+ this.boundObservables = null;
190
+ /**
191
+ * Indicates whether the controller needs to perform initial rendering.
192
+ */
193
+ this.needsInitialization = true;
194
+ /**
195
+ * Indicates whether the element has an existing shadow root (e.g. from declarative shadow DOM).
196
+ */
197
+ this.hasExistingShadowRoot = false;
198
+ /**
199
+ * Resolves `true` when the element had an existing shadow root
200
+ * (from SSR or declarative shadow DOM) at connect time, `false`
201
+ * otherwise.
202
+ */
203
+ this.isPrerendered = new Promise(resolve => {
204
+ this._resolvePrerendered = resolve;
205
+ });
206
+ /**
207
+ * Resolves `true` after prerendered content has been successfully
208
+ * hydrated, or `false` when the component is client-side rendered
209
+ * or hydration is not enabled.
210
+ */
211
+ this.isHydrated = new Promise(resolve => {
212
+ this._resolveHydrated = resolve;
213
+ });
214
+ /**
215
+ * The template used to render the component.
216
+ */
217
+ this._template = null;
218
+ /**
219
+ * The current lifecycle stage of the controller.
220
+ */
221
+ this.stage = Stages.disconnected;
222
+ /**
223
+ * A guard against connecting behaviors multiple times
224
+ * during connect in scenarios where a behavior adds
225
+ * another behavior during it's connectedCallback
226
+ */
227
+ this.guardBehaviorConnection = false;
228
+ /**
229
+ * The behaviors associated with the component.
230
+ */
231
+ this.behaviors = null;
232
+ /**
233
+ * Tracks whether behaviors are connected so that
234
+ * behaviors cant be connected multiple times
235
+ */
236
+ this.behaviorsConnected = false;
237
+ /**
238
+ * The main set of styles used for the component, independent of any
239
+ * dynamically added styles.
240
+ */
241
+ this._mainStyles = null;
242
+ /**
243
+ * This allows Observable.getNotifier(...) to return the Controller
244
+ * when the notifier for the Controller itself is being requested. The
245
+ * result is that the Observable system does not need to create a separate
246
+ * instance of Notifier for observables on the Controller. The component and
247
+ * the controller will now share the same notifier, removing one-object construct
248
+ * per web component instance.
249
+ */
250
+ this.$fastController = this;
251
+ /**
252
+ * The view associated with the custom element.
253
+ * @remarks
254
+ * If `null` then the element is managing its own rendering.
255
+ */
256
+ this.view = null;
257
+ this._notifier = new PropertyChangeNotifier(element);
258
+ this.source = element;
259
+ this.definition = definition;
260
+ this.shadowOptions = definition.shadowOptions;
261
+ const prototype = Reflect.getPrototypeOf(element);
262
+ const accessors = prototype === null ? [] : Observable.getAccessors(prototype);
263
+ if (accessors.length > 0) {
264
+ const boundObservables = (this.boundObservables = Object.create(null));
265
+ for (let i = 0, ii = accessors.length; i < ii; ++i) {
266
+ const propertyName = accessors[i].name;
267
+ const value = element[propertyName];
268
+ if (value !== void 0) {
269
+ delete element[propertyName];
270
+ boundObservables[propertyName] = value;
271
+ }
272
+ }
273
+ if (Object.keys(boundObservables).length === 0) {
274
+ this.boundObservables = null;
275
+ }
276
+ }
277
+ // Capture any observable values that were set after construction but before
278
+ // the first connect (for example, late-defined declarative accessors).
279
+ this.captureBoundObservables();
280
+ for (const factory of behaviorFactories) {
281
+ const behavior = factory(element);
282
+ if (behavior !== void 0) {
283
+ this.addBehavior(behavior);
284
+ }
285
+ }
286
+ }
287
+ /**
288
+ * The subject that subscribers will receive notifications for.
289
+ */
290
+ get subject() {
291
+ return this._notifier.subject;
292
+ }
293
+ /**
294
+ * Notifies all subscribers of a property change.
295
+ * @param args - The property name that changed.
296
+ */
297
+ notify(args) {
298
+ this._notifier.notify(args);
299
+ }
300
+ /**
301
+ * Subscribes to notification of changes in the element's state.
302
+ * @param subscriber - The object that is subscribing for change notification.
303
+ * @param propertyToWatch - The name of the property to watch for changes.
304
+ */
305
+ subscribe(subscriber, propertyToWatch) {
306
+ this._notifier.subscribe(subscriber, propertyToWatch);
307
+ }
308
+ /**
309
+ * Unsubscribes from notification of changes in the element's state.
310
+ * @param subscriber - The object that is unsubscribing from change notification.
311
+ * @param propertyToUnwatch - The name of the property to unsubscribe from.
312
+ */
313
+ unsubscribe(subscriber, propertyToUnwatch) {
314
+ this._notifier.unsubscribe(subscriber, propertyToUnwatch);
315
+ }
316
+ /**
317
+ * Registers an unbind handler with the controller.
318
+ * @param behavior - An object to call when the controller unbinds.
319
+ */
320
+ onUnbind(behavior) {
321
+ var _a;
322
+ (_a = this.view) === null || _a === void 0 ? void 0 : _a.onUnbind(behavior);
323
+ }
324
+ /**
325
+ * Adds the behavior to the component.
326
+ * @param behavior - The behavior to add.
327
+ */
328
+ addBehavior(behavior) {
329
+ var _a, _b;
330
+ const targetBehaviors = (_a = this.behaviors) !== null && _a !== void 0 ? _a : (this.behaviors = new Map());
331
+ const count = (_b = targetBehaviors.get(behavior)) !== null && _b !== void 0 ? _b : 0;
332
+ if (count === 0) {
333
+ targetBehaviors.set(behavior, 1);
334
+ behavior.addedCallback && behavior.addedCallback(this);
335
+ if (behavior.connectedCallback &&
336
+ !this.guardBehaviorConnection &&
337
+ (this.stage === Stages.connected || this.stage === Stages.connecting)) {
338
+ behavior.connectedCallback(this);
339
+ }
340
+ }
341
+ else {
342
+ targetBehaviors.set(behavior, count + 1);
343
+ }
344
+ }
345
+ /**
346
+ * Removes the behavior from the component.
347
+ * @param behavior - The behavior to remove.
348
+ * @param force - Forces removal even if this behavior was added more than once.
349
+ */
350
+ removeBehavior(behavior, force = false) {
351
+ const targetBehaviors = this.behaviors;
352
+ if (targetBehaviors === null) {
353
+ return;
354
+ }
355
+ const count = targetBehaviors.get(behavior);
356
+ if (count === void 0) {
357
+ return;
358
+ }
359
+ if (count === 1 || force) {
360
+ targetBehaviors.delete(behavior);
361
+ if (behavior.disconnectedCallback && this.stage !== Stages.disconnected) {
362
+ behavior.disconnectedCallback(this);
363
+ }
364
+ behavior.removedCallback && behavior.removedCallback(this);
365
+ }
366
+ else {
367
+ targetBehaviors.set(behavior, count - 1);
368
+ }
369
+ }
370
+ /**
371
+ * Adds styles to this element. Providing an HTMLStyleElement will attach the element instance to the shadowRoot.
372
+ * @param styles - The styles to add.
373
+ */
374
+ addStyles(styles) {
375
+ var _a;
376
+ if (!styles) {
377
+ return;
378
+ }
379
+ const source = this.source;
380
+ if (styles instanceof HTMLElement) {
381
+ const target = (_a = getShadowRoot(source)) !== null && _a !== void 0 ? _a : this.source;
382
+ target.append(styles);
383
+ }
384
+ else if (!styles.isAttachedTo(source)) {
385
+ styles.addStylesTo(source);
386
+ }
387
+ }
388
+ /**
389
+ * Removes styles from this element. Providing an HTMLStyleElement will detach the element instance from the shadowRoot.
390
+ * @param styles - the styles to remove.
391
+ */
392
+ removeStyles(styles) {
393
+ var _a;
394
+ if (!styles) {
395
+ return;
396
+ }
397
+ const source = this.source;
398
+ if (styles instanceof HTMLElement) {
399
+ const target = (_a = getShadowRoot(source)) !== null && _a !== void 0 ? _a : source;
400
+ target.removeChild(styles);
401
+ }
402
+ else if (styles.isAttachedTo(source)) {
403
+ styles.removeStylesFrom(source);
404
+ }
405
+ }
406
+ /**
407
+ * Runs connected lifecycle behavior on the associated element.
408
+ */
409
+ connect() {
410
+ if (this.stage !== Stages.disconnected) {
411
+ return;
412
+ }
413
+ this.stage = Stages.connecting;
414
+ this.captureBoundObservables();
415
+ this.syncLateAttributes();
416
+ this.observeLateAttributes();
417
+ this.bindObservables();
418
+ this.connectBehaviors();
419
+ if (this.needsInitialization) {
420
+ this.renderTemplate(this.template);
421
+ this.addStyles(this.mainStyles);
422
+ this.needsInitialization = false;
423
+ }
424
+ else if (this.view !== null) {
425
+ this.view.bind(this.source);
426
+ }
427
+ this.stage = Stages.connected;
428
+ Observable.notify(this, isConnectedPropertyName);
429
+ }
430
+ /**
431
+ * Binds any observables that were set before upgrade.
432
+ */
433
+ bindObservables() {
434
+ if (this.boundObservables !== null) {
435
+ const element = this.source;
436
+ const boundObservables = this.boundObservables;
437
+ const propertyNames = Object.keys(boundObservables);
438
+ for (let i = 0, ii = propertyNames.length; i < ii; ++i) {
439
+ const propertyName = propertyNames[i];
440
+ element[propertyName] = boundObservables[propertyName];
441
+ }
442
+ this.boundObservables = null;
443
+ }
444
+ }
445
+ /**
446
+ * Captures public own-properties that shadow observable accessors on the
447
+ * prototype so they can be rebound through the accessor before rendering.
448
+ */
449
+ captureBoundObservables() {
450
+ const element = this.source;
451
+ const propertyNames = Object.getOwnPropertyNames(element);
452
+ const hasPrototypeAccessor = (propertyName) => {
453
+ let currentTarget = Reflect.getPrototypeOf(element);
454
+ while (currentTarget !== null) {
455
+ const descriptor = Reflect.getOwnPropertyDescriptor(currentTarget, propertyName);
456
+ if ((descriptor === null || descriptor === void 0 ? void 0 : descriptor.get) || (descriptor === null || descriptor === void 0 ? void 0 : descriptor.set)) {
457
+ return true;
458
+ }
459
+ currentTarget = Reflect.getPrototypeOf(currentTarget);
460
+ }
461
+ return false;
462
+ };
463
+ let boundObservables = this.boundObservables;
464
+ for (let i = 0, ii = propertyNames.length; i < ii; ++i) {
465
+ const ownPropertyName = propertyNames[i];
466
+ const propertyName = ownPropertyName;
467
+ if (!hasPrototypeAccessor(propertyName)) {
468
+ continue;
469
+ }
470
+ const value = element[propertyName];
471
+ if (value === void 0) {
472
+ delete element[propertyName];
473
+ continue;
474
+ }
475
+ delete element[propertyName];
476
+ (boundObservables !== null && boundObservables !== void 0 ? boundObservables : (boundObservables = this.boundObservables = Object.create(null)))[propertyName] = value;
477
+ }
478
+ }
479
+ /**
480
+ * Synchronizes late-defined attribute-map attributes from the live DOM to the
481
+ * associated property values before the initial render occurs.
482
+ */
483
+ syncLateAttributes() {
484
+ const lateAttributes = getLateAttributeLookup(this.definition);
485
+ if (lateAttributes === null) {
486
+ return;
487
+ }
488
+ for (const attributeName of Object.keys(lateAttributes)) {
489
+ if (!this.source.hasAttribute(attributeName)) {
490
+ continue;
491
+ }
492
+ this.onAttributeChangedCallback(attributeName, null, this.source.getAttribute(attributeName));
493
+ }
494
+ }
495
+ /**
496
+ * Observes late-defined attribute-map attributes that the platform does not
497
+ * surface through attributeChangedCallback because they were added after
498
+ * customElements.define() completed.
499
+ */
500
+ observeLateAttributes() {
501
+ const lateAttributes = getLateAttributeLookup(this.definition);
502
+ if (lateAttributes === null) {
503
+ return;
504
+ }
505
+ const element = this.source;
506
+ if (element[lateAttributeObserver] !== void 0) {
507
+ return;
508
+ }
509
+ element[lateAttributeObserver] = new MutationObserver(records => {
510
+ const controller = element.$fastController;
511
+ const lateAttributes = getLateAttributeLookup(controller.definition);
512
+ if (lateAttributes === null) {
513
+ return;
514
+ }
515
+ for (let i = 0, ii = records.length; i < ii; ++i) {
516
+ const attributeName = records[i].attributeName;
517
+ if (attributeName === null || lateAttributes[attributeName] === void 0) {
518
+ continue;
519
+ }
520
+ controller.onAttributeChangedCallback(attributeName, null, element.getAttribute(attributeName));
521
+ }
522
+ });
523
+ element[lateAttributeObserver].observe(element, {
524
+ attributes: true,
525
+ attributeFilter: Object.keys(lateAttributes),
526
+ });
527
+ }
528
+ /**
529
+ * Connects any existing behaviors on the associated element.
530
+ */
531
+ connectBehaviors() {
532
+ if (this.behaviorsConnected === false) {
533
+ const behaviors = this.behaviors;
534
+ if (behaviors !== null) {
535
+ this.guardBehaviorConnection = true;
536
+ for (const key of behaviors.keys()) {
537
+ key.connectedCallback && key.connectedCallback(this);
538
+ }
539
+ this.guardBehaviorConnection = false;
540
+ }
541
+ this.behaviorsConnected = true;
542
+ }
543
+ }
544
+ /**
545
+ * Disconnects any behaviors on the associated element.
546
+ */
547
+ disconnectBehaviors() {
548
+ if (this.behaviorsConnected === true) {
549
+ const behaviors = this.behaviors;
550
+ if (behaviors !== null) {
551
+ for (const key of behaviors.keys()) {
552
+ key.disconnectedCallback && key.disconnectedCallback(this);
553
+ }
554
+ }
555
+ this.behaviorsConnected = false;
556
+ }
557
+ }
558
+ /**
559
+ * Runs disconnected lifecycle behavior on the associated element.
560
+ */
561
+ disconnect() {
562
+ if (this.stage !== Stages.connected) {
563
+ return;
564
+ }
565
+ this.stage = Stages.disconnecting;
566
+ Observable.notify(this, isConnectedPropertyName);
567
+ if (this.view !== null) {
568
+ this.view.unbind();
569
+ }
570
+ this.disconnectBehaviors();
571
+ this.stage = Stages.disconnected;
572
+ }
573
+ /**
574
+ * Runs the attribute changed callback for the associated element.
575
+ * @param name - The name of the attribute that changed.
576
+ * @param oldValue - The previous value of the attribute.
577
+ * @param newValue - The new value of the attribute.
578
+ */
579
+ onAttributeChangedCallback(name, oldValue, newValue) {
580
+ const attrDef = this.definition.attributeLookup[name];
581
+ if (attrDef !== void 0) {
582
+ attrDef.onAttributeChangedCallback(this.source, newValue);
583
+ }
584
+ }
585
+ /**
586
+ * Emits a custom HTML event.
587
+ * @param type - The type name of the event.
588
+ * @param detail - The event detail object to send with the event.
589
+ * @param options - The event options. By default bubbles and composed.
590
+ * @remarks
591
+ * Only emits events if connected.
592
+ */
593
+ emit(type, detail, options) {
594
+ if (this.stage === Stages.connected) {
595
+ const _a = options !== null && options !== void 0 ? options : {}, { confidence, reasoning, warnings } = _a, eventOptions = __rest(_a, ["confidence", "reasoning", "warnings"]);
596
+ const wrappedDetail = wrapDetailWithTrust(detail, {
597
+ confidence,
598
+ reasoning,
599
+ warnings,
600
+ });
601
+ return this.source.dispatchEvent(new CustomEvent(type, Object.assign(Object.assign(Object.assign({}, defaultEventOptions), eventOptions), { detail: wrappedDetail })));
602
+ }
603
+ return false;
604
+ }
605
+ /**
606
+ * Renders the provided template to the element.
607
+ *
608
+ * @param template - The template to render.
609
+ * @remarks
610
+ * If `null` is provided, any existing view will be removed.
611
+ */
612
+ renderTemplate(template) {
613
+ var _a;
614
+ const element = this.source;
615
+ const host = (_a = getShadowRoot(element)) !== null && _a !== void 0 ? _a : element;
616
+ if (this.view !== null) {
617
+ this.view.dispose();
618
+ this.view = null;
619
+ }
620
+ else if (!this.needsInitialization || this.hasExistingShadowRoot) {
621
+ if (!this.hasExistingShadowRoot || !this.needsInitialization) {
622
+ for (let child = host.firstChild; child !== null; child = host.firstChild) {
623
+ host.removeChild(child);
624
+ }
625
+ }
626
+ }
627
+ if (template) {
628
+ const hasPrerenderedContent = this.hasExistingShadowRoot && this.needsInitialization;
629
+ let didHydrate = false;
630
+ if (hasPrerenderedContent && ElementController.hydrationHook) {
631
+ didHydrate = ElementController.hydrationHook(this, template, element, host);
632
+ }
633
+ if (!didHydrate) {
634
+ this.renderClientSide(template, element, host);
635
+ }
636
+ this._resolvePrerendered(hasPrerenderedContent);
637
+ this._resolveHydrated(didHydrate);
638
+ }
639
+ else if (this.needsInitialization) {
640
+ this._resolvePrerendered(false);
641
+ this._resolveHydrated(false);
642
+ }
643
+ }
644
+ /**
645
+ * Standard client-side render: clears any stale content, clones the
646
+ * compiled fragment, binds, and appends to the host.
647
+ */
648
+ renderClientSide(template, element, host) {
649
+ var _a;
650
+ if (this.hasExistingShadowRoot) {
651
+ for (let child = host.firstChild; child !== null; child = host.firstChild) {
652
+ host.removeChild(child);
653
+ }
654
+ this.hasExistingShadowRoot = false;
655
+ }
656
+ // Hosts given a scoped custom element registry must create their template's
657
+ // children against it; every other host takes the unchanged default path.
658
+ const scope = ((_a = this._shadowRootOptions) === null || _a === void 0 ? void 0 : _a.customElementRegistry) !== void 0
659
+ ? host
660
+ : void 0;
661
+ this.view = template.render(element, host, element, scope);
662
+ this.view.sourceLifetime =
663
+ SourceLifetime.coupled;
664
+ }
665
+ /**
666
+ * Locates or creates a controller for the specified element.
667
+ * @param element - The element to return the controller for.
668
+ * @param override - Reset the controller even if one has been defined.
669
+ * @remarks
670
+ * The specified element must have a {@link FASTElementDefinition}
671
+ * registered either through the use of the {@link customElement}
672
+ * decorator or a call to `FASTElement.define`.
673
+ */
674
+ static forCustomElement(element, override = false) {
675
+ const controller = element.$fastController;
676
+ if (controller !== void 0 && !override) {
677
+ return controller;
678
+ }
679
+ const definition = FASTElementDefinition.getForInstance(element);
680
+ if (definition === void 0) {
681
+ throw FAST.error(Message.missingElementDefinition);
682
+ }
683
+ Observable.getNotifier(definition).subscribe({
684
+ handleChange: () => {
685
+ ElementController.forCustomElement(element, true);
686
+ element.$fastController.connect();
687
+ },
688
+ }, "template");
689
+ Observable.getNotifier(definition).subscribe({
690
+ handleChange: () => {
691
+ ElementController.forCustomElement(element, true);
692
+ element.$fastController.connect();
693
+ },
694
+ }, "shadowOptions");
695
+ return (element.$fastController = new elementControllerStrategy(element, definition));
696
+ }
697
+ /**
698
+ * Sets the strategy that ElementController.forCustomElement uses to construct
699
+ * ElementController instances for an element.
700
+ * @param strategy - The strategy to use.
701
+ */
702
+ static setStrategy(strategy) {
703
+ elementControllerStrategy = strategy;
704
+ }
705
+ /**
706
+ * Installs the hydration hook. Called by enableHydration().
707
+ * @internal
708
+ */
709
+ static installHydrationHook(hook) {
710
+ ElementController.hydrationHook = hook;
711
+ }
712
+ }
713
+ // --- Static hydration hook ---
714
+ /**
715
+ * A hook that, when set, handles prerendered content hydration.
716
+ * Called by renderTemplate when an existing shadow root is detected.
717
+ * Returns true if hydration was performed, false to fall back to client-side.
718
+ * @internal
719
+ */
720
+ ElementController.hydrationHook = null;
721
+ makeSerializationNoop(ElementController);
722
+ // Set default strategy for ElementController
723
+ ElementController.setStrategy(ElementController);
724
+ /**
725
+ * Converts a styleTarget into the operative target. When the provided target is an Element
726
+ * that is a FASTElement, the function will return the ShadowRoot for that element. Otherwise,
727
+ * it will return the root node for the element.
728
+ * @param target
729
+ * @returns
730
+ */
731
+ function normalizeStyleTarget(target) {
732
+ var _a;
733
+ if ("adoptedStyleSheets" in target) {
734
+ return target;
735
+ }
736
+ else {
737
+ return ((_a = getShadowRoot(target)) !== null && _a !== void 0 ? _a : target.getRootNode());
738
+ }
739
+ }
740
+ // Default StyleStrategy implementations are defined in this module because they
741
+ // require access to element shadowRoots, and we don't want to leak shadowRoot
742
+ // objects out of this module.
743
+ /**
744
+ * https://wicg.github.io/construct-stylesheets/
745
+ * https://developers.google.com/web/updates/2019/02/constructable-stylesheets
746
+ *
747
+ * @internal
748
+ */
749
+ export class AdoptedStyleSheetsStrategy {
750
+ constructor(styles) {
751
+ const styleSheetCache = AdoptedStyleSheetsStrategy.styleSheetCache;
752
+ this.sheets = styles.map((x) => {
753
+ if (x instanceof CSSStyleSheet) {
754
+ return x;
755
+ }
756
+ let sheet = styleSheetCache.get(x);
757
+ if (sheet === void 0) {
758
+ sheet = new CSSStyleSheet();
759
+ sheet.replaceSync(x);
760
+ styleSheetCache.set(x, sheet);
761
+ }
762
+ return sheet;
763
+ });
764
+ }
765
+ addStylesTo(target) {
766
+ addAdoptedStyleSheets(normalizeStyleTarget(target), this.sheets);
767
+ }
768
+ removeStylesFrom(target) {
769
+ removeAdoptedStyleSheets(normalizeStyleTarget(target), this.sheets);
770
+ }
771
+ }
772
+ AdoptedStyleSheetsStrategy.styleSheetCache = new Map();
773
+ let id = 0;
774
+ const nextStyleId = () => `fast-${++id}`;
775
+ function usableStyleTarget(target) {
776
+ return target === document ? document.body : target;
777
+ }
778
+ /**
779
+ * @internal
780
+ */
781
+ export class StyleElementStrategy {
782
+ constructor(styles) {
783
+ this.styles = styles;
784
+ this.styleClass = nextStyleId();
785
+ }
786
+ addStylesTo(target) {
787
+ target = usableStyleTarget(normalizeStyleTarget(target));
788
+ const styles = this.styles;
789
+ const styleClass = this.styleClass;
790
+ for (let i = 0; i < styles.length; i++) {
791
+ const element = document.createElement("style");
792
+ element.innerHTML = styles[i];
793
+ element.className = styleClass;
794
+ target.append(element);
795
+ }
796
+ }
797
+ removeStylesFrom(target) {
798
+ target = usableStyleTarget(normalizeStyleTarget(target));
799
+ const styles = target.querySelectorAll(`.${this.styleClass}`);
800
+ for (let i = 0, ii = styles.length; i < ii; ++i) {
801
+ target.removeChild(styles[i]);
802
+ }
803
+ }
804
+ }
805
+ let addAdoptedStyleSheets = (target, sheets) => {
806
+ target.adoptedStyleSheets = [...target.adoptedStyleSheets, ...sheets];
807
+ };
808
+ let removeAdoptedStyleSheets = (target, sheets) => {
809
+ target.adoptedStyleSheets = target.adoptedStyleSheets.filter((x) => sheets.indexOf(x) === -1);
810
+ };
811
+ if (ElementStyles.supportsAdoptedStyleSheets) {
812
+ try {
813
+ // Test if browser implementation uses FrozenArray.
814
+ // If not, use push / splice to alter the stylesheets
815
+ // in place. This circumvents a bug in Safari 16.4 where
816
+ // periodically, assigning the array would previously
817
+ // cause sheets to be removed.
818
+ document.adoptedStyleSheets.push();
819
+ document.adoptedStyleSheets.splice();
820
+ addAdoptedStyleSheets = (target, sheets) => {
821
+ target.adoptedStyleSheets.push(...sheets);
822
+ };
823
+ removeAdoptedStyleSheets = (target, sheets) => {
824
+ for (const sheet of sheets) {
825
+ const index = target.adoptedStyleSheets.indexOf(sheet);
826
+ if (index !== -1) {
827
+ target.adoptedStyleSheets.splice(index, 1);
828
+ }
829
+ }
830
+ };
831
+ }
832
+ catch (_e) {
833
+ // Do nothing if an error is thrown, the default
834
+ // case handles FrozenArray.
835
+ }
836
+ ElementStyles.setDefaultStrategy(AdoptedStyleSheetsStrategy);
837
+ }
838
+ else {
839
+ ElementStyles.setDefaultStrategy(StyleElementStrategy);
840
+ }