@spcsn/taro-runtime 0.1.2 → 1.0.0

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.
Files changed (85) hide show
  1. package/README.md +16 -39
  2. package/dist/bom/{URL.js → URL2.js} +3 -4
  3. package/dist/bom/URL2.js.map +1 -0
  4. package/dist/bom/document.d.ts +0 -1
  5. package/dist/bom/document.js +1 -55
  6. package/dist/bom/document.js.map +1 -1
  7. package/dist/bom/get-computed-style.js +8 -0
  8. package/dist/bom/get-computed-style.js.map +1 -0
  9. package/dist/bom/history.js +1 -2
  10. package/dist/bom/history.js.map +1 -1
  11. package/dist/bom/location.js +2 -3
  12. package/dist/bom/location.js.map +1 -1
  13. package/dist/bom/navigator.js +1 -2
  14. package/dist/bom/navigator.js.map +1 -1
  15. package/dist/bom/raf.d.ts +2 -2
  16. package/dist/bom/raf.js +2 -2
  17. package/dist/bom/raf.js.map +1 -1
  18. package/dist/bom/url-search-params.d.ts +14 -0
  19. package/dist/bom/{URLSearchParams.js → url-search-params.js} +12 -15
  20. package/dist/bom/url-search-params.js.map +1 -0
  21. package/dist/bom/{URL.d.ts → url.d.ts} +1 -0
  22. package/dist/bom/url.js +196 -0
  23. package/dist/bom/url.js.map +1 -0
  24. package/dist/bom/window.d.ts +3 -3
  25. package/dist/bom/window.js +2 -2
  26. package/dist/bom/window.js.map +1 -1
  27. package/dist/current.d.ts +3 -0
  28. package/dist/current.js +10 -1
  29. package/dist/current.js.map +1 -1
  30. package/dist/dom/anchor-element.js +1 -1
  31. package/dist/dom/class-list.js +2 -1
  32. package/dist/dom/class-list.js.map +1 -1
  33. package/dist/dom/document.js.map +1 -1
  34. package/dist/dom/element.js +7 -7
  35. package/dist/dom/element.js.map +1 -1
  36. package/dist/dom/event.d.ts +1 -1
  37. package/dist/dom/event.js +3 -13
  38. package/dist/dom/event.js.map +1 -1
  39. package/dist/dom/form.js +1 -1
  40. package/dist/dom/form.js.map +1 -1
  41. package/dist/dom/node.d.ts +4 -3
  42. package/dist/dom/node.js +14 -7
  43. package/dist/dom/node.js.map +1 -1
  44. package/dist/dom/root.js +2 -2
  45. package/dist/dom/root.js.map +1 -1
  46. package/dist/dom/{style_properties.js → style-properties.js} +2 -2
  47. package/dist/dom/{style_properties.js.map → style-properties.js.map} +1 -1
  48. package/dist/dom/style.js +1 -1
  49. package/dist/dom/style.js.map +1 -1
  50. package/dist/dom/text.d.ts +1 -1
  51. package/dist/dom/text.js.map +1 -1
  52. package/dist/dom/tree.js.map +1 -1
  53. package/dist/dsl/common.js +26 -47
  54. package/dist/dsl/common.js.map +1 -1
  55. package/dist/env.js +2 -2
  56. package/dist/env.js.map +1 -1
  57. package/dist/hydrate.js +1 -1
  58. package/dist/hydrate.js.map +1 -1
  59. package/dist/index.cjs.d.ts +4 -4
  60. package/dist/index.cjs.js +331 -708
  61. package/dist/index.cjs.js.map +1 -1
  62. package/dist/index.d.ts +4 -4
  63. package/dist/index.js +6 -6
  64. package/dist/next-tick.js +1 -6
  65. package/dist/next-tick.js.map +1 -1
  66. package/dist/perf.js +1 -1
  67. package/dist/perf.js.map +1 -1
  68. package/dist/polyfill/index.js +1 -6
  69. package/dist/polyfill/index.js.map +1 -1
  70. package/dist/runtime.esm.d.ts +4 -4
  71. package/dist/runtime.esm.js +330 -708
  72. package/dist/runtime.esm.js.map +1 -1
  73. package/dist/utils/index.js.map +1 -1
  74. package/package.json +26 -20
  75. package/LICENSE +0 -174
  76. package/dist/bom/URL.js.map +0 -1
  77. package/dist/bom/URLSearchParams.d.ts +0 -1
  78. package/dist/bom/URLSearchParams.js.map +0 -1
  79. package/dist/bom/getComputedStyle.js +0 -9
  80. package/dist/bom/getComputedStyle.js.map +0 -1
  81. package/dist/polyfill/intersection-observer.js +0 -494
  82. package/dist/polyfill/intersection-observer.js.map +0 -1
  83. /package/dist/bom/{getComputedStyle.d.ts → get-computed-style.d.ts} +0 -0
  84. /package/dist/dom/{node_types.d.ts → node-types.d.ts} +0 -0
  85. /package/dist/dom/{style_properties.d.ts → style-properties.d.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"form.js","names":[],"sources":["../../src/dom/form.ts"],"sourcesContent":["import { CHANGE, INPUT, TYPE, VALUE } from '../constants';\nimport { TaroElement } from './element';\n\nimport type { TaroEvent } from './event';\n\nexport class FormElement extends TaroElement {\n public get type() {\n return this.props[TYPE] ?? '';\n }\n\n public set type(val: string) {\n this.setAttribute(TYPE, val);\n }\n\n public get value() {\n // eslint-disable-next-line dot-notation\n const val = this.props[VALUE];\n return val == null ? '' : val;\n }\n\n public set value(val: string | boolean | number | any[]) {\n this.setAttribute(VALUE, val);\n }\n\n public dispatchEvent(event: TaroEvent) {\n if (event.mpEvent) {\n const val = event.mpEvent.detail.value;\n if (event.type === CHANGE) {\n this.props.value = val as string;\n } else if (event.type === INPUT) {\n // Web 规范中表单组件的 value 应该跟着输入改变\n // 只是改 this.props.value 的话不会进行 setData,因此这里修改 this.value。\n // 只测试了 React、Vue3 input 组件的 onInput 事件,onChange 事件不确定有没有副作用,所以暂不修改。\n this.value = val as string;\n }\n }\n\n return super.dispatchEvent(event);\n }\n}\n"],"mappings":";;;AAKA,IAAa,cAAb,cAAiC,YAAY;CAC3C,IAAW,OAAO;;EAChB,QAAA,mBAAO,KAAK,MAAA,aAAA,QAAA,qBAAA,KAAA,IAAA,mBAAe;CAC7B;CAEA,IAAW,KAAK,KAAa;EAC3B,KAAK,aAAa,MAAM,GAAG;CAC7B;CAEA,IAAW,QAAQ;EAEjB,MAAM,MAAM,KAAK,MAAM;EACvB,OAAO,OAAO,OAAO,KAAK;CAC5B;CAEA,IAAW,MAAM,KAAwC;EACvD,KAAK,aAAa,OAAO,GAAG;CAC9B;CAEA,cAAqB,OAAkB;EACrC,IAAI,MAAM,SAAS;GACjB,MAAM,MAAM,MAAM,QAAQ,OAAO;GACjC,IAAI,MAAM,SAAA,UACR,KAAK,MAAM,QAAQ;QACd,IAAI,MAAM,SAAA,SAIf,KAAK,QAAQ;EAEjB;EAEA,OAAO,MAAM,cAAc,KAAK;CAClC;AACF"}
