@pure-ds/storybook 0.1.11 → 0.1.12
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/package.json +1 -1
- package/src/js/pds-core/pds-generator.js +33 -2
- package/src/js/pds-core/pds-registry.js +7 -33
- package/src/js/pds.js +22 -13
package/package.json
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
+
import { registry as pdsRegistry } from "./pds-registry.js";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Generator - A JS-config-first design system
|
|
3
5
|
* Generates comprehensive CSS variables and styles from a minimal configuration
|
|
4
6
|
*/
|
|
5
7
|
export class Generator {
|
|
8
|
+
// Singleton instance
|
|
9
|
+
static #instance;
|
|
10
|
+
|
|
11
|
+
static get instance() {
|
|
12
|
+
return this.#instance;
|
|
13
|
+
}
|
|
14
|
+
|
|
6
15
|
// Private internal fields
|
|
7
16
|
#layers;
|
|
8
17
|
#stylesheets;
|
|
@@ -22,6 +31,10 @@ export class Generator {
|
|
|
22
31
|
if (this.options.debug) {
|
|
23
32
|
this.options.log?.("debug", "Generator options:", this.options);
|
|
24
33
|
}
|
|
34
|
+
|
|
35
|
+
// Set singleton instance
|
|
36
|
+
Generator.#instance = this;
|
|
37
|
+
|
|
25
38
|
this.tokens = this.generateTokens();
|
|
26
39
|
if (this.options.debug) {
|
|
27
40
|
this.options.log?.("debug", "Generated tokens:", this.tokens);
|
|
@@ -5266,7 +5279,25 @@ export async function adoptLayers(
|
|
|
5266
5279
|
try {
|
|
5267
5280
|
// Get all requested stylesheets
|
|
5268
5281
|
const stylesheets = await Promise.all(
|
|
5269
|
-
layers.map((layer) =>
|
|
5282
|
+
layers.map(async (layer) => {
|
|
5283
|
+
// In live mode, get stylesheets directly from the Generator singleton
|
|
5284
|
+
if (Generator.instance) {
|
|
5285
|
+
switch (layer) {
|
|
5286
|
+
case "tokens":
|
|
5287
|
+
return Generator.instance.tokensStylesheet;
|
|
5288
|
+
case "primitives":
|
|
5289
|
+
return Generator.instance.primitivesStylesheet;
|
|
5290
|
+
case "components":
|
|
5291
|
+
return Generator.instance.componentsStylesheet;
|
|
5292
|
+
case "utilities":
|
|
5293
|
+
return Generator.instance.utilitiesStylesheet;
|
|
5294
|
+
default:
|
|
5295
|
+
// Fall through to registry for unknown layers or static fallback
|
|
5296
|
+
break;
|
|
5297
|
+
}
|
|
5298
|
+
}
|
|
5299
|
+
return pdsRegistry.getStylesheet(layer);
|
|
5300
|
+
})
|
|
5270
5301
|
);
|
|
5271
5302
|
|
|
5272
5303
|
// Filter out any null results
|
|
@@ -5311,7 +5342,7 @@ export function createStylesheet(css) {
|
|
|
5311
5342
|
* @returns {boolean}
|
|
5312
5343
|
*/
|
|
5313
5344
|
export function isLiveMode() {
|
|
5314
|
-
return
|
|
5345
|
+
return pdsRegistry.isLive;
|
|
5315
5346
|
}
|
|
5316
5347
|
import { enums } from "./pds-enums.js";
|
|
5317
5348
|
import { ontology } from "./pds-ontology.js";
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
class PDSRegistry {
|
|
7
7
|
constructor() {
|
|
8
8
|
this._mode = "static"; // Default to static mode
|
|
9
|
-
this._designer = null;
|
|
10
9
|
this._staticPaths = {
|
|
11
10
|
tokens: "/assets/pds/styles/pds-tokens.css.js",
|
|
12
11
|
primitives: "/assets/pds/styles/pds-primitives.css.js",
|
|
@@ -17,17 +16,10 @@ class PDSRegistry {
|
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
/**
|
|
20
|
-
*
|
|
19
|
+
* Switch to live mode
|
|
21
20
|
*/
|
|
22
|
-
|
|
23
|
-
this._designer = designer;
|
|
21
|
+
setLiveMode() {
|
|
24
22
|
this._mode = "live";
|
|
25
|
-
const presetName = meta?.presetName;
|
|
26
|
-
if (presetName) {
|
|
27
|
-
designer?.options?.log?.("log", `PDS live with preset "${presetName}"`);
|
|
28
|
-
} else {
|
|
29
|
-
designer?.options?.log?.("log", "PDS live with custom config");
|
|
30
|
-
}
|
|
31
23
|
}
|
|
32
24
|
|
|
33
25
|
/**
|
|
@@ -46,21 +38,10 @@ class PDSRegistry {
|
|
|
46
38
|
* Returns CSSStyleSheet object (constructable stylesheet)
|
|
47
39
|
*/
|
|
48
40
|
async getStylesheet(layer) {
|
|
49
|
-
if (this._mode === "live"
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return this._designer.tokensStylesheet;
|
|
54
|
-
case "primitives":
|
|
55
|
-
return this._designer.primitivesStylesheet;
|
|
56
|
-
case "components":
|
|
57
|
-
return this._designer.componentsStylesheet;
|
|
58
|
-
case "utilities":
|
|
59
|
-
return this._designer.utilitiesStylesheet;
|
|
60
|
-
default:
|
|
61
|
-
this._designer?.options?.log?.("warn", `[PDS Registry] Unknown layer: ${layer}`);
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
41
|
+
if (this._mode === "live") {
|
|
42
|
+
// In live mode, stylesheets should be retrieved from Generator.instance
|
|
43
|
+
// If we are here, it means adoptLayers fell back or something is wrong
|
|
44
|
+
return null;
|
|
64
45
|
} else {
|
|
65
46
|
// Import from static path
|
|
66
47
|
try {
|
|
@@ -90,14 +71,7 @@ class PDSRegistry {
|
|
|
90
71
|
* Check if in live mode
|
|
91
72
|
*/
|
|
92
73
|
get isLive() {
|
|
93
|
-
return this._mode === "live"
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Check if designer is available
|
|
98
|
-
*/
|
|
99
|
-
get hasDesigner() {
|
|
100
|
-
return this._designer !== null;
|
|
74
|
+
return this._mode === "live";
|
|
101
75
|
}
|
|
102
76
|
}
|
|
103
77
|
|
package/src/js/pds.js
CHANGED
|
@@ -40,6 +40,10 @@ class PDSBase extends EventTarget {}
|
|
|
40
40
|
/** @type {PDSAPI & PDSBase} */
|
|
41
41
|
const PDS = new PDSBase();
|
|
42
42
|
|
|
43
|
+
// State properties
|
|
44
|
+
PDS.initializing = false;
|
|
45
|
+
PDS.currentPreset = null;
|
|
46
|
+
|
|
43
47
|
import {
|
|
44
48
|
Generator,
|
|
45
49
|
adoptLayers,
|
|
@@ -64,7 +68,7 @@ import { loadTypographyFonts } from "./common/font-loader.js";
|
|
|
64
68
|
/** Generator class — use to programmatically create design system assets from a config */
|
|
65
69
|
PDS.Generator = Generator;
|
|
66
70
|
|
|
67
|
-
/** Singleton runtime registry. Use `registry.
|
|
71
|
+
/** Singleton runtime registry. Use `registry.setLiveMode()` to enable live mode or `registry.setStaticMode()` for static assets */
|
|
68
72
|
PDS.registry = registry;
|
|
69
73
|
|
|
70
74
|
/** Ontology and metadata about components and tokens */
|
|
@@ -163,8 +167,8 @@ Object.defineProperty(PDS, "currentConfig", {
|
|
|
163
167
|
Object.defineProperty(PDS, "compiled", {
|
|
164
168
|
get() {
|
|
165
169
|
// Only available in live mode when we have a generator
|
|
166
|
-
if (PDS.registry?.isLive &&
|
|
167
|
-
return
|
|
170
|
+
if (PDS.registry?.isLive && Generator.instance) {
|
|
171
|
+
return Generator.instance.compiled;
|
|
168
172
|
}
|
|
169
173
|
return null;
|
|
170
174
|
},
|
|
@@ -1150,10 +1154,15 @@ async function live(config) {
|
|
|
1150
1154
|
}
|
|
1151
1155
|
}
|
|
1152
1156
|
|
|
1153
|
-
// Set the registry to
|
|
1154
|
-
PDS.registry.
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
+
// Set the registry to live mode
|
|
1158
|
+
PDS.registry.setLiveMode();
|
|
1159
|
+
|
|
1160
|
+
// Log preset info if available
|
|
1161
|
+
if (normalized.presetInfo?.name) {
|
|
1162
|
+
generatorConfig?.log?.("log", `PDS live with preset "${normalized.presetInfo.name}"`);
|
|
1163
|
+
} else {
|
|
1164
|
+
generatorConfig?.log?.("log", "PDS live with custom config");
|
|
1165
|
+
}
|
|
1157
1166
|
|
|
1158
1167
|
// Apply styles globally if requested (default behavior)
|
|
1159
1168
|
if (applyGlobalStyles) {
|
|
@@ -1459,13 +1468,13 @@ async function setTheme(theme, options = {}) {
|
|
|
1459
1468
|
}
|
|
1460
1469
|
|
|
1461
1470
|
// If we're in live mode, regenerate styles with new theme
|
|
1462
|
-
if (PDS.registry.isLive &&
|
|
1471
|
+
if (PDS.registry.isLive && Generator.instance) {
|
|
1463
1472
|
try {
|
|
1464
|
-
const
|
|
1465
|
-
if (
|
|
1466
|
-
// Update the
|
|
1467
|
-
const newConfig = { ...
|
|
1468
|
-
|
|
1473
|
+
const currentGenerator = Generator.instance;
|
|
1474
|
+
if (currentGenerator && currentGenerator.configure) {
|
|
1475
|
+
// Update the generator's config with new theme
|
|
1476
|
+
const newConfig = { ...currentGenerator.config, theme: resolvedTheme };
|
|
1477
|
+
currentGenerator.configure(newConfig);
|
|
1469
1478
|
|
|
1470
1479
|
// Reapply styles
|
|
1471
1480
|
await PDS.Generator.applyStyles(currentDesigner);
|