x4js 2.0.20 → 2.0.21
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/lib/cjs/x4.css +1 -1
- package/lib/cjs/x4.js +2 -2
- package/lib/esm/x4.css +1 -1
- package/lib/esm/x4.mjs +2 -2
- package/lib/styles/x4.css +1 -1
- package/lib/types/x4js.d.ts +92 -77
- package/package.json +1 -1
- package/src/components/boxes/boxes.ts +33 -1
- package/src/components/combobox/combobox.module.scss +13 -0
- package/src/components/combobox/combobox.ts +7 -0
- package/src/components/form/form.ts +4 -4
- package/src/components/gridview/gridview.ts +12 -9
- package/src/components/header/header.module.scss +2 -1
- package/src/components/header/header.ts +17 -5
- package/src/components/icon/icon.module.scss +1 -0
- package/src/components/label/label.module.scss +6 -1
- package/src/components/listbox/listbox.module.scss +35 -31
- package/src/components/listbox/listbox.ts +50 -12
- package/src/components/messages/messages.ts +14 -0
- package/src/components/notification/notification.ts +1 -1
- package/src/components/popup/popup.ts +13 -2
- package/src/components/propgrid/propgrid.ts +4 -2
- package/src/components/sizers/sizer.ts +4 -4
- package/src/components/tabs/tabs.module.scss +2 -2
- package/src/components/tabs/tabs.ts +28 -4
- package/src/components/textedit/textedit.ts +1 -1
- package/src/components/treeview/treeview.module.scss +9 -1
- package/src/components/treeview/treeview.ts +52 -13
- package/src/core/component.ts +46 -9
- package/src/core/core_data.ts +8 -8
- package/src/core/core_state.ts +1 -1
- package/src/core/core_tools.ts +2 -0
- package/lib/src/components/base.scss +0 -25
- package/lib/src/components/boxes/boxes.module.scss +0 -54
- package/lib/src/components/boxes/boxes.ts +0 -370
- package/lib/src/components/breadcrumb/breadcrumb.scss +0 -56
- package/lib/src/components/breadcrumb/breadcrumb.ts +0 -93
- package/lib/src/components/breadcrumb/chevron-right.svg +0 -1
- package/lib/src/components/btngroup/btngroup.module.scss +0 -41
- package/lib/src/components/btngroup/btngroup.ts +0 -153
- package/lib/src/components/button/button.module.scss +0 -173
- package/lib/src/components/button/button.ts +0 -185
- package/lib/src/components/calendar/calendar-check-sharp-light.svg +0 -1
- package/lib/src/components/calendar/calendar.module.scss +0 -163
- package/lib/src/components/calendar/calendar.ts +0 -327
- package/lib/src/components/calendar/chevron-left-sharp-light.svg +0 -1
- package/lib/src/components/calendar/chevron-right-sharp-light.svg +0 -1
- package/lib/src/components/canvas/canvas.module.scss +0 -25
- package/lib/src/components/canvas/canvas.ts +0 -189
- package/lib/src/components/canvas/canvas_ex.ts +0 -276
- package/lib/src/components/checkbox/check.svg +0 -4
- package/lib/src/components/checkbox/checkbox.module.scss +0 -142
- package/lib/src/components/checkbox/checkbox.ts +0 -140
- package/lib/src/components/colorinput/colorinput.module.scss +0 -65
- package/lib/src/components/colorinput/colorinput.ts +0 -91
- package/lib/src/components/colorinput/crosshairs-simple-sharp-light.svg +0 -1
- package/lib/src/components/colorpicker/colorpicker.module.scss +0 -133
- package/lib/src/components/colorpicker/colorpicker.ts +0 -482
- package/lib/src/components/combobox/combobox.module.scss +0 -133
- package/lib/src/components/combobox/combobox.ts +0 -275
- package/lib/src/components/combobox/updown.svg +0 -4
- package/lib/src/components/components.ts +0 -42
- package/lib/src/components/dialog/dialog.module.scss +0 -104
- package/lib/src/components/dialog/dialog.ts +0 -229
- package/lib/src/components/dialog/xmark-sharp-light.svg +0 -1
- package/lib/src/components/filedrop/cloud-arrow-up.svg +0 -1
- package/lib/src/components/filedrop/filedrop.module.scss +0 -70
- package/lib/src/components/filedrop/filedrop.ts +0 -131
- package/lib/src/components/form/form.module.scss +0 -38
- package/lib/src/components/form/form.ts +0 -172
- package/lib/src/components/gridview/arrow-down-light.svg +0 -1
- package/lib/src/components/gridview/arrow-up-light.svg +0 -1
- package/lib/src/components/gridview/gridview.module.scss +0 -324
- package/lib/src/components/gridview/gridview.ts +0 -1175
- package/lib/src/components/header/header.module.scss +0 -40
- package/lib/src/components/header/header.ts +0 -130
- package/lib/src/components/icon/icon.module.scss +0 -31
- package/lib/src/components/icon/icon.ts +0 -137
- package/lib/src/components/image/image.module.scss +0 -28
- package/lib/src/components/image/image.ts +0 -168
- package/lib/src/components/input/input.module.scss +0 -74
- package/lib/src/components/input/input.ts +0 -422
- package/lib/src/components/keyboard/arrow-up.svg +0 -1
- package/lib/src/components/keyboard/delete-left.svg +0 -1
- package/lib/src/components/keyboard/eye-slash.svg +0 -1
- package/lib/src/components/keyboard/keyboard.module.scss +0 -134
- package/lib/src/components/keyboard/keyboard.ts +0 -526
- package/lib/src/components/label/label.module.scss +0 -76
- package/lib/src/components/label/label.ts +0 -97
- package/lib/src/components/link/link.ts +0 -81
- package/lib/src/components/listbox/listbox.module.scss +0 -161
- package/lib/src/components/listbox/listbox.ts +0 -539
- package/lib/src/components/menu/caret-right-solid.svg +0 -1
- package/lib/src/components/menu/menu.module.scss +0 -117
- package/lib/src/components/menu/menu.ts +0 -174
- package/lib/src/components/messages/circle-exclamation.svg +0 -1
- package/lib/src/components/messages/messages.module.scss +0 -92
- package/lib/src/components/messages/messages.ts +0 -215
- package/lib/src/components/messages/pen-field.svg +0 -1
- package/lib/src/components/normalize.scss +0 -391
- package/lib/src/components/notification/circle-check-solid.svg +0 -1
- package/lib/src/components/notification/circle-exclamation-solid.svg +0 -1
- package/lib/src/components/notification/circle-notch-light.svg +0 -1
- package/lib/src/components/notification/notification.module.scss +0 -84
- package/lib/src/components/notification/notification.ts +0 -107
- package/lib/src/components/notification/xmark-sharp-light.svg +0 -1
- package/lib/src/components/panel/panel.module.scss +0 -60
- package/lib/src/components/panel/panel.ts +0 -58
- package/lib/src/components/popup/popup.module.scss +0 -51
- package/lib/src/components/popup/popup.ts +0 -442
- package/lib/src/components/progress/progress.module.scss +0 -57
- package/lib/src/components/progress/progress.ts +0 -44
- package/lib/src/components/propgrid/folder-closed.svg +0 -1
- package/lib/src/components/propgrid/folder-open.svg +0 -1
- package/lib/src/components/propgrid/progrid.module.scss +0 -112
- package/lib/src/components/propgrid/propgrid.ts +0 -288
- package/lib/src/components/propgrid/updown.svg +0 -4
- package/lib/src/components/radio/radio.module.scss +0 -147
- package/lib/src/components/radio/radio.svg +0 -4
- package/lib/src/components/radio/radio.ts +0 -142
- package/lib/src/components/rating/rating.module.scss +0 -23
- package/lib/src/components/rating/rating.ts +0 -131
- package/lib/src/components/rating/star-sharp-light.svg +0 -1
- package/lib/src/components/rating/star-sharp-solid.svg +0 -1
- package/lib/src/components/select/select.module.scss +0 -9
- package/lib/src/components/select/select.ts +0 -134
- package/lib/src/components/shared.scss +0 -137
- package/lib/src/components/sizers/sizer.module.scss +0 -90
- package/lib/src/components/sizers/sizer.ts +0 -132
- package/lib/src/components/slider/slider.module.scss +0 -118
- package/lib/src/components/slider/slider.ts +0 -198
- package/lib/src/components/switch/switch.module.scss +0 -127
- package/lib/src/components/switch/switch.ts +0 -62
- package/lib/src/components/tabs/tabs.module.scss +0 -45
- package/lib/src/components/tabs/tabs.ts +0 -205
- package/lib/src/components/textarea/textarea.module.scss +0 -63
- package/lib/src/components/textarea/textarea.ts +0 -125
- package/lib/src/components/textedit/textedit.module.scss +0 -116
- package/lib/src/components/textedit/textedit.ts +0 -115
- package/lib/src/components/themes.scss +0 -88
- package/lib/src/components/tickline/tickline.module.scss +0 -26
- package/lib/src/components/tickline/tickline.ts +0 -82
- package/lib/src/components/tooltips/circle-info-sharp-light.svg +0 -1
- package/lib/src/components/tooltips/comments-question.svg +0 -1
- package/lib/src/components/tooltips/tooltips.scss +0 -72
- package/lib/src/components/tooltips/tooltips.ts +0 -109
- package/lib/src/components/treeview/chevron-down-light.svg +0 -1
- package/lib/src/components/treeview/treeview.module.scss +0 -185
- package/lib/src/components/treeview/treeview.ts +0 -445
- package/lib/src/components/viewport/viewport.module.scss +0 -32
- package/lib/src/components/viewport/viewport.ts +0 -41
- package/lib/src/core/component.ts +0 -1066
- package/lib/src/core/core_application.ts +0 -265
- package/lib/src/core/core_colors.ts +0 -250
- package/lib/src/core/core_data.ts +0 -1310
- package/lib/src/core/core_dom.ts +0 -471
- package/lib/src/core/core_dragdrop.ts +0 -201
- package/lib/src/core/core_element.ts +0 -115
- package/lib/src/core/core_events.ts +0 -177
- package/lib/src/core/core_i18n.ts +0 -393
- package/lib/src/core/core_react.ts +0 -79
- package/lib/src/core/core_router.ts +0 -237
- package/lib/src/core/core_state.ts +0 -62
- package/lib/src/core/core_styles.ts +0 -214
- package/lib/src/core/core_svg.ts +0 -712
- package/lib/src/core/core_tools.ts +0 -906
- package/lib/src/types/scss.d.ts +0 -4
- package/lib/src/types/svg.d.ts +0 -1
- package/lib/src/types/x4react.d.ts +0 -9
- package/lib/src/x4.scss +0 -19
- package/lib/src/x4.ts +0 -35
- package/lib/src/x4tsx.d.ts +0 -25
package/lib/src/core/core_svg.ts
DELETED
|
@@ -1,712 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / \____ _|
|
|
6
|
-
* /__/\__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file core_svg.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 { Component, ComponentProps } from './component';
|
|
18
|
-
import { isUnitLess } from "./core_styles";
|
|
19
|
-
import { DOMEventHandler, GlobalDOMEvents, addEvent } from './core_dom';
|
|
20
|
-
import { isNumber, isString } from './core_tools';
|
|
21
|
-
|
|
22
|
-
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
23
|
-
|
|
24
|
-
// degrees to radian
|
|
25
|
-
function d2r( d: number ): number {
|
|
26
|
-
return d * Math.PI / 180.0;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// polar to cartesian
|
|
30
|
-
function p2c( x: number, y: number, r: number, deg: number ): {x: number,y: number} {
|
|
31
|
-
const rad = d2r( deg );
|
|
32
|
-
return {
|
|
33
|
-
x: x + r * Math.cos( rad ),
|
|
34
|
-
y: y + r * Math.sin( rad )
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// fix prec for numbers
|
|
39
|
-
function num( x: number ): number {
|
|
40
|
-
return Math.round( x * 1000 ) / 1000;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// clean values
|
|
44
|
-
function clean( a: any, ...b: any ) {
|
|
45
|
-
// just round number values to 3 digits
|
|
46
|
-
b = b.map( ( v: any ) => {
|
|
47
|
-
if( typeof v === 'number' && isFinite(v) ) {
|
|
48
|
-
return num(v);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return v;
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
return String.raw( a, ...b );
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
class SvgItem {
|
|
66
|
-
protected _dom : SVGElement;
|
|
67
|
-
|
|
68
|
-
constructor( tag: string ) {
|
|
69
|
-
this._dom = document.createElementNS("http://www.w3.org/2000/svg", tag );
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @returns the svh element dom
|
|
74
|
-
*/
|
|
75
|
-
|
|
76
|
-
getDom( ) {
|
|
77
|
-
return this._dom;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
*
|
|
82
|
-
*/
|
|
83
|
-
|
|
84
|
-
reset( ) {
|
|
85
|
-
const attrs = this._dom.attributes;
|
|
86
|
-
for (let i = attrs.length - 1; i >= 0; i--) {
|
|
87
|
-
this._dom.removeAttribute(attrs[i].name);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* change the stroke color
|
|
96
|
-
* @param color
|
|
97
|
-
*/
|
|
98
|
-
|
|
99
|
-
stroke( color: string, width?: number ): this {
|
|
100
|
-
this.setAttr( 'stroke', color );
|
|
101
|
-
if( width!==undefined ) {
|
|
102
|
-
this.setAttr( 'stroke-width', width+'px' );
|
|
103
|
-
}
|
|
104
|
-
return this;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* change the stroke width
|
|
109
|
-
* @param width
|
|
110
|
-
*/
|
|
111
|
-
strokeWidth( width: number ): this {
|
|
112
|
-
this.setAttr( 'stroke-width', width+'px' );
|
|
113
|
-
return this;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
strokeCap( cap: "butt" | "round" | "sqaure" ) {
|
|
117
|
-
return this.setAttr( "stroke-linecap", cap );
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
strokeOpacity( opacity: number ) {
|
|
121
|
-
return this.setAttr( "stroke-opacity", opacity+"" );
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
*
|
|
126
|
-
*/
|
|
127
|
-
|
|
128
|
-
antiAlias( set: boolean ) {
|
|
129
|
-
return this.setAttr( "shape-rendering", set ? "auto" : "crispEdges" );
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* change the fill color
|
|
134
|
-
* @param color
|
|
135
|
-
*/
|
|
136
|
-
|
|
137
|
-
fill( color: string ): this {
|
|
138
|
-
this.setAttr( 'fill', color );
|
|
139
|
-
return this;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
no_fill( ): this {
|
|
143
|
-
this.setAttr( 'fill', "transparent" );
|
|
144
|
-
return this;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* return the given attribute if any
|
|
149
|
-
*/
|
|
150
|
-
|
|
151
|
-
getAttr( name: string ) : string {
|
|
152
|
-
return this._dom.getAttribute( name );
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
getNumAttr( name: string ) {
|
|
156
|
-
return parseInt( this._dom.getAttribute( name ) );
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* define a new attribute
|
|
161
|
-
* @param name attibute name
|
|
162
|
-
* @param value attribute value
|
|
163
|
-
* @returns this
|
|
164
|
-
*/
|
|
165
|
-
|
|
166
|
-
setAttr( name: string, value: string ) : this {
|
|
167
|
-
this._dom.setAttribute( name, value );
|
|
168
|
-
return this;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
*
|
|
173
|
-
*/
|
|
174
|
-
|
|
175
|
-
setStyle<K extends keyof CSSStyleDeclaration>( name: K, value: string | number ) : this {
|
|
176
|
-
const _style = this._dom.style;
|
|
177
|
-
|
|
178
|
-
if( isNumber(value) ) {
|
|
179
|
-
let v = value+"";
|
|
180
|
-
if( !isUnitLess(name as string) ) {
|
|
181
|
-
v += "px";
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
(_style as any)[name] = v;
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
(_style as any)[name] = value;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return this;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* add a class
|
|
195
|
-
* @param name class name to add
|
|
196
|
-
*/
|
|
197
|
-
|
|
198
|
-
addClass( cls: string ): this {
|
|
199
|
-
if( !cls ) return;
|
|
200
|
-
|
|
201
|
-
cls = cls.trim();
|
|
202
|
-
if( cls.indexOf(' ')>=0 ) {
|
|
203
|
-
const ccs = cls.split( " " );
|
|
204
|
-
this._dom.classList.add(...ccs);
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
this._dom.classList.add(cls);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return this;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* remove a class
|
|
215
|
-
* @param name class name to remove
|
|
216
|
-
*/
|
|
217
|
-
|
|
218
|
-
removeClass( cls: string ): this {
|
|
219
|
-
if( !cls ) return;
|
|
220
|
-
|
|
221
|
-
if( cls.indexOf(' ')>=0 ) {
|
|
222
|
-
const ccs = cls.split( " " );
|
|
223
|
-
this._dom.classList.remove(...ccs);
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
this._dom.classList.remove(cls);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return this;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
*
|
|
234
|
-
*/
|
|
235
|
-
|
|
236
|
-
clip( id: string ): this {
|
|
237
|
-
this.setAttr( "clip-path", `url(#${id})` );
|
|
238
|
-
return this;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
*
|
|
243
|
-
*/
|
|
244
|
-
|
|
245
|
-
transform( tr: string ): this {
|
|
246
|
-
const t = this.getAttr( "transform" ) ?? "";
|
|
247
|
-
this.setAttr( "transform", t+' '+tr );
|
|
248
|
-
return this;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
clear_transform( ) {
|
|
252
|
-
this.setAttr( "transform", null );
|
|
253
|
-
return this;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
*
|
|
258
|
-
*/
|
|
259
|
-
|
|
260
|
-
rotate( deg: number, cx: number, cy: number ): this {
|
|
261
|
-
this.transform( `rotate( ${deg} ${cx} ${cy} )` );
|
|
262
|
-
return this;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
translate( dx: number, dy: number ): this {
|
|
266
|
-
this.transform( `translate( ${dx} ${dy} )` );
|
|
267
|
-
return this;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
scale( x: number ): this {
|
|
271
|
-
this.transform( `scale( ${x} )` );
|
|
272
|
-
return this;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
*
|
|
277
|
-
*/
|
|
278
|
-
|
|
279
|
-
addDOMEvent<K extends keyof GlobalDOMEvents>( name: K, listener: GlobalDOMEvents[K], prepend = false ) {
|
|
280
|
-
addEvent( this._dom, name, listener as DOMEventHandler, prepend );
|
|
281
|
-
return this;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
*
|
|
289
|
-
*/
|
|
290
|
-
|
|
291
|
-
export class SvgPath extends SvgItem {
|
|
292
|
-
private _path: string;
|
|
293
|
-
|
|
294
|
-
constructor( ) {
|
|
295
|
-
super( 'path' );
|
|
296
|
-
this._path = '';
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
private _update( ): this {
|
|
300
|
-
this.setAttr( 'd', this._path );
|
|
301
|
-
return this;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
reset( ) {
|
|
305
|
-
this._path = "";
|
|
306
|
-
super.reset( );
|
|
307
|
-
return this;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* move the current pos
|
|
312
|
-
* @param x new pos x
|
|
313
|
-
* @param y new pos y
|
|
314
|
-
* @returns this
|
|
315
|
-
*/
|
|
316
|
-
|
|
317
|
-
moveTo( x: number, y: number ) : this {
|
|
318
|
-
this._path += clean`M${x},${y}`;
|
|
319
|
-
return this._update( );
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* draw aline to the given point
|
|
324
|
-
* @param x end x
|
|
325
|
-
* @param y end y
|
|
326
|
-
* @returns this
|
|
327
|
-
*/
|
|
328
|
-
|
|
329
|
-
lineTo( x: number, y: number ): this {
|
|
330
|
-
this._path += clean`L${x},${y}`;
|
|
331
|
-
return this._update( );
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* draw a curve
|
|
336
|
-
*/
|
|
337
|
-
|
|
338
|
-
curveTo( x1: number, y1: number, x2: number, y2: number, x3: number, y3: number ) {
|
|
339
|
-
this._path += clean`C${x1},${y1} ${x2},${y2} ${x3},${y3}`;
|
|
340
|
-
return this._update( );
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* close the currentPath
|
|
346
|
-
*/
|
|
347
|
-
|
|
348
|
-
closePath( ): this {
|
|
349
|
-
this._path += 'Z';
|
|
350
|
-
return this._update( );
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* draw an arc
|
|
355
|
-
* @param x center x
|
|
356
|
-
* @param y center y
|
|
357
|
-
* @param r radius
|
|
358
|
-
* @param start angle start in degrees
|
|
359
|
-
* @param end angle end in degrees
|
|
360
|
-
* @returns this
|
|
361
|
-
*/
|
|
362
|
-
|
|
363
|
-
arc( x: number, y: number, r: number, start: number, end: number, clockwise= true ): this {
|
|
364
|
-
|
|
365
|
-
const st = p2c( x, y, r, start-90 );
|
|
366
|
-
const en = p2c( x, y, r, end-90 );
|
|
367
|
-
|
|
368
|
-
const flag = ((end-start) <= 180 ? "0" : "1");
|
|
369
|
-
this._path += clean`M${st.x},${st.y}A${r},${r} 0 ${flag} ${(clockwise ? '1' : '0')} ${en.x},${en.y}`;
|
|
370
|
-
|
|
371
|
-
return this._update( );
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
*
|
|
377
|
-
*/
|
|
378
|
-
|
|
379
|
-
export class SvgText extends SvgItem {
|
|
380
|
-
|
|
381
|
-
constructor( x: number, y: number, txt: string ) {
|
|
382
|
-
super( 'text' );
|
|
383
|
-
|
|
384
|
-
this.setAttr( 'x', num(x)+'' );
|
|
385
|
-
this.setAttr( 'y', num(y)+'' );
|
|
386
|
-
|
|
387
|
-
this._dom.innerHTML = txt;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
font( font: string ): this {
|
|
391
|
-
return this.setAttr( 'font-family', font );
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
fontSize( size: number | string ): this {
|
|
395
|
-
return this.setAttr( 'font-size', size+'' );
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
fontWeight( weight: 'light' | 'normal' | 'bold' ): this {
|
|
399
|
-
return this.setAttr( 'font-weight', weight );
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
textAlign( align: 'left' | 'center' | 'right' ): this {
|
|
403
|
-
|
|
404
|
-
let al;
|
|
405
|
-
switch( align ) {
|
|
406
|
-
case 'left': al = 'start'; break;
|
|
407
|
-
case 'center': al = 'middle'; break;
|
|
408
|
-
case 'right': al = 'end'; break;
|
|
409
|
-
default: return this;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
return this.setAttr( 'text-anchor', al );
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
verticalAlign( align: 'top' | 'center' | 'bottom' | 'baseline' ): this {
|
|
416
|
-
|
|
417
|
-
let al;
|
|
418
|
-
switch( align ) {
|
|
419
|
-
case 'top': al = 'hanging'; break;
|
|
420
|
-
case 'center': al = 'middle'; break;
|
|
421
|
-
case 'bottom': al = 'baseline'; break;
|
|
422
|
-
case 'baseline': al = 'mathematical'; break;
|
|
423
|
-
default: return;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
return this.setAttr( 'alignment-baseline', al );
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
*
|
|
432
|
-
*/
|
|
433
|
-
|
|
434
|
-
export class SvgIcon extends SvgItem {
|
|
435
|
-
constructor( svg: string ) {
|
|
436
|
-
super( "svg" );
|
|
437
|
-
|
|
438
|
-
if( svg.startsWith("data:image/svg+xml,") ) {
|
|
439
|
-
svg = svg.substring( 19 );
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
const parser = new DOMParser();
|
|
443
|
-
const doc = parser.parseFromString( decodeURIComponent(svg), "image/svg+xml");
|
|
444
|
-
|
|
445
|
-
const parserErrorElement = doc.querySelector("parsererror");
|
|
446
|
-
if( parserErrorElement ) {
|
|
447
|
-
console.error( "error while parsing svg:\n"+ parserErrorElement.textContent );
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
const svgRoot = doc.documentElement; // The <svg> element from the string
|
|
451
|
-
for( let i=0; i<svgRoot.attributes.length; i++) {
|
|
452
|
-
this._dom.setAttribute( svgRoot.attributes[i].name, svgRoot.attributes[i].value );
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
for( let i=0; i<svgRoot.childNodes.length; i++) {
|
|
456
|
-
const child = svgRoot.childNodes[i];
|
|
457
|
-
if (child.nodeType === 1) {
|
|
458
|
-
this._dom.appendChild(child);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
*
|
|
468
|
-
*/
|
|
469
|
-
|
|
470
|
-
export class SvgShape extends SvgItem {
|
|
471
|
-
constructor( tag: string ) {
|
|
472
|
-
super( tag );
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
/**
|
|
477
|
-
*
|
|
478
|
-
*/
|
|
479
|
-
|
|
480
|
-
type number_or_perc = number | `${string}%`
|
|
481
|
-
|
|
482
|
-
export class SvgGradient extends SvgItem {
|
|
483
|
-
|
|
484
|
-
private static g_id = 1;
|
|
485
|
-
|
|
486
|
-
private _id: string;
|
|
487
|
-
private _stops: { offset: number_or_perc, color: string } [];
|
|
488
|
-
|
|
489
|
-
constructor( x1: number_or_perc, y1: number_or_perc, x2: number_or_perc, y2: number_or_perc ) {
|
|
490
|
-
super( 'linearGradient')
|
|
491
|
-
|
|
492
|
-
this._id = 'gx-'+SvgGradient.g_id;
|
|
493
|
-
SvgGradient.g_id++;
|
|
494
|
-
|
|
495
|
-
this.setAttr( 'id', this._id );
|
|
496
|
-
this.setAttr( 'x1', isString(x1) ? x1 : num(x1)+'' );
|
|
497
|
-
this.setAttr( 'x2', isString(x2) ? x2 : num(x2)+'' );
|
|
498
|
-
this.setAttr( 'y1', isString(y1) ? y1 : num(y1)+'' );
|
|
499
|
-
this.setAttr( 'y2', isString(y2) ? y2 : num(y2)+'' );
|
|
500
|
-
|
|
501
|
-
this._stops = [];
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
get id( ) {
|
|
505
|
-
return 'url(#'+this._id+')';
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
addStop( offset: number_or_perc, color: string ): this {
|
|
509
|
-
this._dom.insertAdjacentHTML( "beforeend", `<stop offset="${offset}%" stop-color="${color}"></stop>`);
|
|
510
|
-
return this;
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
*
|
|
516
|
-
*/
|
|
517
|
-
|
|
518
|
-
export class SvgGroup extends SvgItem {
|
|
519
|
-
|
|
520
|
-
constructor( tag = "g" ) {
|
|
521
|
-
super( tag )
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
/**
|
|
525
|
-
*
|
|
526
|
-
*/
|
|
527
|
-
|
|
528
|
-
append<K extends SvgItem>( item: K ): K {
|
|
529
|
-
this._dom.appendChild( item.getDom() );
|
|
530
|
-
return item;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
appendItems<K extends SvgItem>( items: K[] ) {
|
|
534
|
-
items.forEach( item => {
|
|
535
|
-
this._dom.appendChild( item.getDom() );
|
|
536
|
-
} );
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
/**
|
|
540
|
-
*
|
|
541
|
-
*/
|
|
542
|
-
|
|
543
|
-
path( ): SvgPath {
|
|
544
|
-
const path = new SvgPath( );
|
|
545
|
-
return this.append( path );
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
text( x: number, y: number, txt: string ) {
|
|
549
|
-
const text = new SvgText( x, y, txt );
|
|
550
|
-
return this.append( text );
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
ellipse( x: number, y: number, r1: number, r2: number ): SvgShape {
|
|
554
|
-
const shape = new SvgShape( 'ellipse' );
|
|
555
|
-
shape.setAttr( 'cx', num(x)+'' );
|
|
556
|
-
shape.setAttr( 'cy', num(y)+'' );
|
|
557
|
-
shape.setAttr( 'rx', num(r1)+'' );
|
|
558
|
-
shape.setAttr( 'ry', num(r2)+'' );
|
|
559
|
-
return this.append( shape );
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
circle( x: number, y: number, r1: number ): SvgShape {
|
|
563
|
-
const shape = new SvgShape( 'ellipse' );
|
|
564
|
-
shape.setAttr( 'cx', num(x)+'' );
|
|
565
|
-
shape.setAttr( 'cy', num(y)+'' );
|
|
566
|
-
shape.setAttr( 'rx', num(r1)+'' );
|
|
567
|
-
shape.setAttr( 'ry', num(r1)+'' );
|
|
568
|
-
return this.append( shape );
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
icon( svg: string, x: number, y: number, w: number, h: number ): SvgIcon {
|
|
572
|
-
const icon = new SvgIcon( svg );
|
|
573
|
-
icon.setAttr( 'x', num(x)+'' );
|
|
574
|
-
icon.setAttr( 'y', num(y)+'' );
|
|
575
|
-
icon.setAttr( 'width', num(w)+'' );
|
|
576
|
-
icon.setAttr( 'height', num(h)+'' );
|
|
577
|
-
return this.append( icon );
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
rect( x: number, y: number, w: number, h: number ): SvgShape {
|
|
581
|
-
|
|
582
|
-
if( h<0 ) {
|
|
583
|
-
y = y+h;
|
|
584
|
-
h = -h;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
const shape = new SvgShape( 'rect' );
|
|
588
|
-
shape.setAttr( 'x', num(x)+'' );
|
|
589
|
-
shape.setAttr( 'y', num(y)+'' );
|
|
590
|
-
shape.setAttr( 'width', num(w)+'' );
|
|
591
|
-
shape.setAttr( 'height', num(h)+'' );
|
|
592
|
-
return this.append( shape );
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
group( id?: string ) {
|
|
596
|
-
const group = new SvgGroup( );
|
|
597
|
-
if( id ) {
|
|
598
|
-
group.setAttr( 'id', id );
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
return this.append( group );
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
/**
|
|
605
|
-
*
|
|
606
|
-
* example
|
|
607
|
-
* ```ts
|
|
608
|
-
* const g = c.linear_gradient( '0%', '0%', '0%', '100%' )
|
|
609
|
-
* .addStop( 0, 'red' )
|
|
610
|
-
* .addStop( 100, 'green' );
|
|
611
|
-
*
|
|
612
|
-
* p.rect( 0, 0, 100, 100 )
|
|
613
|
-
* .stroke( g.id );
|
|
614
|
-
*
|
|
615
|
-
* ```
|
|
616
|
-
*/
|
|
617
|
-
|
|
618
|
-
linear_gradient( x1: number_or_perc, y1: number_or_perc, x2: number_or_perc, y2: number_or_perc ) {
|
|
619
|
-
const grad = new SvgGradient( x1, y1, x2, y2 );
|
|
620
|
-
return this.append( grad );
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
/**
|
|
624
|
-
* clear
|
|
625
|
-
*/
|
|
626
|
-
|
|
627
|
-
clear( ) {
|
|
628
|
-
const dom = this._dom;
|
|
629
|
-
while( dom.firstChild ) {
|
|
630
|
-
dom.removeChild( dom.firstChild );
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
export class SvgBuilder extends SvgGroup {
|
|
640
|
-
private static g_clip_id = 1;
|
|
641
|
-
private static g_pat_id = 1;
|
|
642
|
-
|
|
643
|
-
constructor( ) {
|
|
644
|
-
super( );
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
addClip( x: number, y: number, w: number, h: number ) {
|
|
648
|
-
const id = 'clip-'+SvgBuilder.g_clip_id++;
|
|
649
|
-
const clip = new SvgGroup( 'clipPath' );
|
|
650
|
-
clip.setAttr('id', id );
|
|
651
|
-
clip.rect( x, y, w, h );
|
|
652
|
-
|
|
653
|
-
this.append(clip);
|
|
654
|
-
return {id,clip};
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
addPattern( x: number, y: number, w: number, h: number ) {
|
|
658
|
-
const id = 'pat-'+SvgBuilder.g_pat_id++;
|
|
659
|
-
|
|
660
|
-
const pat = new SvgGroup( 'pattern' );
|
|
661
|
-
pat.setAttr( 'id', id );
|
|
662
|
-
pat.setAttr( 'x', num(x)+'' );
|
|
663
|
-
pat.setAttr( 'y', num(y)+'' );
|
|
664
|
-
pat.setAttr( 'width', num(w)+'' );
|
|
665
|
-
pat.setAttr( 'height', num(h)+'' );
|
|
666
|
-
pat.setAttr( 'patternUnits', "userSpaceOnUse" );
|
|
667
|
-
|
|
668
|
-
this.append(pat);
|
|
669
|
-
return {id,pat};
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
/**
|
|
676
|
-
*
|
|
677
|
-
*/
|
|
678
|
-
|
|
679
|
-
interface SvgProps extends ComponentProps {
|
|
680
|
-
viewbox?: string;
|
|
681
|
-
svg: SvgBuilder;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
/**
|
|
685
|
-
*
|
|
686
|
-
*/
|
|
687
|
-
|
|
688
|
-
export class SvgComponent<P extends SvgProps = SvgProps> extends Component<P> {
|
|
689
|
-
|
|
690
|
-
constructor( props: P ) {
|
|
691
|
-
super( { ...props, tag: "svg", ns: SVG_NS } );
|
|
692
|
-
|
|
693
|
-
this.setAttribute( 'xmlns', SVG_NS );
|
|
694
|
-
|
|
695
|
-
if( props.viewbox ) {
|
|
696
|
-
this.setAttribute( "viewBox", props.viewbox );
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
if( props.svg ) {
|
|
700
|
-
this.dom.appendChild( props.svg.getDom() );
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
setSvg( bld: SvgBuilder ) {
|
|
705
|
-
this.clearContent( );
|
|
706
|
-
this.dom.appendChild( bld.getDom() );
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
addItems( ...items: SvgItem[] ) {
|
|
710
|
-
items.forEach( item => this.dom.appendChild( item.getDom() ) );
|
|
711
|
-
}
|
|
712
|
-
}
|