@arclux/arc-ui 1.0.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.
- package/LICENSE +21 -0
- package/README.md +64 -0
- package/package.json +186 -0
- package/src/content/accordion-item.js +27 -0
- package/src/content/accordion.js +151 -0
- package/src/content/animated-number.js +160 -0
- package/src/content/aspect-ratio.js +78 -0
- package/src/content/avatar-group.js +101 -0
- package/src/content/avatar.js +92 -0
- package/src/content/badge.js +98 -0
- package/src/content/callout.js +141 -0
- package/src/content/card.js +75 -0
- package/src/content/carousel.js +300 -0
- package/src/content/code-block.js +152 -0
- package/src/content/collapsible.js +142 -0
- package/src/content/color-swatch.js +86 -0
- package/src/content/column.js +28 -0
- package/src/content/data-table.js +332 -0
- package/src/content/divider.js +153 -0
- package/src/content/empty-state.js +78 -0
- package/src/content/feature-card.js +142 -0
- package/src/content/highlight.js +63 -0
- package/src/content/icon-library.js +30 -0
- package/src/content/icon-registry.js +39 -0
- package/src/content/icon.js +95 -0
- package/src/content/index.js +44 -0
- package/src/content/infinite-scroll.js +144 -0
- package/src/content/kbd.js +40 -0
- package/src/content/markdown.js +294 -0
- package/src/content/marquee.js +166 -0
- package/src/content/meter.js +167 -0
- package/src/content/scroll-area.js +107 -0
- package/src/content/skeleton.js +85 -0
- package/src/content/spinner.js +77 -0
- package/src/content/stack.js +68 -0
- package/src/content/stat.js +72 -0
- package/src/content/step.js +22 -0
- package/src/content/stepper.js +202 -0
- package/src/content/table.js +134 -0
- package/src/content/tag.js +156 -0
- package/src/content/text.js +111 -0
- package/src/content/timeline-item.js +29 -0
- package/src/content/timeline.js +170 -0
- package/src/content/truncate.js +161 -0
- package/src/content/value-card.js +94 -0
- package/src/feedback/alert.js +187 -0
- package/src/feedback/command-item.js +28 -0
- package/src/feedback/command-palette.js +346 -0
- package/src/feedback/context-menu.js +299 -0
- package/src/feedback/dialog.js +298 -0
- package/src/feedback/dropdown-menu.js +259 -0
- package/src/feedback/hover-card.js +186 -0
- package/src/feedback/index.js +17 -0
- package/src/feedback/modal.js +226 -0
- package/src/feedback/notification-panel.js +196 -0
- package/src/feedback/popover.js +184 -0
- package/src/feedback/progress.js +169 -0
- package/src/feedback/sheet.js +249 -0
- package/src/feedback/toast.js +207 -0
- package/src/feedback/tooltip.js +189 -0
- package/src/icons/lucide.d.ts +1915 -0
- package/src/icons/lucide.js +1915 -0
- package/src/icons/phosphor.d.ts +1517 -0
- package/src/icons/phosphor.js +1517 -0
- package/src/icons/types.d.ts +8 -0
- package/src/index.js +9 -0
- package/src/input/button.js +127 -0
- package/src/input/calendar.js +340 -0
- package/src/input/checkbox.js +159 -0
- package/src/input/chip.js +120 -0
- package/src/input/color-picker.js +461 -0
- package/src/input/combobox.js +295 -0
- package/src/input/copy-button.js +144 -0
- package/src/input/date-picker.js +534 -0
- package/src/input/file-upload.js +333 -0
- package/src/input/form.js +179 -0
- package/src/input/icon-button.js +179 -0
- package/src/input/index.js +31 -0
- package/src/input/input.js +158 -0
- package/src/input/multi-select.js +392 -0
- package/src/input/number-input.js +239 -0
- package/src/input/otp-input.js +221 -0
- package/src/input/pin-input.js +294 -0
- package/src/input/radio-group.js +177 -0
- package/src/input/radio.js +28 -0
- package/src/input/rating.js +195 -0
- package/src/input/search.js +371 -0
- package/src/input/segmented-control.js +174 -0
- package/src/input/select.js +267 -0
- package/src/input/slider.js +217 -0
- package/src/input/sortable-list.js +345 -0
- package/src/input/suggestion.js +26 -0
- package/src/input/textarea.js +203 -0
- package/src/input/theme-toggle.js +196 -0
- package/src/input/toggle.js +166 -0
- package/src/layout/app-shell.js +266 -0
- package/src/layout/auth-shell.js +153 -0
- package/src/layout/container.js +37 -0
- package/src/layout/dashboard-grid.js +62 -0
- package/src/layout/index.js +15 -0
- package/src/layout/page-header.js +100 -0
- package/src/layout/page-layout.js +112 -0
- package/src/layout/resizable.js +221 -0
- package/src/layout/section.js +54 -0
- package/src/layout/settings-layout.js +91 -0
- package/src/layout/split-pane.js +172 -0
- package/src/layout/status-bar.js +84 -0
- package/src/layout/toolbar.js +92 -0
- package/src/navigation/breadcrumb-item.js +26 -0
- package/src/navigation/breadcrumb.js +129 -0
- package/src/navigation/drawer.js +183 -0
- package/src/navigation/footer.js +99 -0
- package/src/navigation/index.js +22 -0
- package/src/navigation/link.js +120 -0
- package/src/navigation/nav-item.js +46 -0
- package/src/navigation/navigation-menu.js +687 -0
- package/src/navigation/pagination.js +186 -0
- package/src/navigation/scroll-spy.js +198 -0
- package/src/navigation/scroll-to-top.js +163 -0
- package/src/navigation/sidebar-link.js +28 -0
- package/src/navigation/sidebar-section.js +45 -0
- package/src/navigation/sidebar.js +336 -0
- package/src/navigation/spy-link.js +26 -0
- package/src/navigation/tab.js +26 -0
- package/src/navigation/tabs.js +202 -0
- package/src/navigation/top-bar.js +263 -0
- package/src/navigation/tree-item.js +38 -0
- package/src/navigation/tree-view.js +255 -0
- package/src/shared/index.js +6 -0
- package/src/shared/menu-divider.js +9 -0
- package/src/shared/menu-item.js +30 -0
- package/src/shared/option.js +31 -0
- package/src/shared-styles.js +81 -0
- package/src/tokens.js +445 -0
- package/types/index.d.ts +973 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { LitElement, html, css } from 'lit';
|
|
2
|
+
import { tokenStyles } from '../shared-styles.js';
|
|
3
|
+
|
|
4
|
+
export class ArcChip extends LitElement {
|
|
5
|
+
static properties = {
|
|
6
|
+
selected: { type: Boolean, reflect: true },
|
|
7
|
+
disabled: { type: Boolean, reflect: true },
|
|
8
|
+
value: { type: String },
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
static styles = [
|
|
12
|
+
tokenStyles,
|
|
13
|
+
css`
|
|
14
|
+
:host { display: inline-flex; }
|
|
15
|
+
:host([disabled]) { pointer-events: none; opacity: 0.4; }
|
|
16
|
+
|
|
17
|
+
.chip {
|
|
18
|
+
display: inline-flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
gap: var(--space-xs);
|
|
21
|
+
font-family: var(--font-accent);
|
|
22
|
+
font-weight: 600;
|
|
23
|
+
font-size: var(--text-xs);
|
|
24
|
+
letter-spacing: 2px;
|
|
25
|
+
text-transform: uppercase;
|
|
26
|
+
color: var(--text-muted);
|
|
27
|
+
padding: calc(var(--space-xs) + 2px) var(--space-md);
|
|
28
|
+
border: 1px solid var(--border-default);
|
|
29
|
+
border-radius: var(--radius-full);
|
|
30
|
+
background: var(--bg-hover);
|
|
31
|
+
cursor: pointer;
|
|
32
|
+
user-select: none;
|
|
33
|
+
transition:
|
|
34
|
+
background var(--transition-base),
|
|
35
|
+
border-color var(--transition-base),
|
|
36
|
+
color var(--transition-base),
|
|
37
|
+
box-shadow var(--transition-base);
|
|
38
|
+
line-height: 1.4;
|
|
39
|
+
outline: none;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.chip:hover {
|
|
43
|
+
border-color: var(--border-bright);
|
|
44
|
+
background: var(--bg-elevated);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
:host([selected]) .chip {
|
|
48
|
+
border-color: var(--accent-primary);
|
|
49
|
+
color: var(--accent-primary);
|
|
50
|
+
background: var(--accent-primary-subtle);
|
|
51
|
+
box-shadow: 0 0 12px rgba(var(--accent-primary-rgb), 0.15);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
:host([selected]) .chip:hover {
|
|
55
|
+
box-shadow: 0 0 16px rgba(var(--accent-primary-rgb), 0.25);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.chip:focus-visible {
|
|
59
|
+
box-shadow: var(--focus-glow);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
:host([selected]) .chip:focus-visible {
|
|
63
|
+
box-shadow: var(--focus-glow), 0 0 12px rgba(var(--accent-primary-rgb), 0.15);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@media (prefers-reduced-motion: reduce) {
|
|
67
|
+
:host *,
|
|
68
|
+
:host *::before,
|
|
69
|
+
:host *::after {
|
|
70
|
+
animation-duration: 0.01ms !important;
|
|
71
|
+
animation-iteration-count: 1 !important;
|
|
72
|
+
transition-duration: 0.01ms !important;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
`,
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
constructor() {
|
|
79
|
+
super();
|
|
80
|
+
this.selected = false;
|
|
81
|
+
this.disabled = false;
|
|
82
|
+
this.value = '';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
_toggle() {
|
|
86
|
+
if (this.disabled) return;
|
|
87
|
+
this.selected = !this.selected;
|
|
88
|
+
this.dispatchEvent(new CustomEvent('arc-change', {
|
|
89
|
+
detail: { value: this.value, selected: this.selected },
|
|
90
|
+
bubbles: true,
|
|
91
|
+
composed: true,
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
_handleKeydown(e) {
|
|
96
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
this._toggle();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
render() {
|
|
103
|
+
return html`
|
|
104
|
+
<span
|
|
105
|
+
class="chip"
|
|
106
|
+
role="option"
|
|
107
|
+
aria-selected=${this.selected ? 'true' : 'false'}
|
|
108
|
+
aria-disabled=${this.disabled ? 'true' : 'false'}
|
|
109
|
+
tabindex=${this.disabled ? '-1' : '0'}
|
|
110
|
+
@click=${this._toggle}
|
|
111
|
+
@keydown=${this._handleKeydown}
|
|
112
|
+
part="chip"
|
|
113
|
+
>
|
|
114
|
+
<slot></slot>
|
|
115
|
+
</span>
|
|
116
|
+
`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
customElements.define('arc-chip', ArcChip);
|
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import { LitElement, html, css } from 'lit';
|
|
2
|
+
import { tokenStyles } from '../shared-styles.js';
|
|
3
|
+
|
|
4
|
+
export class ArcColorPicker extends LitElement {
|
|
5
|
+
static properties = {
|
|
6
|
+
value: { type: String, reflect: true },
|
|
7
|
+
presets: { type: Array },
|
|
8
|
+
disabled: { type: Boolean, reflect: true },
|
|
9
|
+
label: { type: String },
|
|
10
|
+
_hue: { state: true },
|
|
11
|
+
_sat: { state: true },
|
|
12
|
+
_lit: { state: true },
|
|
13
|
+
_hexInput: { state: true },
|
|
14
|
+
_draggingArea: { state: true },
|
|
15
|
+
_draggingHue: { state: true },
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
static styles = [
|
|
19
|
+
tokenStyles,
|
|
20
|
+
css`
|
|
21
|
+
:host { display: block; }
|
|
22
|
+
:host([disabled]) { pointer-events: none; opacity: 0.4; }
|
|
23
|
+
|
|
24
|
+
.picker {
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-direction: column;
|
|
27
|
+
gap: var(--space-sm);
|
|
28
|
+
padding: var(--space-md);
|
|
29
|
+
background: var(--bg-card);
|
|
30
|
+
border: 1px solid var(--border-default);
|
|
31
|
+
border-radius: var(--radius-md);
|
|
32
|
+
width: 260px;
|
|
33
|
+
box-sizing: border-box;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.picker__label {
|
|
37
|
+
font-family: var(--font-accent);
|
|
38
|
+
font-weight: 600;
|
|
39
|
+
font-size: var(--label-inline-size);
|
|
40
|
+
letter-spacing: var(--label-inline-spacing);
|
|
41
|
+
text-transform: uppercase;
|
|
42
|
+
color: var(--text-muted);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.picker__area {
|
|
46
|
+
position: relative;
|
|
47
|
+
width: 100%;
|
|
48
|
+
height: 160px;
|
|
49
|
+
border-radius: var(--radius-sm);
|
|
50
|
+
cursor: crosshair;
|
|
51
|
+
overflow: hidden;
|
|
52
|
+
touch-action: none;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.picker__area-gradient {
|
|
56
|
+
position: absolute;
|
|
57
|
+
inset: 0;
|
|
58
|
+
border-radius: var(--radius-sm);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.picker__crosshair {
|
|
62
|
+
position: absolute;
|
|
63
|
+
width: 14px;
|
|
64
|
+
height: 14px;
|
|
65
|
+
border-radius: var(--radius-full);
|
|
66
|
+
border: 2px solid var(--picker-thumb-color, #fff);
|
|
67
|
+
box-shadow: 0 0 2px rgba(0, 0, 0, 0.6), inset 0 0 2px rgba(0, 0, 0, 0.3);
|
|
68
|
+
transform: translate(-50%, -50%);
|
|
69
|
+
pointer-events: none;
|
|
70
|
+
z-index: 2;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.picker__hue-track {
|
|
74
|
+
position: relative;
|
|
75
|
+
width: 100%;
|
|
76
|
+
height: 14px;
|
|
77
|
+
border-radius: var(--radius-full);
|
|
78
|
+
background: linear-gradient(
|
|
79
|
+
to right,
|
|
80
|
+
hsl(0, 100%, 50%),
|
|
81
|
+
hsl(60, 100%, 50%),
|
|
82
|
+
hsl(120, 100%, 50%),
|
|
83
|
+
hsl(180, 100%, 50%),
|
|
84
|
+
hsl(240, 100%, 50%),
|
|
85
|
+
hsl(300, 100%, 50%),
|
|
86
|
+
hsl(360, 100%, 50%)
|
|
87
|
+
);
|
|
88
|
+
cursor: pointer;
|
|
89
|
+
touch-action: none;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.picker__hue-thumb {
|
|
93
|
+
position: absolute;
|
|
94
|
+
top: 50%;
|
|
95
|
+
width: 18px;
|
|
96
|
+
height: 18px;
|
|
97
|
+
border-radius: var(--radius-full);
|
|
98
|
+
border: 2px solid var(--picker-thumb-color, #fff);
|
|
99
|
+
box-shadow: 0 0 3px rgba(0, 0, 0, 0.4);
|
|
100
|
+
transform: translate(-50%, -50%);
|
|
101
|
+
pointer-events: none;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.picker__hex-row {
|
|
105
|
+
display: flex;
|
|
106
|
+
align-items: center;
|
|
107
|
+
gap: var(--space-sm);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.picker__preview {
|
|
111
|
+
width: 32px;
|
|
112
|
+
height: 32px;
|
|
113
|
+
border-radius: var(--radius-sm);
|
|
114
|
+
border: 1px solid var(--border-default);
|
|
115
|
+
flex-shrink: 0;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.picker__hex-input {
|
|
119
|
+
flex: 1;
|
|
120
|
+
font-family: var(--font-mono);
|
|
121
|
+
font-size: var(--code-size);
|
|
122
|
+
color: var(--text-primary);
|
|
123
|
+
background: var(--bg-surface);
|
|
124
|
+
border: 1px solid var(--border-default);
|
|
125
|
+
border-radius: var(--radius-sm);
|
|
126
|
+
padding: var(--space-xs) var(--space-sm);
|
|
127
|
+
transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
|
|
128
|
+
box-sizing: border-box;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.picker__hex-input:focus {
|
|
132
|
+
outline: none;
|
|
133
|
+
border-color: var(--accent-primary);
|
|
134
|
+
box-shadow: var(--focus-glow);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.picker__presets {
|
|
138
|
+
display: flex;
|
|
139
|
+
flex-wrap: wrap;
|
|
140
|
+
gap: var(--space-xs);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.picker__swatch {
|
|
144
|
+
width: 22px;
|
|
145
|
+
height: 22px;
|
|
146
|
+
border-radius: var(--radius-sm);
|
|
147
|
+
border: 2px solid transparent;
|
|
148
|
+
cursor: pointer;
|
|
149
|
+
transition: border-color var(--transition-fast), transform var(--transition-fast);
|
|
150
|
+
padding: 0;
|
|
151
|
+
box-sizing: border-box;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.picker__swatch:hover {
|
|
155
|
+
transform: scale(1.15);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.picker__swatch:focus-visible {
|
|
159
|
+
outline: none;
|
|
160
|
+
box-shadow: var(--focus-glow);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.picker__swatch--active {
|
|
164
|
+
border-color: var(--text-primary);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
@media (prefers-reduced-motion: reduce) {
|
|
168
|
+
:host *,
|
|
169
|
+
:host *::before,
|
|
170
|
+
:host *::after {
|
|
171
|
+
animation-duration: 0.01ms !important;
|
|
172
|
+
animation-iteration-count: 1 !important;
|
|
173
|
+
transition-duration: 0.01ms !important;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
`,
|
|
177
|
+
];
|
|
178
|
+
|
|
179
|
+
constructor() {
|
|
180
|
+
super();
|
|
181
|
+
this.value = '#4d7ef7';
|
|
182
|
+
this.presets = [];
|
|
183
|
+
this.disabled = false;
|
|
184
|
+
this.label = '';
|
|
185
|
+
this._hue = 225;
|
|
186
|
+
this._sat = 92;
|
|
187
|
+
this._lit = 64;
|
|
188
|
+
this._hexInput = '#4d7ef7';
|
|
189
|
+
this._draggingArea = false;
|
|
190
|
+
this._draggingHue = false;
|
|
191
|
+
this._areaEl = null;
|
|
192
|
+
this._hueTrackEl = null;
|
|
193
|
+
this._onPointerMoveBound = this._onPointerMove.bind(this);
|
|
194
|
+
this._onPointerUpBound = this._onPointerUp.bind(this);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
connectedCallback() {
|
|
198
|
+
super.connectedCallback();
|
|
199
|
+
this._parseHex(this.value);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
updated(changed) {
|
|
203
|
+
if (changed.has('value') && !this._draggingArea && !this._draggingHue) {
|
|
204
|
+
this._parseHex(this.value);
|
|
205
|
+
this._hexInput = this.value;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
disconnectedCallback() {
|
|
210
|
+
super.disconnectedCallback();
|
|
211
|
+
window.removeEventListener('pointermove', this._onPointerMoveBound);
|
|
212
|
+
window.removeEventListener('pointerup', this._onPointerUpBound);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/* ---- Color conversion ---- */
|
|
216
|
+
|
|
217
|
+
_parseHex(hex) {
|
|
218
|
+
if (!hex || !/^#[0-9a-f]{6}$/i.test(hex)) return;
|
|
219
|
+
const r = parseInt(hex.slice(1, 3), 16) / 255;
|
|
220
|
+
const g = parseInt(hex.slice(3, 5), 16) / 255;
|
|
221
|
+
const b = parseInt(hex.slice(5, 7), 16) / 255;
|
|
222
|
+
const max = Math.max(r, g, b);
|
|
223
|
+
const min = Math.min(r, g, b);
|
|
224
|
+
const d = max - min;
|
|
225
|
+
let h = 0;
|
|
226
|
+
const l = (max + min) / 2;
|
|
227
|
+
const s = d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1));
|
|
228
|
+
if (d !== 0) {
|
|
229
|
+
if (max === r) h = ((g - b) / d + (g < b ? 6 : 0)) * 60;
|
|
230
|
+
else if (max === g) h = ((b - r) / d + 2) * 60;
|
|
231
|
+
else h = ((r - g) / d + 4) * 60;
|
|
232
|
+
}
|
|
233
|
+
this._hue = Math.round(h);
|
|
234
|
+
this._sat = Math.round(s * 100);
|
|
235
|
+
this._lit = Math.round(l * 100);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
_hslToHex(h, s, l) {
|
|
239
|
+
s /= 100;
|
|
240
|
+
l /= 100;
|
|
241
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
242
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
243
|
+
const m = l - c / 2;
|
|
244
|
+
let r = 0, g = 0, b = 0;
|
|
245
|
+
if (h < 60) { r = c; g = x; }
|
|
246
|
+
else if (h < 120) { r = x; g = c; }
|
|
247
|
+
else if (h < 180) { g = c; b = x; }
|
|
248
|
+
else if (h < 240) { g = x; b = c; }
|
|
249
|
+
else if (h < 300) { r = x; b = c; }
|
|
250
|
+
else { r = c; b = x; }
|
|
251
|
+
const toHex = (v) => Math.round((v + m) * 255).toString(16).padStart(2, '0');
|
|
252
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
_updateFromHSL() {
|
|
256
|
+
const hex = this._hslToHex(this._hue, this._sat, this._lit);
|
|
257
|
+
this.value = hex;
|
|
258
|
+
this._hexInput = hex;
|
|
259
|
+
this.dispatchEvent(new CustomEvent('arc-change', {
|
|
260
|
+
detail: { value: hex },
|
|
261
|
+
bubbles: true,
|
|
262
|
+
composed: true,
|
|
263
|
+
}));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/* ---- Area (saturation / lightness) interaction ---- */
|
|
267
|
+
|
|
268
|
+
_onAreaPointerDown(e) {
|
|
269
|
+
e.preventDefault();
|
|
270
|
+
this._draggingArea = true;
|
|
271
|
+
this._areaEl = this.shadowRoot.querySelector('.picker__area');
|
|
272
|
+
e.target.setPointerCapture(e.pointerId);
|
|
273
|
+
this._updateAreaFromPointer(e);
|
|
274
|
+
window.addEventListener('pointermove', this._onPointerMoveBound);
|
|
275
|
+
window.addEventListener('pointerup', this._onPointerUpBound);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
_updateAreaFromPointer(e) {
|
|
279
|
+
const area = this._areaEl;
|
|
280
|
+
if (!area) return;
|
|
281
|
+
const rect = area.getBoundingClientRect();
|
|
282
|
+
const x = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
|
|
283
|
+
const y = Math.max(0, Math.min(1, (e.clientY - rect.top) / rect.height));
|
|
284
|
+
// x = saturation (0..100), y inverted = lightness (100..0 mapped through hue)
|
|
285
|
+
// Using HSB-like mapping: saturation = x, lightness derived from both
|
|
286
|
+
this._sat = Math.round(x * 100);
|
|
287
|
+
this._lit = Math.round((1 - y) * 50 + (1 - x) * (1 - y) * 50);
|
|
288
|
+
// Simpler standard mapping: x = saturation, y = lightness (inverted)
|
|
289
|
+
this._sat = Math.round(x * 100);
|
|
290
|
+
this._lit = Math.round((1 - y) * 100);
|
|
291
|
+
this._updateFromHSL();
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/* ---- Hue slider interaction ---- */
|
|
295
|
+
|
|
296
|
+
_onHuePointerDown(e) {
|
|
297
|
+
e.preventDefault();
|
|
298
|
+
this._draggingHue = true;
|
|
299
|
+
this._hueTrackEl = this.shadowRoot.querySelector('.picker__hue-track');
|
|
300
|
+
e.target.setPointerCapture(e.pointerId);
|
|
301
|
+
this._updateHueFromPointer(e);
|
|
302
|
+
window.addEventListener('pointermove', this._onPointerMoveBound);
|
|
303
|
+
window.addEventListener('pointerup', this._onPointerUpBound);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
_updateHueFromPointer(e) {
|
|
307
|
+
const track = this._hueTrackEl;
|
|
308
|
+
if (!track) return;
|
|
309
|
+
const rect = track.getBoundingClientRect();
|
|
310
|
+
const x = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
|
|
311
|
+
this._hue = Math.round(x * 360);
|
|
312
|
+
this._updateFromHSL();
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/* ---- Shared pointer handlers ---- */
|
|
316
|
+
|
|
317
|
+
_onPointerMove(e) {
|
|
318
|
+
if (this._draggingArea) this._updateAreaFromPointer(e);
|
|
319
|
+
else if (this._draggingHue) this._updateHueFromPointer(e);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
_onPointerUp() {
|
|
323
|
+
this._draggingArea = false;
|
|
324
|
+
this._draggingHue = false;
|
|
325
|
+
this._areaEl = null;
|
|
326
|
+
this._hueTrackEl = null;
|
|
327
|
+
window.removeEventListener('pointermove', this._onPointerMoveBound);
|
|
328
|
+
window.removeEventListener('pointerup', this._onPointerUpBound);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/* ---- Hex input ---- */
|
|
332
|
+
|
|
333
|
+
_onHexInput(e) {
|
|
334
|
+
this._hexInput = e.target.value;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
_onHexBlur() {
|
|
338
|
+
let hex = this._hexInput.trim();
|
|
339
|
+
if (!hex.startsWith('#')) hex = '#' + hex;
|
|
340
|
+
if (/^#[0-9a-f]{6}$/i.test(hex)) {
|
|
341
|
+
hex = hex.toLowerCase();
|
|
342
|
+
this.value = hex;
|
|
343
|
+
this._hexInput = hex;
|
|
344
|
+
this._parseHex(hex);
|
|
345
|
+
this.dispatchEvent(new CustomEvent('arc-change', {
|
|
346
|
+
detail: { value: hex },
|
|
347
|
+
bubbles: true,
|
|
348
|
+
composed: true,
|
|
349
|
+
}));
|
|
350
|
+
} else {
|
|
351
|
+
this._hexInput = this.value;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
_onHexKeydown(e) {
|
|
356
|
+
if (e.key === 'Enter') {
|
|
357
|
+
e.target.blur();
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/* ---- Preset swatch ---- */
|
|
362
|
+
|
|
363
|
+
_selectPreset(hex) {
|
|
364
|
+
this.value = hex.toLowerCase();
|
|
365
|
+
this._hexInput = this.value;
|
|
366
|
+
this._parseHex(this.value);
|
|
367
|
+
this.dispatchEvent(new CustomEvent('arc-change', {
|
|
368
|
+
detail: { value: this.value },
|
|
369
|
+
bubbles: true,
|
|
370
|
+
composed: true,
|
|
371
|
+
}));
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/* ---- Render ---- */
|
|
375
|
+
|
|
376
|
+
get _areaBackground() {
|
|
377
|
+
return `linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, hsl(${this._hue}, 100%, 50%))`;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
get _crosshairX() {
|
|
381
|
+
return `${this._sat}%`;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
get _crosshairY() {
|
|
385
|
+
return `${100 - this._lit}%`;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
get _hueThumbLeft() {
|
|
389
|
+
return `${(this._hue / 360) * 100}%`;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
render() {
|
|
393
|
+
return html`
|
|
394
|
+
<div class="picker" part="picker">
|
|
395
|
+
${this.label ? html`<span class="picker__label" part="label">${this.label}</span>` : ''}
|
|
396
|
+
|
|
397
|
+
<div
|
|
398
|
+
class="picker__area"
|
|
399
|
+
@pointerdown=${this._onAreaPointerDown}
|
|
400
|
+
part="area"
|
|
401
|
+
>
|
|
402
|
+
<div
|
|
403
|
+
class="picker__area-gradient"
|
|
404
|
+
style="background: ${this._areaBackground}"
|
|
405
|
+
></div>
|
|
406
|
+
<div
|
|
407
|
+
class="picker__crosshair"
|
|
408
|
+
style="left: ${this._crosshairX}; top: ${this._crosshairY}; background: ${this.value}"
|
|
409
|
+
></div>
|
|
410
|
+
</div>
|
|
411
|
+
|
|
412
|
+
<div
|
|
413
|
+
class="picker__hue-track"
|
|
414
|
+
@pointerdown=${this._onHuePointerDown}
|
|
415
|
+
part="hue-track"
|
|
416
|
+
>
|
|
417
|
+
<div
|
|
418
|
+
class="picker__hue-thumb"
|
|
419
|
+
style="left: ${this._hueThumbLeft}; background: hsl(${this._hue}, 100%, 50%)"
|
|
420
|
+
></div>
|
|
421
|
+
</div>
|
|
422
|
+
|
|
423
|
+
<div class="picker__hex-row" part="hex-row">
|
|
424
|
+
<div
|
|
425
|
+
class="picker__preview"
|
|
426
|
+
style="background: ${this.value}"
|
|
427
|
+
part="preview"
|
|
428
|
+
></div>
|
|
429
|
+
<input
|
|
430
|
+
class="picker__hex-input"
|
|
431
|
+
type="text"
|
|
432
|
+
maxlength="7"
|
|
433
|
+
.value=${this._hexInput}
|
|
434
|
+
@input=${this._onHexInput}
|
|
435
|
+
@blur=${this._onHexBlur}
|
|
436
|
+
@keydown=${this._onHexKeydown}
|
|
437
|
+
aria-label="Hex color value"
|
|
438
|
+
part="hex-input"
|
|
439
|
+
/>
|
|
440
|
+
</div>
|
|
441
|
+
|
|
442
|
+
${this.presets && this.presets.length ? html`
|
|
443
|
+
<div class="picker__presets" part="presets" role="listbox" aria-label="Color presets">
|
|
444
|
+
${this.presets.map(c => html`
|
|
445
|
+
<button
|
|
446
|
+
class="picker__swatch ${c.toLowerCase() === this.value ? 'picker__swatch--active' : ''}"
|
|
447
|
+
style="background: ${c}"
|
|
448
|
+
role="option"
|
|
449
|
+
aria-selected=${c.toLowerCase() === this.value ? 'true' : 'false'}
|
|
450
|
+
aria-label=${c}
|
|
451
|
+
@click=${() => this._selectPreset(c)}
|
|
452
|
+
></button>
|
|
453
|
+
`)}
|
|
454
|
+
</div>
|
|
455
|
+
` : ''}
|
|
456
|
+
</div>
|
|
457
|
+
`;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
customElements.define('arc-color-picker', ArcColorPicker);
|