ziko 0.37.0 → 0.38.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.
Files changed (130) hide show
  1. package/dist/ziko.cjs +1722 -3956
  2. package/dist/ziko.js +6150 -8384
  3. package/dist/ziko.min.js +2 -2
  4. package/dist/ziko.mjs +1713 -3840
  5. package/package.json +16 -13
  6. package/readme.md +79 -5
  7. package/src/__helpers__/composition-dep/compose-class.js +46 -0
  8. package/src/__helpers__/register/index.js +6 -0
  9. package/src/__helpers__/register/register-to-class.js +16 -0
  10. package/src/__helpers__/register/register-to-instance.js +18 -0
  11. package/src/__ziko__/__cache__.js +6 -0
  12. package/src/__ziko__/__config__.js +19 -0
  13. package/src/__ziko__/__hydration__.js +8 -0
  14. package/src/__ziko__/__ui__.js +22 -0
  15. package/src/__ziko__/index.js +17 -0
  16. package/src/__ziko__/params.js +40 -0
  17. package/src/app/globals.js +14 -0
  18. package/src/app/index.js +4 -4
  19. package/src/app/spa-file-based-routing.js +2 -2
  20. package/src/app/ziko-app.js +1 -1
  21. package/src/data/converter/svg.js +2 -2
  22. package/src/hooks/index.js +3 -0
  23. package/src/hooks/use-derived.js +61 -0
  24. package/src/hooks/use-reactive.js +7 -0
  25. package/src/hooks/use-state.js +52 -0
  26. package/src/index.js +1 -78
  27. package/src/math/complex/index.js +3 -0
  28. package/src/math/functions/index.js +23 -23
  29. package/src/math/functions/proxy.js +58 -0
  30. package/src/math/utils/mapfun.js +17 -21
  31. package/src/no-module.js +32 -0
  32. package/src/time/{animation.js → animation/index.js} +2 -2
  33. package/src/time/decorators/index.js +17 -0
  34. package/src/time/index.js +11 -12
  35. package/src/time/utils/index.js +0 -1
  36. package/src/ui/{methods → __methods__}/dom.js +15 -14
  37. package/src/ui/__methods__/index.js +4 -0
  38. package/src/ui/{utils → __utils__}/index.js +1 -1
  39. package/src/ui/constructors/{ziko-ui-element.js → ZikoUIElement.js} +17 -117
  40. package/src/ui/constructors/ZikoUIElementMethodesToBeMoved-dep.js +96 -0
  41. package/src/ui/{style → constructors/style}/index.js +3 -3
  42. package/src/ui/{elements/flex → flex}/index.js +1 -1
  43. package/src/{graphics/canvas/index.js → ui/graphics/canvas.js} +4 -5
  44. package/src/ui/graphics/index.js +2 -0
  45. package/src/{graphics/svg/index.js → ui/graphics/svg.js} +1 -1
  46. package/src/ui/{elements/grid → grid}/index.js +1 -1
  47. package/src/ui/index.js +9 -40
  48. package/src/ui/{elements/misc/suspense.js → suspense/index.js} +1 -15
  49. package/src/ui/tags/index.js +27 -17
  50. package/src/ui/text/index.js +15 -0
  51. package/src/ui/{elements/misc/xml-wrapper.js → wrapper/index.js} +1 -1
  52. package/src/use/index.js +3 -7
  53. package/src/__helpers__/composition/compose-class.js +0 -28
  54. package/src/graphics/canvas/_canvas_offscreen +0 -0
  55. package/src/graphics/canvas/utils/color.js +0 -8
  56. package/src/graphics/canvas/utils/floodFill.js +0 -57
  57. package/src/graphics/index.js +0 -10
  58. package/src/time/utils/decorators.js +0 -17
  59. package/src/ui/elements/embaded/html.js +0 -20
  60. package/src/ui/elements/embaded/index.js +0 -3
  61. package/src/ui/elements/embaded/pdf.js +0 -17
  62. package/src/ui/elements/embaded/youtube.js +0 -24
  63. package/src/ui/elements/hydrate.js +0 -0
  64. package/src/ui/elements/index.js +0 -10
  65. package/src/ui/elements/io/Form/index.js +0 -42
  66. package/src/ui/elements/io/Form/index.js.txt +0 -104
  67. package/src/ui/elements/io/Inputs/__helpers__.js +0 -52
  68. package/src/ui/elements/io/Inputs/index.js +0 -12
  69. package/src/ui/elements/io/Inputs/input/index.js +0 -99
  70. package/src/ui/elements/io/Inputs/input-camera/index.js +0 -26
  71. package/src/ui/elements/io/Inputs/input-checkbox/index.js +0 -26
  72. package/src/ui/elements/io/Inputs/input-color/index.js +0 -16
  73. package/src/ui/elements/io/Inputs/input-date-time/index.js +0 -3
  74. package/src/ui/elements/io/Inputs/input-date-time/input-date-time.js +0 -14
  75. package/src/ui/elements/io/Inputs/input-date-time/input-date.js +0 -14
  76. package/src/ui/elements/io/Inputs/input-date-time/input-time.js +0 -14
  77. package/src/ui/elements/io/Inputs/input-email-password/index.js +0 -2
  78. package/src/ui/elements/io/Inputs/input-email-password/input-email.js +0 -15
  79. package/src/ui/elements/io/Inputs/input-email-password/input-password.js +0 -14
  80. package/src/ui/elements/io/Inputs/input-file/index.js +0 -1
  81. package/src/ui/elements/io/Inputs/input-file/input-file.js +0 -0
  82. package/src/ui/elements/io/Inputs/input-file/input-image.js +0 -43
  83. package/src/ui/elements/io/Inputs/input-number/index.js +0 -37
  84. package/src/ui/elements/io/Inputs/input-radio/index.js +0 -26
  85. package/src/ui/elements/io/Inputs/input-search/index.js +0 -45
  86. package/src/ui/elements/io/Inputs/input-slider/index.js +0 -34
  87. package/src/ui/elements/io/Select/index.js +0 -20
  88. package/src/ui/elements/io/Textarea/index.js +0 -18
  89. package/src/ui/elements/io/index.js +0 -4
  90. package/src/ui/elements/list/elements.js +0 -0
  91. package/src/ui/elements/list/index.js +0 -138
  92. package/src/ui/elements/media/Audio/index.js +0 -17
  93. package/src/ui/elements/media/Image/figure.js +0 -19
  94. package/src/ui/elements/media/Image/image.js +0 -37
  95. package/src/ui/elements/media/Image/index.js +0 -2
  96. package/src/ui/elements/media/Video/index.js +0 -27
  97. package/src/ui/elements/media/__ZikoUIDynamicMediaELement__.js +0 -47
  98. package/src/ui/elements/media/index.js +0 -3
  99. package/src/ui/elements/misc/hyperscript.js +0 -144
  100. package/src/ui/elements/misc/index.js +0 -101
  101. package/src/ui/elements/semantic/index.js +0 -42
  102. package/src/ui/elements/table/elements.js +0 -94
  103. package/src/ui/elements/table/index.js +0 -3
  104. package/src/ui/elements/table/table.js +0 -115
  105. package/src/ui/elements/table/utils.js +0 -12
  106. package/src/ui/elements/text/__ZikoUIText__.js +0 -70
  107. package/src/ui/elements/text/heading.js +0 -36
  108. package/src/ui/elements/text/index.js +0 -3
  109. package/src/ui/elements/text/p.js +0 -26
  110. package/src/ui/elements/text/pre.js +0 -0
  111. package/src/ui/elements/text/text.js +0 -81
  112. package/src/use/use-debounce.js +0 -4
  113. package/src/use/use-state.js +0 -22
  114. package/src/use/use-throttle.js +0 -9
  115. /package/src/__helpers__/{composition → composition-dep}/compose-instance.js +0 -0
  116. /package/src/__helpers__/{composition → composition-dep}/compose.js +0 -0
  117. /package/src/__helpers__/{composition → composition-dep}/index.js +0 -0
  118. /package/src/reactivity/hooks/{Head → head}/_useCssText.js +0 -0
  119. /package/src/reactivity/hooks/{Head → head}/index.js +0 -0
  120. /package/src/reactivity/hooks/{Head → head}/useFavIcon.js +0 -0
  121. /package/src/reactivity/hooks/{Head → head}/useHead.js +0 -0
  122. /package/src/reactivity/hooks/{Head → head}/useMeta.js +0 -0
  123. /package/src/reactivity/hooks/{Head → head}/useTitle.js +0 -0
  124. /package/src/time/{loop.js → loop/index.js} +0 -0
  125. /package/src/ui/{methods → __methods__}/events.js +0 -0
  126. /package/src/ui/{methods → __methods__}/indexing.js +0 -0
  127. /package/src/ui/{methods → __methods__}/observer.js +0 -0
  128. /package/src/ui/{methods → __methods__}/style.js +0 -0
  129. /package/src/ui/constructors/{ziko-ui-node.js → ZikoUINode.js} +0 -0
  130. /package/src/ui/tags/{tags.js → tags-list.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziko",
3
- "version": "0.37.0",
3
+ "version": "0.38.1",
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",
@@ -24,16 +24,16 @@
24
24
  "LICENCE"
25
25
  ],
