sec commit

This commit is contained in:
2024-08-16 15:06:52 +05:30
parent 63dc2b340a
commit dc5b771f30
16489 changed files with 2607484 additions and 0 deletions

1
node_modules/framesync/lib/_tests/test.d.ts generated vendored Normal file
View File

@@ -0,0 +1 @@
export {};

126
node_modules/framesync/lib/_tests/test.js generated vendored Normal file
View File

@@ -0,0 +1,126 @@
import { __awaiter } from "tslib";
import sync, { cancelSync, flushSync } from "../";
import { onNextFrame } from "../on-next-frame";
describe("onNextFrame", () => {
it("fires callback on following frame", () => {
return new Promise((resolve) => onNextFrame(resolve));
});
});
describe("sync", () => {
it("fires callbacks in the correct order", () => {
return new Promise((resolve, reject) => {
const order = [];
sync.read(() => order.push(0));
sync.update(() => order.push(1));
sync.preRender(() => order.push(2));
sync.render(() => order.push(3));
sync.postRender(() => {
order.push(4);
if (order[0] === 0 &&
order[1] === 1 &&
order[2] === 2 &&
order[3] === 3 &&
order[4] === 4) {
resolve();
}
else {
reject(order);
}
});
});
});
it("cancels callbacks", () => {
return new Promise((resolve, reject) => {
let hasFired = false;
const process = sync.render(() => (hasFired = true));
sync.update(() => cancelSync.render(process));
sync.postRender(() => (hasFired ? reject(hasFired) : resolve()));
});
});
it("fires callback on current frame if scheduled with `true` within the same step", () => {
return new Promise((resolve, reject) => {
let v = 0;
sync.update(({ timestamp: prevTimestamp }) => {
v++;
sync.update(({ timestamp }) => {
v++;
if (timestamp !== prevTimestamp) {
reject(`${timestamp} ${prevTimestamp}`);
}
}, false, true);
});
sync.render(() => (v === 2 ? resolve() : reject(v)));
});
});
it("fires callback on next frame if scheduled with `true` outside the same step", () => {
return new Promise((resolve, reject) => {
let v = 0;
sync.update(() => v++);
sync.update(() => v++, false, true);
sync.render(() => (v === 2 ? resolve() : reject()));
});
});
it("uses default elapsed time if first fire", () => {
return new Promise((resolve, reject) => {
sync.update(({ delta: defaultElapsed }) => {
setTimeout(() => sync.update(({ delta }) => delta === defaultElapsed
? resolve()
: reject(defaultElapsed, delta)), 50);
});
});
});
it("correctly cancels", () => {
return new Promise((resolve, reject) => {
const callback = () => reject();
sync.read(() => cancelSync.update(callback));
sync.update(callback);
sync.render(() => resolve());
});
});
it("correctly keeps alive", () => {
return new Promise((resolve) => {
let v = 0;
sync.update(() => v++, true);
sync.render(() => v === 2 && resolve(), true);
});
});
it("correctly cancels a keepAlive process", () => {
return new Promise((resolve, reject) => {
let updateCount = 0;
let renderCount = 0;
const update = sync.update(() => {
updateCount++;
if (updateCount === 4)
cancelSync.update(update);
}, true);
sync.render(() => {
renderCount++;
if (renderCount === 6) {
if (renderCount !== updateCount) {
resolve();
}
else {
reject([renderCount, updateCount]);
}
}
}, true);
});
});
it("correctly keeps alive after a flush", () => __awaiter(void 0, void 0, void 0, function* () {
const promise = new Promise((resolve) => {
let v = 0;
sync.update(() => {
if (v === 2)
flushSync.update();
}, true);
sync.update(() => {
v++;
if (v > 6)
resolve(true);
}, true);
});
flushSync.update();
return expect(promise).resolves.toBe(true);
}));
});
//# sourceMappingURL=test.js.map

1
node_modules/framesync/lib/_tests/test.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

2
node_modules/framesync/lib/create-render-step.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import { Step } from "./types";
export declare function createRenderStep(runNextFrame: () => void): Step;

