@glassly/miniapp 0.3.7 → 0.3.8-dev.976
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/dist/display/index.d.ts +1 -1
- package/dist/display/index.d.ts.map +1 -1
- package/dist/display/index.js +1 -1
- package/dist/display/index.js.map +1 -1
- package/dist/display/measurer/TextMeasurer.d.ts.map +1 -1
- package/dist/display/measurer/TextMeasurer.js +10 -1
- package/dist/display/measurer/TextMeasurer.js.map +1 -1
- package/dist/display/measurer/script-detection.d.ts +13 -0
- package/dist/display/measurer/script-detection.d.ts.map +1 -1
- package/dist/display/measurer/script-detection.js +84 -0
- package/dist/display/measurer/script-detection.js.map +1 -1
- package/dist/display/profiles/index.d.ts +2 -1
- package/dist/display/profiles/index.d.ts.map +1 -1
- package/dist/display/profiles/index.js +3 -2
- package/dist/display/profiles/index.js.map +1 -1
- package/dist/display/profiles/memomind-one.d.ts +3 -0
- package/dist/display/profiles/memomind-one.d.ts.map +1 -0
- package/dist/display/profiles/memomind-one.js +14 -0
- package/dist/display/profiles/memomind-one.js.map +1 -0
- package/dist/display/profiles/rayneo-io.d.ts +11 -1
- package/dist/display/profiles/rayneo-io.d.ts.map +1 -1
- package/dist/display/profiles/rayneo-io.js +73 -3
- package/dist/display/profiles/rayneo-io.js.map +1 -1
- package/dist/display/profiles/types.d.ts +5 -0
- package/dist/display/profiles/types.d.ts.map +1 -1
- package/dist/display/wrapper/TextWrapper.d.ts.map +1 -1
- package/dist/display/wrapper/TextWrapper.js +13 -18
- package/dist/display/wrapper/TextWrapper.js.map +1 -1
- package/dist/globals.d.ts +16 -4
- package/dist/globals.d.ts.map +1 -1
- package/dist/globals.js.map +1 -1
- package/dist/modules/actions.d.ts.map +1 -1
- package/dist/modules/actions.js +5 -1
- package/dist/modules/actions.js.map +1 -1
- package/dist/modules/navigation.d.ts +2 -0
- package/dist/modules/navigation.d.ts.map +1 -1
- package/dist/modules/navigation.js.map +1 -1
- package/dist/protocol.d.ts +6 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +6 -0
- package/dist/protocol.js.map +1 -1
- package/dist/react/capsuleHeaderLayout.d.ts +8 -1
- package/dist/react/capsuleHeaderLayout.d.ts.map +1 -1
- package/dist/react/capsuleHeaderLayout.js +11 -0
- package/dist/react/capsuleHeaderLayout.js.map +1 -1
- package/dist/react/useCapsuleHeaderStyle.d.ts +3 -1
- package/dist/react/useCapsuleHeaderStyle.d.ts.map +1 -1
- package/dist/react/useCapsuleHeaderStyle.js +3 -1
- package/dist/react/useCapsuleHeaderStyle.js.map +1 -1
- package/dist/react/useSafeArea.d.ts +13 -7
- package/dist/react/useSafeArea.d.ts.map +1 -1
- package/dist/react/useSafeArea.js +39 -10
- package/dist/react/useSafeArea.js.map +1 -1
- package/dist/session.d.ts +8 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +16 -0
- package/dist/session.js.map +1 -1
- package/package.json +2 -2
- package/src/display/index.ts +2 -0
- package/src/display/measurer/TextMeasurer.ts +9 -1
- package/src/display/measurer/script-detection.ts +90 -0
- package/src/display/profiles/index.ts +9 -2
- package/src/display/profiles/memomind-one.ts +15 -0
- package/src/display/profiles/rayneo-io.ts +79 -3
- package/src/display/profiles/types.ts +6 -0
- package/src/display/wrapper/TextWrapper.ts +13 -19
- package/src/globals.ts +16 -4
- package/src/modules/actions.ts +14 -7
- package/src/modules/navigation.ts +2 -0
- package/src/protocol.ts +7 -0
- package/src/react/capsuleHeaderLayout.ts +16 -1
- package/src/react/useCapsuleHeaderStyle.ts +3 -1
- package/src/react/useSafeArea.ts +49 -14
- package/src/session.ts +20 -0
|
@@ -145,6 +145,8 @@ export type NavPlaceSuggestion = {
|
|
|
145
145
|
mainText: string
|
|
146
146
|
/** Secondary line, e.g. "66 Mint St, San Francisco". Empty when none. */
|
|
147
147
|
secondaryText: string
|
|
148
|
+
/** Straight-line distance from `near` in meters. Absent without `near` or on older hosts. */
|
|
149
|
+
distanceMeters?: number
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
/** A place resolved from a suggestion via `placeDetails` — has coordinates to route to. */
|
package/src/protocol.ts
CHANGED
|
@@ -362,6 +362,13 @@ export enum MiniappResponseType {
|
|
|
362
362
|
/** Push: miniapp's foreground/background state changed. */
|
|
363
363
|
VISIBILITY_CHANGE = "miniapp_visibility_change",
|
|
364
364
|
|
|
365
|
+
/**
|
|
366
|
+
* Push: the user opened this already-running miniapp again. Carries
|
|
367
|
+
* {launchSource}: "phone" or "glasses". A fresh spawn gets the source in
|
|
368
|
+
* CONNECT_ACK instead.
|
|
369
|
+
*/
|
|
370
|
+
LAUNCH_CHANGE = "miniapp_launch_change",
|
|
371
|
+
|
|
365
372
|
/**
|
|
366
373
|
* Push: the host paused or resumed this miniapp. Carries {paused, reason?};
|
|
367
374
|
* the reason is set while paused ("glasses_disconnected").
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
import type {MiniappCapsuleMenuRect} from "../globals"
|
|
1
|
+
import type {MiniappCapsuleMenuRect, MiniappSafeAreaInsets} from "../globals"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Whether the capsule menu floats over the page content: false when it sits
|
|
5
|
+
* in a side safe-area inset (the iPhone Duo's status rail), where it covers
|
|
6
|
+
* nothing the page lays out. Hosts that predate `placement` report a corner
|
|
7
|
+
* rect on the Duo, which lands inside the rail inset all the same.
|
|
8
|
+
*/
|
|
9
|
+
export function capsuleOverContent(
|
|
10
|
+
capsuleMenu: MiniappCapsuleMenuRect,
|
|
11
|
+
viewportWidth: number,
|
|
12
|
+
insets: MiniappSafeAreaInsets,
|
|
13
|
+
): boolean {
|
|
14
|
+
if (capsuleMenu.placement === "rail") return false
|
|
15
|
+
return capsuleMenu.left < viewportWidth - insets.right && capsuleMenu.left + capsuleMenu.width > insets.left
|
|
16
|
+
}
|
|
2
17
|
|
|
3
18
|
export function getCapsuleHeaderPaddingRight(
|
|
4
19
|
capsuleMenu: MiniappCapsuleMenuRect,
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Use this when you want full control over header markup but want the
|
|
6
6
|
* alignment math done for you. If you just want a stock header, use
|
|
7
|
-
* <MiniappHeader> instead.
|
|
7
|
+
* <MiniappHeader> instead. When the capsule sits in the iPhone Duo's status
|
|
8
|
+
* rail, outside the page, the header takes the fallback height and margin
|
|
9
|
+
* and reserves nothing on the right.
|
|
8
10
|
*
|
|
9
11
|
* Example:
|
|
10
12
|
* const style = useCapsuleHeaderStyle()
|
package/src/react/useSafeArea.ts
CHANGED
|
@@ -2,35 +2,70 @@
|
|
|
2
2
|
* @fileoverview useSafeArea — React hook exposing the host's safe-area insets
|
|
3
3
|
* and the capsule menu rect to miniapp UIs.
|
|
4
4
|
*
|
|
5
|
-
* The host injects these via window.Glassly before content loads
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* The host injects these via window.Glassly before content loads and updates
|
|
6
|
+
* them when they change (an iPhone Duo folding moves its status rail),
|
|
7
|
+
* dispatching `glassly:safe-area-change`; the hook re-renders on that event
|
|
8
|
+
* and on viewport resizes.
|
|
8
9
|
*/
|
|
9
10
|
|
|
10
|
-
import {useState} from "react"
|
|
11
|
+
import {useEffect, useState} from "react"
|
|
11
12
|
|
|
12
13
|
import {getHostGlobals, type MiniappCapsuleMenuRect, type MiniappSafeAreaInsets} from "../globals"
|
|
14
|
+
import {capsuleOverContent} from "./capsuleHeaderLayout"
|
|
13
15
|
|
|
14
16
|
const EMPTY_INSETS: MiniappSafeAreaInsets = {top: 0, bottom: 0, left: 0, right: 0}
|
|
15
17
|
|
|
16
18
|
export interface UseSafeAreaResult {
|
|
17
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Pixel insets around the WebView content. Apply as padding on your root
|
|
21
|
+
* element. On an iPhone Duo the status rail is an 84px left or right inset:
|
|
22
|
+
* let backgrounds run under it and stop content at it.
|
|
23
|
+
*/
|
|
18
24
|
insets: MiniappSafeAreaInsets
|
|
19
25
|
/**
|
|
20
|
-
* Bounding rect of the host's
|
|
21
|
-
* Null when the host doesn't render one (e.g. older builds)
|
|
22
|
-
*
|
|
26
|
+
* Bounding rect of the host's capsule menu when it floats over the page
|
|
27
|
+
* (top-right). Null when the host doesn't render one (e.g. older builds) or
|
|
28
|
+
* draws it outside the content, in the Duo's status rail. Use this to avoid
|
|
29
|
+
* placing clickable content underneath the menu.
|
|
23
30
|
*/
|
|
24
31
|
capsuleMenu: MiniappCapsuleMenuRect | null
|
|
25
32
|
}
|
|
26
33
|
|
|
34
|
+
function readSafeArea(): UseSafeAreaResult {
|
|
35
|
+
const globals = getHostGlobals()
|
|
36
|
+
const insets = globals.safeAreaInsets ?? EMPTY_INSETS
|
|
37
|
+
const capsuleMenu = globals.capsuleMenu ?? null
|
|
38
|
+
const viewportWidth = typeof window === "undefined" ? Number.POSITIVE_INFINITY : window.innerWidth
|
|
39
|
+
return {
|
|
40
|
+
insets,
|
|
41
|
+
capsuleMenu: capsuleMenu && capsuleOverContent(capsuleMenu, viewportWidth, insets) ? capsuleMenu : null,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function sameRect<T extends object>(a: T | null, b: T | null): boolean {
|
|
46
|
+
if (a === b) return true
|
|
47
|
+
if (!a || !b) return false
|
|
48
|
+
return (Object.keys(a) as (keyof T)[]).every((key) => a[key] === b[key])
|
|
49
|
+
}
|
|
50
|
+
|
|
27
51
|
export function useSafeArea(): UseSafeAreaResult {
|
|
28
|
-
const [result] = useState<UseSafeAreaResult>(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
52
|
+
const [result, setResult] = useState<UseSafeAreaResult>(readSafeArea)
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const update = () =>
|
|
55
|
+
setResult((previous) => {
|
|
56
|
+
const next = readSafeArea()
|
|
57
|
+
return sameRect(previous.insets, next.insets) && sameRect(previous.capsuleMenu, next.capsuleMenu)
|
|
58
|
+
? previous
|
|
59
|
+
: next
|
|
60
|
+
})
|
|
61
|
+
// The host may have updated the globals between the first render and now.
|
|
62
|
+
update()
|
|
63
|
+
window.addEventListener("glassly:safe-area-change", update)
|
|
64
|
+
window.addEventListener("resize", update)
|
|
65
|
+
return () => {
|
|
66
|
+
window.removeEventListener("glassly:safe-area-change", update)
|
|
67
|
+
window.removeEventListener("resize", update)
|
|
33
68
|
}
|
|
34
|
-
})
|
|
69
|
+
}, [])
|
|
35
70
|
return result
|
|
36
71
|
}
|
package/src/session.ts
CHANGED
|
@@ -298,6 +298,8 @@ type SessionEmitterEvents = {
|
|
|
298
298
|
beforeDisconnect: (reason: string) => void
|
|
299
299
|
disconnect: (reason: string) => void
|
|
300
300
|
visibility: (v: MiniappVisibility) => void
|
|
301
|
+
/** The user opened the running miniapp again, from the phone or the glasses menu. */
|
|
302
|
+
launch: (source: MiniappLaunchSource) => void
|
|
301
303
|
pause: (reason: MiniappPauseReason) => void
|
|
302
304
|
resume: () => void
|
|
303
305
|
link: (link: MiniappLink) => void
|
|
@@ -754,6 +756,15 @@ export class MiniappSession<TChannels extends object = any> {
|
|
|
754
756
|
return this.on("visibility", handler)
|
|
755
757
|
}
|
|
756
758
|
|
|
759
|
+
/**
|
|
760
|
+
* Fires each time the user opens this miniapp while it is already running,
|
|
761
|
+
* with where they opened it from. `launchSource` is updated first. The
|
|
762
|
+
* initial source arrives with CONNECT_ACK and does not fire this.
|
|
763
|
+
*/
|
|
764
|
+
onLaunch(handler: (source: MiniappLaunchSource) => void): () => void {
|
|
765
|
+
return this.on("launch", handler)
|
|
766
|
+
}
|
|
767
|
+
|
|
757
768
|
/**
|
|
758
769
|
* Fires when the host pauses this miniapp: the glasses disconnected and
|
|
759
770
|
* stayed away. Streams stop and nothing reaches the glasses until
|
|
@@ -999,6 +1010,15 @@ export class MiniappSession<TChannels extends object = any> {
|
|
|
999
1010
|
return
|
|
1000
1011
|
}
|
|
1001
1012
|
|
|
1013
|
+
case MiniappResponseType.LAUNCH_CHANGE: {
|
|
1014
|
+
const source = payload.launchSource as MiniappLaunchSource | undefined
|
|
1015
|
+
if (source === "phone" || source === "glasses") {
|
|
1016
|
+
this.launchSource = source
|
|
1017
|
+
this.emitter.emit("launch", source)
|
|
1018
|
+
}
|
|
1019
|
+
return
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1002
1022
|
case MiniappResponseType.PAUSE_CHANGE: {
|
|
1003
1023
|
const paused = payload.paused === true
|
|
1004
1024
|
if (paused === this.paused) return
|