@inglorious/web 6.1.1 → 6.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inglorious/web",
3
- "version": "6.1.1",
3
+ "version": "6.1.2",
4
4
  "description": "A new web framework that leverages the power of the Inglorious Store combined with the performance and simplicity of lit-html.",
5
5
  "author": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
6
6
  "license": "MIT",
@@ -19,11 +19,8 @@ export function create(entity) {
19
19
  entity.isSupported = isCompassSupported()
20
20
  entity.manualOffset ??= 0
21
21
  entity._absoluteListener ??= null
22
+ entity._cancelTimeout ??= null
22
23
  entity._orientationListener ??= null
23
- // True once a deviceorientationabsolute event fires; used to drop the
24
- // fallback deviceorientation listener so only one path updates heading.
25
- entity._isUsingAbsolute ??= false
26
- entity.compassTimeout ??= NO_TIMEOUT
27
24
  }
28
25
 
29
26
  export function destroy(entity) {
@@ -44,16 +41,15 @@ export function compassUnwatch(entity) {
44
41
  )
45
42
  }
46
43
 
47
- if (entity.compassTimeout !== NO_TIMEOUT) {
48
- clearTimeout(entity.compassTimeout)
44
+ if (entity._cancelTimeout) {
45
+ entity._cancelTimeout()
49
46
  }
50
47
 
51
48
  entity.isLoading = false
52
49
  entity.isActive = false
53
- entity.compassTimeout = NO_TIMEOUT
54
50
  entity._orientationListener = null
55
51
  entity._absoluteListener = null
56
- entity._isUsingAbsolute = false
52
+ entity._cancelTimeout = null
57
53
  }
58
54
 
59
55
  export function compassError(entity, error) {
@@ -101,12 +97,30 @@ export function compassPermissionsGrant(entity) {
101
97
  }
102
98
 
103
99
  export function compassWatch(entity, _, api) {
104
- entity._isUsingAbsolute = false
100
+ // Snapshot values from the entity while the proxy is still live.
101
+ // Closures must not access `entity` after this handler returns, as
102
+ // Mutative revokes the draft proxy at that point.
103
+ const manualOffset = entity.manualOffset
104
+
105
+ let isUsingAbsolute = false
106
+ let timeoutId = NO_TIMEOUT
107
+
108
+ const cancelTimeout = () => {
109
+ if (timeoutId !== NO_TIMEOUT) {
110
+ clearTimeout(timeoutId)
111
+ timeoutId = NO_TIMEOUT
112
+ }
113
+ }
114
+
115
+ const orientationListener = createOrientationChangeListener(
116
+ cancelTimeout,
117
+ manualOffset,
118
+ api,
119
+ )
105
120
 
106
- const orientationListener = createOrientationChangeListener(entity, api)
107
121
  const absoluteListener = (event) => {
108
- if (!entity._isUsingAbsolute) {
109
- entity._isUsingAbsolute = true
122
+ if (!isUsingAbsolute) {
123
+ isUsingAbsolute = true
110
124
  getWindow()?.removeEventListener("deviceorientation", orientationListener)
111
125
  }
112
126
 
@@ -115,23 +129,16 @@ export function compassWatch(entity, _, api) {
115
129
 
116
130
  entity._orientationListener = orientationListener
117
131
  entity._absoluteListener = absoluteListener
132
+ entity._cancelTimeout = cancelTimeout
118
133
 
119
134
  const win = getWindow()
120
135
  win?.addEventListener("deviceorientationabsolute", absoluteListener)
121
136
  win?.addEventListener("deviceorientation", orientationListener)
122
137
 
123
- entity.compassTimeout = globalThis.setTimeout(
124
- () => checkTimeout(entity, api),
125
- COMPASS_TIMEOUT,
126
- )
127
- }
128
-
129
- function checkTimeout(entity, api) {
130
- entity.compassTimeout = NO_TIMEOUT
131
-
132
- if (!entity.heading) {
138
+ timeoutId = globalThis.setTimeout(() => {
139
+ timeoutId = NO_TIMEOUT
133
140
  api.notify("compassActiveChange", false)
134
- }
141
+ }, COMPASS_TIMEOUT)
135
142
  }
136
143
 
137
144
  export function compassActiveChange(entity, value) {
@@ -143,22 +150,18 @@ export function compassHeadingChange(entity, value) {
143
150
  entity.heading = value
144
151
  }
145
152
 
146
- function createOrientationChangeListener(entity, api) {
153
+ function createOrientationChangeListener(cancelTimeout, manualOffset, api) {
147
154
  return (event) => {
148
155
  const heading = event?.alpha
149
156
  if (typeof heading !== "number") {
150
157
  return
151
158
  }
152
159
 
153
- if (entity.compassTimeout !== NO_TIMEOUT) {
154
- clearTimeout(entity.compassTimeout)
155
- entity.compassTimeout = NO_TIMEOUT
156
- }
160
+ cancelTimeout()
157
161
 
158
162
  const screenAngle = getScreenAngle()
159
163
  const adjustedHeading =
160
- (((heading - screenAngle + entity.manualOffset) % FULL_CIRCLE) +
161
- FULL_CIRCLE) %
164
+ (((heading - screenAngle + manualOffset) % FULL_CIRCLE) + FULL_CIRCLE) %
162
165
  FULL_CIRCLE
163
166
 
164
167
  api.notify("compassActiveChange", true)