@beyondwork/docx-react-component 1.0.96 → 1.0.97

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.
Files changed (41) hide show
  1. package/package.json +1 -1
  2. package/src/api/public-types.ts +33 -19
  3. package/src/api/v3/ui/_types.ts +11 -21
  4. package/src/api/v3/ui/chrome.ts +8 -9
  5. package/src/api/v3/ui/debug.ts +15 -77
  6. package/src/api/v3/ui/overlays-visibility.ts +9 -10
  7. package/src/api/v3/ui/overlays.ts +8 -75
  8. package/src/io/ooxml/parse-main-document.ts +30 -0
  9. package/src/io/ooxml/parse-picture.ts +14 -0
  10. package/src/io/ooxml/parse-shapes.ts +41 -1
  11. package/src/model/canonical-document.ts +17 -0
  12. package/src/runtime/layout/layout-engine-version.ts +8 -1
  13. package/src/runtime/layout/page-story-resolver.ts +1 -0
  14. package/src/runtime/layout/paginated-layout-engine.ts +26 -10
  15. package/src/runtime/surface-projection.ts +114 -12
  16. package/src/ui/WordReviewEditor.tsx +6 -10
  17. package/src/ui/editor-command-bag.ts +2 -0
  18. package/src/ui/ui-controller-factory.ts +2 -2
  19. package/src/ui-tailwind/chrome-overlay/tw-chrome-overlay.tsx +11 -25
  20. package/src/ui-tailwind/chrome-overlay/tw-scope-card-layer.tsx +2 -2
  21. package/src/ui-tailwind/chrome-overlay/tw-scope-card.tsx +1 -1
  22. package/src/ui-tailwind/chrome-overlay/tw-scope-rail-layer.tsx +22 -220
  23. package/src/ui-tailwind/debug/README.md +12 -50
  24. package/src/ui-tailwind/debug/tw-debug-overlay.tsx +6 -6
  25. package/src/ui-tailwind/debug/tw-debug-presentation.tsx +9 -20
  26. package/src/ui-tailwind/debug/tw-debug-top-bar.tsx +5 -6
  27. package/src/ui-tailwind/editor-surface/chart-node-view.tsx +1 -4
  28. package/src/ui-tailwind/editor-surface/picture-effects.ts +96 -0
  29. package/src/ui-tailwind/editor-surface/pm-schema.ts +89 -62
  30. package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +205 -0
  31. package/src/ui-tailwind/editor-surface/runtime-decoration-plugin.ts +190 -0
  32. package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +53 -53
  33. package/src/ui-tailwind/page-stack/floating-image-overlay-model.ts +83 -20
  34. package/src/ui-tailwind/page-stack/tw-floating-image-layer.tsx +114 -4
  35. package/src/ui-tailwind/page-stack/tw-page-chrome-entry.tsx +5 -0
  36. package/src/ui-tailwind/page-stack/tw-page-footer-band.tsx +3 -0
  37. package/src/ui-tailwind/page-stack/tw-page-header-band.tsx +3 -0
  38. package/src/ui-tailwind/page-stack/tw-page-stack-chrome-layer.tsx +8 -0
  39. package/src/ui-tailwind/page-stack/tw-region-block-renderer.tsx +26 -0
  40. package/src/ui-tailwind/theme/editor-theme.css +18 -11
  41. package/src/ui-tailwind/tw-review-workspace.tsx +15 -0
