ripple 0.2.106 → 0.2.108
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.
- package/package.json +1 -1
- package/src/compiler/phases/1-parse/index.js +33 -3
- package/src/compiler/phases/2-analyze/index.js +14 -1
- package/src/compiler/phases/3-transform/client/index.js +56 -27
- package/src/compiler/phases/3-transform/server/index.js +34 -34
- package/src/compiler/types/index.d.ts +2 -2
- package/src/compiler/utils.js +29 -1
- package/src/runtime/internal/client/blocks.js +7 -7
- package/src/runtime/internal/client/composite.js +4 -4
- package/src/runtime/internal/client/context.js +51 -51
- package/src/runtime/internal/client/css.js +2 -2
- package/src/runtime/internal/client/html.js +7 -4
- package/src/runtime/internal/client/index.js +1 -1
- package/src/runtime/internal/client/render.js +167 -167
- package/src/runtime/internal/client/runtime.js +7 -5
- package/src/runtime/internal/client/template.js +69 -63
- package/src/runtime/internal/client/try.js +127 -125
- package/src/runtime/internal/client/utils.js +5 -5
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
import { destroy_block, ref } from './blocks.js';
|
|
4
4
|
import { REF_PROP } from './constants.js';
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
get_descriptors,
|
|
7
|
+
get_own_property_symbols,
|
|
8
|
+
get_prototype_of,
|
|
9
|
+
is_tracked_object,
|
|
10
10
|
} from './utils.js';
|
|
11
11
|
import { delegate, event } from './events.js';
|
|
12
12
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
get_attribute_event_name,
|
|
14
|
+
is_delegated,
|
|
15
|
+
is_event_attribute,
|
|
16
16
|
} from '../../../utils/events.js';
|
|
17
17
|
import { get } from './runtime.js';
|
|
18
18
|
import { clsx } from 'clsx';
|
|
@@ -24,14 +24,14 @@ import { normalize_css_property_name } from '../../../utils/normalize_css_proper
|
|
|
24
24
|
* @returns {void}
|
|
25
25
|
*/
|
|
26
26
|
export function set_text(text, value) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
// For objects, we apply string coercion
|
|
28
|
+
var str = value == null ? '' : typeof value === 'object' ? value + '' : value;
|
|
29
|
+
// @ts-expect-error
|
|
30
|
+
if (str !== (text.__t ??= text.nodeValue)) {
|
|
31
|
+
// @ts-expect-error
|
|
32
|
+
text.__t = str;
|
|
33
|
+
text.nodeValue = str + '';
|
|
34
|
+
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/** @type {Map<string, string[]>} */
|
|
@@ -42,29 +42,29 @@ var setters_cache = new Map();
|
|
|
42
42
|
* @returns {string[]}
|
|
43
43
|
*/
|
|
44
44
|
function get_setters(element) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
45
|
+
var setters = setters_cache.get(element.nodeName);
|
|
46
|
+
if (setters) return setters;
|
|
47
|
+
setters_cache.set(element.nodeName, (setters = []));
|
|
48
|
+
|
|
49
|
+
var descriptors;
|
|
50
|
+
var proto = element; // In the case of custom elements there might be setters on the instance
|
|
51
|
+
var element_proto = Element.prototype;
|
|
52
|
+
|
|
53
|
+
// Stop at Element, from there on there's only unnecessary setters we're not interested in
|
|
54
|
+
// Do not use constructor.name here as that's unreliable in some browser environments
|
|
55
|
+
while (element_proto !== proto) {
|
|
56
|
+
descriptors = get_descriptors(proto);
|
|
57
|
+
|
|
58
|
+
for (var key in descriptors) {
|
|
59
|
+
if (descriptors[key].set) {
|
|
60
|
+
setters.push(key);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
proto = get_prototype_of(proto);
|
|
65
|
+
}
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
return setters;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
/**
|
|
@@ -74,25 +74,25 @@ function get_setters(element) {
|
|
|
74
74
|
* @returns {void}
|
|
75
75
|
*/
|
|
76
76
|
export function set_attribute(element, attribute, value) {
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
// @ts-expect-error
|
|
78
|
+
var attributes = (element.__attributes ??= {});
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
if (attributes[attribute] === (attributes[attribute] = value)) return;
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
if (attribute === 'style' && '__styles' in element) {
|
|
83
|
+
// reset styles to force style: directive to update
|
|
84
|
+
element.__styles = {};
|
|
85
|
+
}
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
if (value == null) {
|
|
88
|
+
element.removeAttribute(attribute);
|
|
89
|
+
} else if (attribute === 'style' && typeof value !== 'string') {
|
|
90
90
|
apply_styles(/** @type {HTMLElement} */ (element), value);
|
|
91
91
|
} else if (typeof value !== 'string' && get_setters(element).includes(attribute)) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
/** @type {any} */ (element)[attribute] = value;
|
|
93
|
+
} else {
|
|
94
|
+
element.setAttribute(attribute, value);
|
|
95
|
+
}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
/**
|
|
@@ -103,7 +103,7 @@ export function apply_styles(element, newStyles) {
|
|
|
103
103
|
const style = element.style;
|
|
104
104
|
const new_properties = new Set();
|
|
105
105
|
|
|
106
|
-
for(const [property, value] of Object.entries(newStyles)) {
|
|
106
|
+
for (const [property, value] of Object.entries(newStyles)) {
|
|
107
107
|
const normalized_property = normalize_css_property_name(property);
|
|
108
108
|
const normalized_value = String(value);
|
|
109
109
|
|
|
@@ -128,37 +128,37 @@ export function apply_styles(element, newStyles) {
|
|
|
128
128
|
* @returns {void}
|
|
129
129
|
*/
|
|
130
130
|
export function set_attributes(element, attributes) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
131
|
+
for (const key in attributes) {
|
|
132
|
+
if (key === 'children') continue;
|
|
133
|
+
|
|
134
|
+
let value = attributes[key];
|
|
135
|
+
|
|
136
|
+
if (is_tracked_object(value)) {
|
|
137
|
+
value = get(value);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (key === 'class') {
|
|
141
|
+
const is_html = element.namespaceURI === 'http://www.w3.org/1999/xhtml';
|
|
142
|
+
set_class(/** @type {HTMLElement} */ (element), value, undefined, is_html);
|
|
143
|
+
} else if (key === '#class') {
|
|
144
|
+
// Special case for static class when spreading props
|
|
145
|
+
element.classList.add(value);
|
|
146
|
+
} else if (is_event_attribute(key)) {
|
|
147
|
+
// Handle event handlers in spread props
|
|
148
|
+
const event_name = get_attribute_event_name(key);
|
|
149
|
+
|
|
150
|
+
if (is_delegated(event_name)) {
|
|
151
|
+
// Use delegation for delegated events
|
|
152
|
+
/** @type {any} */ (element)['__' + event_name] = value;
|
|
153
|
+
delegate([event_name]);
|
|
154
|
+
} else {
|
|
155
|
+
// Use addEventListener for non-delegated events
|
|
156
|
+
event(event_name, element, value);
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
set_attribute(element, key, value);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
/**
|
|
@@ -167,7 +167,7 @@ export function set_attributes(element, attributes) {
|
|
|
167
167
|
* @returns {string}
|
|
168
168
|
*/
|
|
169
169
|
function to_class(value, hash) {
|
|
170
|
-
|
|
170
|
+
return value == null ? (hash ?? '') : clsx([value, hash]);
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
/**
|
|
@@ -178,27 +178,27 @@ function to_class(value, hash) {
|
|
|
178
178
|
* @returns {void}
|
|
179
179
|
*/
|
|
180
180
|
export function set_class(dom, value, hash, is_html = true) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
181
|
+
// @ts-expect-error need to add __className to patched prototype
|
|
182
|
+
var prev_class_name = dom.__className;
|
|
183
|
+
var next_class_name = to_class(value, hash);
|
|
184
|
+
|
|
185
|
+
if (prev_class_name !== next_class_name) {
|
|
186
|
+
// Removing the attribute when the value is only an empty string causes
|
|
187
|
+
// peformance issues vs simply making the className an empty string. So
|
|
188
|
+
// we should only remove the class if the the value is nullish.
|
|
189
|
+
if (value == null && !hash) {
|
|
190
|
+
dom.removeAttribute('class');
|
|
191
|
+
} else {
|
|
192
|
+
if (is_html) {
|
|
193
|
+
dom.className = next_class_name;
|
|
194
|
+
} else {
|
|
195
|
+
dom.setAttribute('class', next_class_name);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// @ts-expect-error need to add __className to patched prototype
|
|
200
|
+
dom.__className = next_class_name;
|
|
201
|
+
}
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
/**
|
|
@@ -207,21 +207,21 @@ export function set_class(dom, value, hash, is_html = true) {
|
|
|
207
207
|
* @returns {void}
|
|
208
208
|
*/
|
|
209
209
|
export function set_value(element, value) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
210
|
+
// @ts-expect-error
|
|
211
|
+
var attributes = (element.__attributes ??= {});
|
|
212
|
+
|
|
213
|
+
if (
|
|
214
|
+
attributes.value ===
|
|
215
|
+
(attributes.value =
|
|
216
|
+
// treat null and undefined the same for the initial value
|
|
217
|
+
value ?? undefined) ||
|
|
218
|
+
// `progress` elements always need their value set when it's `0`
|
|
219
|
+
(element.value === value && (value !== 0 || element.nodeName !== 'PROGRESS'))
|
|
220
|
+
) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
element.value = value ?? '';
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
/**
|
|
@@ -230,19 +230,19 @@ export function set_value(element, value) {
|
|
|
230
230
|
* @returns {void}
|
|
231
231
|
*/
|
|
232
232
|
export function set_checked(element, checked) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
233
|
+
// @ts-expect-error
|
|
234
|
+
var attributes = (element.__attributes ??= {});
|
|
235
|
+
|
|
236
|
+
if (
|
|
237
|
+
attributes.checked ===
|
|
238
|
+
(attributes.checked =
|
|
239
|
+
// treat null and undefined the same for the initial value
|
|
240
|
+
checked ?? undefined)
|
|
241
|
+
) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
element.checked = checked;
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
/**
|
|
@@ -251,15 +251,15 @@ export function set_checked(element, checked) {
|
|
|
251
251
|
* @returns {void}
|
|
252
252
|
*/
|
|
253
253
|
export function set_selected(element, selected) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
254
|
+
if (selected) {
|
|
255
|
+
// The selected option could've changed via user selection, and
|
|
256
|
+
// setting the value without this check would set it back.
|
|
257
|
+
if (!element.hasAttribute('selected')) {
|
|
258
|
+
element.setAttribute('selected', '');
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
element.removeAttribute('selected');
|
|
262
|
+
}
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
/**
|
|
@@ -268,35 +268,35 @@ export function set_selected(element, selected) {
|
|
|
268
268
|
* @returns {() => void}
|
|
269
269
|
*/
|
|
270
270
|
export function apply_element_spread(element, fn) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
271
|
+
/** @type {Record<string | symbol, any> | undefined} */
|
|
272
|
+
var prev;
|
|
273
|
+
/** @type {Record<symbol, Block>} */
|
|
274
|
+
var effects = {};
|
|
275
|
+
|
|
276
|
+
return () => {
|
|
277
|
+
var next = fn();
|
|
278
|
+
|
|
279
|
+
for (let symbol of get_own_property_symbols(effects)) {
|
|
280
|
+
if (!next[symbol]) {
|
|
281
|
+
destroy_block(effects[symbol]);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
284
|
|
|
285
|
-
|
|
286
|
-
|
|
285
|
+
for (const symbol of get_own_property_symbols(next)) {
|
|
286
|
+
var ref_fn = next[symbol];
|
|
287
287
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
288
|
+
if (symbol.description === REF_PROP && (!prev || ref_fn !== prev[symbol])) {
|
|
289
|
+
if (effects[symbol]) {
|
|
290
|
+
destroy_block(effects[symbol]);
|
|
291
|
+
}
|
|
292
|
+
effects[symbol] = ref(element, () => ref_fn);
|
|
293
|
+
}
|
|
294
294
|
|
|
295
|
-
|
|
296
|
-
|
|
295
|
+
next[symbol] = ref_fn;
|
|
296
|
+
}
|
|
297
297
|
|
|
298
|
-
|
|
298
|
+
set_attributes(element, next);
|
|
299
299
|
|
|
300
|
-
|
|
301
|
-
|
|
300
|
+
prev = next;
|
|
301
|
+
};
|
|
302
302
|
}
|
|
@@ -412,7 +412,7 @@ function is_tracking_dirty(tracking) {
|
|
|
412
412
|
var tracked = tracking.t;
|
|
413
413
|
|
|
414
414
|
if ((tracked.f & DERIVED) !== 0) {
|
|
415
|
-
update_derived(/** @type {Derived} **/(tracked));
|
|
415
|
+
update_derived(/** @type {Derived} **/ (tracked));
|
|
416
416
|
}
|
|
417
417
|
|
|
418
418
|
if (tracked.c > tracking.c) {
|
|
@@ -472,7 +472,7 @@ export function async_computed(fn, block) {
|
|
|
472
472
|
}
|
|
473
473
|
|
|
474
474
|
promise.then((v) => {
|
|
475
|
-
if (parent && is_destroyed(/** @type {Block} */(parent))) {
|
|
475
|
+
if (parent && is_destroyed(/** @type {Block} */ (parent))) {
|
|
476
476
|
return;
|
|
477
477
|
}
|
|
478
478
|
if (promise === current && t.v !== v) {
|
|
@@ -746,7 +746,7 @@ export function get(tracked) {
|
|
|
746
746
|
}
|
|
747
747
|
|
|
748
748
|
return (tracked.f & DERIVED) !== 0
|
|
749
|
-
? get_derived(/** @type {Derived} */(tracked))
|
|
749
|
+
? get_derived(/** @type {Derived} */ (tracked))
|
|
750
750
|
: get_tracked(tracked);
|
|
751
751
|
}
|
|
752
752
|
|
|
@@ -775,7 +775,9 @@ export function get_tracked(tracked) {
|
|
|
775
775
|
*/
|
|
776
776
|
export function set(tracked, value, block) {
|
|
777
777
|
if (!is_mutating_allowed) {
|
|
778
|
-
throw new Error(
|
|
778
|
+
throw new Error(
|
|
779
|
+
'Assignments or updates to tracked values are not allowed during computed "track(() => ...)" evaluation',
|
|
780
|
+
);
|
|
779
781
|
}
|
|
780
782
|
|
|
781
783
|
var old_value = tracked.v;
|
|
@@ -1152,7 +1154,7 @@ export async function maybe_tracked(v) {
|
|
|
1152
1154
|
} else {
|
|
1153
1155
|
value = await async_computed(async () => {
|
|
1154
1156
|
return await get_tracked(v);
|
|
1155
|
-
}, /** @type {Block} */(active_block));
|
|
1157
|
+
}, /** @type {Block} */ (active_block));
|
|
1156
1158
|
}
|
|
1157
1159
|
} else {
|
|
1158
1160
|
value = await v;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/** @import { Block } from '#client' */
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
TEMPLATE_FRAGMENT,
|
|
5
|
+
TEMPLATE_USE_IMPORT_NODE,
|
|
6
|
+
TEMPLATE_SVG_NAMESPACE,
|
|
7
|
+
TEMPLATE_MATHML_NAMESPACE,
|
|
8
8
|
} from '../../../constants.js';
|
|
9
9
|
import { first_child, is_firefox } from './operations.js';
|
|
10
10
|
import { active_block } from './runtime.js';
|
|
@@ -15,17 +15,17 @@ import { active_block } from './runtime.js';
|
|
|
15
15
|
* @param {Node} end - The end node.
|
|
16
16
|
*/
|
|
17
17
|
export function assign_nodes(start, end) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
var block = /** @type {Block} */ (active_block);
|
|
19
|
+
var s = block.s;
|
|
20
|
+
if (s === null) {
|
|
21
|
+
block.s = {
|
|
22
|
+
start,
|
|
23
|
+
end,
|
|
24
|
+
};
|
|
25
|
+
} else if (s.start === null) {
|
|
26
|
+
s.start = start;
|
|
27
|
+
s.end = end;
|
|
28
|
+
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -35,16 +35,20 @@ export function assign_nodes(start, end) {
|
|
|
35
35
|
* @param {boolean} use_mathml_namespace - Whether to use MathML namespace.
|
|
36
36
|
* @returns {DocumentFragment}
|
|
37
37
|
*/
|
|
38
|
-
export function create_fragment_from_html(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
export function create_fragment_from_html(
|
|
39
|
+
html,
|
|
40
|
+
use_svg_namespace = false,
|
|
41
|
+
use_mathml_namespace = false,
|
|
42
|
+
) {
|
|
43
|
+
if (use_svg_namespace) {
|
|
44
|
+
return from_namespace(html, 'svg');
|
|
45
|
+
}
|
|
46
|
+
if (use_mathml_namespace) {
|
|
47
|
+
return from_namespace(html, 'math');
|
|
48
|
+
}
|
|
49
|
+
var elem = document.createElement('template');
|
|
50
|
+
elem.innerHTML = html;
|
|
51
|
+
return elem.content;
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
/**
|
|
@@ -54,38 +58,40 @@ export function create_fragment_from_html(html, use_svg_namespace = false, use_m
|
|
|
54
58
|
* @returns {() => Node}
|
|
55
59
|
*/
|
|
56
60
|
export function template(content, flags) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
var is_fragment = (flags & TEMPLATE_FRAGMENT) !== 0;
|
|
62
|
+
var use_import_node = (flags & TEMPLATE_USE_IMPORT_NODE) !== 0;
|
|
63
|
+
var use_svg_namespace = (flags & TEMPLATE_SVG_NAMESPACE) !== 0;
|
|
64
|
+
var use_mathml_namespace = (flags & TEMPLATE_MATHML_NAMESPACE) !== 0;
|
|
65
|
+
/** @type {Node | DocumentFragment | undefined} */
|
|
66
|
+
var node;
|
|
67
|
+
var has_start = !content.startsWith('<!>');
|
|
64
68
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
return () => {
|
|
70
|
+
if (node === undefined) {
|
|
71
|
+
node = create_fragment_from_html(
|
|
72
|
+
has_start ? content : '<!>' + content,
|
|
73
|
+
use_svg_namespace,
|
|
74
|
+
use_mathml_namespace,
|
|
75
|
+
);
|
|
76
|
+
if (!is_fragment) node = /** @type {Node} */ (first_child(node));
|
|
77
|
+
}
|
|
74
78
|
|
|
75
|
-
|
|
76
|
-
|
|
79
|
+
var clone =
|
|
80
|
+
use_import_node || is_firefox
|
|
81
|
+
? document.importNode(/** @type {Node} */ (node), true)
|
|
82
|
+
: /** @type {Node} */ (node).cloneNode(true);
|
|
77
83
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
if (is_fragment) {
|
|
85
|
+
var start = first_child(clone);
|
|
86
|
+
var end = clone.lastChild;
|
|
81
87
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
assign_nodes(/** @type {Node} */ (start), /** @type {Node} */ (end));
|
|
89
|
+
} else {
|
|
90
|
+
assign_nodes(clone, clone);
|
|
91
|
+
}
|
|
86
92
|
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
return clone;
|
|
94
|
+
};
|
|
89
95
|
}
|
|
90
96
|
|
|
91
97
|
/**
|
|
@@ -94,7 +100,7 @@ export function template(content, flags) {
|
|
|
94
100
|
* @param {Node} dom - The DOM node to append.
|
|
95
101
|
*/
|
|
96
102
|
export function append(anchor, dom) {
|
|
97
|
-
|
|
103
|
+
anchor.before(/** @type {Node} */ (dom));
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
/**
|
|
@@ -104,18 +110,18 @@ export function append(anchor, dom) {
|
|
|
104
110
|
* @returns {DocumentFragment}
|
|
105
111
|
*/
|
|
106
112
|
function from_namespace(content, ns = 'svg') {
|
|
107
|
-
|
|
113
|
+
var wrapped = `<${ns}>${content}</${ns}>`;
|
|
108
114
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
115
|
+
var elem = document.createElement('template');
|
|
116
|
+
elem.innerHTML = wrapped;
|
|
117
|
+
var fragment = elem.content;
|
|
112
118
|
|
|
113
|
-
|
|
114
|
-
|
|
119
|
+
var root = /** @type {Element} */ (first_child(fragment));
|
|
120
|
+
var result = document.createDocumentFragment();
|
|
115
121
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
while (first_child(root)) {
|
|
123
|
+
result.appendChild(/** @type {Node} */ (first_child(root)));
|
|
124
|
+
}
|
|
119
125
|
|
|
120
|
-
|
|
126
|
+
return result;
|
|
121
127
|
}
|