lecodes-sdk 1.2.0 → 2.0.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.
- package/README.md +5 -2
- package/dist/editor.d.ts +12 -0
- package/dist/global.d.ts +4 -8
- package/dist/host.d.ts +2 -3
- package/dist/types/animate/tween/Animation.d.ts +0 -3
- package/dist/types/animate/tween/animateValue.d.ts +4 -2
- package/dist/types/animate/tween/easing.d.ts +8 -0
- package/dist/types/animate/tween/spec.d.ts +15 -7
- package/dist/types/audio/audio.d.ts +2 -1
- package/dist/types/canvas/Canvas.d.ts +40 -108
- package/dist/types/canvas/gen/cssColor.d.ts +17 -0
- package/dist/types/canvas/gen/recorder.d.ts +118 -0
- package/dist/types/canvas/gen/spec.d.ts +144 -0
- package/dist/types/core/color.d.ts +3 -1
- package/dist/types/core/pins.d.ts +18 -0
- package/dist/types/g2/Node2D.d.ts +5 -8
- package/dist/types/g2/Scene2D.d.ts +6 -2
- package/dist/types/gl/Foliage.d.ts +30 -7
- package/dist/types/gl/Light.d.ts +8 -0
- package/dist/types/gl/Lightmap.d.ts +13 -2
- package/dist/types/gl/Material.d.ts +17 -3
- package/dist/types/gl/Model.d.ts +6 -2
- package/dist/types/gl/Node.d.ts +3 -6
- package/dist/types/gl/Scene.d.ts +41 -13
- package/dist/types/gl/Texture.d.ts +1 -1
- package/dist/types/gl/animation/Locomotion.d.ts +8 -1
- package/dist/types/inject.d.ts +11 -11
- package/dist/types/inject.editor.d.ts +1 -0
- package/dist/types/net/core.d.ts +7 -0
- package/dist/types/plugin.d.ts +76 -0
- package/dist/types/plugins/gen/camera/sdk/camera.d.ts +24 -0
- package/dist/types/plugins/gen/camera/sdk/camera.gen.d.ts +25 -0
- package/dist/types/plugins/{geolocation.d.ts → gen/geolocation/sdk/geolocation.d.ts} +2 -20
- package/dist/types/plugins/gen/geolocation/sdk/geolocation.gen.d.ts +31 -0
- package/dist/types/plugins/{map.d.ts → gen/map/sdk/map.d.ts} +9 -50
- package/dist/types/plugins/gen/map/sdk/map.gen.d.ts +53 -0
- package/dist/types/plugins/gen/push/sdk/push.d.ts +23 -0
- package/dist/types/plugins/gen/push/sdk/push.gen.d.ts +35 -0
- package/dist/types/plugins/{qr.d.ts → gen/qr-scanner/sdk/qr-scanner.d.ts} +2 -3
- package/dist/types/plugins/gen/qr-scanner/sdk/qr-scanner.gen.d.ts +15 -0
- package/dist/types/runtime/app.d.ts +9 -2
- package/dist/types/runtime/fetch.d.ts +2 -0
- package/dist/types/runtime/input.d.ts +1 -1
- package/dist/types/runtime/media.d.ts +6 -10
- package/dist/types/runtime/misc.d.ts +4 -1
- package/dist/types/runtime/net.d.ts +3 -2
- package/dist/types/runtime/touch.d.ts +32 -0
- package/dist/types/scene/defineScene.d.ts +43 -2
- package/dist/types/scene/editor.d.ts +52 -0
- package/dist/types/scene/gizmos.d.ts +7 -4
- package/dist/types/ui/NativeView.d.ts +6 -4
- package/dist/types/ui/UI.d.ts +1 -1
- package/dist/types/ui/UIBottomSheet.d.ts +6 -12
- package/dist/types/ui/UIButton.d.ts +12 -14
- package/dist/types/ui/UIContainer.d.ts +0 -6
- package/dist/types/ui/UIImage.d.ts +1 -4
- package/dist/types/ui/UIInput.d.ts +8 -24
- package/dist/types/ui/UIModal.d.ts +0 -2
- package/dist/types/ui/UINode.d.ts +70 -56
- package/dist/types/ui/UIPager.d.ts +28 -27
- package/dist/types/ui/UIPopover.d.ts +0 -2
- package/dist/types/ui/UIScreen.d.ts +12 -17
- package/dist/types/ui/UIScrollable.d.ts +1 -4
- package/dist/types/ui/UIText.d.ts +0 -2
- package/dist/types/ui/UIVideo.d.ts +3 -5
- package/dist/types/ui/UIVirtualizedList.d.ts +14 -16
- package/dist/types/ui/UIWidget.d.ts +10 -9
- package/dist/types/ui/colorKeys.gen.d.ts +9 -0
- package/dist/types/ui/presentable.d.ts +46 -32
- package/dist/types/ui/router.d.ts +18 -7
- package/dist/types/ui/styleColor.d.ts +1 -0
- package/dist/types/ui/transitions.d.ts +18 -0
- package/dist/types/ui/tree.d.ts +75 -0
- package/dist/types/version.d.ts +10 -0
- package/dist/types.json +1 -1
- package/package.json +12 -3
- package/prompts/2d.md +2 -6
- package/prompts/3d.md +1 -5
- package/prompts/README.md +1 -1
- package/prompts/canvas.md +9 -8
- package/prompts/compose.ts +1 -1
- package/prompts/core.md +3 -3
- package/prompts/design.md +1 -1
- package/prompts/dist/2d-game.md +473 -239
- package/prompts/dist/3d-app.md +553 -205
- package/prompts/dist/ar-app.md +435 -202
- package/prompts/dist/design.md +113 -95
- package/prompts/dist/ui-app.md +386 -170
- package/prompts/ui-design.md +2 -3
- package/prompts/ui.md +45 -37
- package/src/animate/tween/Animation.ts +34 -150
- package/src/animate/tween/Timeline.ts +175 -175
- package/src/animate/tween/animateValue.ts +6 -3
- package/src/animate/tween/easing.ts +10 -3
- package/src/animate/tween/spec.ts +41 -15
- package/src/audio/Sound.ts +3 -3
- package/src/audio/audio.ts +2 -1
- package/src/bridges/2d.d.ts +317 -0
- package/src/bridges/app.d.ts +91 -0
- package/src/bridges/audio.d.ts +97 -0
- package/src/bridges/canvas.d.ts +79 -0
- package/src/bridges/device.d.ts +72 -0
- package/src/bridges/fetch.d.ts +80 -0
- package/src/bridges/files.d.ts +70 -0
- package/src/bridges/gl.d.ts +1133 -0
- package/src/bridges/input.d.ts +72 -0
- package/src/bridges/media.d.ts +55 -0
- package/src/bridges/nav.d.ts +71 -0
- package/src/bridges/net.d.ts +52 -0
- package/src/bridges/service.d.ts +52 -0
- package/src/bridges/socket.d.ts +31 -0
- package/src/bridges/storage.d.ts +33 -0
- package/src/bridges/tree.d.ts +301 -0
- package/src/bridges/types.d.ts +49 -0
- package/src/canvas/Canvas.ts +114 -159
- package/src/canvas/gen/cssColor.ts +224 -0
- package/src/canvas/gen/recorder.ts +212 -0
- package/src/canvas/gen/spec.ts +201 -0
- package/src/chisel.ts +193 -0
- package/src/compile/assetMacro.ts +1 -1
- package/src/compile/bundler.ts +11 -2
- package/src/compile/compileProject.ts +43 -4
- package/src/compile/fontMacro.ts +3 -4
- package/src/compile/header.ts +26 -5
- package/src/compile/index.ts +3 -1
- package/src/compile/liteMaterial.ts +1 -1
- package/src/compile/sceneEditor.ts +11 -26
- package/src/core/color.ts +73 -30
- package/src/core/pins.ts +51 -0
- package/src/core/signals.ts +8 -1
- package/src/g2/CharacterController2D.ts +3 -3
- package/src/g2/Node2D.ts +57 -39
- package/src/g2/Physics2D.ts +2 -2
- package/src/g2/Scene2D.ts +35 -23
- package/src/g2/Texture2D.ts +1 -1
- package/src/g2/loop.ts +4 -4
- package/src/gl/CameraPlace.ts +52 -52
- package/src/gl/Foliage.ts +72 -17
- package/src/gl/Geometry.ts +1 -2
- package/src/gl/Light.ts +10 -0
- package/src/gl/Lightmap.ts +45 -29
- package/src/gl/Material.ts +95 -51
- package/src/gl/Mesh.ts +120 -120
- package/src/gl/Model.ts +21 -16
- package/src/gl/Node.ts +91 -24
- package/src/gl/Particles.ts +1 -1
- package/src/gl/Scene.ts +100 -44
- package/src/gl/Texture.ts +8 -7
- package/src/gl/animation/AnimationClip.ts +1 -1
- package/src/gl/animation/DynamicBone.ts +482 -482
- package/src/gl/animation/Locomotion.ts +8 -3
- package/src/gl/nav/NavMesh.ts +3 -4
- package/src/gl/physics/Physics.ts +2 -2
- package/src/gl/physics/physicsEvents.ts +3 -3
- package/src/gl/scenarios.ts +291 -291
- package/src/gl/terrain/Terrain.ts +4 -5
- package/src/gl/touch.ts +14 -15
- package/src/host.d.ts +2 -3
- package/src/inject.editor.ts +7 -0
- package/src/inject.ts +13 -16
- package/src/net/core.ts +6 -5
- package/src/net/index.ts +1 -1
- package/src/net/replication.ts +1 -1
- package/src/plugin.ts +191 -0
- package/src/plugins/gen/camera/contract.d.ts +27 -0
- package/src/plugins/gen/camera/sdk/camera.gen.ts +46 -0
- package/src/plugins/gen/camera/sdk/camera.ts +57 -0
- package/src/plugins/gen/geolocation/contract.d.ts +50 -0
- package/src/plugins/gen/geolocation/sdk/geolocation.gen.ts +54 -0
- package/src/plugins/{geolocation.ts → gen/geolocation/sdk/geolocation.ts} +22 -43
- package/src/plugins/gen/map/contract.d.ts +144 -0
- package/src/plugins/gen/map/sdk/map.gen.ts +88 -0
- package/src/plugins/{map.ts → gen/map/sdk/map.ts} +68 -102
- package/src/plugins/gen/push/contract.d.ts +61 -0
- package/src/plugins/gen/push/sdk/push.gen.ts +60 -0
- package/src/plugins/gen/push/sdk/push.ts +105 -0
- package/src/plugins/gen/qr-scanner/contract.d.ts +16 -0
- package/src/plugins/gen/qr-scanner/sdk/qr-scanner.gen.ts +29 -0
- package/src/plugins/gen/qr-scanner/sdk/qr-scanner.ts +52 -0
- package/src/plugins/permission.ts +5 -4
- package/src/runtime/app.ts +20 -9
- package/src/runtime/appEvents.ts +5 -4
- package/src/runtime/channel.ts +18 -15
- package/src/runtime/clipboard.ts +4 -3
- package/src/runtime/datetime.ts +2 -1
- package/src/runtime/device.ts +17 -15
- package/src/runtime/fetch.ts +30 -20
- package/src/runtime/files.ts +16 -15
- package/src/runtime/input.ts +12 -10
- package/src/runtime/media.ts +50 -46
- package/src/runtime/misc.ts +7 -3
- package/src/runtime/net.ts +8 -7
- package/src/runtime/rpc.ts +1 -3
- package/src/runtime/service.ts +19 -14
- package/src/runtime/share.ts +4 -3
- package/src/runtime/storage.ts +6 -4
- package/src/runtime/touch.ts +32 -0
- package/src/scene/defineScene.ts +61 -365
- package/src/scene/editor.ts +408 -0
- package/src/scene/editorPlugins.ts +3 -3
- package/src/scene/gizmos.ts +15 -9
- package/src/server/db/marci/query.ts +1 -1
- package/src/server/host.ts +1 -1
- package/src/server/runtime.ts +1 -1
- package/src/ui/NativeView.ts +72 -25
- package/src/ui/UI.ts +3 -3
- package/src/ui/UIBottomSheet.ts +16 -17
- package/src/ui/UIButton.ts +54 -16
- package/src/ui/UIContainer.ts +0 -6
- package/src/ui/UIImage.ts +34 -30
- package/src/ui/UIInput.ts +29 -37
- package/src/ui/UIModal.ts +1 -3
- package/src/ui/UINode.ts +347 -297
- package/src/ui/UIPager.ts +93 -78
- package/src/ui/UIPopover.ts +0 -2
- package/src/ui/UIScreen.ts +41 -36
- package/src/ui/UIScrollable.ts +19 -13
- package/src/ui/UISpacer.ts +1 -1
- package/src/ui/UITabs.ts +8 -6
- package/src/ui/UIText.ts +7 -17
- package/src/ui/UIVideo.ts +30 -27
- package/src/ui/UIVirtualizedList.ts +58 -59
- package/src/ui/UIWidget.ts +38 -18
- package/src/ui/colorKeys.gen.ts +37 -0
- package/src/ui/fonts.ts +2 -2
- package/src/ui/presentable.ts +59 -42
- package/src/ui/router.ts +52 -35
- package/src/ui/styleColor.ts +56 -0
- package/src/ui/theme.ts +7 -6
- package/src/ui/transitions.ts +249 -0
- package/src/ui/tree.ts +346 -0
- package/src/version.ts +24 -0
- package/tests/helpers/engineWorld.ts +11 -0
- package/tests/helpers/fakeTree.ts +353 -0
- package/tests/helpers/hostStubs.ts +31 -0
- package/tests/helpers/index.ts +14 -0
- package/tests/helpers/memoryMarci.ts +124 -0
- package/tests/helpers/phases.ts +23 -0
- package/tests/helpers/preload.ts +18 -0
- package/tests/helpers/stubApp.ts +2 -0
- package/tests/helpers/stubDevice.ts +2 -0
- package/tests/helpers/stubFetch.ts +2 -0
- package/tests/helpers/stubInput.ts +2 -0
- package/dist/inject.js +0 -4629
- package/dist/types/core/registry.d.ts +0 -7
- package/dist/types/plugins/camera.d.ts +0 -25
- package/dist/types/plugins/push.d.ts +0 -46
- package/src/bridges.d.ts +0 -1769
- package/src/compile/__tests__/assetIconMacro.test.ts +0 -219
- package/src/compile/__tests__/assetMacro.test.ts +0 -100
- package/src/compile/__tests__/assetName.test.ts +0 -55
- package/src/compile/__tests__/compile.test.ts +0 -310
- package/src/compile/__tests__/detectEntry.test.ts +0 -151
- package/src/compile/__tests__/fontMacro.test.ts +0 -199
- package/src/compile/__tests__/serverSplit.test.ts +0 -27
- package/src/core/__tests__/stateMachine.test.ts +0 -132
- package/src/core/registry.ts +0 -23
- package/src/plugins/camera.ts +0 -81
- package/src/plugins/push.ts +0 -132
- package/src/plugins/qr.ts +0 -73
|
@@ -1,39 +1,18 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// just `getCurrent()` and `watch()`.
|
|
1
|
+
// GENERATED by scripts/vendor-plugins.ts from lecodes-plugins/plugins/geolocation/sdk/geolocation.ts — do not edit here.
|
|
2
|
+
// Change it in the plugin repo and run `bun run vendor:plugins`; `bun run check:plugins` fails when this copy is stale.
|
|
3
|
+
// Geolocation — the device position: `getCurrent()` and `watch()`.
|
|
5
4
|
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
// rejection. Both methods reject immediately on unsupported hosts, BEFORE any permission path.
|
|
5
|
+
// Hand-written over the generated wire because the public API is not the wire's: the wire has ONE
|
|
6
|
+
// watch per session (startWatch / stopWatch + the `position` event), the app gets `watch(callback)`
|
|
7
|
+
// — any number of subscribers on that one watch, each with its own `stop()`.
|
|
10
8
|
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
9
|
+
// The OS permission prompt happens on the first call that needs it (host-side); a denial is a
|
|
10
|
+
// rejection. Both methods reject on a host without the service BEFORE any permission path.
|
|
13
11
|
|
|
14
|
-
import {
|
|
12
|
+
import { GeolocationBase, NAME } from "./geolocation.gen"
|
|
13
|
+
import type { GeoOptions, GeoPosition } from "../contract"
|
|
15
14
|
|
|
16
|
-
export
|
|
17
|
-
latitude: number
|
|
18
|
-
longitude: number
|
|
19
|
-
/** Horizontal accuracy radius, meters. */
|
|
20
|
-
accuracy: number
|
|
21
|
-
/** Meters above sea level, or null when the provider doesn't know. */
|
|
22
|
-
altitude: number | null
|
|
23
|
-
/** Direction of travel in degrees clockwise from north, or null when stationary/unknown. */
|
|
24
|
-
heading: number | null
|
|
25
|
-
/** Ground speed in m/s, or null when unknown. */
|
|
26
|
-
speed: number | null
|
|
27
|
-
/** When this fix was taken, ms epoch. */
|
|
28
|
-
timestamp: number
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface GeoOptions {
|
|
32
|
-
/** Prefer the precise (GPS) provider — slower first fix, more battery. Default false. */
|
|
33
|
-
highAccuracy?: boolean
|
|
34
|
-
/** getCurrent only: reject with "timeout" if no fix arrives in this many ms. */
|
|
35
|
-
timeout?: number
|
|
36
|
-
}
|
|
15
|
+
export type { GeoOptions, GeoPosition }
|
|
37
16
|
|
|
38
17
|
/** A live `Geolocation.watch()` subscription — `stop()` it when the screen goes away. */
|
|
39
18
|
export interface GeoWatch {
|
|
@@ -44,7 +23,7 @@ export interface GeoWatch {
|
|
|
44
23
|
* The device position. `Geolocation.isSupported` reports whether this host registered the
|
|
45
24
|
* service — check it before offering location features.
|
|
46
25
|
*/
|
|
47
|
-
// PURE IIFE so an app that never uses location tree-shakes the whole plugin away
|
|
26
|
+
// PURE IIFE so an app that never uses location tree-shakes the whole plugin away.
|
|
48
27
|
export const Geolocation: {
|
|
49
28
|
/** Whether this host registered a "geolocation" service. */
|
|
50
29
|
readonly isSupported: boolean
|
|
@@ -56,18 +35,18 @@ export const Geolocation: {
|
|
|
56
35
|
* subscriber; the options of the watch that starts it win. Always `stop()` when done. */
|
|
57
36
|
watch(callback: (position: GeoPosition) => void, options?: GeoOptions): Promise<GeoWatch>
|
|
58
37
|
} = /*#__PURE__*/ (() => {
|
|
59
|
-
let client:
|
|
60
|
-
const service = ():
|
|
38
|
+
let client: GeolocationBase | null = null
|
|
39
|
+
const service = (): GeolocationBase => client ??= new GeolocationBase()
|
|
61
40
|
|
|
62
|
-
// Watch state: one host watch fans out to N subscribers
|
|
41
|
+
// Watch state: one host watch fans out to N subscribers, the last stop() releases it.
|
|
63
42
|
const watchers: ((position: GeoPosition) => void)[] = []
|
|
64
43
|
let positionHooked = false
|
|
65
44
|
let startPromise: Promise<void> | null = null
|
|
66
45
|
|
|
67
46
|
const assertSupported = (): void => {
|
|
68
47
|
// Fail before the host is touched — a permission dialog for a feature that can't exist
|
|
69
|
-
// would be worse than the error
|
|
70
|
-
if (!
|
|
48
|
+
// would be worse than the error.
|
|
49
|
+
if (!GeolocationBase.supports(NAME)) {
|
|
71
50
|
throw new Error('Geolocation isn\'t available on this host — it needs a registered "geolocation" service.')
|
|
72
51
|
}
|
|
73
52
|
}
|
|
@@ -77,26 +56,26 @@ export const Geolocation: {
|
|
|
77
56
|
if (i >= 0) watchers.splice(i, 1)
|
|
78
57
|
if (watchers.length === 0 && startPromise !== null) {
|
|
79
58
|
startPromise = null
|
|
80
|
-
service().
|
|
59
|
+
service().stopWatch().catch(() => {})
|
|
81
60
|
}
|
|
82
61
|
}
|
|
83
62
|
|
|
84
63
|
const geolocation = {
|
|
85
64
|
async getCurrent(options?: GeoOptions): Promise<GeoPosition> {
|
|
86
65
|
assertSupported()
|
|
87
|
-
return await service().
|
|
66
|
+
return await service().getCurrent(options ?? {})
|
|
88
67
|
},
|
|
89
68
|
|
|
90
69
|
async watch(callback: (position: GeoPosition) => void, options?: GeoOptions): Promise<GeoWatch> {
|
|
91
70
|
assertSupported()
|
|
92
71
|
if (!positionHooked) {
|
|
93
72
|
positionHooked = true
|
|
94
|
-
service().on("position",
|
|
73
|
+
service().on("position", position => {
|
|
95
74
|
if (position) for (const cb of [...watchers]) cb(position)
|
|
96
75
|
})
|
|
97
76
|
}
|
|
98
77
|
watchers.push(callback)
|
|
99
|
-
startPromise ??= service().
|
|
78
|
+
startPromise ??= service().startWatch(options ?? {})
|
|
100
79
|
try {
|
|
101
80
|
await startPromise
|
|
102
81
|
} catch (e) {
|
|
@@ -117,7 +96,7 @@ export const Geolocation: {
|
|
|
117
96
|
},
|
|
118
97
|
}
|
|
119
98
|
Object.defineProperty(geolocation, "isSupported", {
|
|
120
|
-
get: (): boolean =>
|
|
99
|
+
get: (): boolean => GeolocationBase.supports(NAME),
|
|
121
100
|
})
|
|
122
101
|
return geolocation as any
|
|
123
102
|
})()
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// GENERATED by scripts/vendor-plugins.ts from lecodes-plugins/plugins/map/contract.d.ts — do not edit here.
|
|
2
|
+
// Change it in the plugin repo and run `bun run vendor:plugins`; `bun run check:plugins` fails when this copy is stale.
|
|
3
|
+
// map — a vector map (maplibre-native on iOS / Android, maplibre-gl in the browser).
|
|
4
|
+
// The wire is lower than the app-facing `MapView`: the wrapper in sdk/ resolves a style to a url or
|
|
5
|
+
// to text, turns marker items into GeoJSON, queues calls until `ready` and re-applies the
|
|
6
|
+
// style-lifetime state (layers, data, padding, the user puck) after every style load.
|
|
7
|
+
//
|
|
8
|
+
// The plugin never touches the location hardware: the user puck is fed by the app.
|
|
9
|
+
|
|
10
|
+
import type { Json, View, f64 } from "../../../plugin"
|
|
11
|
+
|
|
12
|
+
/** `[longitude, latitude]` — GeoJSON order. */
|
|
13
|
+
export type LngLat = [f64, f64]
|
|
14
|
+
|
|
15
|
+
export interface MapParams {
|
|
16
|
+
/** A style URL the map fetches itself. */
|
|
17
|
+
style?: string
|
|
18
|
+
/** A style as JSON text; wins over `style`. It has no base url: every url INSIDE it (sources,
|
|
19
|
+
* sprite, glyphs) must be absolute. */
|
|
20
|
+
styleJson?: string
|
|
21
|
+
center?: LngLat
|
|
22
|
+
/** Default 12 with a center. */
|
|
23
|
+
zoom?: f64
|
|
24
|
+
minZoom?: f64
|
|
25
|
+
maxZoom?: f64
|
|
26
|
+
/** Degrees clockwise from north. */
|
|
27
|
+
bearing?: f64
|
|
28
|
+
/** Degrees from the vertical. */
|
|
29
|
+
pitch?: f64
|
|
30
|
+
/** The two-finger rotate gesture. Default true. */
|
|
31
|
+
rotate?: boolean
|
|
32
|
+
/** The two-finger tilt gesture. Default false. */
|
|
33
|
+
tilt?: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface MapCamera {
|
|
37
|
+
center: LngLat
|
|
38
|
+
zoom: f64
|
|
39
|
+
bearing: f64
|
|
40
|
+
pitch: f64
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** A feature of a managed source under a tap. */
|
|
44
|
+
export interface MapFeature {
|
|
45
|
+
/** The source's name — the layer's name in the app. */
|
|
46
|
+
source: string
|
|
47
|
+
id: string | f64 | null
|
|
48
|
+
properties: { [key: string]: Json }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface MapTap {
|
|
52
|
+
lngLat: LngLat
|
|
53
|
+
/** View-space point, logical px. */
|
|
54
|
+
point: [f64, f64]
|
|
55
|
+
/** Absent for a tap that hit no feature of a managed source. A tap on a CLUSTER zooms in and
|
|
56
|
+
* sends no event. */
|
|
57
|
+
feature?: MapFeature
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface MapEvents {
|
|
61
|
+
/** The style loaded and the map takes calls. Fires again after every style reload. */
|
|
62
|
+
ready: void
|
|
63
|
+
tap: MapTap
|
|
64
|
+
/** The camera settled after a gesture or an animation. */
|
|
65
|
+
moveEnd: MapCamera
|
|
66
|
+
/** A problem that is never fatal: a style that would not load, a source out of reach. */
|
|
67
|
+
error: { message: string }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type MapLayerKind = "markers" | "line"
|
|
71
|
+
|
|
72
|
+
/** The keys of both kinds; a half reads the ones of the kind it is asked for. */
|
|
73
|
+
export interface MapLayerOptions {
|
|
74
|
+
/** markers: group nearby markers (a cluster tap zooms in). Default false. */
|
|
75
|
+
cluster?: boolean
|
|
76
|
+
/** markers: px. Default 50. */
|
|
77
|
+
clusterRadius?: f64
|
|
78
|
+
/** markers: the zoom at which clusters stop forming. */
|
|
79
|
+
clusterMaxZoom?: f64
|
|
80
|
+
/** line. */
|
|
81
|
+
color?: string
|
|
82
|
+
/** line: px. Default 4. */
|
|
83
|
+
width?: f64
|
|
84
|
+
/** line: 0–1. Default 1. */
|
|
85
|
+
opacity?: f64
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface MapCameraMove {
|
|
89
|
+
zoom?: f64
|
|
90
|
+
bearing?: f64
|
|
91
|
+
pitch?: f64
|
|
92
|
+
/** flyTo only: ms. Default 600. */
|
|
93
|
+
duration?: f64
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Px, or a share of the view's size as "NN%". */
|
|
97
|
+
export type MapInset = f64 | string
|
|
98
|
+
|
|
99
|
+
export interface MapPadding {
|
|
100
|
+
top?: MapInset
|
|
101
|
+
left?: MapInset
|
|
102
|
+
bottom?: MapInset
|
|
103
|
+
right?: MapInset
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface MapFitOptions {
|
|
107
|
+
/** Around the points: px on every edge, or per edge. Added to the view padding. */
|
|
108
|
+
padding?: f64 | MapPadding
|
|
109
|
+
/** Default: 16 for one point, none otherwise. */
|
|
110
|
+
maxZoom?: f64
|
|
111
|
+
/** Default true. */
|
|
112
|
+
animate?: boolean
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface MapUserLocationOptions {
|
|
116
|
+
/** Meters — the halo around the dot. */
|
|
117
|
+
accuracy?: f64 | null
|
|
118
|
+
/** Degrees clockwise from north — the direction wedge; null hides it. */
|
|
119
|
+
heading?: f64 | null
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface MapView extends View<"map", MapParams, MapEvents> {
|
|
123
|
+
/** Make sure the GeoJSON source `source` exists. A source the style declares is used as is (its
|
|
124
|
+
* layers draw, only data flows); otherwise the half creates it with the default layers of `kind`.
|
|
125
|
+
* @rejects notReady */
|
|
126
|
+
ensureLayer(source: string, kind: MapLayerKind, options?: MapLayerOptions): Promise<void>
|
|
127
|
+
removeLayer(source: string): Promise<void>
|
|
128
|
+
/** Replace the data of a GeoJSON source: a Feature or a FeatureCollection.
|
|
129
|
+
* @rejects notReady */
|
|
130
|
+
setData(source: string, geojson: Json): Promise<void>
|
|
131
|
+
|
|
132
|
+
flyTo(center: LngLat, options?: MapCameraMove): Promise<void>
|
|
133
|
+
jumpTo(center: LngLat, options?: MapCameraMove): Promise<void>
|
|
134
|
+
/** Fit the camera to the points.
|
|
135
|
+
* @rejects noPoints */
|
|
136
|
+
fitPoints(points: LngLat[], options?: MapFitOptions): Promise<void>
|
|
137
|
+
/** The part of the view covered by the app's UI; camera moves center inside the rest. */
|
|
138
|
+
setPadding(padding: MapPadding): Promise<void>
|
|
139
|
+
/** @rejects notReady */
|
|
140
|
+
getCamera(): Promise<MapCamera>
|
|
141
|
+
|
|
142
|
+
/** Move the user puck; null hides it. */
|
|
143
|
+
setUserLocation(lngLat: LngLat | null, options?: MapUserLocationOptions): Promise<void>
|
|
144
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// GENERATED by scripts/vendor-plugins.ts from lecodes-plugins/plugins/map/sdk/map.gen.ts — do not edit here.
|
|
2
|
+
// Change it in the plugin repo and run `bun run vendor:plugins`; `bun run check:plugins` fails when this copy is stale.
|
|
3
|
+
// GENERATED by `lecodes plugin gen` from contract.d.ts — do not edit.
|
|
4
|
+
// map: the view "map", contract version 1.
|
|
5
|
+
|
|
6
|
+
import { ViewChannel, type Json } from "../../../../plugin"
|
|
7
|
+
import type { LngLat, MapCamera, MapCameraMove, MapEvents, MapFitOptions, MapLayerKind, MapLayerOptions, MapPadding, MapParams, MapUserLocationOptions } from "../contract"
|
|
8
|
+
|
|
9
|
+
/** What the halves register under. */
|
|
10
|
+
export const NAME = "map"
|
|
11
|
+
/** The contract's version: the highest `@since` of its members. */
|
|
12
|
+
export const VERSION = 1
|
|
13
|
+
|
|
14
|
+
// ---- the wire, call by call ----------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
/** Make sure the GeoJSON source `source` exists. A source the style declares is used as is (its
|
|
17
|
+
* layers draw, only data flows); otherwise the half creates it with the default layers of `kind`.
|
|
18
|
+
* Rejects with "notReady". */
|
|
19
|
+
export const ensureLayer = (view: ViewChannel<MapEvents>, source: string, kind: MapLayerKind, options?: MapLayerOptions): Promise<void> =>
|
|
20
|
+
view._call("ensureLayer", [source, kind, options])
|
|
21
|
+
|
|
22
|
+
export const removeLayer = (view: ViewChannel<MapEvents>, source: string): Promise<void> =>
|
|
23
|
+
view._call("removeLayer", [source])
|
|
24
|
+
|
|
25
|
+
/** Replace the data of a GeoJSON source: a Feature or a FeatureCollection.
|
|
26
|
+
* Rejects with "notReady". */
|
|
27
|
+
export const setData = (view: ViewChannel<MapEvents>, source: string, geojson: Json): Promise<void> =>
|
|
28
|
+
view._call("setData", [source, geojson])
|
|
29
|
+
|
|
30
|
+
export const flyTo = (view: ViewChannel<MapEvents>, center: LngLat, options?: MapCameraMove): Promise<void> =>
|
|
31
|
+
view._call("flyTo", [center, options])
|
|
32
|
+
|
|
33
|
+
export const jumpTo = (view: ViewChannel<MapEvents>, center: LngLat, options?: MapCameraMove): Promise<void> =>
|
|
34
|
+
view._call("jumpTo", [center, options])
|
|
35
|
+
|
|
36
|
+
/** Fit the camera to the points.
|
|
37
|
+
* Rejects with "noPoints". */
|
|
38
|
+
export const fitPoints = (view: ViewChannel<MapEvents>, points: LngLat[], options?: MapFitOptions): Promise<void> =>
|
|
39
|
+
view._call("fitPoints", [points, options])
|
|
40
|
+
|
|
41
|
+
/** The part of the view covered by the app's UI; camera moves center inside the rest. */
|
|
42
|
+
export const setPadding = (view: ViewChannel<MapEvents>, padding: MapPadding): Promise<void> =>
|
|
43
|
+
view._call("setPadding", [padding])
|
|
44
|
+
|
|
45
|
+
/** Rejects with "notReady". */
|
|
46
|
+
export const getCamera = (view: ViewChannel<MapEvents>): Promise<MapCamera> =>
|
|
47
|
+
view._call("getCamera", [])
|
|
48
|
+
|
|
49
|
+
/** Move the user puck; null hides it. */
|
|
50
|
+
export const setUserLocation = (view: ViewChannel<MapEvents>, lngLat: LngLat | null, options?: MapUserLocationOptions): Promise<void> =>
|
|
51
|
+
view._call("setUserLocation", [lngLat, options])
|
|
52
|
+
|
|
53
|
+
// ---- what the host's half has --------------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
/** A method of the contract. */
|
|
56
|
+
export type Method = "ensureLayer" | "removeLayer" | "setData" | "flyTo" | "jumpTo" | "fitPoints" | "setPadding" | "getCamera" | "setUserLocation"
|
|
57
|
+
|
|
58
|
+
/** Whether this host has the view "map" — and, given a method, a half new enough for it
|
|
59
|
+
* (a method added after the first version of the contract is tagged `@since`). */
|
|
60
|
+
export const supports = (method?: Method): boolean =>
|
|
61
|
+
ViewChannel.supports(NAME) // every method is of version 1
|
|
62
|
+
|
|
63
|
+
// ---- the element ----------------------------------------------------------------------------------
|
|
64
|
+
|
|
65
|
+
/** The view "map" with the wire's methods as its own. */
|
|
66
|
+
export class MapViewBase extends ViewChannel<MapEvents> {
|
|
67
|
+
constructor(params: MapParams = {}) { super("MapView", NAME, params) }
|
|
68
|
+
|
|
69
|
+
/** Make sure the GeoJSON source `source` exists. A source the style declares is used as is (its
|
|
70
|
+
* layers draw, only data flows); otherwise the half creates it with the default layers of `kind`.
|
|
71
|
+
* Rejects with "notReady". */
|
|
72
|
+
ensureLayer(source: string, kind: MapLayerKind, options?: MapLayerOptions): Promise<void> { return ensureLayer(this, source, kind, options) }
|
|
73
|
+
removeLayer(source: string): Promise<void> { return removeLayer(this, source) }
|
|
74
|
+
/** Replace the data of a GeoJSON source: a Feature or a FeatureCollection.
|
|
75
|
+
* Rejects with "notReady". */
|
|
76
|
+
setData(source: string, geojson: Json): Promise<void> { return setData(this, source, geojson) }
|
|
77
|
+
flyTo(center: LngLat, options?: MapCameraMove): Promise<void> { return flyTo(this, center, options) }
|
|
78
|
+
jumpTo(center: LngLat, options?: MapCameraMove): Promise<void> { return jumpTo(this, center, options) }
|
|
79
|
+
/** Fit the camera to the points.
|
|
80
|
+
* Rejects with "noPoints". */
|
|
81
|
+
fitPoints(points: LngLat[], options?: MapFitOptions): Promise<void> { return fitPoints(this, points, options) }
|
|
82
|
+
/** The part of the view covered by the app's UI; camera moves center inside the rest. */
|
|
83
|
+
setPadding(padding: MapPadding): Promise<void> { return setPadding(this, padding) }
|
|
84
|
+
/** Rejects with "notReady". */
|
|
85
|
+
getCamera(): Promise<MapCamera> { return getCamera(this) }
|
|
86
|
+
/** Move the user puck; null hides it. */
|
|
87
|
+
setUserLocation(lngLat: LngLat | null, options?: MapUserLocationOptions): Promise<void> { return setUserLocation(this, lngLat, options) }
|
|
88
|
+
}
|