origam 2.27.0 → 2.29.2

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/dist/src/assets/css/main.css +1 -1
  3. package/dist/src/assets/css/tokens/dark.css +2 -0
  4. package/dist/src/assets/css/tokens/light.css +1 -0
  5. package/dist/src/assets/scss/tokens/_dark.scss +2 -0
  6. package/dist/src/assets/scss/tokens/_light.scss +1 -0
  7. package/dist/src/components/Btn/OrigamBtn.vue +53 -14
  8. package/dist/src/components/Chart/OrigamChartCartesian.vue +1 -1
  9. package/dist/src/components/Chart/OrigamChartPolar.vue +1 -1
  10. package/dist/src/components/Chip/OrigamChip.vue +1 -1
  11. package/dist/src/components/Code/OrigamCode.vue +0 -2
  12. package/dist/src/composables/Commons/style.composable.cjs +14 -1
  13. package/dist/src/composables/Commons/style.composable.d.ts +0 -14
  14. package/dist/src/composables/Commons/style.composable.js +13 -2
  15. package/dist/src/composables/Commons/styleTag.composable.cjs +10 -4
  16. package/dist/src/composables/Commons/styleTag.composable.js +11 -5
  17. package/dist/src/consts/Commons/ssr-style.const.cjs +8 -0
  18. package/dist/src/consts/Commons/ssr-style.const.d.ts +19 -0
  19. package/dist/src/consts/Commons/ssr-style.const.js +2 -0
  20. package/dist/src/consts/index.cjs +11 -0
  21. package/dist/src/consts/index.d.ts +1 -0
  22. package/dist/src/consts/index.js +1 -0
  23. package/dist/src/directives/Contrast/contrast.directive.cjs +58 -6
  24. package/dist/src/directives/Contrast/contrast.directive.d.ts +10 -0
  25. package/dist/src/directives/Contrast/contrast.directive.js +61 -9
  26. package/dist/src/interfaces/Btn/btn.interface.d.ts +1 -0
  27. package/dist/src/interfaces/Commons/commons.interface.d.ts +14 -0
  28. package/dist/src/interfaces/Commons/nuxt-module.interface.d.ts +18 -4
  29. package/dist/src/interfaces/Commons/style.interface.d.ts +21 -0
  30. package/dist/src/nuxt/module.d.ts +8 -2
  31. package/dist/src/nuxt/plugin.client.cjs +10 -2
  32. package/dist/src/nuxt/plugin.client.js +12 -4
  33. package/dist/src/nuxt/plugin.server.cjs +29 -20
  34. package/dist/src/nuxt/plugin.server.js +26 -22
  35. package/dist/src/origam.cjs +3 -0
  36. package/dist/src/origam.js +5 -1
  37. package/dist/src/types/tokens.type.d.ts +1 -1
  38. package/dist/src/utils/Commons/apply-theme.util.cjs +20 -0
  39. package/dist/src/utils/Commons/apply-theme.util.d.ts +34 -0
  40. package/dist/src/utils/Commons/apply-theme.util.js +18 -0
  41. package/dist/src/utils/Commons/ssr-styles.util.cjs +41 -0
  42. package/dist/src/utils/Commons/ssr-styles.util.d.ts +6 -0
  43. package/dist/src/utils/Commons/ssr-styles.util.js +26 -0
  44. package/dist/src/utils/index.cjs +11 -0
  45. package/dist/src/utils/index.d.ts +1 -0
  46. package/dist/src/utils/index.js +1 -0
  47. package/package.json +1 -1
@@ -6,10 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.applyTheme = applyTheme;
7
7
  exports.applyThemes = applyThemes;
8
8
  exports.installedThemesFromList = installedThemesFromList;
9
+ exports.isModePinned = isModePinned;
9
10
  exports.resolveThemeVars = resolveThemeVars;
10
11
  exports.semanticTreeToVars = semanticTreeToVars;
11
12
  exports.themeSelector = themeSelector;
12
13
  exports.themeToCss = themeToCss;
14
+ exports.themeToUnpinnedCss = themeToUnpinnedCss;
13
15
  exports.themeVarsToVars = themeVarsToVars;
14
16
  var _tokenName = require("./token-name.util.cjs");
15
17
  const STYLE_ELEMENT_PREFIX = "origam-theme";
@@ -91,6 +93,24 @@ ${decls}
91
93
  }
