@panphora/clayjs 0.1.0 → 0.2.0

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.
@@ -0,0 +1,428 @@
1
+ // a nice, simple alert
2
+ // ❗️ don't use too much text!
3
+
4
+ // Default modern icons (normalized to 48x48 viewBox)
5
+ const defaultIcons = {
6
+ success: `<svg viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M13.9404 23.9475L21.9099 31.224L35.1906 15.9045M3 4.5H44.9804V44.309H3V4.5Z" stroke="#33D131" stroke-width="4.3"/></svg>`,
7
+ error: `<svg viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M32.7383 14.4045L14 33.1429M32.7451 33.1429L14.0068 14.4046M3.01 4H44.99V43.809H3.01V4Z" stroke="#FF4450" stroke-width="4"/></svg>`,
8
+ warning: `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke="#F5A623" stroke-width="2" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z"/></svg>`,
9
+ info: `<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke="#4A90D9" stroke-width="2" d="m11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z"/></svg>`
10
+ };
11
+
12
+ // Hyperclay icons
13
+ export const hyperclayIcons = {
14
+ success: `<svg viewBox="0 0 33 33" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M32 1h-5v3.5h-2.5V8h-2v3.5H20V15h-2.5v3.5h-2V22H13v3.5H9V22H7v-3.5H6V15H1v3.5h1V22h2v3.5h1.5V29H7v3.5h5V29h3.5v-3.5H18V22h2.5v-3.5h2V15H25v-3.5h2.5V8h2V4.5H32V1Z" fill="#76C824"/></svg>`,
15
+ error: `<svg viewBox="0 0 33 33" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M33 1h-5v3.5h-3.5V8H21v3.5h-3.5V15h-2v-3.5H12V8H8.5V4.5H5V1H0v3.5h3.5V8H7v3.5h3.5V15H14v3.5h-3.5V22H7v3.5H3.5V29H0v3.5h5V29h3.5v-3.5H12V22h3.5v-3.5h2V22H21v3.5h3.5V29H28v3.5h5V29h-3.5v-3.5H26V22h-3.5v-3.5H19V15h3.5v-3.5H26V8h3.5V4.5H33V1Z" fill="#DD304F"/></svg>`,
16
+ warning: `<svg viewBox="0 0 33 33" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M18 1h-3v3h-2v3h-2v3H9v3H7v3H5v3H3v3H1v6h31v-6h-2v-3h-2v-3h-2v-3h-2v-3h-2V7h-2V4h-2V1zm-2 8h1v10h-1V9zm0 13h1v2h-1v-2z" fill="#F5A623"/></svg>`,
17
+ info: `<svg viewBox="0 0 33 33" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M12 1v3H9v3H6v3H3v6h3v3h3v3h3v3h9v-3h3v-3h3v-3h3v-6h-3V7h-3V4h-3V1H12zm4 7h1v2h-1V8zm0 5h1v9h-1v-9z" fill="#4A90D9"/></svg>`
18
+ };
19
+
20
+ // Default templates
21
+ const defaultTemplates = {
22
+ toast: {
23
+ success: `
24
+ <div class="toast hide success noise-texture">
25
+ <div class="toast-icon">{icon}</div>
26
+ <div class="toast-message">{message}</div>
27
+ </div>
28
+ `,
29
+ error: `
30
+ <div class="toast hide error noise-texture">
31
+ <div class="toast-icon">{icon}</div>
32
+ <div class="toast-message">{message}</div>
33
+ </div>
34
+ `,
35
+ warning: `
36
+ <div class="toast hide warning noise-texture">
37
+ <div class="toast-icon">{icon}</div>
38
+ <div class="toast-message">{message}</div>
39
+ </div>
40
+ `,
41
+ info: `
42
+ <div class="toast hide info noise-texture">
43
+ <div class="toast-icon">{icon}</div>
44
+ <div class="toast-message">{message}</div>
45
+ </div>
46
+ `
47
+ }
48
+ };
49
+
50
+ // Hyperclay templates
51
+ export const hyperclayTemplates = {
52
+ toast: {
53
+ success: `
54
+ <div class="toast hide success">
55
+ {icon}
56
+ <span class="message">{message}</span>
57
+ </div>
58
+ `,
59
+ error: `
60
+ <div class="toast hide error">
61
+ {icon}
62
+ <span class="message">{message}</span>
63
+ </div>
64
+ `,
65
+ warning: `
66
+ <div class="toast hide warning">
67
+ {icon}
68
+ <span class="message">{message}</span>
69
+ </div>
70
+ `,
71
+ info: `
72
+ <div class="toast hide info">
73
+ {icon}
74
+ <span class="message">{message}</span>
75
+ </div>
76
+ `
77
+ }
78
+ };
79
+
80
+ // Modern styles (scoped by data-toast-theme="modern")
81
+ const modernStyles = `
82
+ [data-toast-theme="modern"].toast-container {
83
+ z-index: 9999;
84
+ position: fixed;
85
+ top: 20px;
86
+ right: 20px;
87
+ display: flex;
88
+ flex-direction: column;
89
+ align-items: end;
90
+ gap: 18px;
91
+ }
92
+
93
+ [data-toast-theme="modern"] .toast {
94
+ position: relative;
95
+ right: 0;
96
+ cursor: pointer;
97
+ transition: right 0.5s ease-in-out, opacity 0.5s ease-in-out;
98
+ display: flex;
99
+ align-items: center;
100
+ gap: 12px;
101
+ padding: 16px 24px 16px 16px;
102
+ font-size: var(--hyperclay-toast-font-size, 16px);
103
+ font-family: var(--hyperclay-toast-font-family, monospace);
104
+ font-weight: bold;
105
+ color: white;
106
+ border-width: 1px;
107
+ border-style: solid;
108
+ }
109
+
110
+ [data-toast-theme="modern"] .toast.hide {
111
+ right: -400px;
112
+ opacity: 0;
113
+ }
114
+
115
+ [data-toast-theme="modern"] .toast.success {
116
+ border-color: #358234;
117
+ background: radial-gradient(85.86% 68.42% at 50% 68.42%, #142419 0%, #1D3927 100%);
118
+ }
119
+
120
+ [data-toast-theme="modern"] .toast.error {
121
+ border-color: #992930;
122
+ background: radial-gradient(85.86% 68.42% at 50% 68.42%, #240A13 0%, #481826 100%);
123
+ }
124
+
125
+ [data-toast-theme="modern"] .toast.warning {
126
+ border-color: #B8860B;
127
+ background: radial-gradient(85.86% 68.42% at 50% 68.42%, #2A2010 0%, #3D3018 100%);
128
+ }
129
+
130
+ [data-toast-theme="modern"] .toast.info {
131
+ border-color: #2E6B9E;
132
+ background: radial-gradient(85.86% 68.42% at 50% 68.42%, #0A1A24 0%, #162D3D 100%);
133
+ }
134
+
135
+ [data-toast-theme="modern"] .toast-icon {
136
+ position: relative;
137
+ top: -1px;
138
+ }
139
+
140
+ [data-toast-theme="modern"] .toast-icon svg {
141
+ display: block;
142
+ width: 22px;
143
+ height: 22px;
144
+ }
145
+
146
+ [data-toast-theme="modern"] .toast.info .toast-icon svg {
147
+ width: 24px;
148
+ height: 24px;
149
+ }
150
+
151
+ [data-toast-theme="modern"] .toast-message {
152
+ position: relative;
153
+ top: -1px;
154
+ }
155
+
156
+ [data-toast-theme="modern"] .noise-texture {
157
+ position: relative;
158
+ }
159
+
160
+ [data-toast-theme="modern"] .noise-texture::before {
161
+ content: "";
162
+ position: absolute;
163
+ top: 0;
164
+ left: 0;
165
+ width: 100%;
166
+ height: 100%;
167
+ opacity: 0.12;
168
+ pointer-events: none;
169
+ background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.2' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
170
+ background-repeat: repeat;
171
+ }
172
+ `;
173
+
174
+ // Hyperclay styles (scoped by data-toast-theme="hyperclay")
175
+ export const hyperclayStyles = `
176
+ [data-toast-theme="hyperclay"].toast-container {
177
+ z-index: 9999;
178
+ position: fixed;
179
+ top: 20px;
180
+ right: 20px;
181
+ display: flex;
182
+ flex-direction: column;
183
+ align-items: end;
184
+ }
185
+
186
+ [data-toast-theme="hyperclay"].toast-container > * + * {
187
+ margin-top: 18px;
188
+ }
189
+
190
+ [data-toast-theme="hyperclay"] .toast {
191
+ position: relative;
192
+ right: 0;
193
+ display: flex;
194
+ align-items: center;
195
+ padding: 10px 19px 11px 17px;
196
+ cursor: pointer;
197
+ color: rgba(255,255,255,.8);
198
+ background-color: #0B0C12;
199
+ border: 2px dashed rgba(255,255,255,.6);
200
+ transition: right 0.5s ease-in-out;
201
+ font-size: var(--hyperclay-toast-font-size, inherit);
202
+ font-family: var(--hyperclay-toast-font-family, inherit);
203
+ }
204
+
205
+ [data-toast-theme="hyperclay"] .toast svg {
206
+ position: relative;
207
+ top: -1px;
208
+ width: 17px;
209
+ height: 17px;
210
+ margin-right: 13px;
211
+ }
212
+
213
+ [data-toast-theme="hyperclay"] .toast.hide {
214
+ right: -300px;
215
+ }
216
+
217
+ [data-toast-theme="hyperclay"] .toast.success {
218
+ color: #76C824;
219
+ border: 2px dashed #589E11;
220
+ }
221
+
222
+ [data-toast-theme="hyperclay"] .toast.error {
223
+ color: #DD304F;
224
+ border: 2px dashed #CD2140;
225
+ }
226
+
227
+ [data-toast-theme="hyperclay"] .toast.warning {
228
+ color: #F5A623;
229
+ border: 2px dashed #D4900E;
230
+ }
231
+
232
+ [data-toast-theme="hyperclay"] .toast.info {
233
+ color: #4A90D9;
234
+ border: 2px dashed #3A7BBF;
235
+ }
236
+ `;
237
+
238
+ // Global toast configuration (can be overridden by toast-hyperclay module)
239
+ let toastConfig = {
240
+ styles: modernStyles,
241
+ templates: defaultTemplates,
242
+ icons: defaultIcons,
243
+ theme: 'modern'
244
+ };
245
+
246
+ // Allow other modules (like toast-hyperclay) to override default toast styling
247
+ export function setToastTheme(config) {
248
+ Object.assign(toastConfig, config);
249
+ }
250
+
251
+ // Helper function to inject styles for a theme (additive, not replacing)
252
+ export function injectToastStyles(styles, theme) {
253
+ if (document.querySelector(`style.toast-styles-${theme}`)) return;
254
+
255
+ const styleSheet = document.createElement('style');
256
+ styleSheet.className = `toast-styles-${theme}`;
257
+ styleSheet.setAttribute('clay', 'no-save no-snapshot');
258
+ styleSheet.textContent = styles;
259
+ document.head.appendChild(styleSheet);
260
+ }
261
+
262
+ // Core toast function (used by both toast and toastHyperclay)
263
+ export function toastCore(message, messageType = "success", config = {}) {
264
+ const templates = config.templates || defaultTemplates;
265
+ const icons = config.icons || defaultIcons;
266
+ const theme = config.theme || 'modern';
267
+
268
+ // Get or create container for this theme
269
+ let toastContainer = document.querySelector(`.toast-container[data-toast-theme="${theme}"]`);
270
+ if (!toastContainer) {
271
+ toastContainer = document.createElement('div');
272
+ toastContainer.className = 'toast-container';
273
+ toastContainer.setAttribute('data-toast-theme', theme);
274
+ toastContainer.setAttribute('clay', 'no-save no-snapshot');
275
+ document.body.append(toastContainer);
276
+ }
277
+
278
+ // Create toast element
279
+ const icon = icons[messageType] || icons.success;
280
+ const template = templates.toast[messageType] || templates.toast.success;
281
+ const toastHtml = template
282
+ .replace('{icon}', icon)
283
+ .replace('{message}', message);
284
+
285
+ const tempDiv = document.createElement('div');
286
+ tempDiv.innerHTML = toastHtml.trim();
287
+ const toastElement = tempDiv.firstElementChild;
288
+
289
+ // Add click handler
290
+ toastElement.addEventListener('click', () => {
291
+ toastElement.classList.add('hide');
292
+ setTimeout(() => toastElement.remove(), 500);
293
+ });
294
+
295
+ // Add to container and animate in
296
+ toastContainer.append(toastElement);
297
+ setTimeout(() => toastElement.classList.remove('hide'), 10);
298
+
299
+ // Auto-hide after timeout
300
+ setTimeout(() => {
301
+ toastElement.classList.add('hide');
302
+ setTimeout(() => toastElement.remove(), 500);
303
+ }, 6600);
304
+ }
305
+
306
+ // Main toast function - uses configured theme (default: modern, or hyperclay if toast-hyperclay loaded)
307
+ function toast(message, messageType = "success") {
308
+ injectToastStyles(toastConfig.styles, toastConfig.theme);
309
+ toastCore(message, messageType, {
310
+ templates: toastConfig.templates,
311
+ icons: toastConfig.icons,
312
+ theme: toastConfig.theme
313
+ });
314
+ }
315
+
316
+ // Close button (button with pixel art X icon inside)
317
+ const CLOSE_BUTTON_HTML = `<button class="toast-close" type="button" aria-label="Close"><svg viewBox="0 0 558 558" xmlns="http://www.w3.org/2000/svg"><path d="M0,0h62.02v62.02h-62.02Z M62,0h62.02v62.02h-62.02Z M434,0h62.02v62.02h-62.02Z M496,0h62.02v62.02h-62.02Z M0,62h62.02v62.02h-62.02Z M62,62h62.02v62.02h-62.02Z M124,62h62.02v62.02h-62.02Z M372,62h62.02v62.02h-62.02Z M434,62h62.02v62.02h-62.02Z M496,62h62.02v62.02h-62.02Z M62,124h62.02v62.02h-62.02Z M124,124h62.02v62.02h-62.02Z M186,124h62.02v62.02h-62.02Z M310,124h62.02v62.02h-62.02Z M372,124h62.02v62.02h-62.02Z M434,124h62.02v62.02h-62.02Z M124,186h62.02v62.02h-62.02Z M186,186h62.02v62.02h-62.02Z M248,186h62.02v62.02h-62.02Z M310,186h62.02v62.02h-62.02Z M372,186h62.02v62.02h-62.02Z M186,248h62.02v62.02h-62.02Z M248,248h62.02v62.02h-62.02Z M310,248h62.02v62.02h-62.02Z M124,310h62.02v62.02h-62.02Z M186,310h62.02v62.02h-62.02Z M248,310h62.02v62.02h-62.02Z M310,310h62.02v62.02h-62.02Z M372,310h62.02v62.02h-62.02Z M62,372h62.02v62.02h-62.02Z M124,372h62.02v62.02h-62.02Z M186,372h62.02v62.02h-62.02Z M310,372h62.02v62.02h-62.02Z M372,372h62.02v62.02h-62.02Z M434,372h62.02v62.02h-62.02Z M0,434h62.02v62.02h-62.02Z M62,434h62.02v62.02h-62.02Z M124,434h62.02v62.02h-62.02Z M372,434h62.02v62.02h-62.02Z M434,434h62.02v62.02h-62.02Z M496,434h62.02v62.02h-62.02Z M0,496h62.02v62.02h-62.02Z M62,496h62.02v62.02h-62.02Z M434,496h62.02v62.02h-62.02Z M496,496h62.02v62.02h-62.02Z"/></svg></button>`;
318
+
319
+ // Persistent toast styles (added once)
320
+ const persistentToastStyles = `
321
+ .toast.toast-persistent {
322
+ position: relative;
323
+ align-items: center;
324
+ padding-right: 18px;
325
+ }
326
+ .toast-persistent .toast-close {
327
+ background: none;
328
+ border: none;
329
+ padding: 0;
330
+ margin-left: 3px;
331
+ position: relative;
332
+ top: -2px;
333
+ cursor: pointer;
334
+ opacity: 0.7;
335
+ transition: opacity 0.2s;
336
+ display: flex;
337
+ align-items: center;
338
+ justify-content: center;
339
+ color: white;
340
+ width: 22px;
341
+ height: 22px;
342
+ }
343
+ .toast-persistent .toast-close:hover {
344
+ opacity: 1;
345
+ }
346
+ .toast-persistent .toast-close svg {
347
+ width: 11px;
348
+ height: 11px;
349
+ fill: currentColor;
350
+ }
351
+ `;
352
+
353
+ // Track active persistent toasts by message
354
+ const activePersistentToasts = new Map();
355
+
356
+ // Persistent toast function - doesn't auto-dismiss, requires click to close
357
+ function toastPersistent(message, messageType = "warning") {
358
+ injectToastStyles(toastConfig.styles, toastConfig.theme);
359
+
360
+ // Inject persistent-specific styles once
361
+ if (!document.querySelector('style.toast-styles-persistent')) {
362
+ const styleSheet = document.createElement('style');
363
+ styleSheet.className = 'toast-styles-persistent';
364
+ styleSheet.setAttribute('clay', 'no-save no-snapshot');
365
+ styleSheet.textContent = persistentToastStyles;
366
+ document.head.appendChild(styleSheet);
367
+ }
368
+
369
+ const templates = toastConfig.templates;
370
+ const icons = toastConfig.icons;
371
+ const theme = toastConfig.theme;
372
+
373
+ // Get or create container for this theme
374
+ let toastContainer = document.querySelector(`.toast-container[data-toast-theme="${theme}"]`);
375
+ if (!toastContainer) {
376
+ toastContainer = document.createElement('div');
377
+ toastContainer.className = 'toast-container';
378
+ toastContainer.setAttribute('data-toast-theme', theme);
379
+ toastContainer.setAttribute('clay', 'no-save no-snapshot');
380
+ document.body.append(toastContainer);
381
+ }
382
+
383
+ // If same message already showing, animate it out first
384
+ const existingToast = activePersistentToasts.get(message);
385
+ if (existingToast) {
386
+ existingToast.classList.add('hide');
387
+ setTimeout(() => existingToast.remove(), 500);
388
+ activePersistentToasts.delete(message);
389
+ }
390
+
391
+ // Create toast element
392
+ const icon = icons[messageType] || icons.warning;
393
+ const template = templates.toast[messageType] || templates.toast.warning;
394
+ const toastHtml = template
395
+ .replace('{icon}', icon)
396
+ .replace('{message}', message);
397
+
398
+ const tempDiv = document.createElement('div');
399
+ tempDiv.innerHTML = toastHtml.trim();
400
+ const toastElement = tempDiv.firstElementChild;
401
+ toastElement.classList.add('toast-persistent');
402
+
403
+ // Add close button as sibling (not inside message)
404
+ toastElement.insertAdjacentHTML('beforeend', CLOSE_BUTTON_HTML);
405
+
406
+ // Close handler - only on close button click
407
+ const closeBtn = toastElement.querySelector('.toast-close');
408
+ if (closeBtn) {
409
+ closeBtn.addEventListener('click', (e) => {
410
+ e.stopPropagation();
411
+ toastElement.classList.add('hide');
412
+ setTimeout(() => {
413
+ toastElement.remove();
414
+ activePersistentToasts.delete(message);
415
+ }, 500);
416
+ });
417
+ }
418
+
419
+ // Track this toast
420
+ activePersistentToasts.set(message, toastElement);
421
+
422
+ // Add to container and animate in
423
+ toastContainer.append(toastElement);
424
+ setTimeout(() => toastElement.classList.remove('hide'), 10);
425
+ }
426
+
427
+ export { toastPersistent };
428
+ export default toast;
@@ -0,0 +1,27 @@
1
+ function copyToClipboard(text) {
2
+ // Create temporary textarea element
3
+ const textarea = document.createElement('textarea');
4
+ textarea.value = text;
5
+ textarea.style.position = 'fixed';
6
+ textarea.style.opacity = '0';
7
+
8
+ // Add to DOM, select, copy, and remove
9
+ document.body.appendChild(textarea);
10
+ textarea.select();
11
+ textarea.setSelectionRange(0, 99999); // For mobile devices
12
+
13
+ try {
14
+ const successful = document.execCommand('copy');
15
+ if (successful) {
16
+ console.log('Copied to clipboard');
17
+ } else {
18
+ console.log('Copy failed');
19
+ }
20
+ } catch (err) {
21
+ console.error('Unable to copy:', err);
22
+ }
23
+
24
+ document.body.removeChild(textarea);
25
+ }
26
+
27
+ export default copyToClipboard;
@@ -0,0 +1,23 @@
1
+ // debounce.js
2
+ function debounce(callback, delay) {
3
+ let timeoutId;
4
+ let pendingResolvers = [];
5
+
6
+ return function (...args) {
7
+ const ctx = this;
8
+ clearTimeout(timeoutId);
9
+
10
+ return new Promise((resolve) => {
11
+ pendingResolvers.push(resolve);
12
+
13
+ timeoutId = setTimeout(() => {
14
+ const resolvers = pendingResolvers;
15
+ pendingResolvers = [];
16
+ Promise.resolve(callback.apply(ctx, args))
17
+ .then(value => { for (const r of resolvers) r(value); });
18
+ }, delay);
19
+ });
20
+ };
21
+ }
22
+
23
+ export default debounce;
@@ -0,0 +1,10 @@
1
+ import throttle from "../lib/throttle.js";
2
+ import cookie from "../lib/cookie.js";
3
+ import debounce from "./debounce.js";
4
+ import slugify from "./slugify.js";
5
+ import copyToClipboard from "./copy-to-clipboard.js";
6
+
7
+ const clay = (window.clay = window.clay || {});
8
+ clay.utils = { throttle, debounce, cookie, slugify, copyToClipboard };
9
+
10
+ export default clay.utils;
@@ -0,0 +1,20 @@
1
+ // e.g. "Hello there" → "hello-there"
2
+ // Preserves .html/.htmlclay extensions
3
+ function slugify (text) {
4
+ if (text == null) return '';
5
+ const extMatch = text.toString().match(/\.(html|htmlclay)$/i);
6
+ const ext = extMatch ? extMatch[0].toLowerCase() : '';
7
+ const base = extMatch ? text.toString().slice(0, -ext.length) : text.toString();
8
+
9
+ return base.toLowerCase()
10
+ .normalize('NFD') // separate accents from letters
11
+ .replace(/[\u0300-\u036f]/g, '') // remove accents
12
+ .replace(/\s+/g, '-') // replace spaces with -
13
+ .replace(/[^\w\-]+/g, '') // remove all non-word chars
14
+ .replace(/\-\-+/g, '-') // replace multiple - with single -
15
+ .replace(/^-+/, '') // trim - from start of text
16
+ .replace(/-+$/, '') // trim - from end of text
17
+ + ext;
18
+ }
19
+
20
+ export default slugify;
@@ -1,4 +1,5 @@
1
- var HyperMorph=(()=>{var ne=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var pe=Object.prototype.hasOwnProperty;var me=(c,f)=>{for(var o in f)ne(c,o,{get:f[o],enumerable:!0})},ge=(c,f,o,h)=>{if(f&&typeof f=="object"||typeof f=="function")for(let p of he(f))!pe.call(c,p)&&p!==o&&ne(c,p,{get:()=>f[p],enumerable:!(h=de(f,p))||h.enumerable});return c};var be=c=>ge(ne({},"__esModule",{value:!0}),c);var Ce={};me(Ce,{HyperMorph:()=>Z,default:()=>Re,defaults:()=>xe,morph:()=>Ne});var oe={includeClasses:!0,includeAttributes:["href","src","name","type","role","aria-label","alt","title"],excludeAttributePrefixes:["data-morph-","data-hyper-","data-im-"],textHintLength:64,excludeIds:!0,maxPathDepth:4,landmarks:["HEADER","NAV","MAIN","ASIDE","FOOTER","SECTION","ARTICLE"],weights:{signature:100,pathSegment:10,textMatch:20,textMismatch:25,uniqueCandidate:50,positionPenalty:1,maxDriftPenalty:19,slotMatch:30},minConfidence:101,maxScoredCandidates:16};function Me(c){let f=5381;for(let o=0;o<c.length;o++)f=(f<<5)+f^c.charCodeAt(o);return Math.abs(f).toString(36)}function ve(c){if(c.classList&&c.classList.length>0)return Array.from(c.classList).sort().join(" ");let f=c.getAttribute?.("class");return f?f.split(/\s+/).filter(Boolean).sort().join(" "):""}function Se(c,f){let o=[];for(let h of c.attributes||[]){let p=h.name;p==="id"||p==="class"||f.excludeAttributePrefixes.some(y=>p.startsWith(y))||f.includeAttributes.includes(p)&&o.push(`${p}=${h.value}`)}return o.sort().join("|")}function ye(c,f){return(c.textContent||"").replace(/\s+/g," ").trim().slice(0,f.textHintLength)}function Ae(c,f){let o=[c.tagName];return f.includeClasses&&o.push(ve(c)),o.push(Se(c,f)),Me(o.join("|"))}function Ie(c){let f=c.tagName,o=1,h=c.previousElementSibling;for(;h;)h.tagName===f&&o++,h=h.previousElementSibling;return o}function ke(c,f){return c.getAttribute?.("id")||c.getAttribute?.("role")?!0:f.landmarks.includes(c.tagName)}function Ee(c){let f=c.getAttribute?.("id");if(f)return`#${f}`;let o=c.getAttribute?.("role");return o?`@${o}`:c.tagName}function we(c,f){let o=[],h=c;for(;h&&h.tagName&&o.length<f.maxPathDepth;){let p=`${h.tagName}:${Ie(h)}`;if(o.unshift(p),h!==c&&ke(h,f)){o.unshift(Ee(h));break}h=h.parentElement}return o}function He(c,f){let o=0,h=c.length-1,p=f.length-1;for(;h>=0&&p>=0&&c[h]===f[p];)o++,h--,p--;return o}function j(c,f,o){if(o.has(c))return o.get(c);let h={signature:Ae(c,f),path:we(c,f),textHint:ye(c,f)};return o.set(c,h),h}function le(c,f,o,h){if(h.has(c))return h.get(c);let p=new Map,y=c.querySelectorAll("*"),k=0;for(let v of y){let E=j(v,f,o);E.domIndex=k++,!f.shouldIgnore?.(v)&&(p.has(E.signature)||p.set(E.signature,[]),p.get(E.signature).push(v))}return h.set(c,p),p}function Te(c,f,o){o.delete(c),f.delete(c);let h=c.querySelectorAll("*");for(let p of h)f.delete(p)}function re(c,f,o,h,p){let y=j(c,o,h),k=j(f,o,h),v=o.weights,E={},O=0;if(y.signature!==k.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};O+=v.signature,E.signature=v.signature;let T=He(y.path,k.path)*v.pathSegment;O+=T,E.path=T;let w=!0;if(y.textHint&&k.textHint?y.textHint===k.textHint?(O+=v.textMatch,E.text=v.textMatch):(O-=v.textMismatch,E.text=-v.textMismatch,w=!1):y.textHint!==k.textHint&&(O-=v.textMismatch,E.text=-v.textMismatch,w=!1),p.candidateCount===1&&w&&(O+=v.uniqueCandidate,E.unique=v.uniqueCandidate),typeof y.domIndex=="number"&&typeof k.domIndex=="number"){let M=Math.abs(y.domIndex-k.domIndex),S=Math.min(M*v.positionPenalty,v.maxDriftPenalty);O-=S,E.drift=-S}return{score:O,breakdown:E}}function ae(c,f,o,h,p){if(o.excludeIds&&c.getAttribute("id"))return null;let y=le(f,o,h,p),k=j(c,o,h);if(typeof k.domIndex!="number"){let w=0,M=c.previousElementSibling;for(;M;)w++,M=M.previousElementSibling;k.domIndex=w}let v=y.get(k.signature)||[],E=o.excludeIds?v.filter(w=>!w.getAttribute("id")):v;if(E.length===0)return null;let O=null,$=0,T=null;for(let w of E){let{score:M,breakdown:S}=re(c,w,o,h,{candidateCount:E.length});M>$&&($=M,O=w,T=S)}return $<o.minConfidence?null:{element:O,confidence:$,breakdown:T}}function Le(c,f,o,h){let p=[],y=o.weights.signature+o.weights.slotMatch,k={slot:y};function v(T){if(T.children)return T.children;let w=T.childNodes;if(!w)return[];let M=[];for(let S=0;S<w.length;S++)w[S].nodeType===1&&M.push(w[S]);return M}function E(T,w){let M=v(T),S=v(w);if(M.length===S.length)for(let D=0;D<M.length;D++){let B=M[D],x=S[D];if(o.shouldIgnore?.(B)||o.shouldIgnore?.(x)||o.excludeIds&&(B.getAttribute("id")||x.getAttribute("id"))||B.tagName!==x.tagName)continue;let F=j(B,o,h).signature,P=j(x,o,h).signature;F!==P&&p.push({newEl:B,oldEl:x,score:y,breakdown:k}),E(B,x)}}function O(T,w){for(;;){if(T.tagName===w.tagName)return[T,w];let M=v(T);if(!T.tagName&&M.length===1){T=M[0];continue}let S=v(w);if(S.length===1&&S[0].tagName===T.tagName){w=S[0];continue}return null}}let $=O(c,f);return $&&E($[0],$[1]),p}function ce(c,f,o,h,p){let y=f.querySelectorAll("*"),k=le(c,o,h,p),v=0;for(let M of y){let S=j(M,o,h);S.domIndex=v++}let E=[],O=new Map;function $(M,S,D){let B=new Set;if(M.textHint){let R=O.get(M.signature);if(!R){R=new Map;for(let W of S){let Q=j(W,o,h).textHint,z=R.get(Q);z||(z=[],R.set(Q,z)),z.push(W)}O.set(M.signature,R)}let G=R.get(M.textHint);if(G)for(let W=0;W<G.length&&W<D;W++)B.add(G[W])}let x=0,F=S.length;for(;x<F;){let R=x+F>>1;j(S[R],o,h).domIndex<M.domIndex?x=R+1:F=R}let P=Math.max(0,Math.min(x-(D>>1),S.length-D)),_=Math.min(P+D,S.length);for(let R=P;R<_;R++)B.add(S[R]);return[...B]}for(let M of y){if(o.shouldIgnore?.(M)||o.excludeIds&&M.getAttribute("id"))continue;let S=j(M,o,h),D=k.get(S.signature)||[],B=o.excludeIds?D.filter(P=>!P.getAttribute("id")):D,x=o.maxScoredCandidates,F=x&&B.length>x?$(S,B,x):B;for(let P of F){let{score:_,breakdown:R}=re(M,P,o,h,{candidateCount:B.length});_>=o.minConfidence&&E.push({newEl:M,oldEl:P,score:_,breakdown:R})}}if(o.weights.slotMatch>0){let M=Le(f,c,o,h);for(let S of M)E.push(S)}E.sort((M,S)=>S.score-M.score);let T=new Map,w=new Set;for(let{newEl:M,oldEl:S}of E)T.has(M)||w.has(S)||(T.set(M,S),w.add(S));return T}function ue(c,f,o,h){let p=j(c,o,h),y=j(f,o,h),{score:k,breakdown:v}=re(c,f,o,h,{candidateCount:1});return{matches:k>=o.minConfidence,score:k,breakdown:v,newMeta:{signature:p.signature,path:p.path,textHint:p.textHint},oldMeta:{signature:y.signature,path:y.path,textHint:y.textHint}}}function fe(c={}){let f={...oe,...c,weights:{...oe.weights,...c.weights}},o=new WeakMap,h=new WeakMap;return{findMatch:(p,y)=>ae(p,y,f,o,h),computeMatches:(p,y)=>ce(p,y,f,o,h),explain:(p,y)=>ue(p,y,f,o),invalidate:p=>Te(p,o,h),session:()=>{let p=new WeakMap,y=new WeakMap;return{findMatch:(k,v)=>ae(k,v,f,p,y),computeMatches:(k,v)=>ce(k,v,f,p,y),explain:(k,v)=>ue(k,v,f,p)}},getConfig:()=>({...f})}}var Z=(function(){"use strict";let c=()=>{},f='[save-ignore],[snapshot-remove],[no-snapshot],[no-save],[save-remove],[freeze],[save-freeze],[clay~="no-save"],[clay~="no-snapshot"],[clay~="freeze"]';function o(a){if(!(a instanceof Element))return!1;if(a.matches(f))return!0;if(a.tagName==="LINK"||a.tagName==="SCRIPT"){let g=a.getAttribute("src")||a.getAttribute("href")||"";if(g.startsWith("chrome-extension://")||g.startsWith("moz-extension://")||g.startsWith("safari-web-extension://"))return!0}return!1}function h(a){return a instanceof Element?a.closest(f)?!0:o(a):!1}let p=fe({shouldIgnore:h});function y(a,g){if(g!=="smart")return a.outerHTML;let m=a.getAttribute("src"),A=a.getAttribute("type")||"text/javascript";if(m)try{let b=new URL(m,window.location.href);return`ext:${A}:${b.origin}${b.pathname}${b.search}`}catch{return`ext:${A}:${m}`}else{let b=a.textContent.trim(),H=5381;for(let s=0;s<b.length;s++)H=(H<<5)+H^b.charCodeAt(s);return`inline:${A}:${Math.abs(H).toString(36)}`}}let k="http://www.w3.org/1999/xhtml";function v(a){return a instanceof Element&&a.tagName==="SCRIPT"&&a.namespaceURI===k}function E(a){let g=document.createElement("div");g.innerHTML="<script><\/script>";let m=g.firstChild;for(let A of a.attributes)m.setAttribute(A.name,A.value);return m.textContent=a.textContent,m}function O(a){if(v(a))return E(a);if(a instanceof Element)for(let g of a.querySelectorAll("script"))v(g)&&g.replaceWith(E(g));return a}let $={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:c,afterNodeAdded:c,beforeNodeMorphed:c,afterNodeMorphed:c,beforeNodeRemoved:c,afterNodeRemoved:c,beforeAttributeUpdated:c},head:{style:"merge",shouldPreserve:a=>a.getAttribute("im-preserve")==="true",shouldReAppend:a=>a.getAttribute("im-re-append")==="true",shouldRemove:c,afterHeadMorphed:c},scripts:{handle:!0,matchMode:"outerHTML",shouldPreserve:a=>a.getAttribute("im-preserve")==="true",shouldReAppend:a=>a.getAttribute("im-re-append")==="true",shouldRemove:c,afterScriptsHandled:c},restoreFocus:!0},T={computeMatches(a,g){let{computeMatches:m}=p.session();return m(a,g)}};function w(a,g,m={}){a=Q(a);let A=z(g),b=W(a,A,m),H=b.scripts.handle?new Set(Array.from(a.querySelectorAll("script")).map(t=>y(t,b.scripts.matchMode))):null,s=D(b),l=P(b,a,A,t=>t.morphStyle==="innerHTML"?(x(t,a,A),Array.from(a.childNodes)):S(t,a,A)),n=t=>{s&&B(b,s),M(b);let e=H?G(t,H,b):[];return e.length>0?Promise.all(e).then(()=>t):t};return l instanceof Promise?l.then(n):n(l)}function M(a){for(let g of Array.from(a.pantry.childNodes))a.callbacks.beforeNodeRemoved(g)!==!1&&a.callbacks.afterNodeRemoved(g);a.pantry.remove()}function S(a,g,m){let A=z(g);return x(a,A,m,g,g.nextSibling),Array.from(A.childNodes)}function D(a){if(!a.config.restoreFocus)return null;let g=document.activeElement;if(!(g instanceof HTMLInputElement||g instanceof HTMLTextAreaElement))return null;let{id:m,selectionStart:A,selectionEnd:b}=g;return{element:g,id:m,selectionStart:A,selectionEnd:b}}function B(a,g){let m=g.element;if(g.id&&g.id!==document.activeElement?.getAttribute("id")&&(m=a.target.querySelector(`[id="${CSS.escape(g.id)}"]`),m?.focus()),m&&!m.selectionEnd&&g.selectionEnd!=null)try{m.setSelectionRange(g.selectionStart,g.selectionEnd)}catch{}}let x=(function(){function a(t,e,i,r=null,u=null){e instanceof HTMLTemplateElement&&i instanceof HTMLTemplateElement&&(e=e.content,i=i.content),r||=e.firstChild;for(let d of i.childNodes){if(o(d))continue;if(r&&r!=u){let C=m(t,d,r,u);if(C){C!==r&&b(t,r,C),F(C,d,t),r=C.nextSibling;continue}}if(d instanceof Element){let C=d.getAttribute("id");if(t.persistentIds.has(C)){let L=H(e,C,r,t);F(L,d,t),r=L.nextSibling;continue}if(!t.idMap.has(d)){let L=t.hyperMatches.get(d);if(L&&!t.idMap.has(L)&&!n(L,e)){l(e,L,r),F(L,d,t),r=L.nextSibling;continue}}}let I=g(e,d,r,t);I&&(r=I.nextSibling)}for(;r&&r!=u;){let d=r;r=r.nextSibling,o(d)||A(t,d)}}function g(t,e,i,r){if(r.callbacks.beforeNodeAdded(e)===!1)return null;if(r.idMap.has(e)){let u=e,d=document.createElementNS(u.namespaceURI,u.localName);return t.insertBefore(d,i),F(d,e,r),r.callbacks.afterNodeAdded(d),d}else{let u=O(document.importNode(e,!0));return t.insertBefore(u,i),r.callbacks.afterNodeAdded(u),u}}let m=(function(){function t(r,u,d,I){let C=u instanceof Element&&!r.idMap.has(u)?r.hyperMatches.get(u):null,L=null,K=u.nextSibling,Y=0,N=d;for(;N&&N!=I;){if(o(N)){N=N.nextSibling;continue}if(i(N,u)){if(e(r,N,u)||N===C&&!r.idMap.has(N))return N;if(L===null){let J=N instanceof Element&&r.hyperMatchedOldElements.has(N);!r.idMap.has(N)&&!J&&(L=N)}}if(L===null&&K&&i(N,K)&&(Y++,K=K.nextSibling,Y>=2&&(L=void 0)),r.activeElementAndParents.includes(N))break;N=N.nextSibling}return L||null}function e(r,u,d){let I=r.idMap.get(u),C=r.idMap.get(d);if(!C||!I)return!1;for(let L of I)if(C.has(L))return!0;return!1}function i(r,u){let d=r,I=u;return d.nodeType===I.nodeType&&d.tagName===I.tagName&&(!d.getAttribute?.("id")||d.getAttribute?.("id")===I.getAttribute?.("id"))}return t})();function A(t,e){let i=e instanceof Element&&t.hyperMatchedOldElements.has(e)&&!t.idMap.has(e);if(t.idMap.has(e)||i)l(t.pantry,e,null);else{if(t.callbacks.beforeNodeRemoved(e)===!1)return;e.parentNode?.removeChild(e),t.callbacks.afterNodeRemoved(e)}}function b(t,e,i){let r=e;for(;r&&r!==i;){let u=r;r=r.nextSibling,o(u)||A(t,u)}return r}function H(t,e,i,r){let u=r.target.getAttribute?.("id")===e&&r.target||r.target.querySelector(`[id="${CSS.escape(e)}"]`)||r.pantry.querySelector(`[id="${CSS.escape(e)}"]`);return s(u,r),l(t,u,i),u}function s(t,e){let i=t.getAttribute("id");for(;t=t.parentNode;){let r=e.idMap.get(t);r&&(r.delete(i),r.size||e.idMap.delete(t))}}function l(t,e,i){if(t.moveBefore)try{t.moveBefore(e,i)}catch{t.insertBefore(e,i)}else t.insertBefore(e,i)}function n(t,e){let i=e instanceof Element?e:e.realParentNode;return!!i&&t.contains(i)}return a})(),F=(function(){function a(s,l,n){return n.ignoreActive&&s===document.activeElement?null:(n.callbacks.beforeNodeMorphed(s,l)===!1||(s instanceof HTMLHeadElement&&n.head.ignore||(s instanceof HTMLHeadElement&&n.head.style!=="morph"?R(s,l,n):(g(s,l,n),H(s,n)||x(n,s,l))),n.callbacks.afterNodeMorphed(s,l)),s)}function g(s,l,n){let t=l.nodeType;if(t===1){let e=s,i=l,r=e.attributes,u=i.attributes;for(let d of u)b(d.name,e,"update",n)||e.getAttribute(d.name)!==d.value&&e.setAttribute(d.name,d.value);for(let d=r.length-1;0<=d;d--){let I=r[d];if(I&&!i.hasAttribute(I.name)){if(b(I.name,e,"remove",n))continue;e.removeAttribute(I.name)}}H(e,n)||m(e,i,n)}(t===8||t===3)&&s.nodeValue!==l.nodeValue&&(s.nodeValue=l.nodeValue)}function m(s,l,n){if(s instanceof HTMLInputElement&&l instanceof HTMLInputElement&&l.type!=="file"){let t=l.value,e=s.value;A(s,l,"checked",n),A(s,l,"disabled",n),n.formStateSync==="property"&&s.indeterminate!==l.indeterminate&&(s.indeterminate=l.indeterminate),n.formStateSync==="property"?e!==t&&(b("value",s,"update",n)||(s.value=t)):l.hasAttribute("value")?e!==t&&(b("value",s,"update",n)||(s.setAttribute("value",t),s.value=t)):b("value",s,"remove",n)||(s.value="",s.removeAttribute("value"))}else if(s instanceof HTMLOptionElement&&l instanceof HTMLOptionElement)A(s,l,"selected",n);else if(s instanceof HTMLTextAreaElement&&l instanceof HTMLTextAreaElement){let t=l.value,e=s.value;if(b("value",s,"update",n)||(t!==e&&(s.value=t),n.formStateSync==="property"))return;s.firstChild&&s.firstChild.nodeValue!==t&&(s.firstChild.nodeValue=t)}}function A(s,l,n,t){let e=l[n],i=s[n];if(e!==i){let r=b(n,s,"update",t);if(r||(s[n]=l[n]),t.formStateSync==="property")return;e?r||s.setAttribute(n,""):b(n,s,"remove",t)||s.removeAttribute(n)}}function b(s,l,n,t){return s==="value"&&t.ignoreActiveValue&&l===document.activeElement?!0:t.callbacks.beforeAttributeUpdated(s,l,n)===!1}function H(s,l){return!!l.ignoreActiveValue&&s===document.activeElement&&s!==document.body}return a})();function P(a,g,m,A){if(a.head.block){let b=g.querySelector("head"),H=m.querySelector("head");if(b&&H){let s=R(b,H,a);return Promise.all(s).then(()=>(a.head.block=!1,a.head.ignore=!0,A(a)))}}return A(a)}function _(a){return a.tagName==="SCRIPT"?!!a.getAttribute("src"):a.tagName==="LINK"?(a.getAttribute("rel")||"").toLowerCase().split(/\s+/).includes("stylesheet")&&!!a.getAttribute("href"):!1}function R(a,g,m){let A=[],b=[],H=[],s=[],l=m.scripts.matchMode,n=i=>{if(i.tagName==="SCRIPT")return y(i,l);if(i.tagName==="LINK"&&l==="smart"){let r=i.getAttribute("href");if(r)try{let u=new URL(r,window.location.href);return`link:${i.getAttribute("rel")||""}:${u.origin}${u.pathname}${u.search}`}catch{}}return i.outerHTML},t=new Map;for(let i of g.children){if(o(i))continue;let r=n(i),u=t.get(r);u||(u=[],t.set(r,u)),u.push(i)}for(let i of a.children){let r=n(i),u=t.get(r),d=!!(u&&u.length),I=m.head.shouldReAppend(i),C=m.head.shouldPreserve(i);d||C?I?b.push(i):(u&&u.length&&(u.pop(),u.length||t.delete(r)),H.push(i)):m.head.style==="append"?I&&(b.push(i),s.push(i)):m.head.shouldRemove(i)!==!1&&!o(i)&&b.push(i)}for(let i of t.values())s.push(...i);let e=[];for(let i of s){let r=document.createRange().createContextualFragment(i.outerHTML).firstChild;if(m.callbacks.beforeNodeAdded(r)!==!1){if(r instanceof Element&&_(r)){let u,d=new Promise(function(I){u=I});r.addEventListener("load",function(){u()}),r.addEventListener("error",function(){u()}),e.push(d)}a.appendChild(r),m.callbacks.afterNodeAdded(r),A.push(r)}}for(let i of b)m.callbacks.beforeNodeRemoved(i)!==!1&&(a.removeChild(i),m.callbacks.afterNodeRemoved(i));return m.head.afterHeadMorphed(a,{added:A,kept:H,removed:b}),e}function G(a,g,m){if(!m.scripts.handle)return[];let A=[],b=[],H=[],s=[],l=m.scripts.matchMode,n=[];for(let e of a)if(e instanceof Element){v(e)&&n.push(e);for(let i of e.querySelectorAll("script"))v(i)&&n.push(i)}for(let e of n){if(e.closest("head")||h(e))continue;let i=y(e,l),r=g.has(i),u=m.scripts.shouldPreserve(e),d=m.scripts.shouldReAppend(e);r||u?d?(b.push(e),s.push(e)):H.push(e):s.push(e)}let t=[];for(let e of s){if(m.callbacks.beforeNodeAdded(e)===!1)continue;let i=document.createElement("script");for(let r of e.attributes)i.setAttribute(r.name,r.value);if(i.textContent=e.textContent,i.src){let r,u=new Promise(function(d){r=d});i.addEventListener("load",function(){r()}),i.addEventListener("error",function(){r()}),t.push(u)}e.replaceWith(i),m.callbacks.afterNodeAdded(i),A.push(i)}return m.scripts.afterScriptsHandled(m.target,{added:A,kept:H,removed:b}),t}let W=(function(){function a(n,t,e){let{persistentIds:i,idMap:r}=s(n,t),u=T.computeMatches(n,t);if(typeof e.key=="function"){let L=new Map,K=new Set,Y=q=>{let V=e.key(q);V!=null&&(L.has(V)?K.add(V):L.set(V,q))};n instanceof Element&&Y(n);for(let q of n.querySelectorAll("*"))Y(q);for(let q of K)L.delete(q);let N=new Map;for(let[q,V]of u)N.set(V,q);let J=t.__hyperMorphRoot||t,X=new Map,se=new Set,ie=q=>{let V=e.key(q);V!=null&&(X.has(V)?se.add(V):X.set(V,q))};J instanceof Element&&ie(J);for(let q of J.querySelectorAll("*"))ie(q);for(let q of se)X.delete(q);for(let[q,V]of X){let U=L.get(q);if(!U||U.tagName!==V.tagName)continue;let ee=N.get(U);ee&&ee!==V&&u.delete(ee);let te=u.get(V);te&&te!==U&&N.delete(te),u.set(V,U),N.set(U,V)}}let d=new Set;for(let L of u.values())d.add(L);let I=g(e),C=I.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(C))throw new Error(`Do not understand how to morph style ${C}`);return{target:n,newContent:t,config:I,morphStyle:C,ignoreActive:I.ignoreActive,ignoreActiveValue:I.ignoreActiveValue,restoreFocus:I.restoreFocus,formStateSync:I.formStateSync||"attribute",idMap:r,persistentIds:i,hyperMatches:u,hyperMatchedOldElements:d,pantry:m(),activeElementAndParents:A(n),callbacks:I.callbacks,head:I.head,scripts:I.scripts}}function g(n){let t=Object.assign({},$);return Object.assign(t,n),t.callbacks=Object.assign({},$.callbacks,n.callbacks),t.head=Object.assign({},$.head,n.head),t.scripts=Object.assign({},$.scripts,n.scripts),t}function m(){let n=document.createElement("div");return n.hidden=!0,document.body.insertAdjacentElement("afterend",n),n}function A(n){let t=[],e=document.activeElement;if(e?.tagName!=="BODY"&&n.contains(e))for(;e&&(t.push(e),e!==n);)e=e.parentElement;return t}function b(n){let t=Array.from(n.querySelectorAll("[id]"));return n.getAttribute?.("id")&&t.push(n),t}function H(n,t,e,i){for(let r of i){let u=r.getAttribute("id");if(t.has(u)){let d=r;for(;d;){let I=n.get(d);if(I==null&&(I=new Set,n.set(d,I)),I.add(u),d===e)break;d=d.parentElement}}}}function s(n,t){let e=b(n),i=b(t),r=l(e,i),u=new Map;H(u,r,n,e);let d=t.__hyperMorphRoot||t;return H(u,r,d,i),{persistentIds:r,idMap:u}}function l(n,t){let e=new Set,i=new Map;for(let u of n){let d=u.getAttribute("id");i.has(d)?e.add(d):i.set(d,u.tagName)}let r=new Set;for(let u of t){let d=u.getAttribute("id");r.has(d)?e.add(d):i.get(d)===u.tagName&&r.add(d)}for(let u of e)r.delete(u);return r}return a})(),{normalizeElement:Q,normalizeParent:z}=(function(){let a=new WeakSet;function g(s){return s instanceof Document?s.documentElement:s}function m(s){if(s==null)return document.createElement("div");if(typeof s=="string")return m(H(s));if(a.has(s))return s;if(s instanceof Node){if(s.parentNode)return new A(s);{let l=document.createElement("div");return l.append(s),l}}else{let l=document.createElement("div");for(let n of[...s])l.append(n);return l}}class A{constructor(l){this.originalNode=l,this.realParentNode=l.parentNode,this.previousSibling=l.previousSibling,this.nextSibling=l.nextSibling}get childNodes(){let l=[],n=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;n&&n!=this.nextSibling;)l.push(n),n=n.nextSibling;return l}querySelectorAll(l){return this.childNodes.reduce((n,t)=>{if(t instanceof Element){t.matches(l)&&n.push(t);let e=t.querySelectorAll(l);for(let i=0;i<e.length;i++)n.push(e[i])}return n},[])}insertBefore(l,n){return this.realParentNode.insertBefore(l,n)}moveBefore(l,n){return this.realParentNode.moveBefore(l,n)}get __hyperMorphRoot(){return this.originalNode}}function b(s){let l=i=>`<${i}(?:\\s(?:[^>"']|"[^"]*"|'[^']*')*)?>`,n=s.replace(/<!--[\s\S]*?-->/g,"");for(let i of["script","style","textarea","title"])n=n.replace(new RegExp(`${l(i)}[\\s\\S]*?</${i}\\s*>`,"gi"),"");let t=new RegExp(`${l("svg")}[\\s\\S]*?</svg\\s*>`,"gi"),e;do e=n,n=n.replace(t,"");while(n!==e);return n}function H(s){let l=new DOMParser,n=b(s);if(n.match(/<\/html>/)||n.match(/<\/head>/)||n.match(/<\/body>/)){let t=l.parseFromString(s,"text/html");if(n.match(/<\/html>/))return a.add(t),t;{let e=t.firstChild;return e&&a.add(e),e}}else{let e=l.parseFromString("<body><template>"+s+"</template></body>","text/html").body.querySelector("template").content;return a.add(e),e}}return{normalizeElement:g,normalizeParent:m}})();return{morph:w,defaults:$}})();var Ne=Z.morph,xe=Z.defaults,Re=Z;return be(Ce);})();
1
+ var HyperMorph=(()=>{var fe=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var Ce=Object.getOwnPropertyNames;var Le=Object.prototype.hasOwnProperty;var He=(e,n)=>{for(var t in n)fe(e,t,{get:n[t],enumerable:!0})},Be=(e,n,t,d)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of Ce(n))!Le.call(e,o)&&o!==t&&fe(e,o,{get:()=>n[o],enumerable:!(d=Re(n,o))||d.enumerable});return e};var $e=e=>Be(fe({},"__esModule",{value:!0}),e);var at={};He(at,{HyperMorph:()=>ce,default:()=>ot,defaults:()=>it,mergeJson:()=>oe,mergeScriptText:()=>ae,morph:()=>st,parseJsonRelaxed:()=>ne,parseRulesRelaxed:()=>pe});var be={includeClasses:!0,includeAttributes:["href","src","name","type","role","aria-label","alt","title"],excludeAttributePrefixes:["data-morph-","data-hyper-","data-im-"],textHintLength:64,excludeIds:!0,maxPathDepth:4,landmarks:["HEADER","NAV","MAIN","ASIDE","FOOTER","SECTION","ARTICLE"],weights:{signature:100,pathSegment:10,textMatch:20,textMismatch:25,uniqueCandidate:50,positionPenalty:1,maxDriftPenalty:19,slotMatch:30},minConfidence:101,maxScoredCandidates:16};function je(e){let n=5381;for(let t=0;t<e.length;t++)n=(n<<5)+n^e.charCodeAt(t);return Math.abs(n).toString(36)}function qe(e){if(e.classList&&e.classList.length>0)return Array.from(e.classList).sort().join(" ");let n=e.getAttribute?.("class");return n?n.split(/\s+/).filter(Boolean).sort().join(" "):""}function De(e,n){let t=[];for(let d of e.attributes||[]){let o=d.name;o==="id"||o==="class"||n.excludeAttributePrefixes.some(p=>o.startsWith(p))||n.includeAttributes.includes(o)&&t.push(`${o}=${d.value}`)}return t.sort().join("|")}function _e(e,n){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,n.textHintLength)}function Fe(e,n){let t=[e.tagName];return n.includeClasses&&t.push(qe(e)),t.push(De(e,n)),je(t.join("|"))}function Pe(e){let n=e.tagName,t=1,d=e.previousElementSibling;for(;d;)d.tagName===n&&t++,d=d.previousElementSibling;return t}function ze(e,n){return e.getAttribute?.("id")||e.getAttribute?.("role")?!0:n.landmarks.includes(e.tagName)}function Ke(e){let n=e.getAttribute?.("id");if(n)return`#${n}`;let t=e.getAttribute?.("role");return t?`@${t}`:e.tagName}function Je(e,n){let t=[],d=e;for(;d&&d.tagName&&t.length<n.maxPathDepth;){let o=`${d.tagName}:${Pe(d)}`;if(t.unshift(o),d!==e&&ze(d,n)){t.unshift(Ke(d));break}d=d.parentElement}return t}function Ve(e,n){let t=0,d=e.length-1,o=n.length-1;for(;d>=0&&o>=0&&e[d]===n[o];)t++,d--,o--;return t}function z(e,n,t){if(t.has(e))return t.get(e);let d={signature:Fe(e,n),path:Je(e,n),textHint:_e(e,n)};return t.set(e,d),d}function ve(e,n,t,d){if(d.has(e))return d.get(e);let o=new Map,p=e.querySelectorAll("*"),m=0;for(let u of p){let b=z(u,n,t);b.domIndex=m++,!n.shouldIgnore?.(u)&&(o.has(b.signature)||o.set(b.signature,[]),o.get(b.signature).push(u))}return d.set(e,o),o}function Ue(e,n,t){t.delete(e),n.delete(e);let d=e.querySelectorAll("*");for(let o of d)n.delete(o)}function de(e,n,t,d,o){let p=z(e,t,d),m=z(n,t,d),u=t.weights,b={},T=0;if(p.signature!==m.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};T+=u.signature,b.signature=u.signature;let N=Ve(p.path,m.path)*u.pathSegment;T+=N,b.path=N;let k=!0;if(p.textHint&&m.textHint?p.textHint===m.textHint?(T+=u.textMatch,b.text=u.textMatch):(T-=u.textMismatch,b.text=-u.textMismatch,k=!1):p.textHint!==m.textHint&&(T-=u.textMismatch,b.text=-u.textMismatch,k=!1),o.candidateCount===1&&k&&(T+=u.uniqueCandidate,b.unique=u.uniqueCandidate),typeof p.domIndex=="number"&&typeof m.domIndex=="number"){let S=Math.abs(p.domIndex-m.domIndex),v=Math.min(S*u.positionPenalty,u.maxDriftPenalty);T-=v,b.drift=-v}return{score:T,breakdown:b}}function Se(e,n,t,d,o){if(t.excludeIds&&e.getAttribute("id"))return null;let p=ve(n,t,d,o),m=z(e,t,d);if(typeof m.domIndex!="number"){let k=0,S=e.previousElementSibling;for(;S;)k++,S=S.previousElementSibling;m.domIndex=k}let u=p.get(m.signature)||[],b=t.excludeIds?u.filter(k=>!k.getAttribute("id")):u;if(b.length===0)return null;let T=null,C=0,N=null;for(let k of b){let{score:S,breakdown:v}=de(e,k,t,d,{candidateCount:b.length});S>C&&(C=S,T=k,N=v)}return C<t.minConfidence?null:{element:T,confidence:C,breakdown:N}}function We(e,n,t,d){let o=[],p=t.weights.signature+t.weights.slotMatch,m={slot:p};function u(N){if(N.children)return N.children;let k=N.childNodes;if(!k)return[];let S=[];for(let v=0;v<k.length;v++)k[v].nodeType===1&&S.push(k[v]);return S}function b(N,k){let S=u(N),v=u(k);if(S.length===v.length)for(let B=0;B<S.length;B++){let $=S[B],j=v[B];if(t.shouldIgnore?.($)||t.shouldIgnore?.(j)||t.excludeIds&&($.getAttribute("id")||j.getAttribute("id"))||$.tagName!==j.tagName)continue;let V=z($,t,d).signature,K=z(j,t,d).signature;V!==K&&o.push({newEl:$,oldEl:j,score:p,breakdown:m}),b($,j)}}function T(N,k){for(;;){if(N.tagName===k.tagName)return[N,k];let S=u(N);if(!N.tagName&&S.length===1){N=S[0];continue}let v=u(k);if(v.length===1&&v[0].tagName===N.tagName){k=v[0];continue}return null}}let C=T(e,n);return C&&b(C[0],C[1]),o}function Me(e,n,t,d,o){let p=n.querySelectorAll("*"),m=ve(e,t,d,o),u=0;for(let S of p){let v=z(S,t,d);v.domIndex=u++}let b=[],T=new Map;function C(S,v,B){let $=new Set;if(S.textHint){let q=T.get(S.signature);if(!q){q=new Map;for(let U of v){let se=z(U,t,d).textHint,Q=q.get(se);Q||(Q=[],q.set(se,Q)),Q.push(U)}T.set(S.signature,q)}let W=q.get(S.textHint);if(W)for(let U=0;U<W.length&&U<B;U++)$.add(W[U])}let j=0,V=v.length;for(;j<V;){let q=j+V>>1;z(v[q],t,d).domIndex<S.domIndex?j=q+1:V=q}let K=Math.max(0,Math.min(j-(B>>1),v.length-B)),X=Math.min(K+B,v.length);for(let q=K;q<X;q++)$.add(v[q]);return[...$]}for(let S of p){if(t.shouldIgnore?.(S)||t.excludeIds&&S.getAttribute("id"))continue;let v=z(S,t,d),B=m.get(v.signature)||[],$=t.excludeIds?B.filter(K=>!K.getAttribute("id")):B,j=t.maxScoredCandidates,V=j&&$.length>j?C(v,$,j):$;for(let K of V){let{score:X,breakdown:q}=de(S,K,t,d,{candidateCount:$.length});X>=t.minConfidence&&b.push({newEl:S,oldEl:K,score:X,breakdown:q})}}if(t.weights.slotMatch>0){let S=We(n,e,t,d);for(let v of S)b.push(v)}b.sort((S,v)=>v.score-S.score);let N=new Map,k=new Set;for(let{newEl:S,oldEl:v}of b)N.has(S)||k.has(v)||(N.set(S,v),k.add(v));return N}function Ae(e,n,t,d){let o=z(e,t,d),p=z(n,t,d),{score:m,breakdown:u}=de(e,n,t,d,{candidateCount:1});return{matches:m>=t.minConfidence,score:m,breakdown:u,newMeta:{signature:o.signature,path:o.path,textHint:o.textHint},oldMeta:{signature:p.signature,path:p.path,textHint:p.textHint}}}function ke(e={}){let n={...be,...e,weights:{...be.weights,...e.weights}},t=new WeakMap,d=new WeakMap;return{findMatch:(o,p)=>Se(o,p,n,t,d),computeMatches:(o,p)=>Me(o,p,n,t,d),explain:(o,p)=>Ae(o,p,n,t),invalidate:o=>Ue(o,t,d),session:()=>{let o=new WeakMap,p=new WeakMap;return{findMatch:(m,u)=>Se(m,u,n,o,p),computeMatches:(m,u)=>Me(m,u,n,o,p),explain:(m,u)=>Ae(m,u,n,o)}},getConfig:()=>({...n})}}function he(e,n){for(;;){for(;n<e.length&&/\s/.test(e[n]);)n++;if(e[n]==="/"&&e[n+1]==="/"){for(;n<e.length&&e[n]!==`
2
+ `;)n++;continue}if(e[n]==="/"&&e[n+1]==="*"){let t=e.indexOf("*/",n+2);if(t===-1)return e.length;n=t+2;continue}return n}}function Ee(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(n,t)=>t.length%2===0?t+'\\"':n)}var Ge=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,Ze=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function ne(e){try{return JSON.parse(e)}catch{return JSON.parse(Qe(e))}}function Qe(e){let n="",t=0,d=(o,p)=>{throw new Error(`Invalid relaxed JSON: ${o} at position ${p}`)};for(;t<e.length&&(t=he(e,t),!(t>=e.length));){let o=e[t];if("{}[]:".includes(o)){n+=o,t++;continue}if(o===","){let u=he(e,t+1);if(e[u]==="}"||e[u]==="]"){t++;continue}n+=o,t++;continue}if(o==='"'||o==="'"){let u=t+1;for(;u<e.length&&e[u]!==o;)e[u]==="\\"&&u++,u++;u>=e.length&&d("unterminated string",t);let b=e.slice(t+1,u);o==="'"&&(b=Ee(b)),n+='"'+b+'"',t=u+1;continue}let p=t;for(;p<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[p]);)p++;p===t&&d("unexpected character "+JSON.stringify(o),t);let m=e.slice(t,p);if(m==="true"||m==="false"||m==="null"||Ge.test(m)){n+=m,t=p;continue}if(Ze.test(m)){if(e[he(e,p)]===":"){n+='"'+m+'"',t=p;continue}d("unquoted value "+JSON.stringify(m),t)}d("invalid token "+JSON.stringify(m),t)}return n}function pe(e){try{return JSON.parse(e)}catch{}let n={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function t(o){let p=[],m=0;for(;m<o.length;){let u=o[m];if(/\s/.test(u)){m++;continue}if("{}".includes(u)){p.push({type:u,value:u}),m++;continue}if(u==="["){let N=!1,k=m+1;for(;k<o.length&&/\s/.test(o[k]);)k++;if(k<o.length&&/[a-zA-Z_]/.test(o[k])&&(N=!0),!N){p.push({type:u,value:u}),m++;continue}}if(u==="]"){p.push({type:u,value:u}),m++;continue}if(u===":"){p.push({type:n.COLON,value:u}),m++;continue}if(u===","){p.push({type:n.COMMA,value:u}),m++;continue}if(u==='"'||u==="'"){let N=u,k=m+1;for(;k<o.length&&o[k]!==N;)o[k]==="\\"&&k++,k++;p.push({type:n.STRING,value:o.substring(m+1,k),quoted:!0,sourceQuote:N}),m=k+1;continue}let b=m,T;for(;b<o.length&&!/[{},]/.test(o[b]);)if(o[b]===":"){let N=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],k=!1;for(let S of N){let v=S.substring(1);if(o.substring(b+1,b+1+v.length)===v){k=!0,b+=v.length;break}}if(!k)break}else if(o[b]==="["){for(b++;b<o.length&&o[b]!=="]";){if(o[b]==='"'||o[b]==="'"){let N=o[b];for(b++;b<o.length&&o[b]!==N;)o[b]==="\\"&&b++,b++}b++}b<o.length&&o[b]==="]"&&b++}else b++;T=o.substring(m,b);let C=n.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(T)?C=n.NUMBER:T==="true"||T==="false"||T==="null"?C=n.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(T)&&(C=n.SELECTOR),p.push({type:C,value:T,quoted:!1}),m=b}return p}function d(o){let p="";for(let m=0;m<o.length;m++){let u=o[m];if("{}".includes(u.type)||"[]".includes(u.type)){p+=u.value;continue}if(u.type===n.COLON){p+=u.value;continue}if(u.type===n.COMMA){let b=o[m+1];if(b&&(b.type==="}"||b.type==="]"))continue;p+=u.value;continue}if(u.type===n.STRING){let b=u.value;u.sourceQuote==="'"&&(b=Ee(b)),p+=`"${b}"`;continue}if(u.type===n.NUMBER||u.type===n.BOOLEAN){p+=u.value;continue}p+=`"${u.value}"`}return p}try{let o=t(e),p=d(o);return JSON.parse(p)}catch(o){throw new Error("Invalid extraction rules syntax: "+o.message)}}var H=Symbol("hyper-morph-json-merge:missing"),we=["id","_id","uuid","key","slug","code","name"];function te(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function re(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function Ye(e,n,t){Object.defineProperty(e,n,{value:t,enumerable:!0,writable:!0,configurable:!0})}function Z(e,n){if(e===n)return!0;if(Array.isArray(e)&&Array.isArray(n)){if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!Z(e[t],n[t]))return!1;return!0}if(te(e)&&te(n)){let t=Object.keys(e);if(t.length!==Object.keys(n).length)return!1;for(let d of t)if(!re(n,d)||!Z(e[d],n[d]))return!1;return!0}return!1}function Ie(e,n,t,d){return Z(n,t)?n:Z(n,e)?t:Z(t,e)?n:te(n)&&te(t)?Xe(te(e)?e:{},n,t,d):Array.isArray(n)&&Array.isArray(t)?rt(Array.isArray(e)?e:[],n,t,d):t}function Ne(e,n,t,d){return n===H&&t===H?H:n===H?e===H?t:Z(t,e)?H:t:t===H?e===H?n:H:Ie(e,n,t,d)}function Xe(e,n,t,d){let o={},p=new Set([...Object.keys(e),...Object.keys(n),...Object.keys(t)]);for(let m of p){let u=Ne(re(e,m)?e[m]:H,re(n,m)?n[m]:H,re(t,m)?t[m]:H,d);u!==H&&Ye(o,m,u)}return o}function et(e){return e===null||typeof e!="object"}function ie(e){return typeof e+":"+String(e)}function tt(e,n){for(let t of n){let d=new Set;for(let o of t){if(!re(o,e))return!1;let p=o[e];if(typeof p!="string"&&typeof p!="number")return!1;let m=ie(p);if(d.has(m))return!1;d.add(m)}}return!0}function nt(e,n,t,d){let o=[e,n,t],p=!0;for(let m of o)for(let u of m)te(u)||(p=!1);if(p){for(let m of d.keyCandidates)if(tt(m,o))return{kind:"keyed",field:m};return null}for(let m of o){let u=new Set;for(let b of m){if(!et(b))return null;let T=ie(b);if(u.has(T))return null;u.add(T)}}return{kind:"self"}}function rt(e,n,t,d){let o=nt(e,n,t,d);if(!o)return t;let p=o.kind==="self"?ie:S=>ie(S[o.field]),m=S=>{let v=new Map;for(let B of S)v.set(p(B),B);return v},u=m(e),b=m(n),T=m(t),C=new Map,N=new Set([...u.keys(),...b.keys(),...T.keys()]);for(let S of N){let v=Ne(u.has(S)?u.get(S):H,b.has(S)?b.get(S):H,T.has(S)?T.get(S):H,d);v!==H&&C.set(S,v)}let k=[];for(let S of t){let v=p(S);C.has(v)&&k.push(v)}for(let S=0;S<n.length;S++){let v=p(n[S]);if(!C.has(v)||k.includes(v))continue;let B=0;for(let $=S-1;$>=0;$--){let j=k.indexOf(p(n[$]));if(j!==-1){B=j+1;break}}k.splice(B,0,v)}return k.map(S=>C.get(S))}function oe(e,n,t,d={}){let o=d.keyCandidates?[...d.keyCandidates,...we]:we;return Ie(e===void 0?H:e,n,t,{keyCandidates:o})}function ae(e,n,t,d={}){let o=d.parse||ne,p=[],m=(N,k)=>{if(typeof N!="string")return H;try{return o(N)}catch(S){return p.push(`${k} side is not valid JSON (${S.message})`),H}},u=m(n,"local"),b=m(t,"remote");if(u===H)return{text:t,warnings:p};if(b===H)return{text:n,warnings:p};let T=m(e,"base"),C=oe(T===H?void 0:T,u,b,d);return Z(C,b)?{text:t,warnings:p}:Z(C,u)?{text:n,warnings:p}:{text:JSON.stringify(C,null,2),warnings:p}}var ce=(function(){"use strict";let e=()=>{},n='[save-ignore],[snapshot-remove],[no-snapshot],[no-save],[save-remove],[freeze],[save-freeze],[clay~="no-save"],[clay~="no-snapshot"],[clay~="freeze"]';function t(l){if(!(l instanceof Element))return!1;if(l.matches(n))return!0;if(l.tagName==="LINK"||l.tagName==="SCRIPT"){let A=l.getAttribute("src")||l.getAttribute("href")||"";if(A.startsWith("chrome-extension://")||A.startsWith("moz-extension://")||A.startsWith("safari-web-extension://"))return!0}return!1}function d(l){return l instanceof Element?l.closest(n)?!0:t(l):!1}let o=ke({shouldIgnore:d});function p(l,A,M){if(M){let O=M.identityOf(l);if(O&&!M.disabled.has(O.key))return"hm-merge:"+O.key}if(A!=="smart")return l.outerHTML;let I=l.getAttribute("src"),E=l.getAttribute("type")||"text/javascript";if(I)try{let O=new URL(I,window.location.href);return`ext:${E}:${O.origin}${O.pathname}${O.search}`}catch{return`ext:${E}:${I}`}else{let O=l.textContent.trim(),c=5381;for(let y=0;y<O.length;y++)c=(c<<5)+c^O.charCodeAt(y);return`inline:${E}:${Math.abs(c).toString(36)}`}}let m="http://www.w3.org/1999/xhtml";function u(l){return l instanceof Element&&l.tagName==="SCRIPT"&&l.namespaceURI===m}function b(l){let A=document.createElement("div");A.innerHTML="<script><\/script>";let M=A.firstChild;for(let I of l.attributes)M.setAttribute(I.name,I.value);return M.textContent=l.textContent,M}function T(l){if(u(l))return b(l);if(l instanceof Element)for(let A of l.querySelectorAll("script"))u(A)&&A.replaceWith(b(A));return l}function C(l){let A=(l.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return A==="application/json"||A.endsWith("+json")}let N={match:l=>l.hasAttribute("merge"),identity:l=>l.getAttribute("merge")};function k(l,A,M){if(M.merge===!1)return null;let I=[N,...M.mergeTags||[]],E=new WeakMap,O=i=>{if(E.has(i))return E.get(i);let h=null;if(u(i)&&!i.getAttribute("src")&&!d(i)){let g=i;for(let w=0;w<I.length;w++)if(I[w].match(g)){if(!C(g))console.warn("[hyper-morph] merge ignored: script type is not JSON",g);else{let x=I[w].identity(g);x!=null&&x!==""&&(h={key:w+":"+x,raw:x,recognizer:I[w]})}break}}return E.set(i,h),h},c=new Set,y=i=>{let h=new Map,g=w=>{let x=O(w);x&&(h.has(x.key)?(c.add(x.key),console.warn(`[hyper-morph] merge disabled for duplicate identity "${x.raw}"`)):h.set(x.key,w))};u(i)&&g(i);for(let w of i.querySelectorAll("script"))g(w);return h},a=y(l),s=y(A.__hyperMorphRoot||A);if(a.size===0&&s.size===0)return null;let r=null;return{identityOf:O,disabled:c,oldByKey:a,newByKey:s,baseTexts:()=>{if(r)return r;r=new Map;let i=M.mergeBase;if(!i)return r;let h;typeof i=="string"?h=new DOMParser().parseFromString(i,"text/html").documentElement:i instanceof Document?h=i.documentElement:h=i;let g=w=>{let x=O(w);x&&!r.has(x.key)&&r.set(x.key,w.textContent)};u(h)&&g(h);for(let w of h.querySelectorAll("script"))g(w);return r}}}function S(l,A,M){let I=l.merge;if(!I)return!1;let E=I.identityOf(A);if(!E||I.disabled.has(E.key))return!1;let O=I.identityOf(M);if(!O||O.key!==E.key)return!1;let c=A,y=M,a=y.getAttribute("merge-key")||c.getAttribute("merge-key"),{text:s,warnings:r}=ae(I.baseTexts().get(E.key),c.textContent,y.textContent,{parse:E.recognizer.parse,keyCandidates:a?a.split(/[\s,]+/).filter(Boolean):void 0});for(let f of r)console.warn(`[hyper-morph] merge "${E.raw}": ${f}`);return c.textContent!==s&&(c.textContent=s),!0}let v={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:l=>l.getAttribute("im-preserve")==="true",shouldReAppend:l=>l.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},scripts:{handle:!0,matchMode:"outerHTML",shouldPreserve:l=>l.getAttribute("im-preserve")==="true",shouldReAppend:l=>l.getAttribute("im-re-append")==="true",shouldRemove:e,afterScriptsHandled:e},restoreFocus:!0},B={computeMatches(l,A){let{computeMatches:M}=o.session();return M(l,A)}};function $(l,A,M={}){l=xe(l);let I=ge(A),E=Te(l,I,M),O=E.scripts.handle?new Set(Array.from(l.querySelectorAll("script")).map(s=>p(s,E.scripts.matchMode,E.merge))):null,c=K(E),y=U(E,l,I,s=>s.morphStyle==="innerHTML"?(q(s,l,I),Array.from(l.childNodes)):V(s,l,I)),a=s=>{c&&X(E,c),j(E);let r=O?Oe(s,O,E):[];return r.length>0?Promise.all(r).then(()=>s):s};return y instanceof Promise?y.then(a):a(y)}function j(l){for(let A of Array.from(l.pantry.childNodes))l.callbacks.beforeNodeRemoved(A)!==!1&&l.callbacks.afterNodeRemoved(A);l.pantry.remove()}function V(l,A,M){let I=ge(A);return q(l,I,M,A,A.nextSibling),Array.from(I.childNodes)}function K(l){if(!l.config.restoreFocus)return null;let A=document.activeElement;if(!(A instanceof HTMLInputElement||A instanceof HTMLTextAreaElement))return null;let{id:M,selectionStart:I,selectionEnd:E}=A;return{element:A,id:M,selectionStart:I,selectionEnd:E}}function X(l,A){let M=A.element;if(A.id&&A.id!==document.activeElement?.getAttribute("id")&&(M=l.target.querySelector(`[id="${CSS.escape(A.id)}"]`),M?.focus()),M&&!M.selectionEnd&&A.selectionEnd!=null)try{M.setSelectionRange(A.selectionStart,A.selectionEnd)}catch{}}let q=(function(){function l(s,r,f,i=null,h=null){r instanceof HTMLTemplateElement&&f instanceof HTMLTemplateElement&&(r=r.content,f=f.content),i||=r.firstChild;for(let g of f.childNodes){if(t(g))continue;if(i&&i!=h){let x=M(s,g,i,h);if(x){x!==i&&E(s,i,x),W(x,g,s),i=x.nextSibling;continue}}if(g instanceof Element){let x=g.getAttribute("id");if(s.persistentIds.has(x)){let L=O(r,x,i,s);W(L,g,s),i=L.nextSibling;continue}if(!s.idMap.has(g)){let L=s.hyperMatches.get(g);if(L&&!s.idMap.has(L)&&!a(L,r)){y(r,L,i),W(L,g,s),i=L.nextSibling;continue}}}let w=A(r,g,i,s);w&&(i=w.nextSibling)}for(;i&&i!=h;){let g=i;i=i.nextSibling,t(g)||I(s,g)}}function A(s,r,f,i){if(i.callbacks.beforeNodeAdded(r)===!1)return null;if(i.idMap.has(r)){let h=r,g=document.createElementNS(h.namespaceURI,h.localName);return s.insertBefore(g,f),W(g,r,i),i.callbacks.afterNodeAdded(g),g}else{let h=T(document.importNode(r,!0));return s.insertBefore(h,f),i.callbacks.afterNodeAdded(h),h}}let M=(function(){function s(i,h,g,w){let x=h instanceof Element&&!i.idMap.has(h)?i.hyperMatches.get(h):null,L=null,F=h.nextSibling,J=0,R=g;for(;R&&R!=w;){if(t(R)){R=R.nextSibling;continue}if(f(R,h)){if(r(i,R,h)||R===x&&!i.idMap.has(R))return R;if(L===null){let P=R instanceof Element&&i.hyperMatchedOldElements.has(R);!i.idMap.has(R)&&!P&&(L=R)}}if(L===null&&F&&f(R,F)&&(J++,F=F.nextSibling,J>=2&&(L=void 0)),i.activeElementAndParents.includes(R))break;R=R.nextSibling}return L||null}function r(i,h,g){let w=i.idMap.get(h),x=i.idMap.get(g);if(!x||!w)return!1;for(let L of w)if(x.has(L))return!0;return!1}function f(i,h){let g=i,w=h;return g.nodeType===w.nodeType&&g.tagName===w.tagName&&(!g.getAttribute?.("id")||g.getAttribute?.("id")===w.getAttribute?.("id"))}return s})();function I(s,r){let f=r instanceof Element&&s.hyperMatchedOldElements.has(r)&&!s.idMap.has(r);if(s.idMap.has(r)||f)y(s.pantry,r,null);else{if(s.callbacks.beforeNodeRemoved(r)===!1)return;r.parentNode?.removeChild(r),s.callbacks.afterNodeRemoved(r)}}function E(s,r,f){let i=r;for(;i&&i!==f;){let h=i;i=i.nextSibling,t(h)||I(s,h)}return i}function O(s,r,f,i){let h=i.target.getAttribute?.("id")===r&&i.target||i.target.querySelector(`[id="${CSS.escape(r)}"]`)||i.pantry.querySelector(`[id="${CSS.escape(r)}"]`);return c(h,i),y(s,h,f),h}function c(s,r){let f=s.getAttribute("id");for(;s=s.parentNode;){let i=r.idMap.get(s);i&&(i.delete(f),i.size||r.idMap.delete(s))}}function y(s,r,f){if(s.moveBefore)try{s.moveBefore(r,f)}catch{s.insertBefore(r,f)}else s.insertBefore(r,f)}function a(s,r){let f=r instanceof Element?r:r.realParentNode;return!!f&&s.contains(f)}return l})(),W=(function(){function l(c,y,a){return a.ignoreActive&&c===document.activeElement?null:(a.callbacks.beforeNodeMorphed(c,y)===!1||(c instanceof HTMLHeadElement&&a.head.ignore||(c instanceof HTMLHeadElement&&a.head.style!=="morph"?Q(c,y,a):(A(c,y,a),S(a,c,y)||O(c,a)||q(a,c,y))),a.callbacks.afterNodeMorphed(c,y)),c)}function A(c,y,a){let s=y.nodeType;if(s===1){let r=c,f=y,i=r.attributes,h=f.attributes;for(let g of h)E(g.name,r,"update",a)||r.getAttribute(g.name)!==g.value&&r.setAttribute(g.name,g.value);for(let g=i.length-1;0<=g;g--){let w=i[g];if(w&&!f.hasAttribute(w.name)){if(E(w.name,r,"remove",a))continue;r.removeAttribute(w.name)}}O(r,a)||M(r,f,a)}(s===8||s===3)&&c.nodeValue!==y.nodeValue&&(c.nodeValue=y.nodeValue)}function M(c,y,a){if(c instanceof HTMLInputElement&&y instanceof HTMLInputElement&&y.type!=="file"){let s=y.value,r=c.value;I(c,y,"checked",a),I(c,y,"disabled",a),a.formStateSync==="property"&&c.indeterminate!==y.indeterminate&&(c.indeterminate=y.indeterminate),a.formStateSync==="property"?r!==s&&(E("value",c,"update",a)||(c.value=s)):y.hasAttribute("value")?r!==s&&(E("value",c,"update",a)||(c.setAttribute("value",s),c.value=s)):E("value",c,"remove",a)||(c.value="",c.removeAttribute("value"))}else if(c instanceof HTMLOptionElement&&y instanceof HTMLOptionElement)I(c,y,"selected",a);else if(c instanceof HTMLTextAreaElement&&y instanceof HTMLTextAreaElement){let s=y.value,r=c.value;if(E("value",c,"update",a)||(s!==r&&(c.value=s),a.formStateSync==="property"))return;c.firstChild&&c.firstChild.nodeValue!==s&&(c.firstChild.nodeValue=s)}}function I(c,y,a,s){let r=y[a],f=c[a];if(r!==f){let i=E(a,c,"update",s);if(i||(c[a]=y[a]),s.formStateSync==="property")return;r?i||c.setAttribute(a,""):E(a,c,"remove",s)||c.removeAttribute(a)}}function E(c,y,a,s){return c==="value"&&s.ignoreActiveValue&&y===document.activeElement?!0:s.callbacks.beforeAttributeUpdated(c,y,a)===!1}function O(c,y){return!!y.ignoreActiveValue&&c===document.activeElement&&c!==document.body}return l})();function U(l,A,M,I){if(l.head.block){let E=A.querySelector("head"),O=M.querySelector("head");if(E&&O){let c=Q(E,O,l);return Promise.all(c).then(()=>(l.head.block=!1,l.head.ignore=!0,I(l)))}}return I(l)}function se(l){return l.tagName==="SCRIPT"?!!l.getAttribute("src"):l.tagName==="LINK"?(l.getAttribute("rel")||"").toLowerCase().split(/\s+/).includes("stylesheet")&&!!l.getAttribute("href"):!1}function Q(l,A,M){let I=[],E=[],O=[],c=[],y=M.scripts.matchMode,a=f=>{if(f.tagName==="SCRIPT")return p(f,y,M.merge);if(f.tagName==="LINK"&&y==="smart"){let i=f.getAttribute("href");if(i)try{let h=new URL(i,window.location.href);return`link:${f.getAttribute("rel")||""}:${h.origin}${h.pathname}${h.search}`}catch{}}return f.outerHTML},s=new Map;for(let f of A.children){if(t(f))continue;let i=a(f),h=s.get(i);h||(h=[],s.set(i,h)),h.push(f)}for(let f of l.children){let i=a(f),h=s.get(i),g=!!(h&&h.length),w=M.head.shouldReAppend(f),x=M.head.shouldPreserve(f);if(g||x)if(w)E.push(f);else{if(h&&h.length){let L=h.pop();h.length||s.delete(i),S(M,f,L)}O.push(f)}else M.head.style==="append"?w&&(E.push(f),c.push(f)):M.head.shouldRemove(f)!==!1&&!t(f)&&E.push(f)}for(let f of s.values())c.push(...f);let r=[];for(let f of c){let i=document.createRange().createContextualFragment(f.outerHTML).firstChild;if(M.callbacks.beforeNodeAdded(i)!==!1){if(i instanceof Element&&se(i)){let h,g=new Promise(function(w){h=w});i.addEventListener("load",function(){h()}),i.addEventListener("error",function(){h()}),r.push(g)}l.appendChild(i),M.callbacks.afterNodeAdded(i),I.push(i)}}for(let f of E)M.callbacks.beforeNodeRemoved(f)!==!1&&(l.removeChild(f),M.callbacks.afterNodeRemoved(f));return M.head.afterHeadMorphed(l,{added:I,kept:O,removed:E}),r}function Oe(l,A,M){if(!M.scripts.handle)return[];let I=[],E=[],O=[],c=[],y=M.scripts.matchMode,a=[];for(let r of l)if(r instanceof Element){u(r)&&a.push(r);for(let f of r.querySelectorAll("script"))u(f)&&a.push(f)}for(let r of a){if(r.closest("head")||d(r))continue;let f=p(r,y,M.merge),i=A.has(f),h=M.scripts.shouldPreserve(r),g=M.scripts.shouldReAppend(r);i||h?g?(E.push(r),c.push(r)):O.push(r):c.push(r)}let s=[];for(let r of c){if(M.callbacks.beforeNodeAdded(r)===!1)continue;let f=document.createElement("script");for(let i of r.attributes)f.setAttribute(i.name,i.value);if(f.textContent=r.textContent,f.src){let i,h=new Promise(function(g){i=g});f.addEventListener("load",function(){i()}),f.addEventListener("error",function(){i()}),s.push(h)}r.replaceWith(f),M.callbacks.afterNodeAdded(f),I.push(f)}return M.scripts.afterScriptsHandled(M.target,{added:I,kept:O,removed:E}),s}let Te=(function(){function l(a,s,r){let{persistentIds:f,idMap:i}=c(a,s),h=B.computeMatches(a,s);if(typeof r.key=="function"){let F=new Map,J=new Set,R=D=>{let _=r.key(D);_!=null&&(F.has(_)?J.add(_):F.set(_,D))};a instanceof Element&&R(a);for(let D of a.querySelectorAll("*"))R(D);for(let D of J)F.delete(D);let P=new Map;for(let[D,_]of h)P.set(_,D);let Y=s.__hyperMorphRoot||s,G=new Map,me=new Set,ye=D=>{let _=r.key(D);_!=null&&(G.has(_)?me.add(_):G.set(_,D))};Y instanceof Element&&ye(Y);for(let D of Y.querySelectorAll("*"))ye(D);for(let D of me)G.delete(D);for(let[D,_]of G){let ee=F.get(D);if(!ee||ee.tagName!==_.tagName)continue;let ue=P.get(ee);ue&&ue!==_&&h.delete(ue);let le=h.get(_);le&&le!==ee&&P.delete(le),h.set(_,ee),P.set(ee,_)}}let g=A(r),w=k(a,s,g.scripts);if(w){let F=new Map;for(let[J,R]of h)F.set(R,J);for(let[J,R]of w.newByKey){if(w.disabled.has(J))continue;let P=w.oldByKey.get(J);if(!P)continue;let Y=F.get(P);Y&&Y!==R&&h.delete(Y);let G=h.get(R);G&&G!==P&&F.delete(G),h.set(R,P),F.set(P,R)}}let x=new Set;for(let F of h.values())x.add(F);let L=g.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes(L))throw new Error(`Do not understand how to morph style ${L}`);return{target:a,newContent:s,config:g,morphStyle:L,ignoreActive:g.ignoreActive,ignoreActiveValue:g.ignoreActiveValue,restoreFocus:g.restoreFocus,formStateSync:g.formStateSync||"attribute",idMap:i,persistentIds:f,hyperMatches:h,hyperMatchedOldElements:x,merge:w,pantry:M(),activeElementAndParents:I(a),callbacks:g.callbacks,head:g.head,scripts:g.scripts}}function A(a){let s=Object.assign({},v);return Object.assign(s,a),s.callbacks=Object.assign({},v.callbacks,a.callbacks),s.head=Object.assign({},v.head,a.head),s.scripts=Object.assign({},v.scripts,a.scripts),s}function M(){let a=document.createElement("div");return a.hidden=!0,document.body.insertAdjacentElement("afterend",a),a}function I(a){let s=[],r=document.activeElement;if(r?.tagName!=="BODY"&&a.contains(r))for(;r&&(s.push(r),r!==a);)r=r.parentElement;return s}function E(a){let s=Array.from(a.querySelectorAll("[id]"));return a.getAttribute?.("id")&&s.push(a),s}function O(a,s,r,f){for(let i of f){let h=i.getAttribute("id");if(s.has(h)){let g=i;for(;g;){let w=a.get(g);if(w==null&&(w=new Set,a.set(g,w)),w.add(h),g===r)break;g=g.parentElement}}}}function c(a,s){let r=E(a),f=E(s),i=y(r,f),h=new Map;O(h,i,a,r);let g=s.__hyperMorphRoot||s;return O(h,i,g,f),{persistentIds:i,idMap:h}}function y(a,s){let r=new Set,f=new Map;for(let h of a){let g=h.getAttribute("id");f.has(g)?r.add(g):f.set(g,h.tagName)}let i=new Set;for(let h of s){let g=h.getAttribute("id");i.has(g)?r.add(g):f.get(g)===h.tagName&&i.add(g)}for(let h of r)i.delete(h);return i}return l})(),{normalizeElement:xe,normalizeParent:ge}=(function(){let l=new WeakSet;function A(c){return c instanceof Document?c.documentElement:c}function M(c){if(c==null)return document.createElement("div");if(typeof c=="string")return M(O(c));if(l.has(c))return c;if(c instanceof Node){if(c.parentNode)return new I(c);{let y=document.createElement("div");return y.append(c),y}}else{let y=document.createElement("div");for(let a of[...c])y.append(a);return y}}class I{constructor(y){this.originalNode=y,this.realParentNode=y.parentNode,this.previousSibling=y.previousSibling,this.nextSibling=y.nextSibling}get childNodes(){let y=[],a=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;a&&a!=this.nextSibling;)y.push(a),a=a.nextSibling;return y}querySelectorAll(y){return this.childNodes.reduce((a,s)=>{if(s instanceof Element){s.matches(y)&&a.push(s);let r=s.querySelectorAll(y);for(let f=0;f<r.length;f++)a.push(r[f])}return a},[])}insertBefore(y,a){return this.realParentNode.insertBefore(y,a)}moveBefore(y,a){return this.realParentNode.moveBefore(y,a)}get __hyperMorphRoot(){return this.originalNode}}function E(c){let y=f=>`<${f}(?:\\s(?:[^>"']|"[^"]*"|'[^']*')*)?>`,a=c.replace(/<!--[\s\S]*?-->/g,"");for(let f of["script","style","textarea","title"])a=a.replace(new RegExp(`${y(f)}[\\s\\S]*?</${f}\\s*>`,"gi"),"");let s=new RegExp(`${y("svg")}[\\s\\S]*?</svg\\s*>`,"gi"),r;do r=a,a=a.replace(s,"");while(a!==r);return a}function O(c){let y=new DOMParser,a=E(c);if(a.match(/<\/html>/)||a.match(/<\/head>/)||a.match(/<\/body>/)){let s=y.parseFromString(c,"text/html");if(a.match(/<\/html>/))return l.add(s),s;{let r=s.firstChild;return r&&l.add(r),r}}else{let r=y.parseFromString("<body><template>"+c+"</template></body>","text/html").body.querySelector("template").content;return l.add(r),r}}return{normalizeElement:A,normalizeParent:M}})();return{morph:$,defaults:v,mergeJson:oe,mergeScriptText:ae,parseJsonRelaxed:ne,parseRulesRelaxed:pe}})();var st=ce.morph,it=ce.defaults;var ot=ce;return $e(at);})();
2
3
 
3
4
  // Convenience morph wrapper with data-id support
4
5
  var morph = function(oldEl, newEl, options = {}) {