ziko 0.45.5 → 0.46.1

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 : Mon Sep 08 2025 11:12:25 GMT+0100 (UTC+01:00)
5
+ Date : Sat Sep 27 2025 11:09:49 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
@@ -2003,15 +2003,15 @@ function details_setter$6(){
2003
2003
  }
2004
2004
  const bind_focus_event = (target, customizer) => new ZikoEventFocus(target, customizer);
2005
2005
 
2006
- let ZikoEventHash$1 = class ZikoEventHash extends __ZikoEvent__{
2006
+ class ZikoEventHash extends __ZikoEvent__{
2007
2007
  constructor(target, customizer){
2008
2008
  super(target, Events.Hash, details_setter$5, customizer);
2009
2009
  }
2010
- };
2010
+ }
2011
2011
  function details_setter$5(){
2012
2012
 
2013
2013
  }
2014
- const bindHashEvent = (target, customizer) => new ZikoEventHash$1(target, customizer);
2014
+ const bindHashEvent = (target, customizer) => new ZikoEventHash(target, customizer);
2015
2015
 
2016
2016
  class ZikoEventKey extends __ZikoEvent__{
2017
2017
  constructor(target, customizer){
@@ -2285,850 +2285,57 @@ class ZikoEvent{
2285
2285
  }
2286
2286
  }
2287
2287
 
2288
- function input_controller(e){
2289
- EVENT_CONTROLLER.call(this,e,"input",null,null);
2290
- }
2291
- function change_controller(e){
2292
- EVENT_CONTROLLER.call(this,e,"change",null,null);
2293
- }
2294
- class ZikoEventInput extends ZikoEvent{
2295
- constructor(target){
2296
- super(target);
2297
- this.event=null;
2298
- this.cache={
2299
- prefixe:"",
2300
- preventDefault:{
2301
- input:false,
2302
- change:false,
2303
- },
2304
- paused:{
2305
- input:false,
2306
- change:false,
2307
- },
2308
- stream:{
2309
- enabled:{
2310
- input:false,
2311
- change:false,
2312
- },
2313
- clear:{
2314
- input:false,
2315
- change:false,
2316
- },
2317
- history:{
2318
- input:[],
2319
- change:[],
2320
- }
2321
- },
2322
- callbacks:{
2323
- input:[],
2324
- change:[],
2325
- }
2326
- };
2327
- this.__controller={
2328
- input:input_controller.bind(this),
2329
- change:change_controller.bind(this),
2330
- };
2331
- }
2332
- get value(){
2333
- return this.target.value;
2334
- }
2335
- onInput(...callbacks){
2336
- this.__onEvent("input",{},...callbacks);
2337
- return this;
2338
- }
2339
- onChange(...callbacks){
2340
- this.__onEvent("change",{},...callbacks);
2341
- return this;
2342
- }
2343
- }
2344
- const useInputEvent=target=>new ZikoEventInput(target);
2345
-
2346
- function hashchange_controller(e){
2347
- EVENT_CONTROLLER.call(this,e,"hashchange",null,null);
2348
- }
2349
- class ZikoEventHash extends ZikoEvent{
2350
- constructor(target){
2351
- super(target);
2352
- this.event=null;
2353
- this.cache={
2354
- prefixe:"",
2355
- preventDefault:{
2356
- hashchange:false,
2357
- },
2358
- paused:{
2359
- hashchange:false,
2360
- },
2361
- stream:{
2362
- enabled:{
2363
- hashchange:false,
2364
-
2365
- },
2366
- clear:{
2367
- hashchange:false,
2368
-
2369
- },
2370
- history:{
2371
- hashchange:[],
2372
- }
2373
- },
2374
- callbacks:{
2375
- hashchange:[],
2376
- }
2377
- };
2378
- this.__controller={
2379
- hashchange:hashchange_controller.bind(this),
2380
- };
2381
- }
2382
- onChange(...callbacks){
2383
- this.__onEvent("hashchange",{},...callbacks);
2384
- return this;
2385
- }
2386
- }
2387
- const useHashEvent=target=>new ZikoEventHash(target);
2388
-
2389
2288
  const custom_event_controller=event_name=>function(e){
2390
2289
  EVENT_CONTROLLER.call(this,e,event_name,null,null);
2391
2290
  };
2392
2291
  class ZikoCustomEvent extends ZikoEvent{
2393
2292
  constructor(target){
2394
- super(target);
2395
- this.event=null;
2396
- this.cache={
2397
- prefixe:"",
2398
- preventDefault:{
2399
- },
2400
- paused:{
2401
- },
2402
- stream:{
2403
- enabled:{
2404
- },
2405
- clear:{
2406
- },
2407
- history:{
2408
- }
2409
- },
2410
- callbacks:{
2411
- }
2412
- };
2413
- this.__controller={
2414
- };
2415
- }
2416
- #init(event_name){
2417
- this.cache.preventDefault[event_name]=false;
2418
- this.cache.paused[event_name]=false;
2419
- this.cache.stream.enabled=false;
2420
- this.cache.stream.clear=false;
2421
- this.cache.stream.history=[];
2422
- this.cache.callbacks[event_name]=[];
2423
- this.__controller[event_name]=custom_event_controller(event_name).bind(this);
2424
- return this;
2425
- }
2426
- on(event_name,...callbacks){
2427
- if(!(this.__controller[event_name]))this.#init(event_name);
2428
- this.__onEvent(event_name,{},...callbacks);
2429
- return this;
2430
- }
2431
- emit(event_name,detail={}){
2432
- if(!(this.__controller[event_name]))this.#init(event_name);
2433
- this.detail=detail;
2434
- const event=new Event(event_name);
2435
- this.targetElement.dispatchEvent(event);
2436
- return this;
2437
- }
2438
- }
2439
- const useCustomEvent=target=>new ZikoCustomEvent(target);
2440
-
2441
- class ZikoEventSwipe extends ZikoEvent {
2442
- constructor(target, width_threshold = 0.3, height_threshold = 0.3) {
2443
- super(target);
2444
- const { removeListener, setWidthThreshold, setHeightThreshold } = init_swipe_event_handler(
2445
- this.target?.element,
2446
- width_threshold,
2447
- height_threshold,
2448
- this.target.width,
2449
- this.target.height,
2450
- );
2451
- this.cache = {
2452
- width_threshold,
2453
- height_threshold,
2454
- removeListener,
2455
- setWidthThreshold,
2456
- setHeightThreshold,
2457
- legacyTouchAction : globalThis?.document?.body?.style?.touchAction,
2458
- prefixe: "",
2459
- preventDefault: {
2460
- swipe: false,
2461
- },
2462
- paused: {
2463
- swipe: false,
2464
- },
2465
- stream: {
2466
- enabled: {
2467
- swipe: false,
2468
- },
2469
- clear: {
2470
- swipe: false,
2471
- },
2472
- history: {
2473
- swipe: [],
2474
- },
2475
- },
2476
- callbacks: {
2477
- swipe: [],
2478
- },
2479
- };
2480
- this.__controller = {
2481
- swipe: swipe_controller.bind(this),
2482
- };
2483
- }
2484
- onSwipe(...callbacks) {
2485
- Object.assign(globalThis?.document?.body?.style,{touchAction:"none"});
2486
- this.__onEvent("swipe", {}, ...callbacks);
2487
- return this;
2488
- }
2489
- updateThresholds(width_threshold = this.cache.width_threshold, height_threshold = this.cache.height_threshold) {
2490
- if (width_threshold !== undefined) {
2491
- this.cache.setWidthThreshold(width_threshold);
2492
- }
2493
- if (height_threshold !== undefined) {
2494
- this.cache.setHeightThreshold(height_threshold);
2495
- }
2496
- return this;
2497
- }
2498
- destroy() {
2499
- this.cache.removeListener();
2500
- Object.assign(globalThis?.document?.body?.style,{touchAction:this.cache.legacyTouchAction});
2501
- return this;
2502
- }
2503
- }
2504
- function init_swipe_event_handler(element, width_threshold = 0.50, height_threshold = 0.5, width, height) {
2505
- let Interpolated_width_threshold = lerp(width_threshold, 0, width);
2506
- let Interpolated_height_threshold = lerp(height_threshold, 0, height);
2507
- let startX = 0, startY = 0, endX = 0, endY = 0;
2508
- const pointerDownHandler = (event) => {
2509
- startX = event.clientX;
2510
- startY = event.clientY;
2511
- };
2512
- const pointerUpHandler = (event) => {
2513
- endX = event.clientX;
2514
- endY = event.clientY;
2515
- handleSwipe();
2516
- };
2517
- element?.addEventListener('pointerdown', pointerDownHandler);
2518
- element?.addEventListener('pointerup', pointerUpHandler);
2519
- function handleSwipe() {
2520
- const deltaX = endX - startX;
2521
- const deltaY = endY - startY;
2522
- if (Math.abs(deltaX) > Interpolated_width_threshold || Math.abs(deltaY) > Interpolated_height_threshold) {
2523
- dispatchSwipeEvent(deltaX, deltaY);
2524
- }
2525
- }
2526
- function dispatchSwipeEvent(deltaX, deltaY) {
2527
- const event = globalThis?.CustomEvent ? new CustomEvent('swipe', {
2528
- detail: {
2529
- deltaX: abs(deltaX) < Interpolated_width_threshold ? 0 : sign(deltaX) * norm(abs(deltaX), 0, width),
2530
- deltaY: abs(deltaY) < Interpolated_height_threshold ? 0 : sign(deltaY) * norm(abs(deltaY), 0, height),
2531
- direction: {
2532
- x : abs(deltaX) < Interpolated_width_threshold ? "none" : deltaX > 0 ? "right" : "left",
2533
- y : abs(deltaY) < Interpolated_height_threshold ? "none" : deltaY > 0 ? 'down' : 'up',
2534
- },
2535
- },
2536
- }) : null;
2537
- element?.dispatchEvent(event);
2538
- }
2539
- function setWidthThreshold(new_width_threshold) {
2540
- Interpolated_width_threshold = lerp(new_width_threshold, 0, width);
2541
- }
2542
- function setHeightThreshold(new_height_threshold) {
2543
- Interpolated_height_threshold = lerp(new_height_threshold, 0, height);
2544
- }
2545
- return {
2546
- removeListener() {
2547
- element?.removeEventListener('pointerdown', pointerDownHandler);
2548
- element?.removeEventListener('pointerup', pointerUpHandler);
2549
- console.log('Swipe event listeners removed');
2550
- },
2551
- setWidthThreshold,
2552
- setHeightThreshold,
2553
- };
2554
- }
2555
- function swipe_controller(e) {
2556
- EVENT_CONTROLLER.call(this, e, "swipe", null, null);
2557
- }
2558
- const useSwipeEvent = (target, width_threshold, height_threshold) => new ZikoEventSwipe(target, width_threshold, height_threshold);
2559
- /*
2560
- a=p("ALLL").size("300px","300px").style({background:"red",userSelect:"none"})
2561
- t=text("")
2562
- ev=useSwipeEvent(a, .1, .3)
2563
- ev.onSwipe(e=>{
2564
- // t.setValue(`
2565
- // vertical direction : ${e.event.detail.direction.y}
2566
- // horizontal direction : ${e.event.detail.direction.x}
2567
- // deltaX : ${e.event.detail.deltaX}
2568
- // deltaY : ${e.event.detail.deltaY}
2569
- // `)
2570
- e.target.st.translate(e.event.detail.deltaX * 200, e.event.detail.deltaY * 200,0, 500)
2571
- })
2572
- */
2573
- /*
2574
- a=p("ALLL")
2575
- .size("300px","300px")
2576
- .style({background:"red",userSelect:"none"})
2577
- .onSwipe(
2578
- .3,
2579
- .3,
2580
- e=>{
2581
- e.target.st.translate(e.event.detail.deltaX * 200, e.event.detail.deltaY * 200,0, 500)
2582
- })
2583
- */
2584
-
2585
- class ZikoMutationObserver {
2586
- constructor(targetUIElement, options) {
2587
- this.target = targetUIElement;
2588
- this.observer = null;
2589
- this.cache = {
2590
- options : options || { attributes: true, childList: true, subtree: true },
2591
- streamingEnabled : true,
2592
- lastMutation : null,
2593
- mutationHistory : {
2594
- // attributes: [],
2595
- // childList: [],
2596
- // subtree: [],
2597
- },
2598
- };
2599
- // children to Items : a.items.filter(n=>n.element === a[0].element)
2600
- this.observeCallback = (mutationsList, observer) => {
2601
- // if(this.cache.lastUpdatedAttr){
2602
- // this.cache.lastUpdatedAttr = mutation.target.getAttribute(mutation.attributeName)
2603
- // }
2604
- if (this.cache.streamingEnabled) {
2605
- for (const mutation of mutationsList) {
2606
- switch(mutation.type){
2607
- case 'attributes':this.cache.mutationHistory.attributes.push(mutation.target.getAttribute(mutation.attributeName));break;
2608
- case 'childList':this.cache.mutationHistory.childList.push(mutation);break;
2609
- case 'subtree':this.cache.mutationHistory.subtree.push(mutation);break;
2610
- }
2611
- }
2612
- }
2613
- if (this.callback) {
2614
- this.callback(mutationsList, observer);
2615
- }
2616
- };
2617
- }
2618
-
2619
- observe(callback) {
2620
- if(!this.observer) {
2621
- if(!globalThis.MutationObserver) {
2622
- console.log("MutationObserver Nor Supported");
2623
- return;
2624
- }
2625
- this.observer = new MutationObserver(this.cache.observeCallback);
2626
- this.observer.observe(this.target.element, this.cache.options);
2627
- // this.callback = ([e]) => callback.call(e,this.target);
2628
- this.callback = ([e]) => callback.call(e, this);
2629
- this.cache.streamingEnabled = true;
2630
- }
2631
- }
2632
-
2633
- pause(options) {
2634
- if (this.observer) {
2635
- this.observer.disconnect();
2636
- if (options) {
2637
- this.observer.observe(this.target, options);
2638
- }
2639
- }
2640
- }
2641
-
2642
- reset(options) {
2643
- if (this.observer) {
2644
- this.observer.disconnect();
2645
- this.observer.observe(this.target, options || this.cache.options);
2646
- }
2647
- }
2648
-
2649
- clear() {
2650
- if (this.observer) {
2651
- this.observer.disconnect();
2652
- this.observer = null;
2653
- this.cache.mutationHistory = {
2654
- attributes: [],
2655
- childList: [],
2656
- subtree: [],
2657
- };
2658
- }
2659
- this.cache.streamingEnabled = false;
2660
- return this;
2661
- }
2662
-
2663
- getMutationHistory() {
2664
- return this.cache.mutationHistory;
2665
- }
2666
-
2667
- enableStreaming() {
2668
- this.cache.streamingEnabled = true;
2669
- return this;
2670
- }
2671
-
2672
- disableStreaming() {
2673
- this.cache.streamingEnabled = false;
2674
- return this;
2675
- }
2676
- }
2677
-
2678
-
2679
-
2680
- const watch=(targetUIElement,options={},callback=null)=>{
2681
- const Observer= new ZikoMutationObserver(targetUIElement,options);
2682
- if(callback)Observer.observe(callback);
2683
- return Observer
2684
- };
2685
-
2686
- class ZikoWatchAttr extends ZikoMutationObserver{
2687
- constructor(targetUIElement,callback){
2688
- super(targetUIElement,{ attributes: true, childList: false, subtree: false });
2689
- Object.assign(this.cache,{
2690
- observeCallback : (mutationsList, observer) =>{
2691
- for (const mutation of mutationsList) {
2692
- this.cache.lastMutation = {
2693
- name : mutation.attributeName,
2694
- value : mutation.target.getAttribute(mutation.attributeName)
2695
- };
2696
- if (this.cache.streamingEnabled) this.cache.mutationHistory.attributes.push(this.cache.lastMutation);
2697
- }
2698
- if (this.callback) this.callback(mutationsList, observer);
2699
- }
2700
- });
2701
- this.cache.mutationHistory.attributes = [];
2702
- if(callback)this.observe(callback);
2703
- }
2704
- get history(){
2705
- return this.cache.mutationHistory.attributes;
2706
- }
2707
- }
2708
- const watchAttr=(targetUIElement, callback)=>new ZikoWatchAttr(targetUIElement, callback);
2709
-
2710
- class ZikoWatchChildren extends ZikoMutationObserver{
2711
- constructor(targetUIElement,callback){
2712
- super(targetUIElement,{ attributes: false, childList: true, subtree: false });
2713
- Object.assign(this.cache,{
2714
- observeCallback : (mutationsList, observer) =>{
2715
- for (const mutation of mutationsList) {
2716
- if(mutation.addedNodes)this.cache.lastMutation = {
2717
- type : "add",
2718
- item : this.target.find(n=>n.element === mutation.addedNodes[0])[0],
2719
- previous : this.target.find(n=>n.element === mutation.previousSibling)[0]
2720
- };
2721
- else if(mutation.addedNodes)this.cache.lastMutation = {
2722
- type : "remove",
2723
- item : this.target.find(n=>n.element === mutation.removedNodes[0])[0],
2724
- previous : this.target.find(n=>n.element === mutation.previousSibling)[0]
2725
- };
2726
- if (this.cache.streamingEnabled) this.cache.mutationHistory.children.push(this.cache.lastMutation);
2727
- }
2728
- if (this.callback) this.callback(mutationsList, observer);
2729
- }
2730
- });
2731
- this.cache.mutationHistory.children = [];
2732
- if(callback)this.observe(callback);
2733
- }
2734
- get item(){
2735
- return this.cache.lastMutation.item;
2736
- }
2737
- get history(){
2738
- return this.cache.mutationHistory.children;
2739
- }
2740
- }
2741
-
2742
- const watchChildren=(targetUIElement, callback)=>new ZikoWatchChildren(targetUIElement, callback);
2743
-
2744
- class ZikoIntersectionObserver{
2745
- constructor(UIElement,callback,{threshold=0,margin=0}={}){
2746
- this.target=UIElement;
2747
- this.config={
2748
- threshold,
2749
- margin
2750
- };
2751
- if(!globalThis.IntersectionObserver){
2752
- console.log("IntersectionObserver Not Supported");
2753
- return;
2754
- }
2755
- this.observer=new IntersectionObserver((entries)=>{
2756
- this.entrie=entries[0];
2757
- callback(this);
2758
- },{
2759
- threshold:this.threshold,
2760
- });
2761
- }
2762
- get ratio(){
2763
- return this.entrie.intersectionRatio;
2764
- }
2765
- get isIntersecting(){
2766
- return this.entrie.isIntersecting;
2767
- }
2768
- setThreshould(threshold){
2769
- this.config.threshold=threshold;
2770
- return this;
2771
- }
2772
- setMargin(margin){
2773
- margin=(typeof margin === "number")?margin+"px":margin;
2774
- this.config.margin=margin;
2775
- return this;
2776
- }
2777
- start(){
2778
- this.observer.observe(this.target.element);
2779
- return this;
2780
- }
2781
- stop(){
2782
- return this;
2783
- }
2784
- }
2785
-
2786
- const watchIntersection=(UI,callback,config)=>new ZikoIntersectionObserver(UI,callback,config);
2787
-
2788
- class ZikoResizeObserver{
2789
- constructor(UIElement,callback){
2790
- this.target=UIElement;
2791
- this.contentRect=null;
2792
- this.observer=new ResizeObserver(()=>{
2793
- callback(this);
2794
- });
2795
- }
2796
- get BoundingRect(){
2797
- return this.target.element.getBoundingClientRect();
2798
- }
2799
- get width(){
2800
- return this.BoundingRect.width;
2801
- }
2802
- get height(){
2803
- return this.BoundingRect.height;
2804
- }
2805
- get top(){
2806
- return this.BoundingRect.top;
2807
- }
2808
- get bottom(){
2809
- return this.BoundingRect.bottom;
2810
- }
2811
- get right(){
2812
- return this.BoundingRect.right;
2813
- }
2814
- get left(){
2815
- return this.BoundingRect.left;
2816
- }
2817
- get x(){
2818
- return this.BoundingRect.x;
2819
- }
2820
- get y(){
2821
- return this.BoundingRect.y;
2822
- }
2823
- start(){
2824
- this.observer.observe(this.target.element);
2825
- return this;
2826
- }
2827
- stop(){
2828
- this.observer.unobserve(this.target.element);
2829
- return this;
2830
- }
2831
- }
2832
-
2833
- const watchSize=(UI,callback)=>new ZikoResizeObserver(UI,callback);
2834
-
2835
- class ZikoScreenObserver {
2836
- constructor(callback=e=>console.log({x:e.x,y:e.y})) {
2837
- this.cache={};
2838
- this.previousX = globalThis?.screenX;
2839
- this.previousY = globalThis?.screenY;
2840
- }
2841
- update(){
2842
- Object.assign(this.cache,{
2843
- screenXLeft : globalThis?.screenX, // CORRECT
2844
- screenXRight : globalThis?.screen.availWidth - globalThis?.screenX, // CORRECT
2845
- screenYTop : globalThis?.screenY, // CORRECT
2846
- screenYBottom : globalThis?.screen.availHeight - globalThis?.screenY - globalThis?.outerHeight, // TO TEST
2847
- screenCenterX : globalThis?.screen.availWidth/2, // CORRECT
2848
- screenCenterY : globalThis?.screen.availHeight/2,// CORRECT
2849
- windowCenterX : globalThis?.outerWidth/2+globalThis?.screenX, // CORRECT
2850
- windowCenterY : globalThis?.outerHeight/2+ globalThis?.screenY, // FALSE
2851
- deltaCenterX : globalThis?.screen.availWidth/2-globalThis?.outerWidth/2+globalThis?.screenX, // CORRECT
2852
- deltaCenterY : null //
2853
- });
2854
- }
2855
- get x0(){
2856
- return map$1(globalThis?.screenX, 0, globalThis.screen.availWidth, -1, 1);
2857
- }
2858
- get y0(){
2859
- return - map$1(globalThis?.screenY, 0, globalThis.screen.availHeight, -1, 1);
2860
- }
2861
- get x1(){
2862
- return map$1(globalThis?.screenX + globalThis?.outerWidth, 0, globalThis.screen.availWidth, -1, 1);
2863
- }
2864
- get y1(){
2865
- return - map$1(globalThis?.screenY + globalThis?.outerHeight, 0, globalThis.screen.availHeight, -1, 1);
2866
- }
2867
- get cx(){
2868
- return map$1(globalThis?.outerWidth/2+globalThis?.screenX, 0, globalThis.screen.availWidth, -1, 1);
2869
- }
2870
- get cy(){
2871
- return - map$1(globalThis?.outerHeight/2+ globalThis?.screenY, 0, globalThis.screen.availHeight, -1, 1);
2872
- }
2873
- }
2874
-
2875
- const watchScreen=(callback)=>new ZikoScreenObserver(callback);
2876
-
2877
- const useSuccesifKeys=(self,keys=[],callback=()=>{})=>{
2878
- self.cache.stream.enabled.down=true;
2879
- const length=keys.length;
2880
- const LastKeysDown=self.cache.stream.history.down.slice(-length).map(n=>n.key);
2881
-
2882
- if(keys.join("")===LastKeysDown.join("")){
2883
- self.event.preventDefault();
2884
- callback.call(self,self);
2885
- }
2886
-
2887
- };
2888
-
2889
- class ZikoUseEventEmitter {
2890
- constructor() {
2891
- this.events = {};
2892
- this.maxListeners = 10;
2893
- }
2894
- on(event, listener) {
2895
- if (!this.events[event]) {
2896
- this.events[event] = [];
2897
- }
2898
- this.events[event].push(listener);
2899
- if (this.events[event].length > this.maxListeners) {
2900
- console.warn(`Warning: Possible memory leak. Event '${event}' has more than ${this.maxListeners} listeners.`);
2901
- }
2902
- }
2903
- once(event, listener) {
2904
- const onceListener = (data) => {
2905
- this.off(event, onceListener); // Remove the listener after it's been called
2906
- listener(data);
2907
- };
2908
- this.on(event, onceListener);
2909
- }
2910
-
2911
- off(event, listener) {
2912
- const listeners = this.events[event];
2913
- if (listeners) {
2914
- const index = listeners.indexOf(listener);
2915
- if (index !== -1) {
2916
- listeners.splice(index, 1);
2917
- }
2918
- }
2919
- }
2920
-
2921
- emit(event, data) {
2922
- const listeners = this.events[event];
2923
- if (listeners) {
2924
- listeners.forEach(listener => {
2925
- listener(data);
2926
- });
2927
- }
2928
- }
2929
-
2930
- clear(event) {
2931
- if (event) {
2932
- delete this.events[event];
2933
- } else {
2934
- this.events = {};
2935
- }
2936
- }
2937
-
2938
- setMaxListener(event, max) {
2939
- this.maxListeners = max;
2940
- }
2941
-
2942
- removeAllListeners(event) {
2943
- if (event) {
2944
- this.events[event] = [];
2945
- } else {
2946
- this.events = {};
2947
- }
2948
- }
2949
- }
2950
-
2951
- const useEventEmitter=()=>new ZikoUseEventEmitter();
2952
-
2953
- class ZikoUseFavIcon{
2954
- constructor(FavIcon,useEventEmitter=true){
2955
- this.#init();
2956
- this.cache={
2957
- Emitter:null
2958
- };
2959
- if(useEventEmitter)this.useEventEmitter();
2960
- this.set(FavIcon);
2961
- }
2962
- #init(){
2963
- this.__FavIcon__ = document.querySelector("link[rel*='icon']") || document?.createElement('link');
2964
- this.__FavIcon__.type = 'image/x-icon';
2965
- this.__FavIcon__.rel = 'shortcut icon';
2966
- return this;
2967
- }
2968
- set(href){
2969
- if(href!==this.__FavIcon__.href){
2970
- this.__FavIcon__.href=href;
2971
- if(this.cache.Emitter)this.cache.Emitter.emit("ziko:favicon-changed");
2972
- }
2973
- return this;
2974
- }
2975
- get current(){
2976
- return document.__FavIcon__.href;
2977
- }
2978
- onChange(callback){
2979
- if(this.cache.Emitter)this.cache.Emitter.on("ziko:favicon-changed",callback);
2980
- return this;
2981
- }
2982
- useEventEmitter(){
2983
- this.cache.Emitter=useEventEmitter();
2984
- return this;
2985
- }
2986
-
2987
- }
2988
- const useFavIcon=(FavIcon,useEventEmitter)=>new ZikoUseFavIcon(FavIcon,useEventEmitter);
2989
-
2990
- class ZikoMeta{
2991
- constructor({viewport,charset,description,author,keywords}){
2992
- this.document = globalThis?.document;
2993
- this.meta={};
2994
- this.init({viewport,charset,description,author,keywords});
2995
- }
2996
- init({viewport,charset,description,author,keywords}){
2997
- viewport && this.setViewport(viewport);
2998
- charset && this.setCharset(charset);
2999
- description && this.describe(description);
3000
- author && this.setAuthor(author);
3001
- keywords && this.setKeywords(keywords);
3002
- }
3003
- set(key,value){
3004
- key = key.toLowerCase();
3005
- const isCharset = (key === "charset");
3006
- const meta = isCharset ? document.querySelector("meta[charset]"):document.querySelector(`meta[name=${key}]`);
3007
- this.meta=meta?? document?.createElement("meta");
3008
- if(isCharset) this.meta.setAttribute("charset",value);
3009
- else {
3010
- this.meta.setAttribute("name",key);
3011
- this.meta.setAttribute("content",value);
3012
- }
3013
- if(!meta)this.document.head.append(this.meta);
3014
- return this;
3015
- }
3016
- setCharset(charset="utf-8"){
3017
- this.set("charset",charset);
3018
- return this;
3019
- }
3020
- describe(description){
3021
- this.set("description",description);
3022
- return this;
3023
- }
3024
- setViewport(viewport="width=device-width, initial-scale=1.0"){
3025
- this.set("viewport",viewport);
3026
- return this;
3027
- }
3028
- setKeywords(...keywords){
3029
- // keywords.push("zikojs");
3030
- keywords=[...new Set(keywords)].join(", ");
3031
- this.set("keywords",keywords);
3032
- return this;
3033
- }
3034
- setAuthor(author){
3035
- this.set("author",author);
3036
- return this;
3037
- }
3038
- }
3039
- const useMeta=({viewport,charset,description,author,keywords})=>new ZikoMeta({viewport,charset,description,author,keywords});
3040
-
3041
- class ZikoUseTitle{
3042
- constructor(title=document.title,useEventEmitter=true){
3043
- this.cache={
3044
- Emitter:null
3045
- };
3046
- if(useEventEmitter)this.useEventEmitter();
3047
- this.set(title);
3048
- }
3049
- useEventEmitter(){
3050
- this.cache.Emitter=useEventEmitter();
3051
- return this;
3052
- }
3053
- set(title){
3054
- if(title!==document.title){
3055
- document.title=title;
3056
- if(this.cache.Emitter)this.cache.Emitter.emit("ziko:title-changed");
3057
- }
3058
- return this;
3059
- }
3060
- get current(){
3061
- return document.title;
3062
- }
3063
- onChange(callback){
3064
- if(this.cache.Emitter)this.cache.Emitter.on("ziko:title-changed",callback);
3065
- return this;
3066
- }
3067
- }
3068
- const useTitle=(title, useEventEmitter)=>new ZikoUseTitle(title, useEventEmitter);
3069
-
3070
- // import {useLink} from "./";
3071
- class ZikoHead{
3072
- constructor({title,lang,icon,meta,noscript}){
3073
- this.html = globalThis?.document?.documentElement;
3074
- this.head = globalThis?.document?.head;
3075
-
3076
- title && useTitle(title);
3077
- lang && this.setLang(lang);
3078
- icon && useFavIcon(icon);
3079
- meta && useMeta(meta);
3080
- noscript && this.setNoScript();
3081
- }
3082
- setLang(lang){
3083
- this.html.setAttribute("lang",lang);
3084
- }
3085
- setNoScript(content){
3086
-
3087
- }
3088
- }
3089
-
3090
- const useHead=({ title, lang, icon, meta, noscript })=>new ZikoHead({ title, lang, icon, meta, noscript });
3091
-
3092
- /*
3093
- [
3094
- {
3095
- query: '(min-width: 600px)',
3096
- callback: () => console.log(1)
2293
+ super(target);
2294
+ this.event=null;
2295
+ this.cache={
2296
+ prefixe:"",
2297
+ preventDefault:{
3097
2298
  },
3098
- {
3099
- query: '(max-width: 300px)',
3100
- callback: () => console.log(2)
2299
+ paused:{
2300
+ },
2301
+ stream:{
2302
+ enabled:{
2303
+ },
2304
+ clear:{
2305
+ },
2306
+ history:{
2307
+ }
2308
+ },
2309
+ callbacks:{
3101
2310
  }
3102
- ]
3103
- */
3104
- class ZikoUseMediaQuery {
3105
- constructor(mediaQueryRules=[],fallback=()=>{}) {
3106
- this.mediaQueryRules = mediaQueryRules;
3107
- this.fallback = fallback;
3108
- this.lastCalledCallback = null;
3109
- this.init();
2311
+ };
2312
+ this.__controller={
2313
+ };
3110
2314
  }
