ziko 0.49.1 → 0.49.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/ziko.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  /*
3
3
  Project: ziko.js
4
4
  Author: Zakaria Elalaoui
5
- Date : Sat Nov 22 2025 13:34:29 GMT+0100 (UTC+01:00)
5
+ Date : Tue Nov 25 2025 19:11:53 GMT+0100 (UTC+01:00)
6
6
  Git-Repo : https://github.com/zakarialaoui10/ziko.js
7
7
  Git-Wiki : https://github.com/zakarialaoui10/ziko.js/wiki
8
8
  Released under MIT License
@@ -1179,17 +1179,143 @@ const __CACHE__ = {
1179
1179
  }
1180
1180
  };
1181
1181
 
1182
+ class ZikoUseChannel{
1183
+ constructor(name = ""){
1184
+ this.channel = new BroadcastChannel(name);
1185
+ this.EVENTS_DATAS_PAIRS = new Map();
1186
+ this.EVENTS_HANDLERS_PAIRS = new Map();
1187
+ this.LAST_RECEIVED_EVENT = "";
1188
+ this.UUID="ziko-channel"+Random.string(10);
1189
+ this.SUBSCRIBERS = new Set([this.UUID]);
1190
+ }
1191
+ get broadcast(){
1192
+ // update receiver
1193
+ return this;
1194
+ }
1195
+ emit(event, data){
1196
+ this.EVENTS_DATAS_PAIRS.set(event,data);
1197
+ this.#maintainEmit(event);
1198
+ return this;
1199
+ }
1200
+ on(event,handler=console.log){
1201
+ this.EVENTS_HANDLERS_PAIRS.set(event,handler);
1202
+ this.#maintainOn();
1203
+ return this;
1204
+ }
1205
+ #maintainOn(){
1206
+ this.channel.onmessage = (e) => {
1207
+ this.LAST_RECEIVED_EVENT=e.data.last_sended_event;
1208
+ const USER_ID=e.data.userId;
1209
+ this.SUBSCRIBERS.add(USER_ID);
1210
+ const Data=e.data.EVENTS_DATAS_PAIRS.get(this.LAST_RECEIVED_EVENT);
1211
+ const Handler=this.EVENTS_HANDLERS_PAIRS.get(this.LAST_RECEIVED_EVENT);
1212
+ if(Data && Handler)Handler(Data);
1213
+ };
1214
+ return this;
1215
+ }
1216
+ #maintainEmit(event){
1217
+ this.channel.postMessage({
1218
+ EVENTS_DATAS_PAIRS:this.EVENTS_DATAS_PAIRS,
1219
+ last_sended_event:event,
1220
+ userId:this.UUID
1221
+ });
1222
+ return this;
1223
+ }
1224
+ close(){
1225
+ this.channel.close();
1226
+ return this;
1227
+ }
1228
+ }
1229
+ const useChannel = name => new ZikoUseChannel(name);
1230
+
1231
+ // To do : remove old items
1232
+ class ZikoUseStorage{
1233
+ constructor(storage, globalKey, initialValue){
1234
+ this.cache={
1235
+ storage,
1236
+ globalKey,
1237
+ channel:useChannel(`Ziko:useStorage-${globalKey}`),
1238
+ oldItemKeys:new Set()
1239
+ };
1240
+ this.#init(initialValue);
1241
+ this.#maintain();
1242
+ }
1243
+ get items(){
1244
+ return JSON.parse(this.cache.storage[this.cache.globalKey]??null);
1245
+ }
1246
+ #maintain() {
1247
+ for(let i in this.items)Object.assign(this, { [[i]]: this.items[i] });
1248
+ }
1249
+ #init(initialValue){
1250
+ this.cache.channel=useChannel(`Ziko:useStorage-${this.cache.globalKey}`);
1251
+ this.cache.channel.on("Ziko-Storage-Updated",()=>this.#maintain());
1252
+ if(!initialValue)return;
1253
+ if(this.cache.storage[this.cache.globalKey]){
1254
+ Object.keys(this.items).forEach(key=>this.cache.oldItemKeys.add(key));
1255
+ // console.group("Ziko:useStorage")
1256
+ // console.warn(`Storage key '${this.cache.globalKey}' already exists. we will not overwrite it.`);
1257
+ // console.info(`%cWe'll keep the existing data.`,"background-color:#2222dd; color:gold;");
1258
+ // console.group("")
1259
+ }
1260
+ else this.set(initialValue);
1261
+ }
1262
+ set(data){
1263
+ this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(data));
1264
+ this.cache.channel.emit("Ziko-Storage-Updated",{});
1265
+ Object.keys(data).forEach(key=>this.cache.oldItemKeys.add(key));
1266
+ this.#maintain();
1267
+ return this
1268
+ }
1269
+ add(data){
1270
+ const db={
1271
+ ...this.items,
1272
+ ...data
1273
+ };
1274
+ this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(db));
1275
+ this.#maintain();
1276
+ return this;
1277
+ }
1278
+ remove(...keys){
1279
+ const db={...this.items};
1280
+ for(let i=0;i<keys.length;i++){
1281
+ delete db[keys[i]];
1282
+ delete this[keys[i]];
1283
+ }
1284
+ this.set(db);
1285
+ return this;
1286
+ }
1287
+ get(key){
1288
+ return this.items[key];
1289
+ }
1290
+ clear(){
1291
+ this.cache.storage.removeItem(this.cache.globalKey);
1292
+ this.#maintain();
1293
+ return this;
1294
+ }
1295
+
1296
+ }
1297
+ const useLocaleStorage=(key,initialValue)=>new ZikoUseStorage(localStorage,key,initialValue);
1298
+ const useSessionStorage=(key,initialValue)=>new ZikoUseStorage(sessionStorage,key,initialValue);
1299
+
1182
1300
  const __State__ = {
1183
1301
  store : new Map(),
1184
- index : import.meta.hot?.data?.__Ziko__?.__State__?.index ?? 0,
1302
+ index : 0,
1303
+ session_storage : null,
1185
1304
  register: function(state){
1186
- console.log({
1187
- // hmr : import.meta.hot?.data.__Ziko__.__State__.index,
1188
- index : this.index
1189
- });
1305
+ if(!import.meta.env.SSR && import.meta.env.DEV){
1306
+ if(!this.session) this.session_storage = useSessionStorage('ziko-state', {});
1307
+ const savedValue = this.session_storage.get(this.index);
1308
+ if(!savedValue) this.session_storage.add({[this.index] : state.value});
1309
+ else state.value = savedValue;
1310
+ }
1190
1311
  this.store.set(this.index++, state);
1191
- }
1192
-
1312
+ },
1313
+ update: function(index, value){
1314
+ if(!import.meta.env.SSR && import.meta.env.DEV){
1315
+ this.session_storage.add({[index] : value});
1316
+ }
1317
+ },
1318
+
1193
1319
  };
1194
1320
 
1195
1321
  function __init__global__(){
@@ -1447,20 +1573,8 @@ function _register_to_class_(target, mixin) {
1447
1573
 
1448
1574
  if(!globalThis.__Ziko__) __init__global__();
1449
1575
 
1450
- // HMR persistence
1451
- if (import.meta.hot?.data) {
1452
- import.meta.hot.data.__Ziko__ = import.meta.hot.data?.__Ziko__ || globalThis?.__Ziko__;
1453
- globalThis.__Ziko__ = import.meta.hot.data.__Ziko__;
1454
- // import.meta.hot.accept(n=>console.log(n));
1455
- // console.log(import.meta.hot.data.__Ziko__.__State__.store)
1456
- }
1457
-
1458
-
1459
-
1460
1576
  function useState(initialValue) {
1461
-
1462
- // console.log(import.meta.hot.data.__Ziko__.__State__.store.get(0))
1463
-
1577
+
1464
1578
  const {store, index} = __Ziko__.__State__;
1465
1579
  __Ziko__.__State__.register({
1466
1580
  value : initialValue,
@@ -1468,7 +1582,7 @@ function useState(initialValue) {
1468
1582
  paused : false
1469
1583
  });
1470
1584
 
1471
- const current = store.get(index);
1585
+ let current = store.get(index);
1472
1586
 
1473
1587
  function getValue() {
1474
1588
  return {
@@ -1480,10 +1594,13 @@ function useState(initialValue) {
1480
1594
 
1481
1595
  function setValue(newValue) {
1482
1596
  if (current.paused) return;
1483
- if (typeof newValue === "function") newValue = newValue(current.value);
1597
+ if (typeof newValue === "function") {
1598
+ newValue = newValue(current.value);
1599
+ }
1484
1600
  if (newValue !== current.value) {
1485
1601
  current.value = newValue;
1486
1602
  current.subscribers.forEach(fn => fn(current.value));
1603
+ __Ziko__.__State__.update(index, newValue);
1487
1604
  }
1488
1605
  }
1489
1606
 
@@ -2888,7 +3005,7 @@ const SVGWrapper = (content) => new UISVGWrapper(content);
2888
3005
  function define_wc(name, UIElement, props = {}, { mode = 'open'} = {}) {
2889
3006
  if (globalThis.customElements?.get(name)) {
2890
3007
  console.warn(`Custom element "${name}" is already defined`);
2891
- return; // skip redefinition
3008
+ return;
2892
3009
  }
2893
3010
  if(name.search('-') === -1){
2894
3011
  console.warn(`"${name}" is not a valid custom element name`);
@@ -2912,19 +3029,21 @@ function define_wc(name, UIElement, props = {}, { mode = 'open'} = {}) {
2912
3029
  }
2913
3030
 
2914
3031
  connectedCallback() {
2915
- this.mount();
3032
+ this.render();
2916
3033
  }
2917
3034
 
2918
- mount() {
3035
+ render() {
2919
3036
  this.shadowRoot.innerHTML = '';
2920
- this.UIElement = UIElement(this.props).mount(this.shadowRoot);
3037
+ const item = UIElement(this.props);
3038
+ if(item instanceof Array) item.forEach(n => n.mount(this.shadowRoot));
3039
+ else item.mount(this.shadowRoot);
2921
3040
  }
2922
3041
 
2923
3042
  attributeChangedCallback(name, _, newValue) {
2924
3043
  Object.assign(this.props, {
2925
3044
  [name]: this.mask[name].type(newValue)
2926
3045
  });
2927
- this.mount();
3046
+ this.render();
2928
3047
  }
2929
3048
  }
2930
3049
  );
@@ -4463,6 +4582,7 @@ const throttle=(fn,delay)=>{
4463
4582
  }
4464
4583
  };
4465
4584
 
4585
+ const sleep= ms => new Promise(res => setTimeout(res, ms));
4466
4586
  function timeout(ms, fn) {
4467
4587
  let id;
4468
4588
  const promise = new Promise((resolve) => {
@@ -4479,10 +4599,6 @@ function timeout(ms, fn) {
4479
4599
  };
4480
4600
  }
4481
4601
 
4482
- const sleep= ms => new Promise(res => setTimeout(res, ms));
4483
-
4484
- // use it with await
4485
-
4486
4602
  class TimeLoop {
4487
4603
  constructor(callback, { step = 1000, t0 = 0, t1 = Infinity, autoplay = true } = {}) {
4488
4604
  this.callback = callback;
@@ -5092,55 +5208,6 @@ const useReactive = (nested_value) => mapfun$1(
5092
5208
  nested_value
5093
5209
  );
5094
5210
 
5095
- class ZikoUseChannel{
5096
- constructor(name = ""){
5097
- this.channel = new BroadcastChannel(name);
5098
- this.EVENTS_DATAS_PAIRS = new Map();
5099
- this.EVENTS_HANDLERS_PAIRS = new Map();
5100
- this.LAST_RECEIVED_EVENT = "";
5101
- this.UUID="ziko-channel"+Random.string(10);
5102
- this.SUBSCRIBERS = new Set([this.UUID]);
5103
- }
5104
- get broadcast(){
5105
- // update receiver
5106
- return this;
5107
- }
5108
- emit(event, data){
5109
- this.EVENTS_DATAS_PAIRS.set(event,data);
5110
- this.#maintainEmit(event);
5111
- return this;
5112
- }
5113
- on(event,handler=console.log){
5114
- this.EVENTS_HANDLERS_PAIRS.set(event,handler);
5115
- this.#maintainOn();
5116
- return this;
5117
- }
5118
- #maintainOn(){
5119
- this.channel.onmessage = (e) => {
5120
- this.LAST_RECEIVED_EVENT=e.data.last_sended_event;
5121
- const USER_ID=e.data.userId;
5122
- this.SUBSCRIBERS.add(USER_ID);
5123
- const Data=e.data.EVENTS_DATAS_PAIRS.get(this.LAST_RECEIVED_EVENT);
5124
- const Handler=this.EVENTS_HANDLERS_PAIRS.get(this.LAST_RECEIVED_EVENT);
5125
- if(Data && Handler)Handler(Data);
5126
- };
5127
- return this;
5128
- }
5129
- #maintainEmit(event){
5130
- this.channel.postMessage({
5131
- EVENTS_DATAS_PAIRS:this.EVENTS_DATAS_PAIRS,
5132
- last_sended_event:event,
5133
- userId:this.UUID
5134
- });
5135
- return this;
5136
- }
5137
- close(){
5138
- this.channel.close();
5139
- return this;
5140
- }
5141
- }
5142
- const useChannel = name => new ZikoUseChannel(name);
5143
-
5144
5211
  class ZikoUseThreed {
5145
5212
  #workerContent;
5146
5213
  constructor() {
@@ -5257,75 +5324,6 @@ tags.p("Test useRoot ").style({
5257
5324
 
5258
5325
  */
