@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
@@ -8,12 +8,17 @@ export declare const HY_THEME_TOKENS: Readonly<{
8
8
  readonly danger: "--hy-invalid-border-color";
9
9
  readonly border: "--hy-border-color";
10
10
  readonly focus: "--hy-focus-ring-color";
11
+ readonly selected: "--hy-selected-bg-color";
12
+ readonly pressed: "--hy-pressed-bg-color";
13
+ readonly disabled: "--hy-disabled-text-color";
14
+ readonly elevated: "--hy-surface-elevated-color";
15
+ readonly onAccent: "--hy-on-accent-color";
11
16
  readonly fontSize: "--hy-font-size";
12
17
  readonly lineHeight: "--hy-line-height";
13
18
  readonly gap: "--hy-gap";
14
19
  readonly radius: "--hy-radius";
15
20
  }>;
16
- export type HYThemeVariables = Readonly<Record<(typeof HY_THEME_TOKENS)[keyof typeof HY_THEME_TOKENS], string>>;
21
+ export type HYThemeVariables = Readonly<Record<(typeof HY_THEME_TOKENS)['text' | 'muted' | 'surface' | 'input' | 'accent' | 'danger' | 'border' | 'focus' | 'fontSize' | 'lineHeight' | 'gap' | 'radius'], string> & Partial<Record<(typeof HY_THEME_TOKENS)[keyof typeof HY_THEME_TOKENS], string>> & Record<string, string>>;
17
22
  export declare function hyNativeTheme(theme: HYTheme, fontScale?: number): HYTheme;
18
23
  /** Returns data for an adapter to apply; importing it never creates a stylesheet. */
19
24
  export declare function hyThemeVariables(theme: HYTheme, fontScale?: number): HYThemeVariables;
@@ -3,6 +3,7 @@ import { snapshot } from '../core/data.js';
3
3
  export const HY_THEME_TOKENS = Object.freeze({
4
4
  text: '--hy-text-color', muted: '--hy-secondary-text-color', surface: '--hy-surface-color', input: '--hy-input-bg-color',
5
5
  accent: '--hy-accent-color', danger: '--hy-invalid-border-color', border: '--hy-border-color', focus: '--hy-focus-ring-color',
6
+ selected: '--hy-selected-bg-color', pressed: '--hy-pressed-bg-color', disabled: '--hy-disabled-text-color', elevated: '--hy-surface-elevated-color', onAccent: '--hy-on-accent-color',
6
7
  fontSize: '--hy-font-size', lineHeight: '--hy-line-height', gap: '--hy-gap', radius: '--hy-radius',
7
8
  });
