@ingcreators/annot-product-docs 0.1.0 → 0.2.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/dist/mdx.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import { ParsedMdx } from './types.js';
2
+ /**
3
+ * Parse one MDX file from disk. Returns `null` if the file lacks
4
+ * an `annot:` frontmatter block (regular MDX files in customer
5
+ * docs sites pass through untouched).
6
+ */
7
+ export declare function parseMdxFile(filePath: string): Promise<ParsedMdx | null>;
8
+ export interface ParseMdxOptions {
9
+ /** Used only for error messages; defaults to `<inline>`. */
10
+ filePath?: string;
11
+ }
12
+ /**
13
+ * Parse an MDX source string. Returns `null` for sources without
14
+ * an `annot:` frontmatter block.
15
+ *
16
+ * Throws if the `annot:` block exists but fails Zod validation —
17
+ * typos in `id` / `xlsx.role` etc. should fail loudly rather than
18
+ * silently dropping content from the output.
19
+ */
20
+ export declare function parseMdx(source: string, options?: ParseMdxOptions): ParsedMdx | null;
21
+ /**
22
+ * Rewrite the `annot:snapshot` / `annot:attributes` MDX comment
23
+ * blocks in a source string in-place, returning a new source
24
+ * string with the updates applied.
25
+ *
26
+ * Used by the Playwright `screen` fixture (PR 3) to keep each
27
+ * MDX file's snapshot/attribute documentation in sync with what
28
+ * the live page actually exposes. Pure string transform — does
29
+ * NOT re-parse / re-stringify the full MDX tree, so authored
30
+ * Markdown / JSX / whitespace is byte-stable for the unchanged
31
+ * regions.
32
+ *
33
+ * If a block is absent and an update value is provided, the
34
+ * block is appended at end of file. If a block exists and the
35
+ * update value is `undefined`, the block is left untouched —
36
+ * pass an empty string to clear an existing block.
37
+ */
38
+ export declare function updateCommentBlocks(source: string, updates: {
39
+ snapshot?: string;
40
+ attributes?: string;
41
+ }): string;
@@ -0,0 +1,58 @@
1
+ import { Locator, Page } from '@playwright/test';
2
+ import { MatchKey, OverlaySpec } from './types.js';
3
+ export interface SnapshotEntry {
4
+ role: string;
5
+ name: string;
6
+ ref: string;
7
+ depth: number;
8
+ /** Parent chain at parse time, oldest ancestor first. Used by `under`. */
9
+ ancestors: Array<{
10
+ role: string;
11
+ name: string;
12
+ }>;
13
+ }
14
+ export type ResolveResult = {
15
+ ok: true;
16
+ locator: Locator;
17
+ entry: SnapshotEntry;
18
+ } | {
19
+ ok: false;
20
+ kind: ResolveFailureKind;
21
+ reason: string;
22
+ suggestion?: string;
23
+ candidates?: string[];
24
+ };
25
+ export type ResolveFailureKind = "not-found" | "ambiguous" | "live-mismatch" | "renamed" | "role-changed";
26
+ /**
27
+ * Parse the YAML-ish aria-snapshot output from
28
+ * `page.locator('body').ariaSnapshot({ mode: 'ai' })` into a
29
+ * flat list of entries with parent-chain context.
30
+ *
31
+ * Playwright emits a 2-space-per-level indented bullet list:
32
+ *
33
+ * - dialog "Confirm":
34
+ * - button "OK" [ref=e12]
35
+ * - button "Cancel" [ref=e13]
36
+ *
37
+ * Each line is `- <role> "<name>" [ref=eN]` optionally followed
38
+ * by `:` (for containers). We walk the lines once, maintaining a
39
+ * parent stack so each entry knows its full ancestor chain — the
40
+ * resolver uses that chain to honour `match.under` for
41
+ * disambiguation.
42
+ */
43
+ export declare function parseSnapshot(yaml: string): SnapshotEntry[];
44
+ /**
45
+ * Resolve a single `MatchKey` against a parsed snapshot + live
46
+ * `Page`. Honours `match.under` by filtering candidate entries
47
+ * whose ancestor chain ends with the `under` key.
48
+ */
49
+ export declare function resolveMatch(match: MatchKey, snapshot: SnapshotEntry[], page: Page): Promise<ResolveResult>;
50
+ /**
51
+ * Resolve every `<Overlay>` in a screen against the snapshot.
52
+ * Returns one result per overlay in input order, so the caller
53
+ * can pair them with the source spans for drift reports.
54
+ */
55
+ export declare function resolveOverlays(overlays: OverlaySpec[], snapshot: SnapshotEntry[], page: Page): Promise<Array<{
56
+ overlay: OverlaySpec;
57
+ result: ResolveResult;
58
+ }>>;
@@ -0,0 +1,18 @@
1
+ export type { AnnotFrontmatter, AnnotFrontmatterRole, AnnotMeta, AnnotXlsxConfig, } from './types.js';
2
+ export interface BookConfig {
3
+ template?: string;
4
+ templateSheets?: {
5
+ cover?: string;
6
+ history?: string;
7
+ list?: string;
8
+ screen?: string;
9
+ reference?: string;
10
+ };
11
+ }
12
+ export interface AnnotDocsConfig {
13
+ meta?: Record<string, unknown>;
14
+ xlsx?: {
15
+ defaultBook?: string;
16
+ books?: Record<string, BookConfig>;
17
+ };
18
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Persistent match key — `role + name` pair, optionally
3
+ * constrained by a parent `under` key to disambiguate
4
+ * non-unique role+name combinations.
5
+ *
6
+ * Critical: `match` keys NEVER persist Playwright `ref=eN` ids —
7
+ * those are session-local and change between snapshots. The
8
+ * resolver walks the live snapshot to find the matching element
9
+ * each run.
10
+ */
11
+ export interface MatchKey {
12
+ role: string;
13
+ name: string;
14
+ under?: MatchKey;
15
+ }
16
+ export type OverlayIntent = "info" | "warning" | "error" | "success" | "neutral" | "required" | "action";
17
+ export interface OverlaySpec {
18
+ match: MatchKey;
19
+ intent?: OverlayIntent;
20
+ number?: number;
21
+ /** Markdown body between the `<Overlay>` opening and closing tags. */
22
+ body: string;
23
+ }
24
+ export interface TransitionSpec {
25
+ trigger: MatchKey;
26
+ on?: string;
27
+ to?: string;
28
+ body: string;
29
+ }
30
+ export interface ScreenSpec {
31
+ id: string;
32
+ src?: string;
33
+ overlays: OverlaySpec[];
34
+ }
35
+ export interface HistoryEntrySpec {
36
+ version: string;
37
+ date: string;
38
+ author: string;
39
+ body: string;
40
+ }
41
+ export interface ScreenListSpec {
42
+ book?: string;
43
+ sort?: "byId" | "byOrder" | "byFilePath";
44
+ }
45
+ export type AnnotFrontmatterRole = "cover" | "history" | "list" | "screen" | "reference";
46
+ export interface AnnotXlsxConfig {
47
+ book?: string;
48
+ /** Single sheet name — used when the MDX contributes one sheet. */
49
+ sheet?: string;
50
+ /** Per-`<Screen>` sheet names — used when the MDX contributes multiple sheets. */
51
+ sheets?: Record<string, string>;
52
+ role?: AnnotFrontmatterRole;
53
+ order?: number;
54
+ }
55
+ export interface AnnotMeta {
56
+ author?: string;
57
+ createdDate?: string;
58
+ revisedDate?: string;
59
+ revision?: string;
60
+ reviewedBy?: string;
61
+ [key: string]: unknown;
62
+ }
63
+ export interface AnnotFrontmatter {
64
+ id: string;
65
+ title?: string;
66
+ purpose?: string;
67
+ meta?: AnnotMeta;
68
+ xlsx?: AnnotXlsxConfig;
69
+ }
70
+ /**
71
+ * Aria-snapshot and HTML-attribute blocks that live as MDX
72
+ * comments in the body. The Playwright `screen` fixture (PR 3)
73
+ * writes these in-place after each run so the file's "what the
74
+ * page looks like" stays accurate alongside the human-authored
75
+ * `<Overlay>` prose.
76
+ *
77
+ * Stored verbatim as the inner text between the open / close
78
+ * markers — the resolver parses snapshot YAML separately via
79
+ * `parseSnapshot` in `./resolver.ts`.
80
+ */
81
+ export interface AnnotCommentBlocks {
82
+ /** Raw YAML between `{/* annot:snapshot *‌/}` markers. */
83
+ snapshot?: string;
84
+ /** Raw text between `{/* annot:attributes *‌/}` markers. */
85
+ attributes?: string;
86
+ }
87
+ /**
88
+ * The full extraction result for one MDX file. `frontmatter`
89
+ * is the `annot:` block; `screens` / `transitions` / `history`
90
+ * are the JSX components found in the body; `commentBlocks`
91
+ * captures the MDX comment blocks the fixture rewrites.
92
+ *
93
+ * Files without an `annot:` frontmatter block are not parsed —
94
+ * `parseMdx` returns `null` for them so the CLI can `glob` for
95
+ * every `*.mdx` and ignore non-annot files cheaply.
96
+ */
97
+ export interface ParsedMdx {
98
+ frontmatter: AnnotFrontmatter;
99
+ screens: ScreenSpec[];
100
+ transitions: TransitionSpec[];
101
+ history: HistoryEntrySpec[];
102
+ screenLists: ScreenListSpec[];
103
+ commentBlocks: AnnotCommentBlocks;
104
+ /** Original source text — needed by `serialiseUpdate` for byte-stable rewrites. */
105
+ source: string;
106
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ingcreators/annot-product-docs",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Living product docs core — parse `.mdx` files with `annot:` frontmatter, resolve `<Overlay match>` keys against live Playwright `aria-snapshot` trees, run drift detection against the rendered UI, and ship a Playwright `screen` fixture that re-captures + re-syncs MDX snapshot blocks. Tier A (Node-only). Phase 1 of docs/plans/living-product-docs.md.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "ingcreators",
@@ -21,7 +21,7 @@
21
21
  "docs",
22
22
  "documentation",
23
23
  "screen-spec",
24
- "画面設計書",
24
+ "screen-specifications",
25
25
  "drift",
26
26
  "aria-snapshot"
27
27
  ],
@@ -52,8 +52,8 @@
52
52
  "@types/mdast": "^4.0.4",
53
53
  "@types/unist": "^3.0.3",
54
54
  "typescript": "^6.0.3",
55
- "vite": "^6.4.2",
56
- "vite-plugin-dts": "^5.0.0"
55
+ "vite": "^8.0.13",
56
+ "vite-plugin-dts": "^5.0.1"
57
57
  },
58
58
  "dependencies": {
59
59
  "js-yaml": "^4.1.1",
@@ -65,8 +65,8 @@
65
65
  "unified": "^11.0.5",
66
66
  "unist-util-visit": "^5.0.0",
67
67
  "zod": "^3.25.0",
68
- "@ingcreators/annot-annotator": "0.3.0",
69
- "@ingcreators/annot-playwright": "0.3.0"
68
+ "@ingcreators/annot-annotator": "0.5.0",
69
+ "@ingcreators/annot-playwright": "0.3.1"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "@playwright/test": "^1.40.0"