@tarojs/runtime 4.0.0 → 4.0.1-alpha.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/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import env from "./env.js";
2
2
  export { hooks } from '@tarojs/shared';
3
- export { document } from "./bom/document.js";
4
- export { getComputedStyle } from "./bom/getComputedStyle.js";
3
+ export { taroDocumentProvider as document } from "./bom/document.js";
4
+ export { taroGetComputedStyleProvider as getComputedStyle } from "./bom/getComputedStyle.js";
5
5
  export { History } from "./bom/history.js";
6
6
  export { Location } from "./bom/location.js";
7
7
  export { nav as navigator } from "./bom/navigator.js";
8
8
  export { caf as cancelAnimationFrame, now, raf as requestAnimationFrame } from "./bom/raf.js";
9
- export { parseUrl, URL } from "./bom/URL.js";
9
+ export { parseUrl, TaroURLProvider as URL } from "./bom/URL.js";
10
10
  export { URLSearchParams } from "./bom/URLSearchParams.js";
11
- export { history, location, window } from "./bom/window.js";
11
+ export { taroHistoryProvider as history, taroLocationProvider as location, taroWindowProvider as window } from "./bom/window.js";
12
12
  export { TaroElement } from "./dom/element.js";
13
13
  export { createEvent, eventHandler, TaroEvent } from "./dom/event.js";
14
14
  export { FormElement } from "./dom/form.js";
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import './dom-external/index.js';
2
2
  export { default as env } from './env.js';
3
3
  export { Events, hooks } from '@tarojs/shared';
4
- export { document } from './bom/document.js';
5
- export { getComputedStyle } from './bom/getComputedStyle.js';
4
+ export { taroDocumentProvider as document } from './bom/document.js';
5
+ export { taroGetComputedStyleProvider as getComputedStyle } from './bom/getComputedStyle.js';
6
6
  export { History } from './bom/history.js';
7
7
  export { Location } from './bom/location.js';
8
8
  export { nav as navigator } from './bom/navigator.js';
9
9
  export { caf as cancelAnimationFrame, now, raf as requestAnimationFrame } from './bom/raf.js';
10
- export { URL, parseUrl } from './bom/URL.js';
10
+ export { TaroURLProvider as URL, parseUrl } from './bom/URL.js';
11
11
  export { URLSearchParams } from './bom/URLSearchParams.js';
12
- export { history, location, window } from './bom/window.js';
12
+ export { taroHistoryProvider as history, taroLocationProvider as location, taroWindowProvider as window } from './bom/window.js';
13
13
  export { TaroElement } from './dom/element.js';
14
14
  export { TaroEvent, createEvent, eventHandler } from './dom/event.js';
15
15
  export { FormElement } from './dom/form.js';
@@ -330,9 +330,11 @@ interface Env {
330
330
  document: TaroDocument;
331
331
  }
332
332
  declare const env: Env;
333
- declare const document: TaroDocument;
333
+ // Note: 小程序端 vite 打包成 commonjs,const document = xxx 会报错,所以把 document 改为 taroDocumentProvider
334
+ declare const taroDocumentProvider: TaroDocument;
334
335
  type TGetComputedStyle = typeof window.getComputedStyle | ((el: TaroElement) => Style);
335
- declare const getComputedStyle: TGetComputedStyle;
336
+ // Note: 小程序端 vite 打包成 commonjs,const getComputedStyle = xxx 会报错,所以把 GetComputedStyle 改为 taroGetComputedStyleProvider
337
+ declare const taroGetComputedStyleProvider: TGetComputedStyle;
336
338
  declare const eventCenter: Events;
337
339
  type EventsType = typeof Events;