5259
5326
 
5260
- // To do : remove old items
5261
- class ZikoUseStorage{
5262
- constructor(storage, globalKey, initialValue){
5263
- this.cache={
5264
- storage,
5265
- globalKey,
5266
- channel:useChannel(`Ziko:useStorage-${globalKey}`),
5267
- oldItemKeys:new Set()
5268
- };
5269
- this.#init(initialValue);
5270
- this.#maintain();
5271
- }
5272
- get items(){
5273
- return JSON.parse(this.cache.storage[this.cache.globalKey]??null);
5274
- }
5275
- #maintain() {
5276
- for(let i in this.items)Object.assign(this, { [[i]]: this.items[i] });
5277
- }
5278
- #init(initialValue){
5279
- this.cache.channel=useChannel(`Ziko:useStorage-${this.cache.globalKey}`);
5280
- this.cache.channel.on("Ziko-Storage-Updated",()=>this.#maintain());
5281
- if(!initialValue)return;
5282
- if(this.cache.storage[this.cache.globalKey]){
5283
- Object.keys(this.items).forEach(key=>this.cache.oldItemKeys.add(key));
5284
- console.group("Ziko:useStorage");
5285
- console.warn(`Storage key '${this.cache.globalKey}' already exists. we will not overwrite it.`);
5286
- console.info(`%cWe'll keep the existing data.`,"background-color:#2222dd; color:gold;");
5287
- console.group("");
5288
- }
5289
- else this.set(initialValue);
5290
- }
5291
- set(data){
5292
- this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(data));
5293
- this.cache.channel.emit("Ziko-Storage-Updated",{});
5294
- Object.keys(data).forEach(key=>this.cache.oldItemKeys.add(key));
5295
- this.#maintain();
5296
- return this
5297
- }
5298
- add(data){
5299
- const db={
5300
- ...this.items,
5301
- ...data
5302
- };
5303
- this.cache.storage.setItem(this.cache.globalKey,JSON.stringify(db));
5304
- this.#maintain();
5305
- return this;
5306
- }
5307
- remove(...keys){
5308
- const db={...this.items};
5309
- for(let i=0;i<keys.length;i++){
5310
- delete db[keys[i]];
5311
- delete this[keys[i]];
5312
- }
5313
- this.set(db);
5314
- return this;
5315
- }
5316
- get(key){
5317
- return this.items[key];
5318
- }
5319
- clear(){
5320
- this.cache.storage.removeItem(this.cache.globalKey);
5321
- this.#maintain();
5322
- return this;
5323
- }
5324
-
5325
- }
5326
- const useLocaleStorage=(key,initialValue)=>new ZikoUseStorage(localStorage,key,initialValue);
5327
- const useSessionStorage=(key,initialValue)=>new ZikoUseStorage(sessionStorage,key,initialValue);
5328
-
5329
5327
  let {sqrt, cos, sin, exp, log, cosh, sinh} = Math;
