kitchen-simulator
Version:
It is a kitchen simulator (self-contained micro-frontend).
505 lines • 17.4 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/esm/inherits";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
import { fromJS, List, Map, Record } from 'immutable';
import { MODE_IDLE, UNIT_INCH } from "./constants";
import { SNAP_MASK } from "./utils/snap";
import { isEmpty } from "./utils/helper";
import { convert } from "./utils/convert-units-lite";
export var safeLoadMapList = function safeLoadMapList(mapList, Model, defaultMap) {
return mapList ? new Map(mapList).map(function (m) {
return new Model(m);
}).toMap() : defaultMap || new Map();
};
export var Grid = /*#__PURE__*/function (_Record) {
function Grid() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Grid);
return _callSuper(this, Grid, [_objectSpread(_objectSpread({}, json), {}, {
properties: fromJS(json.properties || {})
})]);
}
_inherits(Grid, _Record);
return _createClass(Grid);
}(Record({
id: '',
type: '',
properties: Map()
}, 'Grid'));
export var DefaultGrids = new Map({
h1: new Grid({
id: 'h1',
type: 'horizontal-streak',
properties: {
step: 30.48,
colors: ['#bbb', '#bbb', '#bbb', '#bbb', '#bbb'] // dot's color
}
}),
v1: new Grid({
id: 'v1',
type: 'vertical-streak',
properties: {
step: 30.48,
colors: ['#bbb', '#bbb', '#bbb', '#bbb', '#bbb'] // dot's color
}
})
});
export var ElementsSet = /*#__PURE__*/function (_Record2) {
function ElementsSet() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, ElementsSet);
return _callSuper(this, ElementsSet, [{
vertices: new List(json.vertices || []),
lines: new List(json.lines || []),
holes: new List(json.holes || []),
areas: new List(json.areas || []),
items: new List(json.items || [])
}]);
}
_inherits(ElementsSet, _Record2);
return _createClass(ElementsSet);
}(Record({
vertices: new List(),
lines: new List(),
holes: new List(),
areas: new List(),
items: new List()
}, 'ElementsSet'));
var sharedAttributes = {
id: '',
type: '',
prototype: '',
name: '',
misc: new Map(),
selected: false,
properties: new Map(),
style: '',
category: '',
visible: true
};
export var Vertex = /*#__PURE__*/function (_Record3) {
function Vertex() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Vertex);
return _callSuper(this, Vertex, [_objectSpread(_objectSpread({}, json), {}, {
lines: new List(json.lines || []),
areas: new List(json.areas || [])
})]);
}
_inherits(Vertex, _Record3);
return _createClass(Vertex);
}(Record(_objectSpread(_objectSpread({}, sharedAttributes), {}, {
x: -1,
y: -1,
prototype: 'vertices',
lines: new List(),
areas: new List()
}), 'Vertex'));
export var Line = /*#__PURE__*/function (_Record4) {
function Line() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Line);
return _callSuper(this, Line, [_objectSpread(_objectSpread({}, json), {}, {
createdDateTime: json.createdDateTime !== undefined ? json.createdDateTime : new Date().getTime(),
properties: fromJS(json.properties || {}),
vertices: new List(json.vertices || []),
holes: new List(json.holes || []),
relatedVertices: new List(json.relatedVertices || []),
userData: {}
})]);
}
_inherits(Line, _Record4);
return _createClass(Line);
}(Record(_objectSpread(_objectSpread({}, sharedAttributes), {}, {
createdDateTime: new Date().getTime(),
prototype: 'lines',
vertices: new List(),
relatedVertices: new List(),
holes: new List(),
focus: false,
wallColor: '#dddddd',
userData: {}
}), 'Line'));
export var Hole = /*#__PURE__*/function (_Record5) {
function Hole() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Hole);
return _callSuper(this, Hole, [_objectSpread(_objectSpread({}, json), {}, {
properties: fromJS(json.properties || {}),
userData: {}
})]);
}
_inherits(Hole, _Record5);
return _createClass(Hole);
}(Record(_objectSpread(_objectSpread({}, sharedAttributes), {}, {
prototype: 'holes',
offset: -1,
x: 0,
y: 0,
rotation: 0,
line: '',
url: '',
userData: {}
}), 'Hole'));
export var Area = /*#__PURE__*/function (_Record6) {
function Area() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Area);
return _callSuper(this, Area, [_objectSpread(_objectSpread({}, json), {}, {
properties: fromJS(json.properties || {}),
vertices: new List(json.vertices || [])
})]);
}
_inherits(Area, _Record6);
return _createClass(Area);
}(Record(_objectSpread(_objectSpread({}, sharedAttributes), {}, {
prototype: 'areas',
vertices: new List(),
holes: new List(),
texture: {
roughness: 0.9,
metalness: 0,
uri: ''
}
}), 'Area'));
export var Item = /*#__PURE__*/function (_Record7) {
function Item() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Item);
return _callSuper(this, Item, [_objectSpread(_objectSpread({}, json), {}, {
properties: fromJS(json.properties || {})
})]);
}
_inherits(Item, _Record7);
return _createClass(Item);
}(Record(_objectSpread(_objectSpread({}, sharedAttributes), {}, {
prototype: 'items',
x: 0,
y: 0,
rotation: 0,
submodule: new List(),
normalMap: new List(),
doorStyle: new Map(),
animate: 0,
animValue: 0,
itemID: -1,
sku_number: '',
layoutpos: '',
cabinet_category: '',
counterTop: {
roughness: 0.9,
metalness: 0.1,
uri: ''
},
molding: [],
backsplashVisible: false,
applianceMaterial: {
roughness: 0.4,
metalness: 0.3
},
distArray: [[0, 0], [0, 0], [0, 0], [0, 0]]
}), 'Item'));
export var Layer = /*#__PURE__*/function (_Record8) {
function Layer() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Layer);
return _callSuper(this, Layer, [_objectSpread(_objectSpread({}, json), {}, {
vertices: safeLoadMapList(json.vertices, Vertex),
lines: safeLoadMapList(json.lines, Line),
holes: safeLoadMapList(json.holes, Hole),
areas: safeLoadMapList(json.areas, Area),
items: safeLoadMapList(json.items, Item),
doorStyle: json.doorStyle !== null ? json.doorStyle : null,
selected: new ElementsSet(json.selected)
})]);
}
_inherits(Layer, _Record8);
return _createClass(Layer);
}(Record({
id: '',
altitude: 0,
order: 0,
opacity: 1,
name: '',
visible: true,
vertices: new Map(),
lines: new Map(),
holes: new Map(),
areas: new Map(),
items: new Map(),
selected: new ElementsSet(),
counterTop: {},
wallColor: {},
floorStyle: {},
doorHandle: '',
doorStyle: null,
molding: [],
backsplash: {
roughness: 0.2,
metalness: 0.1,
uri: ''
},
backsplashApplied: false,
ceilHeight: 96,
unit: UNIT_INCH
}, 'Layer'));
export var Group = /*#__PURE__*/function (_Record9) {
function Group() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Group);
return _callSuper(this, Group, [_objectSpread(_objectSpread({}, json), {}, {
properties: fromJS(json.properties || {}),
elements: fromJS(json.elements || {})
})]);
}
_inherits(Group, _Record9);
return _createClass(Group);
}(Record(_objectSpread(_objectSpread({}, sharedAttributes), {}, {
prototype: 'groups',
x: 0,
y: 0,
rotation: 0,
elements: new Map()
}), 'Group'));
export var DefaultLayers = new Map({
'layer-1': new Layer({
id: 'layer-1',
name: 'default'
})
});
export var Scene = /*#__PURE__*/function (_Record0) {
function Scene() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Scene);
var layers = safeLoadMapList(json.layers, Layer, DefaultLayers);
return _callSuper(this, Scene, [_objectSpread(_objectSpread({}, json), {}, {
// grids: safeLoadMapList(json.grids, Grid, DefaultGrids),
grids: DefaultGrids,
layers: layers,
selectedLayer: layers.first().id,
groups: safeLoadMapList(json.groups || {}, Group),
meta: json.meta ? fromJS(json.meta) : new Map(),
guides: !isEmpty(json.guides) ? fromJS(json.guides) : new Map({
horizontal: new Map(),
vertical: new Map(),
circular: new Map()
})
})]);
}
_inherits(Scene, _Record0);
return _createClass(Scene);
}(Record({
unit: 'cm',
rulerUnit: 'in',
layers: new Map(),
grids: new Map(),
selectedLayer: null,
groups: new Map(),
width: 3000,
height: 2000,
meta: new Map(),
//additional info
guides: new Map(),
title: '',
currentProjectID: null,
showfg: true,
showWallLengthMeasure: 1,
showBaseCabinetMeasure: 1,
showWallCabinetMeasure: 1,
showWindowDoorMeasure: 1,
isLoadingCabinet: false,
loadFlag: false,
isEndDragging: false,
setLineAttributes: false
}, 'Scene'));
export var CatalogElement = /*#__PURE__*/function (_Record1) {
function CatalogElement() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, CatalogElement);
return _callSuper(this, CatalogElement, [_objectSpread(_objectSpread({}, json), {}, {
info: fromJS(json.info),
properties: fromJS(json.properties),
obj: fromJS(json.obj)
})]);
}
_inherits(CatalogElement, _Record1);
return _createClass(CatalogElement);
}(Record({
itemID: -1,
name: '',
prototype: '',
info: new Map(),
properties: new Map(),
obj: new Map(),
type: '',
cds: new Map()
}, 'CatalogElement'));
export var Catalog = /*#__PURE__*/function (_Record10) {
function Catalog() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Catalog);
var elements = safeLoadMapList(json.elements, CatalogElement);
return _callSuper(this, Catalog, [{
elements: elements,
ready: !elements.isEmpty()
}]);
}
_inherits(Catalog, _Record10);
return _createClass(Catalog, [{
key: "factoryElement",
value: function factoryElement(type, options, initialProperties, state) {
if (!this.elements.has(type)) {
var catList = this.elements.map(function (element) {
return element.name;
}).toArray();
throw new Error("Element ".concat(type, " does not exist in catalog ").concat(catList));
}
var element = this.elements.get(type);
var properties = element.properties.map(function (value, key) {
return initialProperties && initialProperties.has(key) ? initialProperties.get(key) : value.get('defaultValue');
});
if (options) {
if (options.isDuplication) {
var layerID = state.scene.selectedLayer;
var currentItemID = state.scene.getIn(['layers', layerID, 'selected', 'items'])._tail.array[0];
var currentItem = state.scene.getIn(['layers', layerID, 'items', currentItemID]);
var sizeinfo = {
width: currentItem.properties.get('width'),
height: currentItem.properties.get('height'),
depth: currentItem.properties.get('depth')
};
properties = properties.set('width', sizeinfo.width).set('height', sizeinfo.height).set('depth', sizeinfo.depth);
if (currentItem.properties.get('oldDepth') !== undefined) properties = properties.set('oldDepth', currentItem.properties.get('oldDepth'));
if (currentItem.properties.get('oldWidth') !== undefined) properties = properties.set('oldWidth', currentItem.properties.get('oldWidth'));
if (currentItem.properties.get('oldHeight') !== undefined) properties = properties.set('oldHeight', currentItem.properties.get('oldHeight'));
} else if (element.prototype === 'holes') {} else {
var temp = {
width: element.getIn(['info', 'sizeinfo', 'width']),
height: element.getIn(['info', 'sizeinfo', 'height']),
depth: element.getIn(['info', 'sizeinfo', 'depth'])
};
var _sizeinfo = {
width: new Map({
_length: temp.width,
_unit: 'in',
length: convert(temp.width).from('in').to('cm')
}),
height: new Map({
_length: temp.height,
_unit: 'in',
length: convert(temp.height).from('in').to('cm')
}),
depth: new Map({
_length: temp.depth,
_unit: 'in',
length: convert(temp.depth).from('in').to('cm')
})
};
properties = properties.set('width', _sizeinfo.width).set('height', _sizeinfo.height).set('depth', _sizeinfo.depth);
}
}
switch (element.prototype) {
case 'lines':
return new Line(options).merge({
properties: properties
});
case 'holes':
return new Hole(options).merge({
properties: properties
});
case 'areas':
return new Area(options).merge({
properties: properties
});
case 'items':
return new Item(options).merge({
properties: properties
});
default:
throw new Error('prototype not valid');
}
}
}]);
}(Record({
ready: false,
page: 'root',
path: new List(),
elements: new Map()
}, 'Catalog'));
export var HistoryStructure = /*#__PURE__*/function (_Record11) {
function HistoryStructure() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, HistoryStructure);
return _callSuper(this, HistoryStructure, [{
list: fromJS(json.list || []),
first: new Scene(json.scene),
last: new Scene(json.last || json.scene)
}]);
}
_inherits(HistoryStructure, _Record11);
return _createClass(HistoryStructure);
}(Record({
list: new List(),
first: null,
last: null
}, 'HistoryStructure'));
export var State = /*#__PURE__*/function (_Record12) {
function State() {
var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, State);
return _callSuper(this, State, [_objectSpread(_objectSpread({}, json), {}, {
scene: new Scene(json.scene),
sceneHistory: new HistoryStructure(json),
catalog: new Catalog(json.catalog || {}),
viewer2D: new Map(json.viewer2D || {}),
replacingSupport: new Map(json.drawingSupport || {}),
drawingSupport: new Map(json.drawingSupport || {}),
draggingSupport: new Map(json.draggingSupport || {}),
rotatingSupport: new Map(json.rotatingSupport || {}),
misc: json.misc ? fromJS(json.misc) : new Map()
})]);
}
_inherits(State, _Record12);
return _createClass(State);
}(Record({
mode: MODE_IDLE,
scene: new Scene(),
sceneHistory: new HistoryStructure(),
catalog: new Catalog(),
viewer2D: new Map(),
mouse: new Map({
x: 0,
y: 0
}),
zoom: 0,
snapMask: SNAP_MASK,
snapElements: new List(),
activeSnapElement: null,
replacingSupport: new Map(),
drawingSupport: new Map(),
draggingSupport: new Map(),
rotatingSupport: new Map(),
doorStyle: null,
oStyle: null,
errors: new List(),
warnings: new List(),
clipboardProperties: new Map(),
selectedElementsHistory: new List(),
misc: new Map(),
//additional info
alterate: false,
isOpen: false,
popup: false,
openedType: 0,
login: false,
userId: 0,
isHelp: false,
isCabinetDrawing: false
}, 'State'));