x4js 1.4.3 → 1.4.4
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/index.d.ts +55 -0
- package/lib/index.js +55 -56
- package/lib/router.d.ts +1 -8
- package/lib/router.js +1 -1
- package/package.json +2 -1
- package/src/index.ts +55 -0
- package/src/router.ts +1 -1
- package/tsconfig.json +2 -1
- package/lib/application.d.ts +0 -95
- package/lib/application.js +0 -137
- package/lib/base64.d.ts +0 -31
- package/lib/base64.js +0 -135
- package/lib/base_component.d.ts +0 -64
- package/lib/base_component.js +0 -77
- package/lib/button.d.ts +0 -145
- package/lib/button.js +0 -235
- package/lib/calendar.d.ts +0 -77
- package/lib/calendar.js +0 -236
- package/lib/canvas.d.ts +0 -88
- package/lib/canvas.js +0 -354
- package/lib/cardview.d.ts +0 -83
- package/lib/cardview.js +0 -152
- package/lib/checkbox.d.ts +0 -72
- package/lib/checkbox.js +0 -126
- package/lib/color.d.ts +0 -144
- package/lib/color.js +0 -584
- package/lib/component.d.ts +0 -572
- package/lib/component.js +0 -1712
- package/lib/dom_events.d.ts +0 -284
- package/lib/dom_events.js +0 -13
- package/lib/hosts/host.d.ts +0 -44
- package/lib/hosts/host.js +0 -69
- package/lib/i18n.d.ts +0 -67
- package/lib/i18n.js +0 -169
- package/lib/icon.d.ts +0 -56
- package/lib/icon.js +0 -173
- package/lib/input.d.ts +0 -86
- package/lib/input.js +0 -172
- package/lib/label.d.ts +0 -54
- package/lib/label.js +0 -86
- package/lib/layout.d.ts +0 -77
- package/lib/layout.js +0 -261
- package/lib/list.txt +0 -56
- package/lib/menu.d.ts +0 -122
- package/lib/menu.js +0 -276
- package/lib/popup.d.ts +0 -71
- package/lib/popup.js +0 -373
- package/lib/settings.d.ts +0 -33
- package/lib/settings.js +0 -63
- package/lib/styles.d.ts +0 -81
- package/lib/styles.js +0 -262
- package/lib/tools.d.ts +0 -382
- package/lib/tools.js +0 -1096
- package/lib/x4_events.d.ts +0 -253
- package/lib/x4_events.js +0 -363
- package/list.txt +0 -0
package/lib/calendar.js
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / \____ _|
|
|
6
|
-
* /__/\__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file calendar.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
* @license
|
|
11
|
-
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* This program is free software; you can redistribute it and/or modify
|
|
14
|
-
* it under the terms of the GNU General Public License as published by
|
|
15
|
-
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
-
* (at your option) any later version.
|
|
17
|
-
*
|
|
18
|
-
* This program is distributed in the hope that it will be useful,
|
|
19
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
-
* GNU General Public License for more details.
|
|
22
|
-
*
|
|
23
|
-
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
-
**/
|
|
25
|
-
import { Button } from './button';
|
|
26
|
-
import { Popup } from './popup';
|
|
27
|
-
import { Component, Flex } from './component';
|
|
28
|
-
import { EvChange } from './x4_events';
|
|
29
|
-
import { _tr } from './i18n';
|
|
30
|
-
import { Label } from './label';
|
|
31
|
-
import { HLayout, VLayout } from './layout';
|
|
32
|
-
import { date_hash, date_clone, formatIntlDate } from './tools';
|
|
33
|
-
import { Menu, MenuItem } from './menu';
|
|
34
|
-
/**
|
|
35
|
-
* default calendar control
|
|
36
|
-
*
|
|
37
|
-
* fires:
|
|
38
|
-
* EventChange ( value = Date )
|
|
39
|
-
*/
|
|
40
|
-
export class Calendar extends VLayout {
|
|
41
|
-
m_date;
|
|
42
|
-
constructor(props) {
|
|
43
|
-
super(props);
|
|
44
|
-
this.mapPropEvents(props, 'change');
|
|
45
|
-
this.m_date = props.date?.clone() ?? new Date();
|
|
46
|
-
}
|
|
47
|
-
/** @ignore */
|
|
48
|
-
render(props) {
|
|
49
|
-
let month_start = date_clone(this.m_date);
|
|
50
|
-
month_start.setDate(1);
|
|
51
|
-
let day = month_start.getDay();
|
|
52
|
-
if (day == 0) {
|
|
53
|
-
day = 7;
|
|
54
|
-
}
|
|
55
|
-
month_start.setDate(-day + 1 + 1);
|
|
56
|
-
let dte = date_clone(month_start);
|
|
57
|
-
let today = this.m_date.hash();
|
|
58
|
-
let month_end = date_clone(this.m_date);
|
|
59
|
-
month_end.setDate(1);
|
|
60
|
-
month_end.setMonth(month_end.getMonth() + 1);
|
|
61
|
-
month_end.setDate(0);
|
|
62
|
-
let end_of_month = date_hash(month_end);
|
|
63
|
-
let rows = [];
|
|
64
|
-
// month selector
|
|
65
|
-
let header = new HLayout({
|
|
66
|
-
cls: 'month-sel',
|
|
67
|
-
content: [
|
|
68
|
-
new Label({
|
|
69
|
-
cls: 'month',
|
|
70
|
-
text: formatIntlDate(this.m_date, 'O'),
|
|
71
|
-
dom_events: {
|
|
72
|
-
click: () => this._choose('month')
|
|
73
|
-
}
|
|
74
|
-
}),
|
|
75
|
-
new Label({
|
|
76
|
-
cls: 'year',
|
|
77
|
-
text: formatIntlDate(this.m_date, 'Y'),
|
|
78
|
-
dom_events: {
|
|
79
|
-
click: () => this._choose('year')
|
|
80
|
-
}
|
|
81
|
-
}),
|
|
82
|
-
new Flex(),
|
|
83
|
-
new Button({ text: '<', click: () => this._next(false) }),
|
|
84
|
-
new Button({ text: '>', click: () => this._next(true) })
|
|
85
|
-
]
|
|
86
|
-
});
|
|
87
|
-
rows.push(header);
|
|
88
|
-
// calendar part
|
|
89
|
-
let day_names = [];
|
|
90
|
-
// day names
|
|
91
|
-
// empty week num
|
|
92
|
-
day_names.push(new HLayout({
|
|
93
|
-
cls: 'weeknum cell',
|
|
94
|
-
}));
|
|
95
|
-
for (let d = 0; d < 7; d++) {
|
|
96
|
-
day_names.push(new Label({
|
|
97
|
-
cls: 'cell',
|
|
98
|
-
flex: 1,
|
|
99
|
-
text: _tr.global.day_short[(d + 1) % 7]
|
|
100
|
-
}));
|
|
101
|
-
}
|
|
102
|
-
rows.push(new HLayout({
|
|
103
|
-
cls: 'week header',
|
|
104
|
-
content: day_names
|
|
105
|
-
}));
|
|
106
|
-
let cmonth = this.m_date.getMonth();
|
|
107
|
-
// weeks
|
|
108
|
-
let first = true;
|
|
109
|
-
while (date_hash(dte) <= end_of_month) {
|
|
110
|
-
let days = [
|
|
111
|
-
new HLayout({ cls: 'weeknum cell', content: new Component({ tag: 'span', content: formatIntlDate(dte, 'w') }) })
|
|
112
|
-
];
|
|
113
|
-
// days
|
|
114
|
-
for (let d = 0; d < 7; d++) {
|
|
115
|
-
let cls = 'cell day';
|
|
116
|
-
if (dte.hash() == today) {
|
|
117
|
-
cls += ' today';
|
|
118
|
-
}
|
|
119
|
-
if (dte.getMonth() != cmonth) {
|
|
120
|
-
cls += ' out';
|
|
121
|
-
}
|
|
122
|
-
days.push(new HLayout({
|
|
123
|
-
cls,
|
|
124
|
-
flex: 1,
|
|
125
|
-
content: new Component({
|
|
126
|
-
tag: 'span',
|
|
127
|
-
content: formatIntlDate(dte, 'd'),
|
|
128
|
-
}),
|
|
129
|
-
dom_events: {
|
|
130
|
-
click: () => this.select(dte.clone())
|
|
131
|
-
}
|
|
132
|
-
}));
|
|
133
|
-
dte.setDate(dte.getDate() + 1);
|
|
134
|
-
first = false;
|
|
135
|
-
}
|
|
136
|
-
rows.push(new HLayout({
|
|
137
|
-
cls: 'week',
|
|
138
|
-
flex: 1,
|
|
139
|
-
content: days
|
|
140
|
-
}));
|
|
141
|
-
}
|
|
142
|
-
this.setContent(rows);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* select the given date
|
|
146
|
-
* @param date
|
|
147
|
-
*/
|
|
148
|
-
select(date) {
|
|
149
|
-
this.m_date = date;
|
|
150
|
-
this.emit('change', EvChange(date));
|
|
151
|
-
this.update();
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
*
|
|
155
|
-
*/
|
|
156
|
-
_next(n) {
|
|
157
|
-
this.m_date.setMonth(this.m_date.getMonth() + (n ? 1 : -1));
|
|
158
|
-
this.update();
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
*
|
|
162
|
-
*/
|
|
163
|
-
_choose(type) {
|
|
164
|
-
let items = [];
|
|
165
|
-
if (type == 'month') {
|
|
166
|
-
for (let m = 0; m < 12; m++) {
|
|
167
|
-
items.push(new MenuItem({
|
|
168
|
-
text: _tr.global.month_long[m],
|
|
169
|
-
click: () => { this.m_date.setMonth(m); this.update(); }
|
|
170
|
-
}));
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
else if (type == 'year') {
|
|
174
|
-
let min = this.m_props.minDate?.getFullYear() ?? 1900;
|
|
175
|
-
let max = this.m_props.maxDate?.getFullYear() ?? 2037;
|
|
176
|
-
for (let m = min; m < max; m++) {
|
|
177
|
-
items.push(new MenuItem({
|
|
178
|
-
text: '' + m,
|
|
179
|
-
click: () => { this.m_date.setFullYear(m); this.update(); }
|
|
180
|
-
}));
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
let menu = new Menu({
|
|
184
|
-
items
|
|
185
|
-
});
|
|
186
|
-
let rc = this.getBoundingRect();
|
|
187
|
-
menu.displayAt(rc.left, rc.top);
|
|
188
|
-
}
|
|
189
|
-
get date() {
|
|
190
|
-
return this.m_date;
|
|
191
|
-
}
|
|
192
|
-
set date(date) {
|
|
193
|
-
this.m_date = date;
|
|
194
|
-
this.update();
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* default popup calendar
|
|
199
|
-
*/
|
|
200
|
-
export class PopupCalendar extends Popup {
|
|
201
|
-
m_cal;
|
|
202
|
-
constructor(props) {
|
|
203
|
-
super({ tabIndex: 1 });
|
|
204
|
-
this.enableMask(false);
|
|
205
|
-
this.m_cal = new Calendar(props);
|
|
206
|
-
this.m_cal.addClass('@fit');
|
|
207
|
-
this.setContent(this.m_cal);
|
|
208
|
-
}
|
|
209
|
-
// binded
|
|
210
|
-
_handleClick = (e) => {
|
|
211
|
-
if (!this.dom) {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
let newfocus = e.target;
|
|
215
|
-
// child of this: ok
|
|
216
|
-
if (this.dom.contains(newfocus)) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
// menu: ok
|
|
220
|
-
let dest = Component.getElement(newfocus, MenuItem);
|
|
221
|
-
if (dest) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
this.close();
|
|
225
|
-
};
|
|
226
|
-
/** @ignore */
|
|
227
|
-
show(modal) {
|
|
228
|
-
document.addEventListener('mousedown', this._handleClick);
|
|
229
|
-
super.show(modal);
|
|
230
|
-
}
|
|
231
|
-
/** @ignore */
|
|
232
|
-
close() {
|
|
233
|
-
document.removeEventListener('mousedown', this._handleClick);
|
|
234
|
-
super.close();
|
|
235
|
-
}
|
|
236
|
-
}
|
package/lib/canvas.d.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / \____ _|
|
|
6
|
-
* /__/\__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file canvas.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
* @license
|
|
11
|
-
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* This program is free software; you can redistribute it and/or modify
|
|
14
|
-
* it under the terms of the GNU General Public License as published by
|
|
15
|
-
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
-
* (at your option) any later version.
|
|
17
|
-
*
|
|
18
|
-
* This program is distributed in the hope that it will be useful,
|
|
19
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
-
* GNU General Public License for more details.
|
|
22
|
-
*
|
|
23
|
-
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
-
**/
|
|
25
|
-
import { Component, CProps, CEventMap } from './component';
|
|
26
|
-
import { BasicEvent, EventCallback } from './x4_events';
|
|
27
|
-
interface EvPaint extends BasicEvent {
|
|
28
|
-
ctx: CanvasPainter;
|
|
29
|
-
}
|
|
30
|
-
declare function EvPaint(ctx: CanvasPainter): EvPaint;
|
|
31
|
-
interface CanvasEventMap extends CEventMap {
|
|
32
|
-
paint: EvPaint;
|
|
33
|
-
}
|
|
34
|
-
interface CanvasProps extends CProps<CanvasEventMap> {
|
|
35
|
-
autoClear?: boolean;
|
|
36
|
-
painter?: PaintHandler;
|
|
37
|
-
paint: EventCallback<EvPaint>;
|
|
38
|
-
}
|
|
39
|
-
export interface CanvasPainter extends CanvasRenderingContext2D {
|
|
40
|
-
width: number;
|
|
41
|
-
height: number;
|
|
42
|
-
smoothLine(points: any[], path: CanvasPath, move: boolean): void;
|
|
43
|
-
smoothLineEx(_points: any[], tension: number, numOfSeg: number, path: CanvasPath, move?: boolean, close?: boolean): void;
|
|
44
|
-
line(x1: number, y1: number, x2: number, y2: number, color: string, lineWidth: number): void;
|
|
45
|
-
roundRect(x: number, y: number, width: number, height: number, radius: number): void;
|
|
46
|
-
calcTextSize(text: string, rounded: boolean): {
|
|
47
|
-
width: number;
|
|
48
|
-
height: number;
|
|
49
|
-
};
|
|
50
|
-
setFontSize(fs: number): void;
|
|
51
|
-
circle(x: number, y: number, radius: number): void;
|
|
52
|
-
}
|
|
53
|
-
declare type PaintHandler = (ctx: CanvasPainter) => any;
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
*/
|
|
57
|
-
/**
|
|
58
|
-
* Standard Canvas
|
|
59
|
-
*/
|
|
60
|
-
export declare class Canvas extends Component<CanvasProps, CanvasEventMap> {
|
|
61
|
-
private m_iwidth;
|
|
62
|
-
private m_iheight;
|
|
63
|
-
private m_scale;
|
|
64
|
-
private m_canvas;
|
|
65
|
-
constructor(props: CanvasProps);
|
|
66
|
-
/** @ignore */
|
|
67
|
-
render(): void;
|
|
68
|
-
update(delay?: number): void;
|
|
69
|
-
/**
|
|
70
|
-
* scale the whole canvas
|
|
71
|
-
*/
|
|
72
|
-
scale(scale: number): void;
|
|
73
|
-
/**
|
|
74
|
-
* return the internal canvas
|
|
75
|
-
*/
|
|
76
|
-
get canvas(): Component;
|
|
77
|
-
/**
|
|
78
|
-
* redraw the canvas (force a paint)
|
|
79
|
-
*/
|
|
80
|
-
private $update_rep;
|
|
81
|
-
redraw(wait?: number): void;
|
|
82
|
-
/**
|
|
83
|
-
*
|
|
84
|
-
*/
|
|
85
|
-
private _paint;
|
|
86
|
-
protected paint(ctx: CanvasPainter): void;
|
|
87
|
-
}
|
|
88
|
-
export {};
|
package/lib/canvas.js
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / \____ _|
|
|
6
|
-
* /__/\__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file canvas.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
* @license
|
|
11
|
-
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* This program is free software; you can redistribute it and/or modify
|
|
14
|
-
* it under the terms of the GNU General Public License as published by
|
|
15
|
-
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
-
* (at your option) any later version.
|
|
17
|
-
*
|
|
18
|
-
* This program is distributed in the hope that it will be useful,
|
|
19
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
-
* GNU General Public License for more details.
|
|
22
|
-
*
|
|
23
|
-
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
-
**/
|
|
25
|
-
import { Component } from './component';
|
|
26
|
-
import { BasicEvent } from './x4_events';
|
|
27
|
-
function EvPaint(ctx) {
|
|
28
|
-
return BasicEvent({ ctx });
|
|
29
|
-
}
|
|
30
|
-
function mkPainter(c2d, w, h) {
|
|
31
|
-
let cp = c2d;
|
|
32
|
-
cp.width = w;
|
|
33
|
-
cp.height = h;
|
|
34
|
-
cp.smoothLine = smoothLine;
|
|
35
|
-
cp.smoothLineEx = smoothLineEx;
|
|
36
|
-
cp.line = line;
|
|
37
|
-
cp.roundRect = roundRect;
|
|
38
|
-
cp.calcTextSize = calcTextSize;
|
|
39
|
-
cp.setFontSize = setFontSize;
|
|
40
|
-
cp.circle = circle;
|
|
41
|
-
return cp;
|
|
42
|
-
}
|
|
43
|
-
function smoothLine(points, path = null, move = true) {
|
|
44
|
-
if (points.length < 2) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (!path) {
|
|
48
|
-
path = this;
|
|
49
|
-
}
|
|
50
|
-
if (points.length == 2) {
|
|
51
|
-
if (move !== false) {
|
|
52
|
-
path.moveTo(points[0].x, points[0].y);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
path.lineTo(points[0].x, points[0].y);
|
|
56
|
-
}
|
|
57
|
-
path.lineTo(points[1].x, points[1].y);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
function midPointBtw(p1, p2) {
|
|
61
|
-
return {
|
|
62
|
-
x: p1.x + (p2.x - p1.x) / 2,
|
|
63
|
-
y: p1.y + (p2.y - p1.y) / 2
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function getQuadraticXY(t, sx, sy, cp1x, cp1y, ex, ey) {
|
|
67
|
-
return {
|
|
68
|
-
x: (1 - t) * (1 - t) * sx + 2 * (1 - t) * t * cp1x + t * t * ex,
|
|
69
|
-
y: (1 - t) * (1 - t) * sy + 2 * (1 - t) * t * cp1y + t * t * ey
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
let p1 = points[0], p2 = points[1], p3 = p1;
|
|
73
|
-
path.moveTo(p1.x, p1.y);
|
|
74
|
-
for (let i = 1, len = points.length; i < len; i++) {
|
|
75
|
-
// we pick the point between pi+1 & pi+2 as the
|
|
76
|
-
// end point and p1 as our control point
|
|
77
|
-
let midPoint = midPointBtw(p1, p2);
|
|
78
|
-
//this.quadraticCurveTo(p1.x, p1.y, midPoint.x, midPoint.y);
|
|
79
|
-
for (let i = 0; i < 8; i++) {
|
|
80
|
-
let { x, y } = getQuadraticXY(i / 8, p3.x, p3.y, p1.x, p1.y, midPoint.x, midPoint.y);
|
|
81
|
-
path.lineTo(x, y);
|
|
82
|
-
}
|
|
83
|
-
p1 = points[i];
|
|
84
|
-
p2 = points[i + 1];
|
|
85
|
-
p3 = midPoint;
|
|
86
|
-
}
|
|
87
|
-
// Draw last line as a straight line while
|
|
88
|
-
// we wait for the next point to be able to calculate
|
|
89
|
-
// the bezier control point
|
|
90
|
-
path.lineTo(p1.x, p1.y);
|
|
91
|
-
}
|
|
92
|
-
function smoothLineEx(_points, tension = 0.5, numOfSeg = 10, path = null, move = true, close = false) {
|
|
93
|
-
let points = [];
|
|
94
|
-
//pts = points.slice(0);
|
|
95
|
-
for (let p = 0, pc = _points.length; p < pc; p++) {
|
|
96
|
-
points.push(_points[p].x);
|
|
97
|
-
points.push(_points[p].y);
|
|
98
|
-
}
|
|
99
|
-
let pts, i = 1, l = points.length, rPos = 0, rLen = (l - 2) * numOfSeg + 2 + (close ? 2 * numOfSeg : 0), res = new Float32Array(rLen), cache = new Float32Array((numOfSeg + 2) * 4), cachePtr = 4;
|
|
100
|
-
pts = points.slice(0);
|
|
101
|
-
if (close) {
|
|
102
|
-
pts.unshift(points[l - 1]); // insert end point as first point
|
|
103
|
-
pts.unshift(points[l - 2]);
|
|
104
|
-
pts.push(points[0], points[1]); // first point as last point
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
pts.unshift(points[1]); // copy 1. point and insert at beginning
|
|
108
|
-
pts.unshift(points[0]);
|
|
109
|
-
pts.push(points[l - 2], points[l - 1]); // duplicate end-points
|
|
110
|
-
}
|
|
111
|
-
// cache inner-loop calculations as they are based on t alone
|
|
112
|
-
cache[0] = 1; // 1,0,0,0
|
|
113
|
-
for (; i < numOfSeg; i++) {
|
|
114
|
-
var st = i / numOfSeg, st2 = st * st, st3 = st2 * st, st23 = st3 * 2, st32 = st2 * 3;
|
|
115
|
-
cache[cachePtr++] = st23 - st32 + 1; // c1
|
|
116
|
-
cache[cachePtr++] = st32 - st23; // c2
|
|
117
|
-
cache[cachePtr++] = st3 - 2 * st2 + st; // c3
|
|
118
|
-
cache[cachePtr++] = st3 - st2; // c4
|
|
119
|
-
}
|
|
120
|
-
cache[cachePtr] = 1; // 0,1,0,0
|
|
121
|
-
// calc. points
|
|
122
|
-
parse(pts, cache, l);
|
|
123
|
-
if (close) {
|
|
124
|
-
//l = points.length;
|
|
125
|
-
pts = [];
|
|
126
|
-
pts.push(points[l - 4], points[l - 3], points[l - 2], points[l - 1]); // second last and last
|
|
127
|
-
pts.push(points[0], points[1], points[2], points[3]); // first and second
|
|
128
|
-
parse(pts, cache, 4);
|
|
129
|
-
}
|
|
130
|
-
function parse(pts, cache, l) {
|
|
131
|
-
for (var i = 2, t; i < l; i += 2) {
|
|
132
|
-
var pt1 = pts[i], pt2 = pts[i + 1], pt3 = pts[i + 2], pt4 = pts[i + 3], t1x = (pt3 - pts[i - 2]) * tension, t1y = (pt4 - pts[i - 1]) * tension, t2x = (pts[i + 4] - pt1) * tension, t2y = (pts[i + 5] - pt2) * tension;
|
|
133
|
-
for (t = 0; t < numOfSeg; t++) {
|
|
134
|
-
var c = t << 2, //t * 4;
|
|
135
|
-
c1 = cache[c], c2 = cache[c + 1], c3 = cache[c + 2], c4 = cache[c + 3];
|
|
136
|
-
res[rPos++] = c1 * pt1 + c2 * pt3 + c3 * t1x + c4 * t2x;
|
|
137
|
-
res[rPos++] = c1 * pt2 + c2 * pt4 + c3 * t1y + c4 * t2y;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
// add last point
|
|
142
|
-
l = close ? 0 : points.length - 2;
|
|
143
|
-
res[rPos++] = points[l];
|
|
144
|
-
res[rPos] = points[l + 1];
|
|
145
|
-
if (!path) {
|
|
146
|
-
path = this;
|
|
147
|
-
}
|
|
148
|
-
// add lines to path
|
|
149
|
-
for (let i = 0, l = res.length; i < l; i += 2) {
|
|
150
|
-
if (i == 0 && move !== false) {
|
|
151
|
-
path.moveTo(res[i], res[i + 1]);
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
path.lineTo(res[i], res[i + 1]);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
function line(x1, y1, x2, y2, color, lineWidth = 1) {
|
|
159
|
-
this.save();
|
|
160
|
-
this.beginPath();
|
|
161
|
-
this.moveTo(x1, y1);
|
|
162
|
-
this.lineTo(x2, y2);
|
|
163
|
-
this.lineWidth = lineWidth;
|
|
164
|
-
this.strokeStyle = color;
|
|
165
|
-
this.stroke();
|
|
166
|
-
this.restore();
|
|
167
|
-
}
|
|
168
|
-
function roundRect(x, y, width, height, radius) {
|
|
169
|
-
//this.beginPath( );
|
|
170
|
-
this.moveTo(x + radius, y);
|
|
171
|
-
this.lineTo(x + width - radius, y);
|
|
172
|
-
this.quadraticCurveTo(x + width, y, x + width, y + radius);
|
|
173
|
-
this.lineTo(x + width, y + height - radius);
|
|
174
|
-
this.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
|
|
175
|
-
this.lineTo(x + radius, y + height);
|
|
176
|
-
this.quadraticCurveTo(x, y + height, x, y + height - radius);
|
|
177
|
-
this.lineTo(x, y + radius);
|
|
178
|
-
this.quadraticCurveTo(x, y, x + radius, y);
|
|
179
|
-
this.closePath();
|
|
180
|
-
}
|
|
181
|
-
function calcTextSize(text, rounded = false) {
|
|
182
|
-
let fh = this.measureText(text);
|
|
183
|
-
let lh = fh.fontBoundingBoxAscent + fh.fontBoundingBoxDescent;
|
|
184
|
-
if (rounded) {
|
|
185
|
-
return { width: Math.round(fh.width), height: Math.round(lh) };
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
return { width: fh.width, height: lh };
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
function setFontSize(fs) {
|
|
192
|
-
let fsize = Math.round(fs) + 'px';
|
|
193
|
-
this.font = this.font.replace(/\d+px/, fsize);
|
|
194
|
-
}
|
|
195
|
-
function circle(x, y, radius) {
|
|
196
|
-
this.moveTo(x + radius, y);
|
|
197
|
-
this.arc(x, y, radius, 0, Math.PI * 2);
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
*
|
|
201
|
-
*/
|
|
202
|
-
//export class CanvasProps extends CProps
|
|
203
|
-
//{
|
|
204
|
-
// low level handlers
|
|
205
|
-
//mousedown?: (ev: MouseEvent) => any;
|
|
206
|
-
//mousemove?: (ev: MouseEvent) => any;
|
|
207
|
-
//mouseup?: (ev: MouseEvent) => any;
|
|
208
|
-
//mouseleave?: (ev: MouseEvent) => any;
|
|
209
|
-
//mousewheel?: (ev: WheelEvent) => any;
|
|
210
|
-
//click?: (ev: MouseEvent) => any;
|
|
211
|
-
//dblclick?: (ev: MouseEvent) => any;
|
|
212
|
-
//touchstart?: (ev: TouchEvent) => any;
|
|
213
|
-
//touchmove?: (ev: TouchEvent) => any;
|
|
214
|
-
//touchend?: (ev: TouchEvent) => any;
|
|
215
|
-
//keydown?: (ev: KeyboardEvent) => any;
|
|
216
|
-
//keyup?: (ev: KeyboardEvent) => any;
|
|
217
|
-
//}
|
|
218
|
-
/**
|
|
219
|
-
* Standard Canvas
|
|
220
|
-
*/
|
|
221
|
-
export class Canvas extends Component {
|
|
222
|
-
m_iwidth = -1;
|
|
223
|
-
m_iheight = -1;
|
|
224
|
-
m_scale = 1.0;
|
|
225
|
-
m_canvas;
|
|
226
|
-
constructor(props) {
|
|
227
|
-
super(props);
|
|
228
|
-
//if( props.mousedown ) { this.setDomEvent( 'mousedown', props.mousedown ); }
|
|
229
|
-
//if( props.mousemove ) { this.setDomEvent( 'mousemove', props.mousemove ); }
|
|
230
|
-
//if( props.mouseup ) { this.setDomEvent( 'mouseup', props.mouseup ); }
|
|
231
|
-
//if( props.mousewheel ) { this.setDomEvent( 'wheel', props.mousewheel ); }
|
|
232
|
-
//if( props.mouseleave ) { this.setDomEvent( 'mouseleave', props.mouseleave ); }
|
|
233
|
-
//if( props.click ) { this.setDomEvent( 'click', props.click ); }
|
|
234
|
-
//if( props.dblclick ) { this.setDomEvent( 'dblclick', props.dblclick ); }
|
|
235
|
-
//if( props.touchstart ) { this.setDomEvent( 'touchstart', props.touchstart ); }
|
|
236
|
-
//if( props.touchmove ) { this.setDomEvent( 'touchmove', props.touchmove ); }
|
|
237
|
-
//if( props.touchend ) { this.setDomEvent( 'touchend', props.touchend ); }
|
|
238
|
-
//if( props.keydown ) { this.setDomEvent( 'keydown', props.keydown ); this.setAttribute( 'tabindex', 0 ); }
|
|
239
|
-
//if( props.keyup ) { this.setDomEvent( 'keyup', props.keyup ); this.setAttribute( 'tabindex', 0 ); }
|
|
240
|
-
//if( props.paint ) { this.onPaint( props.paint ); }
|
|
241
|
-
this.setDomEvent('sizechange', () => { this._paint(); });
|
|
242
|
-
this.mapPropEvents(props, 'paint');
|
|
243
|
-
}
|
|
244
|
-
/** @ignore */
|
|
245
|
-
render() {
|
|
246
|
-
this.m_iwidth = -1;
|
|
247
|
-
this.m_iheight = -1;
|
|
248
|
-
this.m_canvas = new Component({
|
|
249
|
-
tag: 'canvas'
|
|
250
|
-
});
|
|
251
|
-
this.setContent(this.m_canvas);
|
|
252
|
-
// this.redraw(10);
|
|
253
|
-
}
|
|
254
|
-
update(delay = 0) {
|
|
255
|
-
this.m_iheight = this.m_iwidth = -1;
|
|
256
|
-
super.update(delay);
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* scale the whole canvas
|
|
260
|
-
*/
|
|
261
|
-
scale(scale) {
|
|
262
|
-
this.m_scale = scale;
|
|
263
|
-
this.m_iwidth = -1; // force recalc
|
|
264
|
-
this.redraw();
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* return the internal canvas
|
|
268
|
-
*/
|
|
269
|
-
get canvas() {
|
|
270
|
-
return this.m_canvas;
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* redraw the canvas (force a paint)
|
|
274
|
-
*/
|
|
275
|
-
$update_rep = 0;
|
|
276
|
-
redraw(wait) {
|
|
277
|
-
if (wait !== undefined) {
|
|
278
|
-
if (++this.$update_rep >= 20) {
|
|
279
|
-
this.stopTimer('update');
|
|
280
|
-
this._paint();
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
this.startTimer('update', wait, false, () => this._paint());
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
this.stopTimer('update');
|
|
288
|
-
this._paint();
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
*
|
|
293
|
-
*/
|
|
294
|
-
_paint() {
|
|
295
|
-
this.$update_rep = 0;
|
|
296
|
-
let dom = this.dom;
|
|
297
|
-
if (!this.isUserVisible()) {
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
let canvas = this.m_canvas.dom, w = dom.clientWidth, h = dom.clientHeight;
|
|
301
|
-
let ctx = canvas.getContext('2d');
|
|
302
|
-
if (w != this.m_iwidth || h != this.m_iheight) {
|
|
303
|
-
// adjustment for HDPI
|
|
304
|
-
let devicePixelRatio = window.devicePixelRatio || 1;
|
|
305
|
-
let backingStoreRatio = ctx.webkitBackingStorePixelRatio ||
|
|
306
|
-
ctx.mozBackingStorePixelRatio ||
|
|
307
|
-
ctx.msBackingStorePixelRatio ||
|
|
308
|
-
ctx.oBackingStorePixelRatio ||
|
|
309
|
-
ctx.backingStorePixelRatio || 1;
|
|
310
|
-
let canvas = this.canvas;
|
|
311
|
-
if (devicePixelRatio !== backingStoreRatio || this.m_scale != 1.0) {
|
|
312
|
-
let ratio = devicePixelRatio / backingStoreRatio, rw = w * ratio, rh = h * ratio;
|
|
313
|
-
canvas.setAttribute('width', '' + rw);
|
|
314
|
-
canvas.setAttribute('height', '' + rh);
|
|
315
|
-
canvas.setStyleValue('width', w);
|
|
316
|
-
canvas.setStyleValue('height', h);
|
|
317
|
-
ratio *= this.m_scale;
|
|
318
|
-
ctx.scale(ratio, ratio);
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
canvas.setAttribute('width', '' + w);
|
|
322
|
-
canvas.setAttribute('height', '' + h);
|
|
323
|
-
canvas.setStyleValue('width', w);
|
|
324
|
-
canvas.setStyleValue('height', h);
|
|
325
|
-
ctx.scale(1, 1);
|
|
326
|
-
}
|
|
327
|
-
this.m_iwidth = w;
|
|
328
|
-
this.m_iheight = h;
|
|
329
|
-
}
|
|
330
|
-
if (w && h) {
|
|
331
|
-
let cc = mkPainter(ctx, w, h);
|
|
332
|
-
if (this.m_props.autoClear) {
|
|
333
|
-
cc.clearRect(0, 0, w, h);
|
|
334
|
-
}
|
|
335
|
-
cc.save();
|
|
336
|
-
cc.translate(-0.5, -0.5);
|
|
337
|
-
this.paint(cc);
|
|
338
|
-
cc.restore();
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
paint(ctx) {
|
|
342
|
-
try {
|
|
343
|
-
if (this.m_props.painter) {
|
|
344
|
-
this.m_props.painter(ctx);
|
|
345
|
-
}
|
|
346
|
-
else {
|
|
347
|
-
this.emit('paint', EvPaint(ctx));
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
catch (x) {
|
|
351
|
-
console.assert(false, x);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|