@meursyphus/flitter 2.0.3 → 2.1.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/index.cjs CHANGED
@@ -13831,23 +13831,95 @@ var Scheduler = class {
13831
13831
  };
13832
13832
  var Scheduler_default = Scheduler;
13833
13833
 
13834
+ // src/framework/Vsync.ts
13835
+ var Vsync = class _Vsync {
13836
+ constructor() {
13837
+ __publicField(this, "callbacks");
13838
+ __publicField(this, "frameRequested");
13839
+ __publicField(this, "rafId");
13840
+ /**
13841
+ * Handles the animation frame by executing all queued callbacks.
13842
+ */
13843
+ __publicField(this, "handleFrame", (time) => {
13844
+ this.frameRequested = false;
13845
+ this.rafId = null;
13846
+ const callbacksToRun = [...this.callbacks];
13847
+ this.callbacks = [];
13848
+ for (const callback of callbacksToRun) {
13849
+ callback(time);
13850
+ }
13851
+ if (this.callbacks.length > 0 && !this.frameRequested) {
13852
+ this.frameRequested = true;
13853
+ this.rafId = requestAnimationFrame(this.handleFrame);
13854
+ }
13855
+ });
13856
+ this.callbacks = [];
13857
+ this.frameRequested = false;
13858
+ this.rafId = null;
13859
+ }
13860
+ static getInstance() {
13861
+ if (typeof window === "undefined") {
13862
+ throw new Error("Vsync requires window object");
13863
+ }
13864
+ if (!window.__flitter_vsync__) {
13865
+ window.__flitter_vsync__ = new _Vsync();
13866
+ }
13867
+ return window.__flitter_vsync__;
13868
+ }
13869
+ /**
13870
+ * Schedules a callback to be executed in the next animation frame.
13871
+ * If there's already a frame requested, the callback will be queued
13872
+ * to run with other callbacks in that frame.
13873
+ */
13874
+ requestCallback(callback) {
13875
+ this.callbacks.push(callback);
13876
+ if (!this.frameRequested) {
13877
+ this.frameRequested = true;
13878
+ this.rafId = requestAnimationFrame(this.handleFrame);
13879
+ }
13880
+ }
13881
+ /**
13882
+ * Removes a previously scheduled callback.
13883
+ */
13884
+ cancelCallback(callback) {
13885
+ const index = this.callbacks.indexOf(callback);
13886
+ if (index !== -1) {
13887
+ this.callbacks.splice(index, 1);
13888
+ }
13889
+ if (this.callbacks.length === 0 && this.rafId !== null) {
13890
+ cancelAnimationFrame(this.rafId);
13891
+ this.frameRequested = false;
13892
+ this.rafId = null;
13893
+ }
13894
+ }
13895
+ };
13896
+
13834
13897
  // src/framework/RenderFrameDispatcher.ts
