@4399ywkf/core 5.0.19 → 5.0.20

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.js CHANGED
@@ -3594,12 +3594,18 @@ var themePlugin = createPlugin((options = {}) => ({
3594
3594
  order: 10,
3595
3595
  }`;
3596
3596
  if (code.includes("providers: []")) {
3597
- code = code.replace("providers: []", `providers: [
3597
+ code = code.replace(
3598
+ "providers: []",
3599
+ `providers: [
3598
3600
  ${providerEntry},
3599
- ]`);
3601
+ ]`
3602
+ );
3600
3603
  } else if (code.includes("providers: [")) {
3601
- code = code.replace("providers: [", `providers: [
3602
- ${providerEntry},`);
3604
+ code = code.replace(
3605
+ "providers: [",
3606
+ `providers: [
3607
+ ${providerEntry},`
3608
+ );
3603
3609
  }
3604
3610
  if (!code.includes("import React")) {
3605
3611
  code = code.replace(
@@ -3629,13 +3635,23 @@ function generateThemeProvider(opts) {
3629
3635
  sections.push(`// \u6B64\u6587\u4EF6\u7531 @4399ywkf/plugin-theme v3 \u81EA\u52A8\u751F\u6210\uFF0C\u8BF7\u52FF\u624B\u52A8\u4FEE\u6539`);
3630
3636
  sections.push(buildImports({ globalReset, cssVar }));
3631
3637
  sections.push(TYPES_CODE);
3632
- sections.push(buildStoreCode({ defaultAppearance, primaryColor, neutralColor }));
3638
+ sections.push(
3639
+ buildStoreCode({ defaultAppearance, primaryColor, neutralColor })
3640
+ );
3633
3641
  sections.push(HOOKS_CODE);
3634
3642
  if (globalReset) sections.push(GLOBAL_RESET_CODE);
3635
- if (cssVar) sections.push(CSS_VAR_SYNC_CODE);
3643
+ if (cssVar) sections.push(buildCssVarSyncCode());
3636
3644
  if (darkMode) sections.push(APPEARANCE_SYNC_CODE);
3637
3645
  if (externalTheme) sections.push(EXTERNAL_THEME_CODE);
3638
- sections.push(buildWrapperCode({ darkMode, cssVar, globalReset, externalTheme, prefixCls }));
3646
+ sections.push(
3647
+ buildWrapperCode({
3648
+ darkMode,
3649
+ cssVar,
3650
+ globalReset,
3651
+ externalTheme,
3652
+ prefixCls
3653
+ })
3654
+ );
3639
3655
  return sections.join("\n");
3640
3656
  }
3641
3657
  function buildImports(opts) {
@@ -3777,10 +3793,15 @@ const GlobalReset = createGlobalStyle(({ theme }) => css\`
3777
3793
  -webkit-text-fill-color: unset !important;
3778
3794
  }
3779
3795
  \`);`;
3780
- var CSS_VAR_SYNC_CODE = `
3796
+ function buildCssVarSyncCode() {
3797
+ return `
3781
3798
  // \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 CSS Variable Sync \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
3782
3799
 
3783
- const CSS_VAR_PREFIX = "css-var-";
3800
+ const CSS_VAR_CLASS_RE = /(^|-)css-var(-|$)/;
3801
+
3802
+ function isCssVarClassName(className: string): boolean {
3803
+ return CSS_VAR_CLASS_RE.test(className);
3804
+ }
3784
3805
 
3785
3806
  function useCssVarSync(ref: React.RefObject<HTMLDivElement | null>) {
3786
3807
  useLayoutEffect(() => {
@@ -3791,18 +3812,28 @@ function useCssVarSync(ref: React.RefObject<HTMLDivElement | null>) {
3791
3812
  let currentClasses: string[] = [];
3792
3813
 
3793
3814
  const sync = () => {
3794
- for (const cls of currentClasses) htmlEl.classList.remove(cls);
3815
+ for (const cls of currentClasses) {
3816
+ htmlEl.classList.remove(cls);
3817
+ }
3795
3818
 
3796
- const next: string[] = [];
3819
+ const nextSet = new Set<string>();
3797
3820
  let el: HTMLElement | null = node;
3821
+
3798
3822
  while (el && el !== htmlEl) {
3799
3823
  for (const cls of el.classList) {
3800
- if (cls.startsWith(CSS_VAR_PREFIX)) next.push(cls);
3824
+ if (isCssVarClassName(cls)) {
3825
+ nextSet.add(cls);
3826
+ }
3801
3827
  }
3802
3828
  el = el.parentElement;
3803
3829
  }
3804
3830
 
3805
- for (const cls of next) htmlEl.classList.add(cls);
3831
+ const next = Array.from(nextSet);
3832
+
3833
+ for (const cls of next) {
3834
+ htmlEl.classList.add(cls);
3835
+ }
3836
+
3806
3837
  currentClasses = next;
3807
3838
  };
3808
3839
 
@@ -3817,10 +3848,13 @@ function useCssVarSync(ref: React.RefObject<HTMLDivElement | null>) {
3817
3848
 
3818
3849
  return () => {
3819
3850
  observer.disconnect();
3820
- for (const cls of currentClasses) htmlEl.classList.remove(cls);
3851
+ for (const cls of currentClasses) {
3852
+ htmlEl.classList.remove(cls);
3853
+ }
3821
3854
  };
3822
3855
  }, []);
3823
3856
  }`;
3857
+ }
3824
3858
  var APPEARANCE_SYNC_CODE = `
3825
3859
  // \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 Appearance Sync \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
3826
3860