Skip to content

Commit 941bf82

Browse files
committed
Update fixtures
1 parent f5f551c commit 941bf82

16 files changed

+84
-45
lines changed

.api-report/mafs.api.md

+23-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
55
```ts
66

7-
/// <reference types="react" />
8-
97
import { JSX as JSX_2 } from 'react/jsx-runtime';
108
import { KatexOptions } from 'katex';
119
import * as React_2 from 'react';
@@ -82,6 +80,29 @@ export interface Filled {
8280
weight?: number;
8381
}
8482

83+
// @public (undocumented)
84+
function Image_2({ href, x, y, width, height, anchor, preserveAspectRatio, svgImageProps, }: ImageProps): JSX_2.Element;
85+
export { Image_2 as Image }
86+
87+
// @public (undocumented)
88+
export interface ImageProps {
89+
// Warning: (ae-forgotten-export) The symbol "Anchor" needs to be exported by the entry point index.d.ts
90+
anchor?: Anchor;
91+
// (undocumented)
92+
height: number;
93+
// (undocumented)
94+
href: string;
95+
preserveAspectRatio?: string;
96+
// (undocumented)
97+
svgImageProps?: React.SVGProps<SVGImageElement>;
98+
// (undocumented)
99+
width: number;
100+
// (undocumented)
101+
x: number;
102+
// (undocumented)
103+
y: number;
104+
}
105+
85106
// @public (undocumented)
86107
export type Interval = [min: number, max: number];
87108

docs/components/guide-examples/display/images/ImageAnchorExample.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,39 @@ import {
77
useMovablePoint,
88
} from "mafs"
99

10-
import mafs from "./mafs.png"
10+
import image from "./mafs.png"
1111

1212
export default function VectorExample() {
1313
const center = useMovablePoint([2, 2])
1414
return (
1515
<Mafs viewBox={{ x: [-1, 7], y: [-1, 5] }}>
1616
<Coordinates.Cartesian />
1717
<Image
18-
src={mafs.src}
18+
href={image.src ?? image}
1919
anchor="tl"
2020
x={center.x + 0.1}
2121
y={center.y - 0.1}
2222
width={1}
2323
height={1}
2424
/>
2525
<Image
26-
src={mafs.src}
26+
href={image.src ?? image}
2727
anchor="tr"
2828
x={center.x - 0.1}
2929
y={center.y - 0.1}
3030
width={1}
3131
height={1}
3232
/>
3333
<Image
34-
src={mafs.src}
34+
href={image.src ?? image}
3535
anchor="bl"
3636
x={center.x + 0.1}
3737
y={center.y + 0.1}
3838
width={1}
3939
height={1}
4040
/>
4141
<Image
42-
src={mafs.src}
42+
href={image.src ?? image}
4343
anchor="br"
4444
x={center.x - 0.1}
4545
y={center.y + 0.1}

docs/components/guide-examples/display/images/ImageExample.tsx

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
import {
44
Coordinates,
5-
Debug,
65
Image,
76
Mafs,
87
useMovablePoint,
98
} from "mafs"
109

11-
import mafs from "./mafs.png"
10+
import image from "./mafs.png"
1211

1312
export default function ImageExample() {
1413
const origin = useMovablePoint([3, 3])
@@ -18,31 +17,31 @@ export default function ImageExample() {
1817
<Mafs viewBox={{ x: [-1, 7], y: [-1, 5] }}>
1918
<Coordinates.Cartesian />
2019
<Image
21-
src={mafs.src}
20+
href={image.src ?? image}
2221
anchor="tl"
2322
x={origin.x + padding}
2423
y={origin.y - padding}
2524
width={2}
2625
height={2}
2726
/>
2827
<Image
29-
src={mafs.src}
28+
href={image.src ?? image}
3029
anchor="tr"
3130
x={origin.x - padding}
3231
y={origin.y - padding}
3332
width={2}
3433
height={2}
3534
/>
3635
<Image
37-
src={mafs.src}
36+
href={image.src ?? image}
3837
anchor="bl"
3938
x={origin.x + padding}
4039
y={origin.y + padding}
4140
width={2}
4241
height={2}
4342
/>
4443
<Image
45-
src={mafs.src}
44+
href={image.src ?? image}
4645
anchor="br"
4746
x={origin.x - padding}
4847
y={origin.y + padding}

e2e/generated-vrt.spec.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import SimpleTransform from "../docs/components/guide-examples/utility/SimpleTra
4141
import CartesianCoordinatesConfigExample from "../docs/components/guide-examples/display/coordinates/CartesianCoordinatesConfigExample"
4242
import CartesianCoordinatesExample from "../docs/components/guide-examples/display/coordinates/CartesianCoordinatesExample"
4343
import PolarCoordinatesExample from "../docs/components/guide-examples/display/coordinates/PolarCoordinatesExample"
44+
import ImageAnchorExample from "../docs/components/guide-examples/display/images/ImageAnchorExample"
45+
import ImageExample from "../docs/components/guide-examples/display/images/ImageExample"
4446
import VectorExample from "../docs/components/guide-examples/display/vectors/VectorExample"
4547
import ContainViewbox from "../docs/components/guide-examples/display/viewbox/ContainViewbox"
4648
import StretchViewbox from "../docs/components/guide-examples/display/viewbox/StretchViewbox"
@@ -381,6 +383,24 @@ test("guide-examples/display/coordinates/PolarCoordinatesExample", async ({ moun
381383
</TestContextProvider>,
382384
))
383385

386+
test("guide-examples/display/images/ImageAnchorExample", async ({ mount, page }) =>
387+
await visualTest(
388+
mount,
389+
page,
390+
<TestContextProvider value={{ overrideHeight: 500 }}>
391+
<ImageAnchorExample />
392+
</TestContextProvider>,
393+
))
394+
395+
test("guide-examples/display/images/ImageExample", async ({ mount, page }) =>
396+
await visualTest(
397+
mount,
398+
page,
399+
<TestContextProvider value={{ overrideHeight: 500 }}>
400+
<ImageExample />
401+
</TestContextProvider>,
402+
))
403+
384404
test("guide-examples/display/vectors/VectorExample", async ({ mount, page }) =>
385405
await visualTest(
386406
mount,

src/display/Image.tsx

+30-31
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
import { Anchor, computeAnchor } from "../math"
22

33
export interface ImageProps {
4-
src: string
4+
href: string
55
x: number
66
y: number
7+
/**
8+
* Indicate where, in the image (top, bottom, left, right, center), the x and
9+
* y coordinate refers to.
10+
*/
11+
anchor?: Anchor
712
width: number
813
height: number
9-
anchor?: Anchor
14+
/**
15+
* Whether to preserve the aspect ratio of the image. By default, the image
16+
* will be centered and scaled to fit the width and height. If you want to
17+
* squish the image to be the same shape as the box, set this to "none".
18+
*
19+
* This is passed directly to the `preserveAspectRatio` attribute of the SVG
20+
* `<image>` element.
21+
*
22+
* @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio
23+
*/
1024
preserveAspectRatio?: string
25+
1126
svgImageProps?: React.SVGProps<SVGImageElement>
1227
}
1328

1429
export function Image({
15-
src,
30+
href,
1631
x,
1732
y,
1833
width,
@@ -26,37 +41,21 @@ export function Image({
2641
const transform = [
2742
"var(--mafs-view-transform)",
2843
"var(--mafs-user-transform)",
29-
// Ensure the image is not upside down (since Mafs has the y-axis pointing,
30-
// while SVG has it pointing down)
44+
// Ensure the image is not upside down (since Mafs has the y-axis pointing
45+
// up, while SVG has it pointing down).
3146
"scaleY(-1)",
3247
].join(" ")
3348

34-
const debug = false
35-
3649
return (
37-
<>
38-
{debug && (
39-
<rect
40-
x={anchorX}
41-
y={-anchorY}
42-
width={width}
43-
height={height}
44-
fill="none"
45-
stroke="red"
46-
vectorEffect={"non-scaling-stroke"}
47-
style={{ transform }}
48-
/>
49-
)}
50-
<image
51-
href={src}
52-
x={anchorX}
53-
y={-anchorY}
54-
width={width}
55-
height={height}
56-
preserveAspectRatio={preserveAspectRatio}
57-
{...svgImageProps}
58-
style={{ transform }}
59-
/>
60-
</>
50+
<image
51+
href={href}
52+
x={anchorX}
53+
y={-anchorY}
54+
width={width}
55+
height={height}
56+
preserveAspectRatio={preserveAspectRatio}
57+
{...svgImageProps}
58+
style={{ transform }}
59+
/>
6160
)
6261
}

tests/frameworks/pnpm-lock.yaml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)