@pantoken/utils 0.3.0 → 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 CHANGED
@@ -284,18 +284,30 @@ interface UtilityOptions {
284
284
  * falsy value (`null`/`undefined`/`""`) drops the prefix entirely (`.bg-…`).
285
285
  */
286
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[];
287
294
  }
288
- /** The semantic colour token names (without the `--instui-color-<family>-` prefix) per family. */
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. */
289
300
  interface ColorUtilityNames {
290
- background: readonly string[];
291
- text: readonly string[];
292
- stroke: readonly string[];
301
+ background: readonly ColorUtilityEntry[];
302
+ text: readonly ColorUtilityEntry[];
303
+ stroke: readonly ColorUtilityEntry[];
293
304
  }
294
305
  /**
295
306
  * Build the semantic-colour utility stylesheet: `.<prefix>-bg-<name>` (background),
296
- * `.<prefix>-fg-<name>` (text colour), `.<prefix>-border-<name>` (border colour), one per semantic
307
+ * `.<prefix>-text-<name>` (text colour), `.<prefix>-border-<name>` (border colour), one per semantic
297
308
  * colour token. Overrides are therefore only ever token-valid — no primitives, no arbitrary hex. Pass
298
- * 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.
299
311
  *
300
312
  * @param names - {@link ColorUtilityNames}.
301
313
  * @param options - {@link UtilityOptions}.
@@ -328,4 +340,4 @@ interface TokenUtilityGroup {
328
340
  */
329
341
  declare function tokenUtilitiesCss(groups: readonly TokenUtilityGroup[], options?: UtilityOptions): string;
330
342
  //#endregion
331
- export { 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 };
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
@@ -429,9 +429,10 @@ function danglingReferences(css) {
429
429
  }
430
430
  /**
431
431
  * Build the semantic-colour utility stylesheet: `.<prefix>-bg-<name>` (background),
432
- * `.<prefix>-fg-<name>` (text colour), `.<prefix>-border-<name>` (border colour), one per semantic
432
+ * `.<prefix>-text-<name>` (text colour), `.<prefix>-border-<name>` (border colour), one per semantic
433
433
  * colour token. Overrides are therefore only ever token-valid — no primitives, no arbitrary hex. Pass
434
- * 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.
435
436
  *
436
437
  * @param names - {@link ColorUtilityNames}.
437
438
  * @param options - {@link UtilityOptions}.
@@ -442,10 +443,17 @@ function danglingReferences(css) {
442
443
  function colorUtilitiesCss(names, options = {}) {
443
444
  const prefix = options.prefix || "";
444
445
  const p = prefix ? `${prefix}-` : "";
445
- const emit = (family, util, prop, list) => list.map((n) => `.${p}${util}-${n} { ${prop}: var(--instui-color-${family}-${n}); }`).join("\n");
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");
446
454
  return `/* InstUI semantic colour utilities (@pantoken/utils) — prefix: ${prefix} */\n${[
447
455
  emit("background", "bg", "background", names.background),
448
- emit("text", "fg", "color", names.text),
456
+ emit("text", "text", "color", names.text),
449
457
  emit("stroke", "border", "border-color", names.stroke)
450
458
  ].join("\n")}\n`;
451
459
  }
@@ -467,9 +475,11 @@ function colorUtilitiesCss(names, options = {}) {
467
475
  function tokenUtilitiesCss(groups, options = {}) {
468
476
  const prefix = options.prefix || "";
469
477
  const p = prefix ? `${prefix}-` : "";
478
+ const chainTargets = options.chainTargets ?? [];
470
479
  return `/* InstUI token utilities (@pantoken/utils) — prefix: ${prefix} */\n${groups.flatMap(({ property, tokens }) => tokens.map((token) => {
471
480
  const name = token.replace(/^--instui-/, "");
472
- return `.${p}${name} { ${property}: var(${token}); }`;
481
+ const modifier = `.-${name}`;
482
+ return `${[`.${p}${name}`, ...chainTargets.map((target) => `.${p}${target}${modifier}`)].join(", ")} { ${property}: var(${token}); }`;
473
483
  })).join("\n")}\n`;
474
484
  }
475
485
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pantoken/utils",
3
- "version": "0.3.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",