3111
-
3112
- init() {
3113
- this.mediaQueryRules.forEach(({ query, callback }) => {
3114
- const mediaQueryList = globalThis.matchMedia(query);
3115
- const checkMatches = () => {
3116
- const anyMatch = this.mediaQueryRules.some(({ query }) => globalThis.matchMedia(query).matches);
3117
- if (mediaQueryList.matches) {
3118
- callback();
3119
- this.lastCalledCallback = callback;
3120
- } else if (!anyMatch && this.lastCalledCallback !== this.fallback) {
3121
- this.fallback();
3122
- this.lastCalledCallback = this.fallback;
3123
- }
3124
- };
3125
- checkMatches();
3126
- mediaQueryList.addListener(checkMatches);
3127
- });
2315
+ #init(event_name){
2316
+ this.cache.preventDefault[event_name]=false;
2317
+ this.cache.paused[event_name]=false;
2318
+ this.cache.stream.enabled=false;
2319
+ this.cache.stream.clear=false;
2320
+ this.cache.stream.history=[];
2321
+ this.cache.callbacks[event_name]=[];
2322
+ this.__controller[event_name]=custom_event_controller(event_name).bind(this);
2323
+ return this;
2324
+ }
2325
+ on(event_name,...callbacks){
2326
+ if(!(this.__controller[event_name]))this.#init(event_name);
2327
+ this.__onEvent(event_name,{},...callbacks);
2328
+ return this;
2329
+ }
2330
+ emit(event_name,detail={}){
2331
+ if(!(this.__controller[event_name]))this.#init(event_name);
2332
+ this.detail=detail;
2333
+ const event=new Event(event_name);
2334
+ this.targetElement.dispatchEvent(event);
2335
+ return this;
3128
2336
  }
