@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.
- package/CHANGELOG.md +42 -0
- package/README.md +523 -4
- package/dist/adapters/web/controls.js +48 -8
- package/dist/adapters/web/renderer.js +9 -11
- package/dist/adapters/web/styles.d.ts +2 -3
- package/dist/adapters/web/styles.js +26 -23
- package/dist/alert.d.ts +39 -0
- package/dist/alert.js +144 -0
- package/dist/anchor.d.ts +62 -0
- package/dist/anchor.js +293 -0
- package/dist/auto-complete.d.ts +83 -0
- package/dist/auto-complete.js +267 -0
- package/dist/avatar.d.ts +45 -0
- package/dist/avatar.js +135 -0
- package/dist/badge.js +5 -5
- package/dist/border-beam.js +3 -2
- package/dist/breadcrumb.js +5 -5
- package/dist/button-group.js +8 -8
- package/dist/button.js +10 -10
- package/dist/card.d.ts +29 -0
- package/dist/card.js +101 -0
- package/dist/carousel.js +6 -6
- package/dist/cascader.js +19 -13
- package/dist/checkbox.d.ts +12 -0
- package/dist/checkbox.js +22 -6
- package/dist/collapse.js +6 -6
- package/dist/context-menu.js +3 -4
- package/dist/core/actions.js +7 -8
- package/dist/core/data.d.ts +1 -1
- package/dist/core/data.js +44 -10
- package/dist/core/platform-view.js +8 -2
- package/dist/core/selection.js +4 -4
- package/dist/core/semantics.d.ts +26 -0
- package/dist/core/semantics.js +8 -0
- package/dist/core/text.js +3 -3
- package/dist/core/validation.d.ts +3 -1
- package/dist/core/validation.js +23 -5
- package/dist/date-picker.js +19 -13
- package/dist/descriptions.d.ts +44 -0
- package/dist/descriptions.js +169 -0
- package/dist/dialog.d.ts +4 -0
- package/dist/dialog.js +48 -27
- package/dist/divider.js +2 -2
- package/dist/draggable.js +5 -3
- package/dist/drawer.js +16 -24
- package/dist/dropdown.js +3 -4
- package/dist/empty.d.ts +20 -0
- package/dist/empty.js +58 -0
- package/dist/expandable.js +4 -4
- package/dist/form-item.d.ts +60 -0
- package/dist/form-item.js +212 -0
- package/dist/form.d.ts +41 -0
- package/dist/form.js +154 -0
- package/dist/history-controls.js +5 -5
- package/dist/image-preview.d.ts +22 -0
- package/dist/image-preview.js +38 -0
- package/dist/image.d.ts +52 -0
- package/dist/image.js +152 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +72 -0
- package/dist/input.d.ts +11 -0
- package/dist/input.js +32 -18
- package/dist/internal/anchored-popup.d.ts +19 -0
- package/dist/internal/anchored-popup.js +89 -0
- package/dist/internal/focus.d.ts +2 -0
- package/dist/internal/focus.js +31 -0
- package/dist/internal/form-control.d.ts +22 -0
- package/dist/internal/form-control.js +52 -0
- package/dist/internal/image-viewer.d.ts +51 -0
- package/dist/internal/image-viewer.js +210 -0
- package/dist/internal/keyboard.d.ts +2 -0
- package/dist/internal/keyboard.js +12 -0
- package/dist/internal/numbers.d.ts +2 -0
- package/dist/internal/numbers.js +8 -0
- package/dist/internal/pagination.d.ts +35 -0
- package/dist/internal/pagination.js +169 -0
- package/dist/internal/popover-base.d.ts +87 -0
- package/dist/internal/popover-base.js +365 -0
- package/dist/internal/presentation.d.ts +2 -0
- package/dist/internal/presentation.js +28 -0
- package/dist/mentions.d.ts +115 -0
- package/dist/mentions.js +485 -0
- package/dist/menu-shared.d.ts +1 -1
- package/dist/menu-shared.js +3 -3
- package/dist/menu.d.ts +63 -0
- package/dist/menu.js +339 -0
- package/dist/modal.js +11 -40
- package/dist/notification.js +11 -10
- package/dist/pagination.d.ts +34 -0
- package/dist/pagination.js +73 -0
- package/dist/popconfirm.d.ts +6 -0
- package/dist/popconfirm.js +7 -0
- package/dist/popover.d.ts +6 -0
- package/dist/popover.js +7 -0
- package/dist/portable/page.js +25 -14
- package/dist/progress.d.ts +30 -0
- package/dist/progress.js +102 -0
- package/dist/qr-code.js +3 -3
- package/dist/radio.d.ts +10 -0
- package/dist/radio.js +18 -5
- package/dist/range.js +7 -7
- package/dist/rate.js +3 -3
- package/dist/resizable.js +8 -5
- package/dist/result.d.ts +22 -0
- package/dist/result.js +88 -0
- package/dist/ribbon.d.ts +19 -0
- package/dist/ribbon.js +106 -0
- package/dist/segmented.d.ts +39 -0
- package/dist/segmented.js +192 -0
- package/dist/select.d.ts +12 -0
- package/dist/select.js +31 -13
- package/dist/skeleton.js +10 -10
- package/dist/spin.d.ts +26 -0
- package/dist/spin.js +80 -0
- package/dist/steps.js +13 -13
- package/dist/switch.d.ts +44 -0
- package/dist/switch.js +104 -0
- package/dist/table.d.ts +3 -3
- package/dist/table.js +110 -128
- package/dist/tabs.js +7 -7
- package/dist/tag.js +8 -8
- package/dist/time-picker.js +16 -10
- package/dist/timeline.js +12 -12
- package/dist/toast.js +12 -11
- package/dist/tooltip.d.ts +6 -0
- package/dist/tooltip.js +107 -6
- package/dist/tour.js +26 -17
- package/dist/tree-model.d.ts +2 -0
- package/dist/tree-model.js +32 -11
- package/dist/tree-node.js +2 -2
- package/dist/tree-select.d.ts +94 -0
- package/dist/tree-select.js +398 -0
- package/dist/tree.d.ts +0 -2
- package/dist/tree.js +14 -29
- package/dist/upload.d.ts +108 -0
- package/dist/upload.js +358 -0
- package/dist/virtual-keyboard.d.ts +1 -0
- package/dist/virtual-keyboard.js +72 -41
- package/dist/virtual-list.d.ts +1 -0
- package/dist/virtual-list.js +25 -8
- package/dist/virtual-mouse.js +7 -6
- package/dist/watermark.js +2 -1
- package/package.json +82 -1
- package/themes/haiyue-dark.css +51 -0
- package/themes/haiyue-light.css +51 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function focusedElement(document) {
|
|
2
|
+
let element = document.activeElement;
|
|
3
|
+
while (element?.shadowRoot?.activeElement)
|
|
4
|
+
element = element.shadowRoot.activeElement;
|
|
5
|
+
return element instanceof HTMLElement ? element : null;
|
|
6
|
+
}
|
|
7
|
+
export function focusableElements(root) {
|
|
8
|
+
const result = [];
|
|
9
|
+
const visit = (element) => {
|
|
10
|
+
if (element instanceof HTMLElement && (element.hidden || element.inert || element.matches(':disabled')))
|
|
11
|
+
return;
|
|
12
|
+
const style = getComputedStyle(element);
|
|
13
|
+
if (style.display === 'none' || style.visibility === 'hidden')
|
|
14
|
+
return;
|
|
15
|
+
if (element instanceof HTMLSlotElement) {
|
|
16
|
+
const assigned = element.assignedElements({ flatten: true });
|
|
17
|
+
for (const child of assigned.length ? assigned : element.children)
|
|
18
|
+
visit(child);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (element instanceof HTMLElement && element.getClientRects().length &&
|
|
22
|
+
(element.tabIndex >= 0 || (element.isContentEditable && !element.hasAttribute('tabindex'))))
|
|
23
|
+
result.push(element);
|
|
24
|
+
for (const child of element.shadowRoot?.children ?? element.children)
|
|
25
|
+
visit(child);
|
|
26
|
+
};
|
|
27
|
+
for (const child of root.children)
|
|
28
|
+
visit(child);
|
|
29
|
+
return result.sort((a, b) => (a.tabIndex > 0 ? a.tabIndex : Infinity) - (b.tabIndex > 0 ? b.tabIndex : Infinity));
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=focus.js.map
|
|
@@ -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,12 @@
|
|
|
1
|
+
const CONTROL_SELECTOR = 'input,textarea,select,button,a[href],summary,[role="textbox"],[role="combobox"],[role="spinbutton"],[role="slider"],[role="button"],[role="checkbox"],[role="radio"],[role="switch"],[role="listbox"]';
|
|
2
|
+
/** Ancestor shortcuts must leave slotted and shadow-owned controls their editing keys. */
|
|
3
|
+
export function isKeyboardControlEvent(event, boundary) {
|
|
4
|
+
for (const target of event.composedPath()) {
|
|
5
|
+
if (target === boundary)
|
|
6
|
+
break;
|
|
7
|
+
if (target instanceof HTMLElement && (target.isContentEditable || target.matches(CONTROL_SELECTOR)))
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=keyboard.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Missing and empty attributes use their default; an explicit zero remains a value. */
|
|
2
|
+
export function finiteNumber(value, fallback) {
|
|
3
|
+
if (value == null || typeof value === 'string' && !value.trim())
|
|
4
|
+
return fallback;
|
|
5
|
+
const number = Number(value);
|
|
6
|
+
return Number.isFinite(number) ? number : fallback;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=numbers.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
|