UNPKG

core-graphics

Version:

A core library for creating shape-based graphic editors

71 lines (61 loc) 2.43 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.initialGridState = undefined; exports.getInitialEditorState = getInitialEditorState; var _modes = require('../declarations/modes'); var _historyReducer = require('../history/history-reducer'); var _historyReducer2 = _interopRequireDefault(_historyReducer); var _icepick = require('icepick'); var i = _interopRequireWildcard(_icepick); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var initialGridState = exports.initialGridState = { on: false, size: 16 }; function getInitialEditorState(params) { var shapesDeclarations = params.shapesDeclarations; var author = params.author; var viewport = params.viewport; var _params$graphicalCont = params.graphicalContextData; var graphicalContextData = _params$graphicalCont === undefined ? {} : _params$graphicalCont; var _params$persistedHist = params.persistedHistory; var persistedHistory = _params$persistedHist === undefined ? [] : _params$persistedHist; var _params$grid = params.grid; var grid = _params$grid === undefined ? initialGridState : _params$grid; var scene = { shapes: {}, shapesOrder: [] }; if (persistedHistory && persistedHistory.length > 0) { scene = (0, _historyReducer2.default)(persistedHistory, scene); } return i.freeze({ mode: (0, _modes.modeSelect)(), viewport: viewport || { x: 0, y: 0 }, grid: grid, contextMenu: { open: false, x: 0, y: 0, target: null }, mouse: { ignoreCursorUp: false, down: false, inside: false, x: 0, y: 0, lastDownX: 0, lastDownY: 0 }, modifierKeys: {}, shapesDeclarations: shapesDeclarations, author: author, graphicalContextData: graphicalContextData, persistedHistory: persistedHistory, persistedScene: scene, scene: scene, previewedHistoryEvents: [], editorActionsQueue: [] }); }