@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.
- package/LICENSE +174 -0
- package/README.md +49 -0
- package/dist/bom/URL.d.ts +51 -0
- package/dist/bom/URL.js +188 -0
- package/dist/bom/URL.js.map +1 -0
- package/dist/bom/URLSearchParams.d.ts +1 -0
- package/dist/bom/URLSearchParams.js +103 -0
- package/dist/bom/URLSearchParams.js.map +1 -0
- package/dist/bom/document.d.ts +3 -0
- package/dist/bom/document.js +93 -0
- package/dist/bom/document.js.map +1 -0
- package/dist/bom/getComputedStyle.d.ts +4 -0
- package/dist/bom/getComputedStyle.js +9 -0
- package/dist/bom/getComputedStyle.js.map +1 -0
- package/dist/bom/history.d.ts +30 -0
- package/dist/bom/history.js +108 -0
- package/dist/bom/history.js.map +1 -0
- package/dist/bom/location.d.ts +37 -0
- package/dist/bom/location.js +200 -0
- package/dist/bom/location.js.map +1 -0
- package/dist/bom/navigator.d.ts +1 -0
- package/dist/bom/navigator.js +22 -0
- package/dist/bom/navigator.js.map +1 -0
- package/dist/bom/raf.d.ts +4 -0
- package/dist/bom/raf.js +28 -0
- package/dist/bom/raf.js.map +1 -0
- package/dist/bom/window.d.ts +23 -0
- package/dist/bom/window.js +74 -0
- package/dist/bom/window.js.map +1 -0
- package/dist/constants/index.d.ts +57 -0
- package/dist/constants/index.js +63 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/current.d.ts +19 -0
- package/dist/current.js +11 -0
- package/dist/current.js.map +1 -0
- package/dist/dom/anchor-element.d.ts +13 -0
- package/dist/dom/anchor-element.js +42 -0
- package/dist/dom/anchor-element.js.map +1 -0
- package/dist/dom/class-list.d.ts +16 -0
- package/dist/dom/class-list.js +79 -0
- package/dist/dom/class-list.js.map +1 -0
- package/dist/dom/document.d.ts +21 -0
- package/dist/dom/document.js +74 -0
- package/dist/dom/document.js.map +1 -0
- package/dist/dom/element.d.ts +39 -0
- package/dist/dom/element.js +261 -0
- package/dist/dom/element.js.map +1 -0
- package/dist/dom/event-source.d.ts +7 -0
- package/dist/dom/event-source.js +18 -0
- package/dist/dom/event-source.js.map +1 -0
- package/dist/dom/event-target.d.ts +8 -0
- package/dist/dom/event-target.js +72 -0
- package/dist/dom/event-target.js.map +1 -0
- package/dist/dom/event.d.ts +24 -0
- package/dist/dom/event.js +124 -0
- package/dist/dom/event.js.map +1 -0
- package/dist/dom/form.d.ts +9 -0
- package/dist/dom/form.js +30 -0
- package/dist/dom/form.js.map +1 -0
- package/dist/dom/node.d.ts +76 -0
- package/dist/dom/node.js +213 -0
- package/dist/dom/node.js.map +1 -0
- package/dist/dom/node_types.d.ts +10 -0
- package/dist/dom/root.d.ts +16 -0
- package/dist/dom/root.js +127 -0
- package/dist/dom/root.js.map +1 -0
- package/dist/dom/style.d.ts +14 -0
- package/dist/dom/style.js +138 -0
- package/dist/dom/style.js.map +1 -0
- package/dist/dom/style_properties.d.ts +3 -0
- package/dist/dom/style_properties.js +374 -0
- package/dist/dom/style_properties.js.map +1 -0
- package/dist/dom/svg.d.ts +3 -0
- package/dist/dom/svg.js +7 -0
- package/dist/dom/svg.js.map +1 -0
- package/dist/dom/text.d.ts +14 -0
- package/dist/dom/text.js +43 -0
- package/dist/dom/text.js.map +1 -0
- package/dist/dom/transfer.d.ts +7 -0
- package/dist/dom/transfer.js +16 -0
- package/dist/dom/transfer.js.map +1 -0
- package/dist/dom/tree.d.ts +4 -0
- package/dist/dom/tree.js +31 -0
- package/dist/dom/tree.js.map +1 -0
- package/dist/dom-external/element.d.ts +3 -0
- package/dist/dom-external/index.d.ts +1 -0
- package/dist/dom-external/mutation-observer/implements.d.ts +52 -0
- package/dist/dom-external/mutation-observer/implements.js +101 -0
- package/dist/dom-external/mutation-observer/implements.js.map +1 -0
- package/dist/dom-external/mutation-observer/index.d.ts +13 -0
- package/dist/dom-external/mutation-observer/index.js +32 -0
- package/dist/dom-external/mutation-observer/index.js.map +1 -0
- package/dist/dom-external/mutation-observer/record.d.ts +24 -0
- package/dist/dom-external/node.d.ts +5 -0
- package/dist/dsl/common.d.ts +14 -0
- package/dist/dsl/common.js +278 -0
- package/dist/dsl/common.js.map +1 -0
- package/dist/dsl/instance.d.ts +92 -0
- package/dist/emitter/emitter.d.ts +4 -0
- package/dist/emitter/emitter.js +7 -0
- package/dist/emitter/emitter.js.map +1 -0
- package/dist/env.d.ts +7 -0
- package/dist/env.js +10 -0
- package/dist/env.js.map +1 -0
- package/dist/hydrate.d.ts +10 -0
- package/dist/hydrate.js +62 -0
- package/dist/hydrate.js.map +1 -0
- package/dist/index.cjs.d.ts +35 -0
- package/dist/index.cjs.js +3776 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +34 -0
- package/dist/interface/animate.d.ts +81 -0
- package/dist/interface/element.d.ts +4 -0
- package/dist/interface/event-target.d.ts +11 -0
- package/dist/interface/event.d.ts +15 -0
- package/dist/interface/hydrate.d.ts +30 -0
- package/dist/interface/index.d.ts +8 -0
- package/dist/interface/node.d.ts +7 -0
- package/dist/interface/options.d.ts +5 -0
- package/dist/interface/utils.d.ts +2 -0
- package/dist/next-tick.d.ts +2 -0
- package/dist/next-tick.js +35 -0
- package/dist/next-tick.js.map +1 -0
- package/dist/options.d.ts +2 -0
- package/dist/options.js +9 -0
- package/dist/options.js.map +1 -0
- package/dist/perf.d.ts +9 -0
- package/dist/perf.js +36 -0
- package/dist/perf.js.map +1 -0
- package/dist/polyfill/array.d.ts +2 -0
- package/dist/polyfill/array.js +36 -0
- package/dist/polyfill/array.js.map +1 -0
- package/dist/polyfill/index.d.ts +2 -0
- package/dist/polyfill/index.js +20 -0
- package/dist/polyfill/index.js.map +1 -0
- package/dist/polyfill/intersection-observer.d.ts +1 -0
- package/dist/polyfill/intersection-observer.js +494 -0
- package/dist/polyfill/intersection-observer.js.map +1 -0
- package/dist/polyfill/object.d.ts +3 -0
- package/dist/polyfill/object.js +63 -0
- package/dist/polyfill/object.js.map +1 -0
- package/dist/runtime.esm.d.ts +35 -0
- package/dist/runtime.esm.js +3644 -0
- package/dist/runtime.esm.js.map +1 -0
- package/dist/utils/cache.d.ts +12 -0
- package/dist/utils/cache.js +26 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/index.d.ts +25 -0
- package/dist/utils/index.js +82 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/lodash.d.ts +2 -0
- package/dist/utils/lodash.js +33 -0
- package/dist/utils/lodash.js.map +1 -0
- package/dist/utils/router.d.ts +7 -0
- package/dist/utils/router.js +19 -0
- package/dist/utils/router.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/utils/cache.ts
|
|
2
|
+
/**
|
|
3
|
+
* 一个小型缓存池,用于在切换页面时,存储一些上下文信息
|
|
4
|
+
*/
|
|
5
|
+
var RuntimeCache = class {
|
|
6
|
+
constructor(name) {
|
|
7
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
8
|
+
this.name = name;
|
|
9
|
+
}
|
|
10
|
+
has(identifier) {
|
|
11
|
+
return this.cache.has(identifier);
|
|
12
|
+
}
|
|
13
|
+
set(identifier, ctx) {
|
|
14
|
+
if (identifier && ctx) this.cache.set(identifier, ctx);
|
|
15
|
+
}
|
|
16
|
+
get(identifier) {
|
|
17
|
+
if (this.has(identifier)) return this.cache.get(identifier);
|
|
18
|
+
}
|
|
19
|
+
delete(identifier) {
|
|
20
|
+
this.cache.delete(identifier);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { RuntimeCache };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","names":[],"sources":["../../src/utils/cache.ts"],"sourcesContent":["/**\n * 一个小型缓存池,用于在切换页面时,存储一些上下文信息\n */\n\nexport class RuntimeCache<T> {\n name: string;\n cache = new Map<string, T>();\n\n constructor(name: string) {\n this.name = name;\n }\n\n has(identifier: string) {\n return this.cache.has(identifier);\n }\n\n set(identifier: string, ctx: T) {\n if (identifier && ctx) {\n this.cache.set(identifier, ctx);\n }\n }\n\n get(identifier: string): T | undefined {\n if (this.has(identifier)) return this.cache.get(identifier);\n }\n\n delete(identifier: string) {\n this.cache.delete(identifier);\n }\n}\n"],"mappings":";;;;AAIA,IAAa,eAAb,MAA6B;CAI3B,YAAY,MAAc;+BAFlB,IAAI,IAAe;EAGzB,KAAK,OAAO;CACd;CAEA,IAAI,YAAoB;EACtB,OAAO,KAAK,MAAM,IAAI,UAAU;CAClC;CAEA,IAAI,YAAoB,KAAQ;EAC9B,IAAI,cAAc,KAChB,KAAK,MAAM,IAAI,YAAY,GAAG;CAElC;CAEA,IAAI,YAAmC;EACrC,IAAI,KAAK,IAAI,UAAU,GAAG,OAAO,KAAK,MAAM,IAAI,UAAU;CAC5D;CAEA,OAAO,YAAoB;EACzB,KAAK,MAAM,OAAO,UAAU;CAC9B;AACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { TaroElement } from '../dom/element';
|
|
2
|
+
import type { TaroNode } from '../dom/node';
|
|
3
|
+
import type { TaroText } from '../dom/text';
|
|
4
|
+
import type { TFunc } from '../interface';
|
|
5
|
+
export declare const incrementId: () => () => string;
|
|
6
|
+
export declare function isElement(node: TaroNode): node is TaroElement;
|
|
7
|
+
export declare function isText(node: TaroNode): node is TaroText;
|
|
8
|
+
export declare function isComment(node: TaroNode): boolean;
|
|
9
|
+
export declare function isHasExtractProp(el: TaroElement): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* 往上寻找组件树直到 root,寻找是否有祖先组件绑定了同类型的事件
|
|
12
|
+
* @param node 当前组件
|
|
13
|
+
* @param type 事件类型
|
|
14
|
+
*/
|
|
15
|
+
export declare function isParentBound(node: TaroElement | null, type: string): boolean;
|
|
16
|
+
export declare function shortcutAttr(key: string): string;
|
|
17
|
+
export declare const customWrapperCache: Map<string, Record<string, any>>;
|
|
18
|
+
interface Ctor {
|
|
19
|
+
new (...args: any[]): any;
|
|
20
|
+
}
|
|
21
|
+
export declare function extend(ctor: Ctor, methodName: string, options: TFunc | Record<string, any>): void;
|
|
22
|
+
export declare function getComponentsAlias(): any;
|
|
23
|
+
export declare function convertNumber2PX(value: number): string;
|
|
24
|
+
export * from './lodash';
|
|
25
|
+
export * from './router';
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { CLASS, COMMENT, STYLE } from "../constants/index.js";
|
|
2
|
+
import "./lodash.js";
|
|
3
|
+
import "./router.js";
|
|
4
|
+
import { Shortcuts, getComponentsAlias, internalComponents, isFunction } from "@spcsn/taro-shared";
|
|
5
|
+
//#region src/utils/index.ts
|
|
6
|
+
const incrementId = () => {
|
|
7
|
+
const chatCodes = [];
|
|
8
|
+
for (let i = 65; i <= 90; i++) chatCodes.push(i);
|
|
9
|
+
for (let i = 97; i <= 122; i++) chatCodes.push(i);
|
|
10
|
+
const chatCodesLen = chatCodes.length - 1;
|
|
11
|
+
const list = [0, 0];
|
|
12
|
+
return () => {
|
|
13
|
+
const target = list.map((item) => chatCodes[item]);
|
|
14
|
+
const res = String.fromCharCode(...target);
|
|
15
|
+
let tailIdx = list.length - 1;
|
|
16
|
+
list[tailIdx]++;
|
|
17
|
+
while (list[tailIdx] > chatCodesLen) {
|
|
18
|
+
list[tailIdx] = 0;
|
|
19
|
+
tailIdx = tailIdx - 1;
|
|
20
|
+
if (tailIdx < 0) {
|
|
21
|
+
list.push(0);
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
list[tailIdx]++;
|
|
25
|
+
}
|
|
26
|
+
return res;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
function isElement(node) {
|
|
30
|
+
return node.nodeType === 1;
|
|
31
|
+
}
|
|
32
|
+
function isText(node) {
|
|
33
|
+
return node.nodeType === 3;
|
|
34
|
+
}
|
|
35
|
+
function isComment(node) {
|
|
36
|
+
return node.nodeName === COMMENT;
|
|
37
|
+
}
|
|
38
|
+
function isHasExtractProp(el) {
|
|
39
|
+
const res = Object.keys(el.props).find((prop) => {
|
|
40
|
+
return !(/^(class|style|id)$/.test(prop) || prop.startsWith("data-"));
|
|
41
|
+
});
|
|
42
|
+
return Boolean(res);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 往上寻找组件树直到 root,寻找是否有祖先组件绑定了同类型的事件
|
|
46
|
+
* @param node 当前组件
|
|
47
|
+
* @param type 事件类型
|
|
48
|
+
*/
|
|
49
|
+
function isParentBound(node, type) {
|
|
50
|
+
while (node = node?.parentElement || null) if (!node || node.nodeName === "root" || node.nodeName === "root-portal") return false;
|
|
51
|
+
else if (node.__handlers[type]?.length) return true;
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
function shortcutAttr(key) {
|
|
55
|
+
switch (key) {
|
|
56
|
+
case STYLE: return Shortcuts.Style;
|
|
57
|
+
case "id": return "uid";
|
|
58
|
+
case CLASS: return Shortcuts.Class;
|
|
59
|
+
default: return key;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const customWrapperCache = /* @__PURE__ */ new Map();
|
|
63
|
+
function extend(ctor, methodName, options) {
|
|
64
|
+
if (isFunction(options)) options = { value: options };
|
|
65
|
+
Object.defineProperty(ctor.prototype, methodName, {
|
|
66
|
+
configurable: true,
|
|
67
|
+
enumerable: true,
|
|
68
|
+
...options
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
let componentsAlias;
|
|
72
|
+
function getComponentsAlias$1() {
|
|
73
|
+
if (!componentsAlias) componentsAlias = getComponentsAlias(internalComponents);
|
|
74
|
+
return componentsAlias;
|
|
75
|
+
}
|
|
76
|
+
function convertNumber2PX(value) {
|
|
77
|
+
return value + "px";
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
export { convertNumber2PX, customWrapperCache, extend, getComponentsAlias$1 as getComponentsAlias, incrementId, isComment, isElement, isHasExtractProp, isParentBound, isText, shortcutAttr };
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["getComponentsAlias","_getComponentsAlias"],"sources":["../../src/utils/index.ts"],"sourcesContent":["import {\n getComponentsAlias as _getComponentsAlias,\n internalComponents,\n isFunction,\n Shortcuts,\n} from '@spcsn/taro-shared';\n\nimport { CLASS, COMMENT, ID, ROOT_STR, STYLE, UID } from '../constants';\nimport { NodeType } from '../dom/node_types';\n\nimport type { TaroElement } from '../dom/element';\nimport type { TaroNode } from '../dom/node';\nimport type { TaroText } from '../dom/text';\nimport type { TFunc } from '../interface';\n\nexport const incrementId = () => {\n const chatCodes: number[] = [];\n // A-Z\n for (let i = 65; i <= 90; i++) {\n chatCodes.push(i);\n }\n // a-z\n for (let i = 97; i <= 122; i++) {\n chatCodes.push(i);\n }\n const chatCodesLen = chatCodes.length - 1;\n const list = [0, 0];\n return () => {\n const target = list.map((item) => chatCodes[item]);\n const res = String.fromCharCode(...target);\n\n let tailIdx = list.length - 1;\n\n list[tailIdx]++;\n\n while (list[tailIdx] > chatCodesLen) {\n list[tailIdx] = 0;\n tailIdx = tailIdx - 1;\n if (tailIdx < 0) {\n list.push(0);\n break;\n }\n list[tailIdx]++;\n }\n\n return res;\n };\n};\n\nexport function isElement(node: TaroNode): node is TaroElement {\n return node.nodeType === NodeType.ELEMENT_NODE;\n}\n\nexport function isText(node: TaroNode): node is TaroText {\n return node.nodeType === NodeType.TEXT_NODE;\n}\n\nexport function isComment(node: TaroNode): boolean {\n return node.nodeName === COMMENT;\n}\n\nexport function isHasExtractProp(el: TaroElement): boolean {\n const res = Object.keys(el.props).find((prop) => {\n return !(/^(class|style|id)$/.test(prop) || prop.startsWith('data-'));\n });\n return Boolean(res);\n}\n\n/**\n * 往上寻找组件树直到 root,寻找是否有祖先组件绑定了同类型的事件\n * @param node 当前组件\n * @param type 事件类型\n */\nexport function isParentBound(node: TaroElement | null, type: string): boolean {\n while ((node = node?.parentElement || null)) {\n if (!node || node.nodeName === ROOT_STR || node.nodeName === 'root-portal') {\n return false;\n } else if (node.__handlers[type]?.length) {\n return true;\n }\n }\n\n return false;\n}\n\nexport function shortcutAttr(key: string): string {\n switch (key) {\n case STYLE:\n return Shortcuts.Style;\n case ID:\n return UID;\n case CLASS:\n return Shortcuts.Class;\n default:\n return key;\n }\n}\n\nexport const customWrapperCache = new Map<string, Record<string, any>>();\n\ninterface Ctor {\n new (...args: any[]): any;\n}\n\nexport function extend(ctor: Ctor, methodName: string, options: TFunc | Record<string, any>) {\n if (isFunction(options)) {\n options = {\n value: options,\n };\n }\n Object.defineProperty(ctor.prototype, methodName, {\n configurable: true,\n enumerable: true,\n ...options,\n });\n}\n\nlet componentsAlias;\nexport function getComponentsAlias() {\n if (!componentsAlias) {\n componentsAlias = _getComponentsAlias(internalComponents);\n }\n return componentsAlias;\n}\n\nexport function convertNumber2PX(value: number) {\n return value + 'px';\n}\n\nexport * from './lodash';\nexport * from './router';\n"],"mappings":";;;;;AAeA,MAAa,oBAAoB;CAC/B,MAAM,YAAsB,CAAC;CAE7B,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,KACxB,UAAU,KAAK,CAAC;CAGlB,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,KACzB,UAAU,KAAK,CAAC;CAElB,MAAM,eAAe,UAAU,SAAS;CACxC,MAAM,OAAO,CAAC,GAAG,CAAC;CAClB,aAAa;EACX,MAAM,SAAS,KAAK,KAAK,SAAS,UAAU,KAAK;EACjD,MAAM,MAAM,OAAO,aAAa,GAAG,MAAM;EAEzC,IAAI,UAAU,KAAK,SAAS;EAE5B,KAAK;EAEL,OAAO,KAAK,WAAW,cAAc;GACnC,KAAK,WAAW;GAChB,UAAU,UAAU;GACpB,IAAI,UAAU,GAAG;IACf,KAAK,KAAK,CAAC;IACX;GACF;GACA,KAAK;EACP;EAEA,OAAO;CACT;AACF;AAEA,SAAgB,UAAU,MAAqC;CAC7D,OAAO,KAAK,aAAA;AACd;AAEA,SAAgB,OAAO,MAAkC;CACvD,OAAO,KAAK,aAAA;AACd;AAEA,SAAgB,UAAU,MAAyB;CACjD,OAAO,KAAK,aAAa;AAC3B;AAEA,SAAgB,iBAAiB,IAA0B;CACzD,MAAM,MAAM,OAAO,KAAK,GAAG,KAAK,EAAE,MAAM,SAAS;EAC/C,OAAO,EAAE,qBAAqB,KAAK,IAAI,KAAK,KAAK,WAAW,OAAO;CACrE,CAAC;CACD,OAAO,QAAQ,GAAG;AACpB;;;;;;AAOA,SAAgB,cAAc,MAA0B,MAAuB;CAC7E,OAAQ,OAAO,MAAM,iBAAiB,MACpC,IAAI,CAAC,QAAQ,KAAK,aAAA,UAAyB,KAAK,aAAa,eAC3D,OAAO;MACF,IAAI,KAAK,WAAW,OAAO,QAChC,OAAO;CAIX,OAAO;AACT;AAEA,SAAgB,aAAa,KAAqB;CAChD,QAAQ,KAAR;EACE,KAAK,OACH,OAAO,UAAU;EACnB,KAAA,MACE,OAAA;EACF,KAAK,OACH,OAAO,UAAU;EACnB,SACE,OAAO;CACX;AACF;AAEA,MAAa,qCAAqB,IAAI,IAAiC;AAMvE,SAAgB,OAAO,MAAY,YAAoB,SAAsC;CAC3F,IAAI,WAAW,OAAO,GACpB,UAAU,EACR,OAAO,QACT;CAEF,OAAO,eAAe,KAAK,WAAW,YAAY;EAChD,cAAc;EACd,YAAY;EACZ,GAAG;CACL,CAAC;AACH;AAEA,IAAI;AACJ,SAAgBA,uBAAqB;CACnC,IAAI,CAAC,iBACH,kBAAkBC,mBAAoB,kBAAkB;CAE1D,OAAO;AACT;AAEA,SAAgB,iBAAiB,OAAe;CAC9C,OAAO,QAAQ;AACjB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/utils/lodash.ts
|
|
2
|
+
function throttle(fn, threshold = 250, scope) {
|
|
3
|
+
let lastTime = 0;
|
|
4
|
+
let deferTimer;
|
|
5
|
+
return function(...args) {
|
|
6
|
+
const context = scope || this;
|
|
7
|
+
const now = Date.now();
|
|
8
|
+
if (now - lastTime > threshold) {
|
|
9
|
+
fn.apply(this, args);
|
|
10
|
+
lastTime = now;
|
|
11
|
+
} else {
|
|
12
|
+
clearTimeout(deferTimer);
|
|
13
|
+
deferTimer = setTimeout(() => {
|
|
14
|
+
lastTime = now;
|
|
15
|
+
fn.apply(context, args);
|
|
16
|
+
}, threshold);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function debounce(fn, ms = 250, scope) {
|
|
21
|
+
let timer;
|
|
22
|
+
return function(...args) {
|
|
23
|
+
const context = scope || this;
|
|
24
|
+
clearTimeout(timer);
|
|
25
|
+
timer = setTimeout(function() {
|
|
26
|
+
fn.apply(context, args);
|
|
27
|
+
}, ms);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { debounce, throttle };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=lodash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lodash.js","names":[],"sources":["../../src/utils/lodash.ts"],"sourcesContent":["export function throttle(fn, threshold = 250, scope?) {\n let lastTime = 0;\n let deferTimer: ReturnType<typeof setTimeout>;\n return function (...args) {\n const context = scope || this;\n const now = Date.now();\n if (now - lastTime > threshold) {\n fn.apply(this, args);\n lastTime = now;\n } else {\n clearTimeout(deferTimer);\n deferTimer = setTimeout(() => {\n lastTime = now;\n fn.apply(context, args);\n }, threshold);\n }\n };\n}\n\nexport function debounce(fn, ms = 250, scope?) {\n let timer: ReturnType<typeof setTimeout>;\n\n return function (...args) {\n const context = scope || this;\n clearTimeout(timer);\n timer = setTimeout(function () {\n fn.apply(context, args);\n }, ms);\n };\n}\n"],"mappings":";AAAA,SAAgB,SAAS,IAAI,YAAY,KAAK,OAAQ;CACpD,IAAI,WAAW;CACf,IAAI;CACJ,OAAO,SAAU,GAAG,MAAM;EACxB,MAAM,UAAU,SAAS;EACzB,MAAM,MAAM,KAAK,IAAI;EACrB,IAAI,MAAM,WAAW,WAAW;GAC9B,GAAG,MAAM,MAAM,IAAI;GACnB,WAAW;EACb,OAAO;GACL,aAAa,UAAU;GACvB,aAAa,iBAAiB;IAC5B,WAAW;IACX,GAAG,MAAM,SAAS,IAAI;GACxB,GAAG,SAAS;EACd;CACF;AACF;AAEA,SAAgB,SAAS,IAAI,KAAK,KAAK,OAAQ;CAC7C,IAAI;CAEJ,OAAO,SAAU,GAAG,MAAM;EACxB,MAAM,UAAU,SAAS;EACzB,aAAa,KAAK;EAClB,QAAQ,WAAW,WAAY;GAC7B,GAAG,MAAM,SAAS,IAAI;EACxB,GAAG,EAAE;CACP;AACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const addLeadingSlash: (url?: string) => string;
|
|
2
|
+
export declare const hasBasename: (path?: string, prefix?: string) => boolean;
|
|
3
|
+
export declare const stripBasename: (path?: string, prefix?: string) => string;
|
|
4
|
+
export declare const stripTrailing: (str?: string) => string;
|
|
5
|
+
export declare const stripSuffix: (path?: string, suffix?: string) => string;
|
|
6
|
+
export declare const getHomePage: (path?: string, basename?: string, customRoutes?: Record<string, string | string[]>, entryPagePath?: string) => string;
|
|
7
|
+
export declare const getCurrentPage: (routerMode?: string, basename?: string) => string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { taroLocationProvider } from "../bom/window.js";
|
|
2
|
+
//#region src/utils/router.ts
|
|
3
|
+
const addLeadingSlash = (url = "") => url.charAt(0) === "/" ? url : "/" + url;
|
|
4
|
+
const hasBasename = (path = "", prefix = "") => new RegExp("^" + prefix + "(\\/|\\?|#|$)", "i").test(path) || path === prefix;
|
|
5
|
+
const stripBasename = (path = "", prefix = "") => hasBasename(path, prefix) ? path.substring(prefix.length) : path;
|
|
6
|
+
const stripTrailing = (str = "") => str.replace(/[?#][\s\S]*$/, "");
|
|
7
|
+
const stripSuffix = (path = "", suffix = "") => path.includes(suffix) ? path.substring(0, path.length - suffix.length) : path;
|
|
8
|
+
const getHomePage = (path = "", basename = "", customRoutes = {}, entryPagePath = "") => {
|
|
9
|
+
const routePath = addLeadingSlash(stripBasename(path, basename));
|
|
10
|
+
const alias = Object.entries(customRoutes).find(([key]) => key === routePath)?.[1] || routePath;
|
|
11
|
+
return entryPagePath || (typeof alias === "string" ? alias : alias[0]) || basename;
|
|
12
|
+
};
|
|
13
|
+
const getCurrentPage = (routerMode = "hash", basename = "/") => {
|
|
14
|
+
return addLeadingSlash(stripBasename(routerMode === "hash" ? taroLocationProvider.hash.slice(1).split("?")[0] : taroLocationProvider.pathname, basename));
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { addLeadingSlash, getCurrentPage, getHomePage, hasBasename, stripBasename, stripSuffix, stripTrailing };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","names":["location"],"sources":["../../src/utils/router.ts"],"sourcesContent":["import { taroLocationProvider as location } from '../bom/window';\n\n// export const removeLeadingSlash = (str = '') => str.replace(/^\\.?\\//, '')\n// export const removeTrailingSearch = (str = '') => str.replace(/\\?[\\s\\S]*$/, '')\nexport const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);\n\nexport const hasBasename = (path = '', prefix = '') =>\n new RegExp('^' + prefix + '(\\\\/|\\\\?|#|$)', 'i').test(path) || path === prefix;\n\nexport const stripBasename = (path = '', prefix = '') =>\n hasBasename(path, prefix) ? path.substring(prefix.length) : path;\n\nexport const stripTrailing = (str = '') => str.replace(/[?#][\\s\\S]*$/, '');\n\nexport const stripSuffix = (path = '', suffix = '') =>\n path.includes(suffix) ? path.substring(0, path.length - suffix.length) : path;\n\nexport const getHomePage = (\n path = '',\n basename = '',\n customRoutes: Record<string, string | string[]> = {},\n entryPagePath = '',\n) => {\n const routePath = addLeadingSlash(stripBasename(path, basename));\n const alias = Object.entries(customRoutes).find(([key]) => key === routePath)?.[1] || routePath;\n return entryPagePath || (typeof alias === 'string' ? alias : alias[0]) || basename;\n};\n\nexport const getCurrentPage = (routerMode = 'hash', basename = '/') => {\n const pagePath = routerMode === 'hash' ? location.hash.slice(1).split('?')[0] : location.pathname;\n return addLeadingSlash(stripBasename(pagePath, basename));\n};\n"],"mappings":";;AAIA,MAAa,mBAAmB,MAAM,OAAQ,IAAI,OAAO,CAAC,MAAM,MAAM,MAAM,MAAM;AAElF,MAAa,eAAe,OAAO,IAAI,SAAS,OAC9C,IAAI,OAAO,MAAM,SAAS,iBAAiB,GAAG,EAAE,KAAK,IAAI,KAAK,SAAS;AAEzE,MAAa,iBAAiB,OAAO,IAAI,SAAS,OAChD,YAAY,MAAM,MAAM,IAAI,KAAK,UAAU,OAAO,MAAM,IAAI;AAE9D,MAAa,iBAAiB,MAAM,OAAO,IAAI,QAAQ,gBAAgB,EAAE;AAEzE,MAAa,eAAe,OAAO,IAAI,SAAS,OAC9C,KAAK,SAAS,MAAM,IAAI,KAAK,UAAU,GAAG,KAAK,SAAS,OAAO,MAAM,IAAI;AAE3E,MAAa,eACX,OAAO,IACP,WAAW,IACX,eAAkD,CAAC,GACnD,gBAAgB,OACb;CACH,MAAM,YAAY,gBAAgB,cAAc,MAAM,QAAQ,CAAC;CAC/D,MAAM,QAAQ,OAAO,QAAQ,YAAY,EAAE,MAAM,CAAC,SAAS,QAAQ,SAAS,IAAI,MAAM;CACtF,OAAO,kBAAkB,OAAO,UAAU,WAAW,QAAQ,MAAM,OAAO;AAC5E;AAEA,MAAa,kBAAkB,aAAa,QAAQ,WAAW,QAAQ;CAErE,OAAO,gBAAgB,cADN,eAAe,SAASA,qBAAS,KAAK,MAAM,CAAC,EAAE,MAAM,GAAG,EAAE,KAAKA,qBAAS,UAC1C,QAAQ,CAAC;AAC1D"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@spcsn/taro-runtime",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "taro runtime for mini apps.",
|
|
5
|
+
"author": "O2Team",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"browser": "dist/index.js",
|
|
8
|
+
"main:h5": "dist/runtime.esm.js",
|
|
9
|
+
"main": "dist/runtime.esm.js",
|
|
10
|
+
"module": "dist/runtime.esm.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"sideEffects": [
|
|
16
|
+
"./dist/dom-external/index.js"
|
|
17
|
+
],
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/NervJS/taro/tree/master/packages/taro-runtime"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">= 22"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"tslib": "^2.6.2",
|
|
27
|
+
"@spcsn/taro-shared": "0.1.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^22.19.19",
|
|
31
|
+
"lodash": "^4.17.21",
|
|
32
|
+
"typescript": "~6.0.3"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"prod": "pnpm run build",
|
|
36
|
+
"prebuild": "pnpm run clean",
|
|
37
|
+
"build": "pnpm run build:types && pnpm run rolldown --environment NODE_ENV:production",
|
|
38
|
+
"build:types": "tsc --emitDeclarationOnly --declaration --noCheck && node ./scripts/copy-entry-types.mjs",
|
|
39
|
+
"clean": "rimraf ./dist",
|
|
40
|
+
"dev": "concurrently \"pnpm run build:types -- --watch\" \"pnpm run rolldown --environment NODE_ENV:development -w\"",
|
|
41
|
+
"rolldown": "rolldown --config rolldown.config.mjs",
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"test:ci": "vitest run --coverage"
|
|
44
|
+
}
|
|
45
|
+
}
|