@gradio/imageeditor 0.9.0 → 0.10.1
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/CHANGELOG.md +39 -0
- package/ImageEditor.stories.svelte +1 -0
- package/Index.svelte +7 -2
- package/dist/Example.svelte +41 -0
- package/dist/Example.svelte.d.ts +19 -0
- package/dist/Index.svelte +184 -0
- package/dist/Index.svelte.d.ts +192 -0
- package/dist/shared/Controls.svelte +73 -0
- package/dist/shared/Controls.svelte.d.ts +24 -0
- package/dist/shared/ImageEditor.svelte +329 -0
- package/dist/shared/ImageEditor.svelte.d.ts +79 -0
- package/dist/shared/InteractiveImageEditor.svelte +273 -0
- package/dist/shared/InteractiveImageEditor.svelte.d.ts +58 -0
- package/dist/shared/layers/Layers.svelte +216 -0
- package/dist/shared/layers/Layers.svelte.d.ts +18 -0
- package/dist/shared/layers/utils.d.ts +69 -0
- package/dist/shared/layers/utils.js +131 -0
- package/dist/shared/tools/Brush.svelte +208 -0
- package/dist/shared/tools/Brush.svelte.d.ts +29 -0
- package/dist/shared/tools/BrushOptions.svelte +162 -0
- package/dist/shared/tools/BrushOptions.svelte.d.ts +29 -0
- package/dist/shared/tools/BrushSize.svelte +60 -0
- package/dist/shared/tools/BrushSize.svelte.d.ts +20 -0
- package/dist/shared/tools/ColorField.svelte +159 -0
- package/dist/shared/tools/ColorField.svelte.d.ts +20 -0
- package/dist/shared/tools/ColorPicker.svelte +179 -0
- package/dist/shared/tools/ColorPicker.svelte.d.ts +16 -0
- package/dist/shared/tools/ColorSwatch.svelte +183 -0
- package/dist/shared/tools/ColorSwatch.svelte.d.ts +30 -0
- package/dist/shared/tools/Crop.svelte +155 -0
- package/dist/shared/tools/Crop.svelte.d.ts +16 -0
- package/dist/shared/tools/Cropper.svelte +271 -0
- package/dist/shared/tools/Cropper.svelte.d.ts +41 -0
- package/dist/shared/tools/Handle.svelte +260 -0
- package/dist/shared/tools/Handle.svelte.d.ts +29 -0
- package/dist/shared/tools/Sources.svelte +250 -0
- package/dist/shared/tools/Sources.svelte.d.ts +32 -0
- package/dist/shared/tools/Tools.svelte +101 -0
- package/dist/shared/tools/Tools.svelte.d.ts +48 -0
- package/dist/shared/tools/brush.d.ts +62 -0
- package/dist/shared/tools/brush.js +133 -0
- package/dist/shared/tools/crop.d.ts +15 -0
- package/dist/shared/tools/crop.js +154 -0
- package/dist/shared/tools/index.d.ts +5 -0
- package/dist/shared/tools/index.js +5 -0
- package/dist/shared/tools/sources.d.ts +40 -0
- package/dist/shared/tools/sources.js +69 -0
- package/dist/shared/tools/types.d.ts +1 -0
- package/dist/shared/tools/types.js +1 -0
- package/dist/shared/utils/commands.d.ts +96 -0
- package/dist/shared/utils/commands.js +65 -0
- package/dist/shared/utils/events.d.ts +7 -0
- package/dist/shared/utils/events.js +22 -0
- package/dist/shared/utils/parse_placeholder.d.ts +1 -0
- package/dist/shared/utils/parse_placeholder.js +19 -0
- package/dist/shared/utils/pixi.d.ts +76 -0
- package/dist/shared/utils/pixi.js +152 -0
- package/package.json +28 -12
- package/shared/ImageEditor.svelte +8 -4
- package/shared/InteractiveImageEditor.svelte +29 -5
- package/shared/tools/Brush.svelte +4 -6
- package/shared/tools/BrushOptions.svelte +1 -1
- package/shared/tools/Crop.svelte +2 -1
- package/shared/utils/parse_placeholder.ts +27 -0
- package/shared/utils/pixi.ts +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function inject(text: string): [string | false, string | false];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const RE_HEADING = /^(#\s*)(.+)$/m;
|
|
2
|
+
export function inject(text) {
|
|
3
|
+
const trimmed_text = text.trim();
|
|
4
|
+
const heading_match = trimmed_text.match(RE_HEADING);
|
|
5
|
+
if (!heading_match) {
|
|
6
|
+
return [false, trimmed_text || false];
|
|
7
|
+
}
|
|
8
|
+
const [full_match, , heading_content] = heading_match;
|
|
9
|
+
const _heading = heading_content.trim();
|
|
10
|
+
if (trimmed_text === full_match) {
|
|
11
|
+
return [_heading, false];
|
|
12
|
+
}
|
|
13
|
+
const heading_end_index = heading_match.index !== undefined
|
|
14
|
+
? heading_match.index + full_match.length
|
|
15
|
+
: 0;
|
|
16
|
+
const remaining_text = trimmed_text.substring(heading_end_index).trim();
|
|
17
|
+
const _paragraph = remaining_text || false;
|
|
18
|
+
return [_heading, _paragraph];
|
|
19
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Container, Graphics, Rectangle, type IRenderer, type ICanvas } from "pixi.js";
|
|
2
|
+
import { type LayerScene } from "../layers/utils";
|
|
3
|
+
/**
|
|
4
|
+
* interface holding references to pixi app components
|
|
5
|
+
*/
|
|
6
|
+
export interface PixiApp {
|
|
7
|
+
/**
|
|
8
|
+
* The pixi container for layers
|
|
9
|
+
*/
|
|
10
|
+
layer_container: Container;
|
|
11
|
+
/**
|
|
12
|
+
* The pixi container for background images and colors
|
|
13
|
+
*/
|
|
14
|
+
background_container: Container;
|
|
15
|
+
/**
|
|
16
|
+
* The pixi renderer
|
|
17
|
+
*/
|
|
18
|
+
renderer: IRenderer;
|
|
19
|
+
/**
|
|
20
|
+
* The pixi canvas
|
|
21
|
+
*/
|
|
22
|
+
view: HTMLCanvasElement & ICanvas;
|
|
23
|
+
/**
|
|
24
|
+
* The pixi container for masking
|
|
25
|
+
*/
|
|
26
|
+
mask_container: Container;
|
|
27
|
+
destroy(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Resizes the pixi app
|
|
30
|
+
* @param width the new width
|
|
31
|
+
* @param height the new height
|
|
32
|
+
*/
|
|
33
|
+
resize(width: number, height: number): void;
|
|
34
|
+
/**
|
|
35
|
+
* Gets the blobs for the background, layers, and composite
|
|
36
|
+
* @param bounds the bounds of the canvas
|
|
37
|
+
* @returns a promise with the blobs
|
|
38
|
+
*/
|
|
39
|
+
get_blobs(layers: LayerScene[], bounds: Rectangle, dimensions: [number, number]): Promise<ImageBlobs>;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the layers
|
|
42
|
+
*/
|
|
43
|
+
get_layers?: () => LayerScene[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a PIXI app and attaches it to a DOM element
|
|
47
|
+
* @param target DOM element to attach PIXI app to
|
|
48
|
+
* @param width Width of the PIXI app
|
|
49
|
+
* @param height Height of the PIXI app
|
|
50
|
+
* @param antialias Whether to use antialiasing
|
|
51
|
+
* @returns object with pixi container and renderer
|
|
52
|
+
*/
|
|
53
|
+
export declare function create_pixi_app({ target, dimensions: [width, height], antialias }: {
|
|
54
|
+
target: HTMLElement;
|
|
55
|
+
dimensions: [number, number];
|
|
56
|
+
antialias: boolean;
|
|
57
|
+
}): PixiApp;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a pixi graphics object.
|
|
60
|
+
* @param z_index the z index of the graphics object
|
|
61
|
+
* @returns a graphics object
|
|
62
|
+
*/
|
|
63
|
+
export declare function make_graphics(z_index: number): Graphics;
|
|
64
|
+
/**
|
|
65
|
+
* Clamps a number between a min and max value.
|
|
66
|
+
* @param n The number to clamp.
|
|
67
|
+
* @param min The minimum value.
|
|
68
|
+
* @param max The maximum value.
|
|
69
|
+
* @returns The clamped number.
|
|
70
|
+
*/
|
|
71
|
+
export declare function clamp(n: number, min: number, max: number): number;
|
|
72
|
+
export interface ImageBlobs {
|
|
73
|
+
background: Blob | null;
|
|
74
|
+
layers: (Blob | null)[];
|
|
75
|
+
composite: Blob | null;
|
|
76
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { Application, Container, Graphics, Sprite, Rectangle, RenderTexture } from "pixi.js";
|
|
2
|
+
import {} from "../layers/utils";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a PIXI app and attaches it to a DOM element
|
|
5
|
+
* @param target DOM element to attach PIXI app to
|
|
6
|
+
* @param width Width of the PIXI app
|
|
7
|
+
* @param height Height of the PIXI app
|
|
8
|
+
* @param antialias Whether to use antialiasing
|
|
9
|
+
* @returns object with pixi container and renderer
|
|
10
|
+
*/
|
|
11
|
+
export function create_pixi_app({ target, dimensions: [width, height], antialias }) {
|
|
12
|
+
const ratio = window.devicePixelRatio || 1;
|
|
13
|
+
const app = new Application({
|
|
14
|
+
width,
|
|
15
|
+
height,
|
|
16
|
+
antialias: antialias,
|
|
17
|
+
backgroundAlpha: 0,
|
|
18
|
+
eventMode: "static"
|
|
19
|
+
});
|
|
20
|
+
const view = app.view;
|
|
21
|
+
// ensure that we can sort the background and layer containers
|
|
22
|
+
app.stage.sortableChildren = true;
|
|
23
|
+
view.style.maxWidth = `${width / ratio}px`;
|
|
24
|
+
view.style.maxHeight = `${height / ratio}px`;
|
|
25
|
+
view.style.width = "100%";
|
|
26
|
+
view.style.height = "100%";
|
|
27
|
+
target.appendChild(app.view);
|
|
28
|
+
// we need a separate container for the background so that we can
|
|
29
|
+
// clear its content without knowing too much about its children
|
|
30
|
+
const background_container = new Container();
|
|
31
|
+
background_container.zIndex = 0;
|
|
32
|
+
const layer_container = new Container();
|
|
33
|
+
layer_container.zIndex = 1;
|
|
34
|
+
// ensure we can reorder layers via zIndex
|
|
35
|
+
layer_container.sortableChildren = true;
|
|
36
|
+
const mask_container = new Container();
|
|
37
|
+
mask_container.zIndex = 1;
|
|
38
|
+
const composite_container = new Container();
|
|
39
|
+
composite_container.zIndex = 0;
|
|
40
|
+
mask_container.addChild(background_container);
|
|
41
|
+
mask_container.addChild(layer_container);
|
|
42
|
+
app.stage.addChild(mask_container);
|
|
43
|
+
app.stage.addChild(composite_container);
|
|
44
|
+
const mask = new Graphics();
|
|
45
|
+
let text = RenderTexture.create({
|
|
46
|
+
width,
|
|
47
|
+
height
|
|
48
|
+
});
|
|
49
|
+
const sprite = new Sprite(text);
|
|
50
|
+
mask_container.mask = sprite;
|
|
51
|
+
app.render();
|
|
52
|
+
function reset_mask(width, height) {
|
|
53
|
+
background_container.removeChildren();
|
|
54
|
+
mask.beginFill(0xffffff, 1);
|
|
55
|
+
mask.drawRect(0, 0, width, height);
|
|
56
|
+
mask.endFill();
|
|
57
|
+
text = RenderTexture.create({
|
|
58
|
+
width,
|
|
59
|
+
height
|
|
60
|
+
});
|
|
61
|
+
app.renderer.render(mask, {
|
|
62
|
+
renderTexture: text
|
|
63
|
+
});
|
|
64
|
+
const sprite = new Sprite(text);
|
|
65
|
+
mask_container.mask = sprite;
|
|
66
|
+
}
|
|
67
|
+
function resize(width, height) {
|
|
68
|
+
app.renderer.resize(width, height);
|
|
69
|
+
view.style.maxWidth = `${width / ratio}px`;
|
|
70
|
+
view.style.maxHeight = `${height / ratio}px`;
|
|
71
|
+
reset_mask(width, height);
|
|
72
|
+
}
|
|
73
|
+
async function get_blobs(_layers, bounds, [w, h]) {
|
|
74
|
+
const background = await get_canvas_blob(app.renderer, background_container, bounds, w, h);
|
|
75
|
+
const layers = await Promise.all(_layers.map((layer) => get_canvas_blob(app.renderer, layer.composite, bounds, w, h)));
|
|
76
|
+
const composite = await get_canvas_blob(app.renderer, mask_container, bounds, w, h);
|
|
77
|
+
return {
|
|
78
|
+
background,
|
|
79
|
+
layers,
|
|
80
|
+
composite
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
layer_container,
|
|
85
|
+
renderer: app.renderer,
|
|
86
|
+
destroy: () => app.destroy(true),
|
|
87
|
+
view: app.view,
|
|
88
|
+
background_container,
|
|
89
|
+
mask_container,
|
|
90
|
+
resize,
|
|
91
|
+
get_blobs
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Creates a pixi graphics object.
|
|
96
|
+
* @param z_index the z index of the graphics object
|
|
97
|
+
* @returns a graphics object
|
|
98
|
+
*/
|
|
99
|
+
export function make_graphics(z_index) {
|
|
100
|
+
const graphics = new Graphics();
|
|
101
|
+
graphics.eventMode = "none";
|
|
102
|
+
graphics.zIndex = z_index;
|
|
103
|
+
return graphics;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Clamps a number between a min and max value.
|
|
107
|
+
* @param n The number to clamp.
|
|
108
|
+
* @param min The minimum value.
|
|
109
|
+
* @param max The maximum value.
|
|
110
|
+
* @returns The clamped number.
|
|
111
|
+
*/
|
|
112
|
+
export function clamp(n, min, max) {
|
|
113
|
+
return n < min ? min : n > max ? max : n;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Generates a blob from a pixi object.
|
|
117
|
+
* @param renderer The pixi renderer.
|
|
118
|
+
* @param obj The pixi object to generate a blob from.
|
|
119
|
+
* @param bounds The bounds of the canvas that we wish to extract
|
|
120
|
+
* @param width The full width of the canvas
|
|
121
|
+
* @param height The full height of the canvas
|
|
122
|
+
* @returns A promise with the blob.
|
|
123
|
+
*/
|
|
124
|
+
function get_canvas_blob(renderer, obj, bounds, width, height) {
|
|
125
|
+
return new Promise((resolve) => {
|
|
126
|
+
// for some reason pixi won't extract a cropped canvas without distorting it
|
|
127
|
+
// so we have to extract the whole canvas and crop it manually
|
|
128
|
+
const src_canvas = renderer.extract.canvas(obj, new Rectangle(0, 0, width, height));
|
|
129
|
+
// Create a new canvas for the cropped area with the appropriate size
|
|
130
|
+
let dest_canvas = document.createElement("canvas");
|
|
131
|
+
dest_canvas.width = bounds.width;
|
|
132
|
+
dest_canvas.height = bounds.height;
|
|
133
|
+
let dest_ctx = dest_canvas.getContext("2d");
|
|
134
|
+
if (!dest_ctx) {
|
|
135
|
+
resolve(null);
|
|
136
|
+
throw new Error("Could not create canvas context");
|
|
137
|
+
}
|
|
138
|
+
// Draw the cropped area onto the destination canvas
|
|
139
|
+
dest_ctx.drawImage(src_canvas,
|
|
140
|
+
// this is the area of the source that we want to copy (the crop box)
|
|
141
|
+
bounds.x, bounds.y, bounds.width, bounds.height,
|
|
142
|
+
// this is where we want to draw the crop box on the destination canvas
|
|
143
|
+
0, 0, bounds.width, bounds.height);
|
|
144
|
+
// we grab a blob here so we can upload it
|
|
145
|
+
dest_canvas.toBlob?.((blob) => {
|
|
146
|
+
if (!blob) {
|
|
147
|
+
resolve(null);
|
|
148
|
+
}
|
|
149
|
+
resolve(blob);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradio/imageeditor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Gradio UI packages",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "",
|
|
@@ -10,23 +10,39 @@
|
|
|
10
10
|
"@types/tinycolor2": "^1.4.6",
|
|
11
11
|
"pixi.js": "^7.3.2",
|
|
12
12
|
"tinycolor2": "^1.6.0",
|
|
13
|
-
"@gradio/
|
|
14
|
-
"@gradio/
|
|
15
|
-
"@gradio/
|
|
16
|
-
"@gradio/image": "^0.
|
|
17
|
-
"@gradio/
|
|
18
|
-
"@gradio/
|
|
19
|
-
"@gradio/
|
|
20
|
-
"@gradio/
|
|
13
|
+
"@gradio/client": "^1.5.2",
|
|
14
|
+
"@gradio/icons": "^0.7.2",
|
|
15
|
+
"@gradio/atoms": "^0.8.1",
|
|
16
|
+
"@gradio/image": "^0.15.1",
|
|
17
|
+
"@gradio/upload": "^0.12.4",
|
|
18
|
+
"@gradio/statustracker": "^0.7.6",
|
|
19
|
+
"@gradio/utils": "^0.6.1",
|
|
20
|
+
"@gradio/wasm": "^0.13.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@gradio/preview": "^0.
|
|
23
|
+
"@gradio/preview": "^0.11.1"
|
|
24
24
|
},
|
|
25
25
|
"main_changeset": true,
|
|
26
26
|
"main": "./Index.svelte",
|
|
27
27
|
"exports": {
|
|
28
|
-
".":
|
|
29
|
-
|
|
28
|
+
".": {
|
|
29
|
+
"gradio": "./Index.svelte",
|
|
30
|
+
"svelte": "./dist/Index.svelte",
|
|
31
|
+
"types": "./dist/Index.svelte.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./example": {
|
|
34
|
+
"gradio": "./Example.svelte",
|
|
35
|
+
"svelte": "./dist/Example.svelte",
|
|
36
|
+
"types": "./dist/Example.svelte.d.ts"
|
|
37
|
+
},
|
|
30
38
|
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"svelte": "^4.0.0"
|
|
42
|
+
},
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/gradio-app/gradio.git",
|
|
46
|
+
"directory": "js/imageeditor"
|
|
31
47
|
}
|
|
32
48
|
}
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
child_bottom: number;
|
|
29
29
|
}>;
|
|
30
30
|
active_tool: Writable<tool>;
|
|
31
|
-
toolbar_box: Writable<DOMRect
|
|
31
|
+
toolbar_box: Writable<DOMRect | Record<string, never>>;
|
|
32
32
|
crop: Writable<[number, number, number, number]>;
|
|
33
33
|
position_spring: Spring<{
|
|
34
34
|
x: number;
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
}>();
|
|
75
75
|
export let crop_constraint = false;
|
|
76
76
|
export let canvas_size: [number, number] | undefined;
|
|
77
|
+
export let parent_height: number;
|
|
77
78
|
|
|
78
79
|
$: orig_canvas_size = canvas_size;
|
|
79
80
|
|
|
@@ -84,13 +85,13 @@
|
|
|
84
85
|
|
|
85
86
|
let editor_box: EditorContext["editor_box"] = writable({
|
|
86
87
|
parent_width: 0,
|
|
87
|
-
parent_height:
|
|
88
|
+
parent_height: parent_height,
|
|
88
89
|
parent_top: 0,
|
|
89
90
|
parent_left: 0,
|
|
90
91
|
parent_right: 0,
|
|
91
92
|
parent_bottom: 0,
|
|
92
93
|
child_width: 0,
|
|
93
|
-
child_height:
|
|
94
|
+
child_height: parent_height,
|
|
94
95
|
child_top: 0,
|
|
95
96
|
child_left: 0,
|
|
96
97
|
child_right: 0,
|
|
@@ -118,6 +119,7 @@
|
|
|
118
119
|
$: {
|
|
119
120
|
history = !!$current_history.previous || $active_tool !== "bg";
|
|
120
121
|
}
|
|
122
|
+
const is_browser = typeof window !== "undefined";
|
|
121
123
|
|
|
122
124
|
const active_tool: Writable<tool> = writable("bg");
|
|
123
125
|
const reset_context: Writable<PartialRecord<context_type, () => void>> =
|
|
@@ -126,7 +128,9 @@
|
|
|
126
128
|
PartialRecord<context_type, (dimensions?: typeof $dimensions) => void>
|
|
127
129
|
> = writable({});
|
|
128
130
|
const contexts: Writable<context_type[]> = writable([]);
|
|
129
|
-
const toolbar_box: Writable<DOMRect
|
|
131
|
+
const toolbar_box: Writable<DOMRect | Record<string, never>> = writable(
|
|
132
|
+
is_browser ? new DOMRect() : {}
|
|
133
|
+
);
|
|
130
134
|
|
|
131
135
|
const sort_order = ["bg", "layers", "crop", "draw", "erase"] as const;
|
|
132
136
|
const editor_context = setContext<EditorContext>(EDITOR_KEY, {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
import { Tools, Crop, Brush, Sources } from "./tools";
|
|
26
26
|
import { BlockLabel } from "@gradio/atoms";
|
|
27
27
|
import { Image as ImageIcon } from "@gradio/icons";
|
|
28
|
+
import { inject } from "./utils/parse_placeholder";
|
|
28
29
|
|
|
29
30
|
export let brush: IBrush | null;
|
|
30
31
|
export let eraser: Eraser | null;
|
|
@@ -49,6 +50,8 @@
|
|
|
49
50
|
export let upload: Client["upload"];
|
|
50
51
|
export let stream_handler: Client["stream"];
|
|
51
52
|
export let dragging: boolean;
|
|
53
|
+
export let placeholder: string | undefined = undefined;
|
|
54
|
+
export let height = 400;
|
|
52
55
|
|
|
53
56
|
const dispatch = createEventDispatcher<{
|
|
54
57
|
clear?: never;
|
|
@@ -196,7 +199,9 @@
|
|
|
196
199
|
}
|
|
197
200
|
|
|
198
201
|
let active_mode: "webcam" | "color" | null = null;
|
|
199
|
-
let editor_height =
|
|
202
|
+
let editor_height = height - 100;
|
|
203
|
+
|
|
204
|
+
$: [heading, paragraph] = placeholder ? inject(placeholder) : [false, false];
|
|
200
205
|
</script>
|
|
201
206
|
|
|
202
207
|
<BlockLabel
|
|
@@ -209,6 +214,7 @@
|
|
|
209
214
|
crop_size={Array.isArray(crop_size) ? crop_size : undefined}
|
|
210
215
|
bind:this={editor}
|
|
211
216
|
bind:height={editor_height}
|
|
217
|
+
parent_height={height}
|
|
212
218
|
{changeable}
|
|
213
219
|
on:save
|
|
214
220
|
on:change={handle_change}
|
|
@@ -254,13 +260,22 @@
|
|
|
254
260
|
{#if !bg && !history && active_mode !== "webcam" && status !== "error"}
|
|
255
261
|
<div class="empty wrap" style:height={`${editor_height}px`}>
|
|
256
262
|
{#if sources && sources.length}
|
|
257
|
-
|
|
263
|
+
{#if heading || paragraph}
|
|
264
|
+
{#if heading}
|
|
265
|
+
<h2>{heading}</h2>
|
|
266
|
+
{/if}
|
|
267
|
+
{#if paragraph}
|
|
268
|
+
<p>{paragraph}</p>
|
|
269
|
+
{/if}
|
|
270
|
+
{:else}
|
|
271
|
+
<div>Upload an image</div>
|
|
272
|
+
{/if}
|
|
258
273
|
{/if}
|
|
259
274
|
|
|
260
|
-
{#if sources && sources.length && brush}
|
|
275
|
+
{#if sources && sources.length && brush && !placeholder}
|
|
261
276
|
<div class="or">or</div>
|
|
262
277
|
{/if}
|
|
263
|
-
{#if brush}
|
|
278
|
+
{#if brush && !placeholder}
|
|
264
279
|
<div>select the draw tool to start</div>
|
|
265
280
|
{/if}
|
|
266
281
|
</div>
|
|
@@ -268,6 +283,15 @@
|
|
|
268
283
|
</ImageEditor>
|
|
269
284
|
|
|
270
285
|
<style>
|
|
286
|
+
h2 {
|
|
287
|
+
font-size: var(--text-xl);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
p,
|
|
291
|
+
h2 {
|
|
292
|
+
white-space: pre-line;
|
|
293
|
+
}
|
|
294
|
+
|
|
271
295
|
.empty {
|
|
272
296
|
display: flex;
|
|
273
297
|
flex-direction: column;
|
|
@@ -292,7 +316,7 @@
|
|
|
292
316
|
align-items: center;
|
|
293
317
|
color: var(--block-label-text-color);
|
|
294
318
|
line-height: var(--line-md);
|
|
295
|
-
font-size: var(--text-
|
|
319
|
+
font-size: var(--text-md);
|
|
296
320
|
pointer-events: none;
|
|
297
321
|
}
|
|
298
322
|
|
|
@@ -187,12 +187,12 @@
|
|
|
187
187
|
toggle_listeners("off");
|
|
188
188
|
}
|
|
189
189
|
});
|
|
190
|
+
const toggle_options = debounce_toggle();
|
|
190
191
|
|
|
192
|
+
const unregister = register_tool(mode, {
|
|
193
|
+
cb: toggle_options
|
|
194
|
+
});
|
|
191
195
|
onMount(() => {
|
|
192
|
-
const unregister = register_tool(mode, {
|
|
193
|
-
cb: toggle_options
|
|
194
|
-
});
|
|
195
|
-
|
|
196
196
|
return () => {
|
|
197
197
|
unregister();
|
|
198
198
|
toggle_listeners("off");
|
|
@@ -230,8 +230,6 @@
|
|
|
230
230
|
timeout = setTimeout(later, 100);
|
|
231
231
|
};
|
|
232
232
|
}
|
|
233
|
-
|
|
234
|
-
const toggle_options = debounce_toggle();
|
|
235
233
|
</script>
|
|
236
234
|
|
|
237
235
|
<svelte:window
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
export let parent_width: number;
|
|
18
18
|
export let parent_height: number;
|
|
19
19
|
export let parent_left: number;
|
|
20
|
-
export let toolbar_box: DOMRect
|
|
20
|
+
export let toolbar_box: DOMRect | Record<string, never>;
|
|
21
21
|
export let show_swatch: boolean;
|
|
22
22
|
|
|
23
23
|
let color_picker = false;
|
package/shared/tools/Crop.svelte
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const RE_HEADING = /^(#\s*)(.+)$/m;
|
|
2
|
+
|
|
3
|
+
export function inject(text: string): [string | false, string | false] {
|
|
4
|
+
const trimmed_text = text.trim();
|
|
5
|
+
|
|
6
|
+
const heading_match = trimmed_text.match(RE_HEADING);
|
|
7
|
+
if (!heading_match) {
|
|
8
|
+
return [false, trimmed_text || false];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const [full_match, , heading_content] = heading_match;
|
|
12
|
+
const _heading = heading_content.trim();
|
|
13
|
+
|
|
14
|
+
if (trimmed_text === full_match) {
|
|
15
|
+
return [_heading, false];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const heading_end_index =
|
|
19
|
+
heading_match.index !== undefined
|
|
20
|
+
? heading_match.index + full_match.length
|
|
21
|
+
: 0;
|
|
22
|
+
const remaining_text = trimmed_text.substring(heading_end_index).trim();
|
|
23
|
+
|
|
24
|
+
const _paragraph = remaining_text || false;
|
|
25
|
+
|
|
26
|
+
return [_heading, _paragraph];
|
|
27
|
+
}
|