@yodaos-pkg/ink 0.7.0 → 0.8.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.
- package/README.md +53 -0
- package/index.d.ts +15 -0
- package/index.js +56 -7
- package/package.json +1 -1
- package/pkg/ink_web.d.ts +7 -5
- package/pkg/ink_web.js +23 -16
- package/pkg/ink_web_bg.wasm +0 -0
- package/pkg/ink_web_bg.wasm.d.ts +6 -5
package/README.md
CHANGED
|
@@ -397,6 +397,38 @@ Starts the continuous render loop.
|
|
|
397
397
|
- `InkView`
|
|
398
398
|
- Returns the current instance so it can be chained
|
|
399
399
|
|
|
400
|
+
### `view.setOnCloseRequested(callback)`
|
|
401
|
+
|
|
402
|
+
Registers a host callback for runtime-driven close requests.
|
|
403
|
+
|
|
404
|
+
**Parameters**
|
|
405
|
+
|
|
406
|
+
- `callback: (() => void) | null`
|
|
407
|
+
- Required
|
|
408
|
+
- Called after Ink emits `lifecycle.closeRequested`
|
|
409
|
+
- Pass `null` to clear the callback
|
|
410
|
+
|
|
411
|
+
**What it does**
|
|
412
|
+
|
|
413
|
+
- Listens for close requests emitted by the Ink runtime
|
|
414
|
+
- Automatically calls `stopRendering()` before invoking the callback
|
|
415
|
+
- Lets the host destroy or replace the closed view on its own timing
|
|
416
|
+
|
|
417
|
+
**Returns**
|
|
418
|
+
|
|
419
|
+
- `InkView`
|
|
420
|
+
- Returns the current instance so it can be chained
|
|
421
|
+
|
|
422
|
+
### `view.isCloseRequested()`
|
|
423
|
+
|
|
424
|
+
Returns whether Ink has already requested that the host close this view.
|
|
425
|
+
|
|
426
|
+
**Returns**
|
|
427
|
+
|
|
428
|
+
- `boolean`
|
|
429
|
+
- `true` after the runtime emits `lifecycle.closeRequested`
|
|
430
|
+
- `false` before any close request, or after the host opens a new app in the same view
|
|
431
|
+
|
|
400
432
|
### `view.destroy()`
|
|
401
433
|
|
|
402
434
|
Destroys the current `InkView` and releases its resources.
|
|
@@ -411,6 +443,7 @@ Destroys the current `InkView` and releases its resources.
|
|
|
411
443
|
- Removes event listeners created by `bindDomEvents()`
|
|
412
444
|
- Calls the underlying `InkWebView.destroy()`
|
|
413
445
|
- Releases runtime resources held by the current view
|
|
446
|
+
- Should be called by the host after a close-requested view is no longer needed
|
|
414
447
|
|
|
415
448
|
**Returns**
|
|
416
449
|
|
|
@@ -590,6 +623,11 @@ const view = await createInkView({
|
|
|
590
623
|
});
|
|
591
624
|
|
|
592
625
|
view.bindDomEvents();
|
|
626
|
+
view.setOnCloseRequested(() => {
|
|
627
|
+
if (view.isCloseRequested()) {
|
|
628
|
+
view.destroy();
|
|
629
|
+
}
|
|
630
|
+
});
|
|
593
631
|
view.openBundle({
|
|
594
632
|
appId: 'demo-app',
|
|
595
633
|
files,
|
|
@@ -632,6 +670,11 @@ const view = await createInkView({
|
|
|
632
670
|
|
|
633
671
|
```js
|
|
634
672
|
view.bindDomEvents();
|
|
673
|
+
view.setOnCloseRequested(() => {
|
|
674
|
+
if (view.isCloseRequested()) {
|
|
675
|
+
view.destroy();
|
|
676
|
+
}
|
|
677
|
+
});
|
|
635
678
|
|
|
636
679
|
await view.openFromVfs({
|
|
637
680
|
appId: 'demo-app',
|
|
@@ -703,6 +746,11 @@ onMounted(async () => {
|
|
|
703
746
|
});
|
|
704
747
|
|
|
705
748
|
view.bindDomEvents();
|
|
749
|
+
view.setOnCloseRequested(() => {
|
|
750
|
+
if (view.isCloseRequested()) {
|
|
751
|
+
view.destroy();
|
|
752
|
+
}
|
|
753
|
+
});
|
|
706
754
|
view.openBundle({
|
|
707
755
|
appId: props.appId,
|
|
708
756
|
files: props.files,
|
|
@@ -788,6 +836,11 @@ export function InkCanvas({ appId, files }: InkCanvasProps) {
|
|
|
788
836
|
});
|
|
789
837
|
|
|
790
838
|
view.bindDomEvents();
|
|
839
|
+
view.setOnCloseRequested(() => {
|
|
840
|
+
if (view.isCloseRequested()) {
|
|
841
|
+
view.destroy();
|
|
842
|
+
}
|
|
843
|
+
});
|
|
791
844
|
view.openBundle({
|
|
792
845
|
appId,
|
|
793
846
|
files,
|
package/index.d.ts
CHANGED
|
@@ -195,6 +195,9 @@ export interface InkHostMessageStream {
|
|
|
195
195
|
close(): void;
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
+
/** Callback invoked after the runtime requests that the host close the current view. */
|
|
199
|
+
export type InkCloseRequestedHandler = () => void;
|
|
200
|
+
|
|
198
201
|
/**
|
|
199
202
|
* Initializes the browser SDK and ensures the wasm runtime is ready to create
|
|
200
203
|
* views. Most applications can use {@link InkView.create} or
|
|
@@ -396,6 +399,18 @@ export declare class InkView {
|
|
|
396
399
|
/** Returns whether the internal render loop is currently active. */
|
|
397
400
|
isRunning(): boolean;
|
|
398
401
|
|
|
402
|
+
/**
|
|
403
|
+
* Registers the callback fired after Ink requests that the host close this view.
|
|
404
|
+
*
|
|
405
|
+
* When close is requested, the SDK marks the view as close-requested, stops
|
|
406
|
+
* the internal render loop automatically, and then invokes this callback.
|
|
407
|
+
* Pass `null` to clear the current callback.
|
|
408
|
+
*/
|
|
409
|
+
setOnCloseRequested(callback: InkCloseRequestedHandler | null): this;
|
|
410
|
+
|
|
411
|
+
/** Returns whether Ink has already requested that the host close this view. */
|
|
412
|
+
isCloseRequested(): boolean;
|
|
413
|
+
|
|
399
414
|
/**
|
|
400
415
|
* Releases the underlying wasm view and detaches associated host resources.
|
|
401
416
|
*
|
package/index.js
CHANGED
|
@@ -395,8 +395,10 @@ export class InkView {
|
|
|
395
395
|
#animationFrameApi;
|
|
396
396
|
#frameHandle;
|
|
397
397
|
#autoRender;
|
|
398
|
+
#closeRequested;
|
|
398
399
|
#destroyed;
|
|
399
400
|
#domCleanup;
|
|
401
|
+
#onCloseRequested;
|
|
400
402
|
|
|
401
403
|
constructor(rawView, options = {}) {
|
|
402
404
|
this.#rawView = rawView;
|
|
@@ -404,8 +406,33 @@ export class InkView {
|
|
|
404
406
|
this.#animationFrameApi = ensureAnimationFrameApi();
|
|
405
407
|
this.#frameHandle = null;
|
|
406
408
|
this.#autoRender = false;
|
|
409
|
+
this.#closeRequested = false;
|
|
407
410
|
this.#destroyed = false;
|
|
408
411
|
this.#domCleanup = null;
|
|
412
|
+
this.#onCloseRequested = null;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
#resetCloseRequestedState() {
|
|
416
|
+
this.#closeRequested = false;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
#consumeCloseRequested() {
|
|
420
|
+
if (this.#destroyed || this.#closeRequested) {
|
|
421
|
+
return this.#closeRequested;
|
|
422
|
+
}
|
|
423
|
+
if (typeof this.#rawView.consumeCloseRequested !== 'function') {
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
if (!this.#rawView.consumeCloseRequested()) {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
this.#closeRequested = true;
|
|
431
|
+
this.stopRendering();
|
|
432
|
+
if (typeof this.#onCloseRequested === 'function') {
|
|
433
|
+
this.#onCloseRequested();
|
|
434
|
+
}
|
|
435
|
+
return true;
|
|
409
436
|
}
|
|
410
437
|
|
|
411
438
|
bindCanvas(canvas) {
|
|
@@ -559,13 +586,16 @@ export class InkView {
|
|
|
559
586
|
throw new Error('`appId` must be a non-empty string.');
|
|
560
587
|
}
|
|
561
588
|
|
|
589
|
+
this.#resetCloseRequestedState();
|
|
562
590
|
this.#rawView.openBundle(
|
|
563
591
|
appId,
|
|
564
592
|
normalizeBundleFiles(files),
|
|
565
593
|
initialPage,
|
|
566
594
|
serializeQuery(query),
|
|
567
595
|
);
|
|
568
|
-
this
|
|
596
|
+
if (!this.#consumeCloseRequested()) {
|
|
597
|
+
this.requestRender();
|
|
598
|
+
}
|
|
569
599
|
return this;
|
|
570
600
|
}
|
|
571
601
|
|
|
@@ -574,8 +604,11 @@ export class InkView {
|
|
|
574
604
|
throw new Error('`path` must be a non-empty string.');
|
|
575
605
|
}
|
|
576
606
|
|
|
607
|
+
this.#resetCloseRequestedState();
|
|
577
608
|
this.#rawView.open(path.trim(), initialPage, serializeQuery(query));
|
|
578
|
-
this
|
|
609
|
+
if (!this.#consumeCloseRequested()) {
|
|
610
|
+
this.requestRender();
|
|
611
|
+
}
|
|
579
612
|
return this;
|
|
580
613
|
}
|
|
581
614
|
|
|
@@ -656,18 +689,19 @@ export class InkView {
|
|
|
656
689
|
}
|
|
657
690
|
|
|
658
691
|
render() {
|
|
659
|
-
if (this.#destroyed) {
|
|
692
|
+
if (this.#destroyed || this.#closeRequested) {
|
|
660
693
|
return false;
|
|
661
694
|
}
|
|
662
695
|
const hasMoreWork = Boolean(this.#rawView.render());
|
|
663
|
-
|
|
696
|
+
const closeRequested = this.#consumeCloseRequested();
|
|
697
|
+
if (!closeRequested && (hasMoreWork || this.#autoRender)) {
|
|
664
698
|
this.requestRender();
|
|
665
699
|
}
|
|
666
|
-
return hasMoreWork;
|
|
700
|
+
return !closeRequested && hasMoreWork;
|
|
667
701
|
}
|
|
668
702
|
|
|
669
703
|
requestRender() {
|
|
670
|
-
if (this.#destroyed) {
|
|
704
|
+
if (this.#destroyed || this.#closeRequested) {
|
|
671
705
|
return this;
|
|
672
706
|
}
|
|
673
707
|
if (this.#frameHandle != null) {
|
|
@@ -682,6 +716,9 @@ export class InkView {
|
|
|
682
716
|
}
|
|
683
717
|
|
|
684
718
|
startRendering() {
|
|
719
|
+
if (this.#closeRequested) {
|
|
720
|
+
return this;
|
|
721
|
+
}
|
|
685
722
|
this.#autoRender = true;
|
|
686
723
|
this.requestRender();
|
|
687
724
|
return this;
|
|
@@ -697,7 +734,19 @@ export class InkView {
|
|
|
697
734
|
}
|
|
698
735
|
|
|
699
736
|
isRunning() {
|
|
700
|
-
return Boolean(this.#rawView.isRunning());
|
|
737
|
+
return !this.#closeRequested && Boolean(this.#rawView.isRunning());
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
setOnCloseRequested(callback) {
|
|
741
|
+
if (callback != null && typeof callback !== 'function') {
|
|
742
|
+
throw new TypeError('`callback` must be a function or null.');
|
|
743
|
+
}
|
|
744
|
+
this.#onCloseRequested = callback || null;
|
|
745
|
+
return this;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
isCloseRequested() {
|
|
749
|
+
return this.#closeRequested;
|
|
701
750
|
}
|
|
702
751
|
|
|
703
752
|
destroy() {
|
package/package.json
CHANGED
package/pkg/ink_web.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export class InkWebView {
|
|
|
14
14
|
[Symbol.dispose](): void;
|
|
15
15
|
bindCanvas(canvas: HTMLCanvasElement): void;
|
|
16
16
|
blur(): void;
|
|
17
|
+
consumeCloseRequested(): boolean;
|
|
17
18
|
createMessageStream(origin: string, last_event_id: string): InkWebMessageStream;
|
|
18
19
|
destroy(): void;
|
|
19
20
|
dispatchInput(event_type: string, code: string, timestamp: number): void;
|
|
@@ -46,6 +47,7 @@ export interface InitOutput {
|
|
|
46
47
|
readonly inkwebmessagestream_write: (a: number, b: number, c: number, d: number) => void;
|
|
47
48
|
readonly inkwebview_bindCanvas: (a: number, b: number, c: number) => void;
|
|
48
49
|
readonly inkwebview_blur: (a: number) => void;
|
|
50
|
+
readonly inkwebview_consumeCloseRequested: (a: number) => number;
|
|
49
51
|
readonly inkwebview_createMessageStream: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
50
52
|
readonly inkwebview_destroy: (a: number) => void;
|
|
51
53
|
readonly inkwebview_dispatchInput: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
@@ -62,11 +64,11 @@ export interface InitOutput {
|
|
|
62
64
|
readonly inkwebview_resize: (a: number, b: number, c: number, d: number) => void;
|
|
63
65
|
readonly inkwebview_setInteractive: (a: number, b: number) => void;
|
|
64
66
|
readonly main: () => void;
|
|
65
|
-
readonly
|
|
66
|
-
readonly
|
|
67
|
-
readonly
|
|
68
|
-
readonly
|
|
69
|
-
readonly
|
|
67
|
+
readonly __wasm_bindgen_func_elem_9308: (a: number, b: number) => void;
|
|
68
|
+
readonly __wasm_bindgen_func_elem_13493: (a: number, b: number) => void;
|
|
69
|
+
readonly __wasm_bindgen_func_elem_9474: (a: number, b: number, c: number) => void;
|
|
70
|
+
readonly __wasm_bindgen_func_elem_13494: (a: number, b: number, c: number) => void;
|
|
71
|
+
readonly __wasm_bindgen_func_elem_9475: (a: number, b: number) => void;
|
|
70
72
|
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
71
73
|
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
72
74
|
readonly __wbindgen_export3: (a: number) => void;
|
package/pkg/ink_web.js
CHANGED
|
@@ -72,6 +72,13 @@ export class InkWebView {
|
|
|
72
72
|
blur() {
|
|
73
73
|
wasm.inkwebview_blur(this.__wbg_ptr);
|
|
74
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* @returns {boolean}
|
|
77
|
+
*/
|
|
78
|
+
consumeCloseRequested() {
|
|
79
|
+
const ret = wasm.inkwebview_consumeCloseRequested(this.__wbg_ptr);
|
|
80
|
+
return ret !== 0;
|
|
81
|
+
}
|
|
75
82
|
/**
|
|
76
83
|
* @param {string} origin
|
|
77
84
|
* @param {string} last_event_id
|
|
@@ -1087,28 +1094,28 @@ function __wbg_get_imports() {
|
|
|
1087
1094
|
return ret;
|
|
1088
1095
|
},
|
|
1089
1096
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
1090
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx:
|
|
1091
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
1097
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 2519, function: Function { arguments: [NamedExternref("CloseEvent")], shim_idx: 2472, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1098
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_9308, __wasm_bindgen_func_elem_9474);
|
|
1092
1099
|
return addHeapObject(ret);
|
|
1093
1100
|
},
|
|
1094
1101
|
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
1095
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx:
|
|
1096
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
1102
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 2519, function: Function { arguments: [NamedExternref("Event")], shim_idx: 2472, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1103
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_9308, __wasm_bindgen_func_elem_9474);
|
|
1097
1104
|
return addHeapObject(ret);
|
|
1098
1105
|
},
|
|
1099
1106
|
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
|
|
1100
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx:
|
|
1101
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
1107
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 2519, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 2472, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1108
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_9308, __wasm_bindgen_func_elem_9474);
|
|
1102
1109
|
return addHeapObject(ret);
|
|
1103
1110
|
},
|
|
1104
1111
|
__wbindgen_cast_0000000000000004: function(arg0, arg1) {
|
|
1105
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx:
|
|
1106
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
1112
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 2519, function: Function { arguments: [], shim_idx: 2521, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1113
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_9308, __wasm_bindgen_func_elem_9475);
|
|
1107
1114
|
return addHeapObject(ret);
|
|
1108
1115
|
},
|
|
1109
1116
|
__wbindgen_cast_0000000000000005: function(arg0, arg1) {
|
|
1110
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx:
|
|
1111
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
1117
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 3419, function: Function { arguments: [Externref], shim_idx: 3420, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1118
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_13493, __wasm_bindgen_func_elem_13494);
|
|
1112
1119
|
return addHeapObject(ret);
|
|
1113
1120
|
},
|
|
1114
1121
|
__wbindgen_cast_0000000000000006: function(arg0) {
|
|
@@ -1165,16 +1172,16 @@ function __wbg_get_imports() {
|
|
|
1165
1172
|
};
|
|
1166
1173
|
}
|
|
1167
1174
|
|
|
1168
|
-
function
|
|
1169
|
-
wasm.
|
|
1175
|
+
function __wasm_bindgen_func_elem_9475(arg0, arg1) {
|
|
1176
|
+
wasm.__wasm_bindgen_func_elem_9475(arg0, arg1);
|
|
1170
1177
|
}
|
|
1171
1178
|
|
|
1172
|
-
function
|
|
1173
|
-
wasm.
|
|
1179
|
+
function __wasm_bindgen_func_elem_9474(arg0, arg1, arg2) {
|
|
1180
|
+
wasm.__wasm_bindgen_func_elem_9474(arg0, arg1, addHeapObject(arg2));
|
|
1174
1181
|
}
|
|
1175
1182
|
|
|
1176
|
-
function
|
|
1177
|
-
wasm.
|
|
1183
|
+
function __wasm_bindgen_func_elem_13494(arg0, arg1, arg2) {
|
|
1184
|
+
wasm.__wasm_bindgen_func_elem_13494(arg0, arg1, addHeapObject(arg2));
|
|
1178
1185
|
}
|
|
1179
1186
|
|
|
1180
1187
|
|
package/pkg/ink_web_bg.wasm
CHANGED
|
Binary file
|
package/pkg/ink_web_bg.wasm.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export const inkwebmessagestream_close: (a: number) => void;
|
|
|
8
8
|
export const inkwebmessagestream_write: (a: number, b: number, c: number, d: number) => void;
|
|
9
9
|
export const inkwebview_bindCanvas: (a: number, b: number, c: number) => void;
|
|
10
10
|
export const inkwebview_blur: (a: number) => void;
|
|
11
|
+
export const inkwebview_consumeCloseRequested: (a: number) => number;
|
|
11
12
|
export const inkwebview_createMessageStream: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
12
13
|
export const inkwebview_destroy: (a: number) => void;
|
|
13
14
|
export const inkwebview_dispatchInput: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
@@ -24,11 +25,11 @@ export const inkwebview_render: (a: number, b: number) => void;
|
|
|
24
25
|
export const inkwebview_resize: (a: number, b: number, c: number, d: number) => void;
|
|
25
26
|
export const inkwebview_setInteractive: (a: number, b: number) => void;
|
|
26
27
|
export const main: () => void;
|
|
27
|
-
export const
|
|
28
|
-
export const
|
|
29
|
-
export const
|
|
30
|
-
export const
|
|
31
|
-
export const
|
|
28
|
+
export const __wasm_bindgen_func_elem_9308: (a: number, b: number) => void;
|
|
29
|
+
export const __wasm_bindgen_func_elem_13493: (a: number, b: number) => void;
|
|
30
|
+
export const __wasm_bindgen_func_elem_9474: (a: number, b: number, c: number) => void;
|
|
31
|
+
export const __wasm_bindgen_func_elem_13494: (a: number, b: number, c: number) => void;
|
|
32
|
+
export const __wasm_bindgen_func_elem_9475: (a: number, b: number) => void;
|
|
32
33
|
export const __wbindgen_export: (a: number, b: number) => number;
|
|
33
34
|
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
34
35
|
export const __wbindgen_export3: (a: number) => void;
|