55
node_modules/framesync/lib/create-render-step.js generated vendored Normal file
View File

@@ -0,0 +1,55 @@
export function createRenderStep(runNextFrame) {
let toRun = [];
let toRunNextFrame = [];
let numToRun = 0;
let isProcessing = false;
let flushNextFrame = false;
const toKeepAlive = new WeakSet();
const step = {
schedule: (callback, keepAlive = false, immediate = false) => {
const addToCurrentFrame = immediate && isProcessing;
const buffer = addToCurrentFrame ? toRun : toRunNextFrame;
if (keepAlive)
toKeepAlive.add(callback);
if (buffer.indexOf(callback) === -1) {
buffer.push(callback);
if (addToCurrentFrame && isProcessing)
numToRun = toRun.length;
}
return callback;
},
cancel: (callback) => {
const index = toRunNextFrame.indexOf(callback);
if (index !== -1)
toRunNextFrame.splice(index, 1);
toKeepAlive.delete(callback);
},
process: (frameData) => {
if (isProcessing) {
flushNextFrame = true;
return;
}
isProcessing = true;
[toRun, toRunNextFrame] = [toRunNextFrame, toRun];
toRunNextFrame.length = 0;
numToRun = toRun.length;
if (numToRun) {
for (let i = 0; i < numToRun; i++) {
const callback = toRun[i];
callback(frameData);
if (toKeepAlive.has(callback)) {
step.schedule(callback);
runNextFrame();
}
}
}
isProcessing = false;
if (flushNextFrame) {
flushNextFrame = false;
step.process(frameData);
}
},
};
return step;
}
//# sourceMappingURL=create-render-step.js.map