@@ -1,25 +1,23 @@
1
1
  /**
2
- * Scope rail layer — renders workflow scopes as a thin color stripe in
3
- * the reserved left-gutter lane plus a border-only line outline. The
4
- * visible scope ownership border lives on the PM inline text decoration.
2
+ * Scope rail layer — intentionally non-rendering in product chrome.
3
+ *
4
+ * Scoped text is now the only visible rest-state affordance for a set
5
+ * scope. The old gutter rail created duplicate markers, drifted away
6
+ * from the scoped text, and surfaced invisible/implementation scopes in
7
+ * production. Keep this component as a compatibility shim plus a home
8
+ * for the pure geometry helpers used by tests.
5
9
  *
6
10
  * Per runtime-rendering-and-chrome-phase.md §5 and
7
- * docs/plans/scope-card-overlay.md P0, the rail is a projection over
8
- * canonical workflow scopes; it never lives inside the PM NodeView
9
- * tree. Positions come from the render kernel's per-line block data
10
- * (walked directly from `RenderFrame.pages[].regions.body.blocks[]`)
11
- * so multi-line scopes produce one tight tint per line rather than a
12
- * fat bounding-box union.
11
+ * docs/plans/scope-card-overlay.md P0, historical rail geometry came
12
+ * from the render kernel's per-line block data. The helpers remain for
13
+ * callers that need geometry, but the React layer no longer paints or
14
+ * reads scope data.
13
15
  */
14
16
 
15
17
  import * as React from "react";
16
- import {
17
- projectRectToOverlay,
18
- type OverlayCoordinateSpace,
19
- } from "./chrome-overlay-projector";
20
- import { useUiApi } from "../ui-api-context";
18
+ import type { OverlayCoordinateSpace } from "./chrome-overlay-projector";
21
19
  import type { RenderFrame, RenderFrameRect } from "../../api/public-types.ts";
22
- import type { ScopeRailSegment, ScopeRailPosture } from "../../api/public-types.ts";
20
+ import type { ScopeRailSegment } from "../../api/public-types.ts";
23
21
  import type { WorkflowFacet } from "../../api/public-types.ts";
24
22
  import type { GeometryFacet } from "../../api/public-types";
25
23
 
@@ -29,21 +27,18 @@ import type { GeometryFacet } from "../../api/public-types";
29
27
 
