ziko 0.0.17 → 0.0.19

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 (267) hide show
  1. package/README.md +91 -200
  2. package/package.json +17 -46
  3. package/src/__helpers__/index.js +61 -61
  4. package/src/app/json-style-sheet.js +64 -64
  5. package/src/app/spa-file-based-routing.js +0 -1
  6. package/src/app/ziko-app.js +38 -38
  7. package/src/data/api/fetchdom.js +13 -13
  8. package/src/data/api/index.js +3 -3
  9. package/src/data/api/preload.js +10 -10
  10. package/src/data/converter/adoc.js +130 -130
  11. package/src/data/converter/array.js +42 -42
  12. package/src/data/converter/canvas.js +24 -24
  13. package/src/data/converter/css.js +36 -36
  14. package/src/data/converter/csv.js +32 -32
  15. package/src/data/converter/idea.txt +9 -9
  16. package/src/data/converter/index.js +36 -36
  17. package/src/data/converter/json.js +80 -80
  18. package/src/data/converter/markdown.js +95 -95
  19. package/src/data/converter/object.js +69 -69
  20. package/src/data/converter/svg.js +10 -10
  21. package/src/data/datatypes/color.js +11 -0
  22. package/src/data/index.js +16 -16
  23. package/src/data/parser/xml.js +46 -46
  24. package/src/data/string/patterns.js +11 -11
  25. package/src/data/string/string.js +169 -169
  26. package/src/global/{themes → _themes}/dark.js +884 -884
  27. package/src/global/{themes → _themes}/index.js +10 -10
  28. package/src/global/{themes → _themes}/light.js +254 -254
  29. package/src/global/app/index.js +45 -45
  30. package/src/global/component/index.js +38 -38
  31. package/src/global/globals/index.js +20 -20
  32. package/src/global/index.js +3 -11
  33. package/src/global/params/index.js +39 -39
  34. package/src/global/router/index.js +66 -66
  35. package/src/global/seo/index.js +42 -42
  36. package/src/graphics/canvas/canvas.js +176 -189
  37. package/src/graphics/canvas/elements/Basic/arc.js +42 -42
  38. package/src/graphics/canvas/elements/Basic/line.js +25 -25
  39. package/src/graphics/canvas/elements/Basic/points.js +47 -47
  40. package/src/graphics/canvas/elements/Basic/polygon.js +6 -6
  41. package/src/graphics/canvas/elements/Basic/rect.js +45 -45
  42. package/src/graphics/canvas/elements/Chart/scatter.js +2 -2
  43. package/src/graphics/canvas/elements/Element.js +114 -114
  44. package/src/graphics/canvas/elements/index.js +13 -13
  45. package/src/graphics/canvas/index.js +2 -15
  46. package/src/graphics/canvas/utils/color.js +7 -7
  47. package/src/graphics/canvas/utils/floodFill.js +57 -57
  48. package/src/graphics/index.js +10 -69
  49. package/src/graphics/svg/Elements/Basic/circle.js +29 -26
  50. package/src/graphics/svg/Elements/Basic/ellipse.js +24 -21
  51. package/src/graphics/svg/Elements/Basic/{foreignObject.js → foreign-object.js} +36 -33
  52. package/src/graphics/svg/Elements/Basic/groupe.js +32 -29
  53. package/src/graphics/svg/Elements/Basic/image.js +36 -33
  54. package/src/graphics/svg/Elements/Basic/index.js +11 -0
  55. package/src/graphics/svg/Elements/Basic/line.js +32 -29
  56. package/src/graphics/svg/Elements/Basic/link.js +33 -30
  57. package/src/graphics/svg/Elements/Basic/path.js +62 -59
  58. package/src/graphics/svg/Elements/Basic/polygon.js +31 -31
  59. package/src/graphics/svg/Elements/Basic/polyline.js +7 -4
  60. package/src/graphics/svg/Elements/Basic/rect.js +46 -43
  61. package/src/graphics/svg/Elements/Basic/text.js +29 -26
  62. package/src/graphics/svg/Elements/Derived/grid.js +8 -8
  63. package/src/graphics/svg/Elements/Derived/index.js +1 -0
  64. package/src/graphics/svg/Elements/index.js +2 -14
  65. package/src/graphics/svg/Elements/{ZikoSvgElement.js → ziko-svg-element.js} +48 -46
  66. package/src/graphics/svg/index.js +2 -2
  67. package/src/graphics/svg/svg.js +68 -114
  68. package/src/index.js +85 -84
  69. package/src/math/calculus/index.js +2 -2
  70. package/src/math/calculus/special-functions/bessel.js +30 -30
  71. package/src/math/calculus/special-functions/beta.js +37 -37
  72. package/src/math/calculus/special-functions/gamma.js +29 -29
  73. package/src/math/calculus/special-functions/index.js +4 -4
  74. package/src/math/complex/index.js +202 -202
  75. package/src/math/const.js +2 -2
  76. package/src/math/discret/Combinaison/index.js +33 -33
  77. package/src/math/discret/Conversion/index.js +85 -85
  78. package/src/math/discret/Logic/index.js +45 -45
  79. package/src/math/discret/Permutation/index.js +30 -30
  80. package/src/math/discret/Set/index.js +1 -1
  81. package/src/math/discret/Set/power-set.js +14 -14
  82. package/src/math/discret/Set/sub-set.js +10 -10
  83. package/src/math/discret/index.js +11 -11
  84. package/src/math/functions/index.js +161 -161
  85. package/src/math/index.js +32 -32
  86. package/src/math/matrix/Decomposition.js +90 -90
  87. package/src/math/matrix/LinearSystem.js +9 -9
  88. package/src/math/matrix/Matrix.js +716 -716
  89. package/src/math/matrix/index.js +2 -2
  90. package/src/math/random/index.js +172 -172
  91. package/src/math/signal/__np.py.txt +39 -39
  92. package/src/math/signal/conv.js +174 -174
  93. package/src/math/signal/fft.js +54 -54
  94. package/src/math/signal/filter.js +38 -38
  95. package/src/math/signal/functions.js +145 -145
  96. package/src/math/signal/index.js +109 -109
  97. package/src/math/statistics/Functions/index.js +99 -99
  98. package/src/math/statistics/index.js +15 -15
  99. package/src/math/utils/arithmetic.js +138 -138
  100. package/src/math/utils/checkers.js +29 -29
  101. package/src/math/utils/conversions.js +19 -19
  102. package/src/math/utils/discret.js +51 -51
  103. package/src/math/utils/index.js +101 -101
  104. package/src/math/utils/mapfun.js +49 -49
  105. package/src/reactivity/events/Input.js +61 -61
  106. package/src/reactivity/events/Pointer.js +231 -231
  107. package/src/reactivity/events/ZikoEvent.js +90 -90
  108. package/src/reactivity/events/click.js +59 -59
  109. package/src/reactivity/events/clipboard.js +87 -87
  110. package/src/reactivity/events/custom-event.js +56 -56
  111. package/src/reactivity/events/drag.js +136 -136
  112. package/src/reactivity/events/focus.js +58 -58
  113. package/src/reactivity/events/hash.js +46 -46
  114. package/src/reactivity/events/index.js +12 -63
  115. package/src/reactivity/events/key.js +101 -101
  116. package/src/reactivity/events/mouse.js +232 -232
  117. package/src/reactivity/events/swipe.js +149 -149
  118. package/src/reactivity/events/wheel.js +46 -46
  119. package/src/reactivity/hooks/{contexte → Contexte}/useSuccesifKeys.js +13 -13
  120. package/src/reactivity/hooks/{decorators → Decorators}/index.js +6 -6
  121. package/src/reactivity/hooks/{decorators → Decorators}/time.js +16 -16
  122. package/src/reactivity/hooks/{decorators → Decorators}/type.js +87 -87
  123. package/src/reactivity/hooks/{head/useCssText.js → Head/_useCssText.js} +20 -20
  124. package/src/reactivity/hooks/{head → Head}/index.js +5 -5
  125. package/src/reactivity/hooks/{head → Head}/useFavIcon.js +37 -37
  126. package/src/reactivity/hooks/{head → Head}/useHead.js +27 -27
  127. package/src/reactivity/hooks/{head → Head}/useMeta.js +52 -52
  128. package/src/reactivity/hooks/{head → Head}/useTitle.js +29 -29
  129. package/src/reactivity/hooks/{interactions/useBluetooth.js → Interactions/_useBluetooth.js} +47 -47
  130. package/src/reactivity/hooks/{interactions → Interactions}/index.js +4 -4
  131. package/src/reactivity/hooks/{interactions → Interactions}/useChannel.js +49 -49
  132. package/src/reactivity/hooks/{interactions → Interactions}/useEventEmmiter.js +63 -63
  133. package/src/reactivity/hooks/{interactions → Interactions}/useThread.js +43 -43
  134. package/src/reactivity/hooks/Sensors/index.js +2 -0
  135. package/src/reactivity/hooks/{sensors → Sensors}/useBattery.js +35 -35
  136. package/src/reactivity/hooks/{sensors → Sensors}/useGeolocation.js +16 -16
  137. package/src/reactivity/hooks/{storage → Storage}/useStorage.js +72 -72
  138. package/src/reactivity/hooks/{ui → UI}/index.js +6 -5
  139. package/src/reactivity/hooks/{ui → UI}/useMediaQuery.js +43 -43
  140. package/src/reactivity/hooks/UI/useRoot.js +39 -0
  141. package/src/reactivity/hooks/{ui → UI}/useStyle.js +79 -79
  142. package/src/reactivity/hooks/{ui → UI}/useTheme.js +61 -61
  143. package/src/reactivity/hooks/index.js +8 -91
  144. package/src/reactivity/hooks/todo.md +26 -26
  145. package/src/reactivity/idea +1 -1
  146. package/src/reactivity/index.js +11 -11
  147. package/src/reactivity/observer/attributes.js +28 -28
  148. package/src/reactivity/observer/children.js +36 -36
  149. package/src/reactivity/observer/index.js +6 -6
  150. package/src/reactivity/observer/intersection.js +43 -43
  151. package/src/reactivity/observer/mutation.js +112 -112
  152. package/src/reactivity/observer/resize.js +46 -46
  153. package/src/reactivity/observer/screen.js +44 -44
  154. package/src/reactivity/observer/screen.js.txt +83 -83
  155. package/src/reactivity/observer/screen.txt +12 -12
  156. package/src/time/animation.js +75 -75
  157. package/src/time/index.js +11 -11
  158. package/src/time/loop.js +87 -87
  159. package/src/time/utils/decorators.js +16 -16
  160. package/src/time/utils/ease.js +143 -143
  161. package/src/time/utils/index.js +17 -17
  162. package/src/time/utils/performance.js +15 -15
  163. package/src/time/utils/ui.js +25 -25
  164. package/src/types.js +73 -73
  165. package/src/ui/elements/derived/accordion/accordion.js +42 -42
  166. package/src/ui/elements/derived/accordion/collapsible.js +82 -82
  167. package/src/ui/elements/derived/accordion/index.js +1 -1
  168. package/src/ui/elements/derived/alert/alert.js +80 -80
  169. package/src/ui/elements/derived/alert/palette.js +51 -51
  170. package/src/ui/elements/derived/carousel/index.js +50 -50
  171. package/src/ui/elements/derived/code-note/SubElements.js.txt +104 -104
  172. package/src/ui/elements/derived/code-note/code-cell.js +194 -194
  173. package/src/ui/elements/derived/code-note/code-note.js +71 -71
  174. package/src/ui/elements/derived/code-note/index.js +1 -1
  175. package/src/ui/elements/derived/code-note/sub-elements.js +66 -66
  176. package/src/ui/elements/derived/elements/Swipper.js +3 -3
  177. package/src/ui/elements/derived/elements/index.js +9 -9
  178. package/src/ui/elements/derived/flex/index.js +102 -102
  179. package/src/ui/elements/derived/grid/index.js +32 -32
  180. package/src/ui/elements/derived/index.js +11 -11
  181. package/src/ui/elements/derived/menu/menu3d.js +259 -259
  182. package/src/ui/elements/derived/modal/index.js +91 -91
  183. package/src/ui/elements/derived/pagination/breadcrumbs.js +53 -53
  184. package/src/ui/elements/derived/slider/__ZikoUISlider__.js +111 -111
  185. package/src/ui/elements/derived/slider/hSlider.js +33 -33
  186. package/src/ui/elements/derived/slider/index.js +11 -11
  187. package/src/ui/elements/derived/slider/vSlider.js +26 -26
  188. package/src/ui/elements/derived/splitter/__ZikoUISplitter__.js +61 -61
  189. package/src/ui/elements/derived/splitter/hsplitter.js +39 -39
  190. package/src/ui/elements/derived/splitter/index.js +11 -11
  191. package/src/ui/elements/derived/splitter/vsplitter.js +39 -39
  192. package/src/ui/elements/derived/tabs/index.js +179 -179
  193. package/src/ui/elements/primitives/ZikoUIContainerElement.js +163 -126
  194. package/src/ui/elements/primitives/ZikoUIElement.js +492 -492
  195. package/src/ui/elements/primitives/embaded/html.js +19 -19
  196. package/src/ui/elements/primitives/embaded/index.js +3 -3
  197. package/src/ui/elements/primitives/embaded/pdf.js +16 -16
  198. package/src/ui/elements/primitives/embaded/youtube.js +23 -23
  199. package/src/ui/elements/primitives/index.js +7 -7
  200. package/src/ui/elements/primitives/io/Form/index.js +41 -41
  201. package/src/ui/elements/primitives/io/Form/index.js.txt +104 -104
  202. package/src/ui/elements/primitives/io/Inputs/__helpers__.js +51 -51
  203. package/src/ui/elements/primitives/io/Inputs/index.js +12 -12
  204. package/src/ui/elements/primitives/io/Inputs/input/index.js +98 -98
  205. package/src/ui/elements/primitives/io/Inputs/input-camera/index.js +26 -26
  206. package/src/ui/elements/primitives/io/Inputs/input-checkbox/index.js +25 -25
  207. package/src/ui/elements/primitives/io/Inputs/input-color/index.js +15 -15
  208. package/src/ui/elements/primitives/io/Inputs/input-date-time/index.js +2 -2
  209. package/src/ui/elements/primitives/io/Inputs/input-date-time/input-date-time.js +13 -13
  210. package/src/ui/elements/primitives/io/Inputs/input-date-time/input-date.js +13 -13
  211. package/src/ui/elements/primitives/io/Inputs/input-date-time/input-time.js +13 -13
  212. package/src/ui/elements/primitives/io/Inputs/input-email-password/index.js +1 -1
  213. package/src/ui/elements/primitives/io/Inputs/input-email-password/input-email.js +14 -14
  214. package/src/ui/elements/primitives/io/Inputs/input-email-password/input-password.js +13 -13
  215. package/src/ui/elements/primitives/io/Inputs/input-file/input-image.js +42 -42
  216. package/src/ui/elements/primitives/io/Inputs/input-number/index.js +36 -36
  217. package/src/ui/elements/primitives/io/Inputs/input-radio/index.js +25 -25
  218. package/src/ui/elements/primitives/io/Inputs/input-search/index.js +45 -45
  219. package/src/ui/elements/primitives/io/Inputs/input-slider/index.js +34 -34
  220. package/src/ui/elements/primitives/io/Select/index.js +19 -19
  221. package/src/ui/elements/primitives/io/Textarea/index.js +17 -17
  222. package/src/ui/elements/primitives/io/index.js +3 -3
  223. package/src/ui/elements/primitives/list/index.js +138 -138
  224. package/src/ui/elements/primitives/media/Audio/index.js +16 -16
  225. package/src/ui/elements/primitives/media/Image/figure.js +18 -18
  226. package/src/ui/elements/primitives/media/Image/image.js +36 -36
  227. package/src/ui/elements/primitives/media/Image/index.js +1 -1
  228. package/src/ui/elements/primitives/media/Video/index.js +26 -26
  229. package/src/ui/elements/primitives/media/__ZikoUIDynamicMediaELement__.js +46 -46
  230. package/src/ui/elements/primitives/media/index.js +2 -2
  231. package/src/ui/elements/primitives/misc/index.js +101 -101
  232. package/src/ui/elements/primitives/misc/xml-wrapper.js +3 -2
  233. package/src/ui/elements/primitives/semantic/index.js +81 -81
  234. package/src/ui/elements/primitives/table/elements.js +93 -93
  235. package/src/ui/elements/primitives/table/index.js +2 -2
  236. package/src/ui/elements/primitives/table/table.js +115 -115
  237. package/src/ui/elements/primitives/table/utils.js +11 -11
  238. package/src/ui/elements/primitives/text/__ZikoUIText__.js +71 -71
  239. package/src/ui/elements/primitives/text/heading.js +35 -35
  240. package/src/ui/elements/primitives/text/index.js +2 -2
  241. package/src/ui/elements/primitives/text/p.js +26 -26
  242. package/src/ui/elements/primitives/text/text.js +80 -80
  243. package/src/ui/index.js +37 -37
  244. package/src/ui/style/index.js +504 -515
  245. package/src/ui/utils/index.js +69 -69
  246. package/starter/bin/index.js +11 -11
  247. package/dist/ziko.cjs +0 -14018
  248. package/dist/ziko.js +0 -14028
  249. package/dist/ziko.min.js +0 -9
  250. package/dist/ziko.mjs +0 -13688
  251. package/src/graphics/canvas/elements/Groupe.js +0 -0
  252. package/src/graphics/canvas/elements/grid.js +0 -0
  253. package/src/graphics/canvas/filter/index.js +0 -0
  254. package/src/graphics/canvas/paint/index.js +0 -0
  255. package/src/reactivity/hooks/sensors/index.js +0 -2
  256. /package/src/reactivity/hooks/{contexte → Contexte}/index.js +0 -0
  257. /package/src/reactivity/hooks/{interactions → Interactions}/useSerial.js +0 -0
  258. /package/src/reactivity/hooks/{interactions → Interactions}/useUsb.js +0 -0
  259. /package/src/reactivity/hooks/{sensors → Sensors}/useCamera.js +0 -0
  260. /package/src/reactivity/hooks/{sensors → Sensors}/useMicro.js +0 -0
  261. /package/src/reactivity/hooks/{sensors → Sensors}/useOrientation.js +0 -0
  262. /package/src/reactivity/hooks/{storage → Storage}/index.js +0 -0
  263. /package/src/reactivity/hooks/{storage → Storage}/useCookie.js +0 -0
  264. /package/src/reactivity/hooks/{storage → Storage}/useIndexedDb.js +0 -0
  265. /package/src/reactivity/hooks/{ui → UI}/useCssLink.js +0 -0
  266. /package/src/reactivity/hooks/{ui → UI}/useLinearGradient.js +0 -0
  267. /package/src/reactivity/hooks/{ui → UI}/useRadialGradient.js +0 -0
