@spcsn/taro-runtime 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/LICENSE +174 -0
  2. package/README.md +49 -0
  3. package/dist/bom/URL.d.ts +51 -0
  4. package/dist/bom/URL.js +188 -0
  5. package/dist/bom/URL.js.map +1 -0
  6. package/dist/bom/URLSearchParams.d.ts +1 -0
  7. package/dist/bom/URLSearchParams.js +103 -0
  8. package/dist/bom/URLSearchParams.js.map +1 -0
  9. package/dist/bom/document.d.ts +3 -0
  10. package/dist/bom/document.js +93 -0
  11. package/dist/bom/document.js.map +1 -0
  12. package/dist/bom/getComputedStyle.d.ts +4 -0
  13. package/dist/bom/getComputedStyle.js +9 -0
  14. package/dist/bom/getComputedStyle.js.map +1 -0
  15. package/dist/bom/history.d.ts +30 -0
  16. package/dist/bom/history.js +108 -0
  17. package/dist/bom/history.js.map +1 -0
  18. package/dist/bom/location.d.ts +37 -0
  19. package/dist/bom/location.js +200 -0
  20. package/dist/bom/location.js.map +1 -0
  21. package/dist/bom/navigator.d.ts +1 -0
  22. package/dist/bom/navigator.js +22 -0
  23. package/dist/bom/navigator.js.map +1 -0
  24. package/dist/bom/raf.d.ts +4 -0
  25. package/dist/bom/raf.js +28 -0
  26. package/dist/bom/raf.js.map +1 -0
  27. package/dist/bom/window.d.ts +23 -0
  28. package/dist/bom/window.js +74 -0
  29. package/dist/bom/window.js.map +1 -0
  30. package/dist/constants/index.d.ts +57 -0
  31. package/dist/constants/index.js +63 -0
  32. package/dist/constants/index.js.map +1 -0
  33. package/dist/current.d.ts +19 -0
  34. package/dist/current.js +11 -0
  35. package/dist/current.js.map +1 -0
  36. package/dist/dom/anchor-element.d.ts +13 -0
  37. package/dist/dom/anchor-element.js +42 -0
  38. package/dist/dom/anchor-element.js.map +1 -0
  39. package/dist/dom/class-list.d.ts +16 -0
  40. package/dist/dom/class-list.js +79 -0
  41. package/dist/dom/class-list.js.map +1 -0
  42. package/dist/dom/document.d.ts +21 -0
  43. package/dist/dom/document.js +74 -0
  44. package/dist/dom/document.js.map +1 -0
  45. package/dist/dom/element.d.ts +39 -0
  46. package/dist/dom/element.js +261 -0
  47. package/dist/dom/element.js.map +1 -0
  48. package/dist/dom/event-source.d.ts +7 -0
  49. package/dist/dom/event-source.js +18 -0
  50. package/dist/dom/event-source.js.map +1 -0
  51. package/dist/dom/event-target.d.ts +8 -0
  52. package/dist/dom/event-target.js +72 -0
  53. package/dist/dom/event-target.js.map +1 -0
  54. package/dist/dom/event.d.ts +24 -0
  55. package/dist/dom/event.js +124 -0
  56. package/dist/dom/event.js.map +1 -0
  57. package/dist/dom/form.d.ts +9 -0
  58. package/dist/dom/form.js +30 -0
  59. package/dist/dom/form.js.map +1 -0
  60. package/dist/dom/node.d.ts +76 -0
  61. package/dist/dom/node.js +213 -0
  62. package/dist/dom/node.js.map +1 -0
  63. package/dist/dom/node_types.d.ts +10 -0
  64. package/dist/dom/root.d.ts +16 -0
  65. package/dist/dom/root.js +127 -0
  66. package/dist/dom/root.js.map +1 -0
  67. package/dist/dom/style.d.ts +14 -0
  68. package/dist/dom/style.js +138 -0
  69. package/dist/dom/style.js.map +1 -0
  70. package/dist/dom/style_properties.d.ts +3 -0
  71. package/dist/dom/style_properties.js +374 -0
  72. package/dist/dom/style_properties.js.map +1 -0
  73. package/dist/dom/svg.d.ts +3 -0
  74. package/dist/dom/svg.js +7 -0
  75. package/dist/dom/svg.js.map +1 -0
  76. package/dist/dom/text.d.ts +14 -0
  77. package/dist/dom/text.js +43 -0
  78. package/dist/dom/text.js.map +1 -0
  79. package/dist/dom/transfer.d.ts +7 -0
  80. package/dist/dom/transfer.js +16 -0
  81. package/dist/dom/transfer.js.map +1 -0
  82. package/dist/dom/tree.d.ts +4 -0
  83. package/dist/dom/tree.js +31 -0
  84. package/dist/dom/tree.js.map +1 -0
  85. package/dist/dom-external/element.d.ts +3 -0
  86. package/dist/dom-external/index.d.ts +1 -0
  87. package/dist/dom-external/mutation-observer/implements.d.ts +52 -0
  88. package/dist/dom-external/mutation-observer/implements.js +101 -0
  89. package/dist/dom-external/mutation-observer/implements.js.map +1 -0
  90. package/dist/dom-external/mutation-observer/index.d.ts +13 -0
  91. package/dist/dom-external/mutation-observer/index.js +32 -0
  92. package/dist/dom-external/mutation-observer/index.js.map +1 -0
  93. package/dist/dom-external/mutation-observer/record.d.ts +24 -0
  94. package/dist/dom-external/node.d.ts +5 -0
  95. package/dist/dsl/common.d.ts +14 -0
  96. package/dist/dsl/common.js +278 -0
  97. package/dist/dsl/common.js.map +1 -0
  98. package/dist/dsl/instance.d.ts +92 -0
  99. package/dist/emitter/emitter.d.ts +4 -0
  100. package/dist/emitter/emitter.js +7 -0
  101. package/dist/emitter/emitter.js.map +1 -0
  102. package/dist/env.d.ts +7 -0
  103. package/dist/env.js +10 -0
  104. package/dist/env.js.map +1 -0
  105. package/dist/hydrate.d.ts +10 -0
  106. package/dist/hydrate.js +62 -0
  107. package/dist/hydrate.js.map +1 -0
  108. package/dist/index.cjs.d.ts +35 -0
  109. package/dist/index.cjs.js +3776 -0
  110. package/dist/index.cjs.js.map +1 -0
  111. package/dist/index.d.ts +35 -0
  112. package/dist/index.js +34 -0
  113. package/dist/interface/animate.d.ts +81 -0
  114. package/dist/interface/element.d.ts +4 -0
  115. package/dist/interface/event-target.d.ts +11 -0
  116. package/dist/interface/event.d.ts +15 -0
  117. package/dist/interface/hydrate.d.ts +30 -0
  118. package/dist/interface/index.d.ts +8 -0
  119. package/dist/interface/node.d.ts +7 -0
  120. package/dist/interface/options.d.ts +5 -0
  121. package/dist/interface/utils.d.ts +2 -0
  122. package/dist/next-tick.d.ts +2 -0
  123. package/dist/next-tick.js +35 -0
  124. package/dist/next-tick.js.map +1 -0
  125. package/dist/options.d.ts +2 -0
  126. package/dist/options.js +9 -0
  127. package/dist/options.js.map +1 -0
  128. package/dist/perf.d.ts +9 -0
  129. package/dist/perf.js +36 -0
  130. package/dist/perf.js.map +1 -0
  131. package/dist/polyfill/array.d.ts +2 -0
  132. package/dist/polyfill/array.js +36 -0
  133. package/dist/polyfill/array.js.map +1 -0
  134. package/dist/polyfill/index.d.ts +2 -0
  135. package/dist/polyfill/index.js +20 -0
  136. package/dist/polyfill/index.js.map +1 -0
  137. package/dist/polyfill/intersection-observer.d.ts +1 -0
  138. package/dist/polyfill/intersection-observer.js +494 -0
  139. package/dist/polyfill/intersection-observer.js.map +1 -0
  140. package/dist/polyfill/object.d.ts +3 -0
  141. package/dist/polyfill/object.js +63 -0
  142. package/dist/polyfill/object.js.map +1 -0
  143. package/dist/runtime.esm.d.ts +35 -0
  144. package/dist/runtime.esm.js +3644 -0
  145. package/dist/runtime.esm.js.map +1 -0
  146. package/dist/utils/cache.d.ts +12 -0
  147. package/dist/utils/cache.js +26 -0
  148. package/dist/utils/cache.js.map +1 -0
  149. package/dist/utils/index.d.ts +25 -0
  150. package/dist/utils/index.js +82 -0
  151. package/dist/utils/index.js.map +1 -0
  152. package/dist/utils/lodash.d.ts +2 -0
  153. package/dist/utils/lodash.js +33 -0
  154. package/dist/utils/lodash.js.map +1 -0
  155. package/dist/utils/router.d.ts +7 -0
  156. package/dist/utils/router.js +19 -0
  157. package/dist/utils/router.js.map +1 -0
  158. package/package.json +45 -0