92
94
  `;
93
95
  }
96
+ function isModePinned(cookieValue, defaultMode) {
97
+ const concrete = v => v === "light" || v === "dark";
98
+ return concrete(cookieValue) || concrete(defaultMode);
99
+ }
100
+ function themeToUnpinnedCss(theme) {
101
+ if (theme.mode !== "light" && theme.mode !== "dark") return "";
102
+ const vars = resolveThemeVars(theme);
103
+ const decls = Object.keys(vars).map(name => ` ${name}: ${vars[name]};`).join("\n");
104
+ const hasName = typeof theme.name === "string" && theme.name.length > 0;
105
+ const selector = hasName ? `:root:root[data-theme="${theme.name}"]:not([data-mode])` : "html:not([data-theme]):not([data-mode])";
106
+ const query = theme.mode === "dark" ? "(prefers-color-scheme: dark)" : "not (prefers-color-scheme: dark)";
107
+ return `@media ${query} {
108
+ ${selector} {
109
+ ${decls}
110
+ }
111
+ }
112
+ `;
113
+ }
94
114
  function applyTheme(theme) {
95
115
  if (typeof document === "undefined") return null;
96
116
  const vars = resolveThemeVars(theme);
@@ -42,6 +42,40 @@ export declare function themeSelector(theme: IOrigamTheme): string;
42
42
  * the Theme Builder's CSS export so a single code path produces both.
43
43
  */
44
44
  export declare function themeToCss(theme: IOrigamTheme): string;
45
+ /*********************************************************
46
+ * isModePinned
47
+ *
48
+ * @description
49
+ * Is the colour mode PINNED by the visitor or the configuration? Pinned means a
50
+ * `light` / `dark` mode cookie, or a configured `defaultMode` of `light` /
51
+ * `dark`. Anything else (`auto`, absent, junk) leaves the mode to the system.
52
+ * @description
53
+ * Shared by both Nuxt plugins so server and client never disagree on it (#1103).
54
+ ********************************************************/
55
+ export declare function isModePinned(cookieValue: string | null | undefined, defaultMode: string | undefined): boolean;
56
+ /*********************************************************
57
+ * themeToUnpinnedCss
58
+ *
59
+ * @description
60
+ * Serialise a MODE-SCOPED theme (`mode` = `light` | `dark`) for a page whose
61
+ * mode is NOT pinned (#1103): no `data-mode` on `<html>`, the system decides.
62
+ * Returns `''` for a mode-agnostic theme — its selector never mentions
63
+ * `data-mode`, so the plain `themeToCss` block already serves both modes.
64
+ * @description
65
+ * light → wrapped in `@media not (prefers-color-scheme: dark)`; dark → wrapped
66
+ * in `@media (prefers-color-scheme: dark)`.
67
+ * @description
68
+ * Selectors are ROOT-ONLY and carry `:not([data-mode])`, so the moment a mode is
69
+ * pinned (the client writes `data-mode`) they stop matching and the regular
70
+ * `[data-mode]` blocks take over. No sub-tree form is emitted on purpose: an
71
+ * `<OrigamThemeProvider>` nested in a pinned page must never match them.
72
+ * @description
73
+ * Specificity is kept equal to the pinned form: named brand
74
+ * `:root:root[…]:not([data-mode])` = (0,4,0); unnamed
75
+ * `html:not([data-theme]):not([data-mode])` = (0,2,1), which beats the built-in
76
+ * #794 rule (0,2,0) and stays under every named brand.
77
+ ********************************************************/
78
+ export declare function themeToUnpinnedCss(theme: IOrigamTheme): string;
45
79
  /**
46
80
  * Inject (or replace) a theme's CSS variables into `<head>` at runtime.
47
81
  * SSR-safe: a no-op when `document` is unavailable. Returns the `<style>`
@@ -72,6 +72,24 @@ ${decls}
72
72
  }
73
73
  `;
74
74
  }
