x4js 1.6.5 → 2.0.2

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 (292) hide show
  1. package/README.md +3 -14
  2. package/lib/README.txt +3 -14
  3. package/lib/esm/x4.css +1 -0
  4. package/lib/esm/x4.js +1 -0
  5. package/lib/src/assets/house-light.svg +1 -0
  6. package/lib/src/assets/radio.svg +4 -0
  7. package/lib/src/components/base.scss +26 -0
  8. package/lib/src/components/boxes/boxes.module.scss +37 -0
  9. package/lib/src/components/boxes/boxes.ts +125 -0
  10. package/lib/src/components/btngroup/btngroup.module.scss +29 -0
  11. package/lib/src/components/btngroup/btngroup.ts +106 -0
  12. package/lib/src/components/button/button.module.scss +154 -0
  13. package/lib/src/components/button/button.ts +117 -0
  14. package/lib/src/components/calendar/calendar-check-sharp-light.svg +1 -0
  15. package/lib/src/components/calendar/calendar.module.scss +163 -0
  16. package/lib/src/{calendar.ts → components/calendar/calendar.ts} +81 -83
  17. package/lib/src/components/calendar/chevron-left-sharp-light.svg +1 -0
  18. package/lib/src/components/calendar/chevron-right-sharp-light.svg +1 -0
  19. package/lib/src/components/checkbox/check.svg +4 -0
  20. package/lib/src/components/checkbox/checkbox.module.scss +142 -0
  21. package/lib/src/components/checkbox/checkbox.ts +125 -0
  22. package/lib/src/components/colorinput/colorinput.module.scss +65 -0
  23. package/lib/src/components/colorinput/colorinput.ts +88 -0
  24. package/lib/src/components/colorinput/crosshairs-simple-sharp-light.svg +1 -0
  25. package/lib/src/components/colorpicker/colorpicker.module.scss +133 -0
  26. package/lib/src/components/colorpicker/colorpicker.ts +477 -0
  27. package/lib/src/components/combobox/combobox.module.scss +121 -0
  28. package/lib/src/components/combobox/combobox.ts +190 -0
  29. package/lib/src/components/combobox/updown.svg +4 -0
  30. package/lib/src/components/dialog/dialog.module.scss +71 -0
  31. package/lib/src/components/dialog/dialog.ts +91 -0
  32. package/lib/src/components/dialog/xmark-sharp-light.svg +1 -0
  33. package/lib/src/components/form/form.module.scss +34 -0
  34. package/lib/src/components/form/form.ts +36 -0
  35. package/lib/src/components/header/header.module.scss +40 -0
  36. package/lib/src/components/header/header.ts +124 -0
  37. package/lib/src/components/icon/icon.module.scss +30 -0
  38. package/lib/src/components/icon/icon.ts +134 -0
  39. package/lib/src/components/image/image.module.scss +21 -0
  40. package/lib/src/components/image/image.ts +67 -0
  41. package/lib/src/components/input/input.module.scss +69 -0
  42. package/lib/src/components/input/input.ts +274 -0
  43. package/lib/src/components/label/label.module.scss +52 -0
  44. package/lib/src/components/label/label.ts +55 -0
  45. package/lib/src/components/listbox/listbox.module.scss +103 -0
  46. package/lib/src/components/listbox/listbox.ts +427 -0
  47. package/lib/src/components/menu/caret-right-solid.svg +1 -0
  48. package/lib/src/components/menu/menu.module.scss +108 -0
  49. package/lib/src/components/menu/menu.ts +168 -0
  50. package/lib/src/components/messages/circle-exclamation.svg +1 -0
  51. package/lib/src/components/messages/messages.module.scss +47 -0
  52. package/lib/src/components/messages/messages.ts +64 -0
  53. package/lib/src/components/normalize.scss +386 -0
  54. package/lib/src/components/notification/circle-check-solid.svg +1 -0
  55. package/lib/src/components/notification/circle-exclamation-solid.svg +1 -0
  56. package/lib/src/components/notification/circle-notch-light.svg +1 -0
  57. package/lib/src/components/notification/notification.module.scss +82 -0
  58. package/lib/src/components/notification/notification.ts +108 -0
  59. package/lib/src/components/notification/xmark-sharp-light.svg +1 -0
  60. package/lib/src/components/panel/panel.module.scss +48 -0
  61. package/lib/src/components/panel/panel.ts +57 -0
  62. package/lib/src/components/popup/popup.module.scss +43 -0
  63. package/lib/src/components/popup/popup.ts +395 -0
  64. package/lib/src/components/progress/progress.module.scss +57 -0
  65. package/lib/src/components/progress/progress.ts +43 -0
  66. package/lib/src/components/rating/rating.module.scss +23 -0
  67. package/lib/src/components/rating/rating.ts +125 -0
  68. package/lib/src/components/rating/star-sharp-light.svg +1 -0
  69. package/lib/src/components/rating/star-sharp-solid.svg +1 -0
  70. package/lib/src/components/shared.scss +76 -0
  71. package/lib/src/components/sizers/sizer.module.scss +90 -0
  72. package/lib/src/components/sizers/sizer.ts +120 -0
  73. package/lib/src/components/slider/slider.module.scss +71 -0
  74. package/lib/src/components/slider/slider.ts +143 -0
  75. package/lib/src/components/switch/switch.module.scss +127 -0
  76. package/lib/src/components/switch/switch.ts +56 -0
  77. package/lib/src/components/tabs/tabs.module.scss +46 -0
  78. package/lib/src/components/tabs/tabs.ts +157 -0
  79. package/lib/src/components/textarea/textarea.module.scss +59 -0
  80. package/lib/src/components/textarea/textarea.ts +54 -0
  81. package/lib/src/components/textedit/textedit.module.scss +114 -0
  82. package/lib/src/components/textedit/textedit.ts +82 -0
  83. package/lib/src/components/themes.scss +77 -0
  84. package/lib/src/components/tooltips/circle-info-sharp-light.svg +1 -0
  85. package/lib/src/components/tooltips/tooltips.scss +51 -0
  86. package/lib/src/components/tooltips/tooltips.ts +103 -0
  87. package/lib/src/components/treeview/chevron-down-light.svg +1 -0
  88. package/lib/src/components/treeview/treeview.module.scss +116 -0
  89. package/lib/src/components/treeview/treeview.ts +403 -0
  90. package/lib/src/components/viewport/viewport.module.scss +25 -0
  91. package/lib/src/components/viewport/viewport.ts +38 -0
  92. package/lib/src/core/component.ts +979 -0
  93. package/lib/src/core/core_colors.ts +250 -0
  94. package/lib/src/{dom_events.ts → core/core_dom.ts} +195 -39
  95. package/lib/src/{drag_manager.ts → core/core_dragdrop.ts} +29 -44
  96. package/lib/src/core/core_element.ts +98 -0
  97. package/lib/src/core/core_events.ts +149 -0
  98. package/lib/src/{i18n.ts → core/core_i18n.ts} +43 -42
  99. package/lib/src/{router.ts → core/core_router.ts} +27 -40
  100. package/lib/src/core/core_styles.ts +215 -0
  101. package/lib/src/core/core_svg.ts +550 -0
  102. package/lib/src/core/core_tools.ts +673 -0
  103. package/lib/src/demo/assets/house-light.svg +1 -0
  104. package/lib/src/demo/assets/radio.svg +4 -0
  105. package/lib/src/demo/index.html +12 -0
  106. package/lib/src/demo/main.scss +21 -0
  107. package/lib/src/demo/main.tsx +323 -0
  108. package/lib/src/main.scss +21 -0
  109. package/lib/src/main.tsx +323 -0
  110. package/lib/src/x4.scss +19 -0
  111. package/lib/src/x4.ts +60 -0
  112. package/lib/types/x4.d.ts +26548 -0
  113. package/package.json +68 -59
  114. package/scripts/build.mjs +351 -0
  115. package/scripts/prepack.mjs +43 -0
  116. package/src/components/base.scss +26 -0
  117. package/src/components/boxes/boxes.module.scss +37 -0
  118. package/src/components/boxes/boxes.ts +125 -0
  119. package/src/components/btngroup/btngroup.module.scss +29 -0
  120. package/src/components/btngroup/btngroup.ts +106 -0
  121. package/src/components/button/button.module.scss +154 -0
  122. package/src/components/button/button.ts +117 -0
  123. package/src/components/calendar/calendar-check-sharp-light.svg +1 -0
  124. package/src/components/calendar/calendar.module.scss +163 -0
  125. package/src/components/calendar/calendar.ts +326 -0
  126. package/src/components/calendar/chevron-left-sharp-light.svg +1 -0
  127. package/src/components/calendar/chevron-right-sharp-light.svg +1 -0
  128. package/src/components/checkbox/check.svg +4 -0
  129. package/src/components/checkbox/checkbox.module.scss +142 -0
  130. package/src/components/checkbox/checkbox.ts +125 -0
  131. package/src/components/colorinput/colorinput.module.scss +65 -0
  132. package/src/components/colorinput/colorinput.ts +88 -0
  133. package/src/components/colorinput/crosshairs-simple-sharp-light.svg +1 -0
  134. package/src/components/colorpicker/colorpicker.module.scss +133 -0
  135. package/src/components/colorpicker/colorpicker.ts +477 -0
  136. package/src/components/combobox/combobox.module.scss +121 -0
  137. package/src/components/combobox/combobox.ts +190 -0
  138. package/src/components/combobox/updown.svg +4 -0
  139. package/src/components/dialog/dialog.module.scss +71 -0
  140. package/src/components/dialog/dialog.ts +91 -0
  141. package/src/components/dialog/xmark-sharp-light.svg +1 -0
  142. package/src/components/form/form.module.scss +34 -0
  143. package/src/components/form/form.ts +36 -0
  144. package/src/components/header/header.module.scss +40 -0
  145. package/src/components/header/header.ts +124 -0
  146. package/src/components/icon/icon.module.scss +30 -0
  147. package/src/components/icon/icon.ts +134 -0
  148. package/src/components/image/image.module.scss +21 -0
  149. package/src/components/image/image.ts +67 -0
  150. package/src/components/input/input.module.scss +69 -0
  151. package/src/components/input/input.ts +274 -0
  152. package/src/components/label/label.module.scss +52 -0
  153. package/src/components/label/label.ts +55 -0
  154. package/src/components/listbox/listbox.module.scss +103 -0
  155. package/src/components/listbox/listbox.ts +427 -0
  156. package/src/components/menu/caret-right-solid.svg +1 -0
  157. package/src/components/menu/menu.module.scss +108 -0
  158. package/src/components/menu/menu.ts +168 -0
  159. package/src/components/messages/circle-exclamation.svg +1 -0
  160. package/src/components/messages/messages.module.scss +47 -0
  161. package/src/components/messages/messages.ts +64 -0
  162. package/src/components/normalize.scss +386 -0
  163. package/src/components/notification/circle-check-solid.svg +1 -0
  164. package/src/components/notification/circle-exclamation-solid.svg +1 -0
  165. package/src/components/notification/circle-notch-light.svg +1 -0
  166. package/src/components/notification/notification.module.scss +82 -0
  167. package/src/components/notification/notification.ts +108 -0
  168. package/src/components/notification/xmark-sharp-light.svg +1 -0
  169. package/src/components/panel/panel.module.scss +48 -0
  170. package/src/components/panel/panel.ts +57 -0
  171. package/src/components/popup/popup.module.scss +43 -0
  172. package/src/components/popup/popup.ts +395 -0
  173. package/src/components/progress/progress.module.scss +57 -0
  174. package/src/components/progress/progress.ts +43 -0
  175. package/src/components/rating/rating.module.scss +23 -0
  176. package/src/components/rating/rating.ts +125 -0
  177. package/src/components/rating/star-sharp-light.svg +1 -0
  178. package/src/components/rating/star-sharp-solid.svg +1 -0
  179. package/src/components/shared.scss +76 -0
  180. package/src/components/sizers/sizer.module.scss +90 -0
  181. package/src/components/sizers/sizer.ts +120 -0
  182. package/src/components/slider/slider.module.scss +71 -0
  183. package/src/components/slider/slider.ts +143 -0
  184. package/src/components/switch/switch.module.scss +127 -0
  185. package/src/components/switch/switch.ts +56 -0
  186. package/src/components/tabs/tabs.module.scss +46 -0
  187. package/src/components/tabs/tabs.ts +157 -0
  188. package/src/components/textarea/textarea.module.scss +59 -0
  189. package/src/components/textarea/textarea.ts +54 -0
  190. package/src/components/textedit/textedit.module.scss +114 -0
  191. package/src/components/textedit/textedit.ts +82 -0
  192. package/src/components/themes.scss +77 -0
  193. package/src/components/tooltips/circle-info-sharp-light.svg +1 -0
  194. package/src/components/tooltips/tooltips.scss +51 -0
  195. package/src/components/tooltips/tooltips.ts +103 -0
  196. package/src/components/treeview/chevron-down-light.svg +1 -0
  197. package/src/components/treeview/treeview.module.scss +116 -0
  198. package/src/components/treeview/treeview.ts +403 -0
  199. package/src/components/viewport/viewport.module.scss +25 -0
  200. package/src/components/viewport/viewport.ts +38 -0
  201. package/src/core/component.ts +979 -0
  202. package/src/core/core_colors.ts +250 -0
  203. package/src/core/core_dom.ts +471 -0
  204. package/src/core/core_dragdrop.ts +201 -0
  205. package/src/core/core_element.ts +98 -0
  206. package/src/core/core_events.ts +149 -0
  207. package/src/core/core_i18n.ts +377 -0
  208. package/src/core/core_router.ts +221 -0
  209. package/src/core/core_styles.ts +215 -0
  210. package/src/core/core_svg.ts +550 -0
  211. package/src/core/core_tools.ts +673 -0
  212. package/src/demo/assets/house-light.svg +1 -0
  213. package/src/demo/assets/radio.svg +4 -0
  214. package/src/demo/index.html +12 -0
  215. package/src/demo/main.scss +21 -0
  216. package/src/demo/main.tsx +323 -0
  217. package/src/x4.scss +19 -0
  218. package/src/x4.ts +60 -0
  219. package/tsconfig.json +14 -0
  220. package/types/scss.d.ts +4 -0
  221. package/types/svg.d.ts +4 -0
  222. package/types/x4react.d.ts +9 -0
  223. package/lib/changelog.txt +0 -23
  224. package/lib/cjs/x4js.js +0 -39
  225. package/lib/cjs/x4js.js.map +0 -7
  226. package/lib/esm/x4js.mjs +0 -15972
  227. package/lib/esm/x4js.mjs.map +0 -7
  228. package/lib/licence.md +0 -21
  229. package/lib/src/MIT-license.md +0 -14
  230. package/lib/src/action.ts +0 -88
  231. package/lib/src/alpha.jpg +0 -0
  232. package/lib/src/app_sockets.ts +0 -81
  233. package/lib/src/application.ts +0 -262
  234. package/lib/src/autocomplete.ts +0 -232
  235. package/lib/src/base64.ts +0 -166
  236. package/lib/src/base_component.ts +0 -152
  237. package/lib/src/button.ts +0 -355
  238. package/lib/src/canvas.ts +0 -510
  239. package/lib/src/cardview.ts +0 -228
  240. package/lib/src/checkbox.ts +0 -188
  241. package/lib/src/color.ts +0 -752
  242. package/lib/src/colorpicker.ts +0 -1649
  243. package/lib/src/combobox.ts +0 -512
  244. package/lib/src/component.ts +0 -2367
  245. package/lib/src/copyright.txt +0 -27
  246. package/lib/src/datastore.ts +0 -1302
  247. package/lib/src/dialog.ts +0 -656
  248. package/lib/src/drawtext.ts +0 -355
  249. package/lib/src/fileupload.ts +0 -213
  250. package/lib/src/form.ts +0 -413
  251. package/lib/src/formatters.ts +0 -105
  252. package/lib/src/gridview.ts +0 -1185
  253. package/lib/src/icon.ts +0 -362
  254. package/lib/src/image.ts +0 -225
  255. package/lib/src/index.ts +0 -89
  256. package/lib/src/input.ts +0 -297
  257. package/lib/src/label.ts +0 -153
  258. package/lib/src/layout.ts +0 -442
  259. package/lib/src/link.ts +0 -86
  260. package/lib/src/listview.ts +0 -765
  261. package/lib/src/md5.ts +0 -438
  262. package/lib/src/menu.ts +0 -425
  263. package/lib/src/messagebox.ts +0 -224
  264. package/lib/src/panel.ts +0 -86
  265. package/lib/src/popup.ts +0 -494
  266. package/lib/src/property_editor.ts +0 -337
  267. package/lib/src/radiobtn.ts +0 -197
  268. package/lib/src/rating.ts +0 -135
  269. package/lib/src/request.ts +0 -300
  270. package/lib/src/settings.ts +0 -77
  271. package/lib/src/sidebarview.ts +0 -108
  272. package/lib/src/spreadsheet.ts +0 -1449
  273. package/lib/src/styles.ts +0 -343
  274. package/lib/src/svgcomponent.ts +0 -592
  275. package/lib/src/tabbar.ts +0 -151
  276. package/lib/src/tabview.ts +0 -110
  277. package/lib/src/textarea.ts +0 -235
  278. package/lib/src/textedit.ts +0 -533
  279. package/lib/src/toaster.ts +0 -80
  280. package/lib/src/tools.ts +0 -1473
  281. package/lib/src/tooltips.ts +0 -191
  282. package/lib/src/treeview.ts +0 -716
  283. package/lib/src/version.ts +0 -30
  284. package/lib/src/x4.less +0 -2242
  285. package/lib/src/x4dom.ts +0 -57
  286. package/lib/src/x4events.ts +0 -585
  287. package/lib/src/x4js.ts +0 -89
  288. package/lib/src/x4react.ts +0 -90
  289. package/lib/styles/x4.css +0 -1785
  290. package/lib/styles/x4.less +0 -2242
  291. package/lib/types/x4js.d.ts +0 -6728
  292. package/license.md +0 -21
