x4js 1.6.4 → 2.0.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 (282) hide show
  1. package/README.md +3 -14
  2. package/lib/README.txt +3 -14
  3. package/lib/src/assets/house-light.svg +1 -0
  4. package/lib/src/assets/radio.svg +4 -0
  5. package/lib/src/components/base.scss +26 -0
  6. package/lib/src/components/boxes/boxes.module.scss +37 -0
  7. package/lib/src/components/boxes/boxes.ts +125 -0
  8. package/lib/src/components/btngroup/btngroup.module.scss +29 -0
  9. package/lib/src/components/btngroup/btngroup.ts +106 -0
  10. package/lib/src/components/button/button.module.scss +154 -0
  11. package/lib/src/components/button/button.ts +117 -0
  12. package/lib/src/components/calendar/calendar-check-sharp-light.svg +1 -0
  13. package/lib/src/components/calendar/calendar.module.scss +163 -0
  14. package/lib/src/{calendar.ts → components/calendar/calendar.ts} +81 -83
  15. package/lib/src/components/calendar/chevron-left-sharp-light.svg +1 -0
  16. package/lib/src/components/calendar/chevron-right-sharp-light.svg +1 -0
  17. package/lib/src/components/checkbox/check.svg +4 -0
  18. package/lib/src/components/checkbox/checkbox.module.scss +142 -0
  19. package/lib/src/components/checkbox/checkbox.ts +125 -0
  20. package/lib/src/components/colorinput/colorinput.module.scss +65 -0
  21. package/lib/src/components/colorinput/colorinput.ts +88 -0
  22. package/lib/src/components/colorinput/crosshairs-simple-sharp-light.svg +1 -0
  23. package/lib/src/components/colorpicker/colorpicker.module.scss +133 -0
  24. package/lib/src/components/colorpicker/colorpicker.ts +477 -0
  25. package/lib/src/components/combobox/combobox.module.scss +121 -0
  26. package/lib/src/components/combobox/combobox.ts +190 -0
  27. package/lib/src/components/combobox/updown.svg +4 -0
  28. package/lib/src/components/dialog/dialog.module.scss +71 -0
  29. package/lib/src/components/dialog/dialog.ts +91 -0
  30. package/lib/src/components/dialog/xmark-sharp-light.svg +1 -0
  31. package/lib/src/components/form/form.module.scss +34 -0
  32. package/lib/src/components/form/form.ts +36 -0
  33. package/lib/src/components/header/header.module.scss +40 -0
  34. package/lib/src/components/header/header.ts +124 -0
  35. package/lib/src/components/icon/icon.module.scss +30 -0
  36. package/lib/src/components/icon/icon.ts +134 -0
  37. package/lib/src/components/image/image.module.scss +21 -0
  38. package/lib/src/components/image/image.ts +67 -0
  39. package/lib/src/components/input/input.module.scss +69 -0
  40. package/lib/src/components/input/input.ts +274 -0
  41. package/lib/src/components/label/label.module.scss +52 -0
  42. package/lib/src/components/label/label.ts +55 -0
  43. package/lib/src/components/listbox/listbox.module.scss +103 -0
  44. package/lib/src/components/listbox/listbox.ts +427 -0
  45. package/lib/src/components/menu/caret-right-solid.svg +1 -0
  46. package/lib/src/components/menu/menu.module.scss +108 -0
  47. package/lib/src/components/menu/menu.ts +168 -0
  48. package/lib/src/components/messages/circle-exclamation.svg +1 -0
  49. package/lib/src/components/messages/messages.module.scss +47 -0
  50. package/lib/src/components/messages/messages.ts +64 -0
  51. package/lib/src/components/normalize.scss +386 -0
  52. package/lib/src/components/notification/circle-check-solid.svg +1 -0
  53. package/lib/src/components/notification/circle-exclamation-solid.svg +1 -0
  54. package/lib/src/components/notification/circle-notch-light.svg +1 -0
  55. package/lib/src/components/notification/notification.module.scss +82 -0
  56. package/lib/src/components/notification/notification.ts +108 -0
  57. package/lib/src/components/notification/xmark-sharp-light.svg +1 -0
  58. package/lib/src/components/panel/panel.module.scss +48 -0
  59. package/lib/src/components/panel/panel.ts +57 -0
  60. package/lib/src/components/popup/popup.module.scss +43 -0
  61. package/lib/src/components/popup/popup.ts +395 -0
  62. package/lib/src/components/progress/progress.module.scss +57 -0
  63. package/lib/src/components/progress/progress.ts +43 -0
  64. package/lib/src/components/rating/rating.module.scss +23 -0
  65. package/lib/src/components/rating/rating.ts +125 -0
  66. package/lib/src/components/rating/star-sharp-light.svg +1 -0
  67. package/lib/src/components/rating/star-sharp-solid.svg +1 -0
  68. package/lib/src/components/shared.scss +76 -0
  69. package/lib/src/components/sizers/sizer.module.scss +90 -0
  70. package/lib/src/components/sizers/sizer.ts +120 -0
  71. package/lib/src/components/slider/slider.module.scss +71 -0
  72. package/lib/src/components/slider/slider.ts +143 -0
  73. package/lib/src/components/switch/switch.module.scss +127 -0
  74. package/lib/src/components/switch/switch.ts +56 -0
  75. package/lib/src/components/tabs/tabs.module.scss +46 -0
  76. package/lib/src/components/tabs/tabs.ts +157 -0
  77. package/lib/src/components/textarea/textarea.module.scss +59 -0
  78. package/lib/src/components/textarea/textarea.ts +54 -0
  79. package/lib/src/components/textedit/textedit.module.scss +114 -0
  80. package/lib/src/components/textedit/textedit.ts +82 -0
  81. package/lib/src/components/themes.scss +77 -0
  82. package/lib/src/components/tooltips/circle-info-sharp-light.svg +1 -0
  83. package/lib/src/components/tooltips/tooltips.scss +51 -0
  84. package/lib/src/components/tooltips/tooltips.ts +103 -0
  85. package/lib/src/components/treeview/chevron-down-light.svg +1 -0
  86. package/lib/src/components/treeview/treeview.module.scss +116 -0
  87. package/lib/src/components/treeview/treeview.ts +403 -0
  88. package/lib/src/components/viewport/viewport.module.scss +25 -0
  89. package/lib/src/components/viewport/viewport.ts +38 -0
  90. package/lib/src/core/component.ts +979 -0
  91. package/lib/src/core/core_colors.ts +250 -0
  92. package/lib/src/{dom_events.ts → core/core_dom.ts} +195 -39
  93. package/lib/src/{drag_manager.ts → core/core_dragdrop.ts} +29 -44
  94. package/lib/src/core/core_element.ts +98 -0
  95. package/lib/src/core/core_events.ts +149 -0
  96. package/lib/src/{i18n.ts → core/core_i18n.ts} +43 -42
  97. package/lib/src/{router.ts → core/core_router.ts} +27 -40
  98. package/lib/src/core/core_styles.ts +215 -0
  99. package/lib/src/core/core_svg.ts +550 -0
  100. package/lib/src/core/core_tools.ts +673 -0
  101. package/lib/src/main.scss +21 -0
  102. package/lib/src/main.tsx +323 -0
  103. package/lib/src/x4.scss +19 -0
  104. package/lib/types/x4.d.ts +2624 -0
  105. package/package.json +67 -59
  106. package/scripts/build.mjs +351 -0
  107. package/scripts/prepack.mjs +15 -0
  108. package/src/assets/house-light.svg +1 -0
  109. package/src/assets/radio.svg +4 -0
  110. package/src/components/base.scss +26 -0
  111. package/src/components/boxes/boxes.module.scss +37 -0
  112. package/src/components/boxes/boxes.ts +125 -0
  113. package/src/components/btngroup/btngroup.module.scss +29 -0
  114. package/src/components/btngroup/btngroup.ts +106 -0
  115. package/src/components/button/button.module.scss +154 -0
  116. package/src/components/button/button.ts +117 -0
  117. package/src/components/calendar/calendar-check-sharp-light.svg +1 -0
  118. package/src/components/calendar/calendar.module.scss +163 -0
  119. package/src/components/calendar/calendar.ts +326 -0
  120. package/src/components/calendar/chevron-left-sharp-light.svg +1 -0
  121. package/src/components/calendar/chevron-right-sharp-light.svg +1 -0
  122. package/src/components/checkbox/check.svg +4 -0
  123. package/src/components/checkbox/checkbox.module.scss +142 -0
  124. package/src/components/checkbox/checkbox.ts +125 -0
  125. package/src/components/colorinput/colorinput.module.scss +65 -0
  126. package/src/components/colorinput/colorinput.ts +88 -0
  127. package/src/components/colorinput/crosshairs-simple-sharp-light.svg +1 -0
  128. package/src/components/colorpicker/colorpicker.module.scss +133 -0
  129. package/src/components/colorpicker/colorpicker.ts +477 -0
  130. package/src/components/combobox/combobox.module.scss +121 -0
  131. package/src/components/combobox/combobox.ts +190 -0
  132. package/src/components/combobox/updown.svg +4 -0
  133. package/src/components/dialog/dialog.module.scss +71 -0
  134. package/src/components/dialog/dialog.ts +91 -0
  135. package/src/components/dialog/xmark-sharp-light.svg +1 -0
  136. package/src/components/form/form.module.scss +34 -0
  137. package/src/components/form/form.ts +36 -0
  138. package/src/components/header/header.module.scss +40 -0
  139. package/src/components/header/header.ts +124 -0
  140. package/src/components/icon/icon.module.scss +30 -0
  141. package/src/components/icon/icon.ts +134 -0
  142. package/src/components/image/image.module.scss +21 -0
  143. package/src/components/image/image.ts +67 -0
  144. package/src/components/input/input.module.scss +69 -0
  145. package/src/components/input/input.ts +274 -0
  146. package/src/components/label/label.module.scss +52 -0
  147. package/src/components/label/label.ts +55 -0
  148. package/src/components/listbox/listbox.module.scss +103 -0
  149. package/src/components/listbox/listbox.ts +427 -0
  150. package/src/components/menu/caret-right-solid.svg +1 -0
  151. package/src/components/menu/menu.module.scss +108 -0
  152. package/src/components/menu/menu.ts +168 -0
  153. package/src/components/messages/circle-exclamation.svg +1 -0
  154. package/src/components/messages/messages.module.scss +47 -0
  155. package/src/components/messages/messages.ts +64 -0
  156. package/src/components/normalize.scss +386 -0
  157. package/src/components/notification/circle-check-solid.svg +1 -0
  158. package/src/components/notification/circle-exclamation-solid.svg +1 -0
  159. package/src/components/notification/circle-notch-light.svg +1 -0
  160. package/src/components/notification/notification.module.scss +82 -0
  161. package/src/components/notification/notification.ts +108 -0
  162. package/src/components/notification/xmark-sharp-light.svg +1 -0
  163. package/src/components/panel/panel.module.scss +48 -0
  164. package/src/components/panel/panel.ts +57 -0
  165. package/src/components/popup/popup.module.scss +43 -0
  166. package/src/components/popup/popup.ts +395 -0
  167. package/src/components/progress/progress.module.scss +57 -0
  168. package/src/components/progress/progress.ts +43 -0
  169. package/src/components/rating/rating.module.scss +23 -0
  170. package/src/components/rating/rating.ts +125 -0
  171. package/src/components/rating/star-sharp-light.svg +1 -0
  172. package/src/components/rating/star-sharp-solid.svg +1 -0
  173. package/src/components/shared.scss +76 -0
  174. package/src/components/sizers/sizer.module.scss +90 -0
  175. package/src/components/sizers/sizer.ts +120 -0
  176. package/src/components/slider/slider.module.scss +71 -0
  177. package/src/components/slider/slider.ts +143 -0
  178. package/src/components/switch/switch.module.scss +127 -0
  179. package/src/components/switch/switch.ts +56 -0
  180. package/src/components/tabs/tabs.module.scss +46 -0
  181. package/src/components/tabs/tabs.ts +157 -0
  182. package/src/components/textarea/textarea.module.scss +59 -0
  183. package/src/components/textarea/textarea.ts +54 -0
  184. package/src/components/textedit/textedit.module.scss +114 -0
  185. package/src/components/textedit/textedit.ts +82 -0
  186. package/src/components/themes.scss +77 -0
  187. package/src/components/tooltips/circle-info-sharp-light.svg +1 -0
  188. package/src/components/tooltips/tooltips.scss +51 -0
  189. package/src/components/tooltips/tooltips.ts +103 -0
  190. package/src/components/treeview/chevron-down-light.svg +1 -0
  191. package/src/components/treeview/treeview.module.scss +116 -0
  192. package/src/components/treeview/treeview.ts +403 -0
  193. package/src/components/viewport/viewport.module.scss +25 -0
  194. package/src/components/viewport/viewport.ts +38 -0
  195. package/src/core/component.ts +979 -0
  196. package/src/core/core_colors.ts +250 -0
  197. package/src/core/core_dom.ts +471 -0
  198. package/src/core/core_dragdrop.ts +201 -0
  199. package/src/core/core_element.ts +98 -0
  200. package/src/core/core_events.ts +149 -0
  201. package/src/core/core_i18n.ts +377 -0
  202. package/src/core/core_router.ts +221 -0
  203. package/src/core/core_styles.ts +215 -0
  204. package/src/core/core_svg.ts +550 -0
  205. package/src/core/core_tools.ts +673 -0
  206. package/src/main.scss +21 -0
  207. package/src/main.tsx +323 -0
  208. package/src/x4.scss +19 -0
  209. package/tsconfig.json +14 -0
  210. package/types/scss.d.ts +4 -0
  211. package/types/svg.d.ts +4 -0
  212. package/types/x4react.d.ts +9 -0
  213. package/lib/changelog.txt +0 -23
  214. package/lib/cjs/x4js.js +0 -39
  215. package/lib/cjs/x4js.js.map +0 -7
  216. package/lib/esm/x4js.mjs +0 -15972
  217. package/lib/esm/x4js.mjs.map +0 -7
  218. package/lib/licence.md +0 -21
  219. package/lib/src/MIT-license.md +0 -14
  220. package/lib/src/action.ts +0 -88
  221. package/lib/src/alpha.jpg +0 -0
  222. package/lib/src/app_sockets.ts +0 -81
  223. package/lib/src/application.ts +0 -262
  224. package/lib/src/autocomplete.ts +0 -232
  225. package/lib/src/base64.ts +0 -166
  226. package/lib/src/base_component.ts +0 -152
  227. package/lib/src/button.ts +0 -355
  228. package/lib/src/canvas.ts +0 -510
  229. package/lib/src/cardview.ts +0 -228
  230. package/lib/src/checkbox.ts +0 -188
  231. package/lib/src/color.ts +0 -752
  232. package/lib/src/colorpicker.ts +0 -1649
  233. package/lib/src/combobox.ts +0 -512
  234. package/lib/src/component.ts +0 -2367
  235. package/lib/src/copyright.txt +0 -27
  236. package/lib/src/datastore.ts +0 -1302
  237. package/lib/src/dialog.ts +0 -656
  238. package/lib/src/drawtext.ts +0 -355
  239. package/lib/src/fileupload.ts +0 -213
  240. package/lib/src/form.ts +0 -413
  241. package/lib/src/formatters.ts +0 -105
  242. package/lib/src/gridview.ts +0 -1185
  243. package/lib/src/icon.ts +0 -362
  244. package/lib/src/image.ts +0 -225
  245. package/lib/src/index.ts +0 -89
  246. package/lib/src/input.ts +0 -297
  247. package/lib/src/label.ts +0 -153
  248. package/lib/src/layout.ts +0 -442
  249. package/lib/src/link.ts +0 -86
  250. package/lib/src/listview.ts +0 -765
  251. package/lib/src/md5.ts +0 -438
  252. package/lib/src/menu.ts +0 -425
  253. package/lib/src/messagebox.ts +0 -224
  254. package/lib/src/panel.ts +0 -86
  255. package/lib/src/popup.ts +0 -494
  256. package/lib/src/property_editor.ts +0 -337
  257. package/lib/src/radiobtn.ts +0 -197
  258. package/lib/src/rating.ts +0 -135
  259. package/lib/src/request.ts +0 -300
  260. package/lib/src/settings.ts +0 -77
  261. package/lib/src/sidebarview.ts +0 -108
  262. package/lib/src/spreadsheet.ts +0 -1449
  263. package/lib/src/styles.ts +0 -343
  264. package/lib/src/svgcomponent.ts +0 -592
  265. package/lib/src/tabbar.ts +0 -151
  266. package/lib/src/tabview.ts +0 -110
  267. package/lib/src/textarea.ts +0 -235
  268. package/lib/src/textedit.ts +0 -533
  269. package/lib/src/toaster.ts +0 -80
  270. package/lib/src/tools.ts +0 -1473
  271. package/lib/src/tooltips.ts +0 -191
  272. package/lib/src/treeview.ts +0 -716
  273. package/lib/src/version.ts +0 -30
  274. package/lib/src/x4.less +0 -2242
  275. package/lib/src/x4dom.ts +0 -57
  276. package/lib/src/x4events.ts +0 -585
  277. package/lib/src/x4js.ts +0 -89
  278. package/lib/src/x4react.ts +0 -90
  279. package/lib/styles/x4.css +0 -1785
  280. package/lib/styles/x4.less +0 -2242
  281. package/lib/types/x4js.d.ts +0 -6728
  282. package/license.md +0 -21
