js-draw 0.17.2 → 0.17.3
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 +4 -0
- package/dist/bundle.js +1 -1
- package/dist/src/Editor.d.ts +5 -0
- package/dist/src/Editor.js +14 -0
- package/dist/src/components/lib.d.ts +2 -2
- package/dist/src/components/lib.js +2 -2
- package/dist/src/toolbar/widgets/DocumentPropertiesWidget.d.ts +0 -1
- package/dist/src/toolbar/widgets/DocumentPropertiesWidget.js +1 -18
- package/package.json +1 -1
- package/src/Editor.ts +16 -0
- package/src/components/lib.ts +2 -1
- package/src/toolbar/widgets/DocumentPropertiesWidget.ts +1 -21
package/dist/src/Editor.d.ts
CHANGED
@@ -234,6 +234,11 @@ export declare class Editor {
|
|
234
234
|
* Set the background color of the image.
|
235
235
|
*/
|
236
236
|
setBackgroundColor(color: Color4): Command;
|
237
|
+
/**
|
238
|
+
* @returns the average of the colors of all background components. Use this to get the current background
|
239
|
+
* color.
|
240
|
+
*/
|
241
|
+
estimateBackgroundColor(): Color4;
|
237
242
|
getImportExportRect(): Rect2;
|
238
243
|
setImportExportRect(imageRect: Rect2): Command;
|
239
244
|
/**
|
package/dist/src/Editor.js
CHANGED
@@ -799,6 +799,20 @@ export class Editor {
|
|
799
799
|
return background.updateStyle({ color });
|
800
800
|
}
|
801
801
|
}
|
802
|
+
/**
|
803
|
+
* @returns the average of the colors of all background components. Use this to get the current background
|
804
|
+
* color.
|
805
|
+
*/
|
806
|
+
estimateBackgroundColor() {
|
807
|
+
var _a;
|
808
|
+
const backgroundColors = [];
|
809
|
+
for (const component of this.image.getBackgroundComponents()) {
|
810
|
+
if (component instanceof ImageBackground) {
|
811
|
+
backgroundColors.push((_a = component.getStyle().color) !== null && _a !== void 0 ? _a : Color4.transparent);
|
812
|
+
}
|
813
|
+
}
|
814
|
+
return Color4.average(backgroundColors);
|
815
|
+
}
|
802
816
|
// Returns the size of the visible region of the output SVG
|
803
817
|
getImportExportRect() {
|
804
818
|
return this.image.getImportExportViewport().visibleRect;
|
@@ -7,6 +7,6 @@ export { default as AbstractComponent } from './AbstractComponent';
|
|
7
7
|
import Stroke from './Stroke';
|
8
8
|
import TextComponent from './TextComponent';
|
9
9
|
import ImageComponent from './ImageComponent';
|
10
|
-
import RestyleableComponent, { createRestyleComponentCommand } from './RestylableComponent';
|
10
|
+
import RestyleableComponent, { createRestyleComponentCommand, isRestylableComponent } from './RestylableComponent';
|
11
11
|
import ImageBackground from './ImageBackground';
|
12
|
-
export { Stroke, TextComponent as Text, RestyleableComponent, createRestyleComponentCommand, TextComponent, Stroke as StrokeComponent, ImageBackground as BackgroundComponent, ImageComponent, };
|
12
|
+
export { Stroke, TextComponent as Text, RestyleableComponent, createRestyleComponentCommand, isRestylableComponent, TextComponent, Stroke as StrokeComponent, ImageBackground as BackgroundComponent, ImageComponent, };
|
@@ -7,6 +7,6 @@ export { default as AbstractComponent } from './AbstractComponent';
|
|
7
7
|
import Stroke from './Stroke';
|
8
8
|
import TextComponent from './TextComponent';
|
9
9
|
import ImageComponent from './ImageComponent';
|
10
|
-
import { createRestyleComponentCommand } from './RestylableComponent';
|
10
|
+
import { createRestyleComponentCommand, isRestylableComponent } from './RestylableComponent';
|
11
11
|
import ImageBackground from './ImageBackground';
|
12
|
-
export { Stroke, TextComponent as Text, createRestyleComponentCommand, TextComponent, Stroke as StrokeComponent, ImageBackground as BackgroundComponent, ImageComponent, };
|
12
|
+
export { Stroke, TextComponent as Text, createRestyleComponentCommand, isRestylableComponent, TextComponent, Stroke as StrokeComponent, ImageBackground as BackgroundComponent, ImageComponent, };
|
@@ -10,7 +10,6 @@ export default class DocumentPropertiesWidget extends BaseWidget {
|
|
10
10
|
private dropdownUpdateQueued;
|
11
11
|
private queueDropdownUpdate;
|
12
12
|
private updateDropdown;
|
13
|
-
private getBackgroundElem;
|
14
13
|
private setBackgroundColor;
|
15
14
|
private getBackgroundColor;
|
16
15
|
private updateImportExportRectSize;
|
@@ -1,5 +1,3 @@
|
|
1
|
-
import Color4 from '../../Color4';
|
2
|
-
import ImageBackground from '../../components/ImageBackground';
|
3
1
|
import { EditorImageEventType } from '../../EditorImage';
|
4
2
|
import Rect2 from '../../math/Rect2';
|
5
3
|
import { EditorEventType } from '../../types';
|
@@ -41,26 +39,11 @@ export default class DocumentPropertiesWidget extends BaseWidget {
|
|
41
39
|
this.updateDropdownContent();
|
42
40
|
}
|
43
41
|
}
|
44
|
-
getBackgroundElem() {
|
45
|
-
const backgroundComponents = [];
|
46
|
-
for (const component of this.editor.image.getBackgroundComponents()) {
|
47
|
-
if (component instanceof ImageBackground) {
|
48
|
-
backgroundComponents.push(component);
|
49
|
-
}
|
50
|
-
}
|
51
|
-
if (backgroundComponents.length === 0) {
|
52
|
-
return null;
|
53
|
-
}
|
54
|
-
// Return the last background component in the list — the component with highest z-index.
|
55
|
-
return backgroundComponents[backgroundComponents.length - 1];
|
56
|
-
}
|
57
42
|
setBackgroundColor(color) {
|
58
43
|
this.editor.dispatch(this.editor.setBackgroundColor(color));
|
59
44
|
}
|
60
45
|
getBackgroundColor() {
|
61
|
-
|
62
|
-
const background = this.getBackgroundElem();
|
63
|
-
return (_b = (_a = background === null || background === void 0 ? void 0 : background.getStyle()) === null || _a === void 0 ? void 0 : _a.color) !== null && _b !== void 0 ? _b : Color4.transparent;
|
46
|
+
return this.editor.estimateBackgroundColor();
|
64
47
|
}
|
65
48
|
updateImportExportRectSize(size) {
|
66
49
|
const filterDimension = (dim) => {
|
package/package.json
CHANGED
package/src/Editor.ts
CHANGED
@@ -1047,6 +1047,22 @@ export class Editor {
|
|
1047
1047
|
}
|
1048
1048
|
}
|
1049
1049
|
|
1050
|
+
/**
|
1051
|
+
* @returns the average of the colors of all background components. Use this to get the current background
|
1052
|
+
* color.
|
1053
|
+
*/
|
1054
|
+
public estimateBackgroundColor(): Color4 {
|
1055
|
+
const backgroundColors = [];
|
1056
|
+
|
1057
|
+
for (const component of this.image.getBackgroundComponents()) {
|
1058
|
+
if (component instanceof ImageBackground) {
|
1059
|
+
backgroundColors.push(component.getStyle().color ?? Color4.transparent);
|
1060
|
+
}
|
1061
|
+
}
|
1062
|
+
|
1063
|
+
return Color4.average(backgroundColors);
|
1064
|
+
}
|
1065
|
+
|
1050
1066
|
// Returns the size of the visible region of the output SVG
|
1051
1067
|
public getImportExportRect(): Rect2 {
|
1052
1068
|
return this.image.getImportExportViewport().visibleRect;
|
package/src/components/lib.ts
CHANGED
@@ -8,7 +8,7 @@ export { default as AbstractComponent } from './AbstractComponent';
|
|
8
8
|
import Stroke from './Stroke';
|
9
9
|
import TextComponent from './TextComponent';
|
10
10
|
import ImageComponent from './ImageComponent';
|
11
|
-
import RestyleableComponent, { createRestyleComponentCommand } from './RestylableComponent';
|
11
|
+
import RestyleableComponent, { createRestyleComponentCommand, isRestylableComponent } from './RestylableComponent';
|
12
12
|
import ImageBackground from './ImageBackground';
|
13
13
|
|
14
14
|
export {
|
@@ -16,6 +16,7 @@ export {
|
|
16
16
|
TextComponent as Text,
|
17
17
|
RestyleableComponent,
|
18
18
|
createRestyleComponentCommand,
|
19
|
+
isRestylableComponent,
|
19
20
|
|
20
21
|
TextComponent,
|
21
22
|
Stroke as StrokeComponent,
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import Color4 from '../../Color4';
|
2
|
-
import ImageBackground from '../../components/ImageBackground';
|
3
2
|
import Editor from '../../Editor';
|
4
3
|
import { EditorImageEventType } from '../../EditorImage';
|
5
4
|
import Rect2 from '../../math/Rect2';
|
@@ -56,31 +55,12 @@ export default class DocumentPropertiesWidget extends BaseWidget {
|
|
56
55
|
}
|
57
56
|
}
|
58
57
|
|
59
|
-
private getBackgroundElem() {
|
60
|
-
const backgroundComponents = [];
|
61
|
-
|
62
|
-
for (const component of this.editor.image.getBackgroundComponents()) {
|
63
|
-
if (component instanceof ImageBackground) {
|
64
|
-
backgroundComponents.push(component);
|
65
|
-
}
|
66
|
-
}
|
67
|
-
|
68
|
-
if (backgroundComponents.length === 0) {
|
69
|
-
return null;
|
70
|
-
}
|
71
|
-
|
72
|
-
// Return the last background component in the list — the component with highest z-index.
|
73
|
-
return backgroundComponents[backgroundComponents.length - 1];
|
74
|
-
}
|
75
|
-
|
76
58
|
private setBackgroundColor(color: Color4) {
|
77
59
|
this.editor.dispatch(this.editor.setBackgroundColor(color));
|
78
60
|
}
|
79
61
|
|
80
62
|
private getBackgroundColor() {
|
81
|
-
|
82
|
-
|
83
|
-
return background?.getStyle()?.color ?? Color4.transparent;
|
63
|
+
return this.editor.estimateBackgroundColor();
|
84
64
|
}
|
85
65
|
|
86
66
|
private updateImportExportRectSize(size: { width?: number, height?: number }) {
|