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