redhotmagma-graphics-editor 1.28.0-beta.2 → 1.28.2
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/.babelrc +23 -0
- package/README.md +4 -11
- package/package.json +63 -4
- package/scripts/moveLibToPackageRoot.js +41 -0
- package/scripts/utils/process.js +19 -0
- package/App.js +0 -423
- package/CanvasAdapters/Mock/Canvas.js +0 -200
- package/CanvasAdapters/Mock/Objects/CanvasObject.js +0 -155
- package/CanvasAdapters/Mock/Objects/Group.js +0 -102
- package/CanvasAdapters/Mock/Objects/Image.js +0 -102
- package/CanvasAdapters/Mock/Objects/Text.js +0 -121
- package/CanvasAdapters/Mock/index.js +0 -13
- package/CanvasAdapters/PaperJs/Canvas.js +0 -830
- package/CanvasAdapters/PaperJs/CanvasRepository.js +0 -65
- package/CanvasAdapters/PaperJs/Modifiers/FontSizeMin.js +0 -16
- package/CanvasAdapters/PaperJs/Objects/CanvasObject.js +0 -227
- package/CanvasAdapters/PaperJs/Objects/Group.js +0 -113
- package/CanvasAdapters/PaperJs/Objects/Image.js +0 -225
- package/CanvasAdapters/PaperJs/Objects/Text.js +0 -312
- package/CanvasAdapters/PaperJs/Utils/HTML2Paper.js +0 -301
- package/CanvasAdapters/PaperJs/Utils/SVGfix.js +0 -67
- package/CanvasAdapters/PaperJs/Utils/StyleParams.js +0 -68
- package/CanvasAdapters/PaperJs/Utils/TextToSVGRepository.js +0 -179
- package/CanvasAdapters/PaperJs/Utils/TextToSVGUtils.js +0 -32
- package/CanvasAdapters/PaperJs/Utils/UTF8Base64.js +0 -123
- package/CanvasAdapters/PaperJs/Utils/UseMask.js +0 -475
- package/CanvasAdapters/PaperJs/Utils/__tests__/SVGfix.test.js +0 -29
- package/CanvasAdapters/PaperJs/Utils/__tests__/TextToSVGUtils.test.js +0 -17
- package/CanvasAdapters/PaperJs/Utils/__tests__/updateFontStyle.test.js +0 -16
- package/CanvasAdapters/PaperJs/Utils/updateFontStyle.js +0 -35
- package/CanvasAdapters/PaperJs/index.js +0 -13
- package/CanvasInterface/Canvas.js +0 -633
- package/CanvasInterface/CanvasProvider.js +0 -196
- package/CanvasInterface/CanvasSize.d.js +0 -5
- package/CanvasInterface/Objects/CanvasObject.js +0 -510
- package/CanvasInterface/Objects/Group.js +0 -5
- package/CanvasInterface/Objects/Image.js +0 -5
- package/CanvasInterface/Objects/Text.js +0 -5
- package/CanvasInterface/Objects/index.js +0 -13
- package/CanvasInterface/Observable.js +0 -97
- package/CanvasInterface/canvasConnect.js +0 -115
- package/CanvasInterface/index.js +0 -24
- package/Components/Canvas/Canvas.js +0 -78
- package/Components/Canvas/CanvasContainer.js +0 -52
- package/Components/Canvas/styles.js +0 -21
- package/Components/DelayedContainer.js +0 -87
- package/Components/Editor/Editor.js +0 -327
- package/Components/Editor/EditorContainer.js +0 -361
- package/Components/Editor/styles.js +0 -24
- package/Components/InlineToolbox/InlineToolbox.js +0 -493
- package/Components/InlineToolbox/InlineToolboxButton.js +0 -42
- package/Components/InlineToolbox/styles.js +0 -27
- package/Components/ManipulableContainer.js +0 -105
- package/Components/ResizeDetect/ResizeDetect.js +0 -117
- package/Components/Rulers/Ruler.js +0 -213
- package/Components/Rulers/Rulers.js +0 -96
- package/Components/Rulers/styles.js +0 -37
- package/Components/SelectionToolbox/ColorPalette.js +0 -283
- package/Components/SelectionToolbox/SelectionToolbox.js +0 -319
- package/Components/SelectionToolbox/TextTools.js +0 -445
- package/Components/SelectionToolbox/styles.js +0 -18
- package/Components/StandardToolbox/StandardToolbox.js +0 -234
- package/Components/TextEditor/TextEditor.js +0 -592
- package/Components/TextEditor/TextEditorStateProvider.js +0 -147
- package/Components/Toolbox/ToolboxContainer.js +0 -39
- package/Components/Toolbox/ToolboxRow.js +0 -36
- package/Components/Toolbox/styles.js +0 -21
- package/Utils/Calc2D.js +0 -25
- package/Utils/DOM.js +0 -238
- package/Utils/Device.js +0 -20
- package/Utils/Image.js +0 -47
- package/Utils/Logger.js +0 -89
- package/Utils/Range.js +0 -135
- package/Utils/String.js +0 -42
- package/Utils/UnitConversion.js +0 -21
- package/Utils/__tests__/Calc2D.test.js +0 -41
- package/Utils/__tests__/DOM.test.js +0 -170
- package/Utils/__tests__/Range.test.js +0 -52
- package/_demos/UsingExternalControls/App.js +0 -130
- package/_demos/UsingRenderProps/App.js +0 -128
- package/index.js +0 -17
package/.babelrc
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"presets": [
|
|
3
|
+
"@babel/env",
|
|
4
|
+
"@babel/typescript",
|
|
5
|
+
"@babel/react"
|
|
6
|
+
],
|
|
7
|
+
"plugins": [
|
|
8
|
+
"@babel/plugin-transform-async-to-generator",
|
|
9
|
+
"@babel/plugin-proposal-class-properties",
|
|
10
|
+
["module-resolver", {
|
|
11
|
+
"root": ["./src"]
|
|
12
|
+
}]
|
|
13
|
+
],
|
|
14
|
+
"env": {
|
|
15
|
+
"test": {
|
|
16
|
+
"presets": [
|
|
17
|
+
"@babel/env",
|
|
18
|
+
"@babel/typescript",
|
|
19
|
+
"@babel/react"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
package/README.md
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
# redhotmagma-graphics-editor
|
|
2
2
|
|
|
3
|
-
##
|
|
4
|
-
1.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## development
|
|
8
|
-
1. new features:
|
|
9
|
-
- consider adding a demo to the dev app
|
|
10
|
-
- write tests (if possible, interacting with the canvas element is not supported yet)
|
|
11
|
-
1. CRs:
|
|
12
|
-
- test the affected functionalities in the dev app
|
|
13
|
-
- write tests and adjust existing ones if needed
|
|
3
|
+
## Setup for Development
|
|
4
|
+
1. Install NodeJs `> 8.x`
|
|
5
|
+
2. `npm install`
|
|
6
|
+
3. `npm start`
|
package/package.json
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redhotmagma-graphics-editor",
|
|
3
|
-
"version": "1.28.
|
|
3
|
+
"version": "1.28.2",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"private": false,
|
|
6
|
-
"main": "./index.js",
|
|
6
|
+
"main": "./lib/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"src",
|
|
10
|
+
"scripts",
|
|
11
|
+
".babelrc"
|
|
12
|
+
],
|
|
7
13
|
"dependencies": {
|
|
14
|
+
"@babel/cli": "^7.13.14",
|
|
15
|
+
"@babel/core": "^7.13.14",
|
|
16
|
+
"@babel/plugin-proposal-class-properties": "^7.13.0",
|
|
17
|
+
"@babel/plugin-transform-async-to-generator": "^7.13.0",
|
|
8
18
|
"@babel/polyfill": "^7.12.1",
|
|
9
|
-
"
|
|
19
|
+
"@babel/preset-env": "^7.13.12",
|
|
20
|
+
"@babel/preset-react": "^7.13.13",
|
|
21
|
+
"@babel/preset-typescript": "^7.13.0",
|
|
22
|
+
"@typescript-eslint/eslint-plugin": "^3.4.0",
|
|
23
|
+
"@typescript-eslint/parser": "^3.4.0",
|
|
24
|
+
"babel-loader": "^8.2.2",
|
|
25
|
+
"babel-plugin-module-resolver": "^4.1.0",
|
|
10
26
|
"console-polyfill": "^0.3.0",
|
|
27
|
+
"cross-env": "^7.0.3",
|
|
11
28
|
"css-element-queries": "^1.2.3",
|
|
12
29
|
"lodash": "^4.17.21",
|
|
13
30
|
"paper": "^0.12.15",
|
|
@@ -16,12 +33,54 @@
|
|
|
16
33
|
"react": "^16.14.0",
|
|
17
34
|
"react-dom": "^16.14.0",
|
|
18
35
|
"react-hot-loader": "^4.13.0",
|
|
36
|
+
"rimraf": "^3.0.2",
|
|
19
37
|
"text-to-svg": "^3.1.5",
|
|
20
38
|
"uuid": "^3.4.0"
|
|
21
39
|
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@material-ui/core": "^4.11.3",
|
|
42
|
+
"@types/jest": "^26.0.22",
|
|
43
|
+
"@types/lodash": "^4.14.168",
|
|
44
|
+
"@types/paper": "^0.12.3",
|
|
45
|
+
"babel-eslint": "^10.1.0",
|
|
46
|
+
"babel-jest": "^26.6.3",
|
|
47
|
+
"enzyme": "^3.11.0",
|
|
48
|
+
"eslint": "^6.3.0",
|
|
49
|
+
"eslint-config-prettier": "^4.3.0",
|
|
50
|
+
"eslint-plugin-import": "^2.22.1",
|
|
51
|
+
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
52
|
+
"eslint-plugin-prettier": "^3.3.1",
|
|
53
|
+
"eslint-plugin-react": "^7.23.1",
|
|
54
|
+
"eslint-plugin-react-hooks": "^2.5.1",
|
|
55
|
+
"husky": "^3.1.0",
|
|
56
|
+
"jest": "^26.6.3",
|
|
57
|
+
"jest-enzyme": "^7.1.2",
|
|
58
|
+
"jsdom": "^16.5.2",
|
|
59
|
+
"lint-staged": "^9.5.0",
|
|
60
|
+
"prettier": "^1.19.1",
|
|
61
|
+
"react-test-renderer": "^16.14.0",
|
|
62
|
+
"sinon": "^10.0.0",
|
|
63
|
+
"ts-jest": "^26.5.4",
|
|
64
|
+
"typescript": "^4.2.3",
|
|
65
|
+
"webpack": "^5.28.0",
|
|
66
|
+
"webpack-cli": "^4.6.0",
|
|
67
|
+
"webpack-dev-server": "^3.11.2"
|
|
68
|
+
},
|
|
22
69
|
"peerDependencies": {
|
|
23
70
|
"@material-ui/core": "*"
|
|
24
71
|
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"start": "webpack serve --port 3002",
|
|
74
|
+
"package": "npm run package:clean && npm run package:compile && npm run package:after",
|
|
75
|
+
"package:clean": "rimraf ./lib",
|
|
76
|
+
"package:compile": "cross-env NODE_ENV=production babel ./src --out-dir ./lib --extensions .ts,.tsx,.js,.jsx",
|
|
77
|
+
"package:after": "node ./scripts/moveLibToPackageRoot.js",
|
|
78
|
+
"install": "npm run package",
|
|
79
|
+
"test": "jest",
|
|
80
|
+
"lint": "eslint ./ --ext .js,.jsx,.ts",
|
|
81
|
+
"lint-ci": "eslint ./ --ext .js,.jsx,.ts -c .eslintrc.ci.json --quiet",
|
|
82
|
+
"lint-fix": "eslint ./ --ext .js,.jsx,.ts --fix"
|
|
83
|
+
},
|
|
25
84
|
"jest": {
|
|
26
85
|
"roots": [
|
|
27
86
|
"<rootDir>/src"
|
|
@@ -40,4 +99,4 @@
|
|
|
40
99
|
"node"
|
|
41
100
|
]
|
|
42
101
|
}
|
|
43
|
-
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const rimraf = require('rimraf');
|
|
4
|
+
const { isDependency } = require('./utils/process');
|
|
5
|
+
|
|
6
|
+
function walk(dir, cb, cbAfter) {
|
|
7
|
+
try {
|
|
8
|
+
const files = fs.readdirSync(dir);
|
|
9
|
+
for (const f of files) {
|
|
10
|
+
const cf = path.resolve(dir, f);
|
|
11
|
+
const s = fs.lstatSync(cf);
|
|
12
|
+
cb && cb(cf);
|
|
13
|
+
s.isDirectory() && walk(cf, cb, cbAfter);
|
|
14
|
+
cbAfter && cbAfter(cf);
|
|
15
|
+
}
|
|
16
|
+
} catch (e) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (isDependency()) {
|
|
22
|
+
console.log('\x1b[37m\x1b[42m%s\x1b[0m', 'Moving content of lib into the root package directory');
|
|
23
|
+
|
|
24
|
+
const src = path.resolve(__dirname, '../', 'lib');
|
|
25
|
+
const dst = path.resolve(__dirname, '../');
|
|
26
|
+
walk(src, function(file) {
|
|
27
|
+
const relativePath = file.replace(src, '');
|
|
28
|
+
const tp = path.resolve(dst + relativePath);
|
|
29
|
+
if (fs.statSync(file).isFile()) {
|
|
30
|
+
fs.createReadStream(file).pipe(fs.createWriteStream(tp));
|
|
31
|
+
} else {
|
|
32
|
+
fs.mkdirSync(tp);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
rimraf(src, function(err) {
|
|
37
|
+
if (err) {
|
|
38
|
+
console.log('Error occured while clearing the directory: ' + src, err);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* These utils are made to simplify querying process information for the node scripts.
|
|
3
|
+
*
|
|
4
|
+
* @author boda@redhotmagma.de
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Checks if the current installation process is a dependency installation
|
|
9
|
+
* @return {boolean}
|
|
10
|
+
*/
|
|
11
|
+
function isDependency() {
|
|
12
|
+
// if the path of the initial directory contains 'node_modules', it's probably installed as a dependency
|
|
13
|
+
const { INIT_CWD } = process.env;
|
|
14
|
+
return INIT_CWD.indexOf('node_modules') !== -1;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
isDependency,
|
|
19
|
+
};
|
package/App.js
DELETED
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = void 0;
|
|
9
|
-
|
|
10
|
-
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
|
-
var _reactHotLoader = require("react-hot-loader");
|
|
13
|
-
|
|
14
|
-
var _TextEditorStateProvider = require("./Components/TextEditor/TextEditorStateProvider");
|
|
15
|
-
|
|
16
|
-
var _Editor = _interopRequireDefault(require("./Components/Editor/Editor"));
|
|
17
|
-
|
|
18
|
-
var _CanvasProvider = require("./CanvasInterface/CanvasProvider");
|
|
19
|
-
|
|
20
|
-
var _FontSizeMin = require("./CanvasAdapters/PaperJs/Modifiers/FontSizeMin");
|
|
21
|
-
|
|
22
|
-
var _CanvasRepository = require("./CanvasAdapters/PaperJs/CanvasRepository");
|
|
23
|
-
|
|
24
|
-
var _EditorContainer = _interopRequireDefault(require("./Components/Editor/EditorContainer"));
|
|
25
|
-
|
|
26
|
-
var _excluded = ["children"];
|
|
27
|
-
|
|
28
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
29
|
-
|
|
30
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
31
|
-
|
|
32
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
33
|
-
|
|
34
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
35
|
-
|
|
36
|
-
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, descriptor.key, descriptor); } }
|
|
37
|
-
|
|
38
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
39
|
-
|
|
40
|
-
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); }
|
|
41
|
-
|
|
42
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
43
|
-
|
|
44
|
-
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); }; }
|
|
45
|
-
|
|
46
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
47
|
-
|
|
48
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
49
|
-
|
|
50
|
-
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; } }
|
|
51
|
-
|
|
52
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
53
|
-
|
|
54
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
55
|
-
|
|
56
|
-
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; }
|
|
57
|
-
|
|
58
|
-
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; }
|
|
59
|
-
|
|
60
|
-
console.warn('Do not use this App component directly! It was made only for development and demo purposes!');
|
|
61
|
-
var canvasRepository = (0, _CanvasRepository.createCanvasRepository)();
|
|
62
|
-
|
|
63
|
-
canvasRepository.onCreate = function (canvas) {
|
|
64
|
-
return console.log('Canvas is ready', canvas);
|
|
65
|
-
}; // expose canvasRepository to window
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
window.canvasRepository = canvasRepository;
|
|
69
|
-
var canvases = {
|
|
70
|
-
c1: {
|
|
71
|
-
width: 100,
|
|
72
|
-
height: 80,
|
|
73
|
-
dpi: 300,
|
|
74
|
-
isMetric: true
|
|
75
|
-
},
|
|
76
|
-
c2: {
|
|
77
|
-
width: 300,
|
|
78
|
-
height: 600
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
var maskDataSamples = [{
|
|
82
|
-
id: 'iphone',
|
|
83
|
-
src: 'assets/iphone-mask.svg',
|
|
84
|
-
x: 0.5,
|
|
85
|
-
y: 0.5,
|
|
86
|
-
rotation: 0,
|
|
87
|
-
scaling: 1.5,
|
|
88
|
-
outlineColor: 'red',
|
|
89
|
-
relativeScaling: 0.5
|
|
90
|
-
}, {
|
|
91
|
-
id: 'circle',
|
|
92
|
-
src: 'assets/circle-mask.svg',
|
|
93
|
-
x: 0.5,
|
|
94
|
-
y: 0.5,
|
|
95
|
-
rotation: 0,
|
|
96
|
-
scaling: 5,
|
|
97
|
-
relativeScaling: 1,
|
|
98
|
-
outlineColor: 'green'
|
|
99
|
-
}, {
|
|
100
|
-
id: 'clip',
|
|
101
|
-
src: 'assets/clip-mask.svg',
|
|
102
|
-
x: 0.5,
|
|
103
|
-
y: 0.5,
|
|
104
|
-
rotation: 0,
|
|
105
|
-
scaling: 1,
|
|
106
|
-
relativeScaling: 1,
|
|
107
|
-
outlineColor: 'red'
|
|
108
|
-
}];
|
|
109
|
-
var fontToFileMap = {
|
|
110
|
-
'sans-serif': {
|
|
111
|
-
regular: '/fonts/Arcon-Regular.otf'
|
|
112
|
-
},
|
|
113
|
-
'Arial, Helvetica, sans-serif': {
|
|
114
|
-
regular: '/fonts/Arcon-Regular.otf',
|
|
115
|
-
bold: '/fonts/Arcon-Regular.otf'
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
var styles = {
|
|
119
|
-
demoWrapper: {
|
|
120
|
-
position: 'absolute',
|
|
121
|
-
top: 0,
|
|
122
|
-
right: 0,
|
|
123
|
-
background: 'yellow',
|
|
124
|
-
padding: 10
|
|
125
|
-
},
|
|
126
|
-
demoGroup: {
|
|
127
|
-
marginTop: 5
|
|
128
|
-
},
|
|
129
|
-
demoLabel: {
|
|
130
|
-
padding: '0 5px'
|
|
131
|
-
},
|
|
132
|
-
demoExtraContent: {
|
|
133
|
-
position: 'absolute',
|
|
134
|
-
top: 100,
|
|
135
|
-
fontSize: 20
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
var CustomEditorContainer = function CustomEditorContainer(_ref) {
|
|
140
|
-
var children = _ref.children,
|
|
141
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
142
|
-
|
|
143
|
-
return /*#__PURE__*/_react["default"].createElement(_EditorContainer["default"], props, /*#__PURE__*/_react["default"].createElement("div", {
|
|
144
|
-
style: styles.demoExtraContent
|
|
145
|
-
}, "This is how to add extra content inside the EditorContainer"), children);
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
var CanvasSelect = function CanvasSelect(_ref2) {
|
|
149
|
-
var onChange = _ref2.onChange;
|
|
150
|
-
return Object.keys(canvases).map(function (id, i) {
|
|
151
|
-
return /*#__PURE__*/_react["default"].createElement("button", {
|
|
152
|
-
key: i,
|
|
153
|
-
onClick: onChange,
|
|
154
|
-
value: id
|
|
155
|
-
}, id);
|
|
156
|
-
});
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
var MaskSelect = function MaskSelect(_ref3) {
|
|
160
|
-
var onChange = _ref3.onChange;
|
|
161
|
-
return /*#__PURE__*/_react["default"].createElement("select", {
|
|
162
|
-
name: "maskData",
|
|
163
|
-
onChange: onChange
|
|
164
|
-
}, /*#__PURE__*/_react["default"].createElement("option", {
|
|
165
|
-
value: ""
|
|
166
|
-
}, "Choose mask"), maskDataSamples.map(function (maskData, i) {
|
|
167
|
-
return /*#__PURE__*/_react["default"].createElement("option", {
|
|
168
|
-
key: i,
|
|
169
|
-
value: maskData.name
|
|
170
|
-
}, maskData.id);
|
|
171
|
-
}));
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
var App = /*#__PURE__*/function (_React$Component) {
|
|
175
|
-
_inherits(App, _React$Component);
|
|
176
|
-
|
|
177
|
-
var _super = _createSuper(App);
|
|
178
|
-
|
|
179
|
-
function App() {
|
|
180
|
-
var _this;
|
|
181
|
-
|
|
182
|
-
_classCallCheck(this, App);
|
|
183
|
-
|
|
184
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
185
|
-
args[_key] = arguments[_key];
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
189
|
-
|
|
190
|
-
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
191
|
-
canvasInstance: canvasRepository.requestCanvas('c1', canvases.c1)
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
_defineProperty(_assertThisInitialized(_this), "mockUploadFunction", function (files) {
|
|
195
|
-
return new Promise(function (resolve, reject) {
|
|
196
|
-
var reader = new FileReader();
|
|
197
|
-
|
|
198
|
-
reader.onload = function () {
|
|
199
|
-
var dataURL = reader.result;
|
|
200
|
-
resolve([{
|
|
201
|
-
src: dataURL
|
|
202
|
-
}]);
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
reader.onerror = reject;
|
|
206
|
-
reader.readAsDataURL(files[0]);
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
_defineProperty(_assertThisInitialized(_this), "saveCanvasData", function () {
|
|
211
|
-
var canvasData = canvasRepository.getActiveCanvas().toObject(true, {
|
|
212
|
-
includeObjects: true
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
if (window.localStorage) {
|
|
216
|
-
localStorage.setItem('savedCanvasData', canvasData);
|
|
217
|
-
console.log('canvas saved!');
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
_defineProperty(_assertThisInitialized(_this), "loadCanvasData", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
222
|
-
var canvasData;
|
|
223
|
-
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
224
|
-
while (1) {
|
|
225
|
-
switch (_context.prev = _context.next) {
|
|
226
|
-
case 0:
|
|
227
|
-
if (!window.localStorage) {
|
|
228
|
-
_context.next = 13;
|
|
229
|
-
break;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
_context.prev = 1;
|
|
233
|
-
canvasData = JSON.parse(localStorage.getItem('savedCanvasData'));
|
|
234
|
-
|
|
235
|
-
if (!canvasData) {
|
|
236
|
-
_context.next = 7;
|
|
237
|
-
break;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
_context.next = 6;
|
|
241
|
-
return canvasRepository.getActiveCanvas().fromObject(canvasData);
|
|
242
|
-
|
|
243
|
-
case 6:
|
|
244
|
-
console.log('canvas loaded!');
|
|
245
|
-
|
|
246
|
-
case 7:
|
|
247
|
-
_context.next = 13;
|
|
248
|
-
break;
|
|
249
|
-
|
|
250
|
-
case 9:
|
|
251
|
-
_context.prev = 9;
|
|
252
|
-
_context.t0 = _context["catch"](1);
|
|
253
|
-
console.error(_context.t0);
|
|
254
|
-
alert('Could not load data!');
|
|
255
|
-
|
|
256
|
-
case 13:
|
|
257
|
-
case "end":
|
|
258
|
-
return _context.stop();
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}, _callee, null, [[1, 9]]);
|
|
262
|
-
})));
|
|
263
|
-
|
|
264
|
-
_defineProperty(_assertThisInitialized(_this), "setFontSizeMin", function () {
|
|
265
|
-
return (0, _FontSizeMin.applyFontSizeMin)(canvasRepository.getActiveCanvas(), 20);
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
_defineProperty(_assertThisInitialized(_this), "clearCanvas", function () {
|
|
269
|
-
return canvasRepository.getActiveCanvas().clear();
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
_defineProperty(_assertThisInitialized(_this), "switchCanvas", function (_ref5) {
|
|
273
|
-
var value = _ref5.target.value;
|
|
274
|
-
|
|
275
|
-
_this.setState({
|
|
276
|
-
canvasInstance: canvasRepository.requestCanvas(value, canvases[value])
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
_defineProperty(_assertThisInitialized(_this), "screenshotToConsole", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
281
|
-
var screenshot;
|
|
282
|
-
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
283
|
-
while (1) {
|
|
284
|
-
switch (_context2.prev = _context2.next) {
|
|
285
|
-
case 0:
|
|
286
|
-
console.time('screenshot');
|
|
287
|
-
_context2.next = 3;
|
|
288
|
-
return canvasRepository.getActiveCanvas().getScreenshot(fontToFileMap);
|
|
289
|
-
|
|
290
|
-
case 3:
|
|
291
|
-
screenshot = _context2.sent;
|
|
292
|
-
console.log('Screenshot:', screenshot);
|
|
293
|
-
console.timeEnd('screenshot');
|
|
294
|
-
|
|
295
|
-
case 6:
|
|
296
|
-
case "end":
|
|
297
|
-
return _context2.stop();
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}, _callee2);
|
|
301
|
-
})));
|
|
302
|
-
|
|
303
|
-
_defineProperty(_assertThisInitialized(_this), "screenshotsToConsole", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
|
|
304
|
-
var elements;
|
|
305
|
-
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
306
|
-
while (1) {
|
|
307
|
-
switch (_context3.prev = _context3.next) {
|
|
308
|
-
case 0:
|
|
309
|
-
_context3.next = 2;
|
|
310
|
-
return canvasRepository.getActiveCanvas().getScreenshotsOfElements(fontToFileMap);
|
|
311
|
-
|
|
312
|
-
case 2:
|
|
313
|
-
elements = _context3.sent;
|
|
314
|
-
console.log(elements);
|
|
315
|
-
|
|
316
|
-
case 4:
|
|
317
|
-
case "end":
|
|
318
|
-
return _context3.stop();
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}, _callee3);
|
|
322
|
-
})));
|
|
323
|
-
|
|
324
|
-
_defineProperty(_assertThisInitialized(_this), "onMaskSelected", /*#__PURE__*/function () {
|
|
325
|
-
var _ref8 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(_ref9) {
|
|
326
|
-
var value, maskHandler, maskData;
|
|
327
|
-
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
328
|
-
while (1) {
|
|
329
|
-
switch (_context4.prev = _context4.next) {
|
|
330
|
-
case 0:
|
|
331
|
-
value = _ref9.target.value;
|
|
332
|
-
maskHandler = canvasRepository.getActiveCanvas().getMaskHandler();
|
|
333
|
-
|
|
334
|
-
if (!value) {
|
|
335
|
-
_context4.next = 6;
|
|
336
|
-
break;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
maskData = maskDataSamples.filter(function (_ref10) {
|
|
340
|
-
var id = _ref10.id;
|
|
341
|
-
return id === value;
|
|
342
|
-
})[0];
|
|
343
|
-
_context4.next = 6;
|
|
344
|
-
return canvasRepository.getActiveCanvas().useMask(maskData);
|
|
345
|
-
|
|
346
|
-
case 6:
|
|
347
|
-
maskHandler && maskHandler.dispose();
|
|
348
|
-
|
|
349
|
-
case 7:
|
|
350
|
-
case "end":
|
|
351
|
-
return _context4.stop();
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}, _callee4);
|
|
355
|
-
}));
|
|
356
|
-
|
|
357
|
-
return function (_x) {
|
|
358
|
-
return _ref8.apply(this, arguments);
|
|
359
|
-
};
|
|
360
|
-
}());
|
|
361
|
-
|
|
362
|
-
return _this;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
_createClass(App, [{
|
|
366
|
-
key: "render",
|
|
367
|
-
value: function render() {
|
|
368
|
-
return /*#__PURE__*/_react["default"].createElement(_reactHotLoader.AppContainer, null, /*#__PURE__*/_react["default"].createElement(_CanvasProvider.CanvasProvider, {
|
|
369
|
-
canvas: this.state.canvasInstance
|
|
370
|
-
}, /*#__PURE__*/_react["default"].createElement(_TextEditorStateProvider.TextEditorStateProvider, {
|
|
371
|
-
defaultStyle: {
|
|
372
|
-
fontSize: '16px',
|
|
373
|
-
color: {
|
|
374
|
-
value: 'rgb(247, 52, 41)',
|
|
375
|
-
identifier: '{"color": "red", "palette": "f73429"}'
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}, /*#__PURE__*/_react["default"].createElement(_Editor["default"], {
|
|
379
|
-
upload: this.mockUploadFunction,
|
|
380
|
-
EditorContainer: CustomEditorContainer,
|
|
381
|
-
fillContainer: true
|
|
382
|
-
})), /*#__PURE__*/_react["default"].createElement("div", {
|
|
383
|
-
style: styles.demoWrapper
|
|
384
|
-
}, /*#__PURE__*/_react["default"].createElement("span", {
|
|
385
|
-
style: styles.demoLabel
|
|
386
|
-
}, "Demo features"), /*#__PURE__*/_react["default"].createElement("div", {
|
|
387
|
-
style: styles.demoGroup
|
|
388
|
-
}, /*#__PURE__*/_react["default"].createElement("span", {
|
|
389
|
-
style: styles.demoLabel
|
|
390
|
-
}, "Canvas repository"), /*#__PURE__*/_react["default"].createElement(CanvasSelect, {
|
|
391
|
-
onChange: this.switchCanvas
|
|
392
|
-
})), /*#__PURE__*/_react["default"].createElement("div", {
|
|
393
|
-
style: styles.demoGroup
|
|
394
|
-
}, /*#__PURE__*/_react["default"].createElement("button", {
|
|
395
|
-
onClick: this.saveCanvasData
|
|
396
|
-
}, "Save data"), /*#__PURE__*/_react["default"].createElement("button", {
|
|
397
|
-
onClick: this.loadCanvasData
|
|
398
|
-
}, "Load data"), /*#__PURE__*/_react["default"].createElement("button", {
|
|
399
|
-
onClick: this.clearCanvas
|
|
400
|
-
}, "Clear canvas")), /*#__PURE__*/_react["default"].createElement("div", {
|
|
401
|
-
style: styles.demoGroup
|
|
402
|
-
}, /*#__PURE__*/_react["default"].createElement("button", {
|
|
403
|
-
onClick: this.setFontSizeMin
|
|
404
|
-
}, "Set fontSizeMin to 20")), /*#__PURE__*/_react["default"].createElement("div", {
|
|
405
|
-
style: styles.demoGroup
|
|
406
|
-
}, /*#__PURE__*/_react["default"].createElement("button", {
|
|
407
|
-
onClick: this.screenshotToConsole
|
|
408
|
-
}, "Screenshot to console"), /*#__PURE__*/_react["default"].createElement("button", {
|
|
409
|
-
onClick: this.screenshotsToConsole
|
|
410
|
-
}, "Screenshots of Elements")), /*#__PURE__*/_react["default"].createElement("div", {
|
|
411
|
-
style: styles.demoGroup
|
|
412
|
-
}, /*#__PURE__*/_react["default"].createElement(MaskSelect, {
|
|
413
|
-
onChange: this.onMaskSelected
|
|
414
|
-
})))));
|
|
415
|
-
}
|
|
416
|
-
}]);
|
|
417
|
-
|
|
418
|
-
return App;
|
|
419
|
-
}(_react["default"].Component);
|
|
420
|
-
|
|
421
|
-
var _default = (0, _reactHotLoader.hot)(module)(App);
|
|
422
|
-
|
|
423
|
-
exports["default"] = _default;
|