@haiyue/ui 0.2.1 → 0.3.0

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 (139) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE +27 -0
  3. package/README.md +707 -5
  4. package/dist/adapters/web/controls.js +28 -5
  5. package/dist/adapters/web/renderer.js +11 -10
  6. package/dist/adapters/web/styles.d.ts +2 -3
  7. package/dist/adapters/web/styles.js +42 -18
  8. package/dist/alert.d.ts +39 -0
  9. package/dist/alert.js +144 -0
  10. package/dist/anchor.d.ts +60 -0
  11. package/dist/anchor.js +274 -0
  12. package/dist/auto-complete.d.ts +83 -0
  13. package/dist/auto-complete.js +267 -0
  14. package/dist/avatar.d.ts +45 -0
  15. package/dist/avatar.js +135 -0
  16. package/dist/badge.js +5 -5
  17. package/dist/border-beam.js +1 -1
  18. package/dist/breadcrumb.js +5 -5
  19. package/dist/button-group.js +8 -8
  20. package/dist/button.js +10 -10
  21. package/dist/card.d.ts +29 -0
  22. package/dist/card.js +101 -0
  23. package/dist/carousel.d.ts +92 -0
  24. package/dist/carousel.js +509 -0
  25. package/dist/cascader.js +12 -12
  26. package/dist/checkbox.d.ts +12 -0
  27. package/dist/checkbox.js +22 -6
  28. package/dist/collapse.d.ts +13 -0
  29. package/dist/collapse.js +100 -13
  30. package/dist/context-menu.js +3 -3
  31. package/dist/core/types.d.ts +22 -3
  32. package/dist/core/validation.js +9 -4
  33. package/dist/date-picker.js +13 -13
  34. package/dist/descriptions.d.ts +44 -0
  35. package/dist/descriptions.js +169 -0
  36. package/dist/dialog.js +11 -11
  37. package/dist/divider.js +2 -2
  38. package/dist/draggable.js +1 -1
  39. package/dist/drawer.js +12 -12
  40. package/dist/dropdown.js +3 -3
  41. package/dist/empty.d.ts +20 -0
  42. package/dist/empty.js +58 -0
  43. package/dist/expandable.js +4 -4
  44. package/dist/form-item.d.ts +60 -0
  45. package/dist/form-item.js +212 -0
  46. package/dist/form.d.ts +41 -0
  47. package/dist/form.js +154 -0
  48. package/dist/history-controls.js +5 -5
  49. package/dist/image-preview.d.ts +22 -0
  50. package/dist/image-preview.js +38 -0
  51. package/dist/image.d.ts +52 -0
  52. package/dist/image.js +152 -0
  53. package/dist/index.d.ts +56 -0
  54. package/dist/index.js +84 -0
  55. package/dist/input.d.ts +11 -0
  56. package/dist/input.js +29 -15
  57. package/dist/internal/anchored-popup.d.ts +19 -0
  58. package/dist/internal/anchored-popup.js +89 -0
  59. package/dist/internal/form-control.d.ts +22 -0
  60. package/dist/internal/form-control.js +52 -0
  61. package/dist/internal/image-viewer.d.ts +51 -0
  62. package/dist/internal/image-viewer.js +210 -0
  63. package/dist/internal/pagination.d.ts +35 -0
  64. package/dist/internal/pagination.js +169 -0
  65. package/dist/internal/popover-base.d.ts +87 -0
  66. package/dist/internal/popover-base.js +365 -0
  67. package/dist/internal/presentation.d.ts +2 -0
  68. package/dist/internal/presentation.js +28 -0
  69. package/dist/internal/qrcodegen.d.ts +94 -0
  70. package/dist/internal/qrcodegen.js +856 -0
  71. package/dist/masonry.d.ts +36 -0
  72. package/dist/masonry.js +171 -0
  73. package/dist/mentions.d.ts +115 -0
  74. package/dist/mentions.js +485 -0
  75. package/dist/menu-shared.d.ts +1 -1
  76. package/dist/menu-shared.js +3 -3
  77. package/dist/menu.d.ts +63 -0
  78. package/dist/menu.js +339 -0
  79. package/dist/modal.d.ts +73 -0
  80. package/dist/modal.js +361 -0
  81. package/dist/notification.js +9 -9
  82. package/dist/pagination.d.ts +34 -0
  83. package/dist/pagination.js +73 -0
  84. package/dist/popconfirm.d.ts +6 -0
  85. package/dist/popconfirm.js +7 -0
  86. package/dist/popover.d.ts +6 -0
  87. package/dist/popover.js +7 -0
  88. package/dist/portable/icons.d.ts +5 -0
  89. package/dist/portable/icons.js +24 -0
  90. package/dist/portable/index.d.ts +3 -0
  91. package/dist/portable/index.js +2 -0
  92. package/dist/portable/responsive.d.ts +20 -0
  93. package/dist/portable/responsive.js +15 -0
  94. package/dist/portable/theme.d.ts +6 -1
  95. package/dist/portable/theme.js +23 -3
  96. package/dist/progress.d.ts +30 -0
  97. package/dist/progress.js +102 -0
  98. package/dist/qr-code.d.ts +62 -0
  99. package/dist/qr-code.js +224 -0
  100. package/dist/radio.d.ts +10 -0
  101. package/dist/radio.js +18 -5
  102. package/dist/range.js +7 -7
  103. package/dist/rate.js +3 -3
  104. package/dist/resizable.js +4 -4
  105. package/dist/result.d.ts +22 -0
  106. package/dist/result.js +88 -0
  107. package/dist/ribbon.d.ts +19 -0
  108. package/dist/ribbon.js +106 -0
  109. package/dist/segmented.d.ts +39 -0
  110. package/dist/segmented.js +192 -0
  111. package/dist/select.d.ts +12 -0
  112. package/dist/select.js +31 -13
  113. package/dist/skeleton.js +10 -10
  114. package/dist/spin.d.ts +26 -0
  115. package/dist/spin.js +80 -0
  116. package/dist/steps.js +13 -13
  117. package/dist/switch.d.ts +44 -0
  118. package/dist/switch.js +104 -0
  119. package/dist/table.d.ts +0 -2
  120. package/dist/table.js +46 -87
  121. package/dist/tabs.js +7 -7
  122. package/dist/tag.js +8 -8
  123. package/dist/time-picker.js +10 -10
  124. package/dist/timeline.js +12 -12
  125. package/dist/toast.js +9 -9
  126. package/dist/tooltip.js +4 -4
  127. package/dist/tour.js +11 -11
  128. package/dist/tree-node.js +2 -2
  129. package/dist/tree-select.d.ts +94 -0
  130. package/dist/tree-select.js +398 -0
  131. package/dist/tree.js +6 -5
  132. package/dist/upload.d.ts +107 -0
  133. package/dist/upload.js +353 -0
  134. package/dist/virtual-keyboard.js +5 -5
  135. package/dist/virtual-list.js +4 -4
  136. package/dist/virtual-mouse.js +5 -5
  137. package/package.json +99 -1
  138. package/themes/haiyue-dark.css +51 -0
  139. package/themes/haiyue-light.css +51 -0
