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.
@@ -1703,7 +1703,9 @@ var Regor = (() => {
1703
1703
  const contextAliasName = binder.__config.__builtInNames.contextAlias;
1704
1704
  const bindName = binder.__config.__builtInNames.bind;
1705
1705
  const definedProps = (_b = (_a = registeredComponent.props) == null ? void 0 : _a.map(camelize)) != null ? _b : [];
1706
- const getProps = (component2, capturedContext2) => {
1706
+ const inheritedPropAttrs = [];
1707
+ const isInheritableSpecialProp = (propName) => propName === "class" || propName === "style";
1708
+ const getProps = (component2, capturedContext2, collectInheritedPropAttrs = false) => {
1707
1709
  const props = {};
1708
1710
  const hasContext = component2.hasAttribute(contextName);
1709
1711
  parser.__scoped(capturedContext2, () => {
@@ -1726,7 +1728,11 @@ var Regor = (() => {
1726
1728
  ]) {
1727
1729
  const value = component2.getAttribute(name);
1728
1730
  if (value === null) continue;
1729
- props[camelize(name)] = value;
1731
+ const propName = camelize(name);
1732
+ props[propName] = value;
1733
+ if (collectInheritedPropAttrs && registeredComponent.inheritAttrs === true && isInheritableSpecialProp(propName)) {
1734
+ inheritedPropAttrs.push({ name, value });
1735
+ }
1730
1736
  component2.removeAttribute(name);
1731
1737
  }
1732
1738
  const map = binder.__directiveCollector.__collect(component2, false);
@@ -1738,6 +1744,11 @@ var Regor = (() => {
1738
1744
  );
1739
1745
  if (!propName) continue;
1740
1746
  if (name !== "." && name !== ":" && name !== bindName) continue;
1747
+ if (collectInheritedPropAttrs && name !== "." && registeredComponent.inheritAttrs === true && isInheritableSpecialProp(propName)) {
1748
+ const value = component2.getAttribute(attrName);
1749
+ if (value !== null)
1750
+ inheritedPropAttrs.push({ name: attrName, value });
1751
+ }
1741
1752
  binder.__bind(
1742
1753
  singlePropDirective,
1743
1754
  component2,
@@ -1753,7 +1764,7 @@ var Regor = (() => {
1753
1764
  const capturedContext = [...parser.__capture()];
1754
1765
  const createComponentCtx = () => {
1755
1766
  var _a2;
1756
- const props = getProps(component, capturedContext);
1767
+ const props = getProps(component, capturedContext, true);
1757
1768
  const head2 = new ComponentHead(
1758
1769
  props,
1759
1770
  component,
@@ -1913,25 +1924,47 @@ var Regor = (() => {
1913
1924
  );
1914
1925
  const inheritor = inheritorChildNodes[0];
1915
1926
  if (!inheritor) return;
1916
- for (const attrName of component.getAttributeNames()) {
1917
- if (attrName === contextName || attrName === contextAliasName)
1918
- continue;
1919
- const value = component.getAttribute(attrName);
1927
+ const bindClassName = `${bindName}:class`;
1928
+ const bindStyleName = `${bindName}:style`;
1929
+ const mergeBinding = (shortName, longName, value) => {
1930
+ const existingAttr = inheritor.hasAttribute(shortName) ? shortName : inheritor.hasAttribute(longName) ? longName : shortName;
1931
+ const existingValue = inheritor.getAttribute(existingAttr);
1932
+ inheritor.setAttribute(
1933
+ existingAttr,
1934
+ isNullOrWhitespace(existingValue) ? value : `${existingValue}, ${value}`
1935
+ );
1936
+ };
1937
+ const transferAttribute = (attrName, value) => {
1920
1938
  if (attrName === "class") {
1921
1939
  const classTokens = toClassTokens(value);
1922
1940
  if (classTokens.length > 0) inheritor.classList.add(...classTokens);
1941
+ } else if (attrName === ":class" || attrName === bindClassName) {
1942
+ mergeBinding(":class", bindClassName, value);
1923
1943
  } else if (attrName === "style") {
1924
1944
  const inheritorStyle = inheritor.style;
1925
1945
  const componentStyle = component.style;
1926
1946
  for (const s of componentStyle) {
1927
1947
  inheritorStyle.setProperty(s, componentStyle.getPropertyValue(s));
1928
1948
  }
1949
+ } else if (attrName === ":style" || attrName === bindStyleName) {
1950
+ mergeBinding(":style", bindStyleName, value);
1929
1951
  } else {
1930
1952
  inheritor.setAttribute(
1931
1953
  normalizeAttributeName(attrName, binder.__config),
1932
1954
  value
1933
1955
  );
1934
1956
  }
1957
+ };
1958
+ for (const { name, value } of inheritedPropAttrs) {
1959
+ component.setAttribute(name, value);
1960
+ }
1961
+ for (const attrName of component.getAttributeNames()) {
1962
+ if (attrName === contextName || attrName === contextAliasName)
1963
+ continue;
1964
+ transferAttribute(
1965
+ attrName,
1966
+ component.getAttribute(attrName)
1967
+ );
1935
1968
  }
1936
1969
  };
1937
1970
  const clearUnusedAttributes = () => {
@@ -3334,30 +3367,34 @@ var Regor = (() => {
3334
3367
  })
3335
3368
  };
3336
3369
  var patchClass = (el, next, prev) => {
3370
+ const nextValue = unref(next);
3371
+ const prevValue = unref(prev);
3337
3372
  const classList = el.classList;
3338
- const isClassString = isString(next);
3339
- const isPrevClassString = isString(prev);
3340
- if (next && !isClassString) {
3341
- if (prev && !isPrevClassString) {
3342
- for (const key in prev) {
3343
- if (!(key in next) || !next[key]) {
3373
+ const isClassString = isString(nextValue);
3374
+ const isPrevClassString = isString(prevValue);
3375
+ if (nextValue && !isClassString) {
3376
+ const nextMap = nextValue;
3377
+ if (prevValue && !isPrevClassString) {
3378
+ const prevMap = prevValue;
3379
+ for (const key in prevMap) {
3380
+ if (!(key in nextMap) || !unref(nextMap[key])) {
3344
3381
  classList.remove(key);
3345
3382
  }
3346
3383
  }
3347
3384
  }
3348
- for (const key in next) {
3349
- if (next[key]) classList.add(key);
3385
+ for (const key in nextMap) {
3386
+ if (unref(nextMap[key])) classList.add(key);
3350
3387
  }
3351
3388
  } else {
3352
3389
  if (isClassString) {
3353
- if (prev !== next) {
3354
- const prevTokens = isPrevClassString ? toClassTokens(prev) : [];
3355
- const nextTokens = toClassTokens(next);
3390
+ if (prevValue !== nextValue) {
3391
+ const prevTokens = isPrevClassString ? toClassTokens(prevValue) : [];
3392
+ const nextTokens = toClassTokens(nextValue);
3356
3393
  if (prevTokens.length > 0) classList.remove(...prevTokens);
3357
3394
  if (nextTokens.length > 0) classList.add(...nextTokens);
3358
3395
  }
3359
- } else if (prev) {
3360
- const prevTokens = isPrevClassString ? toClassTokens(prev) : [];
3396
+ } else if (prevValue) {
3397
+ const prevTokens = isPrevClassString ? toClassTokens(prevValue) : [];
3361
3398
  if (prevTokens.length > 0) classList.remove(...prevTokens);
3362
3399
  }
3363
3400
  }
@@ -4034,26 +4071,30 @@ var Regor = (() => {
4034
4071
  })
4035
4072
  };
4036
4073
  var patchStyle = (el, next, prev) => {
4074
+ const nextValue = unref(next);
4075
+ const prevValue = unref(prev);
4037
4076
  const style = el.style;
4038
- const isCssString = isString(next);
4039
- if (next && !isCssString) {
4040
- if (prev && !isString(prev)) {
4041
- for (const key in prev) {
4042
- if (next[key] == null) {
4077
+ const isCssString = isString(nextValue);
4078
+ if (nextValue && !isCssString) {
4079
+ const nextMap = nextValue;
4080
+ if (prevValue && !isString(prevValue)) {
4081
+ const prevMap = prevValue;
4082
+ for (const key in prevMap) {
4083
+ if (unref(nextMap[key]) == null) {
4043
4084
  setStyle(style, key, "");
4044
4085
  }
4045
4086
  }
4046
4087
  }
4047
- for (const key in next) {
4048
- setStyle(style, key, next[key]);
4088
+ for (const key in nextMap) {
4089
+ setStyle(style, key, nextMap[key]);
4049
4090
  }
4050
4091
  } else {
4051
4092
  const currentDisplay = style.display;
4052
4093
  if (isCssString) {
4053
- if (prev !== next) {
4054
- style.cssText = next;
4094
+ if (prevValue !== nextValue) {
4095
+ style.cssText = nextValue;
4055
4096
  }
4056
- } else if (prev) {
4097
+ } else if (prevValue) {
4057
4098
  el.removeAttribute("style");
4058
4099
  }
4059
4100
  const data = getBindData(el).data;
@@ -4063,24 +4104,25 @@ var Regor = (() => {
4063
4104
  };
4064
4105
  var importantRE = /\s*!important$/;
4065
4106
  function setStyle(style, name, val) {
4066
- if (isArray(val)) {
4067
- val.forEach((v) => {
4107
+ const value = unref(val);
4108
+ if (isArray(value)) {
4109
+ value.forEach((v) => {
4068
4110
  setStyle(style, name, v);
4069
4111
  });
4070
4112
  } else {
4071
- if (val == null) val = "";
4113
+ const cssValue = value == null ? "" : String(value);
4072
4114
  if (name.startsWith("--")) {
4073
- style.setProperty(name, val);
4115
+ style.setProperty(name, cssValue);
4074
4116
  } else {
4075
4117
  const prefixed = autoPrefix(style, name);
4076
- if (importantRE.test(val)) {
4118
+ if (importantRE.test(cssValue)) {
4077
4119
  style.setProperty(
4078
4120
  hyphenate(prefixed),
4079
- val.replace(importantRE, ""),
4121
+ cssValue.replace(importantRE, ""),
4080
4122
  "important"
4081
4123
  );
4082
4124
  } else {
4083
- style[prefixed] = val;
4125
+ style[prefixed] = cssValue;
4084
4126
  }
4085
4127
  }
4086
4128
  }