5330
5328
  // Math.abs = new Proxy(Math.abs, {
5331
5329
  // apply(target, thisArg, args) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziko",
3
- "version": "0.49.1",
3
+ "version": "0.49.3",
4
4
  "description": "A versatile JavaScript library offering a rich set of Hyperscript Based UI components, advanced mathematical utilities, interactivity ,animations, client side routing and more ...",
5
5
  "keywords": [
6
6
  "front-end",
@@ -1,12 +1,21 @@
1
+ import { useSessionStorage } from '../use/use-storage'
1
2
  export const __State__ = {
2
3
  store : new Map(),
3
- index : import.meta.hot?.data?.__Ziko__?.__State__?.index ?? 0,
4
+ index : 0,
5
+ session_storage : null,
4
6
  register: function(state){
5
- console.log({
6
- // hmr : import.meta.hot?.data.__Ziko__.__State__.index,
7
- index : this.index
8
- })
7
+ if(!import.meta.env.SSR && import.meta.env.DEV){
8
+ if(!this.session) this.session_storage = useSessionStorage('ziko-state', {})
9
+ const savedValue = this.session_storage.get(this.index)
10
+ if(!savedValue) this.session_storage.add({[this.index] : state.value});
11
+ else state.value = savedValue
12
+ }
9
13
  this.store.set(this.index++, state)
10
- }
11
-
14
+ },
15
+ update: function(index, value){
16
+ if(!import.meta.env.SSR && import.meta.env.DEV){
17
+ this.session_storage.add({[index] : value})
18
+ }
19
+ },
20
+
12
21
  }
