@studiometa/js-toolkit 2.8.0 → 2.9.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.cjs +325 -0
- package/Base/Base.cjs.map +7 -0
- package/Base/Base.d.ts +197 -0
- package/Base/Base.js +304 -0
- package/Base/Base.js.map +7 -0
- package/Base/index.cjs +2 -292
- package/Base/index.cjs.map +3 -3
- package/Base/index.d.ts +1 -193
- package/Base/index.js +1 -290
- package/Base/index.js.map +2 -2
- package/Base/managers/AbstractManager.d.ts +2 -2
- package/Base/managers/ChildrenManager.cjs +11 -7
- package/Base/managers/ChildrenManager.cjs.map +2 -2
- package/Base/managers/ChildrenManager.d.ts +1 -1
- package/Base/managers/ChildrenManager.js +12 -8
- package/Base/managers/ChildrenManager.js.map +2 -2
- package/Base/managers/index.cjs +0 -2
- package/Base/managers/index.cjs.map +2 -2
- package/Base/managers/index.d.ts +0 -1
- package/Base/managers/index.js +0 -2
- package/Base/managers/index.js.map +2 -2
- package/Base/utils.cjs +13 -0
- package/Base/utils.cjs.map +2 -2
- package/Base/utils.d.ts +4 -0
- package/Base/utils.js +14 -1
- package/Base/utils.js.map +2 -2
- package/decorators/withScrolledInView/withScrolledInView.cjs +38 -49
- package/decorators/withScrolledInView/withScrolledInView.cjs.map +2 -2
- package/decorators/withScrolledInView/withScrolledInView.d.ts +1 -6
- package/decorators/withScrolledInView/withScrolledInView.js +38 -49
- package/decorators/withScrolledInView/withScrolledInView.js.map +2 -2
- package/package.json +1 -1
- package/utils/Queue.cjs +4 -1
- package/utils/Queue.cjs.map +2 -2
- package/utils/Queue.d.ts +1 -1
- package/utils/Queue.js +4 -1
- package/utils/Queue.js.map +2 -2
- package/utils/SmartQueue.cjs +57 -0
- package/utils/SmartQueue.cjs.map +7 -0
- package/utils/SmartQueue.d.ts +25 -0
- package/utils/SmartQueue.js +29 -0
- package/utils/SmartQueue.js.map +7 -0
- package/utils/index.cjs +3 -0
- package/utils/index.cjs.map +2 -2
- package/utils/index.d.ts +2 -0
- package/utils/index.js +3 -0
- package/utils/index.js.map +2 -2
- package/utils/nextTick.cjs +2 -5
- package/utils/nextTick.cjs.map +2 -2
- package/utils/nextTick.js +2 -5
- package/utils/nextTick.js.map +2 -2
- package/utils/wait.cjs +31 -0
- package/utils/wait.cjs.map +7 -0
- package/utils/wait.d.ts +1 -0
- package/utils/wait.js +9 -0
- package/utils/wait.js.map +7 -0
- package/Base/managers/AsyncChildrenManager.cjs +0 -61
- package/Base/managers/AsyncChildrenManager.cjs.map +0 -7
- package/Base/managers/AsyncChildrenManager.d.ts +0 -18
- package/Base/managers/AsyncChildrenManager.js +0 -39
- package/Base/managers/AsyncChildrenManager.js.map +0 -7
|
@@ -77,13 +77,48 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
77
77
|
y: 0
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
|
+
shouldEvaluateProps = true;
|
|
81
|
+
get props() {
|
|
82
|
+
if (this.shouldEvaluateProps) {
|
|
83
|
+
this.shouldEvaluateProps = false;
|
|
84
|
+
const targetSizes = options.useOffsetSizes ? getOffsetSizes(this.$el) : this.$el.getBoundingClientRect();
|
|
85
|
+
targetSizes.y += window.pageYOffset;
|
|
86
|
+
targetSizes.x += window.pageXOffset;
|
|
87
|
+
const containerSizes = {
|
|
88
|
+
x: 0,
|
|
89
|
+
y: 0,
|
|
90
|
+
height: window.innerHeight,
|
|
91
|
+
width: window.innerWidth
|
|
92
|
+
};
|
|
93
|
+
const offset = normalizeOffset(this.$options.offset);
|
|
94
|
+
const [yStart, yEnd] = getEdges("y", targetSizes, containerSizes, offset);
|
|
95
|
+
const yCurrent = clamp(window.pageYOffset, yStart, yEnd);
|
|
96
|
+
const yProgress = clamp01((yCurrent - yStart) / (yEnd - yStart));
|
|
97
|
+
const [xStart, xEnd] = getEdges("x", targetSizes, containerSizes, offset);
|
|
98
|
+
const xCurrent = clamp(window.pageXOffset, xStart, xEnd);
|
|
99
|
+
const xProgress = clamp01((xCurrent - xStart) / (xEnd - xStart));
|
|
100
|
+
this.__props.start.x = xStart;
|
|
101
|
+
this.__props.start.y = yStart;
|
|
102
|
+
this.__props.end.x = xEnd;
|
|
103
|
+
this.__props.end.y = yEnd;
|
|
104
|
+
this.__props.current.x = xCurrent;
|
|
105
|
+
this.__props.current.y = yCurrent;
|
|
106
|
+
this.__props.dampedCurrent.x = xCurrent;
|
|
107
|
+
this.__props.dampedCurrent.y = yCurrent;
|
|
108
|
+
this.__props.progress.x = xProgress;
|
|
109
|
+
this.__props.progress.y = yProgress;
|
|
110
|
+
this.__props.dampedProgress.x = xProgress;
|
|
111
|
+
this.__props.dampedProgress.y = yProgress;
|
|
112
|
+
}
|
|
113
|
+
return this.__props;
|
|
114
|
+
}
|
|
80
115
|
dampFactor = null;
|
|
81
116
|
dampPrecision = null;
|
|
82
117
|
constructor(element) {
|
|
83
118
|
super(element);
|
|
84
119
|
const render = () => {
|
|
85
120
|
scheduler.update(() => {
|
|
86
|
-
const renderFn = this.__callMethod("scrolledInView", this.
|
|
121
|
+
const renderFn = this.__callMethod("scrolledInView", this.props);
|
|
87
122
|
if (isFunction(renderFn)) {
|
|
88
123
|
scheduler.render(() => {
|
|
89
124
|
renderFn(this.__props);
|
|
@@ -96,7 +131,8 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
96
131
|
delegate[event.type](event.detail[0]);
|
|
97
132
|
},
|
|
98
133
|
resized: () => {
|
|
99
|
-
this.
|
|
134
|
+
this.shouldEvaluateProps = true;
|
|
135
|
+
render();
|
|
100
136
|
},
|
|
101
137
|
scrolled: (props) => {
|
|
102
138
|
if (!this.$services.has("ticked") && props.changed.y || props.changed.x) {
|
|
@@ -119,9 +155,6 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
119
155
|
this.$on("scrolled", delegate);
|
|
120
156
|
this.$on("ticked", delegate);
|
|
121
157
|
});
|
|
122
|
-
this.$on("mounted", () => {
|
|
123
|
-
this.__setProps();
|
|
124
|
-
});
|
|
125
158
|
this.$on("destroyed", () => {
|
|
126
159
|
this.$off("resized", delegate);
|
|
127
160
|
this.$off("scrolled", delegate);
|
|
@@ -158,50 +191,6 @@ function withScrolledInView(BaseClass, options = {}) {
|
|
|
158
191
|
super.destroyed();
|
|
159
192
|
}
|
|
160
193
|
}
|
|
161
|
-
__setProps() {
|
|
162
|
-
const targetSizes = options.useOffsetSizes ? getOffsetSizes(this.$el) : this.$el.getBoundingClientRect();
|
|
163
|
-
targetSizes.y += window.pageYOffset;
|
|
164
|
-
targetSizes.x += window.pageXOffset;
|
|
165
|
-
const containerSizes = {
|
|
166
|
-
x: 0,
|
|
167
|
-
y: 0,
|
|
168
|
-
height: window.innerHeight,
|
|
169
|
-
width: window.innerWidth
|
|
170
|
-
};
|
|
171
|
-
const offset = normalizeOffset(this.$options.offset);
|
|
172
|
-
const [yStart, yEnd] = getEdges("y", targetSizes, containerSizes, offset);
|
|
173
|
-
const yCurrent = clamp(window.pageYOffset, yStart, yEnd);
|
|
174
|
-
const yProgress = clamp01((yCurrent - yStart) / (yEnd - yStart));
|
|
175
|
-
const [xStart, xEnd] = getEdges("x", targetSizes, containerSizes, offset);
|
|
176
|
-
const xCurrent = clamp(window.pageXOffset, xStart, xEnd);
|
|
177
|
-
const xProgress = clamp01((xCurrent - xStart) / (xEnd - xStart));
|
|
178
|
-
this.__props.start.x = xStart;
|
|
179
|
-
this.__props.start.y = yStart;
|
|
180
|
-
this.__props.end.x = xEnd;
|
|
181
|
-
this.__props.end.y = yEnd;
|
|
182
|
-
this.__props.current.x = xCurrent;
|
|
183
|
-
this.__props.current.y = yCurrent;
|
|
184
|
-
this.__props.dampedCurrent.x = damp(
|
|
185
|
-
xCurrent,
|
|
186
|
-
this.__props.dampedCurrent.x,
|
|
187
|
-
this.dampFactor,
|
|
188
|
-
this.dampPrecision
|
|
189
|
-
);
|
|
190
|
-
this.__props.dampedCurrent.y = damp(
|
|
191
|
-
yCurrent,
|
|
192
|
-
this.__props.dampedCurrent.y,
|
|
193
|
-
this.dampFactor,
|
|
194
|
-
this.dampPrecision
|
|
195
|
-
);
|
|
196
|
-
this.__props.progress.x = xProgress;
|
|
197
|
-
this.__props.progress.y = yProgress;
|
|
198
|
-
this.__props.dampedProgress.x = clamp01(
|
|
199
|
-
(this.__props.dampedCurrent.x - xStart) / (xEnd - xStart)
|
|
200
|
-
);
|
|
201
|
-
this.__props.dampedProgress.y = clamp01(
|
|
202
|
-
(this.__props.dampedCurrent.y - yStart) / (yEnd - yStart)
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
194
|
}
|
|
206
195
|
return WithScrolledInView;
|
|
207
196
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/js-toolkit/decorators/withScrolledInView/withScrolledInView.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseInterface, BaseDecorator } from '../../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../../Base/index.js';\nimport type {\n RafServiceProps,\n ScrollServiceProps,\n ResizeServiceProps,\n} from '../../services/index.js';\nimport { withMountWhenInView } from '../withMountWhenInView.js';\nimport {\n damp,\n clamp,\n clamp01,\n getOffsetSizes,\n isFunction,\n useScheduler,\n} from '../../utils/index.js';\nimport { normalizeOffset, getEdges } from './utils.js';\n\nconst scheduler = useScheduler(['update', 'render']);\n\nexport interface WithScrolledInViewProps extends BaseProps {\n $options: {\n dampFactor: number;\n dampPrecision: number;\n offset: string;\n };\n}\n\nexport type ScrollInViewProps = {\n start: {\n x: number;\n y: number;\n };\n end: {\n x: number;\n y: number;\n };\n current: {\n x: number;\n y: number;\n };\n dampedCurrent: {\n x: number;\n y: number;\n };\n progress: {\n x: number;\n y: number;\n };\n dampedProgress: {\n x: number;\n y: number;\n };\n};\n\nexport type WithScrolledInViewOptions = IntersectionObserverInit & {\n useOffsetSizes?: boolean;\n};\n\n/**\n * Update props on tick.\n */\nfunction updateProps(\n props: ScrollInViewProps,\n dampFactor: number,\n dampPrecision: number,\n axis: 'x' | 'y' = 'x',\n): void {\n props.current[axis] = clamp(\n axis === 'x' ? window.pageXOffset : window.pageYOffset,\n props.start[axis],\n props.end[axis],\n );\n props.dampedCurrent[axis] = damp(\n props.current[axis],\n props.dampedCurrent[axis],\n dampFactor,\n dampPrecision,\n );\n props.progress[axis] = clamp01(\n (props.current[axis] - props.start[axis]) / (props.end[axis] - props.start[axis]),\n );\n props.dampedProgress[axis] = clamp01(\n (props.dampedCurrent[axis] - props.start[axis]) / (props.end[axis] - props.start[axis]),\n );\n}\n\nexport interface WithScrolledInViewInterface extends BaseInterface {\n /**\n * @
|
|
5
|
-
"mappings": "AAOA,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB,gBAAgB;AAE1C,MAAM,YAAY,aAAa,CAAC,UAAU,QAAQ,CAAC;AA4CnD,SAAS,YACP,OACA,YACA,eACA,OAAkB,KACZ;AACN,QAAM,QAAQ,QAAQ;AAAA,IACpB,SAAS,MAAM,OAAO,cAAc,OAAO;AAAA,IAC3C,MAAM,MAAM;AAAA,IACZ,MAAM,IAAI;AAAA,EACZ;AACA,QAAM,cAAc,QAAQ;AAAA,IAC1B,MAAM,QAAQ;AAAA,IACd,MAAM,cAAc;AAAA,IACpB;AAAA,IACA;AAAA,EACF;AACA,QAAM,SAAS,QAAQ;AAAA,KACpB,MAAM,QAAQ,QAAQ,MAAM,MAAM,UAAU,MAAM,IAAI,QAAQ,MAAM,MAAM;AAAA,EAC7E;AACA,QAAM,eAAe,QAAQ;AAAA,KAC1B,MAAM,cAAc,QAAQ,MAAM,MAAM,UAAU,MAAM,IAAI,QAAQ,MAAM,MAAM;AAAA,EACnF;AACF;
|
|
4
|
+
"sourcesContent": ["import type { BaseInterface, BaseDecorator } from '../../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../../Base/index.js';\nimport type {\n RafServiceProps,\n ScrollServiceProps,\n ResizeServiceProps,\n} from '../../services/index.js';\nimport { withMountWhenInView } from '../withMountWhenInView.js';\nimport {\n damp,\n clamp,\n clamp01,\n getOffsetSizes,\n isFunction,\n useScheduler,\n} from '../../utils/index.js';\nimport { normalizeOffset, getEdges } from './utils.js';\n\nconst scheduler = useScheduler(['update', 'render']);\n\nexport interface WithScrolledInViewProps extends BaseProps {\n $options: {\n dampFactor: number;\n dampPrecision: number;\n offset: string;\n };\n}\n\nexport type ScrollInViewProps = {\n start: {\n x: number;\n y: number;\n };\n end: {\n x: number;\n y: number;\n };\n current: {\n x: number;\n y: number;\n };\n dampedCurrent: {\n x: number;\n y: number;\n };\n progress: {\n x: number;\n y: number;\n };\n dampedProgress: {\n x: number;\n y: number;\n };\n};\n\nexport type WithScrolledInViewOptions = IntersectionObserverInit & {\n useOffsetSizes?: boolean;\n};\n\n/**\n * Update props on tick.\n */\nfunction updateProps(\n props: ScrollInViewProps,\n dampFactor: number,\n dampPrecision: number,\n axis: 'x' | 'y' = 'x',\n): void {\n props.current[axis] = clamp(\n axis === 'x' ? window.pageXOffset : window.pageYOffset,\n props.start[axis],\n props.end[axis],\n );\n props.dampedCurrent[axis] = damp(\n props.current[axis],\n props.dampedCurrent[axis],\n dampFactor,\n dampPrecision,\n );\n props.progress[axis] = clamp01(\n (props.current[axis] - props.start[axis]) / (props.end[axis] - props.start[axis]),\n );\n props.dampedProgress[axis] = clamp01(\n (props.dampedCurrent[axis] - props.start[axis]) / (props.end[axis] - props.start[axis]),\n );\n}\n\nexport interface WithScrolledInViewInterface extends BaseInterface {\n /**\n * @type {ScrollInViewProps}\n */\n readonly props: ScrollInViewProps;\n dampFactor?: number;\n dampPrecision?: number;\n mounted(): void;\n resized(props: ResizeServiceProps): void;\n scrolled(props: ScrollServiceProps): void;\n ticked(props: RafServiceProps): void;\n destroyed(): void;\n}\n\n/**\n * Add scrolled in view capabilities to a component.\n */\nexport function withScrolledInView<S extends Base = Base>(\n BaseClass: typeof Base,\n options: WithScrolledInViewOptions = {},\n): BaseDecorator<WithScrolledInViewInterface, S, WithScrolledInViewProps> {\n /**\n * Class.\n */\n class WithScrolledInView<T extends BaseProps = BaseProps> extends withMountWhenInView(\n BaseClass,\n options,\n )<T & WithScrolledInViewProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: `${BaseClass.config.name}WithMountWhenInView`,\n emits: ['scrolledInView'],\n options: {\n dampFactor: {\n type: Number,\n default: 0.1,\n },\n dampPrecision: {\n type: Number,\n default: 0.001,\n },\n offset: {\n type: String,\n default: 'start end / end start',\n },\n },\n };\n\n __props: ScrollInViewProps = {\n start: {\n x: 0,\n y: 0,\n },\n end: {\n x: 0,\n y: 0,\n },\n current: {\n x: 0,\n y: 0,\n },\n dampedCurrent: {\n x: 0,\n y: 0,\n },\n progress: {\n x: 0,\n y: 0,\n },\n dampedProgress: {\n x: 0,\n y: 0,\n },\n };\n\n shouldEvaluateProps = true;\n\n get props() {\n if (this.shouldEvaluateProps) {\n this.shouldEvaluateProps = false;\n const targetSizes = options.useOffsetSizes\n ? getOffsetSizes(this.$el)\n : this.$el.getBoundingClientRect();\n\n targetSizes.y += window.pageYOffset;\n targetSizes.x += window.pageXOffset;\n\n const containerSizes = {\n x: 0,\n y: 0,\n height: window.innerHeight,\n width: window.innerWidth,\n };\n\n const offset = normalizeOffset(this.$options.offset);\n\n // Y axis\n const [yStart, yEnd] = getEdges('y', targetSizes, containerSizes, offset);\n const yCurrent = clamp(window.pageYOffset, yStart, yEnd);\n const yProgress = clamp01((yCurrent - yStart) / (yEnd - yStart));\n // X axis\n const [xStart, xEnd] = getEdges('x', targetSizes, containerSizes, offset);\n const xCurrent = clamp(window.pageXOffset, xStart, xEnd);\n const xProgress = clamp01((xCurrent - xStart) / (xEnd - xStart));\n\n this.__props.start.x = xStart;\n this.__props.start.y = yStart;\n this.__props.end.x = xEnd;\n this.__props.end.y = yEnd;\n this.__props.current.x = xCurrent;\n this.__props.current.y = yCurrent;\n this.__props.dampedCurrent.x = xCurrent;\n this.__props.dampedCurrent.y = yCurrent;\n this.__props.progress.x = xProgress;\n this.__props.progress.y = yProgress;\n this.__props.dampedProgress.x = xProgress;\n this.__props.dampedProgress.y = yProgress;\n }\n\n return this.__props;\n }\n\n /**\n * Factor used for the `dampedProgress` props.\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampFactor?: number = null;\n\n /**\n * Precision for the `dampedProgress` props.\n * @deprecated\n * @todo v3 delete in favor of option API\n */\n dampPrecision?: number = null;\n\n /**\n * Bind listeners.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n const render = () => {\n scheduler.update(() => {\n // @ts-ignore\n const renderFn = this.__callMethod('scrolledInView', this.props);\n if (isFunction(renderFn)) {\n scheduler.render(() => {\n renderFn(this.__props);\n });\n }\n });\n };\n\n const delegate = {\n handleEvent(event) {\n delegate[event.type](event.detail[0]);\n },\n resized: () => {\n this.shouldEvaluateProps = true;\n render();\n },\n scrolled: (props) => {\n if ((!this.$services.has('ticked') && props.changed.y) || props.changed.x) {\n this.$services.enable('ticked');\n }\n },\n ticked: () => {\n const dampFactor = this.dampFactor ?? this.$options.dampFactor;\n const dampPrecision = this.dampPrecision ?? this.$options.dampPrecision;\n updateProps(this.__props, dampFactor, dampPrecision, 'x');\n updateProps(this.__props, dampFactor, dampPrecision, 'y');\n\n if (\n this.__props.dampedCurrent.x === this.__props.current.x &&\n this.__props.dampedCurrent.y === this.__props.current.y\n ) {\n this.$services.disable('ticked');\n }\n\n render();\n },\n };\n\n this.$on('before-mounted', () => {\n this.$on('resized', delegate);\n this.$on('scrolled', delegate);\n this.$on('ticked', delegate);\n });\n\n this.$on('destroyed', () => {\n this.$off('resized', delegate);\n this.$off('scrolled', delegate);\n this.$off('ticked', delegate);\n\n // Clamp damped values to their final value and trigger one last render on destroy\n this.__props.dampedCurrent.x = this.__props.current.x;\n this.__props.dampedCurrent.y = this.__props.current.y;\n this.__props.dampedProgress.x = this.__props.progress.x;\n this.__props.dampedProgress.y = this.__props.progress.y;\n render();\n });\n }\n\n /**\n * Mounted hook.\n */\n mounted() {\n // @ts-ignore\n if (isFunction(super.mounted)) {\n // @ts-ignore\n super.mounted();\n }\n }\n\n /**\n * Resized hook.\n */\n resized(props: ResizeServiceProps) {\n // @ts-ignore\n if (isFunction(super.resized)) {\n // @ts-ignore\n super.resized(props);\n }\n }\n\n /**\n * Scrolled hook.\n */\n scrolled(props: ScrollServiceProps) {\n // @ts-ignore\n if (isFunction(super.scrolled)) {\n // @ts-ignore\n super.scrolled(props);\n }\n }\n\n /**\n * Ticked hook.\n */\n ticked(props: RafServiceProps) {\n // @ts-ignore\n if (isFunction(super.ticked)) {\n // @ts-ignore\n super.ticked(props);\n }\n }\n\n /**\n * Destroyed hook.\n */\n destroyed() {\n // @ts-ignore\n if (isFunction(super.destroyed)) {\n // @ts-ignore\n super.destroyed();\n }\n }\n }\n\n // @ts-ignore\n return WithScrolledInView;\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
package/utils/Queue.cjs
CHANGED
|
@@ -32,8 +32,11 @@ var Queue = class {
|
|
|
32
32
|
this.waiter = waiter;
|
|
33
33
|
}
|
|
34
34
|
add(task) {
|
|
35
|
-
|
|
35
|
+
const p = new Promise((resolve) => {
|
|
36
|
+
this.tasks.push(() => resolve(task()));
|
|
37
|
+
});
|
|
36
38
|
this.scheduleFlush();
|
|
39
|
+
return p;
|
|
37
40
|
}
|
|
38
41
|
scheduleFlush() {
|
|
39
42
|
if (this.isScheduled) {
|
package/utils/Queue.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/utils/Queue.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Manage tasks in a queue.\n */\nexport class Queue {\n /**\n * List of tasks.\n */\n tasks: Array<(...args: unknown[]) => unknown> = [];\n\n /**\n * Number of tasks running in a single batch.\n */\n concurrency = 10;\n\n /**\n * A function to schedule the next batch.\n */\n waiter: (cb: (...args: unknown[]) => unknown) => unknown;\n\n /**\n * Is schedule running?\n */\n isScheduled = false;\n\n /**\n * Constructor.\n *\n * @param {number} concurrency Number of tasks running in a single batch.\n * @param {(cb: (...args:unknown[]) => unknown) => unknown} waiter Scheduler for the next batch execution.\n */\n constructor(\n concurrency: number,\n waiter: (cb: (...args: unknown[]) => unknown) => unknown = (cb) => cb(),\n ) {\n this.concurrency = concurrency;\n this.waiter = waiter;\n }\n\n /**\n * Add a task to the queue.\n */\n add(task: (
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,IAAM,QAAN,MAAY;AAAA,EAIjB,QAAgD,CAAC;AAAA,EAKjD,cAAc;AAAA,EAKd;AAAA,EAKA,cAAc;AAAA,EAQd,YACE,aACA,SAA2D,CAAC,OAAO,GAAG,GACtE;AACA,SAAK,cAAc;AACnB,SAAK,SAAS;AAAA,EAChB;AAAA,EAKA,IAAI,
|
|
4
|
+
"sourcesContent": ["/**\n * Manage tasks in a queue.\n */\nexport class Queue {\n /**\n * List of tasks.\n */\n tasks: Array<(...args: unknown[]) => unknown> = [];\n\n /**\n * Number of tasks running in a single batch.\n */\n concurrency = 10;\n\n /**\n * A function to schedule the next batch.\n */\n waiter: (cb: (...args: unknown[]) => unknown) => unknown;\n\n /**\n * Is schedule running?\n */\n isScheduled = false;\n\n /**\n * Constructor.\n *\n * @param {number} concurrency Number of tasks running in a single batch.\n * @param {(cb: (...args:unknown[]) => unknown) => unknown} waiter Scheduler for the next batch execution.\n */\n constructor(\n concurrency: number,\n waiter: (cb: (...args: unknown[]) => unknown) => unknown = (cb) => cb(),\n ) {\n this.concurrency = concurrency;\n this.waiter = waiter;\n }\n\n /**\n * Add a task to the queue.\n */\n add(task: () => unknown) {\n const p = new Promise((resolve) => {\n this.tasks.push(() => resolve(task()));\n });\n this.scheduleFlush();\n return p;\n }\n\n /**\n * Schedule next flush.\n */\n scheduleFlush() {\n if (this.isScheduled) {\n return;\n }\n\n this.isScheduled = true;\n this.waiter(() => this.flush());\n }\n\n /**\n * Flush current batch.\n */\n flush() {\n this.run(this.tasks.splice(0, this.concurrency));\n this.isScheduled = false;\n\n if (this.tasks.length > 0) {\n this.scheduleFlush();\n }\n }\n\n /**\n * Run the queue.\n */\n run(tasks: Array<(...args: unknown[]) => unknown>) {\n let task;\n // eslint-disable-next-line no-cond-assign\n while ((task = tasks.shift())) {\n task();\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,IAAM,QAAN,MAAY;AAAA,EAIjB,QAAgD,CAAC;AAAA,EAKjD,cAAc;AAAA,EAKd;AAAA,EAKA,cAAc;AAAA,EAQd,YACE,aACA,SAA2D,CAAC,OAAO,GAAG,GACtE;AACA,SAAK,cAAc;AACnB,SAAK,SAAS;AAAA,EAChB;AAAA,EAKA,IAAI,MAAqB;AACvB,UAAM,IAAI,IAAI,QAAQ,CAAC,YAAY;AACjC,WAAK,MAAM,KAAK,MAAM,QAAQ,KAAK,CAAC,CAAC;AAAA,IACvC,CAAC;AACD,SAAK,cAAc;AACnB,WAAO;AAAA,EACT;AAAA,EAKA,gBAAgB;AACd,QAAI,KAAK,aAAa;AACpB;AAAA,IACF;AAEA,SAAK,cAAc;AACnB,SAAK,OAAO,MAAM,KAAK,MAAM,CAAC;AAAA,EAChC;AAAA,EAKA,QAAQ;AACN,SAAK,IAAI,KAAK,MAAM,OAAO,GAAG,KAAK,WAAW,CAAC;AAC/C,SAAK,cAAc;AAEnB,QAAI,KAAK,MAAM,SAAS,GAAG;AACzB,WAAK,cAAc;AAAA,IACrB;AAAA,EACF;AAAA,EAKA,IAAI,OAA+C;AACjD,QAAI;AAEJ,WAAQ,OAAO,MAAM,MAAM,GAAI;AAC7B,WAAK;AAAA,IACP;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/utils/Queue.d.ts
CHANGED
package/utils/Queue.js
CHANGED
|
@@ -8,8 +8,11 @@ class Queue {
|
|
|
8
8
|
this.waiter = waiter;
|
|
9
9
|
}
|
|
10
10
|
add(task) {
|
|
11
|
-
|
|
11
|
+
const p = new Promise((resolve) => {
|
|
12
|
+
this.tasks.push(() => resolve(task()));
|
|
13
|
+
});
|
|
12
14
|
this.scheduleFlush();
|
|
15
|
+
return p;
|
|
13
16
|
}
|
|
14
17
|
scheduleFlush() {
|
|
15
18
|
if (this.isScheduled) {
|
package/utils/Queue.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/utils/Queue.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Manage tasks in a queue.\n */\nexport class Queue {\n /**\n * List of tasks.\n */\n tasks: Array<(...args: unknown[]) => unknown> = [];\n\n /**\n * Number of tasks running in a single batch.\n */\n concurrency = 10;\n\n /**\n * A function to schedule the next batch.\n */\n waiter: (cb: (...args: unknown[]) => unknown) => unknown;\n\n /**\n * Is schedule running?\n */\n isScheduled = false;\n\n /**\n * Constructor.\n *\n * @param {number} concurrency Number of tasks running in a single batch.\n * @param {(cb: (...args:unknown[]) => unknown) => unknown} waiter Scheduler for the next batch execution.\n */\n constructor(\n concurrency: number,\n waiter: (cb: (...args: unknown[]) => unknown) => unknown = (cb) => cb(),\n ) {\n this.concurrency = concurrency;\n this.waiter = waiter;\n }\n\n /**\n * Add a task to the queue.\n */\n add(task: (
|
|
5
|
-
"mappings": "AAGO,MAAM,MAAM;AAAA,EAIjB,QAAgD,CAAC;AAAA,EAKjD,cAAc;AAAA,EAKd;AAAA,EAKA,cAAc;AAAA,EAQd,YACE,aACA,SAA2D,CAAC,OAAO,GAAG,GACtE;AACA,SAAK,cAAc;AACnB,SAAK,SAAS;AAAA,EAChB;AAAA,EAKA,IAAI,
|
|
4
|
+
"sourcesContent": ["/**\n * Manage tasks in a queue.\n */\nexport class Queue {\n /**\n * List of tasks.\n */\n tasks: Array<(...args: unknown[]) => unknown> = [];\n\n /**\n * Number of tasks running in a single batch.\n */\n concurrency = 10;\n\n /**\n * A function to schedule the next batch.\n */\n waiter: (cb: (...args: unknown[]) => unknown) => unknown;\n\n /**\n * Is schedule running?\n */\n isScheduled = false;\n\n /**\n * Constructor.\n *\n * @param {number} concurrency Number of tasks running in a single batch.\n * @param {(cb: (...args:unknown[]) => unknown) => unknown} waiter Scheduler for the next batch execution.\n */\n constructor(\n concurrency: number,\n waiter: (cb: (...args: unknown[]) => unknown) => unknown = (cb) => cb(),\n ) {\n this.concurrency = concurrency;\n this.waiter = waiter;\n }\n\n /**\n * Add a task to the queue.\n */\n add(task: () => unknown) {\n const p = new Promise((resolve) => {\n this.tasks.push(() => resolve(task()));\n });\n this.scheduleFlush();\n return p;\n }\n\n /**\n * Schedule next flush.\n */\n scheduleFlush() {\n if (this.isScheduled) {\n return;\n }\n\n this.isScheduled = true;\n this.waiter(() => this.flush());\n }\n\n /**\n * Flush current batch.\n */\n flush() {\n this.run(this.tasks.splice(0, this.concurrency));\n this.isScheduled = false;\n\n if (this.tasks.length > 0) {\n this.scheduleFlush();\n }\n }\n\n /**\n * Run the queue.\n */\n run(tasks: Array<(...args: unknown[]) => unknown>) {\n let task;\n // eslint-disable-next-line no-cond-assign\n while ((task = tasks.shift())) {\n task();\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAGO,MAAM,MAAM;AAAA,EAIjB,QAAgD,CAAC;AAAA,EAKjD,cAAc;AAAA,EAKd;AAAA,EAKA,cAAc;AAAA,EAQd,YACE,aACA,SAA2D,CAAC,OAAO,GAAG,GACtE;AACA,SAAK,cAAc;AACnB,SAAK,SAAS;AAAA,EAChB;AAAA,EAKA,IAAI,MAAqB;AACvB,UAAM,IAAI,IAAI,QAAQ,CAAC,YAAY;AACjC,WAAK,MAAM,KAAK,MAAM,QAAQ,KAAK,CAAC,CAAC;AAAA,IACvC,CAAC;AACD,SAAK,cAAc;AACnB,WAAO;AAAA,EACT;AAAA,EAKA,gBAAgB;AACd,QAAI,KAAK,aAAa;AACpB;AAAA,IACF;AAEA,SAAK,cAAc;AACnB,SAAK,OAAO,MAAM,KAAK,MAAM,CAAC;AAAA,EAChC;AAAA,EAKA,QAAQ;AACN,SAAK,IAAI,KAAK,MAAM,OAAO,GAAG,KAAK,WAAW,CAAC;AAC/C,SAAK,cAAc;AAEnB,QAAI,KAAK,MAAM,SAAS,GAAG;AACzB,WAAK,cAAc;AAAA,IACrB;AAAA,EACF;AAAA,EAKA,IAAI,OAA+C;AACjD,QAAI;AAEJ,WAAQ,OAAO,MAAM,MAAM,GAAI;AAC7B,WAAK;AAAA,IACP;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
|
|
25
|
+
// packages/js-toolkit/utils/SmartQueue.ts
|
|
26
|
+
var SmartQueue_exports = {};
|
|
27
|
+
__export(SmartQueue_exports, {
|
|
28
|
+
SmartQueue: () => SmartQueue
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(SmartQueue_exports);
|
|
31
|
+
var import_Queue = require("./Queue.cjs");
|
|
32
|
+
var import_nextTick = __toESM(require("./nextTick.cjs"), 1);
|
|
33
|
+
var LONG_TASK_DURATION = 40;
|
|
34
|
+
var SmartQueue = class extends import_Queue.Queue {
|
|
35
|
+
waiter = import_nextTick.default;
|
|
36
|
+
constructor() {
|
|
37
|
+
super(Number.POSITIVE_INFINITY, import_nextTick.default);
|
|
38
|
+
}
|
|
39
|
+
flush() {
|
|
40
|
+
this.run(this.tasks);
|
|
41
|
+
this.isScheduled = false;
|
|
42
|
+
if (this.tasks.length > 0) {
|
|
43
|
+
this.scheduleFlush();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
run(tasks) {
|
|
47
|
+
let task;
|
|
48
|
+
const start = performance.now();
|
|
49
|
+
let now = start;
|
|
50
|
+
while (now - start < LONG_TASK_DURATION && (task = tasks.shift())) {
|
|
51
|
+
task();
|
|
52
|
+
now = performance.now();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
if (module.exports.default) module.exports = module.exports.default;
|
|
57
|
+
//# sourceMappingURL=SmartQueue.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/js-toolkit/utils/SmartQueue.ts"],
|
|
4
|
+
"sourcesContent": ["import { Queue } from './Queue.js';\nimport nextTick from './nextTick.js';\n\n/**\n * A task is considered long if it blocks the main thread for more thant 50ms.\n * By using 40ms as a limit, we make the bet that we can avoid long running\n * tasks by dispatching small tasks smartly.\n * @see https://developer.mozilla.org/en-US/docs/Glossary/Long_task\n */\nconst LONG_TASK_DURATION = 40;\n\n/**\n * Manage tasks in a smart queue.\n * Tasks will be automatically batch-called inside a single event loop\n * lasting no more than 50ms, which is considered a long task.\n */\nexport class SmartQueue extends Queue {\n /**\n * A function to schedule the next batch.\n */\n waiter = nextTick;\n\n /**\n * Class constructor.\n */\n constructor() {\n super(Number.POSITIVE_INFINITY, nextTick);\n }\n\n /**\n * Flush current batch.\n */\n flush() {\n this.run(this.tasks);\n this.isScheduled = false;\n\n if (this.tasks.length > 0) {\n this.scheduleFlush();\n }\n }\n\n /**\n * Run the queue.\n */\n run(tasks: Array<(...args: unknown[]) => unknown>) {\n let task;\n const start = performance.now();\n let now = start;\n // eslint-disable-next-line no-cond-assign\n while (now - start < LONG_TASK_DURATION && (task = tasks.shift())) {\n task();\n now = performance.now();\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AACtB,sBAAqB;AAQrB,IAAM,qBAAqB;AAOpB,IAAM,aAAN,cAAyB,mBAAM;AAAA,EAIpC,SAAS,gBAAAA;AAAA,EAKT,cAAc;AACZ,UAAM,OAAO,mBAAmB,gBAAAA,OAAQ;AAAA,EAC1C;AAAA,EAKA,QAAQ;AACN,SAAK,IAAI,KAAK,KAAK;AACnB,SAAK,cAAc;AAEnB,QAAI,KAAK,MAAM,SAAS,GAAG;AACzB,WAAK,cAAc;AAAA,IACrB;AAAA,EACF;AAAA,EAKA,IAAI,OAA+C;AACjD,QAAI;AACJ,UAAM,QAAQ,YAAY,IAAI;AAC9B,QAAI,MAAM;AAEV,WAAO,MAAM,QAAQ,uBAAuB,OAAO,MAAM,MAAM,IAAI;AACjE,WAAK;AACL,YAAM,YAAY,IAAI;AAAA,IACxB;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["nextTick"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Queue } from './Queue.js';
|
|
2
|
+
import nextTick from './nextTick.js';
|
|
3
|
+
/**
|
|
4
|
+
* Manage tasks in a smart queue.
|
|
5
|
+
* Tasks will be automatically batch-called inside a single event loop
|
|
6
|
+
* lasting no more than 50ms, which is considered a long task.
|
|
7
|
+
*/
|
|
8
|
+
export declare class SmartQueue extends Queue {
|
|
9
|
+
/**
|
|
10
|
+
* A function to schedule the next batch.
|
|
11
|
+
*/
|
|
12
|
+
waiter: typeof nextTick;
|
|
13
|
+
/**
|
|
14
|
+
* Class constructor.
|
|
15
|
+
*/
|
|
16
|
+
constructor();
|
|
17
|
+
/**
|
|
18
|
+
* Flush current batch.
|
|
19
|
+
*/
|
|
20
|
+
flush(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Run the queue.
|
|
23
|
+
*/
|
|
24
|
+
run(tasks: Array<(...args: unknown[]) => unknown>): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Queue } from "./Queue.js";
|
|
2
|
+
import nextTick from "./nextTick.js";
|
|
3
|
+
const LONG_TASK_DURATION = 40;
|
|
4
|
+
class SmartQueue extends Queue {
|
|
5
|
+
waiter = nextTick;
|
|
6
|
+
constructor() {
|
|
7
|
+
super(Number.POSITIVE_INFINITY, nextTick);
|
|
8
|
+
}
|
|
9
|
+
flush() {
|
|
10
|
+
this.run(this.tasks);
|
|
11
|
+
this.isScheduled = false;
|
|
12
|
+
if (this.tasks.length > 0) {
|
|
13
|
+
this.scheduleFlush();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
run(tasks) {
|
|
17
|
+
let task;
|
|
18
|
+
const start = performance.now();
|
|
19
|
+
let now = start;
|
|
20
|
+
while (now - start < LONG_TASK_DURATION && (task = tasks.shift())) {
|
|
21
|
+
task();
|
|
22
|
+
now = performance.now();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
SmartQueue
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=SmartQueue.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/js-toolkit/utils/SmartQueue.ts"],
|
|
4
|
+
"sourcesContent": ["import { Queue } from './Queue.js';\nimport nextTick from './nextTick.js';\n\n/**\n * A task is considered long if it blocks the main thread for more thant 50ms.\n * By using 40ms as a limit, we make the bet that we can avoid long running\n * tasks by dispatching small tasks smartly.\n * @see https://developer.mozilla.org/en-US/docs/Glossary/Long_task\n */\nconst LONG_TASK_DURATION = 40;\n\n/**\n * Manage tasks in a smart queue.\n * Tasks will be automatically batch-called inside a single event loop\n * lasting no more than 50ms, which is considered a long task.\n */\nexport class SmartQueue extends Queue {\n /**\n * A function to schedule the next batch.\n */\n waiter = nextTick;\n\n /**\n * Class constructor.\n */\n constructor() {\n super(Number.POSITIVE_INFINITY, nextTick);\n }\n\n /**\n * Flush current batch.\n */\n flush() {\n this.run(this.tasks);\n this.isScheduled = false;\n\n if (this.tasks.length > 0) {\n this.scheduleFlush();\n }\n }\n\n /**\n * Run the queue.\n */\n run(tasks: Array<(...args: unknown[]) => unknown>) {\n let task;\n const start = performance.now();\n let now = start;\n // eslint-disable-next-line no-cond-assign\n while (now - start < LONG_TASK_DURATION && (task = tasks.shift())) {\n task();\n now = performance.now();\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa;AACtB,OAAO,cAAc;AAQrB,MAAM,qBAAqB;AAOpB,MAAM,mBAAmB,MAAM;AAAA,EAIpC,SAAS;AAAA,EAKT,cAAc;AACZ,UAAM,OAAO,mBAAmB,QAAQ;AAAA,EAC1C;AAAA,EAKA,QAAQ;AACN,SAAK,IAAI,KAAK,KAAK;AACnB,SAAK,cAAc;AAEnB,QAAI,KAAK,MAAM,SAAS,GAAG;AACzB,WAAK,cAAc;AAAA,IACrB;AAAA,EACF;AAAA,EAKA,IAAI,OAA+C;AACjD,QAAI;AACJ,UAAM,QAAQ,YAAY,IAAI;AAC9B,QAAI,MAAM;AAEV,WAAO,MAAM,QAAQ,uBAAuB,OAAO,MAAM,MAAM,IAAI;AACjE,WAAK;AACL,YAAM,YAAY,IAAI;AAAA,IACxB;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/utils/index.cjs
CHANGED
|
@@ -27,6 +27,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
27
27
|
var utils_exports = {};
|
|
28
28
|
__export(utils_exports, {
|
|
29
29
|
Queue: () => import_Queue.Queue,
|
|
30
|
+
SmartQueue: () => import_SmartQueue.SmartQueue,
|
|
30
31
|
debounce: () => import_debounce.default,
|
|
31
32
|
focusTrap: () => import_focusTrap.default,
|
|
32
33
|
historyPush: () => import_history.push,
|
|
@@ -62,6 +63,8 @@ __reExport(utils_exports, require("./scheduler.cjs"), module.exports);
|
|
|
62
63
|
__reExport(utils_exports, require("./noop.cjs"), module.exports);
|
|
63
64
|
var import_tween = require("./tween.cjs");
|
|
64
65
|
var import_Queue = require("./Queue.cjs");
|
|
66
|
+
var import_SmartQueue = require("./SmartQueue.cjs");
|
|
65
67
|
__reExport(utils_exports, require("./dom/index.cjs"), module.exports);
|
|
68
|
+
__reExport(utils_exports, require("./wait.cjs"), module.exports);
|
|
66
69
|
if (module.exports.default) module.exports = module.exports.default;
|
|
67
70
|
//# sourceMappingURL=index.cjs.map
|
package/utils/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/utils/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { default as debounce } from './debounce.js';\nexport { default as focusTrap } from './focusTrap.js';\nexport { default as keyCodes } from './keyCodes.js';\nexport { default as memoize } from './memoize.js';\nexport { nextFrame } from './nextFrame.js';\nexport { default as nextTick } from './nextTick.js';\nexport { default as nextMicrotask } from './nextMicrotask.js';\nexport { default as throttle } from './throttle.js';\nexport { default as scrollTo } from './scrollTo.js';\nexport * from './is.js';\nexport * from './has.js';\n// eslint-disable-next-line import/extensions\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 * from './dom/index.js';\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAoC;AACpC,uBAAqC;AACrC,sBAAoC;AACpC,qBAAmC;AACnC,uBAA0B;AAC1B,sBAAoC;AACpC,2BAAyC;AACzC,sBAAoC;AACpC,sBAAoC;AACpC,0BAAc,qBATd;AAUA,0BAAc,sBAVd;AAYA,0BAAc,4BAZd;AAaA,qBAIO;AACP,0BAAc,gCAlBd;AAmBA,0BAAc,6BAnBd;AAoBA,0BAAc,+BApBd;AAqBA,0BAAc,4BArBd;AAsBA,0BAAc,uBAtBd;AAuBA,mBAAsB;AACtB,mBAAsB;AACtB,0BAAc,
|
|
4
|
+
"sourcesContent": ["export { default as debounce } from './debounce.js';\nexport { default as focusTrap } from './focusTrap.js';\nexport { default as keyCodes } from './keyCodes.js';\nexport { default as memoize } from './memoize.js';\nexport { nextFrame } from './nextFrame.js';\nexport { default as nextTick } from './nextTick.js';\nexport { default as nextMicrotask } from './nextMicrotask.js';\nexport { default as throttle } from './throttle.js';\nexport { default as scrollTo } from './scrollTo.js';\nexport * from './is.js';\nexport * from './has.js';\n// eslint-disable-next-line import/extensions\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';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAoC;AACpC,uBAAqC;AACrC,sBAAoC;AACpC,qBAAmC;AACnC,uBAA0B;AAC1B,sBAAoC;AACpC,2BAAyC;AACzC,sBAAoC;AACpC,sBAAoC;AACpC,0BAAc,qBATd;AAUA,0BAAc,sBAVd;AAYA,0BAAc,4BAZd;AAaA,qBAIO;AACP,0BAAc,gCAlBd;AAmBA,0BAAc,6BAnBd;AAoBA,0BAAc,+BApBd;AAqBA,0BAAc,4BArBd;AAsBA,0BAAc,uBAtBd;AAuBA,mBAAsB;AACtB,mBAAsB;AACtB,wBAA2B;AAC3B,0BAAc,4BA1Bd;AA2BA,0BAAc,uBA3Bd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/utils/index.d.ts
CHANGED
package/utils/index.js
CHANGED
|
@@ -22,9 +22,12 @@ export * from "./scheduler.js";
|
|
|
22
22
|
export * from "./noop.js";
|
|
23
23
|
import { tween } from "./tween.js";
|
|
24
24
|
import { Queue } from "./Queue.js";
|
|
25
|
+
import { SmartQueue } from "./SmartQueue.js";
|
|
25
26
|
export * from "./dom/index.js";
|
|
27
|
+
export * from "./wait.js";
|
|
26
28
|
export {
|
|
27
29
|
Queue,
|
|
30
|
+
SmartQueue,
|
|
28
31
|
default2 as debounce,
|
|
29
32
|
default3 as focusTrap,
|
|
30
33
|
push as historyPush,
|
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 { default as debounce } from './debounce.js';\nexport { default as focusTrap } from './focusTrap.js';\nexport { default as keyCodes } from './keyCodes.js';\nexport { default as memoize } from './memoize.js';\nexport { nextFrame } from './nextFrame.js';\nexport { default as nextTick } from './nextTick.js';\nexport { default as nextMicrotask } from './nextMicrotask.js';\nexport { default as throttle } from './throttle.js';\nexport { default as scrollTo } from './scrollTo.js';\nexport * from './is.js';\nexport * from './has.js';\n// eslint-disable-next-line import/extensions\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 * from './dom/index.js';\n"],
|
|
5
|
-
"mappings": "AAAA,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAA4B;AACrC,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAA0B;AACnC,SAAS,iBAAiB;AAC1B,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAAgC;AACzC,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAA2B;AACpC,cAAc;AACd,cAAc;AAEd,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,cAAc;",
|
|
4
|
+
"sourcesContent": ["export { default as debounce } from './debounce.js';\nexport { default as focusTrap } from './focusTrap.js';\nexport { default as keyCodes } from './keyCodes.js';\nexport { default as memoize } from './memoize.js';\nexport { nextFrame } from './nextFrame.js';\nexport { default as nextTick } from './nextTick.js';\nexport { default as nextMicrotask } from './nextMicrotask.js';\nexport { default as throttle } from './throttle.js';\nexport { default as scrollTo } from './scrollTo.js';\nexport * from './is.js';\nexport * from './has.js';\n// eslint-disable-next-line import/extensions\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';\n"],
|
|
5
|
+
"mappings": "AAAA,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAA4B;AACrC,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAA0B;AACnC,SAAS,iBAAiB;AAC1B,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAAgC;AACzC,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAA2B;AACpC,cAAc;AACd,cAAc;AAEd,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;",
|
|
6
6
|
"names": ["default"]
|
|
7
7
|
}
|
package/utils/nextTick.cjs
CHANGED
|
@@ -23,12 +23,9 @@ __export(nextTick_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(nextTick_exports);
|
|
25
25
|
var import_is = require("./is.cjs");
|
|
26
|
+
var import_wait = require("./wait.cjs");
|
|
26
27
|
async function nextTick(fn) {
|
|
27
|
-
return
|
|
28
|
-
setTimeout(() => {
|
|
29
|
-
resolve((0, import_is.isFunction)(fn) && fn());
|
|
30
|
-
}, 0);
|
|
31
|
-
});
|
|
28
|
+
return (0, import_wait.wait)().then((0, import_is.isFunction)(fn) && fn);
|
|
32
29
|
}
|
|
33
30
|
if (module.exports.default) module.exports = module.exports.default;
|
|
34
31
|
//# sourceMappingURL=nextTick.cjs.map
|
package/utils/nextTick.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/utils/nextTick.ts"],
|
|
4
|
-
"sourcesContent": ["import { isFunction } from './is.js';\n\n/**\n * Wait for the next tick.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default async function nextTick<T extends () => any>(\n fn?: T,\n): Promise<T extends void ? void : ReturnType<T>> {\n return
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA2B;
|
|
4
|
+
"sourcesContent": ["import { isFunction } from './is.js';\nimport { wait } from './wait.js';\n\n/**\n * Wait for the next tick.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default async function nextTick<T extends () => any>(\n fn?: T,\n): Promise<T extends void ? void : ReturnType<T>> {\n return wait().then(isFunction(fn) && (fn as ReturnType<T>));\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA2B;AAC3B,kBAAqB;AAMrB,eAAO,SACL,IACgD;AAChD,aAAO,kBAAK,EAAE,SAAK,sBAAW,EAAE,KAAM,EAAoB;AAC5D;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/utils/nextTick.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { isFunction } from "./is.js";
|
|
2
|
+
import { wait } from "./wait.js";
|
|
2
3
|
async function nextTick(fn) {
|
|
3
|
-
return
|
|
4
|
-
setTimeout(() => {
|
|
5
|
-
resolve(isFunction(fn) && fn());
|
|
6
|
-
}, 0);
|
|
7
|
-
});
|
|
4
|
+
return wait().then(isFunction(fn) && fn);
|
|
8
5
|
}
|
|
9
6
|
export {
|
|
10
7
|
nextTick as default
|
package/utils/nextTick.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/utils/nextTick.ts"],
|
|
4
|
-
"sourcesContent": ["import { isFunction } from './is.js';\n\n/**\n * Wait for the next tick.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default async function nextTick<T extends () => any>(\n fn?: T,\n): Promise<T extends void ? void : ReturnType<T>> {\n return
|
|
5
|
-
"mappings": "AAAA,SAAS,kBAAkB;
|
|
4
|
+
"sourcesContent": ["import { isFunction } from './is.js';\nimport { wait } from './wait.js';\n\n/**\n * Wait for the next tick.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default async function nextTick<T extends () => any>(\n fn?: T,\n): Promise<T extends void ? void : ReturnType<T>> {\n return wait().then(isFunction(fn) && (fn as ReturnType<T>));\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AAMrB,eAAO,SACL,IACgD;AAChD,SAAO,KAAK,EAAE,KAAK,WAAW,EAAE,KAAM,EAAoB;AAC5D;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/utils/wait.cjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/js-toolkit/utils/wait.ts
|
|
20
|
+
var wait_exports = {};
|
|
21
|
+
__export(wait_exports, {
|
|
22
|
+
wait: () => wait
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(wait_exports);
|
|
25
|
+
function wait(delay = 0) {
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
setTimeout(resolve, delay);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (module.exports.default) module.exports = module.exports.default;
|
|
31
|
+
//# sourceMappingURL=wait.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/js-toolkit/utils/wait.ts"],
|
|
4
|
+
"sourcesContent": ["export function wait(delay = 0) {\n return new Promise((resolve) => {\n setTimeout(resolve, delay);\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,KAAK,QAAQ,GAAG;AAC9B,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,eAAW,SAAS,KAAK;AAAA,EAC3B,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/utils/wait.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function wait(delay?: number): Promise<unknown>;
|
package/utils/wait.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/js-toolkit/utils/wait.ts"],
|
|
4
|
+
"sourcesContent": ["export function wait(delay = 0) {\n return new Promise((resolve) => {\n setTimeout(resolve, delay);\n });\n}\n"],
|
|
5
|
+
"mappings": "AAAO,SAAS,KAAK,QAAQ,GAAG;AAC9B,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,eAAW,SAAS,KAAK;AAAA,EAC3B,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|