@pure-ds/core 0.3.2 → 0.3.4
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/types/src/js/pds-core/pds-generator.d.ts +2 -0
- package/dist/types/src/js/pds-core/pds-generator.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-registry.d.ts +2 -7
- package/dist/types/src/js/pds-core/pds-registry.d.ts.map +1 -1
- package/dist/types/src/js/pds.d.ts.map +1 -1
- package/package.json +1 -1
- package/public/assets/js/app.js +9777 -430
- package/public/assets/js/app.js.map +7 -0
- package/public/assets/js/lit.js +1048 -3
- package/public/assets/js/lit.js.map +7 -0
- package/public/assets/js/pds.js +6665 -309
- package/public/assets/js/pds.js.map +7 -0
- package/src/js/pds-core/pds-generator.js +38 -9
- package/src/js/pds-core/pds-registry.js +7 -57
- package/src/js/pds.js +25 -16
|
@@ -5,6 +5,13 @@ import { registry as pdsRegistry } from "./pds-registry.js";
|
|
|
5
5
|
* Generates comprehensive CSS variables and styles from a minimal configuration
|
|
6
6
|
*/
|
|
7
7
|
export class Generator {
|
|
8
|
+
// Singleton instance
|
|
9
|
+
static #instance;
|
|
10
|
+
|
|
11
|
+
static get instance() {
|
|
12
|
+
return this.#instance;
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
// Private internal fields
|
|
9
16
|
#layers;
|
|
10
17
|
#stylesheets;
|
|
@@ -24,6 +31,10 @@ export class Generator {
|
|
|
24
31
|
if (this.options.debug) {
|
|
25
32
|
this.options.log?.("debug", "Generator options:", this.options);
|
|
26
33
|
}
|
|
34
|
+
|
|
35
|
+
// Set singleton instance
|
|
36
|
+
Generator.#instance = this;
|
|
37
|
+
|
|
27
38
|
this.tokens = this.generateTokens();
|
|
28
39
|
if (this.options.debug) {
|
|
29
40
|
this.options.log?.("debug", "Generated tokens:", this.tokens);
|
|
@@ -5115,23 +5126,23 @@ export const ${name}CSS = \`${escapedCSS}\`;
|
|
|
5115
5126
|
/**
|
|
5116
5127
|
* Static method to apply styles to document
|
|
5117
5128
|
* Creates a link element with BLOB URL
|
|
5118
|
-
* @param {Generator} generator -
|
|
5129
|
+
* @param {Generator} [generator] - Optional Generator instance (defaults to singleton)
|
|
5119
5130
|
*/
|
|
5120
5131
|
static applyStyles(generator) {
|
|
5132
|
+
// Use provided generator or singleton instance
|
|
5133
|
+
const target = generator || Generator.instance;
|
|
5134
|
+
|
|
5121
5135
|
// Validate parameter
|
|
5122
|
-
if (!
|
|
5123
|
-
generator
|
|
5124
|
-
"error",
|
|
5125
|
-
"[Generator] applyStyles requires a generator object"
|
|
5126
|
-
);
|
|
5136
|
+
if (!target || typeof target !== "object") {
|
|
5137
|
+
console.error("[Generator] applyStyles requires a generator object or active singleton");
|
|
5127
5138
|
return;
|
|
5128
5139
|
}
|
|
5129
5140
|
|
|
5130
5141
|
// Preferred: apply layered CSS so tokens + primitives + components + utilities
|
|
5131
5142
|
// are available in light DOM (ensures primitives like :where(button):active apply)
|
|
5132
|
-
const cssText =
|
|
5143
|
+
const cssText = target.layeredCSS || target.css || "";
|
|
5133
5144
|
if (!cssText) {
|
|
5134
|
-
|
|
5145
|
+
target.options?.log?.(
|
|
5135
5146
|
"warn",
|
|
5136
5147
|
"[Generator] No CSS available on designer to apply"
|
|
5137
5148
|
);
|
|
@@ -5268,7 +5279,25 @@ export async function adoptLayers(
|
|
|
5268
5279
|
try {
|
|
5269
5280
|
// Get all requested stylesheets
|
|
5270
5281
|
const stylesheets = await Promise.all(
|
|
5271
|
-
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
|
+
})
|
|
5272
5301
|
);
|
|
5273
5302
|
|
|
5274
5303
|
// Filter out any null results
|
|
@@ -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 {
|
|
@@ -79,30 +60,6 @@ class PDSRegistry {
|
|
|
79
60
|
}
|
|
80
61
|
}
|
|
81
62
|
|
|
82
|
-
// /**
|
|
83
|
-
// * Get BLOB URL for a layer (live mode only)
|
|
84
|
-
// * Used for @import statements in CSS
|
|
85
|
-
// */
|
|
86
|
-
// getBlobURL(layer) {
|
|
87
|
-
// if (this._mode === "live" && this._designer) {
|
|
88
|
-
// switch (layer) {
|
|
89
|
-
// case "tokens":
|
|
90
|
-
// return this._designer.tokensBlobURL;
|
|
91
|
-
// case "primitives":
|
|
92
|
-
// return this._designer.primitivesBlobURL;
|
|
93
|
-
// case "components":
|
|
94
|
-
// return this._designer.componentsBlobURL;
|
|
95
|
-
// case "utilities":
|
|
96
|
-
// return this._designer.utilitiesBlobURL;
|
|
97
|
-
// case "styles":
|
|
98
|
-
// return this._designer.stylesBlobURL;
|
|
99
|
-
// default:
|
|
100
|
-
// return null;
|
|
101
|
-
// }
|
|
102
|
-
// }
|
|
103
|
-
// return null;
|
|
104
|
-
// }
|
|
105
|
-
|
|
106
63
|
/**
|
|
107
64
|
* Get current mode
|
|
108
65
|
*/
|
|
@@ -114,14 +71,7 @@ class PDSRegistry {
|
|
|
114
71
|
* Check if in live mode
|
|
115
72
|
*/
|
|
116
73
|
get isLive() {
|
|
117
|
-
return this._mode === "live"
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Check if designer is available
|
|
122
|
-
*/
|
|
123
|
-
get hasDesigner() {
|
|
124
|
-
return this._designer !== null;
|
|
74
|
+
return this._mode === "live";
|
|
125
75
|
}
|
|
126
76
|
}
|
|
127
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,14 +1154,19 @@ 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) {
|
|
1160
|
-
await PDS.Generator.applyStyles(
|
|
1169
|
+
await PDS.Generator.applyStyles();
|
|
1161
1170
|
|
|
1162
1171
|
// Clean up critical styles after adoptedStyleSheets are applied
|
|
1163
1172
|
if (typeof window !== "undefined") {
|
|
@@ -1459,19 +1468,19 @@ 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
|
-
await PDS.Generator.applyStyles(
|
|
1480
|
+
await PDS.Generator.applyStyles();
|
|
1472
1481
|
}
|
|
1473
1482
|
} catch (error) {
|
|
1474
|
-
|
|
1483
|
+
console.warn("Failed to update styles for new theme:", error);
|
|
1475
1484
|
}
|
|
1476
1485
|
}
|
|
1477
1486
|
|