@@ -1,20 +1,9 @@
1
1
  import { __init__global__ } from "../__ziko__/index.js";
2
- if(!globalThis.__Ziko__) __init__global__()
3
-
4
- // HMR persistence
5
- if (import.meta.hot?.data) {
6
- import.meta.hot.data.__Ziko__ = import.meta.hot.data?.__Ziko__ || globalThis?.__Ziko__;
7
- globalThis.__Ziko__ = import.meta.hot.data.__Ziko__;
8
- // import.meta.hot.accept(n=>console.log(n));
9
- // console.log(import.meta.hot.data.__Ziko__.__State__.store)
10
- }
11
-
12
2
 
3
+ if(!globalThis.__Ziko__) __init__global__()
13
4
 
14
5
  export function useState(initialValue) {
15
-
16
- // console.log(import.meta.hot.data.__Ziko__.__State__.store.get(0))
17
-
6
+
18
7
  const {store, index} = __Ziko__.__State__
19
8
  __Ziko__.__State__.register({
20
9
  value : initialValue,
@@ -22,7 +11,7 @@ export function useState(initialValue) {
22
11
  paused : false
23
12
  })
24
13
 
25
- const current = store.get(index);
14
+ let current = store.get(index);
26
15
 
27
16
  function getValue() {
28
17
  return {
@@ -34,10 +23,13 @@ export function useState(initialValue) {
34
23
 
35
24
  function setValue(newValue) {
36
25
  if (current.paused) return;
37
- if (typeof newValue === "function") newValue = newValue(current.value);
26
+ if (typeof newValue === "function") {
27
+ newValue = newValue(current.value);
28
+ }
38
29
  if (newValue !== current.value) {
39
30
  current.value = newValue;
40
31
  current.subscribers.forEach(fn => fn(current.value));
32
+ __Ziko__.__State__.update(index, newValue)
41
33
  }
42
34
  }
43
35
 
@@ -1,2 +1,16 @@
1
- export * from './timeout.js';
2
- export * from './sleep.js';
1
+ export const sleep= ms => new Promise(res => setTimeout(res, ms));
2
+ export function timeout(ms, fn) {
3
+ let id;
4
+ const promise = new Promise((resolve) => {
5
+ id = setTimeout(() => {
6
+ if (fn) fn();
7
+ resolve();
8
+ }, ms);
9
+ });
10
+
11
+ return {
12
+ id,
13
+ clear: () => clearTimeout(id),
14
+ promise
15
+ };
16
+ }
@@ -23,10 +23,10 @@ class ZikoUseStorage{
23
23
  if(!initialValue)return;
24
24
  if(this.cache.storage[this.cache.globalKey]){
25
25
  Object.keys(this.items).forEach(key=>this.cache.oldItemKeys.add(key));
26
- console.group("Ziko:useStorage")
27
- console.warn(`Storage key '${this.cache.globalKey}' already exists. we will not overwrite it.`);
28
- console.info(`%cWe'll keep the existing data.`,"background-color:#2222dd; color:gold;");
29
- console.group("")
26
+ // console.group("Ziko:useStorage")
27
+ // console.warn(`Storage key '${this.cache.globalKey}' already exists. we will not overwrite it.`);
28
+ // console.info(`%cWe'll keep the existing data.`,"background-color:#2222dd; color:gold;");
29
+ // console.group("")
30
30
  }
31
31
  else this.set(initialValue);
32
32
  }
@@ -0,0 +1,28 @@
1
+ import { Tick } from "./tick.js";
2
+
3
+ export interface ClockTickEvent {
4
+ elapsed: number;
5
+ delta: number;
6
+ }
7
+
8
+ export declare class Clock extends Tick {
9
+ elapsed: number;
10
+ protected _lastTime: number;
11
+ protected _callbacks: Set<(ev: ClockTickEvent) => void>;
12
+
13
+ constructor(tickMs?: number);
14
+
15
+ protected _tick(): void;
16
+
17
+ onTick(
18
+ cb: (ev: ClockTickEvent) => void
19
+ ): () => boolean;
20
+
21
+ reset(): void;
22
+
23
+ pause(): void;
24
+
25
+ resume(): void;
26
+ }
27
+
28
+ export declare function clock(tickMs?: number): Clock;
@@ -0,0 +1,3 @@
1
+ export type * from './tick.d.ts'
2
+ export type * from './clock.d.ts'
3
+ export type * from './scheduler.d.ts'
@@ -0,0 +1,42 @@
1
+ export interface TimeTask {
2
+ fn: () => Promise<any> | any;
3
+ delay?: number;
4
+ }
5
+
6
+ export type ParallelTasks = TimeTask[];
7
+
8
+ export interface TimeSchedulerOptions {
9
+ repeat?: number;
10
+ loop?: boolean;
11
+ }
12
+
13
+ export declare class TimeScheduler {
14
+ tasks: (TimeTask | ParallelTasks)[];
15
+ repeat: number;
16
+ loop: boolean;
17
+
18
+ stopped: boolean;
19
+ running: boolean;
20
+
21
+ onStart: (() => void) | null;
22
+ onTask: ((fn: () => Promise<any> | any) => void) | null;
23
+ onEnd: (() => void) | null;
24
+
25
+ constructor(
26
+ tasks?: (TimeTask | ParallelTasks)[],
27
+ options?: TimeSchedulerOptions
28
+ );
29
+
30
+ run(): Promise<void>;
31
+
32
+ stop(): void;
33
+
34
+ addTask(task: TimeTask | ParallelTasks): void;
35
+
36
+ clearTasks(): void;
37
+ }
38
+
39
+ export declare function Scheduler(
40
+ tasks?: (TimeTask | ParallelTasks)[],
41
+ options?: { repeat?: number | null }
42
+ ): TimeScheduler;
@@ -0,0 +1,26 @@
1
+ export declare class Tick {
2
+ ms: number;
3
+ fn: (self: Tick) => void;
4
+ count: number;
5
+ frame: number;
6
+ id: ReturnType<typeof setInterval> | null;
7
+ running: boolean;
8
+
9
+ constructor(
10
+ fn: (self: Tick) => void,
11
+ ms: number,
12
+ count?: number,
13
+ start?: boolean
14
+ );
15
+
16
+ start(): this;
17
+ stop(): this;
18
+ isRunning(): boolean;
19
+ }
20
+
21
+ export declare function tick(
22
+ fn: (self: Tick) => void,
23
+ ms: number,
24
+ count?: number,
25
+ start?: boolean
26
+ ): Tick;
@@ -0,0 +1,9 @@
1
+ export declare function debounce<T extends (...args: any[]) => any>(
2
+ fn: T,
3
+ delay?: number
4
+ ): (...args: Parameters<T>) => void;
5
+
6
+ export declare function throttle<T extends (...args: any[]) => any>(
7
+ fn: T,
8
+ delay: number
9
+ ): (...args: Parameters<T>) => void;
@@ -0,0 +1,12 @@
1
+ export declare const sleep: (ms: number) => Promise<void>;
2
+
3
+ export interface TimeoutResult {
4
+ id: ReturnType<typeof setTimeout>;
5
+ clear: () => void;
6
+ promise: Promise<void>;
7
+ }
8
+
9
+ export declare function timeout(
10
+ ms: number,
11
+ fn?: () => any
12
+ ): TimeoutResult;
@@ -1 +1,4 @@
1
- export type * from './ease/index.d.ts'
1
+ export type * from './ease/index.d.ts'
2
+ export type * from './clocks/index.d.ts'
3
+ export type * from './decorators/index.d.ts'
4
+ export type * from './loop/index.d.ts'
@@ -0,0 +1,50 @@
1
+ export declare class TimeLoop {
2
+ callback: (self: TimeLoop) => void;
3
+
4
+ protected cache: {
5
+ isRunning: boolean;
6
+ id: ReturnType<typeof setTimeout> | null;
7
+ last_tick: number | null;
8
+ step: number;
9
+ t0: number;
10
+ t1: number;
11
+ autoplay: boolean;
12
+ pauseTime: number | null;
13
+ frame: number;
14
+ elapsed?: number;
15
+ };
16
+
17
+ constructor(
18
+ callback: (self: TimeLoop) => void,
19
+ options?: {
20
+ step?: number;
21
+ t0?: number;
22
+ t1?: number;
23
+ autoplay?: boolean;
24
+ }
25
+ );
26
+
27
+ get frame(): number;
28
+
29
+ get elapsed(): number | undefined;
30
+
31
+ start(): this;
32
+ pause(): this;
33
+ resume(): this;
34
+ stop(): this;
35
+
36
+ startAfter(t?: number): this;
37
+ stopAfter(t?: number): this;
38
+
39
+ protected animate: () => void;
40
+ }
41
+
42
+ export declare function loop(
43
+ callback: (self: TimeLoop) => void,
44
+ options?: {
45
+ step?: number;
46
+ t0?: number;
47
+ t1?: number;
48
+ autoplay?: boolean;
49
+ }
50
+ ): TimeLoop;