@haiyue/ui 0.2.2 → 0.3.1

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 (145) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +523 -4
  3. package/dist/adapters/web/controls.js +48 -8
  4. package/dist/adapters/web/renderer.js +9 -11
  5. package/dist/adapters/web/styles.d.ts +2 -3
  6. package/dist/adapters/web/styles.js +26 -23
  7. package/dist/alert.d.ts +39 -0
  8. package/dist/alert.js +144 -0
  9. package/dist/anchor.d.ts +62 -0
  10. package/dist/anchor.js +293 -0
  11. package/dist/auto-complete.d.ts +83 -0
  12. package/dist/auto-complete.js +267 -0
  13. package/dist/avatar.d.ts +45 -0
  14. package/dist/avatar.js +135 -0
  15. package/dist/badge.js +5 -5
  16. package/dist/border-beam.js +3 -2
  17. package/dist/breadcrumb.js +5 -5
  18. package/dist/button-group.js +8 -8
  19. package/dist/button.js +10 -10
  20. package/dist/card.d.ts +29 -0
  21. package/dist/card.js +101 -0
  22. package/dist/carousel.js +6 -6
  23. package/dist/cascader.js +19 -13
  24. package/dist/checkbox.d.ts +12 -0
  25. package/dist/checkbox.js +22 -6
  26. package/dist/collapse.js +6 -6
  27. package/dist/context-menu.js +3 -4
  28. package/dist/core/actions.js +7 -8
  29. package/dist/core/data.d.ts +1 -1
  30. package/dist/core/data.js +44 -10
  31. package/dist/core/platform-view.js +8 -2
  32. package/dist/core/selection.js +4 -4
  33. package/dist/core/semantics.d.ts +26 -0
  34. package/dist/core/semantics.js +8 -0
  35. package/dist/core/text.js +3 -3
  36. package/dist/core/validation.d.ts +3 -1
  37. package/dist/core/validation.js +23 -5
  38. package/dist/date-picker.js +19 -13
  39. package/dist/descriptions.d.ts +44 -0
  40. package/dist/descriptions.js +169 -0
  41. package/dist/dialog.d.ts +4 -0
  42. package/dist/dialog.js +48 -27
  43. package/dist/divider.js +2 -2
  44. package/dist/draggable.js +5 -3
  45. package/dist/drawer.js +16 -24
  46. package/dist/dropdown.js +3 -4
  47. package/dist/empty.d.ts +20 -0
  48. package/dist/empty.js +58 -0
  49. package/dist/expandable.js +4 -4
  50. package/dist/form-item.d.ts +60 -0
  51. package/dist/form-item.js +212 -0
  52. package/dist/form.d.ts +41 -0
  53. package/dist/form.js +154 -0
  54. package/dist/history-controls.js +5 -5
  55. package/dist/image-preview.d.ts +22 -0
  56. package/dist/image-preview.js +38 -0
  57. package/dist/image.d.ts +52 -0
  58. package/dist/image.js +152 -0
  59. package/dist/index.d.ts +48 -0
  60. package/dist/index.js +72 -0
  61. package/dist/input.d.ts +11 -0
  62. package/dist/input.js +32 -18
  63. package/dist/internal/anchored-popup.d.ts +19 -0
  64. package/dist/internal/anchored-popup.js +89 -0
  65. package/dist/internal/focus.d.ts +2 -0
  66. package/dist/internal/focus.js +31 -0
  67. package/dist/internal/form-control.d.ts +22 -0
  68. package/dist/internal/form-control.js +52 -0
  69. package/dist/internal/image-viewer.d.ts +51 -0
  70. package/dist/internal/image-viewer.js +210 -0
  71. package/dist/internal/keyboard.d.ts +2 -0
  72. package/dist/internal/keyboard.js +12 -0
  73. package/dist/internal/numbers.d.ts +2 -0
  74. package/dist/internal/numbers.js +8 -0
  75. package/dist/internal/pagination.d.ts +35 -0
  76. package/dist/internal/pagination.js +169 -0
  77. package/dist/internal/popover-base.d.ts +87 -0
  78. package/dist/internal/popover-base.js +365 -0
  79. package/dist/internal/presentation.d.ts +2 -0
  80. package/dist/internal/presentation.js +28 -0
  81. package/dist/mentions.d.ts +115 -0
  82. package/dist/mentions.js +485 -0
  83. package/dist/menu-shared.d.ts +1 -1
  84. package/dist/menu-shared.js +3 -3
  85. package/dist/menu.d.ts +63 -0
  86. package/dist/menu.js +339 -0
  87. package/dist/modal.js +11 -40
  88. package/dist/notification.js +11 -10
  89. package/dist/pagination.d.ts +34 -0
  90. package/dist/pagination.js +73 -0
  91. package/dist/popconfirm.d.ts +6 -0
  92. package/dist/popconfirm.js +7 -0
  93. package/dist/popover.d.ts +6 -0
  94. package/dist/popover.js +7 -0
  95. package/dist/portable/page.js +25 -14
  96. package/dist/progress.d.ts +30 -0
  97. package/dist/progress.js +102 -0
  98. package/dist/qr-code.js +3 -3
  99. package/dist/radio.d.ts +10 -0
  100. package/dist/radio.js +18 -5
  101. package/dist/range.js +7 -7
  102. package/dist/rate.js +3 -3
  103. package/dist/resizable.js +8 -5
  104. package/dist/result.d.ts +22 -0
  105. package/dist/result.js +88 -0
  106. package/dist/ribbon.d.ts +19 -0
  107. package/dist/ribbon.js +106 -0
  108. package/dist/segmented.d.ts +39 -0
  109. package/dist/segmented.js +192 -0
  110. package/dist/select.d.ts +12 -0
  111. package/dist/select.js +31 -13
  112. package/dist/skeleton.js +10 -10
  113. package/dist/spin.d.ts +26 -0
  114. package/dist/spin.js +80 -0
  115. package/dist/steps.js +13 -13
  116. package/dist/switch.d.ts +44 -0
  117. package/dist/switch.js +104 -0
  118. package/dist/table.d.ts +3 -3
  119. package/dist/table.js +110 -128
  120. package/dist/tabs.js +7 -7
  121. package/dist/tag.js +8 -8
  122. package/dist/time-picker.js +16 -10
  123. package/dist/timeline.js +12 -12
  124. package/dist/toast.js +12 -11
  125. package/dist/tooltip.d.ts +6 -0
  126. package/dist/tooltip.js +107 -6
  127. package/dist/tour.js +26 -17
  128. package/dist/tree-model.d.ts +2 -0
  129. package/dist/tree-model.js +32 -11
  130. package/dist/tree-node.js +2 -2
  131. package/dist/tree-select.d.ts +94 -0
  132. package/dist/tree-select.js +398 -0
  133. package/dist/tree.d.ts +0 -2
  134. package/dist/tree.js +14 -29
  135. package/dist/upload.d.ts +108 -0
  136. package/dist/upload.js +358 -0
  137. package/dist/virtual-keyboard.d.ts +1 -0
  138. package/dist/virtual-keyboard.js +72 -41
  139. package/dist/virtual-list.d.ts +1 -0
  140. package/dist/virtual-list.js +25 -8
  141. package/dist/virtual-mouse.js +7 -6
  142. package/dist/watermark.js +2 -1
  143. package/package.json +82 -1
  144. package/themes/haiyue-dark.css +51 -0
  145. package/themes/haiyue-light.css +51 -0
