@celestia-island/hikari 0.4.4

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 (187) hide show
  1. package/README.md +54 -0
  2. package/package.json +63 -0
  3. package/src/DemoApp.vue +400 -0
  4. package/src/components/HkActionBar.tsx +15 -0
  5. package/src/components/HkAlert.scss +121 -0
  6. package/src/components/HkAlert.tsx +85 -0
  7. package/src/components/HkAvatar.tsx +29 -0
  8. package/src/components/HkBadge.scss +117 -0
  9. package/src/components/HkBadge.tsx +50 -0
  10. package/src/components/HkBreadcrumb.tsx +39 -0
  11. package/src/components/HkButton.scss +128 -0
  12. package/src/components/HkButton.tsx +74 -0
  13. package/src/components/HkCard.scss +49 -0
  14. package/src/components/HkCard.tsx +38 -0
  15. package/src/components/HkCheckbox.scss +102 -0
  16. package/src/components/HkCheckbox.tsx +85 -0
  17. package/src/components/HkCollapse.tsx +48 -0
  18. package/src/components/HkColorPicker.scss +148 -0
  19. package/src/components/HkColorPicker.tsx +204 -0
  20. package/src/components/HkConfirmDialog.scss +12 -0
  21. package/src/components/HkConfirmDialog.tsx +75 -0
  22. package/src/components/HkDateTimePicker.scss +361 -0
  23. package/src/components/HkDateTimePicker.tsx +424 -0
  24. package/src/components/HkDivider.scss +85 -0
  25. package/src/components/HkDivider.tsx +51 -0
  26. package/src/components/HkDraggableGrid.scss +132 -0
  27. package/src/components/HkDraggableGrid.tsx +291 -0
  28. package/src/components/HkDraggableList.scss +110 -0
  29. package/src/components/HkDraggableList.tsx +238 -0
  30. package/src/components/HkDrawer.scss +175 -0
  31. package/src/components/HkDrawer.tsx +171 -0
  32. package/src/components/HkEmptyState.scss +42 -0
  33. package/src/components/HkEmptyState.tsx +41 -0
  34. package/src/components/HkErrorBoundary.scss +64 -0
  35. package/src/components/HkErrorBoundary.tsx +82 -0
  36. package/src/components/HkGaugeRing.scss +4 -0
  37. package/src/components/HkGaugeRing.tsx +130 -0
  38. package/src/components/HkHoverRevealAction.scss +66 -0
  39. package/src/components/HkHoverRevealAction.tsx +77 -0
  40. package/src/components/HkIcon.tsx +43 -0
  41. package/src/components/HkIconButton.tsx +42 -0
  42. package/src/components/HkImageViewer.scss +33 -0
  43. package/src/components/HkImageViewer.tsx +250 -0
  44. package/src/components/HkInput.scss +172 -0
  45. package/src/components/HkInput.tsx +175 -0
  46. package/src/components/HkKbd.tsx +26 -0
  47. package/src/components/HkKeywordSearchModal.scss +148 -0
  48. package/src/components/HkKeywordSearchModal.tsx +308 -0
  49. package/src/components/HkListTransition.scss +131 -0
  50. package/src/components/HkListTransition.tsx +29 -0
  51. package/src/components/HkLocalePickerPopup.tsx +42 -0
  52. package/src/components/HkLogo.scss +36 -0
  53. package/src/components/HkLogo.tsx +93 -0
  54. package/src/components/HkMarkdownRenderer.scss +141 -0
  55. package/src/components/HkMarkdownRenderer.tsx +123 -0
  56. package/src/components/HkMediaControlBar.scss +65 -0
  57. package/src/components/HkMediaControlBar.tsx +115 -0
  58. package/src/components/HkMediaPlayer.scss +29 -0
  59. package/src/components/HkMediaPlayer.tsx +210 -0
  60. package/src/components/HkMediaSlider.scss +54 -0
  61. package/src/components/HkMediaSlider.tsx +81 -0
  62. package/src/components/HkMediaVisualizer.scss +7 -0
  63. package/src/components/HkMediaVisualizer.tsx +119 -0
  64. package/src/components/HkMinimap.scss +76 -0
  65. package/src/components/HkMinimap.tsx +255 -0
  66. package/src/components/HkModal.scss +318 -0
  67. package/src/components/HkModal.tsx +481 -0
  68. package/src/components/HkModalBreadcrumb.scss +55 -0
  69. package/src/components/HkModalBreadcrumb.tsx +113 -0
  70. package/src/components/HkMorphingTabs.scss +141 -0
  71. package/src/components/HkMorphingTabs.tsx +113 -0
  72. package/src/components/HkNavItem.scss +81 -0
  73. package/src/components/HkNavItem.tsx +157 -0
  74. package/src/components/HkNumberInput.scss +154 -0
  75. package/src/components/HkNumberInput.tsx +161 -0
  76. package/src/components/HkPasswordInput.scss +289 -0
  77. package/src/components/HkPasswordInput.tsx +533 -0
  78. package/src/components/HkPhaseTransition.scss +25 -0
  79. package/src/components/HkPhaseTransition.tsx +40 -0
  80. package/src/components/HkPopover.scss +82 -0
  81. package/src/components/HkPopover.tsx +410 -0
  82. package/src/components/HkPopupSelect.scss +136 -0
  83. package/src/components/HkPopupSelect.tsx +199 -0
  84. package/src/components/HkProgressBar.scss +106 -0
  85. package/src/components/HkProgressBar.tsx +61 -0
  86. package/src/components/HkProgressDialog.tsx +67 -0
  87. package/src/components/HkProgressRing.scss +56 -0
  88. package/src/components/HkProgressRing.tsx +82 -0
  89. package/src/components/HkRadio.scss +119 -0
  90. package/src/components/HkRadio.tsx +75 -0
  91. package/src/components/HkRollingNumber.scss +37 -0
  92. package/src/components/HkRollingNumber.tsx +97 -0
  93. package/src/components/HkScrollContainer.scss +101 -0
  94. package/src/components/HkScrollContainer.tsx +362 -0
  95. package/src/components/HkSearchInput.scss +132 -0
  96. package/src/components/HkSearchInput.tsx +117 -0
  97. package/src/components/HkSelect.scss +143 -0
  98. package/src/components/HkSelect.tsx +230 -0
  99. package/src/components/HkSelectionGrid.scss +177 -0
  100. package/src/components/HkSelectionGrid.tsx +99 -0
  101. package/src/components/HkSelectionWaterfall.scss +93 -0
  102. package/src/components/HkSelectionWaterfall.tsx +90 -0
  103. package/src/components/HkSidebar.scss +81 -0
  104. package/src/components/HkSidebar.tsx +45 -0
  105. package/src/components/HkSkeleton.scss +44 -0
  106. package/src/components/HkSkeleton.tsx +30 -0
  107. package/src/components/HkSkeletonList.tsx +35 -0
  108. package/src/components/HkSpinner.scss +67 -0
  109. package/src/components/HkSpinner.tsx +41 -0
  110. package/src/components/HkSplash.scss +60 -0
  111. package/src/components/HkSplash.tsx +40 -0
  112. package/src/components/HkSwitch.scss +157 -0
  113. package/src/components/HkSwitch.tsx +72 -0
  114. package/src/components/HkTable.scss +198 -0
  115. package/src/components/HkTable.tsx +246 -0
  116. package/src/components/HkTabs.scss +109 -0
  117. package/src/components/HkTabs.tsx +111 -0
  118. package/src/components/HkTag.scss +88 -0
  119. package/src/components/HkTag.tsx +44 -0
  120. package/src/components/HkTextarea.scss +72 -0
  121. package/src/components/HkTextarea.tsx +104 -0
  122. package/src/components/HkTimeline.scss +139 -0
  123. package/src/components/HkTimeline.tsx +95 -0
  124. package/src/components/HkToast.scss +168 -0
  125. package/src/components/HkToast.tsx +175 -0
  126. package/src/components/HkTooltip.scss +47 -0
  127. package/src/components/HkTooltip.tsx +108 -0
  128. package/src/components/HkTree.scss +188 -0
  129. package/src/components/HkTree.tsx +217 -0
  130. package/src/components/HkTrendChart.tsx +180 -0
  131. package/src/components/HkWindowedItem.scss +17 -0
  132. package/src/components/HkWindowedItem.tsx +107 -0
  133. package/src/components/HkZoomToolbar.scss +35 -0
  134. package/src/components/HkZoomToolbar.tsx +69 -0
  135. package/src/composables/useBreakpoint.ts +41 -0
  136. package/src/composables/useClipboard.ts +37 -0
  137. package/src/composables/useConfirm.ts +35 -0
  138. package/src/composables/useProgressDialog.ts +52 -0
  139. package/src/composables/useReportedTransition.ts +69 -0
  140. package/src/composables/useScrollWindow.ts +21 -0
  141. package/src/composables/useToast.ts +2 -0
  142. package/src/demo.scss +24 -0
  143. package/src/demo.ts +22 -0
  144. package/src/env.d.ts +6 -0
  145. package/src/i18n/context.ts +89 -0
  146. package/src/i18n/locales/ar/components.json +43 -0
  147. package/src/i18n/locales/ar/components.toml +40 -0
  148. package/src/i18n/locales/de/components.json +43 -0
  149. package/src/i18n/locales/de/components.toml +40 -0
  150. package/src/i18n/locales/en/components.json +43 -0
  151. package/src/i18n/locales/en/components.toml +40 -0
  152. package/src/i18n/locales/es/components.json +43 -0
  153. package/src/i18n/locales/es/components.toml +40 -0
  154. package/src/i18n/locales/fr/components.json +43 -0
  155. package/src/i18n/locales/fr/components.toml +40 -0
  156. package/src/i18n/locales/ja/components.json +43 -0
  157. package/src/i18n/locales/ja/components.toml +40 -0
  158. package/src/i18n/locales/ko/components.json +43 -0
  159. package/src/i18n/locales/ko/components.toml +40 -0
  160. package/src/i18n/locales/pt/components.json +43 -0
  161. package/src/i18n/locales/pt/components.toml +40 -0
  162. package/src/i18n/locales/ru/components.json +43 -0
  163. package/src/i18n/locales/ru/components.toml +40 -0
  164. package/src/i18n/locales/zh-Hans/components.json +43 -0
  165. package/src/i18n/locales/zh-Hans/components.toml +40 -0
  166. package/src/i18n/locales/zh-Hant/components.json +43 -0
  167. package/src/i18n/locales/zh-Hant/components.toml +40 -0
  168. package/src/index.ts +137 -0
  169. package/src/render.ts +18 -0
  170. package/src/runtime/animationBus.ts +278 -0
  171. package/src/runtime/cronBus.ts +25 -0
  172. package/src/runtime/index.ts +12 -0
  173. package/src/runtime/useAsyncData.ts +30 -0
  174. package/src/runtime/useBreakpoint.ts +62 -0
  175. package/src/runtime/useClipboard.ts +37 -0
  176. package/src/runtime/useConfirm.ts +35 -0
  177. package/src/runtime/useOverlay.ts +82 -0
  178. package/src/runtime/usePopupManager.ts +89 -0
  179. package/src/runtime/useToast.ts +140 -0
  180. package/src/styles/index.scss +10 -0
  181. package/src/theme/index.ts +5 -0
  182. package/src/theme/presets.ts +307 -0
  183. package/src/theme/theme.scss +17 -0
  184. package/src/theme/useBackgroundLuminance.ts +145 -0
  185. package/src/theme/useSolarTime.ts +101 -0
  186. package/src/theme/useTheme.ts +141 -0
  187. package/src/tokens.scss +26 -0