75
+ export function isModePinned(cookieValue, defaultMode) {
76
+ const concrete = (v) => v === "light" || v === "dark";
77
+ return concrete(cookieValue) || concrete(defaultMode);
78
+ }
79
+ export function themeToUnpinnedCss(theme) {
80
+ if (theme.mode !== "light" && theme.mode !== "dark") return "";
81
+ const vars = resolveThemeVars(theme);
82
+ const decls = Object.keys(vars).map((name) => ` ${name}: ${vars[name]};`).join("\n");
83
+ const hasName = typeof theme.name === "string" && theme.name.length > 0;
84
+ const selector = hasName ? `:root:root[data-theme="${theme.name}"]:not([data-mode])` : "html:not([data-theme]):not([data-mode])";
85
+ const query = theme.mode === "dark" ? "(prefers-color-scheme: dark)" : "not (prefers-color-scheme: dark)";
86
+ return `@media ${query} {
87
+ ${selector} {
88
+ ${decls}
89
+ }
90
+ }
91
+ `;
92
+ }
75
93
  export function applyTheme(theme) {
76
94
  if (typeof document === "undefined") return null;
77
95
  const vars = resolveThemeVars(theme);
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createSsrStyleCollector = createSsrStyleCollector;
7
+ exports.getSsrStyles = getSsrStyles;
8
+ exports.registerSsrStyleCollector = registerSsrStyleCollector;
9
+ exports.renderSsrStyles = renderSsrStyles;
10
+ const collectors = /* @__PURE__ */new WeakMap();
11
+ function escapeStyleText(css) {
12
+ return css.replace(/<\/(style)/gi, "<\\/$1");
13
+ }
14
+ function createSsrStyleCollector() {
15
+ const getters = /* @__PURE__ */new Map();
16
+ return {
17
+ add(id, css) {
18
+ getters.set(id, css);
19
+ },
20
+ entries() {
21
+ return [...getters].map(([id, css]) => ({
22
+ id,
23
+ css: escapeStyleText(css())
24
+ }));
25
+ }
26
+ };
27
+ }
28
+ function registerSsrStyleCollector(app) {
29
+ const collector = createSsrStyleCollector();
30
+ collectors.set(app, collector);
31
+ return collector;
32
+ }
33
+ function getSsrStyles(app) {
34
+ return collectors.get(app)?.entries() ?? [];
35
+ }
36
+ function renderSsrStyles(app) {
37
+ return getSsrStyles(app).map(({
38
+ id,
39
+ css
40
+ }) => `<style id="${id}">${css}</style>`).join("");
41
+ }
@@ -0,0 +1,6 @@
1
+ import type { App } from 'vue';
2
+ import type { ISsrStyleCollector, ISsrStyleEntry } from '../../interfaces/Commons/style.interface';
3
+ export declare function createSsrStyleCollector(): ISsrStyleCollector;
4
+ export declare function registerSsrStyleCollector(app: App): ISsrStyleCollector;
5
+ export declare function getSsrStyles(app: App): ISsrStyleEntry[];
6
+ export declare function renderSsrStyles(app: App): string;
@@ -0,0 +1,26 @@
1
+ const collectors = /* @__PURE__ */ new WeakMap();
2
+ function escapeStyleText(css) {
3
+ return css.replace(/<\/(style)/gi, "<\\/$1");
4
+ }
5
+ export function createSsrStyleCollector() {
6
+ const getters = /* @__PURE__ */ new Map();
7
+ return {
8
+ add(id, css) {
9
+ getters.set(id, css);
10
+ },
11
+ entries() {
12
+ return [...getters].map(([id, css]) => ({ id, css: escapeStyleText(css()) }));
13
+ }
14
+ };
15
+ }
16
+ export function registerSsrStyleCollector(app) {
17
+ const collector = createSsrStyleCollector();
18
+ collectors.set(app, collector);
19
+ return collector;
20
+ }
21
+ export function getSsrStyles(app) {
22
+ return collectors.get(app)?.entries() ?? [];
23
+ }
24
+ export function renderSsrStyles(app) {
25
+ return getSsrStyles(app).map(({ id, css }) => `<style id="${id}">${css}</style>`).join("");
26
+ }
@@ -157,6 +157,17 @@ Object.keys(_getCurrentInstance).forEach(function (key) {
157
157
  }
158
158
  });
159
159
  });
160
+ var _ssrStyles = require("./Commons/ssr-styles.util.cjs");
161
+ Object.keys(_ssrStyles).forEach(function (key) {
162
+ if (key === "default" || key === "__esModule") return;
163
+ if (key in exports && exports[key] === _ssrStyles[key]) return;
164
+ Object.defineProperty(exports, key, {
165
+ enumerable: true,
166
+ get: function () {
167
+ return _ssrStyles[key];
168
+ }
169
+ });
170
+ });
160
171
  var _layout = require("./Commons/layout.util.cjs");
161
172
  Object.keys(_layout).forEach(function (key) {
162
173
  if (key === "default" || key === "__esModule") return;
@@ -12,6 +12,7 @@ export * from './Commons/css-support.util';
12
12
  export * from './Commons/date.util';
13
13
  export * from './Commons/elevation.util';
14
14
  export * from './Commons/getCurrentInstance.util';
15
+ export * from './Commons/ssr-styles.util';
15
16
  export * from './Commons/layout.util';
16
17
  export * from './Commons/locale.util';
17
18
  export * from './Commons/nested.util';
@@ -12,6 +12,7 @@ export * from "./Commons/css-support.util.js";
12
12
  export * from "./Commons/date.util.js";
13
13
  export * from "./Commons/elevation.util.js";
14
14
  export * from "./Commons/getCurrentInstance.util.js";
15
+ export * from "./Commons/ssr-styles.util.js";
15
16
  export * from "./Commons/layout.util.js";
16
17
  export * from "./Commons/locale.util.js";
17
18
  export * from "./Commons/nested.util.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "origam",
3
- "version": "2.27.0",
3
+ "version": "2.29.2",
4
4
  "type": "module",
5
5
  "description": "origam — a Vue 3 design system with multi-theme design tokens, CSS-first components and TypeScript types.",
6
6
  "keywords": [