mancha 0.24.2 → 0.25.1
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 +1 -1
- package/dist/browser.d.ts +6 -8
- package/dist/browser.js +23 -23
- package/dist/cli.js +4 -2
- package/dist/cli.js.map +1 -1
- package/dist/dome.js +1 -1
- package/dist/dome.js.map +1 -1
- package/dist/mancha.js +23 -23
- package/dist/plugins.js +21 -4
- package/dist/plugins.js.map +1 -1
- package/docs/05_css.md +19 -0
- package/docs/06_ssr.md +1 -1
- package/docs/07_typescript.md +24 -0
- package/docs/10_security.md +9 -11
- package/package.json +6 -5
package/docs/05_css.md
CHANGED
|
@@ -655,6 +655,25 @@ Two limitations:
|
|
|
655
655
|
- **ESM only**: `scanAndInject` is exported from the module build, not from the global bundle loaded via a `<script>` tag.
|
|
656
656
|
- **No shadow DOM**: `querySelectorAll` does not pierce a shadow root, so scanning a host element finds nothing inside it. Scanning the shadow root itself does inject rules, but they land in the main document's stylesheet, where shadow-boundary scoping stops them from applying. Style shadow content with its own stylesheet instead.
|
|
657
657
|
|
|
658
|
+
## Getting the Rules as Text
|
|
659
|
+
|
|
660
|
+
`injectCss` appends the stylesheets to `document.head`, which is the right thing almost always. When you need the CSS itself rather than a style tag in the head, each stylesheet is also exported as a function returning its text:
|
|
661
|
+
|
|
662
|
+
```js
|
|
663
|
+
import { basicCssRules, minimalCssRules, utilsCssRules } from "mancha/browser";
|
|
664
|
+
|
|
665
|
+
minimalCssRules(); // Same rules as injectCss(["minimal"]).
|
|
666
|
+
basicCssRules(); // The reset half of injectCss(["utils"]).
|
|
667
|
+
utilsCssRules(); // The utility-class half of injectCss(["utils"]).
|
|
668
|
+
```
|
|
669
|
+
|
|
670
|
+
They take no arguments, touch no DOM, and return the same text on every call, so they can also run at build time or on the server. The two cases that need them:
|
|
671
|
+
|
|
672
|
+
- **Shadow DOM**: rules in `document.head` do not cross a shadow boundary, so give the shadow root its own stylesheet built from these.
|
|
673
|
+
- **Serving the CSS yourself**: write the text to a file at build time and link it, rather than shipping the rules inside the JavaScript bundle.
|
|
674
|
+
|
|
675
|
+
Note that these are the full stylesheets. Rules for custom values like `w-[200px]` are injected on demand as Mancha renders them and are not part of this text.
|
|
676
|
+
|
|
658
677
|
---
|
|
659
678
|
|
|
660
679
|
*Generated automatically from `src/css_gen_utils.ts`*
|
package/docs/06_ssr.md
CHANGED
|
@@ -58,7 +58,7 @@ For a more complete example, see [examples/express](../examples/express).
|
|
|
58
58
|
For servers hosted as worker runtimes, such as `Cloudflare Workers`, you will need to import a stripped down version of `mancha` that does not have the ability to read local files.
|
|
59
59
|
|
|
60
60
|
```js
|
|
61
|
-
import { Renderer } from "mancha/
|
|
61
|
+
import { Renderer } from "mancha/worker";
|
|
62
62
|
import htmlIndex from "./index.html";
|
|
63
63
|
import vars from "./vars.json";
|
|
64
64
|
|
package/docs/07_typescript.md
CHANGED
|
@@ -28,6 +28,30 @@ renderer.$.user = { name: "Alice", email: "alice@example.com" };
|
|
|
28
28
|
|
|
29
29
|
The `$` proxy provides typed access to store values. Without a type parameter, the store accepts any properties.
|
|
30
30
|
|
|
31
|
+
## The Shared Renderer Type
|
|
32
|
+
|
|
33
|
+
Each entry point exports its own `Renderer`: `mancha` parses with jsdom, `mancha/browser` with the DOM, and `mancha/worker` with htmlparser2. All three extend `IRenderer`, which every entry point exports alongside them. It is the type to reach for when code has to work against whichever renderer it is handed — typically logic shared between the server and the client:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import type { IRenderer } from "mancha";
|
|
37
|
+
|
|
38
|
+
// Accepts the jsdom, browser and worker renderers alike.
|
|
39
|
+
async function renderPage(renderer: IRenderer, html: string): Promise<string> {
|
|
40
|
+
const fragment = renderer.parseHTML(html);
|
|
41
|
+
return renderer.serializeHTML(await renderer.renderNode(fragment));
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`IRenderer` is also the `this` type of `RendererPlugin`, so it is needed to annotate a plugin written as a standalone function:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import type { IRenderer, RendererPlugin } from "mancha";
|
|
49
|
+
|
|
50
|
+
const logNodes: RendererPlugin = function (this: IRenderer, node) {
|
|
51
|
+
console.log(this.impl, node.nodeName);
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
31
55
|
## Type Checking (Experimental)
|
|
32
56
|
|
|
33
57
|
**⚠️ This feature is experimental and may change in future versions.**
|
package/docs/10_security.md
CHANGED
|
@@ -88,15 +88,14 @@ value of `<img src=x onerror="...">`:
|
|
|
88
88
|
subrenderer, so directives inside it execute, and in the browser a `<script>` element in that string
|
|
89
89
|
runs when it is inserted.
|
|
90
90
|
|
|
91
|
-
`:text` escapes markup,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
[#104](https://github.com/fresho-dev/mancha/issues/104); this paragraph goes away when it is fixed.
|
|
91
|
+
`:text` escapes markup, and the text it writes is data: the renderer does not visit it again, so a
|
|
92
|
+
value that itself contains `{{ ... }}` renders those braces verbatim instead of being evaluated. The
|
|
93
|
+
same holds for the result of a `{{ ... }}` substitution. What `:text` does evaluate is its
|
|
94
|
+
**attribute** — `:text="expr"` is an expression like every other directive — so the template still
|
|
95
|
+
has to be one you trust; only the value flowing through it is data.
|
|
97
96
|
|
|
98
|
-
So a value is safe in `{{ ... }}` and
|
|
99
|
-
|
|
97
|
+
So a value is safe in `{{ ... }}` and in `:text`; it is unsafe everywhere else. This matters most
|
|
98
|
+
for the values you do not choose yourself:
|
|
100
99
|
|
|
101
100
|
```html
|
|
102
101
|
<!-- Safe: URL query parameters, form input and API responses are escaped here,
|
|
@@ -110,9 +109,8 @@ This matters most for the values you do not choose yourself:
|
|
|
110
109
|
<a :attr:href="$$next">Continue</a>
|
|
111
110
|
```
|
|
112
111
|
|
|
113
|
-
The rule of thumb: untrusted values may only reach `{{ ... }}
|
|
114
|
-
|
|
115
|
-
[Isolating Untrusted Content](#isolating-untrusted-content).
|
|
112
|
+
The rule of thumb: untrusted values may only reach `{{ ... }}` or `:text`. If you need untrusted
|
|
113
|
+
markup, see [Isolating Untrusted Content](#isolating-untrusted-content).
|
|
116
114
|
|
|
117
115
|
## Whatever You Mount Is A Template
|
|
118
116
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mancha",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.1",
|
|
4
4
|
"description": "Javscript HTML rendering engine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -15,10 +15,11 @@
|
|
|
15
15
|
"types": "./dist/browser.d.ts",
|
|
16
16
|
"default": "./dist/browser.js"
|
|
17
17
|
},
|
|
18
|
-
"./
|
|
19
|
-
"types": "./dist
|
|
20
|
-
"default": "./dist
|
|
21
|
-
}
|
|
18
|
+
"./worker": {
|
|
19
|
+
"types": "./dist/worker.d.ts",
|
|
20
|
+
"default": "./dist/worker.js"
|
|
21
|
+
},
|
|
22
|
+
"./package.json": "./package.json"
|
|
22
23
|
},
|
|
23
24
|
"files": [
|
|
24
25
|
"dist",
|