@_unit/unit 1.0.25 → 1.0.26

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/src/API.ts CHANGED
@@ -218,7 +218,6 @@ export type API = {
218
218
  getSelection(): Selection
219
219
  createRange(): Range
220
220
  exitPictureInPicture(): Promise<void>
221
- setTheme(theme: Theme): Promise<void>
222
221
  MutationObserver: IMutationObserverConstructor
223
222
  PositionObserver: IPositionObserverCostructor
224
223
  ResizeObserver: IResizeObserverConstructor
@@ -234,4 +233,7 @@ export type API = {
234
233
  worker: {
235
234
  start(): Worker
236
235
  }
236
+ theme: {
237
+ setTheme(theme: Theme): Promise<void>
238
+ }
237
239
  }
@@ -70,7 +70,7 @@ export const UI_EVENT_SET: Set<IOUIEventName> = new Set([
70
70
  'message',
71
71
  'toggle',
72
72
  'show',
73
- 'hide'
73
+ 'hide',
74
74
  ])
75
75
 
76
76
  export function makeUIEventListener(
@@ -4,7 +4,6 @@ import { PositionObserver } from '../../../PositionObserver'
4
4
  import { NoopIntersectionObserver } from '../../../noop/IntersectionObserver'
5
5
  import { NoopMutationObserver } from '../../../noop/MutationObserver'
6
6
  import { NoopResizeObserver } from '../../../noop/ResizeObserver'
7
- import { Theme, themeBackgroundColor } from '../../../theme'
8
7
 
9
8
  export function webDocument(
10
9
  window: Window,
@@ -58,11 +57,6 @@ export function webDocument(
58
57
  ResizeObserver: ResizeObserver,
59
58
  PositionObserver: PositionObserver,
60
59
  IntersectionObserver: IntersectionObserver,
61
- setTheme: async function (theme: Theme): Promise<void> {
62
- const color = themeBackgroundColor(theme)
63
-
64
- document.body.style.backgroundColor = color
65
- },
66
60
  }
67
61
 
68
62
  return _document
@@ -0,0 +1,19 @@
1
+ import { API } from '../../../../API'
2
+ import { BootOpt } from '../../../../system'
3
+ import { Theme, themeBackgroundColor } from '../../../theme'
4
+
5
+ export function webTheme(
6
+ window: Window,
7
+ root: HTMLElement,
8
+ opt: BootOpt
9
+ ): API['theme'] {
10
+ const theme: API['theme'] = {
11
+ setTheme: async function (theme: Theme): Promise<void> {
12
+ const color = themeBackgroundColor(theme)
13
+
14
+ root.style.backgroundColor = color
15
+ },
16
+ }
17
+
18
+ return theme
19
+ }
@@ -37,6 +37,7 @@ import { webSelection } from './api/selection'
37
37
  import { webSpeech } from './api/speech'
38
38
  import { webStorage } from './api/storage'
39
39
  import { webText } from './api/text'
40
+ import { webTheme } from './api/theme'
40
41
  import { webURI } from './api/uri'
41
42
  import { webURL } from './api/url'
42
43
  import { webWindow } from './api/window'
@@ -92,6 +93,7 @@ export function webBoot(
92
93
  const _window = webWindow(window, opt)
93
94
  const navigator = webNavigator(window, opt)
94
95
  const layout = webLayout(window, opt)
96
+ const theme = webTheme(window, _root, opt)
95
97
 
96
98
  const api: API = {
97
99
  alert,
@@ -121,6 +123,7 @@ export function webBoot(
121
123
  uri,
122
124
  window: _window,
123
125
  navigator,
126
+ theme,
124
127
  }
125
128
 
126
129
  const system = boot(null, api, opt)
@@ -129,6 +132,8 @@ export function webBoot(
129
132
 
130
133
  system.root = _root
131
134
 
135
+ theme.setTheme(system.theme)
136
+
132
137
  attachSprite(system)
133
138
  attachStyle(system)
134
139
  attachApp(system)
package/src/host/none.ts CHANGED
@@ -225,9 +225,6 @@ export function noHost(): API {
225
225
  exitPictureInPicture() {
226
226
  throw new MethodNotImplementedError()
227
227
  },
228
- setTheme: function (theme: Theme): Promise<void> {
229
- throw new MethodNotImplementedError()
230
- },
231
228
  MutationObserver: null,
232
229
  PositionObserver: null,
233
230
  ResizeObserver: null,
@@ -317,6 +314,11 @@ export function noHost(): API {
317
314
  throw new MethodNotImplementedError()
318
315
  },
319
316
  },
317
+ theme: {
318
+ setTheme: function (theme: Theme): Promise<void> {
319
+ throw new MethodNotImplementedError()
320
+ },
321
+ },
320
322
  }
321
323
 
322
324
  return api
@@ -652,7 +652,7 @@ export default class GUI extends Element<HTMLDivElement, Props> {
652
652
  // console.log('GUI', '_on_context_theme_changed')
653
653
  const {
654
654
  api: {
655
- document: { setTheme },
655
+ theme: { setTheme },
656
656
  },
657
657
  } = this.$system
658
658
 
@@ -35,7 +35,6 @@ export default class Write<T> extends Functional<I<T>, O<T>> {
35
35
  async f({ value, data }: I<T>, done: Done<O<T>>) {
36
36
  try {
37
37
  await value.write(data)
38
-
39
38
  done({ data })
40
39
  } catch (err) {
41
40
  done(undefined, err.message)