nuclo 0.1.31 → 0.1.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +570 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/nuclo.cjs +1 -1
- package/dist/nuclo.cjs.map +1 -1
- package/dist/nuclo.js +1 -1
- package/dist/nuclo.js.map +1 -1
- package/dist/nuclo.umd.js +1 -1
- package/dist/nuclo.umd.js.map +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,570 @@
|
|
|
1
|
+
# nuclo
|
|
2
|
+
|
|
3
|
+
**A DOM library for people who peaked in the jQuery era and never looked back.**
|
|
4
|
+
|
|
5
|
+
_Yes, this is yet another JavaScript library. We're aware. The ecosystem now has more libraries than actual developers. We're sorry. Or you're welcome? We're still figuring it out._
|
|
6
|
+
|
|
7
|
+
Build reactive UIs without the magic tricks. Just functions, mutations, and a single `update()` call when you feel like it.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import 'nuclo';
|
|
11
|
+
|
|
12
|
+
let count = 0;
|
|
13
|
+
|
|
14
|
+
const counter = div(
|
|
15
|
+
h1(() => `Count: ${count}`),
|
|
16
|
+
button('Increment', on('click', () => {
|
|
17
|
+
count++;
|
|
18
|
+
update();
|
|
19
|
+
}))
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
render(counter);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Why nuclo?
|
|
26
|
+
|
|
27
|
+
- **Zero magic** – Like a microwave with just one button. You press `update()`, stuff happens.
|
|
28
|
+
- **No virtual DOM** – Why simulate the DOM when you can just... use the DOM? *taps forehead*
|
|
29
|
+
- **Tiny footprint** – Smaller than your average React component's prop types
|
|
30
|
+
- **Global API** – `div()` is everywhere, like that one friend who shows up uninvited but makes everything fun
|
|
31
|
+
- **TypeScript-first** – All 140+ tags typed. Yes, even `<bdi>`. You're welcome.
|
|
32
|
+
- **Real reactivity** – Updates only what changed. Your browser's repaint budget will thank you.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install nuclo
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Usage
|
|
43
|
+
|
|
44
|
+
Simply import once to register all global functions:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import 'nuclo';
|
|
48
|
+
|
|
49
|
+
// Now use div(), update(), on(), list(), when(), render(), etc. globally
|
|
50
|
+
let count = 0;
|
|
51
|
+
const app = div(
|
|
52
|
+
h1(() => `Count: ${count}`),
|
|
53
|
+
button('Click', on('click', () => { count++; update(); }))
|
|
54
|
+
);
|
|
55
|
+
render(app);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### TypeScript Setup
|
|
59
|
+
|
|
60
|
+
Add to your `tsconfig.json`:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"compilerOptions": {
|
|
65
|
+
"types": ["nuclo/types"]
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Or in your `vite-env.d.ts`:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
/// <reference types="nuclo/types" />
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Quick Examples
|
|
79
|
+
|
|
80
|
+
### Counter
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import 'nuclo';
|
|
84
|
+
|
|
85
|
+
let count = 0;
|
|
86
|
+
|
|
87
|
+
const app = div(
|
|
88
|
+
h1(() => `Count: ${count}`),
|
|
89
|
+
button('Increment', on('click', () => { count++; update(); })),
|
|
90
|
+
button('Reset', on('click', () => { count = 0; update(); }))
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
render(app);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Todo List
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import 'nuclo';
|
|
100
|
+
|
|
101
|
+
type Todo = { id: number; text: string; done: boolean };
|
|
102
|
+
|
|
103
|
+
let todos: Todo[] = [];
|
|
104
|
+
let nextId = 1;
|
|
105
|
+
let input = '';
|
|
106
|
+
|
|
107
|
+
function addTodo() {
|
|
108
|
+
if (!input.trim()) return;
|
|
109
|
+
todos.push({ id: nextId++, text: input, done: false });
|
|
110
|
+
input = '';
|
|
111
|
+
update();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const app = div(
|
|
115
|
+
{ className: 'todo-app' },
|
|
116
|
+
|
|
117
|
+
// Input
|
|
118
|
+
div(
|
|
119
|
+
input({ value: () => input },
|
|
120
|
+
on('input', e => { input = e.target.value; update(); }),
|
|
121
|
+
on('keydown', e => e.key === 'Enter' && addTodo())
|
|
122
|
+
),
|
|
123
|
+
button('Add', on('click', addTodo))
|
|
124
|
+
),
|
|
125
|
+
|
|
126
|
+
// List
|
|
127
|
+
when(() => todos.length > 0,
|
|
128
|
+
list(() => todos, (todo) =>
|
|
129
|
+
div(
|
|
130
|
+
{ className: () => todo.done ? 'done' : '' },
|
|
131
|
+
input({ type: 'checkbox', checked: () => todo.done },
|
|
132
|
+
on('change', () => { todo.done = !todo.done; update(); })
|
|
133
|
+
),
|
|
134
|
+
span(() => todo.text),
|
|
135
|
+
button('×', on('click', () => {
|
|
136
|
+
todos = todos.filter(t => t.id !== todo.id);
|
|
137
|
+
update();
|
|
138
|
+
}))
|
|
139
|
+
)
|
|
140
|
+
)
|
|
141
|
+
).else(
|
|
142
|
+
p('No todos yet!')
|
|
143
|
+
)
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
render(app);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Real-time Search Filter
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
import 'nuclo';
|
|
153
|
+
|
|
154
|
+
const users = [
|
|
155
|
+
{ id: 1, name: 'Alice Johnson', email: 'alice@example.com' },
|
|
156
|
+
{ id: 2, name: 'Bob Smith', email: 'bob@example.com' },
|
|
157
|
+
{ id: 3, name: 'Charlie Brown', email: 'charlie@example.com' }
|
|
158
|
+
];
|
|
159
|
+
|
|
160
|
+
let searchQuery = '';
|
|
161
|
+
|
|
162
|
+
function filteredUsers() {
|
|
163
|
+
const q = searchQuery.toLowerCase();
|
|
164
|
+
return users.filter(u =>
|
|
165
|
+
u.name.toLowerCase().includes(q) ||
|
|
166
|
+
u.email.toLowerCase().includes(q)
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const app = div(
|
|
171
|
+
h1('User Directory'),
|
|
172
|
+
|
|
173
|
+
input(
|
|
174
|
+
{
|
|
175
|
+
type: 'search',
|
|
176
|
+
placeholder: 'Search users...',
|
|
177
|
+
value: () => searchQuery
|
|
178
|
+
},
|
|
179
|
+
on('input', e => {
|
|
180
|
+
searchQuery = e.target.value;
|
|
181
|
+
update();
|
|
182
|
+
})
|
|
183
|
+
),
|
|
184
|
+
|
|
185
|
+
when(() => filteredUsers().length > 0,
|
|
186
|
+
list(() => filteredUsers(), user =>
|
|
187
|
+
div(
|
|
188
|
+
{ className: 'user-card' },
|
|
189
|
+
h3(user.name),
|
|
190
|
+
p(user.email)
|
|
191
|
+
)
|
|
192
|
+
)
|
|
193
|
+
).else(
|
|
194
|
+
p(() => `No users found for "${searchQuery}"`)
|
|
195
|
+
)
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
render(app);
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Loading States & Async
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
import 'nuclo';
|
|
205
|
+
|
|
206
|
+
type State = { status: 'idle' | 'loading' | 'error'; data: any[]; error?: string };
|
|
207
|
+
|
|
208
|
+
let state: State = { status: 'idle', data: [] };
|
|
209
|
+
|
|
210
|
+
async function fetchData() {
|
|
211
|
+
state.status = 'loading';
|
|
212
|
+
update();
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
const response = await fetch('/api/data');
|
|
216
|
+
state.data = await response.json();
|
|
217
|
+
state.status = 'idle';
|
|
218
|
+
} catch (err) {
|
|
219
|
+
state.status = 'error';
|
|
220
|
+
state.error = err.message;
|
|
221
|
+
}
|
|
222
|
+
update();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const app = div(
|
|
226
|
+
button('Load Data', on('click', fetchData)),
|
|
227
|
+
|
|
228
|
+
when(() => state.status === 'loading',
|
|
229
|
+
div('Loading...')
|
|
230
|
+
).when(() => state.status === 'error',
|
|
231
|
+
div({ className: 'error' }, () => `Error: ${state.error}`)
|
|
232
|
+
).when(() => state.data.length > 0,
|
|
233
|
+
list(() => state.data, item => div(item.name))
|
|
234
|
+
).else(
|
|
235
|
+
div('No data loaded')
|
|
236
|
+
)
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
render(app);
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Core Concepts
|
|
245
|
+
|
|
246
|
+
### 1. **Explicit Updates**
|
|
247
|
+
|
|
248
|
+
Unlike React or Vue, nuclo doesn't auto-detect changes. You call `update()` when ready:
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
let name = 'World';
|
|
252
|
+
|
|
253
|
+
// Mutate freely
|
|
254
|
+
name = 'Alice';
|
|
255
|
+
name = name.toUpperCase();
|
|
256
|
+
|
|
257
|
+
// Update once when ready
|
|
258
|
+
update();
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
**Advantages of explicit `update()`:**
|
|
262
|
+
|
|
263
|
+
- **Performance**: Batch mutations like a responsible adult. One `update()` > ten thousand proxy getters watching your every variable assignment like helicopter parents.
|
|
264
|
+
- **Control**: You're the boss of when pixels change. Perfect for animations, async chaos, or coordinating changes without asking a framework permission.
|
|
265
|
+
- **Predictability**: Zero surprise re-renders. No "why did this component update 47 times?!" sessions in DevTools.
|
|
266
|
+
- **Simplicity**: No proxies, no dependency graphs, no PhD required. Just objects and a function named `update()`. Revolutionary, we know.
|
|
267
|
+
- **Debugging**: Put a breakpoint at `update()`. That's it. That's the whole debugging strategy.
|
|
268
|
+
|
|
269
|
+
```ts
|
|
270
|
+
// Example: Batch updates for better performance
|
|
271
|
+
items.push(item1);
|
|
272
|
+
items.push(item2);
|
|
273
|
+
items.sort();
|
|
274
|
+
user.name = 'Alice';
|
|
275
|
+
update(); // One update for all changes
|
|
276
|
+
|
|
277
|
+
// vs. automatic tracking (hypothetical)
|
|
278
|
+
items.push(item1); // triggers update
|
|
279
|
+
items.push(item2); // triggers update
|
|
280
|
+
items.sort(); // triggers update
|
|
281
|
+
user.name = 'Alice'; // triggers update
|
|
282
|
+
// 4 updates instead of 1!
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### 2. **Reactive Functions**
|
|
286
|
+
|
|
287
|
+
Zero-arg functions become reactive:
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
let count = 0;
|
|
291
|
+
|
|
292
|
+
div(
|
|
293
|
+
() => `Count: ${count}`, // Updates when update() is called
|
|
294
|
+
{ title: () => `Current: ${count}` } // Attributes too
|
|
295
|
+
)
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### 3. **Conditional Rendering with `when`**
|
|
299
|
+
|
|
300
|
+
First matching condition wins:
|
|
301
|
+
|
|
302
|
+
```ts
|
|
303
|
+
when(() => user.isAdmin,
|
|
304
|
+
div('Admin Panel')
|
|
305
|
+
).when(() => user.isLoggedIn,
|
|
306
|
+
div('User Dashboard')
|
|
307
|
+
).else(
|
|
308
|
+
div('Please log in')
|
|
309
|
+
)
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
DOM is preserved if the active branch doesn't change.
|
|
313
|
+
|
|
314
|
+
### 4. **List Synchronization**
|
|
315
|
+
|
|
316
|
+
Lists use object identity (not keys) to track items:
|
|
317
|
+
|
|
318
|
+
```ts
|
|
319
|
+
list(() => items, (item, index) =>
|
|
320
|
+
div(() => `${index}: ${item.name}`)
|
|
321
|
+
)
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Mutate the array (push, splice, reverse), then call `update()`. Elements are reused if the item reference is the same.
|
|
325
|
+
|
|
326
|
+
## API Reference
|
|
327
|
+
|
|
328
|
+
### Core Functions
|
|
329
|
+
|
|
330
|
+
#### `update()`
|
|
331
|
+
|
|
332
|
+
Triggers all reactive updates. Call this after mutating state:
|
|
333
|
+
|
|
334
|
+
```ts
|
|
335
|
+
count++;
|
|
336
|
+
items.push(newItem);
|
|
337
|
+
update();
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
#### `list(provider, renderer)`
|
|
341
|
+
|
|
342
|
+
Synchronizes an array to DOM elements:
|
|
343
|
+
|
|
344
|
+
```ts
|
|
345
|
+
list(
|
|
346
|
+
() => items, // Provider function
|
|
347
|
+
(item, index) => div( // Renderer
|
|
348
|
+
() => `${index}: ${item.name}`
|
|
349
|
+
)
|
|
350
|
+
)
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
Items are tracked by object identity. Mutate the array and call `update()` to sync.
|
|
354
|
+
|
|
355
|
+
#### `when(condition, ...content)`
|
|
356
|
+
|
|
357
|
+
Conditional rendering with chaining:
|
|
358
|
+
|
|
359
|
+
```ts
|
|
360
|
+
when(() => count > 10,
|
|
361
|
+
div('High')
|
|
362
|
+
).when(() => count > 0,
|
|
363
|
+
div('Low')
|
|
364
|
+
).else(
|
|
365
|
+
div('Zero')
|
|
366
|
+
)
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
First matching condition wins. DOM is preserved if the active branch doesn't change.
|
|
370
|
+
|
|
371
|
+
#### `on(event, handler, options?)`
|
|
372
|
+
|
|
373
|
+
Attach event listeners:
|
|
374
|
+
|
|
375
|
+
```ts
|
|
376
|
+
button('Click me',
|
|
377
|
+
on('click', () => console.log('clicked')),
|
|
378
|
+
on('mouseenter', handleHover, { passive: true })
|
|
379
|
+
)
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### Tag Builders
|
|
383
|
+
|
|
384
|
+
All HTML and SVG tags are available globally:
|
|
385
|
+
|
|
386
|
+
```ts
|
|
387
|
+
div(), span(), button(), input(), h1(), p(), ul(), li()
|
|
388
|
+
svg(), circle(), path(), rect(), g()
|
|
389
|
+
// ... and 140+ more
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### Attributes
|
|
393
|
+
|
|
394
|
+
Pass attributes as objects:
|
|
395
|
+
|
|
396
|
+
```ts
|
|
397
|
+
div('Hello', {
|
|
398
|
+
className: 'container',
|
|
399
|
+
id: 'main',
|
|
400
|
+
'data-test': 'value',
|
|
401
|
+
style: { color: 'red', fontSize: '16px' }
|
|
402
|
+
})
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
Reactive attributes use functions:
|
|
406
|
+
|
|
407
|
+
```ts
|
|
408
|
+
div({
|
|
409
|
+
className: () => isActive ? 'active' : '',
|
|
410
|
+
disabled: () => !isValid,
|
|
411
|
+
style: () => ({ opacity: isVisible ? 1 : 0 })
|
|
412
|
+
})
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
---
|
|
416
|
+
|
|
417
|
+
## Best Practices
|
|
418
|
+
|
|
419
|
+
### Batch Updates
|
|
420
|
+
|
|
421
|
+
Mutate like you're stress-testing the array, then update once like you meant to do that:
|
|
422
|
+
|
|
423
|
+
```ts
|
|
424
|
+
// Galaxy brain
|
|
425
|
+
items.push(item1);
|
|
426
|
+
items.push(item2);
|
|
427
|
+
items.sort();
|
|
428
|
+
update();
|
|
429
|
+
|
|
430
|
+
// Smooth brain (but hey, it works)
|
|
431
|
+
items.push(item1);
|
|
432
|
+
update();
|
|
433
|
+
items.push(item2);
|
|
434
|
+
update();
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
### Object Identity for Lists
|
|
438
|
+
|
|
439
|
+
Lists track items by reference. Mutate the object, not your soul:
|
|
440
|
+
|
|
441
|
+
```ts
|
|
442
|
+
// The way
|
|
443
|
+
todos[0].done = true;
|
|
444
|
+
update();
|
|
445
|
+
|
|
446
|
+
// The dark side (RIP that DOM element, we hardly knew ye)
|
|
447
|
+
todos[0] = { ...todos[0], done: true };
|
|
448
|
+
update();
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
### Use `.else()` for Clarity
|
|
452
|
+
|
|
453
|
+
Even if not initially needed:
|
|
454
|
+
|
|
455
|
+
```ts
|
|
456
|
+
when(() => isLoading,
|
|
457
|
+
div('Loading...')
|
|
458
|
+
).else(
|
|
459
|
+
div('Ready') // Clear intent
|
|
460
|
+
)
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
---
|
|
464
|
+
|
|
465
|
+
## Advanced Patterns
|
|
466
|
+
|
|
467
|
+
### Nested Structures
|
|
468
|
+
|
|
469
|
+
Combine `when` and `list`:
|
|
470
|
+
|
|
471
|
+
```ts
|
|
472
|
+
when(() => user.isLoggedIn,
|
|
473
|
+
div(
|
|
474
|
+
h1(() => `Welcome, ${user.name}`),
|
|
475
|
+
list(() => user.notifications, n =>
|
|
476
|
+
div(n.message, { className: () => n.read ? 'read' : 'unread' })
|
|
477
|
+
)
|
|
478
|
+
)
|
|
479
|
+
).else(
|
|
480
|
+
div('Please log in')
|
|
481
|
+
)
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
### Component-like Functions
|
|
485
|
+
|
|
486
|
+
```ts
|
|
487
|
+
function UserCard(user: User) {
|
|
488
|
+
return div(
|
|
489
|
+
{ className: 'user-card' },
|
|
490
|
+
img({ src: user.avatar }),
|
|
491
|
+
h3(user.name),
|
|
492
|
+
p(user.bio)
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
list(() => users, user => UserCard(user))
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
### Computed Values
|
|
500
|
+
|
|
501
|
+
```ts
|
|
502
|
+
function activeCount() {
|
|
503
|
+
return todos.filter(t => !t.done).length;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
div(
|
|
507
|
+
() => `${activeCount()} remaining`
|
|
508
|
+
)
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
---
|
|
512
|
+
|
|
513
|
+
## Performance
|
|
514
|
+
|
|
515
|
+
- **No virtual DOM diffing** – We skip the middle-manager and talk directly to the DOM
|
|
516
|
+
- **Fine-grained updates** – Only updates what changed. Like a surgeon, not a bulldozer.
|
|
517
|
+
- **Element reuse** – Lists are smart enough to move elements instead of yeeting them into the void
|
|
518
|
+
- **Branch preservation** – `when` branches stay alive unless conditions change. Low-key immortal.
|
|
519
|
+
|
|
520
|
+
For high-frequency updates (animations, game loops, existential crises), batch mutations before calling `update()`.
|
|
521
|
+
|
|
522
|
+
---
|
|
523
|
+
|
|
524
|
+
## Debugging
|
|
525
|
+
|
|
526
|
+
### Inspect Markers
|
|
527
|
+
|
|
528
|
+
Open DevTools, stare at the DOM like it owes you money:
|
|
529
|
+
|
|
530
|
+
```html
|
|
531
|
+
<!-- when-start-1 -->
|
|
532
|
+
<div>Content</div>
|
|
533
|
+
<!-- when-end -->
|
|
534
|
+
|
|
535
|
+
<!-- list-start-2 -->
|
|
536
|
+
<div>Item 1</div>
|
|
537
|
+
<div>Item 2</div>
|
|
538
|
+
<!-- list-end -->
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
These comment markers are your breadcrumbs. Follow them to victory.
|
|
542
|
+
|
|
543
|
+
### Common Issues
|
|
544
|
+
|
|
545
|
+
**Content not updating?**
|
|
546
|
+
- Did you call `update()`? (Asking because 80% of the time, you didn't)
|
|
547
|
+
- Are your conditions/functions returning what you think they are? `console.log()` is your friend.
|
|
548
|
+
|
|
549
|
+
**List items not reusing elements?**
|
|
550
|
+
- Stop spreading objects like it's 2018. Mutate them.
|
|
551
|
+
- Item references need to be stable, not having an identity crisis on every render.
|
|
552
|
+
|
|
553
|
+
---
|
|
554
|
+
|
|
555
|
+
## Roadmap
|
|
556
|
+
|
|
557
|
+
- Keyed list variant (for when object identity isn't your thing)
|
|
558
|
+
- Transition/animation helpers (make things swoosh)
|
|
559
|
+
- Dev mode diagnostics (we'll yell at you when you forget `update()`)
|
|
560
|
+
- SSR support (because apparently servers need to render HTML now)
|
|
561
|
+
|
|
562
|
+
---
|
|
563
|
+
|
|
564
|
+
## License
|
|
565
|
+
|
|
566
|
+
MIT License - see [LICENSE.md](LICENSE.md) for details.
|
|
567
|
+
|
|
568
|
+
This library is free and open source. When using nuclo, please include attribution in your documentation, application, or source code. See the [LICENSE.md](LICENSE.md) file for attribution examples.
|
|
569
|
+
|
|
570
|
+
**TL;DR:** Use it freely, just give credit. It helps others discover this library!
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export { initializeRuntime } from "./core/runtimeBootstrap";
|
|
2
|
-
export { registerGlobalTagBuilders, HTML_TAGS, SVG_TAGS, SELF_CLOSING_TAGS
|
|
2
|
+
export { registerGlobalTagBuilders, HTML_TAGS, SVG_TAGS, SELF_CLOSING_TAGS } from "./core/tagRegistry";
|
|
3
3
|
export { createElementFactory, createTagBuilder } from "./core/elementFactory";
|
|
4
4
|
export { applyNodeModifier } from "./core/modifierProcessor";
|
|
5
|
-
export { list
|
|
5
|
+
export { list } from "./list";
|
|
6
6
|
export { when } from "./when";
|
|
7
7
|
export { update } from "./core/updateController";
|
|
8
8
|
export { applyAttributes } from "./core/attributeManager";
|
|
9
9
|
export { appendChildren } from "./utility/dom";
|
|
10
10
|
export { on } from "./utility/on";
|
|
11
11
|
export { render } from "./utility/render";
|
|
12
|
-
export { isBoolean, isFunction, isNode, isObject, isPrimitive, isTagLike
|
|
12
|
+
export { isBoolean, isFunction, isNode, isObject, isPrimitive, isTagLike } from "./utility/typeGuards";
|
|
13
13
|
export { isBrowser } from "./utility/environment";
|
|
14
14
|
import "./core/runtimeBootstrap";
|
|
15
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,SAAS,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvG,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACvG,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGlD,OAAO,yBAAyB,CAAC"}
|
package/dist/nuclo.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";function e(e){return null===e||"object"!=typeof e&&"function"!=typeof e}function t(e){return e instanceof Node}function n(e){return"object"==typeof e&&null!==e}function r(e){return n(e)&&"tagName"in e}function o(e){return"function"==typeof e}function i(e,t){"undefined"!=typeof console&&console.error(`nuclo: ${e}`,t)}function c(e,t){try{return e()}catch(e){return i("Operation failed",e),t}}const u="undefined"!=typeof window&&"undefined"!=typeof document;function a(e){if(!e?.parentNode)return!1;try{return e.parentNode.removeChild(e),!0}catch{return!1}}function s(e){if(!u)return null;try{return document.createComment(e)}catch{return null}}function l(e){if(!u)throw new Error("Cannot create comment in non-browser environment");const t=s(`${e}-${Math.random().toString(36).slice(2)}`);if(!t)throw new Error("Failed to create comment");return t}function d(e){const t=s(`${e}-end`);if(!t)throw new Error("Failed to create end comment");return{start:l(`${e}-start`),end:t}}function f(e){return!!e&&("boolean"==typeof e.isConnected?e.isConnected:document.contains(e))}const p=new Map,h=new Map;function m(e,t){t.attributeResolvers.forEach(({resolver:e,applyValue:t},n)=>{try{t(c(e))}catch(e){i(`Failed to update reactive attribute: ${n}`,e)}})}function g(e,t){if("function"!=typeof e)return i("Invalid resolver provided to createReactiveTextNode"),document.createTextNode("");const n=arguments.length>1?t:c(e,""),r=void 0===n?"":String(n),o=document.createTextNode(r);return p.set(o,{resolver:e,lastValue:r}),o}function y(e,t,n,r){if(!(e instanceof Element&&t&&"function"==typeof n))return void i("Invalid parameters for registerAttributeResolver");const o=function(e){let t=h.get(e);return t||(t={attributeResolvers:new Map},h.set(e,t)),t}(e);o.attributeResolvers.set(t,{resolver:n,applyValue:r});try{r(c(n))}catch(e){i("Failed to apply initial attribute value",e)}if(!o.updateListener){const t=()=>m(0,o);e.addEventListener("update",t),o.updateListener=t}}function v(e,t){e&&e.style&&t&&Object.entries(t).forEach(([t,n])=>{if(null==n||""===n)e.style.removeProperty(t),e.style[t]="";else try{e.style[t]=String(n)}catch{}})}function b(e,t,n){if(null==n)return;if("style"===t)return i=n,void((r=e)&&(o(i)?y(r,"style",()=>{try{return i()}catch{return null}},e=>{v(r,e)}):v(r,i)));var r,i;const c=n=>{null!=n&&(t in e?e[t]=n:e instanceof Element&&e.setAttribute(String(t),String(n)))};o(n)&&0===n.length?y(e,String(t),n,c):c(n)}function x(e,t){if(t)for(const n of Object.keys(t)){b(e,n,t[n])}}const C=new WeakMap;function E(e){const{value:t,error:n}=function(e){const t=C.get(e);if(t)return t;try{const t={value:e(),error:!1};return C.set(e,t),t}catch{const t={value:void 0,error:!0};return C.set(e,t),t}}(e);return!n&&"boolean"==typeof t}function w(e,r,i){if(!o(e)||0!==e.length||!E(e))return!1;const c=r.filter((e,t)=>t!==i);if(0===c.length)return!1;return c.some(e=>n(e)||t(e)||o(e)&&e.length>0)}function M(r,c,u){if(null==c)return null;if(o(c)){if(0===c.length)try{let t=C.get(c);if(!t){t={value:c(),error:!1},C.set(c,t)}if(t.error){const e=document.createDocumentFragment(),t=document.createComment(` text-${u} `),n=g(()=>"");return e.appendChild(t),e.appendChild(n),e}const n=t.value;if(e(n)&&null!=n){const e=document.createDocumentFragment(),t=document.createComment(` text-${u} `),r=g(c,n);return e.appendChild(t),e.appendChild(r),e}return null}catch(e){C.set(c,{value:void 0,error:!0}),i("Error evaluating reactive text function:",e);const t=document.createDocumentFragment(),n=document.createComment(` text-${u} `),r=g(()=>"");return t.appendChild(n),t.appendChild(r),t}const o=c(r,u);if(null==o)return null;if(e(o)){const e=document.createDocumentFragment(),t=document.createComment(` text-${u} `),n=document.createTextNode(String(o));return e.appendChild(t),e.appendChild(n),e}return t(o)?o:(n(o)&&x(r,o),null)}const a=c;if(null==a)return null;if(e(a)){const e=document.createDocumentFragment(),t=document.createComment(` text-${u} `),n=document.createTextNode(String(a));return e.appendChild(t),e.appendChild(n),e}return t(a)?a:(n(a)&&x(r,a),null)}const S=new Set;function N(e,t){e._conditionalInfo=t,S.add(e)}function k(e,t,n=0){if(!t||0===t.length)return{element:e,nextIndex:n,appended:0};let r=n,o=0;const i=e;for(let n=0;n<t.length;n+=1){const c=t[n];if(null==c)continue;const u=M(e,c,r);u&&(u.parentNode!==i&&i.appendChild(u),r+=1,o+=1)}return{element:e,nextIndex:r,appended:o}}function T(e,t){const n=document.createElement(e);return k(n,t,0),n}function F(e){const t=function(e){for(let t=0;t<e.length;t+=1)if(w(e[t],e,t))return t;return-1}(e);return-1===t?{condition:null,otherModifiers:e}:{condition:e[t],otherModifiers:e.filter((e,n)=>n!==t)}}function I(e,...t){return(n,r)=>{const{condition:o,otherModifiers:i}=F(t);if(o)return function(e,t,n){const r=t();if(!u)return r?T(e,n):document.createComment(`conditional-${e}-ssr`);if(r){const r=T(e,n);return N(r,{condition:t,tagName:e,modifiers:n}),r}const o=document.createComment(`conditional-${e}-hidden`);return N(o,{condition:t,tagName:e,modifiers:n}),o}(e,o,i);const c=document.createElement(e);return k(c,i,r),c}}function L(e){return(...t)=>I(e,...t)}const $=["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","menu","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","script","search","section","select","slot","small","source","span","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr"];function B(e=globalThis){const t="__vc_tags_registered";e[t]||($.forEach(t=>function(e,t){t in e||(e[t]=L(t))}(e,t)),e[t]=!0)}const _=new Set;function D(e,t,n){return function(e,t,n){if(o(e)){const o=e(t,n);return o&&r(o)?o:null}return e&&r(e)?e:null}(e.renderItem(t,n),e.host,n)}function G(e){a(e.element)}function O(e){const{host:t,startMarker:n,endMarker:r}=e,o=n.parentNode??t,i=e.itemsProvider();if(function(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if((n in e?e[n]:void 0)!==(n in t?t[n]:void 0))return!1;return!0}(e.lastSyncedItems,i))return;const c=new Map,u=new Map;e.records.forEach(e=>{const t=u.get(e.item);t?t.push(e):u.set(e.item,[e])}),i.forEach((t,n)=>{if(n<e.lastSyncedItems.length&&e.lastSyncedItems[n]===t){const r=e.records[n];if(r&&r.item===t){c.set(n,r);const e=u.get(t);if(e){const n=e.indexOf(r);n>=0&&(e.splice(n,1),0===e.length&&u.delete(t))}}}});const a=[],s=new Set(e.records);let l=r;for(let t=i.length-1;t>=0;t--){const n=i[t];let r=c.get(t);if(!r){const e=u.get(n);e&&e.length>0&&(r=e.shift(),0===e.length&&u.delete(n))}if(r)s.delete(r);else{const o=D(e,n,t);if(!o)continue;r={item:n,element:o}}a.unshift(r);const d=r.element;d.nextSibling!==l&&o.insertBefore(d,l),l=d}s.forEach(G),e.records=a,e.lastSyncedItems=[...i]}function j(e,t){return n=>{const r=function(e,t,n){const{start:r,end:o}=d("list"),i={itemsProvider:e,renderItem:t,startMarker:r,endMarker:o,records:[],host:n,lastSyncedItems:[]},c=n;return c.appendChild(r),c.appendChild(o),_.add(i),O(i),i}(e,t,n);return r.startMarker}}function A(e,t){try{return e()}catch(e){if(!t)throw e;return t(e),!1}}function P(e,t){return"function"==typeof e?A(e,t):Boolean(e)}const R=new Set;function V(e){const{groups:t,elseContent:n,host:r,index:i,endMarker:c}=e;let u=null;for(let e=0;e<t.length;e++)if(P(t[e].condition)){u=e;break}if(null===u&&n.length&&(u=-1),u===e.activeIndex)return;if(function(e,t){let n=e.nextSibling;for(;n&&n!==t;){const e=n.nextSibling;a(n),n=e}}(e.startMarker,e.endMarker),e.activeIndex=u,null===u)return;const s=[],l=e=>{for(const t of e){if(o(t)){if(0===t.length){C.delete(t);const e=M(r,t,i);e&&s.push(e);continue}const e=r,n=e.appendChild;e.appendChild=function(t){return e.insertBefore(t,c)};try{const e=M(r,t,i);e&&!e.parentNode&&s.push(e)}finally{e.appendChild=n}continue}const e=M(r,t,i);e&&s.push(e)}};u>=0?l(t[u].content):-1===u&&l(n),function(e,t){const n=t.parentNode;n&&e.forEach(e=>function(e,t,n){if(!e||!t)return!1;try{return e.insertBefore(t,n),!0}catch{return!1}}(n,e,t))}(s,c)}class q{groups=[];elseContent=[];constructor(e,...t){this.groups.push({condition:e,content:t})}when(e,...t){return this.groups.push({condition:e,content:t}),this}else(...e){return this.elseContent=e,this}render(e,t){if(!u)return document.createComment("when-ssr");const{start:n,end:r}=d("when"),o={startMarker:n,endMarker:r,host:e,index:t,groups:[...this.groups],elseContent:[...this.elseContent],activeIndex:null,update:()=>V(o)};R.add(o);const i=e;return i.appendChild(n),i.appendChild(r),V(o),n}}function z(e){return Object.assign((t,n)=>e.render(t,n),{when:(t,...n)=>(e.when(t,...n),z(e)),else:(...t)=>(e.else(...t),z(e))})}function H(e,...t){return z(new q(e,...t))}function W(e,t){if(e.parentNode)try{e.parentNode.replaceChild(t,e)}catch(e){console.error("Error replacing conditional node:",e)}}function J(e){const t=function(e){return e._conditionalInfo??null}(e);if(!t)return;const n=A(t.condition,e=>{console.error("Error evaluating conditional condition:",e)}),r=e.nodeType===Node.ELEMENT_NODE;if(n&&!r){const n=function(e){const t=document.createElement(e.tagName);try{k(t,e.modifiers,0)}catch(t){console.error(`Error applying modifiers in conditional element "${e.tagName}":`,t)}return t}(t);N(n,t),W(e,n)}else if(!n&&r){const n=function(e){return document.createComment(`conditional-${e.tagName}-hidden`)}(t);N(n,t),W(e,n)}}const K=[function(){_.forEach(e=>{e.startMarker.isConnected&&e.endMarker.isConnected?O(e):_.delete(e)})},function(){R.forEach(e=>{try{e.update()}catch(t){R.delete(e)}})},function(){if(u)try{S.forEach(e=>{e.isConnected?J(e):function(e){S.delete(e)}(e)})}catch(e){console.error("Error during conditional elements update:",e)}},function(){h.forEach((e,t)=>{if(!f(t))return e.updateListener&&t.removeEventListener("update",e.updateListener),void h.delete(t);m(0,e)})},function(){p.forEach((e,t)=>{if(f(t))try{const n=c(e.resolver),r=void 0===n?"":String(n);r!==e.lastValue&&(t.textContent=r,e.lastValue=r)}catch(e){i("Failed to update reactive text node",e)}else p.delete(t)})},function(){if("undefined"==typeof document)return;const e=[];document.body&&e.push(document.body),e.push(document),e.forEach(e=>{try{e.dispatchEvent(new Event("update",{bubbles:!0}))}catch(e){console.error("Error dispatching global update event:",e)}})}];function Q(){for(const e of K)e()}function U(e,t,n){return r=>{const o=r;if(!o||"function"!=typeof o.addEventListener)return;o.addEventListener(e,n=>{try{t.call(o,n)}catch(t){"undefined"!=typeof console&&console.error&&console.error(`[nuclo:on] Error in '${e}' listener:`,t)}},n)}}function X(e,t,n=0){const r=e(t||document.body,n);return(t||document.body).appendChild(r),r}function Y(){if(B(),"undefined"!=typeof globalThis){const e=globalThis;e.list=j,e.update=Q,e.when=H,e.on=U,e.render=X}}"undefined"!=typeof globalThis&&Y(),console.log("nuclo"),exports.HTML_TAGS=$,exports.SELF_CLOSING_TAGS=["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"],exports.SVG_TAGS=["a","animate","animateMotion","animateTransform","circle","clipPath","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","foreignObject","g","image","line","linearGradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialGradient","rect","script","set","stop","style","svg","switch","symbol","text","textPath","title","tspan","use","view"],exports.appendChildren=function(e,...t){return e?(t.forEach(t=>{if(null!=t){let n;if("string"==typeof t){const e=function(e){if(!u)return null;try{return document.createTextNode(String(e))}catch{return null}}(t);if(!e)return;n=e}else n=t;!function(e,t){if(!e||!t)return!1;try{return e.appendChild(t),!0}catch{return!1}}(e,n)}}),e):e},exports.applyAttributes=x,exports.applyNodeModifier=M,exports.createElementFactory=I,exports.createTagBuilder=L,exports.initializeRuntime=Y,exports.isBoolean=function(e){return"boolean"==typeof e},exports.isBrowser=u,exports.isFunction=o,exports.isNode=t,exports.isObject=n,exports.isPrimitive=e,exports.isTagLike=r,exports.list=j,exports.on=U,exports.registerGlobalTagBuilders=B,exports.render=X,exports.update=Q,exports.when=H;
|
|
1
|
+
"use strict";function e(e){return null===e||"object"!=typeof e&&"function"!=typeof e}function t(e){return e instanceof Node}function n(e){return"object"==typeof e&&null!==e}function r(e){return n(e)&&"tagName"in e}function o(e){return"function"==typeof e}function i(e,t){"undefined"!=typeof console&&console.error(`nuclo: ${e}`,t)}function c(e,t){try{return e()}catch(e){return i("Operation failed",e),t}}const u="undefined"!=typeof window&&"undefined"!=typeof document;function a(e){if(!e?.parentNode)return!1;try{return e.parentNode.removeChild(e),!0}catch{return!1}}function s(e){if(!u)return null;try{return document.createComment(e)}catch{return null}}function l(e){if(!u)throw new Error("Cannot create comment in non-browser environment");const t=s(`${e}-${Math.random().toString(36).slice(2)}`);if(!t)throw new Error("Failed to create comment");return t}function d(e){const t=s(`${e}-end`);if(!t)throw new Error("Failed to create end comment");return{start:l(`${e}-start`),end:t}}function f(e){return!!e&&("boolean"==typeof e.isConnected?e.isConnected:document.contains(e))}const p=new Map,h=new Map;function m(e,t){t.attributeResolvers.forEach(({resolver:e,applyValue:t},n)=>{try{t(c(e))}catch(e){i(`Failed to update reactive attribute: ${n}`,e)}})}function g(e,t){if("function"!=typeof e)return i("Invalid resolver provided to createReactiveTextNode"),document.createTextNode("");const n=arguments.length>1?t:c(e,""),r=void 0===n?"":String(n),o=document.createTextNode(r);return p.set(o,{resolver:e,lastValue:r}),o}function y(e,t,n,r){if(!(e instanceof Element&&t&&"function"==typeof n))return void i("Invalid parameters for registerAttributeResolver");const o=function(e){let t=h.get(e);return t||(t={attributeResolvers:new Map},h.set(e,t)),t}(e);o.attributeResolvers.set(t,{resolver:n,applyValue:r});try{r(c(n))}catch(e){i("Failed to apply initial attribute value",e)}if(!o.updateListener){const t=()=>m(0,o);e.addEventListener("update",t),o.updateListener=t}}function v(e,t){e&&e.style&&t&&Object.entries(t).forEach(([t,n])=>{if(null==n||""===n)e.style.removeProperty(t),e.style[t]="";else try{e.style[t]=String(n)}catch{}})}function b(e,t,n){if(null==n)return;if("style"===t)return i=n,void((r=e)&&(o(i)?y(r,"style",()=>{try{return i()}catch{return null}},e=>{v(r,e)}):v(r,i)));var r,i;const c=n=>{null!=n&&(t in e?e[t]=n:e instanceof Element&&e.setAttribute(String(t),String(n)))};o(n)&&0===n.length?y(e,String(t),n,c):c(n)}function x(e,t){if(t)for(const n of Object.keys(t)){b(e,n,t[n])}}const C=new WeakMap;function E(e){const{value:t,error:n}=function(e){const t=C.get(e);if(t)return t;try{const t={value:e(),error:!1};return C.set(e,t),t}catch{const t={value:void 0,error:!0};return C.set(e,t),t}}(e);return!n&&"boolean"==typeof t}function w(e,r,i){if(!o(e)||0!==e.length||!E(e))return!1;const c=r.filter((e,t)=>t!==i);if(0===c.length)return!1;return c.some(e=>n(e)||t(e)||o(e)&&e.length>0)}function M(r,c,u){if(null==c)return null;if(o(c)){if(0===c.length)try{let t=C.get(c);if(!t){t={value:c(),error:!1},C.set(c,t)}if(t.error){const e=document.createDocumentFragment(),t=document.createComment(` text-${u} `),n=g(()=>"");return e.appendChild(t),e.appendChild(n),e}const n=t.value;if(e(n)&&null!=n){const e=document.createDocumentFragment(),t=document.createComment(` text-${u} `),r=g(c,n);return e.appendChild(t),e.appendChild(r),e}return null}catch(e){C.set(c,{value:void 0,error:!0}),i("Error evaluating reactive text function:",e);const t=document.createDocumentFragment(),n=document.createComment(` text-${u} `),r=g(()=>"");return t.appendChild(n),t.appendChild(r),t}const o=c(r,u);if(null==o)return null;if(e(o)){const e=document.createDocumentFragment(),t=document.createComment(` text-${u} `),n=document.createTextNode(String(o));return e.appendChild(t),e.appendChild(n),e}return t(o)?o:(n(o)&&x(r,o),null)}const a=c;if(null==a)return null;if(e(a)){const e=document.createDocumentFragment(),t=document.createComment(` text-${u} `),n=document.createTextNode(String(a));return e.appendChild(t),e.appendChild(n),e}return t(a)?a:(n(a)&&x(r,a),null)}const S=new Set;function N(e,t){e._conditionalInfo=t,S.add(e)}function k(e,t,n=0){if(!t||0===t.length)return{element:e,nextIndex:n,appended:0};let r=n,o=0;const i=e;for(let n=0;n<t.length;n+=1){const c=t[n];if(null==c)continue;const u=M(e,c,r);u&&(u.parentNode!==i&&i.appendChild(u),r+=1,o+=1)}return{element:e,nextIndex:r,appended:o}}function T(e,t){const n=document.createElement(e);return k(n,t,0),n}function F(e){const t=function(e){for(let t=0;t<e.length;t+=1)if(w(e[t],e,t))return t;return-1}(e);return-1===t?{condition:null,otherModifiers:e}:{condition:e[t],otherModifiers:e.filter((e,n)=>n!==t)}}function I(e,...t){return(n,r)=>{const{condition:o,otherModifiers:i}=F(t);if(o)return function(e,t,n){const r=t();if(!u)return r?T(e,n):document.createComment(`conditional-${e}-ssr`);if(r){const r=T(e,n);return N(r,{condition:t,tagName:e,modifiers:n}),r}const o=document.createComment(`conditional-${e}-hidden`);return N(o,{condition:t,tagName:e,modifiers:n}),o}(e,o,i);const c=document.createElement(e);return k(c,i,r),c}}function L(e){return(...t)=>I(e,...t)}const $=["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","menu","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","script","search","section","select","slot","small","source","span","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr"];function B(e=globalThis){const t="__vc_tags_registered";e[t]||($.forEach(t=>function(e,t){t in e||(e[t]=L(t))}(e,t)),e[t]=!0)}const _=new Set;function D(e,t,n){return function(e,t,n){if(o(e)){const o=e(t,n);return o&&r(o)?o:null}return e&&r(e)?e:null}(e.renderItem(t,n),e.host,n)}function G(e){a(e.element)}function O(e){const{host:t,startMarker:n,endMarker:r}=e,o=n.parentNode??t,i=e.itemsProvider();if(function(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if((n in e?e[n]:void 0)!==(n in t?t[n]:void 0))return!1;return!0}(e.lastSyncedItems,i))return;const c=new Map,u=new Map;e.records.forEach(e=>{const t=u.get(e.item);t?t.push(e):u.set(e.item,[e])}),i.forEach((t,n)=>{if(n<e.lastSyncedItems.length&&e.lastSyncedItems[n]===t){const r=e.records[n];if(r&&r.item===t){c.set(n,r);const e=u.get(t);if(e){const n=e.indexOf(r);n>=0&&(e.splice(n,1),0===e.length&&u.delete(t))}}}});const a=[],s=new Set(e.records);let l=r;for(let t=i.length-1;t>=0;t--){const n=i[t];let r=c.get(t);if(!r){const e=u.get(n);e&&e.length>0&&(r=e.shift(),0===e.length&&u.delete(n))}if(r)s.delete(r);else{const o=D(e,n,t);if(!o)continue;r={item:n,element:o}}a.unshift(r);const d=r.element;d.nextSibling!==l&&o.insertBefore(d,l),l=d}s.forEach(G),e.records=a,e.lastSyncedItems=[...i]}function j(e,t){return n=>{const r=function(e,t,n){const{start:r,end:o}=d("list"),i={itemsProvider:e,renderItem:t,startMarker:r,endMarker:o,records:[],host:n,lastSyncedItems:[]},c=n;return c.appendChild(r),c.appendChild(o),_.add(i),O(i),i}(e,t,n);return r.startMarker}}function A(e,t){try{return e()}catch(e){if(!t)throw e;return t(e),!1}}function P(e,t){return"function"==typeof e?A(e,t):Boolean(e)}const R=new Set;function V(e){const{groups:t,elseContent:n,host:r,index:i,endMarker:c}=e;let u=null;for(let e=0;e<t.length;e++)if(P(t[e].condition)){u=e;break}if(null===u&&n.length&&(u=-1),u===e.activeIndex)return;if(function(e,t){let n=e.nextSibling;for(;n&&n!==t;){const e=n.nextSibling;a(n),n=e}}(e.startMarker,e.endMarker),e.activeIndex=u,null===u)return;const s=[],l=e=>{for(const t of e){if(o(t)){if(0===t.length){C.delete(t);const e=M(r,t,i);e&&s.push(e);continue}const e=r,n=e.appendChild;e.appendChild=function(t){return e.insertBefore(t,c)};try{const e=M(r,t,i);e&&!e.parentNode&&s.push(e)}finally{e.appendChild=n}continue}const e=M(r,t,i);e&&s.push(e)}};u>=0?l(t[u].content):-1===u&&l(n),function(e,t){const n=t.parentNode;n&&e.forEach(e=>function(e,t,n){if(!e||!t)return!1;try{return e.insertBefore(t,n),!0}catch{return!1}}(n,e,t))}(s,c)}class q{groups=[];elseContent=[];constructor(e,...t){this.groups.push({condition:e,content:t})}when(e,...t){return this.groups.push({condition:e,content:t}),this}else(...e){return this.elseContent=e,this}render(e,t){if(!u)return document.createComment("when-ssr");const{start:n,end:r}=d("when"),o={startMarker:n,endMarker:r,host:e,index:t,groups:[...this.groups],elseContent:[...this.elseContent],activeIndex:null,update:()=>V(o)};R.add(o);const i=e;return i.appendChild(n),i.appendChild(r),V(o),n}}function z(e){return Object.assign((t,n)=>e.render(t,n),{when:(t,...n)=>(e.when(t,...n),z(e)),else:(...t)=>(e.else(...t),z(e))})}function H(e,...t){return z(new q(e,...t))}function W(e,t){if(e.parentNode)try{e.parentNode.replaceChild(t,e)}catch(e){console.error("Error replacing conditional node:",e)}}function J(e){const t=function(e){return e._conditionalInfo??null}(e);if(!t)return;const n=A(t.condition,e=>{console.error("Error evaluating conditional condition:",e)}),r=e.nodeType===Node.ELEMENT_NODE;if(n&&!r){const n=function(e){const t=document.createElement(e.tagName);try{k(t,e.modifiers,0)}catch(t){console.error(`Error applying modifiers in conditional element "${e.tagName}":`,t)}return t}(t);N(n,t),W(e,n)}else if(!n&&r){const n=function(e){return document.createComment(`conditional-${e.tagName}-hidden`)}(t);N(n,t),W(e,n)}}const K=[function(){_.forEach(e=>{e.startMarker.isConnected&&e.endMarker.isConnected?O(e):_.delete(e)})},function(){R.forEach(e=>{try{e.update()}catch(t){R.delete(e)}})},function(){if(u)try{S.forEach(e=>{e.isConnected?J(e):function(e){S.delete(e)}(e)})}catch(e){console.error("Error during conditional elements update:",e)}},function(){h.forEach((e,t)=>{if(!f(t))return e.updateListener&&t.removeEventListener("update",e.updateListener),void h.delete(t);m(0,e)})},function(){p.forEach((e,t)=>{if(f(t))try{const n=c(e.resolver),r=void 0===n?"":String(n);r!==e.lastValue&&(t.textContent=r,e.lastValue=r)}catch(e){i("Failed to update reactive text node",e)}else p.delete(t)})},function(){if("undefined"==typeof document)return;const e=[];document.body&&e.push(document.body),e.push(document),e.forEach(e=>{try{e.dispatchEvent(new Event("update",{bubbles:!0}))}catch(e){console.error("Error dispatching global update event:",e)}})}];function Q(){for(const e of K)e()}function U(e,t,n){return r=>{const o=r;if(!o||"function"!=typeof o.addEventListener)return;o.addEventListener(e,n=>{try{t.call(o,n)}catch(t){"undefined"!=typeof console&&console.error&&console.error(`[nuclo:on] Error in '${e}' listener:`,t)}},n)}}function X(e,t,n=0){const r=e(t||document.body,n);return(t||document.body).appendChild(r),r}function Y(){if(B(),"undefined"!=typeof globalThis){const e=globalThis;e.list=j,e.update=Q,e.when=H,e.on=U,e.render=X}}"undefined"!=typeof globalThis&&Y(),exports.HTML_TAGS=$,exports.SELF_CLOSING_TAGS=["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"],exports.SVG_TAGS=["a","animate","animateMotion","animateTransform","circle","clipPath","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","foreignObject","g","image","line","linearGradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialGradient","rect","script","set","stop","style","svg","switch","symbol","text","textPath","title","tspan","use","view"],exports.appendChildren=function(e,...t){return e?(t.forEach(t=>{if(null!=t){let n;if("string"==typeof t){const e=function(e){if(!u)return null;try{return document.createTextNode(String(e))}catch{return null}}(t);if(!e)return;n=e}else n=t;!function(e,t){if(!e||!t)return!1;try{return e.appendChild(t),!0}catch{return!1}}(e,n)}}),e):e},exports.applyAttributes=x,exports.applyNodeModifier=M,exports.createElementFactory=I,exports.createTagBuilder=L,exports.initializeRuntime=Y,exports.isBoolean=function(e){return"boolean"==typeof e},exports.isBrowser=u,exports.isFunction=o,exports.isNode=t,exports.isObject=n,exports.isPrimitive=e,exports.isTagLike=r,exports.list=j,exports.on=U,exports.registerGlobalTagBuilders=B,exports.render=X,exports.update=Q,exports.when=H;
|
|
2
2
|
//# sourceMappingURL=nuclo.cjs.map
|