@astryxdesign/cli 0.7.15 → 0.7.16-canary.g54dd64e
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 +5 -3
- package/api/component/_adapter.d.mts +1 -1
- package/api/component/_adapter.mjs +28 -1
- package/api/doctor/_adapter.d.mts +17 -0
- package/api/doctor/_adapter.mjs +35 -0
- package/api/doctor/doctor.mjs +18 -4
- package/api/integration/pack-check.mjs +13 -7
- package/api/integration/validate-integration.mjs +1 -1
- package/api/theme/_adapter.d.mts +5 -2
- package/api/theme/_adapter.mjs +43 -12
- package/api/theme/build/build.d.mts +64 -27
- package/api/theme/build/build.mjs +341 -69
- package/api/theme/eject/eject.mjs +22 -1
- package/api/theme/template/template.d.mts +19 -0
- package/api/theme/template/template.mjs +102 -25
- package/api/theme/theme.type.d.mts +5 -1
- package/api/theme/theme.type.mjs +2 -1
- package/api/theme/themeBuild.doc.mjs +3 -3
- package/api/theme/themeEject.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +9 -3
- package/api/theme-edit/_adapter.d.mts +33 -0
- package/api/theme-edit/_adapter.mjs +208 -31
- package/api/theme-edit/_check.d.mts +38 -0
- package/api/theme-edit/_check.mjs +1326 -211
- package/api/theme-edit/_color.d.mts +2 -8
- package/api/theme-edit/_color.mjs +292 -219
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +20 -1
- package/api/theme-edit/_context.d.mts +29 -0
- package/api/theme-edit/_context.mjs +329 -30
- package/api/theme-edit/_css.d.mts +60 -1
- package/api/theme-edit/_css.mjs +404 -28
- package/api/theme-edit/_edit.d.mts +9 -0
- package/api/theme-edit/_edit.mjs +1025 -126
- package/api/theme-edit/_how-commands.d.mts +11 -26
- package/api/theme-edit/_how-commands.mjs +30 -2
- package/api/theme-edit/_how-question.d.mts +7 -0
- package/api/theme-edit/_how-question.mjs +1304 -176
- package/api/theme-edit/_how.mjs +144 -30
- package/api/theme-edit/_overview.mjs +2 -0
- package/api/theme-edit/_palette.d.mts +11 -0
- package/api/theme-edit/_palette.mjs +194 -65
- package/api/theme-edit/_parts.d.mts +16 -0
- package/api/theme-edit/_parts.mjs +59 -7
- package/api/theme-edit/_png.mjs +19 -14
- package/api/theme-edit/_preview-app.d.mts +3 -0
- package/api/theme-edit/_preview-app.mjs +843 -45
- package/api/theme-edit/_preview.d.mts +16 -3
- package/api/theme-edit/_preview.mjs +310 -29
- package/api/theme-edit/_project.d.mts +11 -0
- package/api/theme-edit/_project.mjs +46 -12
- package/api/theme-edit/_settings.d.mts +178 -5
- package/api/theme-edit/_settings.mjs +2035 -86
- package/api/theme-edit/_tables.d.mts +24 -0
- package/api/theme-edit/_tables.mjs +211 -149
- package/api/theme-edit/_vet.d.mts +42 -0
- package/api/theme-edit/_vet.mjs +144 -0
- package/api/theme-edit/theme-edit.type.d.mts +2 -1
- package/api/theme-edit/theme-edit.type.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditShow.doc.mjs +11 -3
- package/api/upgrade/registry/registry.mjs +6 -1
- package/assets/docs/tree/single-component.doc.mjs +11 -2
- package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
- package/assets/docs.generated.json +2 -2
- package/assets/preview-app/next.config.mjs +7 -1
- package/assets/preview-app/package.json +1 -0
- package/assets/preview-app/src/app/globals.css +1 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/dashboard/page.tsx +1 -1
- package/authoring/doctypes/_schema.d.mts +52 -5
- package/authoring/doctypes/_schema.mjs +62 -7
- package/authoring/doctypes/base/type.ts +10 -0
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/function/function.doc.mjs +6 -0
- package/authoring/doctypes/function/type.ts +3 -0
- package/authoring/doctypes/legacy.mjs +5 -1
- package/authoring/index.d.ts +1 -0
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/doctor.doc.mjs +2 -2
- package/clients/cli/commands/experimental/theme.mjs +190 -37
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +3 -1
- package/clients/cli/commands/theme.mjs +168 -45
- package/clients/cli/formatters/index.mjs +7 -4
- package/clients/cli/lib/cli-error.mjs +9 -3
- package/clients/cli/lib/component-format.mjs +27 -9
- package/clients/cli/lib/json-shim.mjs +40 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/clients/cli/run.mjs +49 -0
- package/foundation/config/project.mjs +50 -14
- package/foundation/discovery/theme-discovery.d.mts +5 -1
- package/foundation/discovery/theme-discovery.mjs +24 -3
- package/foundation/fs/gather-cache.d.mts +9 -2
- package/foundation/fs/gather-cache.mjs +79 -15
- package/foundation/fs/paths.d.mts +31 -0
- package/foundation/fs/paths.mjs +43 -10
- package/foundation/render/host-exit.d.mts +8 -0
- package/foundation/render/host-exit.mjs +11 -0
- package/foundation/render/page-host.mjs +56 -10
- package/foundation/render/page-worker.mjs +14 -0
- package/foundation/render/render-page.mjs +37 -2
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +5 -0
- package/foundation/response/error-codes.mjs +3 -0
- package/foundation/response/json.d.mts +15 -0
- package/foundation/response/json.mjs +52 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +7 -6
package/api/theme-edit/_css.mjs
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import {createRequire} from 'node:module';
|
|
12
|
+
import {wordTable} from './_tables.mjs';
|
|
12
13
|
|
|
13
14
|
const require = createRequire(import.meta.url);
|
|
14
15
|
|
|
@@ -58,18 +59,118 @@ let names = null;
|
|
|
58
59
|
export function cssProperties() {
|
|
59
60
|
if (names) return names;
|
|
60
61
|
const mdn = mdnProperties();
|
|
62
|
+
const current = syntaxPatches().properties;
|
|
61
63
|
names = new Set([
|
|
62
64
|
...Object.keys(csstree().lexer.properties).filter(
|
|
63
|
-
k =>
|
|
65
|
+
k =>
|
|
66
|
+
!k.startsWith('-') &&
|
|
67
|
+
mdn[k] &&
|
|
68
|
+
// MDN marks a renamed property obsolete (font-stretch is font-width
|
|
69
|
+
// now); one the current specifications still define, as browsers
|
|
70
|
+
// ship it, stays.
|
|
71
|
+
(mdn[k].status !== 'obsolete' || k in current),
|
|
64
72
|
),
|
|
65
73
|
...NOT_IN_MDN_YET,
|
|
66
74
|
]);
|
|
67
75
|
return names;
|
|
68
76
|
}
|
|
69
77
|
|
|
78
|
+
/**
|
|
79
|
+
* The current specifications' grammar, as patches to css-tree's: the
|
|
80
|
+
* ranges MDN's data leaves out (`line-height` takes `<number [0,∞]>`).
|
|
81
|
+
* @returns {{properties: Record<string, string>, types: Record<string, string>, atrules: Record<string, unknown>}}
|
|
82
|
+
*/
|
|
83
|
+
const syntaxPatches = () =>
|
|
84
|
+
require('@csstools/css-syntax-patches-for-csstree').next;
|
|
85
|
+
|
|
86
|
+
/** @type {any} */
|
|
87
|
+
let patched = null;
|
|
88
|
+
/** css-tree's lexer with the current specifications' grammar. */
|
|
89
|
+
const currentLexer = () => (patched ??= csstree().fork(syntaxPatches()).lexer);
|
|
90
|
+
|
|
91
|
+
/** @type {Map<string, Set<string>>} */
|
|
92
|
+
const longhandCache = new Map();
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Every longhand a shorthand sets, through shorthands inside it (border
|
|
96
|
+
* sets border-color, so border-top-color), as MDN's data lists them; empty
|
|
97
|
+
* for a property that is no shorthand.
|
|
98
|
+
* @param {string} prop
|
|
99
|
+
* @returns {Set<string>}
|
|
100
|
+
*/
|
|
101
|
+
export function longhandsOf(prop) {
|
|
102
|
+
const cached = longhandCache.get(prop);
|
|
103
|
+
if (cached) return cached;
|
|
104
|
+
/** @type {Set<string>} */
|
|
105
|
+
const out = new Set();
|
|
106
|
+
longhandCache.set(prop, out);
|
|
107
|
+
const computed = /** @type {any} */ (mdnProperties()[prop])?.computed;
|
|
108
|
+
if (Array.isArray(computed))
|
|
109
|
+
for (const p of computed) {
|
|
110
|
+
if (typeof p !== 'string' || p === prop) continue;
|
|
111
|
+
out.add(p);
|
|
112
|
+
for (const q of longhandsOf(p)) out.add(q);
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Whether setting `a` sets `b` too: `b` is one of `a`'s longhands, or a
|
|
119
|
+
* shorthand whose every longhand `a` sets (border covers border-top).
|
|
120
|
+
* overflow-wrap is no part of overflow, nor transform-origin of transform.
|
|
121
|
+
* @param {string} a
|
|
122
|
+
* @param {string} b
|
|
123
|
+
*/
|
|
124
|
+
export function coversProperty(a, b) {
|
|
125
|
+
if (a === b) return false;
|
|
126
|
+
const of = longhandsOf(a);
|
|
127
|
+
if (of.has(b)) return true;
|
|
128
|
+
const sub = longhandsOf(b);
|
|
129
|
+
return sub.size > 0 && [...sub].every(x => of.has(x));
|
|
130
|
+
}
|
|
131
|
+
|
|
70
132
|
/** What a var() or env() may stand for while the rest of a value is matched. */
|
|
71
133
|
const VAR_STANDS_FOR = ['0', '1px', '1ms', 'red', 'ease', 'serif', '0 0 red'];
|
|
72
134
|
|
|
135
|
+
/**
|
|
136
|
+
* The value as it reads when each variable is unset: every `var(--x, f)`
|
|
137
|
+
* replaced by its fallback `f`; null when no var() has one.
|
|
138
|
+
* @param {string} value
|
|
139
|
+
* @returns {string | null}
|
|
140
|
+
*/
|
|
141
|
+
export function withFallbacks(value) {
|
|
142
|
+
let any = false;
|
|
143
|
+
/** @param {string} v @returns {string} */
|
|
144
|
+
const pass = v => {
|
|
145
|
+
const at = v.search(/var\(/i);
|
|
146
|
+
if (at < 0) return v;
|
|
147
|
+
let depth = 0;
|
|
148
|
+
let comma = -1;
|
|
149
|
+
let end = -1;
|
|
150
|
+
for (let i = at + 4; i < v.length; i++) {
|
|
151
|
+
const c = v[i];
|
|
152
|
+
if (c === '(') depth++;
|
|
153
|
+
else if (c === ')') {
|
|
154
|
+
if (depth === 0) {
|
|
155
|
+
end = i;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
depth--;
|
|
159
|
+
} else if (c === ',' && depth === 0 && comma < 0) comma = i;
|
|
160
|
+
}
|
|
161
|
+
if (end < 0) return v;
|
|
162
|
+
if (comma < 0) return v.slice(0, end + 1) + pass(v.slice(end + 1));
|
|
163
|
+
any = true;
|
|
164
|
+
return (
|
|
165
|
+
v.slice(0, at) +
|
|
166
|
+
pass(v.slice(comma + 1, end).trim()) +
|
|
167
|
+
pass(v.slice(end + 1))
|
|
168
|
+
);
|
|
169
|
+
};
|
|
170
|
+
const out = pass(value);
|
|
171
|
+
return any ? out : null;
|
|
172
|
+
}
|
|
173
|
+
|
|
73
174
|
/**
|
|
74
175
|
* Whether a value matches a property's grammar, as css-tree reads it. A
|
|
75
176
|
* var() or env() can hold anything, so the value matches when some
|
|
@@ -178,7 +279,8 @@ function matchWith(value, match) {
|
|
|
178
279
|
/**
|
|
179
280
|
* Whether a value that matches a property's grammar is still below a range
|
|
180
281
|
* the specs set and css-tree's data does not carry: a `<line-width>` (a
|
|
181
|
-
* border or outline width) and a duration are never negative
|
|
282
|
+
* border or outline width) and a duration are never negative, nor is any
|
|
283
|
+
* number the current specifications' grammar ranges at 0 or more.
|
|
182
284
|
* @param {string} property
|
|
183
285
|
* @param {string} value
|
|
184
286
|
*/
|
|
@@ -208,6 +310,19 @@ export function belowRange(property, value) {
|
|
|
208
310
|
numbersIn(ast).some(n => n.value < 0 && ['s', 'ms'].includes(n.unit))
|
|
209
311
|
)
|
|
210
312
|
below = true;
|
|
313
|
+
// A negative number the current grammar's range refuses (`line-height
|
|
314
|
+
// -1`, `gap -2px`).
|
|
315
|
+
// Only the sign decides: the same value with every number made positive
|
|
316
|
+
// must match the current grammar.
|
|
317
|
+
if (!below && numbersIn(ast).some(n => n.value < 0)) {
|
|
318
|
+
const lexer = currentLexer();
|
|
319
|
+
const positive = parse(value.replace(/(^|[\s(,/])-(?=\.?\d)/g, '$1'), {
|
|
320
|
+
context: 'value',
|
|
321
|
+
});
|
|
322
|
+
below =
|
|
323
|
+
Boolean(lexer.matchProperty(property, ast).error) &&
|
|
324
|
+
!lexer.matchProperty(property, positive).error;
|
|
325
|
+
}
|
|
211
326
|
return below;
|
|
212
327
|
}
|
|
213
328
|
|
|
@@ -299,15 +414,17 @@ const UNIT_TYPES = /** @type {Record<string, string>} */ (
|
|
|
299
414
|
)
|
|
300
415
|
);
|
|
301
416
|
/** A value of each type, to match where a math function stands. */
|
|
302
|
-
const TYPE_SAMPLES =
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
417
|
+
const TYPE_SAMPLES = wordTable(
|
|
418
|
+
/** @type {Record<string, string>} */ ({
|
|
419
|
+
number: '1',
|
|
420
|
+
percent: '1%',
|
|
421
|
+
length: '1px',
|
|
422
|
+
time: '1s',
|
|
423
|
+
angle: '1deg',
|
|
424
|
+
frequency: '1hz',
|
|
425
|
+
resolution: '1dppx',
|
|
426
|
+
}),
|
|
427
|
+
);
|
|
311
428
|
|
|
312
429
|
/**
|
|
313
430
|
* The type of a sum (or of the arguments of min(), max(), clamp()):
|
|
@@ -513,10 +630,15 @@ export function numbersIn(ast) {
|
|
|
513
630
|
csstree().walk(ast, {
|
|
514
631
|
enter(/** @type {any} */ node) {
|
|
515
632
|
if (node.type === 'Function') fns.push(node.name.toLowerCase());
|
|
516
|
-
if (
|
|
633
|
+
if (
|
|
634
|
+
node.type === 'Dimension' ||
|
|
635
|
+
node.type === 'Number' ||
|
|
636
|
+
node.type === 'Percentage'
|
|
637
|
+
)
|
|
517
638
|
out.push({
|
|
518
639
|
value: Number(node.value),
|
|
519
|
-
unit:
|
|
640
|
+
unit:
|
|
641
|
+
node.type === 'Percentage' ? '%' : (node.unit ?? '').toLowerCase(),
|
|
520
642
|
fn: fns.at(-1) ?? null,
|
|
521
643
|
});
|
|
522
644
|
},
|
|
@@ -565,6 +687,40 @@ export function keywordsOf(prop) {
|
|
|
565
687
|
return [...words];
|
|
566
688
|
}
|
|
567
689
|
|
|
690
|
+
/** @type {string[] | null} */
|
|
691
|
+
let generics = null;
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* The CSS generic font families (serif, math, ui-rounded …), as the
|
|
695
|
+
* grammar's `<generic-family>` type lists them; non-standard ones left out.
|
|
696
|
+
* @returns {string[]}
|
|
697
|
+
*/
|
|
698
|
+
export function genericFamilies() {
|
|
699
|
+
if (generics) return generics;
|
|
700
|
+
const t = csstree();
|
|
701
|
+
const seen = new Set();
|
|
702
|
+
/** @type {Set<string>} */
|
|
703
|
+
const words = new Set();
|
|
704
|
+
/** @param {any} syntax */
|
|
705
|
+
const walk = syntax => {
|
|
706
|
+
if (!syntax) return;
|
|
707
|
+
t.definitionSyntax.walk(syntax, (/** @type {any} */ n) => {
|
|
708
|
+
if (n.type === 'Keyword') {
|
|
709
|
+
if (!n.name.startsWith('-')) words.add(n.name);
|
|
710
|
+
} else if (
|
|
711
|
+
n.type === 'Type' &&
|
|
712
|
+
!n.name.startsWith('-') &&
|
|
713
|
+
!seen.has(n.name)
|
|
714
|
+
) {
|
|
715
|
+
seen.add(n.name);
|
|
716
|
+
walk(currentLexer().types[n.name]?.syntax);
|
|
717
|
+
}
|
|
718
|
+
});
|
|
719
|
+
};
|
|
720
|
+
walk(currentLexer().types['generic-family']?.syntax);
|
|
721
|
+
return (generics = [...words]);
|
|
722
|
+
}
|
|
723
|
+
|
|
568
724
|
/**
|
|
569
725
|
* A value the property takes, to put in a suggestion: its initial value
|
|
570
726
|
* from MDN's data (a shorthand's first longhand's).
|
|
@@ -583,13 +739,64 @@ export function initialOf(prop) {
|
|
|
583
739
|
: null;
|
|
584
740
|
}
|
|
585
741
|
|
|
742
|
+
/**
|
|
743
|
+
* One CSS number, percentage or dimension, read by css-tree's tokenizer as
|
|
744
|
+
* the browser reads it (`1.5e0`, `+1.5`, `15E-1`, `1.5EM`; never `50.%`),
|
|
745
|
+
* or null for anything else.
|
|
746
|
+
* @param {string} value
|
|
747
|
+
* @returns {{value: number, unit: string} | null}
|
|
748
|
+
*/
|
|
749
|
+
export function cssNumber(value) {
|
|
750
|
+
/** @type {any} */
|
|
751
|
+
let ast;
|
|
752
|
+
try {
|
|
753
|
+
ast = csstree().parse(value.trim(), {context: 'value'});
|
|
754
|
+
} catch {
|
|
755
|
+
return null;
|
|
756
|
+
}
|
|
757
|
+
const nodes = ast.children?.toArray?.() ?? [];
|
|
758
|
+
if (nodes.length !== 1) return null;
|
|
759
|
+
const [n] = nodes;
|
|
760
|
+
if (n.type === 'Number') return {value: Number(n.value), unit: ''};
|
|
761
|
+
if (n.type === 'Percentage') return {value: Number(n.value), unit: '%'};
|
|
762
|
+
if (n.type === 'Dimension')
|
|
763
|
+
return {value: Number(n.value), unit: String(n.unit).toLowerCase()};
|
|
764
|
+
return null;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* A value split at `sep` outside brackets: `a(b, c), d` by `,` is
|
|
769
|
+
* [`a(b, c)`, ` d`]. A space separator also splits runs of spaces.
|
|
770
|
+
* @param {string} v
|
|
771
|
+
* @param {',' | ' ' | '/'} sep
|
|
772
|
+
* @returns {string[]}
|
|
773
|
+
*/
|
|
774
|
+
export function splitTop(v, sep) {
|
|
775
|
+
/** @type {string[]} */
|
|
776
|
+
const out = [];
|
|
777
|
+
let depth = 0;
|
|
778
|
+
let cur = '';
|
|
779
|
+
for (const c of v) {
|
|
780
|
+
if (c === '(') depth++;
|
|
781
|
+
if (c === ')') depth--;
|
|
782
|
+
if (depth === 0 && (sep === ' ' ? /\s/.test(c) : c === sep)) {
|
|
783
|
+
if (cur.trim() || sep === ',') out.push(cur);
|
|
784
|
+
cur = '';
|
|
785
|
+
} else cur += c;
|
|
786
|
+
}
|
|
787
|
+
if (cur.trim() || sep === ',') out.push(cur);
|
|
788
|
+
return out.filter(x => sep === ',' || x.trim());
|
|
789
|
+
}
|
|
790
|
+
|
|
586
791
|
/** The longhand each type of the `font` grammar sets, where css-tree names a type, not a property. */
|
|
587
|
-
const FONT_TYPE_LONGHAND =
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
792
|
+
const FONT_TYPE_LONGHAND = wordTable(
|
|
793
|
+
/** @type {Record<string, string>} */ ({
|
|
794
|
+
'font-variant-css2': 'font-variant-caps',
|
|
795
|
+
'font-width-css3': 'font-stretch',
|
|
796
|
+
'font-stretch-absolute': 'font-stretch',
|
|
797
|
+
'system-family-name': 'system',
|
|
798
|
+
}),
|
|
799
|
+
);
|
|
593
800
|
|
|
594
801
|
/**
|
|
595
802
|
* The parts of a CSS `font` value, by the longhand each sets, as written:
|
|
@@ -602,15 +809,90 @@ const FONT_TYPE_LONGHAND = /** @type {Record<string, string>} */ ({
|
|
|
602
809
|
*/
|
|
603
810
|
export function fontShorthandParts(value) {
|
|
604
811
|
const {lexer, parse, generate} = csstree();
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
812
|
+
// Words that are each one longhand's keyword, size or weight (`bold`,
|
|
813
|
+
// `italic bold`, `bold 1rem`) are those longhands, in any order before the
|
|
814
|
+
// size; after the size the rest is the family (`1rem bold` names a family
|
|
815
|
+
// called bold), as CSS reads it.
|
|
816
|
+
const LONGHANDS = [
|
|
817
|
+
'font-weight',
|
|
818
|
+
'font-style',
|
|
819
|
+
'font-variant-caps',
|
|
820
|
+
'font-stretch',
|
|
821
|
+
'font-size',
|
|
822
|
+
];
|
|
823
|
+
// A lone generic family (math, fangsong) is a family, though a longhand
|
|
824
|
+
// may share the word (font-size: math).
|
|
825
|
+
if (genericFamilies().includes(value.trim().toLowerCase()))
|
|
826
|
+
return {'font-family': value.trim()};
|
|
827
|
+
if (!value.includes(',')) {
|
|
828
|
+
/** @type {Record<string, string>} */
|
|
829
|
+
const each = {};
|
|
830
|
+
const words = splitTop(value.trim(), ' ');
|
|
831
|
+
let all = true;
|
|
832
|
+
// `normal` fits several longhands: every other word is placed first,
|
|
833
|
+
// then each `normal` takes the first longhand still free.
|
|
834
|
+
const normals = words.filter(w => w.toLowerCase() === 'normal').length;
|
|
835
|
+
// A normal after the size is part of the family, read below.
|
|
836
|
+
const sizeAt = words.findIndex(
|
|
837
|
+
w => matchValue('font-size', w.split('/')[0]) && !/^[a-z-]+$/i.test(w),
|
|
838
|
+
);
|
|
839
|
+
if (
|
|
840
|
+
sizeAt >= 0 &&
|
|
841
|
+
words.slice(sizeAt + 1).some(w => w.toLowerCase() === 'normal')
|
|
842
|
+
)
|
|
843
|
+
all = false;
|
|
844
|
+
for (const w of words.filter(x => x.toLowerCase() !== 'normal')) {
|
|
845
|
+
if (!all) break;
|
|
846
|
+
const lower = w.toLowerCase();
|
|
847
|
+
// After the size, the rest is the family (16px bold names a family
|
|
848
|
+
// called bold): the grammar below reads it.
|
|
849
|
+
if ('font-size' in each) {
|
|
850
|
+
all = false;
|
|
851
|
+
break;
|
|
852
|
+
}
|
|
853
|
+
// A size with its line height (1rem/1.5).
|
|
854
|
+
const slash = /^([^/]+)\/([^/]+)$/.exec(w);
|
|
855
|
+
if (
|
|
856
|
+
slash &&
|
|
857
|
+
!('font-size' in each) &&
|
|
858
|
+
matchValue('font-size', slash[1]) &&
|
|
859
|
+
matchValue('line-height', slash[2])
|
|
860
|
+
) {
|
|
861
|
+
each['font-size'] = slash[1];
|
|
862
|
+
each['line-height'] = slash[2];
|
|
863
|
+
continue;
|
|
864
|
+
}
|
|
865
|
+
const takers = LONGHANDS.filter(p => keywordsOf(p).includes(lower));
|
|
866
|
+
const keyword = takers.find(p => !(p in each));
|
|
867
|
+
// A part given twice (bold bold, bold lighter, italic oblique) is no
|
|
868
|
+
// font value.
|
|
869
|
+
if (takers.length && !keyword) return {repeat: lower, part: takers[0]};
|
|
870
|
+
const prop =
|
|
871
|
+
keyword ??
|
|
872
|
+
['font-size', 'font-weight'].find(
|
|
873
|
+
p => !(p in each) && !/^[a-z-]+$/i.test(w) && matchValue(p, w),
|
|
874
|
+
);
|
|
875
|
+
if (!prop) {
|
|
876
|
+
all = false;
|
|
877
|
+
break;
|
|
878
|
+
}
|
|
879
|
+
each[prop] = /^[a-z-]+$/i.test(w) ? lower : w;
|
|
880
|
+
}
|
|
881
|
+
for (let n = 0; all && n < normals; n += 1) {
|
|
882
|
+
const free = LONGHANDS.find(
|
|
883
|
+
p => !(p in each) && keywordsOf(p).includes('normal'),
|
|
884
|
+
);
|
|
885
|
+
if (!free)
|
|
886
|
+
return {
|
|
887
|
+
repeat: 'normal',
|
|
888
|
+
part: LONGHANDS.filter(p => keywordsOf(p).includes('normal')).join(
|
|
889
|
+
', ',
|
|
890
|
+
),
|
|
891
|
+
};
|
|
892
|
+
each[free] = 'normal';
|
|
893
|
+
}
|
|
894
|
+
if (all && words.length) return each;
|
|
895
|
+
}
|
|
614
896
|
/** @type {any} */
|
|
615
897
|
let ast;
|
|
616
898
|
try {
|
|
@@ -698,3 +980,97 @@ export function takesPercentage(prop) {
|
|
|
698
980
|
percentCache.set(prop, found);
|
|
699
981
|
return found;
|
|
700
982
|
}
|
|
983
|
+
|
|
984
|
+
/** The generic font families CSS names, which are never quoted. */
|
|
985
|
+
const GENERIC_FAMILIES = new Set([
|
|
986
|
+
'serif',
|
|
987
|
+
'sans-serif',
|
|
988
|
+
'monospace',
|
|
989
|
+
'cursive',
|
|
990
|
+
'fantasy',
|
|
991
|
+
'system-ui',
|
|
992
|
+
'math',
|
|
993
|
+
'emoji',
|
|
994
|
+
'fangsong',
|
|
995
|
+
'ui-serif',
|
|
996
|
+
'ui-sans-serif',
|
|
997
|
+
'ui-monospace',
|
|
998
|
+
'ui-rounded',
|
|
999
|
+
]);
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* A font family list with its missing commas put back, read with css-tree:
|
|
1003
|
+
* within one comma-separated entry, a quoted family next to another quoted
|
|
1004
|
+
* family or a generic one (`"Open Sans" serif`) is two families. Returns the
|
|
1005
|
+
* list as CSS writes it (`"Open Sans", serif`), or null when nothing is
|
|
1006
|
+
* missing, the value does not parse, or a family would hold a quote.
|
|
1007
|
+
* @param {string} value
|
|
1008
|
+
* @returns {string | null}
|
|
1009
|
+
*/
|
|
1010
|
+
export function familyListMeant(value) {
|
|
1011
|
+
const {parse} = csstree();
|
|
1012
|
+
/** @type {any} */
|
|
1013
|
+
let ast;
|
|
1014
|
+
try {
|
|
1015
|
+
ast = parse(value, {context: 'value'});
|
|
1016
|
+
} catch {
|
|
1017
|
+
return null;
|
|
1018
|
+
}
|
|
1019
|
+
/** @type {Array<Array<{type: string, value: string}>>} */
|
|
1020
|
+
const entries = [[]];
|
|
1021
|
+
let ok = true;
|
|
1022
|
+
ast.children.forEach((/** @type {any} */ n) => {
|
|
1023
|
+
if (n.type === 'Operator' && n.value === ',') entries.push([]);
|
|
1024
|
+
else if (n.type === 'String' || n.type === 'Identifier')
|
|
1025
|
+
entries[entries.length - 1].push({
|
|
1026
|
+
type: n.type,
|
|
1027
|
+
value: n.type === 'String' ? n.value : n.name,
|
|
1028
|
+
});
|
|
1029
|
+
else ok = false;
|
|
1030
|
+
});
|
|
1031
|
+
if (!ok) return null;
|
|
1032
|
+
/** @type {string[]} */
|
|
1033
|
+
const families = [];
|
|
1034
|
+
let changed = false;
|
|
1035
|
+
for (const entry of entries) {
|
|
1036
|
+
if (!entry.length) return null;
|
|
1037
|
+
// One family: a quoted name alone, or a run of bare words.
|
|
1038
|
+
if (
|
|
1039
|
+
entry.length === 1 ||
|
|
1040
|
+
entry.every(
|
|
1041
|
+
x =>
|
|
1042
|
+
x.type === 'Identifier' &&
|
|
1043
|
+
!GENERIC_FAMILIES.has(x.value.toLowerCase()),
|
|
1044
|
+
)
|
|
1045
|
+
) {
|
|
1046
|
+
families.push(
|
|
1047
|
+
entry.length === 1 && entry[0].type === 'String'
|
|
1048
|
+
? JSON.stringify(entry[0].value)
|
|
1049
|
+
: entry.map(x => x.value).join(' '),
|
|
1050
|
+
);
|
|
1051
|
+
continue;
|
|
1052
|
+
}
|
|
1053
|
+
// A quoted name or a generic family ends a family: the comma between
|
|
1054
|
+
// them was left out.
|
|
1055
|
+
changed = true;
|
|
1056
|
+
/** @type {string[]} */
|
|
1057
|
+
let words = [];
|
|
1058
|
+
const flush = () => {
|
|
1059
|
+
if (words.length) families.push(words.join(' '));
|
|
1060
|
+
words = [];
|
|
1061
|
+
};
|
|
1062
|
+
for (const x of entry) {
|
|
1063
|
+
if (x.type === 'String') {
|
|
1064
|
+
flush();
|
|
1065
|
+
families.push(JSON.stringify(x.value));
|
|
1066
|
+
} else if (GENERIC_FAMILIES.has(x.value.toLowerCase())) {
|
|
1067
|
+
flush();
|
|
1068
|
+
families.push(x.value);
|
|
1069
|
+
} else words.push(x.value);
|
|
1070
|
+
}
|
|
1071
|
+
flush();
|
|
1072
|
+
}
|
|
1073
|
+
// A family that would hold a quote (escaped) is never a suggestion.
|
|
1074
|
+
if (!changed || families.some(f => f.includes('\\'))) return null;
|
|
1075
|
+
return families.join(', ');
|
|
1076
|
+
}
|
|
@@ -11,6 +11,15 @@
|
|
|
11
11
|
* @returns {Promise<import('./theme-edit.type.mjs').ThemeEditNewResponse>}
|
|
12
12
|
*/
|
|
13
13
|
export function themeEditNew(name: string, options?: import("./theme-edit.type.mjs").ThemeEditNewOptions): Promise<import("./theme-edit.type.mjs").ThemeEditNewResponse>;
|
|
14
|
+
/**
|
|
15
|
+
* The options of a `new` as flags, in the order given (`new --help`'s order
|
|
16
|
+
* for the command): `--like`, each dial setting, then `--png`.
|
|
17
|
+
* @param {string | null | undefined} like none when null or undefined
|
|
18
|
+
* @param {Record<string, string | string[] | undefined>} settings
|
|
19
|
+
* @param {boolean} [png]
|
|
20
|
+
* @returns {string[]}
|
|
21
|
+
*/
|
|
22
|
+
export function newFlagList(like: string | null | undefined, settings: Record<string, string | string[] | undefined>, png?: boolean): string[];
|
|
14
23
|
/**
|
|
15
24
|
* Change one thing in a theme: checked, built, previewed.
|
|
16
25
|
* @experimental
|