castle-web-sdk 0.4.11 → 0.4.12
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 +17 -0
- package/dist/castle.d.ts +1 -1
- package/dist/castle.js +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -412,6 +412,23 @@ await writeFile("scenes/main.scene", JSON.stringify(scene, null, 2));
|
|
|
412
412
|
Only works while editing locally with `castle-web serve`. Calls from a
|
|
413
413
|
published deck fail.
|
|
414
414
|
|
|
415
|
+
### `fileUrl(path): string`
|
|
416
|
+
|
|
417
|
+
A URL that serves a deck file as raw bytes. Point an `<img>`, `<audio>`,
|
|
418
|
+
or `<video>` at it when editor UI has to show a file the browser renders
|
|
419
|
+
natively — `writeFile`'s counterpart reads text, which is nothing an
|
|
420
|
+
image or a sound can be read as.
|
|
421
|
+
|
|
422
|
+
```js
|
|
423
|
+
import { fileUrl } from "castle-web-sdk";
|
|
424
|
+
|
|
425
|
+
<img src={fileUrl("assets/logo.png")} alt="" />;
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
Like `writeFile`, this only means anything while editing locally with
|
|
429
|
+
`castle-web serve` — a published deck has no serve to ask, and should
|
|
430
|
+
load its assets through the bundler instead.
|
|
431
|
+
|
|
415
432
|
## CastleError
|
|
416
433
|
|
|
417
434
|
Every error the SDK throws is a `CastleError`. Check `code` to tell
|
package/dist/castle.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export { Pass } from "./passes";
|
|
|
11
11
|
export type { CastlePassApi, PassOfferResult, PassOfferStatus, } from "./passes";
|
|
12
12
|
export { Portal } from "./portal";
|
|
13
13
|
export type { CastlePortalApi, PortalOpenResult, PortalOpenStatus, PortalPrefetchResult, PortalPrefetchStatus, } from "./portal";
|
|
14
|
-
export { CARD_RATIO, initCard, onBeforeRestart, onFilesChanged, onSaveReloadState, requestReload, setup, takeReloadState, writeFile, } from "./runtime";
|
|
14
|
+
export { CARD_RATIO, fileUrl, initCard, onBeforeRestart, onFilesChanged, onSaveReloadState, requestReload, setup, takeReloadState, writeFile, } from "./runtime";
|
|
15
15
|
export type { FileChange, FilesChangedEvent } from "./runtime";
|
|
16
16
|
export { SharedStorage, Storage } from "./storage";
|
|
17
17
|
export { Time } from "./time";
|
package/dist/castle.js
CHANGED
|
@@ -7,7 +7,7 @@ export { Leaderboard } from "./leaderboard";
|
|
|
7
7
|
export { Lifecycle } from "./lifecycle";
|
|
8
8
|
export { Pass } from "./passes";
|
|
9
9
|
export { Portal } from "./portal";
|
|
10
|
-
export { CARD_RATIO, initCard, onBeforeRestart, onFilesChanged, onSaveReloadState, requestReload, setup, takeReloadState, writeFile, } from "./runtime";
|
|
10
|
+
export { CARD_RATIO, fileUrl, initCard, onBeforeRestart, onFilesChanged, onSaveReloadState, requestReload, setup, takeReloadState, writeFile, } from "./runtime";
|
|
11
11
|
export { SharedStorage, Storage } from "./storage";
|
|
12
12
|
export { Time } from "./time";
|
|
13
13
|
export { User } from "./user";
|
package/dist/runtime.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export interface FilesChangedEvent {
|
|
|
25
25
|
}
|
|
26
26
|
export declare function setup(): void;
|
|
27
27
|
export declare function writeFile(path: string, contents: string): Promise<LocalResponse>;
|
|
28
|
+
export declare function fileUrl(path: string): string;
|
|
28
29
|
export declare function initCard(): HTMLDivElement;
|
|
29
30
|
export declare function sendLocalCommand<C extends CommandName>(command: C, params: CommandParams[C]): Promise<CommandResponseEnvelope>;
|
|
30
31
|
export declare function onFilesChanged(listener: (event: FilesChangedEvent) => void): () => void;
|
package/dist/runtime.js
CHANGED
|
@@ -30,6 +30,14 @@ export function writeFile(path, contents) {
|
|
|
30
30
|
contents,
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
+
// A same-origin URL that serves a deck file as raw bytes. Editor UI that shows
|
|
34
|
+
// a file the browser renders natively -- an image in an `<img>`, a sound in an
|
|
35
|
+
// `<audio>` -- points at this instead of reading the file, which only speaks
|
|
36
|
+
// text. Only meaningful while editing locally with `castle-web serve`; a
|
|
37
|
+
// published deck has no serve to ask.
|
|
38
|
+
export function fileUrl(path) {
|
|
39
|
+
return `/__castle/files/raw?path=${encodeURIComponent(path)}`;
|
|
40
|
+
}
|
|
33
41
|
export function initCard() {
|
|
34
42
|
const style = document.createElement("style");
|
|
35
43
|
style.textContent = `
|