@pikacss/core 0.0.20 → 0.0.22

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
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const ATOMIC_STYLE_ID_PLACEHOLDER = "$$";
4
- const ATOMIC_STYLE_ID_PLACEHOLDER_RE_GLOBAL = /\$\$/g;
3
+ const ATOMIC_STYLE_ID_PLACEHOLDER = "%";
4
+ const ATOMIC_STYLE_ID_PLACEHOLDER_RE_GLOBAL = /%/g;
5
5
 
6
6
  let _warn = (...args) => {
7
7
  console.warn("[@pikacss/core]", ...args);
@@ -895,10 +895,16 @@ class Engine {
895
895
  return renderAtomicStyles({
896
896
  atomicStyles,
897
897
  isPreview,
898
- isFormatted
898
+ isFormatted,
899
+ defaultSelector: this.config.defaultSelector
899
900
  });
900
901
  }
901
902
  }
903
+ function calcAtomicStyleRenderingWeight(style, defaultSelector) {
904
+ const { selector } = style.content;
905
+ const isDefaultSelector = selector.length === 1 && selector[0] === defaultSelector;
906
+ return isDefaultSelector ? 0 : selector.length;
907
+ }
902
908
  function resolvePreflight(preflight) {
903
909
  return typeof preflight === "function" ? preflight : () => preflight;
904
910
  }
@@ -972,9 +978,13 @@ async function resolveStyleItemList({
972
978
  };
973
979
  }
