@pure-ds/core 0.5.60 → 0.6.1
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/packages/pds-configurator/src/pds-home-content.d.ts +375 -0
- package/dist/types/packages/pds-configurator/src/pds-home-content.d.ts.map +1 -0
- package/dist/types/packages/pds-configurator/src/pds-home.d.ts +2 -0
- package/dist/types/packages/pds-configurator/src/pds-home.d.ts.map +1 -0
- package/dist/types/pds.config.d.ts +4 -8
- package/dist/types/pds.config.d.ts.map +1 -1
- package/dist/types/pds.d.ts +3 -1
- package/dist/types/public/assets/js/pds-manager.d.ts.map +1 -1
- package/dist/types/public/assets/js/pds.d.ts.map +1 -1
- package/dist/types/public/assets/pds/components/pds-live-edit.d.ts +150 -0
- package/dist/types/public/assets/pds/components/pds-live-edit.d.ts.map +1 -0
- package/dist/types/public/assets/pds/components/pds-omnibox.d.ts +2 -0
- package/dist/types/public/assets/pds/components/pds-omnibox.d.ts.map +1 -1
- package/dist/types/public/assets/pds/components/pds-richtext.d.ts.map +1 -1
- package/dist/types/public/assets/pds/components/pds-theme.d.ts +5 -0
- package/dist/types/public/assets/pds/components/pds-theme.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-config.d.ts +457 -0
- package/dist/types/src/js/pds-core/pds-config.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-enhancers.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-live.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-ontology.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-start-helpers.d.ts.map +1 -1
- package/dist/types/src/js/pds-core/pds-theme-utils.d.ts +6 -0
- package/dist/types/src/js/pds-core/pds-theme-utils.d.ts.map +1 -0
- package/dist/types/src/js/pds.d.ts.map +1 -1
- package/package.json +1 -4
- package/packages/pds-cli/bin/templates/bootstrap/pds.config.js +9 -2
- package/public/assets/js/app.js +106 -5636
- package/public/assets/js/pds-manager.js +156 -156
- package/public/assets/js/pds.js +7 -7
- package/public/assets/pds/components/pds-live-edit.js +1555 -0
- package/public/assets/pds/components/pds-omnibox.js +558 -369
- package/public/assets/pds/components/pds-richtext.js +57 -7
- package/public/assets/pds/components/pds-theme.js +58 -0
- package/readme.md +2 -2
- package/src/js/pds-core/pds-config.js +705 -1
- package/src/js/pds-core/pds-enhancers.js +61 -4
- package/src/js/pds-core/pds-live.js +545 -437
- package/src/js/pds-core/pds-ontology.js +8 -0
- package/src/js/pds-core/pds-start-helpers.js +15 -0
- package/src/js/pds-core/pds-theme-utils.js +33 -0
- package/src/js/pds.d.ts +3 -1
- package/src/js/pds.js +22 -0
|
@@ -1,437 +1,545 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Live-mode initialization and API surface for PDS.
|
|
3
|
-
* Separated to keep the base runtime bundle lean for production/static usage.
|
|
4
|
-
*/
|
|
5
|
-
import { Generator } from "./pds-generator.js";
|
|
6
|
-
import { applyStyles, adoptLayers, adoptPrimitives } from "./pds-runtime.js";
|
|
7
|
-
import { presets, defaultLog } from "./pds-config.js";
|
|
8
|
-
import { defaultPDSEnhancers } from "./pds-enhancers.js";
|
|
9
|
-
import { defaultPDSEnhancerMetadata } from "./pds-enhancers-meta.js";
|
|
10
|
-
import { resolvePublicAssetURL } from "./pds-paths.js";
|
|
11
|
-
import { loadTypographyFonts } from "../common/font-loader.js";
|
|
12
|
-
import {
|
|
13
|
-
ensureAbsoluteAssetURL,
|
|
14
|
-
ensureTrailingSlash,
|
|
15
|
-
attachFoucListener,
|
|
16
|
-
normalizeInitConfig,
|
|
17
|
-
resolveRuntimeAssetRoot,
|
|
18
|
-
resolveThemeAndApply,
|
|
19
|
-
setupAutoDefinerAndEnhancers,
|
|
20
|
-
stripFunctions,
|
|
21
|
-
} from "./pds-start-helpers.js";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
let
|
|
28
|
-
let
|
|
29
|
-
|
|
30
|
-
function
|
|
31
|
-
if (typeof
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
.
|
|
256
|
-
.
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Live-mode initialization and API surface for PDS.
|
|
3
|
+
* Separated to keep the base runtime bundle lean for production/static usage.
|
|
4
|
+
*/
|
|
5
|
+
import { Generator } from "./pds-generator.js";
|
|
6
|
+
import { applyStyles, adoptLayers, adoptPrimitives } from "./pds-runtime.js";
|
|
7
|
+
import { presets, defaultLog, PDS_CONFIG_RELATIONS } from "./pds-config.js";
|
|
8
|
+
import { defaultPDSEnhancers } from "./pds-enhancers.js";
|
|
9
|
+
import { defaultPDSEnhancerMetadata } from "./pds-enhancers-meta.js";
|
|
10
|
+
import { resolvePublicAssetURL } from "./pds-paths.js";
|
|
11
|
+
import { loadTypographyFonts } from "../common/font-loader.js";
|
|
12
|
+
import {
|
|
13
|
+
ensureAbsoluteAssetURL,
|
|
14
|
+
ensureTrailingSlash,
|
|
15
|
+
attachFoucListener,
|
|
16
|
+
normalizeInitConfig,
|
|
17
|
+
resolveRuntimeAssetRoot,
|
|
18
|
+
resolveThemeAndApply,
|
|
19
|
+
setupAutoDefinerAndEnhancers,
|
|
20
|
+
stripFunctions,
|
|
21
|
+
} from "./pds-start-helpers.js";
|
|
22
|
+
import {
|
|
23
|
+
isPresetThemeCompatible,
|
|
24
|
+
resolveThemePreference,
|
|
25
|
+
} from "./pds-theme-utils.js";
|
|
26
|
+
|
|
27
|
+
let __liveApiReady = false;
|
|
28
|
+
let __queryClass = null;
|
|
29
|
+
|
|
30
|
+
function getStoredLiveConfig() {
|
|
31
|
+
if (typeof window === "undefined" || !window.localStorage) return null;
|
|
32
|
+
try {
|
|
33
|
+
const raw = window.localStorage.getItem("pure-ds-config");
|
|
34
|
+
if (!raw) return null;
|
|
35
|
+
const parsed = JSON.parse(raw);
|
|
36
|
+
if (parsed && ("preset" in parsed || "design" in parsed)) return parsed;
|
|
37
|
+
} catch (e) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function deepMergeConfig(target = {}, source = {}) {
|
|
44
|
+
if (!source || typeof source !== "object") return target;
|
|
45
|
+
const out = Array.isArray(target) ? [...target] : { ...target };
|
|
46
|
+
for (const [key, value] of Object.entries(source)) {
|
|
47
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
48
|
+
out[key] = deepMergeConfig(
|
|
49
|
+
out[key] && typeof out[key] === "object" ? out[key] : {},
|
|
50
|
+
value
|
|
51
|
+
);
|
|
52
|
+
} else {
|
|
53
|
+
out[key] = value;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function applyStoredConfigOverrides(baseConfig) {
|
|
60
|
+
const stored = getStoredLiveConfig();
|
|
61
|
+
if (!stored || !baseConfig || typeof baseConfig !== "object") return baseConfig;
|
|
62
|
+
|
|
63
|
+
const storedPreset = stored.preset;
|
|
64
|
+
const storedDesign =
|
|
65
|
+
stored.design && typeof stored.design === "object" ? stored.design : null;
|
|
66
|
+
|
|
67
|
+
if (!storedPreset && !storedDesign) return baseConfig;
|
|
68
|
+
|
|
69
|
+
const hasNewShape =
|
|
70
|
+
"preset" in baseConfig || "design" in baseConfig || "enhancers" in baseConfig;
|
|
71
|
+
|
|
72
|
+
let nextConfig = { ...baseConfig };
|
|
73
|
+
|
|
74
|
+
if (storedPreset) {
|
|
75
|
+
nextConfig.preset = storedPreset;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (storedDesign) {
|
|
79
|
+
if (hasNewShape) {
|
|
80
|
+
const baseDesign =
|
|
81
|
+
baseConfig.design && typeof baseConfig.design === "object"
|
|
82
|
+
? baseConfig.design
|
|
83
|
+
: {};
|
|
84
|
+
nextConfig.design = deepMergeConfig(baseDesign, storedDesign);
|
|
85
|
+
} else {
|
|
86
|
+
nextConfig = deepMergeConfig(baseConfig, storedDesign);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return nextConfig;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function __attachLiveAPIs(PDS, { applyResolvedTheme, setupSystemListenerIfNeeded }) {
|
|
94
|
+
if (__liveApiReady) return;
|
|
95
|
+
|
|
96
|
+
const [ontologyModule, enumsModule, queryModule, commonModule] =
|
|
97
|
+
await Promise.all([
|
|
98
|
+
import("./pds-ontology.js"),
|
|
99
|
+
import("./pds-enums.js"),
|
|
100
|
+
import("./pds-query.js"),
|
|
101
|
+
import("../common/common.js"),
|
|
102
|
+
]);
|
|
103
|
+
|
|
104
|
+
const ontology = ontologyModule?.default || ontologyModule?.ontology;
|
|
105
|
+
const findComponentForElement = ontologyModule?.findComponentForElement;
|
|
106
|
+
const enums = enumsModule?.enums;
|
|
107
|
+
__queryClass = queryModule?.PDSQuery || queryModule?.default || null;
|
|
108
|
+
|
|
109
|
+
// Expose live-only APIs
|
|
110
|
+
PDS.ontology = ontology;
|
|
111
|
+
PDS.findComponentForElement = findComponentForElement;
|
|
112
|
+
PDS.enums = enums;
|
|
113
|
+
PDS.common = commonModule || {};
|
|
114
|
+
PDS.presets = presets;
|
|
115
|
+
PDS.configRelations = PDS_CONFIG_RELATIONS;
|
|
116
|
+
PDS.enhancerMetadata = defaultPDSEnhancerMetadata;
|
|
117
|
+
PDS.applyStyles = function(generator) {
|
|
118
|
+
return applyStyles(generator || Generator.instance);
|
|
119
|
+
};
|
|
120
|
+
PDS.adoptLayers = function(shadowRoot, layers, additionalSheets) {
|
|
121
|
+
return adoptLayers(
|
|
122
|
+
shadowRoot,
|
|
123
|
+
layers,
|
|
124
|
+
additionalSheets,
|
|
125
|
+
Generator.instance
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
PDS.adoptPrimitives = function(shadowRoot, additionalSheets) {
|
|
129
|
+
return adoptPrimitives(shadowRoot, additionalSheets, Generator.instance);
|
|
130
|
+
};
|
|
131
|
+
PDS.getGenerator = async function() {
|
|
132
|
+
return Generator;
|
|
133
|
+
};
|
|
134
|
+
PDS.query = async function(question) {
|
|
135
|
+
if (!__queryClass) {
|
|
136
|
+
const mod = await import("./pds-query.js");
|
|
137
|
+
__queryClass = mod?.PDSQuery || mod?.default || null;
|
|
138
|
+
}
|
|
139
|
+
if (!__queryClass) return [];
|
|
140
|
+
const queryEngine = new __queryClass(PDS);
|
|
141
|
+
return await queryEngine.search(question);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
PDS.applyLivePreset = async function(presetId, options = {}) {
|
|
145
|
+
if (!presetId) return false;
|
|
146
|
+
if (!PDS.registry?.isLive) {
|
|
147
|
+
console.warn("PDS.applyLivePreset is only available in live mode.");
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const baseConfig = PDS.currentConfig || {};
|
|
152
|
+
const { design: _design, preset: _preset, ...rest } = baseConfig;
|
|
153
|
+
const inputConfig = {
|
|
154
|
+
...structuredClone(stripFunctions(rest)),
|
|
155
|
+
preset: presetId,
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const normalized = normalizeInitConfig(inputConfig, {}, {
|
|
159
|
+
presets,
|
|
160
|
+
defaultLog,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const resolvedTheme = resolveThemePreference(PDS.theme);
|
|
164
|
+
if (!isPresetThemeCompatible(normalized.generatorConfig.design, resolvedTheme)) {
|
|
165
|
+
const presetName =
|
|
166
|
+
normalized.presetInfo?.name ||
|
|
167
|
+
normalized.generatorConfig?.design?.name ||
|
|
168
|
+
presetId;
|
|
169
|
+
console.warn(
|
|
170
|
+
`PDS theme "${resolvedTheme}" not supported by preset "${presetName}".`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (baseConfig.theme && !normalized.generatorConfig.theme) {
|
|
175
|
+
normalized.generatorConfig.theme = baseConfig.theme;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const generator = new Generator(normalized.generatorConfig);
|
|
179
|
+
|
|
180
|
+
if (normalized.generatorConfig.design?.typography) {
|
|
181
|
+
try {
|
|
182
|
+
await loadTypographyFonts(normalized.generatorConfig.design.typography);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
normalized.generatorConfig?.log?.(
|
|
185
|
+
"warn",
|
|
186
|
+
"Failed to load some fonts from Google Fonts:",
|
|
187
|
+
error,
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
await applyStyles(generator);
|
|
193
|
+
|
|
194
|
+
const presetInfo = normalized.presetInfo || { id: presetId, name: presetId };
|
|
195
|
+
PDS.currentPreset = presetInfo;
|
|
196
|
+
PDS.currentConfig = Object.freeze({
|
|
197
|
+
...baseConfig,
|
|
198
|
+
preset: normalized.generatorConfig.preset,
|
|
199
|
+
design: structuredClone(normalized.generatorConfig.design),
|
|
200
|
+
theme: normalized.generatorConfig.theme || baseConfig.theme,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const persist = options?.persist !== false;
|
|
204
|
+
if (persist && typeof window !== "undefined") {
|
|
205
|
+
const storageKey = "pure-ds-config";
|
|
206
|
+
try {
|
|
207
|
+
const storedRaw = localStorage.getItem(storageKey);
|
|
208
|
+
const storedParsed = storedRaw ? JSON.parse(storedRaw) : null;
|
|
209
|
+
const nextStored = {
|
|
210
|
+
...(storedParsed && typeof storedParsed === "object"
|
|
211
|
+
? storedParsed
|
|
212
|
+
: {}),
|
|
213
|
+
preset: presetInfo.id || presetId,
|
|
214
|
+
design: structuredClone(normalized.generatorConfig.design || {}),
|
|
215
|
+
};
|
|
216
|
+
localStorage.setItem(storageKey, JSON.stringify(nextStored));
|
|
217
|
+
} catch (error) {
|
|
218
|
+
normalized.generatorConfig?.log?.(
|
|
219
|
+
"warn",
|
|
220
|
+
"Failed to store preset:",
|
|
221
|
+
error,
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return true;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
// Live-only compiled getter
|
|
230
|
+
if (!Object.getOwnPropertyDescriptor(PDS, "compiled")) {
|
|
231
|
+
Object.defineProperty(PDS, "compiled", {
|
|
232
|
+
get() {
|
|
233
|
+
if (PDS.registry?.isLive && Generator.instance) {
|
|
234
|
+
return Generator.instance.compiled;
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
},
|
|
238
|
+
enumerable: true,
|
|
239
|
+
configurable: false,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Live-only preload helper
|
|
244
|
+
PDS.preloadCritical = function(config, options = {}) {
|
|
245
|
+
if (typeof window === "undefined" || !document.head || !config) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const { theme, layers = ["tokens"] } = options;
|
|
250
|
+
|
|
251
|
+
try {
|
|
252
|
+
let resolvedTheme = theme || "light";
|
|
253
|
+
if (theme === "system" || !theme) {
|
|
254
|
+
const prefersDark =
|
|
255
|
+
window.matchMedia &&
|
|
256
|
+
window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
257
|
+
resolvedTheme = prefersDark ? "dark" : "light";
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
document.documentElement.setAttribute("data-theme", resolvedTheme);
|
|
261
|
+
|
|
262
|
+
const tempConfig = config.design
|
|
263
|
+
? { ...config, theme: resolvedTheme }
|
|
264
|
+
: { design: config, theme: resolvedTheme };
|
|
265
|
+
const tempGenerator = new Generator(tempConfig);
|
|
266
|
+
|
|
267
|
+
const criticalCSS = layers
|
|
268
|
+
.map((layer) => {
|
|
269
|
+
try {
|
|
270
|
+
return tempGenerator.css?.[layer] || "";
|
|
271
|
+
} catch (e) {
|
|
272
|
+
return "";
|
|
273
|
+
}
|
|
274
|
+
})
|
|
275
|
+
.filter((css) => css.trim())
|
|
276
|
+
.join("\n");
|
|
277
|
+
|
|
278
|
+
if (criticalCSS) {
|
|
279
|
+
const existing = document.head.querySelector("style[data-pds-preload]");
|
|
280
|
+
if (existing) existing.remove();
|
|
281
|
+
|
|
282
|
+
const styleEl = document.createElement("style");
|
|
283
|
+
styleEl.setAttribute("data-pds-preload", "");
|
|
284
|
+
styleEl.textContent = criticalCSS;
|
|
285
|
+
document.head.insertBefore(styleEl, document.head.firstChild);
|
|
286
|
+
}
|
|
287
|
+
} catch (error) {
|
|
288
|
+
console.warn("PDS preload failed:", error);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
__liveApiReady = true;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
export async function startLive(PDS, config, { emitReady, applyResolvedTheme, setupSystemListenerIfNeeded }) {
|
|
297
|
+
if (!config || typeof config !== "object") {
|
|
298
|
+
throw new Error(
|
|
299
|
+
"PDS.start({ mode: 'live', ... }) requires a valid configuration object"
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
config = applyStoredConfigOverrides(config);
|
|
304
|
+
|
|
305
|
+
// Attach live-only API surface (ontology, presets, query, etc.)
|
|
306
|
+
await __attachLiveAPIs(PDS, { applyResolvedTheme, setupSystemListenerIfNeeded });
|
|
307
|
+
attachFoucListener(PDS);
|
|
308
|
+
|
|
309
|
+
// FOUC Prevention: Use constructable stylesheet for synchronous, immediate effect
|
|
310
|
+
if (typeof document !== "undefined" && document.adoptedStyleSheets) {
|
|
311
|
+
const css = /*css*/`
|
|
312
|
+
html { opacity: 0; }
|
|
313
|
+
html.pds-ready { opacity: 1; transition: opacity 0.3s ease-in; }
|
|
314
|
+
`;
|
|
315
|
+
try {
|
|
316
|
+
const hasFoucSheet = document.adoptedStyleSheets.some((sheet) => sheet._pdsFouc);
|
|
317
|
+
if (!hasFoucSheet) {
|
|
318
|
+
const foucSheet = new CSSStyleSheet();
|
|
319
|
+
foucSheet.replaceSync(css);
|
|
320
|
+
foucSheet._pdsFouc = true;
|
|
321
|
+
document.adoptedStyleSheets = [foucSheet, ...document.adoptedStyleSheets];
|
|
322
|
+
}
|
|
323
|
+
} catch (e) {
|
|
324
|
+
console.warn("Constructable stylesheets not supported, using <style> tag fallback:", e);
|
|
325
|
+
const existingFoucStyle = document.head.querySelector("style[data-pds-fouc]");
|
|
326
|
+
if (!existingFoucStyle) {
|
|
327
|
+
const foucStyle = document.createElement("style");
|
|
328
|
+
foucStyle.setAttribute("data-pds-fouc", "");
|
|
329
|
+
foucStyle.textContent = css;
|
|
330
|
+
document.head.insertBefore(foucStyle, document.head.firstChild);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Extract runtime flags directly from unified config
|
|
336
|
+
let applyGlobalStyles = config.applyGlobalStyles ?? true;
|
|
337
|
+
let manageTheme = config.manageTheme ?? true;
|
|
338
|
+
let themeStorageKey = config.themeStorageKey ?? "pure-ds-theme";
|
|
339
|
+
let preloadStyles = config.preloadStyles ?? false;
|
|
340
|
+
let criticalLayers = config.criticalLayers ?? ["tokens", "primitives"];
|
|
341
|
+
|
|
342
|
+
const cfgAuto = (config && config.autoDefine) || null;
|
|
343
|
+
|
|
344
|
+
try {
|
|
345
|
+
// 1) Handle theme preference
|
|
346
|
+
const { resolvedTheme } = resolveThemeAndApply({
|
|
347
|
+
manageTheme,
|
|
348
|
+
themeStorageKey,
|
|
349
|
+
applyResolvedTheme,
|
|
350
|
+
setupSystemListenerIfNeeded,
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
// 2) Normalize first-arg API: support { preset, design, enhancers }
|
|
354
|
+
const normalized = normalizeInitConfig(config, {}, { presets, defaultLog });
|
|
355
|
+
if (manageTheme && !isPresetThemeCompatible(normalized.generatorConfig.design, resolvedTheme)) {
|
|
356
|
+
const presetName =
|
|
357
|
+
normalized.presetInfo?.name ||
|
|
358
|
+
normalized.generatorConfig?.design?.name ||
|
|
359
|
+
normalized.generatorConfig?.preset ||
|
|
360
|
+
"current preset";
|
|
361
|
+
console.warn(
|
|
362
|
+
`PDS theme "${resolvedTheme}" not supported by preset "${presetName}".`
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
const userEnhancers = normalized.enhancers;
|
|
366
|
+
const { log: logFn, ...configToClone } = normalized.generatorConfig;
|
|
367
|
+
const generatorConfig = structuredClone(configToClone);
|
|
368
|
+
generatorConfig.log = logFn;
|
|
369
|
+
if (manageTheme) {
|
|
370
|
+
generatorConfig.theme = resolvedTheme;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const generator = new Generator(generatorConfig);
|
|
374
|
+
|
|
375
|
+
// 3) Load fonts from Google Fonts if needed (before applying styles)
|
|
376
|
+
if (generatorConfig.design?.typography) {
|
|
377
|
+
try {
|
|
378
|
+
await loadTypographyFonts(generatorConfig.design.typography);
|
|
379
|
+
} catch (ex) {
|
|
380
|
+
generatorConfig?.log?.("warn", "Failed to load some fonts from Google Fonts:", ex);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// 4) Preload critical styles synchronously to prevent flash
|
|
385
|
+
if (preloadStyles && typeof window !== "undefined" && document.head) {
|
|
386
|
+
try {
|
|
387
|
+
const criticalCSS = criticalLayers
|
|
388
|
+
.map((layer) => {
|
|
389
|
+
try {
|
|
390
|
+
return generator.css?.[layer] || "";
|
|
391
|
+
} catch (e) {
|
|
392
|
+
generatorConfig?.log?.(
|
|
393
|
+
"warn",
|
|
394
|
+
`Failed to generate critical CSS for layer "${layer}":`,
|
|
395
|
+
e
|
|
396
|
+
);
|
|
397
|
+
return "";
|
|
398
|
+
}
|
|
399
|
+
})
|
|
400
|
+
.filter((css) => css.trim())
|
|
401
|
+
.join("\n");
|
|
402
|
+
|
|
403
|
+
if (criticalCSS) {
|
|
404
|
+
const existingCritical = document.head.querySelector(
|
|
405
|
+
"style[data-pds-critical]"
|
|
406
|
+
);
|
|
407
|
+
if (existingCritical) {
|
|
408
|
+
existingCritical.remove();
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const styleEl = document.createElement("style");
|
|
412
|
+
styleEl.setAttribute("data-pds-critical", "");
|
|
413
|
+
styleEl.textContent = criticalCSS;
|
|
414
|
+
|
|
415
|
+
const insertAfter = document.head.querySelector(
|
|
416
|
+
'meta[charset], meta[name="viewport"]'
|
|
417
|
+
);
|
|
418
|
+
if (insertAfter) {
|
|
419
|
+
insertAfter.parentNode.insertBefore(
|
|
420
|
+
styleEl,
|
|
421
|
+
insertAfter.nextSibling
|
|
422
|
+
);
|
|
423
|
+
} else {
|
|
424
|
+
document.head.insertBefore(styleEl, document.head.firstChild);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
} catch (error) {
|
|
428
|
+
generatorConfig?.log?.("warn", "Failed to preload critical styles:", error);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// Set the registry to live mode
|
|
433
|
+
PDS.registry.setLiveMode();
|
|
434
|
+
|
|
435
|
+
// Log preset info if available
|
|
436
|
+
if (normalized.presetInfo?.name) {
|
|
437
|
+
generatorConfig?.log?.("log", `PDS live with preset "${normalized.presetInfo.name}"`);
|
|
438
|
+
} else {
|
|
439
|
+
generatorConfig?.log?.("log", "PDS live with custom config");
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// Apply styles globally if requested (default behavior)
|
|
443
|
+
if (applyGlobalStyles) {
|
|
444
|
+
await applyStyles(Generator.instance);
|
|
445
|
+
|
|
446
|
+
if (typeof window !== "undefined") {
|
|
447
|
+
setTimeout(() => {
|
|
448
|
+
const criticalStyle = document.head.querySelector(
|
|
449
|
+
"style[data-pds-critical]"
|
|
450
|
+
);
|
|
451
|
+
if (criticalStyle) criticalStyle.remove();
|
|
452
|
+
|
|
453
|
+
const preloadStyle = document.head.querySelector(
|
|
454
|
+
"style[data-pds-preload]"
|
|
455
|
+
);
|
|
456
|
+
if (preloadStyle) preloadStyle.remove();
|
|
457
|
+
|
|
458
|
+
const legacyRuntime = document.getElementById(
|
|
459
|
+
"pds-runtime-stylesheet"
|
|
460
|
+
);
|
|
461
|
+
if (legacyRuntime) legacyRuntime.remove();
|
|
462
|
+
}, 100);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const assetRootURL = resolveRuntimeAssetRoot(config, { resolvePublicAssetURL });
|
|
467
|
+
|
|
468
|
+
let derivedAutoDefineBaseURL;
|
|
469
|
+
if (cfgAuto && cfgAuto.baseURL) {
|
|
470
|
+
derivedAutoDefineBaseURL = ensureTrailingSlash(
|
|
471
|
+
ensureAbsoluteAssetURL(cfgAuto.baseURL, { preferModule: false })
|
|
472
|
+
);
|
|
473
|
+
} else {
|
|
474
|
+
derivedAutoDefineBaseURL = `${assetRootURL}components/`;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// 5) Set up AutoDefiner + run enhancers (defaults merged with user)
|
|
478
|
+
let autoDefiner = null;
|
|
479
|
+
let mergedEnhancers = [];
|
|
480
|
+
|
|
481
|
+
try {
|
|
482
|
+
const res = await setupAutoDefinerAndEnhancers({
|
|
483
|
+
autoDefineBaseURL: derivedAutoDefineBaseURL,
|
|
484
|
+
autoDefinePreload:
|
|
485
|
+
(cfgAuto && Array.isArray(cfgAuto.predefine) && cfgAuto.predefine) ||
|
|
486
|
+
[],
|
|
487
|
+
autoDefineMapper:
|
|
488
|
+
(cfgAuto && typeof cfgAuto.mapper === "function" && cfgAuto.mapper) ||
|
|
489
|
+
null,
|
|
490
|
+
enhancers: userEnhancers,
|
|
491
|
+
autoDefineOverrides: cfgAuto || null,
|
|
492
|
+
autoDefinePreferModule: !(cfgAuto && cfgAuto.baseURL),
|
|
493
|
+
}, { baseEnhancers: defaultPDSEnhancers });
|
|
494
|
+
autoDefiner = res.autoDefiner;
|
|
495
|
+
mergedEnhancers = res.mergedEnhancers || [];
|
|
496
|
+
|
|
497
|
+
} catch (error) {
|
|
498
|
+
generatorConfig?.log?.("error", "❌ Failed to initialize AutoDefiner/Enhancers:", error);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
const resolvedConfig = generator?.options || generatorConfig;
|
|
502
|
+
|
|
503
|
+
const cloneableConfig = stripFunctions(config);
|
|
504
|
+
PDS.currentConfig = Object.freeze({
|
|
505
|
+
mode: "live",
|
|
506
|
+
...structuredClone(cloneableConfig),
|
|
507
|
+
design: structuredClone(normalized.generatorConfig.design),
|
|
508
|
+
preset: normalized.generatorConfig.preset,
|
|
509
|
+
theme: resolvedTheme,
|
|
510
|
+
enhancers: mergedEnhancers,
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
if (config?.liveEdit && typeof document !== "undefined") {
|
|
515
|
+
try {
|
|
516
|
+
if (!document.querySelector("pds-live-edit")) {
|
|
517
|
+
setTimeout(() => {
|
|
518
|
+
const liveEditor = document.createElement("pds-live-edit");
|
|
519
|
+
document.body.appendChild(liveEditor);
|
|
520
|
+
}, 1000);
|
|
521
|
+
}
|
|
522
|
+
} catch (error) {
|
|
523
|
+
generatorConfig?.log?.("warn", "Live editor failed to start:", error);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
emitReady({
|
|
528
|
+
mode: "live",
|
|
529
|
+
generator,
|
|
530
|
+
config: resolvedConfig,
|
|
531
|
+
theme: resolvedTheme,
|
|
532
|
+
autoDefiner,
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
return {
|
|
536
|
+
generator,
|
|
537
|
+
config: resolvedConfig,
|
|
538
|
+
theme: resolvedTheme,
|
|
539
|
+
autoDefiner,
|
|
540
|
+
};
|
|
541
|
+
} catch (error) {
|
|
542
|
+
PDS.dispatchEvent(new CustomEvent("pds:error", { detail: { error } }));
|
|
543
|
+
throw error;
|
|
544
|
+
}
|
|
545
|
+
}
|