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.
Files changed (56) hide show
  1. package/lib/index.d.ts +55 -0
  2. package/lib/index.js +55 -56
  3. package/lib/router.d.ts +1 -8
  4. package/lib/router.js +1 -1
  5. package/package.json +2 -1
  6. package/src/index.ts +55 -0
  7. package/src/router.ts +1 -1
  8. package/tsconfig.json +2 -1
  9. package/lib/application.d.ts +0 -95
  10. package/lib/application.js +0 -137
  11. package/lib/base64.d.ts +0 -31
  12. package/lib/base64.js +0 -135
  13. package/lib/base_component.d.ts +0 -64
  14. package/lib/base_component.js +0 -77
  15. package/lib/button.d.ts +0 -145
  16. package/lib/button.js +0 -235
  17. package/lib/calendar.d.ts +0 -77
  18. package/lib/calendar.js +0 -236
  19. package/lib/canvas.d.ts +0 -88
  20. package/lib/canvas.js +0 -354
  21. package/lib/cardview.d.ts +0 -83
  22. package/lib/cardview.js +0 -152
  23. package/lib/checkbox.d.ts +0 -72
  24. package/lib/checkbox.js +0 -126
  25. package/lib/color.d.ts +0 -144
  26. package/lib/color.js +0 -584
  27. package/lib/component.d.ts +0 -572
  28. package/lib/component.js +0 -1712
  29. package/lib/dom_events.d.ts +0 -284
  30. package/lib/dom_events.js +0 -13
  31. package/lib/hosts/host.d.ts +0 -44
  32. package/lib/hosts/host.js +0 -69
  33. package/lib/i18n.d.ts +0 -67
  34. package/lib/i18n.js +0 -169
  35. package/lib/icon.d.ts +0 -56
  36. package/lib/icon.js +0 -173
  37. package/lib/input.d.ts +0 -86
  38. package/lib/input.js +0 -172
  39. package/lib/label.d.ts +0 -54
  40. package/lib/label.js +0 -86
  41. package/lib/layout.d.ts +0 -77
  42. package/lib/layout.js +0 -261
  43. package/lib/list.txt +0 -56
  44. package/lib/menu.d.ts +0 -122
  45. package/lib/menu.js +0 -276
  46. package/lib/popup.d.ts +0 -71
  47. package/lib/popup.js +0 -373
  48. package/lib/settings.d.ts +0 -33
  49. package/lib/settings.js +0 -63
  50. package/lib/styles.d.ts +0 -81
  51. package/lib/styles.js +0 -262
  52. package/lib/tools.d.ts +0 -382
  53. package/lib/tools.js +0 -1096
  54. package/lib/x4_events.d.ts +0 -253
  55. package/lib/x4_events.js +0 -363
  56. package/list.txt +0 -0
