UNPKG

@visactor/vrender-core

Version:

```typescript import { xxx } from '@visactor/vrender-core'; ```

191 lines (164 loc) 12.9 kB
"use strict"; var __importDefault = this && this.__importDefault || function(mod) { return mod && mod.__esModule ? mod : { default: mod }; }; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.installRuntimeContributionModule = exports.installRuntimePickersToApp = exports.installRuntimeDrawContributionsToApp = exports.installRuntimeGraphicRenderersToApp = exports.getRuntimeInstallerState = exports.RUNTIME_INSTALLER_STATE_SYMBOL = exports.configureRuntimeApplicationForApp = exports.getRuntimeInstallerGlobal = exports.refreshRuntimeInstallerContributions = exports.getRuntimeInstallerBindingContext = void 0; const application_1 = require("../application"), constants_1 = require("../canvas/constants"), contribution_provider_1 = require("../common/contribution-provider"), constants_2 = require("../constants"), modules_1 = __importDefault(require("../core/contributions/modules")), global_1 = require("../core/global"), window_1 = require("../core/window"), core_modules_1 = __importDefault(require("../core/core-modules")), graphic_module_1 = __importDefault(require("../graphic/graphic-service/graphic-module")), bootstrap_1 = require("../legacy/bootstrap"), pick_modules_1 = __importDefault(require("../picker/pick-modules")), constants_3 = require("../render/contributions/render/contributions/constants"), draw_interceptor_1 = require("../render/contributions/render/draw-interceptor"), incremental_area_render_1 = require("../render/contributions/render/incremental-area-render"), incremental_draw_contribution_1 = require("../render/contributions/render/incremental-draw-contribution"), incremental_line_render_1 = require("../render/contributions/render/incremental-line-render"), render_modules_1 = __importDefault(require("../render/render-modules")), symbol_1 = require("../render/contributions/render/symbol"), modules_2 = __importDefault(require("../render/contributions/modules")), constants_4 = require("../plugins/constants"), plugin_service_1 = require("../plugins/plugin-service"), runtime_installer_state_1 = require("./runtime-installer-state"), runtimeInstallerState = (0, runtime_installer_state_1.getRuntimeInstallerState)(), runtimeInstallerContext = runtimeInstallerState.runtimeInstallerContext, RUNTIME_RENDERER_NAMESPACE = "vrender:runtime-renderer", RUNTIME_PICKER_NAMESPACE = "vrender:runtime-picker", runtimeEntryKeys = runtimeInstallerState.runtimeEntryKeys, runtimeDrawContributions = runtimeInstallerState.runtimeDrawContributions, loadedRuntimeContributionModules = runtimeInstallerState.loadedRuntimeContributionModules, DEFAULT_RUNTIME_CONTRIBUTION_TARGETS = [ "graphic-renderer" ], noopUnbindRuntimeContributionService = () => {}; function ensureRuntimeInstallerPreloaded() { runtimeInstallerState.preloaded || (runtimeInstallerState.preloaded = !0, (0, core_modules_1.default)({ bind: runtimeInstallerContext.bind }), (0, graphic_module_1.default)({ bind: runtimeInstallerContext.bind }), (0, render_modules_1.default)({ bind: runtimeInstallerContext.bind }), (0, pick_modules_1.default)({ bind: runtimeInstallerContext.bind, isBound: runtimeInstallerContext.isBound }), (0, modules_1.default)(runtimeInstallerContext), (0, modules_2.default)(runtimeInstallerContext)); } function resolveRuntimeNamed(serviceIdentifier, name) { const instance = getRuntimeInstallerBindingContext().getNamed(serviceIdentifier, name); if (null == instance) throw new Error(`${String(serviceIdentifier)} is not configured for ${name}`); return instance; } function registerRuntimeEntries(register, entries, prefix) { entries.forEach(((entry, index) => { var _a, _b, _c; const name = null !== (_c = null !== (_a = null == entry ? void 0 : entry.type) && void 0 !== _a ? _a : null === (_b = null == entry ? void 0 : entry.constructor) || void 0 === _b ? void 0 : _b.name) && void 0 !== _c ? _c : `${prefix}-entry`; register(`${prefix}:${String(name)}:${index}`, entry); })); } function getTrackedEntryKeys(registry, namespace) { let namespaces = runtimeEntryKeys.get(registry); namespaces || (namespaces = new Map, runtimeEntryKeys.set(registry, namespaces)); let keys = namespaces.get(namespace); return keys || (keys = new Set, namespaces.set(namespace, keys)), keys; } function clearTrackedEntryKeys(registry, namespace, unregister) { const keys = getTrackedEntryKeys(registry, namespace); unregister && keys.forEach((key => unregister(key))), keys.clear(); } function createAppRegistryContributionProvider(app, key) { return { getContributions: () => app.context.registry.contribution.get(key) }; } function getRuntimeInstallerBindingContext() { return ensureRuntimeInstallerPreloaded(), runtimeInstallerContext; } function refreshRuntimeInstallerContributions() { contribution_provider_1.ContributionStore.refreshAllContributions(); } function getRuntimeInstallerGlobal() { var _a; return ensureRuntimeInstallerPreloaded(), null !== (_a = runtimeInstallerState.runtimeGlobal) && void 0 !== _a || (runtimeInstallerState.runtimeGlobal = new global_1.DefaultGlobal((0, contribution_provider_1.createContributionProvider)(constants_2.EnvContribution, runtimeInstallerContext))), runtimeInstallerState.runtimeGlobal; } function configureRuntimeApplicationForApp(app) { const bindingContext = getRuntimeInstallerBindingContext(), global = getRuntimeInstallerGlobal(); application_1.application.global = global, application_1.application.canvasFactory = env => bindingContext.getNamed(constants_1.CanvasFactory, env), application_1.application.context2dFactory = env => bindingContext.getNamed(constants_1.Context2dFactory, env), application_1.application.windowHandlerFactory = env => resolveRuntimeNamed(window_1.WindowHandlerContribution, env), application_1.application.windowFactory = () => new window_1.DefaultWindow(global, (env => resolveRuntimeNamed(window_1.WindowHandlerContribution, env))), application_1.application.pluginServiceFactory = () => new plugin_service_1.DefaultPluginService((0, contribution_provider_1.createContributionProvider)(constants_4.AutoEnablePlugins, bindingContext), { pluginRegistry: app.context.registry.plugin }), application_1.application.incrementalDrawContributionFactory = () => new incremental_draw_contribution_1.DefaultIncrementalDrawContribution([], new incremental_line_render_1.DefaultIncrementalCanvasLineRender, new incremental_area_render_1.DefaultIncrementalCanvasAreaRender((0, contribution_provider_1.createContributionProvider)(constants_3.AreaRenderContribution, bindingContext)), createAppRegistryContributionProvider(app, draw_interceptor_1.DrawItemInterceptor)); } exports.getRuntimeInstallerBindingContext = getRuntimeInstallerBindingContext, exports.refreshRuntimeInstallerContributions = refreshRuntimeInstallerContributions, exports.getRuntimeInstallerGlobal = getRuntimeInstallerGlobal, exports.configureRuntimeApplicationForApp = configureRuntimeApplicationForApp; var runtime_installer_state_2 = require("./runtime-installer-state"); function installRuntimeGraphicRenderersToApp(app) { var _a; const bindingContext = getRuntimeInstallerBindingContext(); refreshRuntimeInstallerContributions(); const renderers = bindingContext.getAll(symbol_1.GraphicRender), registeredKeys = getTrackedEntryKeys(app.registry.renderer, RUNTIME_RENDERER_NAMESPACE); clearTrackedEntryKeys(app.registry.renderer, RUNTIME_RENDERER_NAMESPACE, null === (_a = app.registry.renderer.unregister) || void 0 === _a ? void 0 : _a.bind(app.registry.renderer)), registerRuntimeEntries(((key, renderer) => { var _a; null === (_a = null == renderer ? void 0 : renderer.reInit) || void 0 === _a || _a.call(renderer), app.registry.renderer.register(key, renderer), registeredKeys.add(key); }), renderers, RUNTIME_RENDERER_NAMESPACE); } function installRuntimeDrawContributionsToApp(app) { var _a; const bindingContext = getRuntimeInstallerBindingContext(); refreshRuntimeInstallerContributions(); const contributions = bindingContext.getAll(draw_interceptor_1.DrawItemInterceptor), tracked = null !== (_a = runtimeDrawContributions.get(app.context.registry.contribution)) && void 0 !== _a ? _a : new Set; tracked.forEach((contribution => { var _a, _b; null === (_b = (_a = app.context.registry.contribution).unregister) || void 0 === _b || _b.call(_a, draw_interceptor_1.DrawItemInterceptor, contribution); })), tracked.clear(), runtimeDrawContributions.set(app.context.registry.contribution, tracked); const registered = new Set(app.context.registry.contribution.get(draw_interceptor_1.DrawItemInterceptor)); contributions.forEach((contribution => { registered.has(contribution) || (app.context.registry.contribution.register(draw_interceptor_1.DrawItemInterceptor, contribution), registered.add(contribution)), tracked.add(contribution); })); } function installRuntimePickersToApp(app, serviceIdentifier) { var _a; const bindingContext = getRuntimeInstallerBindingContext(); refreshRuntimeInstallerContributions(); const pickers = bindingContext.getAll(serviceIdentifier), registeredKeys = getTrackedEntryKeys(app.registry.picker, RUNTIME_PICKER_NAMESPACE); clearTrackedEntryKeys(app.registry.picker, RUNTIME_PICKER_NAMESPACE, null === (_a = app.registry.picker.unregister) || void 0 === _a ? void 0 : _a.bind(app.registry.picker)), registerRuntimeEntries(((key, picker) => { app.registry.picker.register(key, picker), registeredKeys.add(key); }), pickers, RUNTIME_PICKER_NAMESPACE); } function getRuntimeContributionModuleIdentity(module) { return module; } function hasLoadedRuntimeContributionModule(context, module) { var _a, _b; return null !== (_b = null === (_a = loadedRuntimeContributionModules.get(context)) || void 0 === _a ? void 0 : _a.has(getRuntimeContributionModuleIdentity(module))) && void 0 !== _b && _b; } function markRuntimeContributionModuleLoaded(context, module) { let modules = loadedRuntimeContributionModules.get(context); modules || (modules = new WeakSet, loadedRuntimeContributionModules.set(context, modules)), modules.add(getRuntimeContributionModuleIdentity(module)); } function loadRuntimeContributionModuleToContext(context, module) { hasLoadedRuntimeContributionModule(context, module) || ("function" == typeof module ? module(context) : module.registry(context.bind, noopUnbindRuntimeContributionService, context.isBound, context.rebind), markRuntimeContributionModuleLoaded(context, module)); } function isRuntimePickerTarget(target) { return "object" == typeof target && null !== target && "picker" in target; } function installRuntimeContributionTargetsToApp(app, targets) { const resolvedTargets = null != targets ? targets : DEFAULT_RUNTIME_CONTRIBUTION_TARGETS; let installGraphicRenderers = !1, installDrawContributions = !1; const pickerTargets = new Set; resolvedTargets.forEach((target => { "graphic-renderer" === target ? installGraphicRenderers = !0 : "draw-contribution" === target ? installDrawContributions = !0 : isRuntimePickerTarget(target) && pickerTargets.add(target.picker); })), installDrawContributions && installRuntimeDrawContributionsToApp(app), installGraphicRenderers && installRuntimeGraphicRenderersToApp(app), pickerTargets.forEach((serviceIdentifier => { installRuntimePickersToApp(app, serviceIdentifier); })); } function installRuntimeContributionModule(module, {app: app, legacy: legacy = !0, targets: targets} = {}) { loadRuntimeContributionModuleToContext(getRuntimeInstallerBindingContext(), module), legacy && ((0, bootstrap_1.preLoadAllModule)(), loadRuntimeContributionModuleToContext((0, bootstrap_1.getLegacyBindingContext)(), module)), refreshRuntimeInstallerContributions(), app && installRuntimeContributionTargetsToApp(app, targets); } Object.defineProperty(exports, "RUNTIME_INSTALLER_STATE_SYMBOL", { enumerable: !0, get: function() { return runtime_installer_state_2.RUNTIME_INSTALLER_STATE_SYMBOL; } }), Object.defineProperty(exports, "getRuntimeInstallerState", { enumerable: !0, get: function() { return runtime_installer_state_2.getRuntimeInstallerState; } }), exports.installRuntimeGraphicRenderersToApp = installRuntimeGraphicRenderersToApp, exports.installRuntimeDrawContributionsToApp = installRuntimeDrawContributionsToApp, exports.installRuntimePickersToApp = installRuntimePickersToApp, exports.installRuntimeContributionModule = installRuntimeContributionModule; //# sourceMappingURL=runtime-installer.js.map