@pantoken/utils 0.2.6 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +36 -7
- package/dist/index.mjs +74 -11
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -63,6 +63,23 @@ declare function focusOutlineRules(selector?: string): string;
|
|
|
63
63
|
//#region src/index.d.ts
|
|
64
64
|
/** The colour mode to collapse `light-dark()` to. */
|
|
65
65
|
type Mode = "light" | "dark";
|
|
66
|
+
/** One entry of the pantoken spacing scale: the short key, the long (word) key, and the shared CSS value. */
|
|
67
|
+
interface SpacingStep {
|
|
68
|
+
/** The short scale key, e.g. `"sm"` (the zero step's short key is `"0"`). */
|
|
69
|
+
short: string;
|
|
70
|
+
/** The long, word-spelled key, e.g. `"small"` (the zero step's long key is `"none"`). */
|
|
71
|
+
long: string;
|
|
72
|
+
/** The CSS value — a token reference, or a plain `"0"`/`"auto"`. */
|
|
73
|
+
value: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The pantoken spacing scale, `none`/`0` → `2xl` — the single shared source for
|
|
77
|
+
* `@pantoken/components`' spacing/gap utilities and `@pantoken/interactions`' `resolveSpace`, so the
|
|
78
|
+
* two never drift apart.
|
|
79
|
+
*/
|
|
80
|
+
declare const SPACING_STEPS: readonly SpacingStep[];
|
|
81
|
+
/** The `auto` step — margin only, spelled the same both ways. */
|
|
82
|
+
declare const SPACING_AUTO_STEP: SpacingStep;
|
|
66
83
|
/**
|
|
67
84
|
* Strip `<script>` elements and event-handler attributes from SVG markup.
|
|
68
85
|
*
|
|
@@ -267,18 +284,30 @@ interface UtilityOptions {
|
|
|
267
284
|
* falsy value (`null`/`undefined`/`""`) drops the prefix entirely (`.bg-…`).
|
|
268
285
|
*/
|
|
269
286
|
prefix?: string | null;
|
|
287
|
+
/**
|
|
288
|
+
* Component base-class names (e.g. `"button"`, `"view"`) to also emit a chained alias for, per
|
|
289
|
+
* rule — `.<prefix>-bg-danger` (bare) plus `.<prefix>-button.-bg-danger` (chained), so the same
|
|
290
|
+
* modifier works standalone or attached to any component. Omit for bare-only output (unchanged
|
|
291
|
+
* behavior).
|
|
292
|
+
*/
|
|
293
|
+
chainTargets?: readonly string[];
|
|
270
294
|
}
|
|
271
|
-
/**
|
|
295
|
+
/** One semantic colour family entry: a bare name (resolved against `--instui-color-<family>-<name>`)
|
|
296
|
+
* or an explicit `[name, value]` pair — the second element is `var()`-wrapped if it's a `--custom-prop`
|
|
297
|
+
* name, or used verbatim otherwise (a `light-dark(…)` expression, a raw keyword like `transparent`). */
|
|
298
|
+
type ColorUtilityEntry = string | readonly [name: string, value: string];
|
|
299
|
+
/** The semantic colour token names (or explicit `[name, token]` pairs) per family. */
|
|
272
300
|
interface ColorUtilityNames {
|
|
273
|
-
background: readonly
|
|
274
|
-
text: readonly
|
|
275
|
-
stroke: readonly
|
|
301
|
+
background: readonly ColorUtilityEntry[];
|
|
302
|
+
text: readonly ColorUtilityEntry[];
|
|
303
|
+
stroke: readonly ColorUtilityEntry[];
|
|
276
304
|
}
|
|
277
305
|
/**
|
|
278
306
|
* Build the semantic-colour utility stylesheet: `.<prefix>-bg-<name>` (background),
|
|
279
|
-
* `.<prefix>-
|
|
307
|
+
* `.<prefix>-text-<name>` (text colour), `.<prefix>-border-<name>` (border colour), one per semantic
|
|
280
308
|
* colour token. Overrides are therefore only ever token-valid — no primitives, no arbitrary hex. Pass
|
|
281
|
-
* the token names per family (e.g. from `@pantoken/tokens`)
|
|
309
|
+
* the token names per family (e.g. from `@pantoken/tokens`), or an explicit `[name, token]` pair to
|
|
310
|
+
* source a name from a different token than the family's own scale.
|
|
282
311
|
*
|
|
283
312
|
* @param names - {@link ColorUtilityNames}.
|
|
284
313
|
* @param options - {@link UtilityOptions}.
|
|
@@ -311,4 +340,4 @@ interface TokenUtilityGroup {
|
|
|
311
340
|
*/
|
|
312
341
|
declare function tokenUtilitiesCss(groups: readonly TokenUtilityGroup[], options?: UtilityOptions): string;
|
|
313
342
|
//#endregion
|
|
314
|
-
export { ColorUtilityNames, ELEVATION_NAMES, FOCUSABLE_SELECTOR, LIGHT_DARK_RE, Mode, ResolveOptions, Rgba, TokenUtilityGroup, UtilityOptions, VAR_RE, camelCase, colorUtilitiesCss, danglingReferences, elevationDeclarations, extractInstuiRefs, focusOutlineDeclarations, focusOutlineRules, makeResolver, parseHexColor, resolveTokens, sanitizeSvg, tokenNames, tokenUtilitiesCss, unknownReferences };
|
|
343
|
+
export { ColorUtilityEntry, ColorUtilityNames, ELEVATION_NAMES, FOCUSABLE_SELECTOR, LIGHT_DARK_RE, Mode, ResolveOptions, Rgba, SPACING_AUTO_STEP, SPACING_STEPS, SpacingStep, TokenUtilityGroup, UtilityOptions, VAR_RE, camelCase, colorUtilitiesCss, danglingReferences, elevationDeclarations, extractInstuiRefs, focusOutlineDeclarations, focusOutlineRules, makeResolver, parseHexColor, resolveTokens, sanitizeSvg, tokenNames, tokenUtilitiesCss, unknownReferences };
|
package/dist/index.mjs
CHANGED
|
@@ -121,16 +121,69 @@ function focusOutlineRules(selector = FOCUSABLE_SELECTOR) {
|
|
|
121
121
|
/**
|
|
122
122
|
* `@pantoken/utils` — shared, upstream-free helpers used across the pantoken packages: the token
|
|
123
123
|
* reference resolver (with `light-dark()` handling), the two token regexes (typed via `arkregex`),
|
|
124
|
-
* kebab→camel case, hex-colour parsing,
|
|
125
|
-
* ({@link colorUtilitiesCss}, {@link tokenUtilitiesCss}) that
|
|
126
|
-
* tier) and `@pantoken/plugin-primitives` (raw-palette tier)
|
|
127
|
-
* `@pantoken/model` (types) + `arkregex`, so any package can use it without
|
|
128
|
-
* upstream.
|
|
124
|
+
* kebab→camel case, hex-colour parsing, the shared spacing scale ({@link SPACING_STEPS}), and the
|
|
125
|
+
* generic token→utility-class emitters ({@link colorUtilitiesCss}, {@link tokenUtilitiesCss}) that
|
|
126
|
+
* both `@pantoken/components` (semantic tier) and `@pantoken/plugin-primitives` (raw-palette tier)
|
|
127
|
+
* build on. Depends only on `@pantoken/model` (types) + `arkregex`, so any package can use it without
|
|
128
|
+
* pulling the GitHub-only upstream.
|
|
129
129
|
*
|
|
130
130
|
* @module
|
|
131
131
|
* @beta
|
|
132
132
|
*/
|
|
133
133
|
/**
|
|
134
|
+
* The pantoken spacing scale, `none`/`0` → `2xl` — the single shared source for
|
|
135
|
+
* `@pantoken/components`' spacing/gap utilities and `@pantoken/interactions`' `resolveSpace`, so the
|
|
136
|
+
* two never drift apart.
|
|
137
|
+
*/
|
|
138
|
+
const SPACING_STEPS = [
|
|
139
|
+
{
|
|
140
|
+
short: "0",
|
|
141
|
+
long: "none",
|
|
142
|
+
value: "var(--instui-component-shared-tokens-spacing-general-space-none)"
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
short: "2xs",
|
|
146
|
+
long: "xx-small",
|
|
147
|
+
value: "var(--instui-spacing-space2xs)"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
short: "xs",
|
|
151
|
+
long: "x-small",
|
|
152
|
+
value: "var(--instui-spacing-space-xs)"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
short: "sm",
|
|
156
|
+
long: "small",
|
|
157
|
+
value: "var(--instui-spacing-space-sm)"
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
short: "md",
|
|
161
|
+
long: "medium",
|
|
162
|
+
value: "var(--instui-spacing-space-md)"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
short: "lg",
|
|
166
|
+
long: "large",
|
|
167
|
+
value: "var(--instui-spacing-space-lg)"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
short: "xl",
|
|
171
|
+
long: "x-large",
|
|
172
|
+
value: "var(--instui-spacing-space-xl)"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
short: "2xl",
|
|
176
|
+
long: "xx-large",
|
|
177
|
+
value: "var(--instui-spacing-space2xl)"
|
|
178
|
+
}
|
|
179
|
+
];
|
|
180
|
+
/** The `auto` step — margin only, spelled the same both ways. */
|
|
181
|
+
const SPACING_AUTO_STEP = {
|
|
182
|
+
short: "auto",
|
|
183
|
+
long: "auto",
|
|
184
|
+
value: "auto"
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
134
187
|
* Strip `<script>` elements and event-handler attributes from SVG markup.
|
|
135
188
|
*
|
|
136
189
|
* Defense-in-depth for SVG decoded from vendored data URIs or contributed by plugins.
|
|
@@ -376,9 +429,10 @@ function danglingReferences(css) {
|
|
|
376
429
|
}
|
|
377
430
|
/**
|
|
378
431
|
* Build the semantic-colour utility stylesheet: `.<prefix>-bg-<name>` (background),
|
|
379
|
-
* `.<prefix>-
|
|
432
|
+
* `.<prefix>-text-<name>` (text colour), `.<prefix>-border-<name>` (border colour), one per semantic
|
|
380
433
|
* colour token. Overrides are therefore only ever token-valid — no primitives, no arbitrary hex. Pass
|
|
381
|
-
* the token names per family (e.g. from `@pantoken/tokens`)
|
|
434
|
+
* the token names per family (e.g. from `@pantoken/tokens`), or an explicit `[name, token]` pair to
|
|
435
|
+
* source a name from a different token than the family's own scale.
|
|
382
436
|
*
|
|
383
437
|
* @param names - {@link ColorUtilityNames}.
|
|
384
438
|
* @param options - {@link UtilityOptions}.
|
|
@@ -389,10 +443,17 @@ function danglingReferences(css) {
|
|
|
389
443
|
function colorUtilitiesCss(names, options = {}) {
|
|
390
444
|
const prefix = options.prefix || "";
|
|
391
445
|
const p = prefix ? `${prefix}-` : "";
|
|
392
|
-
const
|
|
446
|
+
const chainTargets = options.chainTargets ?? [];
|
|
447
|
+
const emit = (family, util, prop, list) => list.map((entry) => {
|
|
448
|
+
const isPair = (e) => typeof e !== "string";
|
|
449
|
+
const [n, token] = isPair(entry) ? entry : [entry, `--instui-color-${family}-${entry}`];
|
|
450
|
+
const value = token.startsWith("--") ? `var(${token})` : token;
|
|
451
|
+
const modifier = `.-${util}-${n}`;
|
|
452
|
+
return `${[`.${p}${util}-${n}`, ...chainTargets.map((target) => `.${p}${target}${modifier}`)].join(", ")} { ${prop}: ${value}; }`;
|
|
453
|
+
}).join("\n");
|
|
393
454
|
return `/* InstUI semantic colour utilities (@pantoken/utils) — prefix: ${prefix} */\n${[
|
|
394
455
|
emit("background", "bg", "background", names.background),
|
|
395
|
-
emit("text", "
|
|
456
|
+
emit("text", "text", "color", names.text),
|
|
396
457
|
emit("stroke", "border", "border-color", names.stroke)
|
|
397
458
|
].join("\n")}\n`;
|
|
398
459
|
}
|
|
@@ -414,10 +475,12 @@ function colorUtilitiesCss(names, options = {}) {
|
|
|
414
475
|
function tokenUtilitiesCss(groups, options = {}) {
|
|
415
476
|
const prefix = options.prefix || "";
|
|
416
477
|
const p = prefix ? `${prefix}-` : "";
|
|
478
|
+
const chainTargets = options.chainTargets ?? [];
|
|
417
479
|
return `/* InstUI token utilities (@pantoken/utils) — prefix: ${prefix} */\n${groups.flatMap(({ property, tokens }) => tokens.map((token) => {
|
|
418
480
|
const name = token.replace(/^--instui-/, "");
|
|
419
|
-
|
|
481
|
+
const modifier = `.-${name}`;
|
|
482
|
+
return `${[`.${p}${name}`, ...chainTargets.map((target) => `.${p}${target}${modifier}`)].join(", ")} { ${property}: var(${token}); }`;
|
|
420
483
|
})).join("\n")}\n`;
|
|
421
484
|
}
|
|
422
485
|
//#endregion
|
|
423
|
-
export { ELEVATION_NAMES, FOCUSABLE_SELECTOR, LIGHT_DARK_RE, VAR_RE, camelCase, colorUtilitiesCss, danglingReferences, elevationDeclarations, extractInstuiRefs, focusOutlineDeclarations, focusOutlineRules, makeResolver, parseHexColor, resolveTokens, sanitizeSvg, tokenNames, tokenUtilitiesCss, unknownReferences };
|
|
486
|
+
export { ELEVATION_NAMES, FOCUSABLE_SELECTOR, LIGHT_DARK_RE, SPACING_AUTO_STEP, SPACING_STEPS, VAR_RE, camelCase, colorUtilitiesCss, danglingReferences, elevationDeclarations, extractInstuiRefs, focusOutlineDeclarations, focusOutlineRules, makeResolver, parseHexColor, resolveTokens, sanitizeSvg, tokenNames, tokenUtilitiesCss, unknownReferences };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pantoken/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Shared pantoken helpers: token reference resolver, typed regexes (arkregex), name-case, and hex-colour parsing.",
|
|
5
5
|
"homepage": "https://pantoken.iywahl.com",
|
|
6
6
|
"bugs": "https://github.com/thedannywahl/pantoken/issues",
|