vue-canvas-frame-headless 4.3.3 โ†’ 4.4.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 CHANGED
@@ -7,12 +7,12 @@
7
7
 
8
8
  A headless canvas frame: `useCanvasFrame` draws its content in an isolated document at a width, scales it down to fit a narrower pane, and adopts a stylesheet into that document, with no styling of its own.
9
9
 
10
+ Design notes live in [the specs](https://github.com/Esposter/Esposter/tree/main/openspec/specs).
11
+
10
12
  ## Table of Contents
11
13
 
12
14
  - ๐Ÿš€ [Getting Started](#getting-started)
13
- - ๐Ÿ“– [Usage](#usage)
14
- - ๐Ÿ“– [Documentation](#documentation)
15
- - ๐Ÿงช [Tests](#tests)
15
+ - ๐Ÿงฉ [Key Exports](#key-exports)
16
16
  - โš–๏ธ [License](#license)
17
17
 
18
18
  ---
@@ -23,15 +23,20 @@ A headless canvas frame: `useCanvasFrame` draws its content in an isolated docum
23
23
  pnpm i vue-canvas-frame-headless
24
24
  ```
25
25
 
26
- ## <a name="usage">๐Ÿ“– Usage</a>
27
-
28
26
  ```vue
29
27
  <script setup lang="ts">
30
28
  import { CANVAS_FRAME_SRCDOC, useCanvasFrame } from "vue-canvas-frame-headless";
31
-
32
- const frame = useTemplateRef("frame");
33
- const pane = useTemplateRef("pane");
34
- const { frameBody, frameStyle } = useCanvasFrame({ css: pageCss, fill: true, frame, pane, width: 992 });
29
+ import { useTemplateRef } from "vue";
30
+
31
+ const frame = useTemplateRef<HTMLIFrameElement>("frame");
32
+ const pane = useTemplateRef<HTMLElement>("pane");
33
+ const { frameBody, frameStyle } = useCanvasFrame({
34
+ css: "body { margin: 0; font-family: sans-serif; }",
35
+ fill: true,
36
+ frame,
37
+ pane,
38
+ width: 992,
39
+ });
35
40
  </script>
36
41
 
37
42
  <template>
@@ -44,15 +49,16 @@ const { frameBody, frameStyle } = useCanvasFrame({ css: pageCss, fill: true, fra
44
49
  </template>
45
50
  ```
46
51
 
47
- `getFrameWidth` and `getFrameScale` are the pure geometry the composable uses, exported on their own.
52
+ ## <a name="key-exports">๐Ÿงฉ Key Exports</a>
48
53
 
49
- ## <a name="documentation">๐Ÿ“– Documentation</a>
54
+ | Export | Kind | Purpose |
55
+ | --------------------- | ---------- | ---------------------------------------------------------------------------------------- |
56
+ | `CANVAS_FRAME_SRCDOC` | const | The document every frame starts from, before its page's markup is teleported into it |
57
+ | `getFrameScale` | function | The scale that fits a frame to a pane, never above 1, and 1 while the pane is unmeasured |
58
+ | `getFrameWidth` | function | The frame's width: its least width, or the pane's width when it fills a wider pane |
59
+ | `useCanvasFrame` | composable | Draws content in an isolated document at a width, scaled down to fit a narrower pane |
50
60
 
51
- We highly recommend you take a look at the [documentation](https://github.com/Esposter/Esposter/tree/main/openspec/specs) to level up.
52
-
53
- ## <a name="tests">๐Ÿงช Tests</a>
54
-
55
- `pnpm test` runs the unit tests under happy-dom. `pnpm test:browser` runs the browser tests in a real browser, on the shared browser configuration, with no Nuxt.
61
+ `getFrameWidth` and `getFrameScale` are the pure geometry the composable uses, exported on their own.
56
62
 
57
63
  ## <a name="license">โš–๏ธ License</a>
58
64
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-canvas-frame-headless",
3
- "version": "4.3.3",
3
+ "version": "4.4.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,16 @@
40
40
  "lint:fix": "eslint --fix .",
41
41
  "test": "vitest",
42
42
  "test:browser": "vitest --config vitest.browser.config.ts",
43
- "typecheck": "tsc"
43
+ "typecheck": "tsrs --fast"
44
44
  },
45
45
  "devDependencies": {
46
- "@esposter/configuration": "4.3.3",
46
+ "@esposter/configuration": "4.4.0",
47
47
  "@vue/test-utils": "^2.5.1",
48
48
  "happy-dom": "^21.0.4",
49
- "tsdown": "^0.23.1"
49
+ "tsdown": "0.23.2"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "vue": "^3.5.44"
53
53
  },
54
- "gitHead": "955bbc130ad9b28877fd4ae8efc73a045141ce01"
54
+ "gitHead": "e1a416c4b91da69cc2aa259b50a4d656f204d272"
55
55
  }
package/dist/index.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import { ComputedRef, MaybeRefOrGetter, Ref } from "vue";
2
- export declare const useCanvasFrame: ({ css, fill, frame, pane, width }: {
3
- css: MaybeRefOrGetter<string>;
4
- fill?: MaybeRefOrGetter<boolean>;
5
- frame: Ref<HTMLIFrameElement | null | undefined>;
6
- pane: Ref<HTMLElement | null | undefined>;
7
- width: MaybeRefOrGetter<number>;
8
- }) => {
9
- frameBody: ComputedRef<HTMLElement | undefined>;
10
- frameStyle: ComputedRef<Record<string, string>>;
11
- loaded: Promise<void>;
12
- };
13
- export declare const CANVAS_FRAME_SRCDOC = "<!doctype html><html><head></head><body></body></html>";
14
- export declare const getFrameScale: (paneWidth: number, frameWidth: number) => number;
15
- export declare const getFrameWidth: (width: number, fill: boolean, paneWidth: number) => number;
package/dist/index.js DELETED
@@ -1,67 +0,0 @@
1
- import { computed, onMounted, onScopeDispose, shallowRef, toValue, watch } from "vue";
2
- // src/services/getFrameScale.ts
3
- const getFrameScale = (paneWidth, frameWidth) => paneWidth > 0 ? Math.min(1, paneWidth / frameWidth) : 1;
4
- // src/services/getFrameWidth.ts
5
- const getFrameWidth = (width, fill, paneWidth) => fill ? Math.max(paneWidth, width) : width;
6
- // src/composables/useCanvasFrame.ts
7
- const useCanvasFrame = ({ css, fill, frame, pane, width }) => {
8
- const { promise: loaded, resolve: resolveLoaded } = Promise.withResolvers();
9
- const frameDocument = shallowRef();
10
- const frameStyleSheet = shallowRef();
11
- const paneHeight = shallowRef(0);
12
- const paneWidth = shallowRef(0);
13
- const frameBody = computed(() => frameDocument.value?.body);
14
- const frameWidth = computed(() => getFrameWidth(toValue(width), toValue(fill ?? false), paneWidth.value));
15
- const frameScale = computed(() => getFrameScale(paneWidth.value, frameWidth.value));
16
- const frameStyle = computed(() => ({
17
- height: `${paneHeight.value / frameScale.value}px`,
18
- transform: `scale(${frameScale.value})`,
19
- transformOrigin: "0 0",
20
- width: `${frameWidth.value}px`
21
- }));
22
- const updatePaneSize = (paneElement) => {
23
- paneWidth.value = paneElement.clientWidth;
24
- paneHeight.value = paneElement.clientHeight;
25
- };
26
- let resizeObserver;
27
- onMounted(() => {
28
- const paneElement = pane.value;
29
- if (!paneElement) return;
30
- updatePaneSize(paneElement);
31
- resizeObserver = new ResizeObserver(() => updatePaneSize(paneElement));
32
- resizeObserver.observe(paneElement);
33
- });
34
- onScopeDispose(() => resizeObserver?.disconnect());
35
- const handleLoad = () => {
36
- const contentWindow = frame.value?.contentWindow;
37
- const contentDocument = frame.value?.contentDocument;
38
- if (!contentWindow || !contentDocument) return;
39
- const styleSheet = new contentWindow.CSSStyleSheet();
40
- contentDocument.adoptedStyleSheets = [styleSheet];
41
- frameStyleSheet.value = styleSheet;
42
- frameDocument.value = contentDocument;
43
- resolveLoaded();
44
- };
45
- watch(frame, (frameElement, previousFrameElement) => {
46
- previousFrameElement?.removeEventListener("load", handleLoad);
47
- frameElement?.addEventListener("load", handleLoad);
48
- }, {
49
- flush: "sync",
50
- immediate: true
51
- });
52
- onScopeDispose(() => frame.value?.removeEventListener("load", handleLoad));
53
- let styleFrame = 0;
54
- watch([frameStyleSheet, () => toValue(css)], ([styleSheet, cssText]) => {
55
- cancelAnimationFrame(styleFrame);
56
- styleFrame = requestAnimationFrame(() => styleSheet?.replaceSync(cssText));
57
- });
58
- onScopeDispose(() => cancelAnimationFrame(styleFrame));
59
- return {
60
- frameBody,
61
- frameStyle,
62
- loaded
63
- };
64
- };
65
- // src/services/constants.ts
66
- const CANVAS_FRAME_SRCDOC = "<!doctype html><html><head></head><body></body></html>";
67
- export { CANVAS_FRAME_SRCDOC, getFrameScale, getFrameWidth, useCanvasFrame };