338
340
  /**
@@ -462,7 +464,8 @@ declare class TaroURL {
462
464
  href: string;
463
465
  };
464
466
  }
465
- declare const URL: typeof TaroURL;
467
+ // Note: 小程序端 vite 打包成 commonjs,const URL = xxx 会报错,所以把 URL 改为 TaroURLProvider
468
+ declare const TaroURLProvider: typeof TaroURL;
466
469
  declare function parseUrl(url?: string): {
467
470
  href: string;
468
471
  origin: string;
@@ -492,9 +495,10 @@ declare class TaroWindow extends Events {
492
495
  setTimeout(...args: Parameters<typeof setTimeout>): NodeJS.Timeout;
493
496
  clearTimeout(...args: Parameters<typeof clearTimeout>): void;
494
497
  }
495
- declare const window: TaroWindow;
496
- declare const location: TaroLocation;
497
- declare const history: TaroHistory;
498
+ // Note: 小程序端 vite 打包成 commonjs,const window = xxx 会报错,所以把 window 改为 taroWindowProvider,location 和 history 同理
499
+ declare const taroWindowProvider: TaroWindow;
500
+ declare const taroLocationProvider: TaroLocation;
501
+ declare const taroHistoryProvider: TaroHistory;
498
502
  // for Vue3
499
503
  declare class SVGElement extends TaroElement {
500
504
  }
@@ -803,4 +807,4 @@ declare const getHomePage: (path?: string, basename?: string, customRoutes?: Rec
803
807
  declare const getCurrentPage: (routerMode?: string, basename?: string) => string;
804
808
  declare function handlePolyfill(): void;
805
809
  export { hooks } from '@tarojs/shared';
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 };
810
+ export { taroDocumentProvider as document, taroGetComputedStyleProvider as getComputedStyle, History, Location, nav as navigator, _caf as cancelAnimationFrame, now, _raf as requestAnimationFrame, parseUrl, TaroURLProvider as URL, URLSearchParams, taroHistoryProvider as history, taroLocationProvider as location, taroWindowProvider as 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 };
@@ -236,7 +236,8 @@ const env = {
236
236
  document: process.env.TARO_PLATFORM === 'web' ? document : EMPTY_OBJ
237
237
  };
238
238
 
239
- const getComputedStyle = process.env.TARO_PLATFORM === 'web' ? env.window.getComputedStyle : function (element) {
239
+ // Note: 小程序端 vite 打包成 commonjs,const getComputedStyle = xxx 会报错,所以把 GetComputedStyle 改为 taroGetComputedStyleProvider
240
+ const taroGetComputedStyleProvider = process.env.TARO_PLATFORM === 'web' ? env.window.getComputedStyle : function (element) {
240
241
  return element.style;
241
242
  };
242
243
 
@@ -658,7 +659,8 @@ class TaroURL {
658
659
  }
659
660
  }
660
661
  _TaroURL_hash = new WeakMap(), _TaroURL_hostname = new WeakMap(), _TaroURL_pathname = new WeakMap(), _TaroURL_port = new WeakMap(), _TaroURL_protocol = new WeakMap(), _TaroURL_search = new WeakMap();
661
- const URL = process.env.TARO_PLATFORM === 'web' ? env.window.URL : TaroURL;
662
+ // Note: 小程序端 vite 打包成 commonjs,const URL = xxx 会报错,所以把 URL 改为 TaroURLProvider
663
+ const TaroURLProvider = process.env.TARO_PLATFORM === 'web' ? env.window.URL : TaroURL;
662
664
  function parseUrl(url = '') {
663
665
  const result = {
664
666
  href: '',
@@ -731,7 +733,7 @@ class TaroLocation extends Events {
731
733
  super();
732
734
  _TaroLocation_instances.add(this);
733
735
  /* private property */
734
- _TaroLocation_url.set(this, new URL(INIT_URL));
736
+ _TaroLocation_url.set(this, new TaroURLProvider(INIT_URL));
735
737
  _TaroLocation_noCheckUrl.set(this, false);
736
738
  _TaroLocation_window.set(this, void 0);
737
739
  __classPrivateFieldSet(this, _TaroLocation_window, options.window, "f");
@@ -908,7 +910,7 @@ _TaroLocation_url = new WeakMap(), _TaroLocation_noCheckUrl = new WeakMap(), _Ta
908
910
  });
909
911
  const searchStr = searchArr.length > 0 ? '?' + searchArr.join('&') : '';
910
912
  const url = `${INIT_URL}${path.startsWith('/') ? path : '/' + path}${searchStr}`;
911
- __classPrivateFieldSet(this, _TaroLocation_url, new URL(url), "f");
913
+ __classPrivateFieldSet(this, _TaroLocation_url, new TaroURLProvider(url), "f");
912
914
  this.trigger('__reset_history__', this.href);
913
915
  }