package/dist/upload.js ADDED
@@ -0,0 +1,358 @@
1
+ let uploadFileId = 0;
2
+ export class HYUpload extends HTMLElement {
3
+ static formAssociated = true;
4
+ _internals = this.attachInternals();
5
+ _input = document.createElement('input');
6
+ _zone = document.createElement('div');
7
+ _button = document.createElement('button');
8
+ _slot = document.createElement('slot');
9
+ _list = document.createElement('ul');
10
+ _message = document.createElement('div');
11
+ _files = [];
12
+ _initialFiles = null;
13
+ _request = null;
14
+ _beforeUpload = null;
15
+ _requests = new Map();
16
+ _rows = new Map();
17
+ _listeners = null;
18
+ _formDisabled = false;
19
+ _selection = 0;
20
+ _dragDepth = 0;
21
+ static get observedAttributes() { return ['name', 'accept', 'multiple', 'disabled', 'drag', 'required', 'max-count', 'max-size', 'auto-upload', 'label', 'aria-label', 'show-file-list']; }
22
+ constructor() {
23
+ super();
24
+ const root = this.attachShadow({ mode: 'open' });
25
+ const style = document.createElement('style');
26
+ style.textContent = `
27
+ :host { display: block; min-width: 0; color: var(--hy-text-color, #d8e2f2); font: var(--hy-font-size-sm, 12px)/1.5 var(--hy-font-family, system-ui, sans-serif); }
28
+ input { display: none; } .zone { display: flex; align-items: center; gap: var(--hy-space-4, 8px); }
29
+ :host([drag]) .zone { flex-direction: column; padding: var(--hy-space-12, 24px); border: 1px dashed var(--hy-border-color, #303746); border-radius: var(--hy-radius-md, 6px); background: var(--hy-surface-color, #121822); }
30
+ :host([drag]) .zone.dragover { border-color: var(--hy-accent-color, #8177f2); background: var(--hy-hover-bg-color, #273241); }
31
+ button { min-height: var(--hy-control-height-sm, 28px); padding: 0 var(--hy-space-5, 10px); border: 1px solid var(--hy-border-color, #303746); border-radius: var(--hy-radius-sm, 4px); color: inherit; background: var(--hy-surface-elevated-color, #202733); font: inherit; cursor: pointer; }
32
+ button:hover:not(:disabled) { background: var(--hy-hover-bg-color, #273241); } button:focus-visible { outline: 2px solid var(--hy-focus-border-color, #79a8ff); outline-offset: 2px; }
33
+ button:disabled { opacity: .55; cursor: not-allowed; } ul { list-style: none; margin: var(--hy-space-4, 8px) 0 0; padding: 0; }
34
+ li { display: grid; grid-template-columns: minmax(0,1fr) auto auto auto; align-items: center; gap: var(--hy-space-3, 6px); padding: var(--hy-space-3, 6px) 0; border-bottom: 1px solid var(--hy-border-color, #303746); }
35
+ .name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } .status { color: var(--hy-muted-text-color, #8290a3); } li.error .status { color: var(--hy-error-color, #d95d72); }
36
+ progress { grid-column: 1 / -1; width: 100%; height: 5px; accent-color: var(--hy-accent-color, #8177f2); }
37
+ .message { margin-top: var(--hy-space-3, 6px); color: var(--hy-error-color, #d95d72); } [hidden] { display: none !important; }
38
+ `;
39
+ this._input.type = 'file';
40
+ this._input.tabIndex = -1;
41
+ this._input.part.add('input');
42
+ this._zone.className = 'zone';
43
+ this._zone.part.add('dropzone');
44
+ this._button.type = 'button';
45
+ this._button.part.add('trigger');
46
+ this._list.part.add('list');
47
+ this._list.setAttribute('aria-label', 'Selected files');
48
+ this._message.className = 'message';
49
+ this._message.part.add('message');
50
+ this._message.setAttribute('role', 'status');
51
+ this._zone.append(this._button, this._slot);
52
+ root.append(style, this._input, this._zone, this._list, this._message);
53
+ }
54
+ connectedCallback() {
55
+ this._initialFiles ??= this.fileList;
56
+ this._listeners?.abort();
57
+ this._listeners = new AbortController();
58
+ const { signal } = this._listeners;
59
+ this._button.addEventListener('click', () => this.openFileDialog(), { signal });
60
+ // Native picker input precedes asynchronous acceptance; notify only after committing files.
61
+ this._input.addEventListener('input', event => event.stopPropagation(), { signal });
62
+ this._input.addEventListener('change', event => { event.stopPropagation(); const files = [...(this._input.files ?? [])]; this._input.value = ''; void this.selectFiles(files); }, { signal });
63
+ this._zone.addEventListener('dragenter', this._onDragEnter, { signal });
64
+ this._zone.addEventListener('dragleave', this._onDragLeave, { signal });
65
+ this._zone.addEventListener('dragover', this._onDragOver, { signal });
66
+ this._zone.addEventListener('drop', this._onDrop, { signal });
67
+ this._list.addEventListener('click', this._onListClick, { signal });
68
+ this._sync();
69
+ }
70
+ disconnectedCallback() { this._listeners?.abort(); this._listeners = null; this._selection++; this.abort(); this._dragDepth = 0; this._zone.classList.remove('dragover'); }
71
+ attributeChangedCallback(name, previous, next) {
72
+ if (previous === next)
73
+ return;
74
+ if (name === 'disabled' && this.disabled) {
75
+ this._selection++;
76
+ this.abort();
77
+ }
78
+ this._sync();
79
+ }
80
+ get fileList() { return this._files.map(file => ({ ...file })); }
81
+ set fileList(value) {
82
+ const seen = new Set();
83
+ const files = (Array.isArray(value) ? value : []).filter(file => file && typeof file.uid === 'string' && file.uid && typeof file.name === 'string' && !seen.has(file.uid) && Boolean(seen.add(file.uid)))
84
+ .map(file => ({ ...file, status: file.status === 'uploading' || file.status === 'done' || file.status === 'error' ? file.status : 'ready' }));
85
+ this.abort();
86
+ this._selection++;
87
+ this._files = files;
88
+ this._sync();
89
+ }
90
+ get files() { return this._files.flatMap(file => file.file ? [file.file] : []); }
91
+ get request() { return this._request; }
92
+ set request(value) { this.abort(); this._request = typeof value === 'function' ? value : null; }
93
+ get beforeUpload() { return this._beforeUpload; }
94
+ set beforeUpload(value) { this._selection++; this._beforeUpload = typeof value === 'function' ? value : null; }
95
+ get name() { return this.getAttribute('name') ?? ''; }
96
+ set name(value) { this.setAttribute('name', value); }
97
+ get accept() { return this.getAttribute('accept') ?? ''; }
98
+ set accept(value) { this.setAttribute('accept', value); }
99
+ get multiple() { return this.hasAttribute('multiple'); }
100
+ set multiple(value) { this.toggleAttribute('multiple', value); }
101
+ get disabled() { return this.hasAttribute('disabled'); }
102
+ set disabled(value) { this.toggleAttribute('disabled', value); }
103
+ get drag() { return this.hasAttribute('drag'); }
104
+ set drag(value) { this.toggleAttribute('drag', value); }
105
+ get maxCount() { return nonnegative(this.getAttribute('max-count')); }
106
+ set maxCount(value) { this.setAttribute('max-count', String(value)); }
107
+ get maxSize() { return nonnegative(this.getAttribute('max-size')); }
108
+ set maxSize(value) { this.setAttribute('max-size', String(value)); }
109
+ get autoUpload() { return this.getAttribute('auto-upload') !== 'false'; }
110
+ set autoUpload(value) { this.setAttribute('auto-upload', String(value)); }
111
+ get showFileList() { return this.getAttribute('show-file-list') !== 'false'; }
112
+ set showFileList(value) { this.setAttribute('show-file-list', String(value)); }
113
+ get form() { return this._internals.form; }
114
+ get validity() { return this._internals.validity; }
115
+ get validationMessage() { return this._internals.validationMessage; }
116
+ checkValidity() { return this._internals.checkValidity(); }
117
+ reportValidity() { return this._internals.reportValidity(); }
118
+ formDisabledCallback(disabled) { this._formDisabled = disabled; if (disabled) {
119
+ this._selection++;
120
+ this.abort();
121
+ } this._sync(); }
122
+ formResetCallback() { this.fileList = this._initialFiles ?? []; this._message.textContent = ''; }
123
+ focus(options) { this._button.focus(options); }
124
+ openFileDialog() { if (!this.disabled && !this._formDisabled)
125
+ this._input.click(); }
126
+ async selectFiles(value) {
127
+ if (this.disabled || this._formDisabled || !this.isConnected)
128
+ return;
129
+ const selection = ++this._selection;
130
+ const files = [...value].filter(file => file instanceof File);
131
+ const accepted = [];
132
+ this._message.textContent = '';
133
+ for (const file of files) {
134
+ if (this.maxSize && file.size > this.maxSize) {
135
+ this._reject(file, 'size', 'File exceeds the size limit');
136
+ continue;
137
+ }
138
+ if (!matchesAccept(file, this.accept)) {
139
+ this._reject(file, 'type', 'File type is not accepted');
140
+ continue;
141
+ }
142
+ const limit = this.multiple ? this.maxCount : 1;
143
+ if (limit && (this.multiple ? this._files.length : 0) + accepted.length >= limit) {
144
+ this._reject(file, 'count', 'Too many files');
145
+ continue;
146
+ }
147
+ try {
148
+ if (this._beforeUpload && !await this._beforeUpload(file, files)) {
149
+ if (selection !== this._selection)
150
+ return;
151
+ this._reject(file, 'before-upload', 'File was rejected');
152
+ continue;
153
+ }
154
+ }
155
+ catch (cause) {
156
+ if (selection !== this._selection)
157
+ return;
158
+ this._reject(file, 'error', cause instanceof Error ? cause.message : 'File validation failed');
159
+ continue;
160
+ }
161
+ if (selection !== this._selection || !this.isConnected || this.disabled || this._formDisabled)
162
+ return;
163
+ accepted.push({ uid: `hy-upload-${++uploadFileId}`, name: file.name, size: file.size, type: file.type, file, status: 'ready', percent: 0 });
164
+ }
165
+ if (selection !== this._selection || !this.isConnected || !accepted.length)
166
+ return;
167
+ if (!this.multiple) {
168
+ this.abort();
169
+ this._files = [];
170
+ }
171
+ this._files.push(...accepted);
172
+ this._sync();
173
+ this._notifyValueChange();
174
+ for (const file of accepted)
175
+ this._emit(file, 'select');
176
+ if (this.autoUpload && this._request)
177
+ await Promise.all(accepted.map(file => this._upload(file.uid)));
178
+ }
179
+ async upload(uid) {
180
+ if (!this._request || this.disabled || this._formDisabled || !this.isConnected)
181
+ return;
182
+ await Promise.all(this._files.filter(file => (!uid || file.uid === uid) && file.status !== 'done').map(file => this._upload(file.uid)));
183
+ }
184
+ abort(uid) {
185
+ for (const [id, controller] of this._requests) {
186
+ if (uid && id !== uid)
187
+ continue;
188
+ controller.abort();
189
+ this._requests.delete(id);
190
+ const file = this._files.find(file => file.uid === id);
191
+ if (file) {
192
+ file.status = 'ready';
193
+ file.percent = 0;
194
+ this._emit(file, 'abort');
195
+ }
196
+ }
197
+ this._sync();
198
+ }
199
+ removeFile(uid) {
200
+ if (this.disabled || this._formDisabled)
201
+ return false;
202
+ const file = this._files.find(file => file.uid === uid);
203
+ if (!file)
204
+ return false;
205
+ if (!this.dispatchEvent(new CustomEvent('file-remove', { detail: { file: { ...file } }, bubbles: true, composed: true, cancelable: true })))
206
+ return false;
207
+ this.abort(uid);
208
+ this._files = this._files.filter(file => file.uid !== uid);
209
+ this._sync();
210
+ this._notifyValueChange();
211
+ this._emit(file, 'remove');
212
+ return true;
213
+ }
214
+ async _upload(uid) {
215
+ const request = this._request;
216
+ const file = this._files.find(file => file.uid === uid);
217
+ if (!request || !file?.file || this._requests.has(uid) || !this.isConnected || this.disabled || this._formDisabled)
218
+ return;
219
+ const controller = new AbortController();
220
+ this._requests.set(uid, controller);
221
+ file.status = 'uploading';
222
+ file.percent = 0;
223
+ delete file.error;
224
+ this._sync();
225
+ this._emit(file, 'start');
226
+ if (controller.signal.aborted)
227
+ return;
228
+ try {
229
+ const response = await request({ file: file.file, signal: controller.signal, onProgress: percent => {
230
+ if (!controller.signal.aborted && this._requests.get(uid) === controller && Number.isFinite(percent)) {
231
+ file.percent = Math.max(0, Math.min(100, percent));
232
+ this._sync();
233
+ this._emit(file, 'progress');
234
+ }
235
+ } });
236
+ if (controller.signal.aborted || this._requests.get(uid) !== controller)
237
+ return;
238
+ file.status = 'done';
239
+ file.percent = 100;
240
+ file.response = response;
241
+ this._sync();
242
+ this._emit(file, 'success');
243
+ }
244
+ catch (cause) {
245
+ if (controller.signal.aborted || this._requests.get(uid) !== controller)
246
+ return;
247
+ file.status = 'error';
248
+ file.error = cause instanceof Error ? cause.message : 'Upload failed';
249
+ this._sync();
250
+ this._emit(file, 'error');
251
+ }
252
+ finally {
253
+ if (this._requests.get(uid) === controller)
254
+ this._requests.delete(uid);
255
+ }
256
+ }
257
+ _notifyValueChange() { this.dispatchEvent(new Event('change', { bubbles: true, composed: true })); }
258
+ _emit(file, reason) { this.dispatchEvent(new CustomEvent('upload-change', { detail: { file: { ...file }, fileList: this.fileList, reason }, bubbles: true, composed: true })); }
259
+ _reject(file, reason, message) { this._message.textContent = `${file.name}: ${message}`; this.dispatchEvent(new CustomEvent('file-reject', { detail: { file, reason, message }, bubbles: true, composed: true })); }
260
+ _sync() {
261
+ const disabled = this.disabled || this._formDisabled;
262
+ this._input.disabled = this._button.disabled = disabled;
263
+ this._input.accept = this.accept;
264
+ this._input.multiple = this.multiple;
265
+ this._button.textContent = this.getAttribute('label') || 'Choose files';
266
+ this._button.setAttribute('aria-label', this.getAttribute('aria-label') || this.getAttribute('label') || 'Choose files');
267
+ this._zone.setAttribute('aria-disabled', String(disabled));
268
+ this._list.hidden = !this.showFileList || !this._files.length;
269
+ for (const [uid, row] of this._rows)
270
+ if (!this._files.some(file => file.uid === uid)) {
271
+ row.row.remove();
272
+ this._rows.delete(uid);
273
+ }
274
+ this._files.forEach((file, index) => {
275
+ let record = this._rows.get(file.uid);
276
+ if (!record) {
277
+ const row = document.createElement('li');
278
+ row.part.add('file');
279
+ const name = document.createElement('span');
280
+ name.className = 'name';
281
+ name.part.add('file-name');
282
+ const status = document.createElement('span');
283
+ status.className = 'status';
284
+ status.part.add('file-status');
285
+ const progress = document.createElement('progress');
286
+ progress.max = 100;
287
+ progress.part.add('progress');
288
+ const remove = document.createElement('button');
289
+ remove.type = 'button';
290
+ remove.dataset.remove = file.uid;
291
+ remove.textContent = '×';
292
+ remove.part.add('remove');
293
+ const retry = document.createElement('button');
294
+ retry.type = 'button';
295
+ retry.dataset.retry = file.uid;
296
+ retry.textContent = 'Retry';
297
+ retry.part.add('retry');
298
+ row.append(name, status, retry, remove, progress);
299
+ record = { row, name, status, progress, remove, retry };
300
+ this._rows.set(file.uid, record);
301
+ }
302
+ record.row.className = file.status;
303
+ if (record.name.textContent !== file.name)
304
+ record.name.textContent = file.name;
305
+ record.name.title = file.name;
306
+ record.status.textContent = file.status === 'uploading' ? `${Math.round(file.percent ?? 0)}%` : file.error || file.status;
307
+ record.progress.hidden = file.status !== 'uploading';
308
+ record.progress.value = file.percent ?? 0;
309
+ record.progress.setAttribute('aria-label', `Upload ${file.name}`);
310
+ record.remove.disabled = disabled;
311
+ record.remove.setAttribute('aria-label', `Remove ${file.name}`);
312
+ record.retry.hidden = file.status !== 'error' || !this._request;
313
+ record.retry.disabled = disabled;
314
+ record.retry.setAttribute('aria-label', `Retry ${file.name}`);
315
+ if (this._list.children[index] !== record.row)
316
+ this._list.insertBefore(record.row, this._list.children[index] ?? null);
317
+ });
318
+ const data = new FormData();
319
+ for (const file of this.files)
320
+ data.append(this.name, file);
321
+ this._internals.setFormValue(disabled || !this.name ? null : data);
322
+ const missing = !disabled && this.hasAttribute('required') && !this._files.length;
323
+ this._internals.setValidity(missing ? { valueMissing: true } : {}, missing ? 'Choose a file' : '', this._button);
324
+ }
325
+ _onListClick = (event) => {
326
+ const button = event.target instanceof Element ? event.target.closest('button') : null;
327
+ if (button?.dataset.remove)
328
+ this.removeFile(button.dataset.remove);
329
+ else if (button?.dataset.retry)
330
+ void this.upload(button.dataset.retry);
331
+ };
332
+ _onDragEnter = (event) => { if (!this.drag)
333
+ return; event.preventDefault(); if (!this.disabled && !this._formDisabled) {
334
+ this._dragDepth++;
335
+ this._zone.classList.add('dragover');
336
+ } };
337
+ _onDragLeave = (event) => { if (!this.drag)
338
+ return; event.preventDefault(); if (--this._dragDepth <= 0) {
339
+ this._dragDepth = 0;
340
+ this._zone.classList.remove('dragover');
341
+ } };
342
+ _onDragOver = (event) => { if (this.drag) {
343
+ event.preventDefault();
344
+ if (event.dataTransfer)
345
+ event.dataTransfer.dropEffect = this.disabled || this._formDisabled ? 'none' : 'copy';
346
+ } };
347
+ _onDrop = (event) => { if (!this.drag)
348
+ return; event.preventDefault(); this._dragDepth = 0; this._zone.classList.remove('dragover'); if (event.dataTransfer)
349
+ void this.selectFiles(event.dataTransfer.files); };
350
+ }
351
+ function nonnegative(value) { const number = Number(value); return Number.isFinite(number) ? Math.max(0, number) : 0; }
352
+ function matchesAccept(file, accept) {
353
+ const tokens = accept.toLowerCase().split(',').map(token => token.trim()).filter(Boolean);
354
+ return !tokens.length || tokens.some(token => token === '*' || token === '*/*' || (token.startsWith('.') ? file.name.toLowerCase().endsWith(token) : token.endsWith('/*') ? file.type.toLowerCase().startsWith(token.slice(0, -1)) : file.type.toLowerCase() === token));
355
+ }
356
+ export function defineUploadComponents() { if (!customElements.get('hy-upload'))
357
+ customElements.define('hy-upload', HYUpload); }
358
+ //# sourceMappingURL=upload.js.map
@@ -77,6 +77,7 @@ export declare class HYVirtualKeyboard extends HTMLElement {
77
77
  private _press;
78
78
  private _release;
79
79
  private _applyKey;
80
+ private _editableTarget;
80
81
  private _insertText;
81
82
  private _deleteBackward;
82
83
  private _deleteForward;
@@ -1,3 +1,10 @@
1
+ const textSegmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
2
+ function textBoundaries(value) {
3
+ return [0, ...Array.from(textSegmenter.segment(value), part => part.index + part.segment.length)];
4
+ }
5
+ function boundaryBefore(edges, position) { return edges.filter(edge => edge < position).at(-1) ?? 0; }
6
+ function boundaryFloor(edges, position) { return edges.filter(edge => edge <= position).at(-1) ?? 0; }
7
+ function boundaryCeil(edges, position) { return edges.find(edge => edge >= position) ?? edges.at(-1); }
1
8
  const LETTERS = 'QWERTYUIOPASDFGHJKLZXCVBNM';
2
9
  const DIGITS = [
3
10
  ['Digit1', '1', '!'], ['Digit2', '2', '@'], ['Digit3', '3', '#'], ['Digit4', '4', '$'], ['Digit5', '5', '%'],
@@ -70,16 +77,16 @@ export class HYVirtualKeyboard extends HTMLElement {
70
77
  const root = this.attachShadow({ mode: 'open' });
71
78
  const style = document.createElement('style');
72
79
  style.textContent = `
73
- :host { display: block; min-width: 0; color: var(--hy-text-color, #eef3ff); font: 12px/1 system-ui, sans-serif; }
74
- .keyboard { display: grid; gap: var(--hy-virtual-keyboard-row-gap, 7px); box-sizing: border-box; padding: var(--hy-virtual-keyboard-padding, 12px); border: 1px solid var(--hy-border-color, #3d4654); border-radius: var(--hy-virtual-keyboard-radius, 11px); background: var(--hy-virtual-keyboard-bg, var(--hy-surface-color, #111722)); box-shadow: var(--hy-virtual-keyboard-shadow, 0 16px 40px rgba(0, 0, 0, .22)); user-select: none; touch-action: manipulation; }
75
- .row { display: flex; gap: var(--hy-virtual-keyboard-key-gap, 6px); min-width: 0; }
76
- .key { position: relative; min-width: 0; height: var(--hy-virtual-keyboard-key-height, 42px); flex: var(--_key-width, 1) 1 0; overflow: hidden; padding: 0 5px; border: 1px solid var(--hy-virtual-keyboard-key-border, var(--hy-border-color, #3d4654)); border-radius: var(--hy-virtual-keyboard-key-radius, 7px); color: var(--hy-virtual-keyboard-key-color, var(--hy-text-color, #eef3ff)); background: var(--hy-virtual-keyboard-key-bg, var(--hy-surface-elevated-color, #171d27)); box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--hy-border-color, #3d4654) 65%, transparent); cursor: pointer; font: inherit; text-overflow: ellipsis; white-space: nowrap; transition: translate 70ms ease, background-color 70ms ease, box-shadow 70ms ease; }
80
+ :host { display: block; min-width: 0; color: var(--hy-text-color, #eef3ff); font: var(--hy-font-size-sm, 12px)/var(--hy-line-height-tight, 1) var(--hy-font-family, system-ui, sans-serif); }
81
+ .keyboard { display: grid; gap: var(--hy-virtual-keyboard-row-gap, calc(var(--hy-space-3, 6px) + 1px)); box-sizing: border-box; padding: var(--hy-virtual-keyboard-padding, var(--hy-space-6, 12px)); border: 1px solid var(--hy-border-color, #3d4654); border-radius: var(--hy-virtual-keyboard-radius, calc(var(--hy-radius-xl, 12px) - 1px)); background: var(--hy-virtual-keyboard-bg, var(--hy-surface-color, #111722)); box-shadow: var(--hy-virtual-keyboard-shadow, 0 16px 40px var(--hy-shadow-color, rgba(0, 0, 0, .22))); user-select: none; touch-action: manipulation; }
82
+ .row { display: flex; gap: var(--hy-virtual-keyboard-key-gap, var(--hy-space-3, 6px)); min-width: 0; }
83
+ .key { position: relative; min-width: 0; height: var(--hy-virtual-keyboard-key-height, calc(var(--hy-control-height-lg, 44px) - 2px)); flex: var(--_key-width, 1) 1 0; overflow: hidden; padding: 0 calc(var(--hy-space-2, 4px) + 1px); border: 1px solid var(--hy-virtual-keyboard-key-border, var(--hy-border-color, #3d4654)); border-radius: var(--hy-virtual-keyboard-key-radius, calc(var(--hy-radius-md, 6px) + 1px)); color: var(--hy-virtual-keyboard-key-color, var(--hy-text-color, #eef3ff)); background: var(--hy-virtual-keyboard-key-bg, var(--hy-surface-elevated-color, #171d27)); box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--hy-border-color, #3d4654) 65%, transparent); cursor: pointer; font: inherit; text-overflow: ellipsis; white-space: nowrap; transition: translate 70ms ease, background-color 70ms ease, box-shadow 70ms ease; }
77
84
  .key:hover:not(:disabled) { border-color: var(--hy-hover-border-color, #596779); background: var(--hy-hover-bg-color, #273241); }
78
85
  .key:focus-visible { z-index: 1; outline: 2px solid var(--hy-focus-border-color, #79a8ff); outline-offset: 1px; }
79
86
  .key.pressed, .key[aria-pressed="true"] { translate: 0 1px; border-color: var(--hy-selected-bg-color, #554cc6); background: var(--hy-virtual-keyboard-active-bg, color-mix(in srgb, var(--hy-selected-bg-color, #554cc6) 50%, var(--hy-surface-elevated-color, #171d27))); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hy-focus-border-color, #79a8ff) 24%, transparent); }
80
87
  .key:disabled { opacity: .42; cursor: not-allowed; }
81
88
  :host([disabled]) .keyboard { opacity: .62; }
82
- @media (max-width: 620px) { .keyboard { --hy-virtual-keyboard-padding: 7px; --hy-virtual-keyboard-row-gap: 5px; --hy-virtual-keyboard-key-gap: 3px; --hy-virtual-keyboard-key-height: 36px; font-size: 9px; } }
89
+ @media (max-width: 620px) { .keyboard { --hy-virtual-keyboard-padding: calc(var(--hy-space-3, 6px) + 1px); --hy-virtual-keyboard-row-gap: calc(var(--hy-space-2, 4px) + 1px); --hy-virtual-keyboard-key-gap: calc(var(--hy-space-1, 2px) + 1px); --hy-virtual-keyboard-key-height: calc(var(--hy-control-height-md, 34px) + 2px); font-size: calc(var(--hy-font-size-xs, 10px) - 1px); } }
83
90
  @media (prefers-reduced-motion: reduce) { .key { transition: none; } }
84
91
  `;
85
92
  this._keyboard.className = 'keyboard';
@@ -152,7 +159,8 @@ export class HYVirtualKeyboard extends HTMLElement {
152
159
  const operation = ++this._operation;
153
160
  const requested = options.interval == null ? 45 : Number(options.interval);
154
161
  const interval = Number.isFinite(requested) ? Math.min(10_000, Math.max(0, requested)) : 45;
155
- for (const character of String(text)) {
162
+ for (const part of textSegmenter.segment(String(text))) {
163
+ const character = part.segment;
156
164
  if (operation !== this._operation || !this.isConnected)
157
165
  return;
158
166
  const match = this._findCharacterKey(character);
@@ -169,10 +177,11 @@ export class HYVirtualKeyboard extends HTMLElement {
169
177
  }
170
178
  }
171
179
  clear() {
172
- if (!this._target || this.disabled || this._target.disabled || this._target.readOnly)
180
+ const target = this._editableTarget();
181
+ if (!target)
173
182
  return;
174
- this._target.value = '';
175
- this._target.setSelectionRange(0, 0);
183
+ target.value = '';
184
+ target.setSelectionRange(0, 0);
176
185
  this._dispatchTargetInput('deleteContent', null);
177
186
  this._emitInput({ code: 'Clear', key: '', action: 'delete', source: 'api' }, 'deleteContent');
178
187
  }
@@ -279,6 +288,8 @@ export class HYVirtualKeyboard extends HTMLElement {
279
288
  this._dispatchKeyEvent('virtual-keyboard-up', key, resolvedValue, source);
280
289
  }
281
290
  _applyKey(key, resolvedValue, source) {
291
+ if (!this._editableTarget(false))
292
+ return;
282
293
  const descriptor = { code: key.code, key: resolvedValue, action: key.action ?? 'character', source };
283
294
  if (key.action === 'shift' || key.action === 'caps-lock')
284
295
  return;
@@ -313,69 +324,89 @@ export class HYVirtualKeyboard extends HTMLElement {
313
324
  else
314
325
  this._insertText(key.action === 'space' ? ' ' : resolvedValue, 'insertText', descriptor);
315
326
  }
316
- _insertText(text, inputType, descriptor) {
327
+ _editableTarget(edit = true) {
317
328
  const target = this._target;
318
- if (!target || target.disabled || target.readOnly)
329
+ if (!target || this.disabled || target.disabled || edit && target.readOnly)
330
+ return null;
331
+ if (target instanceof HTMLInputElement && !['text', 'search', 'url', 'tel', 'password'].includes(target.type))
332
+ return null;
333
+ return target;
334
+ }
335
+ _insertText(text, inputType, descriptor) {
336
+ const target = this._editableTarget();
337
+ if (!target)
319
338
  return;
320
- const start = target.selectionStart ?? target.value.length;
321
- const end = target.selectionEnd ?? start;
339
+ const edges = textBoundaries(target.value), rawStart = target.selectionStart ?? target.value.length, rawEnd = target.selectionEnd ?? rawStart;
340
+ const start = boundaryFloor(edges, rawStart), end = rawStart === rawEnd ? start : boundaryCeil(edges, rawEnd);
322
341
  target.setRangeText(text, start, end, 'end');
323
342
  this._dispatchTargetInput(inputType, text);
324
343
  this._emitInput(descriptor, inputType);
325
344
  }
326
345
  _deleteBackward(descriptor) {
327
- const target = this._target;
328
- if (!target || target.disabled || target.readOnly)
346
+ const target = this._editableTarget();
347
+ if (!target)
329
348
  return;
330
- const start = target.selectionStart ?? 0;
331
- const end = target.selectionEnd ?? start;
332
- if (start === end && start === 0)
349
+ const edges = textBoundaries(target.value), rawStart = target.selectionStart ?? 0, rawEnd = target.selectionEnd ?? rawStart;
350
+ if (rawStart === 0 && rawEnd === 0)
333
351
  return;
334
- target.setRangeText('', start === end ? start - 1 : start, end, 'end');
352
+ const end = boundaryCeil(edges, rawEnd), start = rawStart === rawEnd ? boundaryBefore(edges, end) : boundaryFloor(edges, rawStart);
353
+ target.setRangeText('', start, end, 'end');
335
354
  this._dispatchTargetInput('deleteContentBackward', null);
336
355
  this._emitInput(descriptor, 'deleteContentBackward');
337
356
  }
338
357
  _deleteForward(descriptor) {
339
- const target = this._target;
340
- if (!target || target.disabled || target.readOnly)
358
+ const target = this._editableTarget();
359
+ if (!target)
341
360
  return;
342
- const start = target.selectionStart ?? 0;
343
- const end = target.selectionEnd ?? start;
344
- if (start === end && end >= target.value.length)
361
+ const edges = textBoundaries(target.value), rawStart = target.selectionStart ?? 0, rawEnd = target.selectionEnd ?? rawStart;
362
+ if (rawStart === rawEnd && rawEnd >= target.value.length)
345
363
  return;
346
- target.setRangeText('', start, start === end ? end + 1 : end, 'end');
364
+ const start = boundaryFloor(edges, rawStart), end = rawStart === rawEnd ? edges.find(edge => edge > start) : boundaryCeil(edges, rawEnd);
365
+ target.setRangeText('', start, end, 'end');
347
366
  this._dispatchTargetInput('deleteContentForward', null);
348
367
  this._emitInput(descriptor, 'deleteContentForward');
349
368
  }
350
- _moveCaret(delta) { const target = this._target; if (!target)
351
- return; const position = Math.max(0, Math.min(target.value.length, (target.selectionStart ?? 0) + delta)); this._setCaret(position); }
369
+ _moveCaret(delta) {
370
+ const target = this._editableTarget(false);
371
+ if (!target)
372
+ return;
373
+ const edges = textBoundaries(target.value), start = target.selectionStart ?? 0, end = target.selectionEnd ?? start;
374
+ const position = start !== end ? (delta < 0 ? boundaryFloor(edges, start) : boundaryCeil(edges, end))
375
+ : delta < 0 ? boundaryBefore(edges, start) : edges.find(edge => edge > start) ?? target.value.length;
376
+ this._setCaret(position);
377
+ }
352
378
  _moveCaretVertical(direction) {
353
- const target = this._target;
379
+ const target = this._editableTarget(false);
354
380
  if (!(target instanceof HTMLTextAreaElement))
355
381
  return;
356
- const value = target.value;
357
- const position = target.selectionStart ?? 0;
358
- const lineStart = value.lastIndexOf('\n', position - 1) + 1;
359
- const column = position - lineStart;
382
+ const value = target.value, position = target.selectionStart ?? 0, lineStart = value.lastIndexOf('\n', position - 1) + 1;
383
+ const column = Array.from(textSegmenter.segment(value.slice(lineStart, position))).length;
384
+ let start, end;
360
385
  if (direction < 0) {
361
386
  if (lineStart === 0)
362
387
  return;
363
- const previousEnd = lineStart - 1;
364
- const previousStart = value.lastIndexOf('\n', previousEnd - 1) + 1;
365
- this._setCaret(previousStart + Math.min(column, previousEnd - previousStart));
388
+ end = lineStart - 1;
389
+ start = value.lastIndexOf('\n', end - 1) + 1;
366
390
  }
367
391
  else {
368
392
  const currentEnd = value.indexOf('\n', position);
369
393
  if (currentEnd < 0)
370
394
  return;
371
- const nextStart = currentEnd + 1;
372
- const nextEnd = value.indexOf('\n', nextStart);
373
- const length = (nextEnd < 0 ? value.length : nextEnd) - nextStart;
374
- this._setCaret(nextStart + Math.min(column, length));
395
+ start = currentEnd + 1;
396
+ const nextEnd = value.indexOf('\n', start);
397
+ end = nextEnd < 0 ? value.length : nextEnd;
375
398
  }
399
+ const edges = textBoundaries(value.slice(start, end));
400
+ this._setCaret(start + edges[Math.min(column, edges.length - 1)]);
401
+ }
402
+ _setCaret(position) {
403
+ const target = this._editableTarget(false);
404
+ if (!target)
405
+ return;
406
+ const next = boundaryFloor(textBoundaries(target.value), Math.max(0, Math.min(target.value.length, position)));
407
+ target.focus({ preventScroll: true });
408
+ target.setSelectionRange(next, next);
376
409
  }
377
- _setCaret(position) { const target = this._target; if (!target)
378
- return; target.focus({ preventScroll: true }); target.setSelectionRange(position, position); }
379
410
  _dispatchTargetInput(inputType, data) {
380
411
  if (!this._target)
381
412
  return;
@@ -27,6 +27,7 @@ export declare class HYVirtualList<T = unknown> extends HTMLElement {
27
27
  private _height;
28
28
  private _overscan;
29
29
  private _range;
30
+ private readonly _rows;
30
31
  private _resizeObserver;
31
32
  private _connected;
32
33
  private readonly _onScroll;
@@ -35,6 +35,7 @@ export class HYVirtualList extends HTMLElement {
35
35
  _height = DEFAULT_HEIGHT;
36
36
  _overscan = DEFAULT_OVERSCAN;
37
37
  _range = null;
38
+ _rows = new Map();
38
39
  _resizeObserver = null;
39
40
  _connected = false;
40
41
  _onScroll = () => this._renderWindow();
@@ -51,7 +52,7 @@ export class HYVirtualList extends HTMLElement {
51
52
  display: block;
52
53
  min-width: 0;
53
54
  color: var(--hy-text-color, #eef3ff);
54
- font: 13px/1.4 system-ui, sans-serif;
55
+ font: calc(var(--hy-font-size-sm, 12px) + 1px)/var(--hy-line-height-snug, 1.4) var(--hy-font-family, system-ui, sans-serif);
55
56
  }
56
57
  .viewport {
57
58
  position: relative;
@@ -60,7 +61,7 @@ export class HYVirtualList extends HTMLElement {
60
61
  overflow-y: auto;
61
62
  overscroll-behavior: contain;
62
63
  border: 1px solid var(--hy-border-color, #3d4654);
63
- border-radius: var(--hy-virtual-list-border-radius, 6px);
64
+ border-radius: var(--hy-virtual-list-border-radius, var(--hy-radius-md, 6px));
64
65
  outline: none;
65
66
  background: var(--hy-surface-color, #171d27);
66
67
  scrollbar-color: var(--hy-border-strong-color, #596779) var(--hy-input-bg-color, #111722);
@@ -75,7 +76,7 @@ export class HYVirtualList extends HTMLElement {
75
76
  .viewport::-webkit-scrollbar-thumb {
76
77
  min-height: 28px;
77
78
  border: 2px solid var(--hy-input-bg-color, #111722);
78
- border-radius: 999px;
79
+ border-radius: var(--hy-radius-full, 999px);
79
80
  background: var(--hy-border-strong-color, #596779);
80
81
  }
81
82
  .viewport::-webkit-scrollbar-thumb:hover { background: var(--hy-accent-color, #79a8ff); }
@@ -95,7 +96,7 @@ export class HYVirtualList extends HTMLElement {
95
96
  display: grid;
96
97
  height: 100%;
97
98
  place-items: center;
98
- padding: 24px;
99
+ padding: var(--hy-space-12, 24px);
99
100
  color: var(--hy-secondary-text-color, #9aa8ba);
100
101
  box-sizing: border-box;
101
102
  }
@@ -270,6 +271,11 @@ export class HYVirtualList extends HTMLElement {
270
271
  const rows = [];
271
272
  for (let index = range.startIndex; index < range.endIndex; index += 1) {
272
273
  const item = this._items[index];
274
+ const retained = !force ? this._rows.get(index) : undefined;
275
+ if (retained) {
276
+ rows.push(retained);
277
+ continue;
278
+ }
273
279
  const row = document.createElement('div');
274
280
  row.className = 'hy-virtual-list-item';
275
281
  row.dataset.hyVirtualListGenerated = '';
@@ -311,10 +317,21 @@ export class HYVirtualList extends HTMLElement {
311
317
  }));
312
318
  }
313
319
  _replaceRows(rows) {
314
- // Keep the recycled window entirely inside the shadow tree. Slotted light
315
- // DOM rows can be redistributed asynchronously while a host application is
316
- // also updating, which may briefly paint rows from the previous range.
317
- this._window.replaceChildren(...rows);
320
+ const retained = new Set(rows), active = this.shadowRoot?.activeElement;
321
+ for (const row of this._rows.values())
322
+ if (!retained.has(row)) {
323
+ if (this.isConnected && active && row.contains(active))
324
+ this._viewport.focus({ preventScroll: true });
325
+ row.remove();
326
+ }
327
+ this._rows.clear();
328
+ let cursor = this._window.firstElementChild;
329
+ for (const row of rows) {
330
+ this._rows.set(Number(row.dataset.index), row);
331
+ if (row !== cursor)
332
+ this._window.insertBefore(row, cursor);
333
+ cursor = row.nextElementSibling;
334
+ }
318
335
  }
319
336
  }
320
337
  export function defineVirtualListComponents() {