@micro-zoe/micro-app 1.0.0-rc.32 → 1.0.0-rc.33

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/lib/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- const version = '1.0.0-rc.32';
1
+ const version = '1.0.0-rc.33';
2
2
  // do not use isUndefined
3
3
  const isBrowser = typeof window !== 'undefined';
4
4
  // do not use isUndefined
@@ -65,13 +65,26 @@ function isBoundFunction(target) {
65
65
  }
66
66
  // is constructor function
67
67
  function isConstructor(target) {
68
- var _a;
69
68
  if (isFunction(target)) {
70
69
  const targetStr = Function.prototype.toString.call(target);
71
- return (((_a = target.prototype) === null || _a === void 0 ? void 0 : _a.constructor) === target &&
72
- Object.getOwnPropertyNames(target.prototype).length > 1) ||
73
- /^function\s+[A-Z]/.test(targetStr) ||
74
- /^class\s+/.test(targetStr);
70
+ if (/^class\s+/.test(targetStr) || /^function\s+[A-Z]/.test(targetStr)) {
71
+ return true;
72
+ }
73
+ const proto = target.prototype;
74
+ if ((proto === null || proto === void 0 ? void 0 : proto.constructor) === target) {
75
+ /**
76
+ * timestamp: 2026/09/16
77
+ * 1. own members on prototype (besides constructor) -> constructor
78
+ * 2. prototype inherits from a non-Object prototype (e.g. prototype = Object.create(ParentProto)),
79
+ * means members live upstream on the prototype chain -> still a constructor.
80
+ * Anonymous proxy constructors like risk-control's `win.XMLHttpRequest = function () {...}`
81
+ * with `prototype = Object.create(realXHRProto)` fall into this case; misjudging them as
82
+ * plain functions makes bindFunctionToRawTarget bind them and breaks `new` (open becomes undefined).
83
+ */
84
+ return Object.getOwnPropertyNames(proto).length > 1 ||
85
+ Object.getPrototypeOf(proto) !== Object.prototype;
86
+ }
87
+ return false;
75
88
  }
76
89
  return false;
77
90
  }
@@ -840,6 +853,40 @@ function parseError(msg, linkPath) {
840
853
  }
841
854
  throw err;
842
855
  }
856
+ // 仅在顶层(不在 () 或 [] 内)的逗号处分割选择器列表。
857
+ // () / [] 内的逗号属于 :is()/:not()/:where()/:has()/:nth-child(of) 或属性值,不是分隔符。
858
+ // 每段保留原分隔符(逗号+其后空白),无括号的选择器重组后与原输出逐字节一致。
859
+ function splitTopLevelSelectors(text) {
860
+ const segments = [];
861
+ let depth = 0;
862
+ let bodyStart = 0;
863
+ let separator = '';
864
+ let i = 0;
865
+ const len = text.length;
866
+ while (i < len) {
867
+ const ch = text.charAt(i);
868
+ if (ch === '(' || ch === '[') {
869
+ depth++;
870
+ }
871
+ else if (ch === ')' || ch === ']') {
872
+ if (depth > 0)
873
+ depth--;
874
+ }
875
+ else if (ch === ',' && depth === 0) {
876
+ segments.push({ separator, body: text.slice(bodyStart, i) });
877
+ let j = i + 1;
878
+ while (j < len && /\s/.test(text.charAt(j)))
879
+ j++;
880
+ separator = text.slice(i, j);
881
+ bodyStart = j;
882
+ i = j;
883
+ continue;
884
+ }
885
+ i++;
886
+ }
887
+ segments.push({ separator, body: text.slice(bodyStart) });
888
+ return segments;
889
+ }
843
890
  /**
844
891
  * Reference https://github.com/reworkcss/css
845
892
  * CSSParser mainly deals with 3 scenes: styleRule, @, and comment
@@ -931,21 +978,13 @@ class CSSParser {
931
978
  * should be ==> micro-app[name=xxx] :is(.a, .b, .c) a {}
932
979
  * 6. :where(.a, .b, .c) a {}
933
980
  * should be ==> micro-app[name=xxx] :where(.a, .b, .c) a {}
981
+ *
982
+ * 仅在顶层逗号处分割(括号深度感知),再逐段加前缀。
983
+ * 旧的 `/(^|,[\n\s]*)([^,]+)/g` 会在每个逗号处分割,把嵌套在
984
+ * :is()/:not()/:where()/:has()/[attr] 内的逗号拆成非法 CSS。
934
985
  */
935
- const attributeValues = {};
936
- const matchRes = m[0].replace(/\[([^\]=]+)(?:=([^\]]+))?\]/g, (match, p1, p2, offset) => {
937
- const mock = `__mock_${p1}_${offset}Value__`;
938
- attributeValues[mock] = p2;
939
- return match.replace(p2, mock);
940
- });
941
- return matchRes.replace(/(^|,[\n\s]*)([^,]+)/g, (_, separator, selector) => {
942
- selector = trim(selector);
943
- selector = selector.replace(/\[[^\]=]+(?:=([^\]]+))?\]/g, (match, p1) => {
944
- if (attributeValues[p1]) {
945
- return match.replace(p1, attributeValues[p1]);
946
- }
947
- return match;
948
- });
986
+ return splitTopLevelSelectors(m[0]).map(({ separator, body }) => {
987
+ let selector = trim(body);
949
988
  // Check if it is in the optionCss list
950
989
  const isIsolationRoot = this.optionCssSelectors.some(includeSelector => {
951
990
  // isolation-root is used to isolation the :root styles between base-app and sub-app
@@ -966,7 +1005,7 @@ class CSSParser {
966
1005
  }
967
1006
  }
968
1007
  return separator + selector;
969
- });
1008
+ }).join('');
970
1009
  }
971
1010
  // https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration
972
1011
  styleDeclarations() {
@@ -7971,7 +8010,10 @@ function patchElementAndDocument() {
7971
8010
  while (i < nodes.length) {
7972
8011
  let node = nodes[i];
7973
8012
  node = isNode(node) ? node : globalEnv.rawCreateTextNode.call(globalEnv.rawDocument, node);
7974
- commonElementHandler(this, markElement(node), null, isDocumentFragment(this) ? globalEnv.rawFragmentAppend : globalEnv.rawAppend);
8013
+ commonElementHandler(this, markElement(node), null,
8014
+ // ShadowRoot 的 append 继承自 DocumentFragment.prototype,需用 rawFragmentAppend;
8015
+ // 若用 rawAppend(Element.prototype.append) 调用会抛 Illegal invocation
8016
+ isDocumentFragment(this) || isDocumentShadowRoot(this) ? globalEnv.rawFragmentAppend : globalEnv.rawAppend);
7975
8017
  i++;
7976
8018
  }
7977
8019
  };