@ingcreators/annot-product-docs-astro 0.1.0 → 0.2.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.
@@ -0,0 +1,129 @@
1
+ import { BboxNumberedBadgeAnnotation } from '@ingcreators/annot-annotator';
2
+ import { FileCache } from './cache.js';
3
+ export interface RenderAnnotatedScreenOptions {
4
+ /** Path to the `.mdx` file (absolute or relative to cwd). */
5
+ mdxPath: string;
6
+ /** Must match a `<Screen id="...">` inside the MDX. */
7
+ screenId: string;
8
+ /** Optional cache. When supplied, identical inputs short-circuit to a cached buffer. */
9
+ cache?: FileCache;
10
+ /** Override the cwd used to resolve relative `mdxPath`. */
11
+ cwd?: string;
12
+ /**
13
+ * Override the base PNG that `<Screen src>` would otherwise
14
+ * point at. Useful when the on-disk PNG and the served URL
15
+ * diverge — e.g. an Astro site that serves PNGs from
16
+ * `public/` while the MDX `<Screen src>` carries the
17
+ * absolute browser URL. The caller hands in the bytes
18
+ * directly and `loadBasePng` is skipped.
19
+ */
20
+ basePngBytes?: Uint8Array;
21
+ /**
22
+ * Emit a re-editable PNG instead of a flat raster. When set,
23
+ * the visible pixels match the default rasterised output but
24
+ * the file additionally carries the original (un-annotated)
25
+ * base image + the annotations SVG in the PNG's XMP metadata
26
+ * + custom `svGo` chunk, so re-opening the file in Annot Cloud
27
+ * / the editor / VSCode hosts restores the annotations as
28
+ * selectable / movable objects.
29
+ *
30
+ * Pass `true` for the defaults, or an object to set the optional
31
+ * `tags` field on the embedded XMP (e.g. `source` / `screen` /
32
+ * `capturedAt` provenance metadata — see
33
+ * `@ingcreators/annot-annotator`'s `EditableInput`).
34
+ *
35
+ * When no overlay bboxes resolve (the snapshot block has no
36
+ * `[box=…]` markers yet), the base PNG is wrapped as an editable
37
+ * PNG with an empty annotations layer — re-opening still works,
38
+ * the editor just shows the un-annotated capture.
39
+ */
40
+ editable?: boolean | {
41
+ tags?: Record<string, string>;
42
+ };
43
+ }
44
+ export interface RenderResult {
45
+ /** Annotated PNG bytes. */
46
+ bytes: Uint8Array;
47
+ /** Whether the result came from cache. Useful for logging. */
48
+ fromCache: boolean;
49
+ /**
50
+ * `false` when the source had no bbox markers and we
51
+ * returned the base PNG verbatim. The Image Service surfaces
52
+ * this so an Astro plugin can warn the author to run the
53
+ * Playwright tour.
54
+ */
55
+ hadBoundingBoxes: boolean;
56
+ }
57
+ /**
58
+ * Top-level renderer used by both the Astro Image Service and
59
+ * vitest test cases. Steps:
60
+ *
61
+ * 1. Parse the MDX via `parseMdxFile`.
62
+ * 2. Find the `<Screen id>` matching `screenId`. Throw with a
63
+ * friendly diagnostic if missing.
64
+ * 3. Compute the cache key from the MDX source + `screenId`.
65
+ * On a cache hit, return the bytes immediately.
66
+ * 4. Load the base PNG referenced by `<Screen src>`.
67
+ * 5. Parse the stored `annot:snapshot` block for bbox markers.
68
+ * If absent, return base PNG verbatim.
69
+ * 6. Build a typed `BboxCalloutAnnotation[]` from the overlays
70
+ * + bbox data, hand it to `createAnnotator().toPng(...)`,
71
+ * and return the result.
72
+ */
73
+ export declare function renderAnnotatedScreen(options: RenderAnnotatedScreenOptions): Promise<RenderResult>;
74
+ interface BoxedEntry {
75
+ role: string;
76
+ name: string;
77
+ ref: string;
78
+ box: {
79
+ x: number;
80
+ y: number;
81
+ width: number;
82
+ height: number;
83
+ };
84
+ }
85
+ /**
86
+ * Parse aria-snapshot YAML for entries that carry both `[ref=…]`
87
+ * and `[box=x,y,w,h]` markers. `box` is the Playwright addition
88
+ * available when `ariaSnapshot({ boxes: true })` was passed.
89
+ *
90
+ * Exposed for unit testing. Returns an empty array if no entries
91
+ * have boxes — the caller falls back to a non-annotated render.
92
+ */
93
+ export declare function parseSnapshotBoxes(yaml: string): BoxedEntry[];
94
+ /**
95
+ * Resolve the `<Overlay>` blocks inside `screenId` against the MDX
96
+ * file's stored `annot:snapshot` block and return a typed annotation
97
+ * array ready to feed into `createAnnotator().toEditablePng()`.
98
+ *
99
+ * Exposed so the Playwright fixture can compose MDX-derived overlays
100
+ * with caller-supplied inline overlays before rasterisation. Throws
101
+ * the same diagnostics `renderAnnotatedScreen` would (no annot
102
+ * frontmatter / no matching `<Screen id>`).
103
+ *
104
+ * Returns an empty array when no `<Overlay>` matches a bbox marker
105
+ * — e.g. the snapshot was never captured, or `<Overlay match>`
106
+ * targets an element that's no longer in the page.
107
+ */
108
+ export declare function resolveMdxAnnotations(opts: {
109
+ mdxPath: string;
110
+ screenId: string;
111
+ dims: {
112
+ width: number;
113
+ height: number;
114
+ };
115
+ cwd?: string;
116
+ }): Promise<BboxNumberedBadgeAnnotation[]>;
117
+ /**
118
+ * Wrap a generic `BboxAnnotation[]` (the union DSL accepted by
119
+ * `@ingcreators/annot-annotator`) into a single-root `<svg>` ready
120
+ * for the annotator's `annotationsSvg` input. Mirrors `svgFromBadges`
121
+ * but stays type-permissive — the Playwright fixture's inline overlays
122
+ * can be any `BboxAnnotation` shape, not just numbered badges.
123
+ *
124
+ * Returns the empty wrapper `<svg/>` when `annotations` is empty —
125
+ * lets the editor open the file with no annotations layer rather
126
+ * than throwing.
127
+ */
128
+ export declare function svgFromBboxAnnotations(annotations: import('@ingcreators/annot-annotator').BboxAnnotation[]): string;
129
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ingcreators/annot-product-docs-astro",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Astro integration for `@ingcreators/annot-product-docs`. Wires the MDX components (`<Screen>` / `<Overlay>` / `<Transition>` / `<HistoryEntry>` / `<ScreenList>` / `<TransitionGraph>`) into an Astro site and supplies the Image Service that renders annotated PNGs from `<Screen>` blocks at build time. Phase 2 of docs/plans/living-product-docs.md.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "ingcreators",
@@ -22,7 +22,7 @@
22
22
  "docs",
