@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.
@@ -1,5 +1,5 @@
1
1
  :root {
2
- --modal-top-height: 100px;
2
+ --modal-top-height: 10px;
3
3
  --modal-header-height: 52px;
4
4
  --modal-footer-height: 57px;
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambo-design/shared",
3
- "version": "1.0.0-beta.246",
3
+ "version": "1.0.0-beta.247",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "lambo",
@@ -1,71 +1,104 @@
1
- class CustomEventSource {
2
- constructor(url, options) {
3
- this.url = url;
4
- this.options = options || {};
5
- this.listeners = {};
6
- this.connect();
7
- }
8
-
9
- connect() {
10
- fetch(this.url, { ...this.options, method: 'POST' })
11
- .then(response => {
12
- if (response.ok && response.body) {
13
- const reader = response.body.getReader();
14
- this.read(reader);
15
- } else {
16
- throw new Error('Failed to connect to the SSE endpoint.');
17
- }
18
- })
19
- .catch(error => {
20
- console.error('Connection error:', error);
21
- this.dispatchEvent('message_finished',error);
22
- });
23
- }
24
-
25
- read(reader) {
26
- reader.read().then(({done,value}) => {
27
- if (done) {
28
- this.dispatchEvent('message_finished');
29
- } else {
30
- const decoder = new TextDecoder('utf-8');
31
- const chunk = decoder.decode(value, { stream: true });
32
- if (chunk) {
33
- const lines = chunk.split('\n');
34
- for (let line of lines) {
35
- if (line.startsWith('data:')) {
36
- const data = line.substring(5).trim(); // 去掉 'data:' 前缀
37
- if (data) {
38
- this.dispatchEvent('message', { data: data });
39
- }
40
- } else if (line.startsWith("{") && line.endsWith("}")) {
41
- this.dispatchEvent('message', { data: line });
42
- }
43
- }
44
- }
45
-
46
- this.read(reader);
47
- }
48
- }).catch(error => {
49
- console.error('Read error:', error);
50
- this.dispatchEvent('message_finished',error);
51
- });
52
- }
53
-
54
- addEventListener(type, listener) {
55
- if (!this.listeners[type]) {
56
- this.listeners[type] = [];
57
- }
58
- this.listeners[type].push(listener);
59
- }
60
-
61
- dispatchEvent(type, event) {
62
- if (this.listeners[type]) {
63
- this.listeners[type].forEach(listener => listener(event));
64
- }
65
- }
66
- }
67
-
68
- export default CustomEventSource;
69
- export {
70
- CustomEventSource
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
+ }
@@ -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 }