package/lib/styles.js DELETED
@@ -1,262 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \_/ / / _
4
- * \ / /_| |_
5
- * / _ \____ _|
6
- * /__/ \__\ |_|
7
- *
8
- * @file styles.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 { pascalCase, isString, isArray } from "./tools";
26
- /**
27
- * -- [ @STYLESHEET ] -----------------------------------------------------------------
28
- */
29
- export class Stylesheet {
30
- m_sheet;
31
- m_rules = new Map();
32
- constructor() {
33
- function getStyleSheet(name) {
34
- for (let i = 0; i < document.styleSheets.length; i++) {
35
- let sheet = document.styleSheets[i];
36
- if (sheet.title === name) {
37
- return sheet;
38
- }
39
- }
40
- }
41
- this.m_sheet = getStyleSheet('@dynamic-css');
42
- if (!this.m_sheet) {
43
- let dom = document.createElement('style');
44
- dom.setAttribute('id', '@dynamic-css');
45
- document.head.appendChild(dom);
46
- this.m_sheet = dom.sheet;
47
- }
48
- }
49
- /**
50
- * add a new rule to the style sheet
51
- * @param {string} name - internal rule name
52
- * @param {string} definition - css definition of the rule
53
- * @example
54
- * setRule('xbody', "body { background-color: #ff0000; }" );
55
- */
56
- setRule(name, definition) {
57
- if (isString(definition)) {
58
- let index = this.m_rules.get(name);
59
- if (index !== undefined) {
60
- this.m_sheet.deleteRule(index);
61
- }
62
- else {
63
- index = this.m_sheet.cssRules.length;
64
- }
65
- this.m_rules.set(name, this.m_sheet.insertRule(definition, index));
66
- }
67
- else {
68
- let idx = 1;
69
- for (let r in definition) {
70
- let rule = r + " { ", css = definition[r];
71
- for (let i in css) {
72
- let values = css[i]; // this is an array !
73
- for (let j = 0; j < values.length; j++) {
74
- rule += i + ": " + values[j] + "; ";
75
- }
76
- }
77
- rule += '}';
78
- console.log(rule);
79
- this.setRule(name + '--' + idx, rule);
80
- idx++;
81
- }
82
- }
83
- }
84
- /**
85
- * return the style variable value
86
- * @param name - variable name without '--'
87
- * @example
88
- * ```
89
- * let color = Component.getCss( ).getVar( 'button-color' );
90
- * ```
91
- */
92
- static getVar(name) {
93
- if (!Stylesheet.doc_style) {
94
- Stylesheet.doc_style = getComputedStyle(document.documentElement);
95
- }
96
- return Stylesheet.doc_style.getPropertyValue('--' + name); // #999999
97
- }
98
- static guid = 1;
99
- static doc_style;
100
- }
101
- /**
102
- * -- [ @CSSPARSER ] -----------------------------------------------------------------
103
- *
104
- * adaptation of jss-for-node-js
105
- */
106
- export class CSSParser {
107
- result = {};
108
- parse(css) {
109
- this.result = {};
110
- this.parse_json('', css);
111
- return CSSParser.mk_string(this.result);
112
- }
113
- static mk_string(rules) {
114
- // output result:
115
- let ret = '';
116
- for (let a in rules) {
117
- let css = rules[a];
118
- ret += a + " { ";
119
- for (let i in css) {
120
- let values = css[i]; // this is an array !
121
- for (let j = 0; j < values.length; j++) {
122
- ret += i + ": " + values[j] + "; ";
123
- }
124
- }
125
- ret += "}\n";
126
- }
127
- return ret;
128
- }
129
- parse_json(scope, css) {
130
- if (scope && !this.result[scope]) {
131
- this.result[scope] = {};
132
- }
133
- for (let property in css) {
134
- let value = css[property];
135
- if (isArray(value)) {
136
- let values = value;
137
- for (let i = 0; i < values.length; i++) {
138
- this.addProperty(scope, property, values[i]);
139
- }
140
- }
141
- /*else if (value instanceof Color) {
142
- this.addProperty(scope, property, value.toString());
143
- }*/
144
- else {
145
- switch (typeof (value)) {
146
- case "number": {
147
- this.addProperty(scope, property, value);
148
- break;
149
- }
150
- case "string": {
151
- this.addProperty(scope, property, value);
152
- break;
153
- }
154
- case "object": {
155
- this.parse_json(this.makeSelectorName(scope, property), value);
156
- break;
157
- }
158
- default: {
159
- console.error("ignoring unknown type " + typeof (value) + " in property " + property);
160
- break;
161
- }
162
- }
163
- }
164
- }
165
- }
166
- makePropertyName(n) {
167
- return pascalCase(n);
168
- }
169
- makeSelectorName(scope, name) {
170
- let snames = [];
171
- let names = name.split(/\s*,\s*/);
172
- let scopes = scope.split(/\s*,\s*/);
173
- for (let s = 0; s < scopes.length; s++) {
174
- let scope = scopes[s];
175
- for (let i = 0; i < names.length; i++) {
176
- let name = names[i], sub = false;
177
- if (name.charAt(0) == "&") {
178
- name = name.substr(1);
179
- sub = true;
180
- }
181
- if (name.charAt(0) === '%') {
182
- name = '.o-' + name.substr(1);
183
- }
184
- if (sub) {
185
- snames.push(scope + name);
186
- }
187
- else {
188
- snames.push(scope ? scope + " " + name : name);
189
- }
190
- }
191
- }
192
- return snames.join(", ");
193
- }
194
- addProperty(scope, property, value) {
195
- let properties = property.split(/\s*,\s*/);
196
- for (let i = 0; i < properties.length; i++) {
197
- let property = this.makePropertyName(properties[i]);
198
- if (this.result[scope][property]) {
199
- this.result[scope][property].push(value);
200
- }
201
- else {
202
- this.result[scope][property] = [value];
203
- }
204
- let specials = {
205
- "box-shadow": [
206
- "-moz-box-shadow",
207
- "-webkit-box-shadow"
208
- ],
209
- "border-radius": [
210
- "-moz-border-radius",
211
- "-webkit-border-radius"
212
- ],
213
- "border-radius-topleft": [
214
- "-moz-border-radius-topleft",
215
- "-webkit-border-top-left-radius"
216
- ],
217
- "border-radius-topright": [
218
- "-moz-border-radius-topright",
219
- "-webkit-border-top-right-radius"
220
- ],
221
- "border-radius-bottomleft": [
222
- "-moz-border-radius-bottomleft",
223
- "-webkit-border-bottom-left-radius"
224
- ],
225
- "border-radius-bottomright": [
226
- "-moz-border-radius-bottomright",
227
- "-webkit-border-bottom-right-radius"
228
- ]
229
- };
230
- let browser_specials = specials[property];
231
- for (let j = 0; browser_specials && j < browser_specials.length; j++) {
232
- this.addProperty(scope, browser_specials[j], value);
233
- }
234
- }
235
- }
236
- }
237
- export class ComputedStyle {
238
- m_style;
239
- constructor(style) {
240
- this.m_style = style;
241
- }
242
- /**
243
- * return the raw value
244
- */
245
- value(name) {
246
- name = pascalCase(name);
247
- return this.m_style[name];
248
- }
249
- /**
250
- * return the interpreted value
251
- */
252
- parse(name) {
253
- name = pascalCase(name);
254
- return parseInt(this.m_style[name]);
255
- }
256
- /**
257
- *
258
- */
259
- get style() {
260
- return this.m_style;
261
- }
262
- }
package/lib/tools.d.ts DELETED
@@ -1,382 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \_/ / / _
4
- * \ / /_| |_
5
- * / _ \____ _|
6
- * /__/ \__\ |_|
7
- *
8
- * @file tools.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
- /**
26
- * @return true is the device has touch
27
- */
28
- export declare function isTouchDevice(): boolean;
29
- /**
30
- * round to a given number of decimals
31
- * @param num numbre to round
32
- * @param ndec number of decimals
33
- * @returns number rounded
34
- */
35
- export declare function roundTo(num: number, ndec: number): number;
36
- /**
37
- * parse an intl formatted number
38
- * understand grouping and ',' separator
39
- * @review us format: grouping = ','
40
- * @param num
41
- */
42
- export declare function parseIntlFloat(num: string): number;
43
- /**
44
- * inverse of camel case
45
- * theThingToCase -> the-thing-to-case
46
- * @param {String} str
47
- */
48
- export declare function pascalCase(string: string): string;
49
- export declare type Constructor<T> = new (...args: any[]) => T;
50
- export declare class Point {
51
- x: number;
52
- y: number;
53
- constructor(x?: number, y?: number);
54
- }
55
- export declare class Size {
56
- width: number;
57
- height: number;
58
- constructor(w?: number, h?: number);
59
- }
60
- export declare class Rect {
61
- left: number;
62
- top: number;
63
- width: number;
64
- height: number;
65
- constructor();
66
- constructor(rc: Rect);
67
- constructor(rc: DOMRect);
68
- constructor(left: number, top: number, width: number, height: number);
69
- set(left: number, top: number, width: number, height: number): void;
70
- get bottom(): number;
71
- set bottom(bottom: number);
72
- get right(): number;
73
- set right(right: number);
74
- get topLeft(): Point;
75
- get bottomRight(): Point;
76
- get size(): Size;
77
- moveTo(left: number, top: number): this;
78
- movedTo(left: number, top: number): Rect;
79
- moveBy(dx: number, dy: number): this;
80
- movedBy(dx: number, dy: number): Rect;
81
- isEmpty(): boolean;
82
- normalize(): this;
83
- normalized(): Rect;
84
- /**
85
- * @deprecated
86
- */
87
- containsPt(x: number, y: number): boolean;
88
- contains(pt: Point): boolean;
89
- contains(rc: Rect): boolean;
90
- touches(rc: Rect): boolean;
91
- inflate(dx: number, dy?: number): void;
92
- inflatedBy(dx: number, dy?: number): Rect;
93
- combine(rc: Rect): void;
94
- }
95
- /**
96
- * replace {0..9} by given arguments
97
- * @param format string
98
- * @param args
99
- *
100
- * @example ```ts
101
- *
102
- * console.log( sprintf( 'here is arg 1 {1} and arg 0 {0}', 'argument 0', 'argument 1' ) )
103
- */
104
- export declare function sprintf(format: string, ...args: any[]): string;
105
- /**
106
- * replace special characters for display
107
- * @param unsafe
108
- *
109
- * console.log( escapeHtml('<div style="width:50px; height: 50px; background-color:red"></div>') );
110
- */
111
- export declare function escapeHtml(unsafe: string, nl_br?: boolean): string;
112
- /**
113
- * replace special characters for display
114
- * @author Steven Levithan <http://slevithan.com/>
115
- * @param unsafe
116
- *
117
- * console.log( removeHtmlTags('<h1>sss</h1>') );
118
- */
119
- export declare function removeHtmlTags(unsafe: string, nl_br?: boolean): string;
120
- /**
121
- * change the current locale for misc translations (date...)
122
- * @param locale
123
- */
124
- export declare function _date_set_locale(locale: string): void;
125
- /**
126
- *
127
- * @param date
128
- * @param options
129
- * @example
130
- * let date = new Date( );
131
- * let options = { day: 'numeric', month: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric' };
132
- * let text = date_format( date, options );
133
- */
134
- export declare function date_format(date: Date, options?: any): string;
135
- /**
136
- *
137
- * @param date
138
- * @param options
139
- */
140
- export declare function date_diff(date1: Date, date2: Date, options?: any): string;
141
- export declare function date_to_sql(date: Date, withHours: boolean): string;
142
- /**
143
- * construct a date from an utc date time (sql format)
144
- * YYYY-MM-DD HH:MM:SS
145
- */
146
- export declare function date_sql_utc(date: string): Date;
147
- /**
148
- * return a number that is a representation of the date
149
- * this number can be compared with another hash
150
- */
151
- export declare function date_hash(date: Date): number;
152
- /**
153
- * return a copy of a date
154
- */
155
- export declare function date_clone(date: Date): Date;
156
- /**
157
- * return the week number of a date
158
- */
159
- export declare function date_calc_weeknum(date: Date): number;
160
- /**
161
- * parse a date according to the given format
162
- * @param value - string date to parse
163
- * @param fmts - format list - i18 tranlation by default
164
- * allowed format specifiers:
165
- * d or D: date (1 or 2 digits)
166
- * m or M: month (1 or 2 digits)
167
- * y or Y: year (2 or 4 digits)
168
- * h or H: hours (1 or 2 digits)
169
- * i or I: minutes (1 or 2 digits)
170
- * s or S: seconds (1 or 2 digits)
171
- * <space>: 1 or more spaces
172
- * any other char: <0 or more spaces><the char><0 or more spaces>
173
- * each specifiers is separated from other by a pipe (|)
174
- * more specific at first
175
- * @example
176
- * 'd/m/y|d m Y|dmy|y-m-d h:i:s|y-m-d'
177
- */
178
- export declare function parseIntlDate(value: string, fmts?: string): Date;
179
- /**
180
- * format a date as string
181
- * @param date - date to format
182
- * @param fmt - format
183
- * format specifiers:
184
- * d: date
185
- * D: 2 digits date padded with 0
186
- * j: day of week short mode 'mon'
187
- * J: day of week long mode 'monday'
188
- * w: week number
189
- * m: month
190
- * M: 2 digits month padded with 0
191
- * o: month short mode 'jan'
192
- * O: month long mode 'january'
193
- * y or Y: year
194
- * h: hour (24 format)
195
- * H: 2 digits hour (24 format) padded with 0
196
- * i: minutes
197
- * I: 2 digits minutes padded with 0
198
- * s: seconds
199
- * S: 2 digits seconds padded with 0
200
- * a: am or pm
201
- * anything else is inserted
202
- * if you need to insert some text, put it between {}
203
- *
204
- * @example
205
- *
206
- * 01/01/1970 11:25:00 with '{this is my demo date formatter: }H-i*M'
207
- * "this is my demo date formatter: 11-25*january"
208
- */
209
- export declare function formatIntlDate(date: Date, fmt?: string): string;
210
- export declare function calcAge(birth: Date, ref?: Date): number;
211
- /**
212
- * date object patch
213
- */
214
- declare global {
215
- interface Date {
216
- hash(): number;
217
- clone(): Date;
218
- weekNum(): number;
219
- format(format: string): string;
220
- isSameDay(date: Date): boolean;
221
- addDays(days: number): any;
222
- }
223
- }
224
- /**
225
- *
226
- * @param data data to export
227
- * @param mimetype - 'text/plain'
228
- */
229
- export declare function downloadData(data: any, mimetype: string, filename: string): void;
230
- /**
231
- * check if a value is a string
232
- * @param val
233
- */
234
- export declare function isString(val: any): val is string;
235
- /**
236
- * check is a value is an array
237
- * @param val
238
- */
239
- export declare function isArray(val: any): val is any[];
240
- /**
241
- *
242
- */
243
- export declare function isFunction(val: any): val is Function;
244
- /**
245
- *
246
- */
247
- export declare function isLiteralObject(val: any): boolean;
248
- /**
249
- * prepend 0 to a value to a given length
250
- * @param value
251
- * @param length
252
- */
253
- export declare function pad(what: unknown, size: number, ch?: string): string;
254
- /**
255
- * return true if val is a finite number
256
- */
257
- export declare function isNumber(val: any): val is number;
258
- /**
259
- *
260
- * @param name
261
- */
262
- export declare function waitFontLoading(name: string): Promise<void>;
263
- /**
264
- *
265
- * @param fn
266
- * @param tm
267
- *
268
- * @example:
269
- *
270
- * defer( ( ) => {
271
- * console.log( x );
272
- * } )( );
273
- */
274
- export declare function deferCall(fn: Function, tm?: number, ...args: any[]): void;
275
- /**
276
- *
277
- */
278
- export declare function asap(cb: (time: number) => void): void;
279
- /**
280
- * micro md to html
281
- *
282
- * understand:
283
- * **bold**
284
- * *italic*
285
- *
286
- * > quote
287
- * - list
288
- * # title lvl 1
289
- * ## title lvl 2
290
- * ### title lvl 3 ...
291
- *
292
- */
293
- export declare function markdownToHtml(text: string): string;
294
- /**
295
- *
296
- */
297
- export declare class NetworkError extends Error {
298
- private m_code;
299
- constructor(response: Response);
300
- constructor(code: number, text: string);
301
- get code(): number;
302
- }
303
- /**
304
- * return the mouse pos in client coordinates
305
- * handle correctly touch & mouse
306
- */
307
- export declare function getMousePos(ev: UIEvent, fromDoc: boolean): Point;
308
- /**
309
- * clamp a value
310
- * @param v - value to clamp
311
- * @param min - min value
312
- * @param max - max value
313
- * @returns clamped value
314
- */
315
- export declare function clamp(v: number, min: number, max: number): number;
316
- /**
317
- *
318
- */
319
- export interface IDisposable {
320
- dispose(): any;
321
- }
322
- export declare class HtmlString extends String {
323
- constructor(text: string);
324
- static from(text: string): HtmlString;
325
- }
326
- export declare function html(a: any, ...b: any[]): HtmlString;
327
- export declare function isHtmlString(val: any): val is HtmlString;
328
- export declare class Clipboard {
329
- static copy(data: any): void;
330
- static paste(cb: (data: string) => void): void;
331
- }
332
- /**
333
- * Calculates the CRC32 checksum of a string.
334
- * taken from: https://gist.github.com/wqli78/1330293/6d85cc967f32cccfcbad94ae7d088a3dcfc14bd9
335
- *
336
- * @param {String} str
337
- * @param {Boolean} hex
338
- * @return {String} checksum
339
- * @api public
340
- */
341
- export declare function crc32(str: any): number;
342
- /**
343
- * taken from this excellent article:
344
- * https://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/
345
- *
346
- * @example:
347
- * class MyClass extends mix(MyBaseClass).with(Mixin1, Mixin2) {
348
- * }
349
- **/
350
- export declare const mix: (superclass: any) => MixinBuilder;
351
- declare class MixinBuilder {
352
- private superclass;
353
- constructor(superclass: any);
354
- with(...mixins: any[]): any;
355
- }
356
- /**
357
- * @example
358
- *
359
- * ```
360
- * const cls = classNames( 'class1 class2', {
361
- * 'class3': false,
362
- * 'class4': true,
363
- * });
364
- *
365
- * // even shorter
366
- * const class1 = true, class2 = false;
367
- * const cls = classNames( { class1, class2 } ); // cls = "class1"
368
- *
369
- * ```
370
- *
371
- * @returns
372
- */
373
- export declare function classNames(...args: (string | any)[]): string;
374
- /**
375
- *
376
- */
377
- interface PasswordRule {
378
- chars: string;
379
- min: number;
380
- }
381
- export declare function generatePassword(length: number, rules?: PasswordRule[]): string;
382
- export {};