@@ -1,175 +1,175 @@
1
- import { Matrix , matrix } from "../matrix/index.js";
2
- import { sqrt } from "../functions/index.js";
3
- const conv1d=(input, kernel , circular = true)=>{
4
- const INPUT_LENGTH = input.length;
5
- const KERNEL_LENGTH = kernel.length;
6
- const output = [];
7
- const LENGTH_OUT = circular ? Math.max(INPUT_LENGTH,KERNEL_LENGTH) : INPUT_LENGTH + KERNEL_LENGTH - 1;
8
- for (let i = 0; i < LENGTH_OUT; i++) {
9
- let sum = 0;
10
- for (let j = 0; j < KERNEL_LENGTH; j++) {
11
- const inputIndex = i + j - Math.floor(KERNEL_LENGTH / 2);
12
- // Apply zero-padding for out-of-bounds indices
13
- const inputValue = inputIndex >= 0 && inputIndex < INPUT_LENGTH
14
- ? input[inputIndex]
15
- : 0;
16
- sum += inputValue * kernel[j];
17
- }
18
- output.push(sum);
19
- }
20
- return output;
21
- }
22
-
23
- const conv2d = (input, kernel, circular = true) => {
24
- if(!(input instanceof Matrix)) input = matrix(input);
25
- if(!(kernel instanceof Matrix)) kernel = matrix(kernel);
26
- const INPUT_ROWS=input.rows;
27
- const INPUT_COLS=input.cols;
28
- const OUTPUT_ROWS = circular ? Math.max(input.rows,kernel.rows) : input.rows + kernel.rows-1;
29
- const OUTPUT_COLS = circular ? Math.max(input.cols,kernel.cols) : input.cols + kernel.cols-1;
30
- const KERNEL_SIZE = kernel.rows;
31
- const output = [];
32
- for (let i = 0; i < OUTPUT_ROWS ; i++) {
33
- const row = [];
34
- for (let j = 0; j < OUTPUT_COLS ; j++) {
35
- let sum = 0;
36
- for (let k = 0; k < KERNEL_SIZE; k++) {
37
- for (let l = 0; l < KERNEL_SIZE; l++) {
38
- const rowIndex = i + k - Math.floor(KERNEL_SIZE / 2);
39
- const colIndex = j + l - Math.floor(KERNEL_SIZE / 2);
40
- // Apply zero-padding for out-of-bounds indices
41
- const inputValue = (rowIndex >= 0 && rowIndex < INPUT_ROWS &&
42
- colIndex >= 0 && colIndex < INPUT_COLS)
43
- ? input[rowIndex][colIndex]
44
- : 0;
45
- sum += inputValue * kernel[k][l];
46
- }
47
- }
48
- row.push(sum);
49
- }
50
- output.push(row);
51
- }
52
- return output;
53
- };
54
-
55
- var convolute=(parent,kernel = [0, -1, 0, -1, 5, -1, 0, -1, 0], x1 = 0, y1 = 0, x2 = parent.element.width, y2 = parent.element.height)=>{
56
- if(kernel instanceof Matrix)kernel=kernel.arr.flat(1)
57
- var opaque = 1;
58
- var pixels = parent.ctx.getImageData(x1, y1, x2, y2);
59
- var side = Math.round(sqrt(kernel.length));
60
- var halfSide = Math.floor(side / 2);
61
- var src = pixels.data;
62
- var sw = pixels.width;
63
- var sh = pixels.height;
64
- // pad output by the convolution matrix
65
- var w = sw;
66
- var h = sh;
67
- var output = parent.ctx.createImageData(w, h);
68
- var dst = output.data;
69
- // go through the destination image pixels
70
- var alphaFac = opaque ? 1 : 0;
71
- for (var y = 0; y < h; y++) {
72
- for (var x = 0; x < w; x++) {
73
- var sy = y;
74
- var sx = x;
75
- var dstOff = (y * w + x) * 4;
76
- // calculate the weighed sum of the source image pixels that
77
- // fall under the convolution matrix
78
- var r = 0,
79
- g = 0,
80
- b = 0,
81
- a = 0;
82
- for (var cy = 0; cy < side; cy++) {
83
- for (var cx = 0; cx < side; cx++) {
84
- var scy = sy + cy - halfSide;
85
- var scx = sx + cx - halfSide;
86
- if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
87
- var srcOff = (scy * sw + scx) * 4;
88
- var wt = kernel[cy * side + cx];
89
- r += src[srcOff] * wt;
90
- g += src[srcOff + 1] * wt;
91
- b += src[srcOff + 2] * wt;
92
- a += src[srcOff + 3] * wt;
93
- }
94
- }
95
- }
96
- dst[dstOff] = r;
97
- dst[dstOff + 1] = g;
98
- dst[dstOff + 2] = b;
99
- dst[dstOff + 3] = a + alphaFac * (255 - a);
100
- }
101
- }
102
- return output;
103
- }
104
-
105
- convolute=(parent,kernel = [0, -1, 0, -1, 5, -1, 0, -1, 0], x1 = 0, y1 = 0, x2 = parent.element.width, y2 = parent.element.height)=>{
106
- if(kernel instanceof Matrix)kernel=kernel.arr.flat(1)
107
- var opaque = 1;
108
- var pixels = parent.ctx.getImageData(x1, y1, x2, y2);
109
- var side = Math.round(sqrt(kernel.length));
110
- var halfSide = Math.floor(side / 2);
111
- var src = pixels.data;
112
- var sw = pixels.width;
113
- var sh = pixels.height;
114
- // pad output by the convolution matrix
115
- var w = sw;
116
- var h = sh;
117
- var output = parent.ctx.createImageData(w, h);
118
- var dst = output.data;
119
- // go through the destination image pixels
120
- var alphaFac = opaque ? 1 : 0;
121
- for (var y = 0; y < h; y++) {
122
- for (var x = 0; x < w; x++) {
123
- var sy = y;
124
- var sx = x;
125
- var dstOff = (y * w + x) * 4;
126
- // calculate the weighed sum of the source image pixels that
127
- // fall under the convolution matrix
128
- var r = 0,
129
- g = 0,
130
- b = 0,
131
- a = 0;
132
- for (var cy = 0; cy < side; cy++) {
133
- for (var cx = 0; cx < side; cx++) {
134
- var scy = sy + cy - halfSide;
135
- var scx = sx + cx - halfSide;
136
- if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
137
- var srcOff = (scy * sw + scx) * 4;
138
- var wt = kernel[cy * side + cx];
139
- r += src[srcOff] * wt;
140
- g += src[srcOff + 1] * wt;
141
- b += src[srcOff + 2] * wt;
142
- a += src[srcOff + 3] * wt;
143
- }
144
- }
145
- }
146
- dst[dstOff] = r;
147
- dst[dstOff + 1] = g;
148
- dst[dstOff + 2] = b;
149
- dst[dstOff + 3] = a + alphaFac * (255 - a);
150
- }
151
- }
152
- return output;
153
- }
154
- const conv=(input,kernel,circular)=>{
155
- if(input instanceof Matrix || (input instanceof Array && input[0][0]))return conv2d(input,kernel,circular);
156
- return conv1d(input,kernel,circular)
157
- }
158
- const circularConv=(input,kernel)=>conv(input,kernel,true);
159
- const linearConv=(input,kernel)=>conv(input,kernel,false);
160
- const circularConv1d=(input,kernel)=>conv1d(input,kernel,true);
161
- const circularConv2d=(input,kernel)=>conv2d(input,kernel,true);
162
- const linearConv1d=(input,kernel)=>conv1d(input,kernel,false);
163
- const linearConv2d=(input,kernel)=>conv2d(input,kernel,false);
164
- export{
165
- conv1d,
166
- conv2d,
167
- conv,
168
- circularConv,
169
- linearConv,
170
- circularConv1d,
171
- linearConv1d,
172
- circularConv2d,
173
- linearConv2d,
174
- convolute
1
+ import { Matrix , matrix } from "../matrix/index.js";
2
+ import { sqrt } from "../functions/index.js";
3
+ const conv1d=(input, kernel , circular = true)=>{
4
+ const INPUT_LENGTH = input.length;
5
+ const KERNEL_LENGTH = kernel.length;
6
+ const output = [];
7
+ const LENGTH_OUT = circular ? Math.max(INPUT_LENGTH,KERNEL_LENGTH) : INPUT_LENGTH + KERNEL_LENGTH - 1;
8
+ for (let i = 0; i < LENGTH_OUT; i++) {
9
+ let sum = 0;
10
+ for (let j = 0; j < KERNEL_LENGTH; j++) {
11
+ const inputIndex = i + j - Math.floor(KERNEL_LENGTH / 2);
12
+ // Apply zero-padding for out-of-bounds indices
13
+ const inputValue = inputIndex >= 0 && inputIndex < INPUT_LENGTH
14
+ ? input[inputIndex]
15
+ : 0;
16
+ sum += inputValue * kernel[j];
17
+ }
18
+ output.push(sum);
19
+ }
20
+ return output;
21
+ }
22
+
23
+ const conv2d = (input, kernel, circular = true) => {
24
+ if(!(input instanceof Matrix)) input = matrix(input);
25
+ if(!(kernel instanceof Matrix)) kernel = matrix(kernel);
26
+ const INPUT_ROWS=input.rows;
27
+ const INPUT_COLS=input.cols;
28
+ const OUTPUT_ROWS = circular ? Math.max(input.rows,kernel.rows) : input.rows + kernel.rows-1;
29
+ const OUTPUT_COLS = circular ? Math.max(input.cols,kernel.cols) : input.cols + kernel.cols-1;
30
+ const KERNEL_SIZE = kernel.rows;
31
+ const output = [];
32
+ for (let i = 0; i < OUTPUT_ROWS ; i++) {
33
+ const row = [];
34
+ for (let j = 0; j < OUTPUT_COLS ; j++) {
35
+ let sum = 0;
36
+ for (let k = 0; k < KERNEL_SIZE; k++) {
37
+ for (let l = 0; l < KERNEL_SIZE; l++) {
38
+ const rowIndex = i + k - Math.floor(KERNEL_SIZE / 2);
39
+ const colIndex = j + l - Math.floor(KERNEL_SIZE / 2);
40
+ // Apply zero-padding for out-of-bounds indices
41
+ const inputValue = (rowIndex >= 0 && rowIndex < INPUT_ROWS &&
42
+ colIndex >= 0 && colIndex < INPUT_COLS)
43
+ ? input[rowIndex][colIndex]
44
+ : 0;
45
+ sum += inputValue * kernel[k][l];
46
+ }
47
+ }
48
+ row.push(sum);
49
+ }
50
+ output.push(row);
51
+ }
52
+ return output;
53
+ };
54
+
55
+ var convolute=(parent,kernel = [0, -1, 0, -1, 5, -1, 0, -1, 0], x1 = 0, y1 = 0, x2 = parent.element.width, y2 = parent.element.height)=>{
56
+ if(kernel instanceof Matrix)kernel=kernel.arr.flat(1)
57
+ var opaque = 1;
58
+ var pixels = parent.ctx.getImageData(x1, y1, x2, y2);
59
+ var side = Math.round(sqrt(kernel.length));
60
+ var halfSide = Math.floor(side / 2);
61
+ var src = pixels.data;
62
+ var sw = pixels.width;
63
+ var sh = pixels.height;
64
+ // pad output by the convolution matrix
65
+ var w = sw;
66
+ var h = sh;
67
+ var output = parent.ctx.createImageData(w, h);
68
+ var dst = output.data;
69
+ // go through the destination image pixels
70
+ var alphaFac = opaque ? 1 : 0;
71
+ for (var y = 0; y < h; y++) {
72
+ for (var x = 0; x < w; x++) {
73
+ var sy = y;
74
+ var sx = x;
75
+ var dstOff = (y * w + x) * 4;
76
+ // calculate the weighed sum of the source image pixels that
77
+ // fall under the convolution matrix
78
+ var r = 0,
79
+ g = 0,
80
+ b = 0,
81
+ a = 0;
82
+ for (var cy = 0; cy < side; cy++) {
83
+ for (var cx = 0; cx < side; cx++) {
84
+ var scy = sy + cy - halfSide;
85
+ var scx = sx + cx - halfSide;
86
+ if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
87
+ var srcOff = (scy * sw + scx) * 4;
88
+ var wt = kernel[cy * side + cx];
89
+ r += src[srcOff] * wt;
90
+ g += src[srcOff + 1] * wt;
91
+ b += src[srcOff + 2] * wt;
92
+ a += src[srcOff + 3] * wt;
93
+ }
94
+ }
95
+ }
96
+ dst[dstOff] = r;
97
+ dst[dstOff + 1] = g;
98
+ dst[dstOff + 2] = b;
99
+ dst[dstOff + 3] = a + alphaFac * (255 - a);
100
+ }
101
+ }
102
+ return output;
103
+ }
104
+
105
+ convolute=(parent,kernel = [0, -1, 0, -1, 5, -1, 0, -1, 0], x1 = 0, y1 = 0, x2 = parent.element.width, y2 = parent.element.height)=>{
106
+ if(kernel instanceof Matrix)kernel=kernel.arr.flat(1)
107
+ var opaque = 1;
108
+ var pixels = parent.ctx.getImageData(x1, y1, x2, y2);
109
+ var side = Math.round(sqrt(kernel.length));
110
+ var halfSide = Math.floor(side / 2);
111
+ var src = pixels.data;
112
+ var sw = pixels.width;
113
+ var sh = pixels.height;
114
+ // pad output by the convolution matrix
115
+ var w = sw;
116
+ var h = sh;
117
+ var output = parent.ctx.createImageData(w, h);
118
+ var dst = output.data;
119
+ // go through the destination image pixels
120
+ var alphaFac = opaque ? 1 : 0;
121
+ for (var y = 0; y < h; y++) {
122
+ for (var x = 0; x < w; x++) {
123
+ var sy = y;
124
+ var sx = x;
125
+ var dstOff = (y * w + x) * 4;
126
+ // calculate the weighed sum of the source image pixels that
127
+ // fall under the convolution matrix
128
+ var r = 0,
129
+ g = 0,
130
+ b = 0,
131
+ a = 0;
132
+ for (var cy = 0; cy < side; cy++) {
133
+ for (var cx = 0; cx < side; cx++) {
134
+ var scy = sy + cy - halfSide;
135
+ var scx = sx + cx - halfSide;
136
+ if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
137
+ var srcOff = (scy * sw + scx) * 4;
138
+ var wt = kernel[cy * side + cx];
139
+ r += src[srcOff] * wt;
140
+ g += src[srcOff + 1] * wt;
141
+ b += src[srcOff + 2] * wt;
142
+ a += src[srcOff + 3] * wt;
143
+ }
144
+ }
145
+ }
146
+ dst[dstOff] = r;
147
+ dst[dstOff + 1] = g;
148
+ dst[dstOff + 2] = b;
149
+ dst[dstOff + 3] = a + alphaFac * (255 - a);
150
+ }
151
+ }
152
+ return output;
153
+ }
154
+ const conv=(input,kernel,circular)=>{
155
+ if(input instanceof Matrix || (input instanceof Array && input[0][0]))return conv2d(input,kernel,circular);
156
+ return conv1d(input,kernel,circular)
157
+ }
158
+ const circularConv=(input,kernel)=>conv(input,kernel,true);
159
+ const linearConv=(input,kernel)=>conv(input,kernel,false);
160
+ const circularConv1d=(input,kernel)=>conv1d(input,kernel,true);
161
+ const circularConv2d=(input,kernel)=>conv2d(input,kernel,true);
162
+ const linearConv1d=(input,kernel)=>conv1d(input,kernel,false);
163
+ const linearConv2d=(input,kernel)=>conv2d(input,kernel,false);
164
+ export{
165
+ conv1d,
166
+ conv2d,
167
+ conv,
168
+ circularConv,
169
+ linearConv,
170
+ circularConv1d,
171
+ linearConv1d,
172
+ circularConv2d,
173
+ linearConv2d,
174
+ convolute
175
175
  }
