@infinite-canvas-tutorial/webcomponents
Version:
WebComponents UI implementation
70 lines • 5.17 kB
JavaScript
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;
import { configureLocalization } from '@lit/localize';
// Generated via output.localeCodesModule
import { sourceLocale, targetLocales } from '../generated/locale-codes';
import { Brush, Camera, Canvas, Children, Circle, Commands, ComputedBounds, ComputedCamera, Cursor, DropShadow, InnerShadow, Ellipse, FillGradient, FillSolid, Font, Grid, Name, Opacity, Parent, Path, Polyline, Rect, Renderable, Selected, Stroke, System, Text, Transform, Visibility, ZIndex, TextDecoration, Wireframe, Rough, VectorNetwork, Marker, Line, LockAspectRatio, HTML, HTMLContainer, Embed, Editable, Filter, Binding, Binded, Locked, ClipMode, Flex, } from '@infinite-canvas-tutorial/ecs';
import { Event } from '../event';
import { ExtendedAPI, pendingCanvases } from '../API';
import { LitStateManagement } from '../context';
import { localizedTemplates } from '../i18n';
export class InitCanvas extends System {
constructor() {
super();
this.commands = new 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(ComputedCamera, ComputedBounds)
.read.and.using(Canvas, Camera, Grid, Name, Cursor, Transform, Parent, Children, Renderable, Visibility, FillSolid, FillGradient, Stroke, Circle, Ellipse, Rect, Polyline, Line, Path, Text, Rough, Brush, VectorNetwork, Selected, Opacity, DropShadow, ZIndex, Font, TextDecoration, Wireframe, Marker, InnerShadow, LockAspectRatio, HTML, HTMLContainer, Embed, Editable, Filter, Binding, Binded, Locked, ClipMode, Flex).write);
}
execute() {
if (pendingCanvases.length) {
pendingCanvases.forEach(({ container, canvas, camera }) => {
const { appStateProvider, nodesProvider, apiProvider } = container;
const stateManagement = new LitStateManagement(appStateProvider, nodesProvider);
const api = new ExtendedAPI(stateManagement, this.commands, container);
apiProvider.setValue(api);
api.createCanvas(Object.assign(Object.assign({}, canvas), { api }));
api.createCamera(camera);
try {
const { getLocale, setLocale } = configureLocalization({
sourceLocale,
targetLocales,
loadLocale: (locale) => __awaiter(this, void 0, void 0, function* () { return 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.READY, { detail: api }));
});
pendingCanvases.length = 0;
}
}
}
_InitCanvas_setLocale = new WeakMap(), _InitCanvas_getLocale = new WeakMap();
//# sourceMappingURL=InitCanvas.js.map