30
28
  export interface TwScopeRailLayerProps {
31
29
  /**
32
- * Geometry facet used for `getRenderFrame()`. Migrated from
33
- * `facet: WordReviewEditorLayoutFacet` in refactor/05 cross-lane-coord
34
- * §8.4 pass. Mounted rail/card data flows through `api.ui.scope.*`.
30
+ * Legacy prop kept for compatibility. The component no longer reads
31
+ * geometry because it does not paint the rail.
35
32
  */
36
33
  geometryFacet: GeometryFacet;
37
34
  /**
38
- * Workflow facet no-provider fallback for scope rail/card reads.
39
- * Mounted editor paths prefer `api.ui.scope.*`; passing `null` makes
40
- * fallback reads no-op.
35
+ * Legacy prop kept for compatibility. The component intentionally does
36
+ * not read workflow scope data.
41
37
  */
42
38
  workflowFacet: WorkflowFacet | null;
43
39
  /**
44
- * Optional pre-read rail snapshot from `ui.scope.rail()`. When omitted,
45
- * the layer reads the mounted UI API itself, then falls back to the
46
- * workflow facet for no-provider paths.
40
+ * Legacy pre-read snapshot. Ignored so invisible implementation scopes
41
+ * cannot surface through the old rail path.
47
42
  */
48
43
  scopeRailSegments?: readonly ScopeRailSegment[];
49
44
  /** Overlay's coordinate space. Defaults to the overlay's own origin. */
@@ -53,215 +48,22 @@ export interface TwScopeRailLayerProps {
53
48
  /** Scope id that should render with the `active` emphasis. */
54
49
  activeScopeId?: string | null;
55
50
  /**
56
- * Fires when the user clicks the rail stripe — opens the scope card.
57
- * P0 wires this directly; P1 replaces with card-layer-aware routing.
51
+ * Deprecated no-op. Scoped text selection/card flows replace rail clicks.
58
52
  */
59
53
  onStripeClick?: (segment: ScopeRailSegment) => void;
60
54
  /**
61
- * Legacy click handler kept for existing consumers. Called alongside
62
- * `onStripeClick` so host apps that subscribed to the pre-stripe API
63
- * continue to receive clicks.
55
+ * Deprecated no-op kept for existing consumers.
64
56
  */
65
57
  onSegmentClick?: (segment: ScopeRailSegment) => void;
66
58
  /** Test id applied to the layer root. */
67
59
  "data-testid"?: string;
68
60
  }
69
61
 
70
- // ---------------------------------------------------------------------------
71
- // Posture → visual grammar
72
- // ---------------------------------------------------------------------------
73
-
74
- interface PostureStyle {
75
- labelText: string;
76
- icon: string;
77
- railToken: string;
78
- tintToken: string;
79
- }
80
-
81
- const POSTURE_STYLES: Record<ScopeRailPosture, PostureStyle> = {
82
- edit: { labelText: "EDIT", icon: "pencil", railToken: "accent", tintToken: "accent" },
83
- suggest: { labelText: "SUGGEST", icon: "sparkles", railToken: "warning", tintToken: "warning" },
84
- comment: { labelText: "COMMENT", icon: "message", railToken: "insert", tintToken: "insert" },
85
- view: { labelText: "IN SCOPE", icon: "eye", railToken: "secondary", tintToken: "secondary" },
86
- candidate: { labelText: "PROPOSED", icon: "flag", railToken: "warning", tintToken: "warning" },
87
- "preserve-only": { labelText: "BLOCKED", icon: "lock", railToken: "danger", tintToken: "danger" },
88
- "blocked-import": { labelText: "BLOCKED", icon: "lock", railToken: "danger", tintToken: "danger" },
89
- };
90
-
91
62
  // ---------------------------------------------------------------------------
92
63
  // Component
93
64
  // ---------------------------------------------------------------------------
94
65
 
95
- const DEFAULT_RAIL_LANE_PX = 44;
96
- const STRIPE_WIDTH_PX = 4;
97
- const LABEL_WIDTH_PX = 28;
98
- const STACK_OFFSET_PX = 6;
99
-
100
- export const TwScopeRailLayer: React.FC<TwScopeRailLayerProps> = ({
101
- geometryFacet,
102
- workflowFacet,
103
- scopeRailSegments,
104
- space,
105
- railLaneWidthPx = DEFAULT_RAIL_LANE_PX,
106
- activeScopeId,
107
- onStripeClick,
108
- onSegmentClick,
109
- "data-testid": testId,
110
- }) => {
111
- const ui = useUiApi();
112
- const frame = geometryFacet.getRenderFrame() ?? null;
113
- const segments =
114
- scopeRailSegments ??
115
- ui?.scope.rail().segments ??
116
- workflowFacet?.getAllRailSegments() ??
117
- [];
118
-
119
- if (!frame || segments.length === 0) {
120
- return null;
121
- }
122
-
123
- // P2: which scopes currently have a `source: "ai"` candidate
124
- // overlapping — drives the agent-pending shimmer class on their
125
- // tints. Mounted surfaces read card projections through ui.scope.card;
126
- // no-provider paths fall back to the workflow facet.
127
- const cardModels = ui ? [] : workflowFacet?.getAllScopeCardModels() ?? [];
128
- const agentPendingByScope = new Map<string, boolean>();
129
- for (const model of cardModels) {
130
- if (model.agentPending) {
131
- agentPendingByScope.set(model.scopeId, true);
132
- }
133
- }
134
- if (ui) {
135
- for (const segment of segments) {
136
- const model = ui.scope.card(segment.scopeId);
137
- if (model?.agentPending) {
138
- agentPendingByScope.set(segment.scopeId, true);
139
- }
140
- }
141
- }
142
-
143
- // P3c: stack offsets for overlapping scopes. Two scopes whose
144
- // offset ranges intersect on the same page render as stacked
145
- // stripes in the gutter; the inner stripe shifts STACK_OFFSET_PX
146
- // further right per overlap count so all are clickable.
147
- const stackIndexByScope = computeStackIndices(segments);
148
-
149
- const projectorSpace: OverlayCoordinateSpace = space ?? { originLeftPx: 0, originTopPx: 0 };
150
-
151
- return (
152
- <div
153
- className="wre-scope-rail-layer pointer-events-none absolute inset-0 z-20"
154
- data-testid={testId ?? "scope-rail-layer"}
155
- aria-hidden="false"
156
- role="group"
157
- aria-label="Workflow scope rail"
158
- >
159
- {segments.map((segment) => {
160
- const style = POSTURE_STYLES[segment.posture];
161
- const lineRects = collectLineRectsForSegment(frame, segment);
162
- if (lineRects.length === 0) return null;
163
-
164
- const isActive =
165
- activeScopeId === segment.scopeId || segment.isActiveWorkItem;
166
-
167
- // Stripe + label span the vertical range of the scope's lines;
168
- // they live in the gutter lane to the left of the first line.
169
- const firstLine = lineRects[0];
170
- const lastLine = lineRects[lineRects.length - 1];
171
- const stripeTopPx = firstLine.topPx;
172
- const stripeHeightPx =
173
- lastLine.topPx + lastLine.heightPx - firstLine.topPx;
174
- const stackIndex = stackIndexByScope.get(segment.scopeId) ?? 0;
175
- const stackOffset = stackIndex * STACK_OFFSET_PX;
176
- const stripeRect: RenderFrameRect = {
177
- leftPx:
178
- firstLine.leftPx
179
- - railLaneWidthPx
180
- + (railLaneWidthPx - STRIPE_WIDTH_PX) / 2
181
- + stackOffset,
182
- topPx: stripeTopPx,
183
- widthPx: STRIPE_WIDTH_PX,
184
- heightPx: Math.max(stripeHeightPx, 14),
185
- };
186
- const labelRect: RenderFrameRect = {
187
- leftPx: firstLine.leftPx - railLaneWidthPx + stackOffset,
188
- topPx: stripeTopPx,
189
- widthPx: LABEL_WIDTH_PX,
190
- heightPx: 20,
191
- };
192
-
193
- const handleActivate = () => {
194
- onStripeClick?.(segment);
195
- onSegmentClick?.(segment);
196
- };
197
- const handleStripeKey = (event: React.KeyboardEvent<HTMLButtonElement>) => {
198
- if (event.key === "Enter" || event.key === " ") {
199
- event.preventDefault();
200
- handleActivate();
201
- }
202
- };
203
-
204
- return (
205
- <React.Fragment key={`${segment.scopeId}:${segment.pageIndex}:${segment.fromOffset}`}>
206
- {/* Per-line tint behind the scoped text runs. */}
207
- {lineRects.map((lineRect, index) => {
208
- const agentPending = agentPendingByScope.get(segment.scopeId) === true;
209
- const tintClassList = [
210
- "wre-scope-rail-tint",
211
- `wre-scope-rail-tint-${style.tintToken}`,
212
- ];
213
- if (isActive) tintClassList.push("wre-scope-rail-tint-active");
214
- if (agentPending) {
215
- tintClassList.push("wre-scope-rail-tint-agent-pending");
216
- }
217
- return (
218
- <div
219
- key={`tint:${index}`}
220
- className={tintClassList.join(" ")}
221
- data-scope-id={segment.scopeId}
222
- data-posture={segment.posture}
223
- data-line-index={index}
224
- data-agent-pending={agentPending ? "true" : undefined}
225
- style={projectRectToOverlay(lineRect, projectorSpace)}
226
- />
227
- );
228
- })}
229
- {/* Rail stripe in the gutter. */}
230
- <button
231
- type="button"
232
- className={`wre-scope-rail-stripe wre-scope-rail-label-${style.railToken} ${
233
- isActive ? "wre-scope-rail-stripe-active" : ""
234
- }`}
235
- data-scope-id={segment.scopeId}
236
- data-posture={segment.posture}
237
- data-stack-index={stackIndex}
238
- data-testid="scope-rail-stripe"
239
- aria-label={`${style.labelText}${segment.label ? `: ${segment.label}` : ""}`}
240
- aria-expanded={isActive ? "true" : "false"}
241
- onClick={handleActivate}
242
- onKeyDown={handleStripeKey}
243
- style={projectRectToOverlay(stripeRect, projectorSpace)}
244
- />
245
- {/* Edit handle — revealed on stripe hover via CSS. */}
246
- <button
247
- type="button"
248
- tabIndex={-1}
249
- className={`wre-scope-rail-label wre-scope-rail-label-${style.railToken}`}
250
- data-scope-id={segment.scopeId}
251
- data-posture={segment.posture}
252
- aria-label={`Edit scope${segment.label ? `: ${segment.label}` : ""}`}
253
- onClick={handleActivate}
254
- style={projectRectToOverlay(labelRect, projectorSpace)}
255
- >
256
- <span aria-hidden="true" className={`wre-scope-rail-icon wre-scope-rail-icon-${style.icon}`} />
257
- <span className="wre-scope-rail-label-text">{style.labelText}</span>
258
- </button>
259
- </React.Fragment>
260
- );
261
- })}
262
- </div>
263
- );
264
- };
66
+ export const TwScopeRailLayer: React.FC<TwScopeRailLayerProps> = (_props) => null;
265
67
 
266
68
  // ---------------------------------------------------------------------------
267
69
  // Internals
@@ -1,57 +1,19 @@
1
- # Phase Q — Debug UX (reserved)
1
+ # Debug UX (internal only)
2
2
 
3
- Target for the runtime-embedded debug UX consumed through `ui.debug.attach()`
4
- (layer 10, refactor/10 Slice 5). This directory is **reserved** — the Slice 5
5
- ship includes the UI API substrate (`src/api/v3/ui/debug.ts` +
6
- `UiController.attachDebug` hook), while the React presentation components +
7
- the public `debugMode` prop + the visibility invariant test are a **Phase Q
8
- follow-up** per `docs/plans/refactor/10-ui-api.md` Risk #3:
3
+ Runtime debug chrome is not a production API surface. `WordReviewEditor` does
4
+ not expose a `debugMode` prop, `api.ui.debug.attach()` is a hard-disabled
5
+ runtime API call, and `ChromePosture.debugMode` is production-forced to
6
+ `"off"`.
9
7
 
10
- > **Phase Q UX surface area.** `src/ui-tailwind/debug/**` is a new substantial
11
- > UI surface. *Mitigation:* ship substrate in M4 Slice 5; polish in follow-up.
8
+ The supported local diagnostic surface is the mounted runtime REPL keyboard
9
+ shortcut. These components remain in the tree for internal harness/story
10
+ experiments only; do not wire them into `WordReviewEditor` or public API paths.
12
11
 
13
- ## Planned files (follow-up)
12
+ ## Files
14
13
 
15
14
  | File | Purpose |
16
15
  |---|---|
17
- | `tw-debug-top-bar.tsx` | Minimal top bar when `debugMode: "top-bar"` — document hash, scope count, invalidation counter |
18
- | `tw-debug-overlay.tsx` | Full overlay when `debugMode: "full"` — renders `DebugInspectorSnapshot` sections |
19
- | `tw-debug-repl.tsx` | REPL with `api`, `runtime`, `debug` in scope; localStorage-persisted history |
16
+ | `tw-debug-top-bar.tsx` | Internal minimal top bar for harness/story experiments |
17
+ | `tw-debug-overlay.tsx` | Internal overlay rendering `DebugInspectorSnapshot` sections |
18
+ | `tw-debug-repl.tsx` | Legacy placeholder; production diagnostics use `tw-runtime-repl-dialog.tsx` |
20
19
  | `tw-debug-event-tail.tsx` | Tail of the last N events on active telemetry channels |
21
- | `keybindings.ts` | Cmd/Ctrl+Shift+D toggles top-bar ↔ full |
22
-
23
- ## Planned prop (follow-up)
24
-
25
- Add `debugMode?: "off" | "top-bar" | "full"` to `WordReviewEditorProps`.
26
- **Default MUST be `"off"`** per CLAUDE.md Protected Invariants § "Phase Q
27
- placeholder" — this default has regressed multiple times in predecessor
28
- surfaces (`showUnsupportedObjectPreviews`, `unsupportedPreviewsPolicy`).
29
-
30
- ## Planned test (follow-up)
31
-
32
- `test/ui/debug-mode-visibility-invariant.test.ts` — asserts:
33
- - `debugMode: "off"` → no debug UI renders
34
- - `debugMode: "top-bar"` → only the top bar renders
35
- - `debugMode: "full"` → overlay renders
36
-
37
- ## How Slice 5 consumers wire today
38
-
39
- Until the Phase Q React components land, Slice 5 ships only the contract:
40
-
41
- ```ts
42
- import { createUiApi } from "@beyondwork/docx-react-component/api/v3/ui";
43
-
44
- const ui = createUiApi(handle);
45
- ui.session.bind({
46
- kind: "runtime-direct",
47
- id: "my-mount",
48
- attachDebug(session) {
49
- // bind-side: wire runtime.debug.bus + getSnapshot to your debug surface
50
- const off = runtime.debug.bus.on(/* ... */, (evt) => {/* render */});
51
- return () => off();
52
- },
53
- });
54
- const attachment = ui.debug.attach({ id: "s1", channels: ["api", "render"] });
55
- // later:
56
- attachment.detach();
57
- ```
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Phase Q — Debug overlay.
3
3
  *
4
- * Full-screen tabbed panel shown when
5
- * `WordReviewEditorProps.debugMode === "full"`. Renders the top bar
6
- * (reused from `tw-debug-top-bar.tsx`) + three content panes:
4
+ * Internal full-screen tabbed panel for harness/story experiments.
5
+ * Production `WordReviewEditor` does not mount this component. Renders
6
+ * the top bar (reused from `tw-debug-top-bar.tsx`) + three content panes:
7
7
  *
8
8
  * - **Inspector** — pretty-prints the bound `DebugInspectorSnapshot`
9
9
  * (canonical / layout / geometry / scope / review / diagnostics
@@ -32,8 +32,8 @@ export interface TwDebugOverlayProps {
32
32
  sessionId: string | null;
33
33
  snapshot: TwDebugTopBarProps["snapshot"];
34
34
  /**
35
- * Raw `DebugInspectorSnapshot` the host wired through
36
- * `ui.debug.attach()`. Rendered as pretty-printed JSON in the
35
+ * Raw `DebugInspectorSnapshot` supplied by an internal harness/story.
36
+ * Rendered as pretty-printed JSON in the
37
37
  * Inspector pane. Large snapshots are clipped to the first 16 KB
38
38
  * to keep the DOM responsive.
39
39
  */
@@ -126,7 +126,7 @@ export function TwDebugOverlay(props: TwDebugOverlayProps): React.ReactElement {
126
126
  <ul className="flex flex-col gap-0.5 font-mono text-[10px] text-[var(--color-text-secondary)]">
127
127
  {(props.events ?? []).length === 0 ? (
128
128
  <li className="italic text-[var(--color-text-tertiary)]">
129
- (no events — wire `ui.debug.attach()` with a DebugBus listener)
129
+ (no events)
130
130
  </li>
131
131
  ) : (
132
132
  props.events!.slice(-200).map((e, i) => (
@@ -1,34 +1,24 @@
1
1
  /**
2
2
  * Phase Q — DebugMode router.
3
3
  *
4
- * Single mount point `WordReviewEditor.tsx` consumes. Picks between
5
- * the minimal top-bar, the full overlay, or nothing depending on the
6
- * public `debugMode` prop. Keeping the router in one file means the
7
- * invariant test + CI guard can target a single surface.
8
- *
9
- * Data flow (consumers wire through `ui.debug.attach()` per refactor/10
10
- * Slice 5):
11
- *
12
- * host → `ui.debug.attach({ id, channels })` →
13
- * controller.attachDebug(session) →
14
- * { sessionId, snapshot, events } → this component
15
- *
16
- * Slice 7 ships the visibility scaffold; the full REPL + event-tail
17
- * wiring to `runtime.debug.bus` + `DebugInspectorSnapshot` lives in a
18
- * follow-up (see `src/ui-tailwind/debug/README.md`).
4
+ * Internal-only debug presentation router. Production `WordReviewEditor`
5
+ * does not mount this component and does not expose a prop or runtime API
6
+ * that can enable it; the supported local diagnostic surface is the runtime
7
+ * REPL keyboard shortcut.
19
8
  */
20
9
 
21
10
  import React from "react";
22
11
 
23
- import type { DebugMode } from "../../api/public-types.ts";
24
12
  import { TwDebugTopBar, type TwDebugTopBarProps } from "./tw-debug-top-bar.tsx";
25
13
  import { TwDebugOverlay, type TwDebugOverlayProps } from "./tw-debug-overlay.tsx";
26
14
 
15
+ export type DebugMode = "off" | "top-bar" | "full";
16
+
27
17
  export interface TwDebugPresentationProps {
28
18
  mode: DebugMode;
29
19
  /**
30
- * Debug session id mirrors what the host passed into
31
- * `ui.debug.attach({ id })`. `null` when no attachment is active.
20
+ * Debug session id for internal harness/storybook experiments.
21
+ * Production runtime mounting never supplies an active attachment.
32
22
  */
33
23
  sessionId?: string | null;
34
24
  snapshot?: TwDebugTopBarProps["snapshot"];
@@ -36,8 +26,7 @@ export interface TwDebugPresentationProps {
36
26
  events?: TwDebugOverlayProps["events"];
37
27
  onReplEval?: TwDebugOverlayProps["onReplEval"];
38
28
  /**
39
- * Optional override for the mode toggle — host supplies when it
40
- * owns the `debugMode` state (e.g. harness with a keyboard shortcut).
29
+ * Optional override for internal harness/storybook mode toggles.
41
30
  */
42
31
  onModeChange?: (next: DebugMode) => void;
43
32
  }
@@ -1,11 +1,10 @@
1
1
  /**
2
2
  * Phase Q — Debug top bar.
3
3
  *
4
- * Minimal always-on status strip shown when
5
- * `WordReviewEditorProps.debugMode === "top-bar"` (or as the header of
6
- * the "full" overlay). Renders the bound debug session id + a small
7
- * set of counters derived from the `DebugInspectorSnapshot` the host
8
- * supplies through `ui.debug.attach()` wiring.
4
+ * Internal status strip for harness/story experiments. Production
5
+ * `WordReviewEditor` does not mount this component or expose a public
6
+ * debugMode prop/API. Renders the bound debug session id + a small set
7
+ * of counters derived from a supplied `DebugInspectorSnapshot`.
9
8
  *
10
9
  * Slice 7 ships the minimal surface; the REPL + event-tail panes live
11
10
  * in `tw-debug-overlay.tsx` (full mode only). Future telemetry (scope
@@ -17,7 +16,7 @@ import React from "react";
17
16
 
18
17
  export interface TwDebugTopBarProps {
19
18
  /**
20
- * The debug-session id the host passed into `ui.debug.attach()`.
19
+ * The debug-session id the internal harness/story surface supplies.
21
20
  * Shown verbatim so operators can correlate with Railway debug-
22
21
  * service logs. `null` when no attachment is active.
23
22
  */
@@ -12,7 +12,6 @@
12
12
  */
13
13
 
14
14
  import React from "react";
15
- import { flushSync } from "react-dom";
16
15
  import { createRoot, type Root } from "react-dom/client";
17
16
  import type { Node as PMNode } from "prosemirror-model";
18
17
  import type { NodeViewConstructor } from "prosemirror-view";
@@ -83,9 +82,7 @@ class ChartNodeViewInstance {
83
82
  if (!this._root) {
84
83
  this._root = createRoot(this.dom);
85
84
  }
86
- flushSync(() => {
87
- this._root?.render(el);
88
- });
85
+ this._root.render(el);
89
86
  this._mountedChartId = parsedChartId;
90
87
  }
91
88
 
@@ -0,0 +1,96 @@
1
+ import {
2
+ EMU_PER_PX,
3
+ ROTATION_UNITS_PER_DEGREE,
4
+ } from "../../api/public-types.ts";
5
+
6
+ type LumEffect = {
7
+ bright?: number;
8
+ contrast?: number;
9
+ };
10
+
11
+ type DropShadowEffect = {
12
+ blurRad: number;
13
+ dist: number;
14
+ dir: number;
15
+ color?: string | null;
16
+ };
17
+
18
+ type GlowEffect = {
19
+ radius: number;
20
+ color?: string | null;
21
+ };
22
+
23
+ export interface CssPictureFilterEffects {
24
+ lum?: LumEffect | null;
25
+ softEdgeRadius?: number | null;
26
+ glow?: GlowEffect | null;
27
+ outerShadow?: DropShadowEffect | null;
28
+ }
29
+
30
+ export function buildPictureFilterCss(
31
+ effects: CssPictureFilterEffects | null | undefined,
32
+ ): string | undefined {
33
+ if (!effects) return undefined;
34
+ const parts: string[] = [];
35
+ parts.push(...buildLumFilterParts(effects.lum));
36
+ if (effects.softEdgeRadius) {
37
+ parts.push(`blur(${(effects.softEdgeRadius / EMU_PER_PX).toFixed(2)}px)`);
38
+ }
39
+ const glowColor = safeFilterHexColor(effects.glow?.color);
40
+ if (effects.glow && glowColor) {
41
+ parts.push(`drop-shadow(0 0 ${(effects.glow.radius / EMU_PER_PX).toFixed(2)}px ${glowColor})`);
42
+ }
43
+ const shadowColor = safeFilterHexColor(effects.outerShadow?.color);
44
+ if (effects.outerShadow && shadowColor) {
45
+ const blurPx = (effects.outerShadow.blurRad / EMU_PER_PX).toFixed(2);
46
+ const distPx = effects.outerShadow.dist / EMU_PER_PX;
47
+ const dirRad = (effects.outerShadow.dir / ROTATION_UNITS_PER_DEGREE) * (Math.PI / 180);
48
+ const dx = (distPx * Math.cos(dirRad)).toFixed(2);
49
+ const dy = (distPx * Math.sin(dirRad)).toFixed(2);
50
+ parts.push(`drop-shadow(${dx}px ${dy}px ${blurPx}px ${shadowColor})`);
51
+ }
52
+ return parts.length > 0 ? parts.join(" ") : undefined;
53
+ }
54
+
55
+ function buildLumFilterParts(lum: LumEffect | null | undefined): string[] {
56
+ if (!lum || (lum.bright === undefined && lum.contrast === undefined)) {
57
+ return [];
58
+ }
59
+ const bright = clamp((lum.bright ?? 0) / 100000, -1, 1);
60
+ const contrast = clamp((lum.contrast ?? 0) / 100000, -1, 1);
61
+ const parts: string[] = [];
62
+ if (lum.bright !== undefined) {
63
+ // OOXML luminance bright is closer to an additive wash than a raw CSS
64
+ // brightness multiplier. CSS cannot express that affine transform in a
65
+ // single filter, so we keep the Word-like bright wash and pair it with
66
+ // contrast/saturation compensation below.
67
+ if (Math.abs(bright) >= 0.0005) {
68
+ parts.push(`brightness(${Math.max(0, 1 + bright).toFixed(3)})`);
69
+ }
70
+ }
71
+ if (lum.contrast !== undefined) {
72
+ const cssContrast = contrast < 0
73
+ ? Math.max(0, 1 + contrast * 0.928571)
74
+ : 1 + contrast;
75
+ if (Math.abs(cssContrast - 1) >= 0.0005) {
76
+ parts.unshift(`contrast(${cssContrast.toFixed(3)})`);
77
+ }
78
+ }
79
+ if (bright > 0 && contrast < 0) {
80
+ const cssSaturate = 1 + bright * Math.abs(contrast) * 0.1;
81
+ if (Math.abs(cssSaturate - 1) >= 0.0005) {
82
+ parts.push(`saturate(${cssSaturate.toFixed(3)})`);
83
+ }
84
+ }
85
+ return parts;
86
+ }
87
+
88
+ function safeFilterHexColor(raw: string | null | undefined): string {
89
+ return typeof raw === "string" && /^[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?$/.test(raw)
90
+ ? `#${raw.toUpperCase()}`
91
+ : "";
92
+ }
93
+
94
+ function clamp(value: number, min: number, max: number): number {
95
+ return Math.min(max, Math.max(min, value));
96
+ }