@rxdi/lit-html 0.7.157 → 0.7.159

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 (95) hide show
  1. package/dist/async.d.ts +3 -3
  2. package/dist/async.js +4 -4
  3. package/dist/decorators/component.decorator.d.ts +1 -2
  4. package/dist/decorators/component.decorator.js +3 -3
  5. package/dist/index.d.ts +28 -17
  6. package/dist/index.js +28 -17
  7. package/package.json +4 -2
  8. package/dist/lit-element/decorators.d.ts +0 -14
  9. package/dist/lit-element/decorators.js +0 -32
  10. package/dist/lit-element/experimental-hydrate-support.d.ts +0 -6
  11. package/dist/lit-element/experimental-hydrate-support.js +0 -65
  12. package/dist/lit-element/index.d.ts +0 -7
  13. package/dist/lit-element/index.js +0 -25
  14. package/dist/lit-element/lit-element.d.ts +0 -157
  15. package/dist/lit-element/lit-element.js +0 -258
  16. package/dist/lit-element/polyfill-support.d.ts +0 -24
  17. package/dist/lit-element/polyfill-support.js +0 -58
  18. package/dist/lit-element/private-ssr-support.d.ts +0 -21
  19. package/dist/lit-element/private-ssr-support.js +0 -25
  20. package/dist/lit-html/async-directive.d.ts +0 -170
  21. package/dist/lit-html/async-directive.js +0 -250
  22. package/dist/lit-html/directive-helpers.d.ts +0 -105
  23. package/dist/lit-html/directive-helpers.js +0 -192
  24. package/dist/lit-html/directive.d.ts +0 -65
  25. package/dist/lit-html/directive.js +0 -52
  26. package/dist/lit-html/directives/async-append.d.ts +0 -38
  27. package/dist/lit-html/directives/async-append.js +0 -55
  28. package/dist/lit-html/directives/async-replace.d.ts +0 -39
  29. package/dist/lit-html/directives/async-replace.js +0 -112
  30. package/dist/lit-html/directives/cache.d.ts +0 -34
  31. package/dist/lit-html/directives/cache.js +0 -80
  32. package/dist/lit-html/directives/class-map.d.ts +0 -44
  33. package/dist/lit-html/directives/class-map.js +0 -92
  34. package/dist/lit-html/directives/guard.d.ts +0 -59
  35. package/dist/lit-html/directives/guard.js +0 -82
  36. package/dist/lit-html/directives/if-defined.d.ts +0 -13
  37. package/dist/lit-html/directives/if-defined.js +0 -17
  38. package/dist/lit-html/directives/live.d.ts +0 -42
  39. package/dist/lit-html/directives/live.js +0 -79
  40. package/dist/lit-html/directives/private-async-helpers.d.ts +0 -57
  41. package/dist/lit-html/directives/private-async-helpers.js +0 -117
  42. package/dist/lit-html/directives/ref.d.ts +0 -65
  43. package/dist/lit-html/directives/ref.js +0 -113
  44. package/dist/lit-html/directives/repeat.d.ts +0 -63
  45. package/dist/lit-html/directives/repeat.js +0 -416
  46. package/dist/lit-html/directives/style-map.d.ts +0 -46
  47. package/dist/lit-html/directives/style-map.js +0 -102
  48. package/dist/lit-html/directives/template-content.d.ts +0 -25
  49. package/dist/lit-html/directives/template-content.js +0 -33
  50. package/dist/lit-html/directives/unsafe-html.d.ts +0 -26
  51. package/dist/lit-html/directives/unsafe-html.js +0 -64
  52. package/dist/lit-html/directives/unsafe-svg.d.ts +0 -26
  53. package/dist/lit-html/directives/unsafe-svg.js +0 -26
  54. package/dist/lit-html/directives/until.d.ts +0 -43
  55. package/dist/lit-html/directives/until.js +0 -137
  56. package/dist/lit-html/experimental-hydrate.d.ts +0 -50
  57. package/dist/lit-html/experimental-hydrate.js +0 -322
  58. package/dist/lit-html/lit-html.d.ts +0 -335
  59. package/dist/lit-html/lit-html.js +0 -1259
  60. package/dist/lit-html/polyfill-support.d.ts +0 -67
  61. package/dist/lit-html/polyfill-support.js +0 -185
  62. package/dist/lit-html/private-ssr-support.d.ts +0 -52
  63. package/dist/lit-html/private-ssr-support.js +0 -54
  64. package/dist/lit-html/static.d.ts +0 -58
  65. package/dist/lit-html/static.js +0 -114
  66. package/dist/reactive-element/css-tag.d.ts +0 -64
  67. package/dist/reactive-element/css-tag.js +0 -125
  68. package/dist/reactive-element/decorators/base.d.ts +0 -47
  69. package/dist/reactive-element/decorators/base.js +0 -70
  70. package/dist/reactive-element/decorators/custom-element.d.ts +0 -26
  71. package/dist/reactive-element/decorators/custom-element.js +0 -47
  72. package/dist/reactive-element/decorators/event-options.d.ts +0 -37
  73. package/dist/reactive-element/decorators/event-options.js +0 -47
  74. package/dist/reactive-element/decorators/index.d.ts +0 -14
  75. package/dist/reactive-element/decorators/index.js +0 -32
  76. package/dist/reactive-element/decorators/property.d.ts +0 -40
  77. package/dist/reactive-element/decorators/property.js +0 -92
  78. package/dist/reactive-element/decorators/query-all.d.ts +0 -31
  79. package/dist/reactive-element/decorators/query-all.js +0 -46
  80. package/dist/reactive-element/decorators/query-assigned-nodes.d.ts +0 -33
  81. package/dist/reactive-element/decorators/query-assigned-nodes.js +0 -55
  82. package/dist/reactive-element/decorators/query-async.d.ts +0 -39
  83. package/dist/reactive-element/decorators/query-async.js +0 -71
  84. package/dist/reactive-element/decorators/query.d.ts +0 -32
  85. package/dist/reactive-element/decorators/query.js +0 -60
  86. package/dist/reactive-element/decorators/state.d.ts +0 -24
  87. package/dist/reactive-element/decorators/state.js +0 -29
  88. package/dist/reactive-element/index.d.ts +0 -5
  89. package/dist/reactive-element/index.js +0 -17
  90. package/dist/reactive-element/polyfill-support.d.ts +0 -40
  91. package/dist/reactive-element/polyfill-support.js +0 -89
  92. package/dist/reactive-element/reactive-controller.d.ts +0 -76
  93. package/dist/reactive-element/reactive-controller.js +0 -7
  94. package/dist/reactive-element/reactive-element.d.ts +0 -653
  95. package/dist/reactive-element/reactive-element.js +0 -979