26
26
  "exports": {
27
- "./*" : "./src/*",
27
+ "./*": "./src/*",
28
28
  ".": {
29
29
  "import": "./dist/ziko.mjs",
30
30
  "require": "./dist/ziko.cjs"
31
31
  },
32
32
  "./math": {
33
- "import" : "./src/math/index.js"
33
+ "import": "./src/math/index.js"
34
34
  },
35
35
  "./helpers": {
36
- "import" : "./src/__helpers__.js"
36
+ "import": "./src/__helpers__.js"
37
37
  },
38
38
  "./events": {
39
39
  "import": "./src/events/index.js"
@@ -44,11 +44,14 @@
44
44
  "./use": {
45
45
  "import": "./src/use/index.js"
46
46
  },
47
- "./ui":{
47
+ "./hooks": {
48
+ "import": "./src/hooks/index.js"
49
+ },
50
+ "./ui": {
48
51
  "import": "./src/ui/index.js",
49
52
  "type": "./src/ui/index.d.ts"
50
53
  },
51
- "./tags":{
54
+ "./tags": {
52
55
  "import": "./src/tags/index.js"
53
56
  },
54
57
  "./src": "./src/index.js",
@@ -56,13 +59,13 @@
56
59
  "./app": {},
57
60
  "./time": {},
58
61
  "./components": {}
59
-
60
62
  },
63
+ "sideEffects" : false,
61
64
  "bin": {
62
65
  "create-ziko-app": "starter/bin/index.js"
63
66
  },
64
67
  "scripts": {
65
- "test": "npx jasmine --config=jasmine.json",
68
+ "test": "npx vitest",
66
69
  "test-link": "node _link/index.js",
67
70
  "lint": "eslint src/*/*/*",
68
71
  "dev": "cross-env NODE_ENV=development rollup --config rollup.config.js",
@@ -83,13 +86,13 @@
83
86
  "@rollup/plugin-commonjs": "^25.0.7",
84
87
  "@rollup/plugin-node-resolve": "^15.2.3",
85
88
  "@rollup/plugin-terser": "^0.4.4",
89
+ "@vitest/coverage-v8": "^3.2.4",
86
90
  "cross-env": "^7.0.3",
87
91
  "eslint": "^8.57.1",
88
- "eslint-plugin-import": "^2.32.0",
89
- "eslint-plugin-spellcheck": "^0.0.20",
90
- "jasmine": "^5.3.0",
92
+ "jsdom": "^26.1.0",
91
93
  "rollup": "^4.1.5",
92
94
  "rollup-plugin-livereload": "^2.0.5",
93
- "rollup-plugin-serve": "^1.1.1"
95
+ "rollup-plugin-serve": "^1.1.1",
96
+ "vitest": "^3.2.4"
94
97
  }
95
- }
98
+ }
package/readme.md CHANGED
@@ -21,22 +21,96 @@ Composition
21
21
  - 🚫 Zero Dependency
22
22
  - 🌳 Partial Tree Shaking
23
23
  - 🔢 Rich Math Functions and Utilities
24
+ - <details>
25
+ <summary>Flexible Math Functions</summary>
26
+ ZikoJS offers flexible math utilities, such as the `mapfun` function, which allows mapping standard mathematical operations to complex and nested data structures.
27
+ For example, the `cos` function in ZikoJS is built on top of mapfun, enabling it to handle multiple arguments with diverse types (numbers, arrays, objects).
28
+
29
+ ```js
30
+ import { cos, PI } from "ziko";
31
+ const result = cos(PI, PI / 2, PI / 4, [PI / 6, PI / 3], {
32
+ x: PI / 2,
33
+ y: PI / 4,
34
+ z: [0, PI / 12],
35
+ }
36
+ );
37
+ /*
38
+ result =>
39
+ [
40
+ -1,
41
+ 0,
42
+ 0.707106781186548,
43
+ [0.866025403784439, 0.5],
44
+ {
45
+ x: 0,
46
+ y: 0.707106781186548,
47
+ z: [1, 0.965925826289068],
48
+ },
49
+ ];
50
+ */
51
+ // console.log(result)
52
+
53
+ ```
54
+ You can also built your own flexible Math function using this mapfun util :
55
+ ```js
56
+ import { mapfun } from "ziko";
57
+ const parabolic_func = (a, b, c, x) => a * x ** 2 + b * x + c;
58
+ const map_parabolic_func =
59
+ (a, b, c) =>
60
+ (...X) =>
61
+ mapfun((n) => parabolic_func(a, b, c, n), ...X);
62
+ const a = -1.5,
63
+ b = 2,
64
+ c = 3;
65
+ const X = [0, 1, 2, 3];
66
+ console.log(parabolic_func(a, b, c)(X));
67
+ // [3,3,1,3]
68
+
69
+ ```
70
+ </details>
71
+
72
+
73
+
24
74
  <!-- - The Math Module supports a new Paradigm -->
25
75
  - ✨ Hyperscript-Based Declarative UI (No Template Engines needed)
76
+ ```js
77
+ import {p, text, Random} from 'ziko'
78
+ const Hello = name => p(
79
+ text("Hello ", name)
80
+ ).onClick(e => e.target.style({color : Random.color()}))
81
+ ```
82
+ - 🔄 Built in State Mangement :
83
+ ```js
84
+ import { tags } from 'ziko/ui'
85
+ import {useState, useDerived} from 'ziko/hooks'
86
+ const [timer, setTimer] = useState(0);
87
+ const converToHMS = seconds => `${Math.floor(seconds / 3600)} : ${Math.floor((seconds % 3600) / 60)} : ${seconds % 60} `
88
+ const [time] = useDerived(t => converToHMS(t) , [timer] )
89
+ tags.p('Elapsed Time : ', time)
90
+ let i = 1;
91
+ setInterval(()=>{
92
+ setTimer(i);
93
+ i++
94
+ }, 1000)
95
+ ```
26
96
  - 📱 Single Page Application With File Based Routing
97
+ ```js
98
+ import { FileBasedRouting } from "ziko";
99
+ FileBasedRouting(import.meta.glob("./src/pages/**/*.js"))
100
+ ```
27
101
  - 🤝 One Way Interleaving With [Vanjs]()
28
102
  - ⏰ Time loop and animations support
29
103
 
30
104
  ### 🚀 External :
31
- - 🧩 Extra UI Components : [Zextra]()
32
- - 🖥️ Server Side Rendering With File Based Routing and Client Side Hydration : [ziko-server]()
33
- - 📝 Mdx-Like Markdown Preprocessor : [Mdz]()
34
- - 🔌 Flexible Integration with Popular Frameworks/Libraries : [Ziko-wrapper]()
105
+ - 🧩 Extra UI Components : [Zextra](https://github.com/zakarialaoui10/zextra)
106
+ - 🖥️ Server Side Rendering With File Based Routing and Client Side Hydration : [ziko-server](https://github.com/zakarialaoui10/ziko-server)
107
+ - 📝 Mdx-Like Markdown Preprocessor : [Mdz](https://github.com/zakarialaoui10/mdz)
108
+ - 🔌 Flexible Integration with Popular Frameworks/Libraries : [Ziko-wrapper](https://github.com/zakarialaoui10/ziko-wrapper)
35
109
  - 🔄 Bi-directional : `React`, `Preact`, `Solid`, `Svelte`, `Vue` , `Vanjs`
36
110
  - ➡️ Uni-directional (ZikoJS → X) :
37
111
  - `Astro` : (SSR + Client Hydration)
38
112
  - 📦 Growing Add-On Ecosystem :
39
- - Ziko-Gl : WebGL/3D Graphics, Built on Top of [Threejs]()
113
+ - Ziko-Gl : WebGL/3D Graphics, Built on Top of [Threejs](https://github.com/zakarialaoui10/ziko-gl)
40
114
  - Ziko-Chart
41
115
  - Ziko-Code
42
116
  - Ziko-Lottie
@@ -0,0 +1,46 @@
1
+ export function composeClass(Class, mixin) {
2
+ const descriptors = Object.getOwnPropertyDescriptors(mixin);
3
+
4
+ class Composed extends Class {
5
+ constructor(...args) {
6
+ super(...args);
7
+ // ⚠️ Do NOT assign mixin functions to `this`
8
+ }
9
+ }
10
+
11
+ // Copy prototype properties (methods, getters/setters, non-functions)
12
+ for (const key of Reflect.ownKeys(descriptors)) {
13
+ const desc = descriptors[key];
14
+
15
+ if ('get' in desc || 'set' in desc || typeof desc.value !== 'function') {
16
+ Object.defineProperty(Composed.prototype, key, desc);
17
+ } else if (typeof desc.value === 'function') {
18
+ // Only add method if it does NOT already exist
19
+ if (!Composed.prototype.hasOwnProperty(key)) {
20
+ Object.defineProperty(Composed.prototype, key, desc);
21
+ }
22
+ }
23
+ }
24
+
25
+ return Composed;
26
+ }
27
+
28
+ // // Usage
29
+ // class UIBase {
30
+ // log() { console.log('UIBase log'); }
31
+ // }
32
+
33
+ // const mixin = {
34
+ // at() { return 0; },
35
+ // hello() { return 'hello'; }
36
+ // };
37
+
38
+ // const UIComposed = composeClass(UIBase, mixin);
39
+
40
+ // class UI2 extends UIComposed {
41
+ // at() { return 1; } // ✅ correctly overrides mixin
42
+ // }
43
+
44
+ // const ui = new UI2();
45
+ // console.log(ui.at()); // 1
46
+ // console.log(ui.hello()); // 'hello'
@@ -0,0 +1,6 @@
1
+ import { register_to_class } from "./register-to-class.js";
2
+ import { register_to_instance } from "./register-to-instance";
3
+ export const register = (target, ...mixins) => {
4
+ if(typeof target === 'function') register_to_class(target, ...mixins)
5
+ else register_to_instance(target, ...mixins)
6
+ }
@@ -0,0 +1,16 @@
1
+ export function register_to_class(target, ...mixins){
2
+ mixins.forEach(n => _register_to_class_(target, n))
3
+ }
4
+ function _register_to_class_(target, mixin) {
5
+ const descriptors = Object.getOwnPropertyDescriptors(mixin);
6
+ for (const key of Reflect.ownKeys(descriptors)) {
7
+ const desc = descriptors[key];
8
+ if ('get' in desc || 'set' in desc || typeof desc.value !== 'function') {
9
+ Object.defineProperty(Object.getPrototypeOf(target), key, desc);
10
+ } else if (typeof desc.value === 'function') {
11
+ if (!Object.getPrototypeOf(target).hasOwnProperty(key)) {
12
+ Object.defineProperty(Object.getPrototypeOf(target), key, desc);
13
+ }
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,18 @@
1
+ export function register_to_instance(target, ...mixins){
2
+ mixins.forEach(n => _register_to_instance_(target, n))
3
+ }
4
+ function _register_to_instance_(instance, mixin) {
5
+ const descriptors = Object.getOwnPropertyDescriptors(mixin);
6
+
7
+ for (const key of Reflect.ownKeys(descriptors)) {
8
+ const desc = descriptors[key];
9
+
10
+ if ('get' in desc || 'set' in desc) {
11
+ Object.defineProperty(instance, key, desc);
12
+ } else if (typeof desc.value === 'function') {
13
+ instance[key] = desc.value.bind(instance);
14
+ } else {
15
+ instance[key] = desc.value;
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,6 @@
1
+ export const __CACHE__ = {
2
+ ui_index : 0,
3
+ get_ui_index:function(){
4
+ return this.ui_index ++
5
+ }
6
+ }
@@ -0,0 +1,19 @@
1
+ export const __Config__ = {
2
+ default:{
3
+ target:null,
4
+ render:true,
5
+ math:{
6
+ mode:"deg"
7
+ }
8
+ },
9
+ setDefault:function(pairs){
10
+ const keys=Object.keys(pairs);
11
+ const values=Object.values(pairs);
12
+ for(let i=0; i<keys.length; i++) this.default[keys[i]]=values[i];
13
+ },
14
+ init:()=>{
15
+ // document.documentElement.setAttribute("data-engine","zikojs")
16
+ },
17
+ renderingMode :"spa",
18
+ isSSC : false,
19
+ }
@@ -0,0 +1,8 @@
1
+ export const __HYDRATION__ = {
2
+ map : new Map(),
3
+ index : 0,
4
+ increment : function(){
5
+ return this.index ++
6
+ }
7
+ }
8
+ export const __HYDRATION_MAP__ = new Map()
@@ -0,0 +1,22 @@
1
+ export const __UI__={
2
+ __all__(){
3
+ return Object.values(this)
4
+ .filter(Array.isArray)
5
+ .flat();
6
+ },
7
+ querySelectorAll(){
8
+ return this.__all__().filter(n=>n)
9
+ },
10
+ getElementByIndex(index){
11
+ return this.__all__().find(n=>n.ui_index===index);
12
+ },
13
+ getElementById(id){
14
+ return null;
15
+ },
16
+ getElementsByClass(){
17
+
18
+ },
19
+ getElementsByTagName(){
20
+
21
+ }
22
+ }
@@ -0,0 +1,17 @@
1
+ import { defineParamsGetter } from './params.js';
2
+ import { __UI__ } from './__ui__.js';
3
+ import { __Config__ } from './__config__.js';
4
+ import { __HYDRATION__, __HYDRATION_MAP__ } from './__hydration__.js';
5
+ import { __CACHE__ } from './__cache__.js';
6
+ export function __init__global__(){
7
+ if ( !globalThis?.__Ziko__ ){
8
+ globalThis.__Ziko__ = {
9
+ __UI__,
10
+ __HYDRATION__,
11
+ __HYDRATION_MAP__,
12
+ __Config__,
13
+ __CACHE__,
14
+ };
15
+ defineParamsGetter(__Ziko__)
16
+ }
17
+ }
@@ -0,0 +1,40 @@
1
+ function parseQueryParams(queryString) {
2
+ const params = {};
3
+ queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
4
+ const [key, value] = match.split('=');
5
+ params[key] = value;
6
+ });
7
+ return params;
8
+ }
9
+
10
+ function defineParamsGetter(target ){
11
+ Object.defineProperties(target, {
12
+ 'QueryParams': {
13
+ get: function() {
14
+ return parseQueryParams(globalThis.location.search.substring(1));
15
+ },
16
+ configurable: false,
17
+ enumerable: true
18
+ },
19
+ 'HashParams': {
20
+ get: function() {
21
+ const hash = globalThis.location.hash.substring(1);
22
+ return hash.split("#");
23
+ },
24
+ configurable: false,
25
+ enumerable: true
26
+ }
27
+ });
28
+ }
29
+
30
+
31
+ /*
32
+
33
+ /users?name=ziko&age=26
34
+ /users#name=ziko
35
+
36
+ */
37
+
38
+ export{
39
+ defineParamsGetter
40
+ }
@@ -1,3 +1,4 @@
1
+ import { defineParamsGetter } from './params.js'
1
2
  const __UI__={
2
3
  __all__(){
3
4
  return Object.values(this)
@@ -53,6 +54,19 @@ const __CACHE__ = {
53
54
  return this.ui_index ++
54
55
  }
55
56
  }
57
+ if ( !globalThis?.__Ziko__ ){
58
+ globalThis.__Ziko__ = {
59
+ // ...Ziko,
60
+ __UI__,
61
+ __HYDRATION__,
62
+ __HYDRATION_MAP__,
63
+ __Config__,
64
+ __CACHE__,
65
+ // ExtractAll,
66
+ // RemoveAll
67
+ };
68
+ defineParamsGetter(__Ziko__)
69
+ }
56
70
  export {
57
71
  __UI__,
58
72
  __HYDRATION_MAP__,
package/src/app/index.js CHANGED
@@ -1,18 +1,18 @@
1
1
  export * from "./ziko-app.js";
2
2
  export * from "./spa.js"
3
3
  export * from "./params.js"
4
- export * from "./globals.js"
4
+ // export * from "./globals.js"
5
5
  export * from "./spa-file-based-routing.js"
6
6
 
7
7
  import * as __App__ from "./ziko-app.js"
8
8
  import * as Spa from "./spa.js"
9
- import * as Global from "./globals.js"
9
+ // import * as Global from "./globals.js"
10
10
  // import * as Params from "./params"
11
11
 
12
- const App={
12
+ const App = {
13
13
  ...__App__,
14
14
  ...Spa,
15
- ...Global,
15
+ // ...Global,
16
16
  // ...Params
17
17
  }
18
18
  export default App
@@ -1,5 +1,5 @@
1
1
  import { SPA } from "./spa.js";
2
- import { Section } from "../ui/index.js";
2
+ import { tags } from "../ui/index.js";
3
3
  // import.meta.glob('./src/pages/**/*.js')
4
4
  async function FileBasedRouting(pages /* use import.meta.glob */){
5
5
  const routes = Object.keys(pages)
@@ -16,7 +16,7 @@ async function FileBasedRouting(pages /* use import.meta.glob */){
16
16
  "/" : ()=>{},
17
17
  ...pairs
18
18
  },
19
- wrapper : Section()
19
+ wrapper : tags.section()
20
20
  })
21
21
  }
22
22
  function customPath(inputPath, root = './src/pages', extensions = ['js', 'ts']) {
@@ -1,4 +1,4 @@
1
- import { ZikoHead , useHead} from "../reactivity/hooks/Head/index.js";
1
+ import { ZikoHead , useHead} from "../reactivity/hooks/head/index.js";
2
2
  class ZikoApp {
3
3
  constructor({head = null, wrapper = null, target = null}){
4
4
  this.head = head;
@@ -1,8 +1,8 @@
1
- import { image } from "../../ui"
1
+ import { tags } from "../../ui"
2
2
  const svg2str=svg=>(new XMLSerializer()).serializeToString(svg);
3
3
  const svg2ascii=svg=>btoa(svg2str(svg));
4
4
  const svg2imgUrl=svg=>'data:image/svg+xml;base64,'+svg2ascii(svg);
5
- const svg2img=(svg,render=true)=>image(svg2imgUrl(svg)).render(render);
5
+ const svg2img=(svg,render=true)=>tags.img(svg2imgUrl(svg)).render(render);
6
6
  export{
7
7
  svg2str,
8
8
  svg2ascii,
@@ -0,0 +1,3 @@
1
+ export * from './use-state.js';
2
+ export * from './use-derived.js';
3
+ export * from './use-reactive.js';
@@ -0,0 +1,61 @@
1
+ export function useDerived(deriveFn, sources) {
2
+ let value = deriveFn(...sources.map(s => s().value));
3
+ const subscribers = new Set();
4
+ let paused = false;
5
+
6
+ function getValue() {
7
+ return {
8
+ value,
9
+ isStateGetter: () => true,
10
+ _subscribe: (fn, UIElement) => {
11
+ subscribers.add(fn);
12
+
13
+ const observer = new MutationObserver(() => {
14
+ if (!document.body.contains(UIElement.element)) {
15
+ subscribers.delete(fn);
16
+ observer.disconnect();
17
+ }
18
+ });
19
+
20
+ observer.observe(document.body, { childList: true, subtree: true });
21
+ },
22
+ };
23
+ }
24
+
25
+ function setValue(newValue) {
26
+ if (paused) return;
27
+ if (typeof newValue === "function") newValue = newValue(value);
28
+ if (newValue !== value) {
29
+ value = newValue;
30
+ subscribers.forEach(fn => fn(value));
31
+ }
32
+ }
33
+
34
+ const controller = {
35
+ pause: () => { paused = true; },
36
+ resume: () => { paused = false; },
37
+ clear: () => { subscribers.clear(); },
38
+ force: (newValue) => {
39
+ if (typeof newValue === "function") newValue = newValue(value);
40
+ value = newValue;
41
+ subscribers.forEach(fn => fn(value));
42
+ },
43
+ getSubscribers: () => new Set(subscribers),
44
+ };
45
+
46
+ // Subscribe to source states
47
+ sources.forEach(source => {
48
+ const srcValue = source(); // getValue()
49
+ srcValue._subscribe(() => {
50
+ if (!paused) {
51
+ const newVal = deriveFn(...sources.map(s => s().value));
52
+ if (newVal !== value) {
53
+ value = newVal;
54
+ subscribers.forEach(fn => fn(value));
55
+ }
56
+ }
57
+ }, { element: document.body }); // dummy UIElement
58
+ });
59
+
60
+ return [getValue, setValue, controller];
61
+ }
@@ -0,0 +1,7 @@
1
+ import {mapfun} from '../math'
2
+ import { useState } from './use-state.js'
3
+
4
+ const useReactive = (nested_value) => mapfun(n => useState(n), nested_value)
5
+ export{
6
+ useReactive
7
+ }
@@ -0,0 +1,52 @@
1
+ export function useState(initialValue) {
2
+ let value = initialValue;
3
+ const subscribers = new Set();
4
+ let paused = false;
5
+
6
+ function getValue() {
7
+ return {
8
+ value,
9
+ isStateGetter: () => true,
10
+ _subscribe: (fn, UIElement) => {
11
+ subscribers.add(fn);
12
+
13
+ const observer = new MutationObserver(() => {
14
+ if (!document.body.contains(UIElement.element)) {
15
+ subscribers.delete(fn);
16
+ observer.disconnect();
17
+ }
18
+ });
19
+
20
+ observer.observe(document.body, { childList: true, subtree: true });
21
+ },
22
+ };
23
+ }
24
+
25
+ function setValue(newValue) {
26
+ if (paused) return;
27
+ if (typeof newValue === "function") newValue = newValue(value);
28
+ if (newValue !== value) {
29
+ value = newValue;
30
+ subscribers.forEach(fn => fn(value));
31
+ }
32
+ }
33
+
34
+ const controller = {
35
+ pause: () => { paused = true; },
36
+ resume: () => { paused = false; },
37
+ clear: () => { subscribers.clear(); },
38
+ force: (newValue) => { // force update even if paused
39
+ if (typeof newValue === "function") newValue = newValue(value);
40
+ value = newValue;
41
+ subscribers.forEach(fn => fn(value));
42
+ },
43
+ getSubscribers: () => new Set(subscribers),
44
+ };
45
+
46
+ return [getValue, setValue, controller];
47
+ }
48
+
49
+ export const isStateGetter = (arg) => {
50
+ return typeof(arg) === 'function' && arg?.()?.isStateGetter?.()
51
+ }
52
+