@pikacss/core 0.0.10 → 0.0.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/dist/index.cjs CHANGED
@@ -3,6 +3,15 @@
3
3
  const ATOMIC_STYLE_ID_PLACEHOLDER = "$$";
4
4
  const ATOMIC_STYLE_ID_PLACEHOLDER_RE_GLOBAL = /\$\$/g;
5
5
 
6
+ let _warn = (...args) => {
7
+ console.warn("[@pikacss/core]", ...args);
8
+ };
9
+ function setWarnFn(fn) {
10
+ _warn = fn;
11
+ }
12
+ function warn(...args) {
13
+ _warn(...args);
14
+ }
6
15
  const chars = [..."abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"];
7
16
  const numOfChars = chars.length;
8
17
  function numberToChars(num) {
@@ -190,9 +199,13 @@ async function execAsyncHook(plugins, hook, payload) {
190
199
  for (const plugin of plugins) {
191
200
  if (plugin[hook] == null)
192
201
  continue;
193
- const newPayload = await plugin[hook](payload);
194
- if (newPayload != null)
195
- payload = newPayload;
202
+ try {
203
+ const newPayload = await plugin[hook](payload);
204
+ if (newPayload != null)
205
+ payload = newPayload;
206
+ } catch (error) {
207
+ warn(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
208
+ }
196
209
  }
197
210
  return payload;
198
211
  }
@@ -200,9 +213,13 @@ function execSyncHook(plugins, hook, payload) {
200
213
  for (const plugin of plugins) {
201
214
  if (plugin[hook] == null)
202
215
  continue;
203
- const newPayload = plugin[hook](payload);
204
- if (newPayload != null)
205
- payload = newPayload;
216
+ try {
217
+ const newPayload = plugin[hook](payload);
218
+ if (newPayload != null)
219
+ payload = newPayload;
220
+ } catch (error) {
221
+ warn(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
222
+ }
206
223
  }
207
224
  return payload;
208
225
  }
@@ -413,7 +430,10 @@ class AbstractResolver {
413
430
 
414
431
  class SelectorResolver extends AbstractResolver {
415
432
  async resolve(selector) {
416
- const resolved = await this._resolve(selector);
433
+ const resolved = await this._resolve(selector).catch((error) => {
434
+ warn(`Failed to resolve selector "${selector}": ${error.message}`, error);
435
+ return void 0;
436
+ });
417
437
  if (resolved == null)
418
438
  return [selector];
419
439
  const result = [];
@@ -426,7 +446,8 @@ class SelectorResolver extends AbstractResolver {
426
446
  function resolveSelectorConfig(config) {
427
447
  if (typeof config === "string") {
428
448
  return config;
429
- } else if (Array.isArray(config)) {
449
+ }
450
+ if (Array.isArray(config)) {
430
451
  if (typeof config[0] === "string" && typeof config[1] !== "function") {
431
452
  return {
432
453
  type: "static",
@@ -450,7 +471,9 @@ function resolveSelectorConfig(config) {
450
471
  autocomplete: config[2] != null ? [config[2]].flat(1) : []
451
472
  };
452
473
  }
453
- } else if (typeof config.selector === "string" && typeof config.value !== "function") {
474
+ return void 0;
475
+ }
476
+ if (typeof config.selector === "string" && typeof config.value !== "function") {
454
477
  return {
455
478
  type: "static",
456
479
  rule: {
@@ -460,7 +483,8 @@ function resolveSelectorConfig(config) {
460
483
  },
461
484
  autocomplete: [config.selector]
462
485
  };
463
- } else if (config.selector instanceof RegExp && typeof config.value === "function") {
486
+ }
487
+ if (config.selector instanceof RegExp && typeof config.value === "function") {
464
488
  const fn = config.value;
465
489
  return {
466
490
  type: "dynamic",
@@ -517,7 +541,10 @@ function selectors() {
517
541
 
518
542
  class ShortcutResolver extends AbstractResolver {
519
543
  async resolve(shortcut) {
520
- const resolved = await this._resolve(shortcut);
544
+ const resolved = await this._resolve(shortcut).catch((error) => {
545
+ warn(`Failed to resolve shortcut "${shortcut}": ${error.message}`, error);
546
+ return void 0;
547
+ });
521
548
  if (resolved == null)
522
549
  return [shortcut];
523
550
  const result = [];
@@ -580,7 +607,7 @@ function resolveShortcutConfig(config) {
580
607
  autocomplete: "autocomplete" in config && config.autocomplete != null ? [config.autocomplete].flat(1) : []
581
608
  };
582
609
  }
583
- throw new Error("Invalid shortcut config");
610
+ return void 0;
584
611
  }
585
612
  function shortcuts() {
586
613
  const shortcutResolver = new ShortcutResolver();
@@ -594,6 +621,8 @@ function shortcuts() {
594
621
  const autocompleteShortcuts = /* @__PURE__ */ new Set();
595
622
  configList.forEach((config) => {
596
623
  const resolved = resolveShortcutConfig(config);
624
+ if (resolved == null)
625
+ return;
597
626
  if (typeof resolved === "string") {
598
627
  addToSet(autocompleteShortcuts, resolved);
599
628
  return;
@@ -955,3 +984,5 @@ exports.createEngine = createEngine;
955
984
  exports.defineEngineConfig = defineEngineConfig;
956
985
  exports.defineEnginePlugin = defineEnginePlugin;
957
986
  exports.renderCSSStyleBlocks = renderCSSStyleBlocks;
987
+ exports.setWarnFn = setWarnFn;
988
+ exports.warn = warn;
package/dist/index.d.cts CHANGED
@@ -404,6 +404,8 @@ type MakeStyleDefinition<Autocomplete_ extends Autocomplete, MaxDepth extends nu
404
404
  type StyleDefinition<Autocomplete_ extends Autocomplete = EmptyAutocomplete> = MakeStyleDefinition<Autocomplete_, 5>;
405
405
  type StyleItem<Autocomplete_ extends Autocomplete = EmptyAutocomplete> = UnionString | Autocomplete_['StyleItemString'] | StyleDefinition<Autocomplete_>;
406
406
 
407
+ declare function setWarnFn(fn: (...args: any[]) => void): void;
408
+ declare function warn(...args: any[]): void;
407
409
  declare function appendAutocompleteSelectors(config: Pick<ResolvedEngineConfig, 'autocomplete'>, ...selectors: string[]): void;
408
410
  declare function appendAutocompleteStyleItemStrings(config: Pick<ResolvedEngineConfig, 'autocomplete'>, ...styleItemStrings: string[]): void;
409
411
  declare function appendAutocompleteExtraProperties(config: Pick<ResolvedEngineConfig, 'autocomplete'>, ...properties: string[]): void;
@@ -417,4 +419,4 @@ declare const defineEnginePlugin: <C extends Record<string, any>>(plugin: Engine
417
419
  declare function createDefineEngineConfigFn<A extends Autocomplete = EmptyAutocomplete>(): <P extends EnginePlugin[] = []>(config: EngineConfig<P, A["Selector"] | CSSSelectors, A["ExtraCssProperty"] | CSSProperty, Properties<A>, StyleDefinition<A>, StyleItem<A>> & PluginsCustomConfig<P>) => EngineConfig<P> & PluginsCustomConfig<P>;
418
420
  declare const defineEngineConfig: <P extends EnginePlugin[] = []>(config: EngineConfig<P, CSSSelectors, keyof CSSProperties, Properties<EmptyAutocomplete>, StyleDefinition<EmptyAutocomplete>, StyleItem<EmptyAutocomplete>> & PluginsCustomConfig<P, {}>) => EngineConfig<P, string, string, Properties$1, StyleDefinition$1, StyleItem$1> & PluginsCustomConfig<P, {}>;
419
421
 
420
- export { type Arrayable, type Autocomplete, type Awaitable, type CSSStyleBlockBody, type CSSStyleBlocks, type EmptyAutocomplete, Engine, type EngineConfig, type EnginePlugin, type FromKebab, type GetValue, type IsEqual, type PluginsCustomConfig, type Properties, type Simplify, type StyleDefinition, type StyleItem, type ToKebab, type UnionNumber, type UnionString, type UnionToIntersection, appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createDefineEngineConfigFn, createDefineEnginePluginFn, createEngine, defineEngineConfig, defineEnginePlugin, renderCSSStyleBlocks };
422
+ export { type Arrayable, type Autocomplete, type Awaitable, type CSSStyleBlockBody, type CSSStyleBlocks, type EmptyAutocomplete, Engine, type EngineConfig, type EnginePlugin, type FromKebab, type GetValue, type IsEqual, type PluginsCustomConfig, type Properties, type Simplify, type StyleDefinition, type StyleItem, type ToKebab, type UnionNumber, type UnionString, type UnionToIntersection, appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createDefineEngineConfigFn, createDefineEnginePluginFn, createEngine, defineEngineConfig, defineEnginePlugin, renderCSSStyleBlocks, setWarnFn, warn };
package/dist/index.d.mts CHANGED
@@ -404,6 +404,8 @@ type MakeStyleDefinition<Autocomplete_ extends Autocomplete, MaxDepth extends nu
404
404
  type StyleDefinition<Autocomplete_ extends Autocomplete = EmptyAutocomplete> = MakeStyleDefinition<Autocomplete_, 5>;
405
405
  type StyleItem<Autocomplete_ extends Autocomplete = EmptyAutocomplete> = UnionString | Autocomplete_['StyleItemString'] | StyleDefinition<Autocomplete_>;
406
406
 
407
+ declare function setWarnFn(fn: (...args: any[]) => void): void;
408
+ declare function warn(...args: any[]): void;
407
409
  declare function appendAutocompleteSelectors(config: Pick<ResolvedEngineConfig, 'autocomplete'>, ...selectors: string[]): void;
408
410
  declare function appendAutocompleteStyleItemStrings(config: Pick<ResolvedEngineConfig, 'autocomplete'>, ...styleItemStrings: string[]): void;
409
411
  declare function appendAutocompleteExtraProperties(config: Pick<ResolvedEngineConfig, 'autocomplete'>, ...properties: string[]): void;
@@ -417,4 +419,4 @@ declare const defineEnginePlugin: <C extends Record<string, any>>(plugin: Engine
417
419
  declare function createDefineEngineConfigFn<A extends Autocomplete = EmptyAutocomplete>(): <P extends EnginePlugin[] = []>(config: EngineConfig<P, A["Selector"] | CSSSelectors, A["ExtraCssProperty"] | CSSProperty, Properties<A>, StyleDefinition<A>, StyleItem<A>> & PluginsCustomConfig<P>) => EngineConfig<P> & PluginsCustomConfig<P>;
418
420
  declare const defineEngineConfig: <P extends EnginePlugin[] = []>(config: EngineConfig<P, CSSSelectors, keyof CSSProperties, Properties<EmptyAutocomplete>, StyleDefinition<EmptyAutocomplete>, StyleItem<EmptyAutocomplete>> & PluginsCustomConfig<P, {}>) => EngineConfig<P, string, string, Properties$1, StyleDefinition$1, StyleItem$1> & PluginsCustomConfig<P, {}>;
419
421
 
420
- export { type Arrayable, type Autocomplete, type Awaitable, type CSSStyleBlockBody, type CSSStyleBlocks, type EmptyAutocomplete, Engine, type EngineConfig, type EnginePlugin, type FromKebab, type GetValue, type IsEqual, type PluginsCustomConfig, type Properties, type Simplify, type StyleDefinition, type StyleItem, type ToKebab, type UnionNumber, type UnionString, type UnionToIntersection, appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createDefineEngineConfigFn, createDefineEnginePluginFn, createEngine, defineEngineConfig, defineEnginePlugin, renderCSSStyleBlocks };
422
+ export { type Arrayable, type Autocomplete, type Awaitable, type CSSStyleBlockBody, type CSSStyleBlocks, type EmptyAutocomplete, Engine, type EngineConfig, type EnginePlugin, type FromKebab, type GetValue, type IsEqual, type PluginsCustomConfig, type Properties, type Simplify, type StyleDefinition, type StyleItem, type ToKebab, type UnionNumber, type UnionString, type UnionToIntersection, appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createDefineEngineConfigFn, createDefineEnginePluginFn, createEngine, defineEngineConfig, defineEnginePlugin, renderCSSStyleBlocks, setWarnFn, warn };
package/dist/index.d.ts CHANGED
@@ -404,6 +404,8 @@ type MakeStyleDefinition<Autocomplete_ extends Autocomplete, MaxDepth extends nu
404
404
  type StyleDefinition<Autocomplete_ extends Autocomplete = EmptyAutocomplete> = MakeStyleDefinition<Autocomplete_, 5>;
405
405
  type StyleItem<Autocomplete_ extends Autocomplete = EmptyAutocomplete> = UnionString | Autocomplete_['StyleItemString'] | StyleDefinition<Autocomplete_>;
406
406
 
407
+ declare function setWarnFn(fn: (...args: any[]) => void): void;
408
+ declare function warn(...args: any[]): void;
407
409
  declare function appendAutocompleteSelectors(config: Pick<ResolvedEngineConfig, 'autocomplete'>, ...selectors: string[]): void;
408
410
  declare function appendAutocompleteStyleItemStrings(config: Pick<ResolvedEngineConfig, 'autocomplete'>, ...styleItemStrings: string[]): void;
409
411
  declare function appendAutocompleteExtraProperties(config: Pick<ResolvedEngineConfig, 'autocomplete'>, ...properties: string[]): void;
@@ -417,4 +419,4 @@ declare const defineEnginePlugin: <C extends Record<string, any>>(plugin: Engine
417
419
  declare function createDefineEngineConfigFn<A extends Autocomplete = EmptyAutocomplete>(): <P extends EnginePlugin[] = []>(config: EngineConfig<P, A["Selector"] | CSSSelectors, A["ExtraCssProperty"] | CSSProperty, Properties<A>, StyleDefinition<A>, StyleItem<A>> & PluginsCustomConfig<P>) => EngineConfig<P> & PluginsCustomConfig<P>;
418
420
  declare const defineEngineConfig: <P extends EnginePlugin[] = []>(config: EngineConfig<P, CSSSelectors, keyof CSSProperties, Properties<EmptyAutocomplete>, StyleDefinition<EmptyAutocomplete>, StyleItem<EmptyAutocomplete>> & PluginsCustomConfig<P, {}>) => EngineConfig<P, string, string, Properties$1, StyleDefinition$1, StyleItem$1> & PluginsCustomConfig<P, {}>;
419
421
 
420
- export { type Arrayable, type Autocomplete, type Awaitable, type CSSStyleBlockBody, type CSSStyleBlocks, type EmptyAutocomplete, Engine, type EngineConfig, type EnginePlugin, type FromKebab, type GetValue, type IsEqual, type PluginsCustomConfig, type Properties, type Simplify, type StyleDefinition, type StyleItem, type ToKebab, type UnionNumber, type UnionString, type UnionToIntersection, appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createDefineEngineConfigFn, createDefineEnginePluginFn, createEngine, defineEngineConfig, defineEnginePlugin, renderCSSStyleBlocks };
422
+ export { type Arrayable, type Autocomplete, type Awaitable, type CSSStyleBlockBody, type CSSStyleBlocks, type EmptyAutocomplete, Engine, type EngineConfig, type EnginePlugin, type FromKebab, type GetValue, type IsEqual, type PluginsCustomConfig, type Properties, type Simplify, type StyleDefinition, type StyleItem, type ToKebab, type UnionNumber, type UnionString, type UnionToIntersection, appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createDefineEngineConfigFn, createDefineEnginePluginFn, createEngine, defineEngineConfig, defineEnginePlugin, renderCSSStyleBlocks, setWarnFn, warn };
package/dist/index.mjs CHANGED
@@ -1,6 +1,15 @@
1
1
  const ATOMIC_STYLE_ID_PLACEHOLDER = "$$";
2
2
  const ATOMIC_STYLE_ID_PLACEHOLDER_RE_GLOBAL = /\$\$/g;
3
3
 
4
+ let _warn = (...args) => {
5
+ console.warn("[@pikacss/core]", ...args);
6
+ };
7
+ function setWarnFn(fn) {
8
+ _warn = fn;
9
+ }
10
+ function warn(...args) {
11
+ _warn(...args);
12
+ }
4
13
  const chars = [..."abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"];
5
14
  const numOfChars = chars.length;
6
15
  function numberToChars(num) {
@@ -188,9 +197,13 @@ async function execAsyncHook(plugins, hook, payload) {
188
197
  for (const plugin of plugins) {
189
198
  if (plugin[hook] == null)
190
199
  continue;
191
- const newPayload = await plugin[hook](payload);
192
- if (newPayload != null)
193
- payload = newPayload;
200
+ try {
201
+ const newPayload = await plugin[hook](payload);
202
+ if (newPayload != null)
203
+ payload = newPayload;
204
+ } catch (error) {
205
+ warn(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
206
+ }
194
207
  }
195
208
  return payload;
196
209
  }
@@ -198,9 +211,13 @@ function execSyncHook(plugins, hook, payload) {
198
211
  for (const plugin of plugins) {
199
212
  if (plugin[hook] == null)
200
213
  continue;
201
- const newPayload = plugin[hook](payload);
202
- if (newPayload != null)
203
- payload = newPayload;
214
+ try {
215
+ const newPayload = plugin[hook](payload);
216
+ if (newPayload != null)
217
+ payload = newPayload;
218
+ } catch (error) {
219
+ warn(`Plugin "${plugin.name}" failed to execute hook "${hook}": ${error.message}`, error);
220
+ }
204
221
  }
205
222
  return payload;
206
223
  }
@@ -411,7 +428,10 @@ class AbstractResolver {
411
428
 
412
429
  class SelectorResolver extends AbstractResolver {
413
430
  async resolve(selector) {
414
- const resolved = await this._resolve(selector);
431
+ const resolved = await this._resolve(selector).catch((error) => {
432
+ warn(`Failed to resolve selector "${selector}": ${error.message}`, error);
433
+ return void 0;
434
+ });
415
435
  if (resolved == null)
416
436
  return [selector];
417
437
  const result = [];
@@ -424,7 +444,8 @@ class SelectorResolver extends AbstractResolver {
424
444
  function resolveSelectorConfig(config) {
425
445
  if (typeof config === "string") {
426
446
  return config;
427
- } else if (Array.isArray(config)) {
447
+ }
448
+ if (Array.isArray(config)) {
428
449
  if (typeof config[0] === "string" && typeof config[1] !== "function") {
429
450
  return {
430
451
  type: "static",
@@ -448,7 +469,9 @@ function resolveSelectorConfig(config) {
448
469
  autocomplete: config[2] != null ? [config[2]].flat(1) : []
449
470
  };
450
471
  }
451
- } else if (typeof config.selector === "string" && typeof config.value !== "function") {
472
+ return void 0;
473
+ }
474
+ if (typeof config.selector === "string" && typeof config.value !== "function") {
452
475
  return {
453
476
  type: "static",
454
477
  rule: {
@@ -458,7 +481,8 @@ function resolveSelectorConfig(config) {
458
481
  },
459
482
  autocomplete: [config.selector]
460
483
  };
461
- } else if (config.selector instanceof RegExp && typeof config.value === "function") {
484
+ }
485
+ if (config.selector instanceof RegExp && typeof config.value === "function") {
462
486
  const fn = config.value;
463
487
  return {
464
488
  type: "dynamic",
@@ -515,7 +539,10 @@ function selectors() {
515
539
 
516
540
  class ShortcutResolver extends AbstractResolver {
517
541
  async resolve(shortcut) {
518
- const resolved = await this._resolve(shortcut);
542
+ const resolved = await this._resolve(shortcut).catch((error) => {
543
+ warn(`Failed to resolve shortcut "${shortcut}": ${error.message}`, error);
544
+ return void 0;
545
+ });
519
546
  if (resolved == null)
520
547
  return [shortcut];
521
548
  const result = [];
@@ -578,7 +605,7 @@ function resolveShortcutConfig(config) {
578
605
  autocomplete: "autocomplete" in config && config.autocomplete != null ? [config.autocomplete].flat(1) : []
579
606
  };
580
607
  }
581
- throw new Error("Invalid shortcut config");
608
+ return void 0;
582
609
  }
583
610
  function shortcuts() {
584
611
  const shortcutResolver = new ShortcutResolver();
@@ -592,6 +619,8 @@ function shortcuts() {
592
619
  const autocompleteShortcuts = /* @__PURE__ */ new Set();
593
620
  configList.forEach((config) => {
594
621
  const resolved = resolveShortcutConfig(config);
622
+ if (resolved == null)
623
+ return;
595
624
  if (typeof resolved === "string") {
596
625
  addToSet(autocompleteShortcuts, resolved);
597
626
  return;
@@ -941,4 +970,4 @@ function createDefineEngineConfigFn() {
941
970
  }
942
971
  const defineEngineConfig = createDefineEngineConfigFn();
943
972
 
944
- export { appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createDefineEngineConfigFn, createDefineEnginePluginFn, createEngine, defineEngineConfig, defineEnginePlugin, renderCSSStyleBlocks };
973
+ export { appendAutocompleteCssPropertyValues, appendAutocompleteExtraCssProperties, appendAutocompleteExtraProperties, appendAutocompletePropertyValues, appendAutocompleteSelectors, appendAutocompleteStyleItemStrings, createDefineEngineConfigFn, createDefineEnginePluginFn, createEngine, defineEngineConfig, defineEnginePlugin, renderCSSStyleBlocks, setWarnFn, warn };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.0.10",
7
+ "version": "0.0.12",
8
8
  "author": "DevilTea <ch19980814@gmail.com>",
9
9
  "license": "MIT",
10
10
  "repository": {
@@ -44,7 +44,6 @@
44
44
  },
45
45
  "scripts": {
46
46
  "build": "unbuild",
47
- "build:pack": "pnpm build && pnpm pack",
48
47
  "stub": "unbuild --stub",
49
48
  "typecheck": "pnpm typecheck:package && pnpm typecheck:test",
50
49
  "typecheck:package": "tsc --project ./tsconfig.package.json --noEmit",