vue-canvas-frame-headless 4.3.3 โ 4.5.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 +26 -16
- package/dist/index.js +12 -9
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -5,33 +5,42 @@
|
|
|
5
5
|
[![NPM downloads][badge-npm-downloads]][url-npm]
|
|
6
6
|
[![NPM Unpacked Size (with version)][badge-npm-unpacked-size]][url-npm]
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
This package is a headless canvas frame with no styling of its own. `useCanvasFrame` draws content in an isolated document at a width, scales it down to fit a narrower pane, and adopts a stylesheet into that document.
|
|
9
|
+
|
|
10
|
+
Design notes live in [the specs](https://github.com/Esposter/Esposter/tree/main/openspec/specs).
|
|
9
11
|
|
|
10
12
|
## Table of Contents
|
|
11
13
|
|
|
12
14
|
- ๐ [Getting Started](#getting-started)
|
|
13
|
-
-
|
|
14
|
-
- ๐ [Documentation](#documentation)
|
|
15
|
-
- ๐งช [Tests](#tests)
|
|
15
|
+
- ๐งฉ [Key Exports](#key-exports)
|
|
16
16
|
- โ๏ธ [License](#license)
|
|
17
17
|
|
|
18
18
|
---
|
|
19
19
|
|
|
20
20
|
## <a name="getting-started">๐ Getting Started</a>
|
|
21
21
|
|
|
22
|
+
1. Install the package.
|
|
23
|
+
|
|
22
24
|
```bash
|
|
23
25
|
pnpm i vue-canvas-frame-headless
|
|
24
26
|
```
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
2. Create a component from this code. The slot content appears inside the frame.
|
|
27
29
|
|
|
28
30
|
```vue
|
|
29
31
|
<script setup lang="ts">
|
|
30
32
|
import { CANVAS_FRAME_SRCDOC, useCanvasFrame } from "vue-canvas-frame-headless";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const
|
|
33
|
+
import { useTemplateRef } from "vue";
|
|
34
|
+
|
|
35
|
+
const frame = useTemplateRef<HTMLIFrameElement>("frame");
|
|
36
|
+
const pane = useTemplateRef<HTMLElement>("pane");
|
|
37
|
+
const { frameBody, frameStyle } = useCanvasFrame({
|
|
38
|
+
css: "body { margin: 0; font-family: sans-serif; }",
|
|
39
|
+
fill: true,
|
|
40
|
+
frame,
|
|
41
|
+
pane,
|
|
42
|
+
width: 992,
|
|
43
|
+
});
|
|
35
44
|
</script>
|
|
36
45
|
|
|
37
46
|
<template>
|
|
@@ -44,15 +53,16 @@ const { frameBody, frameStyle } = useCanvasFrame({ css: pageCss, fill: true, fra
|
|
|
44
53
|
</template>
|
|
45
54
|
```
|
|
46
55
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
## <a name="documentation">๐ Documentation</a>
|
|
50
|
-
|
|
51
|
-
We highly recommend you take a look at the [documentation](https://github.com/Esposter/Esposter/tree/main/openspec/specs) to level up.
|
|
56
|
+
## <a name="key-exports">๐งฉ Key Exports</a>
|
|
52
57
|
|
|
53
|
-
|
|
58
|
+
| Export | Kind | Purpose |
|
|
59
|
+
| --------------------- | ---------- | ----------------------------------------------------------------------------------------------------- |
|
|
60
|
+
| `CANVAS_FRAME_SRCDOC` | const | The document that every frame starts from, before the page markup is teleported into it |
|
|
61
|
+
| `getFrameScale` | function | The scale that fits a frame to a pane. It is never above 1, and it is 1 while the pane is unmeasured. |
|
|
62
|
+
| `getFrameWidth` | function | The frame's width: its least width, or the pane's width when it fills a wider pane |
|
|
63
|
+
| `useCanvasFrame` | composable | Draws content in an isolated document at a width, scaled down to fit a narrower pane |
|
|
54
64
|
|
|
55
|
-
`
|
|
65
|
+
`getFrameWidth` and `getFrameScale` are the pure geometry that `useCanvasFrame` uses. They are exported on their own.
|
|
56
66
|
|
|
57
67
|
## <a name="license">โ๏ธ License</a>
|
|
58
68
|
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,9 @@ const useCanvasFrame = ({ css, fill, frame, pane, width }) => {
|
|
|
28
28
|
const paneElement = pane.value;
|
|
29
29
|
if (!paneElement) return;
|
|
30
30
|
updatePaneSize(paneElement);
|
|
31
|
-
resizeObserver = new ResizeObserver(() =>
|
|
31
|
+
resizeObserver = new ResizeObserver(() => {
|
|
32
|
+
updatePaneSize(paneElement);
|
|
33
|
+
});
|
|
32
34
|
resizeObserver.observe(paneElement);
|
|
33
35
|
});
|
|
34
36
|
onScopeDispose(() => resizeObserver?.disconnect());
|
|
@@ -42,20 +44,21 @@ const useCanvasFrame = ({ css, fill, frame, pane, width }) => {
|
|
|
42
44
|
frameDocument.value = contentDocument;
|
|
43
45
|
resolveLoaded();
|
|
44
46
|
};
|
|
45
|
-
watch(frame, (frameElement,
|
|
46
|
-
previousFrameElement?.removeEventListener("load", handleLoad);
|
|
47
|
+
watch(frame, (frameElement, _previousFrameElement, onCleanup) => {
|
|
47
48
|
frameElement?.addEventListener("load", handleLoad);
|
|
49
|
+
onCleanup(() => {
|
|
50
|
+
frameElement?.removeEventListener("load", handleLoad);
|
|
51
|
+
});
|
|
48
52
|
}, {
|
|
49
53
|
flush: "sync",
|
|
50
54
|
immediate: true
|
|
51
55
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
watch([frameStyleSheet, () => toValue(css)], ([styleSheet, cssText], _previous, onCleanup) => {
|
|
57
|
+
const styleFrame = requestAnimationFrame(() => styleSheet?.replaceSync(cssText));
|
|
58
|
+
onCleanup(() => {
|
|
59
|
+
cancelAnimationFrame(styleFrame);
|
|
60
|
+
});
|
|
57
61
|
});
|
|
58
|
-
onScopeDispose(() => cancelAnimationFrame(styleFrame));
|
|
59
62
|
return {
|
|
60
63
|
frameBody,
|
|
61
64
|
frameStyle,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-canvas-frame-headless",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"description": "A headless canvas frame: an isolated document at a width, scaled down to fit a narrower pane, with its styles adopted into it, and no styling of its own.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"headless",
|
|
@@ -40,16 +40,17 @@
|
|
|
40
40
|
"lint:fix": "eslint --fix .",
|
|
41
41
|
"test": "vitest",
|
|
42
42
|
"test:browser": "vitest --config vitest.browser.config.ts",
|
|
43
|
-
"typecheck": "
|
|
43
|
+
"typecheck": "tsrs --fast"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@esposter/configuration": "4.
|
|
46
|
+
"@esposter/configuration": "4.5.0",
|
|
47
|
+
"@types/node": "^26.6.6",
|
|
47
48
|
"@vue/test-utils": "^2.5.1",
|
|
48
49
|
"happy-dom": "^21.0.4",
|
|
49
|
-
"tsdown": "^0.23.
|
|
50
|
+
"tsdown": "^0.23.5"
|
|
50
51
|
},
|
|
51
52
|
"peerDependencies": {
|
|
52
53
|
"vue": "^3.5.44"
|
|
53
54
|
},
|
|
54
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "e30c001f3b4b15693e75fb53092d62a97ade4d2b"
|
|
55
56
|
}
|