8
9
  export function hyNativeTheme(theme, fontScale = 1) {
@@ -10,7 +11,7 @@ export function hyNativeTheme(theme, fontScale = 1) {
10
11
  if (!theme || typeof theme !== 'object')
11
12
  bad('theme');
12
13
  for (const key of Object.keys(theme))
13
- if (!['color', 'fontSize', 'lineHeight', 'gap', 'radius'].includes(key))
14
+ if (!['color', 'fontSize', 'lineHeight', 'gap', 'radius', 'typography'].includes(key))
14
15
  bad(key);
15
16
  if (!Number.isFinite(fontScale) || fontScale <= 0)
16
17
  bad('fontScale');
@@ -23,11 +24,29 @@ export function hyNativeTheme(theme, fontScale = 1) {
23
24
  bad(`color.${key}`);
24
25
  }
25
26
  for (const key of Object.keys(theme.color))
26
- if (!['text', 'muted', 'surface', 'input', 'accent', 'danger', 'border', 'focus'].includes(key))
27
+ if (!['text', 'muted', 'surface', 'input', 'accent', 'danger', 'border', 'focus', 'selected', 'pressed', 'disabled', 'elevated', 'onAccent'].includes(key))
27
28
  bad(`color.${key}`);
29
+ for (const [key, value] of Object.entries(theme.color))
30
+ if (typeof value !== 'string' || !/^#[\da-f]{6}([\da-f]{2})?$/i.test(value))
31
+ bad(`color.${key}`);
32
+ const typography = {};
33
+ if (theme.typography !== undefined) {
34
+ if (!theme.typography || typeof theme.typography !== 'object' || Array.isArray(theme.typography))
35
+ bad('typography');
36
+ for (const [key, value] of Object.entries(theme.typography)) {
37
+ if (!['title', 'body', 'caption'].includes(key) || !value || typeof value !== 'object')
38
+ bad(`typography.${key}`);
39
+ for (const field of Object.keys(value))
40
+ if (!['fontSize', 'lineHeight', 'weight'].includes(field))
41
+ bad(`typography.${key}.${field}`);
42
+ if (![value.fontSize, value.lineHeight].every(v => Number.isFinite(v) && v > 0 && Number.isFinite(v * fontScale)) || (value.weight !== undefined && !['normal', 'medium', 'bold'].includes(value.weight)))
43
+ bad(`typography.${key}`);
44
+ typography[key] = { ...value, fontSize: value.fontSize * fontScale, lineHeight: value.lineHeight * fontScale };
45
+ }
46
+ }
28
47
  if (!Number.isFinite(theme.fontSize * fontScale) || !Number.isFinite(theme.lineHeight * fontScale))
29
48
  bad('fontScale');
30
- return snapshot({ color: { ...theme.color }, fontSize: theme.fontSize * fontScale, lineHeight: theme.lineHeight * fontScale, gap: theme.gap, radius: theme.radius });
49
+ return snapshot({ color: { ...theme.color }, fontSize: theme.fontSize * fontScale, lineHeight: theme.lineHeight * fontScale, gap: theme.gap, radius: theme.radius, ...(theme.typography ? { typography } : {}) });
31
50
  }
32
51
  /** Returns data for an adapter to apply; importing it never creates a stylesheet. */
33
52
  export function hyThemeVariables(theme, fontScale = 1) {
@@ -35,6 +54,7 @@ export function hyThemeVariables(theme, fontScale = 1) {
35
54
  return Object.freeze(Object.fromEntries([
36
55
  ...Object.entries(data.color).map(([key, value]) => [HY_THEME_TOKENS[key], value]),
37
56
  ...['fontSize', 'lineHeight', 'gap', 'radius'].map(key => [HY_THEME_TOKENS[key], `${data[key]}px`]),
57
+ ...Object.entries(data.typography ?? {}).flatMap(([key, value]) => [[`--hy-${key}-font-size`, `${value.fontSize}px`], [`--hy-${key}-line-height`, `${value.lineHeight}px`], [`--hy-${key}-font-weight`, value.weight === 'bold' ? '700' : value.weight === 'medium' ? '500' : '400']]),
38
58
  ]));
39
59
  }
40
60
  //# sourceMappingURL=theme.js.map
@@ -0,0 +1,30 @@
1
+ export type HYProgressType = 'line' | 'circle';
2
+ export type HYProgressStatus = 'normal' | 'active' | 'success' | 'exception';
3
+ export declare class HYProgress extends HTMLElement {
4
+ private readonly _meter;
5
+ private readonly _line;
6
+ private readonly _fill;
7
+ private readonly _svg;
8
+ private readonly _circle;
9
+ private readonly _info;
10
+ static get observedAttributes(): string[];
11
+ constructor();
12
+ connectedCallback(): void;
13
+ attributeChangedCallback(): void;
14
+ get percent(): number;
15
+ set percent(value: number);
16
+ get type(): HYProgressType;
17
+ set type(value: HYProgressType);
18
+ get status(): HYProgressStatus;
19
+ set status(value: HYProgressStatus);
20
+ get indeterminate(): boolean;
21
+ set indeterminate(value: boolean);
22
+ get showInfo(): boolean;
23
+ set showInfo(value: boolean);
24
+ get strokeWidth(): number;
25
+ set strokeWidth(value: number);
26
+ get size(): number;
27
+ set size(value: number);
28
+ private _sync;
29
+ }
30
+ export declare function defineProgressComponents(): void;
@@ -0,0 +1,102 @@
1
+ export class HYProgress extends HTMLElement {
2
+ _meter = document.createElement('div');
3
+ _line = document.createElement('div');
4
+ _fill = document.createElement('div');
5
+ _svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
6
+ _circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
7
+ _info = document.createElement('span');
8
+ static get observedAttributes() { return ['percent', 'type', 'status', 'indeterminate', 'show-info', 'stroke-width', 'size', 'aria-label']; }
9
+ constructor() {
10
+ super();
11
+ const root = this.attachShadow({ mode: 'open' });
12
+ const style = document.createElement('style');
13
+ style.textContent = `
14
+ :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); }
15
+ .meter { --_color: var(--hy-progress-color, var(--hy-accent-color, #8177f2)); display: flex; align-items: center; gap: var(--hy-space-4, 8px); }
16
+ .meter.success { --_color: var(--hy-success-color, #3ea67a); } .meter.exception { --_color: var(--hy-error-color, #d95d72); }
17
+ .line { flex: 1; overflow: hidden; height: var(--_stroke, 6px); border-radius: 999px; background: var(--hy-progress-trail-color, var(--hy-border-color, #303746)); }
18
+ .fill { height: 100%; border-radius: inherit; background: var(--_color); transition: width 150ms ease; }
19
+ .active .fill { background-image: linear-gradient(90deg, transparent, color-mix(in srgb, var(--hy-selected-text-color, #fff) 35%, transparent), transparent); background-size: 200% 100%; animation: hy-progress-active 1.5s linear infinite; }
20
+ .indeterminate .fill { width: 35% !important; animation: hy-progress-unknown 1.3s ease-in-out infinite; }
21
+ svg { display: block; width: var(--_size, 96px); height: var(--_size, 96px); transform: rotate(-90deg); }
22
+ circle { fill: none; stroke-width: var(--_circle-stroke, 6); } .trail { stroke: var(--hy-progress-trail-color, var(--hy-border-color, #303746)); }
23
+ .arc { stroke: var(--_color); stroke-linecap: round; transition: stroke-dashoffset 150ms ease; }
24
+ .circle { position: relative; display: inline-grid; place-items: center; } .circle .info { position: absolute; max-width: 80%; text-align: center; }
25
+ .circle.indeterminate svg { animation: hy-progress-rotate 1s linear infinite; }
26
+ [hidden] { display: none !important; } .info { flex: 0 0 auto; }
27
+ @keyframes hy-progress-active { to { background-position: -200% 0; } }
28
+ @keyframes hy-progress-unknown { from { transform: translateX(-100%); } to { transform: translateX(385%); } }
29
+ @keyframes hy-progress-rotate { to { transform: rotate(270deg); } }
30
+ @media (prefers-reduced-motion: reduce) { .fill, .arc { transition: none; } .active .fill, .indeterminate .fill, .circle.indeterminate svg { animation: none; } }
31
+ `;
32
+ this._meter.className = 'meter';
33
+ this._meter.part.add('meter');
34
+ this._meter.setAttribute('role', 'progressbar');
35
+ this._line.className = 'line';
36
+ this._line.part.add('trail');
37
+ this._fill.className = 'fill';
38
+ this._fill.part.add('fill');
39
+ this._line.append(this._fill);
40
+ this._svg.setAttribute('viewBox', '0 0 100 100');
41
+ this._svg.setAttribute('aria-hidden', 'true');
42
+ this._svg.part.add('circle');
43
+ const trail = this._circle.cloneNode();
44
+ for (const circle of [trail, this._circle]) {
45
+ circle.setAttribute('cx', '50');
46
+ circle.setAttribute('cy', '50');
47
+ circle.setAttribute('r', '44');
48
+ circle.setAttribute('pathLength', '100');
49
+ }
50
+ trail.classList.add('trail');
51
+ this._circle.classList.add('arc');
52
+ this._circle.setAttribute('stroke-dasharray', '100');
53
+ this._svg.append(trail, this._circle);
54
+ this._info.className = 'info';
55
+ this._info.part.add('info');
56
+ this._meter.append(this._line, this._svg, this._info);
57
+ root.append(style, this._meter);
58
+ }
59
+ connectedCallback() { this._sync(); }
60
+ attributeChangedCallback() { this._sync(); }
61
+ get percent() { return boundedNumber(this.getAttribute('percent'), 0, 100, 0); }
62
+ set percent(value) { this.setAttribute('percent', String(value)); }
63
+ get type() { return this.getAttribute('type') === 'circle' ? 'circle' : 'line'; }
64
+ set type(value) { this.setAttribute('type', value); }
65
+ get status() { const value = this.getAttribute('status'); return value === 'active' || value === 'success' || value === 'exception' ? value : 'normal'; }
66
+ set status(value) { this.setAttribute('status', value); }
67
+ get indeterminate() { return this.hasAttribute('indeterminate'); }
68
+ set indeterminate(value) { this.toggleAttribute('indeterminate', value); }
69
+ get showInfo() { return this.getAttribute('show-info') !== 'false'; }
70
+ set showInfo(value) { this.setAttribute('show-info', String(value)); }
71
+ get strokeWidth() { return boundedNumber(this.getAttribute('stroke-width'), 1, 20, 6); }
72
+ set strokeWidth(value) { this.setAttribute('stroke-width', String(value)); }
73
+ get size() { return boundedNumber(this.getAttribute('size'), 24, 1000, 96); }
74
+ set size(value) { this.setAttribute('size', String(value)); }
75
+ _sync() {
76
+ const circle = this.type === 'circle';
77
+ this._meter.className = `meter ${this.status}${circle ? ' circle' : ''}${this.indeterminate ? ' indeterminate' : ''}`;
78
+ this._meter.setAttribute('aria-valuemin', '0');
79
+ this._meter.setAttribute('aria-valuemax', '100');
80
+ if (this.indeterminate)
81
+ this._meter.removeAttribute('aria-valuenow');
82
+ else
83
+ this._meter.setAttribute('aria-valuenow', String(this.percent));
84
+ this._meter.setAttribute('aria-label', this.getAttribute('aria-label') || 'Progress');
85
+ this._meter.setAttribute('aria-valuetext', this.indeterminate ? 'In progress' : `${this.percent}%${this.status === 'exception' ? ' Failed' : this.status === 'success' ? ' Complete' : ''}`);
86
+ this._meter.style.setProperty('--_stroke', `${this.strokeWidth}px`);
87
+ this._meter.style.setProperty('--_circle-stroke', String(this.strokeWidth));
88
+ this._meter.style.setProperty('--_size', `${this.size}px`);
89
+ this._line.hidden = circle;
90
+ this._svg.style.display = circle ? '' : 'none';
91
+ this._fill.style.width = `${this.percent}%`;
92
+ this._circle.setAttribute('r', String(50 - this.strokeWidth / 2 - 1));
93
+ this._svg.querySelector('.trail')?.setAttribute('r', String(50 - this.strokeWidth / 2 - 1));
94
+ this._circle.setAttribute('stroke-dashoffset', String(this.indeterminate ? 65 : 100 - this.percent));
95
+ this._info.hidden = !this.showInfo;
96
+ this._info.textContent = this.indeterminate ? '…' : `${this.percent}%`;
97
+ }
98
+ }
99
+ function boundedNumber(raw, min, max, fallback) { const value = raw === null ? NaN : Number(raw); return Number.isFinite(value) ? Math.min(max, Math.max(min, value)) : fallback; }
100
+ export function defineProgressComponents() { if (!customElements.get('hy-progress'))
101
+ customElements.define('hy-progress', HYProgress); }
102
+ //# sourceMappingURL=progress.js.map
@@ -0,0 +1,62 @@
1
+ export type HYQRCodeErrorCorrectionLevel = 'L' | 'M' | 'Q' | 'H';
2
+ export type HYQRCodeStatus = 'empty' | 'ready' | 'error';
3
+ export interface HYQRCodeRenderDetail {
4
+ readonly value: string;
5
+ readonly version: number;
6
+ readonly moduleCount: number;
7
+ readonly errorCorrectionLevel: HYQRCodeErrorCorrectionLevel;
8
+ }
9
+ export interface HYQRCodeErrorDetail {
10
+ readonly message: string;
11
+ }
12
+ export interface HYQRCodeIconErrorDetail {
13
+ readonly src: string;
14
+ }
15
+ /** Local SVG QR generation with a bounded decorative image or named icon slot. */
16
+ export declare class HYQRCode extends HTMLElement {
17
+ private readonly _frame;
18
+ private readonly _svg;
19
+ private readonly _background;
20
+ private readonly _modules;
21
+ private readonly _iconFrame;
22
+ private readonly _image;
23
+ private readonly _slot;
24
+ private readonly _message;
25
+ private _code;
26
+ private _key;
27
+ private _pathKey;
28
+ private _lastIcon;
29
+ private _iconReady;
30
+ private _state;
31
+ private _error;
32
+ static get observedAttributes(): string[];
33
+ constructor();
34
+ connectedCallback(): void;
35
+ disconnectedCallback(): void;
36
+ attributeChangedCallback(): void;
37
+ get value(): string;
38
+ set value(value: string);
39
+ get size(): number;
40
+ set size(value: number);
41
+ get color(): string;
42
+ set color(value: string);
43
+ get backgroundColor(): string;
44
+ set backgroundColor(value: string);
45
+ /** Quiet zone in modules. At least four modules are retained. */
46
+ get margin(): number;
47
+ set margin(value: number);
48
+ /** Defaults to H with an icon and M otherwise. An explicit level takes precedence. */
49
+ get errorCorrectionLevel(): HYQRCodeErrorCorrectionLevel;
50
+ set errorCorrectionLevel(value: HYQRCodeErrorCorrectionLevel);
51
+ get icon(): string;
52
+ set icon(value: string);
53
+ /** Requested image/slot size in CSS pixels. Actual coverage is bounded for readability. */
54
+ get iconSize(): number;
55
+ set iconSize(value: number);
56
+ get iconMargin(): number;
57
+ set iconMargin(value: number);
58
+ get status(): HYQRCodeStatus;
59
+ private _hasSlotIcon;
60
+ private _render;
61
+ }
62
+ export declare function defineQRCodeComponents(): void;
@@ -0,0 +1,224 @@
1
+ import { qrcodegen } from './internal/qrcodegen.js';
2
+ const levels = { L: qrcodegen.QrCode.Ecc.LOW, M: qrcodegen.QrCode.Ecc.MEDIUM, Q: qrcodegen.QrCode.Ecc.QUARTILE, H: qrcodegen.QrCode.Ecc.HIGH };
3
+ function integer(value, fallback, min, max) {
4
+ if (value == null || value === '')
5
+ return fallback;
6
+ const number = Number(value);
7
+ return Number.isFinite(number) ? Math.min(max, Math.max(min, Math.floor(number))) : fallback;
8
+ }
9
+ /** Local SVG QR generation with a bounded decorative image or named icon slot. */
10
+ export class HYQRCode extends HTMLElement {
11
+ _frame = document.createElement('div');
12
+ _svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
13
+ _background = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
14
+ _modules = document.createElementNS('http://www.w3.org/2000/svg', 'path');
15
+ _iconFrame = document.createElement('div');
16
+ _image = document.createElement('img');
17
+ _slot = document.createElement('slot');
18
+ _message = document.createElement('span');
19
+ _code = null;
20
+ _key = '';
21
+ _pathKey = '';
22
+ _lastIcon = '';
23
+ _iconReady = false;
24
+ _state = 'empty';
25
+ _error = '';
26
+ static get observedAttributes() {
27
+ return ['value', 'size', 'color', 'background-color', 'margin', 'error-correction-level', 'icon', 'icon-size', 'icon-margin', 'aria-label'];
28
+ }
29
+ constructor() {
30
+ super();
31
+ const root = this.attachShadow({ mode: 'open' });
32
+ const style = document.createElement('style');
33
+ style.textContent = `
34
+ :host { display: inline-block; max-width: 100%; vertical-align: middle; color: var(--hy-text-color, #eef0ff); font: var(--hy-font-size-sm, 12px)/var(--hy-line-height-relaxed, 1.5) var(--hy-font-family, system-ui, sans-serif); }
35
+ :host([hidden]), [hidden] { display: none !important; }
36
+ .frame { position: relative; box-sizing: border-box; max-width: 100%; aspect-ratio: 1; }
37
+ svg { display: block; width: 100%; height: 100%; }
38
+ .icon { position: absolute; box-sizing: border-box; inset: 50% auto auto 50%; transform: translate(-50%, -50%); display: grid; place-items: center; background: var(--_qr-background); border-radius: var(--hy-qr-code-icon-radius, var(--hy-radius-sm, 4px)); pointer-events: none; overflow: hidden; }
39
+ img { display: block; width: 100%; height: 100%; min-width: 0; min-height: 0; object-fit: contain; }
40
+ slot { display: contents; }
41
+ ::slotted([slot="icon"]) { display: block; box-sizing: border-box; width: 100%; height: 100%; min-width: 0; min-height: 0; object-fit: contain; overflow: hidden; }
42
+ .message { position: absolute; inset: 0; display: grid; place-items: center; box-sizing: border-box; padding: var(--hy-space-6, 12px); text-align: center; color: var(--hy-secondary-text-color, #a9add4); background: var(--hy-surface-color, #10132f); border: 1px solid var(--hy-border-color, #343765); border-radius: var(--hy-qr-code-radius, var(--hy-radius-lg, 8px)); }
43
+ `;
44
+ this._frame.className = 'frame';
45
+ this._frame.part.add('frame');
46
+ this._svg.part.add('code');
47
+ this._svg.setAttribute('aria-hidden', 'true');
48
+ this._svg.setAttribute('shape-rendering', 'crispEdges');
49
+ this._background.part.add('background');
50
+ this._modules.part.add('modules');
51
+ this._svg.append(this._background, this._modules);
52
+ this._iconFrame.className = 'icon';
53
+ this._iconFrame.part.add('icon');
54
+ this._iconFrame.setAttribute('aria-hidden', 'true');
55
+ this._iconFrame.inert = true;
56
+ this._image.alt = '';
57
+ this._image.draggable = false;
58
+ this._image.part.add('icon-image');
59
+ this._slot.name = 'icon';
60
+ this._iconFrame.append(this._slot, this._image);
61
+ this._message.className = 'message';
62
+ this._message.part.add('message');
63
+ this._frame.append(this._svg, this._iconFrame, this._message);
64
+ root.append(style, this._frame);
65
+ this._image.addEventListener('load', () => {
66
+ if (!this.isConnected || !this._image.naturalWidth)
67
+ return;
68
+ this._iconReady = true;
69
+ this._render();
70
+ });
71
+ this._image.addEventListener('error', () => {
72
+ if (!this.isConnected || !this._lastIcon)
73
+ return;
74
+ this._iconReady = false;
75
+ this._render();
76
+ this.dispatchEvent(new CustomEvent('qr-icon-error', { detail: { src: this._lastIcon }, bubbles: true, composed: true }));
77
+ });
78
+ }
79
+ connectedCallback() { this._slot.addEventListener('slotchange', this._render); this._render(); }
80
+ disconnectedCallback() {
81
+ this._slot.removeEventListener('slotchange', this._render);
82
+ this._lastIcon = '';
83
+ this._iconReady = false;
84
+ this._image.removeAttribute('src');
85
+ }
86
+ attributeChangedCallback() { this._render(); }
87
+ get value() { return this.getAttribute('value') ?? ''; }
88
+ set value(value) { this.setAttribute('value', String(value ?? '')); }
89
+ get size() { return integer(this.getAttribute('size'), 200, 64, 2048); }
90
+ set size(value) { this.setAttribute('size', String(integer(value, 200, 64, 2048))); }
91
+ get color() { return this.getAttribute('color') ?? ''; }
92
+ set color(value) { this.setAttribute('color', value); }
93
+ get backgroundColor() { return this.getAttribute('background-color') ?? ''; }
94
+ set backgroundColor(value) { this.setAttribute('background-color', value); }
95
+ /** Quiet zone in modules. At least four modules are retained. */
96
+ get margin() { return integer(this.getAttribute('margin'), 4, 4, 16); }
97
+ set margin(value) { this.setAttribute('margin', String(integer(value, 4, 4, 16))); }
98
+ /** Defaults to H with an icon and M otherwise. An explicit level takes precedence. */
99
+ get errorCorrectionLevel() {
100
+ const value = this.getAttribute('error-correction-level')?.toUpperCase();
101
+ if (value === 'L' || value === 'M' || value === 'Q' || value === 'H')
102
+ return value;
103
+ return this.icon || this._hasSlotIcon() ? 'H' : 'M';
104
+ }
105
+ set errorCorrectionLevel(value) { this.setAttribute('error-correction-level', value); }
106
+ get icon() { return this.getAttribute('icon') ?? ''; }
107
+ set icon(value) { this.setAttribute('icon', value ?? ''); }
108
+ /** Requested image/slot size in CSS pixels. Actual coverage is bounded for readability. */
109
+ get iconSize() { return integer(this.getAttribute('icon-size'), 32, 4, 512); }
110
+ set iconSize(value) { this.setAttribute('icon-size', String(integer(value, 32, 4, 512))); }
111
+ get iconMargin() { return integer(this.getAttribute('icon-margin'), 2, 0, 64); }
112
+ set iconMargin(value) { this.setAttribute('icon-margin', String(integer(value, 2, 0, 64))); }
113
+ get status() { return this._state; }
114
+ _hasSlotIcon() {
115
+ return this._slot.assignedNodes().some(node => node.nodeType === Node.ELEMENT_NODE || Boolean(node.textContent?.trim()));
116
+ }
117
+ _render = () => {
118
+ if (!this.isConnected)
119
+ return;
120
+ const value = this.value;
121
+ const level = this.errorCorrectionLevel;
122
+ const key = JSON.stringify([value, level]);
123
+ let generated = false;
124
+ let failed = false;
125
+ if (key !== this._key) {
126
+ this._key = key;
127
+ this._code = null;
128
+ this._error = '';
129
+ this._state = value ? 'ready' : 'empty';
130
+ if (value) {
131
+ try {
132
+ const bytes = new TextEncoder().encode(value);
133
+ if (bytes.length > 7089)
134
+ throw new RangeError('Value too long');
135
+ const segments = /^[\x00-\x7f]*$/.test(value) ? qrcodegen.QrSegment.makeSegments(value) : [qrcodegen.QrSegment.makeEci(26), qrcodegen.QrSegment.makeBytes([...bytes])];
136
+ this._code = qrcodegen.QrCode.encodeSegments(segments, levels[level], 1, 40, -1, false);
137
+ generated = true;
138
+ }
139
+ catch {
140
+ this._state = 'error';
141
+ this._error = 'This value is too long for the selected error correction level.';
142
+ failed = true;
143
+ }
144
+ }
145
+ }
146
+ const background = CSS.supports('color', this.backgroundColor) ? this.backgroundColor : 'var(--hy-qr-code-background-color, #ffffff)';
147
+ const color = CSS.supports('color', this.color) ? this.color : 'var(--hy-qr-code-color, #111827)';
148
+ this._frame.style.width = `${this.size}px`;
149
+ this._frame.style.setProperty('--_qr-background', background);
150
+ this._frame.dataset.state = this._state;
151
+ this._svg.toggleAttribute('hidden', this._state !== 'ready');
152
+ this._message.hidden = this._state === 'ready';
153
+ this._message.textContent = this._state === 'error' ? this._error : 'Enter a value to generate a QR code.';
154
+ this._message.setAttribute('role', this._state === 'error' ? 'alert' : 'status');
155
+ if (this._state === 'ready') {
156
+ this._frame.setAttribute('role', 'img');
157
+ this._frame.setAttribute('aria-label', this.getAttribute('aria-label') ?? 'QR code');
158
+ }
159
+ else {
160
+ this._frame.removeAttribute('role');
161
+ this._frame.removeAttribute('aria-label');
162
+ }
163
+ this._background.setAttribute('fill', background);
164
+ this._modules.setAttribute('fill', color);
165
+ const code = this._code;
166
+ const pathKey = `${key}:${this.margin}`;
167
+ if (!code) {
168
+ this._modules.removeAttribute('d');
169
+ this._pathKey = '';
170
+ }
171
+ else if (pathKey !== this._pathKey) {
172
+ this._pathKey = pathKey;
173
+ const extent = code.size + this.margin * 2;
174
+ this._svg.setAttribute('viewBox', `0 0 ${extent} ${extent}`);
175
+ this._background.setAttribute('width', String(extent));
176
+ this._background.setAttribute('height', String(extent));
177
+ const path = [];
178
+ for (let y = 0; y < code.size; y++) {
179
+ for (let x = 0; x < code.size;) {
180
+ if (!code.getModule(x, y)) {
181
+ x++;
182
+ continue;
183
+ }
184
+ const start = x;
185
+ while (x < code.size && code.getModule(x, y))
186
+ x++;
187
+ path.push(`M${start + this.margin},${y + this.margin}h${x - start}v1h-${x - start}z`);
188
+ }
189
+ }
190
+ this._modules.setAttribute('d', path.join(''));
191
+ }
192
+ const slotted = this._hasSlotIcon();
193
+ const src = slotted || !code ? '' : this.icon;
194
+ if (src !== this._lastIcon) {
195
+ this._lastIcon = src;
196
+ this._iconReady = false;
197
+ if (src)
198
+ this._image.src = src;
199
+ else
200
+ this._image.removeAttribute('src');
201
+ }
202
+ this._image.hidden = slotted || !src;
203
+ this._iconFrame.hidden = !code || (!slotted && !this._iconReady);
204
+ if (code) {
205
+ // Include the backing margin in the coverage limit; percentages also
206
+ // preserve that limit when max-width shrinks the rendered code.
207
+ const coverage = Math.min(this.iconSize + this.iconMargin * 2, this.size * code.size / (code.size + this.margin * 2) * .2);
208
+ const padding = Math.min(this.iconMargin, coverage / 4);
209
+ this._iconFrame.style.width = this._iconFrame.style.height = `${coverage / this.size * 100}%`;
210
+ this._iconFrame.style.padding = `${padding / this.size * 100}%`;
211
+ }
212
+ if (generated && code)
213
+ this.dispatchEvent(new CustomEvent('qr-render', {
214
+ detail: { value, version: code.version, moduleCount: code.size, errorCorrectionLevel: level }, bubbles: true, composed: true,
215
+ }));
216
+ if (failed)
217
+ this.dispatchEvent(new CustomEvent('qr-error', { detail: { message: this._error }, bubbles: true, composed: true }));
218
+ };
219
+ }
220
+ export function defineQRCodeComponents() {
221
+ if (!customElements.get('hy-qr-code'))
222
+ customElements.define('hy-qr-code', HYQRCode);
223
+ }
224
+ //# sourceMappingURL=qr-code.js.map
package/dist/radio.d.ts CHANGED
@@ -4,10 +4,12 @@ export interface HYRadioChangeDetail {
4
4
  name: string;
5
5
  }
6
6
  export declare class HYRadio extends HTMLElement {
7
+ static readonly formAssociated = true;
7
8
  private readonly _input;
8
9
  private readonly _marker;
9
10
  private readonly _label;
10
11
  private readonly _slot;
12
+ private readonly _formControl;
11
13
  static get observedAttributes(): string[];
12
14
  constructor();
13
15
  connectedCallback(): void;
@@ -24,6 +26,14 @@ export declare class HYRadio extends HTMLElement {
24
26
  get name(): string;
25
27
  set name(value: string);
26
28
  private _sync;
29
+ get form(): HTMLFormElement | null;
30
+ checkValidity(): boolean;
31
+ reportValidity(): boolean;
32
+ setCustomValidity(message: string): void;
33
+ formDisabledCallback(disabled: boolean): void;
34
+ formResetCallback(): void;
35
+ formStateRestoreCallback(state: string | File | FormData | null): void;
36
+ focus(options?: FocusOptions): void;
27
37
  private _onChange;
28
38
  private _uncheckNamedPeers;
29
39
  }
package/dist/radio.js CHANGED
@@ -1,8 +1,11 @@
1
+ import { HYFormControl } from './internal/form-control.js';
1
2
  export class HYRadio extends HTMLElement {
3
+ static formAssociated = true;
2
4
  _input = document.createElement('input');
3
5
  _marker = document.createElement('span');
4
6
  _label = document.createElement('span');
5
7
  _slot = document.createElement('slot');
8
+ _formControl = new HYFormControl(this, this._input);
6
9
  static get observedAttributes() {
7
10
  return ['checked', 'disabled', 'label', 'value', 'name', 'aria-label'];
8
11
  }
@@ -16,7 +19,7 @@ export class HYRadio extends HTMLElement {
16
19
  width: max-content;
17
20
  min-width: 0;
18
21
  color: var(--hy-radio-text-color, var(--hy-text-color, #d8e2f2));
19
- font: 12px system-ui, sans-serif;
22
+ font: var(--hy-font-size-sm, 12px) var(--hy-font-family, system-ui, sans-serif);
20
23
  }
21
24
  :host([disabled]) {
22
25
  opacity: 0.55;
@@ -25,7 +28,7 @@ export class HYRadio extends HTMLElement {
25
28
  label {
26
29
  display: inline-flex;
27
30
  align-items: center;
28
- gap: 8px;
31
+ gap: var(--hy-space-4, 8px);
29
32
  min-width: 0;
30
33
  cursor: pointer;
31
34
  user-select: none;
@@ -96,6 +99,7 @@ export class HYRadio extends HTMLElement {
96
99
  connectedCallback() {
97
100
  this._input.addEventListener('change', this._onChange);
98
101
  this._sync();
102
+ this._formControl.connect();
99
103
  if (this.checked)
100
104
  this._uncheckNamedPeers();
101
105
  }
@@ -152,7 +156,7 @@ export class HYRadio extends HTMLElement {
152
156
  }
153
157
  _sync() {
154
158
  this._input.checked = this.checked;
155
- this._input.disabled = this.disabled;
159
+ this._input.disabled = this.disabled || this._formControl.disabled;
156
160
  this._input.value = this.value;
157
161
  this._input.name = this.name;
158
162
  const label = this.getAttribute('label');
@@ -165,7 +169,16 @@ export class HYRadio extends HTMLElement {
165
169
  this._input.setAttribute('aria-label', ariaLabel);
166
170
  else
167
171
  this._input.removeAttribute('aria-label');
168
- }
172
+ this._formControl.sync();
173
+ }
174
+ get form() { return this._formControl.internals.form; }
175
+ checkValidity() { return this._formControl.internals.checkValidity(); }
176
+ reportValidity() { return this._formControl.internals.reportValidity(); }
177
+ setCustomValidity(message) { this._formControl.setCustomValidity(message); }
178
+ formDisabledCallback(disabled) { this._formControl.disabled = disabled; this._sync(); }
179
+ formResetCallback() { this._formControl.reset(); }
180
+ formStateRestoreCallback(state) { this._formControl.restore(state); }
181
+ focus(options) { this._input.focus(options); }
169
182
  _onChange = () => {
170
183
  if (!this._input.checked)
171
184
  return;
@@ -186,7 +199,7 @@ export class HYRadio extends HTMLElement {
186
199
  ? root.querySelectorAll(`hy-radio[name="${cssEscape(this.name)}"]`)
187
200
  : [];
188
201
  for (const peer of peers) {
189
- if (peer === this || peer.disabled)
202
+ if (peer === this || peer.disabled || peer.form !== this.form)
190
203
  continue;
191
204
  peer.removeAttribute('checked');
192
205
  }
package/dist/range.js CHANGED
@@ -30,7 +30,7 @@ export class HYRange extends HTMLElement {
30
30
  width: var(--hy-range-width, 280px);
31
31
  min-width: 120px;
32
32
  color: var(--hy-text-color, #e8effa);
33
- font: 11px/1.3 system-ui, sans-serif;
33
+ font: calc(var(--hy-font-size-xs, 10px) + 1px)/calc(var(--hy-line-height-snug, 1.4) - 0.1) var(--hy-font-family, system-ui, sans-serif);
34
34
  --_handle-size: var(--hy-range-handle-size, 18px);
35
35
  --_rail-height: var(--hy-range-rail-height, 5px);
36
36
  }
@@ -49,7 +49,7 @@ export class HYRange extends HTMLElement {
49
49
  right: 0;
50
50
  left: 0;
51
51
  height: var(--_rail-height);
52
- border-radius: var(--hy-range-rail-radius, 999px);
52
+ border-radius: var(--hy-range-rail-radius, var(--hy-radius-full, 999px));
53
53
  transform: translateY(-50%);
54
54
  }
55
55
  .rail {
@@ -76,7 +76,7 @@ export class HYRange extends HTMLElement {
76
76
  outline: none;
77
77
  color: var(--hy-text-color, #e8effa);
78
78
  background: var(--hy-range-handle-color, var(--hy-surface-elevated-color, #171e2a));
79
- box-shadow: var(--hy-range-handle-shadow, 0 2px 8px rgba(0, 0, 0, 0.28));
79
+ box-shadow: var(--hy-range-handle-shadow, 0 2px 8px var(--hy-shadow-color, rgba(0, 0, 0, 0.28)));
80
80
  cursor: grab;
81
81
  transform: translate(-50%, -50%);
82
82
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
@@ -97,14 +97,14 @@ export class HYRange extends HTMLElement {
97
97
  bottom: calc(100% + 8px);
98
98
  display: none;
99
99
  min-width: 24px;
100
- padding: 3px 6px;
100
+ padding: calc(var(--hy-space-1, 2px) + 1px) var(--hy-space-3, 6px);
101
101
  border: 1px solid var(--hy-border-color, #303746);
102
- border-radius: 4px;
102
+ border-radius: var(--hy-radius-sm, 4px);
103
103
  pointer-events: none;
104
104
  color: var(--hy-text-color, #e8effa);
105
105
  background: var(--hy-surface-elevated-color, #171e2a);
106
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
107
- font: 10px/1.2 ui-monospace, monospace;
106
+ box-shadow: 0 4px 12px var(--hy-shadow-color, rgba(0, 0, 0, 0.22));
107
+ font: var(--hy-font-size-xs, 10px)/var(--hy-line-height-compact, 1.2) var(--hy-font-family-mono, ui-monospace, monospace);
108
108
  white-space: nowrap;
109
109
  }
110
110
  :host([show-value]) .bubble { display: block; }