@defold-typescript/types 0.37.0 → 0.39.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/api-signatures.json +348 -267
- package/examples/translations.json +323 -147
- package/generated/b2d_body.d.ts +7 -4
- package/generated/buffer.d.ts +16 -4
- package/generated/camera.d.ts +1 -0
- package/generated/collectionfactory.d.ts +5 -2
- package/generated/collectionproxy.d.ts +1 -1
- package/generated/factory.d.ts +2 -1
- package/generated/go.d.ts +141 -86
- package/generated/graphics.d.ts +2 -0
- package/generated/gui.d.ts +65 -40
- package/generated/html5.d.ts +1 -1
- package/generated/http.d.ts +4 -0
- package/generated/model.d.ts +9 -4
- package/generated/particlefx.d.ts +1 -1
- package/generated/physics.d.ts +16 -9
- package/generated/profiler.d.ts +9 -2
- package/generated/render.d.ts +224 -99
- package/generated/resource.d.ts +143 -157
- package/generated/socket.d.ts +13 -8
- package/generated/sound.d.ts +3 -2
- package/generated/sys.d.ts +16 -10
- package/generated/tilemap.d.ts +25 -19
- package/generated/timer.d.ts +33 -24
- package/generated/versions/defold-1.12.4/buffer.d.ts +16 -4
- package/generated/versions/defold-1.12.4/camera.d.ts +1 -0
- package/generated/versions/defold-1.12.4/collectionfactory.d.ts +5 -2
- package/generated/versions/defold-1.12.4/collectionproxy.d.ts +1 -1
- package/generated/versions/defold-1.12.4/factory.d.ts +2 -1
- package/generated/versions/defold-1.12.4/go.d.ts +141 -86
- package/generated/versions/defold-1.12.4/graphics.d.ts +2 -0
- package/generated/versions/defold-1.12.4/gui.d.ts +63 -39
- package/generated/versions/defold-1.12.4/html5.d.ts +1 -1
- package/generated/versions/defold-1.12.4/http.d.ts +4 -0
- package/generated/versions/defold-1.12.4/model.d.ts +9 -4
- package/generated/versions/defold-1.12.4/particlefx.d.ts +1 -1
- package/generated/versions/defold-1.12.4/physics.d.ts +16 -9
- package/generated/versions/defold-1.12.4/profiler.d.ts +9 -2
- package/generated/versions/defold-1.12.4/render.d.ts +223 -98
- package/generated/versions/defold-1.12.4/resource.d.ts +143 -157
- package/generated/versions/defold-1.12.4/socket.d.ts +13 -8
- package/generated/versions/defold-1.12.4/sound.d.ts +3 -2
- package/generated/versions/defold-1.12.4/sys.d.ts +16 -10
- package/generated/versions/defold-1.12.4/tilemap.d.ts +25 -19
- package/generated/versions/defold-1.12.4/timer.d.ts +33 -24
- package/generated/versions/defold-1.12.4/vmath.d.ts +13 -5
- package/generated/versions/defold-1.12.4/window.d.ts +5 -3
- package/generated/versions/defold-1.13.0/b2d_body.d.ts +7 -4
- package/generated/versions/defold-1.13.0/buffer.d.ts +16 -4
- package/generated/versions/defold-1.13.0/camera.d.ts +1 -0
- package/generated/versions/defold-1.13.0/collectionfactory.d.ts +5 -2
- package/generated/versions/defold-1.13.0/collectionproxy.d.ts +1 -1
- package/generated/versions/defold-1.13.0/factory.d.ts +2 -1
- package/generated/versions/defold-1.13.0/go.d.ts +141 -86
- package/generated/versions/defold-1.13.0/graphics.d.ts +2 -0
- package/generated/versions/defold-1.13.0/gui.d.ts +63 -39
- package/generated/versions/defold-1.13.0/html5.d.ts +1 -1
- package/generated/versions/defold-1.13.0/http.d.ts +4 -0
- package/generated/versions/defold-1.13.0/model.d.ts +9 -4
- package/generated/versions/defold-1.13.0/particlefx.d.ts +1 -1
- package/generated/versions/defold-1.13.0/physics.d.ts +16 -9
- package/generated/versions/defold-1.13.0/profiler.d.ts +9 -2
- package/generated/versions/defold-1.13.0/render.d.ts +224 -99
- package/generated/versions/defold-1.13.0/resource.d.ts +143 -157
- package/generated/versions/defold-1.13.0/socket.d.ts +13 -8
- package/generated/versions/defold-1.13.0/sound.d.ts +3 -2
- package/generated/versions/defold-1.13.0/sys.d.ts +16 -10
- package/generated/versions/defold-1.13.0/tilemap.d.ts +25 -19
- package/generated/versions/defold-1.13.0/timer.d.ts +33 -24
- package/generated/versions/defold-1.13.0/vmath.d.ts +13 -5
- package/generated/versions/defold-1.13.0/window.d.ts +5 -3
- package/generated/vmath.d.ts +13 -5
- package/generated/window.d.ts +5 -3
- package/package.json +2 -1
- package/src/api-doc.ts +8 -0
- package/src/doc-comment.ts +213 -32
- package/src/emit-dts.ts +501 -10
- package/src/example-store.ts +26 -0
- package/src/index.ts +5 -0
- package/src/lifecycle.ts +31 -8
- package/src/message-dispatch.d.ts +55 -13
- package/src/msg-overloads.d.ts +73 -3
- package/src/render-overloads.d.ts +0 -17
package/src/doc-comment.ts
CHANGED
|
@@ -16,6 +16,47 @@ function decodeEntities(text: string): string {
|
|
|
16
16
|
return out.split("&").join("&");
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Join a list marker left alone on its line back onto the item's first content
|
|
21
|
+
* line. Upstream prose puts a newline between `<li>` and the item's first word,
|
|
22
|
+
* which the whitespace pass preserves, dropping the value out of the list. The
|
|
23
|
+
* item's remaining lines stay where they are: Markdown's lazy continuation
|
|
24
|
+
* already keeps an unindented line inside the item's paragraph.
|
|
25
|
+
*/
|
|
26
|
+
function weldStrandedListMarkers(text: string): string {
|
|
27
|
+
const lines = text.split("\n");
|
|
28
|
+
const out: string[] = [];
|
|
29
|
+
let inFence = false;
|
|
30
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
31
|
+
const line = lines[index] ?? "";
|
|
32
|
+
if (line.startsWith("```")) {
|
|
33
|
+
inFence = !inFence;
|
|
34
|
+
out.push(line);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (inFence || line !== "-") {
|
|
38
|
+
out.push(line);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
let ahead = index + 1;
|
|
42
|
+
while (ahead < lines.length && lines[ahead] === "") ahead += 1;
|
|
43
|
+
const content = lines[ahead];
|
|
44
|
+
if (
|
|
45
|
+
content === undefined ||
|
|
46
|
+
content === "-" ||
|
|
47
|
+
content.startsWith("- ") ||
|
|
48
|
+
content.startsWith("```")
|
|
49
|
+
) {
|
|
50
|
+
// No value to weld onto — drop the marker and the blank run behind it.
|
|
51
|
+
index = ahead - 1;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
out.push(`- ${content}`);
|
|
55
|
+
index = ahead;
|
|
56
|
+
}
|
|
57
|
+
return out.join("\n").trim();
|
|
58
|
+
}
|
|
59
|
+
|
|
19
60
|
/**
|
|
20
61
|
* Convert a ref-doc HTML fragment to clean Markdown/plain text suitable for a
|
|
21
62
|
* JSDoc comment body. Pure and free of any `ApiModule` dependency so the emit
|
|
@@ -45,6 +86,12 @@ export function htmlToDocText(html: string): string {
|
|
|
45
86
|
.replace(/\n{3,}/g, "\n\n")
|
|
46
87
|
.trim();
|
|
47
88
|
|
|
89
|
+
text = weldStrandedListMarkers(text);
|
|
90
|
+
|
|
91
|
+
// Upstream prose can open a fence and end mid-body; left open it swallows the
|
|
92
|
+
// rest of the JSDoc block and everything after it on the rendered page.
|
|
93
|
+
if ((text.match(/^```/gm) ?? []).length % 2 === 1) text += "\n```";
|
|
94
|
+
|
|
48
95
|
// A literal `*/` would close the JSDoc comment early; escape it.
|
|
49
96
|
return text.split("*/").join("*\\/");
|
|
50
97
|
}
|
|
@@ -70,45 +117,169 @@ export function htmlToCodeText(html: string): string {
|
|
|
70
117
|
return collapsed.split("*/").join("*\\/");
|
|
71
118
|
}
|
|
72
119
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
* for plain-code examples). Returns `""` for empty / whitespace-only input.
|
|
82
|
-
*/
|
|
83
|
-
export function examplesHtmlToMarkdown(html: string): string {
|
|
84
|
-
if (html.trim() === "") return "";
|
|
120
|
+
// One run of the `examples` fragment: the inner markup of a `<div
|
|
121
|
+
// class="codehilite">` block, or the markup between two of them. `lang` is
|
|
122
|
+
// meaningful on a code region only.
|
|
123
|
+
interface ExampleRegion {
|
|
124
|
+
kind: "code" | "prose";
|
|
125
|
+
html: string;
|
|
126
|
+
lang: string;
|
|
127
|
+
}
|
|
85
128
|
|
|
86
|
-
|
|
129
|
+
// The one `codehilite` walk. Both the markdown lane (`examplesHtmlToMarkdown`)
|
|
130
|
+
// and the store lane (`splitExampleSources`) read their regions from here, so
|
|
131
|
+
// the two cannot disagree about where an example begins. `matched` is false for
|
|
132
|
+
// a fragment carrying no block at all, which both lanes treat as one whole-blob
|
|
133
|
+
// code run.
|
|
134
|
+
function scanExampleRegions(html: string): { matched: boolean; regions: ExampleRegion[] } {
|
|
135
|
+
const regions: ExampleRegion[] = [];
|
|
87
136
|
const blocks = /<div class="codehilite">([\s\S]*?)<\/div>/gi;
|
|
88
137
|
let lastIndex = 0;
|
|
89
138
|
let matched = false;
|
|
90
139
|
for (let match = blocks.exec(html); match !== null; match = blocks.exec(html)) {
|
|
91
140
|
matched = true;
|
|
92
|
-
|
|
93
|
-
if (prose !== "") parts.push(prose);
|
|
141
|
+
regions.push({ kind: "prose", html: html.slice(lastIndex, match.index), lang: "lua" });
|
|
94
142
|
const inner = match[1] ?? "";
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
143
|
+
regions.push({
|
|
144
|
+
kind: "code",
|
|
145
|
+
html: inner,
|
|
146
|
+
lang: /<code\b[^>]*\bclass="language-([^"\s]+)"/i.exec(inner)?.[1] ?? "lua",
|
|
147
|
+
});
|
|
98
148
|
lastIndex = match.index + match[0].length;
|
|
99
149
|
}
|
|
150
|
+
if (!matched) return { matched: false, regions: [{ kind: "code", html, lang: "lua" }] };
|
|
151
|
+
regions.push({ kind: "prose", html: html.slice(lastIndex), lang: "lua" });
|
|
152
|
+
return { matched: true, regions };
|
|
153
|
+
}
|
|
100
154
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
155
|
+
/**
|
|
156
|
+
* Convert a ref-doc `examples` HTML fragment — prose interleaved with one or
|
|
157
|
+
* more `<div class="codehilite">…</div>` syntax-highlight blocks — into Markdown,
|
|
158
|
+
* one fence per example that `segmentExampleRegions` carves out. Each segment
|
|
159
|
+
* emits its leading prose then a fence in its own language: `class="language-X"`
|
|
160
|
+
* on the block's `<code>` (as converted extension `.script_api` examples carry)
|
|
161
|
+
* or an inner ` ```X ` opener, else `lua`, since engine ref-doc blocks carry no
|
|
162
|
+
* language class. Prose trailing the last example is emitted last, and a
|
|
163
|
+
* fragment with no `codehilite` block is wrapped whole as a single ` ```lua `
|
|
164
|
+
* fence (back-compat for plain-code examples). Returns `""` for empty /
|
|
165
|
+
* whitespace-only input.
|
|
166
|
+
*/
|
|
167
|
+
export function examplesHtmlToMarkdown(html: string): string {
|
|
168
|
+
const { segments, trailingProse } = segmentExampleRegions(html);
|
|
105
169
|
|
|
106
|
-
const
|
|
107
|
-
|
|
170
|
+
const parts: string[] = [];
|
|
171
|
+
for (const segment of segments) {
|
|
172
|
+
if (segment.prose !== "") parts.push(segment.prose);
|
|
173
|
+
parts.push(`\`\`\`${segment.lang}\n${segment.code}\n\`\`\``);
|
|
174
|
+
}
|
|
175
|
+
if (trailingProse !== "") parts.push(trailingProse);
|
|
108
176
|
|
|
109
177
|
return parts.join("\n\n");
|
|
110
178
|
}
|
|
111
179
|
|
|
180
|
+
/** One example carved out of an `examples` fragment, with the prose leading it. */
|
|
181
|
+
export interface ExampleSegment {
|
|
182
|
+
prose: string;
|
|
183
|
+
code: string;
|
|
184
|
+
lang: string;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// A line that opens a code run: ``` followed by a bare language token and
|
|
188
|
+
// nothing else. Any other ``` line closes the run, its remainder being prose
|
|
189
|
+
// upstream welded onto the fence.
|
|
190
|
+
const FENCE_OPENER = /^```([A-Za-z0-9_+-]+)$/;
|
|
191
|
+
|
|
192
|
+
/** The examples a fragment carries, plus any prose left over after the last one. */
|
|
193
|
+
export interface ExampleSegmentation {
|
|
194
|
+
segments: ExampleSegment[];
|
|
195
|
+
/** Prose following the final code run, which belongs to no segment. */
|
|
196
|
+
trailingProse: string;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Carve an `examples` HTML fragment into one segment per example it carries.
|
|
201
|
+
*
|
|
202
|
+
* A `<div class="codehilite">` block is a code region and the markup between
|
|
203
|
+
* two of them is a prose region; inside either, a ` ``` ` line switches between
|
|
204
|
+
* code and prose, and an opener reached while already in code ends the running
|
|
205
|
+
* example and starts the next. Upstream writes several examples both ways — as
|
|
206
|
+
* several blocks, and as its own Markdown fences inside one block — so both
|
|
207
|
+
* signals are read.
|
|
208
|
+
*
|
|
209
|
+
* This is the walk alone: no whole-blob fallback, so a caller sees the real
|
|
210
|
+
* segments even where there is only one. `splitExampleSources` adds the
|
|
211
|
+
* stability post-pass that keys stored translations.
|
|
212
|
+
*/
|
|
213
|
+
export function segmentExampleRegions(html: string): ExampleSegmentation {
|
|
214
|
+
if (html.trim() === "") return { segments: [], trailingProse: "" };
|
|
215
|
+
|
|
216
|
+
const { regions } = scanExampleRegions(html);
|
|
217
|
+
const segments: ExampleSegment[] = [];
|
|
218
|
+
let codeLines: string[] = [];
|
|
219
|
+
let proseLines: string[] = [];
|
|
220
|
+
let lang = "lua";
|
|
221
|
+
|
|
222
|
+
const flush = () => {
|
|
223
|
+
const code = trimBlankEdges(codeLines).join("\n");
|
|
224
|
+
codeLines = [];
|
|
225
|
+
if (code === "") return;
|
|
226
|
+
segments.push({ prose: trimBlankEdges(proseLines).join("\n"), code, lang });
|
|
227
|
+
proseLines = [];
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
for (const region of regions) {
|
|
231
|
+
const text = region.kind === "code" ? htmlToCodeText(region.html) : htmlToDocText(region.html);
|
|
232
|
+
let inCode = region.kind === "code";
|
|
233
|
+
if (region.kind === "code") lang = region.lang;
|
|
234
|
+
// Prose surviving an empty code run keeps its paragraph break from the next.
|
|
235
|
+
if (region.kind === "prose" && text !== "" && proseLines.length > 0) proseLines.push("");
|
|
236
|
+
for (const line of text === "" ? [] : text.split("\n")) {
|
|
237
|
+
const trimmed = line.trim();
|
|
238
|
+
if (!trimmed.startsWith("```")) {
|
|
239
|
+
(inCode ? codeLines : proseLines).push(line);
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
const opener = FENCE_OPENER.exec(trimmed);
|
|
243
|
+
if (opener) {
|
|
244
|
+
if (inCode) flush();
|
|
245
|
+
inCode = true;
|
|
246
|
+
lang = opener[1] ?? lang;
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
flush();
|
|
250
|
+
inCode = false;
|
|
251
|
+
const remainder = trimmed.slice(3).trim();
|
|
252
|
+
if (remainder !== "") proseLines.push(remainder);
|
|
253
|
+
}
|
|
254
|
+
flush();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return { segments, trailingProse: trimBlankEdges(proseLines).join("\n") };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* `segmentExampleRegions` plus the stability post-pass: a fragment that yields
|
|
262
|
+
* at most one segment returns the whole-blob `htmlToCodeText` verbatim, prose
|
|
263
|
+
* lines included. That is the string every stored translation is pinned
|
|
264
|
+
* against, so a single-example element keeps its identity and cannot be re-keyed
|
|
265
|
+
* by this walk.
|
|
266
|
+
*/
|
|
267
|
+
export function splitExampleSources(html: string): ExampleSegment[] {
|
|
268
|
+
const { segments } = segmentExampleRegions(html);
|
|
269
|
+
if (segments.length > 1) return segments;
|
|
270
|
+
if (html.trim() === "") return [];
|
|
271
|
+
const whole = htmlToCodeText(html);
|
|
272
|
+
if (whole === "") return [];
|
|
273
|
+
return [{ prose: "", code: whole, lang: segments[0]?.lang ?? "lua" }];
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function trimBlankEdges(lines: readonly string[]): string[] {
|
|
277
|
+
const out = [...lines];
|
|
278
|
+
while (out.length > 0 && out[0]?.trim() === "") out.shift();
|
|
279
|
+
while (out.length > 0 && out[out.length - 1]?.trim() === "") out.pop();
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
|
|
112
283
|
export interface DocCommentParts {
|
|
113
284
|
summary: string;
|
|
114
285
|
// Present exactly when the source carried a deprecation tag; `""` is the bare
|
|
@@ -117,8 +288,12 @@ export interface DocCommentParts {
|
|
|
117
288
|
deprecated?: string;
|
|
118
289
|
params?: { name: string; doc: string }[];
|
|
119
290
|
returns?: string;
|
|
120
|
-
example
|
|
121
|
-
|
|
291
|
+
// One entry per example the element documents, each rendered as its own
|
|
292
|
+
// `@example` block. An element whose ref-doc blob holds several examples
|
|
293
|
+
// carries several entries; a blank body is dropped. `prose` is the sentence
|
|
294
|
+
// introducing that example, rendered above its fence; blank or absent leaves
|
|
295
|
+
// the block byte-identical to a prose-less one.
|
|
296
|
+
examples?: { text: string; lang: "lua" | "ts"; prose?: string }[];
|
|
122
297
|
}
|
|
123
298
|
|
|
124
299
|
/**
|
|
@@ -129,14 +304,14 @@ export function renderDocComment(parts: DocCommentParts): string[] {
|
|
|
129
304
|
const summaryLines = parts.summary.trim() === "" ? [] : parts.summary.split("\n");
|
|
130
305
|
const params = (parts.params ?? []).filter((p) => p.doc.trim() !== "");
|
|
131
306
|
const returns = parts.returns?.trim() ? parts.returns : "";
|
|
132
|
-
const
|
|
307
|
+
const examples = (parts.examples ?? []).filter((entry) => entry.text.trim() !== "");
|
|
133
308
|
const deprecated = parts.deprecated;
|
|
134
309
|
|
|
135
310
|
if (
|
|
136
311
|
summaryLines.length === 0 &&
|
|
137
312
|
params.length === 0 &&
|
|
138
313
|
returns === "" &&
|
|
139
|
-
|
|
314
|
+
examples.length === 0 &&
|
|
140
315
|
deprecated === undefined
|
|
141
316
|
) {
|
|
142
317
|
return [];
|
|
@@ -147,7 +322,8 @@ export function renderDocComment(parts: DocCommentParts): string[] {
|
|
|
147
322
|
lines.push(line === "" ? " *" : ` * ${line}`);
|
|
148
323
|
}
|
|
149
324
|
|
|
150
|
-
const hasTags =
|
|
325
|
+
const hasTags =
|
|
326
|
+
deprecated !== undefined || params.length > 0 || returns !== "" || examples.length > 0;
|
|
151
327
|
if (summaryLines.length > 0 && hasTags) {
|
|
152
328
|
lines.push(" *");
|
|
153
329
|
}
|
|
@@ -173,10 +349,15 @@ export function renderDocComment(parts: DocCommentParts): string[] {
|
|
|
173
349
|
lines.push(line === "" ? " *" : ` * ${line}`);
|
|
174
350
|
}
|
|
175
351
|
}
|
|
176
|
-
|
|
352
|
+
for (const entry of examples) {
|
|
177
353
|
lines.push(" * @example");
|
|
178
|
-
|
|
179
|
-
|
|
354
|
+
if (entry.prose !== undefined && entry.prose.trim() !== "") {
|
|
355
|
+
for (const line of entry.prose.split("\n")) {
|
|
356
|
+
lines.push(line === "" ? " *" : ` * ${line}`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
lines.push(` * \`\`\`${entry.lang}`);
|
|
360
|
+
for (const line of entry.text.split("\n")) {
|
|
180
361
|
lines.push(line === "" ? " *" : ` * ${line}`);
|
|
181
362
|
}
|
|
182
363
|
lines.push(" * ```");
|