@lambo-design/shared 1.0.0-beta.246 → 1.0.0-beta.247
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/config/themes/atrovirens/atrovirens.css +576 -576
- package/config/themes/blue/blue.css +576 -576
- package/config/themes/blue-white/blue-white.css +576 -576
- package/config/themes/blue-white-tight/blue-white-tight.css +577 -577
- package/config/themes/danqing/danqing.css +576 -576
- package/config/themes/deep/deep.css +576 -576
- package/config/themes/default/default.css +576 -576
- package/config/themes/eap/eap.css +576 -576
- package/config/themes/gold/gold.css +576 -576
- package/config/themes/lime/lime.css +576 -576
- package/config/themes/orange/orange.css +576 -576
- package/config/themes/red/red.css +576 -576
- package/config/themes/white/white.css +576 -576
- package/nstyles/components/modal.less +1 -1
- package/package.json +1 -1
- package/utils/ajax/sseFetchUtil.js +104 -71
- package/utils/style.js +24 -24
- package/utils/transfer-queue.js +7 -7
package/package.json
CHANGED
|
@@ -1,71 +1,104 @@
|
|
|
1
|
-
class CustomEventSource {
|
|
2
|
-
constructor(url, options) {
|
|
3
|
-
this.url = url;
|
|
4
|
-
this.options = options || {};
|
|
5
|
-
this.listeners = {};
|
|
6
|
-
this.
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
fetch(this.url, { ...this.options, method: 'POST' })
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
1
|
+
class CustomEventSource {
|
|
2
|
+
constructor(url, options) {
|
|
3
|
+
this.url = url;
|
|
4
|
+
this.options = options || {};
|
|
5
|
+
this.listeners = {};
|
|
6
|
+
this.awaitConnect()
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async awaitConnect() {
|
|
10
|
+
const response = await fetch(this.url, { ...this.options, method: 'POST' });
|
|
11
|
+
const reader = response.body.getReader();
|
|
12
|
+
await this.readStream(reader);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async readStream(reader) {
|
|
16
|
+
let done, value, chunk = '';
|
|
17
|
+
do {
|
|
18
|
+
({done, value} = await reader.read());
|
|
19
|
+
if (done) {
|
|
20
|
+
this.dispatchEvent('message_finished');
|
|
21
|
+
} else {
|
|
22
|
+
const decoder = new TextDecoder('utf-8');
|
|
23
|
+
chunk +=decoder.decode(value, { stream: true })
|
|
24
|
+
if (chunk && chunk.trim().endsWith("}")) {
|
|
25
|
+
const lines = chunk.split('\n');
|
|
26
|
+
chunk = '';
|
|
27
|
+
for (let line of lines) {
|
|
28
|
+
if (line.startsWith('data:')) {
|
|
29
|
+
const data = line.substring(5).trim(); // 去掉 'data:' 前缀
|
|
30
|
+
if (data) {
|
|
31
|
+
this.dispatchEvent('message', { data: data });
|
|
32
|
+
}
|
|
33
|
+
} else if (line.startsWith("{") && line.endsWith("}")) {
|
|
34
|
+
this.dispatchEvent('message', { data: line });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
} while (!done);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
connect() {
|
|
43
|
+
fetch(this.url, { ...this.options, method: 'POST' })
|
|
44
|
+
.then(response => {
|
|
45
|
+
if (response.ok && response.body) {
|
|
46
|
+
const reader = response.body.getReader();
|
|
47
|
+
this.read(reader);
|
|
48
|
+
} else {
|
|
49
|
+
throw new Error('Failed to connect to the SSE endpoint.');
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
.catch(error => {
|
|
53
|
+
console.error('Connection error:', error);
|
|
54
|
+
this.dispatchEvent('message_finished',error);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
read(reader) {
|
|
59
|
+
reader.read().then(({done,value}) => {
|
|
60
|
+
if (done) {
|
|
61
|
+
this.dispatchEvent('message_finished');
|
|
62
|
+
} else {
|
|
63
|
+
const decoder = new TextDecoder('utf-8');
|
|
64
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
65
|
+
if (chunk) {
|
|
66
|
+
const lines = chunk.split('\n');
|
|
67
|
+
for (let line of lines) {
|
|
68
|
+
if (line.startsWith('data:')) {
|
|
69
|
+
const data = line.substring(5).trim(); // 去掉 'data:' 前缀
|
|
70
|
+
if (data) {
|
|
71
|
+
this.dispatchEvent('message', { data: data });
|
|
72
|
+
}
|
|
73
|
+
} else if (line.startsWith("{") && line.endsWith("}")) {
|
|
74
|
+
this.dispatchEvent('message', { data: line });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
this.read(reader);
|
|
80
|
+
}
|
|
81
|
+
}).catch(error => {
|
|
82
|
+
console.error('Read error:', error);
|
|
83
|
+
this.dispatchEvent('message_finished',error);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
addEventListener(type, listener) {
|
|
88
|
+
if (!this.listeners[type]) {
|
|
89
|
+
this.listeners[type] = [];
|
|
90
|
+
}
|
|
91
|
+
this.listeners[type].push(listener);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
dispatchEvent(type, event) {
|
|
95
|
+
if (this.listeners[type]) {
|
|
96
|
+
this.listeners[type].forEach(listener => listener(event));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export default CustomEventSource;
|
|
102
|
+
export {
|
|
103
|
+
CustomEventSource
|
|
104
|
+
}
|
package/utils/style.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
const SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g
|
|
2
|
-
const MOZ_HACK_REGEXP = /^moz([A-Z])/
|
|
3
|
-
|
|
4
|
-
function camelCase(name) {
|
|
5
|
-
return name
|
|
6
|
-
.replace(SPECIAL_CHARS_REGEXP, function (_, separator, letter, offset) {
|
|
7
|
-
return offset ? letter.toUpperCase() : letter
|
|
8
|
-
})
|
|
9
|
-
.replace(MOZ_HACK_REGEXP, 'Moz$1')
|
|
10
|
-
}
|
|
11
|
-
// getStyle
|
|
12
|
-
export function getStyle(element, styleName) {
|
|
13
|
-
if (!element || !styleName) return null
|
|
14
|
-
styleName = camelCase(styleName)
|
|
15
|
-
if (styleName === 'float') {
|
|
16
|
-
styleName = 'cssFloat'
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
const computed = document.defaultView.getComputedStyle(element, '')
|
|
20
|
-
return element.style[styleName] || computed ? computed[styleName] : null
|
|
21
|
-
} catch (e) {
|
|
22
|
-
return element.style[styleName]
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
const SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g
|
|
2
|
+
const MOZ_HACK_REGEXP = /^moz([A-Z])/
|
|
3
|
+
|
|
4
|
+
function camelCase(name) {
|
|
5
|
+
return name
|
|
6
|
+
.replace(SPECIAL_CHARS_REGEXP, function (_, separator, letter, offset) {
|
|
7
|
+
return offset ? letter.toUpperCase() : letter
|
|
8
|
+
})
|
|
9
|
+
.replace(MOZ_HACK_REGEXP, 'Moz$1')
|
|
10
|
+
}
|
|
11
|
+
// getStyle
|
|
12
|
+
export function getStyle(element, styleName) {
|
|
13
|
+
if (!element || !styleName) return null
|
|
14
|
+
styleName = camelCase(styleName)
|
|
15
|
+
if (styleName === 'float') {
|
|
16
|
+
styleName = 'cssFloat'
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const computed = document.defaultView.getComputedStyle(element, '')
|
|
20
|
+
return element.style[styleName] || computed ? computed[styleName] : null
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return element.style[styleName]
|
|
23
|
+
}
|
|
24
|
+
}
|
package/utils/transfer-queue.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
let transferIndex = 1000
|
|
2
|
-
|
|
3
|
-
function transferIncrease() {
|
|
4
|
-
transferIndex++
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export { transferIndex, transferIncrease }
|
|
1
|
+
let transferIndex = 1000
|
|
2
|
+
|
|
3
|
+
function transferIncrease() {
|
|
4
|
+
transferIndex++
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export { transferIndex, transferIncrease }
|