package/lib/src/canvas.ts DELETED
@@ -1,510 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \/ / / _
4
- * \ / /_| |_
5
- * / \____ _|
6
- * /__/\__\ |_|
7
- *
8
- * @file canvas.ts
9
- * @author Etienne Cochard
10
- *
11
- * Copyright (c) 2019-2023 R-libre ingenierie
12
- *
13
- * Permission is hereby granted, free of charge, to any person obtaining a copy
14
- * of this software and associated documentation files (the "Software"), to deal
15
- * in the Software without restriction, including without limitation the rights
16
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
17
- * of the Software, and to permit persons to whom the Software is furnished to do so,
18
- * subject to the following conditions:
19
- * The above copyright notice and this permission notice shall be included in all copies
20
- * or substantial portions of the Software.
21
- *
22
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
23
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
24
- * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
- **/
29
-
30
- import { Component, CProps, CEventMap, html } from './component'
31
- import { BasicEvent, EventCallback } from './x4events'
32
-
33
- interface IPoint {
34
- x: number;
35
- y: number;
36
- }
37
-
38
- interface EvPaint extends BasicEvent {
39
- ctx: CanvasPainter;
40
- }
41
-
42
- function EvPaint(ctx: CanvasPainter) {
43
- return BasicEvent<EvPaint>({ ctx });
44
- }
45
-
46
- interface CanvasEventMap extends CEventMap {
47
- paint: EvPaint;
48
- }
49
-
50
- interface CanvasProps extends CProps<CanvasEventMap> {
51
- autoClear?: boolean;
52
- painter?: PaintHandler;
53
- paint: EventCallback<EvPaint>
54
- }
55
-
56
-
57
- // ============================================================================
58
- // [CANVAS]
59
- // ============================================================================
60
-
61
-
62
-
63
-
64
- export interface CanvasPainter extends CanvasRenderingContext2D {
65
- width: number;
66
- height: number;
67
-
68
- smoothLine(points: any[], path: CanvasPath, move: boolean): void;
69
- smoothLineEx(_points: any[], tension: number, numOfSeg: number, path: CanvasPath, move?: boolean, close?: boolean): void;
70
- line(x1: number, y1: number, x2: number, y2: number, color: string, lineWidth: number): void;
71
- roundRect(x: number, y: number, width: number, height: number, radius: number): void;
72
- calcTextSize(text: string, rounded: boolean): { width: number, height: number };
73
- setFontSize(fs: number): void;
74
- circle(x: number, y: number, radius: number): void;
75
- }
76
-
77
- function mkPainter(c2d: CanvasRenderingContext2D, w: number, h: number): CanvasPainter {
78
-
79
- let cp = c2d as CanvasPainter;
80
-
81
- cp.width = w;
82
- cp.height = h;
83
-
84
- cp.smoothLine = smoothLine;
85
- cp.smoothLineEx = smoothLineEx;
86
- cp.line = line;
87
- cp.roundRect = roundRect;
88
- cp.calcTextSize = calcTextSize;
89
- cp.setFontSize = setFontSize;
90
- cp.circle = circle;
91
-
92
- return cp;
93
- }
94
-
95
- function smoothLine( this: CanvasRenderingContext2D, points: any[], path: CanvasPath = null, move = true) {
96
- if (points.length < 2) {
97
- return;
98
- }
99
-
100
- if (!path) {
101
- path = this;
102
- }
103
-
104
- if (points.length == 2) {
105
- if (move !== false) {
106
- path.moveTo(points[0].x, points[0].y);
107
- }
108
- else {
109
- path.lineTo(points[0].x, points[0].y);
110
- }
111
-
112
- path.lineTo(points[1].x, points[1].y);
113
- return;
114
- }
115
-
116
- function midPointBtw(p1: IPoint, p2: IPoint ) {
117
- return {
118
- x: p1.x + (p2.x - p1.x) / 2,
119
- y: p1.y + (p2.y - p1.y) / 2
120
- };
121
- }
122
-
123
- function getQuadraticXY(t: number, sx: number, sy: number, cp1x: number, cp1y: number, ex: number, ey: number) : IPoint {
124
- return {
125
- x: (1 - t) * (1 - t) * sx + 2 * (1 - t) * t * cp1x + t * t * ex,
126
- y: (1 - t) * (1 - t) * sy + 2 * (1 - t) * t * cp1y + t * t * ey
127
- };
128
- }
129
-
130
- let p1 = points[0],
131
- p2 = points[1],
132
- p3 = p1;
133
-
134
- path.moveTo(p1.x, p1.y);
135
-
136
- for (let i = 1, len = points.length; i < len; i++) {
137
- // we pick the point between pi+1 & pi+2 as the
138
- // end point and p1 as our control point
139
- let midPoint = midPointBtw(p1, p2);
140
- //this.quadraticCurveTo(p1.x, p1.y, midPoint.x, midPoint.y);
141
- for (let i = 0; i < 8; i++) {
142
- let { x, y } = getQuadraticXY(i / 8, p3.x, p3.y, p1.x, p1.y, midPoint.x, midPoint.y);
143
- path.lineTo(x, y);
144
- }
145
-
146
- p1 = points[i];
147
- p2 = points[i + 1];
148
- p3 = midPoint;
149
- }
150
-
151
- // Draw last line as a straight line while
152
- // we wait for the next point to be able to calculate
153
- // the bezier control point
154
-
155
- path.lineTo(p1.x, p1.y);
156
- }
157
-
158
- function smoothLineEx(this: CanvasRenderingContext2D, _points: any[], tension: number = 0.5, numOfSeg: number = 10, path: CanvasPath = null, move = true, close = false) {
159
-
160
- let points = [];
161
-
162
- //pts = points.slice(0);
163
- for (let p = 0, pc = _points.length; p < pc; p++) {
164
- points.push(_points[p].x);
165
- points.push(_points[p].y);
166
- }
167
-
168
- let pts,
169
- i = 1,
170
- l = points.length,
171
- rPos = 0,
172
- rLen = (l - 2) * numOfSeg + 2 + (close ? 2 * numOfSeg : 0),
173
- res = new Float32Array(rLen),
174
- cache = new Float32Array((numOfSeg + 2) * 4),
175
- cachePtr = 4;
176
-
177
- pts = points.slice(0);
178
-
179
- if (close) {
180
- pts.unshift(points[l - 1]); // insert end point as first point
181
- pts.unshift(points[l - 2]);
182
- pts.push(points[0], points[1]); // first point as last point
183
- }
184
- else {
185
- pts.unshift(points[1]); // copy 1. point and insert at beginning
186
- pts.unshift(points[0]);
187
- pts.push(points[l - 2], points[l - 1]); // duplicate end-points
188
- }
189
-
190
- // cache inner-loop calculations as they are based on t alone
191
- cache[0] = 1; // 1,0,0,0
192
-
193
- for (; i < numOfSeg; i++) {
194
-
195
- var st = i / numOfSeg,
196
- st2 = st * st,
197
- st3 = st2 * st,
198
- st23 = st3 * 2,
199
- st32 = st2 * 3;
200
-
201
- cache[cachePtr++] = st23 - st32 + 1; // c1
202
- cache[cachePtr++] = st32 - st23; // c2
203
- cache[cachePtr++] = st3 - 2 * st2 + st; // c3
204
- cache[cachePtr++] = st3 - st2; // c4
205
- }
206
-
207
- cache[cachePtr] = 1; // 0,1,0,0
208
-
209
- // calc. points
210
- parse(pts, cache, l);
211
-
212
- if (close) {
213
- //l = points.length;
214
- pts = [];
215
- pts.push(points[l - 4], points[l - 3], points[l - 2], points[l - 1]); // second last and last
216
- pts.push(points[0], points[1], points[2], points[3]); // first and second
217
- parse(pts, cache, 4);
218
- }
219
-
220
- function parse(pts: number[], cache: Float32Array, l: number) {
221
-
222
- for (var i = 2, t; i < l; i += 2) {
223
-
224
- var pt1 = pts[i],
225
- pt2 = pts[i + 1],
226
- pt3 = pts[i + 2],
227
- pt4 = pts[i + 3],
228
-
229
- t1x = (pt3 - pts[i - 2]) * tension,
230
- t1y = (pt4 - pts[i - 1]) * tension,
231
- t2x = (pts[i + 4] - pt1) * tension,
232
- t2y = (pts[i + 5] - pt2) * tension;
233
-
234
- for (t = 0; t < numOfSeg; t++) {
235
-
236
- var c = t << 2, //t * 4;
237
-
238
- c1 = cache[c],
239
- c2 = cache[c + 1],
240
- c3 = cache[c + 2],
241
- c4 = cache[c + 3];
242
-
243
- res[rPos++] = c1 * pt1 + c2 * pt3 + c3 * t1x + c4 * t2x;
244
- res[rPos++] = c1 * pt2 + c2 * pt4 + c3 * t1y + c4 * t2y;
245
- }
246
- }
247
- }
248
-
249
- // add last point
250
- l = close ? 0 : points.length - 2;
251
- res[rPos++] = points[l];
252
- res[rPos] = points[l + 1];
253
-
254
- if (!path) {
255
- path = this;
256
- }
257
-
258
- // add lines to path
259
- for (let i = 0, l = res.length; i < l; i += 2) {
260
- if (i == 0 && move !== false) {
261
- path.moveTo(res[i], res[i + 1]);
262
- }
263
- else {
264
- path.lineTo(res[i], res[i + 1]);
265
- }
266
- }
267
- }
268
-
269
- function line(this: CanvasRenderingContext2D, x1: number, y1: number, x2: number, y2: number, color: string, lineWidth: number = 1) {
270
- this.save();
271
- this.beginPath();
272
- this.moveTo(x1, y1);
273
- this.lineTo(x2, y2);
274
- this.lineWidth = lineWidth;
275
- this.strokeStyle = color;
276
- this.stroke();
277
- this.restore();
278
- }
279
-
280
- function roundRect(this: CanvasRenderingContext2D, x: number, y: number, width: number, height: number, radius: number) {
281
- //this.beginPath( );
282
- this.moveTo(x + radius, y);
283
- this.lineTo(x + width - radius, y);
284
- this.quadraticCurveTo(x + width, y, x + width, y + radius);
285
- this.lineTo(x + width, y + height - radius);
286
- this.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
287
- this.lineTo(x + radius, y + height);
288
- this.quadraticCurveTo(x, y + height, x, y + height - radius);
289
- this.lineTo(x, y + radius);
290
- this.quadraticCurveTo(x, y, x + radius, y);
291
- this.closePath();
292
- }
293
-
294
- function calcTextSize( this: CanvasRenderingContext2D, text: string, rounded = false): { width: number, height: number } {
295
-
296
- let fh = this.measureText(text);
297
- let lh = fh.fontBoundingBoxAscent + fh.fontBoundingBoxDescent;
298
-
299
- if (rounded) {
300
- return { width: Math.round(fh.width), height: Math.round(lh) };
301
- }
302
- else {
303
- return { width: fh.width, height: lh };
304
- }
305
- }
306
-
307
- function setFontSize( this: CanvasRenderingContext2D, fs: number) {
308
- let fsize = Math.round(fs) + 'px';
309
- this.font = this.font.replace(/\d+px/, fsize);
310
- }
311
-
312
- function circle( this: CanvasRenderingContext2D, x: number, y: number, radius: number) {
313
- this.moveTo(x + radius, y);
314
- this.arc(x, y, radius, 0, Math.PI * 2);
315
- }
316
-
317
- type PaintHandler = (ctx: CanvasPainter) => any;
318
-
319
- /**
320
- *
321
- */
322
-
323
- //export class CanvasProps extends CProps
324
- //{
325
- // low level handlers
326
- //mousedown?: (ev: MouseEvent) => any;
327
- //mousemove?: (ev: MouseEvent) => any;
328
- //mouseup?: (ev: MouseEvent) => any;
329
- //mouseleave?: (ev: MouseEvent) => any;
330
- //mousewheel?: (ev: WheelEvent) => any;
331
- //click?: (ev: MouseEvent) => any;
332
- //dblclick?: (ev: MouseEvent) => any;
333
- //touchstart?: (ev: TouchEvent) => any;
334
- //touchmove?: (ev: TouchEvent) => any;
335
- //touchend?: (ev: TouchEvent) => any;
336
- //keydown?: (ev: KeyboardEvent) => any;
337
- //keyup?: (ev: KeyboardEvent) => any;
338
- //}
339
-
340
-
341
- /**
342
- * Standard Canvas
343
- */
344
-
345
- export class Canvas extends Component<CanvasProps, CanvasEventMap> {
346
-
347
- private m_iwidth: number = -1;
348
- private m_iheight: number = -1;
349
- private m_scale = 1.0;
350
- private m_canvas: Component;
351
-
352
- constructor(props: CanvasProps) {
353
- super(props);
354
-
355
- //if( props.mousedown ) { this.setDomEvent( 'mousedown', props.mousedown ); }
356
- //if( props.mousemove ) { this.setDomEvent( 'mousemove', props.mousemove ); }
357
- //if( props.mouseup ) { this.setDomEvent( 'mouseup', props.mouseup ); }
358
- //if( props.mousewheel ) { this.setDomEvent( 'wheel', props.mousewheel ); }
359
- //if( props.mouseleave ) { this.setDomEvent( 'mouseleave', props.mouseleave ); }
360
- //if( props.click ) { this.setDomEvent( 'click', props.click ); }
361
- //if( props.dblclick ) { this.setDomEvent( 'dblclick', props.dblclick ); }
362
- //if( props.touchstart ) { this.setDomEvent( 'touchstart', props.touchstart ); }
363
- //if( props.touchmove ) { this.setDomEvent( 'touchmove', props.touchmove ); }
364
- //if( props.touchend ) { this.setDomEvent( 'touchend', props.touchend ); }
365
- //if( props.keydown ) { this.setDomEvent( 'keydown', props.keydown ); this.setAttribute( 'tabindex', 0 ); }
366
- //if( props.keyup ) { this.setDomEvent( 'keyup', props.keyup ); this.setAttribute( 'tabindex', 0 ); }
367
- //if( props.paint ) { this.onPaint( props.paint ); }
368
-
369
- this.setDomEvent('sizechange', () => { this._paint(); })
370
- this.mapPropEvents( props, 'paint' );
371
- }
372
-
373
- /** @ignore */
374
- render() {
375
- this.m_iwidth = -1;
376
- this.m_iheight = -1;
377
- this.m_canvas = new Component({
378
- tag: 'canvas'
379
- });
380
-
381
- this.setContent( this.m_canvas );
382
- // this.redraw(10);
383
- }
384
-
385
- update(delay=0 ) {
386
- this.m_iheight = this.m_iwidth = -1;
387
- super.update( delay );
388
- }
389
-
390
- /**
391
- * scale the whole canvas
392
- */
393
-
394
- scale(scale: number) {
395
- this.m_scale = scale;
396
- this.m_iwidth = -1; // force recalc
397
- this.redraw();
398
- }
399
-
400
- /**
401
- * return the internal canvas
402
- */
403
- get canvas(): Component {
404
- return this.m_canvas;
405
- }
406
-
407
- /**
408
- * redraw the canvas (force a paint)
409
- */
410
-
411
- private $update_rep = 0;
412
- public redraw(wait?: number) {
413
-
414
- if (wait !== undefined) {
415
-
416
- if( ++this.$update_rep>=20 ) {
417
- this.stopTimer( 'update' );
418
- this._paint( );
419
- }
420
- else {
421
- this.startTimer( 'update', wait, false, () => this._paint() );
422
- }
423
- }
424
- else {
425
- this.stopTimer( 'update' );
426
- this._paint();
427
- }
428
- }
429
-
430
- /**
431
- *
432
- */
433
- private _paint() {
434
- this.$update_rep = 0;
435
-
436
- let dom = this.dom;
437
- if (!this.isUserVisible() ) {
438
- return;
439
- }
440
-
441
- let canvas = this.m_canvas.dom as HTMLCanvasElement,
442
- w = dom.clientWidth,
443
- h = dom.clientHeight;
444
-
445
- let ctx = <CanvasPainter>canvas.getContext('2d');
446
- if (w != this.m_iwidth || h != this.m_iheight) {
447
- // adjustment for HDPI
448
- let devicePixelRatio = window.devicePixelRatio || 1;
449
- let backingStoreRatio = (<any>ctx).webkitBackingStorePixelRatio ||
450
- (<any>ctx).mozBackingStorePixelRatio ||
451
- (<any>ctx).msBackingStorePixelRatio ||
452
- (<any>ctx).oBackingStorePixelRatio ||
453
- (<any>ctx).backingStorePixelRatio || 1;
454
-
455
- let canvas = this.canvas;
456
-
457
- if (devicePixelRatio !== backingStoreRatio || this.m_scale != 1.0) {
458
- let ratio = devicePixelRatio / backingStoreRatio,
459
- rw = w * ratio,
460
- rh = h * ratio;
461
-
462
- canvas.setAttribute('width', '' + rw);
463
- canvas.setAttribute('height', '' + rh);
464
- canvas.setStyleValue('width', w);
465
- canvas.setStyleValue('height', h);
466
-
467
- ratio *= this.m_scale;
468
- ctx.scale(ratio, ratio);
469
- }
470
- else {
471
- canvas.setAttribute('width', '' + w);
472
- canvas.setAttribute('height', '' + h);
473
- canvas.setStyleValue('width', w);
474
- canvas.setStyleValue('height', h);
475
- ctx.scale(1, 1);
476
- }
477
-
478
- this.m_iwidth = w;
479
- this.m_iheight = h;
480
- }
481
-
482
- if (w && h) {
483
-
484
- let cc = mkPainter(ctx, w, h);
485
-
486
- if (this.m_props.autoClear) {
487
- cc.clearRect(0, 0, w, h);
488
- }
489
-
490
- cc.save();
491
- cc.translate(-0.5, -0.5);
492
- this.paint(cc);
493
- cc.restore();
494
- }
495
- }
496
-
497
- protected paint(ctx: CanvasPainter) {
498
- try {
499
- if (this.m_props.painter) {
500
- this.m_props.painter(ctx);
501
- }
502
- else {
503
- this.emit('paint', EvPaint(ctx));
504
- }
505
- }
506
- catch (x) {
507
- console.assert(false, x);
508
- }
509
- }
510
- }