974
980
  function renderAtomicStyles(payload) {
975
- const { atomicStyles, isPreview, isFormatted } = payload;
981
+ const { atomicStyles, isPreview, isFormatted, defaultSelector } = payload;
976
982
  const blocks = /* @__PURE__ */ new Map();
977
- atomicStyles.forEach(({ id, content: { selector, property, value } }) => {
983
+ Array.from(atomicStyles).sort((a, b) => {
984
+ const weightA = calcAtomicStyleRenderingWeight(a, defaultSelector);
985
+ const weightB = calcAtomicStyleRenderingWeight(b, defaultSelector);
986
+ return weightA - weightB;
987
+ }).forEach(({ id, content: { selector, property, value } }) => {
978
988
  const isValidSelector = selector.some((s) => s.includes(ATOMIC_STYLE_ID_PLACEHOLDER));
979
989
  if (isValidSelector === false || value == null)
980
990
  return;
package/dist/index.d.cts CHANGED
@@ -395,15 +395,15 @@ interface EngineConfig {
395
395
  */
396
396
  prefix?: string;
397
397
  /**
398
- * Set the default selector format. '$$' will be replaced with the atomic style id.
398
+ * Set the default selector format. '%' will be replaced with the atomic style id.
399
399
  *
400
- * @default '.$$'
400
+ * @default '.%'
401
401
  * @example
402
402
  * ```ts
403
403
  * {
404
- * defaultSelector: '.$$' // Use with class attribute: <div class="a b c">
404
+ * defaultSelector: '.%' // Use with class attribute: <div class="a b c">
405
405
  * // or
406
- * defaultSelector: '[data-pika~="$$"]' // Use with attribute selector: <div data-pika="a b c">
406
+ * defaultSelector: '[data-pika~="%"]' // Use with attribute selector: <div data-pika="a b c">
407
407
  * }
408
408
  * ```
409
409
  */
package/dist/index.d.mts CHANGED
@@ -395,15 +395,15 @@ interface EngineConfig {
395
395
  */
396
396
  prefix?: string;
397
397
  /**
398
- * Set the default selector format. '$$' will be replaced with the atomic style id.
398
+ * Set the default selector format. '%' will be replaced with the atomic style id.
399
399
  *
400
- * @default '.$$'
400
+ * @default '.%'
401
401
  * @example
402
402
  * ```ts
403
403
  * {
404
- * defaultSelector: '.$$' // Use with class attribute: <div class="a b c">
404
+ * defaultSelector: '.%' // Use with class attribute: <div class="a b c">
405
405
  * // or
406
- * defaultSelector: '[data-pika~="$$"]' // Use with attribute selector: <div data-pika="a b c">
406
+ * defaultSelector: '[data-pika~="%"]' // Use with attribute selector: <div data-pika="a b c">
407
407
  * }
408
408
  * ```
409
409
  */
package/dist/index.d.ts CHANGED
@@ -395,15 +395,15 @@ interface EngineConfig {
395
395
  */
396
396
  prefix?: string;
397
397
  /**
398
- * Set the default selector format. '$$' will be replaced with the atomic style id.
398
+ * Set the default selector format. '%' will be replaced with the atomic style id.
399
399
  *
400
- * @default '.$$'
400
+ * @default '.%'
401
401
  * @example
402
402
  * ```ts
403
403
  * {
404
- * defaultSelector: '.$$' // Use with class attribute: <div class="a b c">
404
+ * defaultSelector: '.%' // Use with class attribute: <div class="a b c">
405
405
  * // or
406
- * defaultSelector: '[data-pika~="$$"]' // Use with attribute selector: <div data-pika="a b c">
406
+ * defaultSelector: '[data-pika~="%"]' // Use with attribute selector: <div data-pika="a b c">
407
407
  * }
408
408
  * ```
409
409
  */
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- const ATOMIC_STYLE_ID_PLACEHOLDER = "$$";
2
- const ATOMIC_STYLE_ID_PLACEHOLDER_RE_GLOBAL = /\$\$/g;
1
+ const ATOMIC_STYLE_ID_PLACEHOLDER = "%";
2
+ const ATOMIC_STYLE_ID_PLACEHOLDER_RE_GLOBAL = /%/g;
3
3
 
4
4
  let _warn = (...args) => {
5
5
  console.warn("[@pikacss/core]", ...args);
@@ -893,10 +893,16 @@ class Engine {
893
893
  return renderAtomicStyles({
894
894
  atomicStyles,
895
895
  isPreview,
896
- isFormatted
896
+ isFormatted,
897
+ defaultSelector: this.config.defaultSelector
897
898
  });
898
899
  }
899
900
  }
901
+ function calcAtomicStyleRenderingWeight(style, defaultSelector) {
902
+ const { selector } = style.content;
903
+ const isDefaultSelector = selector.length === 1 && selector[0] === defaultSelector;
904
+ return isDefaultSelector ? 0 : selector.length;
905
+ }
900
906
  function resolvePreflight(preflight) {
901
907
  return typeof preflight === "function" ? preflight : () => preflight;
902
908
  }
@@ -970,9 +976,13 @@ async function resolveStyleItemList({
970
976
  };
971
977
  }
972
978
  function renderAtomicStyles(payload) {
973
- const { atomicStyles, isPreview, isFormatted } = payload;
979
+ const { atomicStyles, isPreview, isFormatted, defaultSelector } = payload;
974
980
  const blocks = /* @__PURE__ */ new Map();
975
- atomicStyles.forEach(({ id, content: { selector, property, value } }) => {
981
+ Array.from(atomicStyles).sort((a, b) => {
982
+ const weightA = calcAtomicStyleRenderingWeight(a, defaultSelector);
983
+ const weightB = calcAtomicStyleRenderingWeight(b, defaultSelector);
984
+ return weightA - weightB;
985
+ }).forEach(({ id, content: { selector, property, value } }) => {
976
986
  const isValidSelector = selector.some((s) => s.includes(ATOMIC_STYLE_ID_PLACEHOLDER));
977
987
  if (isValidSelector === false || value == null)
978
988
  return;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.0.20",
7
+ "version": "0.0.22",
8
8
  "author": "DevilTea <ch19980814@gmail.com>",
9
9
  "license": "MIT",
10
10
  "repository": {