1
node_modules/framesync/lib/create-render-step.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"create-render-step.js","sourceRoot":"","sources":["../src/create-render-step.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,gBAAgB,CAAC,YAAwB;IAKrD,IAAI,KAAK,GAAc,EAAE,CAAA;IACzB,IAAI,cAAc,GAAc,EAAE,CAAA;IAKlC,IAAI,QAAQ,GAAG,CAAC,CAAA;IAMhB,IAAI,YAAY,GAAG,KAAK,CAAA;IAExB,IAAI,cAAc,GAAG,KAAK,CAAA;IAK1B,MAAM,WAAW,GAAG,IAAI,OAAO,EAAW,CAAA;IAE1C,MAAM,IAAI,GAAS;QAIf,QAAQ,EAAE,CAAC,QAAQ,EAAE,SAAS,GAAG,KAAK,EAAE,SAAS,GAAG,KAAK,EAAE,EAAE;YACzD,MAAM,iBAAiB,GAAG,SAAS,IAAI,YAAY,CAAA;YACnD,MAAM,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAAA;YAEzD,IAAI,SAAS;gBAAE,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YAGxC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE;gBACjC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;gBAGrB,IAAI,iBAAiB,IAAI,YAAY;oBAAE,QA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modules/framesync/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,10 @@
import { Process, FrameData, CancelSync, FlushSync, Sync } from "./types";
declare const sync: Sync;
declare const cancelSync: CancelSync;
declare const flushSync: FlushSync;
declare const getFrameData: () => {
delta: number;
timestamp: number;
};
export default sync;
export { cancelSync, flushSync, getFrameData, FrameData, Process };

63
node_modules/framesync/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,63 @@
import { onNextFrame, defaultTimestep } from "./on-next-frame";
import { createRenderStep } from "./create-render-step";
const maxElapsed = 40;
let useDefaultElapsed = true;
let runNextFrame = false;
let isProcessing = false;
const frame = {
delta: 0,
timestamp: 0,
};
const stepsOrder = [
"read",
"update",
"preRender",
"render",
"postRender",
];
const steps = stepsOrder.reduce((acc, key) => {
acc[key] = createRenderStep(() => (runNextFrame = true));
return acc;
}, {});
const sync = stepsOrder.reduce((acc, key) => {
const step = steps[key];
acc[key] = (process, keepAlive = false, immediate = false) => {
if (!runNextFrame)
startLoop();
return step.schedule(process, keepAlive, immediate);
};
return acc;
}, {});
const cancelSync = stepsOrder.reduce((acc, key) => {
acc[key] = steps[key].cancel;
return acc;
}, {});
const flushSync = stepsOrder.reduce((acc, key) => {
acc[key] = () => steps[key].process(frame);
return acc;
}, {});
const processStep = (stepId) => steps[stepId].process(frame);
const processFrame = (timestamp) => {
runNextFrame = false;
frame.delta = useDefaultElapsed
? defaultTimestep
: Math.max(Math.min(timestamp - frame.timestamp, maxElapsed), 1);
frame.timestamp = timestamp;
isProcessing = true;
stepsOrder.forEach(processStep);
isProcessing = false;
if (runNextFrame) {
useDefaultElapsed = false;
onNextFrame(processFrame);
}
};
const startLoop = () => {
runNextFrame = true;
useDefaultElapsed = true;
if (!isProcessing)
onNextFrame(processFrame);
};
const getFrameData = () => frame;
export default sync;
export { cancelSync, flushSync, getFrameData };
//# sourceMappingURL=index.js.map

1
node_modules/framesync/lib/index.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.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AAE,WAAW,CAAC,YAAY,CAAC,CAAA;AAChD,CAAC,CAAA;AAED,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,KAAK,CAAA;AAEhC,eAAe,IAAI,CAAA;AACnB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAsB,CAAA"}

3
node_modules/framesync/lib/on-next-frame.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
/// <reference types="node" />
export declare const defaultTimestep: number;
export declare const onNextFrame: ((callback: FrameRequestCallback) => number) | ((callback: FrameRequestCallback) => NodeJS.Timeout);

8
node_modules/framesync/lib/on-next-frame.js generated vendored Normal file
View File

@@ -0,0 +1,8 @@
export const defaultTimestep = (1 / 60) * 1000;
const getCurrentTime = typeof performance !== "undefined"
? () => performance.now()
: () => Date.now();
export const onNextFrame = typeof window !== "undefined"
? (callback) => window.requestAnimationFrame(callback)
: (callback) => setTimeout(() => callback(getCurrentTime()), defaultTimestep);
//# sourceMappingURL=on-next-frame.js.map

1
node_modules/framesync/lib/on-next-frame.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"on-next-frame.js","sourceRoot":"","sources":["../src/on-next-frame.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAA;AAE9C,MAAM,cAAc,GAChB,OAAO,WAAW,KAAK,WAAW;IAC9B,CAAC,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE;IACzB,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;AAE1B,MAAM,CAAC,MAAM,WAAW,GACpB,OAAO,MAAM,KAAK,WAAW;IACzB,CAAC,CAAC,CAAC,QAA8B,EAAE,EAAE,CAC/B,MAAM,CAAC,qBAAqB,CAAC,QAAQ,CAAC;IAC5C,CAAC,CAAC,CAAC,QAA8B,EAAE,EAAE,CAC/B,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,EAAE,eAAe,CAAC,CAAA"}

24
node_modules/framesync/lib/types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,24 @@
export declare type FrameData = {
delta: number;
timestamp: number;
};
export declare type Process = (data: FrameData) => void;
export declare type Schedule = (process: Process, keepAlive?: boolean, immediate?: boolean) => Process;
export interface Step {
schedule: Schedule;
cancel: (process: Process) => void;
process: (frame: FrameData) => void;
}
export declare type StepId = "read" | "update" | "postUpdate" | "preRender" | "render" | "postRender";
export declare type Sync = {
[key in StepId]: Schedule;
};
export declare type Steps = {
[key in StepId]: Step;
};
export declare type CancelSync = {
[key in StepId]: (process: Process) => void;
};
export declare type FlushSync = {
[key in StepId]: () => void;
};

1
node_modules/framesync/lib/types.js generated vendored Normal file
View File

@@ -0,0 +1 @@
//# sourceMappingURL=types.js.map

1
node_modules/framesync/lib/types.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}