Skip to content

Commit dfefbd1

Browse files
committed
TW: add types for Scratch.external
1 parent 7e85f7a commit dfefbd1

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

tests/test-scratch-vm-extension-tw.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,10 @@ Scratch.extensions.register({
174174
};
175175
}
176176
});
177+
178+
Scratch.external.importModule(
179+
"https://cdn.jsdelivr.net/npm/@mediapipe/[email protected]/face_detection.js"
180+
);
181+
Scratch.external.blob(
182+
"https://cdn.jsdelivr.net/npm/@mediapipe/[email protected]/face_detection_short.binarypb"
183+
);

types/scratch-vm-extension.d.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,39 @@ declare namespace Scratch {
106106
const ROUND: 2;
107107
const SQUARE: 3;
108108
}
109+
namespace external {
110+
/**
111+
* Import an ES module, like import().
112+
* May be inlined at build-time.
113+
* @param url Must be absolute and constant.
114+
*/
115+
function importModule<T = unknown>(url: string): Promise<T>;
116+
/**
117+
* Returns the contents of a resource, like fetch(). Response headers may be missing.
118+
* May be inlined at build-time.
119+
* @param url Must be absolute and constant.
120+
*/
121+
function fetch(url: string): Promise<Response>;
122+
/**
123+
* Returns the contents of a resource as a data: URL.
124+
* May be inlined at build-time.
125+
* @param url Must be absolute and constant.
126+
*/
127+
function dataURL(url: string): Promise<string>;
128+
/**
129+
* Returns the contents of a resource as a Blob.
130+
* May be inlined at build-time.
131+
* @param url Must be absolute and constant.
132+
*/
133+
function blob(url: string): Promise<Blob>;
134+
/**
135+
* Fetch a script and then evaluate it in an IIFE, returning an expression of your choice.
136+
* May be inlined at build-time.
137+
* @param url Must be absolute and constant.
138+
* @param returnExpression JS expression to return, usually a variable name but could be an object instead. Must be constant.
139+
*/
140+
function evalAndReturn<T = unknown>(url: string, returnExpression: string): Promise<T> | T;
141+
}
109142

110143
// Note that the 'B' in the BOOLEAN enums are capitalized in Scratch. It is not a typo in this file.
111144

0 commit comments

Comments
 (0)