ripple 0.2.107 → 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.
@@ -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
- get_descriptors,
7
- get_own_property_symbols,
8
- get_prototype_of,
9
- is_tracked_object,
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
- get_attribute_event_name,
14
- is_delegated,
15
- is_event_attribute,
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
- // 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
- }
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
- 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
- }
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
- proto = get_prototype_of(proto);
65
- }
64
+ proto = get_prototype_of(proto);
65
+ }
66
66
 
67
- return setters;
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
- // @ts-expect-error
78
- var attributes = (element.__attributes ??= {});
77
+ // @ts-expect-error
78
+ var attributes = (element.__attributes ??= {});
79
79
 
80
- if (attributes[attribute] === (attributes[attribute] = value)) return;
80
+ if (attributes[attribute] === (attributes[attribute] = value)) return;
81
81
 
82
- if (attribute === 'style' && '__styles' in element) {
83
- // reset styles to force style: directive to update
84
- element.__styles = {};
85
- }
82
+ if (attribute === 'style' && '__styles' in element) {
83
+ // reset styles to force style: directive to update
84
+ element.__styles = {};
85
+ }
86
86
 
87
- if (value == null) {
88
- element.removeAttribute(attribute);
89
- } else if (attribute === 'style' && typeof value !== 'string') {
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
- /** @type {any} */ (element)[attribute] = value;
93
- } else {
94
- element.setAttribute(attribute, value);
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
- 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
- }
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
- return value == null ? hash ?? '' : clsx([value, hash]);
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
- // @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
- }
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
- // @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 ?? '';
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
- // @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;
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
- 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
- }
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
- /** @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
- }
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
- for (const symbol of get_own_property_symbols(next)) {
286
- var ref_fn = next[symbol];
285
+ for (const symbol of get_own_property_symbols(next)) {
286
+ var ref_fn = next[symbol];
287
287
 
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
- }
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
- next[symbol] = ref_fn;
296
- }
295
+ next[symbol] = ref_fn;
296
+ }
297
297
 
298
- set_attributes(element, next);
298
+ set_attributes(element, next);
299
299
 
300
- prev = next;
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('Assignments or updates to tracked values are not allowed during computed "track(() => ...)" evaluation');
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
- TEMPLATE_FRAGMENT,
5
- TEMPLATE_USE_IMPORT_NODE,
6
- TEMPLATE_SVG_NAMESPACE,
7
- TEMPLATE_MATHML_NAMESPACE,
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
- 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
- }
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(html, use_svg_namespace = false, use_mathml_namespace = false) {
39
- if (use_svg_namespace) {
40
- return from_namespace(html, 'svg');
41
- }
42
- if (use_mathml_namespace) {
43
- return from_namespace(html, 'math');
44
- }
45
- var elem = document.createElement('template');
46
- elem.innerHTML = html;
47
- return elem.content;
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
- var is_fragment = (flags & TEMPLATE_FRAGMENT) !== 0;
58
- var use_import_node = (flags & TEMPLATE_USE_IMPORT_NODE) !== 0;
59
- var use_svg_namespace = (flags & TEMPLATE_SVG_NAMESPACE) !== 0;
60
- var use_mathml_namespace = (flags & TEMPLATE_MATHML_NAMESPACE) !== 0;
61
- /** @type {Node | DocumentFragment | undefined} */
62
- var node;
63
- var has_start = !content.startsWith('<!>');
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
- return () => {
66
- if (node === undefined) {
67
- node = create_fragment_from_html(
68
- has_start ? content : '<!>' + content,
69
- use_svg_namespace,
70
- use_mathml_namespace,
71
- );
72
- if (!is_fragment) node = /** @type {Node} */ (first_child(node));
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
- var clone =
76
- use_import_node || is_firefox ? document.importNode(/** @type {Node} */ (node), true) : /** @type {Node} */ (node).cloneNode(true);
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
- if (is_fragment) {
79
- var start = first_child(clone);
80
- var end = clone.lastChild;
84
+ if (is_fragment) {
85
+ var start = first_child(clone);
86
+ var end = clone.lastChild;
81
87
 
82
- assign_nodes(/** @type {Node} */ (start), /** @type {Node} */ (end));
83
- } else {
84
- assign_nodes(clone, clone);
85
- }
88
+ assign_nodes(/** @type {Node} */ (start), /** @type {Node} */ (end));
89
+ } else {
90
+ assign_nodes(clone, clone);
91
+ }
86
92
 
87
- return clone;
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
- anchor.before(/** @type {Node} */ (dom));
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
- var wrapped = `<${ns}>${content}</${ns}>`;
113
+ var wrapped = `<${ns}>${content}</${ns}>`;
108
114
 
109
- var elem = document.createElement('template');
110
- elem.innerHTML = wrapped;
111
- var fragment = elem.content;
115
+ var elem = document.createElement('template');
116
+ elem.innerHTML = wrapped;
117
+ var fragment = elem.content;
112
118
 
113
- var root = /** @type {Element} */ (first_child(fragment));
114
- var result = document.createDocumentFragment();
119
+ var root = /** @type {Element} */ (first_child(fragment));
120
+ var result = document.createDocumentFragment();
115
121
 
116
- while (first_child(root)) {
117
- result.appendChild(/** @type {Node} */ (first_child(root)));
118
- }
122
+ while (first_child(root)) {
123
+ result.appendChild(/** @type {Node} */ (first_child(root)));
124
+ }
119
125
 
120
- return result;
126
+ return result;
121
127
  }