@psytask/core 1.1.2 → 1.1.3
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 +14 -9
- 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.3 cubxx MIT */
|
|
2
2
|
const symbol = Symbol.dispose ?? /* @__PURE__ */ Symbol.for("Symbol.dispose");
|
|
3
3
|
class EventEmitter {
|
|
4
4
|
listeners = {};
|
|
@@ -62,13 +62,18 @@ const createTimer = (shouldStop) => {
|
|
|
62
62
|
const timer = {
|
|
63
63
|
start: (cb) => new Promise((resolve) => {
|
|
64
64
|
const records = [];
|
|
65
|
-
|
|
66
|
-
currentFrameTime && record(currentFrameTime);
|
|
65
|
+
currentFrameTime && (records.push(currentFrameTime), cb?.(currentFrameTime));
|
|
67
66
|
const frame = (time) => {
|
|
68
|
-
|
|
67
|
+
const is_stoped = shouldStop(time, records);
|
|
68
|
+
records.push(time);
|
|
69
|
+
is_stoped ? timer.stop() : (cb?.(time), handle = rAF(frame));
|
|
69
70
|
};
|
|
70
71
|
let handle = rAF(frame);
|
|
71
|
-
timer.stop = () =>
|
|
72
|
+
timer.stop = () => {
|
|
73
|
+
records.pop();
|
|
74
|
+
cancelAnimationFrame(handle);
|
|
75
|
+
resolve(records);
|
|
76
|
+
};
|
|
72
77
|
}),
|
|
73
78
|
stop() {
|
|
74
79
|
}
|
|
@@ -133,10 +138,10 @@ class Scene extends EventEmitter {
|
|
|
133
138
|
*/
|
|
134
139
|
//@ts-expect-error impl generic component
|
|
135
140
|
show = this.#show;
|
|
136
|
-
/** Add
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
141
|
+
/** Add close task as Microtask if is caled in the frame else next rAF. */
|
|
142
|
+
close() {
|
|
143
|
+
const t = this.#timer;
|
|
144
|
+
(currentFrameTime ? queueMicrotask : rAF)(() => t.stop());
|
|
140
145
|
}
|
|
141
146
|
async #show(patchProps) {
|
|
142
147
|
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 p{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===0&&delete this.listeners[t]),this}once(t,s){const e=r=>{try{s(r)}finally{this.off(t,e)}};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 h=o(a,r);r.push(a),h?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&&l.push(e);const n=t(r);e&&l.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}}}),l=[],P=()=>l[l.length-1]??y("Not found current scene");class k extends p{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:h,data:u}=r.render(t,{...n},this.on("dispose",()=>e.remove()));this.#t=i(),this.#s=a,this.data=u,e.append(...h)}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{p as EventEmitter,k as Scene,F as createComponentAdapter,A as createTimer,E as generic,P as getCurrentScene};
|