@geode/opengeodeweb-front 10.44.0-rc.2 → 10.44.0-rc.4
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/.build/server/utils/cleanup.js +7 -2
- package/.build/server/utils/microservices.js +9 -81
- package/.build/server/utils/microservices_process.js +85 -0
- package/.build/server/utils/typed_handler.js +5 -1
- package/.build/server/utils/ws_client.js +7 -2
- package/.build/shared/utils/fetch_raw.js +2 -2
- package/.build/shared/utils/parse_boolean.js +2 -1
- package/app/components/ClippingPlanes.vue +22 -78
- package/app/components/DragAndDrop.vue +16 -79
- package/app/components/FileSelector.vue +9 -6
- package/app/components/HybridViewerTooltip.vue +8 -2
- package/app/components/MissingFilesSelector.vue +10 -6
- package/app/components/ObjectSelector.vue +6 -3
- package/app/components/Screenshot.vue +9 -2
- package/app/components/ThresholdCard.vue +205 -0
- package/app/components/ThresholdFilter.vue +81 -216
- package/app/components/ViewToolbar.vue +15 -231
- package/app/components/Viewer/EdgedCurve/SpecificEdgesColoring.vue +209 -0
- package/app/components/Viewer/EdgedCurve/SpecificEdgesOptions.vue +3 -191
- package/app/components/Viewer/Generic/Mesh/CellsColoring.vue +228 -0
- package/app/components/Viewer/Generic/Mesh/CellsOptions.vue +3 -210
- package/app/components/Viewer/Generic/Mesh/EdgesColoring.vue +211 -0
- package/app/components/Viewer/Generic/Mesh/EdgesOptions.vue +3 -192
- package/app/components/Viewer/Generic/Mesh/PolygonsColoring.vue +234 -0
- package/app/components/Viewer/Generic/Mesh/PolygonsOptions.vue +3 -215
- package/app/components/Viewer/Generic/Mesh/PolyhedraColoring.vue +221 -0
- package/app/components/Viewer/Generic/Mesh/PolyhedraOptions.vue +3 -203
- package/app/components/Viewer/Generic/Model/BlocksOptions.vue +7 -5
- package/app/components/Viewer/Generic/Model/ComponentPointsOptions.vue +2 -18
- package/app/components/Viewer/Generic/Model/CornerComponentOptions.vue +145 -0
- package/app/components/Viewer/Generic/Model/CornersOptions.vue +13 -292
- package/app/components/Viewer/Generic/Model/CornersTypeOptions.vue +173 -0
- package/app/components/Viewer/Generic/Model/LineComponentOptions.vue +218 -0
- package/app/components/Viewer/Generic/Model/LinesOptions.vue +13 -425
- package/app/components/Viewer/Generic/Model/LinesTypeOptions.vue +229 -0
- package/app/components/Viewer/Generic/Model/ModelEdgesCard.vue +12 -10
- package/app/components/Viewer/Generic/Model/ModelPointsCard.vue +12 -10
- package/app/components/Viewer/Generic/Model/SurfacesOptions.vue +9 -5
- package/app/components/Viewer/ObjectTree/Base/ComponentRelations.vue +4 -1
- package/app/components/Viewer/ObjectTree/Views/GlobalObjects.vue +6 -1
- package/app/components/Viewer/Options/AttributeRangeSelector.vue +11 -4
- package/app/components/Viewer/Options/AttributeSelector.vue +40 -136
- package/app/components/Viewer/Options/ColorPicker.vue +4 -1
- package/app/components/Viewer/Options/ColoringTypeSelector.vue +36 -74
- package/app/components/Viewer/Options/ColormapQuickPicker.vue +13 -7
- package/app/components/Viewer/Options/NoDataColorInfo.vue +56 -0
- package/app/components/Viewer/Solid/SpecificPolyhedraColoring.vue +217 -0
- package/app/components/Viewer/Solid/SpecificPolyhedraOptions.vue +4 -199
- package/app/components/Viewer/Surface/PolygonsColoring.vue +231 -0
- package/app/components/Viewer/Surface/PolygonsOptions.vue +3 -213
- package/app/components/csv-preview/CsvPreviewer.vue +4 -1
- package/app/composables/attribute_coloring_style.ts +8 -2
- package/app/composables/attribute_selector.ts +126 -0
- package/app/composables/clipping_slices.ts +166 -0
- package/app/composables/global_attribute_style.ts +4 -3
- package/app/composables/hover_highlight.ts +6 -5
- package/app/composables/project_manager.ts +5 -5
- package/app/composables/stepper_tree.ts +10 -2
- package/app/composables/tree_filter.ts +11 -2
- package/app/composables/tree_keyboard_nav.ts +4 -2
- package/app/composables/use_overlapping_picker.ts +5 -5
- package/app/composables/view_toolbar_options.ts +126 -0
- package/app/composables/view_toolbar_tool_options.ts +115 -0
- package/app/composables/view_toolbar_tools.ts +108 -0
- package/app/composables/virtual_tree.ts +20 -131
- package/app/composables/virtual_tree_flatten.ts +86 -0
- package/app/composables/virtual_tree_types.ts +81 -0
- package/app/stores/app.ts +8 -55
- package/app/stores/app_helpers/extension.ts +1 -1
- package/app/stores/app_helpers/registry.ts +69 -0
- package/app/stores/feedback.ts +2 -2
- package/app/stores/hybrid_viewer.ts +1 -1
- package/app/stores/menu.ts +1 -124
- package/app/stores/menu_helpers/menus_data.ts +127 -0
- package/app/stores/treeview.ts +17 -10
- package/app/stores/viewer.ts +17 -78
- package/app/stores/viewer_helpers/actions.ts +68 -0
- package/app/stores/viewer_helpers/request.ts +61 -0
- package/app/utils/clipping_planes.ts +4 -131
- package/app/utils/clipping_planes_scene.ts +131 -0
- package/app/utils/coloring_styles.ts +101 -0
- package/app/utils/default_styles/mesh_components.ts +168 -0
- package/app/utils/default_styles/meshes.ts +13 -153
- package/app/utils/default_styles/model_components.ts +170 -0
- package/app/utils/default_styles/models.ts +16 -153
- package/app/utils/drag_and_drop.ts +80 -0
- package/app/utils/extension.ts +1 -1
- package/app/utils/import_workflow.ts +6 -4
- package/app/utils/model_component_coloring.ts +46 -0
- package/app/utils/threshold.ts +33 -0
- package/app/utils/threshold_sources.ts +51 -0
- package/app/utils/upload_path.ts +15 -9
- package/internal/database/database.ts +4 -1
- package/internal/stores/data_style/mesh/cells/cell.ts +27 -150
- package/internal/stores/data_style/mesh/cells/cell_attribute.ts +74 -0
- package/internal/stores/data_style/mesh/cells/cell_config.ts +152 -0
- package/internal/stores/data_style/mesh/cells/vertex.ts +26 -157
- package/internal/stores/data_style/mesh/cells/vertex_attribute.ts +80 -0
- package/internal/stores/data_style/mesh/cells/vertex_config.ts +152 -0
- package/internal/stores/data_style/mesh/edges/edge.ts +27 -150
- package/internal/stores/data_style/mesh/edges/edge_attribute.ts +74 -0
- package/internal/stores/data_style/mesh/edges/edge_config.ts +152 -0
- package/internal/stores/data_style/mesh/edges/vertex.ts +26 -157
- package/internal/stores/data_style/mesh/edges/vertex_attribute.ts +80 -0
- package/internal/stores/data_style/mesh/edges/vertex_config.ts +152 -0
- package/internal/stores/data_style/mesh/points/vertex.ts +26 -157
- package/internal/stores/data_style/mesh/points/vertex_attribute.ts +80 -0
- package/internal/stores/data_style/mesh/points/vertex_config.ts +152 -0
- package/internal/stores/data_style/mesh/polygons/polygon.ts +27 -152
- package/internal/stores/data_style/mesh/polygons/polygon_attribute.ts +80 -0
- package/internal/stores/data_style/mesh/polygons/polygon_config.ts +148 -0
- package/internal/stores/data_style/mesh/polygons/vertex.ts +26 -157
- package/internal/stores/data_style/mesh/polygons/vertex_attribute.ts +80 -0
- package/internal/stores/data_style/mesh/polygons/vertex_config.ts +152 -0
- package/internal/stores/data_style/mesh/polyhedra/polyhedron.ts +27 -160
- package/internal/stores/data_style/mesh/polyhedra/polyhedron_attribute.ts +82 -0
- package/internal/stores/data_style/mesh/polyhedra/polyhedron_config.ts +157 -0
- package/internal/stores/data_style/mesh/polyhedra/vertex.ts +26 -157
- package/internal/stores/data_style/mesh/polyhedra/vertex_attribute.ts +80 -0
- package/internal/stores/data_style/mesh/polyhedra/vertex_config.ts +152 -0
- package/internal/stores/data_style/model/blocks/apply_coloring.ts +173 -0
- package/internal/stores/data_style/model/blocks/coloring_groups.ts +18 -0
- package/internal/stores/data_style/model/blocks/index.ts +12 -140
- package/internal/stores/data_style/model/blocks/polyhedron.ts +14 -10
- package/internal/stores/data_style/model/blocks/vertex.ts +14 -10
- package/internal/stores/data_style/model/common.ts +10 -119
- package/internal/stores/data_style/model/common_mutations.ts +184 -0
- package/internal/stores/data_style/model/corners/vertex.ts +14 -10
- package/internal/stores/data_style/model/lines/apply_coloring.ts +154 -0
- package/internal/stores/data_style/model/lines/coloring_groups.ts +18 -0
- package/internal/stores/data_style/model/lines/edge.ts +14 -10
- package/internal/stores/data_style/model/lines/index.ts +10 -134
- package/internal/stores/data_style/model/lines/vertex.ts +14 -10
- package/internal/stores/data_style/model/surfaces/apply_coloring.ts +186 -0
- package/internal/stores/data_style/model/surfaces/coloring_groups.ts +18 -0
- package/internal/stores/data_style/model/surfaces/index.ts +16 -160
- package/internal/stores/data_style/model/surfaces/polygon.ts +14 -10
- package/internal/stores/data_style/model/surfaces/vertex.ts +14 -10
- package/internal/stores/data_style/model/visibility.ts +3 -156
- package/internal/stores/data_style/model/visibility_dispatch.ts +160 -0
- package/internal/stores/data_style/state.ts +1 -181
- package/internal/stores/data_style/state_shared.ts +191 -0
- package/internal/stores/hybrid_viewer/brightness.ts +8 -2
- package/internal/stores/hybrid_viewer/camera.ts +7 -161
- package/internal/stores/hybrid_viewer/camera_animation.ts +4 -3
- package/internal/stores/hybrid_viewer/camera_helpers.ts +120 -0
- package/internal/stores/hybrid_viewer/camera_orientation.ts +60 -0
- package/internal/stores/hybrid_viewer/filters.ts +54 -11
- package/internal/stores/hybrid_viewer/highlight.ts +10 -9
- package/internal/stores/hybrid_viewer/ruler.ts +4 -3
- package/internal/utils/ws_client.ts +8 -1
- package/package.json +2 -2
- package/server/api/local/extensions/run.post.ts +6 -4
- package/server/utils/cleanup.ts +12 -2
- package/server/utils/microservices.ts +10 -102
- package/server/utils/microservices_process.ts +127 -0
- package/server/utils/typed_handler.ts +8 -1
- package/server/utils/ws_client.ts +15 -2
- package/shared/utils/fetch_raw.ts +2 -2
- package/shared/utils/parse_boolean.ts +4 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { MESH_COMPONENT_TYPES } from "@ogw_front/utils/default_styles";
|
|
2
|
+
import { useDataStore } from "@ogw_front/stores/data";
|
|
3
|
+
|
|
4
|
+
// The four per-component-type style composables (Surface/Line/Block/Corner) each expose a different, large set of methods (color, visibility, per-attribute-kind getters/setters...). This module only cares about looking a handful of them up dynamically by name, so a precise structural type for componentStyleFunctions isn't worth modelling here; `any` keeps the dynamic dispatch table honest about that.
|
|
5
|
+
// oxlint-disable-next-line no-explicit-any
|
|
6
|
+
type ComponentStyleFunctions = Record<"Surface" | "Line" | "Block" | "Corner", any>;
|
|
7
|
+
|
|
8
|
+
interface ModelComponent {
|
|
9
|
+
geode_id: string;
|
|
10
|
+
type: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async function callComponentStyleFunction(
|
|
14
|
+
// oxlint-disable-next-line no-explicit-any
|
|
15
|
+
target: any,
|
|
16
|
+
method: string,
|
|
17
|
+
...args: unknown[]
|
|
18
|
+
): Promise<unknown> {
|
|
19
|
+
// oxlint-disable-next-line no-unsafe-call, no-unsafe-member-access, no-unsafe-argument, no-unsafe-assignment -- ComponentStyleFunctions is deliberately dynamically typed; see comment above.
|
|
20
|
+
const result = await target[method](...args);
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function getModelComponentsMap(
|
|
25
|
+
modelId: string,
|
|
26
|
+
): Promise<{ allComponents: ModelComponent[]; componentsMap: Record<string, ModelComponent> }> {
|
|
27
|
+
const dataStore = useDataStore();
|
|
28
|
+
const results = await Promise.all(
|
|
29
|
+
MESH_COMPONENT_TYPES.map(async (type) => {
|
|
30
|
+
const geodeIds = await dataStore.getMeshComponentGeodeIds(modelId, type);
|
|
31
|
+
return geodeIds.map((geode_id): ModelComponent => ({
|
|
32
|
+
geode_id,
|
|
33
|
+
type,
|
|
34
|
+
}));
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
const allComponents = results.flat();
|
|
38
|
+
return {
|
|
39
|
+
allComponents,
|
|
40
|
+
componentsMap: Object.fromEntries(
|
|
41
|
+
allComponents.map((component): [string, ModelComponent] => [component.geode_id, component]),
|
|
42
|
+
),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async function dispatchToComponentTypes(
|
|
46
|
+
modelId: string,
|
|
47
|
+
componentIds: string[],
|
|
48
|
+
action: string,
|
|
49
|
+
{ componentStyleFunctions }: { componentStyleFunctions: ComponentStyleFunctions },
|
|
50
|
+
...args: unknown[]
|
|
51
|
+
): Promise<unknown[]> {
|
|
52
|
+
const { componentsMap } = await getModelComponentsMap(modelId);
|
|
53
|
+
const idsByComponent: { Block: string[]; Surface: string[]; Line: string[]; Corner: string[] } = {
|
|
54
|
+
Block: [],
|
|
55
|
+
Surface: [],
|
|
56
|
+
Line: [],
|
|
57
|
+
Corner: [],
|
|
58
|
+
};
|
|
59
|
+
for (const id of componentIds) {
|
|
60
|
+
const type = componentsMap[id]?.type;
|
|
61
|
+
if (type !== undefined && type in idsByComponent) {
|
|
62
|
+
(idsByComponent as Record<string, string[]>)[type]?.push(id);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const promises: Promise<unknown>[] = [];
|
|
66
|
+
if (action === "Visibility") {
|
|
67
|
+
if (idsByComponent.Block.length > 0) {
|
|
68
|
+
promises.push(
|
|
69
|
+
callComponentStyleFunction(
|
|
70
|
+
componentStyleFunctions.Block,
|
|
71
|
+
"setModelBlocksVisibility",
|
|
72
|
+
modelId,
|
|
73
|
+
idsByComponent.Block,
|
|
74
|
+
...args,
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (idsByComponent.Surface.length > 0) {
|
|
79
|
+
promises.push(
|
|
80
|
+
callComponentStyleFunction(
|
|
81
|
+
componentStyleFunctions.Surface,
|
|
82
|
+
"setModelSurfacesVisibility",
|
|
83
|
+
modelId,
|
|
84
|
+
idsByComponent.Surface,
|
|
85
|
+
...args,
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (idsByComponent.Line.length > 0) {
|
|
90
|
+
promises.push(
|
|
91
|
+
callComponentStyleFunction(
|
|
92
|
+
componentStyleFunctions.Line,
|
|
93
|
+
"setModelLinesVisibility",
|
|
94
|
+
modelId,
|
|
95
|
+
idsByComponent.Line,
|
|
96
|
+
...args,
|
|
97
|
+
),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
if (idsByComponent.Corner.length > 0) {
|
|
101
|
+
promises.push(
|
|
102
|
+
callComponentStyleFunction(
|
|
103
|
+
componentStyleFunctions.Corner,
|
|
104
|
+
"setModelCornersVisibility",
|
|
105
|
+
modelId,
|
|
106
|
+
idsByComponent.Corner,
|
|
107
|
+
...args,
|
|
108
|
+
),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
} else if (action === "Color") {
|
|
112
|
+
if (idsByComponent.Block.length > 0) {
|
|
113
|
+
promises.push(
|
|
114
|
+
callComponentStyleFunction(
|
|
115
|
+
componentStyleFunctions.Block,
|
|
116
|
+
"setModelBlocksColor",
|
|
117
|
+
modelId,
|
|
118
|
+
idsByComponent.Block,
|
|
119
|
+
...args,
|
|
120
|
+
),
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
if (idsByComponent.Surface.length > 0) {
|
|
124
|
+
promises.push(
|
|
125
|
+
callComponentStyleFunction(
|
|
126
|
+
componentStyleFunctions.Surface,
|
|
127
|
+
"setModelSurfacesColor",
|
|
128
|
+
modelId,
|
|
129
|
+
idsByComponent.Surface,
|
|
130
|
+
...args,
|
|
131
|
+
),
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
if (idsByComponent.Line.length > 0) {
|
|
135
|
+
promises.push(
|
|
136
|
+
callComponentStyleFunction(
|
|
137
|
+
componentStyleFunctions.Line,
|
|
138
|
+
"setModelLinesColor",
|
|
139
|
+
modelId,
|
|
140
|
+
idsByComponent.Line,
|
|
141
|
+
...args,
|
|
142
|
+
),
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
if (idsByComponent.Corner.length > 0) {
|
|
146
|
+
promises.push(
|
|
147
|
+
callComponentStyleFunction(
|
|
148
|
+
componentStyleFunctions.Corner,
|
|
149
|
+
"setModelCornersColor",
|
|
150
|
+
modelId,
|
|
151
|
+
idsByComponent.Corner,
|
|
152
|
+
...args,
|
|
153
|
+
),
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return Promise.all(promises);
|
|
158
|
+
}
|
|
159
|
+
export { getModelComponentsMap, dispatchToComponentTypes };
|
|
160
|
+
export type { ComponentStyleFunctions };
|
|
@@ -4,189 +4,9 @@ import type {
|
|
|
4
4
|
ObjectStyle,
|
|
5
5
|
StyleValues,
|
|
6
6
|
} from "./types";
|
|
7
|
-
import
|
|
7
|
+
import { type SharedState, getSharedState } from "./state_shared";
|
|
8
8
|
import { getTable } from "@ogw_internal/database/database";
|
|
9
|
-
import { liveQuery } from "dexie";
|
|
10
9
|
import merge from "lodash/merge";
|
|
11
|
-
import { useObservable } from "@vueuse/rxjs";
|
|
12
|
-
|
|
13
|
-
interface SharedState {
|
|
14
|
-
styles: Ref<Record<string, ObjectStyle>>;
|
|
15
|
-
modelComponentTypeStyles: Ref<Record<string, ModelComponentTypeStyle>>;
|
|
16
|
-
componentStyles: Ref<Record<string, ModelComponentStyle>>;
|
|
17
|
-
loadFromDatabase: () => Promise<void>;
|
|
18
|
-
updateComponentStyleCache: (
|
|
19
|
-
modelId: string,
|
|
20
|
-
componentId: string,
|
|
21
|
-
styleValues: StyleValues,
|
|
22
|
-
) => void;
|
|
23
|
-
bulkUpdateComponentStyleCache: (
|
|
24
|
-
modelId: string,
|
|
25
|
-
componentStyleUpdates: readonly {
|
|
26
|
-
readonly id_component: string;
|
|
27
|
-
readonly values: StyleValues;
|
|
28
|
-
}[],
|
|
29
|
-
) => void;
|
|
30
|
-
bulkUpdateComponentStylesCache: (
|
|
31
|
-
modelId: string,
|
|
32
|
-
componentIds: readonly string[],
|
|
33
|
-
styleValues: StyleValues,
|
|
34
|
-
) => void;
|
|
35
|
-
updateModelComponentTypeStyleCache: (
|
|
36
|
-
modelId: string,
|
|
37
|
-
componentType: string,
|
|
38
|
-
styleValues: StyleValues,
|
|
39
|
-
) => void;
|
|
40
|
-
updateStyleCache: (objectId: string, styleValues: StyleValues) => void;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
let sharedState: SharedState | undefined = undefined;
|
|
44
|
-
|
|
45
|
-
// oxlint-disable-next-line max-lines-per-function
|
|
46
|
-
function getSharedState(): SharedState {
|
|
47
|
-
if (sharedState) {
|
|
48
|
-
return sharedState;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const dataStyleTable = getTable<ObjectStyle>("data_style");
|
|
52
|
-
const modelComponentDataStyleTable = getTable<ModelComponentStyle>("model_component_datastyle");
|
|
53
|
-
const modelComponentTypeDataStyleTable = getTable<ModelComponentTypeStyle>(
|
|
54
|
-
"model_component_type_datastyle",
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
// Dexie's `liveQuery` returns Dexie's own `Observable` type, structurally distinct
|
|
58
|
-
// From rxjs's `Observable` that `useObservable` (from @vueuse/rxjs) expects, even
|
|
59
|
-
// Though they're interoperable at runtime (both are plain subscribe-based streams).
|
|
60
|
-
const dataStyleLiveQuery = liveQuery(async () => {
|
|
61
|
-
const objectStyles = await dataStyleTable.toArray();
|
|
62
|
-
const stylesByObjectId: Record<string, ObjectStyle> = {};
|
|
63
|
-
for (const objectStyle of objectStyles) {
|
|
64
|
-
stylesByObjectId[objectStyle.id] = objectStyle;
|
|
65
|
-
}
|
|
66
|
-
return stylesByObjectId;
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
const styles = useObservable<Record<string, ObjectStyle>, Record<string, ObjectStyle>>(
|
|
70
|
-
// oxlint-disable-next-line no-unsafe-type-assertion
|
|
71
|
-
dataStyleLiveQuery as unknown as RxObservable<Record<string, ObjectStyle>>,
|
|
72
|
-
{ initialValue: {} },
|
|
73
|
-
) as Ref<Record<string, ObjectStyle>>;
|
|
74
|
-
|
|
75
|
-
const modelComponentTypeStyles = ref<Record<string, ModelComponentTypeStyle>>({});
|
|
76
|
-
const componentStyles = ref<Record<string, ModelComponentStyle>>({});
|
|
77
|
-
|
|
78
|
-
async function loadFromDatabase(): Promise<void> {
|
|
79
|
-
const [fetchedTypeStyles, fetchedComponentStyles] = await Promise.all([
|
|
80
|
-
modelComponentTypeDataStyleTable.toArray(),
|
|
81
|
-
modelComponentDataStyleTable.toArray(),
|
|
82
|
-
]);
|
|
83
|
-
const typeStylesMap: Record<string, ModelComponentTypeStyle> = {};
|
|
84
|
-
for (const typeStyle of fetchedTypeStyles) {
|
|
85
|
-
const cacheKey = `${typeStyle.id_model}_${typeStyle.type}`;
|
|
86
|
-
typeStylesMap[cacheKey] = typeStyle;
|
|
87
|
-
}
|
|
88
|
-
modelComponentTypeStyles.value = typeStylesMap;
|
|
89
|
-
|
|
90
|
-
const componentStylesMap: Record<string, ModelComponentStyle> = {};
|
|
91
|
-
for (const componentStyle of fetchedComponentStyles) {
|
|
92
|
-
const cacheKey = `${componentStyle.id_model}_${componentStyle.id_component}`;
|
|
93
|
-
componentStylesMap[cacheKey] = componentStyle;
|
|
94
|
-
}
|
|
95
|
-
componentStyles.value = componentStylesMap;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
void loadFromDatabase();
|
|
99
|
-
|
|
100
|
-
function updateComponentStyleCache(
|
|
101
|
-
modelId: string,
|
|
102
|
-
componentId: string,
|
|
103
|
-
styleValues: StyleValues,
|
|
104
|
-
): void {
|
|
105
|
-
const cacheKey = `${modelId}_${componentId}`;
|
|
106
|
-
const existingStyle = componentStyles.value[cacheKey];
|
|
107
|
-
if (existingStyle === undefined) {
|
|
108
|
-
componentStyles.value[cacheKey] = merge(
|
|
109
|
-
{ id_model: modelId, id_component: componentId },
|
|
110
|
-
styleValues,
|
|
111
|
-
);
|
|
112
|
-
} else {
|
|
113
|
-
merge(existingStyle, styleValues);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function bulkUpdateComponentStyleCache(
|
|
118
|
-
modelId: string,
|
|
119
|
-
componentStyleUpdates: readonly {
|
|
120
|
-
readonly id_component: string;
|
|
121
|
-
readonly values: StyleValues;
|
|
122
|
-
}[],
|
|
123
|
-
): void {
|
|
124
|
-
const updatedComponentStyles = { ...componentStyles.value };
|
|
125
|
-
for (const { id_component: componentId, values: styleValues } of componentStyleUpdates) {
|
|
126
|
-
const cacheKey = `${modelId}_${componentId}`;
|
|
127
|
-
const existingStyle = updatedComponentStyles[cacheKey];
|
|
128
|
-
if (existingStyle === undefined) {
|
|
129
|
-
updatedComponentStyles[cacheKey] = merge(
|
|
130
|
-
{ id_model: modelId, id_component: componentId },
|
|
131
|
-
styleValues,
|
|
132
|
-
);
|
|
133
|
-
} else {
|
|
134
|
-
updatedComponentStyles[cacheKey] = merge({}, existingStyle, styleValues);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
componentStyles.value = updatedComponentStyles;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function bulkUpdateComponentStylesCache(
|
|
141
|
-
modelId: string,
|
|
142
|
-
componentIds: readonly string[],
|
|
143
|
-
styleValues: StyleValues,
|
|
144
|
-
): void {
|
|
145
|
-
const updatedComponentStyles = { ...componentStyles.value };
|
|
146
|
-
for (const componentId of componentIds) {
|
|
147
|
-
const cacheKey = `${modelId}_${componentId}`;
|
|
148
|
-
const existingStyle = updatedComponentStyles[cacheKey];
|
|
149
|
-
if (existingStyle === undefined) {
|
|
150
|
-
updatedComponentStyles[cacheKey] = merge(
|
|
151
|
-
{ id_model: modelId, id_component: componentId },
|
|
152
|
-
styleValues,
|
|
153
|
-
);
|
|
154
|
-
} else {
|
|
155
|
-
updatedComponentStyles[cacheKey] = merge({}, existingStyle, styleValues);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
componentStyles.value = updatedComponentStyles;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function updateModelComponentTypeStyleCache(
|
|
162
|
-
modelId: string,
|
|
163
|
-
componentType: string,
|
|
164
|
-
styleValues: StyleValues,
|
|
165
|
-
): void {
|
|
166
|
-
const cacheKey = `${modelId}_${componentType}`;
|
|
167
|
-
modelComponentTypeStyles.value[cacheKey] ??= { id_model: modelId, type: componentType };
|
|
168
|
-
merge(modelComponentTypeStyles.value[cacheKey], styleValues);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function updateStyleCache(objectId: string, styleValues: StyleValues): void {
|
|
172
|
-
styles.value[objectId] ??= { id: objectId };
|
|
173
|
-
merge(styles.value[objectId], styleValues);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
sharedState = {
|
|
177
|
-
styles,
|
|
178
|
-
modelComponentTypeStyles,
|
|
179
|
-
componentStyles,
|
|
180
|
-
loadFromDatabase,
|
|
181
|
-
updateComponentStyleCache,
|
|
182
|
-
bulkUpdateComponentStyleCache,
|
|
183
|
-
bulkUpdateComponentStylesCache,
|
|
184
|
-
updateModelComponentTypeStyleCache,
|
|
185
|
-
updateStyleCache,
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
return sharedState;
|
|
189
|
-
}
|
|
190
10
|
|
|
191
11
|
interface DataStyleStateApi extends SharedState {
|
|
192
12
|
getStyle: (objectId: string) => ObjectStyle;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ModelComponentStyle,
|
|
3
|
+
ModelComponentTypeStyle,
|
|
4
|
+
ObjectStyle,
|
|
5
|
+
StyleValues,
|
|
6
|
+
} from "./types";
|
|
7
|
+
import type { Observable as RxObservable } from "rxjs";
|
|
8
|
+
import { getTable } from "@ogw_internal/database/database";
|
|
9
|
+
import { liveQuery } from "dexie";
|
|
10
|
+
import merge from "lodash/merge";
|
|
11
|
+
import { useObservable } from "@vueuse/rxjs";
|
|
12
|
+
|
|
13
|
+
interface SharedState {
|
|
14
|
+
styles: Ref<Record<string, ObjectStyle>>;
|
|
15
|
+
modelComponentTypeStyles: Ref<Record<string, ModelComponentTypeStyle>>;
|
|
16
|
+
componentStyles: Ref<Record<string, ModelComponentStyle>>;
|
|
17
|
+
loadFromDatabase: () => Promise<void>;
|
|
18
|
+
updateComponentStyleCache: (
|
|
19
|
+
modelId: string,
|
|
20
|
+
componentId: string,
|
|
21
|
+
styleValues: StyleValues,
|
|
22
|
+
) => void;
|
|
23
|
+
bulkUpdateComponentStyleCache: (
|
|
24
|
+
modelId: string,
|
|
25
|
+
componentStyleUpdates: readonly {
|
|
26
|
+
readonly id_component: string;
|
|
27
|
+
readonly values: StyleValues;
|
|
28
|
+
}[],
|
|
29
|
+
) => void;
|
|
30
|
+
bulkUpdateComponentStylesCache: (
|
|
31
|
+
modelId: string,
|
|
32
|
+
componentIds: readonly string[],
|
|
33
|
+
styleValues: StyleValues,
|
|
34
|
+
) => void;
|
|
35
|
+
updateModelComponentTypeStyleCache: (
|
|
36
|
+
modelId: string,
|
|
37
|
+
componentType: string,
|
|
38
|
+
styleValues: StyleValues,
|
|
39
|
+
) => void;
|
|
40
|
+
updateStyleCache: (objectId: string, styleValues: StyleValues) => void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let sharedState: SharedState | undefined = undefined;
|
|
44
|
+
|
|
45
|
+
// oxlint-disable-next-line max-lines-per-function
|
|
46
|
+
function getSharedState(): SharedState {
|
|
47
|
+
if (sharedState) {
|
|
48
|
+
return sharedState;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const dataStyleTable = getTable<ObjectStyle>("data_style");
|
|
52
|
+
const modelComponentDataStyleTable = getTable<ModelComponentStyle>("model_component_datastyle");
|
|
53
|
+
const modelComponentTypeDataStyleTable = getTable<ModelComponentTypeStyle>(
|
|
54
|
+
"model_component_type_datastyle",
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// Dexie's `liveQuery` returns Dexie's own `Observable` type, structurally distinct
|
|
58
|
+
// From rxjs's `Observable` that `useObservable` (from @vueuse/rxjs) expects, even
|
|
59
|
+
// Though they're interoperable at runtime (both are plain subscribe-based streams).
|
|
60
|
+
const dataStyleLiveQuery = liveQuery(async () => {
|
|
61
|
+
const objectStyles = await dataStyleTable.toArray();
|
|
62
|
+
const stylesByObjectId: Record<string, ObjectStyle> = {};
|
|
63
|
+
for (const objectStyle of objectStyles) {
|
|
64
|
+
stylesByObjectId[objectStyle.id] = objectStyle;
|
|
65
|
+
}
|
|
66
|
+
return stylesByObjectId;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const styles = useObservable<Record<string, ObjectStyle>, Record<string, ObjectStyle>>(
|
|
70
|
+
// oxlint-disable-next-line no-unsafe-type-assertion
|
|
71
|
+
dataStyleLiveQuery as unknown as RxObservable<Record<string, ObjectStyle>>,
|
|
72
|
+
{ initialValue: {} },
|
|
73
|
+
) as Ref<Record<string, ObjectStyle>>;
|
|
74
|
+
|
|
75
|
+
const modelComponentTypeStyles = ref<Record<string, ModelComponentTypeStyle>>({});
|
|
76
|
+
const componentStyles = ref<Record<string, ModelComponentStyle>>({});
|
|
77
|
+
|
|
78
|
+
async function loadFromDatabase(): Promise<void> {
|
|
79
|
+
const [fetchedTypeStyles, fetchedComponentStyles] = await Promise.all([
|
|
80
|
+
modelComponentTypeDataStyleTable.toArray(),
|
|
81
|
+
modelComponentDataStyleTable.toArray(),
|
|
82
|
+
]);
|
|
83
|
+
const typeStylesMap: Record<string, ModelComponentTypeStyle> = {};
|
|
84
|
+
for (const typeStyle of fetchedTypeStyles) {
|
|
85
|
+
const cacheKey = `${typeStyle.id_model}_${typeStyle.type}`;
|
|
86
|
+
typeStylesMap[cacheKey] = typeStyle;
|
|
87
|
+
}
|
|
88
|
+
modelComponentTypeStyles.value = typeStylesMap;
|
|
89
|
+
|
|
90
|
+
const componentStylesMap: Record<string, ModelComponentStyle> = {};
|
|
91
|
+
for (const componentStyle of fetchedComponentStyles) {
|
|
92
|
+
const cacheKey = `${componentStyle.id_model}_${componentStyle.id_component}`;
|
|
93
|
+
componentStylesMap[cacheKey] = componentStyle;
|
|
94
|
+
}
|
|
95
|
+
componentStyles.value = componentStylesMap;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
void loadFromDatabase();
|
|
99
|
+
|
|
100
|
+
function updateComponentStyleCache(
|
|
101
|
+
modelId: string,
|
|
102
|
+
componentId: string,
|
|
103
|
+
styleValues: StyleValues,
|
|
104
|
+
): void {
|
|
105
|
+
const cacheKey = `${modelId}_${componentId}`;
|
|
106
|
+
const existingStyle = componentStyles.value[cacheKey];
|
|
107
|
+
if (existingStyle === undefined) {
|
|
108
|
+
componentStyles.value[cacheKey] = merge(
|
|
109
|
+
{ id_model: modelId, id_component: componentId },
|
|
110
|
+
styleValues,
|
|
111
|
+
);
|
|
112
|
+
} else {
|
|
113
|
+
merge(existingStyle, styleValues);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function bulkUpdateComponentStyleCache(
|
|
118
|
+
modelId: string,
|
|
119
|
+
componentStyleUpdates: readonly {
|
|
120
|
+
readonly id_component: string;
|
|
121
|
+
readonly values: StyleValues;
|
|
122
|
+
}[],
|
|
123
|
+
): void {
|
|
124
|
+
const updatedComponentStyles = { ...componentStyles.value };
|
|
125
|
+
for (const { id_component: componentId, values: styleValues } of componentStyleUpdates) {
|
|
126
|
+
const cacheKey = `${modelId}_${componentId}`;
|
|
127
|
+
const existingStyle = updatedComponentStyles[cacheKey];
|
|
128
|
+
if (existingStyle === undefined) {
|
|
129
|
+
updatedComponentStyles[cacheKey] = merge(
|
|
130
|
+
{ id_model: modelId, id_component: componentId },
|
|
131
|
+
styleValues,
|
|
132
|
+
);
|
|
133
|
+
} else {
|
|
134
|
+
updatedComponentStyles[cacheKey] = merge({}, existingStyle, styleValues);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
componentStyles.value = updatedComponentStyles;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function bulkUpdateComponentStylesCache(
|
|
141
|
+
modelId: string,
|
|
142
|
+
componentIds: readonly string[],
|
|
143
|
+
styleValues: StyleValues,
|
|
144
|
+
): void {
|
|
145
|
+
const updatedComponentStyles = { ...componentStyles.value };
|
|
146
|
+
for (const componentId of componentIds) {
|
|
147
|
+
const cacheKey = `${modelId}_${componentId}`;
|
|
148
|
+
const existingStyle = updatedComponentStyles[cacheKey];
|
|
149
|
+
if (existingStyle === undefined) {
|
|
150
|
+
updatedComponentStyles[cacheKey] = merge(
|
|
151
|
+
{ id_model: modelId, id_component: componentId },
|
|
152
|
+
styleValues,
|
|
153
|
+
);
|
|
154
|
+
} else {
|
|
155
|
+
updatedComponentStyles[cacheKey] = merge({}, existingStyle, styleValues);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
componentStyles.value = updatedComponentStyles;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function updateModelComponentTypeStyleCache(
|
|
162
|
+
modelId: string,
|
|
163
|
+
componentType: string,
|
|
164
|
+
styleValues: StyleValues,
|
|
165
|
+
): void {
|
|
166
|
+
const cacheKey = `${modelId}_${componentType}`;
|
|
167
|
+
modelComponentTypeStyles.value[cacheKey] ??= { id_model: modelId, type: componentType };
|
|
168
|
+
merge(modelComponentTypeStyles.value[cacheKey], styleValues);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function updateStyleCache(objectId: string, styleValues: StyleValues): void {
|
|
172
|
+
styles.value[objectId] ??= { id: objectId };
|
|
173
|
+
merge(styles.value[objectId], styleValues);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
sharedState = {
|
|
177
|
+
styles,
|
|
178
|
+
modelComponentTypeStyles,
|
|
179
|
+
componentStyles,
|
|
180
|
+
loadFromDatabase,
|
|
181
|
+
updateComponentStyleCache,
|
|
182
|
+
bulkUpdateComponentStyleCache,
|
|
183
|
+
bulkUpdateComponentStylesCache,
|
|
184
|
+
updateModelComponentTypeStyleCache,
|
|
185
|
+
updateStyleCache,
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
return sharedState;
|
|
189
|
+
}
|
|
190
|
+
export { getSharedState };
|
|
191
|
+
export type { SharedState };
|
|
@@ -97,13 +97,19 @@ function computeAverageBrightness(rect: Rect, options: BrightnessOptions): numbe
|
|
|
97
97
|
return BACKGROUND_GREY_VALUE / RGB_MAX;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
+
function createOffscreenCanvas(): HTMLCanvasElement | undefined {
|
|
101
|
+
if (typeof document === "undefined") {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
return document.createElement("canvas");
|
|
105
|
+
}
|
|
106
|
+
|
|
100
107
|
function useHybridViewerBrightness(): {
|
|
101
108
|
latestImage: Ref<DrawableImage | undefined>;
|
|
102
109
|
getAverageBrightness: (rect: Rect) => number;
|
|
103
110
|
} {
|
|
104
111
|
const latestImage = ref<DrawableImage | undefined>(undefined);
|
|
105
|
-
const offscreenCanvas: HTMLCanvasElement | undefined =
|
|
106
|
-
typeof document === "undefined" ? undefined : document.createElement("canvas");
|
|
112
|
+
const offscreenCanvas: HTMLCanvasElement | undefined = createOffscreenCanvas();
|
|
107
113
|
const offscreenCtx: CanvasRenderingContext2D | undefined = offscreenCanvas
|
|
108
114
|
? (offscreenCanvas.getContext("2d", {
|
|
109
115
|
willReadFrequently: true,
|