redhotmagma-graphics-editor 1.41.1 → 1.42.0
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/App.js +90 -165
- package/CanvasAdapters/Mock/Canvas.js +71 -125
- package/CanvasAdapters/Mock/Objects/CanvasObject.js +23 -40
- package/CanvasAdapters/Mock/Objects/Group.js +15 -46
- package/CanvasAdapters/Mock/Objects/Image.js +15 -46
- package/CanvasAdapters/Mock/Objects/Text.js +15 -51
- package/CanvasAdapters/Mock/index.js +0 -1
- package/CanvasAdapters/PaperJs/Canvas.js +268 -398
- package/CanvasAdapters/PaperJs/CanvasRepository.js +6 -23
- package/CanvasAdapters/PaperJs/Modifiers/FontSizeMin.js +2 -5
- package/CanvasAdapters/PaperJs/Objects/CanvasObject.js +33 -65
- package/CanvasAdapters/PaperJs/Objects/Group.js +14 -48
- package/CanvasAdapters/PaperJs/Objects/Image.js +58 -114
- package/CanvasAdapters/PaperJs/Objects/Text.js +43 -99
- package/CanvasAdapters/PaperJs/Utils/HTML2Paper.js +57 -108
- package/CanvasAdapters/PaperJs/Utils/SVGfix.js +9 -30
- package/CanvasAdapters/PaperJs/Utils/StyleParams.js +10 -21
- package/CanvasAdapters/PaperJs/Utils/TextToSVGRepository.js +53 -86
- package/CanvasAdapters/PaperJs/Utils/TextToSVGUtils.js +4 -14
- package/CanvasAdapters/PaperJs/Utils/UTF8Base64.js +3 -24
- package/CanvasAdapters/PaperJs/Utils/UseColorLayer.js +58 -0
- package/CanvasAdapters/PaperJs/Utils/UseMask.js +183 -279
- package/CanvasAdapters/PaperJs/Utils/__tests__/SVGfix.test.js +0 -1
- package/CanvasAdapters/PaperJs/Utils/__tests__/TextToSVGUtils.test.js +0 -1
- package/CanvasAdapters/PaperJs/Utils/__tests__/updateFontStyle.test.js +0 -1
- package/CanvasAdapters/PaperJs/Utils/updateFontStyle.js +5 -11
- package/CanvasAdapters/PaperJs/index.js +0 -1
- package/CanvasInterface/Canvas.js +145 -235
- package/CanvasInterface/CanvasProvider.js +25 -75
- package/CanvasInterface/Objects/CanvasObject.js +68 -148
- package/CanvasInterface/Objects/index.js +0 -1
- package/CanvasInterface/Observable.js +10 -29
- package/CanvasInterface/canvasConnect.js +12 -44
- package/CanvasInterface/index.js +1 -7
- package/Components/Canvas/Canvas.js +14 -41
- package/Components/Canvas/CanvasContainer.js +5 -18
- package/Components/Canvas/styles.js +2 -3
- package/Components/DelayedContainer.js +14 -39
- package/Components/Editor/Editor.js +47 -102
- package/Components/Editor/EditorContainer.js +47 -131
- package/Components/Editor/styles.js +2 -3
- package/Components/InlineToolbox/InlineToolbox.js +49 -142
- package/Components/InlineToolbox/InlineToolboxButton.js +9 -19
- package/Components/InlineToolbox/styles.js +2 -3
- package/Components/ManipulableContainer.js +15 -41
- package/Components/ResizeDetect/ResizeDetect.js +14 -47
- package/Components/Rulers/Ruler.js +20 -68
- package/Components/Rulers/Rulers.js +14 -46
- package/Components/Rulers/styles.js +2 -3
- package/Components/SelectionToolbox/ColorPalette.js +25 -73
- package/Components/SelectionToolbox/SelectionToolbox.js +39 -101
- package/Components/SelectionToolbox/TextTools.js +81 -157
- package/Components/SelectionToolbox/styles.js +2 -3
- package/Components/StandardToolbox/StandardToolbox.js +81 -144
- package/Components/TextEditor/TextEditor.js +67 -182
- package/Components/TextEditor/TextEditorStateProvider.js +20 -56
- package/Components/Toolbox/ToolboxContainer.js +5 -18
- package/Components/Toolbox/ToolboxRow.js +4 -16
- package/Components/Toolbox/styles.js +2 -3
- package/Utils/Calc2D.js +3 -9
- package/Utils/DOM.js +22 -80
- package/Utils/Device.js +2 -6
- package/Utils/Image.js +17 -11
- package/Utils/Logger.js +8 -32
- package/Utils/Range.js +6 -33
- package/Utils/String.js +2 -8
- package/Utils/UnitConversion.js +3 -9
- package/Utils/__tests__/Calc2D.test.js +1 -3
- package/Utils/__tests__/DOM.test.js +17 -25
- package/Utils/__tests__/Range.test.js +0 -1
- package/_demos/UsingExternalControls/App.js +13 -48
- package/_demos/UsingRenderProps/App.js +15 -54
- package/index.js +2 -6
- package/package.json +5 -7
- package/src/App.js +35 -38
- package/src/CanvasAdapters/PaperJs/Canvas.ts +11 -0
- package/src/CanvasAdapters/PaperJs/Utils/UseColorLayer.js +56 -0
- package/src/Components/InlineToolbox/InlineToolbox.js +2 -2
- package/src/Components/SelectionToolbox/TextTools.js +1 -1
- package/src/_demos/UsingExternalControls/App.js +25 -28
- package/src/_demos/UsingRenderProps/App.js +16 -19
- package/src/index.js +2 -2
|
@@ -1,97 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports["default"] = void 0;
|
|
9
|
-
|
|
10
7
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
|
-
var _reactHotLoader = require("react-hot-loader");
|
|
13
|
-
|
|
14
8
|
var _PaperJs = require("../../CanvasAdapters/PaperJs");
|
|
15
|
-
|
|
16
9
|
var _Editor = _interopRequireDefault(require("../../Components/Editor/Editor"));
|
|
17
|
-
|
|
18
10
|
var _CanvasProvider = require("../../CanvasInterface/CanvasProvider");
|
|
19
|
-
|
|
20
11
|
var _TextEditorStateProvider = require("../../Components/TextEditor/TextEditorStateProvider");
|
|
21
|
-
|
|
22
12
|
var _excluded = ["components"];
|
|
23
|
-
|
|
24
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
25
|
-
|
|
26
|
-
function _extends() { _extends = Object.assign
|
|
27
|
-
|
|
14
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
15
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
28
16
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
29
|
-
|
|
30
17
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
31
|
-
|
|
32
18
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
33
|
-
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
39
|
-
|
|
40
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
41
|
-
|
|
19
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
20
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
21
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
22
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
42
23
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
43
|
-
|
|
44
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
45
|
-
|
|
24
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
46
25
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
47
|
-
|
|
48
26
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
49
|
-
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
function
|
|
53
|
-
|
|
27
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
28
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
29
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
30
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
54
31
|
var canvas = new _PaperJs.Canvas();
|
|
55
|
-
|
|
56
32
|
var App = /*#__PURE__*/function (_React$Component) {
|
|
57
33
|
_inherits(App, _React$Component);
|
|
58
|
-
|
|
59
34
|
var _super = _createSuper(App);
|
|
60
|
-
|
|
61
35
|
function App() {
|
|
62
36
|
var _this;
|
|
63
|
-
|
|
64
37
|
_classCallCheck(this, App);
|
|
65
|
-
|
|
66
38
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
67
39
|
args[_key] = arguments[_key];
|
|
68
40
|
}
|
|
69
|
-
|
|
70
41
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
71
|
-
|
|
72
42
|
_defineProperty(_assertThisInitialized(_this), "mockUploadFunction", function (files) {
|
|
73
43
|
return new Promise(function (resolve, reject) {
|
|
74
44
|
var reader = new FileReader();
|
|
75
|
-
|
|
76
45
|
reader.onload = function () {
|
|
77
46
|
var dataURL = reader.result;
|
|
78
47
|
resolve([{
|
|
79
48
|
src: dataURL
|
|
80
49
|
}]);
|
|
81
50
|
};
|
|
82
|
-
|
|
83
51
|
reader.onerror = reject;
|
|
84
52
|
reader.readAsDataURL(files[0]);
|
|
85
53
|
});
|
|
86
54
|
});
|
|
87
|
-
|
|
88
55
|
return _this;
|
|
89
56
|
}
|
|
90
|
-
|
|
91
57
|
_createClass(App, [{
|
|
92
58
|
key: "render",
|
|
93
59
|
value: function render() {
|
|
94
|
-
return /*#__PURE__*/_react["default"].createElement(
|
|
60
|
+
return /*#__PURE__*/_react["default"].createElement(_CanvasProvider.CanvasProvider, {
|
|
95
61
|
canvas: canvas
|
|
96
62
|
}, /*#__PURE__*/_react["default"].createElement(_TextEditorStateProvider.TextEditorStateProvider, {
|
|
97
63
|
defaultStyle: {
|
|
@@ -108,21 +74,16 @@ var App = /*#__PURE__*/function (_React$Component) {
|
|
|
108
74
|
return /*#__PURE__*/_react["default"].createElement(SelectionToolbox, {
|
|
109
75
|
renderTextTools: function renderTextTools(_ref2) {
|
|
110
76
|
var TextTools = _ref2.components.TextTools,
|
|
111
|
-
|
|
112
|
-
|
|
77
|
+
props = _objectWithoutProperties(_ref2, _excluded);
|
|
113
78
|
return /*#__PURE__*/_react["default"].createElement(TextTools, _extends({
|
|
114
79
|
fontSizeList: [3, 9, 27]
|
|
115
80
|
}, props));
|
|
116
81
|
}
|
|
117
82
|
});
|
|
118
83
|
}
|
|
119
|
-
})))
|
|
84
|
+
})));
|
|
120
85
|
}
|
|
121
86
|
}]);
|
|
122
|
-
|
|
123
87
|
return App;
|
|
124
88
|
}(_react["default"].Component);
|
|
125
|
-
|
|
126
|
-
var _default = (0, _reactHotLoader.hot)(module)(App);
|
|
127
|
-
|
|
128
|
-
exports["default"] = _default;
|
|
89
|
+
var _default = exports["default"] = App;
|
package/index.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _react = _interopRequireDefault(require("react"));
|
|
4
|
-
|
|
5
|
-
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
6
|
-
|
|
4
|
+
var _client = require("react-dom/client");
|
|
7
5
|
var _App = _interopRequireDefault(require("./App"));
|
|
8
|
-
|
|
9
6
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
-
|
|
11
7
|
// demos
|
|
12
8
|
//import App from './_demos/UsingRenderProps/App';
|
|
13
9
|
//import App from './_demos/UsingExternalControls/App';
|
|
14
10
|
// basic usage
|
|
15
11
|
(function () {
|
|
16
|
-
|
|
12
|
+
(0, _client.createRoot)(document.getElementById('root')).render( /*#__PURE__*/_react["default"].createElement(_App["default"], null));
|
|
17
13
|
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redhotmagma-graphics-editor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.42.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./index.js",
|
|
@@ -13,14 +13,13 @@
|
|
|
13
13
|
"paper": "^0.12.17",
|
|
14
14
|
"path-browserify": "^1.0.1",
|
|
15
15
|
"prop-types": "^15.7.2",
|
|
16
|
-
"react": "^16.14.0",
|
|
17
|
-
"react-dom": "^16.14.0",
|
|
18
|
-
"react-hot-loader": "^4.13.0",
|
|
19
16
|
"text-to-svg": "^3.1.5",
|
|
20
17
|
"uuid": "^3.4.0"
|
|
21
18
|
},
|
|
22
19
|
"peerDependencies": {
|
|
23
|
-
"@material-ui/core": "
|
|
20
|
+
"@material-ui/core": ">=4.0.0",
|
|
21
|
+
"react": "^18.2.0",
|
|
22
|
+
"react-dom": "^18.2.0"
|
|
24
23
|
},
|
|
25
24
|
"jest": {
|
|
26
25
|
"roots": [
|
|
@@ -39,6 +38,5 @@
|
|
|
39
38
|
"json",
|
|
40
39
|
"node"
|
|
41
40
|
]
|
|
42
|
-
}
|
|
43
|
-
"readme": "# redhotmagma-graphics-editor\n\n## setup for development\n1. follow the \"preparation\", \"install\" and \"start development\" steps in frontend/README.md\n1. open the dev app in the browser: http://localhost:3002\n\n## development\n1. new features:\n - consider adding a demo to the dev app\n - write tests (if possible, interacting with the canvas element is not supported yet)\n1. CRs: \n - test the affected functionalities in the dev app\n - write tests and adjust existing ones if needed\n"
|
|
41
|
+
}
|
|
44
42
|
}
|
package/src/App.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
// It was made only for development and demo purposes!
|
|
6
6
|
|
|
7
7
|
import React from 'react';
|
|
8
|
-
import { AppContainer, hot } from 'react-hot-loader';
|
|
9
8
|
|
|
10
9
|
import { TextEditorStateProvider } from './Components/TextEditor/TextEditorStateProvider';
|
|
11
10
|
import Editor from './Components/Editor/Editor';
|
|
@@ -220,45 +219,43 @@ class App extends React.Component {
|
|
|
220
219
|
|
|
221
220
|
render() {
|
|
222
221
|
return (
|
|
223
|
-
<
|
|
224
|
-
<
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
<
|
|
237
|
-
|
|
238
|
-
<
|
|
239
|
-
|
|
240
|
-
<CanvasSelect onChange={this.switchCanvas} />
|
|
241
|
-
</div>
|
|
242
|
-
<div style={styles.demoGroup}>
|
|
243
|
-
<button onClick={this.saveCanvasData}>Save data</button>
|
|
244
|
-
<button onClick={this.loadCanvasData}>Load data</button>
|
|
245
|
-
<button onClick={this.clearCanvas}>Clear canvas</button>
|
|
246
|
-
</div>
|
|
247
|
-
<div style={styles.demoGroup}>
|
|
248
|
-
<button onClick={this.setFontSizeMin}>Set fontSizeMin to 20</button>
|
|
249
|
-
</div>
|
|
250
|
-
<div style={styles.demoGroup}>
|
|
251
|
-
<button onClick={this.screenshotToConsole}>Screenshot to console</button>
|
|
252
|
-
<button onClick={this.screenshotsToConsole}>Screenshots of Elements</button>
|
|
253
|
-
</div>
|
|
254
|
-
<div style={styles.demoGroup}>
|
|
255
|
-
<MaskSelect onChange={this.onMaskSelected} />
|
|
256
|
-
</div>
|
|
222
|
+
<CanvasProvider canvas={this.state.canvasInstance}>
|
|
223
|
+
<TextEditorStateProvider
|
|
224
|
+
defaultStyle={{
|
|
225
|
+
fontSize: '16px',
|
|
226
|
+
color: {
|
|
227
|
+
value: 'rgb(247, 52, 41)',
|
|
228
|
+
identifier: '{"color": "red", "palette": "f73429"}',
|
|
229
|
+
},
|
|
230
|
+
}}
|
|
231
|
+
>
|
|
232
|
+
<Editor upload={this.mockUploadFunction} EditorContainer={CustomEditorContainer} fillContainer />
|
|
233
|
+
</TextEditorStateProvider>
|
|
234
|
+
<div style={styles.demoWrapper}>
|
|
235
|
+
<span style={styles.demoLabel}>Demo features</span>
|
|
236
|
+
<div style={styles.demoGroup}>
|
|
237
|
+
<span style={styles.demoLabel}>Canvas repository</span>
|
|
238
|
+
<CanvasSelect onChange={this.switchCanvas} />
|
|
257
239
|
</div>
|
|
258
|
-
|
|
259
|
-
|
|
240
|
+
<div style={styles.demoGroup}>
|
|
241
|
+
<button onClick={this.saveCanvasData}>Save data</button>
|
|
242
|
+
<button onClick={this.loadCanvasData}>Load data</button>
|
|
243
|
+
<button onClick={this.clearCanvas}>Clear canvas</button>
|
|
244
|
+
</div>
|
|
245
|
+
<div style={styles.demoGroup}>
|
|
246
|
+
<button onClick={this.setFontSizeMin}>Set fontSizeMin to 20</button>
|
|
247
|
+
</div>
|
|
248
|
+
<div style={styles.demoGroup}>
|
|
249
|
+
<button onClick={this.screenshotToConsole}>Screenshot to console</button>
|
|
250
|
+
<button onClick={this.screenshotsToConsole}>Screenshots of Elements</button>
|
|
251
|
+
</div>
|
|
252
|
+
<div style={styles.demoGroup}>
|
|
253
|
+
<MaskSelect onChange={this.onMaskSelected} />
|
|
254
|
+
</div>
|
|
255
|
+
</div>
|
|
256
|
+
</CanvasProvider>
|
|
260
257
|
);
|
|
261
258
|
}
|
|
262
259
|
}
|
|
263
260
|
|
|
264
|
-
export default
|
|
261
|
+
export default App;
|
|
@@ -10,6 +10,7 @@ import { useMask } from './Utils/UseMask';
|
|
|
10
10
|
import { transformTextToPath } from './Utils/TextToSVGRepository';
|
|
11
11
|
import { removePlaceholders } from './Utils/HTML2Paper';
|
|
12
12
|
import { fixSvgExportResult, prepareSvgStr, wrapWithViewGroup } from './Utils/SVGfix';
|
|
13
|
+
import { useColorLayer } from './Utils/UseColorLayer';
|
|
13
14
|
|
|
14
15
|
const logger = new Logger('Canvas');
|
|
15
16
|
|
|
@@ -19,6 +20,7 @@ export class Canvas extends AbstractCanvas {
|
|
|
19
20
|
// prevents dragging out the object (by default lets dragging only up to the 2/3 of the object width)
|
|
20
21
|
protected _boundTolerance: number = 1 / 2 - 2 / 3;
|
|
21
22
|
protected _maskHandler: any | undefined = undefined;
|
|
23
|
+
protected _colorOverlay: any | undefined = undefined;
|
|
22
24
|
|
|
23
25
|
setBoundTolerance(value: number) {
|
|
24
26
|
this._boundTolerance = value;
|
|
@@ -156,6 +158,15 @@ export class Canvas extends AbstractCanvas {
|
|
|
156
158
|
return this._maskHandler;
|
|
157
159
|
}
|
|
158
160
|
|
|
161
|
+
useColorOverlay(colorLayerData) {
|
|
162
|
+
this._colorOverlay = useColorLayer(this._project, colorLayerData);
|
|
163
|
+
return this._colorOverlay;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
getColorOverlay() {
|
|
167
|
+
return this._colorOverlay;
|
|
168
|
+
}
|
|
169
|
+
|
|
159
170
|
onMouseDown(event) {
|
|
160
171
|
const { point } = event;
|
|
161
172
|
const hitResult = this._project.hitTest(point);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import paper from 'paper';
|
|
2
|
+
|
|
3
|
+
export const useColorLayer = (project, initialColorLayerData) => {
|
|
4
|
+
const designerLayer = project.layers.designerLayer;
|
|
5
|
+
let colorLayer;
|
|
6
|
+
|
|
7
|
+
if (!designerLayer) {
|
|
8
|
+
console.error('Missing designerLayer!');
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const init = colorLayerData => {
|
|
13
|
+
project.layers.colorLayer?.remove();
|
|
14
|
+
const color = colorLayerData?.color;
|
|
15
|
+
if (!color) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const path = new paper.Path.Rectangle(project.layers.designerLayer.view.bounds);
|
|
19
|
+
path.fillColor = color;
|
|
20
|
+
colorLayer = new paper.Layer({
|
|
21
|
+
name: 'colorLayer',
|
|
22
|
+
children: [path],
|
|
23
|
+
locked: true,
|
|
24
|
+
});
|
|
25
|
+
colorLayer.blendMode = 'source-in';
|
|
26
|
+
project.addLayer(colorLayer);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const toggle = on => {
|
|
30
|
+
if (!colorLayer) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const onOrig = colorLayer.visible;
|
|
34
|
+
colorLayer.visible = on;
|
|
35
|
+
project.view.update();
|
|
36
|
+
return () => {
|
|
37
|
+
if (onOrig !== on) {
|
|
38
|
+
colorLayer.visible = onOrig;
|
|
39
|
+
project.view.update();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const dispose = () => {
|
|
45
|
+
colorLayer?.remove();
|
|
46
|
+
colorLayer = null;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
init(initialColorLayerData);
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
init,
|
|
53
|
+
toggle,
|
|
54
|
+
dispose,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import
|
|
3
|
+
import get from 'lodash/get';
|
|
4
4
|
import withStyles from '@material-ui/core/styles/withStyles';
|
|
5
5
|
|
|
6
6
|
import ManipulableContainer from '../ManipulableContainer';
|
|
@@ -29,7 +29,7 @@ class InlineToolBox extends React.Component {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
static defaultProps = {
|
|
32
|
-
ContainerComponent:
|
|
32
|
+
ContainerComponent: ({ children }) => <>{children}</>,
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
state = {
|
|
@@ -128,7 +128,7 @@ export class TextTools extends React.Component {
|
|
|
128
128
|
resetDefaultStyle();
|
|
129
129
|
}
|
|
130
130
|
const colorChanged = currentStyle.color.value !== prevProps.textEditorState.currentStyle.color.value;
|
|
131
|
-
if (colorChanged && editorContent.innerText.trim() === '') {
|
|
131
|
+
if (colorChanged && editorContent && editorContent.innerText && editorContent.innerText.trim() === '') {
|
|
132
132
|
updateDefaultStyle({
|
|
133
133
|
color: currentStyle.color,
|
|
134
134
|
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { AppContainer, hot } from 'react-hot-loader';
|
|
3
2
|
|
|
4
3
|
import { Canvas } from '../../CanvasAdapters/PaperJs';
|
|
5
4
|
import Editor from '../../Components/Editor/Editor';
|
|
@@ -24,34 +23,32 @@ class App extends React.Component {
|
|
|
24
23
|
|
|
25
24
|
render() {
|
|
26
25
|
return (
|
|
27
|
-
<
|
|
28
|
-
<
|
|
29
|
-
<
|
|
30
|
-
<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
>
|
|
46
|
-
<
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
</CanvasProvider>
|
|
52
|
-
</AppContainer>
|
|
26
|
+
<CanvasProvider canvas={canvas}>
|
|
27
|
+
<TextEditorStateProvider defaultStyle={{ fontSize: '16px' }}>
|
|
28
|
+
<div style={{ position: 'absolute', top: 100, left: 0, width: 600, height: 200 }}>
|
|
29
|
+
<Editor
|
|
30
|
+
canvasSize={{ width: 3000, height: 1000 }}
|
|
31
|
+
upload={this.mockUploadFunction}
|
|
32
|
+
renderSelectionToolbox={() => null}
|
|
33
|
+
/>
|
|
34
|
+
</div>
|
|
35
|
+
<div
|
|
36
|
+
style={{
|
|
37
|
+
position: 'absolute',
|
|
38
|
+
top: '50%',
|
|
39
|
+
transform: 'translateY(-50%)',
|
|
40
|
+
right: 0,
|
|
41
|
+
width: 500,
|
|
42
|
+
}}
|
|
43
|
+
>
|
|
44
|
+
<CanvasStateProvider canvas={canvas}>
|
|
45
|
+
<SelectionToolbox />
|
|
46
|
+
</CanvasStateProvider>
|
|
47
|
+
</div>
|
|
48
|
+
</TextEditorStateProvider>
|
|
49
|
+
</CanvasProvider>
|
|
53
50
|
);
|
|
54
51
|
}
|
|
55
52
|
}
|
|
56
53
|
|
|
57
|
-
export default
|
|
54
|
+
export default App;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { AppContainer, hot } from 'react-hot-loader';
|
|
3
2
|
|
|
4
3
|
import { Canvas } from '../../CanvasAdapters/PaperJs';
|
|
5
4
|
import Editor from '../../Components/Editor/Editor';
|
|
@@ -23,25 +22,23 @@ class App extends React.Component {
|
|
|
23
22
|
|
|
24
23
|
render() {
|
|
25
24
|
return (
|
|
26
|
-
<
|
|
27
|
-
<
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
</CanvasProvider>
|
|
42
|
-
</AppContainer>
|
|
25
|
+
<CanvasProvider canvas={canvas}>
|
|
26
|
+
<TextEditorStateProvider defaultStyle={{ fontSize: '16px' }}>
|
|
27
|
+
<Editor
|
|
28
|
+
canvasSize={{ width: 1000, height: 800 }}
|
|
29
|
+
upload={this.mockUploadFunction}
|
|
30
|
+
renderSelectionToolbox={({ components: { SelectionToolbox } }) => (
|
|
31
|
+
<SelectionToolbox
|
|
32
|
+
renderTextTools={({ components: { TextTools }, ...props }) => (
|
|
33
|
+
<TextTools fontSizeList={[3, 9, 27]} {...props} />
|
|
34
|
+
)}
|
|
35
|
+
/>
|
|
36
|
+
)}
|
|
37
|
+
/>
|
|
38
|
+
</TextEditorStateProvider>
|
|
39
|
+
</CanvasProvider>
|
|
43
40
|
);
|
|
44
41
|
}
|
|
45
42
|
}
|
|
46
43
|
|
|
47
|
-
export default
|
|
44
|
+
export default App;
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { createRoot } from 'react-dom/client';
|
|
3
3
|
|
|
4
4
|
// demos
|
|
5
5
|
//import App from './_demos/UsingRenderProps/App';
|
|
@@ -9,5 +9,5 @@ import ReactDOM from 'react-dom';
|
|
|
9
9
|
import App from './App';
|
|
10
10
|
|
|
11
11
|
(() => {
|
|
12
|
-
|
|
12
|
+
createRoot(document.getElementById('root')).render(<App />);
|
|
13
13
|
})();
|