@@ -0,0 +1,22 @@
1
+ type NativeControl = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
2
+ type ControlHost = HTMLElement & {
3
+ value: string;
4
+ checked?: boolean;
5
+ indeterminate?: boolean;
6
+ };
7
+ /** Shared native form participation; never registers a component or imports a public entry. */
8
+ export declare class HYFormControl {
9
+ private readonly _host;
10
+ private readonly _control;
11
+ readonly internals: ElementInternals;
12
+ disabled: boolean;
13
+ private _initial;
14
+ constructor(_host: ControlHost, _control: NativeControl);
15
+ connect(): void;
16
+ sync(): void;
17
+ reset(): void;
18
+ restore(state: string | File | FormData | null): void;
19
+ setCustomValidity(message: string): void;
20
+ private _restore;
21
+ }
22
+ export {};
@@ -0,0 +1,52 @@
1
+ /** Shared native form participation; never registers a component or imports a public entry. */
2
+ export class HYFormControl {
3
+ _host;
4
+ _control;
5
+ internals;
6
+ disabled = false;
7
+ _initial = null;
8
+ constructor(_host, _control) {
9
+ this._host = _host;
10
+ this._control = _control;
11
+ this.internals = _host.attachInternals();
12
+ }
13
+ connect() {
14
+ this._initial ??= { value: this._host.value, ...('checked' in this._host ? { checked: Boolean(this._host.checked) } : {}) };
15
+ this.sync();
16
+ }
17
+ sync() {
18
+ const control = this._control;
19
+ const checkable = control instanceof HTMLInputElement && ['checkbox', 'radio'].includes(control.type);
20
+ this.internals.setFormValue(control.disabled || (checkable && !control.checked) ? null : control.value, JSON.stringify({ value: this._host.value, ...(checkable ? { checked: control.checked } : {}) }));
21
+ this.internals.setValidity(control.disabled ? {} : control.validity, control.disabled ? '' : control.validationMessage, control);
22
+ }
23
+ reset() {
24
+ if (!this._initial)
25
+ return;
26
+ this._restore(this._initial);
27
+ this._control.setCustomValidity('');
28
+ this.sync();
29
+ }
30
+ restore(state) {
31
+ if (typeof state !== 'string')
32
+ return;
33
+ try {
34
+ const parsed = JSON.parse(state);
35
+ if (parsed && typeof parsed === 'object' && 'value' in parsed && typeof parsed.value === 'string')
36
+ this._restore(parsed);
37
+ }
38
+ catch {
39
+ this._host.value = state;
40
+ }
41
+ this.sync();
42
+ }
43
+ setCustomValidity(message) { this._control.setCustomValidity(message); this.sync(); }
44
+ _restore(state) {
45
+ this._host.value = state.value;
46
+ if (state.checked !== undefined)
47
+ this._host.checked = state.checked;
48
+ if ('indeterminate' in this._host)
49
+ this._host.indeterminate = false;
50
+ }
51
+ }
52
+ //# sourceMappingURL=form-control.js.map
@@ -0,0 +1,51 @@
1
+ export interface HYImagePreviewItem {
2
+ src: string;
3
+ alt?: string;
4
+ caption?: string;
5
+ }
6
+ export interface HYImagePreviewChangeDetail {
7
+ index: number;
8
+ item: HYImagePreviewItem;
9
+ }
10
+ export interface HYImagePreviewOpenDetail {
11
+ open: boolean;
12
+ index: number;
13
+ }
14
+ /** Native modal image viewer shared by isolated Image and ImagePreview entries. */
15
+ export declare class HYImageViewer {
16
+ private readonly _host;
17
+ private readonly _onOpen;
18
+ private readonly _onChange;
19
+ readonly dialog: HTMLDialogElement;
20
+ private readonly _stage;
21
+ private readonly _imageHost;
22
+ private readonly _status;
23
+ private readonly _caption;
24
+ private readonly _counter;
25
+ private readonly _buttons;
26
+ private _items;
27
+ private _index;
28
+ private _open;
29
+ private _zoom;
30
+ private _rotation;
31
+ private _x;
32
+ private _y;
33
+ private _image;
34
+ private _imageListeners;
35
+ private _returnFocus;
36
+ private _drag;
37
+ private _maskDown;
38
+ constructor(_host: HTMLElement, root: ShadowRoot, _onOpen: (detail: HYImagePreviewOpenDetail) => void, _onChange: (detail: HYImagePreviewChangeDetail) => void);
39
+ get open(): boolean;
40
+ get index(): number;
41
+ setItems(items: HYImagePreviewItem[], index: number): void;
42
+ show(): void;
43
+ close(notify?: boolean): void;
44
+ dispose(): void;
45
+ navigate(delta: number): void;
46
+ private _act;
47
+ private _render;
48
+ private _transform;
49
+ private _endDrag;
50
+ }
51
+ export declare function normalizePreviewItems(value: unknown): HYImagePreviewItem[];
@@ -0,0 +1,210 @@
1
+ /** Native modal image viewer shared by isolated Image and ImagePreview entries. */
2
+ export class HYImageViewer {
3
+ _host;
4
+ _onOpen;
5
+ _onChange;
6
+ dialog = document.createElement('dialog');
7
+ _stage = document.createElement('div');
8
+ _imageHost = document.createElement('div');
9
+ _status = document.createElement('div');
10
+ _caption = document.createElement('div');
11
+ _counter = document.createElement('span');
12
+ _buttons = new Map();
13
+ _items = [];
14
+ _index = 0;
15
+ _open = false;
16
+ _zoom = 1;
17
+ _rotation = 0;
18
+ _x = 0;
19
+ _y = 0;
20
+ _image = null;
21
+ _imageListeners = null;
22
+ _returnFocus = null;
23
+ _drag = null;
24
+ _maskDown = false;
25
+ constructor(_host, root, _onOpen, _onChange) {
26
+ this._host = _host;
27
+ this._onOpen = _onOpen;
28
+ this._onChange = _onChange;
29
+ const style = document.createElement('style');
30
+ style.textContent = `
31
+ .viewer { box-sizing: border-box; flex-direction: column; width: 100vw; max-width: none; height: 100vh; height: 100dvh; max-height: none; margin: 0; padding: var(--hy-space-6, 12px); border: 0; color: var(--hy-image-preview-text-color, var(--hy-selected-text-color, #fff)); background: var(--hy-image-preview-bg, rgba(12,16,24,.94)); font: var(--hy-font-size-sm, 12px)/1.5 var(--hy-font-family, system-ui, sans-serif); overflow: hidden; overscroll-behavior: contain; }
32
+ .viewer[open] { display: flex; } .viewer:not([open]) { display: none; } .viewer::backdrop { background: var(--hy-image-preview-mask-color, rgba(0,0,0,.65)); }
33
+ .toolbar { display: flex; flex: 0 0 auto; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--hy-space-3, 6px); }
34
+ .toolbar button { min-height: 32px; min-width: 32px; padding: 0 8px; border: 1px solid var(--hy-border-color, #303746); border-radius: var(--hy-radius-sm, 4px); color: var(--hy-text-color, #d8e2f2); background: var(--hy-surface-elevated-color, #202733); cursor: pointer; font: inherit; }
35
+ .toolbar button:hover:not(:disabled) { background: var(--hy-hover-bg-color, #273241); } .toolbar button:disabled { opacity: .4; cursor: default; } .toolbar button:focus-visible { outline: 2px solid var(--hy-focus-border-color, #79a8ff); outline-offset: 1px; }
36
+ .stage { position: relative; display: grid; place-items: center; flex: 1 1 auto; min-height: 0; min-width: 0; overflow: hidden; touch-action: none; }
37
+ .image-host { display: contents; } .preview-image { display: block; max-width: calc(100vw - 48px); max-height: calc(100vh - 120px); max-height: calc(100dvh - 120px); object-fit: contain; user-select: none; transform-origin: center; }
38
+ .viewer.zoomed .preview-image { cursor: grab; } .viewer.dragging .preview-image { cursor: grabbing; } .viewer-status { position: absolute; padding: 12px; color: var(--hy-image-preview-text-color, var(--hy-selected-text-color, #fff)); }
39
+ .caption { flex: 0 0 auto; text-align: center; padding: 4px; overflow-wrap: anywhere; } [hidden] { display: none !important; }
40
+ @media (max-width: 480px) { .toolbar { gap: 3px; } .toolbar button { min-width: 28px; padding: 0 5px; } }
41
+ `;
42
+ this.dialog.className = 'viewer';
43
+ this.dialog.part.add('preview');
44
+ this.dialog.setAttribute('aria-label', 'Image preview');
45
+ const toolbar = document.createElement('div');
46
+ toolbar.className = 'toolbar';
47
+ toolbar.part.add('toolbar');
48
+ for (const [action, text, label] of [['previous', '‹', 'Previous image'], ['next', '›', 'Next image'], ['out', '−', 'Zoom out'], ['in', '+', 'Zoom in'], ['left', '↶', 'Rotate left'], ['right', '↷', 'Rotate right'], ['reset', '1:1', 'Reset view'], ['close', '×', 'Close preview']]) {
49
+ const button = document.createElement('button');
50
+ button.type = 'button';
51
+ button.dataset.action = action;
52
+ button.textContent = text;
53
+ button.setAttribute('aria-label', label);
54
+ button.part.add(action);
55
+ this._buttons.set(action, button);
56
+ toolbar.append(button);
57
+ }
58
+ this._counter.part.add('counter');
59
+ this._counter.setAttribute('aria-live', 'polite');
60
+ toolbar.prepend(this._counter);
61
+ this._stage.className = 'stage';
62
+ this._stage.part.add('stage');
63
+ this._imageHost.className = 'image-host';
64
+ this._status.className = 'viewer-status';
65
+ this._status.part.add('preview-status');
66
+ this._status.setAttribute('role', 'status');
67
+ this._caption.className = 'caption';
68
+ this._caption.part.add('caption');
69
+ this._stage.append(this._imageHost, this._status);
70
+ this.dialog.append(toolbar, this._stage, this._caption);
71
+ root.append(style, this.dialog);
72
+ toolbar.addEventListener('click', event => { const button = event.target instanceof Element ? event.target.closest('button[data-action]') : null; if (button && !button.disabled)
73
+ this._act(button.dataset.action); });
74
+ this.dialog.addEventListener('cancel', event => { event.preventDefault(); this.close(); });
75
+ this.dialog.addEventListener('close', () => { if (!this.dialog.open && this._open)
76
+ this.close(); });
77
+ this.dialog.addEventListener('keydown', event => {
78
+ if (event.key === 'Escape') {
79
+ event.preventDefault();
80
+ event.stopPropagation();
81
+ this.close();
82
+ }
83
+ else if (!event.ctrlKey && !event.metaKey && !event.altKey && (event.key === 'ArrowLeft' || event.key === 'ArrowRight')) {
84
+ event.preventDefault();
85
+ event.stopPropagation();
86
+ this.navigate(event.key === 'ArrowLeft' ? -1 : 1);
87
+ }
88
+ });
89
+ this._stage.addEventListener('wheel', event => { if (this._open) {
90
+ event.preventDefault();
91
+ this._zoom = clamp(this._zoom * (event.deltaY < 0 ? 1.2 : 1 / 1.2), .2, 5);
92
+ this._transform();
93
+ } }, { passive: false });
94
+ this.dialog.addEventListener('pointerdown', event => { this._maskDown = event.target === this.dialog || event.target === this._stage; });
95
+ this.dialog.addEventListener('click', event => { if (this._maskDown && (event.target === this.dialog || event.target === this._stage))
96
+ this.close(); this._maskDown = false; });
97
+ this._stage.addEventListener('pointerdown', event => { if (event.button !== 0 || this._zoom <= 1 || event.target !== this._image)
98
+ return; event.preventDefault(); this._drag = { id: event.pointerId, x: event.clientX, y: event.clientY, originX: this._x, originY: this._y }; this._stage.setPointerCapture(event.pointerId); this.dialog.classList.add('dragging'); });
99
+ this._stage.addEventListener('pointermove', event => { if (this._drag?.id === event.pointerId) {
100
+ this._x = clamp(this._drag.originX + event.clientX - this._drag.x, -5000, 5000);
101
+ this._y = clamp(this._drag.originY + event.clientY - this._drag.y, -5000, 5000);
102
+ this._transform();
103
+ } });
104
+ for (const type of ['pointerup', 'pointercancel', 'lostpointercapture'])
105
+ this._stage.addEventListener(type, () => this._endDrag());
106
+ }
107
+ get open() { return this._open; }
108
+ get index() { return this._index; }
109
+ setItems(items, index) {
110
+ index = Math.max(0, Math.min(items.length - 1, Number.isFinite(index) ? Math.floor(index) : 0));
111
+ const changed = index !== this._index || JSON.stringify(items) !== JSON.stringify(this._items);
112
+ this._items = items.map(item => ({ ...item }));
113
+ this._index = index;
114
+ if (!items.length) {
115
+ this.close();
116
+ return;
117
+ }
118
+ if (changed && this._open)
119
+ this._render();
120
+ }
121
+ show() {
122
+ if (this._open || !this._items.length || !this._host.isConnected)
123
+ return;
124
+ let active = this._host.ownerDocument.activeElement;
125
+ while (active?.shadowRoot?.activeElement)
126
+ active = active.shadowRoot.activeElement;
127
+ this._returnFocus = active instanceof HTMLElement ? active : null;
128
+ this._open = true;
129
+ this._render();
130
+ this.dialog.showModal();
131
+ this._buttons.get('close').focus({ preventScroll: true });
132
+ this._onOpen({ open: true, index: this._index });
133
+ }
134
+ close(notify = true) {
135
+ if (!this._open)
136
+ return;
137
+ this._open = false;
138
+ this._endDrag();
139
+ this._imageListeners?.abort();
140
+ this._imageListeners = null;
141
+ if (this.dialog.open)
142
+ this.dialog.close();
143
+ const focus = this._returnFocus;
144
+ this._returnFocus = null;
145
+ if (this._host.isConnected && focus?.isConnected)
146
+ focus.focus({ preventScroll: true });
147
+ if (notify && this._host.isConnected)
148
+ this._onOpen({ open: false, index: this._index });
149
+ }
150
+ dispose() { this.close(false); this._imageListeners?.abort(); this._imageListeners = null; }
151
+ navigate(delta) { if (this._items.length <= 1)
152
+ return; this._index = (this._index + delta + this._items.length) % this._items.length; this._render(); this._onChange({ index: this._index, item: { ...this._items[this._index] } }); }
153
+ _act(action) {
154
+ if (action === 'close')
155
+ this.close();
156
+ else if (action === 'previous' || action === 'next')
157
+ this.navigate(action === 'previous' ? -1 : 1);
158
+ else {
159
+ if (action === 'in')
160
+ this._zoom = clamp(this._zoom + .2, .2, 5);
161
+ else if (action === 'out')
162
+ this._zoom = clamp(this._zoom - .2, .2, 5);
163
+ else if (action === 'left')
164
+ this._rotation -= 90;
165
+ else if (action === 'right')
166
+ this._rotation += 90;
167
+ else if (action === 'reset') {
168
+ this._zoom = 1;
169
+ this._rotation = 0;
170
+ this._x = this._y = 0;
171
+ }
172
+ this._transform();
173
+ }
174
+ }
175
+ _render() {
176
+ const item = this._items[this._index];
177
+ if (!item)
178
+ return;
179
+ this._endDrag();
180
+ this._zoom = 1;
181
+ this._rotation = this._x = this._y = 0;
182
+ this._counter.textContent = `${this._index + 1} / ${this._items.length}`;
183
+ this._caption.textContent = item.caption ?? '';
184
+ this._caption.hidden = !item.caption;
185
+ this._buttons.get('previous').disabled = this._buttons.get('next').disabled = this._items.length <= 1;
186
+ this._imageListeners?.abort();
187
+ this._imageListeners = new AbortController();
188
+ const { signal } = this._imageListeners;
189
+ const image = document.createElement('img');
190
+ image.className = 'preview-image';
191
+ image.part.add('preview-image');
192
+ image.alt = item.alt ?? '';
193
+ image.draggable = false;
194
+ this._image = image;
195
+ this._status.textContent = 'Loading image…';
196
+ this._status.hidden = false;
197
+ image.addEventListener('load', () => { this._status.hidden = true; }, { signal });
198
+ image.addEventListener('error', () => { image.hidden = true; this._status.textContent = 'Image unavailable'; this._status.hidden = false; }, { signal });
199
+ this._imageHost.replaceChildren(image);
200
+ image.src = item.src;
201
+ this._transform();
202
+ }
203
+ _transform() { if (this._image)
204
+ this._image.style.transform = `translate(${this._x}px, ${this._y}px) rotate(${this._rotation}deg) scale(${this._zoom})`; this.dialog.classList.toggle('zoomed', this._zoom > 1); this._buttons.get('in').disabled = this._zoom >= 5; this._buttons.get('out').disabled = this._zoom <= .2; }
205
+ _endDrag() { const drag = this._drag; this._drag = null; if (drag && this._stage.hasPointerCapture(drag.id))
206
+ this._stage.releasePointerCapture(drag.id); this.dialog.classList.remove('dragging'); }
207
+ }
208
+ export function normalizePreviewItems(value) { return Array.isArray(value) ? value.flatMap(item => typeof item === 'string' && item ? [{ src: item }] : item && typeof item.src === 'string' && item.src ? [{ src: item.src, ...(typeof item.alt === 'string' ? { alt: item.alt } : {}), ...(typeof item.caption === 'string' ? { caption: item.caption } : {}) }] : []) : []; }
209
+ function clamp(value, min, max) { return Math.max(min, Math.min(max, value)); }
210
+ //# sourceMappingURL=image-viewer.js.map
@@ -0,0 +1,35 @@
1
+ type HYPaginationSource = 'page' | 'size' | 'jump';
2
+ interface HYPaginationState {
3
+ page: number;
4
+ pageSize: number;
5
+ total: number;
6
+ pageSizeOptions: readonly number[];
7
+ label?: string;
8
+ hidden?: boolean;
9
+ disabled?: boolean;
10
+ simple?: boolean;
11
+ showTotal?: boolean;
12
+ showSizeChanger?: boolean;
13
+ showQuickJumper?: boolean;
14
+ }
15
+ export declare const HY_PAGINATION_STYLES = "\n .pagination-controls, .pagination-controls .pages { display: flex; align-items: center; flex-wrap: wrap; gap: var(--hy-space-2, 4px); }\n .pagination-controls .pages { display: inline-flex; }\n .pagination-controls :is(button, select, input) {\n box-sizing: border-box; min-height: var(--hy-control-height-sm, 28px); min-width: 28px;\n padding: 2px 7px; border: 1px solid var(--hy-border-color, #303746); border-radius: var(--hy-radius-sm, 4px);\n color: inherit; background: var(--hy-surface-color, #121822); font: inherit;\n }\n .pagination-controls button { cursor: pointer; }\n .pagination-controls button:hover:not(:disabled) { background: var(--hy-hover-bg-color, #273241); }\n .pagination-controls button[aria-current=\"page\"] { border-color: var(--hy-accent-color, #8177f2); color: var(--hy-accent-color, #8177f2); }\n .pagination-controls :is(button, select, input):disabled { opacity: .5; cursor: not-allowed; }\n .pagination-controls :is(button, select, input):focus-visible { outline: 2px solid var(--hy-focus-border-color, #79a8ff); outline-offset: 1px; }\n .pagination-controls label { display: inline-flex; align-items: center; gap: 4px; }\n .pagination-controls input { width: 62px; }\n .pagination-controls .summary { margin-inline-end: 4px; color: var(--hy-muted-text-color, var(--hy-muted-color, #8290a3)); }\n .pagination-controls[hidden], .pagination-controls [hidden] { display: none !important; }\n";
16
+ /** Shared native controls. The owning component validates state and emits its public events. */
17
+ export declare class HYPaginationControls {
18
+ private readonly _onChange;
19
+ private readonly _variant;
20
+ readonly element: HTMLElement;
21
+ private readonly _previous;
22
+ private readonly _next;
23
+ private readonly _pages;
24
+ private readonly _summary;
25
+ private readonly _size;
26
+ private readonly _jump;
27
+ private readonly _jumpLabel;
28
+ private _state;
29
+ constructor(_onChange: (page: number, pageSize: number, source: HYPaginationSource) => void, _variant?: 'pagination' | 'table');
30
+ update(state: HYPaginationState): void;
31
+ private _pageNumbers;
32
+ private _request;
33
+ private _onKeydown;
34
+ }
35
+ export {};
@@ -0,0 +1,169 @@
1
+ export const HY_PAGINATION_STYLES = `
2
+ .pagination-controls, .pagination-controls .pages { display: flex; align-items: center; flex-wrap: wrap; gap: var(--hy-space-2, 4px); }
3
+ .pagination-controls .pages { display: inline-flex; }
4
+ .pagination-controls :is(button, select, input) {
5
+ box-sizing: border-box; min-height: var(--hy-control-height-sm, 28px); min-width: 28px;
6
+ padding: 2px 7px; border: 1px solid var(--hy-border-color, #303746); border-radius: var(--hy-radius-sm, 4px);
7
+ color: inherit; background: var(--hy-surface-color, #121822); font: inherit;
8
+ }
9
+ .pagination-controls button { cursor: pointer; }
10
+ .pagination-controls button:hover:not(:disabled) { background: var(--hy-hover-bg-color, #273241); }
11
+ .pagination-controls button[aria-current="page"] { border-color: var(--hy-accent-color, #8177f2); color: var(--hy-accent-color, #8177f2); }
12
+ .pagination-controls :is(button, select, input):disabled { opacity: .5; cursor: not-allowed; }
13
+ .pagination-controls :is(button, select, input):focus-visible { outline: 2px solid var(--hy-focus-border-color, #79a8ff); outline-offset: 1px; }
14
+ .pagination-controls label { display: inline-flex; align-items: center; gap: 4px; }
15
+ .pagination-controls input { width: 62px; }
16
+ .pagination-controls .summary { margin-inline-end: 4px; color: var(--hy-muted-text-color, var(--hy-muted-color, #8290a3)); }
17
+ .pagination-controls[hidden], .pagination-controls [hidden] { display: none !important; }
18
+ `;
19
+ /** Shared native controls. The owning component validates state and emits its public events. */
20
+ export class HYPaginationControls {
21
+ _onChange;
22
+ _variant;
23
+ element = document.createElement('nav');
24
+ _previous = document.createElement('button');
25
+ _next = document.createElement('button');
26
+ _pages = document.createElement('span');
27
+ _summary = document.createElement('span');
28
+ _size = document.createElement('select');
29
+ _jump = document.createElement('input');
30
+ _jumpLabel = document.createElement('label');
31
+ _state = { page: 1, pageSize: 10, total: 0, pageSizeOptions: [] };
32
+ constructor(_onChange, _variant = 'pagination') {
33
+ this._onChange = _onChange;
34
+ this._variant = _variant;
35
+ this.element.className = 'pagination-controls';
36
+ this.element.part.add(_variant === 'table' ? 'pagination' : 'nav');
37
+ this._previous.type = this._next.type = 'button';
38
+ this._previous.textContent = '‹';
39
+ this._next.textContent = '›';
40
+ this._previous.setAttribute('aria-label', 'Previous page');
41
+ this._next.setAttribute('aria-label', 'Next page');
42
+ this._previous.part.add('previous');
43
+ this._next.part.add('next');
44
+ this._pages.className = 'pages';
45
+ this._pages.part.add('pages');
46
+ this._summary.className = 'summary';
47
+ this._summary.part.add(_variant === 'table' ? 'summary' : 'total');
48
+ this._size.part.add('page-size');
49
+ this._size.setAttribute('aria-label', _variant === 'table' ? 'Rows per page' : 'Items per page');
50
+ this._jump.type = 'number';
51
+ this._jump.min = '1';
52
+ this._jump.part.add('jumper');
53
+ this._jump.setAttribute('aria-label', 'Go to page');
54
+ this._jumpLabel.append('Go to', this._jump);
55
+ this.element.append(this._summary, this._previous, this._pages, this._next, this._size, this._jumpLabel);
56
+ this._previous.addEventListener('click', () => this._request(this._state.page - 1, this._state.pageSize, 'page'));
57
+ this._next.addEventListener('click', () => this._request(this._state.page + 1, this._state.pageSize, 'page'));
58
+ this._pages.addEventListener('click', event => {
59
+ const button = event.target instanceof Element ? event.target.closest('button[data-page]') : null;
60
+ if (button)
61
+ this._request(Number(button.dataset.page), this._state.pageSize, 'page');
62
+ });
63
+ this._pages.addEventListener('keydown', this._onKeydown);
64
+ this._size.addEventListener('change', () => {
65
+ const size = Number(this._size.value);
66
+ this._request(Math.ceil(((this._state.page - 1) * this._state.pageSize + 1) / size), size, 'size');
67
+ });
68
+ this._jump.addEventListener('keydown', event => {
69
+ if (event.key === 'Enter' && !event.isComposing) {
70
+ event.preventDefault();
71
+ event.stopPropagation();
72
+ this._request(Number(this._jump.value), this._state.pageSize, 'jump');
73
+ }
74
+ });
75
+ }
76
+ update(state) {
77
+ this._state = state;
78
+ const { page, pageSize, total, disabled = false } = state;
79
+ const pageCount = Math.max(1, Math.ceil(total / pageSize));
80
+ this.element.hidden = Boolean(state.hidden);
81
+ this.element.setAttribute('aria-label', state.label || 'Pagination');
82
+ this._previous.disabled = disabled || page <= 1;
83
+ this._next.disabled = disabled || page >= pageCount;
84
+ const root = this.element.getRootNode();
85
+ const focusedPage = this._pages.contains(root instanceof ShadowRoot ? root.activeElement : this.element.ownerDocument.activeElement);
86
+ const fragment = document.createDocumentFragment();
87
+ if (state.simple)
88
+ fragment.append(`${page} / ${pageCount}`);
89
+ else {
90
+ let previous = 0;
91
+ for (const value of this._pageNumbers(pageCount)) {
92
+ if (this._variant === 'pagination' && previous && value - previous > 1) {
93
+ const gap = document.createElement('span');
94
+ gap.textContent = '…';
95
+ gap.setAttribute('aria-hidden', 'true');
96
+ fragment.append(gap);
97
+ }
98
+ const button = document.createElement('button');
99
+ button.type = 'button';
100
+ button.dataset.page = String(value);
101
+ button.part.add('page');
102
+ button.textContent = String(value);
103
+ button.disabled = disabled;
104
+ button.setAttribute('aria-label', `Page ${value}`);
105
+ if (page === value)
106
+ button.setAttribute('aria-current', 'page');
107
+ fragment.append(button);
108
+ previous = value;
109
+ }
110
+ }
111
+ this._pages.replaceChildren(fragment);
112
+ if (focusedPage)
113
+ this._pages.querySelector(`button[data-page="${page}"]`)?.focus({ preventScroll: true });
114
+ const start = total ? (page - 1) * pageSize + 1 : 0;
115
+ const end = Math.min(page * pageSize, total);
116
+ this._summary.textContent = this._variant === 'table' ? `${start}–${end} of ${total}` : `${start}–${end} / ${total}`;
117
+ this._summary.hidden = state.showTotal === false;
118
+ const options = [...new Set([...state.pageSizeOptions, pageSize])].sort((a, b) => a - b);
119
+ if ([...this._size.options].map(option => Number(option.value)).join(',') !== options.join(',')) {
120
+ this._size.replaceChildren(...options.map(value => {
121
+ const option = document.createElement('option');
122
+ option.value = String(value);
123
+ option.textContent = `${value} / page`;
124
+ return option;
125
+ }));
126
+ }
127
+ this._size.value = String(pageSize);
128
+ this._size.disabled = disabled;
129
+ this._size.hidden = !state.showSizeChanger;
130
+ this._jump.disabled = disabled;
131
+ this._jump.max = String(pageCount);
132
+ this._jump.value = String(page);
133
+ this._jumpLabel.hidden = !state.showQuickJumper;
134
+ }
135
+ _pageNumbers(pageCount) {
136
+ const page = this._state.page;
137
+ if (this._variant === 'table') {
138
+ if (pageCount <= 7)
139
+ return Array.from({ length: pageCount }, (_, index) => index + 1);
140
+ const start = Math.max(1, Math.min(pageCount - 4, page - 2));
141
+ return Array.from({ length: 5 }, (_, index) => start + index);
142
+ }
143
+ return [...new Set([1, pageCount, ...Array.from({ length: 5 }, (_, index) => page - 2 + index)
144
+ .filter(value => value > 0 && value <= pageCount)])].sort((a, b) => a - b);
145
+ }
146
+ _request(page, pageSize, source) {
147
+ if (!this._state.disabled && !this._state.hidden)
148
+ this._onChange(page, pageSize, source);
149
+ }
150
+ _onKeydown = (event) => {
151
+ if (!(event.target instanceof HTMLButtonElement) || this._state.disabled)
152
+ return;
153
+ const rtl = getComputedStyle(this.element).direction === 'rtl';
154
+ let page;
155
+ if (event.key === 'ArrowRight')
156
+ page = this._state.page + (rtl ? -1 : 1);
157
+ else if (event.key === 'ArrowLeft')
158
+ page = this._state.page + (rtl ? 1 : -1);
159
+ else if (event.key === 'Home')
160
+ page = 1;
161
+ else if (event.key === 'End')
162
+ page = Math.max(1, Math.ceil(this._state.total / this._state.pageSize));
163
+ else
164
+ return;
165
+ event.preventDefault();
166
+ this._request(page, this._state.pageSize, 'page');
167
+ };
168
+ }
169
+ //# sourceMappingURL=pagination.js.map
@@ -0,0 +1,87 @@
1
+ export type HYPopoverPlacement = 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end' | 'right' | 'right-start' | 'right-end';
2
+ export type HYPopoverTrigger = 'click' | 'hover' | 'focus' | 'manual';
3
+ export type HYPopoverCloseReason = 'api' | 'trigger' | 'outside' | 'escape' | 'blur' | 'confirm' | 'cancel' | 'disabled';
4
+ export interface HYPopoverOpenChangeDetail {
5
+ open: boolean;
6
+ reason: HYPopoverCloseReason;
7
+ }
8
+ export interface HYPopconfirmActionDetail {
9
+ source: 'button' | 'api';
10
+ }
11
+ /** Shared implementation for two isolated public entries; importing never registers elements. */
12
+ export declare class HYPopoverBase extends HTMLElement {
13
+ private readonly _confirmation;
14
+ private readonly _triggerSlot;
15
+ private readonly _panel;
16
+ private readonly _headingSlot;
17
+ private readonly _headingText;
18
+ private readonly _contentSlot;
19
+ private readonly _description;
20
+ private readonly _footer;
21
+ private readonly _cancel;
22
+ private readonly _confirm;
23
+ private readonly _panelId;
24
+ private _listeners;
25
+ private _observer;
26
+ private _timer;
27
+ private _focusTimer;
28
+ private _shown;
29
+ private _restoringFocus;
30
+ private _focusInside;
31
+ private _reflecting;
32
+ private _returnFocus;
33
+ private _reason;
34
+ private _triggerAttributes;
35
+ static get observedAttributes(): string[];
36
+ protected constructor(_confirmation: boolean);
37
+ connectedCallback(): void;
38
+ disconnectedCallback(): void;
39
+ attributeChangedCallback(name: string, previous: string | null, next: string | null): void;
40
+ get open(): boolean;
41
+ set open(value: boolean);
42
+ get disabled(): boolean;
43
+ set disabled(value: boolean);
44
+ get trigger(): HYPopoverTrigger;
45
+ set trigger(value: HYPopoverTrigger);
46
+ get placement(): HYPopoverPlacement;
47
+ set placement(value: HYPopoverPlacement);
48
+ get heading(): string;
49
+ set heading(value: string);
50
+ get content(): string;
51
+ set content(value: string);
52
+ get description(): string;
53
+ set description(value: string);
54
+ get confirmLoading(): boolean;
55
+ set confirmLoading(value: boolean);
56
+ get confirmDisabled(): boolean;
57
+ set confirmDisabled(value: boolean);
58
+ get okText(): string;
59
+ set okText(value: string);
60
+ get cancelText(): string;
61
+ set cancelText(value: string);
62
+ show(): void;
63
+ hide(): void;
64
+ confirm(): boolean;
65
+ cancel(): boolean;
66
+ private _setOpen;
67
+ private _sync;
68
+ private _showPanel;
69
+ private _hidePanel;
70
+ private _emitOpen;
71
+ private _syncTrigger;
72
+ private _restoreTrigger;
73
+ private _isTrigger;
74
+ private _onTriggerClick;
75
+ private _onKeydown;
76
+ private _onOutside;
77
+ private _onScroll;
78
+ private _onFocusIn;
79
+ private _onFocusOut;
80
+ private _onEnter;
81
+ private _onLeave;
82
+ private _schedule;
83
+ private _clearTimer;
84
+ private _clearFocusTimer;
85
+ private _act;
86
+ private _position;
87
+ }