@psytask/core 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -2
- package/dist/index.js +16 -17
- package/dist/index.min.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -216,8 +216,8 @@ declare class Scene<T extends MaybeGenericComponent> extends EventEmitter<SceneE
|
|
|
216
216
|
* @param options - {@link SceneOptions}
|
|
217
217
|
*/
|
|
218
218
|
constructor(component: T, options: SceneOptions<T>);
|
|
219
|
-
/** Add
|
|
220
|
-
close():
|
|
219
|
+
/** Add close task as Microtask if is caled in the frame else next rAF. */
|
|
220
|
+
close(): void;
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
export { EventEmitter, Scene, createComponentAdapter, createTimer, generic, getCurrentScene };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @psytask/core v1.1.
|
|
1
|
+
/** @psytask/core v1.1.4 cubxx MIT */
|
|
2
2
|
const symbol = Symbol.dispose ?? /* @__PURE__ */ Symbol.for("Symbol.dispose");
|
|
3
3
|
class EventEmitter {
|
|
4
4
|
listeners = {};
|
|
@@ -15,19 +15,13 @@ class EventEmitter {
|
|
|
15
15
|
const listeners = this.listeners[type];
|
|
16
16
|
if (listeners) {
|
|
17
17
|
listeners.delete(listener);
|
|
18
|
-
listeners.size
|
|
18
|
+
listeners.size || delete this.listeners[type];
|
|
19
19
|
}
|
|
20
20
|
return this;
|
|
21
21
|
}
|
|
22
22
|
/** Add one-time event listener, can not be removed manually */
|
|
23
23
|
once(type, listener) {
|
|
24
|
-
const wrapper = (evt) =>
|
|
25
|
-
try {
|
|
26
|
-
listener(evt);
|
|
27
|
-
} finally {
|
|
28
|
-
this.off(type, wrapper);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
24
|
+
const wrapper = (evt) => (this.off(type, wrapper), listener(evt));
|
|
31
25
|
this.on(type, wrapper);
|
|
32
26
|
return this;
|
|
33
27
|
}
|
|
@@ -62,13 +56,18 @@ const createTimer = (shouldStop) => {
|
|
|
62
56
|
const timer = {
|
|
63
57
|
start: (cb) => new Promise((resolve) => {
|
|
64
58
|
const records = [];
|
|
65
|
-
|
|
66
|
-
currentFrameTime && record(currentFrameTime);
|
|
59
|
+
currentFrameTime && (records.push(currentFrameTime), cb?.(currentFrameTime));
|
|
67
60
|
const frame = (time) => {
|
|
68
|
-
|
|
61
|
+
const is_stoped = shouldStop(time, records);
|
|
62
|
+
records.push(time);
|
|
63
|
+
is_stoped ? timer.stop() : (cb?.(time), handle = rAF(frame));
|
|
69
64
|
};
|
|
70
65
|
let handle = rAF(frame);
|
|
71
|
-
timer.stop = () =>
|
|
66
|
+
timer.stop = () => {
|
|
67
|
+
records.pop();
|
|
68
|
+
cancelAnimationFrame(handle);
|
|
69
|
+
resolve(records);
|
|
70
|
+
};
|
|
72
71
|
}),
|
|
73
72
|
stop() {
|
|
74
73
|
}
|
|
@@ -133,10 +132,10 @@ class Scene extends EventEmitter {
|
|
|
133
132
|
*/
|
|
134
133
|
//@ts-expect-error impl generic component
|
|
135
134
|
show = this.#show;
|
|
136
|
-
/** Add
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
/** Add close task as Microtask if is caled in the frame else next rAF. */
|
|
136
|
+
close() {
|
|
137
|
+
const t = this.#timer;
|
|
138
|
+
(currentFrameTime ? queueMicrotask : rAF)(() => t.stop());
|
|
140
139
|
}
|
|
141
140
|
async #show(patchProps) {
|
|
142
141
|
const { root, defaultProps } = this.options;
|
package/dist/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const f=Symbol.dispose??Symbol.for("Symbol.dispose");class
|
|
1
|
+
const f=Symbol.dispose??Symbol.for("Symbol.dispose");class l{listeners={};[f](){this.emit("dispose")}on(t,s){return(this.listeners[t]??=new Set).add(s),this}off(t,s){const e=this.listeners[t];return e&&(e.delete(s),e.size||delete this.listeners[t]),this}once(t,s){const e=r=>(this.off(t,e),s(r));return this.on(t,e),this}emit(t,...[s]){const e=this.listeners[t];if(e)for(const r of[...e])r(s);return this}}const y=o=>{throw Error(o)},d=requestAnimationFrame,w=Object,b=(o,t)=>w.assign(o,t),S=document;new Proxy({},{get:(o,t)=>s=>b(S.createElement(t),s)});const g=o=>Array.isArray(o)?o:[o];let c;const m=o=>(c=o,setTimeout(()=>c=0),d(m)),A=o=>{c??m(0);const t={start:s=>new Promise(e=>{const r=[];c&&(r.push(c),s?.(c));const n=a=>{const p=o(a,r);r.push(a),p?t.stop():(s?.(a),i=d(n))};let i=d(n);t.stop=()=>{r.pop(),cancelAnimationFrame(i),e(r)}}),stop(){}};return t},E=o=>o,F=o=>({wrap:t=>(s=>t(o(s))),render:(t,s,e)=>{const r=o(s);e&&h.push(e);const n=t(r);e&&h.pop();let i;const a=g(typeof n!="string"&&"node"in n?(i=n.data,n.node):n);return{props:r,nodes:a,data:i}}}),h=[],P=()=>h[h.length-1]??y("Not found current scene");class k extends l{constructor(t,s){super(),this.options=s;const{root:e,adapter:r,defaultProps:n,timer:i}=s;(this.root=e).tabIndex=-1,e.style.scale="0";const{props:a,nodes:p,data:u}=r.render(t,{...n},this.on("dispose",()=>e.remove()));this.#t=i(),this.#s=a,this.data=u,e.append(...p)}root;#t;#s;data;show=this.#e;close(){const t=this.#t;(c?queueMicrotask:d)(()=>t.stop())}async#e(t){const{root:s,defaultProps:e}=this.options,r={...e,...t};for(const i of Object.keys({...this.#s,...r}))this.#s[i]=r[i];this.emit("show"),s.style.scale="1",s.focus();const n=await this.#t.start(i=>this.emit("frame",i));return s.style.scale="0",{...this.emit("close").data?.(),frame_times:n,duration:c-n[0]}}}export{l as EventEmitter,k as Scene,F as createComponentAdapter,A as createTimer,E as generic,P as getCurrentScene};
|