@dxos/lit-theme-editor 0.8.2-main.10c050d
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 +8 -0
- package/README.md +3 -0
- package/dist/src/dx-theme-editor/dx-range-spinbutton.d.ts +16 -0
- package/dist/src/dx-theme-editor/dx-range-spinbutton.d.ts.map +1 -0
- package/dist/src/dx-theme-editor/dx-range-spinbutton.js +127 -0
- package/dist/src/dx-theme-editor/dx-range-spinbutton.js.map +1 -0
- package/dist/src/dx-theme-editor/dx-theme-editor-alias-colors.d.ts +21 -0
- package/dist/src/dx-theme-editor/dx-theme-editor-alias-colors.d.ts.map +1 -0
- package/dist/src/dx-theme-editor/dx-theme-editor-alias-colors.js +267 -0
- package/dist/src/dx-theme-editor/dx-theme-editor-alias-colors.js.map +1 -0
- package/dist/src/dx-theme-editor/dx-theme-editor-physical-colors.d.ts +19 -0
- package/dist/src/dx-theme-editor/dx-theme-editor-physical-colors.d.ts.map +1 -0
- package/dist/src/dx-theme-editor/dx-theme-editor-physical-colors.js +163 -0
- package/dist/src/dx-theme-editor/dx-theme-editor-physical-colors.js.map +1 -0
- package/dist/src/dx-theme-editor/dx-theme-editor-semantic-colors.d.ts +32 -0
- package/dist/src/dx-theme-editor/dx-theme-editor-semantic-colors.d.ts.map +1 -0
- package/dist/src/dx-theme-editor/dx-theme-editor-semantic-colors.js +474 -0
- package/dist/src/dx-theme-editor/dx-theme-editor-semantic-colors.js.map +1 -0
- package/dist/src/dx-theme-editor/dx-theme-editor.d.ts +16 -0
- package/dist/src/dx-theme-editor/dx-theme-editor.d.ts.map +1 -0
- package/dist/src/dx-theme-editor/dx-theme-editor.js +160 -0
- package/dist/src/dx-theme-editor/dx-theme-editor.js.map +1 -0
- package/dist/src/dx-theme-editor/dx-theme-editor.lit-stories.d.ts +22 -0
- package/dist/src/dx-theme-editor/dx-theme-editor.lit-stories.d.ts.map +1 -0
- package/dist/src/dx-theme-editor/dx-theme-editor.lit-stories.js +27 -0
- package/dist/src/dx-theme-editor/dx-theme-editor.lit-stories.js.map +1 -0
- package/dist/src/dx-theme-editor/index.d.ts +5 -0
- package/dist/src/dx-theme-editor/index.d.ts.map +1 -0
- package/dist/src/dx-theme-editor/index.js +8 -0
- package/dist/src/dx-theme-editor/index.js.map +1 -0
- package/dist/src/dx-theme-editor/util.d.ts +8 -0
- package/dist/src/dx-theme-editor/util.d.ts.map +1 -0
- package/dist/src/dx-theme-editor/util.js +61 -0
- package/dist/src/dx-theme-editor/util.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +5 -0
- package/dist/src/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/src/dx-theme-editor/dx-range-spinbutton.d.ts +16 -0
- package/dist/types/src/dx-theme-editor/dx-range-spinbutton.d.ts.map +1 -0
- package/dist/types/src/dx-theme-editor/dx-range-spinbutton.js +127 -0
- package/dist/types/src/dx-theme-editor/dx-range-spinbutton.js.map +1 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor-alias-colors.d.ts +21 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor-alias-colors.d.ts.map +1 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor-alias-colors.js +267 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor-alias-colors.js.map +1 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor-physical-colors.d.ts +19 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor-physical-colors.d.ts.map +1 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor-physical-colors.js +163 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor-physical-colors.js.map +1 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor-semantic-colors.d.ts +32 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor-semantic-colors.d.ts.map +1 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor-semantic-colors.js +474 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor-semantic-colors.js.map +1 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor.d.ts +16 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor.d.ts.map +1 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor.js +160 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor.js.map +1 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor.lit-stories.d.ts +22 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor.lit-stories.d.ts.map +1 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor.lit-stories.js +27 -0
- package/dist/types/src/dx-theme-editor/dx-theme-editor.lit-stories.js.map +1 -0
- package/dist/types/src/dx-theme-editor/index.d.ts +5 -0
- package/dist/types/src/dx-theme-editor/index.d.ts.map +1 -0
- package/dist/types/src/dx-theme-editor/index.js +8 -0
- package/dist/types/src/dx-theme-editor/index.js.map +1 -0
- package/dist/types/src/dx-theme-editor/util.d.ts +8 -0
- package/dist/types/src/dx-theme-editor/util.d.ts.map +1 -0
- package/dist/types/src/dx-theme-editor/util.js +61 -0
- package/dist/types/src/dx-theme-editor/util.js.map +1 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/index.js +5 -0
- package/dist/types/src/index.js.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +40 -0
- package/src/dx-theme-editor/dx-range-spinbutton.ts +124 -0
- package/src/dx-theme-editor/dx-theme-editor-alias-colors.ts +305 -0
- package/src/dx-theme-editor/dx-theme-editor-physical-colors.ts +179 -0
- package/src/dx-theme-editor/dx-theme-editor-semantic-colors.ts +558 -0
- package/src/dx-theme-editor/dx-theme-editor.lit-stories.ts +37 -0
- package/src/dx-theme-editor/dx-theme-editor.pcss +299 -0
- package/src/dx-theme-editor/dx-theme-editor.ts +158 -0
- package/src/dx-theme-editor/index.ts +8 -0
- package/src/dx-theme-editor/util.ts +66 -0
- package/src/index.ts +5 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
dx-theme-editor,
|
|
2
|
+
dx-theme-editor-physical-colors,
|
|
3
|
+
dx-theme-editor-semantic-colors,
|
|
4
|
+
dx-theme-editor-alias-colors {
|
|
5
|
+
display: contents;
|
|
6
|
+
|
|
7
|
+
input {
|
|
8
|
+
accent-color: var(--dx-accentSurface);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
input:not([type="range"]), select, textarea {
|
|
12
|
+
border-radius: .125rem;
|
|
13
|
+
border: 1px solid var(--dx-separator);
|
|
14
|
+
background-color: var(--dx-baseSurface);
|
|
15
|
+
color: var(--dx-baseText);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.dx-button, input:not([type="range"]), select {
|
|
19
|
+
padding-block: .25rem;
|
|
20
|
+
min-block-size: 2rem;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.tabs-container {
|
|
24
|
+
display: flex;
|
|
25
|
+
gap: .25rem;
|
|
26
|
+
border-bottom: 1px solid var(--dx-separator);
|
|
27
|
+
padding-inline: 1rem;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.tab {
|
|
31
|
+
padding: 0.5rem 1rem;
|
|
32
|
+
border: none;
|
|
33
|
+
background: none;
|
|
34
|
+
cursor: pointer;
|
|
35
|
+
font-size: 1rem;
|
|
36
|
+
border-block: .25rem solid transparent;
|
|
37
|
+
margin-block-end: -1px;
|
|
38
|
+
|
|
39
|
+
&.active {
|
|
40
|
+
border-bottom-color: var(--dx-accentSurface);
|
|
41
|
+
font-weight: bold;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&:hover {
|
|
45
|
+
background-color: var(--dx-hoverSurface);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.tab-panel {
|
|
50
|
+
padding: 1rem;
|
|
51
|
+
|
|
52
|
+
&[hidden] {
|
|
53
|
+
display: none;
|
|
54
|
+
}
|
|
55
|
+
textarea {
|
|
56
|
+
inline-size: 100%;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.token-search {
|
|
61
|
+
inline-size: 100%;
|
|
62
|
+
padding: 0.5rem;
|
|
63
|
+
font-size: 1rem;
|
|
64
|
+
box-sizing: border-box;
|
|
65
|
+
margin-block-end: 1rem;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.series-container {
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.series-header {
|
|
72
|
+
display: flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
justify-content: space-between;
|
|
75
|
+
margin-bottom: 1rem;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.series-title {
|
|
79
|
+
margin: 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.series-controls {
|
|
83
|
+
margin-block-end: 1rem;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.series-preview {
|
|
87
|
+
block-size: 4rem;
|
|
88
|
+
border-radius: .25rem;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.shade-preview {
|
|
92
|
+
block-size: 2rem;
|
|
93
|
+
border-radius: .25rem;
|
|
94
|
+
background-color: #888;
|
|
95
|
+
background-image: linear-gradient(45deg, #777 25%, transparent 25%, transparent 75%, #777 75%, #777),
|
|
96
|
+
linear-gradient(45deg, #777 25%, transparent 25%, transparent 75%, #777 75%, #777);
|
|
97
|
+
background-size: 32px 32px;
|
|
98
|
+
background-position: 0 0, 16px 16px;
|
|
99
|
+
position: relative;
|
|
100
|
+
overflow: hidden;
|
|
101
|
+
|
|
102
|
+
& > .shade {
|
|
103
|
+
position: absolute;
|
|
104
|
+
inset: 0;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.control-inputs {
|
|
109
|
+
display: contents;
|
|
110
|
+
|
|
111
|
+
&.reverse-range {
|
|
112
|
+
.range-input {
|
|
113
|
+
direction: rtl;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
&.reverse-order {
|
|
118
|
+
flex-direction: row-reverse;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.control-group {
|
|
123
|
+
display: flex;
|
|
124
|
+
gap: 1rem;
|
|
125
|
+
|
|
126
|
+
.control-row, dx-range-spinbutton, .control-group-item {
|
|
127
|
+
display: block;
|
|
128
|
+
flex: 1 1 0;
|
|
129
|
+
margin-block: 0;
|
|
130
|
+
|
|
131
|
+
.control-inputs {
|
|
132
|
+
display: flex;
|
|
133
|
+
gap: .5rem;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.control-group-title {
|
|
139
|
+
margin-top: 0;
|
|
140
|
+
margin-bottom: 0.5rem;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.control-row, dx-range-spinbutton {
|
|
144
|
+
flex: 1 0 auto;
|
|
145
|
+
display: flex;
|
|
146
|
+
align-items: center;
|
|
147
|
+
margin-block: 0.5rem;
|
|
148
|
+
gap: 0.5rem;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.control-label {
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.range-input {
|
|
155
|
+
flex: 1;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.number-input {
|
|
159
|
+
width: 6rem;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.collapsible-token {
|
|
163
|
+
|
|
164
|
+
.static-token-name {
|
|
165
|
+
display: none;
|
|
166
|
+
border: 1px solid transparent;
|
|
167
|
+
padding: .25rem;
|
|
168
|
+
min-block-size: 2rem;
|
|
169
|
+
flex-grow: 1;
|
|
170
|
+
cursor: pointer;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.token-config-content {
|
|
174
|
+
padding-block-end: 1rem;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
&:not([data-state="expanded"]) {
|
|
178
|
+
.token-config-content {
|
|
179
|
+
display: none;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.remove-token-button, .token-name-input {
|
|
183
|
+
display: none;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.static-token-name {
|
|
187
|
+
display: block;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.toggle-button dx-icon svg {
|
|
191
|
+
transform: rotate(-90deg);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.token-controls {
|
|
197
|
+
padding: 0.5rem;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.token-header {
|
|
201
|
+
display: flex;
|
|
202
|
+
align-items: center;
|
|
203
|
+
gap: 1rem;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.token-title {
|
|
207
|
+
margin: 0;
|
|
208
|
+
display: flex;
|
|
209
|
+
align-items: center;
|
|
210
|
+
flex: 1 0 10rem;
|
|
211
|
+
gap: 0.5rem;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.token-name-input {
|
|
215
|
+
width: 100%;
|
|
216
|
+
min-width: min-content;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.add-token-button {
|
|
220
|
+
margin-block-start: 1rem;
|
|
221
|
+
inline-size: 100%;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.token-series-select {
|
|
225
|
+
display: flex;
|
|
226
|
+
align-items: center;
|
|
227
|
+
gap: 0.5rem;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.series-select {
|
|
231
|
+
flex: 1;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.alias-condition-select {
|
|
235
|
+
inline-size: 8rem;
|
|
236
|
+
place-self: stretch;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
.condition-and-validation {
|
|
240
|
+
display: flex;
|
|
241
|
+
gap: .5rem;
|
|
242
|
+
align-items: center;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.alias-validation {
|
|
246
|
+
display: contents;
|
|
247
|
+
color: var(--dx-errorText);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/* Alias Colors Component Styles */
|
|
251
|
+
|
|
252
|
+
.semantic-alias-token-section {
|
|
253
|
+
padding: 1rem;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.alias-token-list, .semantic-alias-token-list {
|
|
257
|
+
display: grid;
|
|
258
|
+
gap: .5rem;
|
|
259
|
+
margin-bottom: 1rem;
|
|
260
|
+
.alias-token-item, .alias-token-labels {
|
|
261
|
+
display: grid;
|
|
262
|
+
grid-template-columns: subgrid;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.alias-token-list {
|
|
267
|
+
grid-template-columns: 1fr min-content min-content min-content;
|
|
268
|
+
.alias-token-item, .alias-token-labels {
|
|
269
|
+
grid-column: span 4;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
.semantic-alias-token-list {
|
|
274
|
+
grid-template-columns: min-content 1fr min-content;
|
|
275
|
+
.alias-token-item, .alias-token-labels {
|
|
276
|
+
grid-column: span 3;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
.condition-selectors {
|
|
281
|
+
display: flex;
|
|
282
|
+
flex-direction: column;
|
|
283
|
+
gap: 0.5rem;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
.condition-selector {
|
|
287
|
+
display: flex;
|
|
288
|
+
flex-direction: column;
|
|
289
|
+
gap: 0.25rem;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.condition-selector label {
|
|
293
|
+
font-weight: bold;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
dx-autocomplete-combobox {
|
|
297
|
+
width: 100%;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type TokenSet } from '@ch-ui/tokens';
|
|
6
|
+
import { LitElement, html } from 'lit';
|
|
7
|
+
import { customElement, state } from 'lit/decorators.js';
|
|
8
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
9
|
+
|
|
10
|
+
import './dx-theme-editor-physical-colors';
|
|
11
|
+
import './dx-theme-editor-semantic-colors';
|
|
12
|
+
import './dx-theme-editor-alias-colors';
|
|
13
|
+
import { reset, restore, tokenSetUpdateEvent } from './util';
|
|
14
|
+
|
|
15
|
+
export type DxThemeEditorProps = {};
|
|
16
|
+
|
|
17
|
+
type Tab = 'physical' | 'semantic' | 'alias' | 'json' | 'reset';
|
|
18
|
+
|
|
19
|
+
@customElement('dx-theme-editor')
|
|
20
|
+
export class DxThemeEditor extends LitElement {
|
|
21
|
+
@state()
|
|
22
|
+
private activeTab: Tab = 'physical';
|
|
23
|
+
|
|
24
|
+
@state()
|
|
25
|
+
private currentTokenSet: TokenSet = restore();
|
|
26
|
+
|
|
27
|
+
private handleTabClick(tab: Tab): void {
|
|
28
|
+
this.activeTab = tab;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private handleTokenSetUpdate = () => {
|
|
32
|
+
this.currentTokenSet = restore();
|
|
33
|
+
this.requestUpdate();
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
override connectedCallback(): void {
|
|
37
|
+
super.connectedCallback();
|
|
38
|
+
window.addEventListener(tokenSetUpdateEvent, this.handleTokenSetUpdate);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
override disconnectedCallback(): void {
|
|
42
|
+
super.disconnectedCallback();
|
|
43
|
+
window.removeEventListener(tokenSetUpdateEvent, this.handleTokenSetUpdate);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
override render() {
|
|
47
|
+
return html`
|
|
48
|
+
<div class="theme-editor-container">
|
|
49
|
+
<div class="tabs-container" role="tablist">
|
|
50
|
+
<button
|
|
51
|
+
id="tab-physical"
|
|
52
|
+
class=${classMap({ 'dx-focus-ring': true, tab: true, active: this.activeTab === 'physical' })}
|
|
53
|
+
role="tab"
|
|
54
|
+
aria-selected=${this.activeTab === 'physical'}
|
|
55
|
+
aria-controls="panel-physical"
|
|
56
|
+
@click=${() => this.handleTabClick('physical')}
|
|
57
|
+
>
|
|
58
|
+
Physical
|
|
59
|
+
</button>
|
|
60
|
+
<button
|
|
61
|
+
id="tab-semantic"
|
|
62
|
+
class=${classMap({ 'dx-focus-ring': true, tab: true, active: this.activeTab === 'semantic' })}
|
|
63
|
+
role="tab"
|
|
64
|
+
aria-selected=${this.activeTab === 'semantic'}
|
|
65
|
+
aria-controls="panel-semantic"
|
|
66
|
+
@click=${() => this.handleTabClick('semantic')}
|
|
67
|
+
>
|
|
68
|
+
Semantic
|
|
69
|
+
</button>
|
|
70
|
+
<button
|
|
71
|
+
id="tab-alias"
|
|
72
|
+
class=${classMap({ 'dx-focus-ring': true, tab: true, active: this.activeTab === 'alias' })}
|
|
73
|
+
role="tab"
|
|
74
|
+
aria-selected=${this.activeTab === 'alias'}
|
|
75
|
+
aria-controls="panel-alias"
|
|
76
|
+
@click=${() => this.handleTabClick('alias')}
|
|
77
|
+
>
|
|
78
|
+
Alias
|
|
79
|
+
</button>
|
|
80
|
+
<button
|
|
81
|
+
id="tab-json"
|
|
82
|
+
class=${classMap({ 'dx-focus-ring': true, tab: true, active: this.activeTab === 'json' })}
|
|
83
|
+
role="tab"
|
|
84
|
+
aria-selected=${this.activeTab === 'json'}
|
|
85
|
+
aria-controls="panel-json"
|
|
86
|
+
@click=${() => this.handleTabClick('json')}
|
|
87
|
+
>
|
|
88
|
+
JSON
|
|
89
|
+
</button>
|
|
90
|
+
<button
|
|
91
|
+
id="tab-reset"
|
|
92
|
+
class=${classMap({ 'dx-focus-ring': true, tab: true, active: this.activeTab === 'reset' })}
|
|
93
|
+
role="tab"
|
|
94
|
+
aria-selected=${this.activeTab === 'reset'}
|
|
95
|
+
aria-controls="panel-reset"
|
|
96
|
+
@click=${() => this.handleTabClick('reset')}
|
|
97
|
+
>
|
|
98
|
+
Reset
|
|
99
|
+
</button>
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<div
|
|
103
|
+
id="panel-physical"
|
|
104
|
+
class=${classMap({ 'tab-panel': true, active: this.activeTab === 'physical' })}
|
|
105
|
+
role="tabpanel"
|
|
106
|
+
aria-labelledby="tab-physical"
|
|
107
|
+
?hidden=${this.activeTab !== 'physical'}
|
|
108
|
+
>
|
|
109
|
+
<dx-theme-editor-physical-colors></dx-theme-editor-physical-colors>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<div
|
|
113
|
+
id="panel-semantic"
|
|
114
|
+
class=${classMap({ 'tab-panel': true, active: this.activeTab === 'semantic' })}
|
|
115
|
+
role="tabpanel"
|
|
116
|
+
aria-labelledby="tab-semantic"
|
|
117
|
+
?hidden=${this.activeTab !== 'semantic'}
|
|
118
|
+
>
|
|
119
|
+
<dx-theme-editor-semantic-colors></dx-theme-editor-semantic-colors>
|
|
120
|
+
</div>
|
|
121
|
+
|
|
122
|
+
<div
|
|
123
|
+
id="panel-alias"
|
|
124
|
+
class=${classMap({ 'tab-panel': true, active: this.activeTab === 'alias' })}
|
|
125
|
+
role="tabpanel"
|
|
126
|
+
aria-labelledby="tab-alias"
|
|
127
|
+
?hidden=${this.activeTab !== 'alias'}
|
|
128
|
+
>
|
|
129
|
+
<dx-theme-editor-alias-colors></dx-theme-editor-alias-colors>
|
|
130
|
+
</div>
|
|
131
|
+
|
|
132
|
+
<div
|
|
133
|
+
id="panel-json"
|
|
134
|
+
class=${classMap({ 'tab-panel': true, active: this.activeTab === 'json' })}
|
|
135
|
+
role="tabpanel"
|
|
136
|
+
aria-labelledby="tab-json"
|
|
137
|
+
?hidden=${this.activeTab !== 'json'}
|
|
138
|
+
>
|
|
139
|
+
<textarea readonly>${JSON.stringify(this.currentTokenSet, null, 2)}</textarea>
|
|
140
|
+
</div>
|
|
141
|
+
|
|
142
|
+
<div
|
|
143
|
+
id="panel-reset"
|
|
144
|
+
class=${classMap({ 'tab-panel': true, active: this.activeTab === 'reset' })}
|
|
145
|
+
role="tabpanel"
|
|
146
|
+
aria-labelledby="tab-reset"
|
|
147
|
+
?hidden=${this.activeTab !== 'reset'}
|
|
148
|
+
>
|
|
149
|
+
<button class="dx-button dx-focus-ring" data-variant="destructive" @click=${() => reset()}>Reset</button>
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
152
|
+
`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
override createRenderRoot(): this {
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
import { renderTokenSet, type TokenSet } from '@ch-ui/tokens';
|
|
5
|
+
|
|
6
|
+
import { log } from '@dxos/log';
|
|
7
|
+
import { userDefaultTokenSet } from '@dxos/react-ui-theme';
|
|
8
|
+
|
|
9
|
+
const storageKey = 'dxos.org/dx-theme-editor/user-tokens';
|
|
10
|
+
|
|
11
|
+
export const tokenSetUpdateEvent = 'dx-theme-editor-token-set-update';
|
|
12
|
+
|
|
13
|
+
export const notifyTokenSetUpdate = () => {
|
|
14
|
+
window.dispatchEvent(new CustomEvent(tokenSetUpdateEvent));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const save = (value: string) => {
|
|
18
|
+
let nextValue = null;
|
|
19
|
+
try {
|
|
20
|
+
nextValue = JSON.stringify(JSON.parse(value));
|
|
21
|
+
} catch (err) {
|
|
22
|
+
log.warn('Invalid JSON', err);
|
|
23
|
+
return err;
|
|
24
|
+
}
|
|
25
|
+
if (nextValue) {
|
|
26
|
+
localStorage.setItem(storageKey, nextValue);
|
|
27
|
+
log.debug('Saved');
|
|
28
|
+
notifyTokenSetUpdate();
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const restore = () => {
|
|
34
|
+
const storedTokenSet = localStorage.getItem(storageKey);
|
|
35
|
+
return (storedTokenSet ? JSON.parse(storedTokenSet) : userDefaultTokenSet) as TokenSet;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const styleNodeId = `${storageKey}/style`;
|
|
39
|
+
|
|
40
|
+
export const saveAndRender = (tokenSet?: TokenSet) => {
|
|
41
|
+
let tokens = '';
|
|
42
|
+
try {
|
|
43
|
+
const nextTokens = tokenSet ?? restore();
|
|
44
|
+
localStorage.setItem(storageKey, JSON.stringify(nextTokens));
|
|
45
|
+
tokens = `@layer user-tokens { ${renderTokenSet(nextTokens)} }`;
|
|
46
|
+
} catch (err) {
|
|
47
|
+
return log.warn('Failed to render', err);
|
|
48
|
+
}
|
|
49
|
+
if (tokens) {
|
|
50
|
+
const styleNode = document.getElementById(styleNodeId);
|
|
51
|
+
if (styleNode) {
|
|
52
|
+
styleNode.textContent = tokens;
|
|
53
|
+
} else {
|
|
54
|
+
const newStyleNode = document.createElement('style');
|
|
55
|
+
newStyleNode.id = styleNodeId;
|
|
56
|
+
newStyleNode.textContent = tokens;
|
|
57
|
+
document.head.appendChild(newStyleNode);
|
|
58
|
+
}
|
|
59
|
+
notifyTokenSetUpdate();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const reset = () => {
|
|
64
|
+
saveAndRender(userDefaultTokenSet);
|
|
65
|
+
notifyTokenSetUpdate();
|
|
66
|
+
};
|