@perspective-dev/viewer 4.5.0 → 4.5.2
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/dist/cdn/perspective-viewer.js +1 -1
- package/dist/cdn/perspective-viewer.js.map +2 -2
- package/dist/css/botanical.css +1 -1
- package/dist/css/dracula.css +1 -1
- package/dist/css/gruvbox-dark.css +1 -1
- package/dist/css/gruvbox.css +1 -1
- package/dist/css/icons.css +1 -1
- package/dist/css/intl/de.css +1 -1
- package/dist/css/intl/es.css +1 -1
- package/dist/css/intl/fr.css +1 -1
- package/dist/css/intl/ja.css +1 -1
- package/dist/css/intl/pt.css +1 -1
- package/dist/css/intl/zh.css +1 -1
- package/dist/css/intl.css +1 -1
- package/dist/css/monokai.css +1 -1
- package/dist/css/phosphor.css +1 -1
- package/dist/css/pro-dark.css +1 -1
- package/dist/css/pro.css +1 -1
- package/dist/css/solarized-dark.css +1 -1
- package/dist/css/solarized.css +1 -1
- package/dist/css/themes.css +1 -1
- package/dist/css/vaporwave.css +1 -1
- package/dist/esm/perspective-viewer.cdn.d.ts +3 -0
- package/dist/esm/perspective-viewer.inline.d.ts +3 -0
- package/dist/esm/perspective-viewer.inline.js +1 -1
- package/dist/esm/perspective-viewer.inline.js.map +2 -2
- package/dist/esm/perspective-viewer.js +1 -1
- package/dist/esm/perspective-viewer.js.map +2 -2
- package/dist/esm/ts-rs/OnUpdateData.d.ts +6 -0
- package/dist/esm/ts-rs/ViewOnUpdateResp.d.ts +4 -0
- package/dist/wasm/perspective-viewer.d.ts +15 -15
- package/dist/wasm/perspective-viewer.js +93 -88
- package/dist/wasm/perspective-viewer.wasm +0 -0
- package/dist/wasm/perspective-viewer.wasm.d.ts +15 -15
- package/package.json +1 -1
- package/src/{rust/components/style/local_style.rs → css/_column_dropdown.css} +14 -35
- package/src/css/_dropdown_menu.css +14 -0
- package/src/css/_filter_dropdown.css +14 -0
- package/src/css/_function_dropdown.css +14 -0
- package/src/css/_viewer_bundle.css +41 -0
- package/src/css/column-settings-panel.css +9 -3
- package/src/css/column-style.css +9 -1
- package/src/css/dom/checkbox.css +2 -2
- package/src/css/viewer.css +79 -1
- package/src/rust/components/column_dropdown.rs +3 -3
- package/src/rust/components/column_selector/active_column.rs +3 -0
- package/src/rust/components/column_selector/aggregate_selector.rs +0 -3
- package/src/rust/components/column_selector/config_selector.rs +0 -3
- package/src/rust/components/column_selector/empty_column.rs +0 -3
- package/src/rust/components/column_selector/filter_column.rs +0 -3
- package/src/rust/components/column_selector/inactive_column.rs +2 -1
- package/src/rust/components/column_selector/invalid_column.rs +0 -4
- package/src/rust/components/column_selector.rs +0 -3
- package/src/rust/components/column_settings_sidebar/style_tab/primitive_field.rs +1 -0
- package/src/rust/components/column_settings_sidebar/style_tab/symbol/symbol_pairs.rs +0 -3
- package/src/rust/components/column_settings_sidebar/style_tab/symbol.rs +0 -3
- package/src/rust/components/column_settings_sidebar.rs +1 -3
- package/src/rust/components/containers/dragdrop_list.rs +27 -0
- package/src/rust/components/containers/dropdown_menu.rs +1 -3
- package/src/rust/components/containers/scroll_panel.rs +1 -3
- package/src/rust/components/containers/split_panel.rs +0 -4
- package/src/rust/components/containers/tab_list.rs +0 -3
- package/src/rust/components/datetime_column_style.rs +0 -3
- package/src/rust/components/editable_header.rs +15 -0
- package/src/rust/components/empty_row.rs +0 -3
- package/src/rust/components/expression_editor.rs +2 -3
- package/src/rust/components/filter_dropdown.rs +3 -3
- package/src/rust/components/font_loader.rs +2 -2
- package/src/rust/components/form/code_editor.rs +0 -3
- package/src/rust/components/form/debug.rs +0 -4
- package/src/rust/components/function_dropdown.rs +3 -3
- package/src/rust/components/number_series_style.rs +0 -3
- package/src/rust/components/plugin_selector.rs +0 -3
- package/src/rust/components/plugin_tab.rs +0 -5
- package/src/rust/components/portal.rs +5 -2
- package/src/rust/components/render_warning.rs +0 -3
- package/src/rust/components/status_bar.rs +4 -3
- package/src/rust/components/string_column_style.rs +0 -3
- package/src/rust/components/style/mod.rs +60 -27
- package/src/rust/components/style/style_provider.rs +49 -16
- package/src/rust/components/style_controls/number_string_format.rs +1 -8
- package/src/rust/components/type_icon.rs +1 -4
- package/src/rust/components/viewer.rs +79 -5
- package/src/rust/custom_elements/copy_dropdown.rs +6 -2
- package/src/rust/custom_elements/export_dropdown.rs +6 -2
- package/src/rust/lib.rs +0 -1
- package/src/rust/renderer.rs +85 -21
- package/src/rust/session/metadata.rs +11 -1
- package/src/rust/session.rs +14 -1
- package/src/rust/tasks/reset_all.rs +38 -18
- package/src/rust/tasks/restore_and_render.rs +23 -12
- package/src/rust/tasks/send_column_config.rs +3 -2
- package/src/rust/tasks/send_plugin_config.rs +3 -2
- package/src/rust/tasks/update_and_render.rs +11 -4
- package/src/svg/checkbox-checked-icon.svg +1 -1
- package/src/svg/checkbox-unchecked-icon.svg +1 -1
- package/src/themes/botanical.css +2 -0
- package/src/themes/dracula.css +2 -0
- package/src/themes/gruvbox-dark.css +2 -0
- package/src/themes/icons.css +2 -0
- package/src/themes/intl/de.css +1 -0
- package/src/themes/intl/es.css +1 -0
- package/src/themes/intl/fr.css +1 -0
- package/src/themes/intl/ja.css +1 -0
- package/src/themes/intl/pt.css +1 -0
- package/src/themes/intl/zh.css +1 -0
- package/src/themes/intl.css +1 -0
- package/src/themes/monokai.css +2 -0
- package/src/themes/phosphor.css +2 -0
- package/src/themes/pro-dark.css +2 -0
- package/src/themes/vaporwave.css +2 -0
- package/tsconfig.json +1 -1
- package/src/rust/components/style/style_cache.rs +0 -136
- /package/dist/wasm/snippets/{perspective-viewer-39ab7da3ca157861 → perspective-viewer-93064d0d79855d97}/inline0.js +0 -0
- /package/dist/wasm/snippets/{perspective-viewer-39ab7da3ca157861 → perspective-viewer-93064d0d79855d97}/inline1.js +0 -0
- /package/dist/wasm/snippets/{perspective-viewer-39ab7da3ca157861 → perspective-viewer-93064d0d79855d97}/inline2.js +0 -0
- /package/dist/wasm/snippets/{perspective-viewer-39ab7da3ca157861 → perspective-viewer-93064d0d79855d97}/inline3.js +0 -0
- /package/dist/wasm/snippets/{perspective-viewer-39ab7da3ca157861 → perspective-viewer-93064d0d79855d97}/inline4.js +0 -0
package/src/themes/botanical.css
CHANGED
|
@@ -33,6 +33,7 @@ perspective-viewer[theme="Botanical"] {
|
|
|
33
33
|
--psp-expression--function--color: #7bc96f;
|
|
34
34
|
--psp-expression--psp-error--color: rgb(232, 131, 106);
|
|
35
35
|
--psp-calendar--filter: invert(1);
|
|
36
|
+
--psp-input--filter: invert(1);
|
|
36
37
|
--psp-warning--color: #1a2e1a;
|
|
37
38
|
--psp-warning--background: var(--psp--color);
|
|
38
39
|
|
|
@@ -110,6 +111,7 @@ perspective-string-column-style[theme="Botanical"] {
|
|
|
110
111
|
--psp-expression--function--color: #7bc96f;
|
|
111
112
|
--psp-expression--psp-error--color: rgb(232, 131, 106);
|
|
112
113
|
--psp-calendar--filter: invert(1);
|
|
114
|
+
--psp-input--filter: invert(1);
|
|
113
115
|
--psp-warning--color: #1a2e1a;
|
|
114
116
|
--psp-warning--background: var(--psp--color);
|
|
115
117
|
|
package/src/themes/dracula.css
CHANGED
|
@@ -32,6 +32,7 @@ perspective-viewer[theme="Dracula"] {
|
|
|
32
32
|
--psp-expression--function--color: #22a0ce;
|
|
33
33
|
--psp-expression--psp-error--color: rgb(255, 136, 136);
|
|
34
34
|
--psp-calendar--filter: invert(1);
|
|
35
|
+
--psp-input--filter: invert(1);
|
|
35
36
|
--psp-warning--color: #242526;
|
|
36
37
|
--psp-warning--background: var(--psp--color);
|
|
37
38
|
|
|
@@ -170,6 +171,7 @@ perspective-dropdown[theme="Dracula"] {
|
|
|
170
171
|
--psp-expression--function--color: #22a0ce;
|
|
171
172
|
--psp-expression--psp-error--color: rgb(255, 136, 136);
|
|
172
173
|
--psp-calendar--filter: invert(1);
|
|
174
|
+
--psp-input--filter: invert(1);
|
|
173
175
|
--psp-warning--color: #242526;
|
|
174
176
|
--psp-warning--background: var(--psp--color);
|
|
175
177
|
--psp-icon--select-arrow--mask-image: var(
|
|
@@ -32,6 +32,7 @@ perspective-viewer[theme="Gruvbox Dark"] {
|
|
|
32
32
|
--psp-expression--function--color: #22a0ce;
|
|
33
33
|
--psp-expression--psp-error--color: rgb(255, 136, 136);
|
|
34
34
|
--psp-calendar--filter: invert(1);
|
|
35
|
+
--psp-input--filter: invert(1);
|
|
35
36
|
--psp-warning--color: #242526;
|
|
36
37
|
--psp-warning--background: var(--psp--color);
|
|
37
38
|
|
|
@@ -183,6 +184,7 @@ perspective-dropdown[theme="Gruvbox Dark"] {
|
|
|
183
184
|
--psp-expression--function--color: #22a0ce;
|
|
184
185
|
--psp-expression--psp-error--color: rgb(255, 136, 136);
|
|
185
186
|
--psp-calendar--filter: invert(1);
|
|
187
|
+
--psp-input--filter: invert(1);
|
|
186
188
|
--psp-warning--color: #242526;
|
|
187
189
|
--psp-warning--background: var(--psp--color);
|
|
188
190
|
--psp-icon--select-arrow--mask-image: var(
|
package/src/themes/icons.css
CHANGED
|
@@ -34,6 +34,8 @@ perspective-string-column-style {
|
|
|
34
34
|
--psp-icon--radio-on--mask-image: url("../svg/radio-on.svg");
|
|
35
35
|
--psp-icon--radio-hover--mask-image: url("../svg/radio-hover.svg");
|
|
36
36
|
--psp-icon--radio-off--mask-image: url("../svg/radio-off.svg");
|
|
37
|
+
/* --psp-icon--checkbox-checked--mask-image: url("../svg/checkbox-checked-icon.svg");
|
|
38
|
+
--psp-icon--checkbox-unchecked--mask-image: url("../svg/checkbox-unchecked-icon.svg"); */
|
|
37
39
|
--psp-icon--checkbox-on--mask-image: url("../svg/checkbox-on.svg");
|
|
38
40
|
--psp-icon--checkbox-hover--mask-image: url("../svg/checkbox-hover.svg");
|
|
39
41
|
--psp-icon--checkbox-off--mask-image: url("../svg/checkbox-off.svg");
|
package/src/themes/intl/de.css
CHANGED
|
@@ -80,6 +80,7 @@ perspective-dropdown {
|
|
|
80
80
|
--psp-label--style--content: "Stil";
|
|
81
81
|
--psp-label--stack--content: "Stapel";
|
|
82
82
|
--psp-label--alt-axis--content: "Zweite Achse";
|
|
83
|
+
--psp-label--interpolate--content: "Interpolieren";
|
|
83
84
|
--psp-label--minimum-integer-digits--content: "Mindestanzahl ganzzahliger Ziffern";
|
|
84
85
|
--psp-label--rounding-increment--content: "Rundungsinkrement";
|
|
85
86
|
--psp-label--notation--content: "Notation";
|
package/src/themes/intl/es.css
CHANGED
|
@@ -80,6 +80,7 @@ perspective-dropdown {
|
|
|
80
80
|
--psp-label--style--content: "Estilo";
|
|
81
81
|
--psp-label--stack--content: "Apilar";
|
|
82
82
|
--psp-label--alt-axis--content: "Eje Alterno";
|
|
83
|
+
--psp-label--interpolate--content: "Interpolar";
|
|
83
84
|
--psp-label--minimum-integer-digits--content: "Dígitos enteros mínimos";
|
|
84
85
|
--psp-label--rounding-increment--content: "Incremento de redondeo";
|
|
85
86
|
--psp-label--notation--content: "Notación";
|
package/src/themes/intl/fr.css
CHANGED
|
@@ -80,6 +80,7 @@ perspective-dropdown {
|
|
|
80
80
|
--psp-label--style--content: "Style";
|
|
81
81
|
--psp-label--stack--content: "Empiler";
|
|
82
82
|
--psp-label--alt-axis--content: "Axe alternatif";
|
|
83
|
+
--psp-label--interpolate--content: "Interpoler";
|
|
83
84
|
--psp-label--minimum-integer-digits--content: "Chiffres entiers minimaux";
|
|
84
85
|
--psp-label--rounding-increment--content: "Incrément d'arrondi";
|
|
85
86
|
--psp-label--notation--content: "Notation";
|
package/src/themes/intl/ja.css
CHANGED
|
@@ -81,6 +81,7 @@ perspective-dropdown {
|
|
|
81
81
|
--psp-label--style--content: "スタイル";
|
|
82
82
|
--psp-label--stack--content: "スタック";
|
|
83
83
|
--psp-label--alt-axis--content: "副軸";
|
|
84
|
+
--psp-label--interpolate--content: "補間";
|
|
84
85
|
--psp-label--minimum-integer-digits--content: "整数の最小桁数";
|
|
85
86
|
--psp-label--rounding-increment--content: "丸め増分";
|
|
86
87
|
--psp-label--notation--content: "表記";
|
package/src/themes/intl/pt.css
CHANGED
|
@@ -80,6 +80,7 @@ perspective-dropdown {
|
|
|
80
80
|
--psp-label--style--content: "Estilo";
|
|
81
81
|
--psp-label--stack--content: "Empilhar";
|
|
82
82
|
--psp-label--alt-axis--content: "Eixo Alternativo";
|
|
83
|
+
--psp-label--interpolate--content: "Interpolar";
|
|
83
84
|
--psp-label--minimum-integer-digits--content: "Dígitos inteiros mínimos";
|
|
84
85
|
--psp-label--rounding-increment--content: "Incremento de arredondamento";
|
|
85
86
|
--psp-label--notation--content: "Notação";
|
package/src/themes/intl/zh.css
CHANGED
|
@@ -80,6 +80,7 @@ perspective-dropdown {
|
|
|
80
80
|
--psp-label--style--content: "风格";
|
|
81
81
|
--psp-label--stack--content: "堆叠";
|
|
82
82
|
--psp-label--alt-axis--content: "副轴";
|
|
83
|
+
--psp-label--interpolate--content: "插值";
|
|
83
84
|
--psp-label--minimum-integer-digits--content: "最小整数位数";
|
|
84
85
|
--psp-label--rounding-increment--content: "舍入增量";
|
|
85
86
|
--psp-label--notation--content: "符号";
|
package/src/themes/intl.css
CHANGED
|
@@ -132,4 +132,5 @@ perspective-dropdown {
|
|
|
132
132
|
--psp-label--gradient-heat-max--content: "Heat max";
|
|
133
133
|
--psp-label--map-tile-provider--content: "Map provider";
|
|
134
134
|
--psp-label--map-tile-alpha--content: "Map opacity";
|
|
135
|
+
--psp-label--interpolate--content: "Interpolate null";
|
|
135
136
|
}
|
package/src/themes/monokai.css
CHANGED
|
@@ -32,6 +32,7 @@ perspective-viewer[theme="Monokai"] {
|
|
|
32
32
|
--psp-expression--function--color: #22a0ce;
|
|
33
33
|
--psp-expression--psp-error--color: rgb(255, 136, 136);
|
|
34
34
|
--psp-calendar--filter: invert(1);
|
|
35
|
+
--psp-input--filter: invert(1);
|
|
35
36
|
--psp-warning--color: #242526;
|
|
36
37
|
--psp-warning--background: var(--psp--color);
|
|
37
38
|
|
|
@@ -183,6 +184,7 @@ perspective-string-column-style[theme="Monokai"] {
|
|
|
183
184
|
--psp-expression--function--color: #22a0ce;
|
|
184
185
|
--psp-expression--psp-error--color: rgb(255, 136, 136);
|
|
185
186
|
--psp-calendar--filter: invert(1);
|
|
187
|
+
--psp-input--filter: invert(1);
|
|
186
188
|
--psp-warning--color: #242526;
|
|
187
189
|
--psp-warning--background: var(--psp--color);
|
|
188
190
|
--psp-icon--select-arrow--mask-image: var(
|
package/src/themes/phosphor.css
CHANGED
|
@@ -43,6 +43,7 @@ perspective-viewer[theme="Phosphor"] {
|
|
|
43
43
|
--psp-expression--function--color: var(--theme-green-bright);
|
|
44
44
|
--psp-expression--psp-error--color: var(--theme-red);
|
|
45
45
|
--psp-calendar--filter: invert(1) hue-rotate(70deg);
|
|
46
|
+
--psp-input--filter: invert(1) hue-rotate(70deg);
|
|
46
47
|
--psp-warning--color: var(--theme-bg0);
|
|
47
48
|
--psp-warning--background: var(--theme-amber);
|
|
48
49
|
|
|
@@ -153,6 +154,7 @@ perspective-string-column-style[theme="Phosphor"] {
|
|
|
153
154
|
--psp-expression--function--color: var(--theme-green-bright);
|
|
154
155
|
--psp-expression--psp-error--color: var(--theme-red);
|
|
155
156
|
--psp-calendar--filter: invert(1) hue-rotate(70deg);
|
|
157
|
+
--psp-input--filter: invert(1) hue-rotate(70deg);
|
|
156
158
|
--psp-warning--color: var(--theme-bg0);
|
|
157
159
|
--psp-warning--background: var(--theme-amber);
|
|
158
160
|
--psp-icon--select-arrow--mask-image: var(
|
package/src/themes/pro-dark.css
CHANGED
|
@@ -33,6 +33,7 @@ perspective-viewer[theme="Pro Dark"] {
|
|
|
33
33
|
--psp-expression--function--color: #22a0ce;
|
|
34
34
|
--psp-expression--error--color: rgb(255, 136, 136);
|
|
35
35
|
--psp-calendar--filter: invert(1);
|
|
36
|
+
--psp-input--filter: invert(1);
|
|
36
37
|
--psp-warning--color: #242526;
|
|
37
38
|
--psp-warning--background: var(--psp--color);
|
|
38
39
|
|
|
@@ -127,6 +128,7 @@ perspective-string-column-style[theme="Pro Dark"] {
|
|
|
127
128
|
--psp-expression--function--color: #22a0ce;
|
|
128
129
|
--psp-expression--error--color: rgb(255, 136, 136);
|
|
129
130
|
--psp-calendar--filter: invert(1);
|
|
131
|
+
--psp-input--filter: invert(1);
|
|
130
132
|
--psp-warning--color: #242526;
|
|
131
133
|
--psp-warning--background: var(--psp--color);
|
|
132
134
|
|
package/src/themes/vaporwave.css
CHANGED
|
@@ -32,6 +32,7 @@ perspective-viewer[theme="Vaporwave"] {
|
|
|
32
32
|
--psp-expression--function--color: #22a0ce;
|
|
33
33
|
--psp-expression--psp-error--color: rgb(255, 136, 136);
|
|
34
34
|
--psp-calendar--filter: invert(1);
|
|
35
|
+
--psp-input--filter: invert(1);
|
|
35
36
|
--psp-warning--color: #242526;
|
|
36
37
|
--psp-warning--background: var(--psp--color);
|
|
37
38
|
|
|
@@ -195,6 +196,7 @@ perspective-string-column-style[theme="Vaporwave"] {
|
|
|
195
196
|
--psp-expression--function--color: #22a0ce;
|
|
196
197
|
--psp-expression--psp-error--color: rgb(255, 136, 136);
|
|
197
198
|
--psp-calendar--filter: invert(1);
|
|
199
|
+
--psp-input--filter: invert(1);
|
|
198
200
|
--psp-warning--color: #242526;
|
|
199
201
|
--psp-warning--background: var(--psp--color);
|
|
200
202
|
--psp-icon--select-arrow--mask-image: var(
|
package/tsconfig.json
CHANGED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
|
2
|
-
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
|
|
3
|
-
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
|
|
4
|
-
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
|
|
5
|
-
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
|
|
6
|
-
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
|
|
7
|
-
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
|
|
8
|
-
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
|
|
9
|
-
// ┃ This file is part of the Perspective library, distributed under the terms ┃
|
|
10
|
-
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
|
|
11
|
-
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
|
12
|
-
|
|
13
|
-
use std::cell::RefCell;
|
|
14
|
-
use std::collections::{BTreeMap, BTreeSet};
|
|
15
|
-
use std::ops::Deref;
|
|
16
|
-
use std::rc::Rc;
|
|
17
|
-
|
|
18
|
-
use wasm_bindgen::JsCast;
|
|
19
|
-
|
|
20
|
-
use crate::*;
|
|
21
|
-
|
|
22
|
-
type CSSResource = (&'static str, &'static str);
|
|
23
|
-
|
|
24
|
-
/// A dictionary of CSS fragments for native HTML elements which should always
|
|
25
|
-
/// be loaded (and perhaps lack yew components wrappers from which to have
|
|
26
|
-
/// their styles registered).
|
|
27
|
-
static DOM_STYLES: &[CSSResource] = &[
|
|
28
|
-
css!("dom/checkbox"),
|
|
29
|
-
css!("dom/scrollbar"),
|
|
30
|
-
css!("dom/select"),
|
|
31
|
-
];
|
|
32
|
-
|
|
33
|
-
thread_local! {
|
|
34
|
-
/// Cache of `CssStyleSheet` objects, which can safely be re-used across
|
|
35
|
-
/// `HTMLPerspectiveViewerElement` instances
|
|
36
|
-
static STYLE_SHEET_CACHE: RefCell<BTreeMap<&'static str, web_sys::CssStyleSheet>> = RefCell::new(
|
|
37
|
-
DOM_STYLES
|
|
38
|
-
.iter()
|
|
39
|
-
.map(|x| (x.0, StyleCache::into_style(x.1)))
|
|
40
|
-
.collect(),
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/// A state object for `<style>` snippets used by a yew `Component` with a
|
|
45
|
-
/// `<StyleProvider>` at the root.
|
|
46
|
-
#[derive(Clone)]
|
|
47
|
-
pub struct StyleCache(Rc<StyleCacheData>);
|
|
48
|
-
|
|
49
|
-
impl Deref for StyleCache {
|
|
50
|
-
type Target = StyleCacheData;
|
|
51
|
-
|
|
52
|
-
fn deref(&self) -> &Self::Target {
|
|
53
|
-
&self.0
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
impl PartialEq for StyleCache {
|
|
58
|
-
fn eq(&self, _other: &Self) -> bool {
|
|
59
|
-
true
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
impl StyleCache {
|
|
64
|
-
pub fn new(is_shadow: bool, elem: &web_sys::HtmlElement) -> StyleCache {
|
|
65
|
-
StyleCache(Rc::new(StyleCacheData::new(is_shadow, elem)))
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/// Insert a new stylesheet into this manager, _immediately_ inserting it
|
|
69
|
-
/// into the DOM as well if any other elements are already connected,
|
|
70
|
-
/// bypassing yew rendering; when the yew `Component::view` method is
|
|
71
|
-
/// later invoked, this element will get re-attached to the same parent
|
|
72
|
-
/// (though likely in a different order).
|
|
73
|
-
///
|
|
74
|
-
/// This is done synchronously because CSS registration occurs during
|
|
75
|
-
/// the `create` lifecycle phase, and we want these style elements to be
|
|
76
|
-
/// attached _before_ the style's target nodes are attached.
|
|
77
|
-
pub fn add_style(&self, name: &'static str, css: &'static str) {
|
|
78
|
-
let mut map = self.0.styles.borrow_mut();
|
|
79
|
-
STYLE_SHEET_CACHE.with_borrow_mut(|cache| {
|
|
80
|
-
if !map.contains(name) {
|
|
81
|
-
map.insert(name);
|
|
82
|
-
if !cache.contains_key(name) {
|
|
83
|
-
let style = Self::into_style(css);
|
|
84
|
-
cache.insert(name, style);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
self.adopted_style_sheets.splice(
|
|
88
|
-
map.iter().position(|x| x == &name).unwrap() as u32,
|
|
89
|
-
0,
|
|
90
|
-
cache.get(name).unwrap(),
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/// Concert a CSS string to an `HtmlStyleElement`, which are memoized due
|
|
97
|
-
/// to their size and DOM performance impact.
|
|
98
|
-
fn into_style(css: &str) -> web_sys::CssStyleSheet {
|
|
99
|
-
let sheet = web_sys::CssStyleSheet::new().unwrap();
|
|
100
|
-
sheet.replace_sync(css).unwrap();
|
|
101
|
-
sheet
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/// Using a `BTreeMap` so the resulting `<style>` elements have a stable order
|
|
106
|
-
/// when rendered to the DOM.
|
|
107
|
-
pub struct StyleCacheData {
|
|
108
|
-
styles: RefCell<BTreeSet<&'static str>>,
|
|
109
|
-
adopted_style_sheets: js_sys::Array,
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
impl StyleCacheData {
|
|
113
|
-
fn new(is_shadow: bool, elem: &web_sys::HtmlElement) -> Self {
|
|
114
|
-
let styles: RefCell<BTreeSet<&'static str>> =
|
|
115
|
-
RefCell::new(DOM_STYLES.iter().map(|x| x.0).collect());
|
|
116
|
-
|
|
117
|
-
let root: &JsValue = if is_shadow {
|
|
118
|
-
&elem.shadow_root().unwrap()
|
|
119
|
-
} else {
|
|
120
|
-
&web_sys::window().unwrap().document().unwrap()
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
let adopted_style_sheets = js_sys::Reflect::get(root, &"adoptedStyleSheets".into())
|
|
124
|
-
.unwrap()
|
|
125
|
-
.unchecked_into::<js_sys::Array>();
|
|
126
|
-
|
|
127
|
-
for name in styles.borrow().iter() {
|
|
128
|
-
STYLE_SHEET_CACHE.with_borrow(|x| adopted_style_sheets.push(x.get(name).unwrap()));
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
Self {
|
|
132
|
-
styles,
|
|
133
|
-
adopted_style_sheets,
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|