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.
- package/README.md +3 -14
- package/lib/README.txt +3 -14
- package/lib/esm/x4.css +1 -0
- package/lib/esm/x4.js +1 -0
- package/lib/src/assets/house-light.svg +1 -0
- package/lib/src/assets/radio.svg +4 -0
- package/lib/src/components/base.scss +26 -0
- package/lib/src/components/boxes/boxes.module.scss +37 -0
- package/lib/src/components/boxes/boxes.ts +125 -0
- package/lib/src/components/btngroup/btngroup.module.scss +29 -0
- package/lib/src/components/btngroup/btngroup.ts +106 -0
- package/lib/src/components/button/button.module.scss +154 -0
- package/lib/src/components/button/button.ts +117 -0
- package/lib/src/components/calendar/calendar-check-sharp-light.svg +1 -0
- package/lib/src/components/calendar/calendar.module.scss +163 -0
- package/lib/src/{calendar.ts → components/calendar/calendar.ts} +81 -83
- package/lib/src/components/calendar/chevron-left-sharp-light.svg +1 -0
- package/lib/src/components/calendar/chevron-right-sharp-light.svg +1 -0
- package/lib/src/components/checkbox/check.svg +4 -0
- package/lib/src/components/checkbox/checkbox.module.scss +142 -0
- package/lib/src/components/checkbox/checkbox.ts +125 -0
- package/lib/src/components/colorinput/colorinput.module.scss +65 -0
- package/lib/src/components/colorinput/colorinput.ts +88 -0
- package/lib/src/components/colorinput/crosshairs-simple-sharp-light.svg +1 -0
- package/lib/src/components/colorpicker/colorpicker.module.scss +133 -0
- package/lib/src/components/colorpicker/colorpicker.ts +477 -0
- package/lib/src/components/combobox/combobox.module.scss +121 -0
- package/lib/src/components/combobox/combobox.ts +190 -0
- package/lib/src/components/combobox/updown.svg +4 -0
- package/lib/src/components/dialog/dialog.module.scss +71 -0
- package/lib/src/components/dialog/dialog.ts +91 -0
- package/lib/src/components/dialog/xmark-sharp-light.svg +1 -0
- package/lib/src/components/form/form.module.scss +34 -0
- package/lib/src/components/form/form.ts +36 -0
- package/lib/src/components/header/header.module.scss +40 -0
- package/lib/src/components/header/header.ts +124 -0
- package/lib/src/components/icon/icon.module.scss +30 -0
- package/lib/src/components/icon/icon.ts +134 -0
- package/lib/src/components/image/image.module.scss +21 -0
- package/lib/src/components/image/image.ts +67 -0
- package/lib/src/components/input/input.module.scss +69 -0
- package/lib/src/components/input/input.ts +274 -0
- package/lib/src/components/label/label.module.scss +52 -0
- package/lib/src/components/label/label.ts +55 -0
- package/lib/src/components/listbox/listbox.module.scss +103 -0
- package/lib/src/components/listbox/listbox.ts +427 -0
- package/lib/src/components/menu/caret-right-solid.svg +1 -0
- package/lib/src/components/menu/menu.module.scss +108 -0
- package/lib/src/components/menu/menu.ts +168 -0
- package/lib/src/components/messages/circle-exclamation.svg +1 -0
- package/lib/src/components/messages/messages.module.scss +47 -0
- package/lib/src/components/messages/messages.ts +64 -0
- package/lib/src/components/normalize.scss +386 -0
- package/lib/src/components/notification/circle-check-solid.svg +1 -0
- package/lib/src/components/notification/circle-exclamation-solid.svg +1 -0
- package/lib/src/components/notification/circle-notch-light.svg +1 -0
- package/lib/src/components/notification/notification.module.scss +82 -0
- package/lib/src/components/notification/notification.ts +108 -0
- package/lib/src/components/notification/xmark-sharp-light.svg +1 -0
- package/lib/src/components/panel/panel.module.scss +48 -0
- package/lib/src/components/panel/panel.ts +57 -0
- package/lib/src/components/popup/popup.module.scss +43 -0
- package/lib/src/components/popup/popup.ts +395 -0
- package/lib/src/components/progress/progress.module.scss +57 -0
- package/lib/src/components/progress/progress.ts +43 -0
- package/lib/src/components/rating/rating.module.scss +23 -0
- package/lib/src/components/rating/rating.ts +125 -0
- package/lib/src/components/rating/star-sharp-light.svg +1 -0
- package/lib/src/components/rating/star-sharp-solid.svg +1 -0
- package/lib/src/components/shared.scss +76 -0
- package/lib/src/components/sizers/sizer.module.scss +90 -0
- package/lib/src/components/sizers/sizer.ts +120 -0
- package/lib/src/components/slider/slider.module.scss +71 -0
- package/lib/src/components/slider/slider.ts +143 -0
- package/lib/src/components/switch/switch.module.scss +127 -0
- package/lib/src/components/switch/switch.ts +56 -0
- package/lib/src/components/tabs/tabs.module.scss +46 -0
- package/lib/src/components/tabs/tabs.ts +157 -0
- package/lib/src/components/textarea/textarea.module.scss +59 -0
- package/lib/src/components/textarea/textarea.ts +54 -0
- package/lib/src/components/textedit/textedit.module.scss +114 -0
- package/lib/src/components/textedit/textedit.ts +82 -0
- package/lib/src/components/themes.scss +77 -0
- package/lib/src/components/tooltips/circle-info-sharp-light.svg +1 -0
- package/lib/src/components/tooltips/tooltips.scss +51 -0
- package/lib/src/components/tooltips/tooltips.ts +103 -0
- package/lib/src/components/treeview/chevron-down-light.svg +1 -0
- package/lib/src/components/treeview/treeview.module.scss +116 -0
- package/lib/src/components/treeview/treeview.ts +403 -0
- package/lib/src/components/viewport/viewport.module.scss +25 -0
- package/lib/src/components/viewport/viewport.ts +38 -0
- package/lib/src/core/component.ts +979 -0
- package/lib/src/core/core_colors.ts +250 -0
- package/lib/src/{dom_events.ts → core/core_dom.ts} +195 -39
- package/lib/src/{drag_manager.ts → core/core_dragdrop.ts} +29 -44
- package/lib/src/core/core_element.ts +98 -0
- package/lib/src/core/core_events.ts +149 -0
- package/lib/src/{i18n.ts → core/core_i18n.ts} +43 -42
- package/lib/src/{router.ts → core/core_router.ts} +27 -40
- package/lib/src/core/core_styles.ts +215 -0
- package/lib/src/core/core_svg.ts +550 -0
- package/lib/src/core/core_tools.ts +673 -0
- package/lib/src/demo/assets/house-light.svg +1 -0
- package/lib/src/demo/assets/radio.svg +4 -0
- package/lib/src/demo/index.html +12 -0
- package/lib/src/demo/main.scss +21 -0
- package/lib/src/demo/main.tsx +323 -0
- package/lib/src/main.scss +21 -0
- package/lib/src/main.tsx +323 -0
- package/lib/src/x4.scss +19 -0
- package/lib/src/x4.ts +60 -0
- package/lib/types/x4.d.ts +26548 -0
- package/package.json +68 -59
- package/scripts/build.mjs +351 -0
- package/scripts/prepack.mjs +43 -0
- package/src/components/base.scss +26 -0
- package/src/components/boxes/boxes.module.scss +37 -0
- package/src/components/boxes/boxes.ts +125 -0
- package/src/components/btngroup/btngroup.module.scss +29 -0
- package/src/components/btngroup/btngroup.ts +106 -0
- package/src/components/button/button.module.scss +154 -0
- package/src/components/button/button.ts +117 -0
- package/src/components/calendar/calendar-check-sharp-light.svg +1 -0
- package/src/components/calendar/calendar.module.scss +163 -0
- package/src/components/calendar/calendar.ts +326 -0
- package/src/components/calendar/chevron-left-sharp-light.svg +1 -0
- package/src/components/calendar/chevron-right-sharp-light.svg +1 -0
- package/src/components/checkbox/check.svg +4 -0
- package/src/components/checkbox/checkbox.module.scss +142 -0
- package/src/components/checkbox/checkbox.ts +125 -0
- package/src/components/colorinput/colorinput.module.scss +65 -0
- package/src/components/colorinput/colorinput.ts +88 -0
- package/src/components/colorinput/crosshairs-simple-sharp-light.svg +1 -0
- package/src/components/colorpicker/colorpicker.module.scss +133 -0
- package/src/components/colorpicker/colorpicker.ts +477 -0
- package/src/components/combobox/combobox.module.scss +121 -0
- package/src/components/combobox/combobox.ts +190 -0
- package/src/components/combobox/updown.svg +4 -0
- package/src/components/dialog/dialog.module.scss +71 -0
- package/src/components/dialog/dialog.ts +91 -0
- package/src/components/dialog/xmark-sharp-light.svg +1 -0
- package/src/components/form/form.module.scss +34 -0
- package/src/components/form/form.ts +36 -0
- package/src/components/header/header.module.scss +40 -0
- package/src/components/header/header.ts +124 -0
- package/src/components/icon/icon.module.scss +30 -0
- package/src/components/icon/icon.ts +134 -0
- package/src/components/image/image.module.scss +21 -0
- package/src/components/image/image.ts +67 -0
- package/src/components/input/input.module.scss +69 -0
- package/src/components/input/input.ts +274 -0
- package/src/components/label/label.module.scss +52 -0
- package/src/components/label/label.ts +55 -0
- package/src/components/listbox/listbox.module.scss +103 -0
- package/src/components/listbox/listbox.ts +427 -0
- package/src/components/menu/caret-right-solid.svg +1 -0
- package/src/components/menu/menu.module.scss +108 -0
- package/src/components/menu/menu.ts +168 -0
- package/src/components/messages/circle-exclamation.svg +1 -0
- package/src/components/messages/messages.module.scss +47 -0
- package/src/components/messages/messages.ts +64 -0
- package/src/components/normalize.scss +386 -0
- package/src/components/notification/circle-check-solid.svg +1 -0
- package/src/components/notification/circle-exclamation-solid.svg +1 -0
- package/src/components/notification/circle-notch-light.svg +1 -0
- package/src/components/notification/notification.module.scss +82 -0
- package/src/components/notification/notification.ts +108 -0
- package/src/components/notification/xmark-sharp-light.svg +1 -0
- package/src/components/panel/panel.module.scss +48 -0
- package/src/components/panel/panel.ts +57 -0
- package/src/components/popup/popup.module.scss +43 -0
- package/src/components/popup/popup.ts +395 -0
- package/src/components/progress/progress.module.scss +57 -0
- package/src/components/progress/progress.ts +43 -0
- package/src/components/rating/rating.module.scss +23 -0
- package/src/components/rating/rating.ts +125 -0
- package/src/components/rating/star-sharp-light.svg +1 -0
- package/src/components/rating/star-sharp-solid.svg +1 -0
- package/src/components/shared.scss +76 -0
- package/src/components/sizers/sizer.module.scss +90 -0
- package/src/components/sizers/sizer.ts +120 -0
- package/src/components/slider/slider.module.scss +71 -0
- package/src/components/slider/slider.ts +143 -0
- package/src/components/switch/switch.module.scss +127 -0
- package/src/components/switch/switch.ts +56 -0
- package/src/components/tabs/tabs.module.scss +46 -0
- package/src/components/tabs/tabs.ts +157 -0
- package/src/components/textarea/textarea.module.scss +59 -0
- package/src/components/textarea/textarea.ts +54 -0
- package/src/components/textedit/textedit.module.scss +114 -0
- package/src/components/textedit/textedit.ts +82 -0
- package/src/components/themes.scss +77 -0
- package/src/components/tooltips/circle-info-sharp-light.svg +1 -0
- package/src/components/tooltips/tooltips.scss +51 -0
- package/src/components/tooltips/tooltips.ts +103 -0
- package/src/components/treeview/chevron-down-light.svg +1 -0
- package/src/components/treeview/treeview.module.scss +116 -0
- package/src/components/treeview/treeview.ts +403 -0
- package/src/components/viewport/viewport.module.scss +25 -0
- package/src/components/viewport/viewport.ts +38 -0
- package/src/core/component.ts +979 -0
- package/src/core/core_colors.ts +250 -0
- package/src/core/core_dom.ts +471 -0
- package/src/core/core_dragdrop.ts +201 -0
- package/src/core/core_element.ts +98 -0
- package/src/core/core_events.ts +149 -0
- package/src/core/core_i18n.ts +377 -0
- package/src/core/core_router.ts +221 -0
- package/src/core/core_styles.ts +215 -0
- package/src/core/core_svg.ts +550 -0
- package/src/core/core_tools.ts +673 -0
- package/src/demo/assets/house-light.svg +1 -0
- package/src/demo/assets/radio.svg +4 -0
- package/src/demo/index.html +12 -0
- package/src/demo/main.scss +21 -0
- package/src/demo/main.tsx +323 -0
- package/src/x4.scss +19 -0
- package/src/x4.ts +60 -0
- package/tsconfig.json +14 -0
- package/types/scss.d.ts +4 -0
- package/types/svg.d.ts +4 -0
- package/types/x4react.d.ts +9 -0
- package/lib/changelog.txt +0 -23
- package/lib/cjs/x4js.js +0 -39
- package/lib/cjs/x4js.js.map +0 -7
- package/lib/esm/x4js.mjs +0 -15972
- package/lib/esm/x4js.mjs.map +0 -7
- package/lib/licence.md +0 -21
- package/lib/src/MIT-license.md +0 -14
- package/lib/src/action.ts +0 -88
- package/lib/src/alpha.jpg +0 -0
- package/lib/src/app_sockets.ts +0 -81
- package/lib/src/application.ts +0 -262
- package/lib/src/autocomplete.ts +0 -232
- package/lib/src/base64.ts +0 -166
- package/lib/src/base_component.ts +0 -152
- package/lib/src/button.ts +0 -355
- package/lib/src/canvas.ts +0 -510
- package/lib/src/cardview.ts +0 -228
- package/lib/src/checkbox.ts +0 -188
- package/lib/src/color.ts +0 -752
- package/lib/src/colorpicker.ts +0 -1649
- package/lib/src/combobox.ts +0 -512
- package/lib/src/component.ts +0 -2367
- package/lib/src/copyright.txt +0 -27
- package/lib/src/datastore.ts +0 -1302
- package/lib/src/dialog.ts +0 -656
- package/lib/src/drawtext.ts +0 -355
- package/lib/src/fileupload.ts +0 -213
- package/lib/src/form.ts +0 -413
- package/lib/src/formatters.ts +0 -105
- package/lib/src/gridview.ts +0 -1185
- package/lib/src/icon.ts +0 -362
- package/lib/src/image.ts +0 -225
- package/lib/src/index.ts +0 -89
- package/lib/src/input.ts +0 -297
- package/lib/src/label.ts +0 -153
- package/lib/src/layout.ts +0 -442
- package/lib/src/link.ts +0 -86
- package/lib/src/listview.ts +0 -765
- package/lib/src/md5.ts +0 -438
- package/lib/src/menu.ts +0 -425
- package/lib/src/messagebox.ts +0 -224
- package/lib/src/panel.ts +0 -86
- package/lib/src/popup.ts +0 -494
- package/lib/src/property_editor.ts +0 -337
- package/lib/src/radiobtn.ts +0 -197
- package/lib/src/rating.ts +0 -135
- package/lib/src/request.ts +0 -300
- package/lib/src/settings.ts +0 -77
- package/lib/src/sidebarview.ts +0 -108
- package/lib/src/spreadsheet.ts +0 -1449
- package/lib/src/styles.ts +0 -343
- package/lib/src/svgcomponent.ts +0 -592
- package/lib/src/tabbar.ts +0 -151
- package/lib/src/tabview.ts +0 -110
- package/lib/src/textarea.ts +0 -235
- package/lib/src/textedit.ts +0 -533
- package/lib/src/toaster.ts +0 -80
- package/lib/src/tools.ts +0 -1473
- package/lib/src/tooltips.ts +0 -191
- package/lib/src/treeview.ts +0 -716
- package/lib/src/version.ts +0 -30
- package/lib/src/x4.less +0 -2242
- package/lib/src/x4dom.ts +0 -57
- package/lib/src/x4events.ts +0 -585
- package/lib/src/x4js.ts +0 -89
- package/lib/src/x4react.ts +0 -90
- package/lib/styles/x4.css +0 -1785
- package/lib/styles/x4.less +0 -2242
- package/lib/types/x4js.d.ts +0 -6728
- package/license.md +0 -21
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file core_colors.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
*
|
|
11
|
+
* @copyright (c) 2024 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* Use of this source code is governed by an MIT-style license
|
|
14
|
+
* that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
|
15
|
+
**/
|
|
16
|
+
|
|
17
|
+
import { clamp, isString } from './core_tools';
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
function hx( v: number ) {
|
|
21
|
+
const hex = v.toString( 16 );
|
|
22
|
+
return hex.padStart( 2, '0' );
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function round( v: number ) {
|
|
26
|
+
return Math.round(v);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
export interface Rgb {
|
|
31
|
+
red: number;
|
|
32
|
+
green: number;
|
|
33
|
+
blue: number;
|
|
34
|
+
alpha: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface Hsv {
|
|
38
|
+
hue: number;
|
|
39
|
+
saturation: number;
|
|
40
|
+
value: number;
|
|
41
|
+
alpha: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
export class Color {
|
|
46
|
+
|
|
47
|
+
private rgb: [red:number,green:number,blue:number,alpha:number] = [0,0,0,1];
|
|
48
|
+
private invalid = false;
|
|
49
|
+
|
|
50
|
+
constructor( value: string );
|
|
51
|
+
constructor( r: number, g: number, b: number, a?: number );
|
|
52
|
+
constructor( ...args: any[] ) {
|
|
53
|
+
if( isString(args[0] ) ) {
|
|
54
|
+
this.setValue( args[0] );
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.setRgb( args[0], args[1], args[2], args[3] );
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* accepts:
|
|
63
|
+
* #aaa
|
|
64
|
+
* #ababab
|
|
65
|
+
* #ababab55
|
|
66
|
+
* rgb(a,b,c)
|
|
67
|
+
* rgba(a,b,c,d)
|
|
68
|
+
* var( --color-5 )
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
setValue( value: string ): this {
|
|
72
|
+
|
|
73
|
+
this.invalid = false;
|
|
74
|
+
|
|
75
|
+
if( value.length==4 && /#[0-9a-fA-F]{3}/.test(value) ) {
|
|
76
|
+
const r1 = parseInt( value[1], 16 );
|
|
77
|
+
const g1 = parseInt( value[2], 16 );
|
|
78
|
+
const b1 = parseInt( value[3], 16 );
|
|
79
|
+
return this.setRgb( r1<<4|r1, g1<<4|g1, b1<<4|b1, 1.0 );
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if( value.length==7 && /#[0-9a-fA-F]{6}/.test(value) ) {
|
|
83
|
+
const r1 = parseInt( value[1], 16 );
|
|
84
|
+
const r2 = parseInt( value[2], 16 );
|
|
85
|
+
const g1 = parseInt( value[3], 16 );
|
|
86
|
+
const g2 = parseInt( value[4], 16 );
|
|
87
|
+
const b1 = parseInt( value[5], 16 );
|
|
88
|
+
const b2 = parseInt( value[6], 16 );
|
|
89
|
+
return this.setRgb( r1<<4|r2, g1<<4|g2, b1<<4|b2, 1.0 );
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if( value.length==9 && /#[0-9a-fA-F]{8}/.test(value) ) {
|
|
93
|
+
const r1 = parseInt( value[1], 16 );
|
|
94
|
+
const r2 = parseInt( value[2], 16 );
|
|
95
|
+
const g1 = parseInt( value[3], 16 );
|
|
96
|
+
const g2 = parseInt( value[4], 16 );
|
|
97
|
+
const b1 = parseInt( value[5], 16 );
|
|
98
|
+
const b2 = parseInt( value[6], 16 );
|
|
99
|
+
const a1 = parseInt( value[7], 16 );
|
|
100
|
+
const a2 = parseInt( value[8], 16 );
|
|
101
|
+
return this.setRgb( r1<<4|r2, g1<<4|g2, b1<<4|b2, (a1<<4|a2) / 255.0 );
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if( value.startsWith('rgba') ) {
|
|
105
|
+
const re = /rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*((\d+)|(\d*\.\d+)|(\.\d+))\s*\)/;
|
|
106
|
+
const m = re.exec( value );
|
|
107
|
+
if( m ) {
|
|
108
|
+
return this.setRgb( parseInt(m[1]), parseInt(m[2]), parseInt(m[3]), parseFloat(m[4]) );
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else if( value.startsWith('rgb') ) {
|
|
112
|
+
const re = /rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/;
|
|
113
|
+
const m = re.exec( value );
|
|
114
|
+
if( m ) {
|
|
115
|
+
return this.setRgb( parseInt(m[1]), parseInt(m[2]), parseInt(m[3]), 1.0 );
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else if( value.startsWith("var") ) {
|
|
119
|
+
const re = /var\s*\(([^)]*)\)/;
|
|
120
|
+
const m = re.exec( value );
|
|
121
|
+
if( m ) {
|
|
122
|
+
const expr = m[1].trim( );
|
|
123
|
+
const style = getComputedStyle( document.documentElement );
|
|
124
|
+
const value = style.getPropertyValue( expr );
|
|
125
|
+
return this.setValue( value );
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
this.invalid = true;
|
|
130
|
+
return this.setRgb(255,0,0,1);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
setHsv( h: number, s: number, v: number, a = 1.0 ): this {
|
|
134
|
+
|
|
135
|
+
let i = Math.min(5, Math.floor(h * 6)),
|
|
136
|
+
f = h * 6 - i,
|
|
137
|
+
p = v * (1 - s),
|
|
138
|
+
q = v * (1 - f * s),
|
|
139
|
+
t = v * (1 - (1 - f) * s);
|
|
140
|
+
|
|
141
|
+
let R, G, B;
|
|
142
|
+
|
|
143
|
+
switch (i) {
|
|
144
|
+
case 0:
|
|
145
|
+
R = v;
|
|
146
|
+
G = t;
|
|
147
|
+
B = p;
|
|
148
|
+
break;
|
|
149
|
+
case 1:
|
|
150
|
+
R = q;
|
|
151
|
+
G = v;
|
|
152
|
+
B = p;
|
|
153
|
+
break;
|
|
154
|
+
case 2:
|
|
155
|
+
R = p;
|
|
156
|
+
G = v;
|
|
157
|
+
B = t;
|
|
158
|
+
break;
|
|
159
|
+
case 3:
|
|
160
|
+
R = p;
|
|
161
|
+
G = q;
|
|
162
|
+
B = v;
|
|
163
|
+
break;
|
|
164
|
+
case 4:
|
|
165
|
+
R = t;
|
|
166
|
+
G = p;
|
|
167
|
+
B = v;
|
|
168
|
+
break;
|
|
169
|
+
case 5:
|
|
170
|
+
R = v;
|
|
171
|
+
G = p;
|
|
172
|
+
B = q;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return this.setRgb( R*255, G*255, B*255, a );
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
setRgb( r: number, g: number, b: number, a: number ): this {
|
|
181
|
+
this.rgb = [clamp(r,0,255),clamp(g,0,255),clamp(b,0,255),clamp(a,0,1)];
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
toRgbString( withAlpha?: boolean ): string {
|
|
186
|
+
const _ = this.rgb;
|
|
187
|
+
return withAlpha===false || _[3]==1 ? `rgb(${round(_[0])},${round(_[1])},${round(_[2])})` : `rgba(${round(_[0])},${round(_[1])},${round(_[2])},${_[3].toFixed(3)})`
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
toHexString( ): string {
|
|
191
|
+
const _ = this.rgb;
|
|
192
|
+
return _[3]==1 ? `#(${hx(_[0])},${hx(_[1])},${hx(_[2])})` : `rgba(${hx(_[0])},${hx(_[1])},${hx(_[2])},${hx(_[3]*255)})`
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
toRgb( ): Rgb {
|
|
196
|
+
const _ = this.rgb;
|
|
197
|
+
return { red: _[0], green: _[1], blue: _[2], alpha: _[3] };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
toHsv( ): Hsv {
|
|
201
|
+
|
|
202
|
+
let el = this.toRgb( );
|
|
203
|
+
|
|
204
|
+
el.red /= 255.0;
|
|
205
|
+
el.green /= 255.0;
|
|
206
|
+
el.blue /= 255.0;
|
|
207
|
+
|
|
208
|
+
const max = Math.max(el.red, el.green, el.blue);
|
|
209
|
+
const min = Math.min(el.red, el.green, el.blue);
|
|
210
|
+
const delta = max - min;
|
|
211
|
+
const saturation = (max === 0) ? 0 : (delta / max);
|
|
212
|
+
const value = max;
|
|
213
|
+
|
|
214
|
+
let hue;
|
|
215
|
+
|
|
216
|
+
if (delta === 0) {
|
|
217
|
+
hue = 0;
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
switch (max) {
|
|
221
|
+
case el.red:
|
|
222
|
+
hue = (el.green - el.blue) / delta / 6 + (el.green < el.blue ? 1 : 0);
|
|
223
|
+
break;
|
|
224
|
+
|
|
225
|
+
case el.green:
|
|
226
|
+
hue = (el.blue - el.red) / delta / 6 + 1 / 3;
|
|
227
|
+
break;
|
|
228
|
+
|
|
229
|
+
case el.blue:
|
|
230
|
+
hue = (el.red - el.green) / delta / 6 + 2 / 3;
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return { hue, saturation, value, alpha: el.alpha };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
getAlpha( ) {
|
|
239
|
+
return this.rgb[3];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
setAlpha( a: number ): this {
|
|
243
|
+
this.rgb[3] = clamp( a, 0, 1 );
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
isInvalid( ) {
|
|
248
|
+
return this.invalid;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
@@ -1,38 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file core_dom.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
*
|
|
11
|
+
* @copyright (c) 2024 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* Use of this source code is governed by an MIT-style license
|
|
14
|
+
* that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
|
15
|
+
**/
|
|
16
|
+
|
|
17
|
+
/** @ignore this events must be defined on domNode (do not bubble) */
|
|
18
|
+
export const unbubbleEvents = {
|
|
19
|
+
mouseleave: 1, mouseenter: 1, load: 1, unload: 1, scroll: 1, focus: 1, blur: 1, rowexit: 1, beforeunload: 1, stop: 1,
|
|
20
|
+
dragdrop: 1, dragenter: 1, dragexit: 1, draggesture: 1, dragover: 1, contextmenu: 1, created: 2, removed: 2, sizechange: 2
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type DOMEventHandler = ( ev: Event ) => void;
|
|
24
|
+
type EventEntry = Record<string,DOMEventHandler | DOMEventHandler[]>;
|
|
25
|
+
|
|
26
|
+
const event_handlers = new WeakMap<Node,EventEntry>( );
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* handle dom mutations
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
let mutObserver: MutationObserver = null;
|
|
33
|
+
|
|
34
|
+
const observeMutation = (mutations: MutationRecord[], observer: MutationObserver): void => {
|
|
35
|
+
|
|
36
|
+
const sendEvent = ( node: Node, code: "created" | "removed" ) => {
|
|
37
|
+
// console.log( "notify", node, code );
|
|
38
|
+
|
|
39
|
+
const store = event_handlers.get( node );
|
|
40
|
+
if ( store && store[code] ) {
|
|
41
|
+
node.dispatchEvent( new Event( code, {} ) );
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const notify = ( node: Node, create: boolean ) => {
|
|
46
|
+
|
|
47
|
+
if( create ) {
|
|
48
|
+
sendEvent( node, "created" );
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for( let c=node.firstChild; c; c=c.nextSibling ) {
|
|
52
|
+
notify( c, create );
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if( !create ) {
|
|
56
|
+
sendEvent( node, "removed" );
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
for (const mutation of mutations) {
|
|
62
|
+
if( mutation.type=="childList" ) {
|
|
63
|
+
if( mutation.addedNodes ) {
|
|
64
|
+
mutation.addedNodes.forEach( node => {
|
|
65
|
+
notify( node, true );
|
|
66
|
+
} );
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if( mutation.removedNodes ) {
|
|
70
|
+
mutation.removedNodes.forEach( node => {
|
|
71
|
+
notify( node, false );
|
|
72
|
+
} );
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
1
80
|
/**
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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 interface X4ElementEventMap extends HTMLElementEventMap {
|
|
31
|
-
"sizechange": Event;
|
|
32
|
-
"create": Event;
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
let sizeObserver: ResizeObserver = null;
|
|
85
|
+
|
|
86
|
+
function observeSize(entries: ResizeObserverEntry[]) {
|
|
87
|
+
entries.forEach((entry) => {
|
|
88
|
+
let dom = entry.target as HTMLElement;
|
|
89
|
+
if (dom.offsetParent !== null) {
|
|
90
|
+
dom.dispatchEvent( new Event('resized') );
|
|
91
|
+
}
|
|
92
|
+
});
|
|
33
93
|
}
|
|
34
94
|
|
|
35
|
-
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
export function dispatchEvent(ev: Event) {
|
|
100
|
+
|
|
101
|
+
let target = ev.target as Node,
|
|
102
|
+
noup = (unbubbleEvents as any)[ev.type] === 2;
|
|
103
|
+
|
|
104
|
+
while (target) {
|
|
105
|
+
const store = event_handlers.get( target );
|
|
106
|
+
if ( store ) {
|
|
107
|
+
const callback = store[ev.type];
|
|
108
|
+
if( callback ) {
|
|
109
|
+
if( Array.isArray(callback) ) {
|
|
110
|
+
callback.some( c => c( ev ) );
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
callback( ev );
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (ev.stopPropagation || ev.defaultPrevented || noup) {
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
target = target.parentNode;
|
|
123
|
+
|
|
124
|
+
// no need to go above
|
|
125
|
+
if (target == document) {
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
*
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
export function addEvent( node: Node, name: string, handler: DOMEventHandler, prepend = false ) {
|
|
136
|
+
|
|
137
|
+
if( name=="removed" || name=="created" ) {
|
|
138
|
+
if( !mutObserver ) {
|
|
139
|
+
mutObserver = new MutationObserver( observeMutation )
|
|
140
|
+
mutObserver.observe( document.body, {childList: true,subtree: true} );
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else if( name=="resized" ) {
|
|
144
|
+
if (!sizeObserver) {
|
|
145
|
+
sizeObserver = new ResizeObserver( observeSize );
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
sizeObserver.observe( node as Element );
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
let store = event_handlers.get( node );
|
|
153
|
+
if( !store ) {
|
|
154
|
+
store = {}
|
|
155
|
+
event_handlers.set( node, store );
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if( !store[name] ) {
|
|
159
|
+
store[name] = handler;
|
|
160
|
+
node.addEventListener( name, dispatchEvent );
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
const entry = store[name];
|
|
164
|
+
if( Array.isArray(entry) ) {
|
|
165
|
+
entry.push( handler );
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
store[name] = [entry,handler];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
*
|
|
175
|
+
*/
|
|
176
|
+
|
|
177
|
+
export interface GlobalDOMEvents {
|
|
36
178
|
|
|
37
179
|
/**
|
|
38
180
|
* Fires when the user aborts the download.
|
|
@@ -288,10 +430,10 @@ export interface IDOMEvents {
|
|
|
288
430
|
*/
|
|
289
431
|
timeupdate?: (ev: Event) => any;
|
|
290
432
|
toggle?: (ev: Event) => any;
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
433
|
+
touchcancel?: (ev: TouchEvent) => any;
|
|
434
|
+
touchend?: (ev: TouchEvent) => any;
|
|
435
|
+
touchmove?: (ev: TouchEvent) => any;
|
|
436
|
+
touchstart?: (ev: TouchEvent) => any;
|
|
295
437
|
transitioncancel?: (ev: TransitionEvent) => any;
|
|
296
438
|
transitionend?: (ev: TransitionEvent) => any;
|
|
297
439
|
transitionrun?: (ev: TransitionEvent) => any;
|
|
@@ -310,6 +452,20 @@ export interface IDOMEvents {
|
|
|
310
452
|
waiting?: (ev: Event) => any;
|
|
311
453
|
wheel?: (ev: WheelEvent) => any;
|
|
312
454
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
455
|
+
/**
|
|
456
|
+
* custom x4 events
|
|
457
|
+
*/
|
|
458
|
+
|
|
459
|
+
resized?: (ev: Event) => void; // occurs when size changed
|
|
460
|
+
created?: ( ev: Event ) => void; // occurs when inserted in the dom
|
|
461
|
+
removed?: ( ev: Event ) => void; // occurs when removed from dom
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
@@ -1,36 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___
|
|
3
|
-
* \
|
|
4
|
-
* \
|
|
5
|
-
* /
|
|
6
|
-
* /__
|
|
7
|
-
*
|
|
8
|
-
* @file
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
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'
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file core_dragdrop.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
*
|
|
11
|
+
* @copyright (c) 2024 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* Use of this source code is governed by an MIT-style license
|
|
14
|
+
* that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
|
15
|
+
**/
|
|
31
16
|
|
|
32
17
|
import { Component } from './component';
|
|
33
|
-
import { Point } from './
|
|
18
|
+
import { Point } from './core_tools';
|
|
34
19
|
|
|
35
20
|
const x_drag_cb = Symbol( 'x-drag-cb' );
|
|
36
21
|
|
|
@@ -63,13 +48,13 @@ class DragManager {
|
|
|
63
48
|
|
|
64
49
|
registerDraggableElement(el: Component) {
|
|
65
50
|
|
|
66
|
-
el.
|
|
51
|
+
el.addDOMEvent('dragstart', (ev: DragEvent) => {
|
|
67
52
|
|
|
68
53
|
this.dragSource = el;
|
|
69
54
|
this.dragGhost = el.dom.cloneNode(true) as HTMLElement;
|
|
70
55
|
|
|
71
56
|
this.dragGhost.classList.add('dragged');
|
|
72
|
-
|
|
57
|
+
document.body.appendChild(this.dragGhost);
|
|
73
58
|
|
|
74
59
|
el.addClass( 'dragging' );
|
|
75
60
|
|
|
@@ -79,12 +64,12 @@ class DragManager {
|
|
|
79
64
|
ev.stopPropagation( );
|
|
80
65
|
});
|
|
81
66
|
|
|
82
|
-
el.
|
|
67
|
+
el.addDOMEvent('drag', (ev: DragEvent) => {
|
|
83
68
|
this.dragGhost.style.left = ev.pageX + "px";
|
|
84
69
|
this.dragGhost.style.top = ev.pageY + "px";
|
|
85
70
|
});
|
|
86
71
|
|
|
87
|
-
el.
|
|
72
|
+
el.addDOMEvent('dragend', (ev: DragEvent) => {
|
|
88
73
|
el.removeClass( 'dragging' );
|
|
89
74
|
this.dragGhost.remove();
|
|
90
75
|
});
|
|
@@ -128,7 +113,7 @@ class DragManager {
|
|
|
128
113
|
|
|
129
114
|
if( this.dropTarget ) {
|
|
130
115
|
const infos = {
|
|
131
|
-
pt:
|
|
116
|
+
pt: { x: ev.pageX, y: ev.pageY },
|
|
132
117
|
data: ev.dataTransfer,
|
|
133
118
|
}
|
|
134
119
|
|
|
@@ -146,7 +131,7 @@ class DragManager {
|
|
|
146
131
|
|
|
147
132
|
const drop = (ev: DragEvent) => {
|
|
148
133
|
const infos = {
|
|
149
|
-
pt:
|
|
134
|
+
pt: { x: ev.pageX, y: ev.pageY },
|
|
150
135
|
data: ev.dataTransfer,
|
|
151
136
|
}
|
|
152
137
|
|
|
@@ -158,12 +143,12 @@ class DragManager {
|
|
|
158
143
|
ev.preventDefault();
|
|
159
144
|
}
|
|
160
145
|
|
|
161
|
-
el.
|
|
162
|
-
el.
|
|
163
|
-
el.
|
|
164
|
-
el.
|
|
146
|
+
el.addDOMEvent('dragenter', dragEnter);
|
|
147
|
+
el.addDOMEvent('dragover', dragOver);
|
|
148
|
+
el.addDOMEvent('dragleave', dragLeave);
|
|
149
|
+
el.addDOMEvent('drop', drop);
|
|
165
150
|
|
|
166
|
-
el.
|
|
151
|
+
el.setInternalData( x_drag_cb, cb );
|
|
167
152
|
}
|
|
168
153
|
|
|
169
154
|
_startCheck() {
|
|
@@ -181,13 +166,13 @@ class DragManager {
|
|
|
181
166
|
const leaving = ( x: Component ) => {
|
|
182
167
|
x.removeClass('drop-over');
|
|
183
168
|
|
|
184
|
-
const cb = x.
|
|
169
|
+
const cb = x.getInternalData( x_drag_cb );
|
|
185
170
|
cb( 'leave', this.dragSource );
|
|
186
171
|
}
|
|
187
172
|
|
|
188
173
|
const entering = ( x: Component ) => {
|
|
189
174
|
x.addClass('drop-over');
|
|
190
|
-
const cb = x.
|
|
175
|
+
const cb = x.getInternalData( x_drag_cb );
|
|
191
176
|
cb( 'enter', this.dragSource );
|
|
192
177
|
}
|
|
193
178
|
|