@@ -0,0 +1,102 @@
1
+ /*
2
+ * HkCheckbox / HkRadio — unified selection control.
3
+ */
4
+
5
+ .hk-checkbox {
6
+ display: inline-flex;
7
+ align-items: center;
8
+ gap: var(--hi-space-8, 0.5rem);
9
+ cursor: pointer;
10
+ user-select: none;
11
+ }
12
+
13
+ .hk-checkbox[data-disabled] {
14
+ opacity: 0.5;
15
+ cursor: not-allowed;
16
+ }
17
+
18
+ /* ---------- box ---------- */
19
+
20
+ .hk-checkbox-box {
21
+ display: flex;
22
+ align-items: center;
23
+ justify-content: center;
24
+ width: 1.125rem;
25
+ height: 1.125rem;
26
+ border-radius: var(--hi-radius-xs, 4px);
27
+ border: 1px solid var(--hi-color-border, rgba(0, 0, 0, 0.08));
28
+ background: var(--hi-color-surface, rgba(255, 255, 255, 0.95));
29
+ transition:
30
+ border-color var(--hi-duration-normal, 0.3s) ease,
31
+ background var(--hi-duration-normal, 0.3s) ease;
32
+ flex-shrink: 0;
33
+ position: relative;
34
+ }
35
+
36
+ .hk-checkbox[data-type="radio"] .hk-checkbox-box {
37
+ border-radius: 50%;
38
+ }
39
+
40
+ .hk-checkbox-box[data-checked] {
41
+ background: var(--hi-color-primary, #ff6b9d);
42
+ border-color: var(--hi-color-primary, #ff6b9d);
43
+ color: var(--hi-color-text-on-primary, #fff);
44
+ }
45
+
46
+ .hk-checkbox-box[data-indeterminate] {
47
+ background: var(--hi-color-primary, #ff6b9d);
48
+ border-color: var(--hi-color-primary, #ff6b9d);
49
+ }
50
+
51
+ .hk-checkbox:hover .hk-checkbox-box[data-checked],
52
+ .hk-checkbox[data-animating] .hk-checkbox-box[data-checked] {
53
+ background: var(--hi-color-primary, #ff6b9d);
54
+ border-color: var(--hi-color-primary, #ff6b9d);
55
+ }
56
+
57
+ /* ---------- input ---------- */
58
+
59
+ .hk-checkbox-input {
60
+ position: absolute;
61
+ width: 0;
62
+ height: 0;
63
+ opacity: 0;
64
+ pointer-events: none;
65
+ }
66
+
67
+ /* ---------- markers ---------- */
68
+
69
+ .hk-checkbox-icon {
70
+ position: relative;
71
+ z-index: var(--hi-z-above, 1);
72
+ color: var(--hi-color-text-on-primary, #fff);
73
+ width: 14px;
74
+ height: 14px;
75
+ }
76
+
77
+ .hk-checkbox-dot {
78
+ width: 6px;
79
+ height: 6px;
80
+ border-radius: 50%;
81
+ background: var(--hi-color-text-on-primary, #fff);
82
+ z-index: var(--hi-z-above, 1);
83
+ }
84
+
85
+ .hk-checkbox-indeterminate {
86
+ width: 8px;
87
+ height: 2px;
88
+ border-radius: 1px;
89
+ background: var(--hi-color-text-on-primary, #fff);
90
+ z-index: var(--hi-z-above, 1);
91
+ }
92
+
93
+ /* ---------- label ---------- */
94
+
95
+ .hk-checkbox[data-animating] .hk-checkbox-box {
96
+ will-change: border-color, background;
97
+ }
98
+
99
+ .hk-checkbox-label-text {
100
+ font-size: var(--hi-text-sm, 0.8125rem);
101
+ color: var(--hi-color-text-primary, #333);
102
+ }
@@ -0,0 +1,85 @@
1
+ import { defineComponent, ref, type PropType } from "vue";
2
+ import { Check } from "lucide-vue-next";
3
+ import "./HkCheckbox.scss";
4
+
5
+ export default defineComponent({
6
+ name: "HkCheckbox",
7
+ props: {
8
+ modelValue: { type: Boolean, default: false },
9
+ label: { type: String, default: undefined },
10
+ disabled: { type: Boolean, default: false },
11
+ type: {
12
+ type: String as PropType<"checkbox" | "radio">,
13
+ default: "checkbox",
14
+ },
15
+ size: {
16
+ type: String as PropType<"sm" | "md" | "lg">,
17
+ default: "md",
18
+ },
19
+ },
20
+ emits: {
21
+ "update:modelValue": (_value: boolean) => true,
22
+ },
23
+ setup(props, { emit, slots }) {
24
+ const animating = ref(false);
25
+ let animTimer: ReturnType<typeof setTimeout> | null = null;
26
+
27
+ function markActive() {
28
+ animating.value = true;
29
+ if (animTimer) clearTimeout(animTimer);
30
+ animTimer = setTimeout(() => {
31
+ animating.value = false;
32
+ }, 300);
33
+ }
34
+
35
+ function onChange(e: Event) {
36
+ if (props.disabled) return;
37
+ emit("update:modelValue", (e.target as HTMLInputElement).checked);
38
+ markActive();
39
+ }
40
+
41
+ return () => {
42
+ const inputType = props.type === "radio" ? "radio" : "checkbox";
43
+ const isChecked = props.modelValue === true || props.modelValue === null;
44
+
45
+ return (
46
+ <label
47
+ class={[
48
+ "hk-checkbox",
49
+ `hk-checkbox-${props.size}`,
50
+ ]}
51
+ data-type={inputType}
52
+ data-disabled={props.disabled ? "" : undefined}
53
+ data-animating={animating.value ? "" : undefined}
54
+ >
55
+ <span
56
+ class="hk-checkbox-box"
57
+ data-checked={props.modelValue ? "" : undefined}
58
+ data-indeterminate={props.modelValue === null ? "" : undefined}
59
+ >
60
+ <input
61
+ class="hk-checkbox-input"
62
+ type={inputType}
63
+ checked={props.modelValue === true}
64
+ disabled={props.disabled}
65
+ onChange={onChange}
66
+ />
67
+ {props.modelValue === true
68
+ ? props.type === "radio"
69
+ ? <span class="hk-checkbox-dot" />
70
+ : <Check size={14} class="hk-checkbox-icon" />
71
+ : null}
72
+ {props.modelValue === null && props.type !== "radio" ? (
73
+ <span class="hk-checkbox-indeterminate" />
74
+ ) : null}
75
+ </span>
76
+ {props.label || slots.default ? (
77
+ <span class="hk-checkbox-label-text">
78
+ {slots.default?.() ?? props.label}
79
+ </span>
80
+ ) : null}
81
+ </label>
82
+ );
83
+ };
84
+ },
85
+ });
@@ -0,0 +1,48 @@
1
+ import { computed, defineComponent, ref, watch, type PropType } from "vue";
2
+ import "../../../components/src/styles/components/collapse.scss";
3
+
4
+ export default defineComponent({
5
+ name: "HkCollapse",
6
+ props: {
7
+ title: { type: String },
8
+ open: { type: Boolean, default: false },
9
+ },
10
+ emits: {
11
+ "update:open": (_value: boolean) => true,
12
+ },
13
+ setup(props, { emit, slots }) {
14
+ const isOpen = ref(props.open ?? false);
15
+
16
+ watch(() => props.open, (val) => {
17
+ if (val != null) isOpen.value = val;
18
+ });
19
+
20
+ function toggle() {
21
+ isOpen.value = !isOpen.value;
22
+ emit("update:open", isOpen.value);
23
+ }
24
+
25
+ const contentCls = computed(() => [
26
+ "hk-collapse-content",
27
+ isOpen.value ? "hk-collapse-expanded" : "",
28
+ ]);
29
+
30
+ return () => (
31
+ <div class="hk-collapse">
32
+ <div class="hk-collapse-header" onClick={toggle}>
33
+ <span class="hk-collapse-arrow" style={{ transform: isOpen.value ? "rotate(90deg)" : "rotate(0deg)" }}>
34
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
35
+ <polyline points="9 18 15 12 9 6" />
36
+ </svg>
37
+ </span>
38
+ <div class="hk-collapse-header-content">
39
+ {slots.title ? slots.title() : props.title ? <span>{props.title}</span> : null}
40
+ </div>
41
+ </div>
42
+ <div class={contentCls.value}>
43
+ {slots.default?.()}
44
+ </div>
45
+ </div>
46
+ );
47
+ },
48
+ });
@@ -0,0 +1,148 @@
1
+ .hk-color-picker {
2
+ display: inline-flex;
3
+ }
4
+
5
+ .hk-color-picker-trigger {
6
+ outline: none;
7
+ }
8
+
9
+ .hk-color-picker-swatch-btn {
10
+ display: inline-flex;
11
+ flex-direction: column;
12
+ align-items: center;
13
+ gap: 4px;
14
+ padding: 4px 6px;
15
+ border: none;
16
+ border-radius: var(--radius-sm);
17
+ background: none;
18
+ cursor: pointer;
19
+ outline: none;
20
+ }
21
+
22
+ .hk-color-picker-swatch {
23
+ width: 24px;
24
+ height: 24px;
25
+ flex-shrink: 0;
26
+ border-radius: calc(var(--radius-xs) - 1px);
27
+ border: 2px solid rgb(0 0 0 / 10%);
28
+ transition: border-color var(--duration-short);
29
+
30
+ .hk-color-picker-swatch-btn:hover & {
31
+ border-color: rgb(var(--color-primary));
32
+ }
33
+ }
34
+
35
+ .hk-color-picker-label {
36
+ font-size: var(--text-xs);
37
+ font-weight: 500;
38
+ color: rgb(var(--color-muted));
39
+ white-space: nowrap;
40
+ line-height: 1;
41
+ transition: color var(--duration-short);
42
+
43
+ .hk-color-picker-swatch-btn:hover & {
44
+ color: rgb(var(--color-primary));
45
+ }
46
+ }
47
+
48
+ .hk-color-picker-panel {
49
+ padding: var(--space-12);
50
+ background: rgb(var(--color-surface));
51
+ backdrop-filter: blur(var(--blur-lg));
52
+ border: 1px solid var(--border-subtle);
53
+ border-radius: var(--radius-md);
54
+ box-shadow: var(--shadow-modal);
55
+ outline: none;
56
+ }
57
+
58
+ .hk-color-picker-body {
59
+ display: flex;
60
+ }
61
+
62
+ .hk-color-picker-controls {
63
+ display: flex;
64
+ flex-direction: column;
65
+ gap: var(--space-8);
66
+ min-width: 200px;
67
+ }
68
+
69
+ .hk-color-picker-sliders {
70
+ display: flex;
71
+ flex-direction: column;
72
+ gap: var(--space-6);
73
+ }
74
+
75
+ .hk-color-picker-slider-row {
76
+ display: flex;
77
+ align-items: center;
78
+ gap: 6px;
79
+ }
80
+
81
+ .hk-color-picker-slider-label {
82
+ font-size: var(--text-2xs);
83
+ font-weight: 700;
84
+ color: rgb(var(--color-muted));
85
+ width: 10px;
86
+ text-align: center;
87
+ flex-shrink: 0;
88
+ }
89
+
90
+ .hk-color-picker-channel-slider {
91
+ position: relative;
92
+ display: flex;
93
+ align-items: center;
94
+ flex: 1;
95
+ height: 14px;
96
+ touch-action: none;
97
+ user-select: none;
98
+ }
99
+
100
+ .hk-color-picker-slider-track {
101
+ position: relative;
102
+ flex: 1;
103
+ min-width: 60px;
104
+ height: 10px;
105
+ border-radius: var(--radius-full);
106
+ display: block;
107
+ overflow: hidden;
108
+ box-shadow: inset 0 0 0 1px rgb(0 0 0 / 10%);
109
+ }
110
+
111
+ .hk-color-picker-slider-thumb {
112
+ display: block;
113
+ width: 14px;
114
+ height: 14px;
115
+ border-radius: 50%;
116
+ background: white;
117
+ border: 2px solid rgb(255 255 255 / 80%);
118
+ box-shadow: 0 0 0 1px rgb(0 0 0 / 15%), 0 1px 2px rgb(0 0 0 / 20%);
119
+ cursor: grab;
120
+ outline: none;
121
+ transition: transform 0.1s;
122
+
123
+ &:hover { transform: scale(1.15); }
124
+ &:active { cursor: grabbing; }
125
+ }
126
+
127
+ .hk-color-picker-slider-value {
128
+ font-size: var(--text-2xs);
129
+ font-weight: 500;
130
+ color: rgb(var(--color-muted));
131
+ width: 26px;
132
+ text-align: right;
133
+ flex-shrink: 0;
134
+ font-variant-numeric: tabular-nums;
135
+ }
136
+
137
+ .hk-color-picker-hex-row {
138
+ width: 100%;
139
+ }
140
+
141
+ .hk-color-picker-hex-hash {
142
+ font-size: var(--text-xs);
143
+ font-weight: 600;
144
+ color: rgb(var(--color-muted));
145
+ user-select: none;
146
+ pointer-events: none;
147
+ line-height: 1;
148
+ }
@@ -0,0 +1,204 @@
1
+ import { computed, defineComponent, ref } from "vue";
2
+
3
+ import HInput from "./HkInput";
4
+ import HPopover from "./HkPopover";
5
+ import "./HkColorPicker.scss";
6
+
7
+ const CHANNELS = [
8
+ { key: "r", label: "R" },
9
+ { key: "g", label: "G" },
10
+ { key: "b", label: "B" },
11
+ ] as const;
12
+
13
+ type Channel = "r" | "g" | "b";
14
+
15
+ function clamp(v: number, min = 0, max = 255): number {
16
+ return Math.max(min, Math.min(max, v));
17
+ }
18
+
19
+ function rgbToHex(r: number, g: number, b: number): string {
20
+ return (
21
+ "#" +
22
+ [r, g, b]
23
+ .map((v) => clamp(v).toString(16).padStart(2, "0"))
24
+ .join("")
25
+ );
26
+ }
27
+
28
+ function channelGradient(r: number, g: number, b: number, ch: Channel): string {
29
+ const from: Record<Channel, string> = {
30
+ r: rgbToHex(0, g, b),
31
+ g: rgbToHex(r, 0, b),
32
+ b: rgbToHex(r, g, 0),
33
+ };
34
+ const to: Record<Channel, string> = {
35
+ r: rgbToHex(255, g, b),
36
+ g: rgbToHex(r, 255, b),
37
+ b: rgbToHex(r, g, 255),
38
+ };
39
+ return `linear-gradient(to right, ${from[ch]}, ${to[ch]})`;
40
+ }
41
+
42
+ const ColorSlider = defineComponent({
43
+ name: "HkColorSlider",
44
+ props: {
45
+ value: { type: Number, required: true },
46
+ r: { type: Number, required: true },
47
+ g: { type: Number, required: true },
48
+ b: { type: Number, required: true },
49
+ channel: { type: String as () => Channel, required: true },
50
+ },
51
+ emits: {
52
+ change: (_value: number) => true,
53
+ },
54
+ setup(props, { emit }) {
55
+ const trackRef = ref<HTMLElement>();
56
+ let dragging = false;
57
+
58
+ function getValueFromX(clientX: number): number {
59
+ const el = trackRef.value;
60
+ if (!el) return props.value;
61
+ const rect = el.getBoundingClientRect();
62
+ const pct = clamp((clientX - rect.left) / rect.width, 0, 1);
63
+ return Math.round(pct * 255);
64
+ }
65
+
66
+ function onPointerDown(e: PointerEvent) {
67
+ dragging = true;
68
+ (e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);
69
+ emit("change", getValueFromX(e.clientX));
70
+ }
71
+
72
+ function onPointerMove(e: PointerEvent) {
73
+ if (!dragging) return;
74
+ emit("change", getValueFromX(e.clientX));
75
+ }
76
+
77
+ function onPointerUp() {
78
+ dragging = false;
79
+ }
80
+
81
+ const pct = computed(() => (props.value / 255) * 100);
82
+
83
+ return () => (
84
+ <div
85
+ class="hk-color-picker-channel-slider"
86
+ onPointerdown={onPointerDown}
87
+ onPointermove={onPointerMove}
88
+ onPointerup={onPointerUp}
89
+ >
90
+ <div
91
+ ref={trackRef}
92
+ class="hk-color-picker-slider-track"
93
+ style={{ background: channelGradient(props.r, props.g, props.b, props.channel) }}
94
+ />
95
+ <div
96
+ class="hk-color-picker-slider-thumb"
97
+ style={{ left: `${pct.value}%` }}
98
+ />
99
+ </div>
100
+ );
101
+ },
102
+ });
103
+
104
+ export default defineComponent({
105
+ name: "HkColorPicker",
106
+ props: {
107
+ r: { type: Number, required: true },
108
+ g: { type: Number, required: true },
109
+ b: { type: Number, required: true },
110
+ label: { type: String, default: "" },
111
+ },
112
+ emits: {
113
+ change: (_rgb: { r: number; g: number; b: number }) => true,
114
+ },
115
+ setup(props, { emit }) {
116
+ const isOpen = ref(false);
117
+ const triggerRef = ref<HTMLElement>();
118
+
119
+ const hex = computed(() => rgbToHex(props.r, props.g, props.b));
120
+ const hexDisplay = computed(() => hex.value.replace(/^#/, ""));
121
+
122
+ function updateChannel(ch: Channel, value: number) {
123
+ const next = { r: props.r, g: props.g, b: props.b };
124
+ next[ch] = clamp(value);
125
+ emit("change", next);
126
+ }
127
+
128
+ function onHexInput(v: string) {
129
+ if (/^[0-9a-fA-F]{0,6}$/.test(v) && v.length === 6) {
130
+ emit("change", {
131
+ r: parseInt(v.slice(0, 2), 16),
132
+ g: parseInt(v.slice(2, 4), 16),
133
+ b: parseInt(v.slice(4, 6), 16),
134
+ });
135
+ }
136
+ }
137
+
138
+ return () => (
139
+ <div class="hk-color-picker">
140
+ <button
141
+ ref={triggerRef}
142
+ type="button"
143
+ class="hk-color-picker-swatch-btn"
144
+ onClick={() => { isOpen.value = !isOpen.value; }}
145
+ >
146
+ <div
147
+ class="hk-color-picker-swatch"
148
+ style={{ background: hex.value }}
149
+ />
150
+ {props.label && (
151
+ <span class="hk-color-picker-label">{props.label}</span>
152
+ )}
153
+ </button>
154
+ <HPopover
155
+ modelValue={isOpen.value}
156
+ onUpdate:modelValue={(v: boolean) => { isOpen.value = v; }}
157
+ anchorRef={triggerRef.value ?? null}
158
+ placement="bottom-start"
159
+ offset={6}
160
+ backdrop={false}
161
+ class="hk-color-picker-panel"
162
+ >
163
+ <div class="hk-color-picker-body">
164
+ <div class="hk-color-picker-controls">
165
+ <div class="hk-color-picker-sliders">
166
+ {CHANNELS.map((def) => (
167
+ <div key={def.key} class="hk-color-picker-slider-row">
168
+ <span class="hk-color-picker-slider-label">
169
+ {def.label}
170
+ </span>
171
+ <ColorSlider
172
+ value={props[def.key]}
173
+ r={props.r}
174
+ g={props.g}
175
+ b={props.b}
176
+ channel={def.key}
177
+ onChange={(v: number) => updateChannel(def.key, v)}
178
+ />
179
+ <span class="hk-color-picker-slider-value">
180
+ {props[def.key]}
181
+ </span>
182
+ </div>
183
+ ))}
184
+ </div>
185
+
186
+ <div class="hk-color-picker-hex-row">
187
+ <HInput
188
+ modelValue={hexDisplay.value}
189
+ onUpdate:modelValue={onHexInput}
190
+ >
191
+ {{
192
+ prefixIcon: () => (
193
+ <span class="hk-color-picker-hex-hash">#</span>
194
+ ),
195
+ }}
196
+ </HInput>
197
+ </div>
198
+ </div>
199
+ </div>
200
+ </HPopover>
201
+ </div>
202
+ );
203
+ },
204
+ });
@@ -0,0 +1,12 @@
1
+ .hk-confirm-dialog-message {
2
+ margin: 0 0 1.5rem;
3
+ color: color-mix(in srgb, var(--hi-color-text-secondary) 85%, transparent);
4
+ font-size: var(--hi-text-sm, 0.875rem);
5
+ line-height: 1.5;
6
+ }
7
+
8
+ .hk-confirm-dialog-actions {
9
+ display: flex;
10
+ gap: 0.75rem;
11
+ justify-content: flex-end;
12
+ }
@@ -0,0 +1,75 @@
1
+ import { defineComponent } from "vue";
2
+
3
+ import "./HkConfirmDialog.scss";
4
+ import HButton from "./HkButton";
5
+ import HModal from "./HkModal";
6
+ import { useI18n } from "../i18n/context";
7
+
8
+ export default defineComponent({
9
+ name: "HkConfirmDialog",
10
+ props: {
11
+ open: { type: Boolean, required: true },
12
+ title: { type: String, default: "" },
13
+ message: { type: String, default: "" },
14
+ confirmLabel: { type: String, default: "" },
15
+ confirmVariant: {
16
+ type: String as () => "primary" | "danger",
17
+ default: "danger",
18
+ },
19
+ cancelLabel: { type: String, default: "" },
20
+ loading: { type: Boolean, default: false },
21
+ },
22
+ emits: {
23
+ confirm: () => true,
24
+ cancel: () => true,
25
+ "update:open": (_value: boolean) => true,
26
+ },
27
+ setup(props, { emit }) {
28
+ const { t } = useI18n();
29
+
30
+ function onConfirm() {
31
+ emit("confirm");
32
+ emit("update:open", false);
33
+ }
34
+
35
+ function onCancel() {
36
+ emit("cancel");
37
+ emit("update:open", false);
38
+ }
39
+
40
+ return () => (
41
+ <HModal
42
+ modelValue={props.open}
43
+ title={props.title}
44
+ closable={!props.loading}
45
+ onUpdate:modelValue={(v: boolean) => emit("update:open", v)}
46
+ >
47
+ {{
48
+ default: () => (
49
+ <div class="hk-confirm-dialog">
50
+ <p class="hk-confirm-dialog-message">{props.message}</p>
51
+ <div class="hk-confirm-dialog-actions">
52
+ <HButton
53
+ variant="secondary"
54
+ size="sm"
55
+ disabled={props.loading}
56
+ onClick={onCancel}
57
+ >
58
+ {props.cancelLabel || t("hk.confirmDialog.cancel", "Cancel")}
59
+ </HButton>
60
+ <HButton
61
+ variant={props.confirmVariant}
62
+ size="sm"
63
+ loading={props.loading}
64
+ onClick={onConfirm}
65
+ >
66
+ {props.confirmLabel || t("hk.confirmDialog.confirm", "Confirm")}
67
+ </HButton>
68
+ </div>
69
+ </div>
70
+ ),
71
+ }}
72
+ </HModal>
73
+ );
74
+ },
75
+ });