@@ -1,55 +1,55 @@
1
- import { Complex , complex } from "../complex";
2
- import { PI } from "../const";
3
- import { cos , sin } from "../functions";
4
- const fft=x=>{
5
- const output = [];
6
- const N = x.length;
7
- if(!(x[0]instanceof Complex))x=x.map((n)=>complex(n,0));
8
- for (let k = 0; k < N; k++) {
9
- let re = 0,im=0;
10
- for (let n = 0; n < N; n++) {
11
- const phi = (2*PI * k * n) / N;
12
- re += x[n].a*cos(phi)+x[n].b*sin(phi);
13
- im += -x[n].a*sin(phi)+x[n].b*cos(phi);
14
- }
15
- re = re / N;
16
- im = im / N;
17
- output[k] = complex(re,im);
18
- }
19
- return {
20
- output,
21
- re:output.map(n=>n.a),
22
- im:output.map(n=>n.b),
23
- z:output.map(n=>n.z),
24
- phi:output.map(n=>n.phi)
25
- }
26
- }
27
- const ifft=x=>{
28
- const output = [];
29
- const N = x.length;
30
- if(!(x[0]instanceof Complex))x=x.map((n)=>complex(n,0));
31
- for (let k = 0; k < N; k++) {
32
- let re=0,im=0;
33
- for (let n = 0; n < N; n++) {
34
- const phi = (2*PI * k * n) / N;
35
- re += x[n].a*cos(phi)+x[n].b*sin(phi);
36
- im += x[n].a*sin(phi)+x[n].b*cos(phi);
37
- }
38
- re = re / N;
39
- im = im / N;
40
-
41
- output[k] = complex(re,im);
42
- }
43
- return {
44
- output,
45
- re:output.map(n=>n.a),
46
- im:output.map(n=>n.b),
47
- z:output.map(n=>n.z),
48
- phi:output.map(n=>n.phi)
49
- };
50
- }
51
-
52
- export{
53
- fft,
54
- ifft
1
+ import { Complex , complex } from "../complex";
2
+ import { PI } from "../const";
3
+ import { cos , sin } from "../functions";
4
+ const fft=x=>{
5
+ const output = [];
6
+ const N = x.length;
7
+ if(!(x[0]instanceof Complex))x=x.map((n)=>complex(n,0));
8
+ for (let k = 0; k < N; k++) {
9
+ let re = 0,im=0;
10
+ for (let n = 0; n < N; n++) {
11
+ const phi = (2*PI * k * n) / N;
12
+ re += x[n].a*cos(phi)+x[n].b*sin(phi);
13
+ im += -x[n].a*sin(phi)+x[n].b*cos(phi);
14
+ }
15
+ re = re / N;
16
+ im = im / N;
17
+ output[k] = complex(re,im);
18
+ }
19
+ return {
20
+ output,
21
+ re:output.map(n=>n.a),
22
+ im:output.map(n=>n.b),
23
+ z:output.map(n=>n.z),
24
+ phi:output.map(n=>n.phi)
25
+ }
26
+ }
27
+ const ifft=x=>{
28
+ const output = [];
29
+ const N = x.length;
30
+ if(!(x[0]instanceof Complex))x=x.map((n)=>complex(n,0));
31
+ for (let k = 0; k < N; k++) {
32
+ let re=0,im=0;
33
+ for (let n = 0; n < N; n++) {
34
+ const phi = (2*PI * k * n) / N;
35
+ re += x[n].a*cos(phi)+x[n].b*sin(phi);
36
+ im += x[n].a*sin(phi)+x[n].b*cos(phi);
37
+ }
38
+ re = re / N;
39
+ im = im / N;
40
+
41
+ output[k] = complex(re,im);
42
+ }
43
+ return {
44
+ output,
45
+ re:output.map(n=>n.a),
46
+ im:output.map(n=>n.b),
47
+ z:output.map(n=>n.z),
48
+ phi:output.map(n=>n.phi)
49
+ };
50
+ }
51
+
52
+ export{
53
+ fft,
54
+ ifft
55
55
  }
@@ -1,39 +1,39 @@
1
- import { complex } from "../complex/index.js";
2
- import {fft,ifft} from "./fft.js";
3
- // should be processed in other thread
4
- class Filter{
5
- constructor(input){
6
- this.input=input;
7
- this.input_fft=fft(this.input);
8
- this.output_fft=[]
9
- }
10
- // get length(){
11
- // return this.input.length;
12
- // }
13
- lowPass(fc){
14
- this.input_fft.output.forEach((n,i)=>{
15
- n=n.z<fc
16
- ? this.output_fft[i]=this.input_fft.output[i]
17
- : this.output_fft[i]=complex(0,0)
18
- })
19
- return ifft(this.output_fft).re;
20
- }
21
- highPass(fc){
22
- this.input_fft.output.forEach((n,i)=>{
23
- n=n.z>fc
24
- ? this.output_fft[i]=this.input_fft.output[i]
25
- : this.output_fft[i]=complex(0,0)
26
- })
27
- return ifft(this.output_fft).re;
28
- }
29
- bandePass(){
30
-
31
- }
32
- bandeCoupe(){
33
-
34
- }
35
- }
36
- const filter=input=>new Filter(input);
37
- export{
38
- filter
1
+ import { complex } from "../complex/index.js";
2
+ import {fft,ifft} from "./fft.js";
3
+ // should be processed in other thread
4
+ class Filter{
5
+ constructor(input){
6
+ this.input=input;
7
+ this.input_fft=fft(this.input);
8
+ this.output_fft=[]
9
+ }
10
+ // get length(){
11
+ // return this.input.length;
12
+ // }
13
+ lowPass(fc){
14
+ this.input_fft.output.forEach((n,i)=>{
15
+ n=n.z<fc
16
+ ? this.output_fft[i]=this.input_fft.output[i]
17
+ : this.output_fft[i]=complex(0,0)
18
+ })
19
+ return ifft(this.output_fft).re;
20
+ }
21
+ highPass(fc){
22
+ this.input_fft.output.forEach((n,i)=>{
23
+ n=n.z>fc
24
+ ? this.output_fft[i]=this.input_fft.output[i]
25
+ : this.output_fft[i]=complex(0,0)
26
+ })
27
+ return ifft(this.output_fft).re;
28
+ }
29
+ bandePass(){
30
+
31
+ }
32
+ bandeCoupe(){
33
+
34
+ }
35
+ }
36
+ const filter=input=>new Filter(input);
37
+ export{
38
+ filter
39
39
  }