123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import { APP_STATE } from "./core/enums/app-state-enum";
- import { stageManager as Stages } from "./core/application/stage-manager";
- import { objects as Objects } from "./core/application/objects";
- import { state as State } from "./core/application/state";
- import { selector as Selector } from "./core/application/selector";
- import { menu as Menu } from "./core/application/menu";
- import Konva from "konva";
- import { COMPONENT_TYPE } from "./core/enums/component-type-enum";
- import { headerMenu } from "./core/application/header-menu";
- export const app = (function () {
- let _selectedTool = [];
- function _bootstrap() {
- Konva.showWarnings = false;
- headerMenu.bootstrap();
- Selector.bootstrap();
- requireAll(require.context("./component-registry/", true, /\.js$/));
- _refreshMenu();
- $("body").on("mouseenter", ".li-content", e => $(e.currentTarget).parent().find('.level-1').css("background-color", "#d4d4d4"));
- $("body").on("mouseleave", ".li-content", e => $(e.currentTarget).parent().find('.level-1').css("background-color", "transparent"));
- ;
- }
- function _currentLayer() {
- return Stages.getCurrentKonvaLayer();
- }
- function _setSelectedTool(tool) {
- _clearSelectedTool(tool != undefined);
- _setState(APP_STATE.TOOL_SELECTED);
- if (tool.options.id != undefined) {
- document.getElementById("btn-" + tool.options.id).disabled = true;
- }
- _selectedTool.push(tool);
- }
- function _clearSelectedTool(force) {
- let tool = _getSelectedTool();
- if (tool != undefined) {
- if (!force && tool.options.type == COMPONENT_TYPE.SELECTOR) {
- return;
- }
- if (tool.options.id != undefined) {
- document.getElementById("btn-" + tool.options.id).disabled = false;
- }
- }
- _selectedTool = [];
- _setStatus("");
- _setState(APP_STATE.NONE);
- }
- function _getSelectedTool() {
- if (_selectedTool.length > 0) return _selectedTool[0];
- return undefined;
- }
- function _getRelativePointerPosition() {
- const stage = Stages.getCurrentKonvaStage();
- return stage.getPointerPosition();
- }
- function _setStatus(status) {
- document.getElementById("status").innerHTML = status;
- }
- function _pushObject(object) {
- return;
- Objects.add(object);
- }
- function _getObjects() {
- return Objects.get();
- }
- function _setState(e) {
- State.setState(e);
- }
- function _refreshMenu() {
- Menu.refresh();
- }
- function requireAll(r) {
- r.keys().forEach(r);
- }
- _bootstrap();
- return {
- stage: Stages.getCurrentKonvaStage,
- currentLayer: _currentLayer,
- bootstrap: _bootstrap,
- setSelectedTool: _setSelectedTool,
- clearSelectedTool: _clearSelectedTool,
- getSelectedTool: _getSelectedTool,
- pos: _getRelativePointerPosition,
- setStatus: _setStatus,
- pushObject: _pushObject,
- getObjects: _getObjects,
- setState: _setState
- };
- })();
|