@olenbetong/synergi-react 5.0.0 → 5.2.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.
Files changed (168) hide show
  1. package/dist/styles/styles.css +1 -1
  2. package/dist/styles/styles.css.map +1 -1
  3. package/es/components/Checkbox/index.css +1 -1
  4. package/es/components/Checkbox/index.js +1 -9
  5. package/es/components/CodeEditor/CodeEditor.css +6 -6
  6. package/es/components/ColorCard/index.css +17 -28
  7. package/es/components/DateNavigator/index.css +5 -7
  8. package/es/components/FilePond.js +3 -12
  9. package/es/components/ImageEditor/ImageEditor.css +10 -10
  10. package/es/components/ImageEditor/ImageEditor.js +4 -4
  11. package/es/components/ImageEditor/ResponsiveButton.js +2 -2
  12. package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +1 -1
  13. package/es/components/ImageEditor/plugins/redactPlugin/RedactToolbar.js +1 -1
  14. package/es/components/ImageEditor/plugins/redactPlugin/useRedactTool.js +18 -14
  15. package/es/components/ImageEditor/useImageHistory.js +13 -1
  16. package/es/components/MergeProgressDialog/MergeProgressDialogDs.js +3 -3
  17. package/es/components/MergeProgressDialog/useMergeJob.js +5 -4
  18. package/es/components/PageBanner/index.css +1 -1
  19. package/es/components/PdfViewer/PdfViewer.js +1 -1
  20. package/es/components/Portal/index.js +20 -20
  21. package/es/components/Spinner/index.css +1 -1
  22. package/es/components/SplitContainer/index.css +1 -1
  23. package/es/components/SplitContainer/index.js +3 -1
  24. package/es/components/Toolbar/Toolbar.css +137 -137
  25. package/es/components/Toolbar/index.js +6 -1
  26. package/es/components/ValueToggleGroup/index.css +2 -2
  27. package/es/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.css +7 -7
  28. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.js +8 -0
  29. package/es/elements/ElementLookupDialog/HIDScanner/useHIDScanner.js +3 -1
  30. package/es/elements-ds/DescriptionInput.d.ts +16 -0
  31. package/es/elements-ds/DescriptionInput.js +41 -0
  32. package/es/elements-ds/DuplicateElementDamage.d.ts +40 -0
  33. package/es/elements-ds/DuplicateElementDamage.js +57 -0
  34. package/es/elements-ds/ElementLookup.d.ts +23 -0
  35. package/es/elements-ds/ElementLookup.js +35 -0
  36. package/es/elements-ds/ElementLookupDialog.d.ts +7 -0
  37. package/es/elements-ds/ElementLookupDialog.js +84 -0
  38. package/es/elements-ds/FormFields.d.ts +43 -0
  39. package/es/elements-ds/FormFields.js +67 -0
  40. package/es/elements-ds/HIDScanner.d.ts +7 -0
  41. package/es/elements-ds/HIDScanner.js +36 -0
  42. package/es/elements-ds/ManualForm.d.ts +7 -0
  43. package/es/elements-ds/ManualForm.js +70 -0
  44. package/es/elements-ds/ProjectSelect.d.ts +28 -0
  45. package/es/elements-ds/ProjectSelect.js +45 -0
  46. package/es/elements-ds/elements-ds.css +157 -0
  47. package/es/elements-ds/index.d.ts +12 -0
  48. package/es/elements-ds/index.js +14 -0
  49. package/es/index.css +1 -1
  50. package/es/useTranslation/index.js +5 -3
  51. package/package.json +16 -4
  52. package/src/chrome/AppShell/AppShell.test.tsx +48 -0
  53. package/src/chrome/AppShell/index.tsx +29 -29
  54. package/src/chrome/openReport.test.ts +50 -0
  55. package/src/chrome/openReport.ts +34 -34
  56. package/src/colorScheme.test.ts +188 -0
  57. package/src/colorScheme.ts +125 -125
  58. package/src/components/Checkbox/Checkbox.browser.test.tsx +116 -0
  59. package/src/components/Checkbox/index.scss +2 -2
  60. package/src/components/Checkbox/index.tsx +1 -10
  61. package/src/components/CodeEditor/CodeEditor.css +6 -6
  62. package/src/components/CodeEditor/CodeEditor.tsx +173 -173
  63. package/src/components/CodeEditor/index.ts +1 -1
  64. package/src/components/ColorCard/ColorCard.test.tsx +34 -0
  65. package/src/components/ColorCard/index.css +17 -28
  66. package/src/components/DateNavigator/DateNavigator.test.tsx +175 -0
  67. package/src/components/DateNavigator/index.css +5 -7
  68. package/src/components/DateNavigator/index.tsx +186 -186
  69. package/src/components/FilePond.browser.test.tsx +389 -0
  70. package/src/components/FilePond.tsx +303 -312
  71. package/src/components/ImageEditor/ImageEditor.browser.test.tsx +286 -0
  72. package/src/components/ImageEditor/ImageEditor.css +10 -10
  73. package/src/components/ImageEditor/ImageEditor.test.tsx +299 -0
  74. package/src/components/ImageEditor/ImageEditor.tsx +348 -348
  75. package/src/components/ImageEditor/ResponsiveButton.tsx +2 -2
  76. package/src/components/ImageEditor/index.ts +9 -9
  77. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +165 -165
  78. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +42 -48
  79. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.test.ts +225 -0
  80. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +405 -405
  81. package/src/components/ImageEditor/plugins/plugins.browser.test.ts +252 -0
  82. package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
  83. package/src/components/ImageEditor/plugins/redactPlugin/useRedactTool.test.ts +89 -0
  84. package/src/components/ImageEditor/plugins/redactPlugin/useRedactTool.ts +16 -13
  85. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
  86. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
  87. package/src/components/ImageEditor/plugins/zoomPlugin/useZoomPan.test.ts +154 -0
  88. package/src/components/ImageEditor/useActiveTool.ts +21 -21
  89. package/src/components/ImageEditor/useEdgeDetection.test.ts +96 -0
  90. package/src/components/ImageEditor/useEdgeDetection.ts +319 -319
  91. package/src/components/ImageEditor/useImageHistory.test.ts +409 -0
  92. package/src/components/ImageEditor/useImageHistory.ts +206 -197
  93. package/src/components/ImageEditor/useOpenCV.test.ts +208 -0
  94. package/src/components/ImageEditor/useOpenCV.ts +184 -184
  95. package/src/components/LinkedCardList/index.scss +95 -95
  96. package/src/components/MergeProgressDialog/MergeProgressDialogDs.browser.test.tsx +156 -0
  97. package/src/components/MergeProgressDialog/MergeProgressDialogDs.tsx +4 -3
  98. package/src/components/MergeProgressDialog/useMergeJob.test.ts +326 -0
  99. package/src/components/MergeProgressDialog/useMergeJob.ts +4 -3
  100. package/src/components/PageBanner/index.scss +10 -10
  101. package/src/components/PageBanner/index.tsx +80 -80
  102. package/src/components/PdfViewer/PdfViewer.browser.test.tsx +78 -0
  103. package/src/components/PdfViewer/PdfViewer.tsx +158 -158
  104. package/src/components/Portal/Portal.test.tsx +106 -0
  105. package/src/components/Portal/index.tsx +22 -25
  106. package/src/components/Sidebar/Sidebar.browser.test.tsx +57 -0
  107. package/src/components/Sidebar/Sidebar.test.tsx +123 -0
  108. package/src/components/Spinner/index.css +1 -1
  109. package/src/components/SplitContainer/SplitContainer.browser.test.tsx +304 -0
  110. package/src/components/SplitContainer/index.scss +5 -1
  111. package/src/components/SplitContainer/index.tsx +335 -333
  112. package/src/components/Toolbar/Toolbar.css +137 -137
  113. package/src/components/Toolbar/Toolbar.test.tsx +216 -0
  114. package/src/components/Toolbar/ToolbarBreadcrumbs.browser.test.tsx +137 -0
  115. package/src/components/Toolbar/index.tsx +270 -265
  116. package/src/components/ValueToggleGroup/ValueToggleGroup.test.tsx +112 -0
  117. package/src/components/ValueToggleGroup/index.css +2 -2
  118. package/src/designsystemet-web-types.d.ts +24 -24
  119. package/src/elements/ElementDamage/DamageFormButtons.tsx +35 -35
  120. package/src/elements/ElementDamage/DescriptionInput.tsx +120 -120
  121. package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +82 -82
  122. package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +67 -67
  123. package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +45 -45
  124. package/src/elements/ElementDamage/ElementNumberTextField.tsx +41 -41
  125. package/src/elements/ElementDamage/RegisterFix.tsx +100 -100
  126. package/src/elements/ElementDamage/SubmitButtons.tsx +40 -40
  127. package/src/elements/ElementDamage/TransportElementSelect.tsx +52 -52
  128. package/src/elements/ElementLookup.tsx +123 -123
  129. package/src/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.browser.test.tsx +175 -0
  130. package/src/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.css +7 -7
  131. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +8 -0
  132. package/src/elements/ElementLookupDialog/BarcodeScanner/engines.browser.test.ts +225 -0
  133. package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
  134. package/src/elements/ElementLookupDialog/HIDScanner/useHIDScanner.test.ts +124 -0
  135. package/src/elements/ElementLookupDialog/HIDScanner/useHIDScanner.ts +2 -1
  136. package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
  137. package/src/elements/ElementLookupDialog/getElement.test.ts +133 -0
  138. package/src/elements/ElementLookupDialog/index.tsx +226 -226
  139. package/src/elements/ElementLookupDialog/utils/Giai.test.ts +53 -0
  140. package/src/elements/ElementLookupDialog/utils/Giai.ts +209 -209
  141. package/src/elements/ProjectSelect.tsx +130 -130
  142. package/src/elements/index.ts +15 -15
  143. package/src/elements-ds/DamageForm.browser.test.tsx +530 -0
  144. package/src/elements-ds/DescriptionInput.tsx +114 -0
  145. package/src/elements-ds/DuplicateElementDamage.tsx +185 -0
  146. package/src/elements-ds/ElementLookup.tsx +114 -0
  147. package/src/elements-ds/ElementLookupDialog.browser.test.tsx +207 -0
  148. package/src/elements-ds/ElementLookupDialog.tsx +194 -0
  149. package/src/elements-ds/FormFields.tsx +176 -0
  150. package/src/elements-ds/HIDScanner.tsx +53 -0
  151. package/src/elements-ds/ManualForm.tsx +129 -0
  152. package/src/elements-ds/ProjectSelect.tsx +120 -0
  153. package/src/elements-ds/elements-ds.css +157 -0
  154. package/src/elements-ds/index.ts +16 -0
  155. package/src/filter/index.ts +34 -34
  156. package/src/i18n.test.ts +31 -0
  157. package/src/i18n.ts +13 -13
  158. package/src/mui/MuiThemeProvider.tsx +135 -135
  159. package/src/test/fakeCamera.ts +98 -0
  160. package/src/test/fakeDataApi.ts +90 -0
  161. package/src/test/setup.browser.ts +21 -0
  162. package/src/test/setup.ts +23 -23
  163. package/src/useTranslation/index.ts +5 -3
  164. package/src/useTranslation/useTranslation.test.ts +128 -0
  165. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.d.ts +0 -1
  166. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.js +0 -103
  167. package/es/test/setup.d.ts +0 -6
  168. package/es/test/setup.js +0 -6
