@microsoft/fast-build 0.4.0 → 0.6.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 +20 -6
- package/bin/fast.js +38 -20
- package/package.json +1 -1
- package/wasm/microsoft_fast_build.d.ts +24 -16
- package/wasm/microsoft_fast_build.js +40 -28
- package/wasm/microsoft_fast_build_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ import { render } from '@microsoft/fast-build';
|
|
|
25
25
|
|
|
26
26
|
## CLI usage
|
|
27
27
|
|
|
28
|
-
Once installed, the `fast` binary is available. Use the `build` subcommand to render an HTML template with
|
|
28
|
+
Once installed, the `fast` binary is available. Use the `build` subcommand to render an HTML template with an optional JSON state file:
|
|
29
29
|
|
|
30
30
|
```shell
|
|
31
31
|
fast build [options]
|
|
@@ -36,10 +36,10 @@ fast build [options]
|
|
|
36
36
|
| Option | Default | Description |
|
|
37
37
|
|---|---|---|
|
|
38
38
|
| `--entry="<path>"` | `index.html` | Entry HTML template to render |
|
|
39
|
-
| `--state="<path>"` | `
|
|
39
|
+
| `--state="<path>"` | `{}` when omitted | JSON file containing the template state. If omitted, no state file is loaded and rendering uses an empty state object. If `--state` is provided, the file must exist. |
|
|
40
40
|
| `--output="<path>"` | `output.html` | Where to write the rendered HTML |
|
|
41
41
|
| `--templates="<glob>"` | _(none)_ | Glob pattern(s) for custom element template HTML files. Separate multiple patterns with commas. A warning is printed if not provided or if no files match a pattern. |
|
|
42
|
-
| `--attribute-name-strategy="<strategy>"` | `
|
|
42
|
+
| `--attribute-name-strategy="<strategy>"` | `camelCase` | Strategy for mapping HTML attribute names to state property names on custom elements. `"camelCase"` converts dashes to camelCase (e.g. `foo-bar` → `fooBar`). `"none"` preserves dashes (e.g. `foo-bar` → `foo-bar`). See [Attribute name strategy](#attribute-name-strategy). |
|
|
43
43
|
| `--config="<path>"` | `fast-build.config.json` | Path to a JSON configuration file. If omitted, `fast-build.config.json` in the current directory is used when present. CLI arguments take precedence over config values. See [Configuration file](#configuration-file). |
|
|
44
44
|
|
|
45
45
|
### Example
|
|
@@ -81,6 +81,18 @@ Produces `output.html`:
|
|
|
81
81
|
</html>
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
+
### Missing or omitted state
|
|
85
|
+
|
|
86
|
+
State is optional. When `--state` is omitted and no `state` path is provided by config, `fast build` does not look for `state.json`; rendering uses an empty object (`{}`). An explicit `--state` path, or a `state` path from config, must exist or the command exits with an error.
|
|
87
|
+
|
|
88
|
+
> **Breaking change:** Earlier versions implicitly loaded `state.json` from the current working directory when `--state` was omitted. To use a state file, pass `--state=state.json` or set `"state": "state.json"` in `fast-build.config.json`.
|
|
89
|
+
|
|
90
|
+
When a binding value is not present in state:
|
|
91
|
+
|
|
92
|
+
- Content bindings render nothing, including unresolved dot paths: `<p>{{foo.bar}}</p>` becomes `<p></p>`.
|
|
93
|
+
- Attribute bindings omit the entire attribute, including unresolved dot paths: `<div class="{{foo.bar}}"></div>` becomes `<div></div>`.
|
|
94
|
+
- `<f-repeat>` treats a missing list binding, including unresolved dot paths, as an empty array and renders zero iterations. If the binding is present but is not an array, rendering still errors.
|
|
95
|
+
|
|
84
96
|
### Custom element templates
|
|
85
97
|
|
|
86
98
|
Pass a glob pattern (or comma-separated list of patterns) to `--templates` to expand custom elements into [Declarative Shadow DOM](https://developer.chrome.com/docs/css-ui/declarative-shadow-dom):
|
|
@@ -107,14 +119,16 @@ Template files must use the following format:
|
|
|
107
119
|
|
|
108
120
|
If an `<f-template>` element has no `name` attribute, a warning is printed and it is ignored. Exact file paths (no wildcards) are also accepted as patterns, making it possible to register a single template file.
|
|
109
121
|
|
|
122
|
+
Any `shadowroot*` attributes on `<f-template>` are forwarded to the rendered Declarative Shadow DOM `<template>`. The CLI normalizes `shadowrootmode` and legacy `shadowroot` for compatibility: when neither has a non-empty value, it emits `shadowrootmode="open" shadowroot="open"`; when exactly one has a non-empty value, that value is mirrored to the other; when both have explicit non-empty values, both are preserved as authored, even if they conflict.
|
|
123
|
+
|
|
110
124
|
### Attribute name strategy
|
|
111
125
|
|
|
112
126
|
The `--attribute-name-strategy` option controls how HTML attribute names on custom elements are mapped to state property names in their shadow templates.
|
|
113
127
|
|
|
114
128
|
| Strategy | Behaviour | Template binding |
|
|
115
129
|
|---|---|---|
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
130
|
+
| `camelCase` (default) | Dashed attribute names converted to camelCase | `foo-bar` → `{{fooBar}}` |
|
|
131
|
+
| `none` | Attribute names lowercased as-is, dashes preserved | `foo-bar` → `{{foo-bar}}` |
|
|
118
132
|
|
|
119
133
|
The `camelCase` strategy only affects "plain" custom element attributes. It does **not** change:
|
|
120
134
|
- `data-*` attributes (always use `dataset.*` grouping)
|
|
@@ -153,7 +167,7 @@ fast build --config=configs/my-build.json
|
|
|
153
167
|
|
|
154
168
|
**Path resolution:** File paths in the config file (`entry`, `state`, `output`, `templates`) are resolved relative to the config file's directory, not the current working directory. This ensures the config works correctly regardless of where the CLI is invoked.
|
|
155
169
|
|
|
156
|
-
All keys are optional. Only the following keys are allowed: `entry`, `state`, `output`, `templates`, `attribute-name-strategy`. Unknown keys or non-string values produce an error.
|
|
170
|
+
All keys are optional. Only the following keys are allowed: `entry`, `state`, `output`, `templates`, `attribute-name-strategy`. Unknown keys or non-string values produce an error. If `state` is omitted, rendering uses `{}`; if `state` is present, the referenced file must exist.
|
|
157
171
|
|
|
158
172
|
## Template syntax
|
|
159
173
|
|
package/bin/fast.js
CHANGED
|
@@ -218,24 +218,28 @@ function staticPrefixDir(pattern) {
|
|
|
218
218
|
|
|
219
219
|
/**
|
|
220
220
|
* Parse all `<f-template>` elements from an HTML string using the WASM module.
|
|
221
|
-
* Returns
|
|
221
|
+
* Returns template metadata for templates that have a `name` attribute.
|
|
222
222
|
* Emits a warning to stderr for any `<f-template>` without a `name`.
|
|
223
223
|
* @param {string} html
|
|
224
224
|
* @param {string} filePath - used in warning messages
|
|
225
225
|
* @param {object} wasm - the loaded WASM module
|
|
226
|
-
* @returns {{ name: string, content: string }[]}
|
|
226
|
+
* @returns {{ name: string, content: string, shadowrootAttributes: { name: string, value: string | null }[] }[]}
|
|
227
227
|
*/
|
|
228
228
|
function parseFTemplates(html, filePath, wasm) {
|
|
229
|
-
/** @type {{ name: string | null, content: string }[]} */
|
|
229
|
+
/** @type {{ name: string | null, content: string, shadowrootAttributes?: { name: string, value: string | null }[] }[]} */
|
|
230
230
|
const parsed = JSON.parse(wasm.parse_f_templates(html));
|
|
231
231
|
const results = [];
|
|
232
|
-
for (const { name, content } of parsed) {
|
|
232
|
+
for (const { name, content, shadowrootAttributes } of parsed) {
|
|
233
233
|
if (name === null) {
|
|
234
234
|
process.stderr.write(
|
|
235
235
|
`Warning: <f-template> without a 'name' attribute in '${filePath}': ${content.trim()}\n`
|
|
236
236
|
);
|
|
237
237
|
} else {
|
|
238
|
-
results.push({
|
|
238
|
+
results.push({
|
|
239
|
+
name,
|
|
240
|
+
content,
|
|
241
|
+
shadowrootAttributes: shadowrootAttributes || [],
|
|
242
|
+
});
|
|
239
243
|
}
|
|
240
244
|
}
|
|
241
245
|
return results;
|
|
@@ -248,7 +252,7 @@ function parseFTemplates(html, filePath, wasm) {
|
|
|
248
252
|
* Warns (but does not error) if the base directory does not exist.
|
|
249
253
|
* @param {string} pattern
|
|
250
254
|
* @param {object} wasm - the loaded WASM module
|
|
251
|
-
* @returns {{ name: string, content: string }[]}
|
|
255
|
+
* @returns {{ name: string, content: string, shadowrootAttributes: { name: string, value: string | null }[] }[]}
|
|
252
256
|
*/
|
|
253
257
|
function resolvePattern(pattern, wasm) {
|
|
254
258
|
const baseDir = staticPrefixDir(pattern);
|
|
@@ -262,8 +266,8 @@ function resolvePattern(pattern, wasm) {
|
|
|
262
266
|
if (globMatch(pattern, file)) {
|
|
263
267
|
const html = fs.readFileSync(file, "utf8");
|
|
264
268
|
const templates = parseFTemplates(html, file, wasm);
|
|
265
|
-
for (const { name, content } of templates) {
|
|
266
|
-
results.push({ name, content });
|
|
269
|
+
for (const { name, content, shadowrootAttributes } of templates) {
|
|
270
|
+
results.push({ name, content, shadowrootAttributes });
|
|
267
271
|
}
|
|
268
272
|
}
|
|
269
273
|
}
|
|
@@ -278,7 +282,10 @@ async function runBuild(args) {
|
|
|
278
282
|
const templatesArg = resolveOption(args, config, configDir, "templates");
|
|
279
283
|
const output = resolveOption(args, config, configDir, "output", "output.html");
|
|
280
284
|
const entry = resolveOption(args, config, configDir, "entry", "index.html");
|
|
281
|
-
const stateFile = resolveOption(args, config, configDir, "state"
|
|
285
|
+
const stateFile = resolveOption(args, config, configDir, "state");
|
|
286
|
+
const stateWasProvided =
|
|
287
|
+
Object.prototype.hasOwnProperty.call(args, "state") ||
|
|
288
|
+
Object.prototype.hasOwnProperty.call(config, "state");
|
|
282
289
|
const attributeNameStrategy = resolveOption(args, config, configDir, "attribute-name-strategy");
|
|
283
290
|
|
|
284
291
|
if (attributeNameStrategy && attributeNameStrategy !== "none" && attributeNameStrategy !== "camelCase") {
|
|
@@ -306,13 +313,13 @@ async function runBuild(args) {
|
|
|
306
313
|
`Warning: No template files found for pattern "${pattern}".\n`
|
|
307
314
|
);
|
|
308
315
|
}
|
|
309
|
-
for (const { name, content } of matches) {
|
|
316
|
+
for (const { name, content, shadowrootAttributes } of matches) {
|
|
310
317
|
if (name in templatesMap) {
|
|
311
318
|
process.stderr.write(
|
|
312
319
|
`Warning: Duplicate template name "${name}" — later file overwrites earlier.\n`
|
|
313
320
|
);
|
|
314
321
|
}
|
|
315
|
-
templatesMap[name] = content;
|
|
322
|
+
templatesMap[name] = { content, shadowrootAttributes };
|
|
316
323
|
}
|
|
317
324
|
}
|
|
318
325
|
}
|
|
@@ -324,18 +331,28 @@ async function runBuild(args) {
|
|
|
324
331
|
}
|
|
325
332
|
const entryContent = fs.readFileSync(entry, "utf8");
|
|
326
333
|
|
|
327
|
-
// Read state
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
334
|
+
// Read state only when explicitly provided; omitted state is handled by WASM as `{}`.
|
|
335
|
+
let stateContent;
|
|
336
|
+
if (stateWasProvided) {
|
|
337
|
+
if (stateFile === undefined || stateFile === "" || !fs.existsSync(stateFile)) {
|
|
338
|
+
const stateFileLabel =
|
|
339
|
+
stateFile === undefined || stateFile === ""
|
|
340
|
+
? "(no path provided)"
|
|
341
|
+
: `"${stateFile}"`;
|
|
342
|
+
process.stderr.write(`Error: State file ${stateFileLabel} not found.\n`);
|
|
343
|
+
process.exit(1);
|
|
344
|
+
}
|
|
345
|
+
stateContent = fs.readFileSync(stateFile, "utf8");
|
|
331
346
|
}
|
|
332
|
-
const stateContent = fs.readFileSync(stateFile, "utf8");
|
|
333
347
|
|
|
334
348
|
// Render
|
|
335
349
|
let rendered;
|
|
336
350
|
if (Object.keys(templatesMap).length > 0) {
|
|
337
351
|
rendered = wasm.render_entry_with_templates(
|
|
338
|
-
entryContent,
|
|
352
|
+
entryContent,
|
|
353
|
+
JSON.stringify(templatesMap),
|
|
354
|
+
stateContent,
|
|
355
|
+
attributeNameStrategy || "",
|
|
339
356
|
);
|
|
340
357
|
} else {
|
|
341
358
|
rendered = wasm.render(entryContent, stateContent);
|
|
@@ -356,10 +373,11 @@ async function main() {
|
|
|
356
373
|
' Separate multiple patterns with commas.\n' +
|
|
357
374
|
' --output="output.html" Output file path (default: output.html)\n' +
|
|
358
375
|
' --entry="index.html" Entry HTML template file (default: index.html)\n' +
|
|
359
|
-
' --state="state.json" State JSON file
|
|
360
|
-
'
|
|
376
|
+
' --state="state.json" State JSON file. If omitted, rendering uses\n' +
|
|
377
|
+
' an empty state object.\n' +
|
|
378
|
+
' --attribute-name-strategy="camelCase"\n' +
|
|
361
379
|
' Strategy for mapping attribute names to property names.\n' +
|
|
362
|
-
' "
|
|
380
|
+
' "camelCase" (default) or "none".\n' +
|
|
363
381
|
' --config="<path>" Path to a fast-build config JSON file.\n' +
|
|
364
382
|
' Defaults to "fast-build.config.json" in the\n' +
|
|
365
383
|
' current directory if it exists. File paths in\n' +
|
package/package.json
CHANGED
|
@@ -3,38 +3,46 @@
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Parse all `<f-template>` elements from an HTML string.
|
|
6
|
-
* Returns a JSON array of
|
|
6
|
+
* Returns a JSON array of template metadata objects,
|
|
7
7
|
* one per `<f-template>` element found. `name` is `null` when the element has
|
|
8
8
|
* no `name` attribute.
|
|
9
9
|
*/
|
|
10
10
|
export function parse_f_templates(html: string): string;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* Render a FAST HTML template with
|
|
13
|
+
* Render a FAST HTML template with an optional JSON state string.
|
|
14
|
+
* Omitted state is treated as an empty object.
|
|
14
15
|
* Returns the rendered HTML or throws a JavaScript error.
|
|
15
16
|
*/
|
|
16
|
-
export function render(entry: string, state
|
|
17
|
+
export function render(entry: string, state?: string | null): string;
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
|
-
* Render the top-level **entry HTML** with custom element templates and
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* Render the top-level **entry HTML** with custom element templates and an optional JSON state string.
|
|
21
|
+
* Omitted state is treated as an empty object.
|
|
22
|
+
* Custom elements found at the root level of `entry` build child state from the full root
|
|
23
|
+
* state with HTML attributes overlaid on top. For `{{binding}}` attributes on root custom
|
|
22
24
|
* elements, primitive results (`string`, `number`, and `bool`) are preserved in the rendered
|
|
23
|
-
* output, while non-primitive values (`array`, `object`, `null`) are stripped.
|
|
25
|
+
* output, while missing and non-primitive values (`array`, `object`, `null`) are stripped.
|
|
24
26
|
*
|
|
25
|
-
* `templates_json` is a JSON object mapping element names to their HTML template strings
|
|
26
|
-
* `
|
|
27
|
-
*
|
|
27
|
+
* `templates_json` is a JSON object mapping element names to their HTML template strings,
|
|
28
|
+
* e.g. `{"my-button": "<template>...</template>"}`, or template metadata objects.
|
|
29
|
+
* `attribute_name_strategy` controls attribute-to-property mapping: `"camelCase"` (default)
|
|
30
|
+
* or `"none"`. Pass an empty string for the default.
|
|
28
31
|
* Returns the rendered HTML or throws a JavaScript error.
|
|
29
32
|
*/
|
|
30
|
-
export function render_entry_with_templates(entry: string, templates_json: string, state
|
|
33
|
+
export function render_entry_with_templates(entry: string, templates_json: string, state?: string | null, attribute_name_strategy?: string | null): string;
|
|
31
34
|
|
|
32
35
|
/**
|
|
33
|
-
* Render a FAST HTML template with custom element templates and
|
|
36
|
+
* Render a FAST HTML template with custom element templates and an optional JSON state string.
|
|
37
|
+
* Omitted state is treated as an empty object.
|
|
38
|
+
*
|
|
39
|
+
* This preserves the original non-entry rendering semantics for this export.
|
|
40
|
+
* Use `render_entry_with_templates` for top-level entry HTML rendering.
|
|
41
|
+
*
|
|
34
42
|
* `templates_json` is a JSON object mapping element names to their HTML template strings,
|
|
35
|
-
* e.g. `{"my-button": "<template>...</template>"}
|
|
36
|
-
* `attribute_name_strategy` controls attribute-to-property mapping: `"
|
|
37
|
-
* or `"
|
|
43
|
+
* e.g. `{"my-button": "<template>...</template>"}`, or template metadata objects.
|
|
44
|
+
* `attribute_name_strategy` controls attribute-to-property mapping: `"camelCase"` (default)
|
|
45
|
+
* or `"none"`. Pass an empty string for the default.
|
|
38
46
|
* Returns the rendered HTML or throws a JavaScript error.
|
|
39
47
|
*/
|
|
40
|
-
export function render_with_templates(entry: string, templates_json: string, state
|
|
48
|
+
export function render_with_templates(entry: string, templates_json: string, state?: string | null, attribute_name_strategy?: string | null): string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Parse all `<f-template>` elements from an HTML string.
|
|
5
|
-
* Returns a JSON array of
|
|
5
|
+
* Returns a JSON array of template metadata objects,
|
|
6
6
|
* one per `<f-template>` element found. `name` is `null` when the element has
|
|
7
7
|
* no `name` attribute.
|
|
8
8
|
* @param {string} html
|
|
@@ -25,10 +25,11 @@ function parse_f_templates(html) {
|
|
|
25
25
|
exports.parse_f_templates = parse_f_templates;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* Render a FAST HTML template with
|
|
28
|
+
* Render a FAST HTML template with an optional JSON state string.
|
|
29
|
+
* Omitted state is treated as an empty object.
|
|
29
30
|
* Returns the rendered HTML or throws a JavaScript error.
|
|
30
31
|
* @param {string} entry
|
|
31
|
-
* @param {string} state
|
|
32
|
+
* @param {string | null} [state]
|
|
32
33
|
* @returns {string}
|
|
33
34
|
*/
|
|
34
35
|
function render(entry, state) {
|
|
@@ -37,8 +38,8 @@ function render(entry, state) {
|
|
|
37
38
|
try {
|
|
38
39
|
const ptr0 = passStringToWasm0(entry, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
39
40
|
const len0 = WASM_VECTOR_LEN;
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
var ptr1 = isLikeNone(state) ? 0 : passStringToWasm0(state, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
42
|
+
var len1 = WASM_VECTOR_LEN;
|
|
42
43
|
const ret = wasm.render(ptr0, len0, ptr1, len1);
|
|
43
44
|
var ptr3 = ret[0];
|
|
44
45
|
var len3 = ret[1];
|
|
@@ -56,20 +57,22 @@ function render(entry, state) {
|
|
|
56
57
|
exports.render = render;
|
|
57
58
|
|
|
58
59
|
/**
|
|
59
|
-
* Render the top-level **entry HTML** with custom element templates and
|
|
60
|
-
*
|
|
61
|
-
*
|
|
60
|
+
* Render the top-level **entry HTML** with custom element templates and an optional JSON state string.
|
|
61
|
+
* Omitted state is treated as an empty object.
|
|
62
|
+
* Custom elements found at the root level of `entry` build child state from the full root
|
|
63
|
+
* state with HTML attributes overlaid on top. For `{{binding}}` attributes on root custom
|
|
62
64
|
* elements, primitive results (`string`, `number`, and `bool`) are preserved in the rendered
|
|
63
|
-
* output, while non-primitive values (`array`, `object`, `null`) are stripped.
|
|
65
|
+
* output, while missing and non-primitive values (`array`, `object`, `null`) are stripped.
|
|
64
66
|
*
|
|
65
|
-
* `templates_json` is a JSON object mapping element names to their HTML template strings
|
|
66
|
-
* `
|
|
67
|
-
*
|
|
67
|
+
* `templates_json` is a JSON object mapping element names to their HTML template strings,
|
|
68
|
+
* e.g. `{"my-button": "<template>...</template>"}`, or template metadata objects.
|
|
69
|
+
* `attribute_name_strategy` controls attribute-to-property mapping: `"camelCase"` (default)
|
|
70
|
+
* or `"none"`. Pass an empty string for the default.
|
|
68
71
|
* Returns the rendered HTML or throws a JavaScript error.
|
|
69
72
|
* @param {string} entry
|
|
70
73
|
* @param {string} templates_json
|
|
71
|
-
* @param {string} state
|
|
72
|
-
* @param {string} attribute_name_strategy
|
|
74
|
+
* @param {string | null} [state]
|
|
75
|
+
* @param {string | null} [attribute_name_strategy]
|
|
73
76
|
* @returns {string}
|
|
74
77
|
*/
|
|
75
78
|
function render_entry_with_templates(entry, templates_json, state, attribute_name_strategy) {
|
|
@@ -80,10 +83,10 @@ function render_entry_with_templates(entry, templates_json, state, attribute_nam
|
|
|
80
83
|
const len0 = WASM_VECTOR_LEN;
|
|
81
84
|
const ptr1 = passStringToWasm0(templates_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
82
85
|
const len1 = WASM_VECTOR_LEN;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
var ptr2 = isLikeNone(state) ? 0 : passStringToWasm0(state, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
87
|
+
var len2 = WASM_VECTOR_LEN;
|
|
88
|
+
var ptr3 = isLikeNone(attribute_name_strategy) ? 0 : passStringToWasm0(attribute_name_strategy, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
89
|
+
var len3 = WASM_VECTOR_LEN;
|
|
87
90
|
const ret = wasm.render_entry_with_templates(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
88
91
|
var ptr5 = ret[0];
|
|
89
92
|
var len5 = ret[1];
|
|
@@ -101,16 +104,21 @@ function render_entry_with_templates(entry, templates_json, state, attribute_nam
|
|
|
101
104
|
exports.render_entry_with_templates = render_entry_with_templates;
|
|
102
105
|
|
|
103
106
|
/**
|
|
104
|
-
* Render a FAST HTML template with custom element templates and
|
|
107
|
+
* Render a FAST HTML template with custom element templates and an optional JSON state string.
|
|
108
|
+
* Omitted state is treated as an empty object.
|
|
109
|
+
*
|
|
110
|
+
* This preserves the original non-entry rendering semantics for this export.
|
|
111
|
+
* Use `render_entry_with_templates` for top-level entry HTML rendering.
|
|
112
|
+
*
|
|
105
113
|
* `templates_json` is a JSON object mapping element names to their HTML template strings,
|
|
106
|
-
* e.g. `{"my-button": "<template>...</template>"}
|
|
107
|
-
* `attribute_name_strategy` controls attribute-to-property mapping: `"
|
|
108
|
-
* or `"
|
|
114
|
+
* e.g. `{"my-button": "<template>...</template>"}`, or template metadata objects.
|
|
115
|
+
* `attribute_name_strategy` controls attribute-to-property mapping: `"camelCase"` (default)
|
|
116
|
+
* or `"none"`. Pass an empty string for the default.
|
|
109
117
|
* Returns the rendered HTML or throws a JavaScript error.
|
|
110
118
|
* @param {string} entry
|
|
111
119
|
* @param {string} templates_json
|
|
112
|
-
* @param {string} state
|
|
113
|
-
* @param {string} attribute_name_strategy
|
|
120
|
+
* @param {string | null} [state]
|
|
121
|
+
* @param {string | null} [attribute_name_strategy]
|
|
114
122
|
* @returns {string}
|
|
115
123
|
*/
|
|
116
124
|
function render_with_templates(entry, templates_json, state, attribute_name_strategy) {
|
|
@@ -121,10 +129,10 @@ function render_with_templates(entry, templates_json, state, attribute_name_stra
|
|
|
121
129
|
const len0 = WASM_VECTOR_LEN;
|
|
122
130
|
const ptr1 = passStringToWasm0(templates_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
123
131
|
const len1 = WASM_VECTOR_LEN;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
132
|
+
var ptr2 = isLikeNone(state) ? 0 : passStringToWasm0(state, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
133
|
+
var len2 = WASM_VECTOR_LEN;
|
|
134
|
+
var ptr3 = isLikeNone(attribute_name_strategy) ? 0 : passStringToWasm0(attribute_name_strategy, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
135
|
+
var len3 = WASM_VECTOR_LEN;
|
|
128
136
|
const ret = wasm.render_with_templates(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
129
137
|
var ptr5 = ret[0];
|
|
130
138
|
var len5 = ret[1];
|
|
@@ -178,6 +186,10 @@ function getUint8ArrayMemory0() {
|
|
|
178
186
|
return cachedUint8ArrayMemory0;
|
|
179
187
|
}
|
|
180
188
|
|
|
189
|
+
function isLikeNone(x) {
|
|
190
|
+
return x === undefined || x === null;
|
|
191
|
+
}
|
|
192
|
+
|
|
181
193
|
function passStringToWasm0(arg, malloc, realloc) {
|
|
182
194
|
if (realloc === undefined) {
|
|
183
195
|
const buf = cachedTextEncoder.encode(arg);
|
|
Binary file
|