UNPKG

@infinite-canvas-tutorial/webcomponents

Version:
74 lines 5.21 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _InitCanvas_setLocale, _InitCanvas_getLocale; Object.defineProperty(exports, "__esModule", { value: true }); exports.InitCanvas = void 0; const localize_1 = require("@lit/localize"); // Generated via output.localeCodesModule const locale_codes_1 = require("../generated/locale-codes"); const ecs_1 = require("@infinite-canvas-tutorial/ecs"); const event_1 = require("../event"); const API_1 = require("../API"); const context_1 = require("../context"); const i18n_1 = require("../i18n"); class InitCanvas extends ecs_1.System { constructor() { super(); this.commands = new ecs_1.Commands(this); // configureLocalization can only be called once, so we need to store the setLocale and getLocale functions in instance variables. _InitCanvas_setLocale.set(this, void 0); _InitCanvas_getLocale.set(this, void 0); this.query((q) => q .using(ecs_1.ComputedCamera, ecs_1.ComputedBounds) .read.and.using(ecs_1.Canvas, ecs_1.Camera, ecs_1.Grid, ecs_1.Name, ecs_1.Cursor, ecs_1.Transform, ecs_1.Parent, ecs_1.Children, ecs_1.Renderable, ecs_1.Visibility, ecs_1.FillSolid, ecs_1.FillGradient, ecs_1.Stroke, ecs_1.Circle, ecs_1.Ellipse, ecs_1.Rect, ecs_1.Polyline, ecs_1.Line, ecs_1.Path, ecs_1.Text, ecs_1.Rough, ecs_1.Brush, ecs_1.VectorNetwork, ecs_1.Selected, ecs_1.Opacity, ecs_1.DropShadow, ecs_1.ZIndex, ecs_1.Font, ecs_1.TextDecoration, ecs_1.Wireframe, ecs_1.Marker, ecs_1.InnerShadow, ecs_1.LockAspectRatio, ecs_1.HTML, ecs_1.HTMLContainer, ecs_1.Embed, ecs_1.Editable, ecs_1.Filter, ecs_1.Binding, ecs_1.Binded, ecs_1.Locked, ecs_1.ClipMode, ecs_1.Flex).write); } execute() { if (API_1.pendingCanvases.length) { API_1.pendingCanvases.forEach(({ container, canvas, camera }) => { const { appStateProvider, nodesProvider, apiProvider } = container; const stateManagement = new context_1.LitStateManagement(appStateProvider, nodesProvider); const api = new API_1.ExtendedAPI(stateManagement, this.commands, container); apiProvider.setValue(api); api.createCanvas(Object.assign(Object.assign({}, canvas), { api })); api.createCamera(camera); try { const { getLocale, setLocale } = (0, localize_1.configureLocalization)({ sourceLocale: locale_codes_1.sourceLocale, targetLocales: locale_codes_1.targetLocales, loadLocale: (locale) => __awaiter(this, void 0, void 0, function* () { return i18n_1.localizedTemplates.get(locale); }), }); __classPrivateFieldSet(this, _InitCanvas_setLocale, setLocale, "f"); __classPrivateFieldSet(this, _InitCanvas_getLocale, getLocale, "f"); } catch (e) { } api.setLocale = __classPrivateFieldGet(this, _InitCanvas_setLocale, "f"); api.getLocale = __classPrivateFieldGet(this, _InitCanvas_getLocale, "f"); this.commands.execute(); container.dispatchEvent(new CustomEvent(event_1.Event.READY, { detail: api })); }); API_1.pendingCanvases.length = 0; } } } exports.InitCanvas = InitCanvas; _InitCanvas_setLocale = new WeakMap(), _InitCanvas_getLocale = new WeakMap(); //# sourceMappingURL=InitCanvas.js.map