lecodes-sdk 1.1.0 → 2.0.0

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.
Files changed (257) hide show
  1. package/README.md +5 -2
  2. package/dist/editor.d.ts +12 -0
  3. package/dist/global.d.ts +4 -8
  4. package/dist/host.d.ts +2 -3
  5. package/dist/types/animate/tween/Animation.d.ts +0 -3
  6. package/dist/types/animate/tween/animateValue.d.ts +4 -2
  7. package/dist/types/animate/tween/easing.d.ts +8 -0
  8. package/dist/types/animate/tween/spec.d.ts +15 -7
  9. package/dist/types/audio/audio.d.ts +2 -1
  10. package/dist/types/canvas/Canvas.d.ts +40 -108
  11. package/dist/types/canvas/gen/cssColor.d.ts +17 -0
  12. package/dist/types/canvas/gen/recorder.d.ts +118 -0
  13. package/dist/types/canvas/gen/spec.d.ts +144 -0
  14. package/dist/types/core/color.d.ts +3 -1
  15. package/dist/types/core/pins.d.ts +18 -0
  16. package/dist/types/g2/Node2D.d.ts +5 -8
  17. package/dist/types/g2/Scene2D.d.ts +6 -2
  18. package/dist/types/gl/Foliage.d.ts +30 -7
  19. package/dist/types/gl/Light.d.ts +11 -0
  20. package/dist/types/gl/Lightmap.d.ts +13 -2
  21. package/dist/types/gl/Material.d.ts +17 -3
  22. package/dist/types/gl/Model.d.ts +6 -2
  23. package/dist/types/gl/Node.d.ts +3 -6
  24. package/dist/types/gl/Particles.d.ts +15 -0
  25. package/dist/types/gl/Scene.d.ts +41 -13
  26. package/dist/types/gl/Texture.d.ts +1 -1
  27. package/dist/types/gl/animation/Locomotion.d.ts +59 -3
  28. package/dist/types/gl/terrain/Terrain.d.ts +8 -0
  29. package/dist/types/inject.d.ts +11 -11
  30. package/dist/types/inject.editor.d.ts +1 -0
  31. package/dist/types/net/core.d.ts +7 -0
  32. package/dist/types/plugin.d.ts +76 -0
  33. package/dist/types/plugins/gen/camera/sdk/camera.d.ts +24 -0
  34. package/dist/types/plugins/gen/camera/sdk/camera.gen.d.ts +25 -0
  35. package/dist/types/plugins/{geolocation.d.ts → gen/geolocation/sdk/geolocation.d.ts} +2 -20
  36. package/dist/types/plugins/gen/geolocation/sdk/geolocation.gen.d.ts +31 -0
  37. package/dist/types/plugins/{map.d.ts → gen/map/sdk/map.d.ts} +9 -50
  38. package/dist/types/plugins/gen/map/sdk/map.gen.d.ts +53 -0
  39. package/dist/types/plugins/gen/push/sdk/push.d.ts +23 -0
  40. package/dist/types/plugins/gen/push/sdk/push.gen.d.ts +35 -0
  41. package/dist/types/plugins/{qr.d.ts → gen/qr-scanner/sdk/qr-scanner.d.ts} +2 -3
  42. package/dist/types/plugins/gen/qr-scanner/sdk/qr-scanner.gen.d.ts +15 -0
  43. package/dist/types/runtime/app.d.ts +9 -2
  44. package/dist/types/runtime/fetch.d.ts +2 -0
  45. package/dist/types/runtime/input.d.ts +8 -1
  46. package/dist/types/runtime/media.d.ts +6 -10
  47. package/dist/types/runtime/misc.d.ts +4 -1
  48. package/dist/types/runtime/net.d.ts +3 -2
  49. package/dist/types/runtime/touch.d.ts +32 -0
  50. package/dist/types/scene/defineScene.d.ts +43 -2
  51. package/dist/types/scene/editor.d.ts +52 -0
  52. package/dist/types/scene/gizmos.d.ts +7 -4
  53. package/dist/types/ui/NativeView.d.ts +6 -4
  54. package/dist/types/ui/UI.d.ts +1 -1
  55. package/dist/types/ui/UIBottomSheet.d.ts +6 -12
  56. package/dist/types/ui/UIButton.d.ts +12 -14
  57. package/dist/types/ui/UIContainer.d.ts +0 -6
  58. package/dist/types/ui/UIImage.d.ts +1 -4
  59. package/dist/types/ui/UIInput.d.ts +8 -24
  60. package/dist/types/ui/UIModal.d.ts +0 -2
  61. package/dist/types/ui/UINode.d.ts +70 -56
  62. package/dist/types/ui/UIPager.d.ts +28 -27
  63. package/dist/types/ui/UIPopover.d.ts +0 -2
  64. package/dist/types/ui/UIScreen.d.ts +12 -17
  65. package/dist/types/ui/UIScrollable.d.ts +1 -4
  66. package/dist/types/ui/UIText.d.ts +0 -2
  67. package/dist/types/ui/UIVideo.d.ts +3 -5
  68. package/dist/types/ui/UIVirtualizedList.d.ts +14 -16
  69. package/dist/types/ui/UIWidget.d.ts +10 -9
  70. package/dist/types/ui/colorKeys.gen.d.ts +9 -0
  71. package/dist/types/ui/presentable.d.ts +46 -32
  72. package/dist/types/ui/router.d.ts +18 -7
  73. package/dist/types/ui/styleColor.d.ts +1 -0
  74. package/dist/types/ui/transitions.d.ts +18 -0
  75. package/dist/types/ui/tree.d.ts +75 -0
  76. package/dist/types/version.d.ts +10 -0
  77. package/dist/types.json +1 -1
  78. package/package.json +12 -3
  79. package/prompts/2d.md +2 -6
  80. package/prompts/3d.md +1 -5
  81. package/prompts/README.md +142 -142
  82. package/prompts/canvas.md +9 -8
  83. package/prompts/compose.ts +1 -1
  84. package/prompts/core.md +3 -3
  85. package/prompts/design.md +1 -1
  86. package/prompts/dist/2d-game.md +77 -54
  87. package/prompts/dist/3d-app.md +75 -52
  88. package/prompts/dist/ar-app.md +74 -51
  89. package/prompts/dist/design.md +30 -8
  90. package/prompts/dist/ui-app.md +73 -46
  91. package/prompts/ui-design.md +2 -3
  92. package/prompts/ui.md +45 -37
  93. package/src/animate/tween/Animation.ts +262 -378
  94. package/src/animate/tween/animateValue.ts +103 -100
  95. package/src/animate/tween/easing.ts +10 -3
  96. package/src/animate/tween/spec.ts +505 -479
  97. package/src/audio/Sound.ts +3 -3
  98. package/src/audio/audio.ts +162 -161
  99. package/src/bridges/2d.d.ts +317 -0
  100. package/src/bridges/app.d.ts +91 -0
  101. package/src/bridges/audio.d.ts +97 -0
  102. package/src/bridges/canvas.d.ts +79 -0
  103. package/src/bridges/device.d.ts +72 -0
  104. package/src/bridges/fetch.d.ts +80 -0
  105. package/src/bridges/files.d.ts +70 -0
  106. package/src/bridges/gl.d.ts +1133 -0
  107. package/src/bridges/input.d.ts +72 -0
  108. package/src/bridges/media.d.ts +55 -0
  109. package/src/bridges/nav.d.ts +71 -0
  110. package/src/bridges/net.d.ts +52 -0
  111. package/src/bridges/service.d.ts +52 -0
  112. package/src/bridges/socket.d.ts +31 -0
  113. package/src/bridges/storage.d.ts +33 -0
  114. package/src/bridges/tree.d.ts +301 -0
  115. package/src/bridges/types.d.ts +49 -0
  116. package/src/canvas/Canvas.ts +114 -159
  117. package/src/canvas/gen/cssColor.ts +224 -0
  118. package/src/canvas/gen/recorder.ts +212 -0
  119. package/src/canvas/gen/spec.ts +201 -0
  120. package/src/chisel.ts +193 -0
  121. package/src/compile/assetMacro.ts +1 -1
  122. package/src/compile/bundler.ts +11 -2
  123. package/src/compile/compileProject.ts +43 -4
  124. package/src/compile/fontMacro.ts +3 -4
  125. package/src/compile/header.ts +26 -5
  126. package/src/compile/index.ts +3 -1
  127. package/src/compile/liteMaterial.ts +1 -1
  128. package/src/compile/sceneEditor.ts +11 -26
  129. package/src/core/color.ts +73 -30
  130. package/src/core/pins.ts +51 -0
  131. package/src/core/signals.ts +8 -1
  132. package/src/g2/CharacterController2D.ts +3 -3
  133. package/src/g2/Node2D.ts +57 -39
  134. package/src/g2/Physics2D.ts +2 -2
  135. package/src/g2/Scene2D.ts +35 -23
  136. package/src/g2/Texture2D.ts +1 -1
  137. package/src/g2/loop.ts +4 -4
  138. package/src/gl/Foliage.ts +72 -17
  139. package/src/gl/Geometry.ts +1 -2
  140. package/src/gl/Light.ts +13 -0
  141. package/src/gl/Lightmap.ts +45 -29
  142. package/src/gl/Material.ts +95 -51
  143. package/src/gl/Model.ts +172 -167
  144. package/src/gl/Node.ts +91 -24
  145. package/src/gl/Particles.ts +20 -1
  146. package/src/gl/Scene.ts +100 -44
  147. package/src/gl/Texture.ts +8 -7
  148. package/src/gl/animation/AnimationClip.ts +1 -1
  149. package/src/gl/animation/Locomotion.ts +77 -8
  150. package/src/gl/nav/NavMesh.ts +3 -4
  151. package/src/gl/physics/Physics.ts +2 -2
  152. package/src/gl/physics/physicsEvents.ts +3 -3
  153. package/src/gl/terrain/Terrain.ts +33 -5
  154. package/src/gl/touch.ts +14 -15
  155. package/src/host.d.ts +2 -3
  156. package/src/inject.editor.ts +7 -0
  157. package/src/inject.ts +233 -236
  158. package/src/net/core.ts +6 -5
  159. package/src/net/index.ts +1 -1
  160. package/src/net/replication.ts +1 -1
  161. package/src/plugin.ts +191 -0
  162. package/src/plugins/gen/camera/contract.d.ts +27 -0
  163. package/src/plugins/gen/camera/sdk/camera.gen.ts +46 -0
  164. package/src/plugins/gen/camera/sdk/camera.ts +57 -0
  165. package/src/plugins/gen/geolocation/contract.d.ts +50 -0
  166. package/src/plugins/gen/geolocation/sdk/geolocation.gen.ts +54 -0
  167. package/src/plugins/{geolocation.ts → gen/geolocation/sdk/geolocation.ts} +22 -43
  168. package/src/plugins/gen/map/contract.d.ts +144 -0
  169. package/src/plugins/gen/map/sdk/map.gen.ts +88 -0
  170. package/src/plugins/{map.ts → gen/map/sdk/map.ts} +68 -102
  171. package/src/plugins/gen/push/contract.d.ts +61 -0
  172. package/src/plugins/gen/push/sdk/push.gen.ts +60 -0
  173. package/src/plugins/gen/push/sdk/push.ts +105 -0
  174. package/src/plugins/gen/qr-scanner/contract.d.ts +16 -0
  175. package/src/plugins/gen/qr-scanner/sdk/qr-scanner.gen.ts +29 -0
  176. package/src/plugins/gen/qr-scanner/sdk/qr-scanner.ts +52 -0
  177. package/src/plugins/permission.ts +5 -4
  178. package/src/runtime/app.ts +20 -9
  179. package/src/runtime/appEvents.ts +5 -4
  180. package/src/runtime/channel.ts +18 -15
  181. package/src/runtime/clipboard.ts +4 -3
  182. package/src/runtime/datetime.ts +2 -1
  183. package/src/runtime/device.ts +17 -15
  184. package/src/runtime/fetch.ts +30 -20
  185. package/src/runtime/files.ts +16 -15
  186. package/src/runtime/input.ts +21 -8
  187. package/src/runtime/media.ts +50 -46
  188. package/src/runtime/misc.ts +7 -3
  189. package/src/runtime/net.ts +8 -7
  190. package/src/runtime/rpc.ts +1 -3
  191. package/src/runtime/service.ts +19 -14
  192. package/src/runtime/share.ts +4 -3
  193. package/src/runtime/storage.ts +6 -4
  194. package/src/runtime/touch.ts +32 -0
  195. package/src/scene/defineScene.ts +61 -365
  196. package/src/scene/editor.ts +408 -0
  197. package/src/scene/editorPlugins.ts +3 -3
  198. package/src/scene/gizmos.ts +154 -148
  199. package/src/server/db/marci/query.ts +1 -1
  200. package/src/server/host.ts +1 -1
  201. package/src/server/runtime.ts +1 -1
  202. package/src/ui/NativeView.ts +72 -25
  203. package/src/ui/UI.ts +3 -3
  204. package/src/ui/UIBottomSheet.ts +16 -17
  205. package/src/ui/UIButton.ts +54 -16
  206. package/src/ui/UIContainer.ts +0 -6
  207. package/src/ui/UIImage.ts +34 -30
  208. package/src/ui/UIInput.ts +29 -37
  209. package/src/ui/UIModal.ts +1 -3
  210. package/src/ui/UINode.ts +347 -297
  211. package/src/ui/UIPager.ts +93 -78
  212. package/src/ui/UIPopover.ts +0 -2
  213. package/src/ui/UIScreen.ts +41 -36
  214. package/src/ui/UIScrollable.ts +19 -13
  215. package/src/ui/UISpacer.ts +1 -1
  216. package/src/ui/UITabs.ts +8 -6
  217. package/src/ui/UIText.ts +7 -17
  218. package/src/ui/UIVideo.ts +30 -27
  219. package/src/ui/UIVirtualizedList.ts +58 -59
  220. package/src/ui/UIWidget.ts +38 -18
  221. package/src/ui/colorKeys.gen.ts +37 -0
  222. package/src/ui/fonts.ts +2 -2
  223. package/src/ui/presentable.ts +59 -42
  224. package/src/ui/router.ts +52 -35
  225. package/src/ui/styleColor.ts +56 -0
  226. package/src/ui/theme.ts +7 -6
  227. package/src/ui/transitions.ts +249 -0
  228. package/src/ui/tree.ts +346 -0
  229. package/src/version.ts +24 -0
  230. package/tests/helpers/engineWorld.ts +11 -0
  231. package/tests/helpers/fakeTree.ts +353 -0
  232. package/tests/helpers/hostStubs.ts +31 -0
  233. package/tests/helpers/index.ts +14 -0
  234. package/tests/helpers/memoryMarci.ts +124 -0
  235. package/tests/helpers/phases.ts +23 -0
  236. package/tests/helpers/preload.ts +18 -0
  237. package/tests/helpers/stubApp.ts +2 -0
  238. package/tests/helpers/stubDevice.ts +2 -0
  239. package/tests/helpers/stubFetch.ts +2 -0
  240. package/tests/helpers/stubInput.ts +2 -0
  241. package/dist/inject.js +0 -4730
  242. package/dist/types/core/registry.d.ts +0 -7
  243. package/dist/types/plugins/camera.d.ts +0 -25
  244. package/dist/types/plugins/push.d.ts +0 -46
  245. package/src/bridges.d.ts +0 -1760
  246. package/src/compile/__tests__/assetIconMacro.test.ts +0 -219
  247. package/src/compile/__tests__/assetMacro.test.ts +0 -100
  248. package/src/compile/__tests__/assetName.test.ts +0 -55
  249. package/src/compile/__tests__/compile.test.ts +0 -310
  250. package/src/compile/__tests__/detectEntry.test.ts +0 -151
  251. package/src/compile/__tests__/fontMacro.test.ts +0 -199
  252. package/src/compile/__tests__/serverSplit.test.ts +0 -27
  253. package/src/core/__tests__/stateMachine.test.ts +0 -132
  254. package/src/core/registry.ts +0 -23
  255. package/src/plugins/camera.ts +0 -81
  256. package/src/plugins/push.ts +0 -132
  257. package/src/plugins/qr.ts +0 -73
