@difizen/libro-common 0.1.0 → 0.1.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/es/array.d.ts +368 -0
- package/es/array.d.ts.map +1 -0
- package/es/display-wrapper.d.ts +6 -0
- package/es/display-wrapper.d.ts.map +1 -0
- package/es/dom.d.ts +3 -0
- package/es/dom.d.ts.map +1 -0
- package/es/dom.js +97 -0
- package/es/index.d.ts +12 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +2 -1
- package/es/iter.d.ts +147 -0
- package/es/iter.d.ts.map +1 -0
- package/es/json.d.ts +126 -0
- package/es/json.d.ts.map +1 -0
- package/es/path.d.ts +97 -0
- package/es/path.d.ts.map +1 -0
- package/es/polling/index.d.ts +3 -0
- package/es/polling/index.d.ts.map +1 -0
- package/es/polling/poll.d.ts +193 -0
- package/es/polling/poll.d.ts.map +1 -0
- package/es/polling/poll.js +1 -1
- package/es/polling/protocol.d.ts +120 -0
- package/es/polling/protocol.d.ts.map +1 -0
- package/es/posix.d.ts +2 -0
- package/es/posix.d.ts.map +1 -0
- package/es/protocol/cell-protocol.d.ts +181 -0
- package/es/protocol/cell-protocol.d.ts.map +1 -0
- package/es/protocol/index.d.ts +4 -0
- package/es/protocol/index.d.ts.map +1 -0
- package/es/protocol/notebook-protocol.d.ts +63 -0
- package/es/protocol/notebook-protocol.d.ts.map +1 -0
- package/es/protocol/output-protocol.d.ts +125 -0
- package/es/protocol/output-protocol.d.ts.map +1 -0
- package/es/sanitizer.d.ts +45 -0
- package/es/sanitizer.d.ts.map +1 -0
- package/es/url.d.ts +98 -0
- package/es/url.d.ts.map +1 -0
- package/es/url.js +1 -1
- package/es/utils.d.ts +57 -0
- package/es/utils.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/dom.ts +71 -0
- package/src/index.ts +1 -0
- package/src/iter.ts +2 -2
- package/src/polling/poll.ts +2 -2
- package/src/polling/protocol.ts +1 -1
- package/src/sanitizer.ts +15 -15
- package/src/url.ts +1 -1
package/src/dom.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
function copyFallback(string: string) {
|
|
2
|
+
function handler(event: ClipboardEvent) {
|
|
3
|
+
const clipboardData = event.clipboardData || (window as any).clipboardData;
|
|
4
|
+
clipboardData.setData('text/plain', string);
|
|
5
|
+
event.preventDefault();
|
|
6
|
+
document.removeEventListener('copy', handler, true);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
document.addEventListener('copy', handler, true);
|
|
10
|
+
document.execCommand('copy');
|
|
11
|
+
}
|
|
12
|
+
// 复制到剪贴板
|
|
13
|
+
export const copy2clipboard = (string: string) => {
|
|
14
|
+
navigator.permissions
|
|
15
|
+
.query({
|
|
16
|
+
name: 'clipboard-write' as any,
|
|
17
|
+
})
|
|
18
|
+
.then((result) => {
|
|
19
|
+
if (result.state === 'granted' || result.state === 'prompt') {
|
|
20
|
+
if (window.navigator && window.navigator.clipboard) {
|
|
21
|
+
window.navigator.clipboard
|
|
22
|
+
.writeText(string)
|
|
23
|
+
.then(() => {
|
|
24
|
+
return;
|
|
25
|
+
})
|
|
26
|
+
.catch((err) => {
|
|
27
|
+
console.error('Could not copy text: ', err);
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
console.warn('navigator is not exist');
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
console.warn('浏览器权限不允许复制');
|
|
34
|
+
copyFallback(string);
|
|
35
|
+
}
|
|
36
|
+
return;
|
|
37
|
+
})
|
|
38
|
+
.catch(console.error);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
function readFallback() {
|
|
42
|
+
function handler(event: ClipboardEvent) {
|
|
43
|
+
// 获取剪贴板数据
|
|
44
|
+
const clipboardData = event.clipboardData || (window as any).clipboardData;
|
|
45
|
+
// 读取文本内容
|
|
46
|
+
const pastedData = clipboardData.getData('text/plain');
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
document.removeEventListener('paste', handler, true);
|
|
49
|
+
return pastedData;
|
|
50
|
+
}
|
|
51
|
+
document.addEventListener('paste', handler, true);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 从剪贴板读取
|
|
55
|
+
export const readFromClipboard = async () => {
|
|
56
|
+
let clipboardValue = '';
|
|
57
|
+
const result = await navigator.permissions.query({
|
|
58
|
+
name: 'clipboard-read' as any,
|
|
59
|
+
});
|
|
60
|
+
if (result.state === 'granted' || result.state === 'prompt') {
|
|
61
|
+
if (window.navigator && window.navigator.clipboard) {
|
|
62
|
+
clipboardValue = await window.navigator.clipboard.readText();
|
|
63
|
+
} else {
|
|
64
|
+
console.warn('navigator is not exist');
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
console.warn('浏览器权限不允许粘贴');
|
|
68
|
+
readFallback();
|
|
69
|
+
}
|
|
70
|
+
return clipboardValue;
|
|
71
|
+
};
|
package/src/index.ts
CHANGED
package/src/iter.ts
CHANGED
package/src/polling/poll.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import type { Event } from '@difizen/mana-
|
|
3
|
-
import { Emitter, Deferred } from '@difizen/mana-
|
|
2
|
+
import type { Event } from '@difizen/mana-app';
|
|
3
|
+
import { Emitter, Deferred } from '@difizen/mana-app';
|
|
4
4
|
|
|
5
5
|
import { deepEqual } from '../json.js';
|
|
6
6
|
|
package/src/polling/protocol.ts
CHANGED
package/src/sanitizer.ts
CHANGED
|
@@ -8,7 +8,7 @@ class CssProp {
|
|
|
8
8
|
/*
|
|
9
9
|
* Numeric base expressions used to help build more complex regular expressions
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
protected static readonly N = {
|
|
12
12
|
integer: `[+-]?[0-9]+`,
|
|
13
13
|
integer_pos: `[+]?[0-9]+`,
|
|
14
14
|
integer_zero_ff: `([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])`,
|
|
@@ -21,7 +21,7 @@ class CssProp {
|
|
|
21
21
|
/*
|
|
22
22
|
* Base expressions of common CSS syntax elements
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
protected static readonly B = {
|
|
25
25
|
angle: `(${CssProp.N.number}(deg|rad|grad|turn)|0)`,
|
|
26
26
|
frequency: `${CssProp.N.number}(Hz|kHz)`,
|
|
27
27
|
ident: String.raw`-?([_a-z]|[\xA0-\xFF]|\\[0-9a-f]{1,6}(\r\n|[ \t\r\n\f])?|\\[^\r\n\f0-9a-f])([_a-z0-9-]|[\xA0-\xFF]|\\[0-9a-f]{1,6}(\r\n|[ \t\r\n\f])?|\\[^\r\n\f0-9a-f])*`,
|
|
@@ -40,7 +40,7 @@ class CssProp {
|
|
|
40
40
|
/*
|
|
41
41
|
* Atomic (i.e. not dependant on other regular expressions) sub RegEx segments
|
|
42
42
|
*/
|
|
43
|
-
|
|
43
|
+
protected static readonly A = {
|
|
44
44
|
absolute_size: `xx-small|x-small|small|medium|large|x-large|xx-large`,
|
|
45
45
|
attachment: `scroll|fixed|local`,
|
|
46
46
|
bg_origin: `border-box|padding-box|content-box`,
|
|
@@ -62,7 +62,7 @@ class CssProp {
|
|
|
62
62
|
/*
|
|
63
63
|
* Color definition sub expressions
|
|
64
64
|
*/
|
|
65
|
-
|
|
65
|
+
protected static readonly _COLOR = {
|
|
66
66
|
hex: `\\#(0x)?[0-9a-f]+`,
|
|
67
67
|
name: `aliceblue|antiquewhite|aqua|aquamarine|azure|beige|bisque|black|blanchedalmond|blue|blueviolet|brown|burlywood|cadetblue|chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|cyan|darkblue|darkcyan|darkgoldenrod|darkgray|darkgreen|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dodgerblue|firebrick|floralwhite|forestgreen|fuchsia|gainsboro|ghostwhite|gold|goldenrod|gray|green|greenyellow|honeydew|hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgreen|lightgrey|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightsteelblue|lightyellow|lime|limegreen|linen|magenta|maroon|mediumaquamarine|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|mediumturquoise|mediumvioletred|midnightblue|mintcream|mistyrose|moccasin|navajowhite|navy|oldlace|olive|olivedrab|orange|orangered|orchid|palegoldenrod|palegreen|paleturquoise|palevioletred|papayawhip|peachpuff|peru|pink|plum|powderblue|purple|red|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|silver|skyblue|slateblue|slategray|snow|springgreen|steelblue|tan|teal|thistle|tomato|turquoise|transparent|violet|wheat|white|whitesmoke|yellow|yellowgreen`,
|
|
68
68
|
rgb: String.raw`rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)`,
|
|
@@ -72,7 +72,7 @@ class CssProp {
|
|
|
72
72
|
/*
|
|
73
73
|
* Compound (i.e. dependant on other (sub) regular expressions) sub RegEx segments
|
|
74
74
|
*/
|
|
75
|
-
|
|
75
|
+
protected static readonly _C = {
|
|
76
76
|
alpha: `${CssProp.N.integer_zero_ff}|${CssProp.N.number_zero_one}|${CssProp.B.percentage_zero_hundred}`,
|
|
77
77
|
alphavalue: CssProp.N.number_zero_one,
|
|
78
78
|
bg_position: `((${CssProp.B.len_or_perc}|left|center|right|top|bottom)\\s*){1,4}`,
|
|
@@ -96,29 +96,29 @@ class CssProp {
|
|
|
96
96
|
top: `${CssProp.B.length}|auto`,
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
protected static readonly _C1 = {
|
|
100
100
|
image_list: `image\\(\\s*(${CssProp.B.url})*\\s*(${CssProp.B.url}|${CssProp._C.color})\\s*\\)`,
|
|
101
101
|
linear_color_stop: `(${CssProp._C.color})(\\s*${CssProp._C.color_stop_length})?`,
|
|
102
102
|
// eslint-disable-next-line no-useless-escape
|
|
103
103
|
shadow: `((${CssProp._C.color})\\s+((${CssProp.B.length})\\s*){2,4}(\s+inset)?)|((inset\\s+)?((${CssProp.B.length})\\s*){2,4}\\s*(${CssProp._C.color})?)`,
|
|
104
104
|
};
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
protected static readonly _C2 = {
|
|
107
107
|
color_stop_list: `((${CssProp._C1.linear_color_stop})(\\s*(${CssProp._C.linear_color_hint}))?\\s*,\\s*)+(${CssProp._C1.linear_color_stop})`,
|
|
108
108
|
shape: `rect\\(\\s*(${CssProp._C.top})\\s*,\\s*(${CssProp._C.right})\\s*,\\s*(${CssProp._C.bottom})\\s*,\\s*(${CssProp._C.left})\\s*\\)`,
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
protected static readonly _C3 = {
|
|
112
112
|
linear_gradient: `linear-gradient\\((((${CssProp.B.angle})|to\\s+(${CssProp.A.side_or_corner}))\\s*,\\s*)?\\s*(${CssProp._C2.color_stop_list})\\s*\\)`,
|
|
113
113
|
radial_gradient: `radial-gradient\\(((((${CssProp.A.ending_shape})|(${CssProp._C.size}))\\s*)*\\s*(at\\s+${CssProp._C.position})?\\s*,\\s*)?\\s*(${CssProp._C2.color_stop_list})\\s*\\)`,
|
|
114
114
|
};
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
protected static readonly _C4 = {
|
|
117
117
|
image: `${CssProp.B.url}|${CssProp._C3.linear_gradient}|${CssProp._C3.radial_gradient}|${CssProp._C1.image_list}`,
|
|
118
118
|
bg_image: `(${CssProp.B.url}|${CssProp._C3.linear_gradient}|${CssProp._C3.radial_gradient}|${CssProp._C1.image_list})|none`,
|
|
119
119
|
};
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
protected static readonly C = {
|
|
122
122
|
...CssProp._C,
|
|
123
123
|
...CssProp._C1,
|
|
124
124
|
...CssProp._C2,
|
|
@@ -129,7 +129,7 @@ class CssProp {
|
|
|
129
129
|
/*
|
|
130
130
|
* Property value regular expressions not dependant on other sub expressions
|
|
131
131
|
*/
|
|
132
|
-
|
|
132
|
+
protected static readonly AP = {
|
|
133
133
|
border_collapse: `collapse|separate`,
|
|
134
134
|
box: `normal|none|contents`,
|
|
135
135
|
box_sizing: `content-box|padding-box|border-box`,
|
|
@@ -170,7 +170,7 @@ class CssProp {
|
|
|
170
170
|
/*
|
|
171
171
|
* Compound propertiy value regular expressions (i.e. dependant on other sub expressions)
|
|
172
172
|
*/
|
|
173
|
-
|
|
173
|
+
protected static readonly _CP = {
|
|
174
174
|
background_attachment: `${CssProp.A.attachment}(,\\s*${CssProp.A.attachment})*`,
|
|
175
175
|
background_color: CssProp.C.color,
|
|
176
176
|
background_origin: `${CssProp.A.box}(,\\s*${CssProp.A.box})*`,
|
|
@@ -268,11 +268,11 @@ class CssProp {
|
|
|
268
268
|
min_width: `${CssProp.B.length_pos}|${CssProp.B.percentage_pos}|auto`,
|
|
269
269
|
};
|
|
270
270
|
|
|
271
|
-
|
|
271
|
+
protected static readonly _CP1 = {
|
|
272
272
|
font: `(((((${CssProp.AP.font_style}|${CssProp.AP.font_variant}|${CssProp.AP.font_weight})\\s*){1,3})?\\s*(${CssProp._CP.font_size})\\s*(\\/\\s*(${CssProp._CP.line_height}))?\\s+(${CssProp._CP.font_family}))|caption|icon|menu|message-box|small-caption|status-bar)`,
|
|
273
273
|
};
|
|
274
274
|
|
|
275
|
-
|
|
275
|
+
protected static readonly CP = { ...CssProp._CP, ...CssProp._CP1 };
|
|
276
276
|
|
|
277
277
|
// CSS Property value validation regular expressions for use with sanitize-html
|
|
278
278
|
|
|
@@ -456,7 +456,7 @@ export class Sanitizer implements ISanitizer {
|
|
|
456
456
|
return sanitize(dirty, { ...this._options, ...(options || {}) });
|
|
457
457
|
}
|
|
458
458
|
|
|
459
|
-
|
|
459
|
+
protected _options: sanitize.IOptions = {
|
|
460
460
|
// HTML tags that are allowed to be used. Tags were extracted from Google Caja
|
|
461
461
|
allowedTags: [
|
|
462
462
|
'a',
|
package/src/url.ts
CHANGED