@@ -1,416 +0,0 @@
1
- "use strict";
2
- /**
3
- * @license
4
- * Copyright 2017 Google LLC
5
- * SPDX-License-Identifier: BSD-3-Clause
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.repeat = void 0;
9
- const lit_html_1 = require("../lit-html");
10
- const directive_1 = require("../directive");
11
- const directive_helpers_1 = require("../directive-helpers");
12
- // Helper for generating a map of array item to its index over a subset
13
- // of an array (used to lazily generate `newKeyToIndexMap` and
14
- // `oldKeyToIndexMap`)
15
- const generateMap = (list, start, end) => {
16
- const map = new Map();
17
- for (let i = start; i <= end; i++) {
18
- map.set(list[i], i);
19
- }
20
- return map;
21
- };
22
- class RepeatDirective extends directive_1.Directive {
23
- constructor(partInfo) {
24
- super(partInfo);
25
- if (partInfo.type !== directive_1.PartType.CHILD) {
26
- throw new Error('repeat() can only be used in text expressions');
27
- }
28
- }
29
- _getValuesAndKeys(items, keyFnOrTemplate, template) {
30
- let keyFn;
31
- if (template === undefined) {
32
- template = keyFnOrTemplate;
33
- }
34
- else if (keyFnOrTemplate !== undefined) {
35
- keyFn = keyFnOrTemplate;
36
- }
37
- const keys = [];
38
- const values = [];
39
- let index = 0;
40
- for (const item of items) {
41
- keys[index] = keyFn ? keyFn(item, index) : index;
42
- values[index] = template(item, index);
43
- index++;
44
- }
45
- return {
46
- values,
47
- keys,
48
- };
49
- }
50
- render(items, keyFnOrTemplate, template) {
51
- return this._getValuesAndKeys(items, keyFnOrTemplate, template).values;
52
- }
53
- update(containerPart, [items, keyFnOrTemplate, template]) {
54
- var _a;
55
- // Old part & key lists are retrieved from the last update (which may
56
- // be primed by hydration)
57
- const oldParts = (0, directive_helpers_1.getCommittedValue)(containerPart);
58
- const { values: newValues, keys: newKeys } = this._getValuesAndKeys(items, keyFnOrTemplate, template);
59
- // We check that oldParts, the committed value, is an Array as an
60
- // indicator that the previous value came from a repeat() call. If
61
- // oldParts is not an Array then this is the first render and we return
62
- // an array for lit-html's array handling to render, and remember the
63
- // keys.
64
- if (!Array.isArray(oldParts)) {
65
- this._itemKeys = newKeys;
66
- return newValues;
67
- }
68
- // In SSR hydration it's possible for oldParts to be an arrray but for us
69
- // to not have item keys because the update() hasn't run yet. We set the
70
- // keys to an empty array. This will cause all oldKey/newKey comparisons
71
- // to fail and execution to fall to the last nested brach below which
72
- // reuses the oldPart.
73
- const oldKeys = ((_a = this._itemKeys) !== null && _a !== void 0 ? _a : (this._itemKeys = []));
74
- // New part list will be built up as we go (either reused from
75
- // old parts or created for new keys in this update). This is
76
- // saved in the above cache at the end of the update.
77
- const newParts = [];
78
- // Maps from key to index for current and previous update; these
79
- // are generated lazily only when needed as a performance
80
- // optimization, since they are only required for multiple
81
- // non-contiguous changes in the list, which are less common.
82
- let newKeyToIndexMap;
83
- let oldKeyToIndexMap;
84
- // Head and tail pointers to old parts and new values
85
- let oldHead = 0;
86
- let oldTail = oldParts.length - 1;
87
- let newHead = 0;
88
- let newTail = newValues.length - 1;
89
- // Overview of O(n) reconciliation algorithm (general approach
90
- // based on ideas found in ivi, vue, snabbdom, etc.):
91
- //
92
- // * We start with the list of old parts and new values (and
93
- // arrays of their respective keys), head/tail pointers into
94
- // each, and we build up the new list of parts by updating
95
- // (and when needed, moving) old parts or creating new ones.
96
- // The initial scenario might look like this (for brevity of
97
- // the diagrams, the numbers in the array reflect keys
98
- // associated with the old parts or new values, although keys
99
- // and parts/values are actually stored in parallel arrays
100
- // indexed using the same head/tail pointers):
101
- //
102
- // oldHead v v oldTail
103
- // oldKeys: [0, 1, 2, 3, 4, 5, 6]
104
- // newParts: [ , , , , , , ]
105
- // newKeys: [0, 2, 1, 4, 3, 7, 6] <- reflects the user's new
106
- // item order
107
- // newHead ^ ^ newTail
108
- //
109
- // * Iterate old & new lists from both sides, updating,
110
- // swapping, or removing parts at the head/tail locations
111
- // until neither head nor tail can move.
112
- //
113
- // * Example below: keys at head pointers match, so update old
114
- // part 0 in-place (no need to move it) and record part 0 in
115
- // the `newParts` list. The last thing we do is advance the
116
- // `oldHead` and `newHead` pointers (will be reflected in the
117
- // next diagram).
118
- //
119
- // oldHead v v oldTail
120
- // oldKeys: [0, 1, 2, 3, 4, 5, 6]
121
- // newParts: [0, , , , , , ] <- heads matched: update 0
122
- // newKeys: [0, 2, 1, 4, 3, 7, 6] and advance both oldHead
123
- // & newHead
124
- // newHead ^ ^ newTail
125
- //
126
- // * Example below: head pointers don't match, but tail
127
- // pointers do, so update part 6 in place (no need to move
128
- // it), and record part 6 in the `newParts` list. Last,
129
- // advance the `oldTail` and `oldHead` pointers.
130
- //
131
- // oldHead v v oldTail
132
- // oldKeys: [0, 1, 2, 3, 4, 5, 6]
133
- // newParts: [0, , , , , , 6] <- tails matched: update 6
134
- // newKeys: [0, 2, 1, 4, 3, 7, 6] and advance both oldTail
135
- // & newTail
136
- // newHead ^ ^ newTail
137
- //
138
- // * If neither head nor tail match; next check if one of the
139
- // old head/tail items was removed. We first need to generate
140
- // the reverse map of new keys to index (`newKeyToIndexMap`),
141
- // which is done once lazily as a performance optimization,
142
- // since we only hit this case if multiple non-contiguous
143
- // changes were made. Note that for contiguous removal
144
- // anywhere in the list, the head and tails would advance
145
- // from either end and pass each other before we get to this
146
- // case and removals would be handled in the final while loop
147
- // without needing to generate the map.
148
- //
149
- // * Example below: The key at `oldTail` was removed (no longer
150
- // in the `newKeyToIndexMap`), so remove that part from the
151
- // DOM and advance just the `oldTail` pointer.
152
- //
153
- // oldHead v v oldTail
154
- // oldKeys: [0, 1, 2, 3, 4, 5, 6]
155
- // newParts: [0, , , , , , 6] <- 5 not in new map: remove
156
- // newKeys: [0, 2, 1, 4, 3, 7, 6] 5 and advance oldTail
157
- // newHead ^ ^ newTail
158
- //
159
- // * Once head and tail cannot move, any mismatches are due to
160
- // either new or moved items; if a new key is in the previous
161
- // "old key to old index" map, move the old part to the new
162
- // location, otherwise create and insert a new part. Note
163
- // that when moving an old part we null its position in the
164
- // oldParts array if it lies between the head and tail so we
165
- // know to skip it when the pointers get there.
166
- //
167
- // * Example below: neither head nor tail match, and neither
168
- // were removed; so find the `newHead` key in the
169
- // `oldKeyToIndexMap`, and move that old part's DOM into the
170
- // next head position (before `oldParts[oldHead]`). Last,
171
- // null the part in the `oldPart` array since it was
172
- // somewhere in the remaining oldParts still to be scanned
173
- // (between the head and tail pointers) so that we know to
174
- // skip that old part on future iterations.
175
- //
176
- // oldHead v v oldTail
177
- // oldKeys: [0, 1, -, 3, 4, 5, 6]
178
- // newParts: [0, 2, , , , , 6] <- stuck: update & move 2
179
- // newKeys: [0, 2, 1, 4, 3, 7, 6] into place and advance
180
- // newHead
181
- // newHead ^ ^ newTail
182
- //
183
- // * Note that for moves/insertions like the one above, a part
184
- // inserted at the head pointer is inserted before the
185
- // current `oldParts[oldHead]`, and a part inserted at the
186
- // tail pointer is inserted before `newParts[newTail+1]`. The
187
- // seeming asymmetry lies in the fact that new parts are
188
- // moved into place outside in, so to the right of the head
189
- // pointer are old parts, and to the right of the tail
190
- // pointer are new parts.
191
- //
192
- // * We always restart back from the top of the algorithm,
193
- // allowing matching and simple updates in place to
194
- // continue...
195
- //
196
- // * Example below: the head pointers once again match, so
197
- // simply update part 1 and record it in the `newParts`
198
- // array. Last, advance both head pointers.
199
- //
200
- // oldHead v v oldTail
201
- // oldKeys: [0, 1, -, 3, 4, 5, 6]
202
- // newParts: [0, 2, 1, , , , 6] <- heads matched: update 1
203
- // newKeys: [0, 2, 1, 4, 3, 7, 6] and advance both oldHead
204
- // & newHead
205
- // newHead ^ ^ newTail
206
- //
207
- // * As mentioned above, items that were moved as a result of
208
- // being stuck (the final else clause in the code below) are
209
- // marked with null, so we always advance old pointers over
210
- // these so we're comparing the next actual old value on
211
- // either end.
212
- //
213
- // * Example below: `oldHead` is null (already placed in
214
- // newParts), so advance `oldHead`.
215
- //
216
- // oldHead v v oldTail
217
- // oldKeys: [0, 1, -, 3, 4, 5, 6] <- old head already used:
218
- // newParts: [0, 2, 1, , , , 6] advance oldHead
219
- // newKeys: [0, 2, 1, 4, 3, 7, 6]
220
- // newHead ^ ^ newTail
221
- //
222
- // * Note it's not critical to mark old parts as null when they
223
- // are moved from head to tail or tail to head, since they
224
- // will be outside the pointer range and never visited again.
225
- //
226
- // * Example below: Here the old tail key matches the new head
227
- // key, so the part at the `oldTail` position and move its
228
- // DOM to the new head position (before `oldParts[oldHead]`).
229
- // Last, advance `oldTail` and `newHead` pointers.
230
- //
231
- // oldHead v v oldTail
232
- // oldKeys: [0, 1, -, 3, 4, 5, 6]
233
- // newParts: [0, 2, 1, 4, , , 6] <- old tail matches new
234
- // newKeys: [0, 2, 1, 4, 3, 7, 6] head: update & move 4,
235
- // advance oldTail & newHead
236
- // newHead ^ ^ newTail
237
- //
238
- // * Example below: Old and new head keys match, so update the
239
- // old head part in place, and advance the `oldHead` and
240
- // `newHead` pointers.
241
- //
242
- // oldHead v oldTail
243
- // oldKeys: [0, 1, -, 3, 4, 5, 6]
244
- // newParts: [0, 2, 1, 4, 3, ,6] <- heads match: update 3
245
- // newKeys: [0, 2, 1, 4, 3, 7, 6] and advance oldHead &
246
- // newHead
247
- // newHead ^ ^ newTail
248
- //
249
- // * Once the new or old pointers move past each other then all
250
- // we have left is additions (if old list exhausted) or
251
- // removals (if new list exhausted). Those are handled in the
252
- // final while loops at the end.
253
- //
254
- // * Example below: `oldHead` exceeded `oldTail`, so we're done
255
- // with the main loop. Create the remaining part and insert
256
- // it at the new head position, and the update is complete.
257
- //
258
- // (oldHead > oldTail)
259
- // oldKeys: [0, 1, -, 3, 4, 5, 6]
260
- // newParts: [0, 2, 1, 4, 3, 7 ,6] <- create and insert 7
261
- // newKeys: [0, 2, 1, 4, 3, 7, 6]
262
- // newHead ^ newTail
263
- //
264
- // * Note that the order of the if/else clauses is not
265
- // important to the algorithm, as long as the null checks
266
- // come first (to ensure we're always working on valid old
267
- // parts) and that the final else clause comes last (since
268
- // that's where the expensive moves occur). The order of
269
- // remaining clauses is is just a simple guess at which cases
270
- // will be most common.
271
- //
272
- // * Note, we could calculate the longest
273
- // increasing subsequence (LIS) of old items in new position,
274
- // and only move those not in the LIS set. However that costs
275
- // O(nlogn) time and adds a bit more code, and only helps
276
- // make rare types of mutations require fewer moves. The
277
- // above handles removes, adds, reversal, swaps, and single
278
- // moves of contiguous items in linear time, in the minimum
279
- // number of moves. As the number of multiple moves where LIS
280
- // might help approaches a random shuffle, the LIS
281
- // optimization becomes less helpful, so it seems not worth
282
- // the code at this point. Could reconsider if a compelling
283
- // case arises.
284
- while (oldHead <= oldTail && newHead <= newTail) {
285
- if (oldParts[oldHead] === null) {
286
- // `null` means old part at head has already been used
287
- // below; skip
288
- oldHead++;
289
- }
290
- else if (oldParts[oldTail] === null) {
291
- // `null` means old part at tail has already been used
292
- // below; skip
293
- oldTail--;
294
- }
295
- else if (oldKeys[oldHead] === newKeys[newHead]) {
296
- // Old head matches new head; update in place
297
- newParts[newHead] = (0, directive_helpers_1.setChildPartValue)(oldParts[oldHead], newValues[newHead]);
298
- oldHead++;
299
- newHead++;
300
- }
301
- else if (oldKeys[oldTail] === newKeys[newTail]) {
302
- // Old tail matches new tail; update in place
303
- newParts[newTail] = (0, directive_helpers_1.setChildPartValue)(oldParts[oldTail], newValues[newTail]);
304
- oldTail--;
305
- newTail--;
306
- }
307
- else if (oldKeys[oldHead] === newKeys[newTail]) {
308
- // Old head matches new tail; update and move to new tail
309
- newParts[newTail] = (0, directive_helpers_1.setChildPartValue)(oldParts[oldHead], newValues[newTail]);
310
- (0, directive_helpers_1.insertPart)(containerPart, newParts[newTail + 1], oldParts[oldHead]);
311
- oldHead++;
312
- newTail--;
313
- }
314
- else if (oldKeys[oldTail] === newKeys[newHead]) {
315
- // Old tail matches new head; update and move to new head
316
- newParts[newHead] = (0, directive_helpers_1.setChildPartValue)(oldParts[oldTail], newValues[newHead]);
317
- (0, directive_helpers_1.insertPart)(containerPart, oldParts[oldHead], oldParts[oldTail]);
318
- oldTail--;
319
- newHead++;
320
- }
321
- else {
322
- if (newKeyToIndexMap === undefined) {
323
- // Lazily generate key-to-index maps, used for removals &
324
- // moves below
325
- newKeyToIndexMap = generateMap(newKeys, newHead, newTail);
326
- oldKeyToIndexMap = generateMap(oldKeys, oldHead, oldTail);
327
- }
328
- if (!newKeyToIndexMap.has(oldKeys[oldHead])) {
329
- // Old head is no longer in new list; remove
330
- (0, directive_helpers_1.removePart)(oldParts[oldHead]);
331
- oldHead++;
332
- }
333
- else if (!newKeyToIndexMap.has(oldKeys[oldTail])) {
334
- // Old tail is no longer in new list; remove
335
- (0, directive_helpers_1.removePart)(oldParts[oldTail]);
336
- oldTail--;
337
- }
338
- else {
339
- // Any mismatches at this point are due to additions or
340
- // moves; see if we have an old part we can reuse and move
341
- // into place
342
- const oldIndex = oldKeyToIndexMap.get(newKeys[newHead]);
343
- const oldPart = oldIndex !== undefined ? oldParts[oldIndex] : null;
344
- if (oldPart === null) {
345
- // No old part for this value; create a new one and
346
- // insert it
347
- const newPart = (0, directive_helpers_1.insertPart)(containerPart, oldParts[oldHead]);
348
- (0, directive_helpers_1.setChildPartValue)(newPart, newValues[newHead]);
349
- newParts[newHead] = newPart;
350
- }
351
- else {
352
- // Reuse old part
353
- newParts[newHead] = (0, directive_helpers_1.setChildPartValue)(oldPart, newValues[newHead]);
354
- (0, directive_helpers_1.insertPart)(containerPart, oldParts[oldHead], oldPart);
355
- // This marks the old part as having been used, so that
356
- // it will be skipped in the first two checks above
357
- oldParts[oldIndex] = null;
358
- }
359
- newHead++;
360
- }
361
- }
362
- }
363
- // Add parts for any remaining new values
364
- while (newHead <= newTail) {
365
- // For all remaining additions, we insert before last new
366
- // tail, since old pointers are no longer valid
367
- const newPart = (0, directive_helpers_1.insertPart)(containerPart, newParts[newTail + 1]);
368
- (0, directive_helpers_1.setChildPartValue)(newPart, newValues[newHead]);
369
- newParts[newHead++] = newPart;
370
- }
371
- // Remove any remaining unused old parts
372
- while (oldHead <= oldTail) {
373
- const oldPart = oldParts[oldHead++];
374
- if (oldPart !== null) {
375
- (0, directive_helpers_1.removePart)(oldPart);
376
- }
377
- }
378
- // Save order of new parts for next round
379
- this._itemKeys = newKeys;
380
- // Directly set part value, bypassing it's dirty-checking
381
- (0, directive_helpers_1.setCommittedValue)(containerPart, newParts);
382
- return lit_html_1.noChange;
383
- }
384
- }
385
- /**
386
- * A directive that repeats a series of values (usually `TemplateResults`)
387
- * generated from an iterable, and updates those items efficiently when the
388
- * iterable changes based on user-provided `keys` associated with each item.
389
- *
390
- * Note that if a `keyFn` is provided, strict key-to-DOM mapping is maintained,
391
- * meaning previous DOM for a given key is moved into the new position if
392
- * needed, and DOM will never be reused with values for different keys (new DOM
393
- * will always be created for new keys). This is generally the most efficient
394
- * way to use `repeat` since it performs minimum unnecessary work for insertions
395
- * and removals.
396
- *
397
- * The `keyFn` takes two parameters, the item and its index, and returns a unique key value.
398
- *
399
- * ```js
400
- * html`
401
- * <ol>
402
- * ${repeat(this.items, (item) => item.id, (item, index) => {
403
- * return html`<li>${index}: ${item.name}</li>`;
404
- * })}
405
- * </ol>
406
- * `
407
- * ```
408
- *
409
- * **Important**: If providing a `keyFn`, keys *must* be unique for all items in a
410
- * given call to `repeat`. The behavior when two or more items have the same key
411
- * is undefined.
412
- *
413
- * If no `keyFn` is provided, this directive will perform similar to mapping
414
- * items to values, and DOM will be reused against potentially different items.
415
- */
416
- exports.repeat = (0, directive_1.directive)(RepeatDirective);
@@ -1,46 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2018 Google LLC
4
- * SPDX-License-Identifier: BSD-3-Clause
5
- */
6
- import { AttributePart, noChange } from '../lit-html';
7
- import { Directive, DirectiveParameters, PartInfo } from '../directive';
8
- /**
9
- * A key-value set of CSS properties and values.
10
- *
11
- * The key should be either a valid CSS property name string, like
12
- * `'background-color'`, or a valid JavaScript camel case property name
13
- * for CSSStyleDeclaration like `backgroundColor`.
14
- */
15
- export interface StyleInfo {
16
- readonly [name: string]: string | undefined | null;
17
- }
18
- declare class StyleMapDirective extends Directive {
19
- _previousStyleProperties?: Set<string>;
20
- constructor(partInfo: PartInfo);
21
- render(styleInfo: StyleInfo): string;
22
- update(part: AttributePart, [styleInfo]: DirectiveParameters<this>): string | typeof noChange;
23
- }
24
- /**
25
- * A directive that applies CSS properties to an element.
26
- *
27
- * `styleMap` can only be used in the `style` attribute and must be the only
28
- * expression in the attribute. It takes the property names in the `styleInfo`
29
- * object and adds the property values as CSS properties. Property names with
30
- * dashes (`-`) are assumed to be valid CSS property names and set on the
31
- * element's style object using `setProperty()`. Names without dashes are
32
- * assumed to be camelCased JavaScript property names and set on the element's
33
- * style object using property assignment, allowing the style object to
34
- * translate JavaScript-style names to CSS property names.
35
- *
36
- * For example `styleMap({backgroundColor: 'red', 'border-top': '5px', '--size':
37
- * '0'})` sets the `background-color`, `border-top` and `--size` properties.
38
- *
39
- * @param styleInfo
40
- */
41
- export declare const styleMap: (styleInfo: StyleInfo) => import("../directive").DirectiveResult<typeof StyleMapDirective>;
42
- /**
43
- * The type of the class that powers this directive. Necessary for naming the
44
- * directive's return type.
45
- */
46
- export type { StyleMapDirective };
@@ -1,102 +0,0 @@
1
- "use strict";
2
- /**
3
- * @license
4
- * Copyright 2018 Google LLC
5
- * SPDX-License-Identifier: BSD-3-Clause
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.styleMap = void 0;
9
- const lit_html_1 = require("../lit-html");
10
- const directive_1 = require("../directive");
11
- class StyleMapDirective extends directive_1.Directive {
12
- constructor(partInfo) {
13
- var _a;
14
- super(partInfo);
15
- if (partInfo.type !== directive_1.PartType.ATTRIBUTE ||
16
- partInfo.name !== 'style' ||
17
- ((_a = partInfo.strings) === null || _a === void 0 ? void 0 : _a.length) > 2) {
18
- throw new Error('The `styleMap` directive must be used in the `style` attribute ' +
19
- 'and must be the only part in the attribute.');
20
- }
21
- }
22
- render(styleInfo) {
23
- return Object.keys(styleInfo).reduce((style, prop) => {
24
- const value = styleInfo[prop];
25
- if (value == null) {
26
- return style;
27
- }
28
- // Convert property names from camel-case to dash-case, i.e.:
29
- // `backgroundColor` -> `background-color`
30
- // Vendor-prefixed names need an extra `-` appended to front:
31
- // `webkitAppearance` -> `-webkit-appearance`
32
- // Exception is any property name containing a dash, including
33
- // custom properties; we assume these are already dash-cased i.e.:
34
- // `--my-button-color` --> `--my-button-color`
35
- prop = prop
36
- .replace(/(?:^(webkit|moz|ms|o)|)(?=[A-Z])/g, '-$&')
37
- .toLowerCase();
38
- return style + `${prop}:${value};`;
39
- }, '');
40
- }
41
- update(part, [styleInfo]) {
42
- const { style } = part.element;
43
- if (this._previousStyleProperties === undefined) {
44
- this._previousStyleProperties = new Set();
45
- for (const name in styleInfo) {
46
- this._previousStyleProperties.add(name);
47
- }
48
- return this.render(styleInfo);
49
- }
50
- // Remove old properties that no longer exist in styleInfo
51
- // We use forEach() instead of for-of so that re don't require down-level
52
- // iteration.
53
- this._previousStyleProperties.forEach((name) => {
54
- // If the name isn't in styleInfo or it's null/undefined
55
- if (styleInfo[name] == null) {
56
- this._previousStyleProperties.delete(name);
57
- if (name.includes('-')) {
58
- style.removeProperty(name);
59
- }
60
- else {
61
- // Note reset using empty string (vs null) as IE11 does not always
62
- // reset via null (https://developer.mozilla.org/en-US/docs/Web/API/ElementCSSInlineStyle/style#setting_styles)
63
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
- style[name] = '';
65
- }
66
- }
67
- });
68
- // Add or update properties
69
- for (const name in styleInfo) {
70
- const value = styleInfo[name];
71
- if (value != null) {
72
- this._previousStyleProperties.add(name);
73
- if (name.includes('-')) {
74
- style.setProperty(name, value);
75
- }
76
- else {
77
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
- style[name] = value;
79
- }
80
- }
81
- }
82
- return lit_html_1.noChange;
83
- }
84
- }
85
- /**
86
- * A directive that applies CSS properties to an element.
87
- *
88
- * `styleMap` can only be used in the `style` attribute and must be the only
89
- * expression in the attribute. It takes the property names in the `styleInfo`
90
- * object and adds the property values as CSS properties. Property names with
91
- * dashes (`-`) are assumed to be valid CSS property names and set on the
92
- * element's style object using `setProperty()`. Names without dashes are
93
- * assumed to be camelCased JavaScript property names and set on the element's
94
- * style object using property assignment, allowing the style object to
95
- * translate JavaScript-style names to CSS property names.
96
- *
97
- * For example `styleMap({backgroundColor: 'red', 'border-top': '5px', '--size':
98
- * '0'})` sets the `background-color`, `border-top` and `--size` properties.
99
- *
100
- * @param styleInfo
101
- */
102
- exports.styleMap = (0, directive_1.directive)(StyleMapDirective);
@@ -1,25 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2020 Google LLC
4
- * SPDX-License-Identifier: BSD-3-Clause
5
- */
6
- import { noChange } from '../lit-html';
7
- import { Directive, PartInfo } from '../directive';
8
- declare class TemplateContentDirective extends Directive {
9
- private _previousTemplate?;
10
- constructor(partInfo: PartInfo);
11
- render(template: HTMLTemplateElement): typeof noChange | DocumentFragment;
12
- }
13
- /**
14
- * Renders the content of a template element as HTML.
15
- *
16
- * Note, the template should be developer controlled and not user controlled.
17
- * Rendering a user-controlled template with this directive
18
- * could lead to cross-site-scripting vulnerabilities.
19
- */
20
- export declare const templateContent: (template: HTMLTemplateElement) => import("../directive").DirectiveResult<typeof TemplateContentDirective>;
21
- /**
22
- * The type of the class that powers this directive. Necessary for naming the
23
- * directive's return type.
24
- */
25
- export type { TemplateContentDirective };
@@ -1,33 +0,0 @@
1
- "use strict";
2
- /**
3
- * @license
4
- * Copyright 2020 Google LLC
5
- * SPDX-License-Identifier: BSD-3-Clause
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.templateContent = void 0;
9
- const lit_html_1 = require("../lit-html");
10
- const directive_1 = require("../directive");
11
- class TemplateContentDirective extends directive_1.Directive {
12
- constructor(partInfo) {
13
- super(partInfo);
14
- if (partInfo.type !== directive_1.PartType.CHILD) {
15
- throw new Error('templateContent can only be used in child bindings');
16
- }
17
- }
18
- render(template) {
19
- if (this._previousTemplate === template) {
20
- return lit_html_1.noChange;
21
- }
22
- this._previousTemplate = template;
23
- return document.importNode(template.content, true);
24
- }
25
- }
26
- /**
27
- * Renders the content of a template element as HTML.
28
- *
29
- * Note, the template should be developer controlled and not user controlled.
30
- * Rendering a user-controlled template with this directive
31
- * could lead to cross-site-scripting vulnerabilities.
32
- */
33
- exports.templateContent = (0, directive_1.directive)(TemplateContentDirective);
@@ -1,26 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2017 Google LLC
4
- * SPDX-License-Identifier: BSD-3-Clause
5
- */
6
- import { nothing, TemplateResult, noChange } from '../lit-html';
7
- import { Directive, PartInfo } from '../directive';
8
- export declare class UnsafeHTMLDirective extends Directive {
9
- static directiveName: string;
10
- static resultType: number;
11
- private _value;
12
- private _templateResult?;
13
- constructor(partInfo: PartInfo);
14
- render(value: string | typeof nothing | typeof noChange | undefined | null): string | TemplateResult<1 | 2> | typeof noChange | typeof nothing;
15
- }
16
- /**
17
- * Renders the result as HTML, rather than text.
18
- *
19
- * The values `undefined`, `null`, and `nothing`, will all result in no content
20
- * (empty string) being rendered.
21
- *
22
- * Note, this is unsafe to use with any user-provided input that hasn't been
23
- * sanitized or escaped, as it may lead to cross-site-scripting
24
- * vulnerabilities.
25
- */
26
- export declare const unsafeHTML: (value: string | typeof noChange | typeof nothing) => import("../directive").DirectiveResult<typeof UnsafeHTMLDirective>;