@@ -0,0 +1,72 @@
1
+ // The device bridge (`_creatorDevice`): what the app runs on — platform facts, haptics, the motion
2
+ // sensor, the clipboard, the share sheet, the file picker, the camera permission.
3
+ // Part of the host contract: every runtime implements this global (runtime/native in C++, the web
4
+ // runtimes in TS). A HOST bridge (`@host`, see ./app.d.ts): the native side is the `HostDevice`
5
+ // table of runtime/native/include/creator-pkg/host.gen.h, generated from this file. Data properties
6
+ // (`platform`, `language`, `pixelRatio`) are FIELDS of that table, read on every access, so a host
7
+ // may update them in place (a window moving to a display of another density).
8
+ import type { bytes, f32, f64 } from "./types"
9
+
10
+ declare global {
11
+ /** @host device */
12
+ var _creatorDevice: {
13
+ /** The host bucket surfaced as `device.platform`. Apps BRANCH on it (mouse-look vs on-screen
14
+ * sticks, hover affordances, key hints), so it names the INPUT MODEL, not the OS — one of
15
+ * "web" | "ios" | "android" | "desktop". macOS reports "desktop", not "macos": a project
16
+ * testing `device.platform === "desktop"` must get the same answer on every desktop host.
17
+ * OS/version detail belongs in the host's own systemInfo callback, never here. */
18
+ platform: string
19
+ language: string
20
+ /** Display device-pixel ratio (physical px per CSS/logical px): 1 on standard displays, 2–3 on
21
+ * retina / iOS. Surfaced as device.pixelRatio — for baking a Canvas at the right resolution
22
+ * without hardcoding it. */
23
+ pixelRatio: f64
24
+ /** Opt into the precise-touch system (full-rate coalesced sampling) where the host supports it —
25
+ * iOS coalesced touches. Surfaced as device.setPreciseTouch. Optional: hosts without a
26
+ * coalesced-input concept (web, headless) simply don't implement it. */
27
+ setPreciseTouch?(enabled: boolean): void
28
+ /** Fire a one-shot semantic haptic (device.vibrate). `style` is a HapticStyle string. Optional:
29
+ * hosts without haptic hardware (web, headless, iPad / older iPhones) simply don't implement it. */
30
+ vibrate?(style: string): void
31
+
32
+ // ---- device.motion (orientation sensor; pull-per-frame model) --------------------------------
33
+ /** Does this device have the motion sensors (gyro)? Surfaced as device.motion.available. */
34
+ motionAvailable?(): boolean
35
+ /** Start fused device-motion updates at `interval` seconds; returns whether it started (false =
36
+ * no sensor / permission denied). May return a Promise on hosts with an async permission prompt
37
+ * (web). Surfaced as device.motion.start. */
38
+ motionStart?(interval: f64): boolean | Promise<boolean>
39
+ /** Stop updates and release the sensor. Surfaced as device.motion.stop. */
40
+ motionStop?(): void
41
+ /** The freshest raw sample in the DEVICE frame: `[qx,qy,qz,qw, gx,gy,gz, interfaceOrientation]`
42
+ * (orientation code: 0 portrait, 1 landscapeLeft, 2 landscapeRight, 3 upsideDown), or null until
43
+ * the first sample / when not running. The SDK converts it to world/screen space. @out 8 */
44
+ motionSample?(): Float32Array | null
45
+
46
+ // ---- Clipboard (docs/app-lifecycle-plan.md) ---------------------------------------------------
47
+ /** Write text to the system clipboard (fire-and-forget). Backs clipboard.write. */
48
+ clipboardWrite?(text: string): void
49
+ /** Read text from the system clipboard — async because web needs a permission prompt; native
50
+ * hosts may complete synchronously. Reject = no access / nothing readable. Backs clipboard.read. */
51
+ clipboardRead?(onComplete: (text: string) => void, onReject: (err: string) => void): void
52
+
53
+ // ---- Share, pick, camera ----------------------------------------------------------------------
54
+ /** Present the OS media share sheet for a host buffer (`systemId` — a File/response id), with an
55
+ * optional caption. iOS: the share sheet also offers "Save to Files"/Photos. Web: saves
56
+ * (downloads) the file; desktop saves to Downloads. Backs the SDK `share(media, text?)`, which
57
+ * is a no-op where the host has no slot (headless, the windowless server). */
58
+ share?(systemId: bytes, text?: string): void
59
+ /** The OS file picker. Settles `onComplete` with the picked files as `[systemId, name, size]`
60
+ * rows (an empty list / null for a cancelled dialog — not a rejection), `onReject` with the
61
+ * error. Absent on hosts without a dialog (headless, CREATOR_HIDDEN runs): the SDK resolves
62
+ * "nothing picked". */
63
+ openFilePicker?(onComplete: (files: [id: number, name: string, size: number][] | null) => void, onReject: (err: Error) => void, multiple: boolean, accept?: string): void
64
+ /** Prompt for camera permission (resolve = granted, reject = denied). Shared by everything that
65
+ * needs the camera — ARScene.prepare, QRScanner, CameraView. Optional: hosts whose view
66
+ * factory prompts on its own (web getUserMedia) don't implement it and the SDK resolves
67
+ * immediately, so callers go through `_requestCameraPermission()`. */
68
+ requestCamera?(onComplete: () => void, onReject: () => void): void
69
+ }
70
+ }
71
+
72
+ export {}
@@ -0,0 +1,80 @@
1
+ // The fetch bridge (`_creatorFetch`): HTTP requests, local assets by name, and the host BUFFER
2
+ // STORE every `systemId` of the platform points into (a fetched body, a picked file, a canvas bake,
3
+ // a local asset — the `bytes` alias of ./types.d.ts, the `_id` an SDK File / FetchResponse carries).
4
+ // Part of the host contract: every runtime implements this global (runtime/native in C++, the web
5
+ // runtimes in TS). A HOST bridge (`@host`, see ./app.d.ts): the native side is the `HostFetch`
6
+ // table of runtime/native/include/creator-pkg/host.gen.h, generated from this file. The store is the
7
+ // HOST's (it owns the bytes; the runtime reads them through `buffer` / `bufferSlice` and never keeps
8
+ // them), so a `bytes` parameter of any bridge reaches native code as that id.
9
+ import type { bytes, i32 } from "./types"
10
+
11
+ /** One part of a multipart request body (the SDK `FormData`'s `_entries`). A text field carries
12
+ * `value`; a binary one carries the host buffer id in `bufferId` (a File / FetchResponse `_id`)
13
+ * and `value` null. */
14
+ export type FetchFormEntry = {
15
+ key: string
16
+ value: string | null
17
+ /** -1 for a text field. */
18
+ bufferId: i32
19
+ filename: string | null
20
+ }
21
+
22
+ declare global {
23
+ /** @host fetch */
24
+ var _creatorFetch: {
25
+ /** `fetchOptions.body` is either a string or a FormData: an object carrying `_entries`, an
26
+ * array of [key, value, filename?]. A `value` object carrying a numeric `_id` is binary (that's
27
+ * the host buffer id — SDK `File` and `FetchResponse` both expose it under that key); anything
28
+ * else is a text field. Same `_id` convention as an image `src` object (see _creatorTree.updateNode).
29
+ * `onProgress` may also arrive positionally (5th argument); the runtime prefers
30
+ * `fetchOptions.onProgress`. A host that reports progress calls it with `{ loaded, total? }`
31
+ * (Android does; desktop does not). The runtime flattens the options into `HostFetch.request`. @custom */
32
+ fetch(url: string, fetchOptions: any, onComplete: (body: Handle, statusCode: number) => void, onReject: (err: string | Error) => void, onProgress?: (progress: { loaded: number, total?: number }) => void): void
33
+ /** A local asset by NAME → its buffer id, or -1 when the host has no such file. The host searches
34
+ * its own places (the app's assets folder, the launched app.js's dir, the runtime dir) and caches
35
+ * the id per name; `_creatorFiles.write` / `remove` on that name drop the cache. `asset()`
36
+ * compiles to `"id:" + _creatorFetch.local(name)` (sdk/src/compile). */
37
+ local(path: string): i32
38
+ /** The buffer parsed as JSON (a syntax error throws). @custom */
39
+ toJson(systemId: bytes): any
40
+ /** The buffer's bytes [start, end) decoded as text (the bundle-header sniff). @custom */
41
+ slice(systemId: bytes, start: i32, end: i32): string
42
+ /** The buffer decoded as UTF-8 text. @custom */
43
+ toText(systemId: bytes): string
44
+ /** The buffer as a Uint8Array copy (a `.terrain` file, any binary the SDK parses itself). @custom */
45
+ toBytes(systemId: bytes): Uint8Array
46
+ /** Release a buffer the app is done with. Optional: a host that keeps every buffer for the
47
+ * process (desktop, where `local` ids are also cached by name) leaves the slot null. */
48
+ }
49
+ }
50
+
51
+ /** The slots of `HostFetch` the runtime calls and JS never sees. */
52
+ export interface HostFetch {
53
+ /** Release a fetched body's buffer once its response was collected (owned.h). A host that keeps
54
+ * every buffer for the process leaves the slot null. */
55
+ dispose?(systemId: i32): void
56
+ /** One HTTP request, off the JS thread. `headers` alternates name, value. `body` is the raw text
57
+ * body or null; `form` the multipart entries (empty when the body is not a FormData) — a host
58
+ * handles at least the raw body. Settle EXACTLY ONE of `onComplete(systemId, status)` /
59
+ * `onReject(message)` through the dispatch queue (`dispatchHeapCall`) and free the other
60
+ * (`jsFree`); `onProgress` (0 when the app passed none) may be called any number of times with
61
+ * `{ loaded, total? }` before the settle and is the host's to free. A URL of the form `id:<n>`
62
+ * is an asset the store already holds: resolve to that id with status 200. */
63
+ request(url: string, method: string, headers: string[], body: string | null, form: FetchFormEntry[], onComplete: (systemId: number, status: number) => void, onReject: (err: string) => void, onProgress?: (progress: { loaded: number, total?: number }) => void): void
64
+ /** The bytes of buffer `id` as a malloc'd copy the runtime frees, `addByte` = with a trailing
65
+ * NUL (the runtime parses it as text). Null / size 0 for an unknown id. */
66
+ buffer(id: i32, addByte: boolean): bytes
67
+ /** Bytes [start, end) of buffer `id`, clamped; same ownership as `buffer`. */
68
+ bufferSlice(id: i32, start: i32, end: i32, addByte: boolean): bytes
69
+ /** The engine's built-in blobs by system id (1 = the default IBL, 2 = the ubershader archive,
70
+ * 3 = the materials archive — engines/gl/materials/pack.mjs: one file, or several archives back
71
+ * to back), read from the host's runtime dir; same ownership as `buffer`. Null for an id the
72
+ * host has nothing for. */
73
+ systemBuffer(id: i32): bytes
74
+ /** Store a copy of `bytes` as a new buffer and return its id (0 = the host cannot). The runtime
75
+ * hands the store what it produced itself — an encoded canvas (`Canvas.toFile`). Optional: a
76
+ * host without the slot makes `toFile` reject. */
77
+ putBuffer?(bytes: Uint8Array): i32
78
+ }
79
+
80
+ export {}
@@ -0,0 +1,70 @@
1
+ // The files bridge (`_creatorFiles`): the SDK `files` global — the read/write/delete half of
2
+ // `_creatorFetch.local`, for hosts where the app OWNS a filesystem (desktop).
3
+ // Part of the host contract. A HOST bridge (`@host`, see ./app.d.ts): the native side is the
4
+ // `HostFiles` table of runtime/native/include/creator-pkg/host.gen.h, generated from this file.
5
+ // OPTIONAL AS A WHOLE (`@optional`): a sandboxed host (web, mobile) provides no table, the global is
6
+ // absent and `files.supported` is false there — the contract's "stand or fall together".
7
+ //
8
+ // ASYNC, like `fetch`: file IO must not block the frame, so each method takes an onComplete/onReject
9
+ // pair (the SDK turns them into a promise) and the host does the work off the JS thread. Hosts
10
+ // must keep the ops ORDERED — two appends to one file settle in call order — so a queue, not a
11
+ // thread per call. Exactly one handle is ever settled (`dispatchHeapCall` + `jsFree`).
12
+ //
13
+ // PATH POLICY, identical for all of them and owned by the host: an ABSOLUTE path is used verbatim;
14
+ // a RELATIVE one is resolved against the app's OWN folder — never the process cwd — which for a
15
+ // packaged desktop app is the exe's directory, one of the directories `_creatorFetch.local` searches
16
+ // by name. So `write("save.json", …)` and `local("save.json")` are a pair; the host drops the name's
17
+ // cached id on write / remove so the next read sees the new bytes.
18
+
19
+ /** One directory entry, as `list` / `stat` report it. */
20
+ export type FileEntry = {
21
+ /** The last path segment. */
22
+ name: string
23
+ /** Relative to the listed directory, `/`-separated (equal to `name` unless the listing was
24
+ * recursive). `stat` reports `name` here. */
25
+ path: string
26
+ kind: "file" | "dir"
27
+ /** Bytes; 0 for a directory. */
28
+ size: number
29
+ /** Last modification, ms since the epoch. */
30
+ modified: number
31
+ }
32
+
33
+ declare global {
34
+ /** @host files @optional */
35
+ var _creatorFiles: {
36
+ /** Write a file, creating the parent folders. `append` adds to the end instead of replacing.
37
+ * `data` is text (written as UTF-8), raw bytes (Uint8Array / ArrayBuffer), or a host buffer
38
+ * object carrying `_id` (an SDK `File` / `FetchResponse` — so a picked or generated file is
39
+ * saved as it is). The runtime flattens it into one span for `HostFiles.write`; the bytes are
40
+ * only valid for the duration of the call, so a host that defers the write copies them first. @custom */
41
+ write(path: string, data: string | Uint8Array | ArrayBuffer | { _id: number }, append: boolean, onComplete: () => void, onReject: (err: Error) => void): void
42
+ /** The whole file as bytes, or null when there is no such file. Unlike `_creatorFetch.local`
43
+ * this re-reads every call and holds nothing — no buffer id to dispose. Only a real failure
44
+ * (an unreadable file) rejects; "not there" is a null result. */
45
+ readBytes(path: string, onComplete: (bytes: Uint8Array | null) => void, onReject: (err: Error) => void): void
46
+ /** The whole file decoded as UTF-8 text, or null when there is no such file. */
47
+ readText(path: string, onComplete: (text: string | null) => void, onReject: (err: Error) => void): void
48
+ /** Delete a file, or an EMPTY directory; `recursive` also deletes a directory's contents.
49
+ * Deleting something that is already gone SUCCEEDS — the post-condition is what matters. */
50
+ remove(path: string, recursive: boolean, onComplete: () => void, onReject: (err: Error) => void): void
51
+ /** Create a directory and any missing parents. An existing directory is success. */
52
+ mkdir(path: string, onComplete: () => void, onReject: (err: Error) => void): void
53
+ /** List a directory. Settles with an array of entries SORTED by `path`, so two runs and two
54
+ * hosts agree. Symlinks are followed for `kind`; anything that is neither file nor directory
55
+ * is skipped. A MISSING directory is a null result (like the readers); a path that is a file,
56
+ * or an unreadable directory, rejects. */
57
+ list(path: string, recursive: boolean, onComplete: (entries: FileEntry[] | null) => void, onReject: (err: Error) => void): void
58
+ /** One entry's metadata for a file or a directory, or null when there is nothing at `path`. */
59
+ stat(path: string, onComplete: (entry: FileEntry | null) => void, onReject: (err: Error) => void): void
60
+ }
61
+ }
62
+
63
+ /** The slots of `HostFiles` the runtime calls and JS never sees. */
64
+ export interface HostFiles {
65
+ /** `_creatorFiles.write` with the data flattened: `size` bytes to write / append. Settle
66
+ * onComplete with no arguments. */
67
+ write(path: string, data: Uint8Array, append: boolean, onComplete: () => void, onReject: (err: Error) => void): void
68
+ }
69
+
70
+ export {}