13898
+ var _vsync;
13835
13899
  var RenderFrameDispatcher = class {
13836
13900
  constructor({ onFrame } = {}) {
13837
13901
  __publicField(this, "onFrame");
13902
+ __privateAdd(this, _vsync, null);
13838
13903
  this.onFrame = onFrame;
13839
13904
  }
13905
+ get vsync() {
13906
+ if (!__privateGet(this, _vsync)) {
13907
+ __privateSet(this, _vsync, Vsync.getInstance());
13908
+ }
13909
+ return __privateGet(this, _vsync);
13910
+ }
13840
13911
  setOnFrame(callback) {
13841
13912
  this.onFrame = () => callback();
13842
13913
  }
13843
13914
  dispatch() {
13844
13915
  if (typeof window === "undefined") return;
13845
- window.requestAnimationFrame(() => {
13916
+ this.vsync.requestCallback(() => {
13846
13917
  var _a;
13847
13918
  (_a = this.onFrame) == null ? void 0 : _a.call(this);
13848
13919
  });
13849
13920
  }
13850
13921
  };
13922
+ _vsync = new WeakMap();
13851
13923
  var RenderFrameDispatcher_default = RenderFrameDispatcher;
13852
13924
 
13853
13925
  // src/framework/Globalkey.ts
package/index.d.cts CHANGED
@@ -3595,8 +3595,36 @@ declare class CanvasPainter extends Painter$1 {
3595
3595
  skippedPaintingOnLayer(): void;
3596
3596
  }
3597
3597
 
3598
+ /**
3599
+ * Vsync manages requestAnimationFrame calls by queuing callbacks and executing them
3600
+ * in a single animation frame to optimize performance.
3601
+ */
3602
+ declare class Vsync {
3603
+ private callbacks;
3604
+ private frameRequested;
3605
+ private rafId;
3606
+ private constructor();
3607
+ static getInstance(): Vsync;
3608
+ /**
3609
+ * Schedules a callback to be executed in the next animation frame.
3610
+ * If there's already a frame requested, the callback will be queued
3611
+ * to run with other callbacks in that frame.
3612
+ */
3613
+ requestCallback(callback: (time: number) => void): void;
3614
+ /**
3615
+ * Removes a previously scheduled callback.
3616
+ */
3617
+ cancelCallback(callback: (time: number) => void): void;
3618
+ /**
3619
+ * Handles the animation frame by executing all queued callbacks.
3620
+ */
3621
+ private handleFrame;
3622
+ }
3623
+
3598
3624
  declare class RenderFrameDispatcher {
3625
+ #private;
3599
3626
  private onFrame?;
3627
+ get vsync(): Vsync;
3600
3628
  constructor({ onFrame }?: {
3601
3629
  onFrame?: () => void;
3602
3630
  });
package/index.d.ts CHANGED
@@ -3595,8 +3595,36 @@ declare class CanvasPainter extends Painter$1 {
3595
3595
  skippedPaintingOnLayer(): void;
3596
3596
  }
3597
3597
 
3598
+ /**
3599
+ * Vsync manages requestAnimationFrame calls by queuing callbacks and executing them
3600
+ * in a single animation frame to optimize performance.
3601
+ */
3602
+ declare class Vsync {
3603
+ private callbacks;
3604
+ private frameRequested;
3605
+ private rafId;
3606
+ private constructor();
3607
+ static getInstance(): Vsync;
3608
+ /**
3609
+ * Schedules a callback to be executed in the next animation frame.
3610
+ * If there's already a frame requested, the callback will be queued
3611
+ * to run with other callbacks in that frame.
3612
+ */
3613
+ requestCallback(callback: (time: number) => void): void;
3614
+ /**
3615
+ * Removes a previously scheduled callback.
3616
+ */
3617
+ cancelCallback(callback: (time: number) => void): void;
3618
+ /**
3619
+ * Handles the animation frame by executing all queued callbacks.
3620
+ */
3621
+ private handleFrame;
3622
+ }
3623
+
3598
3624
  declare class RenderFrameDispatcher {
3625
+ #private;
3599
3626
  private onFrame?;
3627
+ get vsync(): Vsync;
3600
3628
  constructor({ onFrame }?: {
3601
3629
  onFrame?: () => void;
3602
3630
  });
package/index.global.js CHANGED
@@ -14157,23 +14157,95 @@
14157
14157
  };
14158
14158
  var Scheduler_default = Scheduler;
14159
14159
 
14160
+ // src/framework/Vsync.ts
14161
+ var Vsync = class _Vsync {
14162
+ constructor() {
14163
+ __publicField(this, "callbacks");
14164
+ __publicField(this, "frameRequested");
14165
+ __publicField(this, "rafId");
14166
+ /**
14167
+ * Handles the animation frame by executing all queued callbacks.
14168
+ */
14169
+ __publicField(this, "handleFrame", (time) => {
14170
+ this.frameRequested = false;
14171
+ this.rafId = null;
14172
+ const callbacksToRun = [...this.callbacks];
14173
+ this.callbacks = [];
14174
+ for (const callback of callbacksToRun) {
14175
+ callback(time);
14176
+ }
14177
+ if (this.callbacks.length > 0 && !this.frameRequested) {
14178
+ this.frameRequested = true;
14179
+ this.rafId = requestAnimationFrame(this.handleFrame);
14180
+ }
14181
+ });
14182
+ this.callbacks = [];
14183
+ this.frameRequested = false;
14184
+ this.rafId = null;
14185
+ }
14186
+ static getInstance() {
14187
+ if (typeof window === "undefined") {
14188
+ throw new Error("Vsync requires window object");
14189
+ }
14190
+ if (!window.__flitter_vsync__) {
14191
+ window.__flitter_vsync__ = new _Vsync();
14192
+ }
14193
+ return window.__flitter_vsync__;
14194
+ }
14195
+ /**
14196
+ * Schedules a callback to be executed in the next animation frame.
14197
+ * If there's already a frame requested, the callback will be queued
14198
+ * to run with other callbacks in that frame.
14199
+ */
14200
+ requestCallback(callback) {
14201
+ this.callbacks.push(callback);
14202
+ if (!this.frameRequested) {
14203
+ this.frameRequested = true;
14204
+ this.rafId = requestAnimationFrame(this.handleFrame);
14205
+ }
14206
+ }
14207
+ /**
14208
+ * Removes a previously scheduled callback.
14209
+ */
14210
+ cancelCallback(callback) {
14211
+ const index = this.callbacks.indexOf(callback);
14212
+ if (index !== -1) {
14213
+ this.callbacks.splice(index, 1);
14214
+ }
14215
+ if (this.callbacks.length === 0 && this.rafId !== null) {
14216
+ cancelAnimationFrame(this.rafId);
14217
+ this.frameRequested = false;
14218
+ this.rafId = null;
14219
+ }
14220
+ }
14221
+ };
14222
+
14160
14223
  // src/framework/RenderFrameDispatcher.ts
14224
+ var _vsync;
14161
14225
  var RenderFrameDispatcher = class {
14162
14226
  constructor({ onFrame } = {}) {
14163
14227
  __publicField(this, "onFrame");
14228
+ __privateAdd(this, _vsync, null);
14164
14229
  this.onFrame = onFrame;
14165
14230
  }
14231
+ get vsync() {
14232
+ if (!__privateGet(this, _vsync)) {
14233
+ __privateSet(this, _vsync, Vsync.getInstance());
14234
+ }
14235
+ return __privateGet(this, _vsync);
14236
+ }
14166
14237
  setOnFrame(callback) {
14167
14238
  this.onFrame = () => callback();
14168
14239
  }
14169
14240
  dispatch() {
14170
14241
  if (typeof window === "undefined") return;
14171
- window.requestAnimationFrame(() => {
14242
+ this.vsync.requestCallback(() => {
14172
14243
  var _a;
14173
14244
  (_a = this.onFrame) == null ? void 0 : _a.call(this);
14174
14245
  });
14175
14246
  }
14176
14247
  };
14248
+ _vsync = new WeakMap();
14177
14249
  var RenderFrameDispatcher_default = RenderFrameDispatcher;
14178
14250
 
14179
14251
  // src/framework/Globalkey.ts
package/index.js CHANGED
@@ -13831,23 +13831,95 @@ var Scheduler = class {
13831
13831
  };
13832
13832
  var Scheduler_default = Scheduler;
13833
13833
 
13834
+ // src/framework/Vsync.ts
13835
+ var Vsync = class _Vsync {
13836
+ constructor() {
13837
+ __publicField(this, "callbacks");
13838
+ __publicField(this, "frameRequested");
13839
+ __publicField(this, "rafId");
13840
+ /**
13841
+ * Handles the animation frame by executing all queued callbacks.
13842
+ */
13843
+ __publicField(this, "handleFrame", (time) => {
13844
+ this.frameRequested = false;
13845
+ this.rafId = null;
13846
+ const callbacksToRun = [...this.callbacks];
13847
+ this.callbacks = [];
13848
+ for (const callback of callbacksToRun) {
13849
+ callback(time);
13850
+ }
13851
+ if (this.callbacks.length > 0 && !this.frameRequested) {
13852
+ this.frameRequested = true;
13853
+ this.rafId = requestAnimationFrame(this.handleFrame);
13854
+ }
13855
+ });
13856
+ this.callbacks = [];
13857
+ this.frameRequested = false;
13858
+ this.rafId = null;
13859
+ }
13860
+ static getInstance() {
13861
+ if (typeof window === "undefined") {
13862
+ throw new Error("Vsync requires window object");
13863
+ }
13864
+ if (!window.__flitter_vsync__) {
13865
+ window.__flitter_vsync__ = new _Vsync();
13866
+ }
13867
+ return window.__flitter_vsync__;
13868
+ }
13869
+ /**
13870
+ * Schedules a callback to be executed in the next animation frame.
13871
+ * If there's already a frame requested, the callback will be queued
13872
+ * to run with other callbacks in that frame.
13873
+ */
13874
+ requestCallback(callback) {
13875
+ this.callbacks.push(callback);
13876
+ if (!this.frameRequested) {
13877
+ this.frameRequested = true;
13878
+ this.rafId = requestAnimationFrame(this.handleFrame);
13879
+ }
13880
+ }
13881
+ /**
13882
+ * Removes a previously scheduled callback.
13883
+ */
13884
+ cancelCallback(callback) {
13885
+ const index = this.callbacks.indexOf(callback);
13886
+ if (index !== -1) {
13887
+ this.callbacks.splice(index, 1);
13888
+ }
13889
+ if (this.callbacks.length === 0 && this.rafId !== null) {
13890
+ cancelAnimationFrame(this.rafId);
13891
+ this.frameRequested = false;
13892
+ this.rafId = null;
13893
+ }
13894
+ }
13895
+ };
13896
+
13834
13897
  // src/framework/RenderFrameDispatcher.ts
13898
+ var _vsync;
13835
13899
  var RenderFrameDispatcher = class {
13836
13900
  constructor({ onFrame } = {}) {
13837
13901
  __publicField(this, "onFrame");
13902
+ __privateAdd(this, _vsync, null);
13838
13903
  this.onFrame = onFrame;
13839
13904
  }
13905
+ get vsync() {
13906
+ if (!__privateGet(this, _vsync)) {
13907
+ __privateSet(this, _vsync, Vsync.getInstance());
13908
+ }
13909
+ return __privateGet(this, _vsync);
13910
+ }
13840
13911
  setOnFrame(callback) {
13841
13912
  this.onFrame = () => callback();
13842
13913
  }
13843
13914
  dispatch() {
13844
13915
  if (typeof window === "undefined") return;
13845
- window.requestAnimationFrame(() => {
13916
+ this.vsync.requestCallback(() => {
13846
13917
  var _a;
13847
13918
  (_a = this.onFrame) == null ? void 0 : _a.call(this);
13848
13919
  });
13849
13920
  }
13850
13921
  };
13922
+ _vsync = new WeakMap();
13851
13923
  var RenderFrameDispatcher_default = RenderFrameDispatcher;
13852
13924
 
13853
13925
  // src/framework/Globalkey.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meursyphus/flitter",
3
- "version": "2.0.3",
3
+ "version": "2.1.0",
4
4
  "description": "Flitter: A high-performance JavaScript rendering engine and framework inspired by Flutter. Features declarative programming, SVG and Canvas support, and optimized for complex data visualizations, interactive charts, and graphic editors in web applications.",
5
5
  "keywords": [
6
6
  "rendering-engine",
@@ -51,14 +51,14 @@
51
51
  "url": "https://github.com/meursyphus/flitter/issues"
52
52
  },
53
53
  "main": "./index.cjs",
54
+ "module": "./index.js",
55
+ "types": "./index.d.ts",
54
56
  "type": "module",
55
57
  "publishConfig": {
56
58
  "access": "public"
57
59
  },
58
- "module": "./index.js",
59
60
  "exports": {
60
61
  "import": "./index.js",
61
62
  "default": "./index.js"
62
- },
63
- "types": "./index.d.ts"
63
+ }
64
64
  }