@preference-sl/pref-viewer 2.11.0-beta.8 → 2.11.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/src/styles.js ADDED
@@ -0,0 +1,334 @@
1
+ export const PrefViewerColors = {
2
+ primary: "#ff6700", // Always specify in hexadecimal
3
+ };
4
+
5
+ export const PrefViewerStyles = `
6
+ :host .pref-viewer-wrapper {
7
+ display: grid !important;
8
+ position: relative;
9
+ width: 100%;
10
+ height: 100%;
11
+ grid-template-columns: 1fr;
12
+ grid-template-rows: 1fr;
13
+ grid-gap: 0;
14
+ min-width: 0;
15
+ min-height: 0;
16
+ }
17
+ `;
18
+
19
+ export const PrefViewer2DStyles = `
20
+ pref-viewer-2d {
21
+ --pref-viewer-2d-bg-color: #ffffff;
22
+ --pref-viewer-2d-svg-padding: 10px;
23
+ }
24
+
25
+ pref-viewer-2d[visible="true"] {
26
+ display: block;
27
+ }
28
+
29
+ pref-viewer-2d[visible="false"] {
30
+ display: none;
31
+ }
32
+
33
+ pref-viewer-2d {
34
+ grid-column: 1;
35
+ grid-row: 1;
36
+ overflow: hidden;
37
+ min-width: 0;
38
+ min-height: 0;
39
+ align-self: stretch;
40
+ justify-self: stretch;
41
+ background: var(--pref-viewer-2d-bg-color);
42
+ }
43
+
44
+ pref-viewer-2d,
45
+ pref-viewer-2d>div,
46
+ pref-viewer-2d>div>svg {
47
+ width: 100%;
48
+ height: 100%;
49
+ display: block;
50
+ position: relative;
51
+ outline: none;
52
+ box-sizing: border-box;
53
+ }
54
+
55
+ pref-viewer-2d>div>svg {
56
+ padding: var(--pref-viewer-2d-svg-padding);
57
+ }
58
+ `;
59
+
60
+ export const PrefViewer3DStyles = `
61
+ pref-viewer-3d[visible="true"] {
62
+ display: block;
63
+ }
64
+
65
+ pref-viewer-3d[visible="false"] {
66
+ display: none;
67
+ }
68
+
69
+ pref-viewer-3d {
70
+ grid-column: 1;
71
+ grid-row: 1;
72
+ overflow: hidden;
73
+ min-width: 0;
74
+ min-height: 0;
75
+ align-self: stretch;
76
+ justify-self: stretch;
77
+ }
78
+
79
+ pref-viewer-3d,
80
+ pref-viewer-3d>div,
81
+ pref-viewer-3d>div>canvas {
82
+ width: 100%;
83
+ height: 100%;
84
+ display: block;
85
+ position: relative;
86
+ outline: none;
87
+ box-sizing: border-box;
88
+ }
89
+ `;
90
+
91
+ export const PrefViewer3DAnimationMenuStyles = `
92
+ div.pref-viewer-3d.animation-menu, div.pref-viewer-3d.animation-menu * {
93
+ box-sizing: border-box;
94
+ padding: 0;
95
+ margin: 0;
96
+ }
97
+
98
+ div.pref-viewer-3d.animation-menu {
99
+ --color-primary: ${PrefViewerColors.primary};
100
+ --color-active: var(--color-primary);
101
+ --color-active-hover: color-mix(in oklab, var(--color-active), black 10%);
102
+ --color-enabled: #7a7a7a;
103
+ --color-enabled-hover: color-mix(in oklab, var(--color-enabled), black 15%);
104
+ --color-disabled: #bdbdbd;
105
+ --color-icon: #FFFFFF;
106
+ --color-border: #FFFFFF;
107
+ --button-size: 32px;
108
+ --icon-size: 24px;
109
+ --button-loop-margin-left: 3px;
110
+ --button-spacing: 2px;
111
+ --slider-thumb-width: 20px;
112
+ --slider-bar-height: 8px;
113
+ --slider-bar-offset: 10px;
114
+
115
+ display: block;
116
+ position: absolute;
117
+ bottom: 10px;
118
+
119
+ right: calc(50% - ((6 * var(--button-size) + 5 * var(--button-spacing) + var(--button-loop-margin-left)) / 2));
120
+ z-index: 1000;
121
+ }
122
+
123
+ div.pref-viewer-3d.animation-menu>div.animation-menu-buttons {
124
+ padding: 0;
125
+ margin: 0;
126
+ display: flex;
127
+ gap: var(--button-spacing);
128
+ }
129
+
130
+ div.pref-viewer-3d.animation-menu>div.animation-menu-buttons>button {
131
+ display: flex;
132
+ align-items: center;
133
+ justify-content: center;
134
+ padding: 0;
135
+ margin: 0;
136
+ cursor: pointer;
137
+ border: 1px solid var(--color-border);
138
+ width: var(--button-size);
139
+ height: var(--button-size);
140
+ background: var(--color-enabled);
141
+ }
142
+
143
+ div.pref-viewer-3d.animation-menu>div.animation-menu-buttons>button>svg {
144
+ fill: var(--color-icon);
145
+ width: 100%;
146
+ height: 100%;
147
+ }
148
+
149
+ div.pref-viewer-3d.animation-menu>div.animation-menu-buttons>button.active {
150
+ background: var(--color-active);
151
+ }
152
+
153
+ div.pref-viewer-3d.animation-menu>div.animation-menu-buttons>button.active:hover {
154
+ background: var(--color-active-hover);
155
+ }
156
+
157
+ div.pref-viewer-3d.animation-menu>div.animation-menu-buttons>button.enabled {
158
+ background: var(--color-enabled);
159
+ }
160
+
161
+ div.pref-viewer-3d.animation-menu>div.animation-menu-buttons>button.enabled:hover {
162
+ background: var(--color-enabled-hover);
163
+ }
164
+
165
+ div.pref-viewer-3d.animation-menu>div.animation-menu-buttons>button.disabled {
166
+ background: var(--color-disabled);
167
+ }
168
+
169
+ div.pref-viewer-3d.animation-menu>div.animation-menu-buttons>button.visible {
170
+ display: block-flex;
171
+ }
172
+
173
+ div.pref-viewer-3d.animation-menu>div.animation-menu-buttons>button.hidden {
174
+ display: none;
175
+ }
176
+
177
+ div.pref-viewer-3d.animation-menu>div.animation-menu-buttons>button[name="button_animation_repeat"],
178
+ div.pref-viewer-3d.animation-menu>div.animation-menu-buttons>button[name="button_animation_repeatOff"] {
179
+ margin-left: var(--button-loop-margin-left);
180
+ }
181
+
182
+ div.pref-viewer-3d.animation-menu>input[type="range"] {
183
+ -webkit-appearance: none;
184
+ width: 100%;
185
+ height: var(--slider-bar-height);
186
+ border: 1px solid var(--color-border);
187
+ outline: none;
188
+ accent-color: var(--color-active);
189
+ background: var(--color-enabled);
190
+ border-radius: var(--slider-bar-height);
191
+ -webkit-transition: .2s;
192
+ transition: background .2s;
193
+ margin: var(--slider-bar-offset) 0px;
194
+ }
195
+
196
+ div.pref-viewer-3d.animation-menu>input[type="range"]::-webkit-slider-thumb {
197
+ -webkit-appearance: none;
198
+ appearance: none;
199
+ height: var(--slider-thumb-width);
200
+ width: var(--slider-thumb-width);
201
+ border-radius: 50%;
202
+ border: 1px solid var(--color-border);
203
+ background: var(--color-active);
204
+ cursor: pointer;
205
+ -webkit-transition: .2s;
206
+ transition: background .2s;
207
+ }
208
+
209
+ div.pref-viewer-3d.animation-menu>input[type="range"]::-webkit-slider-thumb:hover {
210
+ background: var(--color-active-hover);
211
+ }
212
+
213
+ div.pref-viewer-3d.animation-menu>input[type="range"]::-moz-range-track {
214
+ height: var(--slider-thumb-width);
215
+ width: var(--slider-thumb-width);
216
+ border-radius: 50%;
217
+ border: 1px solid var(--color-border);
218
+ background: var(--color-active);
219
+ cursor: pointer;
220
+ -webkit-transition: .2s;
221
+ transition: background .2s;
222
+ }
223
+
224
+ div.pref-viewer-3d.animation-menu>input[type="range"]::-moz-range-track:hover {
225
+ background: var(--color-active-hover);
226
+ }
227
+ `;
228
+
229
+ export const PrefViewerDialogStyles = `
230
+ pref-viewer-dialog {
231
+ --color-primary: ${PrefViewerColors.primary};
232
+ --dialog-general-space: 16px;
233
+ --dialog-bg-color: #ffffff;
234
+ --dialog-backdrop-color: rgba(0, 0, 0, 0.25);
235
+ --dialog-border-color: #e7e7e7;
236
+ --dialog-border-radius: 8px;
237
+ --dialog-box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
238
+ --button-default-bg-color: #bbbbbb;
239
+ --button-default-bg-color-hover: color-mix(in oklab, var(--button-default-bg-color), black 10%);
240
+ --button-primary-bg-color: var(--color-primary);
241
+ --button-primary-bg-color-hover: color-mix(in oklab, var(--button-primary-bg-color), black 10%);
242
+ --button-border-radius: 4px;
243
+ --button-padding-horizontal: 16px;
244
+ --button-padding-vertical: 8px;
245
+ }
246
+
247
+ pref-viewer-dialog:not {
248
+ display: none;
249
+ }
250
+
251
+ pref-viewer-dialog[open] {
252
+ font-family: 'Roboto', ui-sans-serif, system-ui, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji;
253
+ grid-row: 1;
254
+ grid-column: 1;
255
+ overflow: hidden;
256
+ min-width: 0;
257
+ min-height: 0;
258
+ align-self: stretch;
259
+ justify-self: stretch;
260
+ display: flex;
261
+ align-items: center;
262
+ justify-content: center;
263
+ background-color: var(--dialog-backdrop-color);
264
+ position: relative;
265
+ z-index: 1000;
266
+ }
267
+
268
+ pref-viewer-dialog>.dialog-wrapper {
269
+ display: flex;
270
+ flex-direction: column;
271
+ align-items: stretch;
272
+ background: var(--dialog-bg-color);
273
+ border: 1px solid var(--dialog-border-color);
274
+ border-radius: var(--dialog-border-radius);
275
+ box-shadow: var(--dialog-box-shadow);
276
+ padding: 0;
277
+ min-width: 320px;
278
+ max-width: 90%;
279
+ max-height: 90%;
280
+ overflow: auto;
281
+ }
282
+
283
+ pref-viewer-dialog .dialog-header {
284
+ padding: var(--dialog-general-space);
285
+ border-bottom: 1px solid var(--dialog-border-color);
286
+ }
287
+
288
+ pref-viewer-dialog .dialog-header h3 {
289
+ margin: 0;
290
+ font-weight: 500;
291
+ font-size: 1.1em;
292
+ }
293
+
294
+ pref-viewer-dialog .dialog-content {
295
+ padding: var(--dialog-general-space);
296
+ }
297
+
298
+ pref-viewer-dialog .dialog-content h4 {
299
+ margin: 0;
300
+ font-weight: 500;
301
+ font-size: 1.05em;
302
+ }
303
+
304
+ pref-viewer-dialog .dialog-footer {
305
+ border-top: 1px solid var(--dialog-border-color);
306
+ padding: var(--dialog-general-space);
307
+ display: flex;
308
+ gap: var(--dialog-general-space);
309
+ justify-content: stretch;
310
+ }
311
+
312
+ pref-viewer-dialog .dialog-footer button {
313
+ width: 100%;
314
+ font-size: 1em;
315
+ padding: var(--button-padding-vertical) var(--button-padding-horizontal);
316
+ border-radius: var(--button-border-radius);
317
+ border: none;
318
+ background: var(--button-default-bg-color);
319
+ cursor: pointer;
320
+ transition: background 0.2s;
321
+ }
322
+
323
+ pref-viewer-dialog .dialog-footer button.primary {
324
+ background: var(--button-primary-bg-color);
325
+ }
326
+
327
+ pref-viewer-dialog .dialog-footer button:hover {
328
+ background: var(--button-default-bg-color-hover);
329
+ }
330
+
331
+ pref-viewer-dialog .dialog-footer button.primary:hover {
332
+ background: var(--button-primary-bg-color-hover);
333
+ }
334
+ `;
@@ -121,6 +121,29 @@ export default class SVGResolver {
121
121
  return [value, size];
122
122
  }
123
123
 
124
+ // Some payloads are base64 of UTF-16 strings, which leave NUL bytes after atob; strip them and retry.
125
+ const cleanedDecoded = decoded.replace(/\u0000/g, "");
126
+ if (cleanedDecoded !== decoded && isSvg(cleanedDecoded)) {
127
+ size = raw.length;
128
+ value = cleanedDecoded;
129
+ return [value, size];
130
+ }
131
+
132
+ // Last resort: attempt decoding the binary buffer as UTF-16LE when available (TextDecoder is native in browsers).
133
+ if (typeof TextDecoder !== "undefined") {
134
+ try {
135
+ const bytes = Uint8Array.from(decoded, (c) => c.charCodeAt(0));
136
+ const utf16 = new TextDecoder("utf-16le").decode(bytes);
137
+ if (isSvg(utf16)) {
138
+ size = raw.length;
139
+ value = utf16;
140
+ return [value, size];
141
+ }
142
+ } catch {
143
+ // ignore and fall through
144
+ }
145
+ }
146
+
124
147
  return [value, size];
125
148
  }
126
149