hy-dispatch-ui-v3 0.2.2 → 0.2.3
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/components/appConfigProvider/appConfigProvider.vue.mjs +3 -1
- package/es/components/appDatePicker/appDatePicker.vue.mjs +57 -3
- package/es/components/appDatePicker/index.mjs +2 -1
- package/es/components/appForm/cpns/appFormItem.vue.mjs +37 -7
- package/es/components/appForm/js/useAppForm.mjs +5 -40
- package/es/components/appIcon/appIcon.vue.mjs +5 -1
- package/es/components/appSearch/cpns/appSearchItem.vue.mjs +33 -3
- package/es/components/appSearch/js/index.mjs +1 -1
- package/es/components/appSearch/js/useAppSearch.mjs +9 -39
- package/es/components/appTimePicker/appTimePicker.vue.mjs +154 -0
- package/es/components/appTimePicker/index.mjs +7 -0
- package/es/components/appTimePicker/style/appTimePicker.scss +0 -0
- package/es/components/appTree/appTree.vue.mjs +11 -8
- package/es/components/appTree/config/tree-config.mjs +33 -0
- package/es/components/appTree/js/index.mjs +10 -12
- package/es/components/appVideoPlayer/appVideoPlayer.vue.mjs +6 -6
- package/es/components/index.mjs +2 -1
- package/es/hooks/index.mjs +1 -0
- package/es/hooks/useEnsureHyIcon.mjs +12 -0
- package/es/hooks/useGlobalConfig.mjs +5 -0
- package/es/index.mjs +3 -1
- package/es/locale/en.mjs +21 -11
- package/es/locale/zh_CN.mjs +21 -11
- package/es/static/_sprite.js +33 -0
- package/es/static/hy-svg-icons/ai.js +30 -0
- package/es/static/hy-svg-icons/batch.js +8 -0
- package/es/static/hy-svg-icons.js +10 -10
- package/es/static/index.js +2 -2
- package/es/static/protocolcheck.js +109 -85
- package/es/static/vite-plugin-hy-svg-icons.js +240 -0
- package/es/utils/date.mjs +1 -0
- package/lib/components/appConfigProvider/appConfigProvider.vue.js +3 -1
- package/lib/components/appDatePicker/appDatePicker.vue.js +56 -2
- package/lib/components/appDatePicker/index.js +2 -0
- package/lib/components/appForm/cpns/appFormItem.vue.js +38 -8
- package/lib/components/appForm/js/useAppForm.js +5 -40
- package/lib/components/appIcon/appIcon.vue.js +4 -0
- package/lib/components/appSearch/cpns/appSearchItem.vue.js +34 -4
- package/lib/components/appSearch/js/index.js +1 -1
- package/lib/components/appSearch/js/useAppSearch.js +9 -39
- package/lib/components/appTimePicker/appTimePicker.vue.js +158 -0
- package/lib/components/appTimePicker/index.js +13 -0
- package/lib/components/appTimePicker/style/appTimePicker.scss +0 -0
- package/lib/components/appTree/appTree.vue.js +10 -7
- package/lib/components/appTree/config/tree-config.js +37 -0
- package/lib/components/appTree/js/index.js +10 -12
- package/lib/components/appVideoPlayer/appVideoPlayer.vue.js +6 -6
- package/lib/components/index.js +12 -8
- package/lib/hooks/index.js +3 -0
- package/lib/hooks/useEnsureHyIcon.js +15 -0
- package/lib/hooks/useGlobalConfig.js +5 -0
- package/lib/index.js +15 -8
- package/lib/locale/en.js +21 -11
- package/lib/locale/zh_CN.js +21 -11
- package/lib/static/_sprite.js +33 -0
- package/lib/static/hy-svg-icons/ai.js +30 -0
- package/lib/static/hy-svg-icons/batch.js +8 -0
- package/lib/static/hy-svg-icons.js +10 -12
- package/lib/static/index.js +2 -5
- package/lib/static/protocolcheck.js +109 -87
- package/lib/static/vite-plugin-hy-svg-icons.js +240 -0
- package/lib/utils/date.js +1 -0
- package/package.json +3 -3
package/es/static/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import './hy-svg-icons.js'
|
|
2
|
-
import './protocolcheck.js'
|
|
1
|
+
import './hy-svg-icons.js'
|
|
2
|
+
import './protocolcheck.js'
|
|
@@ -1,37 +1,38 @@
|
|
|
1
|
-
(function (f) {
|
|
1
|
+
;(function (f) {
|
|
2
2
|
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
|
3
|
-
module.exports = f()
|
|
3
|
+
module.exports = f()
|
|
4
4
|
} else if (typeof define === 'function' && define.amd) {
|
|
5
|
-
define([], f)
|
|
5
|
+
define([], f)
|
|
6
6
|
} else {
|
|
7
|
-
var g
|
|
7
|
+
var g
|
|
8
8
|
if (typeof window !== 'undefined') {
|
|
9
|
-
g = window
|
|
9
|
+
g = window
|
|
10
10
|
} else if (typeof global !== 'undefined') {
|
|
11
|
-
g = global
|
|
11
|
+
g = global
|
|
12
12
|
} else if (typeof self !== 'undefined') {
|
|
13
|
-
g = self
|
|
13
|
+
g = self
|
|
14
14
|
} else {
|
|
15
|
-
g = this
|
|
15
|
+
g = this
|
|
16
16
|
}
|
|
17
|
-
g.protocolCheck = f()
|
|
17
|
+
g.protocolCheck = f()
|
|
18
18
|
}
|
|
19
19
|
})(function () {
|
|
20
|
+
var define, module, exports
|
|
20
21
|
return (function e(t, n, r) {
|
|
21
22
|
function s(o, u) {
|
|
22
23
|
if (!n[o]) {
|
|
23
24
|
if (!t[o]) {
|
|
24
|
-
var a = typeof require == 'function' && require
|
|
25
|
-
if (!u && a) return a(o,
|
|
26
|
-
if (i) return i(o,
|
|
27
|
-
var f = new Error("Cannot find module '" + o + "'")
|
|
25
|
+
var a = typeof require == 'function' && require
|
|
26
|
+
if (!u && a) return a(o, !0)
|
|
27
|
+
if (i) return i(o, !0)
|
|
28
|
+
var f = new Error("Cannot find module '" + o + "'")
|
|
28
29
|
throw ((f.code = 'MODULE_NOT_FOUND'), f)
|
|
29
30
|
}
|
|
30
|
-
var l = (n[o] = { exports: {} })
|
|
31
|
+
var l = (n[o] = { exports: {} })
|
|
31
32
|
t[o][0].call(
|
|
32
33
|
l.exports,
|
|
33
34
|
function (e) {
|
|
34
|
-
var n = t[o][1][e]
|
|
35
|
+
var n = t[o][1][e]
|
|
35
36
|
return s(n ? n : e)
|
|
36
37
|
},
|
|
37
38
|
l,
|
|
@@ -40,141 +41,164 @@
|
|
|
40
41
|
t,
|
|
41
42
|
n,
|
|
42
43
|
r
|
|
43
|
-
)
|
|
44
|
+
)
|
|
44
45
|
}
|
|
45
46
|
return n[o].exports
|
|
46
47
|
}
|
|
47
|
-
var i = typeof require == 'function' && require
|
|
48
|
-
for (var o = 0; o < r.length; o++) s(r[o])
|
|
48
|
+
var i = typeof require == 'function' && require
|
|
49
|
+
for (var o = 0; o < r.length; o++) s(r[o])
|
|
49
50
|
return s
|
|
50
51
|
})(
|
|
51
52
|
{
|
|
52
53
|
1: [
|
|
53
|
-
function (require, module, exports
|
|
54
|
+
function (require, module, exports) {
|
|
54
55
|
function _registerEvent(target, eventType, cb) {
|
|
55
56
|
if (target.addEventListener) {
|
|
56
|
-
target.addEventListener(eventType, cb)
|
|
57
|
+
target.addEventListener(eventType, cb)
|
|
57
58
|
return {
|
|
58
59
|
remove: function () {
|
|
59
|
-
target.removeEventListener(eventType, cb)
|
|
60
|
+
target.removeEventListener(eventType, cb)
|
|
60
61
|
},
|
|
61
62
|
}
|
|
62
63
|
} else {
|
|
63
|
-
target.attachEvent(eventType, cb)
|
|
64
|
+
target.attachEvent(eventType, cb)
|
|
64
65
|
return {
|
|
65
66
|
remove: function () {
|
|
66
|
-
target.detachEvent(eventType, cb)
|
|
67
|
+
target.detachEvent(eventType, cb)
|
|
67
68
|
},
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
function _createHiddenIframe(target, uri) {
|
|
73
|
-
var iframe = document.createElement('iframe')
|
|
74
|
-
iframe.src = uri
|
|
75
|
-
iframe.id = 'hiddenIframe'
|
|
76
|
-
iframe.style.display = 'none'
|
|
77
|
-
target.appendChild(iframe)
|
|
74
|
+
var iframe = document.createElement('iframe')
|
|
75
|
+
iframe.src = uri
|
|
76
|
+
iframe.id = 'hiddenIframe'
|
|
77
|
+
iframe.style.display = 'none'
|
|
78
|
+
target.appendChild(iframe)
|
|
78
79
|
|
|
79
80
|
return iframe
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
function openUriWithHiddenFrame(uri, failCb, successCb) {
|
|
83
84
|
var timeout = setTimeout(function () {
|
|
84
|
-
failCb()
|
|
85
|
-
handler.remove()
|
|
86
|
-
}, 1000)
|
|
85
|
+
failCb()
|
|
86
|
+
handler.remove()
|
|
87
|
+
}, 1000)
|
|
87
88
|
|
|
88
|
-
var iframe = document.querySelector('#hiddenIframe')
|
|
89
|
+
var iframe = document.querySelector('#hiddenIframe')
|
|
89
90
|
if (!iframe) {
|
|
90
|
-
iframe = _createHiddenIframe(document.body, 'about:blank')
|
|
91
|
+
iframe = _createHiddenIframe(document.body, 'about:blank')
|
|
91
92
|
}
|
|
92
93
|
|
|
93
|
-
var handler = _registerEvent(window, 'blur', onBlur)
|
|
94
|
+
var handler = _registerEvent(window, 'blur', onBlur)
|
|
94
95
|
|
|
95
96
|
function onBlur() {
|
|
96
|
-
clearTimeout(timeout)
|
|
97
|
-
handler.remove()
|
|
98
|
-
successCb()
|
|
97
|
+
clearTimeout(timeout)
|
|
98
|
+
handler.remove()
|
|
99
|
+
successCb()
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
iframe.contentWindow.location.href = uri
|
|
102
|
+
iframe.contentWindow.location.href = uri
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function openUriWithTimeoutHack(uri, failCb, successCb) {
|
|
106
|
+
var timeout = setTimeout(function () {
|
|
107
|
+
failCb()
|
|
108
|
+
handler.remove()
|
|
109
|
+
}, 1000)
|
|
110
|
+
|
|
111
|
+
//handle page running in an iframe (blur must be registered with top level window)
|
|
112
|
+
var target = window
|
|
113
|
+
while (target != target.parent) {
|
|
114
|
+
target = target.parent
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
var handler = _registerEvent(target, 'blur', onBlur)
|
|
118
|
+
|
|
119
|
+
function onBlur() {
|
|
120
|
+
clearTimeout(timeout)
|
|
121
|
+
handler.remove()
|
|
122
|
+
successCb()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
window.location = uri
|
|
102
126
|
}
|
|
103
127
|
|
|
104
128
|
function openUriUsingFirefox(uri, failCb, successCb) {
|
|
105
|
-
var iframe = document.querySelector('#hiddenIframe')
|
|
129
|
+
var iframe = document.querySelector('#hiddenIframe')
|
|
106
130
|
|
|
107
131
|
if (!iframe) {
|
|
108
|
-
iframe = _createHiddenIframe(document.body, 'about:blank')
|
|
132
|
+
iframe = _createHiddenIframe(document.body, 'about:blank')
|
|
109
133
|
}
|
|
110
134
|
|
|
111
135
|
try {
|
|
112
|
-
iframe.contentWindow.location.href = uri
|
|
113
|
-
successCb()
|
|
136
|
+
iframe.contentWindow.location.href = uri
|
|
137
|
+
successCb()
|
|
114
138
|
} catch (e) {
|
|
115
139
|
if (e.name == 'NS_ERROR_UNKNOWN_PROTOCOL') {
|
|
116
|
-
failCb()
|
|
140
|
+
failCb()
|
|
117
141
|
}
|
|
118
142
|
}
|
|
119
143
|
}
|
|
120
144
|
|
|
121
145
|
function openUriUsingIEInOlderWindows(uri, failCb, successCb) {
|
|
122
146
|
if (getInternetExplorerVersion() === 10) {
|
|
123
|
-
openUriUsingIE10InWindows7(uri, failCb, successCb)
|
|
147
|
+
openUriUsingIE10InWindows7(uri, failCb, successCb)
|
|
124
148
|
} else if (
|
|
125
149
|
getInternetExplorerVersion() === 9 ||
|
|
126
150
|
getInternetExplorerVersion() === 11
|
|
127
151
|
) {
|
|
128
|
-
openUriWithHiddenFrame(uri, failCb, successCb)
|
|
152
|
+
openUriWithHiddenFrame(uri, failCb, successCb)
|
|
129
153
|
} else {
|
|
130
|
-
openUriInNewWindowHack(uri, failCb, successCb)
|
|
154
|
+
openUriInNewWindowHack(uri, failCb, successCb)
|
|
131
155
|
}
|
|
132
156
|
}
|
|
133
157
|
|
|
134
158
|
function openUriUsingIE10InWindows7(uri, failCb, successCb) {
|
|
135
|
-
var timeout = setTimeout(failCb, 1000)
|
|
159
|
+
var timeout = setTimeout(failCb, 1000)
|
|
136
160
|
window.addEventListener('blur', function () {
|
|
137
|
-
clearTimeout(timeout)
|
|
138
|
-
successCb()
|
|
139
|
-
})
|
|
161
|
+
clearTimeout(timeout)
|
|
162
|
+
successCb()
|
|
163
|
+
})
|
|
140
164
|
|
|
141
|
-
var iframe = document.querySelector('#hiddenIframe')
|
|
165
|
+
var iframe = document.querySelector('#hiddenIframe')
|
|
142
166
|
if (!iframe) {
|
|
143
|
-
iframe = _createHiddenIframe(document.body, 'about:blank')
|
|
167
|
+
iframe = _createHiddenIframe(document.body, 'about:blank')
|
|
144
168
|
}
|
|
145
169
|
try {
|
|
146
|
-
iframe.contentWindow.location.href = uri
|
|
170
|
+
iframe.contentWindow.location.href = uri
|
|
147
171
|
} catch (e) {
|
|
148
|
-
failCb()
|
|
149
|
-
clearTimeout(timeout)
|
|
172
|
+
failCb()
|
|
173
|
+
clearTimeout(timeout)
|
|
150
174
|
}
|
|
151
175
|
}
|
|
152
176
|
|
|
153
177
|
function openUriInNewWindowHack(uri, failCb, successCb) {
|
|
154
|
-
var myWindow = window.open('', '', 'width=0,height=0')
|
|
178
|
+
var myWindow = window.open('', '', 'width=0,height=0')
|
|
155
179
|
|
|
156
|
-
myWindow.document.write("<iframe src='" + uri + "'></iframe>")
|
|
180
|
+
myWindow.document.write("<iframe src='" + uri + "'></iframe>")
|
|
157
181
|
|
|
158
182
|
setTimeout(function () {
|
|
159
183
|
try {
|
|
160
|
-
myWindow.location.href
|
|
161
|
-
myWindow.setTimeout('window.close()', 1000)
|
|
162
|
-
successCb()
|
|
184
|
+
myWindow.location.href
|
|
185
|
+
myWindow.setTimeout('window.close()', 1000)
|
|
186
|
+
successCb()
|
|
163
187
|
} catch (e) {
|
|
164
|
-
myWindow.close()
|
|
165
|
-
failCb()
|
|
188
|
+
myWindow.close()
|
|
189
|
+
failCb()
|
|
166
190
|
}
|
|
167
|
-
}, 1000)
|
|
191
|
+
}, 1000)
|
|
168
192
|
}
|
|
169
193
|
|
|
170
194
|
function openUriWithMsLaunchUri(uri, failCb, successCb) {
|
|
171
|
-
navigator.msLaunchUri(uri, successCb, failCb)
|
|
195
|
+
navigator.msLaunchUri(uri, successCb, failCb)
|
|
172
196
|
}
|
|
173
197
|
|
|
174
198
|
function checkBrowser() {
|
|
175
199
|
var isOpera =
|
|
176
|
-
!!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0
|
|
177
|
-
var ua = navigator.userAgent.toLowerCase()
|
|
200
|
+
!!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0
|
|
201
|
+
var ua = navigator.userAgent.toLowerCase()
|
|
178
202
|
return {
|
|
179
203
|
isOpera: isOpera,
|
|
180
204
|
isFirefox: typeof InstallTrigger !== 'undefined',
|
|
@@ -187,21 +211,21 @@
|
|
|
187
211
|
/iPad|iPhone|iPod/.test(navigator.userAgent) &&
|
|
188
212
|
!window.MSStream,
|
|
189
213
|
isChrome: !!window.chrome && !isOpera,
|
|
190
|
-
isIE: /*@cc_on!@*/ !!document.documentMode, // At least IE6
|
|
214
|
+
isIE: /*@cc_on!@*/ false || !!document.documentMode, // At least IE6
|
|
191
215
|
}
|
|
192
216
|
}
|
|
193
217
|
|
|
194
218
|
function getInternetExplorerVersion() {
|
|
195
|
-
var rv = -1
|
|
219
|
+
var rv = -1
|
|
196
220
|
if (navigator.appName === 'Microsoft Internet Explorer') {
|
|
197
|
-
var ua = navigator.userAgent
|
|
198
|
-
var re = new RegExp('MSIE ([0-9]{1,}[\.0-9]{0,})')
|
|
199
|
-
if (re.exec(ua) != null) rv = parseFloat(RegExp.$1)
|
|
221
|
+
var ua = navigator.userAgent
|
|
222
|
+
var re = new RegExp('MSIE ([0-9]{1,}[\.0-9]{0,})')
|
|
223
|
+
if (re.exec(ua) != null) rv = parseFloat(RegExp.$1)
|
|
200
224
|
} else if (navigator.appName === 'Netscape') {
|
|
201
|
-
var ua = navigator.userAgent
|
|
202
|
-
var re = new RegExp('Trident/.*rv:([0-9]{1,}[\.0-9]{0,})')
|
|
225
|
+
var ua = navigator.userAgent
|
|
226
|
+
var re = new RegExp('Trident/.*rv:([0-9]{1,}[\.0-9]{0,})')
|
|
203
227
|
if (re.exec(ua) != null) {
|
|
204
|
-
rv = parseFloat(RegExp.$1)
|
|
228
|
+
rv = parseFloat(RegExp.$1)
|
|
205
229
|
}
|
|
206
230
|
}
|
|
207
231
|
return rv
|
|
@@ -209,34 +233,34 @@
|
|
|
209
233
|
|
|
210
234
|
module.exports = function (uri, failCb, successCb, unsupportedCb) {
|
|
211
235
|
function failCallback() {
|
|
212
|
-
failCb && failCb()
|
|
236
|
+
failCb && failCb()
|
|
213
237
|
}
|
|
214
238
|
|
|
215
239
|
function successCallback() {
|
|
216
|
-
successCb && successCb()
|
|
240
|
+
successCb && successCb()
|
|
217
241
|
}
|
|
218
242
|
|
|
219
243
|
if (navigator.msLaunchUri) {
|
|
220
244
|
//for IE and Edge in Win 8 and Win 10
|
|
221
|
-
openUriWithMsLaunchUri(uri, failCb, successCb)
|
|
245
|
+
openUriWithMsLaunchUri(uri, failCb, successCb)
|
|
222
246
|
} else {
|
|
223
|
-
var browser = checkBrowser()
|
|
247
|
+
var browser = checkBrowser()
|
|
224
248
|
|
|
225
249
|
if (browser.isFirefox) {
|
|
226
|
-
openUriUsingFirefox(uri, failCallback, successCallback)
|
|
250
|
+
openUriUsingFirefox(uri, failCallback, successCallback)
|
|
227
251
|
} else if (browser.isChrome || browser.isIOS) {
|
|
228
252
|
// openUriWithTimeoutHack(uri, failCallback, successCallback);
|
|
229
|
-
openUriWithHiddenFrame(uri, failCallback, successCallback)
|
|
253
|
+
openUriWithHiddenFrame(uri, failCallback, successCallback)
|
|
230
254
|
} else if (browser.isIE) {
|
|
231
|
-
openUriUsingIEInOlderWindows(uri, failCallback, successCallback)
|
|
255
|
+
openUriUsingIEInOlderWindows(uri, failCallback, successCallback)
|
|
232
256
|
} else if (browser.isSafari) {
|
|
233
|
-
openUriWithHiddenFrame(uri, failCallback, successCallback)
|
|
257
|
+
openUriWithHiddenFrame(uri, failCallback, successCallback)
|
|
234
258
|
} else {
|
|
235
|
-
unsupportedCb()
|
|
259
|
+
unsupportedCb()
|
|
236
260
|
//not supported, implement please
|
|
237
261
|
}
|
|
238
262
|
}
|
|
239
|
-
}
|
|
263
|
+
}
|
|
240
264
|
},
|
|
241
265
|
{},
|
|
242
266
|
],
|
|
@@ -244,4 +268,4 @@
|
|
|
244
268
|
{},
|
|
245
269
|
[1]
|
|
246
270
|
)(1)
|
|
247
|
-
})
|
|
271
|
+
})
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
const STATIC_VIRTUAL_ID = 'virtual:hy-svg-icons';
|
|
5
|
+
const REGISTRY_VIRTUAL_ID = 'virtual:hy-svg-icons/registry';
|
|
6
|
+
const STATIC_RESOLVED_ID = '\0' + STATIC_VIRTUAL_ID;
|
|
7
|
+
const REGISTRY_RESOLVED_ID = '\0' + REGISTRY_VIRTUAL_ID;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 扫描源码里出现的 svg-name 字面量,结合 hy-svg-icons/ 目录下每个图标文件的
|
|
11
|
+
* 顶层 id(形如 'hy-icon-<svg-name>')做白名单匹配,生成两个虚拟模块:
|
|
12
|
+
*
|
|
13
|
+
* virtual:hy-svg-icons — 静态注入:把用到的图标 import + registerSymbol 一次注册进 sprite。
|
|
14
|
+
* virtual:hy-svg-icons/registry — 完整注册表:{ svgName: () => import(iconFile) },用于 AppIcon 动态兜底。
|
|
15
|
+
*
|
|
16
|
+
* 数据源:每个图标一个文件,形如 src/assets/hy-svg-icons/<name>.js
|
|
17
|
+
* export default {
|
|
18
|
+
* id: 'hy-icon-<svg-name>',
|
|
19
|
+
* defs?: `...`,
|
|
20
|
+
* symbol: `...`,
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* 只有 hy-icon- 前缀是固定的(由 AppIcon 拼接),svg-name 内部结构不做假设。
|
|
24
|
+
*/
|
|
25
|
+
export function hySvgIconsPlugin(options = {}) {
|
|
26
|
+
const {
|
|
27
|
+
dataDir = 'src/assets/hy-svg-icons',
|
|
28
|
+
spriteFile = 'src/assets/hy-svg-icons/_sprite.js',
|
|
29
|
+
scanDirs = ['src'],
|
|
30
|
+
exts = ['vue', 'js', 'ts', 'jsx', 'tsx'],
|
|
31
|
+
idPrefix = 'hy-icon-',
|
|
32
|
+
} = options;
|
|
33
|
+
|
|
34
|
+
let projectRoot = process.cwd();
|
|
35
|
+
let dataDirAbs = '';
|
|
36
|
+
/** svg-name (id 去 hy-icon- 前缀) -> 数据文件绝对路径 */
|
|
37
|
+
let available = new Map();
|
|
38
|
+
/** 数据文件绝对路径集合,用于源码扫描时跳过自己 */
|
|
39
|
+
let dataFilesAbs = new Set();
|
|
40
|
+
let used = new Set();
|
|
41
|
+
let server = null;
|
|
42
|
+
|
|
43
|
+
const extSet = new Set(exts.map((e) => '.' + e));
|
|
44
|
+
const escapedIdPrefix = idPrefix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
45
|
+
|
|
46
|
+
// 数据文件里的顶层 id:行首缩进 + `id:` + 引号 + hy-icon-XXX + 引号
|
|
47
|
+
// multiline 模式,只匹配"作为对象键"的 id,绕过 SVG 内嵌 id="..." 的干扰
|
|
48
|
+
function makeIdRe() {
|
|
49
|
+
return new RegExp(`^\\s*id:\\s*['"]${escapedIdPrefix}([A-Za-z0-9_-]+)['"]`, 'm');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 源码里 svg-name 候选:kebab-case 至少两段(首字符字母)
|
|
53
|
+
function makeNameRe() {
|
|
54
|
+
return /[a-zA-Z][a-zA-Z0-9]*(?:-[a-zA-Z0-9]+)+/g;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function collectDataFiles() {
|
|
58
|
+
let entries;
|
|
59
|
+
try {
|
|
60
|
+
entries = await fs.readdir(dataDirAbs, { withFileTypes: true });
|
|
61
|
+
} catch {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
const out = [];
|
|
65
|
+
for (const entry of entries) {
|
|
66
|
+
if (!entry.isFile()) continue;
|
|
67
|
+
if (!entry.name.endsWith('.js')) continue;
|
|
68
|
+
// 以 _ 开头的当内部文件(如 _sprite.js)
|
|
69
|
+
if (entry.name.startsWith('_')) continue;
|
|
70
|
+
// index.js 保留给未来 re-export,不算图标数据
|
|
71
|
+
if (entry.name === 'index.js') continue;
|
|
72
|
+
out.push(path.join(dataDirAbs, entry.name));
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function loadAvailable() {
|
|
78
|
+
const files = await collectDataFiles();
|
|
79
|
+
dataFilesAbs = new Set(files);
|
|
80
|
+
const map = new Map();
|
|
81
|
+
await Promise.all(
|
|
82
|
+
files.map(async (file) => {
|
|
83
|
+
try {
|
|
84
|
+
const content = await fs.readFile(file, 'utf-8');
|
|
85
|
+
const idRe = makeIdRe();
|
|
86
|
+
const m = idRe.exec(content);
|
|
87
|
+
if (m) map.set(m[1], file);
|
|
88
|
+
} catch {}
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
available = map;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function walk(dir, out) {
|
|
95
|
+
let entries;
|
|
96
|
+
try {
|
|
97
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
98
|
+
} catch {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
for (const entry of entries) {
|
|
102
|
+
if (entry.name === 'node_modules' || entry.name.startsWith('.')) continue;
|
|
103
|
+
const full = path.join(dir, entry.name);
|
|
104
|
+
// 数据源自身不算"使用"
|
|
105
|
+
if (dataFilesAbs.has(full)) continue;
|
|
106
|
+
if (entry.isDirectory()) {
|
|
107
|
+
await walk(full, out);
|
|
108
|
+
} else if (extSet.has(path.extname(entry.name))) {
|
|
109
|
+
out.push(full);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function scanUsage() {
|
|
115
|
+
const files = [];
|
|
116
|
+
for (const d of scanDirs) {
|
|
117
|
+
await walk(path.resolve(projectRoot, d), files);
|
|
118
|
+
}
|
|
119
|
+
const found = new Set();
|
|
120
|
+
await Promise.all(
|
|
121
|
+
files.map(async (file) => {
|
|
122
|
+
let content;
|
|
123
|
+
try {
|
|
124
|
+
content = await fs.readFile(file, 'utf-8');
|
|
125
|
+
} catch {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const nameRe = makeNameRe();
|
|
129
|
+
let m;
|
|
130
|
+
while ((m = nameRe.exec(content))) {
|
|
131
|
+
if (available.has(m[0])) found.add(m[0]);
|
|
132
|
+
}
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
return found;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function toImportPath(absPath) {
|
|
139
|
+
const rel = path.relative(projectRoot, absPath).replace(/\\/g, '/');
|
|
140
|
+
// 一律走 project-root 相对绝对路径(形如 /src/... 或 /node_modules/...)。
|
|
141
|
+
// Vite 把 / 开头的路径当作文件来服务,绕过包 exports 校验;
|
|
142
|
+
// 而裸导入 pkg/sub-path 会强制走 exports 白名单,很多包只暴露聚合入口,个文件用不了。
|
|
143
|
+
return '/' + rel;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function toIdent(svgName) {
|
|
147
|
+
return '__hy_' + svgName.replace(/[^a-zA-Z0-9]/g, '_');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function buildStaticModule() {
|
|
151
|
+
const names = [...used].filter((n) => available.has(n)).sort();
|
|
152
|
+
if (names.length === 0) return '// no hy-svg-icons used\n';
|
|
153
|
+
const spritePath = toImportPath(path.resolve(projectRoot, spriteFile));
|
|
154
|
+
const lines = [`import { registerSymbol } from '${spritePath}';`];
|
|
155
|
+
for (const name of names) {
|
|
156
|
+
lines.push(`import ${toIdent(name)} from '${toImportPath(available.get(name))}';`);
|
|
157
|
+
}
|
|
158
|
+
for (const name of names) {
|
|
159
|
+
lines.push(`registerSymbol(${toIdent(name)});`);
|
|
160
|
+
}
|
|
161
|
+
lines.push('');
|
|
162
|
+
return lines.join('\n');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function buildRegistryModule() {
|
|
166
|
+
const names = [...available.keys()].sort();
|
|
167
|
+
if (names.length === 0) return 'export const registry = {};\n';
|
|
168
|
+
const lines = ['export const registry = {'];
|
|
169
|
+
for (const name of names) {
|
|
170
|
+
lines.push(` '${name}': () => import('${toImportPath(available.get(name))}'),`);
|
|
171
|
+
}
|
|
172
|
+
lines.push('};', '');
|
|
173
|
+
return lines.join('\n');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async function refresh() {
|
|
177
|
+
await loadAvailable();
|
|
178
|
+
const next = await scanUsage();
|
|
179
|
+
const same =
|
|
180
|
+
next.size === used.size && [...next].every((x) => used.has(x));
|
|
181
|
+
used = next;
|
|
182
|
+
return !same;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return {
|
|
186
|
+
name: 'vite-plugin-hy-svg-icons',
|
|
187
|
+
enforce: 'pre',
|
|
188
|
+
|
|
189
|
+
configResolved(config) {
|
|
190
|
+
projectRoot = config.root || process.cwd();
|
|
191
|
+
dataDirAbs = path.resolve(projectRoot, dataDir);
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
async buildStart() {
|
|
195
|
+
await refresh();
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
resolveId(id) {
|
|
199
|
+
if (id === STATIC_VIRTUAL_ID) return STATIC_RESOLVED_ID;
|
|
200
|
+
if (id === REGISTRY_VIRTUAL_ID) return REGISTRY_RESOLVED_ID;
|
|
201
|
+
return null;
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
load(id) {
|
|
205
|
+
if (id === STATIC_RESOLVED_ID) return buildStaticModule();
|
|
206
|
+
if (id === REGISTRY_RESOLVED_ID) return buildRegistryModule();
|
|
207
|
+
return null;
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
configureServer(s) {
|
|
211
|
+
server = s;
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
async handleHotUpdate(ctx) {
|
|
215
|
+
const ext = path.extname(ctx.file);
|
|
216
|
+
const inDataDir = ctx.file.startsWith(dataDirAbs + path.sep);
|
|
217
|
+
if (!extSet.has(ext) && !inDataDir) return;
|
|
218
|
+
|
|
219
|
+
const changed = await refresh();
|
|
220
|
+
if (!changed || !server) return;
|
|
221
|
+
|
|
222
|
+
const staticMod = server.moduleGraph.getModuleById(STATIC_RESOLVED_ID);
|
|
223
|
+
const registryMod = server.moduleGraph.getModuleById(REGISTRY_RESOLVED_ID);
|
|
224
|
+
let invalidated = false;
|
|
225
|
+
if (staticMod) {
|
|
226
|
+
server.moduleGraph.invalidateModule(staticMod);
|
|
227
|
+
invalidated = true;
|
|
228
|
+
}
|
|
229
|
+
if (registryMod) {
|
|
230
|
+
server.moduleGraph.invalidateModule(registryMod);
|
|
231
|
+
invalidated = true;
|
|
232
|
+
}
|
|
233
|
+
if (invalidated) {
|
|
234
|
+
server.ws.send({ type: 'full-reload' });
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export default hySvgIconsPlugin;
|
package/es/utils/date.mjs
CHANGED
|
@@ -94,7 +94,8 @@ const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
|
|
|
94
94
|
videoPlayer: {
|
|
95
95
|
type: Object,
|
|
96
96
|
required: false
|
|
97
|
-
}
|
|
97
|
+
},
|
|
98
|
+
ensureHyIcon: Function
|
|
98
99
|
},
|
|
99
100
|
setup(__props) {
|
|
100
101
|
const props = __props;
|
|
@@ -107,6 +108,7 @@ const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
|
|
|
107
108
|
permissionMap,
|
|
108
109
|
audioPlayer,
|
|
109
110
|
videoPlayer,
|
|
111
|
+
ensureHyIcon,
|
|
110
112
|
...config2
|
|
111
113
|
} = globalConfig.value;
|
|
112
114
|
return {
|