@panneau/media 5.0.0-alpha.4 → 5.0.0-alpha.5
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/README.md +94 -7
- package/dist/ImageItem.d.ts +23 -0
- package/dist/ImageItem.d.ts.map +1 -0
- package/dist/ImageItem.js +292 -0
- package/dist/ImageItem.js.map +1 -0
- package/dist/MediaField.css +109 -0
- package/dist/MediaField.d.ts +67 -15
- package/dist/MediaField.d.ts.map +1 -1
- package/dist/MediaField.js +340 -144
- package/dist/MediaField.js.map +1 -1
- package/dist/MediaField.module.js +24 -2
- package/dist/MediaField.module.js.map +1 -1
- package/dist/editor/ImageEditor.css +369 -0
- package/dist/editor/ImageEditor.d.ts +13 -0
- package/dist/editor/ImageEditor.d.ts.map +1 -0
- package/dist/editor/ImageEditor.js +461 -0
- package/dist/editor/ImageEditor.js.map +1 -0
- package/dist/editor/ImageEditor.module.js +86 -0
- package/dist/editor/ImageEditor.module.js.map +1 -0
- package/dist/editor/draw.d.ts +37 -0
- package/dist/editor/draw.d.ts.map +1 -0
- package/dist/editor/draw.js +93 -0
- package/dist/editor/draw.js.map +1 -0
- package/dist/editor/geometry.d.ts +54 -0
- package/dist/editor/geometry.d.ts.map +1 -0
- package/dist/editor/geometry.js +227 -0
- package/dist/editor/geometry.js.map +1 -0
- package/dist/editor/index.d.ts +5 -0
- package/dist/editor/index.d.ts.map +1 -0
- package/dist/editor/index.js +3 -0
- package/dist/editor/tools.d.ts +11 -0
- package/dist/editor/tools.d.ts.map +1 -0
- package/dist/editor/tools.js +1199 -0
- package/dist/editor/tools.js.map +1 -0
- package/dist/editor/types.d.ts +111 -0
- package/dist/editor/types.d.ts.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/picker/MediaDetails.d.ts +22 -0
- package/dist/picker/MediaDetails.d.ts.map +1 -0
- package/dist/picker/MediaDetails.js +368 -0
- package/dist/picker/MediaDetails.js.map +1 -0
- package/dist/picker/MediaGrid.d.ts +30 -0
- package/dist/picker/MediaGrid.d.ts.map +1 -0
- package/dist/picker/MediaGrid.js +260 -0
- package/dist/picker/MediaGrid.js.map +1 -0
- package/dist/picker/MediaPicker.css +642 -0
- package/dist/picker/MediaPicker.d.ts +9 -0
- package/dist/picker/MediaPicker.d.ts.map +1 -0
- package/dist/picker/MediaPicker.js +601 -0
- package/dist/picker/MediaPicker.js.map +1 -0
- package/dist/picker/MediaPicker.module.js +132 -0
- package/dist/picker/MediaPicker.module.js.map +1 -0
- package/dist/picker/PickerToolbar.d.ts +19 -0
- package/dist/picker/PickerToolbar.d.ts.map +1 -0
- package/dist/picker/PickerToolbar.js +266 -0
- package/dist/picker/PickerToolbar.js.map +1 -0
- package/dist/picker/UploadPanel.d.ts +22 -0
- package/dist/picker/UploadPanel.d.ts.map +1 -0
- package/dist/picker/UploadPanel.js +186 -0
- package/dist/picker/UploadPanel.js.map +1 -0
- package/dist/picker/format.d.ts +18 -0
- package/dist/picker/format.d.ts.map +1 -0
- package/dist/picker/format.js +61 -0
- package/dist/picker/format.js.map +1 -0
- package/dist/picker/index.d.ts +3 -0
- package/dist/picker/index.d.ts.map +1 -0
- package/dist/picker/index.js +1 -0
- package/dist/picker/types.d.ts +119 -0
- package/dist/picker/types.d.ts.map +1 -0
- package/dist/picker/useMediaBrowser.d.ts +50 -0
- package/dist/picker/useMediaBrowser.d.ts.map +1 -0
- package/dist/picker/useMediaBrowser.js +314 -0
- package/dist/picker/useMediaBrowser.js.map +1 -0
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +5 -2
- package/dist/plugin.js.map +1 -1
- package/dist/resourceSource.d.ts +21 -0
- package/dist/resourceSource.d.ts.map +1 -0
- package/dist/resourceSource.js +99 -0
- package/dist/resourceSource.js.map +1 -0
- package/package.json +18 -7
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { cropInView, sameEdits, svgTransform } from "./geometry.js";
|
|
2
|
+
import { matchesRatio } from "@panneau/protocol/runtime";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/editor/draw.tsx
|
|
5
|
+
var viewBox = (rect) => `${String(rect.x)} ${String(rect.y)} ${String(rect.width)} ${String(rect.height)}`;
|
|
6
|
+
/** The media's own transform, or null when it has no edits. */
|
|
7
|
+
function ownTransform(image) {
|
|
8
|
+
const own = image.mediaTransform;
|
|
9
|
+
return own !== null && own !== void 0 && !sameEdits(own, {}) ? own : null;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The image a transform applies to, drawn in its own pixels: the original, or the media's version
|
|
13
|
+
* (its own crop, rotation and flips), drawn in a nested viewport.
|
|
14
|
+
*/
|
|
15
|
+
function drawBase(image, base) {
|
|
16
|
+
const original = /* @__PURE__ */ jsx("image", {
|
|
17
|
+
href: image.url,
|
|
18
|
+
width: image.width,
|
|
19
|
+
height: image.height
|
|
20
|
+
});
|
|
21
|
+
const own = ownTransform(image);
|
|
22
|
+
if (base !== "media" || own === null) return {
|
|
23
|
+
size: {
|
|
24
|
+
width: image.width,
|
|
25
|
+
height: image.height
|
|
26
|
+
},
|
|
27
|
+
drawing: original
|
|
28
|
+
};
|
|
29
|
+
const version = cropInView(image, own);
|
|
30
|
+
return {
|
|
31
|
+
size: {
|
|
32
|
+
width: version.width,
|
|
33
|
+
height: version.height
|
|
34
|
+
},
|
|
35
|
+
drawing: /* @__PURE__ */ jsx("svg", {
|
|
36
|
+
width: version.width,
|
|
37
|
+
height: version.height,
|
|
38
|
+
viewBox: viewBox(version),
|
|
39
|
+
children: /* @__PURE__ */ jsx("g", {
|
|
40
|
+
transform: svgTransform(image, own),
|
|
41
|
+
children: original
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* How an image is rendered for one use: with its transform for this use, from its base, or as its
|
|
48
|
+
* library renders it without one.
|
|
49
|
+
*/
|
|
50
|
+
function renderedImage(image, transform) {
|
|
51
|
+
const { base: _base, baseTransform: _baseTransform, ...edits } = transform ?? {};
|
|
52
|
+
const { size, drawing } = drawBase(image, transform === null || transform === void 0 || transform.base === "media" ? "media" : "original");
|
|
53
|
+
return {
|
|
54
|
+
crop: cropInView(size, edits),
|
|
55
|
+
drawing: /* @__PURE__ */ jsx("g", {
|
|
56
|
+
transform: svgTransform(size, edits),
|
|
57
|
+
children: drawing
|
|
58
|
+
})
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** An image as it is rendered for one use, computed in the browser (decision 0031). */
|
|
62
|
+
function TransformedImage({ image, transform, alt, fit = "meet", className }) {
|
|
63
|
+
const { crop, drawing } = renderedImage(image, transform);
|
|
64
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
65
|
+
...alt === "" ? { "aria-hidden": true } : {
|
|
66
|
+
role: "img",
|
|
67
|
+
"aria-label": alt
|
|
68
|
+
},
|
|
69
|
+
viewBox: viewBox(crop),
|
|
70
|
+
preserveAspectRatio: `xMidYMid ${fit}`,
|
|
71
|
+
className,
|
|
72
|
+
children: drawing
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/** A ratio as text: `16:9`, or `1.85:1` when it isn't a common one. */
|
|
76
|
+
function ratioLabel(width, height) {
|
|
77
|
+
return [
|
|
78
|
+
"1:1",
|
|
79
|
+
"16:9",
|
|
80
|
+
"9:16",
|
|
81
|
+
"4:3",
|
|
82
|
+
"3:4",
|
|
83
|
+
"3:2",
|
|
84
|
+
"2:3",
|
|
85
|
+
"4:5",
|
|
86
|
+
"5:4",
|
|
87
|
+
"21:9"
|
|
88
|
+
].find((ratio) => matchesRatio(width, height, ratio)) ?? `${(width / height).toFixed(2)}:1`;
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { TransformedImage, drawBase, ownTransform, ratioLabel, renderedImage, viewBox };
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=draw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draw.js","names":[],"sources":["../../src/editor/draw.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport type { MediaTransform } from '@panneau/protocol';\nimport { matchesRatio } from '@panneau/protocol/runtime';\n\nimport { type Rect, type Size, cropInView, sameEdits, svgTransform } from './geometry';\nimport type { EditedImage, TransformBase } from './types';\n\nexport const viewBox = (rect: Rect) =>\n `${String(rect.x)} ${String(rect.y)} ${String(rect.width)} ${String(rect.height)}`;\n\n/** The media's own transform, or null when it has no edits. */\nexport function ownTransform(image: EditedImage): MediaTransform | null {\n const own = image.mediaTransform;\n return own !== null && own !== undefined && !sameEdits(own, {}) ? own : null;\n}\n\n/**\n * The image a transform applies to, drawn in its own pixels: the original, or the media's version\n * (its own crop, rotation and flips), drawn in a nested viewport.\n */\nexport function drawBase(\n image: EditedImage,\n base: TransformBase,\n): { size: Size; drawing: ReactNode } {\n const original = <image href={image.url} width={image.width} height={image.height} />;\n const own = ownTransform(image);\n if (base !== 'media' || own === null) {\n return { size: { width: image.width, height: image.height }, drawing: original };\n }\n const version = cropInView(image, own);\n return {\n size: { width: version.width, height: version.height },\n drawing: (\n <svg width={version.width} height={version.height} viewBox={viewBox(version)}>\n <g transform={svgTransform(image, own)}>{original}</g>\n </svg>\n ),\n };\n}\n\n/**\n * How an image is rendered for one use: with its transform for this use, from its base, or as its\n * library renders it without one.\n */\nexport function renderedImage(\n image: EditedImage,\n transform: MediaTransform | null | undefined,\n): { crop: Rect; drawing: ReactNode } {\n const { base: _base, baseTransform: _baseTransform, ...edits } = transform ?? {};\n const base: TransformBase =\n transform === null || transform === undefined || transform.base === 'media'\n ? 'media'\n : 'original';\n const { size, drawing } = drawBase(image, base);\n return {\n crop: cropInView(size, edits),\n drawing: <g transform={svgTransform(size, edits)}>{drawing}</g>,\n };\n}\n\nexport interface TransformedImageProps {\n image: EditedImage;\n transform?: MediaTransform | null;\n /** Its text alternative: empty for a decorative image. */\n alt: string;\n /** `slice` fills its box, as a thumbnail does. */\n fit?: 'meet' | 'slice';\n className?: string;\n}\n\n/** An image as it is rendered for one use, computed in the browser (decision 0031). */\nexport function TransformedImage({\n image,\n transform,\n alt,\n fit = 'meet',\n className,\n}: TransformedImageProps) {\n const { crop, drawing } = renderedImage(image, transform);\n return (\n <svg\n {...(alt === '' ? { 'aria-hidden': true } : { role: 'img', 'aria-label': alt })}\n viewBox={viewBox(crop)}\n preserveAspectRatio={`xMidYMid ${fit}`}\n className={className}\n >\n {drawing}\n </svg>\n );\n}\n\n/** A ratio as text: `16:9`, or `1.85:1` when it isn't a common one. */\nexport function ratioLabel(width: number, height: number): string {\n const common = ['1:1', '16:9', '9:16', '4:3', '3:4', '3:2', '2:3', '4:5', '5:4', '21:9'];\n return (\n common.find((ratio) => matchesRatio(width, height, ratio)) ??\n `${(width / height).toFixed(2)}:1`\n );\n}\n"],"mappings":";;;;AAQA,IAAa,WAAW,SACpB,GAAG,OAAO,KAAK,CAAC,EAAC,GAAI,OAAO,KAAK,CAAC,EAAC,GAAI,OAAO,KAAK,KAAK,EAAC,GAAI,OAAO,KAAK,MAAM;;AAGnF,SAAgB,aAAa,OAA2C;CACpE,MAAM,MAAM,MAAM;CAClB,OAAO,QAAQ,QAAQ,QAAQ,KAAA,KAAa,CAAC,UAAU,KAAK,CAAC,CAAC,IAAI,MAAM;AAC5E;;;;;AAMA,SAAgB,SACZ,OACA,MACkC;CAClC,MAAM,WAAW,oBAAC,SAAD;EAAO,MAAM,MAAM;EAAK,OAAO,MAAM;EAAO,QAAQ,MAAM;CAAO,CAAA;CAClF,MAAM,MAAM,aAAa,KAAK;CAC9B,IAAI,SAAS,WAAW,QAAQ,MAC5B,OAAO;EAAE,MAAM;GAAE,OAAO,MAAM;GAAO,QAAQ,MAAM;EAAO;EAAG,SAAS;CAAS;CAEnF,MAAM,UAAU,WAAW,OAAO,GAAG;CACrC,OAAO;EACH,MAAM;GAAE,OAAO,QAAQ;GAAO,QAAQ,QAAQ;EAAO;EACrD,SACI,oBAAC,OAAD;GAAK,OAAO,QAAQ;GAAO,QAAQ,QAAQ;GAAQ,SAAS,QAAQ,OAAO;GACvE,UAAA,oBAAC,KAAD;IAAG,WAAW,aAAa,OAAO,GAAG;IAAI,UAAA;GAAY,CAAA;EACpD,CAAA;CAEb;AACJ;;;;;AAMA,SAAgB,cACZ,OACA,WACkC;CAClC,MAAM,EAAE,MAAM,OAAO,eAAe,gBAAgB,GAAG,UAAU,aAAa,CAAC;CAK/E,MAAM,EAAE,MAAM,YAAY,SAAS,OAH/B,cAAc,QAAQ,cAAc,KAAA,KAAa,UAAU,SAAS,UAC9D,UACA,UACoC;CAC9C,OAAO;EACH,MAAM,WAAW,MAAM,KAAK;EAC5B,SAAS,oBAAC,KAAD;GAAG,WAAW,aAAa,MAAM,KAAK;GAAI,UAAA;EAAW,CAAA;CAClE;AACJ;;AAaA,SAAgB,iBAAiB,EAC7B,OACA,WACA,KACA,MAAM,QACN,aACsB;CACtB,MAAM,EAAE,MAAM,YAAY,cAAc,OAAO,SAAS;CACxD,OACI,oBAAC,OAAD;EACI,GAAK,QAAQ,KAAK,EAAE,eAAe,KAAK,IAAI;GAAE,MAAM;GAAO,cAAc;EAAI;EAC7E,SAAS,QAAQ,IAAI;EACrB,qBAAqB,YAAY;EACtB;EAEV,UAAA;CACA,CAAA;AAEb;;AAGA,SAAgB,WAAW,OAAe,QAAwB;CAE9D,OACI;EAFY;EAAO;EAAQ;EAAQ;EAAO;EAAO;EAAO;EAAO;EAAO;EAAO;CAE7E,CAAA,CAAO,MAAM,UAAU,aAAa,OAAO,QAAQ,KAAK,CAAC,KACzD,IAAI,QAAQ,OAAA,CAAQ,QAAQ,CAAC,EAAC;AAEtC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { MediaTransform } from '@panneau/protocol';
|
|
2
|
+
/**
|
|
3
|
+
* The geometry of the protocol's `MediaTransform`: a crop in pixels of the upright image, then a
|
|
4
|
+
* clockwise rotation, then flips. The editor shows the image as it will be rendered (rotated and
|
|
5
|
+
* flipped), the view, and converts between it and the pixels of the image.
|
|
6
|
+
*/
|
|
7
|
+
export type Size = {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
export type Point = {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
};
|
|
15
|
+
export type Rect = Point & Size;
|
|
16
|
+
export type Rotation = 0 | 90 | 180 | 270;
|
|
17
|
+
/** The edits the geometry reads: those of the protocol, without the base. */
|
|
18
|
+
export type Edits = Pick<MediaTransform, 'crop' | 'rotate' | 'flipX' | 'flipY' | 'focalPoint'>;
|
|
19
|
+
/** The size of an image once rotated. */
|
|
20
|
+
export declare function viewSize(size: Size, rotate?: Rotation): Size;
|
|
21
|
+
/** A point of the image, in the view: rotated, then flipped. */
|
|
22
|
+
export declare function toView(point: Point, size: Size, edits: Edits): Point;
|
|
23
|
+
/** A point of the view, in the image. */
|
|
24
|
+
export declare function fromView(point: Point, size: Size, edits: Edits): Point;
|
|
25
|
+
/** A rectangle of the image, in the view. */
|
|
26
|
+
export declare function rectToView(rect: Rect, size: Size, edits: Edits): Rect;
|
|
27
|
+
/** A rectangle of the view, in whole pixels of the image, as the protocol stores a crop. */
|
|
28
|
+
export declare function rectFromView(rect: Rect, size: Size, edits: Edits): Rect;
|
|
29
|
+
/** The crop of the edits, in the view: the whole image without one. */
|
|
30
|
+
export declare function cropInView(size: Size, edits: Edits): Rect;
|
|
31
|
+
/** The SVG transform that draws the image as the view shows it. */
|
|
32
|
+
export declare function svgTransform({ width, height }: Size, edits: Edits): string;
|
|
33
|
+
/** The focal point in the view, in pixels: the center of the image without one. */
|
|
34
|
+
export declare function focalInView(size: Size, edits: Edits): Point;
|
|
35
|
+
/** A point of the view as a focal point: from 0 to 1, relative to the image. */
|
|
36
|
+
export declare function focalFromView(point: Point, size: Size, edits: Edits): Point;
|
|
37
|
+
/** The largest crop of a ratio inside a rectangle, centered on a point as far as it can be. */
|
|
38
|
+
export declare function cropAround(within: Rect, ratio: number, center: Point): Rect;
|
|
39
|
+
/**
|
|
40
|
+
* A crop inside an image, for a crop made on another version of it (decision 0031): what falls
|
|
41
|
+
* outside is cut off, and a crop wholly outside is dropped.
|
|
42
|
+
*/
|
|
43
|
+
export declare function clampCrop(crop: Rect, size: Size): Rect | null;
|
|
44
|
+
/** Moves a rectangle within bounds. */
|
|
45
|
+
export declare function moveRect(rect: Rect, dx: number, dy: number, bounds: Size): Rect;
|
|
46
|
+
/** A corner or an edge of a crop frame. */
|
|
47
|
+
export type Handle = 'nw' | 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w';
|
|
48
|
+
/** Moves the edges of a rectangle that a handle holds, within bounds, keeping a ratio if any. */
|
|
49
|
+
export declare function resizeRect(rect: Rect, handle: Handle, dx: number, dy: number, ratio: number | null, bounds: Size): Rect;
|
|
50
|
+
/** Where a handle sits on a rectangle. */
|
|
51
|
+
export declare function handlePoint(rect: Rect, handle: Handle): Point;
|
|
52
|
+
/** Whether two transforms have the same edits, whatever the order of their keys. */
|
|
53
|
+
export declare function sameEdits(a: Edits | null | undefined, b: Edits | null | undefined): boolean;
|
|
54
|
+
//# sourceMappingURL=geometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../src/editor/geometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD;;;;GAIG;AAGH,MAAM,MAAM,IAAI,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAErD,MAAM,MAAM,KAAK,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7C,MAAM,MAAM,IAAI,GAAG,KAAK,GAAG,IAAI,CAAC;AAEhC,MAAM,MAAM,QAAQ,GAAG,CAA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,KAAK,CAI3E;AAED,+FAA+F;AAC/F,wBAAgB,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,GAAG,IAAI,CAS3E;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAM7D;AAED,uCAAuC;AACvC,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,GAAG,IAAI,CAM/E;AAED,2CAA2C;AAC3C,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,CAAC;AAEvE,iGAAiG;AACjG,wBAAgB,UAAU,CACtB,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,MAAM,EAAE,IAAI,GACb,IAAI,CAwCN;AAED,0CAA0C;AAC1C,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,CAY7D;AAED,oFAAoF;AACpF,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,SAAS,EAAE,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAY3F"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
//#region src/editor/geometry.ts
|
|
2
|
+
var clamp = (value, min, max) => Math.min(Math.max(value, min), max);
|
|
3
|
+
/** The size of an image once rotated. */
|
|
4
|
+
function viewSize(size, rotate = 0) {
|
|
5
|
+
return rotate === 90 || rotate === 270 ? {
|
|
6
|
+
width: size.height,
|
|
7
|
+
height: size.width
|
|
8
|
+
} : {
|
|
9
|
+
width: size.width,
|
|
10
|
+
height: size.height
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function rotatePoint({ x, y }, { width, height }, rotate) {
|
|
14
|
+
switch (rotate) {
|
|
15
|
+
case 90: return {
|
|
16
|
+
x: height - y,
|
|
17
|
+
y: x
|
|
18
|
+
};
|
|
19
|
+
case 180: return {
|
|
20
|
+
x: width - x,
|
|
21
|
+
y: height - y
|
|
22
|
+
};
|
|
23
|
+
case 270: return {
|
|
24
|
+
x: y,
|
|
25
|
+
y: width - x
|
|
26
|
+
};
|
|
27
|
+
default: return {
|
|
28
|
+
x,
|
|
29
|
+
y
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** A point of the image, in the view: rotated, then flipped. */
|
|
34
|
+
function toView(point, size, edits) {
|
|
35
|
+
const view = viewSize(size, edits.rotate);
|
|
36
|
+
const rotated = rotatePoint(point, size, edits.rotate ?? 0);
|
|
37
|
+
return {
|
|
38
|
+
x: edits.flipX === true ? view.width - rotated.x : rotated.x,
|
|
39
|
+
y: edits.flipY === true ? view.height - rotated.y : rotated.y
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** A point of the view, in the image. */
|
|
43
|
+
function fromView(point, size, edits) {
|
|
44
|
+
const view = viewSize(size, edits.rotate);
|
|
45
|
+
return rotatePoint({
|
|
46
|
+
x: edits.flipX === true ? view.width - point.x : point.x,
|
|
47
|
+
y: edits.flipY === true ? view.height - point.y : point.y
|
|
48
|
+
}, view, (360 - (edits.rotate ?? 0)) % 360);
|
|
49
|
+
}
|
|
50
|
+
function rectBetween(a, b) {
|
|
51
|
+
return {
|
|
52
|
+
x: Math.min(a.x, b.x),
|
|
53
|
+
y: Math.min(a.y, b.y),
|
|
54
|
+
width: Math.abs(a.x - b.x),
|
|
55
|
+
height: Math.abs(a.y - b.y)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** A rectangle of the image, in the view. */
|
|
59
|
+
function rectToView(rect, size, edits) {
|
|
60
|
+
return rectBetween(toView(rect, size, edits), toView({
|
|
61
|
+
x: rect.x + rect.width,
|
|
62
|
+
y: rect.y + rect.height
|
|
63
|
+
}, size, edits));
|
|
64
|
+
}
|
|
65
|
+
/** A rectangle of the view, in whole pixels of the image, as the protocol stores a crop. */
|
|
66
|
+
function rectFromView(rect, size, edits) {
|
|
67
|
+
const found = rectBetween(fromView(rect, size, edits), fromView({
|
|
68
|
+
x: rect.x + rect.width,
|
|
69
|
+
y: rect.y + rect.height
|
|
70
|
+
}, size, edits));
|
|
71
|
+
const x = clamp(Math.round(found.x), 0, size.width - 1);
|
|
72
|
+
const y = clamp(Math.round(found.y), 0, size.height - 1);
|
|
73
|
+
return {
|
|
74
|
+
x,
|
|
75
|
+
y,
|
|
76
|
+
width: clamp(Math.round(found.width), 1, size.width - x),
|
|
77
|
+
height: clamp(Math.round(found.height), 1, size.height - y)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** The crop of the edits, in the view: the whole image without one. */
|
|
81
|
+
function cropInView(size, edits) {
|
|
82
|
+
return rectToView(edits.crop ?? {
|
|
83
|
+
x: 0,
|
|
84
|
+
y: 0,
|
|
85
|
+
width: size.width,
|
|
86
|
+
height: size.height
|
|
87
|
+
}, size, edits);
|
|
88
|
+
}
|
|
89
|
+
/** The SVG transform that draws the image as the view shows it. */
|
|
90
|
+
function svgTransform({ width, height }, edits) {
|
|
91
|
+
const view = viewSize({
|
|
92
|
+
width,
|
|
93
|
+
height
|
|
94
|
+
}, edits.rotate);
|
|
95
|
+
const parts = [];
|
|
96
|
+
if (edits.flipX === true) parts.push(`translate(${String(view.width)} 0) scale(-1 1)`);
|
|
97
|
+
if (edits.flipY === true) parts.push(`translate(0 ${String(view.height)}) scale(1 -1)`);
|
|
98
|
+
switch (edits.rotate) {
|
|
99
|
+
case 90:
|
|
100
|
+
parts.push(`translate(${String(height)} 0) rotate(90)`);
|
|
101
|
+
break;
|
|
102
|
+
case 180:
|
|
103
|
+
parts.push(`translate(${String(width)} ${String(height)}) rotate(180)`);
|
|
104
|
+
break;
|
|
105
|
+
case 270: parts.push(`translate(0 ${String(width)}) rotate(270)`);
|
|
106
|
+
}
|
|
107
|
+
return parts.join(" ");
|
|
108
|
+
}
|
|
109
|
+
/** The focal point in the view, in pixels: the center of the image without one. */
|
|
110
|
+
function focalInView(size, edits) {
|
|
111
|
+
const focal = edits.focalPoint ?? {
|
|
112
|
+
x: .5,
|
|
113
|
+
y: .5
|
|
114
|
+
};
|
|
115
|
+
return toView({
|
|
116
|
+
x: focal.x * size.width,
|
|
117
|
+
y: focal.y * size.height
|
|
118
|
+
}, size, edits);
|
|
119
|
+
}
|
|
120
|
+
/** A point of the view as a focal point: from 0 to 1, relative to the image. */
|
|
121
|
+
function focalFromView(point, size, edits) {
|
|
122
|
+
const found = fromView(point, size, edits);
|
|
123
|
+
const round = (value) => Math.round(clamp(value, 0, 1) * 1e3) / 1e3;
|
|
124
|
+
return {
|
|
125
|
+
x: round(found.x / size.width),
|
|
126
|
+
y: round(found.y / size.height)
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/** The largest crop of a ratio inside a rectangle, centered on a point as far as it can be. */
|
|
130
|
+
function cropAround(within, ratio, center) {
|
|
131
|
+
const width = Math.min(within.width, within.height * ratio);
|
|
132
|
+
const height = width / ratio;
|
|
133
|
+
return {
|
|
134
|
+
x: clamp(center.x - width / 2, within.x, within.x + within.width - width),
|
|
135
|
+
y: clamp(center.y - height / 2, within.y, within.y + within.height - height),
|
|
136
|
+
width,
|
|
137
|
+
height
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* A crop inside an image, for a crop made on another version of it (decision 0031): what falls
|
|
142
|
+
* outside is cut off, and a crop wholly outside is dropped.
|
|
143
|
+
*/
|
|
144
|
+
function clampCrop(crop, size) {
|
|
145
|
+
const x = clamp(crop.x, 0, size.width);
|
|
146
|
+
const y = clamp(crop.y, 0, size.height);
|
|
147
|
+
const width = Math.min(crop.x + crop.width, size.width) - x;
|
|
148
|
+
const height = Math.min(crop.y + crop.height, size.height) - y;
|
|
149
|
+
return width >= 1 && height >= 1 ? {
|
|
150
|
+
x,
|
|
151
|
+
y,
|
|
152
|
+
width,
|
|
153
|
+
height
|
|
154
|
+
} : null;
|
|
155
|
+
}
|
|
156
|
+
/** Moves a rectangle within bounds. */
|
|
157
|
+
function moveRect(rect, dx, dy, bounds) {
|
|
158
|
+
return {
|
|
159
|
+
...rect,
|
|
160
|
+
x: clamp(rect.x + dx, 0, bounds.width - rect.width),
|
|
161
|
+
y: clamp(rect.y + dy, 0, bounds.height - rect.height)
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/** Moves the edges of a rectangle that a handle holds, within bounds, keeping a ratio if any. */
|
|
165
|
+
function resizeRect(rect, handle, dx, dy, ratio, bounds) {
|
|
166
|
+
const min = Math.min(bounds.width, bounds.height) * .05;
|
|
167
|
+
const west = handle.includes("w");
|
|
168
|
+
const north = handle.includes("n");
|
|
169
|
+
if (ratio !== null) {
|
|
170
|
+
const anchor = {
|
|
171
|
+
x: west ? rect.x + rect.width : rect.x,
|
|
172
|
+
y: north ? rect.y + rect.height : rect.y
|
|
173
|
+
};
|
|
174
|
+
const roomX = west ? anchor.x : bounds.width - anchor.x;
|
|
175
|
+
const roomY = north ? anchor.y : bounds.height - anchor.y;
|
|
176
|
+
const largest = Math.min(roomX, roomY * ratio);
|
|
177
|
+
const width = clamp(west ? rect.width - dx : rect.width + dx, Math.min(min, largest), largest);
|
|
178
|
+
const height = width / ratio;
|
|
179
|
+
return {
|
|
180
|
+
x: west ? anchor.x - width : anchor.x,
|
|
181
|
+
y: north ? anchor.y - height : anchor.y,
|
|
182
|
+
width,
|
|
183
|
+
height
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
let left = rect.x;
|
|
187
|
+
let right = rect.x + rect.width;
|
|
188
|
+
let top = rect.y;
|
|
189
|
+
let bottom = rect.y + rect.height;
|
|
190
|
+
if (west) left = clamp(left + dx, 0, right - min);
|
|
191
|
+
else if (handle.includes("e")) right = clamp(right + dx, left + min, bounds.width);
|
|
192
|
+
if (north) top = clamp(top + dy, 0, bottom - min);
|
|
193
|
+
else if (handle.includes("s")) bottom = clamp(bottom + dy, top + min, bounds.height);
|
|
194
|
+
return {
|
|
195
|
+
x: left,
|
|
196
|
+
y: top,
|
|
197
|
+
width: right - left,
|
|
198
|
+
height: bottom - top
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/** Where a handle sits on a rectangle. */
|
|
202
|
+
function handlePoint(rect, handle) {
|
|
203
|
+
return {
|
|
204
|
+
x: handle.includes("w") ? rect.x : handle.includes("e") ? rect.x + rect.width : rect.x + rect.width / 2,
|
|
205
|
+
y: handle.includes("n") ? rect.y : handle.includes("s") ? rect.y + rect.height : rect.y + rect.height / 2
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/** Whether two transforms have the same edits, whatever the order of their keys. */
|
|
209
|
+
function sameEdits(a, b) {
|
|
210
|
+
const normalized = (edits) => JSON.stringify({
|
|
211
|
+
crop: edits?.crop ? [
|
|
212
|
+
edits.crop.x,
|
|
213
|
+
edits.crop.y,
|
|
214
|
+
edits.crop.width,
|
|
215
|
+
edits.crop.height
|
|
216
|
+
] : null,
|
|
217
|
+
rotate: edits?.rotate ?? 0,
|
|
218
|
+
flipX: edits?.flipX === true,
|
|
219
|
+
flipY: edits?.flipY === true,
|
|
220
|
+
focalPoint: edits?.focalPoint ? [edits.focalPoint.x, edits.focalPoint.y] : null
|
|
221
|
+
});
|
|
222
|
+
return normalized(a) === normalized(b);
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
export { clampCrop, cropAround, cropInView, focalFromView, focalInView, fromView, handlePoint, moveRect, rectFromView, rectToView, resizeRect, sameEdits, svgTransform, toView, viewSize };
|
|
226
|
+
|
|
227
|
+
//# sourceMappingURL=geometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.js","names":[],"sources":["../../src/editor/geometry.ts"],"sourcesContent":["import type { MediaTransform } from '@panneau/protocol';\n\n/**\n * The geometry of the protocol's `MediaTransform`: a crop in pixels of the upright image, then a\n * clockwise rotation, then flips. The editor shows the image as it will be rendered (rotated and\n * flipped), the view, and converts between it and the pixels of the image.\n */\n\n// Type aliases rather than interfaces, so that they fit the protocol's loose objects.\nexport type Size = { width: number; height: number };\n\nexport type Point = { x: number; y: number };\n\nexport type Rect = Point & Size;\n\nexport type Rotation = 0 | 90 | 180 | 270;\n\n/** The edits the geometry reads: those of the protocol, without the base. */\nexport type Edits = Pick<MediaTransform, 'crop' | 'rotate' | 'flipX' | 'flipY' | 'focalPoint'>;\n\nconst clamp = (value: number, min: number, max: number) => Math.min(Math.max(value, min), max);\n\n/** The size of an image once rotated. */\nexport function viewSize(size: Size, rotate: Rotation = 0): Size {\n return rotate === 90 || rotate === 270\n ? { width: size.height, height: size.width }\n : { width: size.width, height: size.height };\n}\n\nfunction rotatePoint({ x, y }: Point, { width, height }: Size, rotate: Rotation): Point {\n switch (rotate) {\n case 90:\n return { x: height - y, y: x };\n case 180:\n return { x: width - x, y: height - y };\n case 270:\n return { x: y, y: width - x };\n default:\n return { x, y };\n }\n}\n\n/** A point of the image, in the view: rotated, then flipped. */\nexport function toView(point: Point, size: Size, edits: Edits): Point {\n const view = viewSize(size, edits.rotate);\n const rotated = rotatePoint(point, size, edits.rotate ?? 0);\n return {\n x: edits.flipX === true ? view.width - rotated.x : rotated.x,\n y: edits.flipY === true ? view.height - rotated.y : rotated.y,\n };\n}\n\n/** A point of the view, in the image. */\nexport function fromView(point: Point, size: Size, edits: Edits): Point {\n const view = viewSize(size, edits.rotate);\n const unflipped = {\n x: edits.flipX === true ? view.width - point.x : point.x,\n y: edits.flipY === true ? view.height - point.y : point.y,\n };\n return rotatePoint(unflipped, view, ((360 - (edits.rotate ?? 0)) % 360) as Rotation);\n}\n\nfunction rectBetween(a: Point, b: Point): Rect {\n return {\n x: Math.min(a.x, b.x),\n y: Math.min(a.y, b.y),\n width: Math.abs(a.x - b.x),\n height: Math.abs(a.y - b.y),\n };\n}\n\n/** A rectangle of the image, in the view. */\nexport function rectToView(rect: Rect, size: Size, edits: Edits): Rect {\n return rectBetween(\n toView(rect, size, edits),\n toView({ x: rect.x + rect.width, y: rect.y + rect.height }, size, edits),\n );\n}\n\n/** A rectangle of the view, in whole pixels of the image, as the protocol stores a crop. */\nexport function rectFromView(rect: Rect, size: Size, edits: Edits): Rect {\n const found = rectBetween(\n fromView(rect, size, edits),\n fromView({ x: rect.x + rect.width, y: rect.y + rect.height }, size, edits),\n );\n const x = clamp(Math.round(found.x), 0, size.width - 1);\n const y = clamp(Math.round(found.y), 0, size.height - 1);\n return {\n x,\n y,\n width: clamp(Math.round(found.width), 1, size.width - x),\n height: clamp(Math.round(found.height), 1, size.height - y),\n };\n}\n\n/** The crop of the edits, in the view: the whole image without one. */\nexport function cropInView(size: Size, edits: Edits): Rect {\n return rectToView(\n edits.crop ?? { x: 0, y: 0, width: size.width, height: size.height },\n size,\n edits,\n );\n}\n\n/** The SVG transform that draws the image as the view shows it. */\nexport function svgTransform({ width, height }: Size, edits: Edits): string {\n const view = viewSize({ width, height }, edits.rotate);\n const parts: string[] = [];\n if (edits.flipX === true) {\n parts.push(`translate(${String(view.width)} 0) scale(-1 1)`);\n }\n if (edits.flipY === true) {\n parts.push(`translate(0 ${String(view.height)}) scale(1 -1)`);\n }\n switch (edits.rotate) {\n case 90:\n parts.push(`translate(${String(height)} 0) rotate(90)`);\n break;\n case 180:\n parts.push(`translate(${String(width)} ${String(height)}) rotate(180)`);\n break;\n case 270:\n parts.push(`translate(0 ${String(width)}) rotate(270)`);\n break;\n default:\n break;\n }\n return parts.join(' ');\n}\n\n/** The focal point in the view, in pixels: the center of the image without one. */\nexport function focalInView(size: Size, edits: Edits): Point {\n const focal = edits.focalPoint ?? { x: 0.5, y: 0.5 };\n return toView({ x: focal.x * size.width, y: focal.y * size.height }, size, edits);\n}\n\n/** A point of the view as a focal point: from 0 to 1, relative to the image. */\nexport function focalFromView(point: Point, size: Size, edits: Edits): Point {\n const found = fromView(point, size, edits);\n const round = (value: number) => Math.round(clamp(value, 0, 1) * 1000) / 1000;\n return { x: round(found.x / size.width), y: round(found.y / size.height) };\n}\n\n/** The largest crop of a ratio inside a rectangle, centered on a point as far as it can be. */\nexport function cropAround(within: Rect, ratio: number, center: Point): Rect {\n const width = Math.min(within.width, within.height * ratio);\n const height = width / ratio;\n return {\n x: clamp(center.x - width / 2, within.x, within.x + within.width - width),\n y: clamp(center.y - height / 2, within.y, within.y + within.height - height),\n width,\n height,\n };\n}\n\n/**\n * A crop inside an image, for a crop made on another version of it (decision 0031): what falls\n * outside is cut off, and a crop wholly outside is dropped.\n */\nexport function clampCrop(crop: Rect, size: Size): Rect | null {\n const x = clamp(crop.x, 0, size.width);\n const y = clamp(crop.y, 0, size.height);\n const width = Math.min(crop.x + crop.width, size.width) - x;\n const height = Math.min(crop.y + crop.height, size.height) - y;\n return width >= 1 && height >= 1 ? { x, y, width, height } : null;\n}\n\n/** Moves a rectangle within bounds. */\nexport function moveRect(rect: Rect, dx: number, dy: number, bounds: Size): Rect {\n return {\n ...rect,\n x: clamp(rect.x + dx, 0, bounds.width - rect.width),\n y: clamp(rect.y + dy, 0, bounds.height - rect.height),\n };\n}\n\n/** A corner or an edge of a crop frame. */\nexport type Handle = 'nw' | 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w';\n\n/** Moves the edges of a rectangle that a handle holds, within bounds, keeping a ratio if any. */\nexport function resizeRect(\n rect: Rect,\n handle: Handle,\n dx: number,\n dy: number,\n ratio: number | null,\n bounds: Size,\n): Rect {\n const min = Math.min(bounds.width, bounds.height) * 0.05;\n const west = handle.includes('w');\n const north = handle.includes('n');\n if (ratio !== null) {\n const anchor = {\n x: west ? rect.x + rect.width : rect.x,\n y: north ? rect.y + rect.height : rect.y,\n };\n const roomX = west ? anchor.x : bounds.width - anchor.x;\n const roomY = north ? anchor.y : bounds.height - anchor.y;\n const largest = Math.min(roomX, roomY * ratio);\n const width = clamp(\n west ? rect.width - dx : rect.width + dx,\n Math.min(min, largest),\n largest,\n );\n const height = width / ratio;\n return {\n x: west ? anchor.x - width : anchor.x,\n y: north ? anchor.y - height : anchor.y,\n width,\n height,\n };\n }\n let left = rect.x;\n let right = rect.x + rect.width;\n let top = rect.y;\n let bottom = rect.y + rect.height;\n if (west) {\n left = clamp(left + dx, 0, right - min);\n } else if (handle.includes('e')) {\n right = clamp(right + dx, left + min, bounds.width);\n }\n if (north) {\n top = clamp(top + dy, 0, bottom - min);\n } else if (handle.includes('s')) {\n bottom = clamp(bottom + dy, top + min, bounds.height);\n }\n return { x: left, y: top, width: right - left, height: bottom - top };\n}\n\n/** Where a handle sits on a rectangle. */\nexport function handlePoint(rect: Rect, handle: Handle): Point {\n const x = handle.includes('w')\n ? rect.x\n : handle.includes('e')\n ? rect.x + rect.width\n : rect.x + rect.width / 2;\n const y = handle.includes('n')\n ? rect.y\n : handle.includes('s')\n ? rect.y + rect.height\n : rect.y + rect.height / 2;\n return { x, y };\n}\n\n/** Whether two transforms have the same edits, whatever the order of their keys. */\nexport function sameEdits(a: Edits | null | undefined, b: Edits | null | undefined): boolean {\n const normalized = (edits: Edits | null | undefined) =>\n JSON.stringify({\n crop: edits?.crop\n ? [edits.crop.x, edits.crop.y, edits.crop.width, edits.crop.height]\n : null,\n rotate: edits?.rotate ?? 0,\n flipX: edits?.flipX === true,\n flipY: edits?.flipY === true,\n focalPoint: edits?.focalPoint ? [edits.focalPoint.x, edits.focalPoint.y] : null,\n });\n return normalized(a) === normalized(b);\n}\n"],"mappings":";AAoBA,IAAM,SAAS,OAAe,KAAa,QAAgB,KAAK,IAAI,KAAK,IAAI,OAAO,GAAG,GAAG,GAAG;;AAG7F,SAAgB,SAAS,MAAY,SAAmB,GAAS;CAC7D,OAAO,WA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,IAAI,SAAS,KAAK,IAAI,KAAK;CAC3B,IAAI,MACA,OAAO,MAAM,OAAO,IAAI,GAAG,QAAQ,GAAG;MACnC,IAAI,OAAO,SAAS,GAAG,GAC1B,QAAQ,MAAM,QAAQ,IAAI,OAAO,KAAK,OAAO,KAAK;CAEtD,IAAI,OACA,MAAM,MAAM,MAAM,IAAI,GAAG,SAAS,GAAG;MAClC,IAAI,OAAO,SAAS,GAAG,GAC1B,SAAS,MAAM,SAAS,IAAI,MAAM,KAAK,OAAO,MAAM;CAExD,OAAO;EAAE,GAAG;EAAM,GAAG;EAAK,OAAO,QAAQ;EAAM,QAAQ,SAAS;CAAI;AACxE;;AAGA,SAAgB,YAAY,MAAY,QAAuB;CAW3D,OAAO;EAAE,GAVC,OAAO,SAAS,GAAG,IACvB,KAAK,IACL,OAAO,SAAS,GAAG,IACjB,KAAK,IAAI,KAAK,QACd,KAAK,IAAI,KAAK,QAAQ;EAMlB,GALF,OAAO,SAAS,GAAG,IACvB,KAAK,IACL,OAAO,SAAS,GAAG,IACjB,KAAK,IAAI,KAAK,SACd,KAAK,IAAI,KAAK,SAAS;CACjB;AAClB;;AAGA,SAAgB,UAAU,GAA6B,GAAsC;CACzF,MAAM,cAAc,UAChB,KAAK,UAAU;EACX,MAAM,OAAO,OACP;GAAC,MAAM,KAAK;GAAG,MAAM,KAAK;GAAG,MAAM,KAAK;GAAO,MAAM,KAAK;EAAM,IAChE;EACN,QAAQ,OAAO,UAAU;EACzB,OAAO,OAAO,UAAU;EACxB,OAAO,OAAO,UAAU;EACxB,YAAY,OAAO,aAAa,CAAC,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,IAAI;CAC/E,CAAC;CACL,OAAO,WAAW,CAAC,MAAM,WAAW,CAAC;AACzC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ImageEditor, ImageEditorDialog } from './ImageEditor';
|
|
2
|
+
export { useImageEditorTools } from './tools';
|
|
3
|
+
export type { EditedImage, ImageEditorDialogProps, ImageEditorProps, ImageEditorTool, ImageEditorToolContext, TransformBase, } from './types';
|
|
4
|
+
export type { Point, Rect, Size } from './geometry';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/editor/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9C,YAAY,EACR,WAAW,EACX,sBAAsB,EACtB,gBAAgB,EAChB,eAAe,EACf,sBAAsB,EACtB,aAAa,GAChB,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ImageEditorTool } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* The tools of the editor by default: crop, rotate (with flips) and focal point. A product passes
|
|
4
|
+
* them to `ImageEditor`'s `tools` with its own, or without the ones a field doesn't offer.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useImageEditorTools(): {
|
|
7
|
+
crop: ImageEditorTool;
|
|
8
|
+
rotate: ImageEditorTool;
|
|
9
|
+
focalPoint: ImageEditorTool;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/editor/tools.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,eAAe,EAA0B,MAAM,SAAS,CAAC;AAmcvE;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI;IACnC,IAAI,EAAE,eAAe,CAAC;IACtB,MAAM,EAAE,eAAe,CAAC;IACxB,UAAU,EAAE,eAAe,CAAC;CAC/B,CA2BA"}
|