package/lib/src/icon.ts DELETED
@@ -1,362 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \/ / / _
4
- * \ / /_| |_
5
- * / \____ _|
6
- * /__/\__\ |_|
7
- *
8
- * @file icon.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 } from './component'
31
- import { Stylesheet } from './styles'
32
- import { HtmlString, isString } from './tools';
33
- import { BasicEvent, EventMap, EvSource } from './x4events';
34
-
35
- // ============================================================================
36
- // [ICON]
37
- // ============================================================================
38
-
39
- /**
40
- * iconID can be:
41
- * - "url( <path to image> )" ex: "url(my/path/to/my/image.svg)"
42
- * - "var( <css variable> )"
43
- * - "cls( <font class> )"
44
- * - "char( <character> )" ex: "font-char( \uf00d )"
45
- */
46
-
47
- export type IconID = string | number;
48
-
49
- export interface IconProps extends CProps {
50
- icon: IconID;
51
- size?: number;
52
- }
53
-
54
- export interface EvLoaded extends BasicEvent {
55
- url: string;
56
- svg: string;
57
- }
58
-
59
- export function EvLoaded( url: string, svg: string, context = null ) {
60
- return BasicEvent<EvLoaded>({ url, svg, context });
61
- }
62
-
63
- interface LoadingEventMap extends EventMap {
64
- loaded: EvLoaded;
65
- }
66
-
67
- function trimQuotes( str:string ): string {
68
- const l = str.length;
69
-
70
- //chrome
71
- if( str[0]=='"' && str[l-1]=='"' ) {
72
- str = str.substring( 1, l-1 )
73
- str = str.replaceAll( '\\"', "'" );
74
- return str;
75
- }
76
-
77
- //firefox
78
- if( str[0]=="'" && str[l-1]=="'" ) {
79
- str = str.substring( 1, l-1 )
80
- return str;
81
- }
82
-
83
- return str;
84
- }
85
-
86
- class Loader extends EvSource<LoadingEventMap> {
87
- svgs: Map<string,string>;
88
-
89
- constructor( ) {
90
- super( );
91
- this.svgs = new Map( );
92
- }
93
-
94
- load( url: string ) {
95
- if( this.svgs.has(url) ) {
96
- const svg = this.svgs.get( url );
97
- if( svg ) {
98
- //console.log( 'cached=', url );
99
- this.signal( 'loaded', EvLoaded(url,svg) );
100
- }
101
- }
102
- else {
103
- // mark it as loading
104
- this.svgs.set( url, null );
105
-
106
- // then start loading
107
- const _load = async ( url ) => {
108
-
109
- // shortcut
110
- if( url.substring(0,24)=="data:image/svg+xml;utf8,") {
111
- const svg = url.substring(24);
112
- this.svgs.set( url, svg );
113
- this.signal( 'loaded', EvLoaded(url,svg) );
114
- }
115
- else {
116
- const r = await fetch( url );
117
- if( r.ok ) {
118
- const svg = await r.text();
119
- // check response, must be svg
120
- //TODO: find better
121
- if (!svg.startsWith("<svg") && !svg.startsWith('<?xml') ) {
122
- console.error( "svg loading error (svg files must start with <svg... ): ", svg );
123
- this.signal( 'loaded', EvLoaded(url,"") );
124
- }
125
- else {
126
- this.svgs.set( url, svg );
127
- this.signal( 'loaded', EvLoaded(url,svg) );
128
- }
129
- }
130
- }
131
- }
132
-
133
- _load( url );
134
- }
135
- }
136
- }
137
-
138
- const svgLoader = new Loader( );
139
-
140
-
141
- /**
142
- * standard icon
143
- */
144
- export class Icon extends Component<IconProps>
145
- {
146
- private m_icon: string;
147
- private m_iconName: IconID;
148
-
149
- constructor( props: IconProps | string ) {
150
-
151
- if( isString(props) ) {
152
- super( { icon: props } );
153
- }
154
- else {
155
- super( props );
156
- }
157
-
158
- this._setIcon( this.m_props.icon, false );
159
- if( this.m_props.size ) {
160
- this.setStyleValue( 'fontSize', this.m_props.size );
161
- }
162
- }
163
-
164
- private _setIcon(icon: IconID, remove_old: boolean) {
165
-
166
- if( !icon ) {
167
- this.m_iconName = '';
168
- return;
169
- }
170
-
171
- this.removeClass( '@svg' );
172
-
173
- // todo: deprecated
174
- let name, url: string;
175
- if (typeof (icon) === 'number') {
176
- icon = icon.toString(16);
177
- name = icon;
178
- console.error( "deprecation error: invalid icon name" );
179
- }
180
- else {
181
- // var( <var-name> )
182
- //
183
- // in the .css
184
- // --------------------------
185
- // :root {
186
- // --chevron-up: data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M0 96C0 78.33 14.33 64 32 64H416C433.7 64 448 78.33 448 96C448 113.7 433.7 128 416 128H32C14.33 128 0 113.7 0 96z"/></svg>';
187
- // }
188
- //
189
- // var( "--chevron-up" )
190
- const reVar = /\s*var\s*\(\s*(.+)\s*\)\s*/gi;
191
- let match_var = reVar.exec( icon );
192
- while( match_var ) {
193
- const varname = match_var[1].trim( );
194
- icon = (Stylesheet.getVar(varname) as string).trim( );
195
- if (icon == '' || icon === undefined) {
196
- console.error( `icon: unable to find variable named '${varname}'` );
197
- return;
198
- }
199
- else {
200
- icon = trimQuotes( icon );
201
- }
202
-
203
- match_var = reVar.exec( icon );
204
- }
205
-
206
- // <svg ...>
207
- if( icon.startsWith('<svg') ) {
208
- this._setSVG( 'data:image/svg+xml;utf8,'+icon);
209
- return;
210
- }
211
-
212
- // svg( <svg-filename> ) -> svg( "mysvgfile.svg" )
213
- // <svg-filename>.svg -> "mysvgfile.svg"
214
-
215
- const reSvg = /\s*svg\s*\(\s*(.+)\s*\)\s*/gi;
216
- const reSvg2 = /(.*\.svg)$/gi;
217
-
218
- let match_svg = reSvg.exec( icon ) || reSvg2.exec(icon);
219
- if( match_svg ) {
220
- const url = match_svg[1].trim( );
221
- this._setSVG( url );
222
- return;
223
- }
224
-
225
- // data( <direct> )
226
- // data( "data:image/svg+xml;utf8,<svg...></svg>" )
227
-
228
- const reSvg4 = /^\s*(data\:image\/.+)\s*$/gi;
229
- let match_dta = reSvg4.exec( icon );
230
- if( match_dta ) {
231
- this._setSVG( match_dta[1] );
232
- return;
233
- }
234
-
235
- // cls( "fas fa-angle-up" )
236
- //
237
- const reCls = /\s*cls\s*\(\s*(.+)\s*\)\s*/gi;
238
- let match_cls = reCls.exec( icon );
239
- if( match_cls ) {
240
- const classes = match_cls[1].trim( );
241
- this.addClass( classes );
242
- return;
243
- }
244
-
245
- // url( "www.google.com" )
246
- //
247
- const reUrl = /\s*url\s*\(\s*(.+)\s*\)\s*/gi;
248
- let match_url = reUrl.exec( icon );
249
- if( match_url ) {
250
- url = trimQuotes( match_url[1].trim( ) );
251
- // this value is escaped
252
- url = url.replaceAll( "\\", "" );
253
- this._setSVG( url );
254
- return;
255
- }
256
-
257
- // url( "www.google.com" )
258
- //
259
- const reChar = /\s*font-char\s*\(\s*(.+)\s*\)\s*/gi;
260
- let match_char = reChar.exec( icon );
261
- if( match_char ) {
262
- this.removeClass( '@svg-icon' );
263
- this.setContent( match_char[1], false );
264
- return;
265
- }
266
-
267
- else {
268
- // todo: deprecated
269
- console.error( "deprecation error: invalid icon name" );
270
-
271
- name = icon;
272
- icon = Stylesheet.getVar( 'icon-'+icon ) as string;
273
-
274
- if( icon=='' || icon===undefined ) {
275
- // name your icon 'icon-xxx'
276
- // ex:
277
- // :root { --icon-zoom-p: f00e; }
278
- icon = '0';
279
- }
280
- }
281
- }
282
-
283
- this.m_iconName = name;
284
- if( this.m_icon===icon ) {
285
- return;
286
- }
287
-
288
- let css = Component.getCss(),
289
- rulename: string;
290
-
291
- if (remove_old && this.m_icon) {
292
- rulename = 'icon-' + name;
293
- this.removeClass(rulename);
294
- }
295
-
296
- // generate dynamic css icon rule
297
- rulename = 'icon-' + name;
298
-
299
- if( Icon.icon_cache[rulename]===undefined ) {
300
- Icon.icon_cache[rulename] = true;
301
-
302
- let rule: string;
303
-
304
- if( url ) {
305
- rule = `display: block; content: ' '; background-image: url(${url}); background-size: contain; width: 100%; height: 100%; background-repeat: no-repeat; color: white;`;
306
- }
307
- else {
308
- rule = `content: "\\${icon}";`;
309
- }
310
-
311
- css.setRule(rulename, `.${rulename}::before {${rule}}`);
312
- }
313
-
314
- this.addClass(rulename);
315
- this.m_icon = icon;
316
- }
317
-
318
- /**
319
- * change the icon
320
- * @param icon - new icon
321
- */
322
-
323
- public set icon( icon: IconID ) {
324
- this._setIcon( icon, true );
325
- }
326
-
327
- public get icon( ) : IconID {
328
- return this.m_iconName;
329
- }
330
-
331
- private _setSVG( url: string ) {
332
-
333
- const set = ( ev: EvLoaded ) => {
334
- //console.log( 'set=', ev.url, 'url=', url );
335
-
336
- if( ev.url==url ) {
337
- this.addClass( '@svg-icon' );
338
- this.setContent( HtmlString.from(ev.svg), false );
339
- svgLoader.off( 'loaded', set );
340
- }
341
- }
342
-
343
- svgLoader.on( 'loaded', set );
344
- svgLoader.load( url );
345
- }
346
-
347
- /**
348
- * todo: try to extract viewbox
349
- */
350
-
351
- private _setSVGPath( pth: string ) {
352
- this.addClass( '@svg-icon' );
353
- this.setContent( HtmlString.from(`<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor"><path d="${pth}/></svg>`), false );
354
- }
355
-
356
- /**
357
- *
358
- */
359
-
360
- private static icon_cache = [];
361
- }
362
-
package/lib/src/image.ts DELETED
@@ -1,225 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \/ / / _
4
- * \ / /_| |_
5
- * / \____ _|
6
- * /__/\__\ |_|
7
- *
8
- * @file image.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 { x4document } from './x4dom'
31
- import { Component, CProps, html } from './component'
32
-
33
- interface LazyLoad {
34
- el: Component;
35
- src: string;
36
- }
37
-
38
- // ============================================================================
39
- // [IMAGE]
40
- // ============================================================================
41
-
42
- export interface ImageProps extends CProps
43
- {
44
- src: string;
45
- alt?: string;
46
- lazy?: boolean; // mark image as lazy loading
47
- alignment?: 'fill' | 'contain' | 'cover' | 'scale-down' | 'none';
48
- overlays?: Component[];
49
- }
50
-
51
- const emptyImageSrc = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
52
-
53
- function _isStaticImage( src: string ) {
54
- return src.substring(0,5)=='data:';
55
- }
56
-
57
-
58
-
59
- /**
60
- * Standard image class
61
- */
62
- export class Image extends Component<ImageProps>
63
- {
64
- protected m_created: boolean;
65
- protected m_lazysrc: string; // expected
66
- private m_img: Component;
67
-
68
- constructor(props: ImageProps) {
69
- super(props);
70
-
71
- this.m_created = false;
72
-
73
- this.m_props.lazy = props.lazy===false ? false : true;
74
- this.m_props.alt = props.alt;
75
-
76
- if( props.lazy!==false ) {
77
- this.m_lazysrc = props.src;
78
- props.src = emptyImageSrc;
79
- }
80
-
81
- this.setDomEvent( 'create', ( ) => {
82
- if( props.lazy ) {
83
- this.setImage( this.m_lazysrc, true );
84
- }
85
- });
86
- }
87
-
88
- /** @ignore */
89
- render( ) {
90
- let mp = this.m_props;
91
-
92
- this.m_img = new Component( {
93
- tag: 'img',
94
- attrs: {
95
- draggable: false,
96
- alt: mp.alt ?? '',
97
- decoding: mp.lazy ? 'async' : undefined,
98
- },
99
- style: {
100
- objectFit: mp.alignment ? mp.alignment : undefined
101
- }
102
- });
103
-
104
- if( mp.overlays ) {
105
- mp.overlays.forEach( x => x.addClass('@fit') );
106
- this.setContent( [this.m_img,...mp.overlays] );
107
- }
108
- else {
109
- this.setContent( this.m_img );
110
- }
111
- }
112
-
113
- /**
114
- * change the image
115
- * @param src - image path
116
- */
117
-
118
- public setImage( src: string, force?: boolean ) {
119
-
120
- if( !src ) {
121
- src = emptyImageSrc;
122
- this.addClass( 'empty' );
123
- }
124
- else {
125
- this.removeClass( 'empty' );
126
- }
127
-
128
- if( !this.m_props.lazy ) {
129
- this.m_props.src = src;
130
- this.m_lazysrc = src;
131
-
132
- if( this.m_img.dom ) {
133
- this.m_img.dom.setAttribute( 'src', src );
134
- }
135
- }
136
- else if( force || this.m_lazysrc!=src ) {
137
- if( _isStaticImage(src) ) {
138
- // not to download -> direct display
139
- this.m_props.src = src;
140
- this.m_lazysrc = src;
141
-
142
- if( this.m_img.dom ) {
143
- this.m_img.dom.setAttribute( 'src', this.m_props.src );
144
- }
145
- }
146
- else {
147
- // clear current image while waiting
148
- this.m_props.src = emptyImageSrc;
149
- if( this.m_img.dom ) {
150
- this.m_img.dom.setAttribute( 'src', this.m_props.src );
151
- }
152
-
153
- this.m_lazysrc = src;
154
- if( this.dom ) {
155
- this._update_image( );
156
- }
157
- }
158
- }
159
- }
160
-
161
- private _update_image( ) {
162
-
163
- console.assert( !!this.dom );
164
-
165
- if( this.m_lazysrc && !_isStaticImage(this.m_lazysrc) ) {
166
- // we do not push Components in a static array...
167
- Image.lazy_images_waiting.push( {
168
- el: this,
169
- src: this.m_lazysrc
170
- } );
171
-
172
- if( Image.lazy_image_timer===undefined ) {
173
- Image.lazy_image_timer = setInterval( Image.lazyWatch as TimerHandler, 10 );
174
- }
175
- }
176
- }
177
-
178
- private static lazy_images_waiting: LazyLoad[] = [];
179
- private static lazy_image_timer: number = undefined;
180
-
181
- private static lazyWatch( ) {
182
-
183
- let newList = [];
184
- let done = 0;
185
-
186
- Image.lazy_images_waiting.forEach( ( lazy ) => {
187
-
188
- let dom = lazy.el.dom,
189
- src = lazy.src;
190
-
191
- // skip deleted elements
192
- if( !dom || dom.offsetParent === null ) {
193
- // do not append to newList
194
- return;
195
- }
196
-
197
- let rc = dom.getBoundingClientRect();
198
-
199
- // if it is visible & inserted inside the document
200
- if( !done && dom.offsetParent!==null &&
201
- rc.bottom >= 0 && rc.right >= 0 &&
202
- rc.top <= (window.innerHeight || x4document.documentElement.clientHeight) &&
203
- rc.left <= (window.innerWidth || x4document.documentElement.clientWidth) ) {
204
-
205
- // ok, we load the image
206
- let img = <HTMLElement>dom.firstChild;
207
- img.setAttribute( 'src', src );
208
- lazy.el.removeClass( 'empty' );
209
- done++;
210
- }
211
- else {
212
- // still not visible: may be next time
213
- newList.push( lazy );
214
- }
215
- } );
216
-
217
- Image.lazy_images_waiting = newList;
218
-
219
- // no more elements to watch...
220
- if( newList.length==0 ) {
221
- clearInterval( Image.lazy_image_timer );
222
- Image.lazy_image_timer = undefined;
223
- }
224
- }
225
- }
package/lib/src/index.ts DELETED
@@ -1,89 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \_/ / / _
4
- * \ / /_| |_
5
- * / _ \____ _|
6
- * /__/ \__\ |_|
7
- *
8
- * @file index.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
- export * from "./application"
31
- export * from "./autocomplete"
32
- export * from "./base_component"
33
- //export * from "./base64"
34
- export * from "./button"
35
- export * from "./calendar"
36
- export * from "./canvas"
37
- export * from "./cardview"
38
- export * from "./checkbox"
39
- export * from "./color"
40
- export * from "./colorpicker"
41
- export * from "./combobox"
42
- export * from "./component"
43
- export * from "./datastore"
44
- export * from "./dialog"
45
- export * from "./dom_events"
46
- export * from "./drag_manager"
47
- export * from "./drawtext"
48
- export * from "./fileupload"
49
- export * from "./form"
50
- export * from "./formatters"
51
- export * from "./gridview"
52
- export * from "./i18n"
53
- export * from "./icon"
54
- export * from "./image"
55
- export * from "./input"
56
- export * from "./label"
57
- export * from "./layout"
58
- export * from "./link"
59
- export * from "./listview"
60
- export * from "./md5"
61
- export * from "./menu"
62
- export * from "./messagebox"
63
- export * from "./panel"
64
- export * from "./popup"
65
- export * from "./property_editor"
66
- export * from "./radiobtn"
67
- export * from "./rating"
68
- export * from "./request"
69
- export * from "./router"
70
- export * from "./settings"
71
- export * from "./sidebarview"
72
- //export * from "./smartedit"
73
- export * from "./spreadsheet"
74
- export * from "./styles"
75
- export * from "./svgcomponent"
76
- export * from "./tabbar"
77
- export * from "./tabview"
78
- export * from "./textarea"
79
- export * from "./textedit"
80
- //export * from "./texthiliter"
81
- export * from "./toaster"
82
- export * from "./tools"
83
- export * from "./tooltips"
84
- export * from "./treeview"
85
- export * from "./x4events"
86
- export * from "./x4react"
87
- export * from "./app_sockets"
88
-
89
- export * from "./version"