@pikacss/core 0.0.33 → 0.0.35

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/index.cjs CHANGED
@@ -5,15 +5,48 @@ const ATOMIC_STYLE_ID_PLACEHOLDER_RE_GLOBAL = /%/g;
5
5
 
6
6
  //#endregion
7
7
  //#region src/internal/utils.ts
8
- let _warn = (...args) => {
9
- console.warn("[@pikacss/core]", ...args);
10
- };
11
- function setWarnFn(fn) {
12
- _warn = fn;
13
- }
14
- function warn(...args) {
15
- _warn(...args);
8
+ function createLogger(prefix) {
9
+ let currentPrefix = prefix;
10
+ let enabledDebug = false;
11
+ let _debug = console.log;
12
+ let _info = console.log;
13
+ let _warn = console.warn;
14
+ let _error = console.error;
15
+ return {
16
+ debug: (...args) => {
17
+ if (!enabledDebug) return;
18
+ _debug(`${currentPrefix}[DEBUG]`, ...args);
19
+ },
20
+ info: (...args) => {
21
+ _info(`${currentPrefix}[INFO]`, ...args);
22
+ },
23
+ warn: (...args) => {
24
+ _warn(`${currentPrefix}[WARN]`, ...args);
25
+ },
26
+ error: (...args) => {
27
+ _error(`${currentPrefix}[ERROR]`, ...args);
28
+ },
29
+ toggleDebug() {
30
+ enabledDebug = !enabledDebug;
31
+ },
32
+ setPrefix(newPrefix) {
33
+ currentPrefix = newPrefix;
34
+ },
35
+ setDebugFn(fn) {
36
+ _debug = fn;
37
+ },
38
+ setInfoFn(fn) {
39
+ _info = fn;
40
+ },
41
+ setWarnFn(fn) {
42
+ _warn = fn;
43
+ },
44
+ setErrorFn(fn) {
45
+ _error = fn;
46
+ }
47
+ };
16
48
  }
49
+ const log = createLogger("[PikaCSS]");
17
50
  const chars = [..."abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"];
18
51
  const numOfChars = chars.length;
19
52
  function numberToChars(num) {
@@ -150,27 +183,35 @@ function createExtractFn(options) {
150
183
  //#endregion
151
184
  //#region src/internal/plugin.ts
152
185
  async function execAsyncHook(plugins, hook, payload) {
186
+ log.debug(`Executing async hook: ${hook}`);
153
187
  for (const plugin of plugins) {
154
188
  if (plugin[hook] == null) continue;
155
189
  try {
190
+ log.debug(` - Plugin "${plugin.name}" executing ${hook}`);
156
191
  const newPayload = await plugin[hook](payload);
157
192
  if (newPayload != null) payload = newPayload;
193
+ log.debug(` - Plugin "${plugin.name}" completed ${hook}`);
158
194
  } catch (error) {
159
- warn(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
195
+ log.error(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
160
196
  }
161
197
  }
198
+ log.debug(`Async hook "${hook}" completed`);
162
199
  return payload;
163
200
  }
164
201
  function execSyncHook(plugins, hook, payload) {
202
+ log.debug(`Executing sync hook: ${hook}`);
165
203
  for (const plugin of plugins) {
166
204
  if (plugin[hook] == null) continue;
167
205
  try {
206
+ log.debug(` - Plugin "${plugin.name}" executing ${hook}`);
168
207
  const newPayload = plugin[hook](payload);
169
208
  if (newPayload != null) payload = newPayload;
209
+ log.debug(` - Plugin "${plugin.name}" completed ${hook}`);
170
210
  } catch (error) {
171
- warn(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
211
+ log.error(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
172
212
  }
173
213
  }
214
+ log.debug(`Sync hook "${hook}" completed`);
174
215
  return payload;
175
216
  }
176
217
  const hooks = {
@@ -324,33 +365,48 @@ var AbstractResolver = class {
324
365
  return [...this.dynamicRulesMap.values()];
325
366
  }
326
367
  addStaticRule(rule) {
368
+ log.debug(`Adding static rule: ${rule.key}`);
327
369
  this.staticRulesMap.set(rule.key, rule);
328
370
  return this;
329
371
  }
330
372
  removeStaticRule(key) {
331
373
  const rule = this.staticRulesMap.get(key);
332
- if (rule == null) return this;
374
+ if (rule == null) {
375
+ log.warn(`Static rule not found for removal: ${key}`);
376
+ return this;
377
+ }
378
+ log.debug(`Removing static rule: ${key}`);
333
379
  this.staticRulesMap.delete(key);
334
380
  this._resolvedResultsMap.delete(rule.string);
335
381
  return this;
336
382
  }
337
383
  addDynamicRule(rule) {
384
+ log.debug(`Adding dynamic rule: ${rule.key}`);
338
385
  this.dynamicRulesMap.set(rule.key, rule);
339
386
  return this;
340
387
  }
341
388
  removeDynamicRule(key) {
342
389
  const rule = this.dynamicRulesMap.get(key);
343
- if (rule == null) return this;
390
+ if (rule == null) {
391
+ log.warn(`Dynamic rule not found for removal: ${key}`);
392
+ return this;
393
+ }
394
+ log.debug(`Removing dynamic rule: ${key}`);
344
395
  const matchedResolvedStringList = Array.from(this._resolvedResultsMap.keys()).filter((string) => rule.stringPattern.test(string));
345
396
  this.dynamicRulesMap.delete(key);
346
397
  matchedResolvedStringList.forEach((string) => this._resolvedResultsMap.delete(string));
398
+ log.debug(` - Cleared ${matchedResolvedStringList.length} cached results`);
347
399
  return this;
348
400
  }
349
401
  async _resolve(string) {
350
402
  const existedResult = this._resolvedResultsMap.get(string);
351
- if (existedResult != null) return existedResult;
403
+ if (existedResult != null) {
404
+ log.debug(`Resolved from cache: ${string}`);
405
+ return existedResult;
406
+ }
352
407
  const staticRule = Array.from(this.staticRulesMap.values()).find((rule) => rule.string === string);
353
408
  if (staticRule != null) {
409
+ log.debug(`Resolved by static rule: ${staticRule.key}`);
354
410
  const resolvedResult = { value: staticRule.resolved };
355
411
  this._resolvedResultsMap.set(string, resolvedResult);
356
412
  this.onResolved(string, "static", resolvedResult);
@@ -366,11 +422,13 @@ var AbstractResolver = class {
366
422
  }
367
423
  }
368
424
  if (dynamicRule != null && matched != null) {
425
+ log.debug(`Resolved by dynamic rule: ${dynamicRule.key}`);
369
426
  const resolvedResult = { value: await dynamicRule.createResolved(matched) };
370
427
  this._resolvedResultsMap.set(string, resolvedResult);
371
428
  this.onResolved(string, "dynamic", resolvedResult);
372
429
  return resolvedResult;
373
430
  }
431
+ log.debug(`Resolution failed for: ${string}`);
374
432
  }
375
433
  _setResolvedResult(string, resolved) {
376
434
  const resolvedResult = this._resolvedResultsMap.get(string);
@@ -425,7 +483,7 @@ function selectors() {
425
483
  var SelectorResolver = class extends AbstractResolver {
426
484
  async resolve(selector) {
427
485
  const resolved = await this._resolve(selector).catch((error) => {
428
- warn(`Failed to resolve selector "${selector}": ${error.message}`, error);
486
+ log.warn(`Failed to resolve selector "${selector}": ${error.message}`, error);
429
487
  });
430
488
  if (resolved == null) return [selector];
431
489
  const result = [];
@@ -548,7 +606,7 @@ function shortcuts() {
548
606
  var ShortcutResolver = class extends AbstractResolver {
549
607
  async resolve(shortcut) {
550
608
  const resolved = await this._resolve(shortcut).catch((error) => {
551
- warn(`Failed to resolve shortcut "${shortcut}": ${error.message}`, error);
609
+ log.warn(`Failed to resolve shortcut "${shortcut}": ${error.message}`, error);
552
610
  });
553
611
  if (resolved == null) return [shortcut];
554
612
  const result = [];
@@ -702,19 +760,27 @@ function defineEngineConfig(config) {
702
760
  }
703
761
  /* c8 ignore end */
704
762
  async function createEngine(config = {}) {
705
- config.plugins = resolvePlugins([...[
763
+ log.debug("Creating engine with config:", config);
764
+ const corePlugins = [
706
765
  important(),
707
766
  variables(),
708
767
  keyframes(),
709
768
  selectors(),
710
769
  shortcuts()
711
- ], ...config.plugins || []]);
770
+ ];
771
+ log.debug("Core plugins loaded:", corePlugins.length);
772
+ const plugins = resolvePlugins([...corePlugins, ...config.plugins || []]);
773
+ config.plugins = plugins;
774
+ log.debug(`Total plugins resolved: ${plugins.length}`);
712
775
  config = await hooks.configureRawConfig(config.plugins, config);
713
776
  hooks.rawConfigConfigured(resolvePlugins(config.plugins || []), config);
714
777
  let resolvedConfig = await resolveEngineConfig(config);
778
+ log.debug("Engine config resolved with prefix:", resolvedConfig.prefix);
715
779
  resolvedConfig = await hooks.configureResolvedConfig(resolvedConfig.plugins, resolvedConfig);
716
780
  let engine = new Engine(resolvedConfig);
781
+ log.debug("Engine instance created");
717
782
  engine = await hooks.configureEngine(engine.config.plugins, engine);
783
+ log.debug("Engine initialized successfully");
718
784
  return engine;
719
785
  }
720
786
  var Engine = class {
@@ -766,10 +832,13 @@ var Engine = class {
766
832
  this.notifyAutocompleteConfigUpdated();
767
833
  }
768
834
  addPreflight(preflight) {
835
+ log.debug("Adding preflight");
769
836
  this.config.preflights.push(resolvePreflight(preflight));
837
+ log.debug(`Total preflights: ${this.config.preflights.length}`);
770
838
  this.notifyPreflightUpdated();
771
839
  }
772
840
  async use(...itemList) {
841
+ log.debug(`Processing ${itemList.length} style items`);
773
842
  const { unknown, contents } = await resolveStyleItemList({
774
843
  itemList,
775
844
  transformStyleItems: (styleItems) => hooks.transformStyleItems(this.config.plugins, styleItems),
@@ -789,14 +858,17 @@ var Engine = class {
789
858
  content
790
859
  };
791
860
  this.store.atomicStyles.set(id, atomicStyle);
861
+ log.debug(`Atomic style added: ${id}`);
792
862
  this.notifyAtomicStyleAdded(atomicStyle);
793
863
  }
794
864
  });
865
+ log.debug(`Resolved ${resolvedIds.length} atomic styles, ${unknown.size} unknown items`);
795
866
  return [...unknown, ...resolvedIds];
796
867
  }
797
868
  async renderPreflights(isFormatted) {
869
+ log.debug("Rendering preflights...");
798
870
  const lineEnd = isFormatted ? "\n" : "";
799
- return (await Promise.all(this.config.preflights.map(async (p) => {
871
+ const results = await Promise.all(this.config.preflights.map(async (p) => {
800
872
  const result = await p(this, isFormatted);
801
873
  if (typeof result === "string") return result;
802
874
  return renderPreflightDefinition({
@@ -804,12 +876,17 @@ var Engine = class {
804
876
  preflightDefinition: result,
805
877
  isFormatted
806
878
  });
807
- }))).join(lineEnd);
879
+ }));
880
+ log.debug(`Rendered ${results.length} preflights`);
881
+ return results.join(lineEnd);
808
882
  }
809
883
  async renderAtomicStyles(isFormatted, options = {}) {
884
+ log.debug("Rendering atomic styles...");
810
885
  const { atomicStyleIds = null, isPreview = false } = options;
886
+ const atomicStyles = atomicStyleIds == null ? [...this.store.atomicStyles.values()] : atomicStyleIds.map((id) => this.store.atomicStyles.get(id)).filter(isNotNullish);
887
+ log.debug(`Rendering ${atomicStyles.length} atomic styles (preview: ${isPreview})`);
811
888
  return renderAtomicStyles({
812
- atomicStyles: atomicStyleIds == null ? [...this.store.atomicStyles.values()] : atomicStyleIds.map((id) => this.store.atomicStyles.get(id)).filter(isNotNullish),
889
+ atomicStyles,
813
890
  isPreview,
814
891
  isFormatted,
815
892
  defaultSelector: this.config.defaultSelector
@@ -825,6 +902,7 @@ function resolvePreflight(preflight) {
825
902
  }
826
903
  async function resolveEngineConfig(config) {
827
904
  const { prefix = "", defaultSelector = `.${ATOMIC_STYLE_ID_PLACEHOLDER}`, plugins = [], preflights = [] } = config;
905
+ log.debug(`Resolving engine config with prefix: "${prefix}", plugins: ${plugins.length}, preflights: ${preflights.length}`);
828
906
  const resolvedConfig = {
829
907
  rawConfig: config,
830
908
  plugins: resolvePlugins(plugins),
@@ -842,6 +920,7 @@ async function resolveEngineConfig(config) {
842
920
  };
843
921
  const resolvedPreflights = preflights.map(resolvePreflight);
844
922
  resolvedConfig.preflights.push(...resolvedPreflights);
923
+ log.debug(`Engine config resolved: ${resolvedPreflights.length} preflights processed`);
845
924
  return resolvedConfig;
846
925
  }
847
926
  function getAtomicStyleId({ content, prefix, stored }) {
@@ -851,10 +930,14 @@ function getAtomicStyleId({ content, prefix, stored }) {
851
930
  content.value
852
931
  ]);
853
932
  const cached = stored.get(key);
854
- if (cached != null) return cached;
933
+ if (cached != null) {
934
+ log.debug(`Atomic style cached: ${cached}`);
935
+ return cached;
936
+ }
855
937
  const num = stored.size;
856
938
  const id = `${prefix}${numberToChars(num)}`;
857
939
  stored.set(key, id);
940
+ log.debug(`Generated new atomic style ID: ${id}`);
858
941
  return id;
859
942
  }
860
943
  function optimizeAtomicStyleContents(list) {
@@ -961,8 +1044,8 @@ exports.appendAutocompletePropertyValues = appendAutocompletePropertyValues;
961
1044
  exports.appendAutocompleteSelectors = appendAutocompleteSelectors;
962
1045
  exports.appendAutocompleteStyleItemStrings = appendAutocompleteStyleItemStrings;
963
1046
  exports.createEngine = createEngine;
1047
+ exports.createLogger = createLogger;
964
1048
  exports.defineEngineConfig = defineEngineConfig;
965
1049
  exports.defineEnginePlugin = defineEnginePlugin;
966
- exports.renderCSSStyleBlocks = renderCSSStyleBlocks;
967
- exports.setWarnFn = setWarnFn;
968
- exports.warn = warn;
1050
+ exports.log = log;
1051
+ exports.renderCSSStyleBlocks = renderCSSStyleBlocks;
package/dist/index.d.cts CHANGED
@@ -512,8 +512,30 @@ declare class Engine {
512
512
  }
513
513
  //#endregion
514
514
  //#region src/internal/utils.d.ts
515
- declare function setWarnFn(fn: (...args: any[]) => void): void;
516
- declare function warn(...args: any[]): void;
515
+ declare function createLogger(prefix: string): {
516
+ debug: (...args: any[]) => void;
517
+ info: (...args: any[]) => void;
518
+ warn: (...args: any[]) => void;
519
+ error: (...args: any[]) => void;
520
+ toggleDebug: () => void;
521
+ setPrefix: (newPrefix: string) => void;
522
+ setDebugFn: (fn: (prefix: string, ...args: any[]) => void) => void;
523
+ setInfoFn: (fn: (prefix: string, ...args: any[]) => void) => void;
524
+ setWarnFn: (fn: (prefix: string, ...args: any[]) => void) => void;
525
+ setErrorFn: (fn: (prefix: string, ...args: any[]) => void) => void;
526
+ };
527
+ declare const log: {
528
+ debug: (...args: any[]) => void;
529
+ info: (...args: any[]) => void;
530
+ warn: (...args: any[]) => void;
531
+ error: (...args: any[]) => void;
532
+ toggleDebug: () => void;
533
+ setPrefix: (newPrefix: string) => void;
534
+ setDebugFn: (fn: (prefix: string, ...args: any[]) => void) => void;
535
+ setInfoFn: (fn: (prefix: string, ...args: any[]) => void) => void;
536
+ setWarnFn: (fn: (prefix: string, ...args: any[]) => void) => void;
537
+ setErrorFn: (fn: (prefix: string, ...args: any[]) => void) => void;
538
+ };
517
539
  declare function appendAutocompleteSelectors(config: Pick<ResolvedEngineConfig, 'autocomplete'>, ...selectors: string[]): void;
518
540
  declare function appendAutocompleteStyleItemStrings(config: Pick<ResolvedEngineConfig, 'autocomplete'>, ...styleItemStrings: string[]): void;
519
541
  declare function appendAutocompleteExtraProperties(config: Pick<ResolvedEngineConfig, 'autocomplete'>, ...properties: string[]): void;
@@ -538,4 +560,4 @@ type MakeStyleDefinition<MaxDepth extends number, Tuple extends any[] = []> = Tu
538
560
  type StyleDefinition = MakeStyleDefinition<5>;
539
561
  type StyleItem = UnionString | ResolvedAutocomplete['StyleItemString'] | StyleDefinition;
540
562
  //#endregion
541
- export { Arrayable, Awaitable, type CSSProperty, type CSSSelectors, type CSSStyleBlockBody, type CSSStyleBlocks, type DefineAutocomplete, type Engine, type EngineConfig, type EnginePlugin, FromKebab, GetValue, IsEqual, IsNever, Nullish, type PikaAugment, type Properties, ResolveFrom, Simplify, type StyleDefinition, type StyleItem, ToKebab, UnionNumber, UnionString, UnionToIntersection, appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createEngine, defineEngineConfig, defineEnginePlugin, renderCSSStyleBlocks, setWarnFn, warn };
563
+ export { Arrayable, Awaitable, type CSSProperty, type CSSSelectors, type CSSStyleBlockBody, type CSSStyleBlocks, type DefineAutocomplete, type Engine, type EngineConfig, type EnginePlugin, FromKebab, GetValue, IsEqual, IsNever, Nullish, type PikaAugment, type Properties, ResolveFrom, Simplify, type StyleDefinition, type StyleItem, ToKebab, UnionNumber, UnionString, UnionToIntersection, appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createEngine, createLogger, defineEngineConfig, defineEnginePlugin, log, renderCSSStyleBlocks };
package/dist/index.d.mts CHANGED
@@ -512,8 +512,30 @@ declare class Engine {
512
512
  }
513
513
  //#endregion
514
514
  //#region src/internal/utils.d.ts
515
- declare function setWarnFn(fn: (...args: any[]) => void): void;
516
- declare function warn(...args: any[]): void;
515
+ declare function createLogger(prefix: string): {
516
+ debug: (...args: any[]) => void;
517
+ info: (...args: any[]) => void;
518
+ warn: (...args: any[]) => void;
519
+ error: (...args: any[]) => void;
520
+ toggleDebug: () => void;
521
+ setPrefix: (newPrefix: string) => void;
522
+ setDebugFn: (fn: (prefix: string, ...args: any[]) => void) => void;
523
+ setInfoFn: (fn: (prefix: string, ...args: any[]) => void) => void;
524
+ setWarnFn: (fn: (prefix: string, ...args: any[]) => void) => void;
525
+ setErrorFn: (fn: (prefix: string, ...args: any[]) => void) => void;
526
+ };
527
+ declare const log: {
528
+ debug: (...args: any[]) => void;
529
+ info: (...args: any[]) => void;
530
+ warn: (...args: any[]) => void;
531
+ error: (...args: any[]) => void;
532
+ toggleDebug: () => void;
533
+ setPrefix: (newPrefix: string) => void;
534
+ setDebugFn: (fn: (prefix: string, ...args: any[]) => void) => void;
535
+ setInfoFn: (fn: (prefix: string, ...args: any[]) => void) => void;
536
+ setWarnFn: (fn: (prefix: string, ...args: any[]) => void) => void;
537
+ setErrorFn: (fn: (prefix: string, ...args: any[]) => void) => void;
538
+ };
517
539
  declare function appendAutocompleteSelectors(config: Pick<ResolvedEngineConfig, 'autocomplete'>, ...selectors: string[]): void;
518
540
  declare function appendAutocompleteStyleItemStrings(config: Pick<ResolvedEngineConfig, 'autocomplete'>, ...styleItemStrings: string[]): void;
519
541
  declare function appendAutocompleteExtraProperties(config: Pick<ResolvedEngineConfig, 'autocomplete'>, ...properties: string[]): void;
@@ -538,4 +560,4 @@ type MakeStyleDefinition<MaxDepth extends number, Tuple extends any[] = []> = Tu
538
560
  type StyleDefinition = MakeStyleDefinition<5>;
539
561
  type StyleItem = UnionString | ResolvedAutocomplete['StyleItemString'] | StyleDefinition;
540
562
  //#endregion
541
- export { Arrayable, Awaitable, type CSSProperty, type CSSSelectors, type CSSStyleBlockBody, type CSSStyleBlocks, type DefineAutocomplete, type Engine, type EngineConfig, type EnginePlugin, FromKebab, GetValue, IsEqual, IsNever, Nullish, type PikaAugment, type Properties, ResolveFrom, Simplify, type StyleDefinition, type StyleItem, ToKebab, UnionNumber, UnionString, UnionToIntersection, appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createEngine, defineEngineConfig, defineEnginePlugin, renderCSSStyleBlocks, setWarnFn, warn };
563
+ export { Arrayable, Awaitable, type CSSProperty, type CSSSelectors, type CSSStyleBlockBody, type CSSStyleBlocks, type DefineAutocomplete, type Engine, type EngineConfig, type EnginePlugin, FromKebab, GetValue, IsEqual, IsNever, Nullish, type PikaAugment, type Properties, ResolveFrom, Simplify, type StyleDefinition, type StyleItem, ToKebab, UnionNumber, UnionString, UnionToIntersection, appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createEngine, createLogger, defineEngineConfig, defineEnginePlugin, log, renderCSSStyleBlocks };
package/dist/index.mjs CHANGED
@@ -4,15 +4,48 @@ const ATOMIC_STYLE_ID_PLACEHOLDER_RE_GLOBAL = /%/g;
4
4
 
5
5
  //#endregion
6
6
  //#region src/internal/utils.ts
7
- let _warn = (...args) => {
8
- console.warn("[@pikacss/core]", ...args);
9
- };
10
- function setWarnFn(fn) {
11
- _warn = fn;
12
- }
13
- function warn(...args) {
14
- _warn(...args);
7
+ function createLogger(prefix) {
8
+ let currentPrefix = prefix;
9
+ let enabledDebug = false;
10
+ let _debug = console.log;
11
+ let _info = console.log;
12
+ let _warn = console.warn;
13
+ let _error = console.error;
14
+ return {
15
+ debug: (...args) => {
16
+ if (!enabledDebug) return;
17
+ _debug(`${currentPrefix}[DEBUG]`, ...args);
18
+ },
19
+ info: (...args) => {
20
+ _info(`${currentPrefix}[INFO]`, ...args);
21
+ },
22
+ warn: (...args) => {
23
+ _warn(`${currentPrefix}[WARN]`, ...args);
24
+ },
25
+ error: (...args) => {
26
+ _error(`${currentPrefix}[ERROR]`, ...args);
27
+ },
28
+ toggleDebug() {
29
+ enabledDebug = !enabledDebug;
30
+ },
31
+ setPrefix(newPrefix) {
32
+ currentPrefix = newPrefix;
33
+ },
34
+ setDebugFn(fn) {
35
+ _debug = fn;
36
+ },
37
+ setInfoFn(fn) {
38
+ _info = fn;
39
+ },
40
+ setWarnFn(fn) {
41
+ _warn = fn;
42
+ },
43
+ setErrorFn(fn) {
44
+ _error = fn;
45
+ }
46
+ };
15
47
  }
48
+ const log = createLogger("[PikaCSS]");
16
49
  const chars = [..."abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"];
17
50
  const numOfChars = chars.length;
18
51
  function numberToChars(num) {
@@ -149,27 +182,35 @@ function createExtractFn(options) {
149
182
  //#endregion
150
183
  //#region src/internal/plugin.ts
151
184
  async function execAsyncHook(plugins, hook, payload) {
185
+ log.debug(`Executing async hook: ${hook}`);
152
186
  for (const plugin of plugins) {
153
187
  if (plugin[hook] == null) continue;
154
188
  try {
189
+ log.debug(` - Plugin "${plugin.name}" executing ${hook}`);
155
190
  const newPayload = await plugin[hook](payload);
156
191
  if (newPayload != null) payload = newPayload;
192
+ log.debug(` - Plugin "${plugin.name}" completed ${hook}`);
157
193
  } catch (error) {
158
- warn(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
194
+ log.error(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
159
195
  }
160
196
  }
197
+ log.debug(`Async hook "${hook}" completed`);
161
198
  return payload;
162
199
  }
163
200
  function execSyncHook(plugins, hook, payload) {
201
+ log.debug(`Executing sync hook: ${hook}`);
164
202
  for (const plugin of plugins) {
165
203
  if (plugin[hook] == null) continue;
166
204
  try {
205
+ log.debug(` - Plugin "${plugin.name}" executing ${hook}`);
167
206
  const newPayload = plugin[hook](payload);
168
207
  if (newPayload != null) payload = newPayload;
208
+ log.debug(` - Plugin "${plugin.name}" completed ${hook}`);
169
209
  } catch (error) {
170
- warn(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
210
+ log.error(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
171
211
  }
172
212
  }
213
+ log.debug(`Sync hook "${hook}" completed`);
173
214
  return payload;
174
215
  }
175
216
  const hooks = {
@@ -323,33 +364,48 @@ var AbstractResolver = class {
323
364
  return [...this.dynamicRulesMap.values()];
324
365
  }
325
366
  addStaticRule(rule) {
367
+ log.debug(`Adding static rule: ${rule.key}`);
326
368
  this.staticRulesMap.set(rule.key, rule);
327
369
  return this;
328
370
  }
329
371
  removeStaticRule(key) {
330
372
  const rule = this.staticRulesMap.get(key);
331
- if (rule == null) return this;
373
+ if (rule == null) {
374
+ log.warn(`Static rule not found for removal: ${key}`);
375
+ return this;
376
+ }
377
+ log.debug(`Removing static rule: ${key}`);
332
378
  this.staticRulesMap.delete(key);
333
379
  this._resolvedResultsMap.delete(rule.string);
334
380
  return this;
335
381
  }
336
382
  addDynamicRule(rule) {
383
+ log.debug(`Adding dynamic rule: ${rule.key}`);
337
384
  this.dynamicRulesMap.set(rule.key, rule);
338
385
  return this;
339
386
  }
340
387
  removeDynamicRule(key) {
341
388
  const rule = this.dynamicRulesMap.get(key);
342
- if (rule == null) return this;
389
+ if (rule == null) {
390
+ log.warn(`Dynamic rule not found for removal: ${key}`);
391
+ return this;
392
+ }
393
+ log.debug(`Removing dynamic rule: ${key}`);
343
394
  const matchedResolvedStringList = Array.from(this._resolvedResultsMap.keys()).filter((string) => rule.stringPattern.test(string));
344
395
  this.dynamicRulesMap.delete(key);
345
396
  matchedResolvedStringList.forEach((string) => this._resolvedResultsMap.delete(string));
397
+ log.debug(` - Cleared ${matchedResolvedStringList.length} cached results`);
346
398
  return this;
347
399
  }
348
400
  async _resolve(string) {
349
401
  const existedResult = this._resolvedResultsMap.get(string);
350
- if (existedResult != null) return existedResult;
402
+ if (existedResult != null) {
403
+ log.debug(`Resolved from cache: ${string}`);
404
+ return existedResult;
405
+ }
351
406
  const staticRule = Array.from(this.staticRulesMap.values()).find((rule) => rule.string === string);
352
407
  if (staticRule != null) {
408
+ log.debug(`Resolved by static rule: ${staticRule.key}`);
353
409
  const resolvedResult = { value: staticRule.resolved };
354
410
  this._resolvedResultsMap.set(string, resolvedResult);
355
411
  this.onResolved(string, "static", resolvedResult);
@@ -365,11 +421,13 @@ var AbstractResolver = class {
365
421
  }
366
422
  }
367
423
  if (dynamicRule != null && matched != null) {
424
+ log.debug(`Resolved by dynamic rule: ${dynamicRule.key}`);
368
425
  const resolvedResult = { value: await dynamicRule.createResolved(matched) };
369
426
  this._resolvedResultsMap.set(string, resolvedResult);
370
427
  this.onResolved(string, "dynamic", resolvedResult);
371
428
  return resolvedResult;
372
429
  }
430
+ log.debug(`Resolution failed for: ${string}`);
373
431
  }
374
432
  _setResolvedResult(string, resolved) {
375
433
  const resolvedResult = this._resolvedResultsMap.get(string);
@@ -424,7 +482,7 @@ function selectors() {
424
482
  var SelectorResolver = class extends AbstractResolver {
425
483
  async resolve(selector) {
426
484
  const resolved = await this._resolve(selector).catch((error) => {
427
- warn(`Failed to resolve selector "${selector}": ${error.message}`, error);
485
+ log.warn(`Failed to resolve selector "${selector}": ${error.message}`, error);
428
486
  });
429
487
  if (resolved == null) return [selector];
430
488
  const result = [];
@@ -547,7 +605,7 @@ function shortcuts() {
547
605
  var ShortcutResolver = class extends AbstractResolver {
548
606
  async resolve(shortcut) {
549
607
  const resolved = await this._resolve(shortcut).catch((error) => {
550
- warn(`Failed to resolve shortcut "${shortcut}": ${error.message}`, error);
608
+ log.warn(`Failed to resolve shortcut "${shortcut}": ${error.message}`, error);
551
609
  });
552
610
  if (resolved == null) return [shortcut];
553
611
  const result = [];
@@ -701,19 +759,27 @@ function defineEngineConfig(config) {
701
759
  }
702
760
  /* c8 ignore end */
703
761
  async function createEngine(config = {}) {
704
- config.plugins = resolvePlugins([...[
762
+ log.debug("Creating engine with config:", config);
763
+ const corePlugins = [
705
764
  important(),
706
765
  variables(),
707
766
  keyframes(),
708
767
  selectors(),
709
768
  shortcuts()
710
- ], ...config.plugins || []]);
769
+ ];
770
+ log.debug("Core plugins loaded:", corePlugins.length);
771
+ const plugins = resolvePlugins([...corePlugins, ...config.plugins || []]);
772
+ config.plugins = plugins;
773
+ log.debug(`Total plugins resolved: ${plugins.length}`);
711
774
  config = await hooks.configureRawConfig(config.plugins, config);
712
775
  hooks.rawConfigConfigured(resolvePlugins(config.plugins || []), config);
713
776
  let resolvedConfig = await resolveEngineConfig(config);
777
+ log.debug("Engine config resolved with prefix:", resolvedConfig.prefix);
714
778
  resolvedConfig = await hooks.configureResolvedConfig(resolvedConfig.plugins, resolvedConfig);
715
779
  let engine = new Engine(resolvedConfig);
780
+ log.debug("Engine instance created");
716
781
  engine = await hooks.configureEngine(engine.config.plugins, engine);
782
+ log.debug("Engine initialized successfully");
717
783
  return engine;
718
784
  }
719
785
  var Engine = class {
@@ -765,10 +831,13 @@ var Engine = class {
765
831
  this.notifyAutocompleteConfigUpdated();
766
832
  }
767
833
  addPreflight(preflight) {
834
+ log.debug("Adding preflight");
768
835
  this.config.preflights.push(resolvePreflight(preflight));
836
+ log.debug(`Total preflights: ${this.config.preflights.length}`);
769
837
  this.notifyPreflightUpdated();
770
838
  }
771
839
  async use(...itemList) {
840
+ log.debug(`Processing ${itemList.length} style items`);
772
841
  const { unknown, contents } = await resolveStyleItemList({
773
842
  itemList,
774
843
  transformStyleItems: (styleItems) => hooks.transformStyleItems(this.config.plugins, styleItems),
@@ -788,14 +857,17 @@ var Engine = class {
788
857
  content
789
858
  };
790
859
  this.store.atomicStyles.set(id, atomicStyle);
860
+ log.debug(`Atomic style added: ${id}`);
791
861
  this.notifyAtomicStyleAdded(atomicStyle);
792
862
  }
793
863
  });
864
+ log.debug(`Resolved ${resolvedIds.length} atomic styles, ${unknown.size} unknown items`);
794
865
  return [...unknown, ...resolvedIds];
795
866
  }
796
867
  async renderPreflights(isFormatted) {
868
+ log.debug("Rendering preflights...");
797
869
  const lineEnd = isFormatted ? "\n" : "";
798
- return (await Promise.all(this.config.preflights.map(async (p) => {
870
+ const results = await Promise.all(this.config.preflights.map(async (p) => {
799
871
  const result = await p(this, isFormatted);
800
872
  if (typeof result === "string") return result;
801
873
  return renderPreflightDefinition({
@@ -803,12 +875,17 @@ var Engine = class {
803
875
  preflightDefinition: result,
804
876
  isFormatted
805
877
  });
806
- }))).join(lineEnd);
878
+ }));
879
+ log.debug(`Rendered ${results.length} preflights`);
880
+ return results.join(lineEnd);
807
881
  }
808
882
  async renderAtomicStyles(isFormatted, options = {}) {
883
+ log.debug("Rendering atomic styles...");
809
884
  const { atomicStyleIds = null, isPreview = false } = options;
885
+ const atomicStyles = atomicStyleIds == null ? [...this.store.atomicStyles.values()] : atomicStyleIds.map((id) => this.store.atomicStyles.get(id)).filter(isNotNullish);
886
+ log.debug(`Rendering ${atomicStyles.length} atomic styles (preview: ${isPreview})`);
810
887
  return renderAtomicStyles({
811
- atomicStyles: atomicStyleIds == null ? [...this.store.atomicStyles.values()] : atomicStyleIds.map((id) => this.store.atomicStyles.get(id)).filter(isNotNullish),
888
+ atomicStyles,
812
889
  isPreview,
813
890
  isFormatted,
814
891
  defaultSelector: this.config.defaultSelector
@@ -824,6 +901,7 @@ function resolvePreflight(preflight) {
824
901
  }
825
902
  async function resolveEngineConfig(config) {
826
903
  const { prefix = "", defaultSelector = `.${ATOMIC_STYLE_ID_PLACEHOLDER}`, plugins = [], preflights = [] } = config;
904
+ log.debug(`Resolving engine config with prefix: "${prefix}", plugins: ${plugins.length}, preflights: ${preflights.length}`);
827
905
  const resolvedConfig = {
828
906
  rawConfig: config,
829
907
  plugins: resolvePlugins(plugins),
@@ -841,6 +919,7 @@ async function resolveEngineConfig(config) {
841
919
  };
842
920
  const resolvedPreflights = preflights.map(resolvePreflight);
843
921
  resolvedConfig.preflights.push(...resolvedPreflights);
922
+ log.debug(`Engine config resolved: ${resolvedPreflights.length} preflights processed`);
844
923
  return resolvedConfig;
845
924
  }
846
925
  function getAtomicStyleId({ content, prefix, stored }) {
@@ -850,10 +929,14 @@ function getAtomicStyleId({ content, prefix, stored }) {
850
929
  content.value
851
930
  ]);
852
931
  const cached = stored.get(key);
853
- if (cached != null) return cached;
932
+ if (cached != null) {
933
+ log.debug(`Atomic style cached: ${cached}`);
934
+ return cached;
935
+ }
854
936
  const num = stored.size;
855
937
  const id = `${prefix}${numberToChars(num)}`;
856
938
  stored.set(key, id);
939
+ log.debug(`Generated new atomic style ID: ${id}`);
857
940
  return id;
858
941
  }
859
942
  function optimizeAtomicStyleContents(list) {
@@ -953,4 +1036,4 @@ async function renderPreflightDefinition(payload) {
953
1036
  /* c8 ignore end */
954
1037
 
955
1038
  //#endregion
956
- export { appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createEngine, defineEngineConfig, defineEnginePlugin, renderCSSStyleBlocks, setWarnFn, warn };
1039
+ export { appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createEngine, createLogger, defineEngineConfig, defineEnginePlugin, log, renderCSSStyleBlocks };
package/package.json CHANGED
@@ -1,15 +1,12 @@
1
1
  {
2
2
  "name": "@pikacss/core",
3
3
  "type": "module",
4
- "publishConfig": {
5
- "access": "public"
6
- },
7
- "version": "0.0.33",
4
+ "version": "0.0.35",
8
5
  "author": "DevilTea <ch19980814@gmail.com>",
9
6
  "license": "MIT",
10
7
  "repository": {
11
8
  "type": "git",
12
- "url": "git+https://github.com/DevilTea/pikacss.git",
9
+ "url": "https://github.com/pikacss/pikacss.git",
13
10
  "directory": "packages/core"
14
11
  },
15
12
  "bugs": {
@@ -36,6 +33,9 @@
36
33
  "main": "dist/index.cjs",
37
34
  "module": "dist/index.mjs",
38
35
  "types": "dist/index.d.mts",
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
39
  "files": [
40
40
  "dist"
41
41
  ],
@@ -43,7 +43,7 @@
43
43
  "csstype": "^3.2.3"
44
44
  },
45
45
  "scripts": {
46
- "build": "tsdown",
46
+ "build": "tsdown && pnpm exec publint",
47
47
  "typecheck": "pnpm typecheck:package && pnpm typecheck:test",
48
48
  "typecheck:package": "tsc --project ./tsconfig.package.json --noEmit",
49
49
  "typecheck:test": "tsc --project ./tsconfig.tests.json --noEmit",