@tarojs/runtime 4.0.0-canary.9 → 4.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.
- package/LICENSE +8 -8
- package/dist/bom/URL.js.map +1 -1
- package/dist/bom/URLSearchParams.js +12 -4
- package/dist/bom/URLSearchParams.js.map +1 -1
- package/dist/bom/history.js.map +1 -1
- package/dist/bom/location.js.map +1 -1
- package/dist/bom/raf.d.ts +1 -0
- package/dist/bom/raf.js +2 -2
- package/dist/bom/raf.js.map +1 -1
- package/dist/bom/window.d.ts +1 -0
- package/dist/bom/window.js.map +1 -1
- package/dist/dom/anchor-element.js.map +1 -1
- package/dist/dom/class-list.js.map +1 -1
- package/dist/dom/document.js.map +1 -1
- package/dist/dom/element.js.map +1 -1
- package/dist/dom/event-target.js.map +1 -1
- package/dist/dom/event.js +5 -4
- 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.js +2 -2
- package/dist/dom/node.js.map +1 -1
- package/dist/dom/root.js.map +1 -1
- package/dist/dom/style.js.map +1 -1
- package/dist/dom/style_properties.js.map +1 -1
- package/dist/dom/tree.js.map +1 -1
- package/dist/dom-external/element.js.map +1 -1
- package/dist/dom-external/index.js +1 -3
- package/dist/dom-external/index.js.map +1 -1
- package/dist/dom-external/inner-html/html.js.map +1 -1
- package/dist/dom-external/inner-html/parser.js.map +1 -1
- package/dist/dom-external/inner-html/scaner.js.map +1 -1
- package/dist/dom-external/inner-html/style.js.map +1 -1
- package/dist/dom-external/inner-html/tags.js +4 -4
- package/dist/dom-external/inner-html/tags.js.map +1 -1
- package/dist/dom-external/inner-html/utils.js.map +1 -1
- package/dist/dom-external/mutation-observer/implements.js.map +1 -1
- package/dist/dom-external/mutation-observer/index.js.map +1 -1
- package/dist/dom-external/node.js +1 -0
- package/dist/dom-external/node.js.map +1 -1
- package/dist/dsl/common.d.ts +1 -0
- package/dist/dsl/common.js +6 -1
- package/dist/dsl/common.js.map +1 -1
- package/dist/hydrate.js +9 -2
- package/dist/hydrate.js.map +1 -1
- package/dist/index.cjs.d.ts +17 -14
- package/dist/index.cjs.js +76 -28
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/instance-4c64b022.d.ts +7 -14
- package/dist/next-tick.js.map +1 -1
- package/dist/perf.d.ts +3 -1
- package/dist/perf.js +24 -3
- package/dist/perf.js.map +1 -1
- package/dist/polyfill/array.js.map +1 -1
- package/dist/polyfill/index.js.map +1 -1
- package/dist/polyfill/intersection-observer.js +4 -3
- package/dist/polyfill/intersection-observer.js.map +1 -1
- package/dist/polyfill/object.js.map +1 -1
- package/dist/runtime.esm.d.ts +17 -14
- package/dist/runtime.esm.js +74 -28
- package/dist/runtime.esm.js.map +1 -1
- package/dist/utils/cache.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/lodash.d.ts +2 -1
- package/dist/utils/lodash.js +11 -1
- package/dist/utils/lodash.js.map +1 -1
- package/package.json +15 -23
package/dist/hydrate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydrate.js","sources":["../src/hydrate.ts"],"sourcesContent":["import { hooks, Shortcuts, toCamelCase } from '@tarojs/shared'\n\nimport {\n CATCH_VIEW,\n CATCHMOVE,\n CLASS,\n COMPILE_MODE,\n ID,\n PURE_VIEW,\n STYLE,\n VIEW\n} from './constants'\nimport { getComponentsAlias, isComment, isHasExtractProp, isText } from './utils'\n\nimport type { TaroElement } from './dom/element'\nimport type { TaroText } from './dom/text'\nimport type { MiniData, MiniElementData } from './interface'\n\nlet SPECIAL_NODES\nlet componentsAlias\n\n/**\n * React also has a fancy function's name for this: `hydrate()`.\n * You may have been heard `hydrate` as a SSR-related function,\n * actually, `hydrate` basicly do the `render()` thing, but ignore some properties,\n * it's a vnode traverser and modifier: that's exactly what Taro's doing in here.\n */\nexport function hydrate (node: TaroElement | TaroText): MiniData {\n // 初始化 componentsAlias\n componentsAlias ||= getComponentsAlias()\n\n // 初始化 SPECIAL_NODES\n SPECIAL_NODES ||= hooks.call('getSpecialNodes')!\n\n const nodeName = node.nodeName\n\n if (isText(node)) {\n return {\n sid: node.sid,\n [Shortcuts.Text]: node.nodeValue,\n [Shortcuts.NodeName]: componentsAlias[nodeName]?._num || '8'\n }\n }\n\n const data: MiniElementData = {\n [Shortcuts.NodeName]: nodeName,\n sid: node.sid\n }\n\n if (node.uid !== node.sid) {\n data.uid = node.uid\n }\n\n if (!node.isAnyEventBinded() && SPECIAL_NODES.indexOf(nodeName) > -1) {\n data[Shortcuts.NodeName] = `static-${nodeName}`\n if (nodeName === VIEW && !isHasExtractProp(node)) {\n data[Shortcuts.NodeName] = PURE_VIEW\n }\n }\n\n const { props } = node\n for (const prop in props) {\n const propInCamelCase = toCamelCase(prop)\n if (\n !prop.startsWith('data-') && // 在 node.dataset 的数据\n prop !== CLASS &&\n prop !== STYLE &&\n prop !== ID &&\n propInCamelCase !== CATCHMOVE &&\n propInCamelCase !== COMPILE_MODE\n ) {\n data[propInCamelCase] = props[prop]\n }\n if (nodeName === VIEW
|
|
1
|
+
{"version":3,"file":"hydrate.js","sources":["../src/hydrate.ts"],"sourcesContent":["import { hooks, Shortcuts, toCamelCase } from '@tarojs/shared'\n\nimport {\n CATCH_VIEW,\n CATCHMOVE,\n CLASS,\n COMPILE_MODE,\n ID,\n PURE_VIEW,\n STYLE,\n VIEW\n} from './constants'\nimport { getComponentsAlias, isComment, isHasExtractProp, isText } from './utils'\n\nimport type { TaroElement } from './dom/element'\nimport type { TaroText } from './dom/text'\nimport type { MiniData, MiniElementData } from './interface'\n\nlet SPECIAL_NODES\nlet componentsAlias\n\n/**\n * React also has a fancy function's name for this: `hydrate()`.\n * You may have been heard `hydrate` as a SSR-related function,\n * actually, `hydrate` basicly do the `render()` thing, but ignore some properties,\n * it's a vnode traverser and modifier: that's exactly what Taro's doing in here.\n */\nexport function hydrate (node: TaroElement | TaroText): MiniData {\n // 初始化 componentsAlias\n componentsAlias ||= getComponentsAlias()\n\n // 初始化 SPECIAL_NODES\n SPECIAL_NODES ||= hooks.call('getSpecialNodes')!\n\n const nodeName = node.nodeName\n let compileModeName = null\n\n if (isText(node)) {\n return {\n sid: node.sid,\n [Shortcuts.Text]: node.nodeValue,\n [Shortcuts.NodeName]: componentsAlias[nodeName]?._num || '8'\n }\n }\n\n const data: MiniElementData = {\n [Shortcuts.NodeName]: nodeName,\n sid: node.sid\n }\n\n if (node.uid !== node.sid) {\n data.uid = node.uid\n }\n\n if (!node.isAnyEventBinded() && SPECIAL_NODES.indexOf(nodeName) > -1) {\n data[Shortcuts.NodeName] = `static-${nodeName}`\n if (nodeName === VIEW && !isHasExtractProp(node)) {\n data[Shortcuts.NodeName] = PURE_VIEW\n }\n }\n\n const { props } = node\n for (const prop in props) {\n const propInCamelCase = toCamelCase(prop)\n if (\n !prop.startsWith('data-') && // 在 node.dataset 的数据\n prop !== CLASS &&\n prop !== STYLE &&\n prop !== ID &&\n propInCamelCase !== CATCHMOVE &&\n propInCamelCase !== COMPILE_MODE\n ) {\n data[propInCamelCase] = props[prop]\n }\n if (\n process.env.TARO_ENV !== 'swan' &&\n nodeName === VIEW &&\n propInCamelCase === CATCHMOVE &&\n props[prop] !== false\n ) {\n data[Shortcuts.NodeName] = CATCH_VIEW\n }\n if (propInCamelCase === COMPILE_MODE) {\n compileModeName = props[prop]\n }\n }\n\n // Children\n data[Shortcuts.Childnodes] = node.childNodes.filter(node => !isComment(node)).map(hydrate)\n\n if (node.className !== '') {\n data[Shortcuts.Class] = node.className\n }\n\n const cssText = node.cssText\n if (cssText !== '' && nodeName !== 'swiper-item') {\n data[Shortcuts.Style] = cssText\n }\n\n hooks.call('modifyHydrateData', data, node)\n\n const nn = data[Shortcuts.NodeName]\n const componentAlias = componentsAlias[nn]\n if (componentAlias) {\n data[Shortcuts.NodeName] = componentAlias._num\n for (const prop in data) {\n if (prop in componentAlias) {\n data[componentAlias[prop]] = data[prop]\n delete data[prop]\n }\n }\n }\n\n if (compileModeName !== null) {\n data[Shortcuts.NodeName] = compileModeName\n }\n\n const resData = hooks.call('transferHydrateData', data, node, componentAlias)\n\n return resData || data\n}\n"],"names":[],"mappings":"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"}
|
package/dist/index.cjs.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="react" />
|
|
1
3
|
import { Shortcuts, Events } from "@tarojs/shared";
|
|
2
|
-
import VueCtor from "vue";
|
|
3
|
-
import { ComponentOptions, VNode } from "vue";
|
|
4
4
|
import { Component as Vue3Component } from "@vue/runtime-core";
|
|
5
5
|
import { Component, ComponentClass } from "react";
|
|
6
|
-
import { CombinedVueInstance } from "vue/types/vue";
|
|
7
6
|
declare class ClassList {
|
|
8
7
|
private el;
|
|
9
8
|
private tokenList;
|
|
@@ -649,14 +648,6 @@ interface Instance<T = Record<string, any>> extends Component<T>, Show, PageInst
|
|
|
649
648
|
$nextTick?(cb: () => void): void;
|
|
650
649
|
$options: Instance;
|
|
651
650
|
}
|
|
652
|
-
interface VueAppInstance extends ComponentOptions<VueCtor> {
|
|
653
|
-
$options: AppInstance;
|
|
654
|
-
}
|
|
655
|
-
type VueInstance<M = Record<string, any>, P = Record<string, any>> = CombinedVueInstance<VueCtor, Record<string, any>, M, P, Record<never, any>> & VueInternal;
|
|
656
|
-
interface VueInternal {
|
|
657
|
-
_render(): VNode;
|
|
658
|
-
_update(vnode: VNode, hyrate: boolean): void;
|
|
659
|
-
}
|
|
660
651
|
interface PageProps {
|
|
661
652
|
tid?: string;
|
|
662
653
|
}
|
|
@@ -706,6 +697,8 @@ interface PageInstance extends PageLifeCycle {
|
|
|
706
697
|
options?: Record<string, unknown>;
|
|
707
698
|
/** 页面渲染引擎类型 */
|
|
708
699
|
renderer?: "webview" | "skyline";
|
|
700
|
+
/** 获得一个 EventChannel 对象,用于页面间通讯 */
|
|
701
|
+
getOpenerEventChannel?(): Record<string, any>;
|
|
709
702
|
}
|
|
710
703
|
interface Show {
|
|
711
704
|
componentDidShow?(): void;
|
|
@@ -715,13 +708,14 @@ interface Show {
|
|
|
715
708
|
}
|
|
716
709
|
interface AppInstance extends Show {
|
|
717
710
|
componentDidShow?(options?: Record<string, unknown>): void;
|
|
718
|
-
mount?(component: React.ComponentClass |
|
|
719
|
-
mount?(component: React.ComponentClass |
|
|
711
|
+
mount?(component: React.ComponentClass | Vue3Component, id: string, cb: (...args: any[]) => void): void;
|
|
712
|
+
mount?(component: React.ComponentClass | Vue3Component, id: string, getCtx: (...args: any[]) => void, cb: (...args: any[]) => void): void;
|
|
720
713
|
onError?(error: string): void;
|
|
721
714
|
onLaunch?(options?: Record<string, unknown>): void;
|
|
722
715
|
onPageNotFound?(res: any): void;
|
|
723
716
|
onUnhandledRejection?(error: any): void;
|
|
724
717
|
onShow?(options?: Record<string, unknown>): void;
|
|
718
|
+
onHide?(options?: Record<string, unknown>): void;
|
|
725
719
|
unmount?(id: string, cb?: () => void): void;
|
|
726
720
|
taroGlobalData?: Record<any, any>;
|
|
727
721
|
config?: Record<any, any>;
|
|
@@ -769,6 +763,14 @@ declare function createRecursiveComponentConfig(componentName?: string): any;
|
|
|
769
763
|
declare function hydrate(node: TaroElement | TaroText): MiniData;
|
|
770
764
|
declare const nextTick: (cb: TFunc, ctx?: Record<string, any>) => void;
|
|
771
765
|
declare const options: Options;
|
|
766
|
+
declare class Performance {
|
|
767
|
+
#private;
|
|
768
|
+
private recorder;
|
|
769
|
+
start(id: string): void;
|
|
770
|
+
stop(id: string, now?: number): void;
|
|
771
|
+
delayStop(id: string, delay?: number): ((...args: any[]) => void) | undefined;
|
|
772
|
+
}
|
|
773
|
+
declare const perf: Performance;
|
|
772
774
|
declare const incrementId: () => () => string;
|
|
773
775
|
declare function isElement(node: TaroNode): node is TaroElement;
|
|
774
776
|
declare function isText(node: TaroNode): node is TaroText;
|
|
@@ -789,6 +791,7 @@ declare function extend(ctor: Ctor, methodName: string, options: TFunc | Record<
|
|
|
789
791
|
declare function getComponentsAlias(): any;
|
|
790
792
|
declare function convertNumber2PX(value: number): string;
|
|
791
793
|
declare function throttle(fn: any, threshold?: number, scope?: any): (...args: any[]) => void;
|
|
794
|
+
declare function debounce(fn: any, ms?: number, scope?: any): (...args: any[]) => void;
|
|
792
795
|
// export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
|
|
793
796
|
// export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')
|
|
794
797
|
declare const addLeadingSlash: (url?: string) => string;
|
|
@@ -800,4 +803,4 @@ declare const getHomePage: (path?: string, basename?: string, customRoutes?: Rec
|
|
|
800
803
|
declare const getCurrentPage: (routerMode?: string, basename?: string) => string;
|
|
801
804
|
declare function handlePolyfill(): void;
|
|
802
805
|
export { hooks } from '@tarojs/shared';
|
|
803
|
-
export { document, getComputedStyle, History, Location, nav as navigator, _caf as cancelAnimationFrame, now, _raf as requestAnimationFrame, parseUrl, URL, URLSearchParams, history, location, window, TaroElement, createEvent, eventHandler, TaroEvent, FormElement, TaroNode, TaroRootElement, Style, SVGElement, TaroText, MutationObserver, env, PROPERTY_THRESHOLD, TARO_RUNTIME, HOOKS_APP_ID, SET_DATA, PAGE_INIT, ROOT_STR, HTML, HEAD, BODY, APP, CONTAINER, DOCUMENT_ELEMENT_NAME, DOCUMENT_FRAGMENT, ID, UID, CLASS, STYLE, FOCUS, VIEW, STATIC_VIEW, PURE_VIEW, PROPS, DATASET, OBJECT, VALUE, INPUT, CHANGE, CUSTOM_WRAPPER, TARGET, CURRENT_TARGET, TYPE, CONFIRM, TIME_STAMP, KEY_CODE, TOUCHMOVE, DATE, SET_TIMEOUT, COMPILE_MODE, CATCHMOVE, CATCH_VIEW, COMMENT, ON_LOAD, ON_READY, ON_SHOW, ON_HIDE, OPTIONS, EXTERNAL_CLASSES, EVENT_CALLBACK_RESULT, BEHAVIORS, A, CONTEXT_ACTIONS, Current, getCurrentInstance, eventSource, createComponentConfig, createPageConfig, createRecursiveComponentConfig, getOnHideEventKey, getOnReadyEventKey, getOnShowEventKey, getPageInstance, getPath, injectPageInstance, removePageInstance, safeExecute, stringify, EventsType, eventCenter, Events, hydrate, nextTick, options, incrementId, isElement, isText, isComment, isHasExtractProp, isParentBinded, shortcutAttr, customWrapperCache, extend, getComponentsAlias, convertNumber2PX, throttle, addLeadingSlash, hasBasename, stripBasename, stripTrailing, stripSuffix, getHomePage, getCurrentPage, Instance,
|
|
806
|
+
export { document, getComputedStyle, History, Location, nav as navigator, _caf as cancelAnimationFrame, now, _raf as requestAnimationFrame, parseUrl, URL, URLSearchParams, history, location, window, TaroElement, createEvent, eventHandler, TaroEvent, FormElement, TaroNode, TaroRootElement, Style, SVGElement, TaroText, MutationObserver, env, PROPERTY_THRESHOLD, TARO_RUNTIME, HOOKS_APP_ID, SET_DATA, PAGE_INIT, ROOT_STR, HTML, HEAD, BODY, APP, CONTAINER, DOCUMENT_ELEMENT_NAME, DOCUMENT_FRAGMENT, ID, UID, CLASS, STYLE, FOCUS, VIEW, STATIC_VIEW, PURE_VIEW, PROPS, DATASET, OBJECT, VALUE, INPUT, CHANGE, CUSTOM_WRAPPER, TARGET, CURRENT_TARGET, TYPE, CONFIRM, TIME_STAMP, KEY_CODE, TOUCHMOVE, DATE, SET_TIMEOUT, COMPILE_MODE, CATCHMOVE, CATCH_VIEW, COMMENT, ON_LOAD, ON_READY, ON_SHOW, ON_HIDE, OPTIONS, EXTERNAL_CLASSES, EVENT_CALLBACK_RESULT, BEHAVIORS, A, CONTEXT_ACTIONS, Current, getCurrentInstance, eventSource, createComponentConfig, createPageConfig, createRecursiveComponentConfig, getOnHideEventKey, getOnReadyEventKey, getOnShowEventKey, getPageInstance, getPath, injectPageInstance, removePageInstance, safeExecute, stringify, EventsType, eventCenter, Events, hydrate, nextTick, options, perf, incrementId, isElement, isText, isComment, isHasExtractProp, isParentBinded, shortcutAttr, customWrapperCache, extend, getComponentsAlias, convertNumber2PX, throttle, debounce, addLeadingSlash, hasBasename, stripBasename, stripTrailing, stripSuffix, getHomePage, getCurrentPage, Instance, PageProps, ReactPageComponent, ReactPageInstance, ReactAppInstance, PageLifeCycle, PageInstance, AppInstance, Attributes, EventOptions, MpEvent, EventListenerOptions, AddEventListenerOptions, EventHandler, MpInstance, MiniElementData, MiniTextData, MiniData, HydratedData, UpdatePayloadValue, DataTree, UpdatePayload, Options$1 as Options, TFunc, PageConfig, handlePolyfill };
|
package/dist/index.cjs.js
CHANGED
|
@@ -219,6 +219,16 @@ function throttle(fn, threshold = 250, scope) {
|
|
|
219
219
|
}
|
|
220
220
|
};
|
|
221
221
|
}
|
|
222
|
+
function debounce(fn, ms = 250, scope) {
|
|
223
|
+
let timer;
|
|
224
|
+
return function (...args) {
|
|
225
|
+
const context = scope || this;
|
|
226
|
+
clearTimeout(timer);
|
|
227
|
+
timer = setTimeout(function () {
|
|
228
|
+
fn.apply(context, args);
|
|
229
|
+
}, ms);
|
|
230
|
+
};
|
|
231
|
+
}
|
|
222
232
|
|
|
223
233
|
const eventCenter = shared.hooks.call('getEventCenter', shared.Events);
|
|
224
234
|
|
|
@@ -418,11 +428,19 @@ const URLSearchParams = process.env.TARO_PLATFORM === 'web' ? env.window.URLSear
|
|
|
418
428
|
for (let pairs = query.split('&'), i = 0, length = pairs.length; i < length; i++) {
|
|
419
429
|
const value = pairs[i];
|
|
420
430
|
const index = value.indexOf('=');
|
|
421
|
-
|
|
422
|
-
|
|
431
|
+
// 针对不规范的 url 参数做容错处理,如:word=你%好
|
|
432
|
+
try {
|
|
433
|
+
if (index > -1) {
|
|
434
|
+
appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1)));
|
|
435
|
+
}
|
|
436
|
+
else if (value.length) {
|
|
437
|
+
appendTo(dict, decode(value), '');
|
|
438
|
+
}
|
|
423
439
|
}
|
|
424
|
-
|
|
425
|
-
|
|
440
|
+
catch (err) {
|
|
441
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
442
|
+
console.warn(`[Taro warn] URL 参数 ${value} decode 异常`);
|
|
443
|
+
}
|
|
426
444
|
}
|
|
427
445
|
}
|
|
428
446
|
}
|
|
@@ -974,12 +992,12 @@ exports.now = void 0;
|
|
|
974
992
|
let lastTime = 0;
|
|
975
993
|
// https://gist.github.com/paulirish/1579671
|
|
976
994
|
// https://gist.github.com/jalbam/5fe05443270fa6d8136238ec72accbc0
|
|
977
|
-
const _raf =
|
|
995
|
+
const _raf = process.env.TARO_PLATFORM === 'web' ? requestAnimationFrame : function (callback) {
|
|
978
996
|
const _now = exports.now();
|
|
979
997
|
const nextTime = Math.max(lastTime + 16, _now); // First time will execute it immediately but barely noticeable and performance is gained.
|
|
980
998
|
return setTimeout(function () { callback(lastTime = nextTime); }, nextTime - _now);
|
|
981
999
|
};
|
|
982
|
-
const _caf =
|
|
1000
|
+
const _caf = process.env.TARO_PLATFORM === 'web'
|
|
983
1001
|
? cancelAnimationFrame
|
|
984
1002
|
: function (seed) {
|
|
985
1003
|
// fix https://github.com/NervJS/taro/issues/7749
|
|
@@ -1299,6 +1317,7 @@ function hydrate(node) {
|
|
|
1299
1317
|
// 初始化 SPECIAL_NODES
|
|
1300
1318
|
SPECIAL_NODES || (SPECIAL_NODES = shared.hooks.call('getSpecialNodes'));
|
|
1301
1319
|
const nodeName = node.nodeName;
|
|
1320
|
+
let compileModeName = null;
|
|
1302
1321
|
if (isText(node)) {
|
|
1303
1322
|
return {
|
|
1304
1323
|
sid: node.sid,
|
|
@@ -1330,11 +1349,14 @@ function hydrate(node) {
|
|
|
1330
1349
|
propInCamelCase !== COMPILE_MODE) {
|
|
1331
1350
|
data[propInCamelCase] = props[prop];
|
|
1332
1351
|
}
|
|
1333
|
-
if (
|
|
1352
|
+
if (process.env.TARO_ENV !== 'swan' &&
|
|
1353
|
+
nodeName === VIEW &&
|
|
1354
|
+
propInCamelCase === CATCHMOVE &&
|
|
1355
|
+
props[prop] !== false) {
|
|
1334
1356
|
data["nn" /* Shortcuts.NodeName */] = CATCH_VIEW;
|
|
1335
1357
|
}
|
|
1336
1358
|
if (propInCamelCase === COMPILE_MODE) {
|
|
1337
|
-
|
|
1359
|
+
compileModeName = props[prop];
|
|
1338
1360
|
}
|
|
1339
1361
|
}
|
|
1340
1362
|
// Children
|
|
@@ -1358,6 +1380,9 @@ function hydrate(node) {
|
|
|
1358
1380
|
}
|
|
1359
1381
|
}
|
|
1360
1382
|
}
|
|
1383
|
+
if (compileModeName !== null) {
|
|
1384
|
+
data["nn" /* Shortcuts.NodeName */] = compileModeName;
|
|
1385
|
+
}
|
|
1361
1386
|
const resData = shared.hooks.call('transferHydrateData', data, node, componentAlias);
|
|
1362
1387
|
return resData || data;
|
|
1363
1388
|
}
|
|
@@ -1629,7 +1654,7 @@ class TaroNode extends TaroEventTarget {
|
|
|
1629
1654
|
: [],
|
|
1630
1655
|
nextSibling: isReplace
|
|
1631
1656
|
? refChild.nextSibling /** replaceChild */
|
|
1632
|
-
: (refChild || null),
|
|
1657
|
+
: (refChild || null), /** insertBefore & appendChild */
|
|
1633
1658
|
previousSibling: newChild.previousSibling
|
|
1634
1659
|
});
|
|
1635
1660
|
return newChild;
|
|
@@ -2953,7 +2978,7 @@ function makeMap(str, expectsLowerCase) {
|
|
|
2953
2978
|
for (let i = 0; i < list.length; i++) {
|
|
2954
2979
|
map[list[i]] = true;
|
|
2955
2980
|
}
|
|
2956
|
-
return
|
|
2981
|
+
return val => !!map[val.toLowerCase()] ;
|
|
2957
2982
|
}
|
|
2958
2983
|
const specialMiniElements = {
|
|
2959
2984
|
img: 'image',
|
|
@@ -2963,11 +2988,11 @@ const internalCompsList = Object.keys(shared.internalComponents)
|
|
|
2963
2988
|
.map(i => i.toLowerCase())
|
|
2964
2989
|
.join(',');
|
|
2965
2990
|
// https://developers.weixin.qq.com/miniprogram/dev/component
|
|
2966
|
-
const isMiniElements = makeMap(internalCompsList
|
|
2991
|
+
const isMiniElements = makeMap(internalCompsList);
|
|
2967
2992
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
|
|
2968
|
-
const isInlineElements = makeMap('a,i,abbr,iframe,select,acronym,slot,small,span,bdi,kbd,strong,big,map,sub,sup,br,mark,mark,meter,template,canvas,textarea,cite,object,time,code,output,u,data,picture,tt,datalist,var,dfn,del,q,em,s,embed,samp,b'
|
|
2993
|
+
const isInlineElements = makeMap('a,i,abbr,iframe,select,acronym,slot,small,span,bdi,kbd,strong,big,map,sub,sup,br,mark,mark,meter,template,canvas,textarea,cite,object,time,code,output,u,data,picture,tt,datalist,var,dfn,del,q,em,s,embed,samp,b');
|
|
2969
2994
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
|
|
2970
|
-
const isBlockElements = makeMap('address,fieldset,li,article,figcaption,main,aside,figure,nav,blockquote,footer,ol,details,form,p,dialog,h1,h2,h3,h4,h5,h6,pre,dd,header,section,div,hgroup,table,dl,hr,ul,dt'
|
|
2995
|
+
const isBlockElements = makeMap('address,fieldset,li,article,figcaption,main,aside,figure,nav,blockquote,footer,ol,details,form,p,dialog,h1,h2,h3,h4,h5,h6,pre,dd,header,section,div,hgroup,table,dl,hr,ul,dt');
|
|
2971
2996
|
|
|
2972
2997
|
const closingTagAncestorBreakers = {
|
|
2973
2998
|
li: ['ul', 'ol', 'menu'],
|
|
@@ -3264,6 +3289,7 @@ function cloneNode(isDeep = false) {
|
|
|
3264
3289
|
}
|
|
3265
3290
|
for (const key in this) {
|
|
3266
3291
|
const value = this[key];
|
|
3292
|
+
// eslint-disable-next-line valid-typeof
|
|
3267
3293
|
if ([PROPS, DATASET].includes(key) && typeof value === OBJECT) {
|
|
3268
3294
|
newNode[key] = Object.assign({}, value);
|
|
3269
3295
|
}
|
|
@@ -3292,9 +3318,7 @@ function contains(node) {
|
|
|
3292
3318
|
return isContains;
|
|
3293
3319
|
}
|
|
3294
3320
|
|
|
3295
|
-
|
|
3296
|
-
const isHarmony = process.env.TARO_PLATFORM === 'harmony' || process.env.TARO_ENV === 'harmony';
|
|
3297
|
-
if (!isWeb && !isHarmony) {
|
|
3321
|
+
if (process.env.TARO_PLATFORM !== 'web' && !(process.env.TARO_PLATFORM === 'harmony' || process.env.TARO_ENV === 'harmony')) {
|
|
3298
3322
|
if (ENABLE_INNER_HTML) {
|
|
3299
3323
|
TaroNode.extend('innerHTML', {
|
|
3300
3324
|
set(html) {
|
|
@@ -3352,14 +3376,15 @@ class TaroEvent {
|
|
|
3352
3376
|
this.defaultPrevented = true;
|
|
3353
3377
|
}
|
|
3354
3378
|
get target() {
|
|
3355
|
-
var _a, _b, _c, _d;
|
|
3379
|
+
var _a, _b, _c, _d, _e;
|
|
3356
3380
|
const cacheTarget = this.cacheTarget;
|
|
3357
3381
|
if (!cacheTarget) {
|
|
3358
3382
|
const target = Object.create(((_a = this.mpEvent) === null || _a === void 0 ? void 0 : _a.target) || null);
|
|
3383
|
+
const currentEle = env.document.getElementById(((_b = target.dataset) === null || _b === void 0 ? void 0 : _b.sid) || target.id || null);
|
|
3359
3384
|
// Note:优先判断冒泡场景alipay的targetDataset的sid, 不然冒泡场景target属性吐出不对,其余拿取当前绑定id
|
|
3360
|
-
const element = env.document.getElementById(((
|
|
3361
|
-
target.dataset = element !== null ? element.dataset : shared.EMPTY_OBJ;
|
|
3362
|
-
for (const key in (
|
|
3385
|
+
const element = env.document.getElementById(((_c = target.targetDataset) === null || _c === void 0 ? void 0 : _c.sid) || ((_d = target.dataset) === null || _d === void 0 ? void 0 : _d.sid) || target.id || null);
|
|
3386
|
+
target.dataset = Object.assign(Object.assign({}, (currentEle !== null ? currentEle.dataset : shared.EMPTY_OBJ)), (element !== null ? element.dataset : shared.EMPTY_OBJ));
|
|
3387
|
+
for (const key in (_e = this.mpEvent) === null || _e === void 0 ? void 0 : _e.detail) {
|
|
3363
3388
|
target[key] = this.mpEvent.detail[key];
|
|
3364
3389
|
}
|
|
3365
3390
|
this.cacheTarget = target;
|
|
@@ -3495,7 +3520,7 @@ class FormElement extends TaroElement {
|
|
|
3495
3520
|
else if (event.type === INPUT) {
|
|
3496
3521
|
// Web 规范中表单组件的 value 应该跟着输入改变
|
|
3497
3522
|
// 只是改 this.props.value 的话不会进行 setData,因此这里修改 this.value。
|
|
3498
|
-
// 只测试了 React、
|
|
3523
|
+
// 只测试了 React、Vue3 input 组件的 onInput 事件,onChange 事件不确定有没有副作用,所以暂不修改。
|
|
3499
3524
|
this.value = val;
|
|
3500
3525
|
}
|
|
3501
3526
|
}
|
|
@@ -3503,8 +3528,10 @@ class FormElement extends TaroElement {
|
|
|
3503
3528
|
}
|
|
3504
3529
|
}
|
|
3505
3530
|
|
|
3531
|
+
var _Performance_instances, _Performance_parseTime;
|
|
3506
3532
|
class Performance {
|
|
3507
3533
|
constructor() {
|
|
3534
|
+
_Performance_instances.add(this);
|
|
3508
3535
|
this.recorder = new Map();
|
|
3509
3536
|
}
|
|
3510
3537
|
start(id) {
|
|
@@ -3513,18 +3540,32 @@ class Performance {
|
|
|
3513
3540
|
}
|
|
3514
3541
|
this.recorder.set(id, Date.now());
|
|
3515
3542
|
}
|
|
3516
|
-
stop(id) {
|
|
3543
|
+
stop(id, now = Date.now()) {
|
|
3517
3544
|
if (!options.debug) {
|
|
3518
3545
|
return;
|
|
3519
3546
|
}
|
|
3520
|
-
const now = Date.now();
|
|
3521
3547
|
const prev = this.recorder.get(id);
|
|
3548
|
+
if (!(prev >= 0))
|
|
3549
|
+
return;
|
|
3522
3550
|
this.recorder.delete(id);
|
|
3523
3551
|
const time = now - prev;
|
|
3524
3552
|
// eslint-disable-next-line no-console
|
|
3525
|
-
console.log(`${id} 时长: ${time}ms`);
|
|
3553
|
+
console.log(`${id} 时长: ${time}ms 开始时间:${tslib.__classPrivateFieldGet(this, _Performance_instances, "m", _Performance_parseTime).call(this, prev)} 结束时间:${tslib.__classPrivateFieldGet(this, _Performance_instances, "m", _Performance_parseTime).call(this, now)}`);
|
|
3554
|
+
}
|
|
3555
|
+
delayStop(id, delay = 500) {
|
|
3556
|
+
if (!options.debug) {
|
|
3557
|
+
return;
|
|
3558
|
+
}
|
|
3559
|
+
return debounce((now = Date.now(), cb) => {
|
|
3560
|
+
this.stop(id, now);
|
|
3561
|
+
cb === null || cb === void 0 ? void 0 : cb();
|
|
3562
|
+
}, delay);
|
|
3526
3563
|
}
|
|
3527
3564
|
}
|
|
3565
|
+
_Performance_instances = new WeakSet(), _Performance_parseTime = function _Performance_parseTime(time) {
|
|
3566
|
+
const d = new Date(time);
|
|
3567
|
+
return `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}.${`${d.getMilliseconds()}`.padStart(3, '0')}`;
|
|
3568
|
+
};
|
|
3528
3569
|
const perf = new Performance();
|
|
3529
3570
|
|
|
3530
3571
|
function findCustomWrapper(root, dataPathArr) {
|
|
@@ -4069,6 +4110,11 @@ function createPageConfig(component, pageName, data, pageConfig) {
|
|
|
4069
4110
|
eventCenter.trigger(getOnHideEventKey(id));
|
|
4070
4111
|
}
|
|
4071
4112
|
};
|
|
4113
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
4114
|
+
config.getOpenerEventChannel = () => {
|
|
4115
|
+
return shared.EventChannel.pageChannel;
|
|
4116
|
+
};
|
|
4117
|
+
}
|
|
4072
4118
|
LIFECYCLES.forEach((lifecycle) => {
|
|
4073
4119
|
let isDefer = false;
|
|
4074
4120
|
lifecycle = lifecycle.replace(/^defer:/, () => {
|
|
@@ -4763,7 +4809,7 @@ function handleIntersectionObserverObjectPolyfill() {
|
|
|
4763
4809
|
*/
|
|
4764
4810
|
function addEvent(node, event, fn, opt_useCapture) {
|
|
4765
4811
|
if (shared.isFunction(node.addEventListener)) {
|
|
4766
|
-
node.addEventListener(event, fn, opt_useCapture
|
|
4812
|
+
node.addEventListener(event, fn, opt_useCapture );
|
|
4767
4813
|
}
|
|
4768
4814
|
else if (shared.isFunction(node.attachEvent)) {
|
|
4769
4815
|
node.attachEvent('on' + event, fn);
|
|
@@ -4779,7 +4825,7 @@ function handleIntersectionObserverObjectPolyfill() {
|
|
|
4779
4825
|
*/
|
|
4780
4826
|
function removeEvent(node, event, fn, opt_useCapture) {
|
|
4781
4827
|
if (shared.isFunction(node.removeEventListener)) {
|
|
4782
|
-
node.removeEventListener(event, fn, opt_useCapture
|
|
4828
|
+
node.removeEventListener(event, fn, opt_useCapture );
|
|
4783
4829
|
}
|
|
4784
4830
|
else if (shared.isFunction(node.detatchEvent)) {
|
|
4785
4831
|
node.detatchEvent('on' + event, fn);
|
|
@@ -5016,11 +5062,11 @@ if (process.env.SUPPORT_TARO_POLYFILL !== 'disabled' && process.env.TARO_PLATFOR
|
|
|
5016
5062
|
handlePolyfill();
|
|
5017
5063
|
}
|
|
5018
5064
|
|
|
5019
|
-
Object.defineProperty(exports,
|
|
5065
|
+
Object.defineProperty(exports, "Events", {
|
|
5020
5066
|
enumerable: true,
|
|
5021
5067
|
get: function () { return shared.Events; }
|
|
5022
5068
|
});
|
|
5023
|
-
Object.defineProperty(exports,
|
|
5069
|
+
Object.defineProperty(exports, "hooks", {
|
|
5024
5070
|
enumerable: true,
|
|
5025
5071
|
get: function () { return shared.hooks; }
|
|
5026
5072
|
});
|
|
@@ -5096,6 +5142,7 @@ exports.createEvent = createEvent;
|
|
|
5096
5142
|
exports.createPageConfig = createPageConfig;
|
|
5097
5143
|
exports.createRecursiveComponentConfig = createRecursiveComponentConfig;
|
|
5098
5144
|
exports.customWrapperCache = customWrapperCache;
|
|
5145
|
+
exports.debounce = debounce;
|
|
5099
5146
|
exports.document = document$1;
|
|
5100
5147
|
exports.env = env;
|
|
5101
5148
|
exports.eventCenter = eventCenter;
|
|
@@ -5128,6 +5175,7 @@ exports.navigator = nav;
|
|
|
5128
5175
|
exports.nextTick = nextTick;
|
|
5129
5176
|
exports.options = options;
|
|
5130
5177
|
exports.parseUrl = parseUrl;
|
|
5178
|
+
exports.perf = perf;
|
|
5131
5179
|
exports.removePageInstance = removePageInstance;
|
|
5132
5180
|
exports.requestAnimationFrame = _raf;
|
|
5133
5181
|
exports.safeExecute = safeExecute;
|