@@ -0,0 +1,93 @@
1
+ import { BODY, CONTAINER, HEAD, HTML } from "../constants/index.js";
2
+ import env from "../env.js";
3
+ import { TaroDocument } from "../dom/document.js";
4
+ import { DEFAULT_COMPONENTS, TT_SPECIFIC_COMPONENTS, isEnableTTDom } from "@spcsn/taro-shared";
5
+ //#region src/bom/document.ts
6
+ function createDocument() {
7
+ /**
8
+ * <document>
9
+ * <html>
10
+ * <head></head>
11
+ * <body>
12
+ * <container>
13
+ * <app id="app" />
14
+ * </container>
15
+ * </body>
16
+ * </html>
17
+ * </document>
18
+ */
19
+ const doc = new TaroDocument();
20
+ const documentCreateElement = doc.createElement.bind(doc);
21
+ const html = documentCreateElement(HTML);
22
+ const head = documentCreateElement(HEAD);
23
+ const body = documentCreateElement(BODY);
24
+ const app = documentCreateElement("app");
25
+ app.id = "app";
26
+ const container = documentCreateElement(CONTAINER);
27
+ doc.appendChild(html);
28
+ html.appendChild(head);
29
+ html.appendChild(body);
30
+ body.appendChild(container);
31
+ container.appendChild(app);
32
+ doc.documentElement = html;
33
+ doc.head = head;
34
+ doc.body = body;
35
+ return doc;
36
+ }
37
+ function createTTDomDocument() {
38
+ const document = tt?.appDocument;
39
+ if (!document) throw new Error("tt.appDocument is not found");
40
+ const html = document.createElement(HTML);
41
+ const head = document.createElement(HEAD);
42
+ const body = document.createElement(BODY);
43
+ const app = document.createElement("app");
44
+ app.id = "app";
45
+ const container = document.createElement(CONTAINER);
46
+ const emptyFunction = () => {};
47
+ document.childNodes.push(html);
48
+ html.childNodes.push(head, body);
49
+ body.childNodes.push(container);
50
+ container.childNodes.push(app);
51
+ document.documentElement = html;
52
+ document.head = head;
53
+ document.body = body;
54
+ document.appElement = app;
55
+ let builtInComponents = tt?.getBuiltInComponents?.();
56
+ if (Array.isArray(builtInComponents)) builtInComponents = new Set(builtInComponents);
57
+ else if (!(builtInComponents instanceof Set)) builtInComponents = new Set([...DEFAULT_COMPONENTS, ...TT_SPECIFIC_COMPONENTS]);
58
+ document.getElementById = function getElementById(id) {
59
+ if (id === "app") return app;
60
+ else return Object.getPrototypeOf(this).getElementById.call(this, id);
61
+ };
62
+ document.getLastPage = function getLastPage() {
63
+ let last;
64
+ for (const v of this._pageDocumentMap.values()) last = v;
65
+ return last;
66
+ };
67
+ document.createElement = function(type, ...args) {
68
+ if (type === "root") return this.getLastPage();
69
+ else {
70
+ const el = builtInComponents.has(type) ? Object.getPrototypeOf(this).createElement.call(this, type, ...args) : Object.getPrototypeOf(this).createNativeComponent.call(this, type, { __tt__inner__options__: { name: type } });
71
+ el.setAttribute("class", "");
72
+ const originalSetAttribute = el.setAttribute.bind(el);
73
+ const originalRemoveAttribute = el.removeAttribute.bind(el);
74
+ el.setAttribute = function(name, value) {
75
+ const result = originalSetAttribute(name, value);
76
+ if (name === "catchMove" && value) el.addEventListener("catchtouchmove", emptyFunction);
77
+ return result;
78
+ };
79
+ el.removeAttribute = function(name) {
80
+ const oldValue = el.getAttribute(name);
81
+ if (name === "catchMove" && oldValue) el.removeEventListener("catchtouchmove", emptyFunction);
82
+ return originalRemoveAttribute(name);
83
+ };
84
+ return el;
85
+ }
86
+ };
87
+ return document;
88
+ }
89
+ const taroDocumentProvider = process.env.TARO_PLATFORM === "web" ? env.document : env.document = isEnableTTDom() ? createTTDomDocument() : createDocument();
90
+ //#endregion
91
+ export { taroDocumentProvider };
92
+
93
+ //# sourceMappingURL=document.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.js","names":[],"sources":["../../src/bom/document.ts"],"sourcesContent":["import { DEFAULT_COMPONENTS, isEnableTTDom, TT_SPECIFIC_COMPONENTS } from '@spcsn/taro-shared';\n\nimport { APP, BODY, CONTAINER, HEAD, HTML } from '../constants';\nimport { TaroDocument } from '../dom/document';\nimport env from '../env';\n\nfunction createDocument(): TaroDocument {\n /**\n * <document>\n * <html>\n * <head></head>\n * <body>\n * <container>\n * <app id=\"app\" />\n * </container>\n * </body>\n * </html>\n * </document>\n */\n const doc = new TaroDocument();\n const documentCreateElement = doc.createElement.bind(doc);\n const html = documentCreateElement(HTML);\n const head = documentCreateElement(HEAD);\n const body = documentCreateElement(BODY);\n const app = documentCreateElement(APP);\n app.id = APP;\n const container = documentCreateElement(CONTAINER);\n\n doc.appendChild(html);\n html.appendChild(head);\n html.appendChild(body);\n body.appendChild(container);\n container.appendChild(app);\n\n doc.documentElement = html;\n doc.head = head;\n doc.body = body;\n\n return doc;\n}\n\ndeclare const tt: any;\n\nexport function createTTDomDocument(): TaroDocument {\n const document = tt?.appDocument;\n if (!document) {\n throw new Error('tt.appDocument is not found');\n }\n const html = document.createElement(HTML);\n const head = document.createElement(HEAD);\n const body = document.createElement(BODY);\n const app = document.createElement(APP);\n app.id = APP;\n const container = document.createElement(CONTAINER);\n\n const emptyFunction = () => {};\n\n document.childNodes.push(html);\n html.childNodes.push(head, body);\n body.childNodes.push(container);\n container.childNodes.push(app);\n\n document.documentElement = html;\n document.head = head;\n document.body = body;\n document.appElement = app;\n\n let builtInComponents = tt?.getBuiltInComponents?.();\n if (Array.isArray(builtInComponents)) {\n builtInComponents = new Set(builtInComponents);\n } else if (!(builtInComponents instanceof Set)) {\n builtInComponents = new Set([...DEFAULT_COMPONENTS, ...TT_SPECIFIC_COMPONENTS]);\n }\n\n document.getElementById = function getElementById(id: string) {\n if (id === 'app') {\n return app;\n } else {\n return Object.getPrototypeOf(this).getElementById.call(this, id);\n }\n };\n\n document.getLastPage = function getLastPage() {\n let last;\n for (const v of this._pageDocumentMap.values()) last = v;\n return last;\n };\n\n document.createElement = function (type: string, ...args) {\n if (type === 'root') {\n return this.getLastPage();\n } else {\n const el = builtInComponents.has(type)\n ? Object.getPrototypeOf(this).createElement.call(this, type, ...args)\n : Object.getPrototypeOf(this).createNativeComponent.call(this, type, {\n __tt__inner__options__: {\n name: type,\n },\n });\n // 给元素加上 scopeId\n el.setAttribute('class', '');\n\n // 保存原始的 setAttribute 和 removeAttribute\n const originalSetAttribute = el.setAttribute.bind(el);\n const originalRemoveAttribute = el.removeAttribute.bind(el);\n\n // 拦截 setAttribute 来处理 catchMove\n el.setAttribute = function (name: string, value: any) {\n const result = originalSetAttribute(name, value);\n\n // 处理 catchMove 属性\n if (name === 'catchMove' && value) {\n el.addEventListener('catchtouchmove', emptyFunction);\n }\n\n return result;\n };\n\n // 拦截 removeAttribute 来处理 catchMove\n el.removeAttribute = function (name: string) {\n const oldValue = el.getAttribute(name);\n\n // 处理 catchMove 属性\n if (name === 'catchMove' && oldValue) {\n el.removeEventListener('catchtouchmove', emptyFunction);\n }\n\n return originalRemoveAttribute(name);\n };\n\n return el;\n }\n };\n return document;\n}\n\n// Note: 小程序端 vite 打包成 commonjs,const document = xxx 会报错,所以把 document 改为 taroDocumentProvider\nexport const taroDocumentProvider: TaroDocument =\n process.env.TARO_PLATFORM === 'web'\n ? env.document\n : (env.document = isEnableTTDom() ? createTTDomDocument() : createDocument());\n"],"mappings":";;;;;AAMA,SAAS,iBAA+B;;;;;;;;;;;;;CAatC,MAAM,MAAM,IAAI,aAAa;CAC7B,MAAM,wBAAwB,IAAI,cAAc,KAAK,GAAG;CACxD,MAAM,OAAO,sBAAsB,IAAI;CACvC,MAAM,OAAO,sBAAsB,IAAI;CACvC,MAAM,OAAO,sBAAsB,IAAI;CACvC,MAAM,MAAM,sBAAA,KAAyB;CACrC,IAAI,KAAA;CACJ,MAAM,YAAY,sBAAsB,SAAS;CAEjD,IAAI,YAAY,IAAI;CACpB,KAAK,YAAY,IAAI;CACrB,KAAK,YAAY,IAAI;CACrB,KAAK,YAAY,SAAS;CAC1B,UAAU,YAAY,GAAG;CAEzB,IAAI,kBAAkB;CACtB,IAAI,OAAO;CACX,IAAI,OAAO;CAEX,OAAO;AACT;AAIA,SAAgB,sBAAoC;CAClD,MAAM,WAAW,IAAI;CACrB,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,6BAA6B;CAE/C,MAAM,OAAO,SAAS,cAAc,IAAI;CACxC,MAAM,OAAO,SAAS,cAAc,IAAI;CACxC,MAAM,OAAO,SAAS,cAAc,IAAI;CACxC,MAAM,MAAM,SAAS,cAAA,KAAiB;CACtC,IAAI,KAAA;CACJ,MAAM,YAAY,SAAS,cAAc,SAAS;CAElD,MAAM,sBAAsB,CAAC;CAE7B,SAAS,WAAW,KAAK,IAAI;CAC7B,KAAK,WAAW,KAAK,MAAM,IAAI;CAC/B,KAAK,WAAW,KAAK,SAAS;CAC9B,UAAU,WAAW,KAAK,GAAG;CAE7B,SAAS,kBAAkB;CAC3B,SAAS,OAAO;CAChB,SAAS,OAAO;CAChB,SAAS,aAAa;CAEtB,IAAI,oBAAoB,IAAI,uBAAuB;CACnD,IAAI,MAAM,QAAQ,iBAAiB,GACjC,oBAAoB,IAAI,I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AAe"}
@@ -0,0 +1,4 @@
1
+ import type { TaroElement } from '../dom/element';
2
+ import type { Style } from '../dom/style';
3
+ export type TGetComputedStyle = typeof window.getComputedStyle | ((el: TaroElement) => Style);
4
+ export declare const taroGetComputedStyleProvider: TGetComputedStyle;
@@ -0,0 +1,9 @@
1
+ import env from "../env.js";
2
+ //#region src/bom/getComputedStyle.ts
3
+ const taroGetComputedStyleProvider = process.env.TARO_PLATFORM === "web" ? env.window.getComputedStyle : function(element) {
4
+ return element.style;
5
+ };
6
+ //#endregion
7
+ export { taroGetComputedStyleProvider };
8
+
9
+ //# sourceMappingURL=getComputedStyle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getComputedStyle.js","names":[],"sources":["../../src/bom/getComputedStyle.ts"],"sourcesContent":["import env from '../env';\n\nimport type { TaroElement } from '../dom/element';\nimport type { Style } from '../dom/style';\n\nexport type TGetComputedStyle = typeof window.getComputedStyle | ((el: TaroElement) => Style);\n\n// Note: 小程序端 vite 打包成 commonjs,const getComputedStyle = xxx 会报错,所以把 GetComputedStyle 改为 taroGetComputedStyleProvider\nexport const taroGetComputedStyleProvider: TGetComputedStyle =\n process.env.TARO_PLATFORM === 'web'\n ? env.window.getComputedStyle\n : function (element: TaroElement): Style {\n return element.style;\n };\n"],"mappings":";;AAQA,MAAa,+BACX,QAAQ,IAAI,kBAAkB,QAC1B,IAAI,OAAO,mBACX,SAAU,SAA6B;CACrC,OAAO,QAAQ;AACjB"}
@@ -0,0 +1,30 @@
1
+ import { Events } from '../emitter/emitter';
2
+ import { RuntimeCache } from '../utils/cache';
3
+ import type { TaroLocation } from './location';
4
+ export interface HistoryState {
5
+ state: Record<string, any> | null;
6
+ title: string;
7
+ url: string;
8
+ }
9
+ type Options = {
10
+ window: any;
11
+ };
12
+ type HistoryContext = {
13
+ location: TaroLocation;
14
+ stack: HistoryState[];
15
+ cur: number;
16
+ };
17
+ declare class TaroHistory extends Events {
18
+ #private;
19
+ constructor(location: TaroLocation, options: Options);
20
+ get length(): number;
21
+ get state(): Record<string, any> | null;
22
+ go(delta: number): void;
23
+ back(): void;
24
+ forward(): void;
25
+ pushState(state: any, title: string, url: string): void;
26
+ replaceState(state: any, title: string, url: string): void;
27
+ get cache(): RuntimeCache<HistoryContext>;
28
+ }
29
+ export type { TaroHistory };
30
+ export declare const History: typeof TaroHistory;
@@ -0,0 +1,108 @@
1
+ import "../constants/index.js";
2
+ import { Events } from "../emitter/emitter.js";
3
+ import env from "../env.js";
4
+ import { RuntimeCache } from "../utils/cache.js";
5
+ import { isNumber, isString } from "@spcsn/taro-shared";
6
+ //#region src/bom/history.ts
7
+ const cache = new RuntimeCache("history");
8
+ var TaroHistory = class extends Events {
9
+ #location;
10
+ #stack = [];
11
+ #cur = 0;
12
+ #window;
13
+ constructor(location, options) {
14
+ super();
15
+ this.#window = options.window;
16
+ this.#location = location;
17
+ this.#location.on("__record_history__", (href) => {
18
+ this.#cur++;
19
+ this.#stack = this.#stack.slice(0, this.#cur);
20
+ this.#stack.push({
21
+ state: null,
22
+ title: "",
23
+ url: href
24
+ });
25
+ }, null);
26
+ this.#location.on("__reset_history__", (href) => {
27
+ this.#reset(href);
28
+ }, null);
29
+ this.on("0", () => {
30
+ this.#reset();
31
+ }, null);
32
+ this.on("1", (pageId) => {
33
+ cache.set(pageId, {
34
+ location: this.#location,
35
+ stack: this.#stack.slice(),
36
+ cur: this.#cur
37
+ });
38
+ }, null);
39
+ this.on("2", (pageId) => {
40
+ if (cache.has(pageId)) {
41
+ const ctx = cache.get(pageId);
42
+ this.#location = ctx.location;
43
+ this.#stack = ctx.stack;
44
+ this.#cur = ctx.cur;
45
+ }
46
+ }, null);
47
+ this.on("3", (pageId) => {
48
+ cache.delete(pageId);
49
+ }, null);
50
+ this.#reset();
51
+ }
52
+ #reset(href = "") {
53
+ this.#stack = [{
54
+ state: null,
55
+ title: "",
56
+ url: href || this.#location.href
57
+ }];
58
+ this.#cur = 0;
59
+ }
60
+ get length() {
61
+ return this.#stack.length;
62
+ }
63
+ get state() {
64
+ return this.#stack[this.#cur].state;
65
+ }
66
+ go(delta) {
67
+ if (!isNumber(delta) || isNaN(delta)) return;
68
+ let targetIdx = this.#cur + delta;
69
+ targetIdx = Math.min(Math.max(targetIdx, 0), this.length - 1);
70
+ this.#cur = targetIdx;
71
+ this.#location.trigger("__set_href_without_history__", this.#stack[this.#cur].url);
72
+ this.#window.trigger("popstate", this.#stack[this.#cur]);
73
+ }
74
+ back() {
75
+ this.go(-1);
76
+ }
77
+ forward() {
78
+ this.go(1);
79
+ }
80
+ pushState(state, title, url) {
81
+ if (!url || !isString(url)) return;
82
+ this.#stack = this.#stack.slice(0, this.#cur + 1);
83
+ this.#stack.push({
84
+ state,
85
+ title,
86
+ url
87
+ });
88
+ this.#cur = this.length - 1;
89
+ this.#location.trigger("__set_href_without_history__", url);
90
+ }
91
+ replaceState(state, title, url) {
92
+ if (!url || !isString(url)) return;
93
+ this.#stack[this.#cur] = {
94
+ state,
95
+ title,
96
+ url
97
+ };
98
+ this.#location.trigger("__set_href_without_history__", url);
99
+ }
100
+ get cache() {
101
+ return cache;
102
+ }
103
+ };
104
+ const History = process.env.TARO_PLATFORM === "web" ? env.window.History : TaroHistory;
105
+ //#endregion
106
+ export { History };
107
+
108
+ //# sourceMappingURL=history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.js","names":["#window","#location","#cur","#stack","#reset"],"sources":["../../src/bom/history.ts"],"sourcesContent":["import { isNumber, isString } from '@spcsn/taro-shared';\n\nimport { CONTEXT_ACTIONS } from '../constants';\nimport { Events } from '../emitter/emitter';\nimport env from '../env';\nimport { RuntimeCache } from '../utils/cache';\n\nimport type { TaroLocation } from './location';\n\nexport interface HistoryState {\n state: Record<string, any> | null;\n title: string;\n url: string;\n}\n\ntype Options = {\n window: any;\n};\ntype HistoryContext = {\n location: TaroLocation;\n stack: HistoryState[];\n cur: number;\n};\nconst cache = new RuntimeCache<HistoryContext>('history');\n\nclass TaroHistory extends Events {\n /* private property */\n #location: TaroLocation;\n #stack: HistoryState[] = [];\n #cur = 0;\n\n #window: any;\n\n constructor(location: TaroLocation, options: Options) {\n super();\n\n this.#window = options.window;\n this.#location = location;\n\n this.#location.on(\n '__record_history__',\n (href: string) => {\n this.#cur++;\n this.#stack = this.#stack.slice(0, this.#cur);\n this.#stack.push({\n state: null,\n title: '',\n url: href,\n });\n },\n null,\n );\n\n this.#location.on(\n '__reset_history__',\n (href: string) => {\n this.#reset(href);\n },\n null,\n );\n\n // 切换上下文行为\n\n this.on(\n CONTEXT_ACTIONS.INIT,\n () => {\n this.#reset();\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.RESTORE,\n (pageId: string) => {\n cache.set(pageId, {\n location: this.#location,\n stack: this.#stack.slice(),\n cur: this.#cur,\n });\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.RECOVER,\n (pageId: string) => {\n if (cache.has(pageId)) {\n const ctx = cache.get(pageId)!;\n this.#location = ctx.location;\n this.#stack = ctx.stack;\n this.#cur = ctx.cur;\n }\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.DESTROY,\n (pageId: string) => {\n cache.delete(pageId);\n },\n null,\n );\n\n this.#reset();\n }\n\n #reset(href = '') {\n this.#stack = [\n {\n state: null,\n title: '',\n url: href || this.#location.href,\n },\n ];\n this.#cur = 0;\n }\n\n /* public property */\n get length() {\n return this.#stack.length;\n }\n\n get state() {\n return this.#stack[this.#cur].state;\n }\n\n /* public method */\n go(delta: number) {\n if (!isNumber(delta) || isNaN(delta)) return;\n\n let targetIdx = this.#cur + delta;\n targetIdx = Math.min(Math.max(targetIdx, 0), this.length - 1);\n\n this.#cur = targetIdx;\n\n this.#location.trigger('__set_href_without_history__', this.#stack[this.#cur].url);\n this.#window.trigger('popstate', this.#stack[this.#cur]);\n }\n\n back() {\n this.go(-1);\n }\n\n forward() {\n this.go(1);\n }\n\n pushState(state: any, title: string, url: string) {\n if (!url || !isString(url)) return;\n this.#stack = this.#stack.slice(0, this.#cur + 1);\n this.#stack.push({\n state,\n title,\n url,\n });\n this.#cur = this.length - 1;\n\n this.#location.trigger('__set_href_without_history__', url);\n }\n\n replaceState(state: any, title: string, url: string) {\n if (!url || !isString(url)) return;\n this.#stack[this.#cur] = {\n state,\n title,\n url,\n };\n\n this.#location.trigger('__set_href_without_history__', url);\n }\n\n // For debug\n get cache() {\n return cache;\n }\n}\n\nexport type { TaroHistory };\nexport const History: typeof TaroHistory = process.env.TARO_PLATFORM === 'web' ? env.window.History : TaroHistory;\n"],"mappings":";;;;;;AAuBA,MAAM,QAAQ,IAAI,aAA6B,SAAS;AAExD,IAAM,cAAN,cAA0B,OAAO;CAE/B;CACA,SAAyB,CAAC;CAC1B,OAAO;CAEP;CAEA,YAAY,UAAwB,SAAkB;EACpD,MAAM;EAEN,KAAKA,UAAU,QAAQ;EACvB,KAAKC,YAAY;EAEjB,KAAKA,UAAU,GACb,uBACC,SAAiB;GAChB,KAAKC;GACL,KAAKC,SAAS,KAAKA,OAAO,MAAM,GAAG,KAAKD,IAAI;GAC5C,KAAKC,OAAO,KAAK;IACf,OAAO;IACP,OAAO;IACP,KAAK;GACP,CAAC;EACH,GACA,IACF;EAEA,KAAKF,UAAU,GACb,sBACC,SAAiB;GAChB,KAAKG,OAAO,IAAI;EAClB,GACA,IACF;EAIA,KAAK,GAAA,WAEG;GACJ,KAAKA,OAAO;EACd,GACA,IACF;EAEA,KAAK,GAAA,MAEF,WAAmB;GAClB,MAAM,IAAI,QAAQ;IAChB,UAAU,KAAKH;IACf,OAAO,KAAKE,OAAO,MAAM;IACzB,KAAK,KAAKD;GACZ,CAAC;EACH,GACA,IACF;EAEA,KAAK,GAAA,MAEF,WAAmB;GAClB,IAAI,MAAM,IAAI,MAAM,GAAG;IACrB,MAAM,MAAM,MAAM,IAAI,MAAM;IAC5B,KAAKD,YAAY,IAAI;IACrB,KAAKE,SAAS,IAAI;IAClB,KAAKD,OAAO,IAAI;GAClB;EACF,GACA,IACF;EAEA,KAAK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ACT;AACF;AAGA,MAAa,UAA8B,QAAQ,IAAI,kBAAkB,QAAQ,IAAI,OAAO,UAAU"}
@@ -0,0 +1,37 @@
1
+ import { Events } from '../emitter/emitter';
2
+ import { RuntimeCache } from '../utils/cache';
3
+ type Options = {
4
+ window: any;
5
+ };
6
+ type LocationContext = {
7
+ lastHref: string;
8
+ };
9
+ declare class TaroLocation extends Events {
10
+ #private;
11
+ constructor(options: Options);
12
+ get protocol(): string;
13
+ set protocol(val: string);
14
+ get host(): string;
15
+ set host(val: string);
16
+ get hostname(): string;
17
+ set hostname(val: string);
18
+ get port(): string;
19
+ set port(val: string);
20
+ get pathname(): string;
21
+ set pathname(val: string);
22
+ get search(): string;
23
+ set search(val: string);
24
+ get hash(): string;
25
+ set hash(val: string);
26
+ get href(): string;
27
+ set href(val: string);
28
+ get origin(): string;
29
+ set origin(val: string);
30
+ assign(): void;
31
+ reload(): void;
32
+ replace(url: string): void;
33
+ toString(): string;
34
+ get cache(): RuntimeCache<LocationContext>;
35
+ }
36
+ export type { TaroLocation };
37
+ export declare const Location: typeof TaroLocation;
@@ -0,0 +1,200 @@
1
+ import "../constants/index.js";
2
+ import { Events } from "../emitter/emitter.js";
3
+ import env from "../env.js";
4
+ import { RuntimeCache } from "../utils/cache.js";
5
+ import { getCurrentInstance } from "../current.js";
6
+ import { TaroURLProvider } from "./URL.js";
7
+ import { isNumber, isString, warn } from "@spcsn/taro-shared";
8
+ //#region src/bom/location.ts
9
+ const INIT_URL = "https://taro.com";
10
+ const cache = new RuntimeCache("location");
11
+ var TaroLocation = class extends Events {
12
+ #url = new TaroURLProvider(INIT_URL);
13
+ #noCheckUrl = false;
14
+ #window;
15
+ constructor(options) {
16
+ super();
17
+ this.#window = options.window;
18
+ this.#reset();
19
+ this.on("__set_href_without_history__", (href) => {
20
+ this.#noCheckUrl = true;
21
+ const lastHash = this.#url.hash;
22
+ this.#url.href = generateFullUrl(href);
23
+ if (lastHash !== this.#url.hash) this.#window.trigger("hashchange");
24
+ this.#noCheckUrl = false;
25
+ }, null);
26
+ this.on("0", () => {
27
+ this.#reset();
28
+ }, null);
29
+ this.on("1", (pageId) => {
30
+ cache.set(pageId, { lastHref: this.href });
31
+ }, null);
32
+ this.on("2", (pageId) => {
33
+ if (cache.has(pageId)) {
34
+ const ctx = cache.get(pageId);
35
+ this.#noCheckUrl = true;
36
+ this.#url.href = ctx.lastHref;
37
+ this.#noCheckUrl = false;
38
+ }
39
+ }, null);
40
+ this.on("3", (pageId) => {
41
+ cache.delete(pageId);
42
+ }, null);
43
+ }
44
+ #reset() {
45
+ const router = getCurrentInstance().router;
46
+ if (router) {
47
+ const { path, params } = router;
48
+ const searchArr = Object.keys(params).map((key) => {
49
+ return `${key}=${params[key]}`;
50
+ });
51
+ const searchStr = searchArr.length > 0 ? "?" + searchArr.join("&") : "";
52
+ const url = `${INIT_URL}${path.startsWith("/") ? path : "/" + path}${searchStr}`;
53
+ this.#url = new TaroURLProvider(url);
54
+ this.trigger("__reset_history__", this.href);
55
+ }
56
+ }
57
+ #getPreValue() {
58
+ return this.#url._toRaw();
59
+ }
60
+ #rollBack(href) {
61
+ this.#url.href = href;
62
+ }
63
+ #recordHistory() {
64
+ this.trigger("__record_history__", this.href);
65
+ }
66
+ /**
67
+ * 校验url的变化,是否需要更新history
68
+ */
69
+ #checkUrlChange(preValue) {
70
+ if (this.#noCheckUrl) return false;
71
+ const { protocol, hostname, port, pathname, search, hash } = this.#url._toRaw();
72
+ if (protocol !== preValue.protocol || hostname !== preValue.hostname || port !== preValue.port) {
73
+ this.#rollBack(preValue.href);
74
+ return false;
75
+ }
76
+ if (pathname !== preValue.pathname) return true;
77
+ if (search !== preValue.search) return true;
78
+ if (hash !== preValue.hash) {
79
+ this.#window.trigger("hashchange");
80
+ return true;
81
+ }
82
+ this.#rollBack(preValue.href);
83
+ return false;
84
+ }
85
+ get protocol() {
86
+ return this.#url.protocol;
87
+ }
88
+ set protocol(val) {
89
+ if (!val || !isString(val) || !/^(http|https):$/i.test(val.trim())) return;
90
+ val = val.trim();
91
+ const preValue = this.#getPreValue();
92
+ this.#url.protocol = val;
93
+ if (this.#checkUrlChange(preValue)) this.#recordHistory();
94
+ }
95
+ get host() {
96
+ return this.#url.host;
97
+ }
98
+ set host(val) {
99
+ if (!val || !isString(val)) return;
100
+ val = val.trim();
101
+ const preValue = this.#getPreValue();
102
+ this.#url.host = val;
103
+ if (this.#checkUrlChange(preValue)) this.#recordHistory();
104
+ }
105
+ get hostname() {
106
+ return this.#url.hostname;
107
+ }
108
+ set hostname(val) {
109
+ if (!val || !isString(val)) return;
110
+ val = val.trim();
111
+ const preValue = this.#getPreValue();
112
+ this.#url.hostname = val;
113
+ if (this.#checkUrlChange(preValue)) this.#recordHistory();
114
+ }
115
+ get port() {
116
+ return this.#url.port;
117
+ }
118
+ set port(val) {
119
+ const xVal = Number(val = val.trim());
120
+ if (!isNumber(xVal) || xVal <= 0) return;
121
+ const preValue = this.#getPreValue();
122
+ this.#url.port = val;
123
+ if (this.#checkUrlChange(preValue)) this.#recordHistory();
124
+ }
125
+ get pathname() {
126
+ return this.#url.pathname;
127
+ }
128
+ set pathname(val) {
129
+ if (!val || !isString(val)) return;
130
+ val = val.trim();
131
+ const preValue = this.#getPreValue();
132
+ this.#url.pathname = val;
133
+ if (this.#checkUrlChange(preValue)) this.#recordHistory();
134
+ }
135
+ get search() {
136
+ return this.#url.search;
137
+ }
138
+ set search(val) {
139
+ if (!val || !isString(val)) return;
140
+ val = val.trim();
141
+ val = val.startsWith("?") ? val : `?${val}`;
142
+ const preValue = this.#getPreValue();
143
+ this.#url.search = val;
144
+ if (this.#checkUrlChange(preValue)) this.#recordHistory();
145
+ }
146
+ get hash() {
147
+ return this.#url.hash;
148
+ }
149
+ set hash(val) {
150
+ if (!val || !isString(val)) return;
151
+ val = val.trim();
152
+ val = val.startsWith("#") ? val : `#${val}`;
153
+ const preValue = this.#getPreValue();
154
+ this.#url.hash = val;
155
+ if (this.#checkUrlChange(preValue)) this.#recordHistory();
156
+ }
157
+ get href() {
158
+ return this.#url.href;
159
+ }
160
+ set href(val) {
161
+ if (!val || !isString(val) || !/^(http:|https:)?\/\/.+/.test(val = val.trim())) return;
162
+ const preValue = this.#getPreValue();
163
+ this.#url.href = val;
164
+ if (this.#checkUrlChange(preValue)) this.#recordHistory();
165
+ }
166
+ get origin() {
167
+ return this.#url.origin;
168
+ }
169
+ set origin(val) {
170
+ if (!val || !isString(val) || !/^(http:|https:)?\/\/.+/.test(val = val.trim())) return;
171
+ const preValue = this.#getPreValue();
172
+ this.#url.origin = val;
173
+ if (this.#checkUrlChange(preValue)) this.#recordHistory();
174
+ }
175
+ assign() {
176
+ warn(true, "小程序环境中调用location.assign()无效.");
177
+ }
178
+ reload() {
179
+ warn(true, "小程序环境中调用location.reload()无效.");
180
+ }
181
+ replace(url) {
182
+ this.trigger("__set_href_without_history__", url);
183
+ }
184
+ toString() {
185
+ return this.href;
186
+ }
187
+ get cache() {
188
+ return cache;
189
+ }
190
+ };
191
+ const Location = process.env.TARO_PLATFORM === "web" ? env.window.Location : TaroLocation;
192
+ function generateFullUrl(val = "") {
193
+ const origin = INIT_URL;
194
+ if (/^[/?#]/.test(val)) return origin + val;
195
+ return val;
196
+ }
197
+ //#endregion
198
+ export { Location };
199
+
200
+ //# sourceMappingURL=location.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"location.js","names":["#window","#reset","#noCheckUrl","#url","#rollBack","#getPreValue","#checkUrlChange","#recordHistory"],"sources":["../../src/bom/location.ts"],"sourcesContent":["import { isNumber, isString, warn } from '@spcsn/taro-shared';\n\nimport { CONTEXT_ACTIONS } from '../constants';\nimport { getCurrentInstance } from '../current';\nimport { Events } from '../emitter/emitter';\nimport env from '../env';\nimport { RuntimeCache } from '../utils/cache';\nimport { TaroURLProvider } from './URL';\n\ntype PreValue = ReturnType<typeof TaroURLProvider.prototype._toRaw>;\n\ntype Options = {\n window: any;\n};\ntype LocationContext = {\n lastHref: string;\n};\n\nconst INIT_URL = 'https://taro.com';\nconst cache = new RuntimeCache<LocationContext>('location');\n\nclass TaroLocation extends Events {\n /* private property */\n #url = new TaroURLProvider(INIT_URL);\n #noCheckUrl = false;\n #window: any;\n\n constructor(options: Options) {\n super();\n\n this.#window = options.window;\n\n this.#reset();\n\n this.on(\n '__set_href_without_history__',\n (href: string) => {\n this.#noCheckUrl = true;\n\n const lastHash = this.#url.hash;\n this.#url.href = generateFullUrl(href);\n\n if (lastHash !== this.#url.hash) {\n this.#window.trigger('hashchange');\n }\n\n this.#noCheckUrl = false;\n },\n null,\n );\n\n // 切换上下文行为\n this.on(\n CONTEXT_ACTIONS.INIT,\n () => {\n this.#reset();\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.RESTORE,\n (pageId: string) => {\n cache.set(pageId, {\n lastHref: this.href,\n });\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.RECOVER,\n (pageId: string) => {\n // 数据恢复时,不需要执行跳转\n if (cache.has(pageId)) {\n const ctx = cache.get(pageId)!;\n this.#noCheckUrl = true;\n this.#url.href = ctx.lastHref;\n this.#noCheckUrl = false;\n }\n },\n null,\n );\n\n this.on(\n CONTEXT_ACTIONS.DESTROY,\n (pageId: string) => {\n cache.delete(pageId);\n },\n null,\n );\n }\n\n /* private method */\n #reset() {\n const Current = getCurrentInstance();\n const router = Current.router;\n if (router) {\n const { path, params } = router;\n const searchArr = Object.keys(params).map((key) => {\n return `${key}=${params[key]}`;\n });\n const searchStr = searchArr.length > 0 ? '?' + searchArr.join('&') : '';\n const url = `${INIT_URL}${path.startsWith('/') ? path : '/' + path}${searchStr}`;\n\n this.#url = new TaroURLProvider(url);\n\n this.trigger('__reset_history__', this.href);\n }\n }\n\n #getPreValue(): PreValue {\n return this.#url._toRaw();\n }\n\n #rollBack(href: string) {\n this.#url.href = href;\n }\n\n #recordHistory() {\n this.trigger('__record_history__', this.href);\n }\n\n /**\n * 校验url的变化,是否需要更新history\n */\n #checkUrlChange(preValue: PreValue): boolean {\n if (this.#noCheckUrl) {\n return false;\n }\n\n const { protocol, hostname, port, pathname, search, hash } = this.#url._toRaw();\n\n // 跨域三要素不允许修改\n if (protocol !== preValue.protocol || hostname !== preValue.hostname || port !== preValue.port) {\n this.#rollBack(preValue.href);\n return false;\n }\n\n // pathname\n if (pathname !== preValue.pathname) {\n return true;\n }\n\n // search\n if (search !== preValue.search) {\n return true;\n }\n\n // hashchange\n if (hash !== preValue.hash) {\n this.#window.trigger('hashchange');\n return true;\n }\n\n this.#rollBack(preValue.href);\n return false;\n }\n\n /* public property */\n get protocol() {\n return this.#url.protocol;\n }\n\n set protocol(val: string) {\n const REG = /^(http|https):$/i;\n if (!val || !isString(val) || !REG.test(val.trim())) return;\n\n val = val.trim();\n const preValue = this.#getPreValue();\n this.#url.protocol = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n get host() {\n return this.#url.host;\n }\n\n set host(val: string) {\n if (!val || !isString(val)) return;\n val = val.trim();\n\n const preValue = this.#getPreValue();\n this.#url.host = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n get hostname() {\n return this.#url.hostname;\n }\n\n set hostname(val: string) {\n if (!val || !isString(val)) return;\n val = val.trim();\n\n const preValue = this.#getPreValue();\n this.#url.hostname = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n get port() {\n return this.#url.port;\n }\n\n set port(val: string) {\n const xVal = Number((val = val.trim()));\n if (!isNumber(xVal) || xVal <= 0) return;\n\n const preValue = this.#getPreValue();\n this.#url.port = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n get pathname() {\n return this.#url.pathname;\n }\n\n set pathname(val: string) {\n if (!val || !isString(val)) return;\n val = val.trim();\n\n const preValue = this.#getPreValue();\n this.#url.pathname = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n get search() {\n return this.#url.search;\n }\n\n set search(val: string) {\n if (!val || !isString(val)) return;\n val = val.trim();\n val = val.startsWith('?') ? val : `?${val}`;\n\n const preValue = this.#getPreValue();\n this.#url.search = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n get hash() {\n return this.#url.hash;\n }\n\n // 小程序的navigateTo存在截断hash字符串的问题\n set hash(val: string) {\n if (!val || !isString(val)) return;\n val = val.trim();\n val = val.startsWith('#') ? val : `#${val}`;\n\n const preValue = this.#getPreValue();\n this.#url.hash = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n get href() {\n return this.#url.href;\n }\n\n set href(val: string) {\n const REG = /^(http:|https:)?\\/\\/.+/;\n if (!val || !isString(val) || !REG.test((val = val.trim()))) return;\n\n const preValue = this.#getPreValue();\n this.#url.href = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n get origin() {\n return this.#url.origin;\n }\n\n set origin(val: string) {\n const REG = /^(http:|https:)?\\/\\/.+/;\n if (!val || !isString(val) || !REG.test((val = val.trim()))) return;\n\n const preValue = this.#getPreValue();\n this.#url.origin = val;\n\n if (this.#checkUrlChange(preValue)) this.#recordHistory();\n }\n\n /* public method */\n assign() {\n warn(true, '小程序环境中调用location.assign()无效.');\n }\n\n reload() {\n warn(true, '小程序环境中调用location.reload()无效.');\n }\n\n replace(url: string) {\n this.trigger('__set_href_without_history__', url);\n }\n\n toString() {\n return this.href;\n }\n\n // For debug\n get cache() {\n return cache;\n }\n}\n\nexport type { TaroLocation };\nexport const Location: typeof TaroLocation = process.env.TARO_PLATFORM === 'web' ? env.window.Location : TaroLocation;\n\nfunction generateFullUrl(val = '') {\n const origin = INIT_URL;\n if (/^[/?#]/.test(val)) {\n return origin + val;\n }\n return val;\n}\n"],"mappings":";;;;;;;;AAkBA,MAAM,WAAW;AACjB,MAAM,QAAQ,IAAI,aAA8B,UAAU;AAE1D,IAAM,eAAN,cAA2B,OAAO;CAEhC,OAAO,IAAI,gBAAgB,QAAQ;CACnC,cAAc;CACd;CAEA,YAAY,SAAkB;EAC5B,MAAM;EAE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jB,IAAI,KAAKG,gBAAgB,QAAQ,GAAG,KAAKC,eAAe;CAC1D;CAEA,IAAI,OAAO;EACT,OAAO,KAAKJ,KAAK;CACnB;CAEA,IAAI,KAAK,KAAa;EAEpB,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC,yBAAI,KAAM,MAAM,IAAI,KAAK,CAAE,GAAG;EAE7D,MAAM,WAAW,KAAKE,aAAa;EACnC,KAAKF,KAAK,OAAO;EAEjB,IAAI,KAAKG,gBAAgB,QAAQ,GAAG,KAAKC,eAAe;CAC1D;CAEA,IAAI,SAAS;EACX,OAAO,KAAKJ,KAAK;CACnB;CAEA,IAAI,OAAO,KAAa;EAEtB,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC,yBAAI,KAAM,MAAM,IAAI,KAAK,CAAE,GAAG;EAE7D,MAAM,WAAW,KAAKE,aAAa;EACnC,KAAKF,KAAK,SAAS;EAEnB,IAAI,KAAKG,gBAAgB,QAAQ,GAAG,KAAKC,eAAe;CAC1D;CAGA,SAAS;EACP,KAAK,MAAM,8BAA8B;CAC3C;CAEA,SAAS;EACP,KAAK,MAAM,8BAA8B;CAC3C;CAEA,QAAQ,KAAa;EACnB,KAAK,QAAQ,gCAAgC,GAAG;CAClD;CAEA,WAAW;EACT,OAAO,KAAK;CACd;CAGA,IAAI,QAAQ;EACV,OAAO;CACT;AACF;AAGA,MAAa,WAAgC,QAAQ,IAAI,kBAAkB,QAAQ,IAAI,OAAO,WAAW;AAEzG,SAAS,gBAAgB,MAAM,IAAI;CACjC,MAAM,SAAS;CACf,IAAI,SAAS,KAAK,GAAG,GACnB,OAAO,SAAS;CAElB,OAAO;AACT"}
@@ -0,0 +1 @@
1
+ export declare const nav: typeof window.navigator;
@@ -0,0 +1,22 @@
1
+ import env from "../env.js";
2
+ //#region src/bom/navigator.ts
3
+ const msg = "(Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/534.36 (KHTML, like Gecko) NodeJS/v4.1.0 Chrome/76.0.3809.132 Safari/534.36";
4
+ const nav = process.env.TARO_PLATFORM === "web" ? env.window.navigator : {
5
+ appCodeName: "Mozilla",
6
+ appName: "Netscape",
7
+ appVersion: "5.0 " + msg,
8
+ cookieEnabled: true,
9
+ mimeTypes: [],
10
+ onLine: true,
11
+ platform: "MacIntel",
12
+ plugins: [],
13
+ product: "Taro",
14
+ productSub: "20030107",
15
+ userAgent: "Mozilla/5.0 " + msg,
16
+ vendor: "Joyent",
17
+ vendorSub: ""
18
+ };
19
+ //#endregion
20
+ export { nav };
21
+
22
+ //# sourceMappingURL=navigator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigator.js","names":[],"sources":["../../src/bom/navigator.ts"],"sourcesContent":["import env from '../env';\n\nconst machine = 'Macintosh';\nconst arch = 'Intel Mac OS X 10_14_5';\nconst engine = 'AppleWebKit/534.36 (KHTML, like Gecko) NodeJS/v4.1.0 Chrome/76.0.3809.132 Safari/534.36';\n\nconst msg = '(' + machine + '; ' + arch + ') ' + engine;\n\nexport const nav: typeof window.navigator =\n process.env.TARO_PLATFORM === 'web'\n ? env.window.navigator\n : {\n appCodeName: 'Mozilla',\n appName: 'Netscape',\n appVersion: '5.0 ' + msg,\n cookieEnabled: true,\n mimeTypes: [],\n onLine: true,\n platform: 'MacIntel',\n plugins: [],\n product: 'Taro',\n productSub: '20030107',\n userAgent: 'Mozilla/5.0 ' + msg,\n vendor: 'Joyent',\n vendorSub: '',\n };\n"],"mappings":";;AAMA,MAAM,MAAM;AAEZ,MAAa,MACX,QAAQ,IAAI,kBAAkB,QAC1B,IAAI,OAAO,YACX;CACE,aAAa;CACb,SAAS;CACT,YAAY,SAAS;CACrB,eAAe;CACf,WAAW,CAAC;CACZ,QAAQ;CACR,UAAU;CACV,SAAS,CAAC;CACV,SAAS;CACT,YAAY;CACZ,WAAW,iBAAiB;CAC5B,QAAQ;CACR,WAAW;AACb"}
@@ -0,0 +1,4 @@
1
+ export declare let now: () => number;
2
+ declare const _raf: typeof requestAnimationFrame | ((callback: any) => NodeJS.Timeout);
3
+ declare const _caf: typeof cancelAnimationFrame;
4
+ export { _caf as caf, _raf as raf };
@@ -0,0 +1,28 @@
1
+ //#region src/bom/raf.ts
2
+ let now;
3
+ (function() {
4
+ let loadTime;
5
+ if (typeof performance !== "undefined" && performance !== null && performance.now) now = () => performance.now();
6
+ else if (Date.now) {
7
+ loadTime = Date.now();
8
+ now = () => Date.now() - loadTime;
9
+ } else {
10
+ loadTime = (/* @__PURE__ */ new Date()).getTime();
11
+ now = () => (/* @__PURE__ */ new Date()).getTime() - loadTime;
12
+ }
13
+ })();
14
+ let lastTime = 0;
15
+ const _raf = process.env.TARO_PLATFORM === "web" ? requestAnimationFrame : function(callback) {
16
+ const _now = now();
17
+ const nextTime = Math.max(lastTime + 16, _now);
18
+ return setTimeout(function() {
19
+ callback(lastTime = nextTime);
20
+ }, nextTime - _now);
21
+ };
22
+ const _caf = process.env.TARO_PLATFORM === "web" ? cancelAnimationFrame : function(seed) {
23
+ clearTimeout(seed);
24
+ };
25
+ //#endregion
26
+ export { _caf, _raf, now };
27
+
28
+ //# sourceMappingURL=raf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raf.js","names":[],"sources":["../../src/bom/raf.ts"],"sourcesContent":["// https://github.com/myrne/performance-now\nexport let now: () => number;\n\n(function () {\n let loadTime;\n if (typeof performance !== 'undefined' && performance !== null && performance.now) {\n now = () => performance.now();\n } else if (Date.now) {\n loadTime = Date.now();\n now = () => Date.now() - loadTime;\n } else {\n loadTime = new Date().getTime();\n now = () => new Date().getTime() - loadTime;\n }\n})();\n\nlet lastTime = 0;\n\n// https://gist.github.com/paulirish/1579671\n// https://gist.github.com/jalbam/5fe05443270fa6d8136238ec72accbc0\nconst _raf =\n process.env.TARO_PLATFORM === 'web'\n ? requestAnimationFrame\n : function (callback) {\n const _now = now();\n const nextTime = Math.max(lastTime + 16, _now); // First time will execute it immediately but barely noticeable and performance is gained.\n return setTimeout(function () {\n callback((lastTime = nextTime));\n }, nextTime - _now);\n };\n\nconst _caf =\n process.env.TARO_PLATFORM === 'web'\n ? cancelAnimationFrame\n : function (seed) {\n // fix https://github.com/NervJS/taro/issues/7749\n clearTimeout(seed);\n };\n\nexport { _caf as caf, _raf as raf };\n"],"mappings":";AACA,IAAW;CAEV,WAAY;CACX,IAAI;CACJ,IAAI,OAAO,gBAAgB,eAAe,gBAAgB,QAAQ,YAAY,KAC5E,YAAY,YAAY,IAAI;MACvB,IAAI,KAAK,KAAK;EACnB,WAAW,KAAK,IAAI;EACpB,YAAY,KAAK,IAAI,IAAI;CAC3B,OAAO;EACL,4BAAW,IAAI,KAAK,GAAE,QAAQ;EAC9B,6BAAY,IAAI,KAAK,GAAE,QAAQ,IAAI;CACrC;AACF,GAAG;AAEH,IAAI,WAAW;AAIf,MAAM,OACJ,QAAQ,IAAI,kBAAkB,QAC1B,wBACA,SAAU,UAAU;CAClB,MAAM,OAAO,IAAI;CACjB,MAAM,WAAW,KAAK,IAAI,WAAW,IAAI,IAAI;CAC7C,OAAO,WAAW,WAAY;EAC5B,SAAU,WAAW,QAAS;CAChC,GAAG,WAAW,IAAI;AACpB;AAEN,MAAM,OACJ,QAAQ,IAAI,kBAAkB,QAC1B,uBACA,SAAU,MAAM;CAEd,aAAa,IAAI;AACnB"}
@@ -0,0 +1,23 @@
1
+ import { Events } from '../emitter/emitter';
2
+ import type { TaroHistory } from './history';
3
+ import type { TaroLocation } from './location';
4
+ export declare class TaroWindow extends Events {
5
+ navigator: Navigator;
6
+ requestAnimationFrame: typeof requestAnimationFrame | ((callback: any) => NodeJS.Timeout);
7
+ cancelAnimationFrame: typeof cancelAnimationFrame;
8
+ getComputedStyle: import("./getComputedStyle").TGetComputedStyle;
9
+ Date: DateConstructor;
10
+ location: TaroLocation;
11
+ history: TaroHistory;
12
+ XMLHttpRequest?: Partial<XMLHttpRequest>;
13
+ constructor();
14
+ initEvent(): void;
15
+ get document(): import("../dom/document").TaroDocument;
16
+ addEventListener(event: string, callback: (arg: any) => void): void;
17
+ removeEventListener(event: string, callback: (arg: any) => void): void;
18
+ setTimeout(...args: Parameters<typeof setTimeout>): NodeJS.Timeout;
19
+ clearTimeout(...args: Parameters<typeof clearTimeout>): void;
20
+ }
21
+ export declare const taroWindowProvider: TaroWindow;
22
+ export declare const taroLocationProvider: TaroLocation;
23
+ export declare const taroHistoryProvider: TaroHistory;