@opencor/opencor 0.20250814.0 → 0.20250814.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.
@@ -1,4 +1,4 @@
1
- import { c as ce, g as gl } from "./index-DnnuRqyP.js";
1
+ import { c as ce, g as gl } from "./index-tP7x8zIn.js";
2
2
  var pl = typeof global == "object" && global && global.Object === Object && global, yo = typeof self == "object" && self && self.Object === Object && self, Zt = pl || yo || Function("return this")(), de = Zt.Symbol, ml = Object.prototype, vo = ml.hasOwnProperty, Eo = ml.toString, yr = de ? de.toStringTag : void 0;
3
3
  function Ao(n) {
4
4
  var t = vo.call(n, yr), e = n[yr];
package/package.json CHANGED
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "./style.css": "./dist/opencor.css"
44
44
  },
45
- "version": "0.20250814.0",
45
+ "version": "0.20250814.4",
46
46
  "peerDependencies": {
47
47
  "vue": "^3.0.0"
48
48
  },
@@ -85,6 +85,7 @@
85
85
  "format": "prettier --log-level silent --write . && clang-format -i src/libopencor/src/*",
86
86
  "format:check": "prettier --check . && clang-format --dry-run -Werror src/libopencor/src/*",
87
87
  "lint": "eslint --fix .",
88
- "serve": "pnpm build && vite preview"
88
+ "serve": "pnpm build && vite preview",
89
+ "version:new": "node scripts/version.js"
89
90
  }
90
91
  }
@@ -1,17 +1,41 @@
1
1
  import * as vue from 'vue'
2
2
 
3
- // Some constants to know whether the operating system uses light mode or dark mode.
3
+ import type { Theme } from '../../index.js'
4
4
 
5
- const prefersColorScheme = window.matchMedia('(prefers-color-scheme: light)')
5
+ // Some constants to know whether the operating system uses light mode or dark mode.
6
6
 
7
- export const isLightMode = vue.ref(prefersColorScheme.matches)
8
- export const isDarkMode = vue.ref(!prefersColorScheme.matches)
7
+ const _prefersColorScheme = window.matchMedia('(prefers-color-scheme: light)')
8
+ const _isLightMode = vue.ref(_prefersColorScheme.matches)
9
+ const _isDarkMode = vue.ref(!_prefersColorScheme.matches)
10
+ let _theme: Theme = 'system'
9
11
 
10
- prefersColorScheme.addEventListener('change', (event) => {
11
- isLightMode.value = event.matches
12
- isDarkMode.value = !event.matches
12
+ _prefersColorScheme.addEventListener('change', (event) => {
13
+ if (_theme === 'system') {
14
+ _isLightMode.value = event.matches
15
+ _isDarkMode.value = !event.matches
16
+ }
13
17
  })
14
18
 
19
+ export function setTheme(theme: Theme) {
20
+ _theme = theme
21
+
22
+ if (theme === 'light') {
23
+ _isLightMode.value = true
24
+ _isDarkMode.value = false
25
+ } else if (theme === 'dark') {
26
+ _isLightMode.value = false
27
+ _isDarkMode.value = true
28
+ }
29
+ }
30
+
31
+ export function useLightMode(): boolean {
32
+ return _isLightMode.value
33
+ }
34
+
35
+ export function useDarkMode(): boolean {
36
+ return _isDarkMode.value
37
+ }
38
+
15
39
  // A method to track the height of a given element.
16
40
 
17
41
  export function trackElementHeight(id: string): void {
@@ -105,9 +105,13 @@ if (getCurrentInstance !== null) {
105
105
  app.use(primeVueToastService as unknown as vue.Plugin)
106
106
  }
107
107
 
108
+ if (props.theme !== undefined) {
109
+ vueCommon.setTheme(props.theme)
110
+ }
111
+
108
112
  const toast = useToast()
109
113
 
110
- // Asynchronous initialise our libOpenCOR API.
114
+ // Asynchronously initialise our libOpenCOR API.
111
115
 
112
116
  const locApiInitialised = vue.ref(false)
113
117
 
@@ -55,19 +55,19 @@ function themeData() {
55
55
 
56
56
  function axisThemeData() {
57
57
  return {
58
- zerolinecolor: vueCommon.isDarkMode.value ? '#71717a' : '#94a3b8', // --p-surface-500 / --p-surface-400
59
- gridcolor: vueCommon.isDarkMode.value ? '#3f3f46' : '#e2e8f0', // --p-surface-700 / --p-surface-200
58
+ zerolinecolor: vueCommon.useLightMode() ? '#94a3b8' : '#71717a', // --p-surface-400 / --p-surface-500
59
+ gridcolor: vueCommon.useLightMode() ? '#e2e8f0' : '#3f3f46', // --p-surface-200 / --p-surface-700
60
60
  minor: {
61
- gridcolor: vueCommon.isDarkMode.value ? '#27272a' : '#f1f5f9' // --p-surface-800 / --p-surface-100
61
+ gridcolor: vueCommon.useLightMode() ? '#f1f5f9' : '#27272a' // --p-surface-100 / --p-surface-800
62
62
  }
63
63
  }
64
64
  }
65
65
 
66
66
  return {
67
- paper_bgcolor: vueCommon.isDarkMode.value ? '#18181b' : '#ffffff', // --p-content-background
68
- plot_bgcolor: vueCommon.isDarkMode.value ? '#18181b' : '#ffffff', // --p-content-background
67
+ paper_bgcolor: vueCommon.useLightMode() ? '#ffffff' : '#18181b', // --p-content-background
68
+ plot_bgcolor: vueCommon.useLightMode() ? '#ffffff' : '#18181b', // --p-content-background
69
69
  font: {
70
- color: vueCommon.isDarkMode.value ? '#ffffff' : '#334155' // --p-text-color
70
+ color: vueCommon.useLightMode() ? '#334155' : '#ffffff' // --p-text-color
71
71
  },
72
72
  colorway: [
73
73
  '#7289ab', // Blue
@@ -84,7 +84,7 @@ function themeData() {
84
84
  }
85
85
 
86
86
  vue.watch(
87
- () => [plots, vueCommon.isDarkMode.value],
87
+ () => [plots, vueCommon.useLightMode()],
88
88
  () => {
89
89
  Plotly.react(
90
90
  mainDiv.value,