@spcsn/taro-runtime 0.1.2 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -153
- package/README.md +16 -39
- package/dist/bom/{URL.js → URL2.js} +3 -4
- package/dist/bom/URL2.js.map +1 -0
- package/dist/bom/document.d.ts +0 -1
- package/dist/bom/document.js +1 -55
- package/dist/bom/document.js.map +1 -1
- package/dist/bom/get-computed-style.js +8 -0
- package/dist/bom/get-computed-style.js.map +1 -0
- package/dist/bom/history.js +1 -2
- package/dist/bom/history.js.map +1 -1
- package/dist/bom/location.js +2 -3
- package/dist/bom/location.js.map +1 -1
- package/dist/bom/navigator.js +1 -2
- package/dist/bom/navigator.js.map +1 -1
- package/dist/bom/raf.d.ts +2 -2
- package/dist/bom/raf.js +2 -2
- package/dist/bom/raf.js.map +1 -1
- package/dist/bom/url-search-params.d.ts +14 -0
- package/dist/bom/{URLSearchParams.js → url-search-params.js} +12 -15
- package/dist/bom/url-search-params.js.map +1 -0
- package/dist/bom/{URL.d.ts → url.d.ts} +1 -0
- package/dist/bom/url.js +196 -0
- package/dist/bom/url.js.map +1 -0
- package/dist/bom/window.d.ts +3 -3
- package/dist/bom/window.js +2 -2
- package/dist/bom/window.js.map +1 -1
- package/dist/current.d.ts +3 -0
- package/dist/current.js +10 -1
- package/dist/current.js.map +1 -1
- package/dist/dom/anchor-element.js +1 -1
- package/dist/dom/class-list.js +2 -1
- package/dist/dom/class-list.js.map +1 -1
- package/dist/dom/document.js.map +1 -1
- package/dist/dom/element.js +7 -7
- package/dist/dom/element.js.map +1 -1
- package/dist/dom/event.d.ts +1 -1
- package/dist/dom/event.js +3 -13
- package/dist/dom/event.js.map +1 -1
- package/dist/dom/form.js +1 -1
- package/dist/dom/form.js.map +1 -1
- package/dist/dom/node.d.ts +4 -3
- package/dist/dom/node.js +14 -7
- package/dist/dom/node.js.map +1 -1
- package/dist/dom/root.js +2 -2
- package/dist/dom/root.js.map +1 -1
- package/dist/dom/{style_properties.js → style-properties.js} +2 -2
- package/dist/dom/{style_properties.js.map → style-properties.js.map} +1 -1
- package/dist/dom/style.js +1 -1
- package/dist/dom/style.js.map +1 -1
- package/dist/dom/text.d.ts +1 -1
- package/dist/dom/text.js.map +1 -1
- package/dist/dom/tree.js.map +1 -1
- package/dist/dsl/common.js +26 -47
- package/dist/dsl/common.js.map +1 -1
- package/dist/env.js +2 -2
- package/dist/env.js.map +1 -1
- package/dist/hydrate.js +1 -1
- package/dist/hydrate.js.map +1 -1
- package/dist/index.cjs.d.ts +4 -4
- package/dist/index.cjs.js +331 -708
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -6
- package/dist/next-tick.js +1 -6
- package/dist/next-tick.js.map +1 -1
- package/dist/perf.js +1 -1
- package/dist/perf.js.map +1 -1
- package/dist/polyfill/index.js +1 -6
- package/dist/polyfill/index.js.map +1 -1
- package/dist/runtime.esm.d.ts +4 -4
- package/dist/runtime.esm.js +330 -708
- package/dist/runtime.esm.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +16 -10
- package/dist/bom/URL.js.map +0 -1
- package/dist/bom/URLSearchParams.d.ts +0 -1
- package/dist/bom/URLSearchParams.js.map +0 -1
- package/dist/bom/getComputedStyle.js +0 -9
- package/dist/bom/getComputedStyle.js.map +0 -1
- package/dist/polyfill/intersection-observer.js +0 -494
- package/dist/polyfill/intersection-observer.js.map +0 -1
- /package/dist/bom/{getComputedStyle.d.ts → get-computed-style.d.ts} +0 -0
- /package/dist/dom/{node_types.d.ts → node-types.d.ts} +0 -0
- /package/dist/dom/{style_properties.d.ts → style-properties.d.ts} +0 -0
package/dist/dom/event.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EVENT_CALLBACK_RESULT
|
|
1
|
+
import { EVENT_CALLBACK_RESULT } from "../constants/index.js";
|
|
2
2
|
import { _objectSpread2 } from "../_virtual/_@oxc-project_runtime@0.130.0/helpers/objectSpread2.js";
|
|
3
3
|
import env from "../env.js";
|
|
4
4
|
import { isParentBound } from "../utils/index.js";
|
|
@@ -68,7 +68,7 @@ function createEvent(event, node) {
|
|
|
68
68
|
}, event);
|
|
69
69
|
for (const key in event) if (key === "currentTarget" || key === "target" || key === "type" || key === "timeStamp") continue;
|
|
70
70
|
else domEv[key] = event[key];
|
|
71
|
-
if (domEv.type === "confirm" && (node === null || node === void 0 ? void 0 : node.nodeName) === "input") domEv
|
|
71
|
+
if (domEv.type === "confirm" && (node === null || node === void 0 ? void 0 : node.nodeName) === "input") domEv.keyCode = 13;
|
|
72
72
|
return domEv;
|
|
73
73
|
}
|
|
74
74
|
const eventsBatch = {};
|
|
@@ -79,8 +79,6 @@ function getEventCBResult(event) {
|
|
|
79
79
|
}
|
|
80
80
|
function eventHandler(event) {
|
|
81
81
|
var _currentTarget$datase2, _event$detail;
|
|
82
|
-
event.type === void 0 && Object.defineProperty(event, "type", { value: event._type });
|
|
83
|
-
event.detail === void 0 && Object.defineProperty(event, "detail", { value: event._detail || _objectSpread2({}, event) });
|
|
84
82
|
event.currentTarget = event.currentTarget || event.target || _objectSpread2({}, event);
|
|
85
83
|
hooks.call("modifyMpEventImpl", event);
|
|
86
84
|
const currentTarget = event.currentTarget;
|
|
@@ -111,15 +109,7 @@ function eventHandler(event) {
|
|
|
111
109
|
}
|
|
112
110
|
}
|
|
113
111
|
}
|
|
114
|
-
function eventHandlerTTDom(ele, listener, event) {
|
|
115
|
-
Object.assign(event, {
|
|
116
|
-
mpEvent: event,
|
|
117
|
-
bubbles: true,
|
|
118
|
-
cancelable: true
|
|
119
|
-
});
|
|
120
|
-
listener(event, ele);
|
|
121
|
-
}
|
|
122
112
|
//#endregion
|
|
123
|
-
export { TaroEvent, createEvent, eventHandler
|
|
113
|
+
export { TaroEvent, createEvent, eventHandler };
|
|
124
114
|
|
|
125
115
|
//# sourceMappingURL=event.js.map
|
package/dist/dom/event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.js","names":[],"sources":["../../src/dom/event.ts"],"sourcesContent":["import { EMPTY_OBJ, hooks, isUndefined } from '@spcsn/taro-shared';\n\nimport {\n CONFIRM,\n CURRENT_TARGET,\n EVENT_CALLBACK_RESULT,\n INPUT,\n
|
|
1
|
+
{"version":3,"file":"event.js","names":[],"sources":["../../src/dom/event.ts"],"sourcesContent":["import { EMPTY_OBJ, hooks, isUndefined } from '@spcsn/taro-shared';\n\nimport {\n CONFIRM,\n CURRENT_TARGET,\n EVENT_CALLBACK_RESULT,\n INPUT,\n TARGET,\n TIME_STAMP,\n TOUCHMOVE,\n TYPE,\n} from '../constants';\nimport env from '../env';\nimport { isParentBound } from '../utils';\n\nimport type { EventOptions, MpEvent } from '../interface';\nimport type { TaroElement } from './element';\n\n// Taro 事件对象。以 Web 标准的事件对象为基础,加入小程序事件对象中携带的部分信息,并模拟实现事件冒泡。\nexport class TaroEvent {\n private cacheTarget;\n private cacheCurrentTarget;\n\n public type: string;\n\n public bubbles: boolean;\n\n public cancelable: boolean;\n\n public _stop = false;\n\n public _end = false;\n\n public defaultPrevented = false;\n\n // Mouse Event botton property, it's used in 3rd lib, like react-router. default 0 in general\n public button = 0;\n\n public keyCode?: number;\n\n // timestamp can either be hi-res ( relative to page load) or low-res (relative to UNIX epoch)\n // here use hi-res timestamp\n public timeStamp = Date.now();\n\n public mpEvent: MpEvent | undefined;\n\n public constructor(type: string, opts: EventOptions, event?: MpEvent) {\n this.type = type.toLowerCase();\n this.mpEvent = event;\n this.bubbles = Boolean(opts && opts.bubbles);\n this.cancelable = Boolean(opts && opts.cancelable);\n }\n\n public stopPropagation() {\n this._stop = true;\n }\n\n public stopImmediatePropagation() {\n this._end = this._stop = true;\n }\n\n public preventDefault() {\n this.defaultPrevented = true;\n }\n\n get target() {\n const cacheTarget = this.cacheTarget;\n if (!cacheTarget) {\n const target = Object.create(this.mpEvent?.target || null);\n const currentEle = env.document.getElementById(target.dataset?.sid || target.id || null);\n // Note:优先判断冒泡场景alipay的targetDataset的sid, 不然冒泡场景target属性吐出不对,其余拿取当前绑定id\n const element = env.document.getElementById(\n target.targetDataset?.sid || target.dataset?.sid || target.id || null,\n );\n\n target.dataset = {\n ...(currentEle !== null ? currentEle.dataset : EMPTY_OBJ),\n ...(element !== null ? element.dataset : EMPTY_OBJ),\n };\n\n for (const key in this.mpEvent?.detail) {\n target[key] = this.mpEvent!.detail[key];\n }\n\n this.cacheTarget = target;\n\n return target;\n } else {\n return cacheTarget;\n }\n }\n\n get currentTarget() {\n const cacheCurrentTarget = this.cacheCurrentTarget;\n if (!cacheCurrentTarget) {\n const doc = env.document;\n\n const currentTarget = Object.create(this.mpEvent?.currentTarget || null);\n\n const element = doc.getElementById(currentTarget.dataset?.sid || currentTarget.id || null);\n const targetElement = doc.getElementById(\n (this.mpEvent?.target?.dataset?.sid as string) || (this.mpEvent?.target?.id as string) || null,\n );\n\n if (element === null || (element && element === targetElement)) {\n this.cacheCurrentTarget = this.target;\n return this.target;\n }\n\n currentTarget.dataset = element.dataset;\n\n for (const key in this.mpEvent?.detail) {\n currentTarget[key] = this.mpEvent!.detail[key];\n }\n\n this.cacheCurrentTarget = currentTarget;\n\n return currentTarget;\n } else {\n return cacheCurrentTarget;\n }\n }\n}\n\nexport function createEvent(event: MpEvent | string, node?: TaroElement) {\n if (typeof event === 'string') {\n // For Vue3 using document.createEvent\n return new TaroEvent(event, { bubbles: true, cancelable: true });\n }\n\n const domEv = new TaroEvent(event.type, { bubbles: true, cancelable: true }, event);\n\n for (const key in event) {\n if (key === CURRENT_TARGET || key === TARGET || key === TYPE || key === TIME_STAMP) {\n continue;\n } else {\n domEv[key] = event[key];\n }\n }\n\n if (domEv.type === CONFIRM && node?.nodeName === INPUT) {\n domEv.keyCode = 13;\n }\n\n return domEv;\n}\n\nconst eventsBatch = {};\n\nfunction getEventCBResult(event: MpEvent) {\n const result = event[EVENT_CALLBACK_RESULT];\n if (!isUndefined(result)) {\n delete event[EVENT_CALLBACK_RESULT];\n }\n return result;\n}\n\n// 小程序的事件代理回调函数\nexport function eventHandler(event: MpEvent) {\n event.currentTarget = event.currentTarget || event.target || { ...event };\n hooks.call('modifyMpEventImpl', event);\n\n const currentTarget = event.currentTarget;\n const id =\n (currentTarget.dataset?.sid as string) /** sid */ ||\n currentTarget.id /** uid */ ||\n (event.detail?.id as string) ||\n '';\n\n const node = env.document.getElementById(id);\n if (node) {\n const dispatch = () => {\n const e = createEvent(event, node);\n\n hooks.call('modifyTaroEvent', e, node);\n hooks.call('dispatchTaroEvent', e, node);\n hooks.call('dispatchTaroEventFinish', e, node);\n };\n if (hooks.isExist('batchedEventUpdates')) {\n const type = event.type;\n\n if (\n !hooks.call('isBubbleEvents', type) ||\n !isParentBound(node, type) ||\n (type === TOUCHMOVE && !!node.props.catchMove)\n ) {\n // 最上层组件统一 batchUpdate\n hooks.call('batchedEventUpdates', () => {\n if (eventsBatch[type]) {\n eventsBatch[type].forEach((fn) => fn());\n delete eventsBatch[type];\n }\n dispatch();\n });\n return getEventCBResult(event);\n } else {\n // 如果上层组件也有绑定同类型的组件,委托给上层组件调用事件回调\n (eventsBatch[type] ||= []).push(dispatch);\n }\n } else {\n dispatch();\n return getEventCBResult(event);\n }\n }\n}\n"],"mappings":";;;;;;AAmBA,IAAa,YAAb,MAAuB;CA2BrB,YAAmB,MAAc,MAAoB,OAAiB;EAjBtE,KAAO,QAAQ;EAEf,KAAO,OAAO;EAEd,KAAO,mBAAmB;EAG1B,KAAO,SAAS;EAMhB,KAAO,YAAY,KAAK,IAAI;EAK1B,KAAK,OAAO,KAAK,YAAY;EAC7B,KAAK,UAAU;EACf,KAAK,UAAU,QAAQ,QAAQ,KAAK,OAAO;EAC3C,KAAK,aAAa,QAAQ,QAAQ,KAAK,UAAU;CACnD;CAEA,kBAAyB;EACvB,KAAK,QAAQ;CACf;CAEA,2BAAkC;EAChC,KAAK,OAAO,KAAK,QAAQ;CAC3B;CAEA,iBAAwB;EAC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AAK,qBAAqB,KAAK;CAErC,MAAM,gBAAgB,MAAM;CAC5B,MAAM,OAAA,yBACH,cAAc,aAAA,QAAA,2BAAA,KAAA,IAAA,KAAA,IAAA,uBAAS,QACxB,cAAc,QAAA,gBACb,MAAM,YAAA,QAAA,kBAAA,KAAA,IAAA,KAAA,IAAA,cAAQ,OACf;CAEF,MAAM,OAAO,IAAI,SAAS,eAAe,EAAE;CAC3C,IAAI,MAAM;EACR,MAAM,iBAAiB;GACrB,MAAM,IAAI,YAAY,OAAO,IAAI;GAEjC,MAAM,KAAK,mBAAmB,GAAG,IAAI;GACrC,MAAM,KAAK,qBAAqB,GAAG,IAAI;GACvC,MAAM,KAAK,2BAA2B,GAAG,IAAI;EAC/C;EACA,IAAI,MAAM,QAAQ,qBAAqB,GAAG;GACxC,MAAM,OAAO,MAAM;GAEnB,IACE,CAAC,MAAM,KAAK,kBAAkB,IAAI,KAClC,CAAC,cAAc,MAAM,IAAI,KACxB,SAAA,eAAsB,CAAC,CAAC,KAAK,MAAM,WACpC;IAEA,MAAM,KAAK,6BAA6B;KACtC,IAAI,YAAY,OAAO;MACrB,YAAY,MAAM,SAAS,OAAO,GAAG,CAAC;MACtC,OAAO,YAAY;KACrB;KACA,SAAS;IACX,CAAC;IACD,OAAO,iBAAiB,KAAK;GAC/B,OAEE,CAAC,YAAY,UAAZ,YAAY,QAAU,CAAC,IAAG,KAAK,QAAQ;EAE5C,OAAO;GACL,SAAS;GACT,OAAO,iBAAiB,KAAK;EAC/B;CACF;AACF"}
|
package/dist/dom/form.js
CHANGED
package/dist/dom/form.js.map
CHANGED
|
@@ -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
|
|
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"}
|
package/dist/dom/node.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TaroEventTarget } from './event-target';
|
|
2
|
-
import { NodeType } from './
|
|
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
|
-
|
|
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],
|
package/dist/dom/node.js.map
CHANGED
|
@@ -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;AAE3B,IAAa,WAAb,MAAa,iBAAiB,gBAAgB;CAQ5C,cAAqB;EACnB,MAAM;EAJR,KAAO,aAA8B;EACrC,KAAO,aAAyB,CAAC;EASjC,KAAQ,WAAW,eAAyB,QAAQ,IAAmB;EALrE,KAAK,MAAM,MAAM,OAAO;EACxB,KAAK,MAAM,KAAK;EAChB,YAAY,IAAI,KAAK,KAAK,IAAI;CAChC;CAIA,iBAAyB,SAAmB;EAC1C,MAAM,wBAAwB,CAAC;EAC/B,MAAM,2BAA2B;GAE/B,OADmB,KAAK,WAAW,QAAQ,SAAS,CAAC,UAAU,IAAI,CACnD,EAAE,IAAI,OAAO;EAC/B;EAEA,KAAK,cAAc;GACjB,MAAM,GAAG,KAAK,MAAM,GAAG;GACvB,OAAO,UAAU,kBAAkB;EACrC,CAAC;CACH;CAEA,kBAA0B,OAAe;EACvC,KAAK,WAAW,SAAS,OAAO,eAAe;GAC7C,IAAI,UAAU,KAAK,GAAG;GAEtB,IAAI,SAAS,aAAa,OAAO;GAEjC,KAAK,cAAc;IACjB,MAAM,MAAM;IACZ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B,SAAS;EAC5B,CAAC;EAED,OAAO;CACT;;;;;;;;;CAUA,YAAmB,UAAoB;EACrC,OAAO,KAAK,aAAa,QAAQ;CACnC;;;;;;;;;CAUA,aAAoB,UAAoB,UAAoB;EAC1D,IAAI,SAAS,eAAe,MAAM;EAGlC,KAAK,aAAa,UAAU,UAAU,IAAI;EAK1C,SAAS,OAAO,EAAE,UAAU,MAAM,CAAC;EAEnC,OAAO;CACT;;;;;;;;CASA,YAAuC,OAAU,UAA8B,CAAC,GAAM;EACpF,MAAM,EAAE,UAAU,aAAa;EAE/B,IAAI,aAAa,SAAS,aAAa,OAGrC,iBAAiB,OAAO;GACtB,MAAA;GACA,QAAQ;GACR,cAAc,CAAC,KAAK;GACpB,aAAa,MAAM;GACnB,iBAAiB,MAAM;EACzB,CAAC;EAIH,MAAM,QAAQ,KAAK,UAAU,KAAK;EAClC,KAAK,WAAW,OAAO,OAAO,CAAC;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,KAAK,KAAK,IAAI;CAChC;CAIA,iBAAyB,SAAmB;EAC1C,MAAM,wBAAwB,CAAC;EAC/B,MAAM,2BAA2B;GAE/B,OADmB,KAAK,WAAW,QAAQ,SAAS,CAAC,UAAU,IAAI,CACnD,EAAE,KAAK,cAAc,QAAQ,SAAmC,CAAC;EACnF;EAEA,KAAK,cAAc;GACjB,MAAM,GAAG,KAAK,MAAM,GAAG;GACvB,OAAO,UAAU,kBAAkB;EACrC,CAAC;CACH;CAEA,kBAA0B,OAAe;EACvC,KAAK,WAAW,SAAS,OAAO,eAAe;GAC7C,IAAI,UAAU,KAAK,GAAG;GAEtB,IAAI,SAAS,aAAa,OAAO;GAEjC,KAAK,cAAc;IACjB,MAAM,MAAM;IACZ,OAAO,KAAK,QAAQ,KAAK;GAC3B,CAAC;EACH,CAAC;CACH;CAEA,IAAW,QAAgC;;EACzC,SAAA,mBAAO,KAAK,gBAAA,QAAA,qBAAA,KAAA,IAAA,KAAA,IAAA,iBAAY,UAAS;CACnC;CAEA,UAAoB,UAA4B;EAC9C,MAAM,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5B,CAAC;EAED,OAAO;CACT;;;;;;;;;CAUA,YAAmB,UAAoB;EACrC,OAAO,KAAK,aAAa,QAAQ;CACnC;;;;;;;;;CAUA,aAAoB,UAAoB,UAAoB;EAC1D,IAAI,SAAS,eAAe,MAAM;EAGlC,KAAK,aAAa,UAAU,UAAU,IAAI;EAK1C,SAAS,OAAO,EAAE,UAAU,MAAM,CAAC;EAEnC,OAAO;CACT;;;;;;;;CASA,YAAuC,OAAU,UAA8B,CAAC,GAAM;EACpF,MAAM,EAAE,UAAU,UAAU,mBAAmB;EAE/C,IAAK,aAAa,SAAS,aAAa,SAAU,gBAChD,iBAAiB,OAAO;GACtB,MAAA;GACA,QAAQ;GACR,cAAc,CAAC,KAAK;GACpB,aAAa,MAAM;GACnB,iBAAiB,MAAM;EACzB,CAAC;EAIH,MAAM,QAAQ,KAAK,UAAU,KAAK;EAClC,KAAK,WAAW,OAAO,OAAO,CAAC;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
|
});
|
package/dist/dom/root.js.map
CHANGED
|
@@ -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
|
|
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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,oBAAoB;KACzB,cAAc,KAAK,KAAA,OAAc;IACnC;GACF;GAGA,IAAI,oBACF,iBAAiB,SAAS,MAAM,QAAQ;IACtC,IAA6C,QAAQ,OACnD,WAAW,QAAQ,IAAI,4BAA4B,IAAI;IAEzD,IAAI,QAAQ,MAAM,EAAE;GACtB,CAAC;GAIH,IAAI,oBAAoB;IACtB,IAA6C,QAAQ,OACnD,WAAW,QAAQ,IAAI,iBAAiB,YAAY;IAEtD,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,4 +1,4 @@
|
|
|
1
|
-
//#region src/dom/
|
|
1
|
+
//#region src/dom/style-properties.ts
|
|
2
2
|
const WEBKIT = "webkit";
|
|
3
3
|
const styleProperties = [
|
|
4
4
|
"all",
|
|
@@ -371,4 +371,4 @@ combine(WEBKIT, [
|
|
|
371
371
|
//#endregion
|
|
372
372
|
export { styleProperties };
|
|
373
373
|
|
|
374
|
-
//# sourceMappingURL=
|
|
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;AACzD,MAAM,wBAAwB;CAAC;CAAU;CAAQ;CAAS;AAAK;AAC/D,MAAM,YAAY,CAAC,OAAO,OAAO;AACjC,MAAM,qBAAqB;CAAC;CAAW;CAAS;AAAM;AACtD,MAAM,oCAAoC;CAAC;CAAa;CAAU;CAAc;AAAK;AACrF,MAAM,eAAe,CAAC,SAAS,QAAQ;AAEvC,QAAQ,eAAe,iBAAiB;AACxC,QAAQ,kBAAkB,iBAAiB;AAC3C,QAAQ,oBAAoB,iBAAiB;AAC7C,QAAQ,WAAW,CAAC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.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;AACzD,MAAM,wBAAwB;CAAC;CAAU;CAAQ;CAAS;AAAK;AAC/D,MAAM,YAAY,CAAC,OAAO,OAAO;AACjC,MAAM,qBAAqB;CAAC;CAAW;CAAS;AAAM;AACtD,MAAM,oCAAoC;CAAC;CAAa;CAAU;CAAc;AAAK;AACrF,MAAM,eAAe,CAAC,SAAS,QAAQ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AAI"}
|
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 "./
|
|
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) {
|
package/dist/dom/style.js.map
CHANGED
|
@@ -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 './
|
|
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,c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;EAGzC,IAAI,OAAO,KAAK,KAAK,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"}
|
package/dist/dom/text.d.ts
CHANGED
package/dist/dom/text.js.map
CHANGED
|
@@ -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 './
|
|
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"}
|
package/dist/dom/tree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.js","names":[],"sources":["../../src/dom/tree.ts"],"sourcesContent":["import { NodeType } from './
|
|
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"}
|