@@ -0,0 +1,157 @@
1
+ /*
2
+ * Styles for the Designsystemet element components. The package is not scanned by the apps'
3
+ * Tailwind, so everything is a plain class here.
4
+ */
5
+
6
+ @property --ob-hid-angle {
7
+ syntax: "<angle>";
8
+ inherits: false;
9
+ initial-value: 0deg;
10
+ }
11
+
12
+ @keyframes ObElementsHidScanner-move {
13
+ 0% {
14
+ --ob-hid-angle: 0deg;
15
+ }
16
+ 50% {
17
+ --ob-hid-angle: 180deg;
18
+ }
19
+ 100% {
20
+ --ob-hid-angle: 360deg;
21
+ }
22
+ }
23
+
24
+ .ObElementsHidScanner-root {
25
+ height: 100%;
26
+ min-height: 12rem;
27
+ display: flex;
28
+ align-items: center;
29
+ justify-content: center;
30
+ background-color: var(--ds-color-neutral-surface-tinted);
31
+
32
+ &[data-enabled] {
33
+ background-image: linear-gradient(
34
+ var(--ob-hid-angle),
35
+ var(--ds-color-neutral-border-default),
36
+ var(--ds-color-neutral-surface-active),
37
+ var(--ds-color-neutral-border-default)
38
+ );
39
+ animation: ObElementsHidScanner-move 8s linear infinite;
40
+ }
41
+ }
42
+
43
+ .ObElementsLookupDialog-body {
44
+ display: flex;
45
+ flex-direction: column;
46
+ padding: 0;
47
+ min-height: 0;
48
+ overflow: hidden;
49
+
50
+ /* One height for every tab, so the dialog does not jump when the tab changes. */
51
+ @media (min-width: 600px) {
52
+ height: min(40rem, 85dvh);
53
+ }
54
+ }
55
+
56
+ .ObElementsLookupDialog-tabs > [role="tablist"] > * {
57
+ flex: 1;
58
+ flex-direction: column;
59
+ }
60
+
61
+ .ObElementsLookupDialog-source {
62
+ flex: 1 2 14rem;
63
+ min-height: 0;
64
+ }
65
+
66
+ /* The manual form keeps its full height; the element list below gives way first. */
67
+ .ObElementsLookupDialog-manual {
68
+ flex: 0 1 auto;
69
+ min-height: 0;
70
+ padding: var(--ds-size-4);
71
+ overflow-y: auto;
72
+ }
73
+
74
+ .ObElementsLookupDialog-list {
75
+ flex: 3 1 6rem;
76
+ overflow-y: auto;
77
+ }
78
+
79
+ .ObElementsLookupDialog-item {
80
+ transition: background-color 200ms ease-out;
81
+
82
+ &[data-recent] {
83
+ background-color: var(--ds-color-brand-surface-active);
84
+ }
85
+ }
86
+
87
+ .ObElementsLookupDialog-actions,
88
+ .ObElements-buttons {
89
+ display: flex;
90
+ flex-wrap: wrap;
91
+ justify-content: flex-end;
92
+ gap: var(--ds-size-2);
93
+ }
94
+
95
+ .ObElements-form {
96
+ display: flex;
97
+ flex-direction: column;
98
+ align-items: stretch;
99
+ gap: var(--ds-size-4);
100
+ }
101
+
102
+ .ObElements-subtle {
103
+ color: var(--ds-color-neutral-text-subtle);
104
+ }
105
+
106
+ .ObElements-option {
107
+ display: flex;
108
+ flex-direction: column;
109
+
110
+ & > :last-child {
111
+ font-size: 0.875em;
112
+ color: var(--ds-color-neutral-text-subtle);
113
+ }
114
+ }
115
+
116
+ .ObElementsDuplicate-table {
117
+ width: 100%;
118
+
119
+ & td {
120
+ white-space: pre-line;
121
+ vertical-align: top;
122
+ }
123
+ }
124
+
125
+ .ObElementsDuplicate-cards {
126
+ display: flex;
127
+ flex-direction: column;
128
+ gap: var(--ds-size-3);
129
+ }
130
+
131
+ .ObElementsDuplicate-wide {
132
+ @media (max-width: 899.98px) {
133
+ display: none;
134
+ }
135
+ }
136
+
137
+ .ObElementsDuplicate-narrow {
138
+ @media (min-width: 900px) {
139
+ display: none;
140
+ }
141
+ }
142
+
143
+ .ObElementsDuplicate-card dl {
144
+ display: grid;
145
+ grid-template-columns: auto 1fr;
146
+ gap: var(--ds-size-1) var(--ds-size-3);
147
+ margin: 0;
148
+
149
+ & dt {
150
+ font-weight: 500;
151
+ }
152
+
153
+ & dd {
154
+ margin: 0;
155
+ white-space: pre-line;
156
+ }
157
+ }
@@ -0,0 +1,16 @@
1
+ // The element lookup and element damage components on Designsystemet, for apps on the 2026
2
+ // template. Nothing here imports MUI or appframe-mui; "@olenbetong/synergi-react/elements" keeps
3
+ // the MUI versions for the apps that still use them.
4
+ import "./elements-ds.css";
5
+
6
+ export * from "../elements/data/index.js";
7
+ export { dsReportProjects } from "../elements/data/dsReportProjects.js";
8
+ export type { AddElementSource, ElementDetails } from "../elements/ElementLookupDialog/getElement.js";
9
+ export * from "./DescriptionInput.js";
10
+ export * from "./DuplicateElementDamage.js";
11
+ export * from "./ElementLookup.js";
12
+ export * from "./ElementLookupDialog.js";
13
+ export * from "./FormFields.js";
14
+ export * from "./HIDScanner.js";
15
+ export * from "./ManualForm.js";
16
+ export * from "./ProjectSelect.js";
@@ -1,34 +1,34 @@
1
- /**
2
- * The filter builder now lives in `@olenbetong/appframe-ds`, which is where the
3
- * Designsystemet components it is built from live. Re-exported here so existing
4
- * imports from `@olenbetong/synergi-react` keep working.
5
- *
6
- * @deprecated Import from `@olenbetong/appframe-ds` instead.
7
- */
8
- export {
9
- ChipListInput,
10
- type ChipListInputProps,
11
- FilterBuilder,
12
- type FilterBuilderProps,
13
- FilterEditor,
14
- type FilterEditorProps,
15
- type FilterEditorSize,
16
- FilterGroupEditor,
17
- type FilterGroupEditorProps,
18
- FilterNameDialog,
19
- type FilterNameDialogProps,
20
- FilterRow,
21
- type FilterRowProps,
22
- FilterShareDialog,
23
- type FilterShareDialogProps,
24
- FilterStringField,
25
- type FilterStringFieldProps,
26
- FilterValueEditor,
27
- type FilterValueEditorProps,
28
- type FilterValueOption,
29
- type GetFieldOptions,
30
- type SavedFilterSelection,
31
- SavedFilterTree,
32
- type SavedFilterTreeProps,
33
- type SavedFilterValues,
34
- } from "@olenbetong/appframe-ds";
1
+ /**
2
+ * The filter builder now lives in `@olenbetong/appframe-ds`, which is where the
3
+ * Designsystemet components it is built from live. Re-exported here so existing
4
+ * imports from `@olenbetong/synergi-react` keep working.
5
+ *
6
+ * @deprecated Import from `@olenbetong/appframe-ds` instead.
7
+ */
8
+ export {
9
+ ChipListInput,
10
+ type ChipListInputProps,
11
+ FilterBuilder,
12
+ type FilterBuilderProps,
13
+ FilterEditor,
14
+ type FilterEditorProps,
15
+ type FilterEditorSize,
16
+ FilterGroupEditor,
17
+ type FilterGroupEditorProps,
18
+ FilterNameDialog,
19
+ type FilterNameDialogProps,
20
+ FilterRow,
21
+ type FilterRowProps,
22
+ FilterShareDialog,
23
+ type FilterShareDialogProps,
24
+ FilterStringField,
25
+ type FilterStringFieldProps,
26
+ FilterValueEditor,
27
+ type FilterValueEditorProps,
28
+ type FilterValueOption,
29
+ type GetFieldOptions,
30
+ type SavedFilterSelection,
31
+ SavedFilterTree,
32
+ type SavedFilterTreeProps,
33
+ type SavedFilterValues,
34
+ } from "@olenbetong/appframe-ds";
@@ -0,0 +1,31 @@
1
+ import { afterEach, describe, expect, it } from "vitest";
2
+
3
+ import { getLocalizedString, PROJECT } from "./i18n";
4
+
5
+ let globals = globalThis as { af?: unknown };
6
+
7
+ afterEach(() => {
8
+ delete globals.af;
9
+ });
10
+
11
+ describe("getLocalizedString", () => {
12
+ it("returns the text unchanged on a page without af", () => {
13
+ expect(getLocalizedString("Toggle menu")).toBe("Toggle menu");
14
+ });
15
+
16
+ it("uses the package's own project, which the 2026 templates render", () => {
17
+ globals.af = {
18
+ article: { id: "fleet-map", i18n: { "Toggle menu": "Vis meny (artikkel)" } },
19
+ i18n: { "synergi-react": { "Toggle menu": "Vis/skjul meny" } },
20
+ };
21
+
22
+ expect(PROJECT).toBe("synergi-react");
23
+ expect(getLocalizedString("Toggle menu")).toBe("Vis/skjul meny");
24
+ });
25
+
26
+ it("falls back to the article's strings on a legacy template", () => {
27
+ globals.af = { article: { id: "fleet-map", i18n: { "Toggle menu": "Vis meny" } } };
28
+
29
+ expect(getLocalizedString("Toggle menu")).toBe("Vis meny");
30
+ });
31
+ });
package/src/i18n.ts CHANGED
@@ -1,13 +1,13 @@
1
- /*
2
- * The package's strings live in their own globalization project, `synergi-react`, so one
3
- * translation covers every app and the package can word a term its own way. The templates
4
- * render the dictionary as af.i18n["synergi-react"]; on a page that does not (a legacy
5
- * template) the localizer falls back to the article's strings, exactly as before. See
6
- * `createLocalizer` in @olenbetong/appframe-core.
7
- */
8
-
9
- import { createLocalizer } from "@olenbetong/appframe-core";
10
-
11
- export const PROJECT = "synergi-react";
12
-
13
- export const { getLocalizedString, localize } = createLocalizer(PROJECT);
1
+ /*
2
+ * The package's strings live in their own globalization project, `synergi-react`, so one
3
+ * translation covers every app and the package can word a term its own way. The templates
4
+ * render the dictionary as af.i18n["synergi-react"]; on a page that does not (a legacy
5
+ * template) the localizer falls back to the article's strings, exactly as before. See
6
+ * `createLocalizer` in @olenbetong/appframe-core.
7
+ */
8
+
9
+ import { createLocalizer } from "@olenbetong/appframe-core";
10
+
11
+ export const PROJECT = "synergi-react";
12
+
13
+ export const { getLocalizedString, localize } = createLocalizer(PROJECT);
@@ -1,135 +1,135 @@
1
- import { StyledEngineProvider, ThemeProvider } from "@mui/material";
2
- import { createTheme as muiCreateTheme } from "@mui/material/styles";
3
- import { type ReactNode, useEffect, useState } from "react";
4
-
5
- import { useResolvedColorScheme as useColorScheme } from "../colorScheme.js";
6
-
7
- function buildMuiTheme(mode: "light" | "dark") {
8
- const s = getComputedStyle(document.body);
9
- const get = (v: string) => s.getPropertyValue(v).trim();
10
- const isDark = mode === "dark";
11
-
12
- return muiCreateTheme({
13
- palette: {
14
- mode,
15
- primary: {
16
- main: get("--ds-color-brand-base-default") || "#116069",
17
- dark: get("--ds-color-brand-base-hover") || "#0d4b52",
18
- contrastText: get("--ds-color-brand-base-contrast-default") || "#ffffff",
19
- },
20
- secondary: {
21
- main: get("--ds-color-brand-light-base-default") || "#1a95a2",
22
- },
23
- background: {
24
- default: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
25
- paper: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
26
- },
27
- text: {
28
- primary: get("--ds-color-neutral-text-default") || (isDark ? "#e5e6e7" : "#292c30"),
29
- secondary: get("--ds-color-neutral-text-subtle") || (isDark ? "#b3b5b7" : "#5b5f64"),
30
- },
31
- divider: get("--ds-color-neutral-border-subtle") || (isDark ? "#4e5052" : "#bbbcbd"),
32
- },
33
- typography: {
34
- fontFamily: [
35
- "-apple-system",
36
- "BlinkMacSystemFont",
37
- '"Segoe UI"',
38
- "Roboto",
39
- '"Helvetica Neue"',
40
- "Arial",
41
- "sans-serif",
42
- '"Apple Color Emoji"',
43
- '"Segoe UI Emoji"',
44
- '"Segoe UI Symbol"',
45
- ].join(","),
46
- },
47
- components: {
48
- MuiTypography: {
49
- styleOverrides: {
50
- h1: { fontSize: "2.488rem" },
51
- h2: { fontSize: "2.074rem" },
52
- h3: { fontSize: "1.728rem" },
53
- h4: { fontSize: "1.44rem" },
54
- h5: { fontSize: "1.2rem" },
55
- h6: { fontSize: "1rem" },
56
- },
57
- },
58
- MuiAppBar: {
59
- styleOverrides: {
60
- root: {
61
- "& .MuiTypography-h1": {
62
- fontSize: "1.25rem",
63
- fontWeight: "500",
64
- },
65
- },
66
- },
67
- },
68
- MuiButton: {
69
- styleOverrides: {
70
- root: { borderRadius: 2 },
71
- },
72
- },
73
- MuiDialogTitle: {
74
- styleOverrides: {
75
- root: {
76
- fontSize: "1.2rem",
77
- fontWeight: 500,
78
- paddingLeft: 16,
79
- paddingRight: 16,
80
- },
81
- },
82
- },
83
- MuiFormLabel: {
84
- styleOverrides: {
85
- root: { color: get("--ds-color-neutral-text-subtle") || "rgba(0, 0, 0, 0.72)" },
86
- },
87
- },
88
- MuiTextField: { defaultProps: { variant: "filled" } },
89
- MuiSelect: { defaultProps: { variant: "filled" } },
90
- MuiFormControl: { defaultProps: { variant: "filled" } },
91
- },
92
- });
93
- }
94
-
95
- export type MuiThemeProviderProps = {
96
- children: ReactNode;
97
- };
98
-
99
- /**
100
- * Bridges Designsystemet's colour tokens into a MUI theme, so MUI components
101
- * (most notably the data grid) follow Designsystemet instead of MUI defaults.
102
- *
103
- * This lives in a separate entry point (`@olenbetong/synergi-react/mui`) so apps
104
- * that have migrated to Designsystemet don't pull ~160 kB of MUI and Emotion
105
- * into their bundle just by using `AppShell`. Wrap `AppShell` with it in apps
106
- * that still render MUI components:
107
- *
108
- * @example
109
- * ```tsx
110
- * import { AppShell } from "@olenbetong/synergi-react";
111
- * import { MuiThemeProvider } from "@olenbetong/synergi-react/mui";
112
- *
113
- * <MuiThemeProvider>
114
- * <AppShell>{children}</AppShell>
115
- * </MuiThemeProvider>
116
- * ```
117
- */
118
- export function MuiThemeProvider({ children }: MuiThemeProviderProps) {
119
- const colorScheme = useColorScheme();
120
-
121
- // Rebuilt whenever the color scheme changes so MUI components (notably the
122
- // data grid) follow Designsystemet instead of staying stuck in light mode.
123
- // Also re-read after mount, since the stylesheets are imported from JS and
124
- // the CSS variables aren't necessarily resolved during the first render.
125
- const [theme, setTheme] = useState(() => buildMuiTheme(colorScheme));
126
- useEffect(() => {
127
- setTheme(buildMuiTheme(colorScheme));
128
- }, [colorScheme]);
129
-
130
- return (
131
- <StyledEngineProvider injectFirst>
132
- <ThemeProvider theme={theme}>{children}</ThemeProvider>
133
- </StyledEngineProvider>
134
- );
135
- }
1
+ import { StyledEngineProvider, ThemeProvider } from "@mui/material";
2
+ import { createTheme as muiCreateTheme } from "@mui/material/styles";
3
+ import { type ReactNode, useEffect, useState } from "react";
4
+
5
+ import { useResolvedColorScheme as useColorScheme } from "../colorScheme.js";
6
+
7
+ function buildMuiTheme(mode: "light" | "dark") {
8
+ const s = getComputedStyle(document.body);
9
+ const get = (v: string) => s.getPropertyValue(v).trim();
10
+ const isDark = mode === "dark";
11
+
12
+ return muiCreateTheme({
13
+ palette: {
14
+ mode,
15
+ primary: {
16
+ main: get("--ds-color-brand-base-default") || "#116069",
17
+ dark: get("--ds-color-brand-base-hover") || "#0d4b52",
18
+ contrastText: get("--ds-color-brand-base-contrast-default") || "#ffffff",
19
+ },
20
+ secondary: {
21
+ main: get("--ds-color-brand-light-base-default") || "#1a95a2",
22
+ },
23
+ background: {
24
+ default: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
25
+ paper: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
26
+ },
27
+ text: {
28
+ primary: get("--ds-color-neutral-text-default") || (isDark ? "#e5e6e7" : "#292c30"),
29
+ secondary: get("--ds-color-neutral-text-subtle") || (isDark ? "#b3b5b7" : "#5b5f64"),
30
+ },
31
+ divider: get("--ds-color-neutral-border-subtle") || (isDark ? "#4e5052" : "#bbbcbd"),
32
+ },
33
+ typography: {
34
+ fontFamily: [
35
+ "-apple-system",
36
+ "BlinkMacSystemFont",
37
+ '"Segoe UI"',
38
+ "Roboto",
39
+ '"Helvetica Neue"',
40
+ "Arial",
41
+ "sans-serif",
42
+ '"Apple Color Emoji"',
43
+ '"Segoe UI Emoji"',
44
+ '"Segoe UI Symbol"',
45
+ ].join(","),
46
+ },
47
+ components: {
48
+ MuiTypography: {
49
+ styleOverrides: {
50
+ h1: { fontSize: "2.488rem" },
51
+ h2: { fontSize: "2.074rem" },
52
+ h3: { fontSize: "1.728rem" },
53
+ h4: { fontSize: "1.44rem" },
54
+ h5: { fontSize: "1.2rem" },
55
+ h6: { fontSize: "1rem" },
56
+ },
57
+ },
58
+ MuiAppBar: {
59
+ styleOverrides: {
60
+ root: {
61
+ "& .MuiTypography-h1": {
62
+ fontSize: "1.25rem",
63
+ fontWeight: "500",
64
+ },
65
+ },
66
+ },
67
+ },
68
+ MuiButton: {
69
+ styleOverrides: {
70
+ root: { borderRadius: 2 },
71
+ },
72
+ },
73
+ MuiDialogTitle: {
74
+ styleOverrides: {
75
+ root: {
76
+ fontSize: "1.2rem",
77
+ fontWeight: 500,
78
+ paddingLeft: 16,
79
+ paddingRight: 16,
80
+ },
81
+ },
82
+ },
83
+ MuiFormLabel: {
84
+ styleOverrides: {
85
+ root: { color: get("--ds-color-neutral-text-subtle") || "rgba(0, 0, 0, 0.72)" },
86
+ },
87
+ },
88
+ MuiTextField: { defaultProps: { variant: "filled" } },
89
+ MuiSelect: { defaultProps: { variant: "filled" } },
90
+ MuiFormControl: { defaultProps: { variant: "filled" } },
91
+ },
92
+ });
93
+ }
94
+
95
+ export type MuiThemeProviderProps = {
96
+ children: ReactNode;
97
+ };
98
+
99
+ /**
100
+ * Bridges Designsystemet's colour tokens into a MUI theme, so MUI components
101
+ * (most notably the data grid) follow Designsystemet instead of MUI defaults.
102
+ *
103
+ * This lives in a separate entry point (`@olenbetong/synergi-react/mui`) so apps
104
+ * that have migrated to Designsystemet don't pull ~160 kB of MUI and Emotion
105
+ * into their bundle just by using `AppShell`. Wrap `AppShell` with it in apps
106
+ * that still render MUI components:
107
+ *
108
+ * @example
109
+ * ```tsx
110
+ * import { AppShell } from "@olenbetong/synergi-react";
111
+ * import { MuiThemeProvider } from "@olenbetong/synergi-react/mui";
112
+ *
113
+ * <MuiThemeProvider>
114
+ * <AppShell>{children}</AppShell>
115
+ * </MuiThemeProvider>
116
+ * ```
117
+ */
118
+ export function MuiThemeProvider({ children }: MuiThemeProviderProps) {
119
+ const colorScheme = useColorScheme();
120
+
121
+ // Rebuilt whenever the color scheme changes so MUI components (notably the
122
+ // data grid) follow Designsystemet instead of staying stuck in light mode.
123
+ // Also re-read after mount, since the stylesheets are imported from JS and
124
+ // the CSS variables aren't necessarily resolved during the first render.
125
+ const [theme, setTheme] = useState(() => buildMuiTheme(colorScheme));
126
+ useEffect(() => {
127
+ setTheme(buildMuiTheme(colorScheme));
128
+ }, [colorScheme]);
129
+
130
+ return (
131
+ <StyledEngineProvider injectFirst>
132
+ <ThemeProvider theme={theme}>{children}</ThemeProvider>
133
+ </StyledEngineProvider>
134
+ );
135
+ }
@@ -0,0 +1,98 @@
1
+ /*
2
+ * An emulated camera for browser tests: a canvas, repainted continuously, whose stream is what
3
+ * `navigator.mediaDevices.getUserMedia` returns. Put generated barcode labels in front of it with
4
+ * `show`, take them away with `clear`. Everything downstream of `getUserMedia` - the `<video>`,
5
+ * the frame loop, the decoder reading the pixels - is the real code.
6
+ */
7
+ import { prepareZXingModule, writeBarcode } from "zxing-wasm/writer";
8
+ import writerWasmUrl from "zxing-wasm/writer/zxing_writer.wasm?url";
9
+ import { vi } from "vitest";
10
+
11
+ prepareZXingModule({
12
+ overrides: {
13
+ locateFile: (path: string, prefix: string) => (path.endsWith(".wasm") ? writerWasmUrl : prefix + path),
14
+ },
15
+ });
16
+
17
+ /** Group separator: some labels put it between the GIAI company prefix and asset reference. */
18
+ export const GS = "\u001d";
19
+
20
+ /**
21
+ * A GS1 DataMatrix for a GIAI (AI 8004), as a conformant label prints it: no separator inside
22
+ * the element string, so a reader sees `8004` + company prefix + asset reference.
23
+ */
24
+ export function createGs1Label(companyPrefix: string, assetReference: string) {
25
+ return createDataMatrix(`(8004)${companyPrefix}${assetReference}`, "gs1");
26
+ }
27
+
28
+ /** A plain DataMatrix whose content separates prefix and reference with GS, the legacy layout. */
29
+ export function createSeparatedLabel(companyPrefix: string, assetReference: string) {
30
+ return createDataMatrix(`8004${companyPrefix}${GS}${assetReference}`);
31
+ }
32
+
33
+ async function createDataMatrix(text: string, options = ""): Promise<ImageBitmap> {
34
+ let result = await writeBarcode(text, { format: "DataMatrix", options, scale: 8 });
35
+
36
+ if (!result.image) {
37
+ throw new Error(`Could not write a DataMatrix for "${text}": ${result.error}`);
38
+ }
39
+
40
+ return createImageBitmap(result.image);
41
+ }
42
+
43
+ type Placement = { image: ImageBitmap; x: number; y: number; size: number };
44
+
45
+ export type FakeCamera = {
46
+ /** Puts a label in view, `size` pixels wide (height to scale) with its top-left corner at `x`, `y`. */
47
+ show(image: ImageBitmap, placement?: Partial<Omit<Placement, "image">>): void;
48
+ /** Takes every label out of view. */
49
+ clear(): void;
50
+ getUserMedia: ReturnType<typeof vi.fn>;
51
+ /** Stops repainting and restores the browser's own media devices. */
52
+ restore(): void;
53
+ };
54
+
55
+ export function installFakeCamera({ width = 640, height = 480 } = {}): FakeCamera {
56
+ let canvas = document.createElement("canvas");
57
+ canvas.width = width;
58
+ canvas.height = height;
59
+ let context = canvas.getContext("2d")!;
60
+ let scene: Placement[] = [];
61
+
62
+ function paint() {
63
+ context.fillStyle = "#fff";
64
+ context.fillRect(0, 0, width, height);
65
+ for (let { image, x, y, size } of scene) {
66
+ context.drawImage(image, x, y, size, (size * image.height) / image.width);
67
+ }
68
+ }
69
+
70
+ // A canvas stream only carries a frame when the canvas is painted, so keep painting.
71
+ paint();
72
+ let timer = setInterval(paint, 1000 / 30);
73
+
74
+ let getUserMedia = vi.fn(async () => canvas.captureStream(30));
75
+ let getUserMediaSpy = vi.spyOn(navigator.mediaDevices, "getUserMedia").mockImplementation(getUserMedia);
76
+ let enumerateSpy = vi
77
+ .spyOn(navigator.mediaDevices, "enumerateDevices")
78
+ .mockResolvedValue([
79
+ { deviceId: "fake-camera", groupId: "", kind: "videoinput", label: "Fake camera", toJSON: () => ({}) },
80
+ ]);
81
+
82
+ return {
83
+ show(image, { size = 280, x = (width - size) / 2, y = (height - (size * image.height) / image.width) / 2 } = {}) {
84
+ scene.push({ image, x, y, size });
85
+ paint();
86
+ },
87
+ clear() {
88
+ scene = [];
89
+ paint();
90
+ },
91
+ getUserMedia,
92
+ restore() {
93
+ clearInterval(timer);
94
+ getUserMediaSpy.mockRestore();
95
+ enumerateSpy.mockRestore();
96
+ },
97
+ };
98
+ }