3129
2337
  }
3130
-
3131
- const useMediaQuery = (mediaQueryRules,fallback) => new ZikoUseMediaQuery(mediaQueryRules,fallback);
2338
+ const useCustomEvent=target=>new ZikoCustomEvent(target);
3132
2339
 
3133
2340
  let UIElement$1 = class UIElement extends UIElementCore{
3134
2341
  constructor({element, name ='', type='html', render = __Ziko__.__Config__.default.render}={}){
@@ -3302,6 +2509,15 @@ let UIElement$1 = class UIElement extends UIElementCore{
3302
2509
 
3303
2510
  };
3304
2511
 
2512
+ class UIView extends UIElement$1{
2513
+ constructor(...items){
2514
+ super({element : 'div', name : 'view'});
2515
+ this.append(...items);
2516
+ }
2517
+ }
2518
+
2519
+ const View = (...items) => new UIView(...items);
2520
+
3305
2521
  const HTMLTags = [
3306
2522
  'a',
3307
2523
  'abb',
@@ -5385,6 +4601,209 @@ const timeTaken = callback => {
5385
4601
  return r;
5386
4602
  };
5387
4603
 
4604
+ class ZikoUseEventEmitter {
4605
+ constructor() {
4606
+ this.events = {};
4607
+ this.maxListeners = 10;
4608
+ }
4609
+ on(event, listener) {
4610
+ if (!this.events[event]) {
4611
+ this.events[event] = [];
4612
+ }
4613
+ this.events[event].push(listener);
4614
+ if (this.events[event].length > this.maxListeners) {
4615
+ console.warn(`Warning: Possible memory leak. Event '${event}' has more than ${this.maxListeners} listeners.`);
4616
+ }
4617
+ }
4618
+ once(event, listener) {
4619
+ const onceListener = (data) => {
4620
+ this.off(event, onceListener); // Remove the listener after it's been called
4621
+ listener(data);
4622
+ };
4623
+ this.on(event, onceListener);
4624
+ }
4625
+
4626
+ off(event, listener) {
4627
+ const listeners = this.events[event];
4628
+ if (listeners) {
4629
+ const index = listeners.indexOf(listener);
4630
+ if (index !== -1) {
4631
+ listeners.splice(index, 1);
4632
+ }
4633
+ }
4634
+ }
4635
+
4636
+ emit(event, data) {
4637
+ const listeners = this.events[event];
4638
+ if (listeners) {
4639
+ listeners.forEach(listener => {
4640
+ listener(data);
4641
+ });
4642
+ }
4643
+ }
4644
+
4645
+ clear(event) {
4646
+ if (event) {
4647
+ delete this.events[event];
4648
+ } else {
4649
+ this.events = {};
4650
+ }
4651
+ }
4652
+
4653
+ setMaxListener(event, max) {
4654
+ this.maxListeners = max;
4655
+ }
4656
+
4657
+ removeAllListeners(event) {
4658
+ if (event) {
4659
+ this.events[event] = [];
4660
+ } else {
4661
+ this.events = {};
4662
+ }
4663
+ }
4664
+ }
4665
+
4666
+ const useEventEmitter=()=>new ZikoUseEventEmitter();
4667
+
4668
+ class ZikoUseFavIcon{
4669
+ constructor(FavIcon,useEventEmitter=true){
4670
+ this.#init();
4671
+ this.cache={
4672
+ Emitter:null
4673
+ };
4674
+ if(useEventEmitter)this.useEventEmitter();
4675
+ this.set(FavIcon);
4676
+ }
4677
+ #init(){
4678
+ this.__FavIcon__ = document.querySelector("link[rel*='icon']") || document?.createElement('link');
4679
+ this.__FavIcon__.type = 'image/x-icon';
4680
+ this.__FavIcon__.rel = 'shortcut icon';
4681
+ return this;
4682
+ }
4683
+ set(href){
4684
+ if(href!==this.__FavIcon__.href){
4685
+ this.__FavIcon__.href=href;
4686
+ if(this.cache.Emitter)this.cache.Emitter.emit("ziko:favicon-changed");
4687
+ }
4688
+ return this;
4689
+ }
4690
+ get current(){
4691
+ return document.__FavIcon__.href;
4692
+ }
4693
+ onChange(callback){
4694
+ if(this.cache.Emitter)this.cache.Emitter.on("ziko:favicon-changed",callback);
4695
+ return this;
4696
+ }
4697
+ useEventEmitter(){
4698
+ this.cache.Emitter=useEventEmitter();
4699
+ return this;
4700
+ }
4701
+
4702
+ }
4703
+ const useFavIcon=(FavIcon,useEventEmitter)=>new ZikoUseFavIcon(FavIcon,useEventEmitter);
4704
+
4705
+ class ZikoMeta{
4706
+ constructor({viewport,charset,description,author,keywords}){
4707
+ this.document = globalThis?.document;
4708
+ this.meta={};
4709
+ this.init({viewport,charset,description,author,keywords});
4710
+ }
4711
+ init({viewport,charset,description,author,keywords}){
4712
+ viewport && this.setViewport(viewport);
4713
+ charset && this.setCharset(charset);
4714
+ description && this.describe(description);
4715
+ author && this.setAuthor(author);
4716
+ keywords && this.setKeywords(keywords);
4717
+ }
4718
+ set(key,value){
4719
+ key = key.toLowerCase();
4720
+ const isCharset = (key === "charset");
4721
+ const meta = isCharset ? document.querySelector("meta[charset]"):document.querySelector(`meta[name=${key}]`);
4722
+ this.meta=meta?? document?.createElement("meta");
4723
+ if(isCharset) this.meta.setAttribute("charset",value);
4724
+ else {
4725
+ this.meta.setAttribute("name",key);
4726
+ this.meta.setAttribute("content",value);
4727
+ }
4728
+ if(!meta)this.document.head.append(this.meta);
4729
+ return this;
4730
+ }
4731
+ setCharset(charset="utf-8"){
4732
+ this.set("charset",charset);
4733
+ return this;
4734
+ }
4735
+ describe(description){
4736
+ this.set("description",description);
4737
+ return this;
4738
+ }
4739
+ setViewport(viewport="width=device-width, initial-scale=1.0"){
4740
+ this.set("viewport",viewport);
4741
+ return this;
4742
+ }
4743
+ setKeywords(...keywords){
4744
+ // keywords.push("zikojs");
4745
+ keywords=[...new Set(keywords)].join(", ");
4746
+ this.set("keywords",keywords);
4747
+ return this;
4748
+ }
4749
+ setAuthor(author){
4750
+ this.set("author",author);
4751
+ return this;
4752
+ }
4753
+ }
4754
+ const useMeta=({viewport,charset,description,author,keywords})=>new ZikoMeta({viewport,charset,description,author,keywords});
4755
+
4756
+ class ZikoUseTitle{
4757
+ constructor(title=document.title,useEventEmitter=true){
4758
+ this.cache={
4759
+ Emitter:null
4760
+ };
4761
+ if(useEventEmitter)this.useEventEmitter();
4762
+ this.set(title);
4763
+ }
4764
+ useEventEmitter(){
4765
+ this.cache.Emitter=useEventEmitter();
4766
+ return this;
4767
+ }
4768
+ set(title){
4769
+ if(title!==document.title){
4770
+ document.title=title;
4771
+ if(this.cache.Emitter)this.cache.Emitter.emit("ziko:title-changed");
4772
+ }
4773
+ return this;
4774
+ }
4775
+ get current(){
4776
+ return document.title;
4777
+ }
4778
+ onChange(callback){
4779
+ if(this.cache.Emitter)this.cache.Emitter.on("ziko:title-changed",callback);
4780
+ return this;
4781
+ }
4782
+ }
4783
+ const useTitle=(title, useEventEmitter)=>new ZikoUseTitle(title, useEventEmitter);
4784
+
4785
+ // import {useLink} from "./";
4786
+ class ZikoHead{
4787
+ constructor({title,lang,icon,meta,noscript}){
4788
+ this.html = globalThis?.document?.documentElement;
4789
+ this.head = globalThis?.document?.head;
4790
+
4791
+ title && useTitle(title);
4792
+ lang && this.setLang(lang);
4793
+ icon && useFavIcon(icon);
4794
+ meta && useMeta(meta);
4795
+ noscript && this.setNoScript();
4796
+ }
4797
+ setLang(lang){
4798
+ this.html.setAttribute("lang",lang);
4799
+ }
4800
+ setNoScript(content){
4801
+
4802
+ }
4803
+ }
4804
+
4805
+ const useHead=({ title, lang, icon, meta, noscript })=>new ZikoHead({ title, lang, icon, meta, noscript });
4806
+
5388
4807
  class ZikoApp {
5389
4808
  constructor({head = null, wrapper = null, target = null}){
5390
4809
  this.head = head;
@@ -5933,4 +5352,4 @@ if(globalThis?.document){
5933
5352
  document?.addEventListener("DOMContentLoaded", __Ziko__.__Config__.init());
5934
5353
  }
5935
5354
 
5936
- export { App, Arc, Back, Base, Clock, Combinaison, Complex, Discret, E, EPSILON, Elastic, FileBasedRouting, Flex, HTMLWrapper, InBack, InBounce, InCirc, InCubic, InElastic, InExpo, InOutBack, InOutBounce, InOutCirc, InOutCubic, InOutElastic, InOutExpo, InOutQuad, InOutQuart, InOutQuint, InOutSin, InQuad, InQuart, InQuint, InSin, Linear, Logic$1 as Logic, Matrix, OutBack, OutBounce, OutCirc, OutCubic, OutElastic, OutExpo, OutQuad, OutQuart, OutQuint, OutSin, PI$2 as PI, Permutation, Random, SPA, SVGWrapper, Scheduler, Step, Suspense, Switch, Tick, TimeAnimation, TimeLoop, TimeScheduler, UIElement$1 as UIElement, UIHTMLWrapper, UINode, UISVGWrapper, UISwitch, Utils, ZikoApp, ZikoCustomEvent, ZikoEventClick, ZikoEventClipboard, ZikoEventCustom, ZikoEventDrag, ZikoEventFocus, ZikoEventInput, ZikoEventKey, ZikoEventMouse, ZikoEventPointer, ZikoEventSwipe, ZikoEventTouch, ZikoEventWheel, ZikoHead, ZikoMutationObserver, ZikoSPA, ZikoUIFlex, ZikoUISuspense, ZikoUIText, ZikoUseRoot, __ZikoEvent__, abs, accum, acos$1 as acos, acosh, acot, add, animation, arange, arr2str, asin, asinh, atan, atan2, atanh, bindCustomEvent, bindHashEvent, bindTouchEvent, bind_click_event, bind_clipboard_event, bind_drag_event, bind_focus_event, bind_key_event, bind_mouse_event, bind_pointer_event, bind_wheel_event, cartesianProduct, ceil, clamp, clock, combinaison, complex, cos$2 as cos, cosh$1 as cosh, cot, coth, csc, csv2arr, csv2json, csv2matrix, csv2object, csv2sql, debounce, defineParamsGetter, define_wc, deg2rad, div, e, fact, floor, geomspace, getEvent, hypot, inRange, isApproximatlyEqual, isStateGetter, json2arr, json2css, json2csv, json2csvFile, json2xml, json2xmlFile, json2yml, json2ymlFile, lerp, linspace, ln, logspace, loop, map$1 as map, mapfun$1 as mapfun, matrix, matrix2, matrix3, matrix4, max, min, modulo, mul, norm, nums, obj2str, ones, pgcd, pow$1 as pow, powerSet, ppcm, preload, prod, rad2deg, round, sec, sig, sign, sin$2 as sin, sinc, sinh$1 as sinh, sleep, sqrt$2 as sqrt, sqrtn, step_fps, sub, subSet, sum, svg2ascii, svg2img, svg2imgUrl, svg2str, tags, tan, tanh, text, throttle, tick, timeTaken, time_memory_Taken, timeout, useChannel, useCustomEvent, useDerived, useEventEmitter, useFavIcon, useHashEvent, useHead, useInputEvent, useLocaleStorage, useMediaQuery, useMeta, useReactive, useRoot, useSessionStorage, useState, useSuccesifKeys, useSwipeEvent, useThread, useTitle, wait, waitForUIElm, waitForUIElmSync, watch, watchAttr, watchChildren, watchIntersection, watchScreen, watchSize, zeros };
5355
+ export { App, Arc, Back, Base, Clock, Combinaison, Complex, Discret, E, EPSILON, Elastic, FileBasedRouting, Flex, HTMLWrapper, InBack, InBounce, InCirc, InCubic, InElastic, InExpo, InOutBack, InOutBounce, InOutCirc, InOutCubic, InOutElastic, InOutExpo, InOutQuad, InOutQuart, InOutQuint, InOutSin, InQuad, InQuart, InQuint, InSin, Linear, Logic$1 as Logic, Matrix, OutBack, OutBounce, OutCirc, OutCubic, OutElastic, OutExpo, OutQuad, OutQuart, OutQuint, OutSin, PI$2 as PI, Permutation, Random, SPA, SVGWrapper, Scheduler, Step, Suspense, Switch, Tick, TimeAnimation, TimeLoop, TimeScheduler, UIElement$1 as UIElement, UIHTMLWrapper, UINode, UISVGWrapper, UISwitch, UIView, Utils, View, ZikoApp, ZikoEventClick, ZikoEventClipboard, ZikoEventCustom, ZikoEventDrag, ZikoEventFocus, ZikoEventHash, ZikoEventKey, ZikoEventMouse, ZikoEventPointer, ZikoEventTouch, ZikoEventWheel, ZikoSPA, ZikoUIFlex, ZikoUISuspense, ZikoUIText, ZikoUseRoot, __ZikoEvent__, abs, accum, acos$1 as acos, acosh, acot, add, animation, arange, arr2str, asin, asinh, atan, atan2, atanh, bindCustomEvent, bindHashEvent, bindTouchEvent, bind_click_event, bind_clipboard_event, bind_drag_event, bind_focus_event, bind_key_event, bind_mouse_event, bind_pointer_event, bind_wheel_event, cartesianProduct, ceil, clamp, clock, combinaison, complex, cos$2 as cos, cosh$1 as cosh, cot, coth, csc, csv2arr, csv2json, csv2matrix, csv2object, csv2sql, debounce, defineParamsGetter, define_wc, deg2rad, div, e, fact, floor, geomspace, getEvent, hypot, inRange, isApproximatlyEqual, isStateGetter, json2arr, json2css, json2csv, json2csvFile, json2xml, json2xmlFile, json2yml, json2ymlFile, lerp, linspace, ln, logspace, loop, map$1 as map, mapfun$1 as mapfun, matrix, matrix2, matrix3, matrix4, max, min, modulo, mul, norm, nums, obj2str, ones, pgcd, pow$1 as pow, powerSet, ppcm, preload, prod, rad2deg, round, sec, sig, sign, sin$2 as sin, sinc, sinh$1 as sinh, sleep, sqrt$2 as sqrt, sqrtn, step_fps, sub, subSet, sum, svg2ascii, svg2img, svg2imgUrl, svg2str, tags, tan, tanh, text, throttle, tick, timeTaken, time_memory_Taken, timeout, useChannel, useDerived, useEventEmitter, useLocaleStorage, useReactive, useRoot, useSessionStorage, useState, useThread, wait, waitForUIElm, waitForUIElmSync, zeros };