914
916
  }, _TaroLocation_getPreValue = function _TaroLocation_getPreValue() {
@@ -1009,7 +1011,7 @@ class TaroWindow extends Events {
1009
1011
  this.navigator = nav;
1010
1012
  this.requestAnimationFrame = _raf;
1011
1013
  this.cancelAnimationFrame = _caf;
1012
- this.getComputedStyle = getComputedStyle;
1014
+ this.getComputedStyle = taroGetComputedStyleProvider;
1013
1015
  const globalProperties = [
1014
1016
  ...Object.getOwnPropertyNames(global || {}),
1015
1017
  ...Object.getOwnPropertySymbols(global || {})
@@ -1079,9 +1081,10 @@ class TaroWindow extends Events {
1079
1081
  return clearTimeout(...args);
1080
1082
  }
1081
1083
  }
1082
- const window$1 = process.env.TARO_PLATFORM === 'web' ? env.window : (env.window = new TaroWindow());
1083
- const location = window$1.location;
1084
- const history = window$1.history;
1084
+ // Note: 小程序端 vite 打包成 commonjs,const window = xxx 会报错,所以把 window 改为 taroWindowProvider,location history 同理
1085
+ const taroWindowProvider = process.env.TARO_PLATFORM === 'web' ? env.window : (env.window = new TaroWindow());
1086
+ const taroLocationProvider = taroWindowProvider.location;
1087
+ const taroHistoryProvider = taroWindowProvider.history;
1085
1088
 
1086
1089
  // export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
1087
1090
  // export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')
@@ -1098,8 +1101,8 @@ const getHomePage = (path = '', basename = '', customRoutes = {}, entryPagePath
1098
1101
  };
1099
1102
  const getCurrentPage = (routerMode = 'hash', basename = '/') => {
1100
1103
  const pagePath = routerMode === 'hash'
1101
- ? location.hash.slice(1).split('?')[0]
1102
- : location.pathname;
1104
+ ? taroLocationProvider.hash.slice(1).split('?')[0]
1105
+ : taroLocationProvider.pathname;
1103
1106
  return addLeadingSlash(stripBasename(pagePath, basename));
1104
1107
  };
1105
1108
 
@@ -3920,7 +3923,8 @@ function createDocument() {
3920
3923
  doc.body = body;
3921
3924
  return doc;
3922
3925
  }
3923
- const document$1 = process.env.TARO_PLATFORM === 'web' ? env.document : (env.document = createDocument());
3926
+ // Note: 小程序端 vite 打包成 commonjs,const document = xxx 会报错,所以把 document 改为 taroDocumentProvider
3927
+ const taroDocumentProvider = process.env.TARO_PLATFORM === 'web' ? env.document : (env.document = createDocument());
3924
3928
 
3925
3929
  // for Vue3
3926
3930
  class SVGElement extends TaroElement {
@@ -4023,7 +4027,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
4023
4027
  setCurrentRouter(this);
4024
4028
  // 初始化当前页面的上下文信息
4025
4029
  if (process.env.TARO_PLATFORM !== 'web') {
4026
- window$1.trigger(CONTEXT_ACTIONS.INIT, $taroPath);
4030
+ taroWindowProvider.trigger(CONTEXT_ACTIONS.INIT, $taroPath);
4027
4031
  }
4028
4032
  const mount = () => {
4029
4033
  Current.app.mount(component, $taroPath, () => {
@@ -4051,7 +4055,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
4051
4055
  const $taroPath = this.$taroPath;
4052
4056
  // 销毁当前页面的上下文信息
4053
4057
  if (process.env.TARO_PLATFORM !== 'web') {
4054
- window$1.trigger(CONTEXT_ACTIONS.DESTORY, $taroPath);
4058
+ taroWindowProvider.trigger(CONTEXT_ACTIONS.DESTORY, $taroPath);
4055
4059
  }
4056
4060
  // 触发onUnload生命周期
4057
4061
  safeExecute($taroPath, ONUNLOAD);
@@ -4085,7 +4089,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
4085
4089
  setCurrentRouter(this);
4086
4090
  // 恢复上下文信息
4087
4091
  if (process.env.TARO_PLATFORM !== 'web') {
4088
- window$1.trigger(CONTEXT_ACTIONS.RECOVER, this.$taroPath);
4092
+ taroWindowProvider.trigger(CONTEXT_ACTIONS.RECOVER, this.$taroPath);
4089
4093
  }
4090
4094
  // 触发生命周期
4091
4095
  safeExecute(this.$taroPath, ON_SHOW, options);
@@ -4096,7 +4100,7 @@ function createPageConfig(component, pageName, data, pageConfig) {
4096
4100
  [ONHIDE]() {
4097
4101
  // 缓存当前页面上下文信息
4098
4102
  if (process.env.TARO_PLATFORM !== 'web') {
4099
- window$1.trigger(CONTEXT_ACTIONS.RESTORE, this.$taroPath);
4103
+ taroWindowProvider.trigger(CONTEXT_ACTIONS.RESTORE, this.$taroPath);
4100
4104
  }
4101
4105
  // 设置 Current 的 page 和 router
4102
4106
  if (Current.page === this) {
@@ -5061,5 +5065,5 @@ if (process.env.SUPPORT_TARO_POLYFILL !== 'disabled' && process.env.TARO_PLATFOR
5061
5065
  handlePolyfill();
5062
5066
  }
5063
5067
 
5064
- export { A, APP, BEHAVIORS, BODY, CATCHMOVE, CATCH_VIEW, CHANGE, CLASS, COMMENT, COMPILE_MODE, CONFIRM, CONTAINER, CONTEXT_ACTIONS, CURRENT_TARGET, CUSTOM_WRAPPER, Current, DATASET, DATE, DOCUMENT_ELEMENT_NAME, DOCUMENT_FRAGMENT, EVENT_CALLBACK_RESULT, EXTERNAL_CLASSES, FOCUS, FormElement, HEAD, HOOKS_APP_ID, HTML, History, ID, INPUT, KEY_CODE, Location, MutationObserver$1 as MutationObserver, OBJECT, ON_HIDE, ON_LOAD, ON_READY, ON_SHOW, OPTIONS, PAGE_INIT, PROPERTY_THRESHOLD, PROPS, PURE_VIEW, ROOT_STR, SET_DATA, SET_TIMEOUT, STATIC_VIEW, STYLE, SVGElement, Style, TARGET, TARO_RUNTIME, TIME_STAMP, TOUCHMOVE, TYPE, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, UID, URL, URLSearchParams, VALUE, VIEW, addLeadingSlash, _caf as cancelAnimationFrame, convertNumber2PX, createComponentConfig, createEvent, createPageConfig, createRecursiveComponentConfig, customWrapperCache, debounce, document$1 as document, env, eventCenter, eventHandler, eventSource, extend, getComponentsAlias, getComputedStyle, getCurrentInstance, getCurrentPage, getHomePage, getOnHideEventKey, getOnReadyEventKey, getOnShowEventKey, getPageInstance, getPath, handlePolyfill, hasBasename, history, hydrate, incrementId, injectPageInstance, isComment, isElement, isHasExtractProp, isParentBinded, isText, location, nav as navigator, nextTick, now, options, parseUrl, perf, removePageInstance, _raf as requestAnimationFrame, safeExecute, shortcutAttr, stringify, stripBasename, stripSuffix, stripTrailing, throttle, window$1 as window };
5068
+ export { A, APP, BEHAVIORS, BODY, CATCHMOVE, CATCH_VIEW, CHANGE, CLASS, COMMENT, COMPILE_MODE, CONFIRM, CONTAINER, CONTEXT_ACTIONS, CURRENT_TARGET, CUSTOM_WRAPPER, Current, DATASET, DATE, DOCUMENT_ELEMENT_NAME, DOCUMENT_FRAGMENT, EVENT_CALLBACK_RESULT, EXTERNAL_CLASSES, FOCUS, FormElement, HEAD, HOOKS_APP_ID, HTML, History, ID, INPUT, KEY_CODE, Location, MutationObserver$1 as MutationObserver, OBJECT, ON_HIDE, ON_LOAD, ON_READY, ON_SHOW, OPTIONS, PAGE_INIT, PROPERTY_THRESHOLD, PROPS, PURE_VIEW, ROOT_STR, SET_DATA, SET_TIMEOUT, STATIC_VIEW, STYLE, SVGElement, Style, TARGET, TARO_RUNTIME, TIME_STAMP, TOUCHMOVE, TYPE, TaroElement, TaroEvent, TaroNode, TaroRootElement, TaroText, UID, TaroURLProvider as URL, URLSearchParams, VALUE, VIEW, addLeadingSlash, _caf as cancelAnimationFrame, convertNumber2PX, createComponentConfig, createEvent, createPageConfig, createRecursiveComponentConfig, customWrapperCache, debounce, taroDocumentProvider as document, env, eventCenter, eventHandler, eventSource, extend, getComponentsAlias, taroGetComputedStyleProvider as getComputedStyle, getCurrentInstance, getCurrentPage, getHomePage, getOnHideEventKey, getOnReadyEventKey, getOnShowEventKey, getPageInstance, getPath, handlePolyfill, hasBasename, taroHistoryProvider as history, hydrate, incrementId, injectPageInstance, isComment, isElement, isHasExtractProp, isParentBinded, isText, taroLocationProvider as location, nav as navigator, nextTick, now, options, parseUrl, perf, removePageInstance, _raf as requestAnimationFrame, safeExecute, shortcutAttr, stringify, stripBasename, stripSuffix, stripTrailing, throttle, taroWindowProvider as window };
5065
5069
  //# sourceMappingURL=runtime.esm.js.map