@pantoken/css 0.2.8 → 0.3.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.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { i as buildCssFile, n as leanCss, r as toCss, t as css } from "./src-DGq2ZbhV.mjs";
1
+ import { i as buildCssFile, n as leanCss, r as toCss, t as css } from "./src-YRQrYIS8.mjs";
2
2
  export { buildCssFile, css, css as default, leanCss, toCss };
package/dist/inject.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as css } from "./src-DGq2ZbhV.mjs";
1
+ import { t as css } from "./src-YRQrYIS8.mjs";
2
2
  //#region src/inject.ts
3
3
  /**
4
4
  * `@pantoken/css/inject` — a DOM side-effect entry. Importing it injects the pantoken stylesheet
@@ -1,6 +1,6 @@
1
- import { tokens } from "@pantoken/tokens";
2
1
  import { checkPlugins, definePlugin } from "@pantoken/plugin-kit";
3
2
  import { elevationDeclarations, focusOutlineDeclarations } from "@pantoken/utils";
3
+ import { byTheme } from "@pantoken/tokens";
4
4
  //#region src/foundation.ts
5
5
  /**
6
6
  * The elevation (`--instui-elevation-*`) and focus-outline (`--instui-focus-outline-*`) composite
@@ -14,6 +14,43 @@ const foundationPlugin = definePlugin({
14
14
  })
15
15
  });
16
16
  //#endregion
17
+ //#region src/theme-variants.ts
18
+ const ICON_TOKEN_PREFIX = "--instui-icon-";
19
+ function withoutIcons(tokens) {
20
+ return tokens.filter((t) => !t.name.startsWith(ICON_TOKEN_PREFIX));
21
+ }
22
+ function lightBranch(value) {
23
+ const trimmed = value.trim();
24
+ if (!trimmed.startsWith("light-dark(") || !trimmed.endsWith(")")) return null;
25
+ const inner = trimmed.slice(11, -1);
26
+ let depth = 0;
27
+ for (let i = 0; i < inner.length; i += 1) {
28
+ const char = inner[i];
29
+ if (char === "(") depth += 1;
30
+ else if (char === ")") depth = Math.max(0, depth - 1);
31
+ else if (char === "," && depth === 0) return inner.slice(0, i).trim();
32
+ }
33
+ return null;
34
+ }
35
+ function rebrandLightOnly(tokens) {
36
+ return tokens.map((token) => {
37
+ const light = lightBranch(token.value);
38
+ if (!light) return token;
39
+ return {
40
+ ...token,
41
+ value: light,
42
+ themed: false
43
+ };
44
+ });
45
+ }
46
+ /** Build a theme token set with optional icon removal and rebrand light-only collapse. */
47
+ function themedTokens(theme, options) {
48
+ const { includeIcons = true, lightOnly = false } = options ?? {};
49
+ const themeTokens = byTheme(theme);
50
+ const modeTokens = lightOnly ? rebrandLightOnly(themeTokens) : themeTokens;
51
+ return includeIcons ? modeTokens : withoutIcons(modeTokens);
52
+ }
53
+ //#endregion
17
54
  //#region src/emit.ts
18
55
  function renderSection(scope, { layer, pairs }) {
19
56
  const declarations = [
@@ -188,6 +225,9 @@ function appendContribution(c, prepends, appends) {
188
225
  * @module
189
226
  * @beta
190
227
  */
228
+ function themedCss(theme, options) {
229
+ return toCss(themedTokens(theme, options), { plugins: [foundationPlugin] });
230
+ }
191
231
  /**
192
232
  * The ready-made `rebrand` stylesheet string (typed: concrete tokens as `@property` registrations).
193
233
  *
@@ -198,9 +238,7 @@ function appendContribution(c, prepends, appends) {
198
238
  * document.head.insertAdjacentHTML("beforeend", `<style>${css}</style>`);
199
239
  * ```
200
240
  */
201
- const css = toCss(tokens, { plugins: [foundationPlugin] });
202
- /** The `--instui-icon-*` glyph tokens — the full icon set as data-URIs, ~86% of the sheet's bytes. */
203
- const ICON_TOKEN_PREFIX = "--instui-icon-";
241
+ const css = themedCss("rebrand");
204
242
  /**
205
243
  * The lean `rebrand` stylesheet string — the full sheet minus the `--instui-icon-*` glyph tokens (the
206
244
  * ~1,777 icon data-URIs that make up most of {@link css}). Roughly a sixth the size over the wire; the
@@ -214,6 +252,6 @@ const ICON_TOKEN_PREFIX = "--instui-icon-";
214
252
  * import { leanCss } from "@pantoken/css";
215
253
  * ```
216
254
  */
217
- const leanCss = toCss(tokens.filter((t) => !t.name.startsWith(ICON_TOKEN_PREFIX)), { plugins: [foundationPlugin] });
255
+ const leanCss = toCss(themedTokens("rebrand", { includeIcons: false }), { plugins: [foundationPlugin] });
218
256
  //#endregion
219
257
  export { buildCssFile as i, leanCss as n, toCss as r, css as t };