23
23
  "documentation",
24
24
  "screen-spec",
25
- "画面設計書",
25
+ "screen-specifications",
26
26
  "image-service"
27
27
  ],
28
28
  "type": "module",
@@ -33,6 +33,10 @@
33
33
  "types": "./dist/index.d.ts",
34
34
  "default": "./dist/index.js"
35
35
  },
36
+ "./playwright": {
37
+ "types": "./dist/playwright/index.d.ts",
38
+ "default": "./dist/playwright/index.js"
39
+ },
36
40
  "./components/Screen.astro": "./dist/components/Screen.astro",
37
41
  "./components/Overlay.astro": "./dist/components/Overlay.astro",
38
42
  "./components/Transition.astro": "./dist/components/Transition.astro",
@@ -50,17 +54,25 @@
50
54
  "access": "public"
51
55
  },
52
56
  "devDependencies": {
53
- "astro": "^5.0.0",
57
+ "@playwright/test": "^1.50.0",
58
+ "astro": "^6.3.6",
54
59
  "typescript": "^6.0.3",
55
- "vite": "^6.4.2",
56
- "vite-plugin-dts": "^5.0.0"
60
+ "vite": "^8.0.13",
61
+ "vite-plugin-dts": "^5.0.1"
57
62
  },
58
63
  "dependencies": {
59
- "@ingcreators/annot-annotator": "0.3.0",
60
- "@ingcreators/annot-product-docs": "0.1.0"
64
+ "@ingcreators/annot-core": "0.2.0",
65
+ "@ingcreators/annot-annotator": "0.5.0",
66
+ "@ingcreators/annot-product-docs": "0.2.0"
61
67
  },
62
68
  "peerDependencies": {
63
- "astro": "^5.0.0"
69
+ "@playwright/test": "^1.42.0",
70
+ "astro": "^5.0.0 || ^6.0.0"
71
+ },
72
+ "peerDependenciesMeta": {
73
+ "@playwright/test": {
74
+ "optional": true
75
+ }
64
76
  },
65
77
  "scripts": {
66
78
  "build": "vite build",