@pure-ds/core 0.5.19 → 0.5.21

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.
@@ -13,7 +13,6 @@ import {
13
13
  ensureAbsoluteAssetURL,
14
14
  ensureTrailingSlash,
15
15
  attachFoucListener,
16
- createSetTheme,
17
16
  normalizeInitConfig,
18
17
  resolveRuntimeAssetRoot,
19
18
  resolveThemeAndApply,
@@ -74,10 +73,6 @@ async function __attachLiveAPIs(PDS, { applyResolvedTheme, setupSystemListenerIf
74
73
  return await queryEngine.search(question);
75
74
  };
76
75
 
77
- // Expose internal theme helpers for configurator usage
78
- PDS._applyResolvedTheme = applyResolvedTheme;
79
- PDS._setupSystemListenerIfNeeded = setupSystemListenerIfNeeded;
80
-
81
76
  // Live-only compiled getter
82
77
  if (!Object.getOwnPropertyDescriptor(PDS, "compiled")) {
83
78
  Object.defineProperty(PDS, "compiled", {
@@ -92,27 +87,6 @@ async function __attachLiveAPIs(PDS, { applyResolvedTheme, setupSystemListenerIf
92
87
  });
93
88
  }
94
89
 
95
- // Live-only setTheme helper
96
- PDS.setTheme = createSetTheme({
97
- PDS,
98
- defaultStorageKey: "pure-ds-theme",
99
- setupSystemListenerIfNeeded,
100
- onApply: async ({ resolvedTheme }) => {
101
- if (PDS.registry.isLive && Generator.instance) {
102
- try {
103
- const currentGenerator = Generator.instance;
104
- if (currentGenerator && currentGenerator.configure) {
105
- const newConfig = { ...currentGenerator.config, theme: resolvedTheme };
106
- currentGenerator.configure(newConfig);
107
- await applyStyles(Generator.instance);
108
- }
109
- } catch (error) {
110
- console.warn("Failed to update styles for new theme:", error);
111
- }
112
- }
113
- },
114
- });
115
-
116
90
  // Live-only preload helper
117
91
  PDS.preloadCritical = function(config, options = {}) {
118
92
  if (typeof window === "undefined" || !document.head || !config) {
@@ -272,66 +272,6 @@ export function resolveThemeAndApply({ manageTheme, themeStorageKey, applyResolv
272
272
  return { resolvedTheme, storedTheme };
273
273
  }
274
274
 
275
- // Internal: create a reusable setTheme helper for live/static modes
276
- export function createSetTheme({
277
- PDS,
278
- defaultStorageKey = "pure-ds-theme",
279
- setupSystemListenerIfNeeded,
280
- onApply,
281
- } = {}) {
282
- return async function setTheme(theme, options = {}) {
283
- const { storageKey = defaultStorageKey, persist = true } = options;
284
-
285
- if (!["light", "dark", "system"].includes(theme)) {
286
- throw new Error(
287
- `Invalid theme "${theme}". Must be "light", "dark", or "system".`
288
- );
289
- }
290
-
291
- if (typeof window === "undefined") {
292
- return theme === "system" ? "light" : theme;
293
- }
294
-
295
- let resolvedTheme = theme;
296
- if (theme === "system") {
297
- const prefersDark =
298
- window.matchMedia &&
299
- window.matchMedia("(prefers-color-scheme: dark)").matches;
300
- resolvedTheme = prefersDark ? "dark" : "light";
301
- }
302
-
303
- document.documentElement.setAttribute("data-theme", resolvedTheme);
304
-
305
- if (persist) {
306
- try {
307
- localStorage.setItem(storageKey, theme);
308
- } catch (e) {}
309
- }
310
-
311
- try {
312
- setupSystemListenerIfNeeded?.(theme);
313
- } catch (e) {}
314
-
315
- if (typeof onApply === "function") {
316
- await onApply({ theme, resolvedTheme });
317
- }
318
-
319
- try {
320
- PDS?.dispatchEvent(
321
- new CustomEvent("pds:theme:changed", {
322
- detail: {
323
- theme: resolvedTheme,
324
- requested: theme,
325
- source: "programmatic",
326
- },
327
- })
328
- );
329
- } catch (e) {}
330
-
331
- return resolvedTheme;
332
- };
333
- }
334
-
335
275
  export function resolveRuntimeAssetRoot(config, { resolvePublicAssetURL }) {
336
276
  const hasCustomRoot = Boolean(config?.public?.root || config?.static?.root);
337
277
  let candidate = resolvePublicAssetURL(config);
package/src/js/pds.d.ts CHANGED
@@ -298,7 +298,6 @@ export class PDS extends EventTarget {
298
298
  readonly autoDefiner?: any;
299
299
 
300
300
  // Instance helpers
301
- setTheme?(theme: 'light' | 'dark' | 'system', options?: { storageKey?: string; persist?: boolean }): Promise<string>;
302
301
  preloadCritical?(config: any, options?: { theme?: string; layers?: string[] }): void;
303
302
  }
304
303
 
package/src/js/pds.js CHANGED
@@ -42,6 +42,7 @@ const PDS = new PDSBase();
42
42
  // State properties
43
43
  PDS.initializing = false;
44
44
  PDS.currentPreset = null;
45
+ PDS.debug = false;
45
46
 
46
47
  import {
47
48
  adoptLayers,
@@ -57,7 +58,6 @@ import {
57
58
  ensureAbsoluteAssetURL,
58
59
  ensureTrailingSlash,
59
60
  attachFoucListener,
60
- createSetTheme,
61
61
  normalizeInitConfig,
62
62
  resolveRuntimeAssetRoot,
63
63
  resolveThemeAndApply,
@@ -73,14 +73,21 @@ const __slugifyPreset = (str = "") =>
73
73
  .replace(/^-+|-+$/g, "");
74
74
 
75
75
  const __defaultLog = function (level = "log", message, ...data) {
76
- const debug = this?.debug || this?.design?.debug || false;
77
- if (debug || level === "error" || level === "warn") {
78
- const method = console[level] || console.log;
79
- if (data.length > 0) {
80
- method(message, ...data);
81
- } else {
82
- method(message);
83
- }
76
+ const isStaticMode = Boolean(PDS.registry && !PDS.registry.isLive);
77
+ const debug =
78
+ (this?.debug || this?.design?.debug || PDS.debug || false) === true;
79
+
80
+ if (isStaticMode) {
81
+ if (!PDS.debug) return;
82
+ } else if (!debug && level !== "error" && level !== "warn") {
83
+ return;
84
+ }
85
+
86
+ const method = console[level] || console.log;
87
+ if (data.length > 0) {
88
+ method(message, ...data);
89
+ } else {
90
+ method(message);
84
91
  }
85
92
  };
86
93
 
@@ -110,7 +117,6 @@ PDS.adoptPrimitives = adoptPrimitives;
110
117
  /** Create a constructable CSSStyleSheet from a CSS string */
111
118
  PDS.createStylesheet = createStylesheet;
112
119
 
113
-
114
120
  /** Return true when running inside a live/designer-backed environment */
115
121
  PDS.isLiveMode = () => registry.isLive;
116
122
  PDS.ask = ask;
@@ -146,15 +152,6 @@ function __emitPDSReady(detail) {
146
152
  }
147
153
  }
148
154
 
149
- /** Current configuration (set after PDS.start() completes) - read-only, frozen after initialization */
150
- Object.defineProperty(PDS, "currentConfig", {
151
- value: null,
152
- writable: true,
153
- enumerable: true,
154
- configurable: false,
155
- });
156
-
157
- // Always expose PDS on the window in browser contexts so consumers can access it in both live and static modes
158
155
  if (typeof window !== "undefined") {
159
156
  // @ts-ignore
160
157
  window.PDS = PDS;
@@ -273,10 +270,6 @@ Object.defineProperty(PDS, "theme", {
273
270
  },
274
271
  });
275
272
 
276
- // Internal theme helpers (used by configurator/live tooling)
277
- PDS._applyResolvedTheme = __applyResolvedTheme;
278
- PDS._setupSystemListenerIfNeeded = __setupSystemListenerIfNeeded;
279
-
280
273
  // ----------------------------------------------------------------------------
281
274
  // Default Enhancers — first-class citizens alongside AutoDefiner
282
275
  // ----------------------------------------------------------------------------
@@ -287,8 +280,6 @@ PDS._setupSystemListenerIfNeeded = __setupSystemListenerIfNeeded;
287
280
  */
288
281
  PDS.defaultEnhancers = defaultPDSEnhancers;
289
282
 
290
-
291
-
292
283
  /**
293
284
  * Initialize PDS in live mode with the given configuration (new unified shape).
294
285
  * Typically invoked via PDS.start({ mode: 'live', ... }).
@@ -352,7 +343,6 @@ async function start(config) {
352
343
  /** Primary unified entry point */
353
344
  PDS.start = start;
354
345
 
355
-
356
346
  /**
357
347
  * Initialize PDS in static mode with the same unified configuration shape as live mode.
358
348
  *
@@ -410,13 +400,6 @@ async function staticInit(config) {
410
400
  setupSystemListenerIfNeeded: __setupSystemListenerIfNeeded,
411
401
  });
412
402
 
413
- // 1b) Static-mode setTheme helper (live mode overrides this later)
414
- PDS.setTheme = createSetTheme({
415
- PDS,
416
- defaultStorageKey: themeStorageKey,
417
- setupSystemListenerIfNeeded: __setupSystemListenerIfNeeded,
418
- });
419
-
420
403
  // Normalize first-arg to allow { preset, design, enhancers }
421
404
  const runtimeConfig = await __loadRuntimeConfig(assetRootURL, config);
422
405
  const runtimeDesign =
@@ -463,7 +446,10 @@ async function staticInit(config) {
463
446
  }
464
447
  : config;
465
448
 
466
- const normalized = normalizeInitConfig(normalizedInput, {}, { presets, defaultLog: __defaultLog });
449
+ const normalized = normalizeInitConfig(normalizedInput, {}, {
450
+ presets,
451
+ defaultLog: __defaultLog,
452
+ });
467
453
  const userEnhancers = normalized.enhancers;
468
454
 
469
455
  // 2) Derive static asset URLs from the normalized public root
@@ -494,8 +480,7 @@ async function staticInit(config) {
494
480
  document.adoptedStyleSheets = [...others, stylesSheet];
495
481
  }
496
482
  } catch (e) {
497
- // No config available in static mode, using console
498
- console.warn("Failed to apply static styles:", e);
483
+ __defaultLog.call(PDS, "warn", "Failed to apply static styles:", e);
499
484
  }
500
485
  }
501
486
 
@@ -514,8 +499,9 @@ async function staticInit(config) {
514
499
  autoDefiner = res.autoDefiner;
515
500
  mergedEnhancers = res.mergedEnhancers || [];
516
501
  } catch (error) {
517
- // No config available in static mode, using console
518
- console.error(
502
+ __defaultLog.call(
503
+ PDS,
504
+ "error",
519
505
  "❌ Failed to initialize AutoDefiner/Enhancers (static):",
520
506
  error
521
507
  );
@@ -553,8 +539,9 @@ async function staticInit(config) {
553
539
 
554
540
  // Note: PDS.static is not exported. Use PDS.start({ mode: 'static', ... }).
555
541
 
556
-
557
542
  // Note: PDS object is not frozen to allow runtime properties like currentConfig
558
543
  // to be set during initialization. The config object itself is frozen for immutability.
559
544
 
545
+ export const applyResolvedTheme = __applyResolvedTheme;
546
+ export const setupSystemListenerIfNeeded = __setupSystemListenerIfNeeded;
560
547
  export { PDS };