Skip to content

Commit 1c02ada

Browse files
authored
refactor(contracts): extract shared ImageHyperlink type (#2738)
1 parent e1f5bc6 commit 1c02ada

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

packages/layout-engine/contracts/src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ export type ImageLuminanceAdjustment = {
287287
contrast?: number;
288288
};
289289

290+
/** Hyperlink metadata from OOXML a:hlinkClick on a DrawingML image. */
291+
export type ImageHyperlink = { url: string; tooltip?: string };
292+
290293
/**
291294
* Inline image run for images that flow with text on the same line.
292295
* Unlike ImageBlock (anchored/floating images), ImageRun is part of the paragraph's run array
@@ -362,7 +365,7 @@ export type ImageRun = {
362365
grayscale?: boolean; // Apply grayscale filter to image
363366
lum?: ImageLuminanceAdjustment; // DrawingML luminance adjustment from a:lum
364367
/** Image hyperlink from OOXML a:hlinkClick. When set, clicking the image opens the URL. */
365-
hyperlink?: { url: string; tooltip?: string };
368+
hyperlink?: ImageHyperlink;
366369
};
367370

368371
export type BreakRun = {
@@ -638,7 +641,7 @@ export type ImageBlock = {
638641
flipH?: boolean; // Horizontal flip
639642
flipV?: boolean; // Vertical flip
640643
/** Image hyperlink from OOXML a:hlinkClick. When set, clicking the image opens the URL. */
641-
hyperlink?: { url: string; tooltip?: string };
644+
hyperlink?: ImageHyperlink;
642645
};
643646

644647
export type DrawingKind = 'image' | 'vectorShape' | 'shapeGroup' | 'chart';

packages/layout-engine/painters/dom/src/index.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { DomPainterOptions, DomPainterInput, PaintSnapshot } from './index.
55
import { resolveListMarkerGeometry } from '../../../../../shared/common/list-marker-utils.js';
66
import type {
77
FlowBlock,
8+
ImageHyperlink,
89
Measure,
910
Layout,
1011
Line,
@@ -7693,7 +7694,7 @@ describe('ImageFragment (block-level images)', () => {
76937694
});
76947695

76957696
describe('hyperlink (DrawingML a:hlinkClick)', () => {
7696-
const makePainter = (hyperlink?: { url: string; tooltip?: string }) => {
7697+
const makePainter = (hyperlink?: ImageHyperlink) => {
76977698
const block: FlowBlock = {
76987699
kind: 'image',
76997700
id: 'linked-img',

packages/layout-engine/painters/dom/src/renderer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
ImageBlock,
1515
ImageDrawing,
1616
ImageFragment,
17+
ImageHyperlink,
1718
ImageRun,
1819
Layout,
1920
Line,
@@ -3698,7 +3699,7 @@ export class DomPainter {
36983699
*/
36993700
private buildImageHyperlinkAnchor(
37003701
imageEl: HTMLElement,
3701-
hyperlink: { url: string; tooltip?: string } | undefined,
3702+
hyperlink: ImageHyperlink | undefined,
37023703
display: 'block' | 'inline-block',
37033704
): HTMLElement {
37043705
if (!hyperlink?.url || !this.doc) return imageEl;

packages/layout-engine/pm-adapter/src/utilities.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
DrawingBlock,
1111
DrawingContentSnapshot,
1212
ImageBlock,
13+
ImageHyperlink,
1314
ShapeGroupChild,
1415
ShapeGroupDrawing,
1516
ShapeGroupImageChild,
@@ -231,7 +232,7 @@ export const normalizeString = (value: unknown): string | undefined => {
231232
* `{ url, tooltip? }` shape used by ImageBlock and ImageRun. Empty or invalid
232233
* URLs are dropped, and tooltip text is trimmed before inclusion.
233234
*/
234-
export const readImageHyperlink = (value: unknown): { url: string; tooltip?: string } | undefined => {
235+
export const readImageHyperlink = (value: unknown): ImageHyperlink | undefined => {
235236
const hyperlink = isPlainObject(value) ? value : undefined;
236237
const url = normalizeString(hyperlink?.url);
237238
if (!url) {

packages/super-editor/src/editors/v1/extensions/types/node-attributes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
InlineNodeAttributes,
1515
ShapeNodeAttributes,
1616
} from '../../core/types/NodeCategories.js';
17-
import type { StructuredContentLockMode } from '@superdoc/contracts';
17+
import type { ImageHyperlink, StructuredContentLockMode } from '@superdoc/contracts';
1818

1919
// ============================================
2020
// SHARED TYPES
@@ -512,7 +512,7 @@ export interface ImageAttrs extends ShapeNodeAttributes {
512512
/** Decorative image flag. Maps to OOXML adec:decorative. */
513513
decorative?: boolean;
514514
/** Image hyperlink. Maps to OOXML pic:cNvPr > a:hlinkClick. */
515-
hyperlink?: { url: string; tooltip?: string } | null;
515+
hyperlink?: ImageHyperlink | null;
516516
}
517517

518518
// ============================================

0 commit comments

Comments
 (0)