clarusjs 0.11.0 → 0.13.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.
- package/README.md +2 -0
- package/dist/check/generate.js +12 -3
- package/dist/cli/check.js +15 -4
- package/dist/compiler/class-style.d.ts +2 -0
- package/dist/compiler/class-style.js +49 -0
- package/dist/compiler/emit-client.js +9 -3
- package/dist/compiler/emit-server.js +4 -1
- package/dist/compiler/html-expr.js +3 -1
- package/dist/compiler/icon.d.ts +24 -0
- package/dist/compiler/icon.js +79 -0
- package/dist/compiler/index.d.ts +4 -0
- package/dist/compiler/index.js +43 -8
- package/dist/compiler/ir.d.ts +4 -0
- package/dist/compiler/ir.js +53 -6
- package/dist/compiler/script.d.ts +10 -0
- package/dist/compiler/script.js +61 -0
- package/dist/forms/index.js +4 -1
- package/dist/icons.d.ts +59 -0
- package/dist/icons.js +112 -0
- package/dist/runtime/attrs.d.ts +27 -0
- package/dist/runtime/attrs.js +66 -0
- package/dist/runtime/dom.d.ts +6 -0
- package/dist/runtime/dom.js +26 -1
- package/dist/runtime/html.d.ts +6 -0
- package/dist/runtime/html.js +19 -1
- package/dist/runtime/index.d.ts +3 -2
- package/dist/runtime/index.js +3 -2
- package/dist/runtime/server.d.ts +2 -1
- package/dist/runtime/server.js +2 -1
- package/dist/vite/node.d.ts +2 -0
- package/dist/vite/node.js +13 -0
- package/dist/vite/plugin.d.ts +6 -1
- package/dist/vite/plugin.js +107 -16
- package/dist/vite/sitemap.d.ts +20 -1
- package/dist/vite/sitemap.js +27 -3
- package/package.json +5 -1
package/dist/compiler/script.js
CHANGED
|
@@ -367,6 +367,67 @@ export function rewriteServer(code) {
|
|
|
367
367
|
export function referencesSignal(expr, signals) {
|
|
368
368
|
return referencesNames(expr, new Set(signals.keys()));
|
|
369
369
|
}
|
|
370
|
+
const MUTATORS = {
|
|
371
|
+
push: (n) => `${n} = [...${n}, …]`,
|
|
372
|
+
unshift: (n) => `${n} = […, ...${n}]`,
|
|
373
|
+
pop: (n) => `${n} = ${n}.slice(0, -1)`,
|
|
374
|
+
shift: (n) => `${n} = ${n}.slice(1)`,
|
|
375
|
+
splice: (n) => `${n} = ${n}.toSpliced(…)`,
|
|
376
|
+
sort: (n) => `${n} = ${n}.toSorted(…)`,
|
|
377
|
+
reverse: (n) => `${n} = ${n}.toReversed()`,
|
|
378
|
+
fill: (n) => `${n} = ${n}.map(…)`,
|
|
379
|
+
copyWithin: (n) => `${n} = [...${n}]`,
|
|
380
|
+
set: (n) => `${n} = new Map(${n}).set(…)`,
|
|
381
|
+
add: (n) => `${n} = new Set(${n}).add(…)`,
|
|
382
|
+
delete: (n) => `a copy without it: ${n} = new Map(${n}), then delete from that`,
|
|
383
|
+
clear: (n) => `${n} = new Map() or new Set()`,
|
|
384
|
+
};
|
|
385
|
+
function rootOf(node) {
|
|
386
|
+
let n = node;
|
|
387
|
+
while (n.type === 'MemberExpression')
|
|
388
|
+
n = n.object;
|
|
389
|
+
return n.type === 'Identifier' ? n : undefined;
|
|
390
|
+
}
|
|
391
|
+
function chain(node) {
|
|
392
|
+
if (node.type === 'Identifier')
|
|
393
|
+
return node.name;
|
|
394
|
+
if (node.type !== 'MemberExpression')
|
|
395
|
+
return '…';
|
|
396
|
+
return node.computed ? `${chain(node.object)}[…]` : `${chain(node.object)}.${node.property.name}`;
|
|
397
|
+
}
|
|
398
|
+
export function mutationsOf(code, names) {
|
|
399
|
+
const found = [];
|
|
400
|
+
const say = (name, start, what, instead) => found.push({ name, start, message: `${what} changes ${name} in place, so the page won't update: assign a new value instead (${instead})` });
|
|
401
|
+
const visit = (active, entered) => (node, parent, key) => {
|
|
402
|
+
if (!entered.has(node)) {
|
|
403
|
+
const shadowed = [...scopeNames(node)].filter((n) => active.has(n));
|
|
404
|
+
if (shadowed.length) {
|
|
405
|
+
entered.add(node);
|
|
406
|
+
print(node, code, visit(new Set([...active].filter((n) => !shadowed.includes(n))), entered), parent, key);
|
|
407
|
+
return '';
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (node.type === 'CallExpression' && node.callee.type === 'MemberExpression' && !node.callee.computed) {
|
|
411
|
+
const method = node.callee.property.name;
|
|
412
|
+
const root = rootOf(node.callee.object);
|
|
413
|
+
if (root && active.has(root.name) && Object.hasOwn(MUTATORS, method)) {
|
|
414
|
+
say(root.name, node.start, `${chain(node.callee.object)}.${method}()`, MUTATORS[method](root.name));
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
const target = node.type === 'AssignmentExpression' ? node.left : node.type === 'UpdateExpression' ? node.argument : node.type === 'UnaryExpression' && node.operator === 'delete' ? node.argument : null;
|
|
418
|
+
if (target?.type === 'MemberExpression') {
|
|
419
|
+
const root = rootOf(target);
|
|
420
|
+
if (root && active.has(root.name)) {
|
|
421
|
+
const what = node.type === 'AssignmentExpression' ? `${chain(target)} ${node.operator} …` : node.type === 'UpdateExpression' ? `${chain(target)}${node.operator}` : `delete ${chain(target)}`;
|
|
422
|
+
const direct = target.object.type === 'Identifier' && !target.computed;
|
|
423
|
+
say(root.name, node.start, what, direct ? `${root.name} = { ...${root.name}, ${target.property.name}: … }` : `${root.name} = { ...${root.name}, … }`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return undefined;
|
|
427
|
+
};
|
|
428
|
+
print(parseScript(code), code, visit(names, new WeakSet()));
|
|
429
|
+
return found;
|
|
430
|
+
}
|
|
370
431
|
export function writesTo(code, names) {
|
|
371
432
|
const found = [];
|
|
372
433
|
const visit = (active, entered) => (node, parent, key) => {
|
package/dist/forms/index.js
CHANGED
|
@@ -154,7 +154,10 @@ export function form(values, options = {}) {
|
|
|
154
154
|
step.toggleAttribute('data-cl-current', step.id === id);
|
|
155
155
|
}
|
|
156
156
|
if (push && location.hash !== `#${id}`)
|
|
157
|
-
|
|
157
|
+
try {
|
|
158
|
+
history.pushState(null, '', `#${id}`);
|
|
159
|
+
}
|
|
160
|
+
catch { }
|
|
158
161
|
refresh();
|
|
159
162
|
}
|
|
160
163
|
const hashStep = () => {
|
package/dist/icons.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An icon as the compiler draws it: its SVG body and its box (`viewBox="left top width height"`).
|
|
3
|
+
* @see https://clarusjs.com/guide/icons
|
|
4
|
+
*/
|
|
5
|
+
export type IconData = {
|
|
6
|
+
body: string;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
left: number;
|
|
10
|
+
top: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* What a lookup found: the icon, or what's missing (the set, or the icon in it, with the closest names).
|
|
14
|
+
* @see https://clarusjs.com/guide/icons
|
|
15
|
+
*/
|
|
16
|
+
export type IconLookup = {
|
|
17
|
+
data: IconData;
|
|
18
|
+
} | {
|
|
19
|
+
missing: 'set';
|
|
20
|
+
set: string;
|
|
21
|
+
} | {
|
|
22
|
+
missing: 'icon';
|
|
23
|
+
set: string;
|
|
24
|
+
suggestions: string[];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The icon `set:name` (Iconify naming), from the sets installed for the package `fromFile` is in. Throws for an alias
|
|
28
|
+
* that flips or rotates its icon (not supported yet).
|
|
29
|
+
* @example
|
|
30
|
+
* resolveIcon('lucide:rocket', '/app/src/pages/index.tscl') // { data: { body: '<path …/>', width: 24, … } }
|
|
31
|
+
* @see https://clarusjs.com/guide/icons
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveIcon(name: string, fromFile: string): IconLookup;
|
|
34
|
+
/**
|
|
35
|
+
* The icon sets installed for the package `fromFile` is in (its `@iconify-json/*` dependencies, and those in its
|
|
36
|
+
* node_modules), for the editor's completion.
|
|
37
|
+
* @example
|
|
38
|
+
* iconSets('/app/src/pages/index.tscl') // [{ prefix: 'lucide', name: 'Lucide', total: 1600 }]
|
|
39
|
+
* @see https://clarusjs.com/guide/icons
|
|
40
|
+
*/
|
|
41
|
+
export declare function iconSets(fromFile: string): {
|
|
42
|
+
prefix: string;
|
|
43
|
+
name: string;
|
|
44
|
+
total: number;
|
|
45
|
+
}[];
|
|
46
|
+
/**
|
|
47
|
+
* The names in an installed set (icons and aliases, sorted); none when it isn't installed.
|
|
48
|
+
* @example
|
|
49
|
+
* iconNames('lucide', '/app/src/pages/index.tscl') // ['a-arrow-down', …, 'rocket', …]
|
|
50
|
+
* @see https://clarusjs.com/guide/icons
|
|
51
|
+
*/
|
|
52
|
+
export declare function iconNames(set: string, fromFile: string): string[];
|
|
53
|
+
/**
|
|
54
|
+
* A standalone `<svg>` for an icon, with extra attributes (`'width="48"'`); the editor's hover preview uses it.
|
|
55
|
+
* @example
|
|
56
|
+
* iconSvg(data, 'width="48" height="48"') // '<svg xmlns="…" viewBox="0 0 24 24" width="48" height="48">…</svg>'
|
|
57
|
+
* @see https://clarusjs.com/guide/icons
|
|
58
|
+
*/
|
|
59
|
+
export declare function iconSvg(data: IconData, attrs?: string): string;
|
package/dist/icons.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
const sets = new Map();
|
|
5
|
+
function packageDir(file) {
|
|
6
|
+
for (let dir = dirname(file);; dir = dirname(dir)) {
|
|
7
|
+
if (existsSync(join(dir, 'package.json')))
|
|
8
|
+
return dir;
|
|
9
|
+
if (dirname(dir) === dir)
|
|
10
|
+
return dirname(file);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function loadSet(set, fromFile) {
|
|
14
|
+
const dir = packageDir(fromFile);
|
|
15
|
+
let path;
|
|
16
|
+
try {
|
|
17
|
+
path = createRequire(join(dir, 'package.json')).resolve(`@iconify-json/${set}/icons.json`);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const mtime = statSync(path).mtimeMs;
|
|
23
|
+
const cached = sets.get(path);
|
|
24
|
+
if (cached?.mtime === mtime)
|
|
25
|
+
return cached.data;
|
|
26
|
+
const data = JSON.parse(readFileSync(path, 'utf8'));
|
|
27
|
+
sets.set(path, { mtime, data });
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
30
|
+
function distance(a, b) {
|
|
31
|
+
let row = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
32
|
+
for (let i = 1; i <= a.length; i++) {
|
|
33
|
+
const next = [i];
|
|
34
|
+
for (let j = 1; j <= b.length; j++)
|
|
35
|
+
next[j] = Math.min(row[j] + 1, next[j - 1] + 1, row[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
36
|
+
row = next;
|
|
37
|
+
}
|
|
38
|
+
return row[b.length];
|
|
39
|
+
}
|
|
40
|
+
export function resolveIcon(name, fromFile) {
|
|
41
|
+
const colon = name.indexOf(':');
|
|
42
|
+
const set = colon === -1 ? name : name.slice(0, colon);
|
|
43
|
+
const icon = colon === -1 ? '' : name.slice(colon + 1);
|
|
44
|
+
const data = loadSet(set, fromFile);
|
|
45
|
+
if (!data)
|
|
46
|
+
return { missing: 'set', set };
|
|
47
|
+
const all = Object.assign(Object.create(null), data.aliases, data.icons);
|
|
48
|
+
const own = (n) => (Object.hasOwn(all, n) ? all[n] : undefined);
|
|
49
|
+
const first = own(icon);
|
|
50
|
+
if (!first) {
|
|
51
|
+
const suggestions = Object.keys(all)
|
|
52
|
+
.map((n) => [n, distance(icon, n)])
|
|
53
|
+
.filter(([n, d]) => d <= Math.max(2, Math.floor(n.length / 3)))
|
|
54
|
+
.sort((a, b) => a[1] - b[1] || a[0].localeCompare(b[0]))
|
|
55
|
+
.slice(0, 3)
|
|
56
|
+
.map(([n]) => n);
|
|
57
|
+
return { missing: 'icon', set, suggestions };
|
|
58
|
+
}
|
|
59
|
+
let found = first;
|
|
60
|
+
let merged = { ...found };
|
|
61
|
+
for (let depth = 0; found.parent && depth < 10; depth++) {
|
|
62
|
+
const parent = own(found.parent);
|
|
63
|
+
if (!parent)
|
|
64
|
+
break;
|
|
65
|
+
merged = { ...parent, ...merged, parent: parent.parent };
|
|
66
|
+
found = parent;
|
|
67
|
+
}
|
|
68
|
+
for (const key of ['hFlip', 'vFlip', 'rotate']) {
|
|
69
|
+
if (merged[key])
|
|
70
|
+
throw new Error(`the icon ${name} uses ${key}, which <icon> doesn't support yet`);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
data: {
|
|
74
|
+
body: merged.body ?? '',
|
|
75
|
+
width: merged.width ?? data.width ?? 16,
|
|
76
|
+
height: merged.height ?? data.height ?? 16,
|
|
77
|
+
left: merged.left ?? data.left ?? 0,
|
|
78
|
+
top: merged.top ?? data.top ?? 0,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export function iconSets(fromFile) {
|
|
83
|
+
const dir = packageDir(fromFile);
|
|
84
|
+
const names = new Set();
|
|
85
|
+
try {
|
|
86
|
+
const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));
|
|
87
|
+
for (const deps of [pkg.dependencies, pkg.devDependencies])
|
|
88
|
+
for (const d of Object.keys(deps ?? {}))
|
|
89
|
+
if (d.startsWith('@iconify-json/'))
|
|
90
|
+
names.add(d.slice(14));
|
|
91
|
+
}
|
|
92
|
+
catch { }
|
|
93
|
+
try {
|
|
94
|
+
for (const d of readdirSync(join(dir, 'node_modules/@iconify-json')))
|
|
95
|
+
names.add(d);
|
|
96
|
+
}
|
|
97
|
+
catch { }
|
|
98
|
+
const out = [];
|
|
99
|
+
for (const prefix of [...names].sort()) {
|
|
100
|
+
const data = loadSet(prefix, fromFile);
|
|
101
|
+
if (data)
|
|
102
|
+
out.push({ prefix, name: data.info?.name ?? prefix, total: data.info?.total ?? Object.keys(data.icons).length });
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
export function iconNames(set, fromFile) {
|
|
107
|
+
const data = loadSet(set, fromFile);
|
|
108
|
+
return data ? Object.keys({ ...data.icons, ...data.aliases }).sort() : [];
|
|
109
|
+
}
|
|
110
|
+
export function iconSvg(data, attrs = '') {
|
|
111
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${data.left} ${data.top} ${data.width} ${data.height}"${attrs ? ' ' + attrs : ''}>${data.body}</svg>`;
|
|
112
|
+
}
|
package/dist/runtime/attrs.d.ts
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
export declare const UNSAFE_URL = "about:invalid#unsafe";
|
|
2
|
+
/**
|
|
3
|
+
* A class from a string (as written), an object (its truthy keys) or an array (flattened, falsy entries dropped), like
|
|
4
|
+
* clsx. Templates use it for `[class]` values and `[class.name]` toggles.
|
|
5
|
+
* @example
|
|
6
|
+
* classValue(['a', on && 'b', { c: true, d: false }]) // 'a b c' when on
|
|
7
|
+
* @see https://clarusjs.com/guide/attributes
|
|
8
|
+
*/
|
|
9
|
+
export declare function classValue(value: unknown): string;
|
|
10
|
+
/**
|
|
11
|
+
* A style from a string (as written), an object (camelCase keys to kebab-case, custom properties as they are; null,
|
|
12
|
+
* undefined, false and '' left out; no units added) or an array of those. Templates use it for `[style]` values and
|
|
13
|
+
* `[style.prop]` bindings.
|
|
14
|
+
* @example
|
|
15
|
+
* styleValue({ fontSize: '2em', '--accent': c, color: null }) // 'font-size: 2em; --accent: …;'
|
|
16
|
+
* @see https://clarusjs.com/guide/attributes
|
|
17
|
+
*/
|
|
18
|
+
export declare function styleValue(value: unknown): string;
|
|
2
19
|
/**
|
|
3
20
|
* What an attribute should become: `null` removes it, `true` makes it a bare boolean attribute, a string is its value.
|
|
4
21
|
*/
|
|
5
22
|
export declare function attrValue(name: string, value: unknown, tag?: string): string | true | null;
|
|
23
|
+
/**
|
|
24
|
+
* A spread's attributes (#405): each key with its value as attrValue gives it, except the names written on the element
|
|
25
|
+
* (`skip`, lowercase), class and style (merged with the element's own), and what a spread may never set, listed in
|
|
26
|
+
* `dropped` with why: event handlers, srcdoc, invalid names, JSX names and objects or functions.
|
|
27
|
+
* @internal the runtimes call this; apps write [...]="attrs".
|
|
28
|
+
*/
|
|
29
|
+
export declare function spreadAttrs(obj: unknown, skip: readonly string[], tag?: string): {
|
|
30
|
+
set: [string, string | true | null][];
|
|
31
|
+
dropped: [string, string][];
|
|
32
|
+
};
|
package/dist/runtime/attrs.js
CHANGED
|
@@ -29,6 +29,33 @@ function safeUrl(url, image) {
|
|
|
29
29
|
// ARIA states whose absence means "doesn't apply" (no aria-expanded: nothing expands). Other aria-* (aria-current:
|
|
30
30
|
// `active ? 'page' : false`) keep false = removed.
|
|
31
31
|
const ENUMERATED = new Set(['contenteditable', 'draggable', 'spellcheck', 'translate', 'aria-expanded', 'aria-pressed', 'aria-checked', 'aria-selected']);
|
|
32
|
+
/**
|
|
33
|
+
* A class from a string (as written), an object (its truthy keys) or an array (flattened, falsy entries dropped), like
|
|
34
|
+
* clsx. Templates use it for `[class]` values and `[class.name]` toggles.
|
|
35
|
+
* @example
|
|
36
|
+
* classValue(['a', on && 'b', { c: true, d: false }]) // 'a b c' when on
|
|
37
|
+
* @see https://clarusjs.com/guide/attributes
|
|
38
|
+
*/
|
|
39
|
+
export function classValue(value) {
|
|
40
|
+
const names = (v) => (!v ? [] : typeof v === 'string' ? v.split(/\s+/) : Array.isArray(v) ? v.flatMap(names) : typeof v === 'object' ? Object.keys(v).filter((k) => v[k]) : [String(v)]);
|
|
41
|
+
// Each class once, single spaces: a written class="star" and a bound 'star on' make "star on".
|
|
42
|
+
return [...new Set(names(value).filter(Boolean))].join(' ');
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A style from a string (as written), an object (camelCase keys to kebab-case, custom properties as they are; null,
|
|
46
|
+
* undefined, false and '' left out; no units added) or an array of those. Templates use it for `[style]` values and
|
|
47
|
+
* `[style.prop]` bindings.
|
|
48
|
+
* @example
|
|
49
|
+
* styleValue({ fontSize: '2em', '--accent': c, color: null }) // 'font-size: 2em; --accent: …;'
|
|
50
|
+
* @see https://clarusjs.com/guide/attributes
|
|
51
|
+
*/
|
|
52
|
+
export function styleValue(value) {
|
|
53
|
+
// A string stays whole (a url(data:…;base64,…) holds a ';'); only a trailing ';' is dropped before joining.
|
|
54
|
+
const decls = (v) => !v ? [] : typeof v === 'string' ? [v.trim().replace(/;\s*$/, '')].filter(Boolean) : Array.isArray(v) ? v.flatMap(decls) : typeof v === 'object'
|
|
55
|
+
? Object.entries(v).filter(([, x]) => x != null && x !== false && x !== '').map(([k, x]) => `${k.startsWith('--') ? k : k.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase())}: ${x}`)
|
|
56
|
+
: [];
|
|
57
|
+
return decls(value).map((d) => d + ';').join(' ');
|
|
58
|
+
}
|
|
32
59
|
/**
|
|
33
60
|
* What an attribute should become: `null` removes it, `true` makes it a bare boolean attribute, a string is its value.
|
|
34
61
|
*/
|
|
@@ -36,6 +63,14 @@ export function attrValue(name, value, tag) {
|
|
|
36
63
|
if (value == null)
|
|
37
64
|
return null;
|
|
38
65
|
const n = name.toLowerCase();
|
|
66
|
+
// A class from an object or an array (a spread's class, or one bound directly): its classes, never [object Object].
|
|
67
|
+
if (n === 'class' && typeof value === 'object')
|
|
68
|
+
return classValue(value) || null;
|
|
69
|
+
if (n === 'style' && typeof value === 'object')
|
|
70
|
+
return styleValue(value) || null;
|
|
71
|
+
// An empty class or style adds nothing (a spread without one, a class whose toggles are all off).
|
|
72
|
+
if ((n === 'class' || n === 'style') && value === '')
|
|
73
|
+
return null;
|
|
39
74
|
if (typeof value === 'boolean' && ENUMERATED.has(n))
|
|
40
75
|
return n === 'translate' ? (value ? 'yes' : 'no') : String(value); // translate: yes/no
|
|
41
76
|
if (value === false)
|
|
@@ -62,3 +97,34 @@ export function attrValue(name, value, tag) {
|
|
|
62
97
|
return UNSAFE_URL;
|
|
63
98
|
return s;
|
|
64
99
|
}
|
|
100
|
+
const ATTR_NAME = /^[a-zA-Z_:][-a-zA-Z0-9_:.]*$/;
|
|
101
|
+
/**
|
|
102
|
+
* A spread's attributes (#405): each key with its value as attrValue gives it, except the names written on the element
|
|
103
|
+
* (`skip`, lowercase), class and style (merged with the element's own), and what a spread may never set, listed in
|
|
104
|
+
* `dropped` with why: event handlers, srcdoc, invalid names, JSX names and objects or functions.
|
|
105
|
+
* @internal the runtimes call this; apps write [...]="attrs".
|
|
106
|
+
*/
|
|
107
|
+
export function spreadAttrs(obj, skip, tag) {
|
|
108
|
+
const set = [];
|
|
109
|
+
const dropped = [];
|
|
110
|
+
if (!obj || typeof obj !== 'object')
|
|
111
|
+
return { set, dropped };
|
|
112
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
113
|
+
const n = key.toLowerCase();
|
|
114
|
+
if (skip.includes(n) || n === 'class' || n === 'style')
|
|
115
|
+
continue;
|
|
116
|
+
const why = !ATTR_NAME.test(key) ? 'not an attribute name'
|
|
117
|
+
// clarusjs's own markers (data-cl-e, data-cl-a, data-cl-path…): data must not spoof the runtime's wiring.
|
|
118
|
+
: n.startsWith('data-cl-') || n.startsWith('cl-') ? 'reserved for clarusjs'
|
|
119
|
+
: n.startsWith('on') ? 'an event handler: use (event)="…" in an island'
|
|
120
|
+
: n === 'srcdoc' ? 'srcdoc is static only'
|
|
121
|
+
: key === 'className' ? 'a JSX name: use class' : key === 'htmlFor' ? 'a JSX name: use for'
|
|
122
|
+
: value !== null && (typeof value === 'object' || typeof value === 'function') ? 'not a value for an attribute (an object or a function)'
|
|
123
|
+
: '';
|
|
124
|
+
if (why)
|
|
125
|
+
dropped.push([key, why]);
|
|
126
|
+
else
|
|
127
|
+
set.push([key, attrValue(key, value, tag)]);
|
|
128
|
+
}
|
|
129
|
+
return { set, dropped };
|
|
130
|
+
}
|
package/dist/runtime/dom.d.ts
CHANGED
|
@@ -69,6 +69,12 @@ export declare function text(hole: Hole, fn: () => unknown): void;
|
|
|
69
69
|
export declare function on(ctx: Ctx, index: number, type: string, fn: (e: Event) => void): void;
|
|
70
70
|
/** The element matching `selector` in `ctx`: this island's (not a nested island's), and in a row, that row's. */
|
|
71
71
|
export declare function marked(ctx: Ctx, selector: string): Element | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* A reactive spread (#405): sets the attributes the object has, removes the ones it no longer has (only those it set:
|
|
74
|
+
* never one written on the element, which `skip` lists). Dropped keys are dropped silently here; the server warns.
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
export declare function spread(ctx: Ctx, index: number, fn: () => unknown, skip: readonly string[], tag?: string): void;
|
|
72
78
|
/** Keep attribute `name` of the element marked `data-cl-a="index"` in `ctx` in sync with `fn()`. @internal */
|
|
73
79
|
export declare function attr(ctx: Ctx, index: number, name: string, fn: () => unknown, tag?: string): void;
|
|
74
80
|
/**
|
package/dist/runtime/dom.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Attach helpers: find markers in server HTML and keep them updated. Browser only. Never re-renders existing HTML;
|
|
2
2
|
// only @if branches and @for rows that did not exist on the server are rendered here.
|
|
3
|
-
import { attrValue } from './attrs.js';
|
|
3
|
+
import { attrValue, spreadAttrs } from './attrs.js';
|
|
4
4
|
import { batch, effect, onDispose, scope, state, untrack } from './signals.js';
|
|
5
5
|
const rootOf = (ctx) => ('root' in ctx ? ctx.root : ctx);
|
|
6
6
|
/** Is `node` inside `ctx` (always true for a whole island)? */
|
|
@@ -328,6 +328,31 @@ export function marked(ctx, selector) {
|
|
|
328
328
|
const island = root.closest('cl-island');
|
|
329
329
|
return [...root.querySelectorAll(selector)].find((e) => e.closest('cl-island') === island && inside(ctx, e));
|
|
330
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* A reactive spread (#405): sets the attributes the object has, removes the ones it no longer has (only those it set:
|
|
333
|
+
* never one written on the element, which `skip` lists). Dropped keys are dropped silently here; the server warns.
|
|
334
|
+
* @internal
|
|
335
|
+
*/
|
|
336
|
+
export function spread(ctx, index, fn, skip, tag) {
|
|
337
|
+
const el = marked(ctx, `[data-cl-a="${index}"]`);
|
|
338
|
+
if (!el)
|
|
339
|
+
return;
|
|
340
|
+
let had = new Set();
|
|
341
|
+
effect(() => {
|
|
342
|
+
const now = new Set();
|
|
343
|
+
for (const [name, v] of spreadAttrs(fn(), skip, tag).set) {
|
|
344
|
+
now.add(name);
|
|
345
|
+
if (v === null)
|
|
346
|
+
el.removeAttribute(name);
|
|
347
|
+
else
|
|
348
|
+
el.setAttribute(name, v === true ? '' : v);
|
|
349
|
+
}
|
|
350
|
+
for (const name of had)
|
|
351
|
+
if (!now.has(name))
|
|
352
|
+
el.removeAttribute(name);
|
|
353
|
+
had = now;
|
|
354
|
+
});
|
|
355
|
+
}
|
|
331
356
|
/** Keep attribute `name` of the element marked `data-cl-a="index"` in `ctx` in sync with `fn()`. @internal */
|
|
332
357
|
export function attr(ctx, index, name, fn, tag) {
|
|
333
358
|
const el = marked(ctx, `[data-cl-a="${index}"]`);
|
package/dist/runtime/html.d.ts
CHANGED
|
@@ -4,6 +4,12 @@ export declare const HTML: unique symbol;
|
|
|
4
4
|
export declare function escape(value: unknown): string;
|
|
5
5
|
/** A value as JSON for a <script> (JSON-LD): <, >, & and line separators escaped, so it can't end the script. @internal */
|
|
6
6
|
export declare function json(value: unknown): string;
|
|
7
|
+
/**
|
|
8
|
+
* A spread's attributes as HTML (#405); `where` (file:line:col, server code only) names the place in a warning for
|
|
9
|
+
* each key it drops, once.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare function spreadHtml(obj: unknown, skip: readonly string[], tag?: string, where?: string): string;
|
|
7
13
|
/** ` name="value"`, ` name` (true) or '' (false/null/undefined), escaped and URL-checked. @internal */
|
|
8
14
|
export declare function attrHtml(name: string, value: unknown, tag?: string): string;
|
|
9
15
|
/** An @if block inside an island: markers record which branch (k, or -1 for none) was rendered. @internal */
|
package/dist/runtime/html.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// HTML-string helpers used by compiled code on the server (render) and in the browser (branch HTML for @if).
|
|
2
|
-
import { attrValue } from './attrs.js';
|
|
2
|
+
import { attrValue, spreadAttrs } from './attrs.js';
|
|
3
3
|
/** The mark of h()'s output (clarusjs/views). Symbol.for: two copies of the module agree. @internal */
|
|
4
4
|
export const HTML = Symbol.for('clarusjs.html');
|
|
5
5
|
const ENTITIES = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' };
|
|
@@ -16,6 +16,24 @@ export function escape(value) {
|
|
|
16
16
|
export function json(value) {
|
|
17
17
|
return (JSON.stringify(value) ?? 'null').replace(/[<>&\u2028\u2029]/g, (ch) => `\\u${ch.charCodeAt(0).toString(16).padStart(4, '0')}`);
|
|
18
18
|
}
|
|
19
|
+
const warned = new Set();
|
|
20
|
+
/**
|
|
21
|
+
* A spread's attributes as HTML (#405); `where` (file:line:col, server code only) names the place in a warning for
|
|
22
|
+
* each key it drops, once.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export function spreadHtml(obj, skip, tag, where) {
|
|
26
|
+
const { set, dropped } = spreadAttrs(obj, skip, tag);
|
|
27
|
+
// Once per place and reason, not per key: keys come from data, so a set of them could grow without end on a server.
|
|
28
|
+
if (where)
|
|
29
|
+
for (const [key, why] of dropped) {
|
|
30
|
+
if (warned.has(`${where} ${why}`))
|
|
31
|
+
continue;
|
|
32
|
+
warned.add(`${where} ${why}`);
|
|
33
|
+
console.warn(`[clarusjs] ${where}: [...] dropped ${JSON.stringify(key)} (${why})`);
|
|
34
|
+
}
|
|
35
|
+
return set.map(([name, v]) => (v === null ? '' : v === true ? ` ${name}` : ` ${name}="${escape(v)}"`)).join('');
|
|
36
|
+
}
|
|
19
37
|
/** ` name="value"`, ` name` (true) or '' (false/null/undefined), escaped and URL-checked. @internal */
|
|
20
38
|
export function attrHtml(name, value, tag) {
|
|
21
39
|
const v = attrValue(name, value, tag);
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { state, derived, shared, effect, scope, onDispose, untrack, batch, type Signal, type ReadSignal } from './signals.ts';
|
|
2
|
-
export { holes, blocks, text, on, attr, block, forBlock, region, model, modelInput, type Hole, type Block, type Ctx } from './dom.ts';
|
|
3
|
-
export { escape, attrHtml, blockHtml, forHtml, regionHtml } from './html.ts';
|
|
2
|
+
export { holes, blocks, text, on, attr, spread, block, forBlock, region, model, modelInput, type Hole, type Block, type Ctx } from './dom.ts';
|
|
3
|
+
export { escape, attrHtml, spreadHtml, blockHtml, forHtml, regionHtml } from './html.ts';
|
|
4
4
|
export { parse as parseIslandData } from './serialize.ts';
|
|
5
|
+
export { classValue, styleValue } from './attrs.ts';
|
|
5
6
|
export { browser } from './env.ts';
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Browser runtime used by compiled attach() functions.
|
|
2
2
|
export { state, derived, shared, effect, scope, onDispose, untrack, batch } from './signals.js';
|
|
3
|
-
export { holes, blocks, text, on, attr, block, forBlock, region, model, modelInput } from './dom.js';
|
|
4
|
-
export { escape, attrHtml, blockHtml, forHtml, regionHtml } from './html.js';
|
|
3
|
+
export { holes, blocks, text, on, attr, spread, block, forBlock, region, model, modelInput } from './dom.js';
|
|
4
|
+
export { escape, attrHtml, spreadHtml, blockHtml, forHtml, regionHtml } from './html.js';
|
|
5
5
|
export { parse as parseIslandData } from './serialize.js';
|
|
6
|
+
export { classValue, styleValue } from './attrs.js';
|
|
6
7
|
export { browser } from './env.js';
|
package/dist/runtime/server.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { attrHtml } from './html.ts';
|
|
2
|
-
export { escape, json, blockHtml, forHtml, regionHtml } from './html.ts';
|
|
2
|
+
export { escape, json, blockHtml, forHtml, regionHtml, spreadHtml } from './html.ts';
|
|
3
|
+
export { classValue, styleValue } from './attrs.ts';
|
|
3
4
|
/**
|
|
4
5
|
* Wrap a stateful component's HTML in its island boundary: name, client chunk URL, props (`p`) and, when the
|
|
5
6
|
* component has state, the state values it rendered with (`s`), so the browser starts from the same values.
|
package/dist/runtime/server.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Server-side helpers used by compiled render() functions. Runs at build time or per request, never in the browser.
|
|
2
2
|
import { attrHtml, escape, HTML } from './html.js';
|
|
3
3
|
import { stringify } from './serialize.js';
|
|
4
|
-
export { escape, json, blockHtml, forHtml, regionHtml } from './html.js';
|
|
4
|
+
export { escape, json, blockHtml, forHtml, regionHtml, spreadHtml } from './html.js';
|
|
5
|
+
export { classValue, styleValue } from './attrs.js';
|
|
5
6
|
/**
|
|
6
7
|
* Wrap a stateful component's HTML in its island boundary: name, client chunk URL, props (`p`) and, when the
|
|
7
8
|
* component has state, the state values it rendered with (`s`), so the browser starts from the same values.
|
package/dist/vite/node.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
2
|
export declare function toRequest(req: IncomingMessage): Request;
|
|
3
3
|
export declare function sendResponse(res: ServerResponse, response: Response): Promise<void>;
|
|
4
|
+
/** Whether an Accept-Encoding header allows `encoding`: named, or through `*`, and not with q=0. */
|
|
5
|
+
export declare function acceptsEncoding(header: string, encoding: string): boolean;
|
package/dist/vite/node.js
CHANGED
|
@@ -16,3 +16,16 @@ export async function sendResponse(res, response) {
|
|
|
16
16
|
response.headers.forEach((value, key) => res.setHeader(key, value));
|
|
17
17
|
res.end(Buffer.from(await response.arrayBuffer()));
|
|
18
18
|
}
|
|
19
|
+
export function acceptsEncoding(header, encoding) {
|
|
20
|
+
let star = false;
|
|
21
|
+
for (const part of header.toLowerCase().split(',')) {
|
|
22
|
+
const [name, ...params] = part.trim().split(';');
|
|
23
|
+
const q = params.map((p) => p.trim()).find((p) => p.startsWith('q='));
|
|
24
|
+
const allowed = !q || Number(q.slice(2)) > 0;
|
|
25
|
+
if (name === encoding)
|
|
26
|
+
return allowed;
|
|
27
|
+
if (name === '*')
|
|
28
|
+
star = allowed;
|
|
29
|
+
}
|
|
30
|
+
return star;
|
|
31
|
+
}
|
package/dist/vite/plugin.d.ts
CHANGED
|
@@ -66,10 +66,15 @@ export type ClarusOptions = {
|
|
|
66
66
|
/**
|
|
67
67
|
* With site.url, vite build writes sitemap.xml (static pages, dated from git). false: no sitemap. `exclude`: paths
|
|
68
68
|
* left out ('/legal', '/tags/*' one segment, '/drafts/**' any depth). A page opts out itself with
|
|
69
|
-
* <cl-head><meta name="sitemap" content="false"></cl-head> (removed from the built page) or noindex
|
|
69
|
+
* <cl-head><meta name="sitemap" content="false"></cl-head> (removed from the built page) or noindex, and sets its
|
|
70
|
+
* own date with <meta name="sitemap:lastmod" content="2026-11-01">. Each page's images (not alt="", not data:) are
|
|
71
|
+
* listed with Google's image extension; `images: false` leaves them out. `include`: paths the build can't list (server
|
|
72
|
+
* and client routes), or a function returning them (async, to read them from a database at build time).
|
|
70
73
|
*/
|
|
71
74
|
sitemap?: boolean | {
|
|
72
75
|
exclude?: string[];
|
|
76
|
+
images?: boolean;
|
|
77
|
+
include?: string[] | (() => string[] | Promise<string[]>);
|
|
73
78
|
};
|
|
74
79
|
/** With site.url, vite build writes robots.txt (allow all, and the sitemap), unless public/robots.txt exists. */
|
|
75
80
|
robots?: boolean;
|