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.
@@ -1740,7 +1740,9 @@ var Regor = (() => {
1740
1740
  const contextAliasName = binder.__config.__builtInNames.contextAlias;
1741
1741
  const bindName = binder.__config.__builtInNames.bind;
1742
1742
  const definedProps = (_b = (_a = registeredComponent.props) == null ? void 0 : _a.map(camelize)) != null ? _b : [];
1743
- const getProps = (component2, capturedContext2) => {
1743
+ const inheritedPropAttrs = [];
1744
+ const isInheritableSpecialProp = (propName) => propName === "class" || propName === "style";
1745
+ const getProps = (component2, capturedContext2, collectInheritedPropAttrs = false) => {
1744
1746
  const props = {};
1745
1747
  const hasContext = component2.hasAttribute(contextName);
1746
1748
  parser.__scoped(capturedContext2, () => {
@@ -1763,7 +1765,11 @@ var Regor = (() => {
1763
1765
  ]) {
1764
1766
  const value = component2.getAttribute(name);
1765
1767
  if (value === null) continue;
1766
- props[camelize(name)] = value;
1768
+ const propName = camelize(name);
1769
+ props[propName] = value;
1770
+ if (collectInheritedPropAttrs && registeredComponent.inheritAttrs === true && isInheritableSpecialProp(propName)) {
1771
+ inheritedPropAttrs.push({ name, value });
1772
+ }
1767
1773
  component2.removeAttribute(name);
1768
1774
  }
1769
1775
  const map = binder.__directiveCollector.__collect(component2, false);
@@ -1775,6 +1781,11 @@ var Regor = (() => {
1775
1781
  );
1776
1782
  if (!propName) continue;
1777
1783
  if (name !== "." && name !== ":" && name !== bindName) continue;
1784
+ if (collectInheritedPropAttrs && name !== "." && registeredComponent.inheritAttrs === true && isInheritableSpecialProp(propName)) {
1785
+ const value = component2.getAttribute(attrName);
1786
+ if (value !== null)
1787
+ inheritedPropAttrs.push({ name: attrName, value });
1788
+ }
1778
1789
  binder.__bind(
1779
1790
  singlePropDirective,
1780
1791
  component2,
@@ -1790,7 +1801,7 @@ var Regor = (() => {
1790
1801
  const capturedContext = [...parser.__capture()];
1791
1802
  const createComponentCtx = () => {
1792
1803
  var _a2;
1793
- const props = getProps(component, capturedContext);
1804
+ const props = getProps(component, capturedContext, true);
1794
1805
  const head2 = new ComponentHead(
1795
1806
  props,
1796
1807
  component,
@@ -1950,25 +1961,47 @@ var Regor = (() => {
1950
1961
  );
1951
1962
  const inheritor = inheritorChildNodes[0];
1952
1963
  if (!inheritor) return;
1953
- for (const attrName of component.getAttributeNames()) {
1954
- if (attrName === contextName || attrName === contextAliasName)
1955
- continue;
1956
- const value = component.getAttribute(attrName);
1964
+ const bindClassName = `${bindName}:class`;
1965
+ const bindStyleName = `${bindName}:style`;
1966
+ const mergeBinding = (shortName, longName, value) => {
1967
+ const existingAttr = inheritor.hasAttribute(shortName) ? shortName : inheritor.hasAttribute(longName) ? longName : shortName;
1968
+ const existingValue = inheritor.getAttribute(existingAttr);
1969
+ inheritor.setAttribute(
1970
+ existingAttr,
1971
+ isNullOrWhitespace(existingValue) ? value : `${existingValue}, ${value}`
1972
+ );
1973
+ };
1974
+ const transferAttribute = (attrName, value) => {
1957
1975
  if (attrName === "class") {
1958
1976
  const classTokens = toClassTokens(value);
1959
1977
  if (classTokens.length > 0) inheritor.classList.add(...classTokens);
1978
+ } else if (attrName === ":class" || attrName === bindClassName) {
1979
+ mergeBinding(":class", bindClassName, value);
1960
1980
  } else if (attrName === "style") {
1961
1981
  const inheritorStyle = inheritor.style;
1962
1982
  const componentStyle = component.style;
1963
1983
  for (const s of componentStyle) {
1964
1984
  inheritorStyle.setProperty(s, componentStyle.getPropertyValue(s));
1965
1985
  }
1986
+ } else if (attrName === ":style" || attrName === bindStyleName) {
1987
+ mergeBinding(":style", bindStyleName, value);
1966
1988
  } else {
1967
1989
  inheritor.setAttribute(
1968
1990
  normalizeAttributeName(attrName, binder.__config),
1969
1991
  value
1970
1992
  );
1971
1993
  }
1994
+ };
1995
+ for (const { name, value } of inheritedPropAttrs) {
1996
+ component.setAttribute(name, value);
1997
+ }
1998
+ for (const attrName of component.getAttributeNames()) {
1999
+ if (attrName === contextName || attrName === contextAliasName)
2000
+ continue;
2001
+ transferAttribute(
2002
+ attrName,
2003
+ component.getAttribute(attrName)
2004
+ );
1972
2005
  }
1973
2006
  };
1974
2007
  const clearUnusedAttributes = () => {
@@ -3371,30 +3404,34 @@ var Regor = (() => {
3371
3404
  })
3372
3405
  };
3373
3406
  var patchClass = (el, next, prev) => {
3407
+ const nextValue = unref(next);
3408
+ const prevValue = unref(prev);
3374
3409
  const classList = el.classList;
3375
- const isClassString = isString(next);
3376
- const isPrevClassString = isString(prev);
3377
- if (next && !isClassString) {
3378
- if (prev && !isPrevClassString) {
3379
- for (const key in prev) {
3380
- if (!(key in next) || !next[key]) {
3410
+ const isClassString = isString(nextValue);
3411
+ const isPrevClassString = isString(prevValue);
3412
+ if (nextValue && !isClassString) {
3413
+ const nextMap = nextValue;
3414
+ if (prevValue && !isPrevClassString) {
3415
+ const prevMap = prevValue;
3416
+ for (const key in prevMap) {
3417
+ if (!(key in nextMap) || !unref(nextMap[key])) {
3381
3418
  classList.remove(key);
3382
3419
  }
3383
3420
  }
3384
3421
  }
3385
- for (const key in next) {
3386
- if (next[key]) classList.add(key);
3422
+ for (const key in nextMap) {
3423
+ if (unref(nextMap[key])) classList.add(key);
3387
3424
  }
3388
3425
  } else {
3389
3426
  if (isClassString) {
3390
- if (prev !== next) {
3391
- const prevTokens = isPrevClassString ? toClassTokens(prev) : [];
3392
- const nextTokens = toClassTokens(next);
3427
+ if (prevValue !== nextValue) {
3428
+ const prevTokens = isPrevClassString ? toClassTokens(prevValue) : [];
3429
+ const nextTokens = toClassTokens(nextValue);
3393
3430
  if (prevTokens.length > 0) classList.remove(...prevTokens);
3394
3431
  if (nextTokens.length > 0) classList.add(...nextTokens);
3395
3432
  }
3396
- } else if (prev) {
3397
- const prevTokens = isPrevClassString ? toClassTokens(prev) : [];
3433
+ } else if (prevValue) {
3434
+ const prevTokens = isPrevClassString ? toClassTokens(prevValue) : [];
3398
3435
  if (prevTokens.length > 0) classList.remove(...prevTokens);
3399
3436
  }
3400
3437
  }
@@ -4071,26 +4108,30 @@ var Regor = (() => {
4071
4108
  })
4072
4109
  };
4073
4110
  var patchStyle = (el, next, prev) => {
4111
+ const nextValue = unref(next);
4112
+ const prevValue = unref(prev);
4074
4113
  const style = el.style;
4075
- const isCssString = isString(next);
4076
- if (next && !isCssString) {
4077
- if (prev && !isString(prev)) {
4078
- for (const key in prev) {
4079
- if (next[key] == null) {
4114
+ const isCssString = isString(nextValue);
4115
+ if (nextValue && !isCssString) {
4116
+ const nextMap = nextValue;
4117
+ if (prevValue && !isString(prevValue)) {
4118
+ const prevMap = prevValue;
4119
+ for (const key in prevMap) {
4120
+ if (unref(nextMap[key]) == null) {
4080
4121
  setStyle(style, key, "");
4081
4122
  }
4082
4123
  }
4083
4124
  }
4084
- for (const key in next) {
4085
- setStyle(style, key, next[key]);
4125
+ for (const key in nextMap) {
4126
+ setStyle(style, key, nextMap[key]);
4086
4127
  }
4087
4128
  } else {
4088
4129
  const currentDisplay = style.display;
4089
4130
  if (isCssString) {
4090
- if (prev !== next) {
4091
- style.cssText = next;
4131
+ if (prevValue !== nextValue) {
4132
+ style.cssText = nextValue;
4092
4133
  }
4093
- } else if (prev) {
4134
+ } else if (prevValue) {
4094
4135
  el.removeAttribute("style");
4095
4136
  }
4096
4137
  const data = getBindData(el).data;
@@ -4100,24 +4141,25 @@ var Regor = (() => {
4100
4141
  };
4101
4142
  var importantRE = /\s*!important$/;
4102
4143
  function setStyle(style, name, val) {
4103
- if (isArray(val)) {
4104
- val.forEach((v) => {
4144
+ const value = unref(val);
4145
+ if (isArray(value)) {
4146
+ value.forEach((v) => {
4105
4147
  setStyle(style, name, v);
4106
4148
  });
4107
4149
  } else {
4108
- if (val == null) val = "";
4150
+ const cssValue = value == null ? "" : String(value);
4109
4151
  if (name.startsWith("--")) {
4110
- style.setProperty(name, val);
4152
+ style.setProperty(name, cssValue);
4111
4153
  } else {
4112
4154
  const prefixed = autoPrefix(style, name);
4113
- if (importantRE.test(val)) {
4155
+ if (importantRE.test(cssValue)) {
4114
4156
  style.setProperty(
4115
4157
  hyphenate(prefixed),
4116
- val.replace(importantRE, ""),
4158
+ cssValue.replace(importantRE, ""),
4117
4159
  "important"
4118
4160
  );
4119
4161
  } else {
4120
- style[prefixed] = val;
4162
+ style[prefixed] = cssValue;
4121
4163
  }
4122
4164
  }
4123
4165
  }