vue-canvas-frame-headless 4.3.1 โ†’ 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.1",
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.1",
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": "777a39636b789c13af33ed13370246ccf6dbaf31"
54
+ "gitHead": "e1a416c4b91da69cc2aa259b50a4d656f204d272"
55
55
  }
package/dist/index.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import { ComputedRef, MaybeRefOrGetter, Ref } from "vue";
2
- //#region src/composables/useCanvasFrame.d.ts
3
- export declare const useCanvasFrame: ({ css, fill, frame, pane, width }: {
4
- css: MaybeRefOrGetter<string>;
5
- fill?: MaybeRefOrGetter<boolean>;
6
- frame: Ref<HTMLIFrameElement | null | undefined>;
7
- pane: Ref<HTMLElement | null | undefined>;
8
- width: MaybeRefOrGetter<number>;
9
- }) => {
10
- frameBody: ComputedRef<HTMLElement | undefined>;
11
- frameStyle: ComputedRef<Record<string, string>>;
12
- loaded: Promise<void>;
13
- };
14
- //#endregion
15
- //#region src/services/constants.d.ts
16
- export declare const CANVAS_FRAME_SRCDOC = "<!doctype html><html><head></head><body></body></html>";
17
- //#endregion
18
- //#region src/services/getFrameScale.d.ts
19
- export declare const getFrameScale: (paneWidth: number, frameWidth: number) => number;
20
- //#endregion
21
- //#region src/services/getFrameWidth.d.ts
22
- export declare const getFrameWidth: (width: number, fill: boolean, paneWidth: number) => number;
23
- //#endregion
package/dist/index.js DELETED
@@ -1,71 +0,0 @@
1
- import { computed, onMounted, onScopeDispose, shallowRef, toValue, watch } from "vue";
2
- //#region src/services/getFrameScale.ts
3
- const getFrameScale = (paneWidth, frameWidth) => paneWidth > 0 ? Math.min(1, paneWidth / frameWidth) : 1;
4
- //#endregion
5
- //#region src/services/getFrameWidth.ts
6
- const getFrameWidth = (width, fill, paneWidth) => fill ? Math.max(paneWidth, width) : width;
7
- //#endregion
8
- //#region src/composables/useCanvasFrame.ts
9
- const useCanvasFrame = ({ css, fill, frame, pane, width }) => {
10
- const { promise: loaded, resolve: resolveLoaded } = Promise.withResolvers();
11
- const frameDocument = shallowRef();
12
- const frameStyleSheet = shallowRef();
13
- const paneHeight = shallowRef(0);
14
- const paneWidth = shallowRef(0);
15
- const frameBody = computed(() => frameDocument.value?.body);
16
- const frameWidth = computed(() => getFrameWidth(toValue(width), toValue(fill ?? false), paneWidth.value));
17
- const frameScale = computed(() => getFrameScale(paneWidth.value, frameWidth.value));
18
- const frameStyle = computed(() => ({
19
- height: `${paneHeight.value / frameScale.value}px`,
20
- transform: `scale(${frameScale.value})`,
21
- transformOrigin: "0 0",
22
- width: `${frameWidth.value}px`
23
- }));
24
- const updatePaneSize = (paneElement) => {
25
- paneWidth.value = paneElement.clientWidth;
26
- paneHeight.value = paneElement.clientHeight;
27
- };
28
- let resizeObserver;
29
- onMounted(() => {
30
- const paneElement = pane.value;
31
- if (!paneElement) return;
32
- updatePaneSize(paneElement);
33
- resizeObserver = new ResizeObserver(() => updatePaneSize(paneElement));
34
- resizeObserver.observe(paneElement);
35
- });
36
- onScopeDispose(() => resizeObserver?.disconnect());
37
- const handleLoad = () => {
38
- const contentWindow = frame.value?.contentWindow;
39
- const contentDocument = frame.value?.contentDocument;
40
- if (!contentWindow || !contentDocument) return;
41
- const styleSheet = new contentWindow.CSSStyleSheet();
42
- contentDocument.adoptedStyleSheets = [styleSheet];
43
- frameStyleSheet.value = styleSheet;
44
- frameDocument.value = contentDocument;
45
- resolveLoaded();
46
- };
47
- watch(frame, (frameElement, previousFrameElement) => {
48
- previousFrameElement?.removeEventListener("load", handleLoad);
49
- frameElement?.addEventListener("load", handleLoad);
50
- }, {
51
- flush: "sync",
52
- immediate: true
53
- });
54
- onScopeDispose(() => frame.value?.removeEventListener("load", handleLoad));
55
- let styleFrame = 0;
56
- watch([frameStyleSheet, () => toValue(css)], ([styleSheet, cssText]) => {
57
- cancelAnimationFrame(styleFrame);
58
- styleFrame = requestAnimationFrame(() => styleSheet?.replaceSync(cssText));
59
- });
60
- onScopeDispose(() => cancelAnimationFrame(styleFrame));
61
- return {
62
- frameBody,
63
- frameStyle,
64
- loaded
65
- };
66
- };
67
- //#endregion
68
- //#region src/services/constants.ts
69
- const CANVAS_FRAME_SRCDOC = "<!doctype html><html><head></head><body></body></html>";
70
- //#endregion
71
- export { CANVAS_FRAME_SRCDOC, getFrameScale, getFrameWidth, useCanvasFrame };