regor 1.5.6 → 1.5.8

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.
@@ -1635,7 +1635,9 @@ var ComponentBinder = class {
1635
1635
  const contextAliasName = binder.__config.__builtInNames.contextAlias;
1636
1636
  const bindName = binder.__config.__builtInNames.bind;
1637
1637
  const definedProps = (_b = (_a = registeredComponent.props) == null ? void 0 : _a.map(camelize)) != null ? _b : [];
1638
- const getProps = (component2, capturedContext2) => {
1638
+ const inheritedPropAttrs = [];
1639
+ const isInheritableSpecialProp = (propName) => propName === "class" || propName === "style";
1640
+ const getProps = (component2, capturedContext2, collectInheritedPropAttrs = false) => {
1639
1641
  const props = {};
1640
1642
  const hasContext = component2.hasAttribute(contextName);
1641
1643
  parser.__scoped(capturedContext2, () => {
@@ -1658,7 +1660,11 @@ var ComponentBinder = class {
1658
1660
  ]) {
1659
1661
  const value = component2.getAttribute(name);
1660
1662
  if (value === null) continue;
1661
- props[camelize(name)] = value;
1663
+ const propName = camelize(name);
1664
+ props[propName] = value;
1665
+ if (collectInheritedPropAttrs && registeredComponent.inheritAttrs === true && isInheritableSpecialProp(propName)) {
1666
+ inheritedPropAttrs.push({ name, value });
1667
+ }
1662
1668
  component2.removeAttribute(name);
1663
1669
  }
1664
1670
  const map = binder.__directiveCollector.__collect(component2, false);
@@ -1670,6 +1676,11 @@ var ComponentBinder = class {
1670
1676
  );
1671
1677
  if (!propName) continue;
1672
1678
  if (name !== "." && name !== ":" && name !== bindName) continue;
1679
+ if (collectInheritedPropAttrs && name !== "." && registeredComponent.inheritAttrs === true && isInheritableSpecialProp(propName)) {
1680
+ const value = component2.getAttribute(attrName);
1681
+ if (value !== null)
1682
+ inheritedPropAttrs.push({ name: attrName, value });
1683
+ }
1673
1684
  binder.__bind(
1674
1685
  singlePropDirective,
1675
1686
  component2,
@@ -1685,7 +1696,7 @@ var ComponentBinder = class {
1685
1696
  const capturedContext = [...parser.__capture()];
1686
1697
  const createComponentCtx = () => {
1687
1698
  var _a2;
1688
- const props = getProps(component, capturedContext);
1699
+ const props = getProps(component, capturedContext, true);
1689
1700
  const head2 = new ComponentHead(
1690
1701
  props,
1691
1702
  component,
@@ -1845,25 +1856,47 @@ var ComponentBinder = class {
1845
1856
  );
1846
1857
  const inheritor = inheritorChildNodes[0];
1847
1858
  if (!inheritor) return;
1848
- for (const attrName of component.getAttributeNames()) {
1849
- if (attrName === contextName || attrName === contextAliasName)
1850
- continue;
1851
- const value = component.getAttribute(attrName);
1859
+ const bindClassName = `${bindName}:class`;
1860
+ const bindStyleName = `${bindName}:style`;
1861
+ const mergeBinding = (shortName, longName, value) => {
1862
+ const existingAttr = inheritor.hasAttribute(shortName) ? shortName : inheritor.hasAttribute(longName) ? longName : shortName;
1863
+ const existingValue = inheritor.getAttribute(existingAttr);
1864
+ inheritor.setAttribute(
1865
+ existingAttr,
1866
+ isNullOrWhitespace(existingValue) ? value : `${existingValue}, ${value}`
1867
+ );
1868
+ };
1869
+ const transferAttribute = (attrName, value) => {
1852
1870
  if (attrName === "class") {
1853
1871
  const classTokens = toClassTokens(value);
1854
1872
  if (classTokens.length > 0) inheritor.classList.add(...classTokens);
1873
+ } else if (attrName === ":class" || attrName === bindClassName) {
1874
+ mergeBinding(":class", bindClassName, value);
1855
1875
  } else if (attrName === "style") {
1856
1876
  const inheritorStyle = inheritor.style;
1857
1877
  const componentStyle = component.style;
1858
1878
  for (const s of componentStyle) {
1859
1879
  inheritorStyle.setProperty(s, componentStyle.getPropertyValue(s));
1860
1880
  }
1881
+ } else if (attrName === ":style" || attrName === bindStyleName) {
1882
+ mergeBinding(":style", bindStyleName, value);
1861
1883
  } else {
1862
1884
  inheritor.setAttribute(
1863
1885
  normalizeAttributeName(attrName, binder.__config),
1864
1886
  value
1865
1887
  );
1866
1888
  }
1889
+ };
1890
+ for (const { name, value } of inheritedPropAttrs) {
1891
+ component.setAttribute(name, value);
1892
+ }
1893
+ for (const attrName of component.getAttributeNames()) {
1894
+ if (attrName === contextName || attrName === contextAliasName)
1895
+ continue;
1896
+ transferAttribute(
1897
+ attrName,
1898
+ component.getAttribute(attrName)
1899
+ );
1867
1900
  }
1868
1901
  };
1869
1902
  const clearUnusedAttributes = () => {
@@ -3266,30 +3299,34 @@ var classDirective = {
3266
3299
  })
3267
3300
  };
3268
3301
  var patchClass = (el, next, prev) => {
3302
+ const nextValue = unref(next);
3303
+ const prevValue = unref(prev);
3269
3304
  const classList = el.classList;
3270
- const isClassString = isString(next);
3271
- const isPrevClassString = isString(prev);
3272
- if (next && !isClassString) {
3273
- if (prev && !isPrevClassString) {
3274
- for (const key in prev) {
3275
- if (!(key in next) || !next[key]) {
3305
+ const isClassString = isString(nextValue);
3306
+ const isPrevClassString = isString(prevValue);
3307
+ if (nextValue && !isClassString) {
3308
+ const nextMap = nextValue;
3309
+ if (prevValue && !isPrevClassString) {
3310
+ const prevMap = prevValue;
3311
+ for (const key in prevMap) {
3312
+ if (!(key in nextMap) || !unref(nextMap[key])) {
3276
3313
  classList.remove(key);
3277
3314
  }
3278
3315
  }
3279
3316
  }
3280
- for (const key in next) {
3281
- if (next[key]) classList.add(key);
3317
+ for (const key in nextMap) {
3318
+ if (unref(nextMap[key])) classList.add(key);
3282
3319
  }
3283
3320
  } else {
3284
3321
  if (isClassString) {
3285
- if (prev !== next) {
3286
- const prevTokens = isPrevClassString ? toClassTokens(prev) : [];
3287
- const nextTokens = toClassTokens(next);
3322
+ if (prevValue !== nextValue) {
3323
+ const prevTokens = isPrevClassString ? toClassTokens(prevValue) : [];
3324
+ const nextTokens = toClassTokens(nextValue);
3288
3325
  if (prevTokens.length > 0) classList.remove(...prevTokens);
3289
3326
  if (nextTokens.length > 0) classList.add(...nextTokens);
3290
3327
  }
3291
- } else if (prev) {
3292
- const prevTokens = isPrevClassString ? toClassTokens(prev) : [];
3328
+ } else if (prevValue) {
3329
+ const prevTokens = isPrevClassString ? toClassTokens(prevValue) : [];
3293
3330
  if (prevTokens.length > 0) classList.remove(...prevTokens);
3294
3331
  }
3295
3332
  }
@@ -3966,26 +4003,30 @@ var styleDirective = {
3966
4003
  })
3967
4004
  };
3968
4005
  var patchStyle = (el, next, prev) => {
4006
+ const nextValue = unref(next);
4007
+ const prevValue = unref(prev);
3969
4008
  const style = el.style;
3970
- const isCssString = isString(next);
3971
- if (next && !isCssString) {
3972
- if (prev && !isString(prev)) {
3973
- for (const key in prev) {
3974
- if (next[key] == null) {
4009
+ const isCssString = isString(nextValue);
4010
+ if (nextValue && !isCssString) {
4011
+ const nextMap = nextValue;
4012
+ if (prevValue && !isString(prevValue)) {
4013
+ const prevMap = prevValue;
4014
+ for (const key in prevMap) {
4015
+ if (unref(nextMap[key]) == null) {
3975
4016
  setStyle(style, key, "");
3976
4017
  }
3977
4018
  }
3978
4019
  }
3979
- for (const key in next) {
3980
- setStyle(style, key, next[key]);
4020
+ for (const key in nextMap) {
4021
+ setStyle(style, key, nextMap[key]);
3981
4022
  }
3982
4023
  } else {
3983
4024
  const currentDisplay = style.display;
3984
4025
  if (isCssString) {
3985
- if (prev !== next) {
3986
- style.cssText = next;
4026
+ if (prevValue !== nextValue) {
4027
+ style.cssText = nextValue;
3987
4028
  }
3988
- } else if (prev) {
4029
+ } else if (prevValue) {
3989
4030
  el.removeAttribute("style");
3990
4031
  }
3991
4032
  const data = getBindData(el).data;
@@ -3995,24 +4036,25 @@ var patchStyle = (el, next, prev) => {
3995
4036
  };
3996
4037
  var importantRE = /\s*!important$/;
3997
4038
  function setStyle(style, name, val) {
3998
- if (isArray(val)) {
3999
- val.forEach((v) => {
4039
+ const value = unref(val);
4040
+ if (isArray(value)) {
4041
+ value.forEach((v) => {
4000
4042
  setStyle(style, name, v);
4001
4043
  });
4002
4044
  } else {
4003
- if (val == null) val = "";
4045
+ const cssValue = value == null ? "" : String(value);
4004
4046
  if (name.startsWith("--")) {
4005
- style.setProperty(name, val);
4047
+ style.setProperty(name, cssValue);
4006
4048
  } else {
4007
4049
  const prefixed = autoPrefix(style, name);
4008
- if (importantRE.test(val)) {
4050
+ if (importantRE.test(cssValue)) {
4009
4051
  style.setProperty(
4010
4052
  hyphenate(prefixed),
4011
- val.replace(importantRE, ""),
4053
+ cssValue.replace(importantRE, ""),
4012
4054
  "important"
4013
4055
  );
4014
4056
  } else {
4015
- style[prefixed] = val;
4057
+ style[prefixed] = cssValue;
4016
4058
  }
4017
4059
  }
4018
4060
  }