@opencor/opencor 0.20250813.0 → 0.20250814.1

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-BxzyBYAw.js";
1
+ import { c as ce, g as gl } from "./index-Bwy89M_M.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.20250813.0",
45
+ "version": "0.20250814.1",
46
46
  "peerDependencies": {
47
47
  "vue": "^3.0.0"
48
48
  },
@@ -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 {
@@ -57,6 +57,8 @@ import primeVueToastService from 'primevue/toastservice'
57
57
  import { useToast } from 'primevue/usetoast'
58
58
  import * as vue from 'vue'
59
59
 
60
+ import type { IOpenCORProps } from '../../index'
61
+
60
62
  import '../assets/app.css'
61
63
  import * as common from '../common/common'
62
64
  import { SHORT_DELAY, TOAST_LIFE } from '../common/constants'
@@ -66,9 +68,7 @@ import * as vueCommon from '../common/vueCommon'
66
68
  import IContentsComponent from '../components/ContentsComponent.vue'
67
69
  import * as locApi from '../libopencor/locApi'
68
70
 
69
- const props = defineProps<{
70
- omex?: string
71
- }>()
71
+ const props = defineProps<IOpenCORProps>()
72
72
 
73
73
  // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
74
74
  const contents = vue.ref<InstanceType<typeof IContentsComponent> | null>(null)
@@ -80,19 +80,38 @@ const getCurrentInstance = vue.getCurrentInstance()
80
80
 
81
81
  if (getCurrentInstance !== null) {
82
82
  const app = getCurrentInstance.appContext.app
83
+ let options = {}
84
+
85
+ if (props.theme === 'light') {
86
+ options = {
87
+ darkModeSelector: false
88
+ }
89
+ } else if (props.theme === 'dark') {
90
+ document.documentElement.classList.add('opencor-dark-mode')
91
+ document.body.classList.add('opencor-dark-mode')
92
+
93
+ options = {
94
+ darkModeSelector: '.opencor-dark-mode'
95
+ }
96
+ }
83
97
 
84
98
  app.use(primeVueConfig as unknown as vue.Plugin, {
85
99
  theme: {
86
- preset: primeVueAuraTheme
100
+ preset: primeVueAuraTheme,
101
+ options: options
87
102
  }
88
103
  })
89
104
  app.use(primeVueConfirmationService as unknown as vue.Plugin)
90
105
  app.use(primeVueToastService as unknown as vue.Plugin)
91
106
  }
92
107
 
108
+ if (props.theme !== undefined) {
109
+ vueCommon.setTheme(props.theme)
110
+ }
111
+
93
112
  const toast = useToast()
94
113
 
95
- // Asynchronous initialise our libOpenCOR API.
114
+ // Asynchronously initialise our libOpenCOR API.
96
115
 
97
116
  const locApiInitialised = vue.ref(false)
98
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,