@defold-typescript/types 0.38.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.
Files changed (80) hide show
  1. package/api-signatures.json +336 -255
  2. package/examples/translations.json +323 -147
  3. package/generated/b2d_body.d.ts +7 -4
  4. package/generated/buffer.d.ts +16 -4
  5. package/generated/camera.d.ts +1 -0
  6. package/generated/collectionfactory.d.ts +5 -2
  7. package/generated/collectionproxy.d.ts +1 -1
  8. package/generated/factory.d.ts +2 -1
  9. package/generated/go.d.ts +141 -86
  10. package/generated/graphics.d.ts +2 -0
  11. package/generated/gui.d.ts +65 -40
  12. package/generated/html5.d.ts +1 -1
  13. package/generated/http.d.ts +4 -0
  14. package/generated/model.d.ts +9 -4
  15. package/generated/particlefx.d.ts +1 -1
  16. package/generated/physics.d.ts +16 -9
  17. package/generated/profiler.d.ts +9 -2
  18. package/generated/render.d.ts +224 -99
  19. package/generated/resource.d.ts +143 -157
  20. package/generated/socket.d.ts +13 -8
  21. package/generated/sound.d.ts +3 -2
  22. package/generated/sys.d.ts +16 -10
  23. package/generated/tilemap.d.ts +25 -19
  24. package/generated/timer.d.ts +33 -24
  25. package/generated/versions/defold-1.12.4/buffer.d.ts +16 -4
  26. package/generated/versions/defold-1.12.4/camera.d.ts +1 -0
  27. package/generated/versions/defold-1.12.4/collectionfactory.d.ts +5 -2
  28. package/generated/versions/defold-1.12.4/collectionproxy.d.ts +1 -1
  29. package/generated/versions/defold-1.12.4/factory.d.ts +2 -1
  30. package/generated/versions/defold-1.12.4/go.d.ts +141 -86
  31. package/generated/versions/defold-1.12.4/graphics.d.ts +2 -0
  32. package/generated/versions/defold-1.12.4/gui.d.ts +63 -39
  33. package/generated/versions/defold-1.12.4/html5.d.ts +1 -1
  34. package/generated/versions/defold-1.12.4/http.d.ts +4 -0
  35. package/generated/versions/defold-1.12.4/model.d.ts +9 -4
  36. package/generated/versions/defold-1.12.4/particlefx.d.ts +1 -1
  37. package/generated/versions/defold-1.12.4/physics.d.ts +16 -9
  38. package/generated/versions/defold-1.12.4/profiler.d.ts +9 -2
  39. package/generated/versions/defold-1.12.4/render.d.ts +223 -98
  40. package/generated/versions/defold-1.12.4/resource.d.ts +143 -157
  41. package/generated/versions/defold-1.12.4/socket.d.ts +13 -8
  42. package/generated/versions/defold-1.12.4/sound.d.ts +3 -2
  43. package/generated/versions/defold-1.12.4/sys.d.ts +16 -10
  44. package/generated/versions/defold-1.12.4/tilemap.d.ts +25 -19
  45. package/generated/versions/defold-1.12.4/timer.d.ts +33 -24
  46. package/generated/versions/defold-1.12.4/vmath.d.ts +13 -5
  47. package/generated/versions/defold-1.12.4/window.d.ts +5 -3
  48. package/generated/versions/defold-1.13.0/b2d_body.d.ts +7 -4
  49. package/generated/versions/defold-1.13.0/buffer.d.ts +16 -4
  50. package/generated/versions/defold-1.13.0/camera.d.ts +1 -0
  51. package/generated/versions/defold-1.13.0/collectionfactory.d.ts +5 -2
  52. package/generated/versions/defold-1.13.0/collectionproxy.d.ts +1 -1
  53. package/generated/versions/defold-1.13.0/factory.d.ts +2 -1
  54. package/generated/versions/defold-1.13.0/go.d.ts +141 -86
  55. package/generated/versions/defold-1.13.0/graphics.d.ts +2 -0
  56. package/generated/versions/defold-1.13.0/gui.d.ts +63 -39
  57. package/generated/versions/defold-1.13.0/html5.d.ts +1 -1
  58. package/generated/versions/defold-1.13.0/http.d.ts +4 -0
  59. package/generated/versions/defold-1.13.0/model.d.ts +9 -4
  60. package/generated/versions/defold-1.13.0/particlefx.d.ts +1 -1
  61. package/generated/versions/defold-1.13.0/physics.d.ts +16 -9
  62. package/generated/versions/defold-1.13.0/profiler.d.ts +9 -2
  63. package/generated/versions/defold-1.13.0/render.d.ts +224 -99
  64. package/generated/versions/defold-1.13.0/resource.d.ts +143 -157
  65. package/generated/versions/defold-1.13.0/socket.d.ts +13 -8
  66. package/generated/versions/defold-1.13.0/sound.d.ts +3 -2
  67. package/generated/versions/defold-1.13.0/sys.d.ts +16 -10
  68. package/generated/versions/defold-1.13.0/tilemap.d.ts +25 -19
  69. package/generated/versions/defold-1.13.0/timer.d.ts +33 -24
  70. package/generated/versions/defold-1.13.0/vmath.d.ts +13 -5
  71. package/generated/versions/defold-1.13.0/window.d.ts +5 -3
  72. package/generated/vmath.d.ts +13 -5
  73. package/generated/window.d.ts +5 -3
  74. package/package.json +2 -1
  75. package/src/api-doc.ts +8 -0
  76. package/src/doc-comment.ts +213 -32
  77. package/src/emit-dts.ts +501 -10
  78. package/src/example-store.ts +26 -0
  79. package/src/index.ts +5 -0
  80. package/src/render-overloads.d.ts +0 -17
@@ -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
- * Convert a ref-doc `examples` HTML fragment — prose interleaved with one or
75
- * more `<div class="codehilite">…</div>` syntax-highlight blocks — into Markdown:
76
- * prose runs become `htmlToDocText`, each highlight block becomes a fence via
77
- * `htmlToCodeText`. The fence language comes from a `class="language-X"` on the
78
- * block's `<code>` (as converted extension `.script_api` examples carry), else
79
- * `lua`, since engine ref-doc blocks carry no language class. A fragment with no
80
- * `codehilite` block is wrapped whole as a single ` ```lua ` fence (back-compat
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
- const parts: string[] = [];
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
- const prose = htmlToDocText(html.slice(lastIndex, match.index));
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
- const lang = /<code\b[^>]*\bclass="language-([^"\s]+)"/i.exec(inner)?.[1] ?? "lua";
96
- const code = htmlToCodeText(inner);
97
- if (code !== "") parts.push(`\`\`\`${lang}\n${code}\n\`\`\``);
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
- if (!matched) {
102
- const code = htmlToCodeText(html);
103
- return code === "" ? "" : `\`\`\`lua\n${code}\n\`\`\``;
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 trailing = htmlToDocText(html.slice(lastIndex));
107
- if (trailing !== "") parts.push(trailing);
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?: string;
121
- exampleLang?: "lua" | "ts";
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 example = parts.example?.trim() ? parts.example : "";
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
- example === "" &&
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 = deprecated !== undefined || params.length > 0 || returns !== "" || example !== "";
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
- if (example !== "") {
352
+ for (const entry of examples) {
177
353
  lines.push(" * @example");
178
- lines.push(` * \`\`\`${parts.exampleLang ?? "lua"}`);
179
- for (const line of example.split("\n")) {
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(" * ```");