1
+ {"version":3,"file":"form.js","names":[],"sources":["../../src/dom/form.ts"],"sourcesContent":["import { CHANGE, INPUT, TYPE, VALUE } from '../constants';\nimport { TaroElement } from './element';\n\nimport type { TaroEvent } from './event';\n\nexport class FormElement extends TaroElement {\n public get type() {\n return this.props[TYPE] ?? '';\n }\n\n public set type(val: string) {\n this.setAttribute(TYPE, val);\n }\n\n public get value() {\n const val = this.props.value;\n return val == null ? '' : val;\n }\n\n public set value(val: string | boolean | number | any[]) {\n this.setAttribute(VALUE, val);\n }\n\n public dispatchEvent(event: TaroEvent) {\n if (event.mpEvent) {\n const val = event.mpEvent.detail.value;\n if (event.type === CHANGE) {\n this.props.value = val as string;\n } else if (event.type === INPUT) {\n // Web 规范中表单组件的 value 应该跟着输入改变\n // 只是改 this.props.value 的话不会进行 setData,因此这里修改 this.value。\n // 只测试了 React、Vue3 input 组件的 onInput 事件,onChange 事件不确定有没有副作用,所以暂不修改。\n this.value = val as string;\n }\n }\n\n return super.dispatchEvent(event);\n }\n}\n"],"mappings":";;;AAKA,IAAa,cAAb,cAAiC,YAAY;CAC3C,IAAW,OAAO;;EAChB,QAAA,mBAAO,KAAK,MAAA,aAAA,QAAA,qBAAA,KAAA,IAAA,mBAAe;CAC7B;CAEA,IAAW,KAAK,KAAa;EAC3B,KAAK,aAAa,MAAM,GAAG;CAC7B;CAEA,IAAW,QAAQ;EACjB,MAAM,MAAM,KAAK,MAAM;EACvB,OAAO,OAAO,OAAO,KAAK;CAC5B;CAEA,IAAW,MAAM,KAAwC;EACvD,KAAK,aAAa,OAAO,GAAG;CAC9B;CAEA,cAAqB,OAAkB;EACrC,IAAI,MAAM,SAAS;GACjB,MAAM,MAAM,MAAM,QAAQ,OAAO;GACjC,IAAI,MAAM,SAAA,UACR,KAAK,MAAM,QAAQ;QACd,IAAI,MAAM,SAAA,SAIf,KAAK,QAAQ;EAEjB;EAEA,OAAO,MAAM,cAAc,KAAK;CAClC;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { TaroEventTarget } from './event-target';
2
- import { NodeType } from './node_types';
2
+ import { NodeType } from './node-types';
3
3
  import type { TFunc, UpdatePayload } from '../interface';
4
4
  import type { TaroDocument } from './document';
5
5
  import type { TaroElement } from './element';
@@ -7,6 +7,7 @@ import type { TaroRootElement } from './root';
7
7
  interface RemoveChildOptions {
8
8
  cleanRef?: boolean;
9
9
  doUpdate?: boolean;
10
+ recordMutation?: boolean;
10
11
  }
11
12
  export declare class TaroNode extends TaroEventTarget {
12
13
  uid: string;
@@ -27,9 +28,9 @@ export declare class TaroNode extends TaroEventTarget {
27
28
  get parentElement(): TaroElement | null;
28
29
  get firstChild(): TaroNode | null;
29
30
  get lastChild(): TaroNode | null;
31
+ get textContent(): string;
30
32
  /**
31
- * @textContent 目前只能置空子元素
32
- * @TODO 等待完整 innerHTML 实现
33
+ * @textContent 当前实现会用纯文本节点替换全部子节点。
33
34
  */
34
35
  set textContent(text: string);
35
36
  /**
package/dist/dom/node.js CHANGED
@@ -22,7 +22,7 @@ var TaroNode = class TaroNode extends TaroEventTarget {
22
22
  updateChildNodes(isClean) {
23
23
  const cleanChildNodes = () => [];
24
24
  const rerenderChildNodes = () => {
25
- return this.childNodes.filter((node) => !isComment(node)).map(hydrate);
25
+ return this.childNodes.filter((node) => !isComment(node)).map((childNode) => hydrate(childNode));
26
26
  };
27
27
  this.enqueueUpdate({
28
28
  path: `${this._path}.${CHILDNODES}`,
@@ -77,9 +77,11 @@ var TaroNode = class TaroNode extends TaroEventTarget {
77
77
  const childNodes = this.childNodes;
78
78
  return childNodes[childNodes.length - 1] || null;
79
79
  }
80
+ get textContent() {
81
+ return this.childNodes.map((childNode) => childNode.textContent).join("");
82
+ }
80
83
  /**
81
- * @textContent 目前只能置空子元素
82
- * @TODO 等待完整 innerHTML 实现
84
+ * @textContent 当前实现会用纯文本节点替换全部子节点。
83
85
  */
84
86
  set textContent(text) {
85
87
  const removedNodes = this.childNodes.slice();
@@ -88,8 +90,9 @@ var TaroNode = class TaroNode extends TaroEventTarget {
88
90
  if (text === "") this.updateChildNodes(true);
89
91
  else {
90
92
  const newText = env.document.createTextNode(text);
93
+ newText.parentNode = this;
94
+ this.childNodes.push(newText);
91
95
  addedNodes.push(newText);
92
- this.appendChild(newText);
93
96
  this.updateChildNodes();
94
97
  }
95
98
  MutationObserver.record({
@@ -115,7 +118,11 @@ var TaroNode = class TaroNode extends TaroEventTarget {
115
118
  }, refChild);
116
119
  return newChild;
117
120
  }
118
- newChild.remove({ cleanRef: false });
121
+ const previousParentNode = newChild.parentNode;
122
+ newChild.remove({
123
+ cleanRef: false,
124
+ recordMutation: !!previousParentNode && previousParentNode !== this
125
+ });
119
126
  let index = 0;
120
127
  newChild.parentNode = this;
121
128
  if (refChild) {
@@ -177,8 +184,8 @@ var TaroNode = class TaroNode extends TaroEventTarget {
177
184
  * 2. remove C
178
185
  */
179
186
  removeChild(child, options = {}) {
180
- const { cleanRef, doUpdate } = options;
181
- if (cleanRef !== false && doUpdate !== false) MutationObserver.record({
187
+ const { cleanRef, doUpdate, recordMutation } = options;
188
+ if (cleanRef !== false && doUpdate !== false || recordMutation) MutationObserver.record({
182
189
  type: "childList",
183
190
  target: this,
184
191
  removedNodes: [child],
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","names":[],"sources":["../../src/dom/node.ts"],"sourcesContent":["import { ensure, hooks, Shortcuts } from '@spcsn/taro-shared';\n\nimport { DOCUMENT_FRAGMENT } from '../constants';\nimport { MutationObserver, MutationRecordType } from '../dom-external/mutation-observer';\nimport env from '../env';\nimport { hydrate } from '../hydrate';\nimport { extend, incrementId, isComment } from '../utils';\nimport { eventSource } from './event-source';\nimport { TaroEventTarget } from './event-target';\nimport { NodeType } from './node_types';\n\nimport type { TFunc, UpdatePayload } from '../interface';\nimport type { TaroDocument } from './document';\nimport type { TaroElement } from './element';\nimport type { TaroRootElement } from './root';\n\ninterface RemoveChildOptions {\n cleanRef?: boolean;\n doUpdate?: boolean;\n}\n\nconst CHILDNODES = Shortcuts.Childnodes;\nconst nodeId = incrementId();\n\nexport class TaroNode extends TaroEventTarget {\n public uid: string;\n public sid: string;\n public nodeType: NodeType;\n public nodeName: string;\n public parentNode: TaroNode | null = null;\n public childNodes: TaroNode[] = [];\n\n public constructor() {\n super();\n this.uid = '_' + nodeId(); // dom 节点 id,开发者可修改\n this.sid = this.uid; // dom 节点全局唯一 id,不可被修改\n eventSource.set(this.sid, this);\n }\n\n private hydrate = (node: TaroNode) => () => hydrate(node as TaroElement);\n\n private updateChildNodes(isClean?: boolean) {\n const cleanChildNodes = () => [];\n const rerenderChildNodes = () => {\n const childNodes = this.childNodes.filter((node) => !isComment(node));\n return childNodes.map(hydrate);\n };\n\n this.enqueueUpdate({\n path: `${this._path}.${CHILDNODES}`,\n value: isClean ? cleanChildNodes : rerenderChildNodes,\n });\n }\n\n private updateSingleChild(index: number) {\n this.childNodes.forEach((child, childIndex) => {\n if (isComment(child)) return;\n\n if (index && childIndex < index) return;\n\n this.enqueueUpdate({\n path: child._path,\n value: this.hydrate(child),\n });\n });\n }\n\n public get _root(): TaroRootElement | null {\n return this.parentNode?._root || null;\n }\n\n protected findIndex(refChild: TaroNode): number {\n const index = this.childNodes.indexOf(refChild);\n\n ensure(index !== -1, 'The node to be replaced is not a child of this node.');\n\n return index;\n }\n\n public get _path(): string {\n const parentNode = this.parentNode;\n\n if (parentNode) {\n // 计算路径时,先过滤掉 comment 节点\n const list = parentNode.childNodes.filter((node) => !isComment(node));\n const indexOfNode = list.indexOf(this);\n const index = hooks.call('getPathIndex', indexOfNode);\n\n return `${parentNode._path}.${CHILDNODES}.${index}`;\n }\n\n return '';\n }\n\n public get nextSibling(): TaroNode | null {\n const parentNode = this.parentNode;\n return parentNode?.childNodes[parentNode.findIndex(this) + 1] || null;\n }\n\n public get previousSibling(): TaroNode | null {\n const parentNode = this.parentNode;\n return parentNode?.childNodes[parentNode.findIndex(this) - 1] || null;\n }\n\n public get parentElement(): TaroElement | null {\n const parentNode = this.parentNode;\n if (parentNode?.nodeType === NodeType.ELEMENT_NODE) {\n return parentNode as TaroElement;\n }\n return null;\n }\n\n public get firstChild(): TaroNode | null {\n return this.childNodes[0] || null;\n }\n\n public get lastChild(): TaroNode | null {\n const childNodes = this.childNodes;\n return childNodes[childNodes.length - 1] || null;\n }\n\n /**\n * @textContent 目前只能置空子元素\n * @TODO 等待完整 innerHTML 实现\n */\n // eslint-disable-next-line accessor-pairs\n public set textContent(text: string) {\n const removedNodes = this.childNodes.slice();\n const addedNodes: TaroNode[] = [];\n\n // Handle old children' data structure & ref\n while (this.firstChild) {\n this.removeChild(this.firstChild, { doUpdate: false });\n }\n\n if (text === '') {\n this.updateChildNodes(true);\n } else {\n const newText = env.document.createTextNode(text);\n addedNodes.push(newText);\n this.appendChild(newText);\n this.updateChildNodes();\n }\n\n // @Todo: appendChild 会多触发一次\n MutationObserver.record({\n type: MutationRecordType.CHILD_LIST,\n target: this,\n removedNodes,\n addedNodes,\n });\n }\n\n /**\n * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/insertBefore\n * @scenario\n * [A,B,C]\n * 1. insert D before C, D has no parent\n * 2. insert D before C, D has the same parent of C\n * 3. insert D before C, D has the different parent of C\n */\n public insertBefore<T extends TaroNode>(newChild: T, refChild?: TaroNode | null, isReplace?: boolean): T {\n if (newChild.nodeName === DOCUMENT_FRAGMENT) {\n newChild.childNodes.reduceRight((previousValue, currentValue) => {\n this.insertBefore(currentValue, previousValue);\n return currentValue;\n }, refChild);\n return newChild;\n }\n\n // Parent release newChild\n // - cleanRef: false (No need to clean eventSource, because newChild is about to be inserted)\n // - update: true (Need to update parent.childNodes, because parent.childNodes is reordered)\n newChild.remove({ cleanRef: false });\n\n let index = 0;\n // Data structure\n newChild.parentNode = this;\n if (refChild) {\n // insertBefore & replaceChild\n index = this.findIndex(refChild);\n this.childNodes.splice(index, 0, newChild);\n } else {\n // appendChild\n this.childNodes.push(newChild);\n }\n\n const childNodesLength = this.childNodes.length;\n // Serialization\n if (this._root) {\n if (!refChild) {\n // appendChild\n const isOnlyChild = childNodesLength === 1;\n if (isOnlyChild) {\n this.updateChildNodes();\n } else {\n this.enqueueUpdate({\n path: newChild._path,\n value: this.hydrate(newChild),\n });\n }\n } else if (isReplace) {\n // replaceChild\n this.enqueueUpdate({\n path: newChild._path,\n value: this.hydrate(newChild),\n });\n } else {\n // insertBefore 有两种更新模式\n // 比方说有 A B C 三个节点,现在要在 C 前插入 D\n // 1. 插入 D,然后更新整个父节点的 childNodes 数组\n // setData({ cn: [A, B, D, C] })\n // 2. 插入 D,然后更新 D 以及 D 之后每个节点的数据\n // setData ({\n // cn.[2]: D,\n // cn.[3]: C,\n // })\n // 由于微信解析 ’cn.[2]‘ 这些路径的时候也需要消耗时间,\n // 所以根据 insertBefore 插入的位置来做不同的处理\n const mark = (childNodesLength * 2) / 3;\n if (mark > index) {\n // 如果 insertBefore 的位置在 childNodes 的 2/3 前,则为了避免解析路径消耗过多的时间,采用第一种方式\n this.updateChildNodes();\n } else {\n // 如果 insertBefore 的位置在 childNodes 的 2/3 之后,则采用第二种方式,避免 childNodes 的全量更新\n this.updateSingleChild(index);\n }\n }\n }\n\n MutationObserver.record({\n type: MutationRecordType.CHILD_LIST,\n target: this,\n addedNodes: [newChild],\n removedNodes: isReplace ? [refChild as TaroNode] /** replaceChild */ : [],\n nextSibling: isReplace\n ? (refChild as TaroNode).nextSibling /** replaceChild */\n : refChild || null /** insertBefore & appendChild */,\n previousSibling: newChild.previousSibling,\n });\n\n return newChild;\n }\n\n /**\n * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/appendChild\n * @scenario\n * [A,B,C]\n * 1. append C, C has no parent\n * 2. append C, C has the same parent of B\n * 3. append C, C has the different parent of B\n */\n public appendChild(newChild: TaroNode) {\n return this.insertBefore(newChild);\n }\n\n /**\n * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/replaceChild\n * @scenario\n * [A,B,C]\n * 1. replace B with C, C has no parent\n * 2. replace B with C, C has no parent, C has the same parent of B\n * 3. replace B with C, C has no parent, C has the different parent of B\n */\n public replaceChild(newChild: TaroNode, oldChild: TaroNode) {\n if (oldChild.parentNode !== this) return;\n\n // Insert the newChild\n this.insertBefore(newChild, oldChild, true);\n\n // Destroy the oldChild\n // - cleanRef: true (Need to clean eventSource, because the oldChild was detached from the DOM tree)\n // - update: false (No need to update parent.childNodes, because replace will not cause the parent.childNodes being reordered)\n oldChild.remove({ doUpdate: false });\n\n return oldChild;\n }\n\n /**\n * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/removeChild\n * @scenario\n * [A,B,C]\n * 1. remove A or B\n * 2. remove C\n */\n public removeChild<T extends TaroNode>(child: T, options: RemoveChildOptions = {}): T {\n const { cleanRef, doUpdate } = options;\n\n if (cleanRef !== false && doUpdate !== false) {\n // appendChild/replaceChild/insertBefore 不应该触发\n // @Todo: 但其实如果 newChild 的父节点是另一颗子树的节点,应该是要触发的\n MutationObserver.record({\n type: MutationRecordType.CHILD_LIST,\n target: this,\n removedNodes: [child],\n nextSibling: child.nextSibling,\n previousSibling: child.previousSibling,\n });\n }\n\n // Data Structure\n const index = this.findIndex(child);\n this.childNodes.splice(index, 1);\n child.parentNode = null;\n\n // Set eventSource\n if (cleanRef !== false) {\n eventSource.removeNodeTree(child);\n }\n\n // Serialization\n if (this._root && doUpdate !== false) {\n this.updateChildNodes();\n }\n\n return child;\n }\n\n public remove(options?: RemoveChildOptions) {\n this.parentNode?.removeChild(this, options);\n }\n\n public hasChildNodes() {\n return this.childNodes.length > 0;\n }\n\n public enqueueUpdate(payload: UpdatePayload) {\n this._root?.enqueueUpdate(payload);\n }\n\n public get ownerDocument(): TaroDocument {\n return env.document;\n }\n\n static extend(methodName: string, options: TFunc | Record<string, any>) {\n extend(TaroNode, methodName, options);\n }\n}\n"],"mappings":";;;;;;;;;AAqBA,MAAM,aAAa,UAAU;AAC7B,MAAM,SAAS,YAAY;AA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AAC;EAC/B,MAAM,aAAa;EAGnB,IAAI,aAAa,OACf,YAAY,eAAe,KAAK;EAIlC,IAAI,KAAK,SAAS,aAAa,OAC7B,KAAK,iBAAiB;EAGxB,OAAO;CACT;CAEA,OAAc,SAA8B;;EAC1C,CAAA,oBAAA,KAAK,gBAAA,QAAA,sBAAA,KAAA,KAAA,kBAAY,YAAY,MAAM,OAAO;CAC5C;CAEA,gBAAuB;EACrB,OAAO,KAAK,WAAW,SAAS;CAClC;CAEA,cAAqB,SAAwB;;EAC3C,CAAA,cAAA,KAAK,WAAA,QAAA,gBAAA,KAAA,KAAA,YAAO,cAAc,OAAO;CACnC;CAEA,IAAW,gBAA8B;EACvC,OAAO,IAAI;CACb;CAEA,OAAO,OAAO,YAAoB,SAAsC;EACtE,OAAO,UAAU,YAAY,OAAO;CACtC;AACF"}
1
+ {"version":3,"file":"node.js","names":[],"sources":["../../src/dom/node.ts"],"sourcesContent":["import { ensure, hooks, Shortcuts } from '@spcsn/taro-shared';\n\nimport { DOCUMENT_FRAGMENT } from '../constants';\nimport { MutationObserver, MutationRecordType } from '../dom-external/mutation-observer';\nimport env from '../env';\nimport { hydrate } from '../hydrate';\nimport { extend, incrementId, isComment } from '../utils';\nimport { eventSource } from './event-source';\nimport { TaroEventTarget } from './event-target';\nimport { NodeType } from './node-types';\n\nimport type { TFunc, UpdatePayload } from '../interface';\nimport type { TaroDocument } from './document';\nimport type { TaroElement } from './element';\nimport type { TaroRootElement } from './root';\nimport type { TaroText } from './text';\n\ninterface RemoveChildOptions {\n cleanRef?: boolean;\n doUpdate?: boolean;\n recordMutation?: boolean;\n}\n\nconst CHILDNODES = Shortcuts.Childnodes;\nconst nodeId = incrementId();\n\nexport class TaroNode extends TaroEventTarget {\n public uid: string;\n public sid: string;\n public nodeType!: NodeType;\n public nodeName!: string;\n public parentNode: TaroNode | null = null;\n public childNodes: TaroNode[] = [];\n\n public constructor() {\n super();\n this.uid = '_' + nodeId(); // dom 节点 id,开发者可修改\n this.sid = this.uid; // dom 节点全局唯一 id,不可被修改\n eventSource.set(this.sid, this);\n }\n\n private hydrate = (node: TaroNode) => () => hydrate(node as TaroElement | TaroText);\n\n private updateChildNodes(isClean?: boolean) {\n const cleanChildNodes = () => [];\n const rerenderChildNodes = () => {\n const childNodes = this.childNodes.filter((node) => !isComment(node));\n return childNodes.map((childNode) => hydrate(childNode as TaroElement | TaroText));\n };\n\n this.enqueueUpdate({\n path: `${this._path}.${CHILDNODES}`,\n value: isClean ? cleanChildNodes : rerenderChildNodes,\n });\n }\n\n private updateSingleChild(index: number) {\n this.childNodes.forEach((child, childIndex) => {\n if (isComment(child)) return;\n\n if (index && childIndex < index) return;\n\n this.enqueueUpdate({\n path: child._path,\n value: this.hydrate(child),\n });\n });\n }\n\n public get _root(): TaroRootElement | null {\n return this.parentNode?._root || null;\n }\n\n protected findIndex(refChild: TaroNode): number {\n const index = this.childNodes.indexOf(refChild);\n\n ensure(index !== -1, 'The node to be replaced is not a child of this node.');\n\n return index;\n }\n\n public get _path(): string {\n const parentNode = this.parentNode;\n\n if (parentNode) {\n // 计算路径时,先过滤掉 comment 节点\n const list = parentNode.childNodes.filter((node) => !isComment(node));\n const indexOfNode = list.indexOf(this);\n const index = hooks.call('getPathIndex', indexOfNode);\n\n return `${parentNode._path}.${CHILDNODES}.${index}`;\n }\n\n return '';\n }\n\n public get nextSibling(): TaroNode | null {\n const parentNode = this.parentNode;\n return parentNode?.childNodes[parentNode.findIndex(this) + 1] || null;\n }\n\n public get previousSibling(): TaroNode | null {\n const parentNode = this.parentNode;\n return parentNode?.childNodes[parentNode.findIndex(this) - 1] || null;\n }\n\n public get parentElement(): TaroElement | null {\n const parentNode = this.parentNode;\n if (parentNode?.nodeType === NodeType.ELEMENT_NODE) {\n return parentNode as TaroElement;\n }\n return null;\n }\n\n public get firstChild(): TaroNode | null {\n return this.childNodes[0] || null;\n }\n\n public get lastChild(): TaroNode | null {\n const childNodes = this.childNodes;\n return childNodes[childNodes.length - 1] || null;\n }\n\n public get textContent(): string {\n return this.childNodes.map((childNode) => childNode.textContent).join('');\n }\n\n /**\n * @textContent 当前实现会用纯文本节点替换全部子节点。\n */\n public set textContent(text: string) {\n const removedNodes = this.childNodes.slice();\n const addedNodes: TaroNode[] = [];\n\n // Handle old children' data structure & ref\n while (this.firstChild) {\n this.removeChild(this.firstChild, { doUpdate: false });\n }\n\n if (text === '') {\n this.updateChildNodes(true);\n } else {\n const newText = env.document.createTextNode(text);\n newText.parentNode = this;\n this.childNodes.push(newText);\n addedNodes.push(newText);\n this.updateChildNodes();\n }\n\n MutationObserver.record({\n type: MutationRecordType.CHILD_LIST,\n target: this,\n removedNodes,\n addedNodes,\n });\n }\n\n /**\n * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/insertBefore\n * @scenario\n * [A,B,C]\n * 1. insert D before C, D has no parent\n * 2. insert D before C, D has the same parent of C\n * 3. insert D before C, D has the different parent of C\n */\n public insertBefore<T extends TaroNode>(newChild: T, refChild?: TaroNode | null, isReplace?: boolean): T {\n if (newChild.nodeName === DOCUMENT_FRAGMENT) {\n newChild.childNodes.reduceRight((previousValue, currentValue) => {\n this.insertBefore(currentValue, previousValue);\n return currentValue;\n }, refChild);\n return newChild;\n }\n\n // Parent release newChild\n // - cleanRef: false (No need to clean eventSource, because newChild is about to be inserted)\n // - update: true (Need to update parent.childNodes, because parent.childNodes is reordered)\n const previousParentNode = newChild.parentNode;\n newChild.remove({ cleanRef: false, recordMutation: !!previousParentNode && previousParentNode !== this });\n\n let index = 0;\n // Data structure\n newChild.parentNode = this;\n if (refChild) {\n // insertBefore & replaceChild\n index = this.findIndex(refChild);\n this.childNodes.splice(index, 0, newChild);\n } else {\n // appendChild\n this.childNodes.push(newChild);\n }\n\n const childNodesLength = this.childNodes.length;\n // Serialization\n if (this._root) {\n if (!refChild) {\n // appendChild\n const isOnlyChild = childNodesLength === 1;\n if (isOnlyChild) {\n this.updateChildNodes();\n } else {\n this.enqueueUpdate({\n path: newChild._path,\n value: this.hydrate(newChild),\n });\n }\n } else if (isReplace) {\n // replaceChild\n this.enqueueUpdate({\n path: newChild._path,\n value: this.hydrate(newChild),\n });\n } else {\n // insertBefore 有两种更新模式\n // 比方说有 A B C 三个节点,现在要在 C 前插入 D\n // 1. 插入 D,然后更新整个父节点的 childNodes 数组\n // setData({ cn: [A, B, D, C] })\n // 2. 插入 D,然后更新 D 以及 D 之后每个节点的数据\n // setData ({\n // cn.[2]: D,\n // cn.[3]: C,\n // })\n // 由于微信解析 ’cn.[2]‘ 这些路径的时候也需要消耗时间,\n // 所以根据 insertBefore 插入的位置来做不同的处理\n const mark = (childNodesLength * 2) / 3;\n if (mark > index) {\n // 如果 insertBefore 的位置在 childNodes 的 2/3 前,则为了避免解析路径消耗过多的时间,采用第一种方式\n this.updateChildNodes();\n } else {\n // 如果 insertBefore 的位置在 childNodes 的 2/3 之后,则采用第二种方式,避免 childNodes 的全量更新\n this.updateSingleChild(index);\n }\n }\n }\n\n MutationObserver.record({\n type: MutationRecordType.CHILD_LIST,\n target: this,\n addedNodes: [newChild],\n removedNodes: isReplace ? [refChild as TaroNode] /** replaceChild */ : [],\n nextSibling: isReplace\n ? (refChild as TaroNode).nextSibling /** replaceChild */\n : refChild || null /** insertBefore & appendChild */,\n previousSibling: newChild.previousSibling,\n });\n\n return newChild;\n }\n\n /**\n * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/appendChild\n * @scenario\n * [A,B,C]\n * 1. append C, C has no parent\n * 2. append C, C has the same parent of B\n * 3. append C, C has the different parent of B\n */\n public appendChild(newChild: TaroNode) {\n return this.insertBefore(newChild);\n }\n\n /**\n * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/replaceChild\n * @scenario\n * [A,B,C]\n * 1. replace B with C, C has no parent\n * 2. replace B with C, C has no parent, C has the same parent of B\n * 3. replace B with C, C has no parent, C has the different parent of B\n */\n public replaceChild(newChild: TaroNode, oldChild: TaroNode) {\n if (oldChild.parentNode !== this) return;\n\n // Insert the newChild\n this.insertBefore(newChild, oldChild, true);\n\n // Destroy the oldChild\n // - cleanRef: true (Need to clean eventSource, because the oldChild was detached from the DOM tree)\n // - update: false (No need to update parent.childNodes, because replace will not cause the parent.childNodes being reordered)\n oldChild.remove({ doUpdate: false });\n\n return oldChild;\n }\n\n /**\n * @doc https://developer.mozilla.org/zh-CN/docs/Web/API/Node/removeChild\n * @scenario\n * [A,B,C]\n * 1. remove A or B\n * 2. remove C\n */\n public removeChild<T extends TaroNode>(child: T, options: RemoveChildOptions = {}): T {\n const { cleanRef, doUpdate, recordMutation } = options;\n\n if ((cleanRef !== false && doUpdate !== false) || recordMutation) {\n MutationObserver.record({\n type: MutationRecordType.CHILD_LIST,\n target: this,\n removedNodes: [child],\n nextSibling: child.nextSibling,\n previousSibling: child.previousSibling,\n });\n }\n\n // Data Structure\n const index = this.findIndex(child);\n this.childNodes.splice(index, 1);\n child.parentNode = null;\n\n // Set eventSource\n if (cleanRef !== false) {\n eventSource.removeNodeTree(child);\n }\n\n // Serialization\n if (this._root && doUpdate !== false) {\n this.updateChildNodes();\n }\n\n return child;\n }\n\n public remove(options?: RemoveChildOptions) {\n this.parentNode?.removeChild(this, options);\n }\n\n public hasChildNodes() {\n return this.childNodes.length > 0;\n }\n\n public enqueueUpdate(payload: UpdatePayload) {\n this._root?.enqueueUpdate(payload);\n }\n\n public get ownerDocument(): TaroDocument {\n return env.document;\n }\n\n static extend(methodName: string, options: TFunc | Record<string, any>) {\n extend(TaroNode, methodName, options);\n }\n}\n"],"mappings":";;;;;;;;;AAuBA,MAAM,aAAa,UAAU;AAC7B,MAAM,SAAS,YAAY;AAE3B,IAAa,WAAb,MAAa,iBAAiB,gBAAgB;CAQ5C,cAAqB;EACnB,MAAM;EAJR,KAAO,aAA8B;EACrC,KAAO,aAAyB,CAAC;EASjC,KAAQ,WAAW,eAAyB,QAAQ,IAA8B;EALhF,KAAK,MAAM,MAAM,OAAO;EACxB,KAAK,MAAM,KAAK;EAChB,YAAY,IAAI,K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EAC/B,MAAM,aAAa;EAGnB,IAAI,aAAa,OACf,YAAY,eAAe,KAAK;EAIlC,IAAI,KAAK,SAAS,aAAa,OAC7B,KAAK,iBAAiB;EAGxB,OAAO;CACT;CAEA,OAAc,SAA8B;;EAC1C,CAAA,oBAAA,KAAK,gBAAA,QAAA,sBAAA,KAAA,KAAA,kBAAY,YAAY,MAAM,OAAO;CAC5C;CAEA,gBAAuB;EACrB,OAAO,KAAK,WAAW,SAAS;CAClC;CAEA,cAAqB,SAAwB;;EAC3C,CAAA,cAAA,KAAK,WAAA,QAAA,gBAAA,KAAA,KAAA,YAAO,cAAc,OAAO;CACnC;CAEA,IAAW,gBAA8B;EACvC,OAAO,IAAI;CACb;CAEA,OAAO,OAAO,YAAoB,SAAsC;EACtE,OAAO,UAAU,YAAY,OAAO;CACtC;AACF"}
package/dist/dom/root.js CHANGED
@@ -97,11 +97,11 @@ var TaroRootElement = class extends TaroElement {
97
97
  }
98
98
  };
99
99
  if (customWrapperCount) customWrapperMap.forEach((data, ctx) => {
100
- if (options.debug) console.log("custom wrapper setData: ", data);
100
+ if (options.debug) globalThis.console.log("custom wrapper setData: ", data);
101
101
  ctx.setData(data, cb);
102
102
  });
103
103
  if (isNeedNormalUpdate) {
104
- if (options.debug) console.log("page setData:", normalUpdate);
104
+ if (options.debug) globalThis.console.log("page setData:", normalUpdate);
105
105
  ctx.setData(normalUpdate, cb);
106
106
  }
107
107
  });
@@ -1 +1 @@
1
- {"version":3,"file":"root.js","names":[],"sources":["../../src/dom/root.ts"],"sourcesContent":["import { hooks, isArray, isFunction, isUndefined, Shortcuts } from '@spcsn/taro-shared';\n\nimport { CUSTOM_WRAPPER, PAGE_INIT, ROOT_STR, SET_DATA } from '../constants';\nimport { options } from '../options';\nimport { perf } from '../perf';\nimport { customWrapperCache, isComment } from '../utils';\nimport { TaroElement } from './element';\n\nimport type { HydratedData, MpInstance, TFunc, UpdatePayload, UpdatePayloadValue } from '../interface';\n\nfunction findCustomWrapper(root: TaroRootElement, dataPathArr: string[]) {\n // ['root', 'cn', '[0]'] remove 'root' => ['cn', '[0]']\n const list = dataPathArr.slice(1);\n let currentData: any = root;\n let customWrapper: Record<string, any> | undefined;\n let splitedPath = '';\n\n list.some((item, i) => {\n const key = item\n // '[0]' => '0'\n .replace(/^\\[(.+)\\]$/, '$1')\n // 'cn' => 'childNodes'\n .replace(/\\bcn\\b/g, 'childNodes');\n\n currentData = currentData[key];\n\n if (isArray(currentData)) {\n currentData = currentData.filter((el) => !isComment(el));\n }\n\n if (isUndefined(currentData)) return true;\n\n if (currentData.nodeName === CUSTOM_WRAPPER) {\n const res = customWrapperCache.get(currentData.sid);\n if (res) {\n customWrapper = res;\n splitedPath = dataPathArr.slice(i + 2).join('.');\n }\n }\n });\n\n if (customWrapper) {\n return {\n customWrapper,\n splitedPath,\n };\n }\n}\n\nexport class TaroRootElement extends TaroElement {\n private updatePayloads: UpdatePayload[] = [];\n\n private updateCallbacks: TFunc[] = [];\n\n public pendingUpdate = false;\n\n public ctx: null | MpInstance = null;\n\n public constructor() {\n super();\n this.nodeName = ROOT_STR;\n this.tagName = ROOT_STR.toUpperCase();\n }\n\n public get _path(): string {\n return ROOT_STR;\n }\n\n public get _root(): TaroRootElement {\n return this;\n }\n\n public scheduleTask(fn: TFunc) {\n // 这里若使用微任务可略微提前setData的执行时机,但在部分场景下可能会出现连续setData两次,造成更大的性能问题\n setTimeout(fn);\n }\n\n public enqueueUpdate(payload: UpdatePayload): void {\n this.updatePayloads.push(payload);\n\n if (!this.pendingUpdate && this.ctx) {\n this.performUpdate();\n }\n }\n\n public performUpdate(initRender = false, prerender?: TFunc) {\n this.pendingUpdate = true;\n\n const ctx = hooks.call('proxyToRaw', this.ctx)!;\n\n this.scheduleTask(() => {\n const setDataMark = `${SET_DATA} 开始时间戳 ${Date.now()}`;\n perf.start(setDataMark);\n const data: Record<string, UpdatePayloadValue | ReturnType<HydratedData>> = Object.create(null);\n const resetPaths = new Set<string>(initRender ? ['root.cn.[0]', 'root.cn[0]'] : []);\n\n while (this.updatePayloads.length > 0) {\n const { path, value } = this.updatePayloads.shift()!;\n if (path.endsWith(Shortcuts.Childnodes)) {\n resetPaths.add(path);\n }\n data[path] = value;\n }\n\n for (const path in data) {\n resetPaths.forEach((p) => {\n // 已经重置了数组,就不需要分别再设置了\n if (path.includes(p) && path !== p) {\n delete data[path];\n }\n });\n\n const value = data[path];\n if (isFunction(value)) {\n data[path] = value();\n }\n }\n\n // 预渲染\n if (isFunction(prerender)) return prerender(data);\n\n // 正常渲染\n this.pendingUpdate = false;\n let normalUpdate = {};\n const customWrapperMap: Map<Record<any, any>, Record<string, any>> = new Map();\n\n if (initRender) {\n // 初次渲染,使用页面级别的 setData\n normalUpdate = data;\n } else {\n // 更新渲染,区分 CustomWrapper 与页面级别的 setData\n for (const p in data) {\n const dataPathArr = p.split('.');\n const found = findCustomWrapper(this, dataPathArr);\n if (found) {\n // 此项数据使用 CustomWrapper 去更新\n const { customWrapper, splitedPath } = found;\n // 合并同一个 customWrapper 的相关更新到一次 setData 中\n customWrapperMap.set(customWrapper, {\n ...(customWrapperMap.get(customWrapper) || {}),\n [`i.${splitedPath}`]: data[p],\n });\n } else {\n // 此项数据使用页面去更新\n normalUpdate[p] = data[p];\n }\n }\n }\n\n const customWrapperCount = customWrapperMap.size;\n const isNeedNormalUpdate = Object.keys(normalUpdate).length > 0;\n const updateArrLen = customWrapperCount + (isNeedNormalUpdate ? 1 : 0);\n let executeTime = 0;\n\n const cb = () => {\n if (++executeTime === updateArrLen) {\n perf.stop(setDataMark);\n this.flushUpdateCallback();\n initRender && perf.stop(PAGE_INIT);\n }\n };\n\n // custom-wrapper setData\n if (customWrapperCount) {\n customWrapperMap.forEach((data, ctx) => {\n if (process.env.NODE_ENV !== 'production' && options.debug) {\n // eslint-disable-next-line no-console\n console.log('custom wrapper setData: ', data);\n }\n ctx.setData(data, cb);\n });\n }\n\n // page setData\n if (isNeedNormalUpdate) {\n if (process.env.NODE_ENV !== 'production' && options.debug) {\n // eslint-disable-next-line no-console\n console.log('page setData:', normalUpdate);\n }\n ctx.setData(normalUpdate, cb);\n }\n });\n }\n\n public enqueueUpdateCallback(cb: TFunc, ctx?: Record<string, any>) {\n this.updateCallbacks.push(() => {\n ctx ? cb.call(ctx) : cb();\n });\n }\n\n public flushUpdateCallback() {\n const updateCallbacks = this.updateCallbacks;\n if (!updateCallbacks.length) return;\n\n const copies = updateCallbacks.slice(0);\n this.updateCallbacks.length = 0;\n for (let i = 0; i < copies.length; i++) {\n copies[i]();\n }\n }\n}\n"],"mappings":";;;;;;;;AAUA,SAAS,kBAAkB,MAAuB,aAAuB;CAEvE,MAAM,OAAO,YAAY,MAAM,CAAC;CAChC,IAAI,cAAmB;CACvB,IAAI;CACJ,IAAI,cAAc;CAElB,KAAK,MAAM,MAAM,MAAM;EACrB,MAAM,MAAM,KAET,QAAQ,cAAc,IAAI,EAE1B,QAAQ,WAAW,YAAY;EAElC,cAAc,YAAY;EAE1B,IAAI,QAAQ,WAAW,GACrB,cAAc,YAAY,QAAQ,OAAO,CAAC,UAAU,EAAE,CAAC;EAGzD,IAAI,YAAY,WAAW,GAAG,OAAO;EAErC,IAAI,YAAY,aAAA,kBAA6B;GAC3C,MAAM,MAAM,mBAAmB,IAAI,YAAY,GAAG;GAClD,IAAI,KAAK;IACP,gBAAgB;IAChB,cAAc,YAAY,MAAM,IAAI,CAAC,EAAE,KAAK,GAAG;GACjD;EACF;CACF,CAAC;CAED,IAAI,eACF,OAAO;EACL;EACA;CACF;AAEJ;AAEA,IAAa,kBAAb,cAAqC,YAAY;CAS/C,cAAqB;EACnB,MAAM;EATR,KAAQ,iBAAkC,CAAC;EAE3C,KAAQ,kBAA2B,CAAC;EAEpC,KAAO,gBAAgB;EAEvB,KAAO,MAAyB;EAI9B,KAAK,WAAW;EAChB,KAAK,UAAU,SAAS,YAAY;CACtC;CAEA,IAAW,QAAgB;EACzB,OAAO;CACT;CAEA,IAAW,QAAyB;EAClC,OAAO;CACT;CA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C,CAAA,GAAA,CAAA,GAAA,GAC3C,KAAK,gBAAgB,KAAK,GAAA,CAC7B,CAAC;IACH,OAEE,aAAa,KAAK,KAAK;GAE3B;GAGF,MAAM,qBAAqB,iBAAiB;GAC5C,MAAM,qBAAqB,OAAO,KAAK,YAAY,EAAE,SAAS;GAC9D,MAAM,eAAe,sBAAsB,qBAAqB,IAAI;GACpE,IAAI,cAAc;GAElB,MAAM,WAAW;IACf,IAAI,EAAE,gBAAgB,cAAc;KAClC,KAAK,KAAK,WAAW;KACrB,KAAK,oBAAoB;KACzB,cAAc,KAAK,KAAA,OAAc;IACnC;GACF;GAGA,IAAI,oBACF,iBAAiB,SAAS,MAAM,QAAQ;IACtC,IAA6C,QAAQ,OAEnD,QAAQ,IAAI,4BAA4B,IAAI;IAE9C,IAAI,QAAQ,MAAM,EAAE;GACtB,CAAC;GAIH,IAAI,oBAAoB;IACtB,IAA6C,QAAQ,OAEnD,QAAQ,IAAI,iBAAiB,YAAY;IAE3C,IAAI,QAAQ,cAAc,EAAE;GAC9B;EACF,CAAC;CACH;CAEA,sBAA6B,IAAW,KAA2B;EACjE,KAAK,gBAAgB,WAAW;GAC9B,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG;EAC1B,CAAC;CACH;CAEA,sBAA6B;EAC3B,MAAM,kBAAkB,KAAK;EAC7B,IAAI,CAAC,gBAAgB,QAAQ;EAE7B,MAAM,SAAS,gBAAgB,MAAM,CAAC;EACtC,KAAK,gBAAgB,SAAS;EAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KACjC,OAAO,GAAG;CAEd;AACF"}
1
+ {"version":3,"file":"root.js","names":[],"sources":["../../src/dom/root.ts"],"sourcesContent":["import { hooks, isArray, isFunction, isUndefined, Shortcuts } from '@spcsn/taro-shared';\n\nimport { CUSTOM_WRAPPER, PAGE_INIT, ROOT_STR, SET_DATA } from '../constants';\nimport { options } from '../options';\nimport { perf } from '../perf';\nimport { customWrapperCache, isComment } from '../utils';\nimport { TaroElement } from './element';\n\nimport type { HydratedData, MpInstance, TFunc, UpdatePayload, UpdatePayloadValue } from '../interface';\n\nfunction findCustomWrapper(root: TaroRootElement, dataPathArr: string[]) {\n // ['root', 'cn', '[0]'] remove 'root' => ['cn', '[0]']\n const list = dataPathArr.slice(1);\n let currentData: any = root;\n let customWrapper: Record<string, any> | undefined;\n let splitedPath = '';\n\n list.some((item, i) => {\n const key = item\n // '[0]' => '0'\n .replace(/^\\[(.+)\\]$/, '$1')\n // 'cn' => 'childNodes'\n .replace(/\\bcn\\b/g, 'childNodes');\n\n currentData = currentData[key];\n\n if (isArray(currentData)) {\n currentData = currentData.filter((el) => !isComment(el));\n }\n\n if (isUndefined(currentData)) return true;\n\n if (currentData.nodeName === CUSTOM_WRAPPER) {\n const res = customWrapperCache.get(currentData.sid);\n if (res) {\n customWrapper = res;\n splitedPath = dataPathArr.slice(i + 2).join('.');\n }\n }\n });\n\n if (customWrapper) {\n return {\n customWrapper,\n splitedPath,\n };\n }\n}\n\nexport class TaroRootElement extends TaroElement {\n private updatePayloads: UpdatePayload[] = [];\n\n private updateCallbacks: TFunc[] = [];\n\n public pendingUpdate = false;\n\n public ctx: null | MpInstance = null;\n\n public constructor() {\n super();\n this.nodeName = ROOT_STR;\n this.tagName = ROOT_STR.toUpperCase();\n }\n\n public get _path(): string {\n return ROOT_STR;\n }\n\n public get _root(): TaroRootElement {\n return this;\n }\n\n public scheduleTask(fn: TFunc) {\n // 这里若使用微任务可略微提前setData的执行时机,但在部分场景下可能会出现连续setData两次,造成更大的性能问题\n setTimeout(fn);\n }\n\n public enqueueUpdate(payload: UpdatePayload): void {\n this.updatePayloads.push(payload);\n\n if (!this.pendingUpdate && this.ctx) {\n this.performUpdate();\n }\n }\n\n public performUpdate(initRender = false, prerender?: TFunc) {\n this.pendingUpdate = true;\n\n const ctx = hooks.call('proxyToRaw', this.ctx)!;\n\n this.scheduleTask(() => {\n const setDataMark = `${SET_DATA} 开始时间戳 ${Date.now()}`;\n perf.start(setDataMark);\n const data: Record<string, UpdatePayloadValue | ReturnType<HydratedData>> = Object.create(null);\n const resetPaths = new Set<string>(initRender ? ['root.cn.[0]', 'root.cn[0]'] : []);\n\n while (this.updatePayloads.length > 0) {\n const { path, value } = this.updatePayloads.shift()!;\n if (path.endsWith(Shortcuts.Childnodes)) {\n resetPaths.add(path);\n }\n data[path] = value;\n }\n\n for (const path in data) {\n resetPaths.forEach((p) => {\n // 已经重置了数组,就不需要分别再设置了\n if (path.includes(p) && path !== p) {\n delete data[path];\n }\n });\n\n const value = data[path];\n if (isFunction(value)) {\n data[path] = value();\n }\n }\n\n // 预渲染\n if (isFunction(prerender)) return prerender(data);\n\n // 正常渲染\n this.pendingUpdate = false;\n let normalUpdate = {};\n const customWrapperMap: Map<Record<any, any>, Record<string, any>> = new Map();\n\n if (initRender) {\n // 初次渲染,使用页面级别的 setData\n normalUpdate = data;\n } else {\n // 更新渲染,区分 CustomWrapper 与页面级别的 setData\n for (const p in data) {\n const dataPathArr = p.split('.');\n const found = findCustomWrapper(this, dataPathArr);\n if (found) {\n // 此项数据使用 CustomWrapper 去更新\n const { customWrapper, splitedPath } = found;\n // 合并同一个 customWrapper 的相关更新到一次 setData 中\n customWrapperMap.set(customWrapper, {\n ...(customWrapperMap.get(customWrapper) || {}),\n [`i.${splitedPath}`]: data[p],\n });\n } else {\n // 此项数据使用页面去更新\n normalUpdate[p] = data[p];\n }\n }\n }\n\n const customWrapperCount = customWrapperMap.size;\n const isNeedNormalUpdate = Object.keys(normalUpdate).length > 0;\n const updateArrLen = customWrapperCount + (isNeedNormalUpdate ? 1 : 0);\n let executeTime = 0;\n\n const cb = () => {\n if (++executeTime === updateArrLen) {\n perf.stop(setDataMark);\n this.flushUpdateCallback();\n initRender && perf.stop(PAGE_INIT);\n }\n };\n\n // custom-wrapper setData\n if (customWrapperCount) {\n customWrapperMap.forEach((data, ctx) => {\n if (process.env.NODE_ENV !== 'production' && options.debug) {\n globalThis.console.log('custom wrapper setData: ', data);\n }\n ctx.setData(data, cb);\n });\n }\n\n // page setData\n if (isNeedNormalUpdate) {\n if (process.env.NODE_ENV !== 'production' && options.debug) {\n globalThis.console.log('page setData:', normalUpdate);\n }\n ctx.setData(normalUpdate, cb);\n }\n });\n }\n\n public enqueueUpdateCallback(cb: TFunc, ctx?: Record<string, any>) {\n this.updateCallbacks.push(() => {\n ctx ? cb.call(ctx) : cb();\n });\n }\n\n public flushUpdateCallback() {\n const updateCallbacks = this.updateCallbacks;\n if (!updateCallbacks.length) return;\n\n const copies = updateCallbacks.slice(0);\n this.updateCallbacks.length = 0;\n for (let i = 0; i < copies.length; i++) {\n copies[i]();\n }\n }\n}\n"],"mappings":";;;;;;;;AAUA,SAAS,kBAAkB,MAAuB,aAAuB;CAEvE,MAAM,OAAO,YAAY,MAAM,CAAC;CAChC,IAAI,cAAmB;CACvB,IAAI;CACJ,IAAI,cAAc;CAElB,KAAK,MAAM,MAAM,MAAM;EACrB,MAAM,MAAM,KAET,QAAQ,cAAc,IAAI,EAE1B,QAAQ,WAAW,YAAY;EAElC,cAAc,YAAY;EAE1B,IAAI,QAAQ,WAAW,GACrB,cAAc,YAAY,QAAQ,OAAO,CAAC,UAAU,EAAE,CAAC;EAGzD,IAAI,YAAY,WAAW,GAAG,OAAO;EAErC,IAAI,YAAY,aAAA,kBAA6B;GAC3C,MAAM,MAAM,mBAAmB,IAAI,YAAY,GAAG;GAClD,IAAI,KAAK;IACP,gBAAgB;IAChB,cAAc,YAAY,MAAM,IAAI,CAAC,EAAE,KAAK,GAAG;GACjD;EACF;CACF,CAAC;CAED,IAAI,eACF,OAAO;EACL;EACA;CACF;AAEJ;AAEA,IAAa,kBAAb,cAAqC,YAAY;CAS/C,cAAqB;EACnB,MAAM;EATR,KAAQ,iBAAkC,CAAC;EAE3C,KAAQ,kBAA2B,CAAC;EAEpC,KAAO,gBAAgB;EAEvB,KAAO,MAAyB;EAI9B,KAAK,WAAW;EAChB,KAAK,UAAU,SAAS,YAAY;CACt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KIT, [
371
371
  //#endregion
372
372
  export { styleProperties };
373
373
 
374
- //# sourceMappingURL=style_properties.js.map
374
+ //# sourceMappingURL=style-properties.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"style_properties.js","names":[],"sources":["../../src/dom/style_properties.ts"],"sourcesContent":["/*\n *\n * https://www.w3.org/Style/CSS/all-properties.en.html\n */\n\nconst WEBKIT = 'webkit';\n\nconst styleProperties = [\n 'all',\n 'appearance',\n 'backdropFilter',\n 'blockOverflow',\n 'blockSize',\n 'bottom',\n 'clear',\n 'contain',\n 'content',\n 'continue',\n 'cursor',\n 'direction',\n 'display',\n 'filter',\n 'float',\n 'gap',\n 'height',\n 'inset',\n 'isolation',\n 'left',\n 'letterSpacing',\n 'lightingColor',\n 'markerSide',\n 'mixBlendMode',\n 'opacity',\n 'order',\n 'position',\n 'quotes',\n 'resize',\n 'right',\n 'rowGap',\n 'tabSize',\n 'tableLayout',\n 'top',\n 'userSelect',\n 'verticalAlign',\n 'visibility',\n 'voiceFamily',\n 'volume',\n 'whiteSpace',\n 'widows',\n 'width',\n 'zIndex',\n 'pointerEvents',\n 'aspectRatio',\n\n /** 非常用 style */\n // 'azimuth',\n // 'backfaceVisibility',\n // 'baselineShift',\n // 'captionSide',\n // 'chains',\n // 'dominantBaseline',\n // 'elevation',\n // 'emptyCells',\n // 'forcedColorAdjust',\n // 'glyphOrientationVertical',\n // 'hangingPunctuation',\n // 'hyphenateCharacter',\n // 'hyphens',\n // 'imageOrientation',\n // 'imageResolution',\n // 'orphans',\n // 'playDuring',\n // 'pointerEvents',\n // 'regionFragment',\n // 'richness',\n // 'running',\n // 'scrollBehavior',\n // 'speechRate',\n // 'stress',\n // 'stringSet',\n // 'unicodeBidi',\n // 'willChange',\n // 'writingMode',\n];\n\n// 减少文件体积\nfunction combine(prefix: string, list: string[], excludeSelf?: boolean) {\n !excludeSelf && styleProperties.push(prefix);\n list.forEach((item) => {\n styleProperties.push(prefix + item);\n if (prefix === WEBKIT) {\n styleProperties.push('Webkit' + item);\n }\n });\n}\n\nconst color = 'Color';\nconst style = 'Style';\nconst width = 'Width';\nconst image = 'Image';\nconst size = 'Size';\nconst color_style_width = [color, style, width];\nconst fitlength_fitwidth_image = ['FitLength', 'FitWidth', image];\nconst fitlength_fitwidth_image_radius = [...fitlength_fitwidth_image, 'Radius'];\nconst color_style_width_fitlength_fitwidth_image = [...color_style_width, ...fitlength_fitwidth_image];\nconst endRadius_startRadius = ['EndRadius', 'StartRadius'];\nconst bottom_left_right_top = ['Bottom', 'Left', 'Right', 'Top'];\nconst end_start = ['End', 'Start'];\nconst content_items_self = ['Content', 'Items', 'Self'];\nconst blockSize_height_inlineSize_width = ['BlockSize', 'Height', 'InlineSize', width];\nconst after_before = ['After', 'Before'];\n\ncombine('borderBlock', color_style_width);\ncombine('borderBlockEnd', color_style_width);\ncombine('borderBlockStart', color_style_width);\ncombine('outline', [...color_style_width, 'Offset']);\ncombine('border', [...color_style_width, 'Boundary', 'Break', 'Collapse', 'Radius', 'Spacing']);\ncombine('borderFit', ['Length', width]);\ncombine('borderInline', color_style_width);\ncombine('borderInlineEnd', color_style_width);\ncombine('borderInlineStart', color_style_width);\ncombine('borderLeft', color_style_width_fitlength_fitwidth_image);\ncombine('borderRight', color_style_width_fitlength_fitwidth_image);\ncombine('borderTop', color_style_width_fitlength_fitwidth_image);\ncombine('borderBottom', color_style_width_fitlength_fitwidth_image);\ncombine('textDecoration', [color, style, 'Line']);\ncombine('textEmphasis', [color, style, 'Position']);\ncombine('scrollMargin', bottom_left_right_top);\ncombine('scrollPadding', bottom_left_right_top);\ncombine('padding', bottom_left_right_top);\ncombine('margin', [...bottom_left_right_top, 'Trim']);\ncombine('scrollMarginBlock', end_start);\ncombine('scrollMarginInline', end_start);\ncombine('scrollPaddingBlock', end_start);\ncombine('scrollPaddingInline', end_start);\ncombine('gridColumn', end_start);\ncombine('gridRow', end_start);\ncombine('insetBlock', end_start);\ncombine('insetInline', end_start);\ncombine('marginBlock', end_start);\ncombine('marginInline', end_start);\ncombine('paddingBlock', end_start);\ncombine('paddingInline', end_start);\ncombine('pause', after_before);\ncombine('cue', after_before);\ncombine('mask', ['Clip', 'Composite', image, 'Mode', 'Origin', 'Position', 'Repeat', size, 'Type']);\ncombine('borderImage', ['Outset', 'Repeat', 'Slice', 'Source', 'Transform', width]);\ncombine('maskBorder', ['Mode', 'Outset', 'Repeat', 'Slice', 'Source', width]);\ncombine('font', [\n 'Family',\n 'FeatureSettings',\n 'Kerning',\n 'LanguageOverride',\n 'MaxSize',\n 'MinSize',\n 'OpticalSizing',\n 'Palette',\n size,\n 'SizeAdjust',\n 'Stretch',\n style,\n 'Weight',\n 'VariationSettings',\n]);\ncombine('transform', ['Box', 'Origin', style]);\ncombine('background', [color, image, 'Attachment', 'BlendMode', 'Clip', 'Origin', 'Position', 'Repeat', size]);\ncombine('listStyle', [image, 'Position', 'Type']);\ncombine('scrollSnap', ['Align', 'Stop', 'Type']);\ncombine('grid', ['Area', 'AutoColumns', 'AutoFlow', 'AutoRows']);\ncombine('gridTemplate', ['Areas', 'Columns', 'Rows']);\ncombine('overflow', ['Block', 'Inline', 'Wrap', 'X', 'Y']);\ncombine('transition', ['Delay', 'Duration', 'Property', 'TimingFunction']);\ncombine('color', ['Adjust', 'InterpolationFilters', 'Scheme']);\ncombine('textAlign', ['All', 'Last']);\ncombine('page', ['BreakAfter', 'BreakBefore', 'BreakInside']);\ncombine('animation', [\n 'Delay',\n 'Direction',\n 'Duration',\n 'FillMode',\n 'IterationCount',\n 'Name',\n 'PlayState',\n 'TimingFunction',\n]);\ncombine('flex', ['Basis', 'Direction', 'Flow', 'Grow', 'Shrink', 'Wrap']);\ncombine('offset', [...after_before, ...end_start, 'Anchor', 'Distance', 'Path', 'Position', 'Rotate']);\ncombine('perspective', ['Origin']);\ncombine('clip', ['Path', 'Rule']);\ncombine('flow', ['From', 'Into']);\n\ncombine('align', ['Content', 'Items', 'Self'], true);\ncombine('alignment', ['Adjust', 'Baseline'], true);\ncombine('borderStart', endRadius_startRadius, true);\ncombine('borderEnd', endRadius_startRadius, true);\ncombine('borderCorner', ['Fit', image, 'ImageTransform'], true);\ncombine('borderTopLeft', fitlength_fitwidth_image_radius, true);\ncombine('borderTopRight', fitlength_fitwidth_image_radius, true);\ncombine('borderBottomLeft', fitlength_fitwidth_image_radius, true);\ncombine('borderBottomRight', fitlength_fitwidth_image_radius, true);\ncombine('column', ['s', 'Count', 'Fill', 'Gap', 'Rule', 'RuleColor', 'RuleStyle', 'RuleWidth', 'Span', width], true);\ncombine('break', [...after_before, 'Inside'], true);\ncombine('wrap', [...after_before, 'Flow', 'Inside', 'Through'], true);\ncombine('justify', content_items_self, true);\ncombine('place', content_items_self, true);\ncombine('max', [...blockSize_height_inlineSize_width, 'Lines'], true);\ncombine('min', blockSize_height_inlineSize_width, true);\ncombine('line', ['Break', 'Clamp', 'Grid', 'Height', 'Padding', 'Snap'], true);\ncombine('inline', ['BoxAlign', size, 'Sizing'], true);\ncombine(\n 'text',\n [\n 'CombineUpright',\n 'GroupAlign',\n 'Height',\n 'Indent',\n 'Justify',\n 'Orientation',\n 'Overflow',\n 'Shadow',\n 'SpaceCollapse',\n 'SpaceTrim',\n 'Spacing',\n 'Transform',\n 'UnderlinePosition',\n 'Wrap',\n ],\n true,\n);\ncombine('shape', ['ImageThreshold', 'Inside', 'Margin', 'Outside'], true);\ncombine('word', ['Break', 'Spacing', 'Wrap'], true);\ncombine('object', ['Fit', 'Position'], true);\ncombine('box', ['DecorationBreak', 'Shadow', 'Sizing', 'Snap'], true);\n\ncombine(WEBKIT, ['LineClamp', 'BoxOrient', 'TextFillColor', 'TextStroke', 'TextStrokeColor', 'TextStrokeWidth'], true);\n\n/** 非常用 style */\n// combine('caret', [color, 'Shape'])\n// combine('counter', ['Increment', 'Reset', 'Set'], true)\n// combine('dropInitial', ['AfterAdjust', 'AfterAlign', 'BeforeAdjust', 'BeforeAlign', size, 'Value'], true)\n// combine('flood', [color, 'Opacity'], true)\n// combine('footnote', ['Display', 'Policy'], true)\n// combine('hyphenateLimit', ['Chars', 'Last', 'Lines', 'Zone'], true)\n// combine('initialLetters', ['Align', 'Wrap'])\n// combine('ruby', ['Align', 'Merge', 'Position'], true)\n// combine('lineStacking', ['Ruby', 'Shift', 'Strategy'])\n// combine('bookmark', ['Label', 'Level', 'State'], true)\n// combine('speak', ['Header', 'Numeral', 'Punctuation'])\n// combine('pitch', ['Range'])\n// combine('nav', ['Down', 'Left', 'Right', 'Up'], true)\n// combine('fontSynthesis', ['SmallCaps', style, 'Weight'])\n// combine('fontVariant', ['Alternates', 'Caps', 'EastAsian', 'Emoji', 'Ligatures', 'Numeric', 'Position'])\n\nexport { styleProperties };\n"],"mappings":";AAKA,MAAM,SAAS;AAEf,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AA+BF;AAGA,SAAS,QAAQ,QAAgB,MAAgB,aAAuB;CACtE,CAAC,eAAe,gBAAgB,KAAK,MAAM;CAC3C,KAAK,SAAS,SAAS;EACrB,gBAAgB,KAAK,SAAS,IAAI;EAClC,IAAI,WAAW,QACb,gBAAgB,KAAK,WAAW,IAAI;CAExC,CAAC;AACH;AAEA,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,OAAO;AACb,MAAM,oBAAoB;CAAC;CAAO;CAAO;AAAK;AAC9C,MAAM,2BAA2B;CAAC;CAAa;CAAY;AAAK;AAChE,MAAM,kCAAkC,CAAC,GAAG,0BAA0B,QAAQ;AAC9E,MAAM,6CAA6C,CAAC,GAAG,mBAAmB,GAAG,wBAAwB;AACrG,MAAM,wBAAwB,CAAC,aAAa,aAAa;AACz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AAS;CAAW;AAAM,GAAG,IAAI;AAClD,QAAQ,UAAU,CAAC,OAAO,UAAU,GAAG,IAAI;AAC3C,QAAQ,OAAO;CAAC;CAAmB;CAAU;CAAU;AAAM,GAAG,IAAI;AAEpE,QAAQ,QAAQ;CAAC;CAAa;CAAa;CAAiB;CAAc;CAAmB;AAAiB,GAAG,IAAI"}
1
+ {"version":3,"file":"style-properties.js","names":[],"sources":["../../src/dom/style-properties.ts"],"sourcesContent":["/*\n *\n * https://www.w3.org/Style/CSS/all-properties.en.html\n */\n\nconst WEBKIT = 'webkit';\n\nconst styleProperties = [\n 'all',\n 'appearance',\n 'backdropFilter',\n 'blockOverflow',\n 'blockSize',\n 'bottom',\n 'clear',\n 'contain',\n 'content',\n 'continue',\n 'cursor',\n 'direction',\n 'display',\n 'filter',\n 'float',\n 'gap',\n 'height',\n 'inset',\n 'isolation',\n 'left',\n 'letterSpacing',\n 'lightingColor',\n 'markerSide',\n 'mixBlendMode',\n 'opacity',\n 'order',\n 'position',\n 'quotes',\n 'resize',\n 'right',\n 'rowGap',\n 'tabSize',\n 'tableLayout',\n 'top',\n 'userSelect',\n 'verticalAlign',\n 'visibility',\n 'voiceFamily',\n 'volume',\n 'whiteSpace',\n 'widows',\n 'width',\n 'zIndex',\n 'pointerEvents',\n 'aspectRatio',\n\n /** 非常用 style */\n // 'azimuth',\n // 'backfaceVisibility',\n // 'baselineShift',\n // 'captionSide',\n // 'chains',\n // 'dominantBaseline',\n // 'elevation',\n // 'emptyCells',\n // 'forcedColorAdjust',\n // 'glyphOrientationVertical',\n // 'hangingPunctuation',\n // 'hyphenateCharacter',\n // 'hyphens',\n // 'imageOrientation',\n // 'imageResolution',\n // 'orphans',\n // 'playDuring',\n // 'pointerEvents',\n // 'regionFragment',\n // 'richness',\n // 'running',\n // 'scrollBehavior',\n // 'speechRate',\n // 'stress',\n // 'stringSet',\n // 'unicodeBidi',\n // 'willChange',\n // 'writingMode',\n];\n\n// 减少文件体积\nfunction combine(prefix: string, list: string[], excludeSelf?: boolean) {\n !excludeSelf && styleProperties.push(prefix);\n list.forEach((item) => {\n styleProperties.push(prefix + item);\n if (prefix === WEBKIT) {\n styleProperties.push('Webkit' + item);\n }\n });\n}\n\nconst color = 'Color';\nconst style = 'Style';\nconst width = 'Width';\nconst image = 'Image';\nconst size = 'Size';\nconst color_style_width = [color, style, width];\nconst fitlength_fitwidth_image = ['FitLength', 'FitWidth', image];\nconst fitlength_fitwidth_image_radius = [...fitlength_fitwidth_image, 'Radius'];\nconst color_style_width_fitlength_fitwidth_image = [...color_style_width, ...fitlength_fitwidth_image];\nconst endRadius_startRadius = ['EndRadius', 'StartRadius'];\nconst bottom_left_right_top = ['Bottom', 'Left', 'Right', 'Top'];\nconst end_start = ['End', 'Start'];\nconst content_items_self = ['Content', 'Items', 'Self'];\nconst blockSize_height_inlineSize_width = ['BlockSize', 'Height', 'InlineSize', width];\nconst after_before = ['After', 'Before'];\n\ncombine('borderBlock', color_style_width);\ncombine('borderBlockEnd', color_style_width);\ncombine('borderBlockStart', color_style_width);\ncombine('outline', [...color_style_width, 'Offset']);\ncombine('border', [...color_style_width, 'Boundary', 'Break', 'Collapse', 'Radius', 'Spacing']);\ncombine('borderFit', ['Length', width]);\ncombine('borderInline', color_style_width);\ncombine('borderInlineEnd', color_style_width);\ncombine('borderInlineStart', color_style_width);\ncombine('borderLeft', color_style_width_fitlength_fitwidth_image);\ncombine('borderRight', color_style_width_fitlength_fitwidth_image);\ncombine('borderTop', color_style_width_fitlength_fitwidth_image);\ncombine('borderBottom', color_style_width_fitlength_fitwidth_image);\ncombine('textDecoration', [color, style, 'Line']);\ncombine('textEmphasis', [color, style, 'Position']);\ncombine('scrollMargin', bottom_left_right_top);\ncombine('scrollPadding', bottom_left_right_top);\ncombine('padding', bottom_left_right_top);\ncombine('margin', [...bottom_left_right_top, 'Trim']);\ncombine('scrollMarginBlock', end_start);\ncombine('scrollMarginInline', end_start);\ncombine('scrollPaddingBlock', end_start);\ncombine('scrollPaddingInline', end_start);\ncombine('gridColumn', end_start);\ncombine('gridRow', end_start);\ncombine('insetBlock', end_start);\ncombine('insetInline', end_start);\ncombine('marginBlock', end_start);\ncombine('marginInline', end_start);\ncombine('paddingBlock', end_start);\ncombine('paddingInline', end_start);\ncombine('pause', after_before);\ncombine('cue', after_before);\ncombine('mask', ['Clip', 'Composite', image, 'Mode', 'Origin', 'Position', 'Repeat', size, 'Type']);\ncombine('borderImage', ['Outset', 'Repeat', 'Slice', 'Source', 'Transform', width]);\ncombine('maskBorder', ['Mode', 'Outset', 'Repeat', 'Slice', 'Source', width]);\ncombine('font', [\n 'Family',\n 'FeatureSettings',\n 'Kerning',\n 'LanguageOverride',\n 'MaxSize',\n 'MinSize',\n 'OpticalSizing',\n 'Palette',\n size,\n 'SizeAdjust',\n 'Stretch',\n style,\n 'Weight',\n 'VariationSettings',\n]);\ncombine('transform', ['Box', 'Origin', style]);\ncombine('background', [color, image, 'Attachment', 'BlendMode', 'Clip', 'Origin', 'Position', 'Repeat', size]);\ncombine('listStyle', [image, 'Position', 'Type']);\ncombine('scrollSnap', ['Align', 'Stop', 'Type']);\ncombine('grid', ['Area', 'AutoColumns', 'AutoFlow', 'AutoRows']);\ncombine('gridTemplate', ['Areas', 'Columns', 'Rows']);\ncombine('overflow', ['Block', 'Inline', 'Wrap', 'X', 'Y']);\ncombine('transition', ['Delay', 'Duration', 'Property', 'TimingFunction']);\ncombine('color', ['Adjust', 'InterpolationFilters', 'Scheme']);\ncombine('textAlign', ['All', 'Last']);\ncombine('page', ['BreakAfter', 'BreakBefore', 'BreakInside']);\ncombine('animation', [\n 'Delay',\n 'Direction',\n 'Duration',\n 'FillMode',\n 'IterationCount',\n 'Name',\n 'PlayState',\n 'TimingFunction',\n]);\ncombine('flex', ['Basis', 'Direction', 'Flow', 'Grow', 'Shrink', 'Wrap']);\ncombine('offset', [...after_before, ...end_start, 'Anchor', 'Distance', 'Path', 'Position', 'Rotate']);\ncombine('perspective', ['Origin']);\ncombine('clip', ['Path', 'Rule']);\ncombine('flow', ['From', 'Into']);\n\ncombine('align', ['Content', 'Items', 'Self'], true);\ncombine('alignment', ['Adjust', 'Baseline'], true);\ncombine('borderStart', endRadius_startRadius, true);\ncombine('borderEnd', endRadius_startRadius, true);\ncombine('borderCorner', ['Fit', image, 'ImageTransform'], true);\ncombine('borderTopLeft', fitlength_fitwidth_image_radius, true);\ncombine('borderTopRight', fitlength_fitwidth_image_radius, true);\ncombine('borderBottomLeft', fitlength_fitwidth_image_radius, true);\ncombine('borderBottomRight', fitlength_fitwidth_image_radius, true);\ncombine('column', ['s', 'Count', 'Fill', 'Gap', 'Rule', 'RuleColor', 'RuleStyle', 'RuleWidth', 'Span', width], true);\ncombine('break', [...after_before, 'Inside'], true);\ncombine('wrap', [...after_before, 'Flow', 'Inside', 'Through'], true);\ncombine('justify', content_items_self, true);\ncombine('place', content_items_self, true);\ncombine('max', [...blockSize_height_inlineSize_width, 'Lines'], true);\ncombine('min', blockSize_height_inlineSize_width, true);\ncombine('line', ['Break', 'Clamp', 'Grid', 'Height', 'Padding', 'Snap'], true);\ncombine('inline', ['BoxAlign', size, 'Sizing'], true);\ncombine(\n 'text',\n [\n 'CombineUpright',\n 'GroupAlign',\n 'Height',\n 'Indent',\n 'Justify',\n 'Orientation',\n 'Overflow',\n 'Shadow',\n 'SpaceCollapse',\n 'SpaceTrim',\n 'Spacing',\n 'Transform',\n 'UnderlinePosition',\n 'Wrap',\n ],\n true,\n);\ncombine('shape', ['ImageThreshold', 'Inside', 'Margin', 'Outside'], true);\ncombine('word', ['Break', 'Spacing', 'Wrap'], true);\ncombine('object', ['Fit', 'Position'], true);\ncombine('box', ['DecorationBreak', 'Shadow', 'Sizing', 'Snap'], true);\n\ncombine(WEBKIT, ['LineClamp', 'BoxOrient', 'TextFillColor', 'TextStroke', 'TextStrokeColor', 'TextStrokeWidth'], true);\n\n/** 非常用 style */\n// combine('caret', [color, 'Shape'])\n// combine('counter', ['Increment', 'Reset', 'Set'], true)\n// combine('dropInitial', ['AfterAdjust', 'AfterAlign', 'BeforeAdjust', 'BeforeAlign', size, 'Value'], true)\n// combine('flood', [color, 'Opacity'], true)\n// combine('footnote', ['Display', 'Policy'], true)\n// combine('hyphenateLimit', ['Chars', 'Last', 'Lines', 'Zone'], true)\n// combine('initialLetters', ['Align', 'Wrap'])\n// combine('ruby', ['Align', 'Merge', 'Position'], true)\n// combine('lineStacking', ['Ruby', 'Shift', 'Strategy'])\n// combine('bookmark', ['Label', 'Level', 'State'], true)\n// combine('speak', ['Header', 'Numeral', 'Punctuation'])\n// combine('pitch', ['Range'])\n// combine('nav', ['Down', 'Left', 'Right', 'Up'], true)\n// combine('fontSynthesis', ['SmallCaps', style, 'Weight'])\n// combine('fontVariant', ['Alternates', 'Caps', 'EastAsian', 'Emoji', 'Ligatures', 'Numeric', 'Position'])\n\nexport { styleProperties };\n"],"mappings":";AAKA,MAAM,SAAS;AAEf,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AA+BF;AAGA,SAAS,QAAQ,QAAgB,MAAgB,aAAuB;CACtE,CAAC,eAAe,gBAAgB,KAAK,MAAM;CAC3C,KAAK,SAAS,SAAS;EACrB,gBAAgB,KAAK,SAAS,IAAI;EAClC,IAAI,WAAW,QACb,gBAAgB,KAAK,WAAW,IAAI;CAExC,CAAC;AACH;AAEA,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,OAAO;AACb,MAAM,oBAAoB;CAAC;CAAO;CAAO;AAAK;AAC9C,MAAM,2BAA2B;CAAC;CAAa;CAAY;AAAK;AAChE,MAAM,kCAAkC,CAAC,GAAG,0BAA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;CACA;AACF,GACA,IACF;AACA,QAAQ,SAAS;CAAC;CAAkB;CAAU;CAAU;AAAS,GAAG,IAAI;AACxE,QAAQ,QAAQ;CAAC;CAAS;CAAW;AAAM,GAAG,IAAI;AAClD,QAAQ,UAAU,CAAC,OAAO,UAAU,GAAG,IAAI;AAC3C,QAAQ,OAAO;CAAC;CAAmB;CAAU;CAAU;AAAM,GAAG,IAAI;AAEpE,QAAQ,QAAQ;CAAC;CAAa;CAAa;CAAiB;CAAc;CAAmB;AAAiB,GAAG,IAAI"}
package/dist/dom/style.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import "../constants/index.js";
2
2
  import { MutationObserver } from "../dom-external/mutation-observer/index.js";
3
- import { styleProperties } from "./style_properties.js";
3
+ import { styleProperties } from "./style-properties.js";
4
4
  import { Shortcuts, hooks, isArray, isNull, isString, isUndefined, toCamelCase, toDashed, warn } from "@spcsn/taro-shared";
5
5
  //#region src/dom/style.ts
6
6
  function recordCss(obj) {
@@ -1 +1 @@
1
- {"version":3,"file":"style.js","names":[],"sources":["../../src/dom/style.ts"],"sourcesContent":["import {\n hooks,\n isArray,\n isNull,\n isString,\n isUndefined,\n Shortcuts,\n toCamelCase,\n toDashed,\n warn,\n} from '@spcsn/taro-shared';\n\nimport { PROPERTY_THRESHOLD } from '../constants';\nimport { MutationObserver, MutationRecordType } from '../dom-external/mutation-observer';\nimport { TaroElement } from './element';\nimport { styleProperties } from './style_properties';\n\nfunction recordCss(obj: Style) {\n MutationObserver.record({\n type: MutationRecordType.ATTRIBUTES,\n target: obj._element,\n attributeName: 'style',\n oldValue: obj.cssText,\n });\n}\n\nfunction enqueueUpdate(obj: Style) {\n const element = obj._element;\n if (element._root) {\n element.enqueueUpdate({\n path: `${element._path}.${Shortcuts.Style}`,\n value: obj.cssText,\n });\n }\n}\n\nfunction setStyle(this: Style, newVal: string, styleKey: string) {\n process.env.NODE_ENV !== 'production' &&\n warn(\n isString(newVal) && newVal.length > PROPERTY_THRESHOLD,\n `Style 属性 ${styleKey} 的值数据量过大,可能会影响渲染性能,考虑使用 CSS 类或其它方案替代。`,\n );\n\n const old = this[styleKey];\n\n if (old === newVal) return;\n\n !this._pending && recordCss(this);\n\n if (isNull(newVal) || isUndefined(newVal) || newVal === '') {\n this._usedStyleProp.delete(styleKey);\n delete this._value[styleKey];\n } else {\n this._usedStyleProp.add(styleKey);\n this._value[styleKey] = newVal;\n }\n\n !this._pending && enqueueUpdate(this);\n}\n\nfunction initStyle(ctor: typeof Style, styleProperties: string[]) {\n const properties = {};\n\n for (let i = 0; i < styleProperties.length; i++) {\n const styleKey = styleProperties[i];\n\n if (ctor[styleKey]) return;\n\n properties[styleKey] = {\n get(this: Style) {\n const val = this._value[styleKey];\n return isNull(val) || isUndefined(val) ? '' : val;\n },\n set(this: Style, newVal: string) {\n setStyle.call(this, newVal, styleKey);\n },\n };\n }\n\n Object.defineProperties(ctor.prototype, properties);\n}\n\nfunction isCssVariable(propertyName) {\n return /^--/.test(propertyName);\n}\n\nexport class Style {\n public _pending: boolean;\n\n public _usedStyleProp: Set<string>;\n\n public _value: Partial<CSSStyleDeclaration>;\n\n public _element: TaroElement;\n\n public constructor(element: TaroElement) {\n this._element = element;\n this._usedStyleProp = new Set();\n this._value = {};\n }\n\n private setCssVariables(styleKey: string) {\n this.hasOwnProperty(styleKey) ||\n Object.defineProperty(this, styleKey, {\n enumerable: true,\n configurable: true,\n get: () => {\n return this._value[styleKey] || '';\n },\n set: (newVal: string) => {\n setStyle.call(this, newVal, styleKey);\n },\n });\n }\n\n public get cssText() {\n if (!this._usedStyleProp.size) return '';\n\n const texts: string[] = [];\n this._usedStyleProp.forEach((key) => {\n const val = this[key];\n if (isNull(val) || isUndefined(val)) return;\n let styleName = isCssVariable(key) ? key : toDashed(key);\n if (styleName.indexOf('webkit') === 0 || styleName.indexOf('Webkit') === 0) {\n styleName = `-${styleName}`;\n }\n texts.push(`${styleName}: ${val};`);\n });\n return texts.join(' ');\n }\n\n public set cssText(str: string) {\n this._pending = true;\n recordCss(this);\n\n this._usedStyleProp.forEach((prop) => {\n this.removeProperty(prop);\n });\n\n if (str === '' || isUndefined(str) || isNull(str)) {\n this._pending = false;\n enqueueUpdate(this);\n return;\n }\n\n const rules = str.split(';');\n\n for (let i = 0; i < rules.length; i++) {\n const rule = rules[i].trim();\n if (rule === '') {\n continue;\n }\n\n // 可能存在 'background: url(http:x/y/z)' 的情况\n const [propName, ...valList] = rule.split(':');\n const val = valList.join(':');\n\n if (isUndefined(val)) {\n continue;\n }\n this.setProperty(propName.trim(), val.trim());\n }\n\n this._pending = false;\n enqueueUpdate(this);\n }\n\n public setProperty(propertyName: string, value?: string | null) {\n if (propertyName[0] === '-') {\n // 支持 webkit 属性或 css 变量\n this.setCssVariables(propertyName);\n } else {\n propertyName = toCamelCase(propertyName);\n }\n\n if (isNull(value) || isUndefined(value)) {\n this.removeProperty(propertyName);\n } else {\n this[propertyName] = value;\n }\n }\n\n public removeProperty(propertyName: string): string {\n propertyName = toCamelCase(propertyName);\n if (!this._usedStyleProp.has(propertyName)) {\n return '';\n }\n\n const value = this[propertyName];\n this[propertyName] = undefined;\n return value;\n }\n\n public getPropertyValue(propertyName: string) {\n propertyName = toCamelCase(propertyName);\n const value = this[propertyName];\n if (!value) {\n return '';\n }\n\n return value;\n }\n}\n\ninitStyle(Style, styleProperties);\n\nhooks.tap('injectNewStyleProperties', (newStyleProperties: string[]) => {\n if (isArray(newStyleProperties)) {\n initStyle(Style, newStyleProperties);\n } else {\n if (typeof newStyleProperties !== 'string') return;\n\n initStyle(Style, [newStyleProperties]);\n }\n});\n"],"mappings":";;;;;AAiBA,SAAS,UAAU,KAAY;CAC7B,iBAAiB,OAAO;EACtB,MAAA;EACA,QAAQ,IAAI;EACZ,eAAe;EACf,UAAU,IAAI;CAChB,CAAC;AACH;AAEA,SAAS,cAAc,KAAY;CACjC,MAAM,UAAU,IAAI;CACpB,IAAI,QAAQ,OACV,QAAQ,cAAc;EACpB,MAAM,GAAG,QAAQ,MA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YAAY,KAAK,GACpC,KAAK,eAAe,YAAY;OAEhC,KAAK,gBAAgB;CAEzB;CAEA,eAAsB,cAA8B;EAClD,eAAe,YAAY,YAAY;EACvC,IAAI,CAAC,KAAK,eAAe,IAAI,YAAY,GACvC,OAAO;EAGT,MAAM,QAAQ,KAAK;EACnB,KAAK,gBAAgB,KAAA;EACrB,OAAO;CACT;CAEA,iBAAwB,cAAsB;EAC5C,eAAe,YAAY,YAAY;EACvC,MAAM,QAAQ,KAAK;EACnB,IAAI,CAAC,OACH,OAAO;EAGT,OAAO;CACT;AACF;AAEA,UAAU,OAAO,eAAe;AAEhC,MAAM,IAAI,6BAA6B,uBAAiC;CACtE,IAAI,QAAQ,kBAAkB,GAC5B,UAAU,OAAO,kBAAkB;MAC9B;EACL,IAAI,OAAO,uBAAuB,UAAU;EAE5C,UAAU,OAAO,CAAC,kBAAkB,CAAC;CACvC;AACF,CAAC"}
1
+ {"version":3,"file":"style.js","names":[],"sources":["../../src/dom/style.ts"],"sourcesContent":["import {\n hooks,\n isArray,\n isNull,\n isString,\n isUndefined,\n Shortcuts,\n toCamelCase,\n toDashed,\n warn,\n} from '@spcsn/taro-shared';\n\nimport { PROPERTY_THRESHOLD } from '../constants';\nimport { MutationObserver, MutationRecordType } from '../dom-external/mutation-observer';\nimport { TaroElement } from './element';\nimport { styleProperties } from './style-properties';\n\nfunction recordCss(obj: Style) {\n MutationObserver.record({\n type: MutationRecordType.ATTRIBUTES,\n target: obj._element,\n attributeName: 'style',\n oldValue: obj.cssText,\n });\n}\n\nfunction enqueueUpdate(obj: Style) {\n const element = obj._element;\n if (element._root) {\n element.enqueueUpdate({\n path: `${element._path}.${Shortcuts.Style}`,\n value: obj.cssText,\n });\n }\n}\n\nfunction setStyle(this: Style, newVal: string, styleKey: string) {\n process.env.NODE_ENV !== 'production' &&\n warn(\n isString(newVal) && newVal.length > PROPERTY_THRESHOLD,\n `Style 属性 ${styleKey} 的值数据量过大,可能会影响渲染性能,考虑使用 CSS 类或其它方案替代。`,\n );\n\n const old = this[styleKey];\n\n if (old === newVal) return;\n\n !this._pending && recordCss(this);\n\n if (isNull(newVal) || isUndefined(newVal) || newVal === '') {\n this._usedStyleProp.delete(styleKey);\n delete this._value[styleKey];\n } else {\n this._usedStyleProp.add(styleKey);\n this._value[styleKey] = newVal;\n }\n\n !this._pending && enqueueUpdate(this);\n}\n\nfunction initStyle(ctor: typeof Style, styleProperties: string[]) {\n const properties = {};\n\n for (let i = 0; i < styleProperties.length; i++) {\n const styleKey = styleProperties[i];\n\n if (ctor[styleKey]) return;\n\n properties[styleKey] = {\n get(this: Style) {\n const val = this._value[styleKey];\n return isNull(val) || isUndefined(val) ? '' : val;\n },\n set(this: Style, newVal: string) {\n setStyle.call(this, newVal, styleKey);\n },\n };\n }\n\n Object.defineProperties(ctor.prototype, properties);\n}\n\nfunction isCssVariable(propertyName) {\n return /^--/.test(propertyName);\n}\n\nexport class Style {\n public _pending: boolean;\n\n public _usedStyleProp: Set<string>;\n\n public _value: Partial<CSSStyleDeclaration>;\n\n public _element: TaroElement;\n\n public constructor(element: TaroElement) {\n this._element = element;\n this._usedStyleProp = new Set();\n this._value = {};\n }\n\n private setCssVariables(styleKey: string) {\n this.hasOwnProperty(styleKey) ||\n Object.defineProperty(this, styleKey, {\n enumerable: true,\n configurable: true,\n get: () => {\n return this._value[styleKey] || '';\n },\n set: (newVal: string) => {\n setStyle.call(this, newVal, styleKey);\n },\n });\n }\n\n public get cssText() {\n if (!this._usedStyleProp.size) return '';\n\n const texts: string[] = [];\n this._usedStyleProp.forEach((key) => {\n const val = this[key];\n if (isNull(val) || isUndefined(val)) return;\n let styleName = isCssVariable(key) ? key : toDashed(key);\n if (styleName.indexOf('webkit') === 0 || styleName.indexOf('Webkit') === 0) {\n styleName = `-${styleName}`;\n }\n texts.push(`${styleName}: ${val};`);\n });\n return texts.join(' ');\n }\n\n public set cssText(str: string) {\n this._pending = true;\n recordCss(this);\n\n this._usedStyleProp.forEach((prop) => {\n this.removeProperty(prop);\n });\n\n if (str === '' || isUndefined(str) || isNull(str)) {\n this._pending = false;\n enqueueUpdate(this);\n return;\n }\n\n const rules = str.split(';');\n\n for (let i = 0; i < rules.length; i++) {\n const rule = rules[i].trim();\n if (rule === '') {\n continue;\n }\n\n // 可能存在 'background: url(http:x/y/z)' 的情况\n const [propName, ...valList] = rule.split(':');\n const val = valList.join(':');\n\n if (isUndefined(val)) {\n continue;\n }\n this.setProperty(propName.trim(), val.trim());\n }\n\n this._pending = false;\n enqueueUpdate(this);\n }\n\n public setProperty(propertyName: string, value?: string | null) {\n if (propertyName[0] === '-') {\n // 支持 webkit 属性或 css 变量\n this.setCssVariables(propertyName);\n } else {\n propertyName = toCamelCase(propertyName);\n }\n\n if (isNull(value) || isUndefined(value)) {\n this.removeProperty(propertyName);\n } else {\n this[propertyName] = value;\n }\n }\n\n public removeProperty(propertyName: string): string {\n propertyName = toCamelCase(propertyName);\n if (!this._usedStyleProp.has(propertyName)) {\n return '';\n }\n\n const value = this[propertyName];\n this[propertyName] = undefined;\n return value;\n }\n\n public getPropertyValue(propertyName: string) {\n propertyName = toCamelCase(propertyName);\n const value = this[propertyName];\n if (!value) {\n return '';\n }\n\n return value;\n }\n}\n\ninitStyle(Style, styleProperties);\n\nhooks.tap('injectNewStyleProperties', (newStyleProperties: string[]) => {\n if (isArray(newStyleProperties)) {\n initStyle(Style, newStyleProperties);\n } else {\n if (typeof newStyleProperties !== 'string') return;\n\n initStyle(Style, [newStyleProperties]);\n }\n});\n"],"mappings":";;;;;AAiBA,SAAS,UAAU,KAAY;CAC7B,iBAAiB,OAAO;EACtB,MAAA;EACA,QAAQ,IAAI;EACZ,eAAe;EACf,UAAU,IAAI;CAChB,CAAC;AACH;AAEA,SAAS,cAAc,KAAY;CACjC,MAAM,UAAU,IAAI;CACpB,IAAI,QAAQ,OACV,QAAQ,cAAc;EACpB,MAAM,GAAG,QAAQ,MAAM,GAAG,UAAU;EACpC,OAAO,IAAI;CACb,CAAC;AAEL;A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AAgB;CAEzB;CAEA,eAAsB,cAA8B;EAClD,eAAe,YAAY,YAAY;EACvC,IAAI,CAAC,KAAK,eAAe,IAAI,YAAY,GACvC,OAAO;EAGT,MAAM,QAAQ,KAAK;EACnB,KAAK,gBAAgB,KAAA;EACrB,OAAO;CACT;CAEA,iBAAwB,cAAsB;EAC5C,eAAe,YAAY,YAAY;EACvC,MAAM,QAAQ,KAAK;EACnB,IAAI,CAAC,OACH,OAAO;EAGT,OAAO;CACT;AACF;AAEA,UAAU,OAAO,eAAe;AAEhC,MAAM,IAAI,6BAA6B,uBAAiC;CACtE,IAAI,QAAQ,kBAAkB,GAC5B,UAAU,OAAO,kBAAkB;MAC9B;EACL,IAAI,OAAO,uBAAuB,UAAU;EAE5C,UAAU,OAAO,CAAC,kBAAkB,CAAC;CACvC;AACF,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { TaroNode } from './node';
2
- import { NodeType } from './node_types';
2
+ import { NodeType } from './node-types';
3
3
  export declare class TaroText extends TaroNode {
4
4
  _value: string;
5
5
  nodeType: NodeType;
@@ -1 +1 @@
1
- {"version":3,"file":"text.js","names":[],"sources":["../../src/dom/text.ts"],"sourcesContent":["import { Shortcuts } from '@spcsn/taro-shared';\n\nimport { MutationObserver, MutationRecordType } from '../dom-external/mutation-observer';\nimport { TaroNode } from './node';\nimport { NodeType } from './node_types';\n\nexport class TaroText extends TaroNode {\n public _value: string;\n public nodeType = NodeType.TEXT_NODE;\n public nodeName = '#text';\n\n constructor(value) {\n super();\n this._value = value;\n }\n\n public set textContent(text: string) {\n MutationObserver.record({\n target: this,\n type: MutationRecordType.CHARACTER_DATA,\n oldValue: this._value,\n });\n this._value = text;\n this.enqueueUpdate({\n path: `${this._path}.${Shortcuts.Text}`,\n value: text,\n });\n }\n\n public get textContent(): string {\n return this._value;\n }\n\n public set nodeValue(text: string) {\n this.textContent = text;\n }\n\n public get nodeValue(): string {\n return this._value;\n }\n\n public set data(text: string) {\n this.textContent = text;\n }\n\n public get data(): string {\n return this._value;\n }\n}\n"],"mappings":";;;;AAMA,IAAa,WAAb,cAA8B,SAAS;CAKrC,YAAY,OAAO;EACjB,MAAM;EAJR,KAAO,WAAA;EACP,KAAO,WAAW;EAIhB,KAAK,SAAS;CAChB;CAEA,IAAW,YAAY,MAAc;EACnC,iBAAiB,OAAO;GACtB,QAAQ;GACR,MAAA;GACA,UAAU,KAAK;EACjB,CAAC;EACD,KAAK,SAAS;EACd,KAAK,cAAc;GACjB,MAAM,GAAG,KAAK,MAAM,GAAG,UAAU;GACjC,OAAO;EACT,CAAC;CACH;CAEA,IAAW,cAAsB;EAC/B,OAAO,KAAK;CACd;CAEA,IAAW,UAAU,MAAc;EACjC,KAAK,cAAc;CACrB;CAEA,IAAW,YAAoB;EAC7B,OAAO,KAAK;CACd;CAEA,IAAW,KAAK,MAAc;EAC5B,KAAK,cAAc;CACrB;CAEA,IAAW,OAAe;EACxB,OAAO,KAAK;CACd;AACF"}
1
+ {"version":3,"file":"text.js","names":[],"sources":["../../src/dom/text.ts"],"sourcesContent":["import { Shortcuts } from '@spcsn/taro-shared';\n\nimport { MutationObserver, MutationRecordType } from '../dom-external/mutation-observer';\nimport { TaroNode } from './node';\nimport { NodeType } from './node-types';\n\nexport class TaroText extends TaroNode {\n public _value: string;\n public nodeType = NodeType.TEXT_NODE;\n public nodeName = '#text';\n\n constructor(value) {\n super();\n this._value = value;\n }\n\n public set textContent(text: string) {\n MutationObserver.record({\n target: this,\n type: MutationRecordType.CHARACTER_DATA,\n oldValue: this._value,\n });\n this._value = text;\n this.enqueueUpdate({\n path: `${this._path}.${Shortcuts.Text}`,\n value: text,\n });\n }\n\n public get textContent(): string {\n return this._value;\n }\n\n public set nodeValue(text: string) {\n this.textContent = text;\n }\n\n public get nodeValue(): string {\n return this._value;\n }\n\n public set data(text: string) {\n this.textContent = text;\n }\n\n public get data(): string {\n return this._value;\n }\n}\n"],"mappings":";;;;AAMA,IAAa,WAAb,cAA8B,SAAS;CAKrC,YAAY,OAAO;EACjB,MAAM;EAJR,KAAO,WAAA;EACP,KAAO,WAAW;EAIhB,KAAK,SAAS;CAChB;CAEA,IAAW,YAAY,MAAc;EACnC,iBAAiB,OAAO;GACtB,QAAQ;GACR,MAAA;GACA,UAAU,KAAK;EACjB,CAAC;EACD,KAAK,SAAS;EACd,KAAK,cAAc;GACjB,MAAM,GAAG,KAAK,MAAM,GAAG,UAAU;GACjC,OAAO;EACT,CAAC;CACH;CAEA,IAAW,cAAsB;EAC/B,OAAO,KAAK;CACd;CAEA,IAAW,UAAU,MAAc;EACjC,KAAK,cAAc;CACrB;CAEA,IAAW,YAAoB;EAC7B,OAAO,KAAK;CACd;CAEA,IAAW,KAAK,MAAc;EAC5B,KAAK,cAAc;CACrB;CAEA,IAAW,OAAe;EACxB,OAAO,KAAK;CACd;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"tree.js","names":[],"sources":["../../src/dom/tree.ts"],"sourcesContent":["import { NodeType } from './node_types';\n\nimport type { TaroElement } from './element';\n\ntype Filter = (element: TaroElement) => boolean;\n\nfunction returnTrue() {\n return true;\n}\n\nexport function treeToArray(root: TaroElement, predict?: Filter): TaroElement[] {\n const array: TaroElement[] = [];\n const filter = predict ?? returnTrue;\n\n let object: TaroElement | null = root;\n\n while (object) {\n if (object.nodeType === NodeType.ELEMENT_NODE && filter(object)) {\n array.push(object);\n }\n\n object = following(object, root);\n }\n\n return array;\n}\n\nfunction following(el: TaroElement, root: TaroElement): TaroElement | null {\n const firstChild = el.firstChild;\n const isElmentTypeValid = el.nodeType === NodeType.ELEMENT_NODE || el.nodeType === NodeType.DOCUMENT_NODE;\n\n // 如果当前 el 不是 element 或 document 元素,则可以直接不递归他的子元素了\n if (firstChild && isElmentTypeValid) {\n return firstChild as TaroElement;\n }\n\n let current: TaroElement | null = el;\n\n do {\n if (current === root) {\n return null;\n }\n\n const nextSibling = current.nextSibling;\n\n if (nextSibling) {\n return nextSibling as TaroElement;\n }\n current = current.parentElement;\n } while (current);\n\n return null;\n}\n"],"mappings":";AAMA,SAAS,aAAa;CACpB,OAAO;AACT;AAEA,SAAgB,YAAY,MAAmB,SAAiC;CAC9E,MAAM,QAAuB,CAAC;CAC9B,MAAM,SAAS,YAAA,QAAA,YAAA,KAAA,IAAA,UAAW;CAE1B,IAAI,SAA6B;CAEjC,OAAO,QAAQ;EACb,IAAI,OAAO,aAAA,KAAsC,OAAO,MAAM,GAC5D,MAAM,KAAK,MAAM;EAGnB,SAAS,UAAU,QAAQ,IAAI;CACjC;CAEA,OAAO;AACT;AAEA,SAAS,UAAU,IAAiB,MAAuC;CACzE,MAAM,aAAa,GAAG;CACtB,MAAM,oBAAoB,GAAG,aAAA,KAAsC,GAAG,aAAA;CAGtE,IAAI,cAAc,mBAChB,OAAO;CAGT,IAAI,UAA8B;CAElC,GAAG;EACD,IAAI,YAAY,MACd,OAAO;EAGT,MAAM,cAAc,QAAQ;EAE5B,IAAI,aACF,OAAO;EAET,UAAU,QAAQ;CACpB,SAAS;CAET,OAAO;AACT"}
1
+ {"version":3,"file":"tree.js","names":[],"sources":["../../src/dom/tree.ts"],"sourcesContent":["import { NodeType } from './node-types';\n\nimport type { TaroElement } from './element';\n\ntype Filter = (element: TaroElement) => boolean;\n\nfunction returnTrue() {\n return true;\n}\n\nexport function treeToArray(root: TaroElement, predict?: Filter): TaroElement[] {\n const array: TaroElement[] = [];\n const filter = predict ?? returnTrue;\n\n let object: TaroElement | null = root;\n\n while (object) {\n if (object.nodeType === NodeType.ELEMENT_NODE && filter(object)) {\n array.push(object);\n }\n\n object = following(object, root);\n }\n\n return array;\n}\n\nfunction following(el: TaroElement, root: TaroElement): TaroElement | null {\n const firstChild = el.firstChild;\n const isElmentTypeValid = el.nodeType === NodeType.ELEMENT_NODE || el.nodeType === NodeType.DOCUMENT_NODE;\n\n // 如果当前 el 不是 element 或 document 元素,则可以直接不递归他的子元素了\n if (firstChild && isElmentTypeValid) {\n return firstChild as TaroElement;\n }\n\n let current: TaroElement | null = el;\n\n do {\n if (current === root) {\n return null;\n }\n\n const nextSibling = current.nextSibling;\n\n if (nextSibling) {\n return nextSibling as TaroElement;\n }\n current = current.parentElement;\n } while (current);\n\n return null;\n}\n"],"mappings":";AAMA,SAAS,aAAa;CACpB,OAAO;AACT;AAEA,SAAgB,YAAY,MAAmB,SAAiC;CAC9E,MAAM,QAAuB,CAAC;CAC9B,MAAM,SAAS,YAAA,QAAA,YAAA,KAAA,IAAA,UAAW;CAE1B,IAAI,SAA6B;CAEjC,OAAO,QAAQ;EACb,IAAI,OAAO,aAAA,KAAsC,OAAO,MAAM,GAC5D,MAAM,KAAK,MAAM;EAGnB,SAAS,UAAU,QAAQ,IAAI;CACjC;CAEA,OAAO;AACT;AAEA,SAAS,UAAU,IAAiB,MAAuC;CACzE,MAAM,aAAa,GAAG;CACtB,MAAM,oBAAoB,GAAG,aAAA,KAAsC,GAAG,aAAA;CAGtE,IAAI,cAAc,mBAChB,OAAO;CAGT,IAAI,UAA8B;CAElC,GAAG;EACD,IAAI,YAAY,MACd,OAAO;EAGT,MAAM,cAAc,QAAQ;EAE5B,IAAI,aACF,OAAO;EAET,UAAU,QAAQ;CACpB,SAAS;CAET,OAAO;AACT"}
@@ -2,14 +2,14 @@ import { BEHAVIORS, CUSTOM_WRAPPER, EXTERNAL_CLASSES, ON_HIDE, ON_LOAD, ON_READY
2
2
  import { _objectSpread2 } from "../_virtual/_@oxc-project_runtime@0.130.0/helpers/objectSpread2.js";
3
3
  import { eventCenter } from "../emitter/emitter.js";
4
4
  import env from "../env.js";
5
- import { Current } from "../current.js";
5
+ import { Current, whenAppReady } from "../current.js";
6
6
  import { _raf } from "../bom/raf.js";
7
7
  import { taroWindowProvider } from "../bom/window.js";
8
8
  import { addLeadingSlash } from "../utils/router.js";
9
9
  import { customWrapperCache, incrementId } from "../utils/index.js";
10
10
  import { eventHandler } from "../dom/event.js";
11
11
  import { perf } from "../perf.js";
12
- import { EMPTY_OBJ, EventChannel, Shortcuts, ensure, getComponentsAlias, hooks, internalComponents, isArray, isEnableTTDom, isFunction, isString, isUndefined } from "@spcsn/taro-shared";
12
+ import { EMPTY_OBJ, Shortcuts, ensure, getComponentsAlias, hooks, internalComponents, isArray, isFunction, isString, isUndefined } from "@spcsn/taro-shared";
13
13
  //#region src/dsl/common.ts
14
14
  const instances = /* @__PURE__ */ new Map();
15
15
  const pageId = incrementId();
@@ -40,8 +40,7 @@ function stringify(obj) {
40
40
  }
41
41
  function getPath(id, options) {
42
42
  const idx = id.indexOf("?");
43
- if (process.env.TARO_PLATFORM === "web") return `${idx > -1 ? id.substring(0, idx) : id}${stringify((options === null || options === void 0 ? void 0 : options.stamp) ? { stamp: options.stamp } : {})}`;
44
- else return `${idx > -1 ? id.substring(0, idx) : id}${stringify(options)}`;
43
+ return `${idx > -1 ? id.substring(0, idx) : id}${stringify(options)}`;
45
44
  }
46
45
  function getOnReadyEventKey(path) {
47
46
  return path + "." + ON_READY;
@@ -59,7 +58,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
59
58
  let unmounting = false;
60
59
  let prepareMountList = [];
61
60
  function setCurrentRouter(page) {
62
- const router = process.env.TARO_PLATFORM === "web" ? page.$taroPath : page.route || page.__route__ || page.$taroPath;
61
+ const router = page.route || page.__route__ || page.$taroPath;
63
62
  Current.router = {
64
63
  params: page.$taroParams,
65
64
  path: addLeadingSlash(router),
@@ -82,33 +81,28 @@ function createPageConfig(component, pageName, data, pageConfig) {
82
81
  this.config = pageConfig || {};
83
82
  const uniqueOptions = Object.assign({}, options, { $taroTimestamp: Date.now() });
84
83
  const $taroPath = this.$taroPath = getPath(id, uniqueOptions);
85
- if (process.env.TARO_PLATFORM === "web") config.path = $taroPath;
86
84
  if (this.$taroParams == null) this.$taroParams = uniqueOptions;
87
85
  setCurrentRouter(this);
88
- if (process.env.TARO_PLATFORM !== "web") taroWindowProvider.trigger("0", $taroPath);
86
+ taroWindowProvider.trigger("0", $taroPath);
89
87
  const mount = () => {
90
- Current.app.mount(component, $taroPath, () => {
91
- if (process.env.TARO_ENV === "tt" && isEnableTTDom()) pageElement = env.document.getPageDocumentById(this.__webviewId__);
92
- else pageElement = env.document.getElementById($taroPath);
88
+ whenAppReady((app) => app.mount(component, $taroPath, () => {
89
+ pageElement = env.document.getElementById($taroPath);
93
90
  ensure(pageElement !== null, "没有找到页面实例。");
94
91
  safeExecute($taroPath, ON_LOAD, this.$taroParams);
95
92
  loadResolver();
96
- if (process.env.TARO_PLATFORM !== "web") {
97
- pageElement.ctx = this;
98
- if (process.env.TARO_ENV === "tt" && isEnableTTDom()) pageElement.sync();
99
- else pageElement.performUpdate(true, cb);
100
- } else isFunction(cb) && cb();
101
- });
93
+ pageElement.ctx = this;
94
+ pageElement.performUpdate(true, cb);
95
+ }));
102
96
  };
103
97
  if (unmounting) prepareMountList.push(mount);
104
98
  else mount();
105
99
  },
106
100
  [ONUNLOAD]() {
107
101
  const $taroPath = this.$taroPath;
108
- if (process.env.TARO_PLATFORM !== "web") taroWindowProvider.trigger("3", $taroPath);
102
+ taroWindowProvider.trigger("3", $taroPath);
109
103
  safeExecute($taroPath, ONUNLOAD);
110
104
  unmounting = true;
111
- Current.app.unmount($taroPath, () => {
105
+ whenAppReady((app) => app.unmount($taroPath, () => {
112
106
  unmounting = false;
113
107
  instances.delete($taroPath);
114
108
  if (pageElement) {
@@ -119,26 +113,26 @@ function createPageConfig(component, pageName, data, pageConfig) {
119
113
  prepareMountList.forEach((fn) => fn());
120
114
  prepareMountList = [];
121
115
  }
122
- });
116
+ }));
123
117
  },
124
118
  [ONREADY]() {
125
119
  hasLoaded.then(() => {
126
120
  safeExecute(this.$taroPath, ON_READY);
127
121
  _raf(() => eventCenter.trigger(getOnReadyEventKey(id)));
128
- this.onReady.called = true;
122
+ this[ONREADY].called = true;
129
123
  });
130
124
  },
131
125
  [ONSHOW](options = {}) {
132
126
  hasLoaded.then(() => {
133
127
  Current.page = this;
134
128
  setCurrentRouter(this);
135
- if (process.env.TARO_PLATFORM !== "web") taroWindowProvider.trigger("2", this.$taroPath);
129
+ taroWindowProvider.trigger("2", this.$taroPath);
136
130
  safeExecute(this.$taroPath, ON_SHOW, options);
137
131
  _raf(() => eventCenter.trigger(getOnShowEventKey(id)));
138
132
  });
139
133
  },
140
134
  [ONHIDE]() {
141
- if (process.env.TARO_PLATFORM !== "web") taroWindowProvider.trigger("1", this.$taroPath);
135
+ taroWindowProvider.trigger("1", this.$taroPath);
142
136
  if (Current.page === this) {
143
137
  Current.page = null;
144
138
  Current.router = null;
@@ -147,10 +141,6 @@ function createPageConfig(component, pageName, data, pageConfig) {
147
141
  eventCenter.trigger(getOnHideEventKey(id));
148
142
  }
149
143
  };
150
- if (process.env.TARO_PLATFORM === "web") config.getOpenerEventChannel = () => {
151
- return EventChannel.pageChannel;
152
- };
153
- const isSWAN = process.env.TARO_ENV === "swan";
154
144
  LIFECYCLES.forEach((lifecycle) => {
155
145
  let isDefer = false;
156
146
  let isEvent = false;
@@ -162,14 +152,9 @@ function createPageConfig(component, pageName, data, pageConfig) {
162
152
  isEvent = true;
163
153
  return "";
164
154
  });
165
- if (isEvent && process.env.TARO_ENV === "alipay") {
166
- if (!config.events) config.events = {};
167
- config.events[lifecycle] = function() {
168
- return safeExecute(this.$taroPath, lifecycle, ...arguments);
169
- };
170
- } else config[lifecycle] = function() {
171
- const exec = () => safeExecute(this.$taroPath, lifecycle, ...arguments);
172
- if (isSWAN) return exec();
155
+ if (isEvent) return;
156
+ config[lifecycle] = function(...args) {
157
+ const exec = () => safeExecute(this.$taroPath, lifecycle, ...args);
173
158
  if (isDefer) hasLoaded.then(exec);
174
159
  else return exec();
175
160
  };
@@ -202,23 +187,21 @@ function createComponentConfig(component, componentName, data) {
202
187
  perf.start(PAGE_INIT);
203
188
  this.pageIdCache = ((_this$getPageId = this.getPageId) === null || _this$getPageId === void 0 ? void 0 : _this$getPageId.call(this)) || pageId();
204
189
  const path = getPath(id, { id: this.pageIdCache });
205
- Current.app.mount(component, path, () => {
190
+ whenAppReady((app) => app.mount(component, path, () => {
206
191
  componentElement = env.document.getElementById(path);
207
192
  ensure(componentElement !== null, "没有找到组件实例。");
208
193
  this.$taroInstances = instances.get(path);
209
194
  safeExecute(path, ON_LOAD);
210
- if (process.env.TARO_PLATFORM !== "web") {
211
- componentElement.ctx = this;
212
- if (process.env.TARO_ENV !== "tt" || !isEnableTTDom()) componentElement.performUpdate(true);
213
- }
214
- });
195
+ componentElement.ctx = this;
196
+ componentElement.performUpdate(true);
197
+ }));
215
198
  },
216
199
  [DETACHED]() {
217
200
  const path = getPath(id, { id: this.pageIdCache });
218
- Current.app.unmount(path, () => {
201
+ whenAppReady((app) => app.unmount(path, () => {
219
202
  instances.delete(path);
220
203
  if (componentElement) componentElement.ctx = null;
221
- });
204
+ }));
222
205
  },
223
206
  methods: { eh: eventHandler }
224
207
  };
@@ -239,7 +222,6 @@ function createRecursiveComponentConfig(componentName) {
239
222
  const lifeCycles = isCustomWrapper ? {
240
223
  [ATTACHED]() {
241
224
  var _this$data$i, _this$props$i;
242
- if (process.env.TARO_ENV === "tt" && isEnableTTDom()) return;
243
225
  const componentId = ((_this$data$i = this.data.i) === null || _this$data$i === void 0 ? void 0 : _this$data$i.sid) || ((_this$props$i = this.props.i) === null || _this$props$i === void 0 ? void 0 : _this$props$i.sid);
244
226
  if (isString(componentId)) {
245
227
  customWrapperCache.set(componentId, this);
@@ -249,7 +231,6 @@ function createRecursiveComponentConfig(componentName) {
249
231
  },
250
232
  [DETACHED]() {
251
233
  var _this$data$i2, _this$props$i2;
252
- if (process.env.TARO_ENV === "tt" && isEnableTTDom()) return;
253
234
  const componentId = ((_this$data$i2 = this.data.i) === null || _this$data$i2 === void 0 ? void 0 : _this$data$i2.sid) || ((_this$props$i2 = this.props.i) === null || _this$props$i2 === void 0 ? void 0 : _this$props$i2.sid);
254
235
  if (isString(componentId)) {
255
236
  customWrapperCache.delete(componentId);
@@ -258,8 +239,6 @@ function createRecursiveComponentConfig(componentName) {
258
239
  }
259
240
  }
260
241
  } : EMPTY_OBJ;
261
- const extraOptions = {};
262
- if (process.env.TARO_ENV === "jd") extraOptions.addGlobalClass = true;
263
242
  return hooks.call("modifyRecursiveComponentConfig", _objectSpread2({
264
243
  properties: {
265
244
  i: {
@@ -271,7 +250,7 @@ function createRecursiveComponentConfig(componentName) {
271
250
  value: ""
272
251
  }
273
252
  },
274
- options: _objectSpread2(_objectSpread2({}, extraOptions), {}, { virtualHost: !isCustomWrapper }),
253
+ options: { virtualHost: !isCustomWrapper },
275
254
  methods: { eh: eventHandler }
276
255
  }, lifeCycles), { isCustomWrapper });
277
256
  }