dsh-fonttune 0.1.6 → 0.2.1
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/CHANGELOG.en.md +39 -0
- package/CHANGELOG.md +39 -0
- package/README.en.md +27 -15
- package/README.md +26 -14
- package/lib/client.js +2982 -527
- package/lib/index.js +168 -32
- package/lib/shared.cjs +1435 -265
- package/package.json +4 -4
package/lib/shared.cjs
CHANGED
|
@@ -10,6 +10,26 @@
|
|
|
10
10
|
* configuration produces, and the sanitizing that keeps user-typed font names
|
|
11
11
|
* from breaking out of the injected stylesheet.
|
|
12
12
|
*
|
|
13
|
+
* 0.2.x shape: the axes are grouped into three SURFACES — interface (the UI
|
|
14
|
+
* chrome), dialog (the conversation markdown) and code. The CONVERSATION owns
|
|
15
|
+
* every axis: a family, a size offset, a weight and a line-height ratio. The
|
|
16
|
+
* interface owns a family and a weight, and by default FOLLOWS the conversation
|
|
17
|
+
* on both (the switch turns that off and reveals its own controls); DSH exposes
|
|
18
|
+
* no interface size or line-height hook at all, so those two axes are retired
|
|
19
|
+
* and the durable fields inject nothing. Code carries a family, a size offset,
|
|
20
|
+
* a weight, an additive line-height offset and the ligature/feature controls.
|
|
21
|
+
* `perTheme` enables a second value set for the dark theme, stored as a sparse
|
|
22
|
+
* override map.
|
|
23
|
+
*
|
|
24
|
+
* The interface weight is the one axis that has to reach the WHOLE page (DSH
|
|
25
|
+
* pins its labels with literal weights on class rules, so nothing narrower can
|
|
26
|
+
* move them), which is why it is a `body, body *` rule with an exclusion for
|
|
27
|
+
* the conversation markdown subtree: the conversation's own weight rule then
|
|
28
|
+
* owns that subtree completely and neither axis can disturb the other. That
|
|
29
|
+
* exclusion is what makes the axis safe — measured on a live page (computed
|
|
30
|
+
* styles, `test/weight-verify.mjs`): every text element outside the markdown
|
|
31
|
+
* subtree takes the weight, and not one element inside it moves.
|
|
32
|
+
*
|
|
13
33
|
* @module dsh-fonttune/shared
|
|
14
34
|
*/
|
|
15
35
|
"use strict";
|
|
@@ -17,24 +37,99 @@
|
|
|
17
37
|
/** Settings namespace registered by the host half. */
|
|
18
38
|
var NAMESPACE = "dsh-fonttune";
|
|
19
39
|
|
|
20
|
-
|
|
40
|
+
/* ------------------------------------------------------------------ *
|
|
41
|
+
* durable field names
|
|
42
|
+
* ------------------------------------------------------------------ */
|
|
43
|
+
|
|
44
|
+
/** Field carrying the interface CSS font-family stack (empty = leave DSH). */
|
|
21
45
|
var SANS_FIELD = "sans";
|
|
22
46
|
|
|
23
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Field carrying the dialog stack. The conversation owns the family: empty
|
|
49
|
+
* means DSH's own default family. A document written before 0.2.0 only has the
|
|
50
|
+
* interface family, so an empty dialog takes it (see `expandFollow`) — that is
|
|
51
|
+
* a migration bridge, not a live rule the card describes.
|
|
52
|
+
*/
|
|
53
|
+
var STACK_DIALOG_FIELD = "stackDialog";
|
|
54
|
+
|
|
55
|
+
/** Field carrying the code CSS font-family stack (empty = leave DSH). */
|
|
24
56
|
var MONO_FIELD = "mono";
|
|
25
57
|
|
|
26
|
-
/** Field carrying the
|
|
58
|
+
/** Field carrying the interface font-size offset in px (0 = leave DSH alone). */
|
|
27
59
|
var SIZE_FIELD = "sizeOffset";
|
|
28
60
|
|
|
61
|
+
/** Field carrying the dialog font-size offset in px (0 = DSH's own sizes). */
|
|
62
|
+
var SIZE_DIALOG_FIELD = "sizeOffsetDialog";
|
|
63
|
+
|
|
29
64
|
/** Field carrying the code font-size offset in px (0 = leave DSH alone). */
|
|
30
65
|
var CODE_SIZE_FIELD = "sizeOffsetCode";
|
|
31
66
|
|
|
32
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Field carrying the interface font weight (0 = leave DSH alone). While the
|
|
69
|
+
* interface follows the conversation this is the fallback for a conversation
|
|
70
|
+
* that sets no weight of its own.
|
|
71
|
+
*/
|
|
33
72
|
var WEIGHT_FIELD = "weight";
|
|
34
73
|
|
|
74
|
+
/** Field carrying the dialog font weight (0 = DSH's own weights). */
|
|
75
|
+
var WEIGHT_DIALOG_FIELD = "weightDialog";
|
|
76
|
+
|
|
35
77
|
/** Field carrying the code font weight (0 = leave DSH alone). */
|
|
36
78
|
var CODE_WEIGHT_FIELD = "weightCode";
|
|
37
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Field carrying the interface line-height ratio in percent (100 = untouched).
|
|
82
|
+
* A ratio rather than a px offset: interface line heights form a design ladder
|
|
83
|
+
* (14/18/20/22/24/26/28/32), and a ratio keeps every step proportional.
|
|
84
|
+
*/
|
|
85
|
+
var LINE_HEIGHT_FIELD = "lineHeight";
|
|
86
|
+
|
|
87
|
+
/** Field carrying the dialog line-height ratio in percent (100 = DSH's own). */
|
|
88
|
+
var LINE_HEIGHT_DIALOG_FIELD = "lineHeightDialog";
|
|
89
|
+
|
|
90
|
+
/** Field carrying the code line-height offset in px (0 = leave DSH alone). */
|
|
91
|
+
var CODE_LINE_HEIGHT_FIELD = "lineHeightCode";
|
|
92
|
+
|
|
93
|
+
/** Ligature mode: 0 = DSH default, 1 = forced on, 2 = forced off. */
|
|
94
|
+
var LIGATURES_FIELD = "codeLigatures";
|
|
95
|
+
|
|
96
|
+
/** Advanced `font-feature-settings` value for code (sanitized; empty = none). */
|
|
97
|
+
var FEATURES_FIELD = "codeFeatures";
|
|
98
|
+
|
|
99
|
+
/** Disable synthetic (faux) italic — the "tilted CJK" rendering. */
|
|
100
|
+
var NO_SYNTHETIC_ITALIC_FIELD = "noSyntheticItalic";
|
|
101
|
+
|
|
102
|
+
/** Disable synthetic (faux) bold, for faces without a real bold. */
|
|
103
|
+
var NO_SYNTHETIC_BOLD_FIELD = "noSyntheticBold";
|
|
104
|
+
|
|
105
|
+
/** Whether the dark theme keeps its own value set (sparse overrides). */
|
|
106
|
+
var PER_THEME_FIELD = "perTheme";
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* JSON string of the dark-theme sparse overrides: a map of axis field to
|
|
110
|
+
* value, applied over the single set while the dark theme is active.
|
|
111
|
+
*/
|
|
112
|
+
var DARK_VALUES_FIELD = "darkValues";
|
|
113
|
+
|
|
114
|
+
/** JSON string of saved presets: [{name, values, savedAt}]. */
|
|
115
|
+
var PRESETS_FIELD = "presets";
|
|
116
|
+
|
|
117
|
+
/** Name of the preset the card's edits auto-save into. */
|
|
118
|
+
var ACTIVE_PRESET_FIELD = "activePreset";
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Whether the INTERFACE follows the conversation. The conversation owns every
|
|
122
|
+
* axis; the interface has a family and a weight of its own (DSH exposes no
|
|
123
|
+
* interface size or line-height hook), so on — the default — the conversation's
|
|
124
|
+
* family and weight win and the interface's own values stand as the fallback
|
|
125
|
+
* for an axis the conversation does not set.
|
|
126
|
+
*/
|
|
127
|
+
var UI_FOLLOWS_FIELD = "uiFollowsDialog";
|
|
128
|
+
|
|
129
|
+
/* ------------------------------------------------------------------ *
|
|
130
|
+
* ranges and constants
|
|
131
|
+
* ------------------------------------------------------------------ */
|
|
132
|
+
|
|
38
133
|
/** Allowed font-size offset range. The upper bound stays under a 2x scale. */
|
|
39
134
|
var SIZE_MIN = -3;
|
|
40
135
|
var SIZE_MAX = 6;
|
|
@@ -44,10 +139,23 @@ var WEIGHT_MIN = 300;
|
|
|
44
139
|
var WEIGHT_MAX = 600;
|
|
45
140
|
var WEIGHT_UNSET = 0;
|
|
46
141
|
|
|
142
|
+
/** Allowed line-height ratio range, in percent (100 = untouched). */
|
|
143
|
+
var LINE_HEIGHT_MIN = 100;
|
|
144
|
+
var LINE_HEIGHT_MAX = 160;
|
|
145
|
+
|
|
146
|
+
/** Allowed code line-height offset range, in px. */
|
|
147
|
+
var CODE_LINE_HEIGHT_MIN = -4;
|
|
148
|
+
var CODE_LINE_HEIGHT_MAX = 8;
|
|
149
|
+
|
|
150
|
+
/** Ligature modes. */
|
|
151
|
+
var LIGATURES_DEFAULT = 0;
|
|
152
|
+
var LIGATURES_ON = 1;
|
|
153
|
+
var LIGATURES_OFF = 2;
|
|
154
|
+
|
|
47
155
|
/** Marker on both injected style tags, used for scoping every rule we write. */
|
|
48
156
|
var MARKER = "dfp";
|
|
49
157
|
|
|
50
|
-
/** `data-plugin-css` value of the tag applying
|
|
158
|
+
/** `data-plugin-css` value of the tag applying the configuration. */
|
|
51
159
|
var STYLE_TAG = "dsh-fonttune";
|
|
52
160
|
|
|
53
161
|
/** `data-plugin-css` value of the card's own chrome stylesheet. */
|
|
@@ -56,13 +164,52 @@ var CARD_STYLE_TAG = "dsh-fonttune-card";
|
|
|
56
164
|
/** Composition defaults: every axis dormant, so installing changes nothing. */
|
|
57
165
|
var DEFAULTS = {
|
|
58
166
|
sans: "",
|
|
167
|
+
stackDialog: "",
|
|
59
168
|
mono: "",
|
|
60
169
|
sizeOffset: 0,
|
|
170
|
+
sizeOffsetDialog: 0,
|
|
61
171
|
sizeOffsetCode: 0,
|
|
62
172
|
weight: WEIGHT_UNSET,
|
|
173
|
+
weightDialog: WEIGHT_UNSET,
|
|
63
174
|
weightCode: WEIGHT_UNSET,
|
|
175
|
+
lineHeight: LINE_HEIGHT_MIN,
|
|
176
|
+
lineHeightDialog: LINE_HEIGHT_MIN,
|
|
177
|
+
lineHeightCode: 0,
|
|
178
|
+
codeLigatures: LIGATURES_DEFAULT,
|
|
179
|
+
codeFeatures: "",
|
|
180
|
+
noSyntheticItalic: false,
|
|
181
|
+
noSyntheticBold: false,
|
|
182
|
+
perTheme: false,
|
|
183
|
+
darkValues: "{}",
|
|
184
|
+
presets: "[]",
|
|
185
|
+
activePreset: "",
|
|
186
|
+
uiFollowsDialog: true,
|
|
64
187
|
};
|
|
65
188
|
|
|
189
|
+
/**
|
|
190
|
+
* The axis fields a preset snapshots: everything the card edits, excluding
|
|
191
|
+
* the storage fields themselves.
|
|
192
|
+
*/
|
|
193
|
+
var VALUE_FIELDS = [
|
|
194
|
+
SANS_FIELD,
|
|
195
|
+
STACK_DIALOG_FIELD,
|
|
196
|
+
MONO_FIELD,
|
|
197
|
+
SIZE_FIELD,
|
|
198
|
+
SIZE_DIALOG_FIELD,
|
|
199
|
+
CODE_SIZE_FIELD,
|
|
200
|
+
WEIGHT_FIELD,
|
|
201
|
+
WEIGHT_DIALOG_FIELD,
|
|
202
|
+
CODE_WEIGHT_FIELD,
|
|
203
|
+
LINE_HEIGHT_FIELD,
|
|
204
|
+
LINE_HEIGHT_DIALOG_FIELD,
|
|
205
|
+
CODE_LINE_HEIGHT_FIELD,
|
|
206
|
+
LIGATURES_FIELD,
|
|
207
|
+
FEATURES_FIELD,
|
|
208
|
+
NO_SYNTHETIC_ITALIC_FIELD,
|
|
209
|
+
NO_SYNTHETIC_BOLD_FIELD,
|
|
210
|
+
UI_FOLLOWS_FIELD,
|
|
211
|
+
];
|
|
212
|
+
|
|
66
213
|
/**
|
|
67
214
|
* Longest accepted font stack, in characters (mirrored by the host schema).
|
|
68
215
|
*/
|
|
@@ -71,6 +218,19 @@ var MAX_STACK_LENGTH = 200;
|
|
|
71
218
|
/** Longest accepted single family name, in characters. */
|
|
72
219
|
var MAX_FAMILY_LENGTH = 64;
|
|
73
220
|
|
|
221
|
+
/** Longest accepted `font-feature-settings` value, in characters. */
|
|
222
|
+
var MAX_FEATURES_LENGTH = 120;
|
|
223
|
+
|
|
224
|
+
/** Most presets one configuration may hold. */
|
|
225
|
+
var MAX_PRESETS = 20;
|
|
226
|
+
|
|
227
|
+
/** Longest preset name, in characters. */
|
|
228
|
+
var MAX_PRESET_NAME = 32;
|
|
229
|
+
|
|
230
|
+
/* ------------------------------------------------------------------ *
|
|
231
|
+
* sanitizing
|
|
232
|
+
* ------------------------------------------------------------------ */
|
|
233
|
+
|
|
74
234
|
/**
|
|
75
235
|
* What may survive in a family name.
|
|
76
236
|
*
|
|
@@ -141,28 +301,93 @@ var GENERIC_FAMILIES = [
|
|
|
141
301
|
"blinkmacsystemfont",
|
|
142
302
|
];
|
|
143
303
|
|
|
304
|
+
/**
|
|
305
|
+
* Sanitize an advanced `font-feature-settings` value.
|
|
306
|
+
*
|
|
307
|
+
* Feature tags are letters and digits; entries may carry on/off/number and are
|
|
308
|
+
* comma separated. The allow-list (letters, digits, quotes, spaces, commas)
|
|
309
|
+
* keeps the value from closing the declaration or opening another one, and a
|
|
310
|
+
* coarse shape test rejects anything that is not a tag-entry list.
|
|
311
|
+
* @param {unknown} value - candidate features value.
|
|
312
|
+
* @returns {string} the sanitized value, or "".
|
|
313
|
+
*/
|
|
314
|
+
function sanitizeFeatures(value) {
|
|
315
|
+
if (typeof value !== "string") return "";
|
|
316
|
+
var text = value.replace(FEATURES_UNSAFE, "").slice(0, MAX_FEATURES_LENGTH).trim();
|
|
317
|
+
if (text === "") return "";
|
|
318
|
+
if (!/^(?:"?[a-zA-Z0-9]{1,8}"?(?: (?:on|off|-?\d+))?(?:, ?)?)+$/.test(text)) return "";
|
|
319
|
+
return text;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** Characters a `font-feature-settings` value cannot contain. */
|
|
323
|
+
var FEATURES_UNSAFE = /[^a-zA-Z0-9"' ,]/g;
|
|
324
|
+
|
|
325
|
+
/* ------------------------------------------------------------------ *
|
|
326
|
+
* configuration normalization
|
|
327
|
+
* ------------------------------------------------------------------ */
|
|
328
|
+
|
|
329
|
+
/** Clamp/validate one field by name (shared by config and value sets). */
|
|
330
|
+
function normalizeField(field, value) {
|
|
331
|
+
switch (field) {
|
|
332
|
+
case SANS_FIELD:
|
|
333
|
+
case STACK_DIALOG_FIELD:
|
|
334
|
+
case MONO_FIELD:
|
|
335
|
+
return sanitize(value).slice(0, MAX_STACK_LENGTH);
|
|
336
|
+
case SIZE_FIELD:
|
|
337
|
+
case SIZE_DIALOG_FIELD:
|
|
338
|
+
case CODE_SIZE_FIELD:
|
|
339
|
+
return clampOffset(value);
|
|
340
|
+
case WEIGHT_FIELD:
|
|
341
|
+
case WEIGHT_DIALOG_FIELD:
|
|
342
|
+
case CODE_WEIGHT_FIELD:
|
|
343
|
+
return clampWeight(value);
|
|
344
|
+
case LINE_HEIGHT_FIELD:
|
|
345
|
+
case LINE_HEIGHT_DIALOG_FIELD:
|
|
346
|
+
return clampRatio(value);
|
|
347
|
+
case CODE_LINE_HEIGHT_FIELD:
|
|
348
|
+
return clampLineOffset(value);
|
|
349
|
+
case LIGATURES_FIELD:
|
|
350
|
+
return clampLigatures(value);
|
|
351
|
+
case FEATURES_FIELD:
|
|
352
|
+
return sanitizeFeatures(value);
|
|
353
|
+
case NO_SYNTHETIC_ITALIC_FIELD:
|
|
354
|
+
case NO_SYNTHETIC_BOLD_FIELD:
|
|
355
|
+
return toBool(value);
|
|
356
|
+
case UI_FOLLOWS_FIELD:
|
|
357
|
+
// Absent means the default: the interface follows the conversation.
|
|
358
|
+
return value === undefined || value === null || value === "" ? true : toBool(value);
|
|
359
|
+
default:
|
|
360
|
+
return undefined;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
144
364
|
/**
|
|
145
365
|
* Normalize a configuration-shaped object coming from the settings document,
|
|
146
|
-
* a config layer, or a test fixture.
|
|
366
|
+
* a config layer, or a test fixture. Storage fields (`darkValues`,
|
|
367
|
+
* `presets`) are decoded and validated here too, so every consumer sees
|
|
368
|
+
* plain data.
|
|
147
369
|
* @param {unknown} value - candidate configuration.
|
|
148
|
-
* @returns {
|
|
370
|
+
* @returns {Record<string, string|number|boolean|object|array>} the normalized config.
|
|
149
371
|
*/
|
|
150
372
|
function normalizeConfig(value) {
|
|
151
373
|
var source = value !== null && typeof value === "object" ? value : {};
|
|
152
|
-
var size = clampOffset(source[SIZE_FIELD]);
|
|
153
|
-
var codeSize = clampOffset(source[CODE_SIZE_FIELD]);
|
|
154
|
-
var weight = clampWeight(source[WEIGHT_FIELD]);
|
|
155
|
-
var codeWeight = clampWeight(source[CODE_WEIGHT_FIELD]);
|
|
156
374
|
var config = {};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
config[
|
|
162
|
-
config[
|
|
375
|
+
for (var index = 0; index < VALUE_FIELDS.length; index += 1) {
|
|
376
|
+
var field = VALUE_FIELDS[index];
|
|
377
|
+
config[field] = normalizeField(field, source[field]);
|
|
378
|
+
}
|
|
379
|
+
config[PER_THEME_FIELD] = toBool(source[PER_THEME_FIELD]);
|
|
380
|
+
config[DARK_VALUES_FIELD] = normalizeDarkValues(source[DARK_VALUES_FIELD]);
|
|
381
|
+
config[PRESETS_FIELD] = normalizePresets(source[PRESETS_FIELD]);
|
|
382
|
+
config[ACTIVE_PRESET_FIELD] = sanitize(source[ACTIVE_PRESET_FIELD]).slice(0, MAX_PRESET_NAME);
|
|
163
383
|
return config;
|
|
164
384
|
}
|
|
165
385
|
|
|
386
|
+
/** Coerce a settings value to a strict boolean; anything unusable is false. */
|
|
387
|
+
function toBool(value) {
|
|
388
|
+
return value === true || value === 1 || value === "1" || value === "true";
|
|
389
|
+
}
|
|
390
|
+
|
|
166
391
|
/**
|
|
167
392
|
* Clamp one size offset to the allowed range, with 0 for anything unusable.
|
|
168
393
|
* @param {unknown} value - candidate offset in px.
|
|
@@ -187,6 +412,109 @@ function clampWeight(value) {
|
|
|
187
412
|
return Math.min(WEIGHT_MAX, Math.max(WEIGHT_MIN, weight));
|
|
188
413
|
}
|
|
189
414
|
|
|
415
|
+
/**
|
|
416
|
+
* Clamp one line-height ratio to the allowed percent range.
|
|
417
|
+
* @param {unknown} value - candidate ratio in percent.
|
|
418
|
+
* @returns {number} the integer ratio (100 when unusable).
|
|
419
|
+
*/
|
|
420
|
+
function clampRatio(value) {
|
|
421
|
+
var ratio = Math.round(Number(value));
|
|
422
|
+
if (!isFinite(ratio)) return LINE_HEIGHT_MIN;
|
|
423
|
+
return Math.min(LINE_HEIGHT_MAX, Math.max(LINE_HEIGHT_MIN, ratio));
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Clamp one code line-height offset to the allowed px range.
|
|
428
|
+
* @param {unknown} value - candidate offset in px.
|
|
429
|
+
* @returns {number} the integer offset (0 when unusable).
|
|
430
|
+
*/
|
|
431
|
+
function clampLineOffset(value) {
|
|
432
|
+
var offset = Math.round(Number(value));
|
|
433
|
+
if (!isFinite(offset) || offset === 0) return 0;
|
|
434
|
+
return Math.min(CODE_LINE_HEIGHT_MAX, Math.max(CODE_LINE_HEIGHT_MIN, offset));
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Clamp one ligature mode to the three known values.
|
|
439
|
+
* @param {unknown} value - candidate mode.
|
|
440
|
+
* @returns {number} 0, 1 or 2.
|
|
441
|
+
*/
|
|
442
|
+
function clampLigatures(value) {
|
|
443
|
+
var mode = Math.round(Number(value));
|
|
444
|
+
if (!isFinite(mode) || mode <= 0) return LIGATURES_DEFAULT;
|
|
445
|
+
return mode >= LIGATURES_OFF ? LIGATURES_OFF : LIGATURES_ON;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Validate and normalize one sparse axis-value map (dark overrides, presets).
|
|
450
|
+
* Only known axis fields survive, each clamped.
|
|
451
|
+
* @param {unknown} values - candidate map.
|
|
452
|
+
* @returns {Record<string, string|number|boolean>} the safe subset.
|
|
453
|
+
*/
|
|
454
|
+
function normalizeValueSet(values) {
|
|
455
|
+
var out = {};
|
|
456
|
+
if (values === null || typeof values !== "object" || Array.isArray(values)) return out;
|
|
457
|
+
for (var index = 0; index < VALUE_FIELDS.length; index += 1) {
|
|
458
|
+
var field = VALUE_FIELDS[index];
|
|
459
|
+
if (!Object.prototype.hasOwnProperty.call(values, field)) continue;
|
|
460
|
+
out[field] = normalizeField(field, values[field]);
|
|
461
|
+
}
|
|
462
|
+
return out;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Parse and validate the durable `darkValues` JSON string.
|
|
467
|
+
* @param {unknown} value - candidate JSON text or object.
|
|
468
|
+
* @returns {Record<string, string|number|boolean>} the sparse override map.
|
|
469
|
+
*/
|
|
470
|
+
function normalizeDarkValues(value) {
|
|
471
|
+
if (typeof value === "string") {
|
|
472
|
+
if (value.trim() === "") return {};
|
|
473
|
+
try {
|
|
474
|
+
value = JSON.parse(value);
|
|
475
|
+
} catch (error) {
|
|
476
|
+
return {};
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
return normalizeValueSet(value);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Parse and validate the durable `presets` JSON string.
|
|
484
|
+
* @param {unknown} value - candidate JSON text or array.
|
|
485
|
+
* @returns {{name: string, values: object, savedAt: number}[]}
|
|
486
|
+
*/
|
|
487
|
+
function normalizePresets(value) {
|
|
488
|
+
var list = value;
|
|
489
|
+
if (typeof value === "string") {
|
|
490
|
+
if (value.trim() === "") return [];
|
|
491
|
+
try {
|
|
492
|
+
list = JSON.parse(value);
|
|
493
|
+
} catch (error) {
|
|
494
|
+
return [];
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
if (!Array.isArray(list)) return [];
|
|
498
|
+
var out = [];
|
|
499
|
+
for (var index = 0; index < list.length && out.length < MAX_PRESETS; index += 1) {
|
|
500
|
+
var entry = list[index];
|
|
501
|
+
if (entry === null || typeof entry !== "object") continue;
|
|
502
|
+
var name = sanitize(entry.name).slice(0, MAX_PRESET_NAME);
|
|
503
|
+
if (name === "") continue;
|
|
504
|
+
var stamp = Math.round(Number(entry.savedAt));
|
|
505
|
+
out.push({
|
|
506
|
+
name: name,
|
|
507
|
+
values: normalizeValueSet(entry.values),
|
|
508
|
+
savedAt: isFinite(stamp) && stamp > 0 ? stamp : 0,
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
return out;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/* ------------------------------------------------------------------ *
|
|
515
|
+
* stacks
|
|
516
|
+
* ------------------------------------------------------------------ */
|
|
517
|
+
|
|
190
518
|
/**
|
|
191
519
|
* Format a family list as a CSS font-family value.
|
|
192
520
|
* @param {readonly string[]} families - family names in precedence order.
|
|
@@ -360,6 +688,10 @@ function removeStackEntry(families, family) {
|
|
|
360
688
|
return next;
|
|
361
689
|
}
|
|
362
690
|
|
|
691
|
+
/* ------------------------------------------------------------------ *
|
|
692
|
+
* scaling helpers
|
|
693
|
+
* ------------------------------------------------------------------ */
|
|
694
|
+
|
|
363
695
|
/**
|
|
364
696
|
* Compute the uniform scale a pixel offset produces over DSH's 16px base.
|
|
365
697
|
*
|
|
@@ -380,152 +712,16 @@ function scaleFor(sizeOffset, base) {
|
|
|
380
712
|
}
|
|
381
713
|
|
|
382
714
|
/**
|
|
383
|
-
*
|
|
384
|
-
* @param {
|
|
385
|
-
* @
|
|
386
|
-
|
|
387
|
-
function isDormant(config) {
|
|
388
|
-
return (
|
|
389
|
-
config[SANS_FIELD] === "" &&
|
|
390
|
-
config[MONO_FIELD] === "" &&
|
|
391
|
-
config[SIZE_FIELD] === 0 &&
|
|
392
|
-
config[CODE_SIZE_FIELD] === 0 &&
|
|
393
|
-
config[WEIGHT_FIELD] === WEIGHT_UNSET &&
|
|
394
|
-
config[CODE_WEIGHT_FIELD] === WEIGHT_UNSET
|
|
395
|
-
);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Build the stylesheet one configuration applies.
|
|
400
|
-
*
|
|
401
|
-
* Families are declared at their SOURCE: DSH's design tokens chain to two
|
|
402
|
-
* variables (`--dsw-font-family` for every sans token, `--ds-font-family-code`
|
|
403
|
-
* for every code token — verified against the shipped theme), so overriding
|
|
404
|
-
* those variables is what reaches the conversation markdown and the sidebar,
|
|
405
|
-
* whose elements declare `font-family: var(--dsw-font-family)` themselves and
|
|
406
|
-
* would never inherit a plain `body` rule. The explicit `body` / `pre,code`
|
|
407
|
-
* rules stay as a second path for elements that hardcode a family.
|
|
408
|
-
*
|
|
409
|
-
* The size offsets rewrite DSH's own design tokens rather than every element:
|
|
410
|
-
* a token whose name ends in `-font-size` or `-line-height` is re-declared as
|
|
411
|
-
* itself multiplied by one scale factor. `baseTokens` supplies the untouched
|
|
412
|
-
* values (read from the live document, falling back to the embedded map), so
|
|
413
|
-
* the ratio composes with DSH's own font-size slider instead of replacing it.
|
|
414
|
-
*
|
|
415
|
-
* Body and code are two independent axes. Body sizes hang off the content-size
|
|
416
|
-
* chain (`--dsh-content-font-size` and the `--dsw-font-*` steps), while every
|
|
417
|
-
* markdown code token is a bare literal (`--dsw-font-markdown-code-block:
|
|
418
|
-
* 11px/19px …`) that the content chain never touches — so the code axis is the
|
|
419
|
-
* only thing that moves it, and the body axis deliberately leaves those tokens
|
|
420
|
-
* alone. Code sizing is consumed through the `font` SHORTHAND tokens (that is
|
|
421
|
-
* what the shipped stylesheets use), which is why those are re-declared too,
|
|
422
|
-
* not just their `-font-size` / `-line-height` parts.
|
|
423
|
-
*
|
|
424
|
-
* Weight has no token chain to ride: no shipped rule reads a `-font-weight`
|
|
425
|
-
* token (measured — zero `font-weight: var(--dsw-font-…)` in rc.2), the theme
|
|
426
|
-
* writes literal weights on its own class rules, and that is exactly why the
|
|
427
|
-
* body axis has to be a blanket `!important` rule. The code axis is therefore a
|
|
428
|
-
* selector-scoped `!important` rule placed after it, which wins on specificity
|
|
429
|
-
* (`[class*=…]`) or on source order (`pre, …` ties with `body *`).
|
|
430
|
-
*
|
|
431
|
-
* @param {{sans: string, mono: string, sizeOffset: number, sizeOffsetCode: number, weight: number, weightCode: number}} config - normalized config.
|
|
432
|
-
* @param {Record<string, string>} [baseTokens] - token name to untouched value.
|
|
433
|
-
* @returns {string} declarations for one `<style>` element ("" when dormant).
|
|
715
|
+
* Round to a fixed number of decimals so generated CSS stays readable.
|
|
716
|
+
* @param {number} value - the number.
|
|
717
|
+
* @param {number} digits - decimals to keep.
|
|
718
|
+
* @returns {number} the rounded number.
|
|
434
719
|
*/
|
|
435
|
-
function
|
|
436
|
-
var
|
|
437
|
-
|
|
438
|
-
var mono = formatStack(parseStack(normalized[MONO_FIELD]));
|
|
439
|
-
var offset = normalized[SIZE_FIELD];
|
|
440
|
-
var codeOffset = normalized[CODE_SIZE_FIELD];
|
|
441
|
-
var weight = normalized[WEIGHT_FIELD];
|
|
442
|
-
var codeWeight = normalized[CODE_WEIGHT_FIELD];
|
|
443
|
-
if (isDormant(normalized)) return "";
|
|
444
|
-
var declarations = [];
|
|
445
|
-
|
|
446
|
-
if (sans !== "") {
|
|
447
|
-
declarations.push(":root,body{--dsw-font-family:" + sans + " !important}");
|
|
448
|
-
declarations.push("body{font-family:" + sans + " !important}");
|
|
449
|
-
}
|
|
450
|
-
if (mono !== "") {
|
|
451
|
-
// The theme's code tokens chain to `--ds-font-family-code`; the other name
|
|
452
|
-
// is what dsh-ui-font historically wrote and costs nothing to cover.
|
|
453
|
-
declarations.push(
|
|
454
|
-
":root,body{--dsw-font-mono:" + mono + " !important;--ds-font-family-code:" + mono + " !important}"
|
|
455
|
-
);
|
|
456
|
-
// Written after the body rule: equal specificity on a code element means
|
|
457
|
-
// the later declaration wins, so code keeps its own family inside the UI.
|
|
458
|
-
declarations.push(
|
|
459
|
-
"pre,code,kbd,samp,var,tt,textarea,.cm-editor .cm-content{font-family:" +
|
|
460
|
-
mono +
|
|
461
|
-
" !important}"
|
|
462
|
-
);
|
|
463
|
-
}
|
|
464
|
-
if (offset !== 0) {
|
|
465
|
-
var scaled = scaleTokens(bodyTokenNames(baseTokens), baseTokens, round(scaleFor(offset), 6));
|
|
466
|
-
if (scaled.length > 0) {
|
|
467
|
-
declarations.push(bodyAndDescendants(scaled.join(";")));
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
if (codeOffset !== 0) {
|
|
471
|
-
var scaledCode = scaleCodeTokens(baseTokens, round(scaleFor(codeOffset), 6));
|
|
472
|
-
if (scaledCode.length > 0) {
|
|
473
|
-
declarations.push(bodyAndDescendants(scaledCode.join(";")));
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
if (weight !== WEIGHT_UNSET) {
|
|
477
|
-
// Written as the user chose it: a variable font honors every integer, and
|
|
478
|
-
// a static one rounds to its own nearest step by itself.
|
|
479
|
-
declarations.push(bodyAndDescendants("font-weight:" + weight + " !important"));
|
|
480
|
-
}
|
|
481
|
-
if (codeWeight !== WEIGHT_UNSET) {
|
|
482
|
-
declarations.push(CODE_SELECTOR + "{font-weight:" + codeWeight + " !important}");
|
|
483
|
-
} else if (weight !== WEIGHT_UNSET) {
|
|
484
|
-
// The body axis is a blanket `body, body *` rule, so code would inherit the
|
|
485
|
-
// body weight unless it is explicitly taken back out. `normal` is what DSH
|
|
486
|
-
// itself computes there (the code `font` shorthands carry no weight), so an
|
|
487
|
-
// unset code weight means "code stays exactly as DSH shipped it".
|
|
488
|
-
declarations.push(CODE_SELECTOR + "{font-weight:normal !important}");
|
|
489
|
-
}
|
|
490
|
-
return declarations.join("\n");
|
|
720
|
+
function round(value, digits) {
|
|
721
|
+
var factor = Math.pow(10, digits);
|
|
722
|
+
return Math.round(value * factor) / factor;
|
|
491
723
|
}
|
|
492
724
|
|
|
493
|
-
/**
|
|
494
|
-
* What counts as code text for the weight axis.
|
|
495
|
-
*
|
|
496
|
-
* There is no token to hook here (see `buildFontCss`), so the code axis has to
|
|
497
|
-
* name the elements. Two layers, both measured against rc.2:
|
|
498
|
-
*
|
|
499
|
-
* 1. The tags DSH's own stylesheets size with a code token: markdown `pre` /
|
|
500
|
-
* inline `code`, the tool card's `:where(pre)` block, form controls, and the
|
|
501
|
-
* CodeMirror editor. Their descendants are listed too, because the blanket
|
|
502
|
-
* body rule matches EVERY element — a `<span>` inside a highlighted block
|
|
503
|
-
* would otherwise be pulled back to the body weight.
|
|
504
|
-
* 2. Containers that only a class name identifies: the terminal and tool-code
|
|
505
|
-
* bodies are plain `div`s (`…_terminal`, `…_codeBody`, `md-code-block`).
|
|
506
|
-
*
|
|
507
|
-
* The `i` flag keeps a casing change in a future DSH from silently dropping the
|
|
508
|
-
* rule, and an unmatched token/class simply means that surface follows the body
|
|
509
|
-
* axis — the same degradation as an unknown token name on the size axes.
|
|
510
|
-
*/
|
|
511
|
-
var CODE_SELECTOR = [
|
|
512
|
-
"pre",
|
|
513
|
-
"code",
|
|
514
|
-
"kbd",
|
|
515
|
-
"samp",
|
|
516
|
-
"var",
|
|
517
|
-
"tt",
|
|
518
|
-
"textarea",
|
|
519
|
-
".cm-editor",
|
|
520
|
-
".dfp-previewCode",
|
|
521
|
-
'[class*="code" i]',
|
|
522
|
-
'[class*="terminal" i]',
|
|
523
|
-
]
|
|
524
|
-
.map(function (selector) {
|
|
525
|
-
return selector + "," + selector + " *";
|
|
526
|
-
})
|
|
527
|
-
.join(",");
|
|
528
|
-
|
|
529
725
|
/**
|
|
530
726
|
* Values a ratio may multiply: a number with a unit, a bare number, or an
|
|
531
727
|
* expression. A keyword (`unset`, `inherit`) or an unrecognized shape is left
|
|
@@ -543,17 +739,17 @@ function isScalableValue(value) {
|
|
|
543
739
|
}
|
|
544
740
|
|
|
545
741
|
/**
|
|
546
|
-
* Scale one set of tokens by one ratio.
|
|
742
|
+
* Scale one set of SIZE tokens by one ratio.
|
|
547
743
|
*
|
|
548
744
|
* A base that itself references another token via var() derives from it:
|
|
549
745
|
* scaling the var target already scales this one, so re-scaling here would
|
|
550
746
|
* compound (markdown-base = var(--dsh-content-font-size) would take the ratio
|
|
551
747
|
* twice). DSH's chain does the work instead.
|
|
552
748
|
*
|
|
553
|
-
* `!important` is required: the theme writes `--dsh-content-font-size` INLINE
|
|
554
|
-
* body, and an inline declaration outranks a plain stylesheet one —
|
|
555
|
-
* flag body itself would keep DSH's own size while every
|
|
556
|
-
* splitting the page in two.
|
|
749
|
+
* `!important` is required: the theme writes `--dsh-content-font-size` INLINE
|
|
750
|
+
* on body, and an inline declaration outranks a plain stylesheet one —
|
|
751
|
+
* without the flag body itself would keep DSH's own size while every
|
|
752
|
+
* descendant scales, splitting the page in two.
|
|
557
753
|
*
|
|
558
754
|
* @param {string[]} names - token names to re-declare.
|
|
559
755
|
* @param {Record<string, string>} baseTokens - token name to untouched value.
|
|
@@ -574,66 +770,143 @@ function scaleTokens(names, baseTokens, scale) {
|
|
|
574
770
|
}
|
|
575
771
|
|
|
576
772
|
/**
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
* Two shapes exist and both must be covered, because the shipped stylesheets
|
|
580
|
-
* consume the shorthand (`font: var(--dsw-font-markdown-code-block-small)`)
|
|
581
|
-
* while the split tokens exist for anything that asks for a single part:
|
|
582
|
-
* `11px/19px <family>` and a bare `11px`.
|
|
773
|
+
* Scale one set of LINE-HEIGHT tokens by one factor.
|
|
583
774
|
*
|
|
775
|
+
* Unlike sizes, a line height never chains through another line height in
|
|
776
|
+
* DSH's theme (heights are literals or `calc(Npx + size-delta)`), so var()
|
|
777
|
+
* values are wrapped rather than skipped — the wrap keeps the var chain
|
|
778
|
+
* resolving at use time and cannot compound.
|
|
779
|
+
* @param {string[]} names - token names to re-declare.
|
|
584
780
|
* @param {Record<string, string>} baseTokens - token name to untouched value.
|
|
585
|
-
* @param {number}
|
|
781
|
+
* @param {number} factor - the ratio to apply.
|
|
586
782
|
* @returns {string[]} declarations.
|
|
587
783
|
*/
|
|
588
|
-
function
|
|
589
|
-
var names = codeTokenNames(baseTokens);
|
|
784
|
+
function scaleLineTokens(names, baseTokens, factor) {
|
|
590
785
|
var out = [];
|
|
591
786
|
for (var index = 0; index < names.length; index += 1) {
|
|
592
787
|
var name = names[index];
|
|
593
788
|
var base = baseTokens[name];
|
|
594
789
|
if (typeof base !== "string" || base === "") continue;
|
|
595
|
-
var shorthand = scaleFontShorthand(base, scale);
|
|
596
|
-
if (shorthand !== null) {
|
|
597
|
-
out.push(name + ":" + shorthand + " !important");
|
|
598
|
-
continue;
|
|
599
|
-
}
|
|
600
|
-
// A part token that derives from another token follows that token's own
|
|
601
|
-
// scaling; re-declaring it here would compound the ratio.
|
|
602
|
-
if (base.indexOf("var(") !== -1) continue;
|
|
603
790
|
if (!isScalableValue(base)) continue;
|
|
604
|
-
out.push(name + ":calc((" + base + ") * " +
|
|
791
|
+
out.push(name + ":calc((" + base + ") * " + factor + ") !important");
|
|
605
792
|
}
|
|
606
793
|
return out;
|
|
607
794
|
}
|
|
608
795
|
|
|
609
796
|
/**
|
|
610
|
-
*
|
|
611
|
-
*
|
|
612
|
-
* @param {string}
|
|
613
|
-
* @param {number}
|
|
614
|
-
* @returns {string
|
|
797
|
+
* Shift one set of tokens by an additive px amount.
|
|
798
|
+
* @param {string[]} names - token names to re-declare.
|
|
799
|
+
* @param {Record<string, string>} baseTokens - token name to untouched value.
|
|
800
|
+
* @param {number} offset - the px amount to add.
|
|
801
|
+
* @returns {string[]} declarations.
|
|
615
802
|
*/
|
|
616
|
-
function
|
|
617
|
-
var
|
|
803
|
+
function shiftTokens(names, baseTokens, offset) {
|
|
804
|
+
var out = [];
|
|
805
|
+
for (var index = 0; index < names.length; index += 1) {
|
|
806
|
+
var name = names[index];
|
|
807
|
+
var base = baseTokens[name];
|
|
808
|
+
if (typeof base !== "string" || base === "") continue;
|
|
809
|
+
if (!isScalableValue(base)) continue;
|
|
810
|
+
out.push(name + ":calc((" + base + ") + " + offset + "px) !important");
|
|
811
|
+
}
|
|
812
|
+
return out;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/* ------------------------------------------------------------------ *
|
|
816
|
+
* `font` shorthand parsing
|
|
817
|
+
* ------------------------------------------------------------------ */
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* The family reference every DSH `font` shorthand ends with. Markdown tokens
|
|
821
|
+
* chain to the sans variable, code tokens to the code variable.
|
|
822
|
+
*/
|
|
823
|
+
var FAMILY_REFS = ["var(--dsw-font-family)", "var(--ds-font-family-code)"];
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* Parse one `font` shorthand into its parts.
|
|
827
|
+
*
|
|
828
|
+
* DSH's shorthands come in four shapes, all ending in a family var():
|
|
829
|
+
* `11px/19px var(--ds-font-family-code)` (code),
|
|
830
|
+
* `var(--dsh-content-font-size,14px) / calc(24px + var(--dsh-content-font-delta)) var(--dsw-font-family)` (base),
|
|
831
|
+
* `700 calc(21px + var(...)) / calc(30px + var(...)) var(--dsw-font-family)` (h1),
|
|
832
|
+
* `italic 600 var(...) / calc(...) var(--dsw-font-family)` (strong-italic).
|
|
833
|
+
*
|
|
834
|
+
* Because the size expression may itself contain `var(...)`, the split keys
|
|
835
|
+
* off the family reference (found from the right) and the `/`, never off
|
|
836
|
+
* whitespace inside `calc()`.
|
|
837
|
+
* @param {string} value - a `font` shorthand value.
|
|
838
|
+
* @returns {{lead: string, size: string, height: string, family: string}|null} the parts, or null when the shape differs.
|
|
839
|
+
*/
|
|
840
|
+
function parseShorthand(value) {
|
|
841
|
+
if (typeof value !== "string") return null;
|
|
842
|
+
var familyAt = -1;
|
|
843
|
+
for (var index = 0; index < FAMILY_REFS.length; index += 1) {
|
|
844
|
+
var at = value.lastIndexOf(FAMILY_REFS[index]);
|
|
845
|
+
if (at > familyAt) familyAt = at;
|
|
846
|
+
}
|
|
847
|
+
if (familyAt <= 0) return null;
|
|
848
|
+
var family = value.slice(familyAt).trim();
|
|
849
|
+
if (family === "") return null;
|
|
850
|
+
var head = value.slice(0, familyAt).trim();
|
|
851
|
+
var slash = head.lastIndexOf("/");
|
|
618
852
|
if (slash <= 0) return null;
|
|
619
|
-
var
|
|
620
|
-
var
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
var
|
|
624
|
-
var
|
|
625
|
-
if (size === "" || height === "" || family === "") return null;
|
|
853
|
+
var sizeChunk = head.slice(0, slash).trim();
|
|
854
|
+
var height = head.slice(slash + 1).trim();
|
|
855
|
+
if (sizeChunk === "" || height === "") return null;
|
|
856
|
+
var chunks = splitTopLevel(sizeChunk);
|
|
857
|
+
var size = chunks.pop();
|
|
858
|
+
var lead = chunks.join(" ");
|
|
626
859
|
if (!isScalableValue(size) || !isScalableValue(height)) return null;
|
|
627
|
-
return
|
|
628
|
-
|
|
629
|
-
|
|
860
|
+
return { lead: lead, size: size, height: height, family: family };
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
/**
|
|
864
|
+
* Split a value on whitespace that sits OUTSIDE any parentheses, so a leading
|
|
865
|
+
* `700 calc(21px + var(…))` yields `["700", "calc(21px + var(...))"]`.
|
|
866
|
+
* @param {string} value - the chunk to split.
|
|
867
|
+
* @returns {string[]} the top-level chunks.
|
|
868
|
+
*/
|
|
869
|
+
function splitTopLevel(value) {
|
|
870
|
+
var out = [];
|
|
871
|
+
var current = "";
|
|
872
|
+
var depth = 0;
|
|
873
|
+
for (var index = 0; index < value.length; index += 1) {
|
|
874
|
+
var char = value.charAt(index);
|
|
875
|
+
if (char === "(") depth += 1;
|
|
876
|
+
else if (char === ")") depth -= 1;
|
|
877
|
+
if (depth === 0 && /\s/.test(char)) {
|
|
878
|
+
if (current !== "") {
|
|
879
|
+
out.push(current);
|
|
880
|
+
current = "";
|
|
881
|
+
}
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
current += char;
|
|
885
|
+
}
|
|
886
|
+
if (current !== "") out.push(current);
|
|
887
|
+
return out;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Rebuild one `font` shorthand from parsed parts.
|
|
892
|
+
* @param {{lead: string, size: string, height: string, family: string}} parts - parsed parts.
|
|
893
|
+
* @returns {string} the shorthand value (without `!important`).
|
|
894
|
+
*/
|
|
895
|
+
function rebuildShorthand(parts) {
|
|
896
|
+
var out = "";
|
|
897
|
+
if (parts.lead !== "") out += parts.lead + " ";
|
|
898
|
+
return out + parts.size + " / " + parts.height + " " + parts.family;
|
|
630
899
|
}
|
|
631
900
|
|
|
901
|
+
/* ------------------------------------------------------------------ *
|
|
902
|
+
* token classification
|
|
903
|
+
* ------------------------------------------------------------------ */
|
|
904
|
+
|
|
632
905
|
/**
|
|
633
|
-
* Match DSH's typography tokens: the design system's sizes plus the
|
|
634
|
-
* size the theme plugin writes on `body` (whose secondary variant
|
|
635
|
-
* suffix of its own). Line heights scale with sizes so a token's
|
|
636
|
-
* never disagrees with its parts.
|
|
906
|
+
* Match DSH's typography PART tokens: the design system's sizes plus the
|
|
907
|
+
* content size the theme plugin writes on `body` (whose secondary variant
|
|
908
|
+
* carries a suffix of its own). Line heights scale with sizes so a token's
|
|
909
|
+
* shorthand never disagrees with its parts.
|
|
637
910
|
*
|
|
638
911
|
* Deliberately a shape test rather than an enumeration: DSH generates these
|
|
639
912
|
* tokens at runtime, so whatever a future release names them, a token that
|
|
@@ -641,6 +914,26 @@ function scaleFontShorthand(value, scale) {
|
|
|
641
914
|
*/
|
|
642
915
|
var TOKEN_PATTERN = /^--(?:dsw-font-[a-z0-9-]*|dsh-content-font)-(?:font-size|line-height)(?:-secondary)?$|^--dsh-content-font-(?:size|line-height)(?:-secondary)?$/;
|
|
643
916
|
|
|
917
|
+
/**
|
|
918
|
+
* The content-size DELTA tokens the theme derives on `body`; the dialog size
|
|
919
|
+
* offset shifts these additively, which is what moves every delta-derived
|
|
920
|
+
* markdown size by exactly the offset.
|
|
921
|
+
*/
|
|
922
|
+
var DELTA_PATTERN = /^--dsh-content-font-delta(?:-secondary)?$/;
|
|
923
|
+
|
|
924
|
+
/** The whole official content-size chain (size / line height / delta). */
|
|
925
|
+
var CONTENT_PATTERN = /^--dsh-content-font-(?:size|line-height|delta)(?:-secondary)?$/;
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* The PART-token suffixes DSH appends for single-axis consumers.
|
|
929
|
+
*/
|
|
930
|
+
var PART_SUFFIXES = ["-font-size", "-line-height", "-font-family", "-font-weight", "-font-style"];
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* The bare family variables, which are NOT `font` shorthands.
|
|
934
|
+
*/
|
|
935
|
+
var FAMILY_VARS = { "--dsw-font-family": true, "--dsw-font-mono": true, "--ds-font-family-code": true };
|
|
936
|
+
|
|
644
937
|
/**
|
|
645
938
|
* A `body, body *` selector list, kept in one place because every global
|
|
646
939
|
* declaration needs the same reach (DSH writes some tokens on descendants).
|
|
@@ -652,7 +945,23 @@ function bodyAndDescendants(declarations) {
|
|
|
652
945
|
}
|
|
653
946
|
|
|
654
947
|
/**
|
|
655
|
-
* Whether one
|
|
948
|
+
* Whether one name belongs to the official CONTENT-size chain the conversation
|
|
949
|
+
* owns: `--dsh-content-font-size` / `-line-height` (the official "对话字号"
|
|
950
|
+
* setting writes the former) and the delta tokens derived from it.
|
|
951
|
+
*
|
|
952
|
+
* The interface axis must never scale these. Doing so was the real reason an
|
|
953
|
+
* interface size change moved the conversation: the markdown ladder consumes
|
|
954
|
+
* this chain directly, so scaling it is a conversation edit no matter which
|
|
955
|
+
* slider caused it.
|
|
956
|
+
* @param {string} name - custom property name including the leading dashes.
|
|
957
|
+
* @returns {boolean}
|
|
958
|
+
*/
|
|
959
|
+
function isContentToken(name) {
|
|
960
|
+
return typeof name === "string" && CONTENT_PATTERN.test(name);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* Whether one custom-property name is a PART token this plugin scales.
|
|
656
965
|
* @param {string} name - custom property name including the leading dashes.
|
|
657
966
|
* @returns {boolean} true when the token carries a size or a line height.
|
|
658
967
|
*/
|
|
@@ -661,13 +970,21 @@ function isFontToken(name) {
|
|
|
661
970
|
}
|
|
662
971
|
|
|
663
972
|
/**
|
|
664
|
-
*
|
|
973
|
+
* Whether one name is a content-size delta token.
|
|
974
|
+
* @param {string} name - custom property name including the leading dashes.
|
|
975
|
+
* @returns {boolean}
|
|
976
|
+
*/
|
|
977
|
+
function isDeltaToken(name) {
|
|
978
|
+
return typeof name === "string" && DELTA_PATTERN.test(name);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* Whether one name is a markdown CODE token: its own sizing axis.
|
|
665
983
|
*
|
|
666
984
|
* The theme declares these as literals the content-size chain never reaches
|
|
667
985
|
* (`--dsw-font-markdown-code:12px/19px …`, `-code-block:11px/19px …`,
|
|
668
986
|
* `-code-block-small:11px/16px …`), and the shipped stylesheets consume them
|
|
669
|
-
* through the `font` shorthand.
|
|
670
|
-
* to the code offset and to nothing else.
|
|
987
|
+
* through the `font` shorthand.
|
|
671
988
|
* @param {string} name - custom property name including the leading dashes.
|
|
672
989
|
* @returns {boolean} true when the token sizes code.
|
|
673
990
|
*/
|
|
@@ -676,23 +993,63 @@ function isCodeToken(name) {
|
|
|
676
993
|
}
|
|
677
994
|
|
|
678
995
|
/**
|
|
679
|
-
* Whether a token is
|
|
996
|
+
* Whether one name is a markdown (dialog) token that is NOT code: the token
|
|
997
|
+
* family the dialog axes own.
|
|
998
|
+
* @param {string} name - custom property name including the leading dashes.
|
|
999
|
+
* @returns {boolean}
|
|
1000
|
+
*/
|
|
1001
|
+
function isMarkdownToken(name) {
|
|
1002
|
+
return typeof name === "string" && name.indexOf("--dsw-font-markdown-") === 0 && !isCodeToken(name);
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* Whether one NAME looks like a `font` shorthand token (a bare
|
|
1007
|
+
* `--dsw-font-…` name that is not a PART token or a family variable).
|
|
1008
|
+
* @param {string} name - custom property name including the leading dashes.
|
|
1009
|
+
* @returns {boolean}
|
|
1010
|
+
*/
|
|
1011
|
+
function isShorthandName(name) {
|
|
1012
|
+
if (typeof name !== "string" || name.indexOf("--dsw-font-") !== 0) return false;
|
|
1013
|
+
if (FAMILY_VARS[name] === true) return false;
|
|
1014
|
+
for (var index = 0; index < PART_SUFFIXES.length; index += 1) {
|
|
1015
|
+
var suffix = PART_SUFFIXES[index];
|
|
1016
|
+
if (name.length > suffix.length && name.slice(-suffix.length) === suffix) return false;
|
|
1017
|
+
}
|
|
1018
|
+
return true;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* Whether one token (name + value) is a `font` shorthand this plugin may
|
|
1023
|
+
* rewrite: a bare `--dsw-font-…` name whose value parses as a shorthand.
|
|
1024
|
+
* @param {string} name - custom property name.
|
|
1025
|
+
* @param {string} value - the token's untouched value.
|
|
1026
|
+
* @returns {boolean}
|
|
1027
|
+
*/
|
|
1028
|
+
function isShorthandToken(name, value) {
|
|
1029
|
+
return isShorthandName(name) && parseShorthand(value) !== null;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
/**
|
|
1033
|
+
* Whether a token is one this plugin reads and re-declares at all.
|
|
680
1034
|
* @param {string} name - custom property name including the leading dashes.
|
|
681
|
-
* @returns {boolean} true for
|
|
1035
|
+
* @returns {boolean} true for part tokens, code tokens, shorthand names and
|
|
1036
|
+
* the content-size deltas.
|
|
682
1037
|
*/
|
|
683
1038
|
function isScaledToken(name) {
|
|
684
|
-
return isFontToken(name) || isCodeToken(name);
|
|
1039
|
+
return isFontToken(name) || isCodeToken(name) || isShorthandName(name) || isDeltaToken(name);
|
|
685
1040
|
}
|
|
686
1041
|
|
|
687
1042
|
/**
|
|
688
|
-
* Ordered token names present in a base map, sizes before line heights
|
|
689
|
-
* reader of the stylesheet sees each size next to its height.
|
|
1043
|
+
* Ordered PART-token names present in a base map, sizes before line heights
|
|
1044
|
+
* so a reader of the stylesheet sees each size next to its height.
|
|
690
1045
|
* @param {Record<string, string>} [baseTokens] - token name to value.
|
|
691
|
-
* @returns {string[]} the names
|
|
1046
|
+
* @returns {string[]} the names.
|
|
692
1047
|
*/
|
|
693
1048
|
function tokenNames(baseTokens) {
|
|
694
1049
|
if (baseTokens === null || typeof baseTokens !== "object") return [];
|
|
695
|
-
var names = Object.keys(baseTokens).filter(
|
|
1050
|
+
var names = Object.keys(baseTokens).filter(function (name) {
|
|
1051
|
+
return isFontToken(name) || isCodeToken(name) || isDeltaToken(name);
|
|
1052
|
+
});
|
|
696
1053
|
names.sort(function (left, right) {
|
|
697
1054
|
if (left.length !== right.length) return left.length - right.length;
|
|
698
1055
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
@@ -701,102 +1058,848 @@ function tokenNames(baseTokens) {
|
|
|
701
1058
|
}
|
|
702
1059
|
|
|
703
1060
|
/**
|
|
704
|
-
* The
|
|
705
|
-
*
|
|
1061
|
+
* The interface PART size tokens: everything scalable except the code and
|
|
1062
|
+
* markdown families and the delta tokens (which the dialog offset shifts
|
|
1063
|
+
* additively, never multiplicatively).
|
|
706
1064
|
* @param {Record<string, string>} [baseTokens] - token name to value.
|
|
707
|
-
* @returns {string[]} the names the
|
|
1065
|
+
* @returns {string[]} the names the interface offset re-declares.
|
|
708
1066
|
*/
|
|
709
1067
|
function bodyTokenNames(baseTokens) {
|
|
710
1068
|
return tokenNames(baseTokens).filter(function (name) {
|
|
711
|
-
return
|
|
1069
|
+
return (
|
|
1070
|
+
!isCodeToken(name) &&
|
|
1071
|
+
!isMarkdownToken(name) &&
|
|
1072
|
+
!isDeltaToken(name) &&
|
|
1073
|
+
!isContentToken(name)
|
|
1074
|
+
);
|
|
712
1075
|
});
|
|
713
1076
|
}
|
|
714
1077
|
|
|
715
1078
|
/**
|
|
716
|
-
* The
|
|
717
|
-
* `-line-height` parts, when the live stylesheets declare them.
|
|
1079
|
+
* The interface line-height PART tokens (non-code, non-markdown).
|
|
718
1080
|
* @param {Record<string, string>} [baseTokens] - token name to value.
|
|
719
|
-
* @returns {string[]}
|
|
1081
|
+
* @returns {string[]}
|
|
1082
|
+
*/
|
|
1083
|
+
function uiLineTokenNames(baseTokens) {
|
|
1084
|
+
return bodyTokenNames(baseTokens).filter(function (name) {
|
|
1085
|
+
return name.indexOf("-line-height") >= 0;
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
/**
|
|
1090
|
+
* The markdown (dialog) PART tokens: sizes and line heights of the markdown
|
|
1091
|
+
* family, excluding code.
|
|
1092
|
+
* @param {Record<string, string>} [baseTokens] - token name to value.
|
|
1093
|
+
* @returns {string[]}
|
|
1094
|
+
*/
|
|
1095
|
+
function markdownTokenNames(baseTokens) {
|
|
1096
|
+
return tokenNames(baseTokens).filter(isMarkdownToken);
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
/**
|
|
1100
|
+
* The markdown content-size DELTA tokens present in a base map.
|
|
1101
|
+
* @param {Record<string, string>} [baseTokens] - token name to value.
|
|
1102
|
+
* @returns {string[]}
|
|
1103
|
+
*/
|
|
1104
|
+
function deltaTokenNames(baseTokens) {
|
|
1105
|
+
if (baseTokens === null || typeof baseTokens !== "object") return [];
|
|
1106
|
+
return Object.keys(baseTokens).filter(isDeltaToken);
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
/**
|
|
1110
|
+
* The code PART tokens: the `font` shorthands' size/height parts, when the
|
|
1111
|
+
* live stylesheets declare them. The shorthands themselves are handled by
|
|
1112
|
+
* `codeShorthandTokens`, so they are excluded here to avoid double
|
|
1113
|
+
* declarations.
|
|
1114
|
+
* @param {Record<string, string>} [baseTokens] - token name to value.
|
|
1115
|
+
* @returns {string[]}
|
|
720
1116
|
*/
|
|
721
1117
|
function codeTokenNames(baseTokens) {
|
|
722
|
-
return tokenNames(baseTokens).filter(
|
|
1118
|
+
return tokenNames(baseTokens).filter(function (name) {
|
|
1119
|
+
return isCodeToken(name) && !isShorthandName(name);
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
/**
|
|
1124
|
+
* Every `font` shorthand token in a base map that parses, sorted by name
|
|
1125
|
+
* length (families before variants, mirroring the part-token order).
|
|
1126
|
+
* @param {Record<string, string>} [baseTokens] - token name to value.
|
|
1127
|
+
* @returns {{name: string, parts: object}[]}
|
|
1128
|
+
*/
|
|
1129
|
+
function shorthandTokens(baseTokens) {
|
|
1130
|
+
if (baseTokens === null || typeof baseTokens !== "object") return [];
|
|
1131
|
+
var out = [];
|
|
1132
|
+
var names = Object.keys(baseTokens).filter(isShorthandName);
|
|
1133
|
+
names.sort(function (left, right) {
|
|
1134
|
+
if (left.length !== right.length) return left.length - right.length;
|
|
1135
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
1136
|
+
});
|
|
1137
|
+
for (var index = 0; index < names.length; index += 1) {
|
|
1138
|
+
var parts = parseShorthand(baseTokens[names[index]]);
|
|
1139
|
+
if (parts !== null) out.push({ name: names[index], parts: parts });
|
|
1140
|
+
}
|
|
1141
|
+
return out;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* The markdown (dialog) `font` shorthand tokens, excluding code.
|
|
1146
|
+
* @param {Record<string, string>} [baseTokens] - token name to value.
|
|
1147
|
+
* @returns {{name: string, parts: object}[]}
|
|
1148
|
+
*/
|
|
1149
|
+
function markdownShorthandTokens(baseTokens) {
|
|
1150
|
+
return shorthandTokens(baseTokens).filter(function (entry) {
|
|
1151
|
+
return isMarkdownToken(entry.name);
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* The interface (non-markdown, non-code) `font` shorthand tokens.
|
|
1157
|
+
* @param {Record<string, string>} [baseTokens] - token name to value.
|
|
1158
|
+
* @returns {{name: string, parts: object}[]}
|
|
1159
|
+
*/
|
|
1160
|
+
function uiShorthandTokens(baseTokens) {
|
|
1161
|
+
return shorthandTokens(baseTokens).filter(function (entry) {
|
|
1162
|
+
return !isMarkdownToken(entry.name) && !isCodeToken(entry.name);
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
/**
|
|
1167
|
+
* The code `font` shorthand tokens.
|
|
1168
|
+
* @param {Record<string, string>} [baseTokens] - token name to value.
|
|
1169
|
+
* @returns {{name: string, parts: object}[]}
|
|
1170
|
+
*/
|
|
1171
|
+
function codeShorthandTokens(baseTokens) {
|
|
1172
|
+
return shorthandTokens(baseTokens).filter(function (entry) {
|
|
1173
|
+
return isCodeToken(entry.name);
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
/* ------------------------------------------------------------------ *
|
|
1178
|
+
* selectors
|
|
1179
|
+
* ------------------------------------------------------------------ */
|
|
1180
|
+
|
|
1181
|
+
/**
|
|
1182
|
+
* What counts as code text for the code axes.
|
|
1183
|
+
*
|
|
1184
|
+
* There is no token to hook here (no shipped rule reads a `-font-weight`
|
|
1185
|
+
* token — measured, zero `font-weight: var(--dsw-font-…)` in rc.2), so the
|
|
1186
|
+
* code axes have to name the elements. Two layers, both measured against
|
|
1187
|
+
* rc.2:
|
|
1188
|
+
*
|
|
1189
|
+
* 1. The tags DSH's own stylesheets size with a code token: markdown `pre` /
|
|
1190
|
+
* inline `code`, the tool card's `:where(pre)` block, form controls, and
|
|
1191
|
+
* CodeMirror-like editors. Their descendants are listed too, because the
|
|
1192
|
+
* blanket body rule matches EVERY element — a `<span>` inside a
|
|
1193
|
+
* highlighted block would otherwise be pulled back to the body weight.
|
|
1194
|
+
* 2. Containers that only a class name identifies: the terminal and tool-code
|
|
1195
|
+
* bodies are plain `div`s (`…_terminal`, `…_codeBody`, `md-code-block`).
|
|
1196
|
+
*
|
|
1197
|
+
* The `i` flag keeps a casing change in a future DSH from silently dropping
|
|
1198
|
+
* the rule, and an unmatched token/class simply means that surface follows
|
|
1199
|
+
* the interface axis — the same degradation as an unknown token name.
|
|
1200
|
+
*/
|
|
1201
|
+
var CODE_SELECTOR = [
|
|
1202
|
+
"pre",
|
|
1203
|
+
"code",
|
|
1204
|
+
"kbd",
|
|
1205
|
+
"samp",
|
|
1206
|
+
"var",
|
|
1207
|
+
"tt",
|
|
1208
|
+
"textarea",
|
|
1209
|
+
".cm-editor",
|
|
1210
|
+
".dfp-previewCode",
|
|
1211
|
+
'[class*="code" i]',
|
|
1212
|
+
'[class*="terminal" i]',
|
|
1213
|
+
]
|
|
1214
|
+
.map(function (selector) {
|
|
1215
|
+
return selector + "," + selector + " *";
|
|
1216
|
+
})
|
|
1217
|
+
.join(",");
|
|
1218
|
+
|
|
1219
|
+
/**
|
|
1220
|
+
* Everything a code surface must be excluded from a DIALOG-scoped rule:
|
|
1221
|
+
* the code elements themselves AND their descendants (a highlight `<span>`
|
|
1222
|
+
* inside a `<pre>` is not a `pre`, so the exclusion has to reach through
|
|
1223
|
+
* ancestry with complex `:not()` arguments — supported by the Chromium line
|
|
1224
|
+
* DSH targets).
|
|
1225
|
+
*/
|
|
1226
|
+
var CODE_EXCLUDES = [
|
|
1227
|
+
"pre",
|
|
1228
|
+
"pre *",
|
|
1229
|
+
"code",
|
|
1230
|
+
"code *",
|
|
1231
|
+
"kbd",
|
|
1232
|
+
"kbd *",
|
|
1233
|
+
"samp",
|
|
1234
|
+
"samp *",
|
|
1235
|
+
"var",
|
|
1236
|
+
"var *",
|
|
1237
|
+
"tt",
|
|
1238
|
+
"tt *",
|
|
1239
|
+
"textarea",
|
|
1240
|
+
"textarea *",
|
|
1241
|
+
'[class*="code" i]',
|
|
1242
|
+
'[class*="code" i] *',
|
|
1243
|
+
'[class*="terminal" i]',
|
|
1244
|
+
'[class*="terminal" i] *',
|
|
1245
|
+
]
|
|
1246
|
+
.map(function (selector) {
|
|
1247
|
+
return ":not(" + selector + ")";
|
|
1248
|
+
})
|
|
1249
|
+
.join("");
|
|
1250
|
+
|
|
1251
|
+
/**
|
|
1252
|
+
* The dialog surface: DSH renders the conversation markdown in a CSS-module
|
|
1253
|
+
* container whose class hashes per release (`_markdown_<hash>_…`). A
|
|
1254
|
+
* class-substring match degrades safely — no match means the dialog follows
|
|
1255
|
+
* the interface axis, the same behavior as an unknown token name.
|
|
1256
|
+
*/
|
|
1257
|
+
var MARKDOWN_SELECTOR =
|
|
1258
|
+
'[class*="_markdown_" i]' +
|
|
1259
|
+
CODE_EXCLUDES +
|
|
1260
|
+
',[class*="_markdown_" i] *' +
|
|
1261
|
+
CODE_EXCLUDES;
|
|
1262
|
+
|
|
1263
|
+
/** The dark-theme attribute DSH's ThemePresenter writes on body. */
|
|
1264
|
+
var DARK_ATTR = "body[data-ds-dark-theme]";
|
|
1265
|
+
|
|
1266
|
+
/**
|
|
1267
|
+
* Everything the INTERFACE weight rule must stay out of.
|
|
1268
|
+
*
|
|
1269
|
+
* A weight can only be expressed as a `body, body *` rule: DSH pins its labels
|
|
1270
|
+
* with literal weights on class rules (`…_label{font-weight:500}`,
|
|
1271
|
+
* `…_heading{font-weight:600}`) that nothing narrower reaches. That rule would
|
|
1272
|
+
* otherwise cover the conversation too, so the conversation markdown subtree is
|
|
1273
|
+
* excluded here — and with it every code surface, because the code axis owns
|
|
1274
|
+
* those and the two rules would otherwise fight over the same elements (the
|
|
1275
|
+
* `:not()` arguments raise this rule's specificity above a single class).
|
|
1276
|
+
*
|
|
1277
|
+
* `dfp-previewDialog` is the card's conversation preview: it carries the
|
|
1278
|
+
* conversation's own weight, so the interface rule must not flatten it. The
|
|
1279
|
+
* interface's own preview stays inside the rule, and `dfp-previewCode` is a
|
|
1280
|
+
* code surface like any other.
|
|
1281
|
+
*/
|
|
1282
|
+
var INTERFACE_EXCLUDES =
|
|
1283
|
+
CODE_EXCLUDES +
|
|
1284
|
+
":not(.cm-editor):not(.cm-editor *):not(.dfp-previewCode):not(.dfp-previewCode *)" +
|
|
1285
|
+
':not([class*="_markdown_" i]):not([class*="_markdown_" i] *)' +
|
|
1286
|
+
":not(.dfp-previewDialog):not(.dfp-previewDialog *)";
|
|
1287
|
+
|
|
1288
|
+
/**
|
|
1289
|
+
* Prefix every selector in a comma list, for the per-theme rules.
|
|
1290
|
+
* @param {string} selectorList - a comma-separated selector list.
|
|
1291
|
+
* @param {string} prefix - the prefix to prepend to each selector.
|
|
1292
|
+
* @returns {string} the prefixed list.
|
|
1293
|
+
*/
|
|
1294
|
+
function prefixSelector(selectorList, prefix) {
|
|
1295
|
+
var parts = selectorList.split(",");
|
|
1296
|
+
var out = [];
|
|
1297
|
+
for (var index = 0; index < parts.length; index += 1) {
|
|
1298
|
+
out.push(prefix + " " + parts[index]);
|
|
1299
|
+
}
|
|
1300
|
+
return out.join(",");
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
/* ------------------------------------------------------------------ *
|
|
1304
|
+
* per-theme resolution
|
|
1305
|
+
* ------------------------------------------------------------------ */
|
|
1306
|
+
|
|
1307
|
+
/**
|
|
1308
|
+
* Expand the FOLLOW semantics over one normalized configuration.
|
|
1309
|
+
*
|
|
1310
|
+
* The conversation owns every axis. Follow — the default — makes the interface
|
|
1311
|
+
* take the conversation's family and weight, keeping its own value only for an
|
|
1312
|
+
* axis the conversation leaves unset. Follow off leaves both of the interface's
|
|
1313
|
+
* axes standing on their own; the conversation is never touched either way,
|
|
1314
|
+
* because the interface's rules exclude the markdown subtree.
|
|
1315
|
+
*
|
|
1316
|
+
* The interface's size and line-height axes are retired and render nothing, so
|
|
1317
|
+
* nothing follows for them (see `buildAxisCss` for the measurement).
|
|
1318
|
+
*
|
|
1319
|
+
* @param {Record<string, unknown>} raw - a normalized configuration.
|
|
1320
|
+
* @returns {Record<string, unknown>} the set with the follow rule applied.
|
|
1321
|
+
*/
|
|
1322
|
+
function expandFollow(raw) {
|
|
1323
|
+
var out = {};
|
|
1324
|
+
for (var field in raw) {
|
|
1325
|
+
if (Object.prototype.hasOwnProperty.call(raw, field)) out[field] = raw[field];
|
|
1326
|
+
}
|
|
1327
|
+
// Migration bridge, not a live rule: a document written before 0.2.0 carries
|
|
1328
|
+
// the family on the interface only, so an empty conversation family takes it.
|
|
1329
|
+
// The card never describes an empty field as "follows the interface".
|
|
1330
|
+
out[STACK_DIALOG_FIELD] =
|
|
1331
|
+
raw[STACK_DIALOG_FIELD] !== "" ? raw[STACK_DIALOG_FIELD] : raw[SANS_FIELD];
|
|
1332
|
+
out[WEIGHT_DIALOG_FIELD] = raw[WEIGHT_DIALOG_FIELD];
|
|
1333
|
+
if (raw[UI_FOLLOWS_FIELD] !== false) {
|
|
1334
|
+
out[SANS_FIELD] = out[STACK_DIALOG_FIELD];
|
|
1335
|
+
out[WEIGHT_FIELD] =
|
|
1336
|
+
raw[WEIGHT_DIALOG_FIELD] !== WEIGHT_UNSET ? raw[WEIGHT_DIALOG_FIELD] : raw[WEIGHT_FIELD];
|
|
1337
|
+
}
|
|
1338
|
+
return out;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
/**
|
|
1342
|
+
* Resolve the effective light and dark axis sets of one configuration.
|
|
1343
|
+
*
|
|
1344
|
+
* With `perTheme` off the dark set IS the light set; with it on, the sparse
|
|
1345
|
+
* `darkValues` map is applied over the single set first and follow-expansion
|
|
1346
|
+
* runs on the result, so a dark dialog value still tracks the dark interface
|
|
1347
|
+
* value when the interface itself is overridden per theme.
|
|
1348
|
+
* @param {unknown} config - candidate configuration.
|
|
1349
|
+
* @returns {{light: object, dark: object}} the two axis sets.
|
|
1350
|
+
*/
|
|
1351
|
+
function resolveAxes(config) {
|
|
1352
|
+
var raw = normalizeConfig(config);
|
|
1353
|
+
var light = expandFollow(raw);
|
|
1354
|
+
if (raw[PER_THEME_FIELD] !== true) return { light: light, dark: light };
|
|
1355
|
+
// The dark overrides are applied to the RAW values and only then expanded: an
|
|
1356
|
+
// already-expanded set has the follow-borrowed values baked in, so expanding
|
|
1357
|
+
// it again would let a borrowed value shadow the dark override.
|
|
1358
|
+
var merged = {};
|
|
1359
|
+
for (var field in raw) {
|
|
1360
|
+
if (Object.prototype.hasOwnProperty.call(raw, field)) merged[field] = raw[field];
|
|
1361
|
+
}
|
|
1362
|
+
var overrides = raw[DARK_VALUES_FIELD];
|
|
1363
|
+
for (var key in overrides) {
|
|
1364
|
+
if (Object.prototype.hasOwnProperty.call(overrides, key)) merged[key] = overrides[key];
|
|
1365
|
+
}
|
|
1366
|
+
return { light: light, dark: expandFollow(merged) };
|
|
723
1367
|
}
|
|
724
1368
|
|
|
1369
|
+
/* ------------------------------------------------------------------ *
|
|
1370
|
+
* the stylesheet builder
|
|
1371
|
+
* ------------------------------------------------------------------ */
|
|
1372
|
+
|
|
1373
|
+
/**
|
|
1374
|
+
* Whether a normalized configuration asks for any change at all.
|
|
1375
|
+
* @param {unknown} config - candidate configuration.
|
|
1376
|
+
* @returns {boolean} true when nothing should be injected.
|
|
1377
|
+
*/
|
|
1378
|
+
function isDormant(config) {
|
|
1379
|
+
var axis = config !== null && typeof config === "object" ? config : {};
|
|
1380
|
+
if (axis[PER_THEME_FIELD] === true) {
|
|
1381
|
+
var dark = axis[DARK_VALUES_FIELD];
|
|
1382
|
+
if (dark !== null && typeof dark === "object") {
|
|
1383
|
+
for (var field in dark) {
|
|
1384
|
+
if (Object.prototype.hasOwnProperty.call(dark, field)) return false;
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
return (
|
|
1389
|
+
// The retired interface size and line-height axes are deliberately absent:
|
|
1390
|
+
// a configuration that only sets them renders nothing, so it is dormant like
|
|
1391
|
+
// an empty one. The interface WEIGHT is not retired — it renders a blanket
|
|
1392
|
+
// rule — so it counts.
|
|
1393
|
+
sanitize(axis[SANS_FIELD]) === "" &&
|
|
1394
|
+
sanitize(axis[STACK_DIALOG_FIELD]) === "" &&
|
|
1395
|
+
sanitize(axis[MONO_FIELD]) === "" &&
|
|
1396
|
+
clampOffset(axis[SIZE_DIALOG_FIELD]) === 0 &&
|
|
1397
|
+
clampOffset(axis[CODE_SIZE_FIELD]) === 0 &&
|
|
1398
|
+
clampWeight(axis[WEIGHT_FIELD]) === WEIGHT_UNSET &&
|
|
1399
|
+
clampWeight(axis[WEIGHT_DIALOG_FIELD]) === WEIGHT_UNSET &&
|
|
1400
|
+
clampWeight(axis[CODE_WEIGHT_FIELD]) === WEIGHT_UNSET &&
|
|
1401
|
+
clampRatio(axis[LINE_HEIGHT_DIALOG_FIELD]) === LINE_HEIGHT_MIN &&
|
|
1402
|
+
clampLineOffset(axis[CODE_LINE_HEIGHT_FIELD]) === 0 &&
|
|
1403
|
+
clampLigatures(axis[LIGATURES_FIELD]) === LIGATURES_DEFAULT &&
|
|
1404
|
+
sanitizeFeatures(axis[FEATURES_FIELD]) === "" &&
|
|
1405
|
+
toBool(axis[NO_SYNTHETIC_ITALIC_FIELD]) === false &&
|
|
1406
|
+
toBool(axis[NO_SYNTHETIC_BOLD_FIELD]) === false
|
|
1407
|
+
);
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
/**
|
|
1411
|
+
* Build the stylesheet one THEME VALUE SET applies.
|
|
1412
|
+
*
|
|
1413
|
+
* The dialog axes reach the conversation markdown through a scope rule keyed
|
|
1414
|
+
* on the markdown container (class-substring match) rather than through the
|
|
1415
|
+
* design tokens: the tokens' `font` shorthands inline their parts, so a
|
|
1416
|
+
* token-level dialog override would need a full shorthand rebuild, while a
|
|
1417
|
+
* scoped `!important` rule wins over every non-important declaration the
|
|
1418
|
+
* theme ships and degrades to "follows the interface" when nothing matches.
|
|
1419
|
+
* Code surfaces are excluded from the dialog scope by construction (see
|
|
1420
|
+
* `CODE_EXCLUDES`), so inline code inside a serif conversation stays mono.
|
|
1421
|
+
*
|
|
1422
|
+
* @param {Record<string, unknown>} axis - an expanded (follow-applied) value set.
|
|
1423
|
+
* @param {Record<string, string>} baseTokens - token name to untouched value.
|
|
1424
|
+
* @param {boolean} isDark - prefix every rule with the dark-theme attribute.
|
|
1425
|
+
* @returns {string} declarations for one `<style>` element.
|
|
1426
|
+
*/
|
|
1427
|
+
function buildAxisCss(axis, baseTokens, isDark) {
|
|
1428
|
+
var sans = formatStack(parseStack(axis[SANS_FIELD]));
|
|
1429
|
+
var mono = formatStack(parseStack(axis[MONO_FIELD]));
|
|
1430
|
+
var declarations = [];
|
|
1431
|
+
|
|
1432
|
+
function blanket(declarations, excludes) {
|
|
1433
|
+
// The exclusion reaches the descendants only: `body` itself inherits
|
|
1434
|
+
// nothing, and neither the body element nor its dark attribute can be a
|
|
1435
|
+
// markdown container or a code surface.
|
|
1436
|
+
var suffix = excludes === undefined ? "" : excludes;
|
|
1437
|
+
var selector = isDark
|
|
1438
|
+
? DARK_ATTR + "," + DARK_ATTR + " *" + suffix
|
|
1439
|
+
: "body,body *" + suffix;
|
|
1440
|
+
return selector + "{" + declarations + "}";
|
|
1441
|
+
}
|
|
1442
|
+
function codeRule(declarations) {
|
|
1443
|
+
var selector = isDark ? prefixSelector(CODE_SELECTOR, DARK_ATTR) : CODE_SELECTOR;
|
|
1444
|
+
return selector + "{" + declarations + "}";
|
|
1445
|
+
}
|
|
1446
|
+
function dialogRule(declarations) {
|
|
1447
|
+
var selector = isDark ? prefixSelector(MARKDOWN_SELECTOR, DARK_ATTR) : MARKDOWN_SELECTOR;
|
|
1448
|
+
return selector + "{" + declarations + "}";
|
|
1449
|
+
}
|
|
1450
|
+
/**
|
|
1451
|
+
* Re-assert the code family inside the dialog: scoped under the markdown
|
|
1452
|
+
* container, after the dialog rule and above it in specificity, so a
|
|
1453
|
+
* serif conversation keeps monospaced code.
|
|
1454
|
+
*/
|
|
1455
|
+
function pushScopedCodeFamily() {
|
|
1456
|
+
var scopedCode = [];
|
|
1457
|
+
var surfaces = CODE_SELECTOR.split(",");
|
|
1458
|
+
for (var cIndex = 0; cIndex < surfaces.length; cIndex += 1) {
|
|
1459
|
+
scopedCode.push('[class*="_markdown_" i] ' + surfaces[cIndex]);
|
|
1460
|
+
}
|
|
1461
|
+
declarations.push(scopedCode.join(",") + "{font-family:" + mono + " !important}");
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
// ---- families ----
|
|
1465
|
+
if (sans !== "") {
|
|
1466
|
+
declarations.push(
|
|
1467
|
+
(isDark ? DARK_ATTR : ":root,body") + "{--dsw-font-family:" + sans + " !important}"
|
|
1468
|
+
);
|
|
1469
|
+
declarations.push((isDark ? DARK_ATTR : "body") + "{font-family:" + sans + " !important}");
|
|
1470
|
+
}
|
|
1471
|
+
if (mono !== "") {
|
|
1472
|
+
// The theme's code tokens chain to `--ds-font-family-code`; the other name
|
|
1473
|
+
// is what dsh-ui-font historically wrote and costs nothing to cover.
|
|
1474
|
+
declarations.push(
|
|
1475
|
+
(isDark ? DARK_ATTR : ":root,body") +
|
|
1476
|
+
"{--dsw-font-mono:" +
|
|
1477
|
+
mono +
|
|
1478
|
+
" !important;--ds-font-family-code:" +
|
|
1479
|
+
mono +
|
|
1480
|
+
" !important}"
|
|
1481
|
+
);
|
|
1482
|
+
// Written after the interface family rule: equal specificity on a code
|
|
1483
|
+
// element means the later declaration wins, so code keeps its own family.
|
|
1484
|
+
declarations.push(codeRule("font-family:" + mono + " !important"));
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
// ---- interface size / line height: RETIRED, and deliberately so ----
|
|
1488
|
+
// Verified against DSH 0.1.5-rc.2: the official settings expose exactly one
|
|
1489
|
+
// size hook, the CONVERSATION font size (`--dsh-content-font-size`). The
|
|
1490
|
+
// interface ladder tokens (`--dsw-font-xs-13`, `--dsw-font-s-14`, …) are
|
|
1491
|
+
// consumed only by conversation-area widgets (tool cards, trajectory,
|
|
1492
|
+
// attachment chips — 6 client-ui packages), while the settings sheet, the
|
|
1493
|
+
// left workspace/sidebar and the right sidebar declare their text sizes as
|
|
1494
|
+
// literals inside their own CSS modules. There is therefore no interface
|
|
1495
|
+
// size or line-height hook: scaling the ladder from these fields moved
|
|
1496
|
+
// nothing a user could recognise as "interface", and scaling the content
|
|
1497
|
+
// chain from them moved the conversation. The durable fields stay in the
|
|
1498
|
+
// schema (old documents keep parsing, presets keep round-tripping) but inject
|
|
1499
|
+
// nothing at all. The interface axis that DOES work is the family (a
|
|
1500
|
+
// page-wide `font-family` on body plus the theme variable) and the weight
|
|
1501
|
+
// (below).
|
|
1502
|
+
|
|
1503
|
+
// ---- interface weight ----
|
|
1504
|
+
// Measured on rc.2 (live page, computed styles): a `body{font-weight}` rule
|
|
1505
|
+
// only reaches the elements that INHERIT their weight, while `body, body *`
|
|
1506
|
+
// also reaches the labels DSH pins with a literal weight on a class rule —
|
|
1507
|
+
// which is why the axis has to be blanket, and why the rule without the
|
|
1508
|
+
// markdown exclusion drags the conversation along with it. With the
|
|
1509
|
+
// exclusion the interface still moves and the markdown subtree does not.
|
|
1510
|
+
var interfaceWeight = axis[WEIGHT_FIELD];
|
|
1511
|
+
var codeWeight = axis[CODE_WEIGHT_FIELD];
|
|
1512
|
+
if (interfaceWeight !== WEIGHT_UNSET) {
|
|
1513
|
+
declarations.push(
|
|
1514
|
+
blanket("font-weight:" + interfaceWeight + " !important", INTERFACE_EXCLUDES)
|
|
1515
|
+
);
|
|
1516
|
+
if (codeWeight === WEIGHT_UNSET) {
|
|
1517
|
+
// Code surfaces are excluded from the blanket rule, so without this they
|
|
1518
|
+
// would inherit the interface weight from body. `normal` is what DSH
|
|
1519
|
+
// computes for them (the code `font` shorthands carry no weight), so an
|
|
1520
|
+
// unset code weight keeps code exactly as DSH shipped it.
|
|
1521
|
+
declarations.push(codeRule("font-weight:normal !important"));
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
// ---- dialog family (scoped; skipped when it equals the interface) ----
|
|
1526
|
+
var dialog = formatStack(parseStack(axis[STACK_DIALOG_FIELD]));
|
|
1527
|
+
if (dialog !== "" && dialog !== sans) {
|
|
1528
|
+
declarations.push(dialogRule("font-family:" + dialog + " !important"));
|
|
1529
|
+
if (mono !== "") {
|
|
1530
|
+
// Keep the code family inside the dialog.
|
|
1531
|
+
pushScopedCodeFamily();
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
// ---- dialog weight (uniform inside the conversation) ----
|
|
1536
|
+
var dialogWeight = axis[WEIGHT_DIALOG_FIELD];
|
|
1537
|
+
if (dialogWeight !== WEIGHT_UNSET) {
|
|
1538
|
+
declarations.push(dialogRule("font-weight:" + dialogWeight + " !important"));
|
|
1539
|
+
// The card's conversation preview simulates this surface, so it takes the
|
|
1540
|
+
// same weight (and is excluded from the interface rule above).
|
|
1541
|
+
declarations.push(
|
|
1542
|
+
(isDark ? DARK_ATTR + " " : "") +
|
|
1543
|
+
".dfp-previewDialog{font-weight:" +
|
|
1544
|
+
dialogWeight +
|
|
1545
|
+
" !important}"
|
|
1546
|
+
);
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
// ---- dialog size offset (additive, on the official content-size source) ----
|
|
1550
|
+
// Every markdown size derives from the official content-size chain, and that
|
|
1551
|
+
// chain is COMPUTED ON BODY: custom properties resolve where they are
|
|
1552
|
+
// declared, so overriding the size deeper down would leave the derived tokens
|
|
1553
|
+
// (secondary size, both deltas, delta-based heading sizes, heights) at their
|
|
1554
|
+
// body-computed values. The offset is therefore added once, at the source —
|
|
1555
|
+
// `--dsh-content-font-size` becomes "official base + offset" — and the whole
|
|
1556
|
+
// ladder follows by derivation, with nothing counted twice. The interface
|
|
1557
|
+
// axis never touches this chain (see `bodyTokenNames`), so the conversation
|
|
1558
|
+
// moves only when this axis says so, and a dialog that FOLLOWS the interface
|
|
1559
|
+
// follows it through this value.
|
|
1560
|
+
var dialogOffsetValue = axis[SIZE_DIALOG_FIELD];
|
|
1561
|
+
if (dialogOffsetValue !== 0) {
|
|
1562
|
+
var contentSources = tokenNames(baseTokens).filter(function (name) {
|
|
1563
|
+
if (!isContentToken(name)) return false;
|
|
1564
|
+
var base = baseTokens[name];
|
|
1565
|
+
// The source token only: the derived ones carry var()/calc() and would
|
|
1566
|
+
// add the offset a second time if they were shifted as well.
|
|
1567
|
+
return (
|
|
1568
|
+
typeof base === "string" &&
|
|
1569
|
+
base !== "" &&
|
|
1570
|
+
base.indexOf("var(") === -1 &&
|
|
1571
|
+
base.indexOf("calc(") === -1
|
|
1572
|
+
);
|
|
1573
|
+
});
|
|
1574
|
+
var contentShift = shiftTokens(contentSources, baseTokens, dialogOffsetValue);
|
|
1575
|
+
if (contentShift.length > 0) declarations.push(blanket(contentShift.join(";")));
|
|
1576
|
+
// The `small` series is the only markdown family with literal sizes: it
|
|
1577
|
+
// does not derive from the chain, so its parts and shorthands shift here.
|
|
1578
|
+
var literals = markdownTokenNames(baseTokens).filter(function (name) {
|
|
1579
|
+
var base = baseTokens[name];
|
|
1580
|
+
return name.indexOf("-font-size") >= 0 && typeof base === "string" && base.indexOf("var(") === -1;
|
|
1581
|
+
});
|
|
1582
|
+
var literalShift = shiftTokens(literals, baseTokens, dialogOffsetValue);
|
|
1583
|
+
if (literalShift.length > 0) declarations.push(blanket(literalShift.join(";")));
|
|
1584
|
+
// The shorthands whose size is a literal (the small series) must ride the
|
|
1585
|
+
// shift too; the delta-derived shorthands flow through the chain above.
|
|
1586
|
+
var sizeShifted = [];
|
|
1587
|
+
var markdownEntries = shorthandTokens(baseTokens).filter(function (entry) {
|
|
1588
|
+
return isMarkdownToken(entry.name) && entry.parts.size.indexOf("var(") === -1;
|
|
1589
|
+
});
|
|
1590
|
+
for (var mIndex = 0; mIndex < markdownEntries.length; mIndex += 1) {
|
|
1591
|
+
var mEntry = markdownEntries[mIndex];
|
|
1592
|
+
var mSize =
|
|
1593
|
+
"calc((" + mEntry.parts.size + ") + " + dialogOffsetValue + "px)";
|
|
1594
|
+
sizeShifted.push(
|
|
1595
|
+
mEntry.name + ":" + rebuildShorthand({ lead: mEntry.parts.lead, size: mSize, height: mEntry.parts.height, family: mEntry.parts.family }) + " !important"
|
|
1596
|
+
);
|
|
1597
|
+
}
|
|
1598
|
+
if (sizeShifted.length > 0) declarations.push(blanket(sizeShifted.join(";")));
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
// ---- dialog line height (ratio, through the shorthand heights) ----
|
|
1602
|
+
var dialogLine = axis[LINE_HEIGHT_DIALOG_FIELD];
|
|
1603
|
+
if (dialogLine !== LINE_HEIGHT_MIN) {
|
|
1604
|
+
var dialogFactor = round(dialogLine / LINE_HEIGHT_MIN, 6);
|
|
1605
|
+
var markdownLines = markdownTokenNames(baseTokens).filter(function (name) {
|
|
1606
|
+
return name.indexOf("-line-height") >= 0;
|
|
1607
|
+
});
|
|
1608
|
+
var dialogLineDecls = scaleLineTokens(markdownLines, baseTokens, dialogFactor);
|
|
1609
|
+
if (dialogLineDecls.length > 0) declarations.push(blanket(dialogLineDecls.join(";")));
|
|
1610
|
+
var dialogShorthandList = markdownShorthandTokens(baseTokens);
|
|
1611
|
+
var dialogShorthandShifted = [];
|
|
1612
|
+
for (var dIndex = 0; dIndex < dialogShorthandList.length; dIndex += 1) {
|
|
1613
|
+
var dEntry = dialogShorthandList[dIndex];
|
|
1614
|
+
dialogShorthandShifted.push(
|
|
1615
|
+
dEntry.name +
|
|
1616
|
+
":" +
|
|
1617
|
+
rebuildShorthand({
|
|
1618
|
+
lead: dEntry.parts.lead,
|
|
1619
|
+
size: dEntry.parts.size,
|
|
1620
|
+
height: "calc((" + dEntry.parts.height + ") * " + dialogFactor + ")",
|
|
1621
|
+
family: dEntry.parts.family,
|
|
1622
|
+
}) +
|
|
1623
|
+
" !important"
|
|
1624
|
+
);
|
|
1625
|
+
}
|
|
1626
|
+
if (dialogShorthandShifted.length > 0) {
|
|
1627
|
+
declarations.push(blanket(dialogShorthandShifted.join(";")));
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
// ---- code axes ----
|
|
1632
|
+
var codeSize = axis[CODE_SIZE_FIELD];
|
|
1633
|
+
var codeLine = axis[CODE_LINE_HEIGHT_FIELD];
|
|
1634
|
+
if (codeSize !== 0 || codeLine !== 0) {
|
|
1635
|
+
var codeScaled = scaleCodeTokens(
|
|
1636
|
+
baseTokens,
|
|
1637
|
+
round(scaleFor(codeSize), 6),
|
|
1638
|
+
codeLine
|
|
1639
|
+
);
|
|
1640
|
+
if (codeScaled.length > 0) declarations.push(blanket(codeScaled.join(";")));
|
|
1641
|
+
}
|
|
1642
|
+
var codeWeightRule = axis[CODE_WEIGHT_FIELD];
|
|
1643
|
+
if (codeWeightRule !== WEIGHT_UNSET) {
|
|
1644
|
+
declarations.push(codeRule("font-weight:" + codeWeightRule + " !important"));
|
|
1645
|
+
}
|
|
1646
|
+
var ligatures = axis[LIGATURES_FIELD];
|
|
1647
|
+
if (ligatures === LIGATURES_ON) {
|
|
1648
|
+
declarations.push(codeRule("font-variant-ligatures:contextual !important"));
|
|
1649
|
+
} else if (ligatures === LIGATURES_OFF) {
|
|
1650
|
+
declarations.push(codeRule("font-variant-ligatures:none !important"));
|
|
1651
|
+
}
|
|
1652
|
+
var features = axis[FEATURES_FIELD];
|
|
1653
|
+
if (features !== "") {
|
|
1654
|
+
declarations.push(codeRule("font-feature-settings:" + features + " !important"));
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
// ---- synthesis (faux italic / faux bold) ----
|
|
1658
|
+
var noItalic = axis[NO_SYNTHETIC_ITALIC_FIELD] === true;
|
|
1659
|
+
var noBold = axis[NO_SYNTHETIC_BOLD_FIELD] === true;
|
|
1660
|
+
if (noItalic && noBold) {
|
|
1661
|
+
declarations.push(blanket("font-synthesis:none !important"));
|
|
1662
|
+
} else {
|
|
1663
|
+
if (noItalic) declarations.push(blanket("font-synthesis-style:none !important"));
|
|
1664
|
+
if (noBold) declarations.push(blanket("font-synthesis-weight:none !important"));
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
return declarations.join("\n");
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
/**
|
|
1671
|
+
* Re-declare the markdown code tokens at their own ratio and line offset.
|
|
1672
|
+
*
|
|
1673
|
+
* Two shapes exist and both must be covered, because the shipped stylesheets
|
|
1674
|
+
* consume the shorthand (`font: var(--dsw-font-markdown-code-block-small)`)
|
|
1675
|
+
* while the split tokens exist for anything that asks for a single part:
|
|
1676
|
+
* `11px/19px <family>` and a bare `11px`. The shorthand's height rides BOTH
|
|
1677
|
+
* the ratio and the additive offset; the size rides the ratio only.
|
|
1678
|
+
*
|
|
1679
|
+
* @param {Record<string, string>} baseTokens - token name to untouched value.
|
|
1680
|
+
* @param {number} scale - the size ratio to apply.
|
|
1681
|
+
* @param {number} [lineOffset=0] - additive px on the height.
|
|
1682
|
+
* @returns {string[]} declarations.
|
|
1683
|
+
*/
|
|
1684
|
+
function scaleCodeTokens(baseTokens, scale, lineOffset) {
|
|
1685
|
+
var shift = typeof lineOffset === "number" && lineOffset !== 0 ? lineOffset : 0;
|
|
1686
|
+
// The code axis covers every `--dsw-font-markdown-code*` token exactly once:
|
|
1687
|
+
// a value that parses as a shorthand rides the shorthand path, everything
|
|
1688
|
+
// else the part path.
|
|
1689
|
+
var entries = [];
|
|
1690
|
+
var seen = {};
|
|
1691
|
+
var all = tokenNames(baseTokens).filter(isCodeToken);
|
|
1692
|
+
for (var aIndex = 0; aIndex < all.length; aIndex += 1) {
|
|
1693
|
+
seen[all[aIndex]] = true;
|
|
1694
|
+
entries.push({ name: all[aIndex], value: baseTokens[all[aIndex]] });
|
|
1695
|
+
}
|
|
1696
|
+
var shorthands = shorthandTokens(baseTokens);
|
|
1697
|
+
for (var sIndex = 0; sIndex < shorthands.length; sIndex += 1) {
|
|
1698
|
+
var entry = shorthands[sIndex];
|
|
1699
|
+
if (!isCodeToken(entry.name) || seen[entry.name] === true) continue;
|
|
1700
|
+
seen[entry.name] = true;
|
|
1701
|
+
entries.push({ name: entry.name, value: baseTokens[entry.name] });
|
|
1702
|
+
}
|
|
1703
|
+
var out = [];
|
|
1704
|
+
for (var index = 0; index < entries.length; index += 1) {
|
|
1705
|
+
var name = entries[index].name;
|
|
1706
|
+
var base = entries[index].value;
|
|
1707
|
+
if (typeof base !== "string" || base === "") continue;
|
|
1708
|
+
var parsed = parseShorthand(base);
|
|
1709
|
+
if (parsed !== null) {
|
|
1710
|
+
var size = scale === 1 ? parsed.size : "calc((" + parsed.size + ") * " + scale + ")";
|
|
1711
|
+
var height = "calc((" + parsed.height + ") * " + scale + ")";
|
|
1712
|
+
if (shift !== 0) height = "calc(" + height + " + " + shift + "px)";
|
|
1713
|
+
out.push(
|
|
1714
|
+
name +
|
|
1715
|
+
":" +
|
|
1716
|
+
rebuildShorthand({ lead: parsed.lead, size: size, height: height, family: parsed.family }) +
|
|
1717
|
+
" !important"
|
|
1718
|
+
);
|
|
1719
|
+
continue;
|
|
1720
|
+
}
|
|
1721
|
+
// A part token that derives from another token follows that token's own
|
|
1722
|
+
// scaling; re-declaring it here would compound the ratio — except the
|
|
1723
|
+
// line-height parts, which must additionally carry the offset.
|
|
1724
|
+
if (base.indexOf("var(") !== -1 && !(name.indexOf("-line-height") >= 0 && shift !== 0)) continue;
|
|
1725
|
+
if (!isScalableValue(base)) continue;
|
|
1726
|
+
if (name.indexOf("-line-height") >= 0 && shift !== 0) {
|
|
1727
|
+
out.push(
|
|
1728
|
+
name +
|
|
1729
|
+
":calc(((" + base + ") * " + scale + ") + " + shift + "px) !important"
|
|
1730
|
+
);
|
|
1731
|
+
} else {
|
|
1732
|
+
out.push(name + ":calc((" + base + ") * " + scale + ") !important");
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
return out;
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
/* ------------------------------------------------------------------ *
|
|
1739
|
+
* entry point
|
|
1740
|
+
* ------------------------------------------------------------------ */
|
|
1741
|
+
|
|
1742
|
+
/**
|
|
1743
|
+
* Build the stylesheet one configuration applies.
|
|
1744
|
+
*
|
|
1745
|
+
* The configuration resolves into a light set and — when `perTheme` is on — a
|
|
1746
|
+
* dark set; the light rules are emitted unprefixed and the dark rules carry
|
|
1747
|
+
* the dark-theme attribute, so the dark set wins by specificity exactly while
|
|
1748
|
+
* that theme is active. When `perTheme` is off, or the dark set equals the
|
|
1749
|
+
* light set, no prefixed rules are emitted at all.
|
|
1750
|
+
*
|
|
1751
|
+
* @param {unknown} config - normalized or raw configuration.
|
|
1752
|
+
* @param {Record<string, string>} [baseTokens] - token name to untouched value.
|
|
1753
|
+
* @returns {string} declarations for one `<style>` element ("" when dormant).
|
|
1754
|
+
*/
|
|
1755
|
+
function buildFontCss(config, baseTokens) {
|
|
1756
|
+
var tokens = baseTokens === undefined || baseTokens === null ? FALLBACK_TOKENS : baseTokens;
|
|
1757
|
+
var sets = resolveAxes(config);
|
|
1758
|
+
if (isDormant(sets.light) && isDormant(sets.dark)) return "";
|
|
1759
|
+
var light = buildAxisCss(sets.light, tokens, false);
|
|
1760
|
+
if (sameValueSet(sets.light, sets.dark)) return light;
|
|
1761
|
+
var dark = buildAxisCss(sets.dark, tokens, true);
|
|
1762
|
+
if (dark === "") return light;
|
|
1763
|
+
return light + "\n" + dark;
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
/**
|
|
1767
|
+
* Whether two axis sets produce the same declarations, compared over the
|
|
1768
|
+
* visual fields only (the storage fields — presets, the dark map itself —
|
|
1769
|
+
* never render).
|
|
1770
|
+
* @param {Record<string, unknown>} left - an expanded axis set.
|
|
1771
|
+
* @param {Record<string, unknown>} right - another expanded axis set.
|
|
1772
|
+
* @returns {boolean}
|
|
1773
|
+
*/
|
|
1774
|
+
function sameValueSet(left, right) {
|
|
1775
|
+
for (var index = 0; index < VALUE_FIELDS.length; index += 1) {
|
|
1776
|
+
var field = VALUE_FIELDS[index];
|
|
1777
|
+
if (left[field] !== right[field]) return false;
|
|
1778
|
+
}
|
|
1779
|
+
return true;
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
/* ------------------------------------------------------------------ *
|
|
1783
|
+
* embedded fallback map
|
|
1784
|
+
* ------------------------------------------------------------------ */
|
|
1785
|
+
|
|
725
1786
|
/**
|
|
726
1787
|
* Embedded fallback for the tokens the theme plugin defines at runtime.
|
|
727
1788
|
*
|
|
728
1789
|
* The live document is always preferred; this map only covers the window
|
|
729
1790
|
* before those declarations exist (and any token a future release renames
|
|
730
|
-
* away from the pattern). Values
|
|
731
|
-
* DSH 0.1.5-rc.2.
|
|
1791
|
+
* away from the pattern). Values are read byte for byte from the theme's own
|
|
1792
|
+
* stylesheet in DSH 0.1.5-rc.2.
|
|
732
1793
|
*/
|
|
733
1794
|
var FALLBACK_TOKENS = {
|
|
1795
|
+
// interface ladder shorthands
|
|
1796
|
+
"--dsw-font-xxxs-11": "11px/14px var(--dsw-font-family)",
|
|
1797
|
+
"--dsw-font-xxxs-strong-11": "500 11px/14px var(--dsw-font-family)",
|
|
1798
|
+
"--dsw-font-xxs-12": "12px/18px var(--dsw-font-family)",
|
|
1799
|
+
"--dsw-font-xxs-strong-12": "500 12px/18px var(--dsw-font-family)",
|
|
1800
|
+
"--dsw-font-xs-13": "13px/20px var(--dsw-font-family)",
|
|
1801
|
+
"--dsw-font-xs-strong-13": "500 13px/20px var(--dsw-font-family)",
|
|
1802
|
+
"--dsw-font-s-14": "14px/22px var(--dsw-font-family)",
|
|
1803
|
+
"--dsw-font-s-strong-14": "500 14px/22px var(--dsw-font-family)",
|
|
1804
|
+
"--dsw-font-base-16": "16px/24px var(--dsw-font-family)",
|
|
1805
|
+
"--dsw-font-base-strong-16": "500 16px/24px var(--dsw-font-family)",
|
|
1806
|
+
"--dsw-font-m-18": "500 16px/28px var(--dsw-font-family)",
|
|
1807
|
+
"--dsw-font-l-20": "500 20px/28px var(--dsw-font-family)",
|
|
1808
|
+
"--dsw-font-xl-24": "600 24px/32px var(--dsw-font-family)",
|
|
1809
|
+
// interface ladder parts
|
|
734
1810
|
"--dsw-font-xxxs-11-font-size": "11px",
|
|
735
|
-
"--dsw-font-xxxs-11-line-height": "
|
|
1811
|
+
"--dsw-font-xxxs-11-line-height": "14px",
|
|
736
1812
|
"--dsw-font-xxxs-strong-11-font-size": "11px",
|
|
737
|
-
"--dsw-font-xxxs-strong-11-line-height": "
|
|
1813
|
+
"--dsw-font-xxxs-strong-11-line-height": "14px",
|
|
738
1814
|
"--dsw-font-xxs-12-font-size": "12px",
|
|
739
|
-
"--dsw-font-xxs-12-line-height": "
|
|
1815
|
+
"--dsw-font-xxs-12-line-height": "18px",
|
|
740
1816
|
"--dsw-font-xxs-strong-12-font-size": "12px",
|
|
741
|
-
"--dsw-font-xxs-strong-12-line-height": "
|
|
1817
|
+
"--dsw-font-xxs-strong-12-line-height": "18px",
|
|
742
1818
|
"--dsw-font-xs-13-font-size": "13px",
|
|
743
|
-
"--dsw-font-xs-13-line-height": "
|
|
1819
|
+
"--dsw-font-xs-13-line-height": "20px",
|
|
744
1820
|
"--dsw-font-xs-strong-13-font-size": "13px",
|
|
745
|
-
"--dsw-font-xs-strong-13-line-height": "
|
|
1821
|
+
"--dsw-font-xs-strong-13-line-height": "20px",
|
|
746
1822
|
"--dsw-font-s-14-font-size": "14px",
|
|
747
|
-
"--dsw-font-s-14-line-height": "
|
|
1823
|
+
"--dsw-font-s-14-line-height": "22px",
|
|
748
1824
|
"--dsw-font-s-strong-14-font-size": "14px",
|
|
749
|
-
"--dsw-font-s-strong-14-line-height": "
|
|
1825
|
+
"--dsw-font-s-strong-14-line-height": "22px",
|
|
750
1826
|
"--dsw-font-base-16-font-size": "16px",
|
|
751
|
-
"--dsw-font-base-16-line-height": "
|
|
1827
|
+
"--dsw-font-base-16-line-height": "24px",
|
|
752
1828
|
"--dsw-font-base-strong-16-font-size": "16px",
|
|
753
|
-
"--dsw-font-base-strong-16-line-height": "
|
|
754
|
-
"--dsw-font-m-18-font-size": "
|
|
1829
|
+
"--dsw-font-base-strong-16-line-height": "24px",
|
|
1830
|
+
"--dsw-font-m-18-font-size": "16px",
|
|
755
1831
|
"--dsw-font-m-18-line-height": "28px",
|
|
756
1832
|
"--dsw-font-l-20-font-size": "20px",
|
|
757
|
-
"--dsw-font-l-20-line-height": "
|
|
1833
|
+
"--dsw-font-l-20-line-height": "28px",
|
|
758
1834
|
"--dsw-font-xl-24-font-size": "24px",
|
|
759
|
-
"--dsw-font-xl-24-line-height": "
|
|
760
|
-
|
|
761
|
-
"--dsw-font-markdown-
|
|
762
|
-
"--dsw-font-markdown-
|
|
763
|
-
"--dsw-font-markdown-
|
|
764
|
-
"--dsw-font-markdown-
|
|
765
|
-
"--dsw-font-markdown-
|
|
766
|
-
"--dsw-font-markdown-
|
|
767
|
-
"--dsw-font-markdown-
|
|
768
|
-
"--dsw-font-markdown-
|
|
769
|
-
"--dsw-font-markdown-
|
|
770
|
-
"--dsw-font-markdown-
|
|
771
|
-
"--dsw-font-markdown-
|
|
772
|
-
|
|
773
|
-
|
|
1835
|
+
"--dsw-font-xl-24-line-height": "32px",
|
|
1836
|
+
// markdown (dialog) shorthands
|
|
1837
|
+
"--dsw-font-markdown-h1": "700 calc(21px + var(--dsh-content-font-delta)) / calc(30px + var(--dsh-content-font-delta)) var(--dsw-font-family)",
|
|
1838
|
+
"--dsw-font-markdown-h2": "700 calc(19px + var(--dsh-content-font-delta)) / calc(28px + var(--dsh-content-font-delta)) var(--dsw-font-family)",
|
|
1839
|
+
"--dsw-font-markdown-h3": "700 calc(18px + var(--dsh-content-font-delta)) / calc(26px + var(--dsh-content-font-delta)) var(--dsw-font-family)",
|
|
1840
|
+
"--dsw-font-markdown-h4": "600 var(--dsh-content-font-size,14px) / calc(24px + var(--dsh-content-font-delta)) var(--dsw-font-family)",
|
|
1841
|
+
"--dsw-font-markdown-base": "var(--dsh-content-font-size,14px) / calc(24px + var(--dsh-content-font-delta)) var(--dsw-font-family)",
|
|
1842
|
+
"--dsw-font-markdown-base-strong": "600 var(--dsh-content-font-size,14px) / calc(24px + var(--dsh-content-font-delta)) var(--dsw-font-family)",
|
|
1843
|
+
"--dsw-font-markdown-base-italic": "italic var(--dsh-content-font-size,14px) / calc(24px + var(--dsh-content-font-delta)) var(--dsw-font-family)",
|
|
1844
|
+
"--dsw-font-markdown-base-strong-italic": "italic 600 var(--dsh-content-font-size,14px) / calc(24px + var(--dsh-content-font-delta)) var(--dsw-font-family)",
|
|
1845
|
+
"--dsw-font-markdown-table": "var(--dsh-content-font-size-secondary,13px)/calc(22px + var(--dsh-content-font-delta-secondary,0px)) var(--dsw-font-family)",
|
|
1846
|
+
"--dsw-font-markdown-table-head": "500 var(--dsh-content-font-size-secondary,13px)/calc(22px + var(--dsh-content-font-delta-secondary,0px)) var(--dsw-font-family)",
|
|
1847
|
+
"--dsw-font-markdown-small": "12px/20px var(--dsw-font-family)",
|
|
1848
|
+
"--dsw-font-markdown-small-strong": "600 12px/20px var(--dsw-font-family)",
|
|
1849
|
+
"--dsw-font-markdown-small-italic": "italic 12px/20px var(--dsw-font-family)",
|
|
1850
|
+
"--dsw-font-markdown-small-strong-italic": "italic 600 12px/20px var(--dsw-font-family)",
|
|
1851
|
+
// markdown small-series literals (the additive dialog offset rewrites these)
|
|
1852
|
+
"--dsw-font-markdown-small-font-size": "12px",
|
|
1853
|
+
"--dsw-font-markdown-small-line-height": "20px",
|
|
1854
|
+
"--dsw-font-markdown-small-strong-font-size": "12px",
|
|
1855
|
+
"--dsw-font-markdown-small-strong-line-height": "20px",
|
|
1856
|
+
"--dsw-font-markdown-small-italic-font-size": "12px",
|
|
1857
|
+
"--dsw-font-markdown-small-italic-line-height": "20px",
|
|
1858
|
+
"--dsw-font-markdown-small-strong-italic-font-size": "12px",
|
|
1859
|
+
"--dsw-font-markdown-small-strong-italic-line-height": "20px",
|
|
1860
|
+
// markdown part tokens (the dialog line-height ratio scales their heights;
|
|
1861
|
+
// their var-derived sizes ride the delta tokens, never the ratio)
|
|
1862
|
+
"--dsw-font-markdown-base-font-size": "var(--dsh-content-font-size,14px)",
|
|
1863
|
+
"--dsw-font-markdown-base-line-height": "calc(24px + var(--dsh-content-font-delta))",
|
|
1864
|
+
"--dsw-font-markdown-base-strong-font-size": "var(--dsh-content-font-size,14px)",
|
|
1865
|
+
"--dsw-font-markdown-base-strong-line-height": "calc(24px + var(--dsh-content-font-delta))",
|
|
1866
|
+
"--dsw-font-markdown-base-italic-font-size": "var(--dsh-content-font-size,14px)",
|
|
1867
|
+
"--dsw-font-markdown-base-italic-line-height": "calc(24px + var(--dsh-content-font-delta))",
|
|
1868
|
+
"--dsw-font-markdown-base-strong-italic-font-size": "var(--dsh-content-font-size,14px)",
|
|
1869
|
+
"--dsw-font-markdown-base-strong-italic-line-height": "calc(24px + var(--dsh-content-font-delta))",
|
|
1870
|
+
"--dsw-font-markdown-h1-font-size": "calc(21px + var(--dsh-content-font-delta))",
|
|
1871
|
+
"--dsw-font-markdown-h1-line-height": "calc(30px + var(--dsh-content-font-delta))",
|
|
1872
|
+
"--dsw-font-markdown-h2-font-size": "calc(19px + var(--dsh-content-font-delta))",
|
|
1873
|
+
"--dsw-font-markdown-h2-line-height": "calc(28px + var(--dsh-content-font-delta))",
|
|
1874
|
+
"--dsw-font-markdown-h3-font-size": "calc(18px + var(--dsh-content-font-delta))",
|
|
1875
|
+
"--dsw-font-markdown-h3-line-height": "calc(26px + var(--dsh-content-font-delta))",
|
|
1876
|
+
"--dsw-font-markdown-h4-font-size": "var(--dsh-content-font-size,14px)",
|
|
1877
|
+
"--dsw-font-markdown-h4-line-height": "calc(24px + var(--dsh-content-font-delta))",
|
|
1878
|
+
"--dsw-font-markdown-table-font-size": "var(--dsh-content-font-size-secondary,13px)",
|
|
1879
|
+
"--dsw-font-markdown-table-line-height": "calc(22px + var(--dsh-content-font-delta-secondary,0px))",
|
|
1880
|
+
"--dsw-font-markdown-table-head-font-size": "var(--dsh-content-font-size-secondary,13px)",
|
|
1881
|
+
"--dsw-font-markdown-table-head-line-height": "calc(22px + var(--dsh-content-font-delta-secondary,0px))",
|
|
1882
|
+
// markdown delta tokens (the dialog offset shifts these additively)
|
|
1883
|
+
"--dsh-content-font-delta": "calc(var(--dsh-content-font-size,14px) - 14px)",
|
|
1884
|
+
"--dsh-content-font-delta-secondary": "calc(var(--dsh-content-font-size-secondary) - 13px)",
|
|
1885
|
+
// the code family: shorthand + parts, at rc.2's values
|
|
774
1886
|
"--dsw-font-markdown-code": "12px/19px var(--ds-font-family-code)",
|
|
775
1887
|
"--dsw-font-markdown-code-font-size": "12px",
|
|
776
1888
|
"--dsw-font-markdown-code-line-height": "19px",
|
|
777
1889
|
"--dsw-font-markdown-code-block": "11px/19px var(--ds-font-family-code)",
|
|
778
|
-
"--dsw-font-markdown-code-block": "11px/19px var(--ds-font-family-code)",
|
|
779
1890
|
"--dsw-font-markdown-code-block-font-size": "11px",
|
|
780
1891
|
"--dsw-font-markdown-code-block-line-height": "19px",
|
|
781
1892
|
"--dsw-font-markdown-code-block-small": "11px/16px var(--ds-font-family-code)",
|
|
782
1893
|
"--dsw-font-markdown-code-block-small-font-size": "11px",
|
|
783
1894
|
"--dsw-font-markdown-code-block-small-line-height": "16px",
|
|
784
|
-
|
|
785
|
-
"--dsw-font-markdown-table-line-height": "22px",
|
|
1895
|
+
// content size (the interface chain's anchor, written inline by the theme)
|
|
786
1896
|
"--dsh-content-font-size": "14px",
|
|
787
1897
|
"--dsh-content-font-size-secondary": "13px",
|
|
788
1898
|
};
|
|
789
1899
|
|
|
790
|
-
|
|
791
|
-
*
|
|
792
|
-
*
|
|
793
|
-
* @param {number} digits - decimals to keep.
|
|
794
|
-
* @returns {number} the rounded number.
|
|
795
|
-
*/
|
|
796
|
-
function round(value, digits) {
|
|
797
|
-
var factor = Math.pow(10, digits);
|
|
798
|
-
return Math.round(value * factor) / factor;
|
|
799
|
-
}
|
|
1900
|
+
/* ------------------------------------------------------------------ *
|
|
1901
|
+
* curated family lists
|
|
1902
|
+
* ------------------------------------------------------------------ */
|
|
800
1903
|
|
|
801
1904
|
/**
|
|
802
1905
|
* Curated families offered when the browser cannot enumerate local fonts —
|
|
@@ -862,44 +1965,111 @@ var PRESETS = {
|
|
|
862
1965
|
generic: ["system-ui", "sans-serif", "serif"],
|
|
863
1966
|
};
|
|
864
1967
|
|
|
1968
|
+
/**
|
|
1969
|
+
* Legacy single-purpose helper kept for compatibility: scale the size and the
|
|
1970
|
+
* height inside one simple `size/height <family>` shorthand.
|
|
1971
|
+
* @param {string} value - a value shaped like `11px/19px var(--ds-font-family-code)`.
|
|
1972
|
+
* @param {number} scale - the ratio to apply.
|
|
1973
|
+
* @returns {string|null} the scaled shorthand, or null when the shape differs.
|
|
1974
|
+
*/
|
|
1975
|
+
function scaleFontShorthand(value, scale) {
|
|
1976
|
+
var parts = parseShorthand(value);
|
|
1977
|
+
if (parts === null || parts.lead !== "") return null;
|
|
1978
|
+
return (
|
|
1979
|
+
"calc((" + parts.size + ") * " + scale + ")/calc((" + parts.height + ") * " + scale + ") " + parts.family
|
|
1980
|
+
);
|
|
1981
|
+
}
|
|
1982
|
+
|
|
865
1983
|
var shared = {
|
|
866
1984
|
NAMESPACE: NAMESPACE,
|
|
867
1985
|
SANS_FIELD: SANS_FIELD,
|
|
1986
|
+
STACK_DIALOG_FIELD: STACK_DIALOG_FIELD,
|
|
868
1987
|
MONO_FIELD: MONO_FIELD,
|
|
869
1988
|
SIZE_FIELD: SIZE_FIELD,
|
|
1989
|
+
SIZE_DIALOG_FIELD: SIZE_DIALOG_FIELD,
|
|
870
1990
|
CODE_SIZE_FIELD: CODE_SIZE_FIELD,
|
|
871
1991
|
WEIGHT_FIELD: WEIGHT_FIELD,
|
|
1992
|
+
WEIGHT_DIALOG_FIELD: WEIGHT_DIALOG_FIELD,
|
|
872
1993
|
CODE_WEIGHT_FIELD: CODE_WEIGHT_FIELD,
|
|
1994
|
+
LINE_HEIGHT_FIELD: LINE_HEIGHT_FIELD,
|
|
1995
|
+
LINE_HEIGHT_DIALOG_FIELD: LINE_HEIGHT_DIALOG_FIELD,
|
|
1996
|
+
CODE_LINE_HEIGHT_FIELD: CODE_LINE_HEIGHT_FIELD,
|
|
1997
|
+
LIGATURES_FIELD: LIGATURES_FIELD,
|
|
1998
|
+
FEATURES_FIELD: FEATURES_FIELD,
|
|
1999
|
+
NO_SYNTHETIC_ITALIC_FIELD: NO_SYNTHETIC_ITALIC_FIELD,
|
|
2000
|
+
NO_SYNTHETIC_BOLD_FIELD: NO_SYNTHETIC_BOLD_FIELD,
|
|
2001
|
+
PER_THEME_FIELD: PER_THEME_FIELD,
|
|
2002
|
+
DARK_VALUES_FIELD: DARK_VALUES_FIELD,
|
|
2003
|
+
PRESETS_FIELD: PRESETS_FIELD,
|
|
2004
|
+
ACTIVE_PRESET_FIELD: ACTIVE_PRESET_FIELD,
|
|
2005
|
+
UI_FOLLOWS_FIELD: UI_FOLLOWS_FIELD,
|
|
2006
|
+
VALUE_FIELDS: VALUE_FIELDS,
|
|
873
2007
|
SIZE_MIN: SIZE_MIN,
|
|
874
2008
|
SIZE_MAX: SIZE_MAX,
|
|
875
2009
|
WEIGHT_MIN: WEIGHT_MIN,
|
|
876
2010
|
WEIGHT_MAX: WEIGHT_MAX,
|
|
877
2011
|
WEIGHT_UNSET: WEIGHT_UNSET,
|
|
2012
|
+
LINE_HEIGHT_MIN: LINE_HEIGHT_MIN,
|
|
2013
|
+
LINE_HEIGHT_MAX: LINE_HEIGHT_MAX,
|
|
2014
|
+
CODE_LINE_HEIGHT_MIN: CODE_LINE_HEIGHT_MIN,
|
|
2015
|
+
CODE_LINE_HEIGHT_MAX: CODE_LINE_HEIGHT_MAX,
|
|
2016
|
+
LIGATURES_DEFAULT: LIGATURES_DEFAULT,
|
|
2017
|
+
LIGATURES_ON: LIGATURES_ON,
|
|
2018
|
+
LIGATURES_OFF: LIGATURES_OFF,
|
|
878
2019
|
MARKER: MARKER,
|
|
879
2020
|
STYLE_TAG: STYLE_TAG,
|
|
880
2021
|
CARD_STYLE_TAG: CARD_STYLE_TAG,
|
|
881
2022
|
DEFAULTS: DEFAULTS,
|
|
882
2023
|
MAX_STACK_LENGTH: MAX_STACK_LENGTH,
|
|
883
2024
|
MAX_FAMILY_LENGTH: MAX_FAMILY_LENGTH,
|
|
2025
|
+
MAX_FEATURES_LENGTH: MAX_FEATURES_LENGTH,
|
|
2026
|
+
MAX_PRESETS: MAX_PRESETS,
|
|
2027
|
+
MAX_PRESET_NAME: MAX_PRESET_NAME,
|
|
884
2028
|
FALLBACK_TOKENS: FALLBACK_TOKENS,
|
|
885
2029
|
PRESETS: PRESETS,
|
|
2030
|
+
MARKDOWN_SELECTOR: MARKDOWN_SELECTOR,
|
|
2031
|
+
DARK_ATTR: DARK_ATTR,
|
|
886
2032
|
sanitize: sanitize,
|
|
887
2033
|
sanitizeFamily: sanitizeFamily,
|
|
2034
|
+
sanitizeFeatures: sanitizeFeatures,
|
|
888
2035
|
quoteFamily: quoteFamily,
|
|
889
2036
|
normalizeConfig: normalizeConfig,
|
|
2037
|
+
normalizeDarkValues: normalizeDarkValues,
|
|
2038
|
+
normalizePresets: normalizePresets,
|
|
2039
|
+
normalizeValueSet: normalizeValueSet,
|
|
890
2040
|
clampOffset: clampOffset,
|
|
891
2041
|
clampWeight: clampWeight,
|
|
2042
|
+
clampRatio: clampRatio,
|
|
2043
|
+
clampLineOffset: clampLineOffset,
|
|
2044
|
+
clampLigatures: clampLigatures,
|
|
892
2045
|
CODE_SELECTOR: CODE_SELECTOR,
|
|
893
2046
|
formatStack: formatStack,
|
|
894
2047
|
parseStack: parseStack,
|
|
2048
|
+
parseShorthand: parseShorthand,
|
|
2049
|
+
rebuildShorthand: rebuildShorthand,
|
|
895
2050
|
scaleFor: scaleFor,
|
|
896
2051
|
isDormant: isDormant,
|
|
2052
|
+
buildAxisCss: buildAxisCss,
|
|
897
2053
|
buildFontCss: buildFontCss,
|
|
2054
|
+
resolveAxes: resolveAxes,
|
|
2055
|
+
expandFollow: expandFollow,
|
|
898
2056
|
isFontToken: isFontToken,
|
|
899
2057
|
isCodeToken: isCodeToken,
|
|
2058
|
+
isMarkdownToken: isMarkdownToken,
|
|
2059
|
+
isDeltaToken: isDeltaToken,
|
|
2060
|
+
isShorthandName: isShorthandName,
|
|
2061
|
+
isShorthandToken: isShorthandToken,
|
|
900
2062
|
isScaledToken: isScaledToken,
|
|
2063
|
+
tokenNames: tokenNames,
|
|
901
2064
|
codeTokenNames: codeTokenNames,
|
|
2065
|
+
markdownTokenNames: markdownTokenNames,
|
|
902
2066
|
bodyTokenNames: bodyTokenNames,
|
|
2067
|
+
uiLineTokenNames: uiLineTokenNames,
|
|
2068
|
+
deltaTokenNames: deltaTokenNames,
|
|
2069
|
+
shorthandTokens: shorthandTokens,
|
|
2070
|
+
markdownShorthandTokens: markdownShorthandTokens,
|
|
2071
|
+
uiShorthandTokens: uiShorthandTokens,
|
|
2072
|
+
codeShorthandTokens: codeShorthandTokens,
|
|
903
2073
|
scaleFontShorthand: scaleFontShorthand,
|
|
904
2074
|
isGenericFamilyName: isGenericFamilyName,
|
|
905
2075
|
isCJKFamilyName: isCJKFamilyName,
|