@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,661 @@
1
+ import { emptyArray } from "../platform.js";
2
+ import { SubscriberSet } from "./notifier.js";
3
+ import { Observable } from "./observable.js";
4
+ import { Updates } from "./update-queue.js";
5
+ /**
6
+ * A splice map is a representation of how a previous array of items
7
+ * was transformed into a new array of items. Conceptually it is a list of
8
+ * tuples of
9
+ *
10
+ * (index, removed, addedCount)
11
+ *
12
+ * which are kept in ascending index order of. The tuple represents that at
13
+ * the |index|, |removed| sequence of items were removed, and counting forward
14
+ * from |index|, |addedCount| items were added.
15
+ * @public
16
+ */
17
+ export class Splice {
18
+ /**
19
+ * Creates a splice.
20
+ * @param index - The index that the splice occurs at.
21
+ * @param removed - The items that were removed.
22
+ * @param addedCount - The number of items that were added.
23
+ */
24
+ constructor(index, removed, addedCount) {
25
+ this.index = index;
26
+ this.removed = removed;
27
+ this.addedCount = addedCount;
28
+ }
29
+ /**
30
+ * Adjusts the splice index based on the provided array.
31
+ * @param array - The array to adjust to.
32
+ * @returns The same splice, mutated based on the reference array.
33
+ */
34
+ adjustTo(array) {
35
+ let index = this.index;
36
+ const arrayLength = array.length;
37
+ if (index > arrayLength) {
38
+ index = arrayLength - this.addedCount;
39
+ }
40
+ else if (index < 0) {
41
+ index = arrayLength + this.removed.length + index - this.addedCount;
42
+ }
43
+ this.index = index < 0 ? 0 : index;
44
+ return this;
45
+ }
46
+ }
47
+ /**
48
+ * A sort array indicates new index positions of array items.
49
+ * @public
50
+ */
51
+ export class Sort {
52
+ /**
53
+ * Creates a sort update.
54
+ * @param sorted - The updated index of sorted items.
55
+ */
56
+ constructor(sorted) {
57
+ this.sorted = sorted;
58
+ }
59
+ }
60
+ /**
61
+ * Indicates what level of feature support the splice
62
+ * strategy provides.
63
+ * @public
64
+ */
65
+ export const SpliceStrategySupport = Object.freeze({
66
+ /**
67
+ * Only supports resets.
68
+ */
69
+ reset: 1,
70
+ /**
71
+ * Supports tracking splices and resets.
72
+ */
73
+ splice: 2,
74
+ /**
75
+ * Supports tracking splices and resets, while applying some form
76
+ * of optimization, such as merging, to the splices.
77
+ */
78
+ optimized: 3,
79
+ });
80
+ const reset = new Splice(0, emptyArray, 0);
81
+ reset.reset = true;
82
+ const resetSplices = [reset];
83
+ var Edit;
84
+ (function (Edit) {
85
+ Edit[Edit["leave"] = 0] = "leave";
86
+ Edit[Edit["update"] = 1] = "update";
87
+ Edit[Edit["add"] = 2] = "add";
88
+ Edit[Edit["delete"] = 3] = "delete";
89
+ })(Edit || (Edit = {}));
90
+ // Note: This function is *based* on the computation of the Levenshtein
91
+ // "edit" distance. The one change is that "updates" are treated as two
92
+ // edits - not one. With Array splices, an update is really a delete
93
+ // followed by an add. By retaining this, we optimize for "keeping" the
94
+ // maximum array items in the original array. For example:
95
+ //
96
+ // 'xxxx123' to '123yyyy'
97
+ //
98
+ // With 1-edit updates, the shortest path would be just to update all seven
99
+ // characters. With 2-edit updates, we delete 4, leave 3, and add 4. This
100
+ // leaves the substring '123' intact.
101
+ function calcEditDistances(current, currentStart, currentEnd, old, oldStart, oldEnd) {
102
+ // "Deletion" columns
103
+ const rowCount = oldEnd - oldStart + 1;
104
+ const columnCount = currentEnd - currentStart + 1;
105
+ const distances = new Array(rowCount);
106
+ let north;
107
+ let west;
108
+ // "Addition" rows. Initialize null column.
109
+ for (let i = 0; i < rowCount; ++i) {
110
+ distances[i] = new Array(columnCount);
111
+ distances[i][0] = i;
112
+ }
113
+ // Initialize null row
114
+ for (let j = 0; j < columnCount; ++j) {
115
+ distances[0][j] = j;
116
+ }
117
+ for (let i = 1; i < rowCount; ++i) {
118
+ for (let j = 1; j < columnCount; ++j) {
119
+ if (current[currentStart + j - 1] === old[oldStart + i - 1]) {
120
+ distances[i][j] = distances[i - 1][j - 1];
121
+ }
122
+ else {
123
+ north = distances[i - 1][j] + 1;
124
+ west = distances[i][j - 1] + 1;
125
+ distances[i][j] = north < west ? north : west;
126
+ }
127
+ }
128
+ }
129
+ return distances;
130
+ }
131
+ // This starts at the final weight, and walks "backward" by finding
132
+ // the minimum previous weight recursively until the origin of the weight
133
+ // matrix.
134
+ function spliceOperationsFromEditDistances(distances) {
135
+ let i = distances.length - 1;
136
+ let j = distances[0].length - 1;
137
+ let current = distances[i][j];
138
+ const edits = [];
139
+ while (i > 0 || j > 0) {
140
+ if (i === 0) {
141
+ edits.push(Edit.add);
142
+ j--;
143
+ continue;
144
+ }
145
+ if (j === 0) {
146
+ edits.push(Edit.delete);
147
+ i--;
148
+ continue;
149
+ }
150
+ const northWest = distances[i - 1][j - 1];
151
+ const west = distances[i - 1][j];
152
+ const north = distances[i][j - 1];
153
+ let min;
154
+ if (west < north) {
155
+ min = west < northWest ? west : northWest;
156
+ }
157
+ else {
158
+ min = north < northWest ? north : northWest;
159
+ }
160
+ if (min === northWest) {
161
+ if (northWest === current) {
162
+ edits.push(Edit.leave);
163
+ }
164
+ else {
165
+ edits.push(Edit.update);
166
+ current = northWest;
167
+ }
168
+ i--;
169
+ j--;
170
+ }
171
+ else if (min === west) {
172
+ edits.push(Edit.delete);
173
+ i--;
174
+ current = west;
175
+ }
176
+ else {
177
+ edits.push(Edit.add);
178
+ j--;
179
+ current = north;
180
+ }
181
+ }
182
+ return edits.reverse();
183
+ }
184
+ function sharedPrefix(current, old, searchLength) {
185
+ for (let i = 0; i < searchLength; ++i) {
186
+ if (current[i] !== old[i]) {
187
+ return i;
188
+ }
189
+ }
190
+ return searchLength;
191
+ }
192
+ function sharedSuffix(current, old, searchLength) {
193
+ let index1 = current.length;
194
+ let index2 = old.length;
195
+ let count = 0;
196
+ while (count < searchLength && current[--index1] === old[--index2]) {
197
+ count++;
198
+ }
199
+ return count;
200
+ }
201
+ function intersect(start1, end1, start2, end2) {
202
+ // Disjoint
203
+ if (end1 < start2 || end2 < start1) {
204
+ return -1;
205
+ }
206
+ // Adjacent
207
+ if (end1 === start2 || end2 === start1) {
208
+ return 0;
209
+ }
210
+ // Non-zero intersect, span1 first
211
+ if (start1 < start2) {
212
+ if (end1 < end2) {
213
+ return end1 - start2; // Overlap
214
+ }
215
+ return end2 - start2; // Contained
216
+ }
217
+ // Non-zero intersect, span2 first
218
+ if (end2 < end1) {
219
+ return end2 - start1; // Overlap
220
+ }
221
+ return end1 - start1; // Contained
222
+ }
223
+ /**
224
+ * @remarks
225
+ * Lacking individual splice mutation information, the minimal set of
226
+ * splices can be synthesized given the previous state and final state of an
227
+ * array. The basic approach is to calculate the edit distance matrix and
228
+ * choose the shortest path through it.
229
+ *
230
+ * Complexity: O(l * p)
231
+ * l: The length of the current array
232
+ * p: The length of the old array
233
+ */
234
+ function calc(current, currentStart, currentEnd, old, oldStart, oldEnd) {
235
+ let prefixCount = 0;
236
+ let suffixCount = 0;
237
+ const minLength = Math.min(currentEnd - currentStart, oldEnd - oldStart);
238
+ if (currentStart === 0 && oldStart === 0) {
239
+ prefixCount = sharedPrefix(current, old, minLength);
240
+ }
241
+ if (currentEnd === current.length && oldEnd === old.length) {
242
+ suffixCount = sharedSuffix(current, old, minLength - prefixCount);
243
+ }
244
+ currentStart += prefixCount;
245
+ oldStart += prefixCount;
246
+ currentEnd -= suffixCount;
247
+ oldEnd -= suffixCount;
248
+ if (currentEnd - currentStart === 0 && oldEnd - oldStart === 0) {
249
+ return emptyArray;
250
+ }
251
+ if (currentStart === currentEnd) {
252
+ const splice = new Splice(currentStart, [], 0);
253
+ while (oldStart < oldEnd) {
254
+ splice.removed.push(old[oldStart++]);
255
+ }
256
+ return [splice];
257
+ }
258
+ else if (oldStart === oldEnd) {
259
+ return [new Splice(currentStart, [], currentEnd - currentStart)];
260
+ }
261
+ const ops = spliceOperationsFromEditDistances(calcEditDistances(current, currentStart, currentEnd, old, oldStart, oldEnd));
262
+ const splices = [];
263
+ let splice = void 0;
264
+ let index = currentStart;
265
+ let oldIndex = oldStart;
266
+ for (let i = 0; i < ops.length; ++i) {
267
+ switch (ops[i]) {
268
+ case Edit.leave:
269
+ if (splice !== void 0) {
270
+ splices.push(splice);
271
+ splice = void 0;
272
+ }
273
+ index++;
274
+ oldIndex++;
275
+ break;
276
+ case Edit.update:
277
+ if (splice === void 0) {
278
+ splice = new Splice(index, [], 0);
279
+ }
280
+ splice.addedCount++;
281
+ index++;
282
+ splice.removed.push(old[oldIndex]);
283
+ oldIndex++;
284
+ break;
285
+ case Edit.add:
286
+ if (splice === void 0) {
287
+ splice = new Splice(index, [], 0);
288
+ }
289
+ splice.addedCount++;
290
+ index++;
291
+ break;
292
+ case Edit.delete:
293
+ if (splice === void 0) {
294
+ splice = new Splice(index, [], 0);
295
+ }
296
+ splice.removed.push(old[oldIndex]);
297
+ oldIndex++;
298
+ break;
299
+ // no default
300
+ }
301
+ }
302
+ if (splice !== void 0) {
303
+ splices.push(splice);
304
+ }
305
+ return splices;
306
+ }
307
+ function merge(splice, splices) {
308
+ let inserted = false;
309
+ let insertionOffset = 0;
310
+ for (let i = 0; i < splices.length; i++) {
311
+ const current = splices[i];
312
+ current.index += insertionOffset;
313
+ if (inserted) {
314
+ continue;
315
+ }
316
+ const intersectCount = intersect(splice.index, splice.index + splice.removed.length, current.index, current.index + current.addedCount);
317
+ if (intersectCount >= 0) {
318
+ // Merge the two splices
319
+ splices.splice(i, 1);
320
+ i--;
321
+ insertionOffset -= current.addedCount - current.removed.length;
322
+ splice.addedCount += current.addedCount - intersectCount;
323
+ const deleteCount = splice.removed.length + current.removed.length - intersectCount;
324
+ if (!splice.addedCount && !deleteCount) {
325
+ // merged splice is a noop. discard.
326
+ inserted = true;
327
+ }
328
+ else {
329
+ let currentRemoved = current.removed;
330
+ if (splice.index < current.index) {
331
+ // some prefix of splice.removed is prepended to current.removed.
332
+ const prepend = splice.removed.slice(0, current.index - splice.index);
333
+ prepend.push(...currentRemoved);
334
+ currentRemoved = prepend;
335
+ }
336
+ if (splice.index + splice.removed.length >
337
+ current.index + current.addedCount) {
338
+ // some suffix of splice.removed is appended to current.removed.
339
+ const append = splice.removed.slice(current.index + current.addedCount - splice.index);
340
+ currentRemoved.push(...append);
341
+ }
342
+ splice.removed = currentRemoved;
343
+ if (current.index < splice.index) {
344
+ splice.index = current.index;
345
+ }
346
+ }
347
+ }
348
+ else if (splice.index < current.index) {
349
+ // Insert splice here.
350
+ inserted = true;
351
+ splices.splice(i, 0, splice);
352
+ i++;
353
+ const offset = splice.addedCount - splice.removed.length;
354
+ current.index += offset;
355
+ insertionOffset += offset;
356
+ }
357
+ }
358
+ if (!inserted) {
359
+ splices.push(splice);
360
+ }
361
+ }
362
+ function project(array, changes) {
363
+ let splices = [];
364
+ const initialSplices = [];
365
+ for (let i = 0, ii = changes.length; i < ii; i++) {
366
+ merge(changes[i], initialSplices);
367
+ }
368
+ for (let i = 0, ii = initialSplices.length; i < ii; ++i) {
369
+ const splice = initialSplices[i];
370
+ if (splice.addedCount === 1 && splice.removed.length === 1) {
371
+ if (splice.removed[0] !== array[splice.index]) {
372
+ splices.push(splice);
373
+ }
374
+ continue;
375
+ }
376
+ splices = splices.concat(calc(array, splice.index, splice.index + splice.addedCount, splice.removed, 0, splice.removed.length));
377
+ }
378
+ return splices;
379
+ }
380
+ /**
381
+ * A SpliceStrategy that attempts to merge all splices into the minimal set of
382
+ * splices needed to represent the change from the old array to the new array.
383
+ * @public
384
+ */
385
+ let defaultMutationStrategy = Object.freeze({
386
+ support: SpliceStrategySupport.optimized,
387
+ normalize(previous, current, changes) {
388
+ if (previous === void 0) {
389
+ if (changes === void 0) {
390
+ return emptyArray;
391
+ }
392
+ return project(current, changes);
393
+ }
394
+ return resetSplices;
395
+ },
396
+ pop(array, observer, pop, args) {
397
+ const notEmpty = array.length > 0;
398
+ const result = pop.apply(array, args);
399
+ if (notEmpty) {
400
+ observer.addSplice(new Splice(array.length, [result], 0));
401
+ }
402
+ return result;
403
+ },
404
+ push(array, observer, push, args) {
405
+ const result = push.apply(array, args);
406
+ observer.addSplice(new Splice(array.length - args.length, [], args.length).adjustTo(array));
407
+ return result;
408
+ },
409
+ reverse(array, observer, reverse, args) {
410
+ const result = reverse.apply(array, args);
411
+ array.sorted++;
412
+ const sortedItems = [];
413
+ for (let i = array.length - 1; i >= 0; i--) {
414
+ sortedItems.push(i);
415
+ }
416
+ observer.addSort(new Sort(sortedItems));
417
+ return result;
418
+ },
419
+ shift(array, observer, shift, args) {
420
+ const notEmpty = array.length > 0;
421
+ const result = shift.apply(array, args);
422
+ if (notEmpty) {
423
+ observer.addSplice(new Splice(0, [result], 0));
424
+ }
425
+ return result;
426
+ },
427
+ sort(array, observer, sort, args) {
428
+ const map = new Map();
429
+ for (let i = 0, ii = array.length; i < ii; ++i) {
430
+ const mapValue = map.get(array[i]) || [];
431
+ map.set(array[i], [...mapValue, i]);
432
+ }
433
+ const result = sort.apply(array, args);
434
+ array.sorted++;
435
+ const sortedItems = [];
436
+ for (let i = 0, ii = array.length; i < ii; ++i) {
437
+ const indexs = map.get(array[i]);
438
+ sortedItems.push(indexs[0]);
439
+ map.set(array[i], indexs.splice(1));
440
+ }
441
+ observer.addSort(new Sort(sortedItems));
442
+ return result;
443
+ },
444
+ splice(array, observer, splice, args) {
445
+ const result = splice.apply(array, args);
446
+ observer.addSplice(new Splice(+args[0], result, args.length > 2 ? args.length - 2 : 0).adjustTo(array));
447
+ return result;
448
+ },
449
+ unshift(array, observer, unshift, args) {
450
+ const result = unshift.apply(array, args);
451
+ observer.addSplice(new Splice(0, [], args.length).adjustTo(array));
452
+ return result;
453
+ },
454
+ });
455
+ /**
456
+ * Functionality related to tracking changes in arrays.
457
+ * @public
458
+ */
459
+ export const SpliceStrategy = Object.freeze({
460
+ /**
461
+ * A set of changes that represent a full array reset.
462
+ */
463
+ reset: resetSplices,
464
+ /**
465
+ * Sets the default strategy to use for array observers.
466
+ * @param strategy - The splice strategy to use.
467
+ */
468
+ setDefaultStrategy(strategy) {
469
+ defaultMutationStrategy = strategy;
470
+ },
471
+ });
472
+ function setNonEnumerable(target, property, value, writable = true) {
473
+ Reflect.defineProperty(target, property, {
474
+ value,
475
+ enumerable: false,
476
+ writable,
477
+ });
478
+ }
479
+ class DefaultArrayObserver extends SubscriberSet {
480
+ get strategy() {
481
+ return this._strategy;
482
+ }
483
+ set strategy(value) {
484
+ this._strategy = value;
485
+ }
486
+ get lengthObserver() {
487
+ let observer = this._lengthObserver;
488
+ if (observer === void 0) {
489
+ const array = this.subject;
490
+ this._lengthObserver = observer = {
491
+ length: array.length,
492
+ handleChange() {
493
+ if (this.length !== array.length) {
494
+ this.length = array.length;
495
+ Observable.notify(observer, "length");
496
+ }
497
+ },
498
+ };
499
+ this.subscribe(observer);
500
+ }
501
+ return observer;
502
+ }
503
+ get sortObserver() {
504
+ let observer = this._sortObserver;
505
+ if (observer === void 0) {
506
+ const array = this.subject;
507
+ this._sortObserver = observer = {
508
+ sorted: array.sorted,
509
+ handleChange() {
510
+ if (this.sorted !== array.sorted) {
511
+ this.sorted = array.sorted;
512
+ Observable.notify(observer, "sorted");
513
+ }
514
+ },
515
+ };
516
+ this.subscribe(observer);
517
+ }
518
+ return observer;
519
+ }
520
+ constructor(subject) {
521
+ super(subject);
522
+ this.oldCollection = void 0;
523
+ this.splices = void 0;
524
+ this.sorts = void 0;
525
+ this.needsQueue = true;
526
+ this._strategy = null;
527
+ this._lengthObserver = void 0;
528
+ this._sortObserver = void 0;
529
+ this.call = this.flush;
530
+ setNonEnumerable(subject, "$fastController", this);
531
+ }
532
+ subscribe(subscriber) {
533
+ this.flush();
534
+ super.subscribe(subscriber);
535
+ }
536
+ addSplice(splice) {
537
+ if (this.splices === void 0) {
538
+ this.splices = [splice];
539
+ }
540
+ else {
541
+ this.splices.push(splice);
542
+ }
543
+ this.enqueue();
544
+ }
545
+ addSort(sort) {
546
+ if (this.sorts === void 0) {
547
+ this.sorts = [sort];
548
+ }
549
+ else {
550
+ this.sorts.push(sort);
551
+ }
552
+ this.enqueue();
553
+ }
554
+ reset(oldCollection) {
555
+ this.oldCollection = oldCollection;
556
+ this.enqueue();
557
+ }
558
+ flush() {
559
+ var _a;
560
+ const splices = this.splices;
561
+ const sorts = this.sorts;
562
+ const oldCollection = this.oldCollection;
563
+ if (splices === void 0 && oldCollection === void 0 && sorts === void 0) {
564
+ return;
565
+ }
566
+ this.needsQueue = true;
567
+ this.splices = void 0;
568
+ this.sorts = void 0;
569
+ this.oldCollection = void 0;
570
+ sorts !== void 0
571
+ ? this.notify(sorts)
572
+ : this.notify(((_a = this._strategy) !== null && _a !== void 0 ? _a : defaultMutationStrategy).normalize(oldCollection, this.subject, splices));
573
+ }
574
+ enqueue() {
575
+ if (this.needsQueue) {
576
+ this.needsQueue = false;
577
+ Updates.enqueue(this);
578
+ }
579
+ }
580
+ }
581
+ let enabled = false;
582
+ /**
583
+ * An observer for arrays.
584
+ * @public
585
+ */
586
+ export const ArrayObserver = Object.freeze({
587
+ sorted: 0,
588
+ /**
589
+ * Enables the array observation mechanism.
590
+ * @remarks
591
+ * Array observation is enabled automatically when using the
592
+ * `RepeatDirective`, so calling this API manually is
593
+ * not typically necessary.
594
+ */
595
+ enable() {
596
+ if (enabled) {
597
+ return;
598
+ }
599
+ enabled = true;
600
+ Observable.setArrayObserverFactory((collection) => new DefaultArrayObserver(collection));
601
+ const proto = Array.prototype;
602
+ if (!proto.$fastPatch) {
603
+ setNonEnumerable(proto, "$fastPatch", 1);
604
+ setNonEnumerable(proto, "sorted", 0);
605
+ [
606
+ proto.pop,
607
+ proto.push,
608
+ proto.reverse,
609
+ proto.shift,
610
+ proto.sort,
611
+ proto.splice,
612
+ proto.unshift,
613
+ ].forEach(method => {
614
+ proto[method.name] = function (...args) {
615
+ var _a;
616
+ const o = this.$fastController;
617
+ return o === void 0
618
+ ? method.apply(this, args)
619
+ : ((_a = o.strategy) !== null && _a !== void 0 ? _a : defaultMutationStrategy)[method.name](this, o, method, args);
620
+ };
621
+ });
622
+ }
623
+ },
624
+ });
625
+ /**
626
+ * Enables observing the length of an array.
627
+ * @param array - The array to observe the length of.
628
+ * @returns The length of the array.
629
+ * @public
630
+ */
631
+ export function lengthOf(array) {
632
+ if (!array) {
633
+ return 0;
634
+ }
635
+ let arrayObserver = array.$fastController;
636
+ if (arrayObserver === void 0) {
637
+ ArrayObserver.enable();
638
+ arrayObserver = Observable.getNotifier(array);
639
+ }
640
+ Observable.track(arrayObserver.lengthObserver, "length");
641
+ return array.length;
642
+ }
643
+ /**
644
+ * Enables observing the sorted property of an array.
645
+ * @param array - The array to observe the sorted property of.
646
+ * @returns The sorted property.
647
+ * @public
648
+ */
649
+ export function sortedCount(array) {
650
+ if (!array) {
651
+ return 0;
652
+ }
653
+ let arrayObserver = array.$fastController;
654
+ if (arrayObserver === void 0) {
655
+ ArrayObserver.enable();
656
+ arrayObserver = Observable.getNotifier(array);
657
+ }
658
+ Observable.track(arrayObserver.sortObserver, "sorted");
659
+ return array.sorted;
660
+ }
661
+ export { SubscriberSet } from "./notifier.js";