@studiometa/js-toolkit 3.5.0 → 3.6.0-beta.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/Base/Base.d.ts +2 -2
- package/Base/managers/AbstractManager.d.ts +2 -2
- package/Base/utils.d.ts +1 -1
- package/Base/utils.js +1 -2
- package/Base/utils.js.map +2 -2
- package/helpers/createApp.js +5 -0
- package/helpers/createApp.js.map +2 -2
- package/helpers/index.d.ts +1 -0
- package/helpers/index.js +1 -0
- package/helpers/index.js.map +2 -2
- package/helpers/logTree.d.ts +17 -0
- package/helpers/logTree.js +59 -0
- package/helpers/logTree.js.map +7 -0
- package/helpers/queryComponent.js +9 -10
- package/helpers/queryComponent.js.map +2 -2
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/services/AbstractService.d.ts +1 -1
- package/services/AbstractService.js +1 -1
- package/services/AbstractService.js.map +2 -2
- package/services/DragService.d.ts +5 -5
- package/services/RafService.d.ts +1 -1
- package/services/RafService.js +13 -7
- package/services/RafService.js.map +2 -2
- package/services/ScrollService.d.ts +21 -3
- package/services/ScrollService.js +55 -7
- package/services/ScrollService.js.map +2 -2
- package/utils/collide/boundingRectToCircle.d.ts +2 -2
- package/utils/css/animate.js +166 -96
- package/utils/css/animate.js.map +2 -2
- package/utils/css/transform.js +12 -13
- package/utils/css/transform.js.map +2 -2
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/index.js.map +2 -2
- package/utils/math/smoothTo.d.ts +24 -6
- package/utils/memoize.d.ts +1 -1
- package/utils/object/getAllProperties.js +4 -2
- package/utils/object/getAllProperties.js.map +2 -2
- package/utils/scheduler.d.ts +1 -1
- package/utils/storage/createLocalStorageProvider.d.ts +2 -0
- package/utils/storage/createLocalStorageProvider.js +32 -0
- package/utils/storage/createLocalStorageProvider.js.map +7 -0
- package/utils/storage/createMemoryStorageProvider.d.ts +2 -0
- package/utils/storage/createMemoryStorageProvider.js +27 -0
- package/utils/storage/createMemoryStorageProvider.js.map +7 -0
- package/utils/storage/createNoopProvider.d.ts +2 -0
- package/utils/storage/createNoopProvider.js +23 -0
- package/utils/storage/createNoopProvider.js.map +7 -0
- package/utils/storage/createSessionStorageProvider.d.ts +2 -0
- package/utils/storage/createSessionStorageProvider.js +31 -0
- package/utils/storage/createSessionStorageProvider.js.map +7 -0
- package/utils/storage/createStorage.d.ts +2 -0
- package/utils/storage/createStorage.js +100 -0
- package/utils/storage/createStorage.js.map +7 -0
- package/utils/storage/createUrlSearchParamsInHashProvider.d.ts +2 -0
- package/utils/storage/createUrlSearchParamsInHashProvider.js +57 -0
- package/utils/storage/createUrlSearchParamsInHashProvider.js.map +7 -0
- package/utils/storage/createUrlSearchParamsProvider.d.ts +2 -0
- package/utils/storage/createUrlSearchParamsProvider.js +41 -0
- package/utils/storage/createUrlSearchParamsProvider.js.map +7 -0
- package/utils/storage/getBrowserContext.d.ts +1 -0
- package/utils/storage/getBrowserContext.js +17 -0
- package/utils/storage/getBrowserContext.js.map +7 -0
- package/utils/storage/getGlobalStorage.d.ts +1 -0
- package/utils/storage/getGlobalStorage.js +7 -0
- package/utils/storage/getGlobalStorage.js.map +7 -0
- package/utils/storage/getStorageKeys.d.ts +1 -0
- package/utils/storage/getStorageKeys.js +12 -0
- package/utils/storage/getStorageKeys.js.map +7 -0
- package/utils/storage/index.d.ts +8 -0
- package/utils/storage/index.js +62 -0
- package/utils/storage/index.js.map +7 -0
- package/utils/storage/providers.d.ts +11 -0
- package/utils/storage/providers.js +30 -0
- package/utils/storage/providers.js.map +7 -0
- package/utils/storage/serializers.d.ts +2 -0
- package/utils/storage/serializers.js +14 -0
- package/utils/storage/serializers.js.map +7 -0
- package/utils/storage/types.d.ts +33 -0
- package/utils/storage/types.js +1 -0
- package/utils/storage/types.js.map +7 -0
- package/utils/storage.d.ts +1 -0
- package/utils/storage.js +2 -0
- package/utils/storage.js.map +7 -0
- package/utils/string/changeCase.js +1 -1
- package/utils/string/changeCase.js.map +2 -2
- package/utils/tween.js +5 -5
- package/utils/tween.js.map +2 -2
- package/tsconfig.build.tsbuildinfo +0 -1
package/utils/css/transform.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { isDefined } from "../is.js";
|
|
2
1
|
import { eachElements } from "./utils.js";
|
|
3
2
|
const TRANSFORM_PROPS = [
|
|
4
3
|
"x",
|
|
@@ -19,42 +18,42 @@ const TRANSFORM_PROPS = [
|
|
|
19
18
|
function transform(elementOrElements, props) {
|
|
20
19
|
if (!elementOrElements) return;
|
|
21
20
|
let value = "";
|
|
22
|
-
if (
|
|
21
|
+
if (props.x !== void 0 || props.y !== void 0 || props.z !== void 0) {
|
|
23
22
|
value += `translate3d(${props.x ?? 0}px, ${props.y ?? 0}px, ${props.z ?? 0}px) `;
|
|
24
23
|
}
|
|
25
|
-
if (
|
|
24
|
+
if (props.rotate !== void 0) {
|
|
26
25
|
value += `rotate(${props.rotate}deg) `;
|
|
27
26
|
} else {
|
|
28
|
-
if (
|
|
27
|
+
if (props.rotateX !== void 0) {
|
|
29
28
|
value += `rotateX(${props.rotateX}deg) `;
|
|
30
29
|
}
|
|
31
|
-
if (
|
|
30
|
+
if (props.rotateY !== void 0) {
|
|
32
31
|
value += `rotateY(${props.rotateY}deg) `;
|
|
33
32
|
}
|
|
34
|
-
if (
|
|
33
|
+
if (props.rotateZ !== void 0) {
|
|
35
34
|
value += `rotateZ(${props.rotateZ}deg) `;
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
|
-
if (
|
|
37
|
+
if (props.scale !== void 0) {
|
|
39
38
|
value += `scale(${props.scale}) `;
|
|
40
39
|
} else {
|
|
41
|
-
if (
|
|
40
|
+
if (props.scaleX !== void 0) {
|
|
42
41
|
value += `scaleX(${props.scaleX}) `;
|
|
43
42
|
}
|
|
44
|
-
if (
|
|
43
|
+
if (props.scaleY !== void 0) {
|
|
45
44
|
value += `scaleY(${props.scaleY}) `;
|
|
46
45
|
}
|
|
47
|
-
if (
|
|
46
|
+
if (props.scaleZ !== void 0) {
|
|
48
47
|
value += `scaleZ(${props.scaleZ}) `;
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
|
-
if (
|
|
50
|
+
if (props.skew !== void 0) {
|
|
52
51
|
value += `skew(${props.skew}deg) `;
|
|
53
52
|
} else {
|
|
54
|
-
if (
|
|
53
|
+
if (props.skewX !== void 0) {
|
|
55
54
|
value += `skewX(${props.skewX}deg) `;
|
|
56
55
|
}
|
|
57
|
-
if (
|
|
56
|
+
if (props.skewY !== void 0) {
|
|
58
57
|
value += `skewY(${props.skewY}deg) `;
|
|
59
58
|
}
|
|
60
59
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/js-toolkit/utils/css/transform.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["// eslint-disable-next-line import/extensions\nimport { eachElements } from './utils.js';\n\nexport type TransformProps = Partial<{\n x: number;\n y: number;\n z: number;\n rotate: number;\n rotateX: number;\n rotateY: number;\n rotateZ: number;\n scale: number;\n scaleX: number;\n scaleY: number;\n scaleZ: number;\n skew: number;\n skewX: number;\n skewY: number;\n}>;\n\nexport const TRANSFORM_PROPS = [\n 'x',\n 'y',\n 'z',\n 'rotate',\n 'rotateX',\n 'rotateY',\n 'rotateZ',\n 'scale',\n 'scaleX',\n 'scaleY',\n 'scaleZ',\n 'skew',\n 'skewX',\n 'skewY',\n];\n\n/**\n * Generate a CSS transform.\n * @link https://js-toolkit.studiometa.dev/utils/css/transform.html\n*/\nexport function transform(\n elementOrElements: HTMLElement | HTMLElement[] | NodeListOf<HTMLElement>,\n props: TransformProps,\n): string {\n if (!elementOrElements) return\n\n let value = '';\n\n if (props.x !== undefined || props.y !== undefined || props.z !== undefined) {\n value += `translate3d(${props.x ?? 0}px, ${props.y ?? 0}px, ${props.z ?? 0}px) `;\n }\n\n if (props.rotate !== undefined) {\n value += `rotate(${props.rotate}deg) `;\n } else {\n if (props.rotateX !== undefined) {\n value += `rotateX(${props.rotateX}deg) `;\n }\n\n if (props.rotateY !== undefined) {\n value += `rotateY(${props.rotateY}deg) `;\n }\n\n if (props.rotateZ !== undefined) {\n value += `rotateZ(${props.rotateZ}deg) `;\n }\n }\n\n if (props.scale !== undefined) {\n value += `scale(${props.scale}) `;\n } else {\n if (props.scaleX !== undefined) {\n value += `scaleX(${props.scaleX}) `;\n }\n\n if (props.scaleY !== undefined) {\n value += `scaleY(${props.scaleY}) `;\n }\n\n if (props.scaleZ !== undefined) {\n value += `scaleZ(${props.scaleZ}) `;\n }\n }\n\n if (props.skew !== undefined) {\n value += `skew(${props.skew}deg) `;\n } else {\n if (props.skewX !== undefined) {\n value += `skewX(${props.skewX}deg) `;\n }\n\n if (props.skewY !== undefined) {\n value += `skewY(${props.skewY}deg) `;\n }\n }\n\n eachElements(elementOrElements, (element) => {\n element.style.transform = value;\n });\n return value;\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,oBAAoB;AAmBtB,MAAM,kBAAkB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAMO,SAAS,UACd,mBACA,OACQ;AACR,MAAI,CAAC,kBAAmB;AAExB,MAAI,QAAQ;AAEZ,MAAI,MAAM,MAAM,UAAa,MAAM,MAAM,UAAa,MAAM,MAAM,QAAW;AAC3E,aAAS,eAAe,MAAM,KAAK,CAAC,OAAO,MAAM,KAAK,CAAC,OAAO,MAAM,KAAK,CAAC;AAAA,EAC5E;AAEA,MAAI,MAAM,WAAW,QAAW;AAC9B,aAAS,UAAU,MAAM,MAAM;AAAA,EACjC,OAAO;AACL,QAAI,MAAM,YAAY,QAAW;AAC/B,eAAS,WAAW,MAAM,OAAO;AAAA,IACnC;AAEA,QAAI,MAAM,YAAY,QAAW;AAC/B,eAAS,WAAW,MAAM,OAAO;AAAA,IACnC;AAEA,QAAI,MAAM,YAAY,QAAW;AAC/B,eAAS,WAAW,MAAM,OAAO;AAAA,IACnC;AAAA,EACF;AAEA,MAAI,MAAM,UAAU,QAAW;AAC7B,aAAS,SAAS,MAAM,KAAK;AAAA,EAC/B,OAAO;AACL,QAAI,MAAM,WAAW,QAAW;AAC9B,eAAS,UAAU,MAAM,MAAM;AAAA,IACjC;AAEA,QAAI,MAAM,WAAW,QAAW;AAC9B,eAAS,UAAU,MAAM,MAAM;AAAA,IACjC;AAEA,QAAI,MAAM,WAAW,QAAW;AAC9B,eAAS,UAAU,MAAM,MAAM;AAAA,IACjC;AAAA,EACF;AAEA,MAAI,MAAM,SAAS,QAAW;AAC5B,aAAS,QAAQ,MAAM,IAAI;AAAA,EAC7B,OAAO;AACL,QAAI,MAAM,UAAU,QAAW;AAC7B,eAAS,SAAS,MAAM,KAAK;AAAA,IAC/B;AAEA,QAAI,MAAM,UAAU,QAAW;AAC7B,eAAS,SAAS,MAAM,KAAK;AAAA,IAC/B;AAAA,EACF;AAEA,eAAa,mBAAmB,CAAC,YAAY;AAC3C,YAAQ,MAAM,YAAY;AAAA,EAC5B,CAAC;AACD,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/utils/index.d.ts
CHANGED
package/utils/index.js
CHANGED
package/utils/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/utils/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { debounce } from './debounce.js';\nexport * from './trapFocus.js';\nexport { keyCodes } from './keyCodes.js';\nexport { memoize } from './memoize.js';\nexport { nextFrame } from './nextFrame.js';\nexport { nextTick } from './nextTick.js';\nexport { nextMicrotask } from './nextMicrotask.js';\nexport { throttle } from './throttle.js';\nexport { scrollTo } from './scrollTo.js';\nexport { getComponentResolver } from './getComponentResolver.js';\nexport * from './is.js';\nexport * from './has.js';\nexport * from './css/index.js';\nexport {\n objectToURLSearchParams,\n push as historyPush,\n replace as historyReplace,\n} from './history.js';\nexport * from './collide/index.js';\nexport * from './math/index.js';\nexport * from './string/index.js';\nexport * from './scheduler.js';\nexport * from './noop.js';\nexport { tween } from './tween.js';\nexport { Queue } from './Queue.js';\nexport { SmartQueue } from './SmartQueue.js';\nexport * from './dom/index.js';\nexport * from './wait.js';\nexport * from './random.js';\nexport * from './memo.js';\nexport * from './loadElement.js';\nexport * from './cache.js';\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,gBAAgB;AACzB,cAAc;AACd,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,4BAA4B;AACrC,cAAc;AACd,cAAc;AACd,cAAc;AACd;AAAA,EACE;AAAA,EACQ;AAAA,EACG;AAAA,OACN;AACP,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,aAAa;AACtB,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAC3B,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
4
|
+
"sourcesContent": ["export { debounce } from './debounce.js';\nexport * from './trapFocus.js';\nexport { keyCodes } from './keyCodes.js';\nexport { memoize } from './memoize.js';\nexport { nextFrame } from './nextFrame.js';\nexport { nextTick } from './nextTick.js';\nexport { nextMicrotask } from './nextMicrotask.js';\nexport { throttle } from './throttle.js';\nexport { scrollTo } from './scrollTo.js';\nexport { getComponentResolver } from './getComponentResolver.js';\nexport * from './is.js';\nexport * from './has.js';\nexport * from './css/index.js';\nexport {\n objectToURLSearchParams,\n push as historyPush,\n replace as historyReplace,\n} from './history.js';\nexport * from './collide/index.js';\nexport * from './math/index.js';\nexport * from './string/index.js';\nexport * from './scheduler.js';\nexport * from './noop.js';\nexport { tween } from './tween.js';\nexport { Queue } from './Queue.js';\nexport { SmartQueue } from './SmartQueue.js';\nexport * from './dom/index.js';\nexport * from './wait.js';\nexport * from './random.js';\nexport * from './memo.js';\nexport * from './loadElement.js';\nexport * from './cache.js';\nexport * from './storage.js';\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,gBAAgB;AACzB,cAAc;AACd,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,4BAA4B;AACrC,cAAc;AACd,cAAc;AACd,cAAc;AACd;AAAA,EACE;AAAA,EACQ;AAAA,EACG;AAAA,OACN;AACP,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,aAAa;AACtB,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAC3B,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/utils/math/smoothTo.d.ts
CHANGED
|
@@ -42,10 +42,28 @@ export declare function smoothTo(start?: number, options?: SmoothToOptions): {
|
|
|
42
42
|
* Unsubscribe a callback from the value update.
|
|
43
43
|
*/
|
|
44
44
|
unsubscribe: (fn: (value: number) => any) => boolean;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Get the raw target value.
|
|
47
|
+
*/
|
|
48
|
+
raw: () => number;
|
|
49
|
+
/**
|
|
50
|
+
* Add the given value to the current raw value.
|
|
51
|
+
*/
|
|
52
|
+
add: (val: number) => number;
|
|
53
|
+
/**
|
|
54
|
+
* Get or set the damping factor.
|
|
55
|
+
*/
|
|
56
|
+
damping: (val?: number) => number;
|
|
57
|
+
/**
|
|
58
|
+
* Get or set the precision.
|
|
59
|
+
*/
|
|
60
|
+
precision: (val?: number) => number;
|
|
61
|
+
/**
|
|
62
|
+
* Get or set the stiffness factor.
|
|
63
|
+
*/
|
|
64
|
+
stiffness: (val?: number) => number;
|
|
65
|
+
/**
|
|
66
|
+
* Get or set the spring option.
|
|
67
|
+
*/
|
|
68
|
+
spring: (val?: boolean) => boolean;
|
|
51
69
|
};
|
package/utils/memoize.d.ts
CHANGED
|
@@ -18,4 +18,4 @@ export interface MemoizeOptions<T> {
|
|
|
18
18
|
* Memoize the output of a function.
|
|
19
19
|
* @link https://js-toolkit.studiometa.dev/utils/memoize.html
|
|
20
20
|
*/
|
|
21
|
-
export declare function memoize<T extends (...args: unknown[]) => unknown>(fn: T, { maxAge, cacheKey, cache
|
|
21
|
+
export declare function memoize<T extends (...args: unknown[]) => unknown>(fn: T, { maxAge, cacheKey, cache }?: MemoizeOptions<ReturnType<T>>): (...args: Parameters<T>) => ReturnType<T>;
|
|
@@ -8,8 +8,10 @@ function getAllProperties(object, props = [], testFn = null) {
|
|
|
8
8
|
if (isFunction(testFn)) {
|
|
9
9
|
foundProps = foundProps.filter((name) => testFn(name, proto));
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
for (const name of foundProps) {
|
|
12
|
+
props.push([name, proto]);
|
|
13
|
+
}
|
|
14
|
+
return getAllProperties(proto, props, testFn);
|
|
13
15
|
}
|
|
14
16
|
export {
|
|
15
17
|
getAllProperties
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/js-toolkit/utils/object/getAllProperties.ts"],
|
|
4
|
-
"sourcesContent": ["import { isFunction } from '../is.js';\n\n/**\n * Gets all non-builtin properties up the prototype chain.\n *\n * @param {Object} object\n * The object to get the propeties from.\n * @param {Array} [props=[]]\n * The already existing properties.\n * @param {(name:string, proto:any) => boolean} testFn\n * @return {Array<[string, Object]>} An array of properties and the prototype they belong to.\n */\nexport function getAllProperties(\n object: unknown,\n props: Array<[string, unknown]> = [],\n testFn: (name: string, proto: unknown) => boolean = null,\n): Array<[string, unknown]> {\n const proto = Object.getPrototypeOf(object);\n\n if (proto === Object.prototype || proto === null) {\n return props;\n }\n\n let foundProps = Object.getOwnPropertyNames(proto);\n\n if (isFunction(testFn)) {\n foundProps = foundProps.filter((name) => testFn(name, proto));\n }\n\n const
|
|
5
|
-
"mappings": "AAAA,SAAS,kBAAkB;AAYpB,SAAS,iBACd,QACA,QAAkC,CAAC,GACnC,SAAoD,MAC1B;AAC1B,QAAM,QAAQ,OAAO,eAAe,MAAM;AAE1C,MAAI,UAAU,OAAO,aAAa,UAAU,MAAM;AAChD,WAAO;AAAA,EACT;AAEA,MAAI,aAAa,OAAO,oBAAoB,KAAK;AAEjD,MAAI,WAAW,MAAM,GAAG;AACtB,iBAAa,WAAW,OAAO,CAAC,SAAS,OAAO,MAAM,KAAK,CAAC;AAAA,EAC9D;AAEA,
|
|
4
|
+
"sourcesContent": ["import { isFunction } from '../is.js';\n\n/**\n * Gets all non-builtin properties up the prototype chain.\n *\n * @param {Object} object\n * The object to get the propeties from.\n * @param {Array} [props=[]]\n * The already existing properties.\n * @param {(name:string, proto:any) => boolean} testFn\n * @return {Array<[string, Object]>} An array of properties and the prototype they belong to.\n */\nexport function getAllProperties(\n object: unknown,\n props: Array<[string, unknown]> = [],\n testFn: (name: string, proto: unknown) => boolean = null,\n): Array<[string, unknown]> {\n const proto = Object.getPrototypeOf(object);\n\n if (proto === Object.prototype || proto === null) {\n return props;\n }\n\n let foundProps = Object.getOwnPropertyNames(proto);\n\n if (isFunction(testFn)) {\n foundProps = foundProps.filter((name) => testFn(name, proto));\n }\n\n for (const name of foundProps) {\n props.push([name, proto]);\n }\n\n return getAllProperties(proto, props, testFn);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAYpB,SAAS,iBACd,QACA,QAAkC,CAAC,GACnC,SAAoD,MAC1B;AAC1B,QAAM,QAAQ,OAAO,eAAe,MAAM;AAE1C,MAAI,UAAU,OAAO,aAAa,UAAU,MAAM;AAChD,WAAO;AAAA,EACT;AAEA,MAAI,aAAa,OAAO,oBAAoB,KAAK;AAEjD,MAAI,WAAW,MAAM,GAAG;AACtB,iBAAa,WAAW,OAAO,CAAC,SAAS,OAAO,MAAM,KAAK,CAAC;AAAA,EAC9D;AAEA,aAAW,QAAQ,YAAY;AAC7B,UAAM,KAAK,CAAC,MAAM,KAAK,CAAC;AAAA,EAC1B;AAEA,SAAO,iBAAiB,OAAO,OAAO,MAAM;AAC9C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/utils/scheduler.d.ts
CHANGED
|
@@ -11,5 +11,5 @@ export declare function useScheduler<T extends string>(steps?: T[]): ReturnType<
|
|
|
11
11
|
* DOM-oriented scheduler using read/write/afterWrite steps.
|
|
12
12
|
* @link https://js-toolkit.studiometa.dev/utils/domScheduler.html
|
|
13
13
|
*/
|
|
14
|
-
export declare const domScheduler: Record<"
|
|
14
|
+
export declare const domScheduler: Record<"afterWrite" | "read" | "write", (fn: () => unknown) => void>;
|
|
15
15
|
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getGlobalStorage } from "./getGlobalStorage.js";
|
|
2
|
+
import { getStorageKeys } from "./getStorageKeys.js";
|
|
3
|
+
function createLocalStorageProvider() {
|
|
4
|
+
return {
|
|
5
|
+
syncEvent: "storage",
|
|
6
|
+
get storageArea() {
|
|
7
|
+
return getGlobalStorage("localStorage");
|
|
8
|
+
},
|
|
9
|
+
get(key) {
|
|
10
|
+
return getGlobalStorage("localStorage")?.getItem(key) ?? null;
|
|
11
|
+
},
|
|
12
|
+
set(key, value) {
|
|
13
|
+
getGlobalStorage("localStorage")?.setItem(key, value);
|
|
14
|
+
},
|
|
15
|
+
remove(key) {
|
|
16
|
+
getGlobalStorage("localStorage")?.removeItem(key);
|
|
17
|
+
},
|
|
18
|
+
has(key) {
|
|
19
|
+
return getGlobalStorage("localStorage")?.getItem(key) !== null;
|
|
20
|
+
},
|
|
21
|
+
keys() {
|
|
22
|
+
return getStorageKeys(getGlobalStorage("localStorage"));
|
|
23
|
+
},
|
|
24
|
+
clear() {
|
|
25
|
+
getGlobalStorage("localStorage")?.clear();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
createLocalStorageProvider
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=createLocalStorageProvider.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/js-toolkit/utils/storage/createLocalStorageProvider.ts"],
|
|
4
|
+
"sourcesContent": ["import type { StorageProvider } from './types.js';\nimport { getGlobalStorage } from './getGlobalStorage.js';\nimport { getStorageKeys } from './getStorageKeys.js';\n\nexport function createLocalStorageProvider(): StorageProvider {\n return {\n syncEvent: 'storage',\n get storageArea() {\n return getGlobalStorage('localStorage');\n },\n get(key) {\n return getGlobalStorage('localStorage')?.getItem(key) ?? null;\n },\n set(key, value) {\n getGlobalStorage('localStorage')?.setItem(key, value);\n },\n remove(key) {\n getGlobalStorage('localStorage')?.removeItem(key);\n },\n has(key) {\n return getGlobalStorage('localStorage')?.getItem(key) !== null;\n },\n keys() {\n return getStorageKeys(getGlobalStorage('localStorage'));\n },\n clear() {\n getGlobalStorage('localStorage')?.clear();\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAExB,SAAS,6BAA8C;AAC5D,SAAO;AAAA,IACL,WAAW;AAAA,IACX,IAAI,cAAc;AAChB,aAAO,iBAAiB,cAAc;AAAA,IACxC;AAAA,IACA,IAAI,KAAK;AACP,aAAO,iBAAiB,cAAc,GAAG,QAAQ,GAAG,KAAK;AAAA,IAC3D;AAAA,IACA,IAAI,KAAK,OAAO;AACd,uBAAiB,cAAc,GAAG,QAAQ,KAAK,KAAK;AAAA,IACtD;AAAA,IACA,OAAO,KAAK;AACV,uBAAiB,cAAc,GAAG,WAAW,GAAG;AAAA,IAClD;AAAA,IACA,IAAI,KAAK;AACP,aAAO,iBAAiB,cAAc,GAAG,QAAQ,GAAG,MAAM;AAAA,IAC5D;AAAA,IACA,OAAO;AACL,aAAO,eAAe,iBAAiB,cAAc,CAAC;AAAA,IACxD;AAAA,IACA,QAAQ;AACN,uBAAiB,cAAc,GAAG,MAAM;AAAA,IAC1C;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
function createMemoryStorageProvider() {
|
|
2
|
+
const map = /* @__PURE__ */ new Map();
|
|
3
|
+
return {
|
|
4
|
+
get(key) {
|
|
5
|
+
return map.get(key) ?? null;
|
|
6
|
+
},
|
|
7
|
+
set(key, value) {
|
|
8
|
+
map.set(key, value);
|
|
9
|
+
},
|
|
10
|
+
remove(key) {
|
|
11
|
+
map.delete(key);
|
|
12
|
+
},
|
|
13
|
+
has(key) {
|
|
14
|
+
return map.has(key);
|
|
15
|
+
},
|
|
16
|
+
keys() {
|
|
17
|
+
return [...map.keys()];
|
|
18
|
+
},
|
|
19
|
+
clear() {
|
|
20
|
+
map.clear();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
createMemoryStorageProvider
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=createMemoryStorageProvider.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/js-toolkit/utils/storage/createMemoryStorageProvider.ts"],
|
|
4
|
+
"sourcesContent": ["import type { StorageProvider } from './types.js';\n\nexport function createMemoryStorageProvider(): StorageProvider {\n const map = new Map<string, string>();\n\n return {\n get(key) {\n return map.get(key) ?? null;\n },\n set(key, value) {\n map.set(key, value);\n },\n remove(key) {\n map.delete(key);\n },\n has(key) {\n return map.has(key);\n },\n keys() {\n return [...map.keys()];\n },\n clear() {\n map.clear();\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "AAEO,SAAS,8BAA+C;AAC7D,QAAM,MAAM,oBAAI,IAAoB;AAEpC,SAAO;AAAA,IACL,IAAI,KAAK;AACP,aAAO,IAAI,IAAI,GAAG,KAAK;AAAA,IACzB;AAAA,IACA,IAAI,KAAK,OAAO;AACd,UAAI,IAAI,KAAK,KAAK;AAAA,IACpB;AAAA,IACA,OAAO,KAAK;AACV,UAAI,OAAO,GAAG;AAAA,IAChB;AAAA,IACA,IAAI,KAAK;AACP,aAAO,IAAI,IAAI,GAAG;AAAA,IACpB;AAAA,IACA,OAAO;AACL,aAAO,CAAC,GAAG,IAAI,KAAK,CAAC;AAAA,IACvB;AAAA,IACA,QAAQ;AACN,UAAI,MAAM;AAAA,IACZ;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
function createNoopProvider() {
|
|
2
|
+
return {
|
|
3
|
+
get() {
|
|
4
|
+
return null;
|
|
5
|
+
},
|
|
6
|
+
set() {
|
|
7
|
+
},
|
|
8
|
+
remove() {
|
|
9
|
+
},
|
|
10
|
+
has() {
|
|
11
|
+
return false;
|
|
12
|
+
},
|
|
13
|
+
keys() {
|
|
14
|
+
return [];
|
|
15
|
+
},
|
|
16
|
+
clear() {
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
createNoopProvider
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=createNoopProvider.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/js-toolkit/utils/storage/createNoopProvider.ts"],
|
|
4
|
+
"sourcesContent": ["import type { StorageProvider } from './types.js';\n\nexport function createNoopProvider(): StorageProvider {\n return {\n get() {\n return null;\n },\n set() {},\n remove() {},\n has() {\n return false;\n },\n keys() {\n return [];\n },\n clear() {},\n };\n}\n"],
|
|
5
|
+
"mappings": "AAEO,SAAS,qBAAsC;AACpD,SAAO;AAAA,IACL,MAAM;AACJ,aAAO;AAAA,IACT;AAAA,IACA,MAAM;AAAA,IAAC;AAAA,IACP,SAAS;AAAA,IAAC;AAAA,IACV,MAAM;AACJ,aAAO;AAAA,IACT;AAAA,IACA,OAAO;AACL,aAAO,CAAC;AAAA,IACV;AAAA,IACA,QAAQ;AAAA,IAAC;AAAA,EACX;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getGlobalStorage } from "./getGlobalStorage.js";
|
|
2
|
+
import { getStorageKeys } from "./getStorageKeys.js";
|
|
3
|
+
function createSessionStorageProvider() {
|
|
4
|
+
return {
|
|
5
|
+
get storageArea() {
|
|
6
|
+
return getGlobalStorage("sessionStorage");
|
|
7
|
+
},
|
|
8
|
+
get(key) {
|
|
9
|
+
return getGlobalStorage("sessionStorage")?.getItem(key) ?? null;
|
|
10
|
+
},
|
|
11
|
+
set(key, value) {
|
|
12
|
+
getGlobalStorage("sessionStorage")?.setItem(key, value);
|
|
13
|
+
},
|
|
14
|
+
remove(key) {
|
|
15
|
+
getGlobalStorage("sessionStorage")?.removeItem(key);
|
|
16
|
+
},
|
|
17
|
+
has(key) {
|
|
18
|
+
return getGlobalStorage("sessionStorage")?.getItem(key) !== null;
|
|
19
|
+
},
|
|
20
|
+
keys() {
|
|
21
|
+
return getStorageKeys(getGlobalStorage("sessionStorage"));
|
|
22
|
+
},
|
|
23
|
+
clear() {
|
|
24
|
+
getGlobalStorage("sessionStorage")?.clear();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
createSessionStorageProvider
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=createSessionStorageProvider.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/js-toolkit/utils/storage/createSessionStorageProvider.ts"],
|
|
4
|
+
"sourcesContent": ["import type { StorageProvider } from './types.js';\nimport { getGlobalStorage } from './getGlobalStorage.js';\nimport { getStorageKeys } from './getStorageKeys.js';\n\nexport function createSessionStorageProvider(): StorageProvider {\n return {\n get storageArea() {\n return getGlobalStorage('sessionStorage');\n },\n get(key) {\n return getGlobalStorage('sessionStorage')?.getItem(key) ?? null;\n },\n set(key, value) {\n getGlobalStorage('sessionStorage')?.setItem(key, value);\n },\n remove(key) {\n getGlobalStorage('sessionStorage')?.removeItem(key);\n },\n has(key) {\n return getGlobalStorage('sessionStorage')?.getItem(key) !== null;\n },\n keys() {\n return getStorageKeys(getGlobalStorage('sessionStorage'));\n },\n clear() {\n getGlobalStorage('sessionStorage')?.clear();\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAExB,SAAS,+BAAgD;AAC9D,SAAO;AAAA,IACL,IAAI,cAAc;AAChB,aAAO,iBAAiB,gBAAgB;AAAA,IAC1C;AAAA,IACA,IAAI,KAAK;AACP,aAAO,iBAAiB,gBAAgB,GAAG,QAAQ,GAAG,KAAK;AAAA,IAC7D;AAAA,IACA,IAAI,KAAK,OAAO;AACd,uBAAiB,gBAAgB,GAAG,QAAQ,KAAK,KAAK;AAAA,IACxD;AAAA,IACA,OAAO,KAAK;AACV,uBAAiB,gBAAgB,GAAG,WAAW,GAAG;AAAA,IACpD;AAAA,IACA,IAAI,KAAK;AACP,aAAO,iBAAiB,gBAAgB,GAAG,QAAQ,GAAG,MAAM;AAAA,IAC9D;AAAA,IACA,OAAO;AACL,aAAO,eAAe,iBAAiB,gBAAgB,CAAC;AAAA,IAC1D;AAAA,IACA,QAAQ;AACN,uBAAiB,gBAAgB,GAAG,MAAM;AAAA,IAC5C;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { hasWindow } from "../has.js";
|
|
2
|
+
import { localStorageProvider } from "./providers.js";
|
|
3
|
+
import { jsonSerializer } from "./serializers.js";
|
|
4
|
+
function createStorage(options = {}) {
|
|
5
|
+
const {
|
|
6
|
+
provider = localStorageProvider,
|
|
7
|
+
serializer = jsonSerializer,
|
|
8
|
+
prefix = ""
|
|
9
|
+
} = options;
|
|
10
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
11
|
+
function resolveKey(key) {
|
|
12
|
+
return `${prefix}${key}`;
|
|
13
|
+
}
|
|
14
|
+
function syncHandler(event) {
|
|
15
|
+
if (event instanceof StorageEvent) {
|
|
16
|
+
if (provider.storageArea && event.storageArea !== provider.storageArea) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const rawKey = event.key;
|
|
20
|
+
for (const [listenerKey, callbacks] of listeners) {
|
|
21
|
+
if (resolveKey(listenerKey) === rawKey) {
|
|
22
|
+
const newValue = event.newValue ? serializer.deserialize(event.newValue) : void 0;
|
|
23
|
+
callbacks.forEach((callback) => callback(newValue));
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
listeners.forEach((callbacks, key) => {
|
|
30
|
+
const value = provider.get(resolveKey(key));
|
|
31
|
+
const newValue = value !== null ? serializer.deserialize(value) : void 0;
|
|
32
|
+
callbacks.forEach((callback) => callback(newValue));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (hasWindow() && provider.syncEvent) {
|
|
36
|
+
window.addEventListener(provider.syncEvent, syncHandler);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
get(key, defaultValue) {
|
|
40
|
+
const storedValue = provider.get(resolveKey(key));
|
|
41
|
+
if (storedValue !== null) {
|
|
42
|
+
const deserialized = serializer.deserialize(storedValue);
|
|
43
|
+
if (deserialized !== void 0) {
|
|
44
|
+
return deserialized;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return defaultValue;
|
|
48
|
+
},
|
|
49
|
+
set(key, value) {
|
|
50
|
+
provider.set(resolveKey(key), serializer.serialize(value));
|
|
51
|
+
listeners.get(key)?.forEach((callback) => callback(value));
|
|
52
|
+
},
|
|
53
|
+
delete(key) {
|
|
54
|
+
provider.remove(resolveKey(key));
|
|
55
|
+
listeners.get(key)?.forEach((callback) => callback(void 0));
|
|
56
|
+
},
|
|
57
|
+
has(key) {
|
|
58
|
+
return provider.has(resolveKey(key));
|
|
59
|
+
},
|
|
60
|
+
keys() {
|
|
61
|
+
const allKeys = provider.keys();
|
|
62
|
+
if (!prefix) {
|
|
63
|
+
return allKeys;
|
|
64
|
+
}
|
|
65
|
+
return allKeys.filter((key) => key.startsWith(prefix)).map((key) => key.slice(prefix.length));
|
|
66
|
+
},
|
|
67
|
+
clear() {
|
|
68
|
+
if (prefix) {
|
|
69
|
+
provider.keys().filter((key) => key.startsWith(prefix)).forEach((key) => provider.remove(key));
|
|
70
|
+
} else {
|
|
71
|
+
provider.clear();
|
|
72
|
+
}
|
|
73
|
+
listeners.forEach((callbacks) => {
|
|
74
|
+
callbacks.forEach((callback) => callback(void 0));
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
subscribe(key, callback) {
|
|
78
|
+
if (!listeners.has(key)) {
|
|
79
|
+
listeners.set(key, /* @__PURE__ */ new Set());
|
|
80
|
+
}
|
|
81
|
+
listeners.get(key)?.add(callback);
|
|
82
|
+
return () => {
|
|
83
|
+
listeners.get(key)?.delete(callback);
|
|
84
|
+
if (listeners.get(key)?.size === 0) {
|
|
85
|
+
listeners.delete(key);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
destroy() {
|
|
90
|
+
listeners.clear();
|
|
91
|
+
if (hasWindow() && provider.syncEvent) {
|
|
92
|
+
window.removeEventListener(provider.syncEvent, syncHandler);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export {
|
|
98
|
+
createStorage
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=createStorage.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/js-toolkit/utils/storage/createStorage.ts"],
|
|
4
|
+
"sourcesContent": ["import { hasWindow } from '../has.js';\nimport { localStorageProvider } from './providers.js';\nimport { jsonSerializer } from './serializers.js';\nimport type { StorageInstance, StorageOptions } from './types.js';\n\nexport function createStorage<T extends Record<string, any> = Record<string, any>>(\n options: StorageOptions = {},\n): StorageInstance<T> {\n const {\n provider = localStorageProvider,\n serializer = jsonSerializer,\n prefix = '',\n } = options;\n\n const listeners = new Map<keyof T, Set<(value: any) => void>>();\n\n function resolveKey(key: string): string {\n return `${prefix}${key}`;\n }\n\n function syncHandler(event: Event): void {\n if (event instanceof StorageEvent) {\n if (provider.storageArea && event.storageArea !== provider.storageArea) {\n return;\n }\n\n const rawKey = event.key;\n for (const [listenerKey, callbacks] of listeners) {\n if (resolveKey(listenerKey as string) === rawKey) {\n const newValue = event.newValue ? serializer.deserialize(event.newValue) : undefined;\n callbacks.forEach((callback) => callback(newValue));\n break;\n }\n }\n return;\n }\n\n listeners.forEach((callbacks, key) => {\n const value = provider.get(resolveKey(key as string));\n const newValue = value !== null ? serializer.deserialize(value) : undefined;\n callbacks.forEach((callback) => callback(newValue));\n });\n }\n\n if (hasWindow() && provider.syncEvent) {\n window.addEventListener(provider.syncEvent, syncHandler);\n }\n\n return {\n get(key, defaultValue?) {\n const storedValue = provider.get(resolveKey(key as string));\n if (storedValue !== null) {\n const deserialized = serializer.deserialize(storedValue);\n if (deserialized !== undefined) {\n return deserialized;\n }\n }\n return defaultValue;\n },\n set(key, value) {\n provider.set(resolveKey(key as string), serializer.serialize(value));\n listeners.get(key)?.forEach((callback) => callback(value));\n },\n delete(key) {\n provider.remove(resolveKey(key as string));\n listeners.get(key)?.forEach((callback) => callback(undefined));\n },\n has(key) {\n return provider.has(resolveKey(key as string));\n },\n keys() {\n const allKeys = provider.keys();\n if (!prefix) {\n return allKeys as (keyof T)[];\n }\n\n return allKeys\n .filter((key) => key.startsWith(prefix))\n .map((key) => key.slice(prefix.length) as keyof T);\n },\n clear() {\n if (prefix) {\n provider\n .keys()\n .filter((key) => key.startsWith(prefix))\n .forEach((key) => provider.remove(key));\n } else {\n provider.clear();\n }\n\n listeners.forEach((callbacks) => {\n callbacks.forEach((callback) => callback(undefined));\n });\n },\n subscribe(key, callback) {\n if (!listeners.has(key)) {\n listeners.set(key, new Set());\n }\n\n listeners.get(key)?.add(callback);\n\n return () => {\n listeners.get(key)?.delete(callback);\n if (listeners.get(key)?.size === 0) {\n listeners.delete(key);\n }\n };\n },\n destroy() {\n listeners.clear();\n if (hasWindow() && provider.syncEvent) {\n window.removeEventListener(provider.syncEvent, syncHandler);\n }\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createNoopProvider } from "./createNoopProvider.js";
|
|
2
|
+
import { getBrowserContext } from "./getBrowserContext.js";
|
|
3
|
+
function createUrlSearchParamsInHashProvider(options = {}) {
|
|
4
|
+
const browserContext = getBrowserContext();
|
|
5
|
+
if (!browserContext) {
|
|
6
|
+
return createNoopProvider();
|
|
7
|
+
}
|
|
8
|
+
const { push = false } = options;
|
|
9
|
+
const { location, history } = browserContext;
|
|
10
|
+
function getParamsFromHash() {
|
|
11
|
+
return new URLSearchParams(location.hash.slice(1));
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
syncEvent: "hashchange",
|
|
15
|
+
get(key) {
|
|
16
|
+
return getParamsFromHash().get(key);
|
|
17
|
+
},
|
|
18
|
+
set(key, value) {
|
|
19
|
+
const params = getParamsFromHash();
|
|
20
|
+
params.set(key, value);
|
|
21
|
+
const newHash = params.toString();
|
|
22
|
+
if (push) {
|
|
23
|
+
location.hash = newHash;
|
|
24
|
+
} else {
|
|
25
|
+
history.replaceState({}, "", `${location.pathname}${location.search}#${newHash}`);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
remove(key) {
|
|
29
|
+
const params = getParamsFromHash();
|
|
30
|
+
params.delete(key);
|
|
31
|
+
const newHash = params.toString();
|
|
32
|
+
if (push) {
|
|
33
|
+
location.hash = newHash;
|
|
34
|
+
} else {
|
|
35
|
+
const url = newHash ? `${location.pathname}${location.search}#${newHash}` : `${location.pathname}${location.search}`;
|
|
36
|
+
history.replaceState({}, "", url);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
has(key) {
|
|
40
|
+
return getParamsFromHash().has(key);
|
|
41
|
+
},
|
|
42
|
+
keys() {
|
|
43
|
+
return [...getParamsFromHash().keys()];
|
|
44
|
+
},
|
|
45
|
+
clear() {
|
|
46
|
+
if (push) {
|
|
47
|
+
location.hash = "";
|
|
48
|
+
} else {
|
|
49
|
+
history.replaceState({}, "", `${location.pathname}${location.search}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
createUrlSearchParamsInHashProvider
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=createUrlSearchParamsInHashProvider.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/js-toolkit/utils/storage/createUrlSearchParamsInHashProvider.ts"],
|
|
4
|
+
"sourcesContent": ["import { createNoopProvider } from './createNoopProvider.js';\nimport { getBrowserContext } from './getBrowserContext.js';\nimport type { StorageProvider, UrlProviderOptions } from './types.js';\n\nexport function createUrlSearchParamsInHashProvider(\n options: UrlProviderOptions = {},\n): StorageProvider {\n const browserContext = getBrowserContext();\n\n if (!browserContext) {\n return createNoopProvider();\n }\n\n const { push = false } = options;\n const { location, history } = browserContext;\n\n function getParamsFromHash(): URLSearchParams {\n return new URLSearchParams(location.hash.slice(1));\n }\n\n return {\n syncEvent: 'hashchange',\n get(key) {\n return getParamsFromHash().get(key);\n },\n set(key, value) {\n const params = getParamsFromHash();\n params.set(key, value);\n const newHash = params.toString();\n\n if (push) {\n location.hash = newHash;\n } else {\n history.replaceState({}, '', `${location.pathname}${location.search}#${newHash}`);\n }\n },\n remove(key) {\n const params = getParamsFromHash();\n params.delete(key);\n const newHash = params.toString();\n\n if (push) {\n location.hash = newHash;\n } else {\n const url = newHash\n ? `${location.pathname}${location.search}#${newHash}`\n : `${location.pathname}${location.search}`;\n history.replaceState({}, '', url);\n }\n },\n has(key) {\n return getParamsFromHash().has(key);\n },\n keys() {\n return [...getParamsFromHash().keys()];\n },\n clear() {\n if (push) {\n location.hash = '';\n } else {\n history.replaceState({}, '', `${location.pathname}${location.search}`);\n }\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,0BAA0B;AACnC,SAAS,yBAAyB;AAG3B,SAAS,oCACd,UAA8B,CAAC,GACd;AACjB,QAAM,iBAAiB,kBAAkB;AAEzC,MAAI,CAAC,gBAAgB;AACnB,WAAO,mBAAmB;AAAA,EAC5B;AAEA,QAAM,EAAE,OAAO,MAAM,IAAI;AACzB,QAAM,EAAE,UAAU,QAAQ,IAAI;AAE9B,WAAS,oBAAqC;AAC5C,WAAO,IAAI,gBAAgB,SAAS,KAAK,MAAM,CAAC,CAAC;AAAA,EACnD;AAEA,SAAO;AAAA,IACL,WAAW;AAAA,IACX,IAAI,KAAK;AACP,aAAO,kBAAkB,EAAE,IAAI,GAAG;AAAA,IACpC;AAAA,IACA,IAAI,KAAK,OAAO;AACd,YAAM,SAAS,kBAAkB;AACjC,aAAO,IAAI,KAAK,KAAK;AACrB,YAAM,UAAU,OAAO,SAAS;AAEhC,UAAI,MAAM;AACR,iBAAS,OAAO;AAAA,MAClB,OAAO;AACL,gBAAQ,aAAa,CAAC,GAAG,IAAI,GAAG,SAAS,QAAQ,GAAG,SAAS,MAAM,IAAI,OAAO,EAAE;AAAA,MAClF;AAAA,IACF;AAAA,IACA,OAAO,KAAK;AACV,YAAM,SAAS,kBAAkB;AACjC,aAAO,OAAO,GAAG;AACjB,YAAM,UAAU,OAAO,SAAS;AAEhC,UAAI,MAAM;AACR,iBAAS,OAAO;AAAA,MAClB,OAAO;AACL,cAAM,MAAM,UACR,GAAG,SAAS,QAAQ,GAAG,SAAS,MAAM,IAAI,OAAO,KACjD,GAAG,SAAS,QAAQ,GAAG,SAAS,MAAM;AAC1C,gBAAQ,aAAa,CAAC,GAAG,IAAI,GAAG;AAAA,MAClC;AAAA,IACF;AAAA,IACA,IAAI,KAAK;AACP,aAAO,kBAAkB,EAAE,IAAI,GAAG;AAAA,IACpC;AAAA,IACA,OAAO;AACL,aAAO,CAAC,GAAG,kBAAkB,EAAE,KAAK,CAAC;AAAA,IACvC;AAAA,IACA,QAAQ;AACN,UAAI,MAAM;AACR,iBAAS,OAAO;AAAA,MAClB,OAAO;AACL,gBAAQ,aAAa,CAAC,GAAG,IAAI,GAAG,SAAS,QAAQ,GAAG,SAAS,MAAM,EAAE;AAAA,MACvE;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createNoopProvider } from "./createNoopProvider.js";
|
|
2
|
+
import { getBrowserContext } from "./getBrowserContext.js";
|
|
3
|
+
function createUrlSearchParamsProvider(options = {}) {
|
|
4
|
+
const browserContext = getBrowserContext();
|
|
5
|
+
if (!browserContext) {
|
|
6
|
+
return createNoopProvider();
|
|
7
|
+
}
|
|
8
|
+
const { push = false } = options;
|
|
9
|
+
const method = push ? "pushState" : "replaceState";
|
|
10
|
+
const { location, history } = browserContext;
|
|
11
|
+
return {
|
|
12
|
+
syncEvent: "popstate",
|
|
13
|
+
get(key) {
|
|
14
|
+
return new URLSearchParams(location.search).get(key);
|
|
15
|
+
},
|
|
16
|
+
set(key, value) {
|
|
17
|
+
const params = new URLSearchParams(location.search);
|
|
18
|
+
params.set(key, value);
|
|
19
|
+
history[method]({}, "", `${location.pathname}?${params.toString()}${location.hash}`);
|
|
20
|
+
},
|
|
21
|
+
remove(key) {
|
|
22
|
+
const params = new URLSearchParams(location.search);
|
|
23
|
+
params.delete(key);
|
|
24
|
+
const search = params.toString();
|
|
25
|
+
history[method]({}, "", `${location.pathname}${search ? `?${search}` : ""}${location.hash}`);
|
|
26
|
+
},
|
|
27
|
+
has(key) {
|
|
28
|
+
return new URLSearchParams(location.search).has(key);
|
|
29
|
+
},
|
|
30
|
+
keys() {
|
|
31
|
+
return [...new URLSearchParams(location.search).keys()];
|
|
32
|
+
},
|
|
33
|
+
clear() {
|
|
34
|
+
history[method]({}, "", `${location.pathname}${location.hash}`);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
createUrlSearchParamsProvider
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=createUrlSearchParamsProvider.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/js-toolkit/utils/storage/createUrlSearchParamsProvider.ts"],
|
|
4
|
+
"sourcesContent": ["import { createNoopProvider } from './createNoopProvider.js';\nimport { getBrowserContext } from './getBrowserContext.js';\nimport type { StorageProvider, UrlProviderOptions } from './types.js';\n\nexport function createUrlSearchParamsProvider(\n options: UrlProviderOptions = {},\n): StorageProvider {\n const browserContext = getBrowserContext();\n\n if (!browserContext) {\n return createNoopProvider();\n }\n\n const { push = false } = options;\n const method = push ? 'pushState' : 'replaceState';\n const { location, history } = browserContext;\n\n return {\n syncEvent: 'popstate',\n get(key) {\n return new URLSearchParams(location.search).get(key);\n },\n set(key, value) {\n const params = new URLSearchParams(location.search);\n params.set(key, value);\n history[method]({}, '', `${location.pathname}?${params.toString()}${location.hash}`);\n },\n remove(key) {\n const params = new URLSearchParams(location.search);\n params.delete(key);\n const search = params.toString();\n history[method]({}, '', `${location.pathname}${search ? `?${search}` : ''}${location.hash}`);\n },\n has(key) {\n return new URLSearchParams(location.search).has(key);\n },\n keys() {\n return [...new URLSearchParams(location.search).keys()];\n },\n clear() {\n history[method]({}, '', `${location.pathname}${location.hash}`);\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,0BAA0B;AACnC,SAAS,yBAAyB;AAG3B,SAAS,8BACd,UAA8B,CAAC,GACd;AACjB,QAAM,iBAAiB,kBAAkB;AAEzC,MAAI,CAAC,gBAAgB;AACnB,WAAO,mBAAmB;AAAA,EAC5B;AAEA,QAAM,EAAE,OAAO,MAAM,IAAI;AACzB,QAAM,SAAS,OAAO,cAAc;AACpC,QAAM,EAAE,UAAU,QAAQ,IAAI;AAE9B,SAAO;AAAA,IACL,WAAW;AAAA,IACX,IAAI,KAAK;AACP,aAAO,IAAI,gBAAgB,SAAS,MAAM,EAAE,IAAI,GAAG;AAAA,IACrD;AAAA,IACA,IAAI,KAAK,OAAO;AACd,YAAM,SAAS,IAAI,gBAAgB,SAAS,MAAM;AAClD,aAAO,IAAI,KAAK,KAAK;AACrB,cAAQ,MAAM,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,QAAQ,IAAI,OAAO,SAAS,CAAC,GAAG,SAAS,IAAI,EAAE;AAAA,IACrF;AAAA,IACA,OAAO,KAAK;AACV,YAAM,SAAS,IAAI,gBAAgB,SAAS,MAAM;AAClD,aAAO,OAAO,GAAG;AACjB,YAAM,SAAS,OAAO,SAAS;AAC/B,cAAQ,MAAM,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,QAAQ,GAAG,SAAS,IAAI,MAAM,KAAK,EAAE,GAAG,SAAS,IAAI,EAAE;AAAA,IAC7F;AAAA,IACA,IAAI,KAAK;AACP,aAAO,IAAI,gBAAgB,SAAS,MAAM,EAAE,IAAI,GAAG;AAAA,IACrD;AAAA,IACA,OAAO;AACL,aAAO,CAAC,GAAG,IAAI,gBAAgB,SAAS,MAAM,EAAE,KAAK,CAAC;AAAA,IACxD;AAAA,IACA,QAAQ;AACN,cAAQ,MAAM,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,QAAQ,GAAG,SAAS,IAAI,EAAE;AAAA,IAChE;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|