@preference-sl/pref-viewer 2.16.0-beta.10 → 2.16.0-beta.11
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/README.md +125 -102
- package/package.json +1 -1
- package/src/babylonjs-animation-opening.js +11 -5
- package/src/babylonjs-controller.js +337 -60
- package/src/pref-viewer-2d.js +14 -21
- package/src/pref-viewer-3d.js +140 -85
- package/src/pref-viewer-menu-3d.js +84 -40
- package/src/pref-viewer-task.js +7 -2
- package/src/pref-viewer.js +547 -185
- package/src/styles.js +105 -29
package/src/styles.js
CHANGED
|
@@ -1,9 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* localStorage key used to persist supported PrefViewer runtime style overrides.
|
|
3
|
+
* @type {string}
|
|
4
|
+
*/
|
|
5
|
+
export const PREF_VIEWER_STYLES_STORAGE_KEY = "pref-viewer/styles";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Default style variables used before host overrides or persisted values are applied.
|
|
9
|
+
* @type {{colorPrimary: string, fontFamily: string, fontSize: string}}
|
|
10
|
+
*/
|
|
11
|
+
const PrefViewerDefaultStyleVariables = {
|
|
12
|
+
colorPrimary: "#ff6700",
|
|
3
13
|
fontFamily: "'Roboto', ui-sans-serif, system-ui, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji",
|
|
14
|
+
fontSize: "15px",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Reads persisted runtime style overrides in browser contexts.
|
|
19
|
+
* Only `colorPrimary` is consumed by `PrefViewerStyleVariables`; other keys are ignored by the host component.
|
|
20
|
+
* @returns {object} Parsed persisted style overrides, or an empty object when unavailable or invalid.
|
|
21
|
+
*/
|
|
22
|
+
function readPersistedStyleVariables() {
|
|
23
|
+
if (typeof window === "undefined") {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const serialized = window.localStorage?.getItem(PREF_VIEWER_STYLES_STORAGE_KEY);
|
|
28
|
+
return serialized ? JSON.parse(serialized) : {};
|
|
29
|
+
} catch (_error) {
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @type {object} Persisted raw style overrides loaded during module initialization. */
|
|
35
|
+
const persistedStyleVariables = readPersistedStyleVariables();
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Shared style variables consumed by PrefViewer CSS templates and Babylon defaults.
|
|
39
|
+
* `colorPrimary` can be overridden at runtime through `<pref-viewer styles>`, `viewer.styles`, `viewer.setStyles()`, or `loadConfig({ styles })`.
|
|
40
|
+
* @type {{colorPrimary: string, fontFamily: string, fontSize: string}}
|
|
41
|
+
*/
|
|
42
|
+
export const PrefViewerStyleVariables = {
|
|
43
|
+
...PrefViewerDefaultStyleVariables,
|
|
44
|
+
colorPrimary: typeof persistedStyleVariables.colorPrimary === "string" && persistedStyleVariables.colorPrimary.trim().length > 0
|
|
45
|
+
? persistedStyleVariables.colorPrimary.trim()
|
|
46
|
+
: PrefViewerDefaultStyleVariables.colorPrimary,
|
|
4
47
|
};
|
|
5
48
|
|
|
49
|
+
/** Root `<pref-viewer>` host styles. Uses `--pref-viewer-color-primary` so `setStyles({ colorPrimary })` can update mounted instances. */
|
|
6
50
|
export const PrefViewerStyles = `
|
|
51
|
+
:host {
|
|
52
|
+
all: initial;
|
|
53
|
+
display: block;
|
|
54
|
+
font-family: ${PrefViewerStyleVariables.fontFamily};
|
|
55
|
+
font-size: ${PrefViewerStyleVariables.fontSize};
|
|
56
|
+
line-height: 1.2;
|
|
57
|
+
color: #000000;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
:host *, :host *::before, :host *::after {
|
|
61
|
+
box-sizing: border-box;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
:host ::selection {
|
|
65
|
+
background: var(--pref-viewer-color-primary, ${PrefViewerStyleVariables.colorPrimary});
|
|
66
|
+
color: #ffffff;
|
|
67
|
+
}
|
|
68
|
+
|
|
7
69
|
:host .pref-viewer-wrapper {
|
|
8
70
|
display: grid !important;
|
|
9
71
|
position: relative;
|
|
@@ -50,7 +112,6 @@ export const PrefViewer2DStyles = `
|
|
|
50
112
|
display: block;
|
|
51
113
|
position: relative;
|
|
52
114
|
outline: none;
|
|
53
|
-
box-sizing: border-box;
|
|
54
115
|
}
|
|
55
116
|
|
|
56
117
|
pref-viewer-2d>div>svg {
|
|
@@ -67,9 +128,6 @@ export const PrefViewer3DStyles = `
|
|
|
67
128
|
display: none;
|
|
68
129
|
}
|
|
69
130
|
|
|
70
|
-
pref-viewer-3d[show-animation-menu="false"] > div.animation-menu {
|
|
71
|
-
display: none;
|
|
72
|
-
}
|
|
73
131
|
|
|
74
132
|
pref-viewer-3d {
|
|
75
133
|
grid-column: 1;
|
|
@@ -89,7 +147,6 @@ export const PrefViewer3DStyles = `
|
|
|
89
147
|
display: block;
|
|
90
148
|
position: relative;
|
|
91
149
|
outline: none;
|
|
92
|
-
box-sizing: border-box;
|
|
93
150
|
}
|
|
94
151
|
`;
|
|
95
152
|
|
|
@@ -98,12 +155,12 @@ export const PrefViewerMenu3DStyles = `
|
|
|
98
155
|
--font-family: ${PrefViewerStyleVariables.fontFamily};
|
|
99
156
|
--font-weight-bold: 600;
|
|
100
157
|
--font-weight-medium: 500;
|
|
101
|
-
--font-size-large: 1.
|
|
102
|
-
--font-size-medium: 0.
|
|
103
|
-
--font-size-small: 0.
|
|
158
|
+
--font-size-large: calc(1.1 * ${PrefViewerStyleVariables.fontSize});
|
|
159
|
+
--font-size-medium: calc(0.95 * ${PrefViewerStyleVariables.fontSize});
|
|
160
|
+
--font-size-small: calc(0.75 * ${PrefViewerStyleVariables.fontSize});
|
|
104
161
|
--text-color: #ffffff;
|
|
105
162
|
--muted-color: #b2b2b2;
|
|
106
|
-
--accent-color: ${PrefViewerStyleVariables.colorPrimary};
|
|
163
|
+
--accent-color: var(--pref-viewer-color-primary, ${PrefViewerStyleVariables.colorPrimary});
|
|
107
164
|
|
|
108
165
|
--separator-border: 1px solid rgba(255, 255, 255, 0.1);
|
|
109
166
|
|
|
@@ -121,7 +178,7 @@ export const PrefViewerMenu3DStyles = `
|
|
|
121
178
|
--button-shadow: 0 8px 16px rgba(0, 0, 0, 0.35);
|
|
122
179
|
--button-radius: 8px;
|
|
123
180
|
|
|
124
|
-
--panel-width:
|
|
181
|
+
--panel-width: 300px;
|
|
125
182
|
--panel-spacing: 16px;
|
|
126
183
|
--panel-spacing-large: calc(var(--panel-spacing) * 1.5);
|
|
127
184
|
--panel-bg-color: rgba(19, 21, 28, 0.85);
|
|
@@ -279,6 +336,10 @@ export const PrefViewerMenu3DStyles = `
|
|
|
279
336
|
cursor: pointer;
|
|
280
337
|
}
|
|
281
338
|
|
|
339
|
+
pref-viewer-menu-3d>.menu-wrapper>.menu-panel>.menu-switches>.menu-switch[data-hidden] {
|
|
340
|
+
display: none;
|
|
341
|
+
}
|
|
342
|
+
|
|
282
343
|
pref-viewer-menu-3d>.menu-wrapper>.menu-panel>.menu-switches>.menu-switch[data-disabled]>.menu-switch-copy {
|
|
283
344
|
opacity: 0.6;
|
|
284
345
|
}
|
|
@@ -325,11 +386,20 @@ export const PrefViewerMenu3DStyles = `
|
|
|
325
386
|
transform: translateX(var(--switch-control-thumb-size));
|
|
326
387
|
}
|
|
327
388
|
|
|
328
|
-
pref-viewer-menu-3d>.menu-wrapper>.menu-panel>.menu-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
389
|
+
pref-viewer-menu-3d>.menu-wrapper>.menu-panel>.menu-slider[data-hidden] {
|
|
390
|
+
display: none;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
pref-viewer-menu-3d>.menu-wrapper>.menu-panel>.menu-slider[data-disabled] .menu-slider-label {
|
|
394
|
+
opacity: 0.6;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
pref-viewer-menu-3d>.menu-wrapper>.menu-panel>.menu-slider[data-disabled] input[type="range"] {
|
|
398
|
+
opacity: 0.4;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
pref-viewer-menu-3d>.menu-wrapper>.menu-panel>.menu-slider[data-disabled] input[type="range"]:disabled {
|
|
402
|
+
cursor: not-allowed;
|
|
333
403
|
}
|
|
334
404
|
|
|
335
405
|
pref-viewer-menu-3d>.menu-wrapper>.menu-panel>.menu-color-picker {
|
|
@@ -366,7 +436,6 @@ export const PrefViewerMenu3DStyles = `
|
|
|
366
436
|
appearance: none;
|
|
367
437
|
width: 100%;
|
|
368
438
|
height: var(--slider-bar-height);
|
|
369
|
-
box-sizing: border-box;
|
|
370
439
|
border-radius: calc(var(--slider-bar-height) / 2);
|
|
371
440
|
background: linear-gradient(to right,
|
|
372
441
|
hsl(0,100%,50%), hsl(30,100%,50%), hsl(60,100%,50%), hsl(90,100%,50%),
|
|
@@ -437,7 +506,6 @@ export const PrefViewerMenu3DStyles = `
|
|
|
437
506
|
-webkit-appearance: none;
|
|
438
507
|
appearance: none;
|
|
439
508
|
width: 100%;
|
|
440
|
-
box-sizing: border-box;
|
|
441
509
|
height: var(--slider-bar-height);
|
|
442
510
|
border-radius: calc(var(--slider-bar-height) / 2);
|
|
443
511
|
background: linear-gradient(to right,
|
|
@@ -508,17 +576,23 @@ export const PrefViewerMenu3DStyles = `
|
|
|
508
576
|
outline: none;
|
|
509
577
|
box-shadow: var(--button-shadow);
|
|
510
578
|
}
|
|
579
|
+
|
|
580
|
+
pref-viewer-menu-3d>.menu-wrapper>.menu-panel>.menu-footer {
|
|
581
|
+
margin-top: calc(var(--panel-spacing) / 2);
|
|
582
|
+
display: flex;
|
|
583
|
+
flex-direction: column;
|
|
584
|
+
gap: calc(var(--panel-spacing) / 2);
|
|
585
|
+
}
|
|
511
586
|
`;
|
|
512
587
|
|
|
513
588
|
export const PrefViewer3DAnimationMenuStyles = `
|
|
514
589
|
div.pref-viewer-3d.animation-menu, div.pref-viewer-3d.animation-menu * {
|
|
515
|
-
box-sizing: border-box;
|
|
516
590
|
padding: 0;
|
|
517
591
|
margin: 0;
|
|
518
592
|
}
|
|
519
593
|
|
|
520
594
|
div.pref-viewer-3d.animation-menu {
|
|
521
|
-
--color-primary: ${PrefViewerStyleVariables.colorPrimary};
|
|
595
|
+
--color-primary: var(--pref-viewer-color-primary, ${PrefViewerStyleVariables.colorPrimary});
|
|
522
596
|
--color-active: var(--color-primary);
|
|
523
597
|
--color-active-hover: color-mix(in oklab, var(--color-active), black 10%);
|
|
524
598
|
--color-enabled: #7a7a7a;
|
|
@@ -536,7 +610,7 @@ export const PrefViewer3DAnimationMenuStyles = `
|
|
|
536
610
|
--selector-button-radius: 6px;
|
|
537
611
|
--selector-button-padding-horizontal: 8px;
|
|
538
612
|
--selector-button-padding-vertical: 4px;
|
|
539
|
-
--selector-button-font-size:
|
|
613
|
+
--selector-button-font-size: ${PrefViewerStyleVariables.fontSize};
|
|
540
614
|
--selector-button-font-weight: 500;
|
|
541
615
|
--width: calc(var(--button-size) * 6 + var(--button-spacing) * 5 + var(--button-loop-margin-left));
|
|
542
616
|
|
|
@@ -577,6 +651,7 @@ export const PrefViewer3DAnimationMenuStyles = `
|
|
|
577
651
|
font-size: var(--selector-button-font-size);
|
|
578
652
|
font-weight: var(--selector-button-font-weight);
|
|
579
653
|
line-height: 1;
|
|
654
|
+
letter-spacing: 0.05em;
|
|
580
655
|
flex: 1;
|
|
581
656
|
}
|
|
582
657
|
|
|
@@ -592,7 +667,7 @@ export const PrefViewer3DAnimationMenuStyles = `
|
|
|
592
667
|
cursor: pointer;
|
|
593
668
|
}
|
|
594
669
|
|
|
595
|
-
div.pref-viewer-3d.animation-menu>div.animation-menu-
|
|
670
|
+
div.pref-viewer-3d.animation-menu>div.animation-menu-selector>button:not(.active):hover {
|
|
596
671
|
background: var(--color-enabled-hover);
|
|
597
672
|
}
|
|
598
673
|
|
|
@@ -609,7 +684,6 @@ export const PrefViewer3DAnimationMenuStyles = `
|
|
|
609
684
|
justify-content: center;
|
|
610
685
|
padding: 0;
|
|
611
686
|
margin: 0;
|
|
612
|
-
cursor: pointer;
|
|
613
687
|
border: 1px solid var(--color-border);
|
|
614
688
|
width: var(--button-size);
|
|
615
689
|
height: var(--button-size);
|
|
@@ -632,13 +706,15 @@ export const PrefViewer3DAnimationMenuStyles = `
|
|
|
632
706
|
|
|
633
707
|
div.pref-viewer-3d.animation-menu>div.animation-menu-buttons>button.enabled {
|
|
634
708
|
background: var(--color-enabled);
|
|
709
|
+
cursor: pointer;
|
|
635
710
|
}
|
|
636
711
|
|
|
637
712
|
div.pref-viewer-3d.animation-menu>div.animation-menu-buttons>button.enabled:hover {
|
|
638
713
|
background: var(--color-enabled-hover);
|
|
639
714
|
}
|
|
640
715
|
|
|
641
|
-
div.pref-viewer-3d.animation-menu>div.animation-menu-buttons>button.disabled
|
|
716
|
+
div.pref-viewer-3d.animation-menu>div.animation-menu-buttons>button.disabled,
|
|
717
|
+
div.pref-viewer-3d.animation-menu>div.animation-menu-buttons>button.disabled:hover {
|
|
642
718
|
background: var(--color-disabled);
|
|
643
719
|
}
|
|
644
720
|
|
|
@@ -704,7 +780,7 @@ export const PrefViewer3DAnimationMenuStyles = `
|
|
|
704
780
|
|
|
705
781
|
export const PrefViewerDialogStyles = `
|
|
706
782
|
pref-viewer-dialog {
|
|
707
|
-
--color-primary: ${PrefViewerStyleVariables.colorPrimary};
|
|
783
|
+
--color-primary: var(--pref-viewer-color-primary, ${PrefViewerStyleVariables.colorPrimary});
|
|
708
784
|
--dialog-general-space: 16px;
|
|
709
785
|
--dialog-bg-color: #ffffff;
|
|
710
786
|
--dialog-backdrop-color: rgba(0, 0, 0, 0.25);
|
|
@@ -764,7 +840,7 @@ export const PrefViewerDialogStyles = `
|
|
|
764
840
|
pref-viewer-dialog .dialog-header h3 {
|
|
765
841
|
margin: 0;
|
|
766
842
|
font-weight: 500;
|
|
767
|
-
font-size: 1.
|
|
843
|
+
font-size: calc(1.1 * ${PrefViewerStyleVariables.fontSize});
|
|
768
844
|
}
|
|
769
845
|
|
|
770
846
|
pref-viewer-dialog .dialog-content {
|
|
@@ -774,7 +850,7 @@ export const PrefViewerDialogStyles = `
|
|
|
774
850
|
pref-viewer-dialog .dialog-content h4 {
|
|
775
851
|
margin: 0;
|
|
776
852
|
font-weight: 500;
|
|
777
|
-
font-size: 1.
|
|
853
|
+
font-size: calc(1.05 * ${PrefViewerStyleVariables.fontSize});
|
|
778
854
|
}
|
|
779
855
|
|
|
780
856
|
pref-viewer-dialog .dialog-footer {
|
|
@@ -787,7 +863,7 @@ export const PrefViewerDialogStyles = `
|
|
|
787
863
|
|
|
788
864
|
pref-viewer-dialog .dialog-footer button {
|
|
789
865
|
width: 100%;
|
|
790
|
-
font-size: 0.
|
|
866
|
+
font-size: calc(0.95 * ${PrefViewerStyleVariables.fontSize});
|
|
791
867
|
font-weight: 600;
|
|
792
868
|
padding: var(--button-padding-vertical) var(--button-padding-horizontal);
|
|
793
869
|
border-radius: var(--button-border-radius);
|