From 0576c0f377e5cf18787068b4ede9a95f92521291 Mon Sep 17 00:00:00 2001 From: xile611 Date: Mon, 12 Jan 2026 13:51:36 +0800 Subject: [PATCH 1/6] refactor(core,kits): remove Inversify DI and migrate to Application registry - Delete legacy ContainerModule/DI files and module-based render/picker registrations - Introduce application.contributions/services registries and update env/window/canvas registrations - Refactor pickers and renders (including rough and 3D) to no-arg constructors with internal lookups - Update kits register-* APIs and Lottie to use application.global - Ensure vrender-kits builds successfully under new architecture Co-Authored-By: Claude Sonnet 4.5 --- .claude/CLAUDE.md | 104 +++ .claude/settings.json | 6 + .gitignore | 2 + packages/vrender-core/di-removal-plan.md | 63 ++ packages/vrender-core/src/application.ts | 9 +- .../vrender-core/src/canvas/empty-context.ts | 6 +- packages/vrender-core/src/canvas/util.ts | 15 +- .../src/common/contribution-provider.ts | 67 -- .../src/common/contribution-registry.ts | 90 +++ .../annotation/decorator_utils.ts | 146 ---- .../inversify-lite/annotation/inject.ts | 6 - .../inversify-lite/annotation/inject_base.ts | 26 - .../inversify-lite/annotation/injectable.ts | 18 - .../annotation/lazy_service_identifier.ts | 14 - .../inversify-lite/annotation/multi_inject.ts | 6 - .../common/inversify-lite/annotation/named.ts | 10 - .../annotation/property_event_decorator.ts | 17 - .../common/inversify-lite/bindings/binding.ts | 80 -- .../inversify-lite/bindings/binding_count.ts | 5 - .../inversify-lite/constants/error_msgs.ts | 61 -- .../inversify-lite/constants/literal_types.ts | 26 - .../inversify-lite/constants/metadata_keys.ts | 41 - .../inversify-lite/container/container.ts | 698 ------------------ .../container/container_module.ts | 22 - .../common/inversify-lite/container/lookup.ts | 129 ---- .../src/common/inversify-lite/index.ts | 36 - .../inversify-lite/interfaces/interfaces.ts | 393 ---------- .../common/inversify-lite/planning/context.ts | 24 - .../inversify-lite/planning/metadata.ts | 21 - .../planning/metadata_reader.ts | 26 - .../common/inversify-lite/planning/plan.ts | 13 - .../common/inversify-lite/planning/planner.ts | 233 ------ .../planning/queryable_string.ts | 34 - .../planning/reflection_utils.ts | 239 ------ .../common/inversify-lite/planning/request.ts | 44 -- .../common/inversify-lite/planning/target.ts | 106 --- .../resolution/instantiation.ts | 157 ---- .../inversify-lite/resolution/resolver.ts | 262 ------- .../src/common/inversify-lite/scope/scope.ts | 69 -- .../syntax/binding_in_syntax.ts | 28 - .../syntax/binding_in_when_on_syntax.ts | 102 --- .../syntax/binding_on_syntax.ts | 24 - .../syntax/binding_to_syntax.ts | 103 --- .../syntax/binding_when_on_syntax.ts | 85 --- .../syntax/binding_when_syntax.ts | 119 --- .../syntax/constraint_helpers.ts | 52 -- .../src/common/inversify-lite/utils/async.ts | 15 - .../inversify-lite/utils/binding_utils.ts | 54 -- .../common/inversify-lite/utils/clonable.ts | 12 - .../common/inversify-lite/utils/exceptions.ts | 17 - .../inversify-lite/utils/factory_type.ts | 5 - .../src/common/inversify-lite/utils/id.ts | 7 - .../src/common/inversify-lite/utils/js.ts | 11 - .../inversify-lite/utils/serialization.ts | 125 ---- .../src/common/inversify/annotation/inject.ts | 4 - .../inversify/annotation/inject_base.ts | 67 -- .../common/inversify/annotation/injectable.ts | 10 - .../inversify/annotation/multi_inject.ts | 4 - .../src/common/inversify/annotation/named.ts | 7 - .../common/inversify/annotation/optional.ts | 9 - .../src/common/inversify/binding.ts | 80 -- .../src/common/inversify/container.ts | 278 ------- .../src/common/inversify/cotainer-module.ts | 12 - .../src/common/inversify/index.ts | 34 - .../src/common/inversify/interfaces.ts | 360 --------- .../src/common/inversify/literal_types.ts | 25 - .../src/common/inversify/meta-data.ts | 18 - .../src/common/inversify/metadata_keys.ts | 38 - .../src/common/inversify/metadata_reader.ts | 27 - .../inversify/syntax/binding_in_syntax.ts | 34 - .../inversify/syntax/binding_to_syntax.ts | 55 -- .../inversify/syntax/constraint_helpers.ts | 31 - .../common/registry/contribution-registry.ts | 142 ++++ .../vrender-core/src/common/registry/index.ts | 8 + .../src/common/registry/service-registry.ts | 127 ++++ .../vrender-core/src/common/registry/types.ts | 5 + .../src/common/service-factory.ts | 162 ++++ .../src/common/service-registry.ts | 94 +++ packages/vrender-core/src/common/types.ts | 9 + packages/vrender-core/src/container.ts | 2 - .../contributions/env/base-contribution.ts | 2 - .../src/core/contributions/env/modules.ts | 7 - .../layerHandler/canvas2d-contribution.ts | 2 - .../layerHandler/empty-contribution.ts | 2 - .../contributions/layerHandler/modules.ts | 25 - .../layerHandler/offscreen2d-contribution.ts | 2 - .../src/core/contributions/modules.ts | 13 +- .../contributions/textMeasure/AtextMeasure.ts | 2 - .../core/contributions/textMeasure/modules.ts | 8 - .../textMeasure/textMeasure-contribution.ts | 2 - .../contributions/window/base-contribution.ts | 2 - .../vrender-core/src/core/core-modules.ts | 29 - .../vrender-core/src/core/global-module.ts | 20 - packages/vrender-core/src/core/global.ts | 20 +- .../vrender-core/src/core/graphic-utils.ts | 23 +- .../vrender-core/src/core/layer-service.ts | 10 +- packages/vrender-core/src/core/layer.ts | 1 - packages/vrender-core/src/core/stage.ts | 16 +- packages/vrender-core/src/core/window.ts | 9 +- .../graphic/graphic-service/graphic-module.ts | 12 - .../graphic-service/graphic-service.ts | 9 +- packages/vrender-core/src/index.ts | 31 - packages/vrender-core/src/modules.ts | 63 +- .../src/picker/global-picker-service.ts | 2 - .../src/picker/pick-interceptor.ts | 5 - .../vrender-core/src/picker/pick-modules.ts | 41 - .../vrender-core/src/picker/picker-service.ts | 29 +- .../src/plugins/plugin-modules.ts | 12 - .../src/plugins/plugin-service.ts | 21 +- packages/vrender-core/src/register-modules.ts | 178 +++++ .../src/render/contributions/modules.ts | 6 - .../render/contributions/render/arc-module.ts | 21 - .../render/contributions/render/arc-render.ts | 20 +- .../contributions/render/arc3d-module.ts | 17 - .../contributions/render/arc3d-render.ts | 2 - .../contributions/render/area-module.ts | 26 - .../contributions/render/area-render.ts | 20 +- .../contributions/render/base-render.ts | 4 +- .../contributions/render/circle-module.ts | 22 - .../contributions/render/circle-render.ts | 21 +- .../contributions/base-contribution-render.ts | 19 +- .../contributions/rect-contribution-render.ts | 3 - .../contributions/render/draw-contribution.ts | 32 +- .../contributions/render/draw-interceptor.ts | 2 - .../contributions/render/glyph-module.ts | 14 - .../contributions/render/glyph-render.ts | 2 - .../contributions/render/graphic-render.ts | 2 - .../contributions/render/group-render.ts | 21 +- .../contributions/render/image-module.ts | 20 - .../contributions/render/image-render.ts | 20 +- .../render/incremental-area-render.ts | 2 - .../render/incremental-draw-contribution.ts | 33 +- .../render/incremental-line-render.ts | 2 - .../contributions/render/line-module.ts | 17 - .../contributions/render/line-render.ts | 2 - .../src/render/contributions/render/module.ts | 47 -- .../contributions/render/path-module.ts | 22 - .../contributions/render/path-render.ts | 20 +- .../contributions/render/polygon-module.ts | 22 - .../contributions/render/polygon-render.ts | 20 +- .../contributions/render/pyramid3d-module.ts | 14 - .../contributions/render/pyramid3d-render.ts | 2 - .../contributions/render/rect-module.ts | 30 - .../contributions/render/rect-render.ts | 20 +- .../contributions/render/rect3d-module.ts | 14 - .../contributions/render/rect3d-render.ts | 3 +- .../contributions/render/richtext-module.ts | 14 - .../contributions/render/richtext-render.ts | 2 - .../contributions/render/star-module.ts | 14 - .../contributions/render/star-render.ts | 20 +- .../contributions/render/symbol-module.ts | 21 - .../contributions/render/symbol-render.ts | 20 +- .../contributions/render/text-module.ts | 21 - .../contributions/render/text-render.ts | 19 +- .../vrender-core/src/render/render-modules.ts | 7 - .../vrender-core/src/render/render-service.ts | 8 +- .../canvas/contributions/browser/canvas.ts | 3 +- .../canvas/contributions/browser/context.ts | 2 - .../canvas/contributions/browser/modules.ts | 6 +- .../contributions/create-canvas-module.ts | 23 +- .../src/canvas/contributions/feishu/canvas.ts | 3 +- .../canvas/contributions/feishu/context.ts | 2 - .../canvas/contributions/feishu/modules.ts | 6 +- .../canvas/contributions/harmony/canvas.ts | 3 +- .../canvas/contributions/harmony/context.ts | 3 +- .../canvas/contributions/harmony/modules.ts | 6 +- .../src/canvas/contributions/lynx/canvas.ts | 3 +- .../src/canvas/contributions/lynx/context.ts | 3 +- .../src/canvas/contributions/lynx/modules.ts | 6 +- .../src/canvas/contributions/modules.ts | 59 +- .../src/canvas/contributions/node/canvas.ts | 3 +- .../src/canvas/contributions/node/context.ts | 2 - .../src/canvas/contributions/node/modules.ts | 6 +- .../src/canvas/contributions/taro/canvas.ts | 2 - .../src/canvas/contributions/taro/context.ts | 3 +- .../src/canvas/contributions/taro/modules.ts | 6 +- .../src/canvas/contributions/tt/canvas.ts | 3 +- .../src/canvas/contributions/tt/context.ts | 2 - .../src/canvas/contributions/tt/modules.ts | 6 +- .../src/canvas/contributions/wx/canvas.ts | 3 +- .../src/canvas/contributions/wx/context.ts | 2 - .../src/canvas/contributions/wx/modules.ts | 6 +- packages/vrender-kits/src/env/all.ts | 44 +- packages/vrender-kits/src/env/browser.ts | 40 +- .../env/contributions/browser-contribution.ts | 3 +- .../env/contributions/feishu-contribution.ts | 3 +- .../env/contributions/harmony-contribution.ts | 3 +- .../env/contributions/lynx-contribution.ts | 3 +- .../env/contributions/node-contribution.ts | 3 +- .../env/contributions/taro-contribution.ts | 3 +- .../src/env/contributions/tt-contribution.ts | 3 +- .../src/env/contributions/wx-contribution.ts | 3 +- packages/vrender-kits/src/env/feishu.ts | 35 +- packages/vrender-kits/src/env/harmony.ts | 35 +- packages/vrender-kits/src/env/lynx.ts | 35 +- packages/vrender-kits/src/env/node.ts | 38 +- packages/vrender-kits/src/env/taro.ts | 36 +- packages/vrender-kits/src/env/tt.ts | 35 +- packages/vrender-kits/src/env/wx.ts | 39 +- packages/vrender-kits/src/graphic/Lottie.ts | 6 +- packages/vrender-kits/src/index-node.ts | 4 +- packages/vrender-kits/src/index.ts | 4 +- .../vrender-kits/src/picker/canvas-module.ts | 27 +- .../src/picker/canvas-picker-service.ts | 80 +- .../contributions/canvas-picker/arc-module.ts | 17 +- .../contributions/canvas-picker/arc-picker.ts | 7 +- .../canvas-picker/arc3d-module.ts | 18 +- .../canvas-picker/arc3d-picker.ts | 10 +- .../canvas-picker/area-module.ts | 9 +- .../canvas-picker/area-picker.ts | 10 +- .../canvas-picker/circle-module.ts | 20 +- .../canvas-picker/circle-picker.ts | 10 +- .../canvas-picker/gif-image-module.ts | 18 +- .../canvas-picker/gif-image-picker.ts | 8 - .../canvas-picker/glyph-module.ts | 18 +- .../canvas-picker/glyph-picker.ts | 10 +- .../canvas-picker/group-picker.ts | 8 +- .../canvas-picker/image-module.ts | 19 +- .../canvas-picker/image-picker.ts | 7 +- .../canvas-picker/line-module.ts | 17 +- .../canvas-picker/line-picker.ts | 7 +- .../canvas-picker/lottie-module.ts | 17 +- .../canvas-picker/lottie-picker.ts | 10 +- .../contributions/canvas-picker/module.ts | 21 +- .../canvas-picker/path-module.ts | 10 +- .../canvas-picker/path-picker.ts | 7 +- .../canvas-picker/polygon-module.ts | 18 +- .../canvas-picker/polygon-picker.ts | 10 +- .../canvas-picker/pyramid3d-module.ts | 18 +- .../canvas-picker/pyramid3d-picker.ts | 10 +- .../canvas-picker/rect-module.ts | 18 +- .../canvas-picker/rect-picker.ts | 7 +- .../canvas-picker/rect3d-module.ts | 20 +- .../canvas-picker/rect3d-picker.ts | 10 +- .../canvas-picker/richtext-module.ts | 10 +- .../canvas-picker/richtext-picker.ts | 11 +- .../canvas-picker/star-module.ts | 10 +- .../canvas-picker/star-picker.ts | 10 +- .../canvas-picker/symbol-module.ts | 10 +- .../canvas-picker/symbol-picker.ts | 17 +- .../canvas-picker/text-module.ts | 20 +- .../canvas-picker/text-picker.ts | 13 +- .../contributions/common/glyph-picker-base.ts | 2 + .../contributions/math-picker/arc-module.ts | 18 +- .../contributions/math-picker/arc-picker.ts | 10 +- .../contributions/math-picker/area-module.ts | 19 +- .../contributions/math-picker/area-picker.ts | 10 +- .../math-picker/circle-module.ts | 18 +- .../math-picker/circle-picker.ts | 10 +- .../contributions/math-picker/glyph-module.ts | 18 +- .../contributions/math-picker/glyph-picker.ts | 10 +- .../contributions/math-picker/image-module.ts | 18 +- .../contributions/math-picker/image-picker.ts | 9 +- .../contributions/math-picker/line-module.ts | 18 +- .../contributions/math-picker/line-picker.ts | 12 +- .../contributions/math-picker/module.ts | 44 +- .../contributions/math-picker/path-module.ts | 20 +- .../contributions/math-picker/path-picker.ts | 10 +- .../math-picker/polygon-module.ts | 19 +- .../math-picker/polygon-picker.ts | 10 +- .../contributions/math-picker/rect-module.ts | 18 +- .../contributions/math-picker/rect-picker.ts | 10 +- .../math-picker/richtext-module.ts | 20 +- .../math-picker/richtext-picker.ts | 11 +- .../math-picker/symbol-module.ts | 18 +- .../math-picker/symbol-picker.ts | 10 +- .../contributions/math-picker/text-module.ts | 19 +- .../contributions/math-picker/text-picker.ts | 3 +- .../vrender-kits/src/picker/math-module.ts | 48 +- .../src/picker/math-picker-service.ts | 56 +- .../vrender-kits/src/register/register-arc.ts | 13 +- .../src/register/register-arc3d.ts | 16 +- .../src/register/register-area.ts | 14 +- .../src/register/register-circle.ts | 14 +- .../vrender-kits/src/register/register-gif.ts | 10 +- .../src/register/register-glyph.ts | 14 +- .../src/register/register-image.ts | 14 +- .../src/register/register-line.ts | 13 +- .../src/register/register-path.ts | 14 +- .../src/register/register-polygon.ts | 14 +- .../src/register/register-pyramid3d.ts | 16 +- .../src/register/register-rect.ts | 14 +- .../src/register/register-rect3d.ts | 10 +- .../src/register/register-richtext.ts | 14 +- .../src/register/register-star.ts | 8 +- .../src/register/register-symbol.ts | 14 +- .../src/register/register-text.ts | 14 +- .../contributions/canvas/gif-image-module.ts | 16 +- .../contributions/canvas/gif-image-render.ts | 20 +- .../contributions/canvas/lottie-module.ts | 18 +- .../contributions/canvas/lottie-render.ts | 5 +- .../src/render/contributions/rough/module.ts | 50 +- .../render/contributions/rough/rough-arc.ts | 14 +- .../render/contributions/rough/rough-area.ts | 3 +- .../contributions/rough/rough-circle.ts | 13 +- .../render/contributions/rough/rough-line.ts | 13 +- .../render/contributions/rough/rough-path.ts | 13 +- .../render/contributions/rough/rough-rect.ts | 14 +- .../contributions/rough/rough-symbol.ts | 14 +- .../contributions/browser-contribution.ts | 19 +- .../contributions/feishu-contribution.ts | 24 +- .../contributions/harmony-contribution.ts | 24 +- .../window/contributions/lynx-contribution.ts | 24 +- .../window/contributions/node-contribution.ts | 24 +- .../window/contributions/taro-contribution.ts | 24 +- .../window/contributions/tt-contribution.ts | 24 +- .../window/contributions/wx-contribution.ts | 24 +- packages/vrender/src/index.ts | 10 +- rush.json | 2 +- 309 files changed, 2193 insertions(+), 7090 deletions(-) create mode 100644 .claude/CLAUDE.md create mode 100644 .claude/settings.json create mode 100644 packages/vrender-core/di-removal-plan.md delete mode 100644 packages/vrender-core/src/common/contribution-provider.ts create mode 100644 packages/vrender-core/src/common/contribution-registry.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/annotation/decorator_utils.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/annotation/inject.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/annotation/inject_base.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/annotation/injectable.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/annotation/lazy_service_identifier.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/annotation/multi_inject.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/annotation/named.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/annotation/property_event_decorator.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/bindings/binding.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/bindings/binding_count.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/constants/error_msgs.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/constants/literal_types.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/constants/metadata_keys.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/container/container.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/container/container_module.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/container/lookup.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/index.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/interfaces/interfaces.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/planning/context.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/planning/metadata.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/planning/metadata_reader.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/planning/plan.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/planning/planner.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/planning/queryable_string.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/planning/reflection_utils.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/planning/request.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/planning/target.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/resolution/instantiation.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/resolution/resolver.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/scope/scope.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/syntax/binding_in_syntax.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/syntax/binding_in_when_on_syntax.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/syntax/binding_on_syntax.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/syntax/binding_to_syntax.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/syntax/binding_when_on_syntax.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/syntax/binding_when_syntax.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/syntax/constraint_helpers.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/utils/async.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/utils/binding_utils.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/utils/clonable.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/utils/exceptions.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/utils/factory_type.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/utils/id.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/utils/js.ts delete mode 100644 packages/vrender-core/src/common/inversify-lite/utils/serialization.ts delete mode 100644 packages/vrender-core/src/common/inversify/annotation/inject.ts delete mode 100644 packages/vrender-core/src/common/inversify/annotation/inject_base.ts delete mode 100644 packages/vrender-core/src/common/inversify/annotation/injectable.ts delete mode 100644 packages/vrender-core/src/common/inversify/annotation/multi_inject.ts delete mode 100644 packages/vrender-core/src/common/inversify/annotation/named.ts delete mode 100644 packages/vrender-core/src/common/inversify/annotation/optional.ts delete mode 100644 packages/vrender-core/src/common/inversify/binding.ts delete mode 100644 packages/vrender-core/src/common/inversify/container.ts delete mode 100644 packages/vrender-core/src/common/inversify/cotainer-module.ts delete mode 100644 packages/vrender-core/src/common/inversify/index.ts delete mode 100644 packages/vrender-core/src/common/inversify/interfaces.ts delete mode 100644 packages/vrender-core/src/common/inversify/literal_types.ts delete mode 100644 packages/vrender-core/src/common/inversify/meta-data.ts delete mode 100644 packages/vrender-core/src/common/inversify/metadata_keys.ts delete mode 100644 packages/vrender-core/src/common/inversify/metadata_reader.ts delete mode 100644 packages/vrender-core/src/common/inversify/syntax/binding_in_syntax.ts delete mode 100644 packages/vrender-core/src/common/inversify/syntax/binding_to_syntax.ts delete mode 100644 packages/vrender-core/src/common/inversify/syntax/constraint_helpers.ts create mode 100644 packages/vrender-core/src/common/registry/contribution-registry.ts create mode 100644 packages/vrender-core/src/common/registry/index.ts create mode 100644 packages/vrender-core/src/common/registry/service-registry.ts create mode 100644 packages/vrender-core/src/common/registry/types.ts create mode 100644 packages/vrender-core/src/common/service-factory.ts create mode 100644 packages/vrender-core/src/common/service-registry.ts create mode 100644 packages/vrender-core/src/common/types.ts delete mode 100644 packages/vrender-core/src/container.ts delete mode 100644 packages/vrender-core/src/core/contributions/env/modules.ts delete mode 100644 packages/vrender-core/src/core/contributions/layerHandler/modules.ts delete mode 100644 packages/vrender-core/src/core/contributions/textMeasure/modules.ts delete mode 100644 packages/vrender-core/src/core/core-modules.ts delete mode 100644 packages/vrender-core/src/core/global-module.ts delete mode 100644 packages/vrender-core/src/graphic/graphic-service/graphic-module.ts delete mode 100644 packages/vrender-core/src/picker/pick-modules.ts delete mode 100644 packages/vrender-core/src/plugins/plugin-modules.ts create mode 100644 packages/vrender-core/src/register-modules.ts delete mode 100644 packages/vrender-core/src/render/contributions/modules.ts delete mode 100644 packages/vrender-core/src/render/contributions/render/arc-module.ts delete mode 100644 packages/vrender-core/src/render/contributions/render/arc3d-module.ts delete mode 100644 packages/vrender-core/src/render/contributions/render/area-module.ts delete mode 100644 packages/vrender-core/src/render/contributions/render/circle-module.ts delete mode 100644 packages/vrender-core/src/render/contributions/render/glyph-module.ts delete mode 100644 packages/vrender-core/src/render/contributions/render/image-module.ts delete mode 100644 packages/vrender-core/src/render/contributions/render/line-module.ts delete mode 100644 packages/vrender-core/src/render/contributions/render/module.ts delete mode 100644 packages/vrender-core/src/render/contributions/render/path-module.ts delete mode 100644 packages/vrender-core/src/render/contributions/render/polygon-module.ts delete mode 100644 packages/vrender-core/src/render/contributions/render/pyramid3d-module.ts delete mode 100644 packages/vrender-core/src/render/contributions/render/rect-module.ts delete mode 100644 packages/vrender-core/src/render/contributions/render/rect3d-module.ts delete mode 100644 packages/vrender-core/src/render/contributions/render/richtext-module.ts delete mode 100644 packages/vrender-core/src/render/contributions/render/star-module.ts delete mode 100644 packages/vrender-core/src/render/contributions/render/symbol-module.ts delete mode 100644 packages/vrender-core/src/render/contributions/render/text-module.ts delete mode 100644 packages/vrender-core/src/render/render-modules.ts diff --git a/.claude/CLAUDE.md b/.claude/CLAUDE.md new file mode 100644 index 000000000..9ca04166f --- /dev/null +++ b/.claude/CLAUDE.md @@ -0,0 +1,104 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +> 说明:本仓库是 **Rush + PNPM** 管理的 monorepo(见 `rush.json`、`common/config/rush/*`)。大多数开发命令应通过 `rush` 运行。 + +## 常用命令(开发/构建/测试) + +### 安装依赖 + +```bash +rush install +``` + +> `rush.json` 指定了 PNPM 版本与 Node 支持范围(`nodeSupportedVersionRange`)。 + +### 构建 + +```bash +# 构建所有项目(bulk command) +rush build + +# 重新构建所有项目(bulk command) +rush rebuild + +# 仅构建某个 package(在该 package 的 scripts 中存在 build 时) +rush run -p @visactor/vrender-core -s build +``` + +### 启动开发服务 + +```bash +# 启动 VRender 开发服务(等价于:rush run -p @visactor/vrender -s start) +rush start + +# 启动组件库开发服务(等价于:rush run -p @visactor/vrender-components -s start) +rush components + +# 启动文档站点开发服务(等价于:rush run -p @internal/docs -s start) +rush docs +``` + +### Lint / 格式化 + +```bash +# 运行各 package 的 eslint 脚本(bulk command) +rush eslint + +# 预提交相关(仓库自定义全局命令,见 common/config/rush/command-line.json) +rush lint-staged +rush prettier +``` + +### 测试 + +```bash +# 运行各 package 的 test 脚本(bulk command) +rush test + +# 仅运行某个 package 的测试(前提:该 package 定义了 test 脚本) +rush run -p @visactor/vrender-core -s test + +# 运行单个测试文件/用例: +# 本仓库通常使用 Jest(见 share/jest-config),具体参数以对应 package 的 test 脚本为准。 +# 常见做法是把 Jest 参数透传给 package 的 test 脚本,例如: +# rush run -p @visactor/vrender-core -s test -- --runTestsByPath +``` + +## 代码架构(大图景) + +### Monorepo 包划分(按职责) + +- `packages/vrender`:对外的“整合包”。入口会根据运行环境(browser/node)加载对应 env,并注册常用图元、插件与动画,然后 re-export 各子包能力(见 `packages/vrender/src/index.ts`)。 +- `packages/vrender-core`:渲染核心与基础设施(Stage/Layer/Window、渲染管线、事件、拾取、插件系统、资源加载等)。对外导出面很大(见 `packages/vrender-core/src/index.ts`)。 +- `packages/vrender-kits`:图元/环境适配与“套件”能力(例如 browser/node 环境加载、各类 registerXXX 图元注册函数等;整合包会调用这些注册)。 +- `packages/vrender-animate`:动画系统与自定义动画(ticker、插值、状态动画、组件动画扩展等)。 +- `packages/vrender-components`:更高层的可复用组件(如 axis、brush 等),通常依赖 core/kits。 +- `packages/react-vrender`、`packages/react-vrender-utils`:React 绑定/宿主配置与工具。 + +### 核心运行时模型:Window / Stage / Layer + +(仓库内也有简短说明:`packages/vrender-core/src/core/README.md`) + +- **Window**:对接“原生环境窗口/Canvas 区域”的抽象(浏览器 Canvas、小程序 Canvas 等)。 +- **Stage**:逻辑上的“舞台/视口”,不必与单个 Canvas 一一对应;可以是整个窗口,也可以是窗口中的一个区域。Stage 负责组织图形树、驱动渲染与事件系统(见 `packages/vrender-core/src/core/stage.ts`)。 +- **Layer**:Stage 内的图层抽象。多图层时通常对应多个底层渲染目标(Canvas / ImageData / WebGL FrameBuffer 等),并支持子图层与混合(见 `packages/vrender-core/src/core/layer.ts`)。 + +### 图形树与创建入口 + +- 图形对象以 `Group` 为容器节点,Stage/Layer 也继承自 `Group`,因此“场景图”本质是一棵图形树。 +- 常用创建入口:`createStage`(见 `packages/vrender-core/src/create.ts`)。 + +### 插件与模块注册(“按需注册”思路) + +- `@visactor/vrender`(整合包)在入口中会: + 1) `preLoadAllModule()` 预加载模块; + 2) 根据环境调用 `loadBrowserEnv/loadNodeEnv`; + 3) 调用大量 `registerXXX()` 注册图元; + 4) 注册内置插件(flex layout、3D view transform、HTML/React attribute 等); + 5) 注册动画(`registerCustomAnimate/registerAnimate`)。 + +这意味着: +- 如果你在 **core/kits/animate/components** 中新增能力,通常需要提供/更新对应的 `register...` 入口,并确认整合包是否需要默认注册。 +- 排查“某图元/能力不可用”时,优先检查是否已注册(入口通常在 `packages/vrender/src/index.ts` 或各包的 `register/` 目录)。 diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 000000000..d9e17ddc5 --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,6 @@ +{ + "permissions": { + "defaultMode": "bypassPermissions" + }, + "enableAllProjectMcpServers": true +} diff --git a/.gitignore b/.gitignore index 592fd6d7c..7a80acb74 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,8 @@ report.html coverage/ *.local.ts +*.local.md +*.local.json # Dependency directories node_modules/ diff --git a/packages/vrender-core/di-removal-plan.md b/packages/vrender-core/di-removal-plan.md new file mode 100644 index 000000000..1da653520 --- /dev/null +++ b/packages/vrender-core/di-removal-plan.md @@ -0,0 +1,63 @@ +# vrender-core 去 DI(inversify / Reflect-metadata)改造进度更新 + +## 当前状态(Registry-only 已落地) +- 运行时架构已切换到 ServiceRegistry + ContributionRegistry: + - Stage/Window/Render/Plugin/Picker 等核心路径不再使用 container.get/ContainerModule + - preLoadAllModule() 由 registerAllModules() 完成默认注册(无 ContainerModule) +- Canvas 工厂与 Context 工厂: + - wrapCanvas/wrapContext 通过 ContributionRegistry 按 env 选择工厂(不再使用 container.getNamed) +- Kits 环境与窗口: + - kits 平台(browser/node/wx/feishu/taro/lynx/harmony/tt)统一通过 registerXxxEnvRegistry 注册 Env 与 WindowHandler,实现 registry-only + +## 已删除/置空的旧模块 +- 入口模块与加载器(改为 no-op): + - render/render-modules.ts(no-op) + - render/contributions/modules.ts(no-op) + - core/contributions/modules.ts(no-op) + - core/core-modules.ts(no-op) +- env/layer/textMeasure 模块(no-op): + - core/contributions/env/modules.ts + - core/contributions/layerHandler/modules.ts + - core/contributions/textMeasure/modules.ts +- picker/plugin/graphic 模块(no-op): + - picker/pick-modules.ts + - plugins/plugin-modules.ts + - graphic/graphic-service/graphic-module.ts +- 渲染单元模块导出(全部删除旧导出): + - text/symbol/rect/path/image/area/arc/circle/polygon/line/glyph/star/richtext/rect3d/arc3d/pyramid3d 的 *-module.ts 均已移除导出与内部 ContainerModule 逻辑 + +## 已删除的 DI 基础设施 +- 删除目录: + - src/common/inversify-lite/** + - src/common/inversify/** +- 删除文件: + - src/container.ts + - src/common/contribution-provider.ts(退役化后整体删除) + - src/core/global-module.ts + +## 关键文件现状 +- core/stage.ts:通过 serviceRegistry.createInstance/get 获取 IWindow/IRenderService/IPickerService/Plugin/Layer/Graphic 服务(不再使用 container) +- core/window.ts:通过 application.contributions.get(WindowHandlerContribution) 按 env 选择 handler +- canvas/util.ts:通过 ContributionRegistry 获取 ICanvasFactory/IContext2dFactory +- modules.ts:preLoadAllModule → registerAllModules,随后从 serviceRegistry 获取并挂载 application.global/graphicUtil/transformUtil/graphicService/layerService + +## 后续检查清单 +- 构建验证: + - rush build(确保删除的目录/文件不在编译输入中) + - 类型检查是否仍有对 removed 文件/目录的引用 +- 注册面完整性: + - registerAllModules 与 kits 的 registerXxxEnvRegistry 是否覆盖所有默认能力 +- 测试与示例: + - 移除/更新仍引用旧 ContainerModule 或 container 的测试/示例 + - Smoke test:createStage + 基本渲染/拾取/插件启用流程 +- 对外导出清理: + - 确认 core/index.ts 不再暴露 common/inversify(-lite) 能力(breaking 已接受) + +## 风险与对策(维持不变) +- 初始化顺序/副作用:保留 index.ts 的 side-effect 初始化,preLoadAllModule() 等价 +- 贡献列表顺序:ContributionRegistry 保持 order 语义 +- 多端构建兼容:在 wx/tt/feishu 等 demo/产物中进行 smoke test,确保无 Reflect 依赖 + +## 完成标记 +- 旧 DI 路径已全面移除,运行时完全 registry-only +- 等待构建与测试通过后关闭此计划 diff --git a/packages/vrender-core/src/application.ts b/packages/vrender-core/src/application.ts index 39a7f0560..9d07e81fb 100644 --- a/packages/vrender-core/src/application.ts +++ b/packages/vrender-core/src/application.ts @@ -1,8 +1,9 @@ import type { ILayerService } from './interface/core'; import type { IGraphicUtil, ITransformUtil } from './interface/core'; import type { IGlobal, IGraphicService, IRenderService } from './interface'; -import { container } from './container'; import { RenderService } from './render/constants'; +import { serviceRegistry, contributionRegistry } from './common/registry'; +import type { ServiceRegistry, ContributionRegistry } from './common/registry'; export class Application { global: IGlobal; @@ -10,13 +11,17 @@ export class Application { graphicService: IGraphicService; get renderService(): IRenderService { if (!this._renderService) { - this._renderService = container.get(RenderService); + this._renderService = serviceRegistry.createInstance(RenderService); } return this._renderService; } private _renderService: IRenderService; transformUtil: ITransformUtil; layerService: ILayerService; + + // 新的注册表系统 + readonly services: ServiceRegistry = serviceRegistry; + readonly contributions: ContributionRegistry = contributionRegistry; } export const application = new Application(); diff --git a/packages/vrender-core/src/canvas/empty-context.ts b/packages/vrender-core/src/canvas/empty-context.ts index 14350ced7..05de59c5f 100644 --- a/packages/vrender-core/src/canvas/empty-context.ts +++ b/packages/vrender-core/src/canvas/empty-context.ts @@ -1,6 +1,5 @@ import type { IMatrix } from '@visactor/vutils'; import { Matrix } from '@visactor/vutils'; -import { injectable } from '../common/inversify-lite'; import type { ICanvas, ICommonStyleParams, @@ -45,13 +44,12 @@ import { matrixAllocate } from '../allocator/matrix-allocate'; const initMatrix = new Matrix(1, 0, 0, 1, 0, 0); const globalPoint = { x: 0, y: 0 }; -@injectable() export class EmptyContext2d implements IContext2d { declare path: CustomPath2D; declare canvas: null; declare stack: Matrix[]; - declare protected matrix: Matrix; - declare protected applyedMatrix?: Matrix; // 被应用的matrix + protected declare matrix: Matrix; + protected declare applyedMatrix?: Matrix; // 被应用的matrix // 属性代理 declare fillStyle: string | CanvasGradient | CanvasPattern; /** diff --git a/packages/vrender-core/src/canvas/util.ts b/packages/vrender-core/src/canvas/util.ts index 1b7effd07..22f759e95 100644 --- a/packages/vrender-core/src/canvas/util.ts +++ b/packages/vrender-core/src/canvas/util.ts @@ -2,17 +2,26 @@ import type { IPointLike, vec2 } from '@visactor/vutils'; import { isPointInLine, pi, pi2 } from '@visactor/vutils'; import { enumCommandMap as CMD } from '../common/path-svg'; import type { CommandType, IContext2d } from '../interface'; -import { container } from '../container'; import { application } from '../application'; import { CanvasFactory, Context2dFactory } from './constants'; import type { CanvasConfigType, ICanvas, ICanvasFactory, IContext2dFactory } from '../interface'; export function wrapCanvas(params: CanvasConfigType) { - return container.getNamed(CanvasFactory, application.global.env)(params); + const factories = application.contributions.get(CanvasFactory); + const factory = factories.find((f: any) => (f as any).env === application.global.env) ?? factories[0]; + if (!factory) { + throw new Error('No CanvasFactory registered'); + } + return factory(params); } export function wrapContext(canvas: ICanvas, dpr: number) { - return container.getNamed(Context2dFactory, application.global.env)(canvas, dpr); + const factories = application.contributions.get(Context2dFactory); + const factory = factories.find((f: any) => (f as any).env === application.global.env) ?? factories[0]; + if (!factory) { + throw new Error('No Context2dFactory registered'); + } + return factory(canvas, dpr); } // 源码参考 http://pomax.github.io/bezierinfo/#projections /** diff --git a/packages/vrender-core/src/common/contribution-provider.ts b/packages/vrender-core/src/common/contribution-provider.ts deleted file mode 100644 index 043e6b71c..000000000 --- a/packages/vrender-core/src/common/contribution-provider.ts +++ /dev/null @@ -1,67 +0,0 @@ -import type { interfaces } from '../common/inversify-lite'; -import type { IContributionProvider } from '../interface'; - -export const ContributionProvider = Symbol('ContributionProvider'); - -class ContributionProviderCache implements IContributionProvider { - protected caches?: T[]; - protected serviceIdentifier: interfaces.ServiceIdentifier; - protected container: interfaces.Container; - - constructor(serviceIdentifier: interfaces.ServiceIdentifier, container: interfaces.Container) { - this.serviceIdentifier = serviceIdentifier; - this.container = container; - ContributionStore.setStore(this.serviceIdentifier, this); - } - - getContributions(): T[] { - if (!this.caches) { - this.caches = []; - this.container && - this.container.isBound(this.serviceIdentifier) && - this.caches.push(...this.container.getAll(this.serviceIdentifier)); - } - return this.caches; - } - - refresh() { - if (!this.caches) { - return; - } - this.caches.length = 0; - this.container && - this.container.isBound(this.serviceIdentifier) && - this.caches.push(...this.container.getAll(this.serviceIdentifier)); - } -} - -export function bindContributionProvider(bind: interfaces.Bind, id: any): void { - bind(ContributionProvider) - .toDynamicValue(({ container }) => new ContributionProviderCache(id, container)) - .inSingletonScope() - .whenTargetNamed(id); -} - -export function bindContributionProviderNoSingletonScope(bind: interfaces.Bind, id: any): void { - bind(ContributionProvider) - .toDynamicValue(({ container }) => new ContributionProviderCache(id, container)) - .whenTargetNamed(id); -} - -export class ContributionStore { - static store: Map, ContributionProviderCache> = new Map(); - - static getStore(id: interfaces.ServiceIdentifier): ContributionProviderCache { - return this.store.get(id); - } - - static setStore(id: interfaces.ServiceIdentifier, cache: ContributionProviderCache): void { - this.store.set(id, cache); - } - - static refreshAllContributions(): void { - this.store.forEach(cache => { - cache.refresh(); - }); - } -} diff --git a/packages/vrender-core/src/common/contribution-registry.ts b/packages/vrender-core/src/common/contribution-registry.ts new file mode 100644 index 000000000..5331943cc --- /dev/null +++ b/packages/vrender-core/src/common/contribution-registry.ts @@ -0,0 +1,90 @@ +/** + * ContributionRegistry - 贡献/扩展注册表 + * 替代 ContributionProvider + container.getAll() 的多实现聚合能力 + */ +import type { ServiceIdentifier } from './types'; + +export interface ContributionItem { + contribution: T; + order?: number; +} + +export class ContributionRegistry { + private contributions: Map, ContributionItem[]> = new Map(); + + /** + * 注册一个贡献实现 + */ + register(id: ServiceIdentifier, contribution: T, order: number = 0): void { + let list = this.contributions.get(id); + if (!list) { + list = []; + this.contributions.set(id, list); + } + list.push({ contribution, order }); + } + + /** + * 获取所有贡献(按 order 排序) + */ + getContributions(id: ServiceIdentifier): T[] { + const list = this.contributions.get(id); + if (!list || list.length === 0) { + return []; + } + // 按 order 升序排序 + return list.sort((a, b) => (a.order ?? 0) - (b.order ?? 0)).map(item => item.contribution); + } + + /** + * 检查是否有贡献注册 + */ + has(id: ServiceIdentifier): boolean { + const list = this.contributions.get(id); + return list !== undefined && list.length > 0; + } + + /** + * 移除某个 token 下的所有贡献 + */ + remove(id: ServiceIdentifier): void { + this.contributions.delete(id); + } + + /** + * 移除某个具体的贡献实例 + */ + removeContribution(id: ServiceIdentifier, contribution: T): void { + const list = this.contributions.get(id); + if (list) { + const index = list.findIndex(item => item.contribution === contribution); + if (index !== -1) { + list.splice(index, 1); + } + } + } + + /** + * 刷新指定 token 的贡献列表(清空缓存,下次 get 时重新排序) + */ + refresh(id: ServiceIdentifier): void { + // 当前实现不需要特殊处理,因为每次 getContributions 都会重新排序 + // 保留此方法以兼容 ContributionProvider 的 refresh 语义 + } + + /** + * 刷新所有贡献列表 + */ + refreshAll(): void { + // 同上 + } + + /** + * 清空所有注册 + */ + clear(): void { + this.contributions.clear(); + } +} + +export const contributionRegistry = new ContributionRegistry(); diff --git a/packages/vrender-core/src/common/inversify-lite/annotation/decorator_utils.ts b/packages/vrender-core/src/common/inversify-lite/annotation/decorator_utils.ts deleted file mode 100644 index c7e0df312..000000000 --- a/packages/vrender-core/src/common/inversify-lite/annotation/decorator_utils.ts +++ /dev/null @@ -1,146 +0,0 @@ -import * as ERROR_MSGS from '../constants/error_msgs'; -import * as METADATA_KEY from '../constants/metadata_keys'; -import type { interfaces } from '../interfaces/interfaces'; -import { getFirstArrayDuplicate } from '../utils/js'; -import Reflect from '../../Reflect-metadata'; - -function targetIsConstructorFunction(target: DecoratorTarget): target is ConstructorFunction { - return (target as ConstructorFunction).prototype !== undefined; -} - -type Prototype = { - [Property in keyof T]: T[Property] extends NewableFunction ? T[Property] : T[Property] | undefined; -} & { constructor: NewableFunction }; - -interface ConstructorFunction> { - new (...args: unknown[]): T; - prototype: Prototype; -} - -export type DecoratorTarget = ConstructorFunction | Prototype; - -function _throwIfMethodParameter(parameterName: string | symbol | undefined): void { - if (parameterName !== undefined) { - throw new Error(ERROR_MSGS.INVALID_DECORATOR_OPERATION); - } -} - -function tagParameter( - annotationTarget: DecoratorTarget, - parameterName: string | symbol | undefined, - parameterIndex: number, - metadata: interfaces.MetadataOrMetadataArray -) { - _throwIfMethodParameter(parameterName); - _tagParameterOrProperty( - METADATA_KEY.TAGGED, - annotationTarget as ConstructorFunction, - parameterIndex.toString(), - metadata - ); -} - -function tagProperty( - annotationTarget: DecoratorTarget, - propertyName: string | symbol, - metadata: interfaces.MetadataOrMetadataArray -) { - if (targetIsConstructorFunction(annotationTarget)) { - throw new Error(ERROR_MSGS.INVALID_DECORATOR_OPERATION); - } - _tagParameterOrProperty(METADATA_KEY.TAGGED_PROP, annotationTarget.constructor, propertyName, metadata); -} - -function _ensureNoMetadataKeyDuplicates(metadata: interfaces.MetadataOrMetadataArray): interfaces.Metadata[] { - let metadatas: interfaces.Metadata[] = []; - if (Array.isArray(metadata)) { - metadatas = metadata; - const duplicate = getFirstArrayDuplicate(metadatas.map(md => md.key)); - if (duplicate !== undefined) { - throw new Error(`${ERROR_MSGS.DUPLICATED_METADATA} ${duplicate.toString()}`); - } - } else { - metadatas = [metadata]; - } - return metadatas; -} - -function _tagParameterOrProperty( - metadataKey: string, - annotationTarget: NewableFunction, - key: string | symbol, - metadata: interfaces.MetadataOrMetadataArray -) { - const metadatas: interfaces.Metadata[] = _ensureNoMetadataKeyDuplicates(metadata); - - let paramsOrPropertiesMetadata: Record = {}; - // read metadata if available - if ((Reflect as any).hasOwnMetadata(metadataKey, annotationTarget)) { - paramsOrPropertiesMetadata = (Reflect as any).getMetadata(metadataKey, annotationTarget); - } - - let paramOrPropertyMetadata: interfaces.Metadata[] | undefined = paramsOrPropertiesMetadata[key as string]; - - if (paramOrPropertyMetadata === undefined) { - paramOrPropertyMetadata = []; - } else { - for (const m of paramOrPropertyMetadata) { - if (metadatas.some(md => md.key === m.key)) { - throw new Error(`${ERROR_MSGS.DUPLICATED_METADATA} ${m.key.toString()}`); - } - } - } - - // set metadata - paramOrPropertyMetadata.push(...metadatas); - paramsOrPropertiesMetadata[key] = paramOrPropertyMetadata; - (Reflect as any).defineMetadata(metadataKey, paramsOrPropertiesMetadata, annotationTarget); -} - -function createTaggedDecorator(metadata: interfaces.MetadataOrMetadataArray) { - return ( - target: DecoratorTarget, - targetKey?: string | symbol, - indexOrPropertyDescriptor?: number | TypedPropertyDescriptor - ) => { - if (typeof indexOrPropertyDescriptor === 'number') { - tagParameter(target, targetKey, indexOrPropertyDescriptor, metadata); - } else { - tagProperty(target, targetKey as string | symbol, metadata); - } - }; -} - -function _decorate( - decorators: (DecoratorTarget | ParameterDecorator | MethodDecorator)[], - target: any | NewableFunction -): void { - (Reflect as any).decorate(decorators as ClassDecorator[], target as NewableFunction); -} - -function _param(paramIndex: number, decorator: ParameterDecorator) { - return function (target: string, key: string) { - decorator(target, key, paramIndex); - }; -} - -// Allows VanillaJS developers to use decorators: -// decorate(injectable(), FooBar); -// decorate(targetName('foo', 'bar'), FooBar); -// decorate(named('foo'), FooBar, 0); -// decorate(tagged('bar'), FooBar, 1); -function decorate( - decorator: DecoratorTarget | ParameterDecorator | MethodDecorator, - target: any, - parameterIndexOrProperty?: number | string -): void { - if (typeof parameterIndexOrProperty === 'number') { - _decorate([_param(parameterIndexOrProperty, decorator as ParameterDecorator)], target); - } else if (typeof parameterIndexOrProperty === 'string') { - (Reflect as any).decorate([decorator as MethodDecorator], target, parameterIndexOrProperty); - } else { - _decorate([decorator], target); - } -} - -export { decorate, tagParameter, tagProperty, createTaggedDecorator }; diff --git a/packages/vrender-core/src/common/inversify-lite/annotation/inject.ts b/packages/vrender-core/src/common/inversify-lite/annotation/inject.ts deleted file mode 100644 index 392c85df0..000000000 --- a/packages/vrender-core/src/common/inversify-lite/annotation/inject.ts +++ /dev/null @@ -1,6 +0,0 @@ -import * as METADATA_KEY from '../constants/metadata_keys'; -import { injectBase } from './inject_base'; - -const inject = injectBase(METADATA_KEY.INJECT_TAG); - -export { inject }; diff --git a/packages/vrender-core/src/common/inversify-lite/annotation/inject_base.ts b/packages/vrender-core/src/common/inversify-lite/annotation/inject_base.ts deleted file mode 100644 index 333447f79..000000000 --- a/packages/vrender-core/src/common/inversify-lite/annotation/inject_base.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { UNDEFINED_INJECT_ANNOTATION } from '../constants/error_msgs'; -import { Metadata } from '../planning/metadata'; -import type { DecoratorTarget } from './decorator_utils'; -import { createTaggedDecorator } from './decorator_utils'; -import type { ServiceIdentifierOrFunc } from './lazy_service_identifier'; - -export function injectBase(metadataKey: string) { - return (serviceIdentifier: ServiceIdentifierOrFunc) => { - return ( - target: DecoratorTarget, - targetKey?: string | symbol, - indexOrPropertyDescriptor?: number | TypedPropertyDescriptor - ) => { - if (serviceIdentifier === undefined) { - const className = typeof target === 'function' ? target.name : target.constructor.name; - - throw new Error(UNDEFINED_INJECT_ANNOTATION(className)); - } - return createTaggedDecorator(new Metadata(metadataKey, serviceIdentifier))( - target, - targetKey, - indexOrPropertyDescriptor - ); - }; - }; -} diff --git a/packages/vrender-core/src/common/inversify-lite/annotation/injectable.ts b/packages/vrender-core/src/common/inversify-lite/annotation/injectable.ts deleted file mode 100644 index 64f0512c5..000000000 --- a/packages/vrender-core/src/common/inversify-lite/annotation/injectable.ts +++ /dev/null @@ -1,18 +0,0 @@ -import * as ERRORS_MSGS from '../constants/error_msgs'; -import * as METADATA_KEY from '../constants/metadata_keys'; -import Reflect from '../../Reflect-metadata'; - -function injectable() { - return function unknown>(target: T) { - if ((Reflect as any).hasOwnMetadata(METADATA_KEY.PARAM_TYPES, target)) { - throw new Error(ERRORS_MSGS.DUPLICATED_INJECTABLE_DECORATOR); - } - - const types = (Reflect as any).getMetadata(METADATA_KEY.DESIGN_PARAM_TYPES, target) || []; - (Reflect as any).defineMetadata(METADATA_KEY.PARAM_TYPES, types, target); - - return target; - }; -} - -export { injectable }; diff --git a/packages/vrender-core/src/common/inversify-lite/annotation/lazy_service_identifier.ts b/packages/vrender-core/src/common/inversify-lite/annotation/lazy_service_identifier.ts deleted file mode 100644 index 1c028297c..000000000 --- a/packages/vrender-core/src/common/inversify-lite/annotation/lazy_service_identifier.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { interfaces } from '../interfaces/interfaces'; - -export type ServiceIdentifierOrFunc = interfaces.ServiceIdentifier | LazyServiceIdentifer; - -export class LazyServiceIdentifer { - private _cb: () => interfaces.ServiceIdentifier; - constructor(cb: () => interfaces.ServiceIdentifier) { - this._cb = cb; - } - - unwrap() { - return this._cb(); - } -} diff --git a/packages/vrender-core/src/common/inversify-lite/annotation/multi_inject.ts b/packages/vrender-core/src/common/inversify-lite/annotation/multi_inject.ts deleted file mode 100644 index ec234781b..000000000 --- a/packages/vrender-core/src/common/inversify-lite/annotation/multi_inject.ts +++ /dev/null @@ -1,6 +0,0 @@ -import * as METADATA_KEY from '../constants/metadata_keys'; -import { injectBase } from './inject_base'; - -const multiInject = injectBase(METADATA_KEY.MULTI_INJECT_TAG); - -export { multiInject }; diff --git a/packages/vrender-core/src/common/inversify-lite/annotation/named.ts b/packages/vrender-core/src/common/inversify-lite/annotation/named.ts deleted file mode 100644 index a13aa6d3f..000000000 --- a/packages/vrender-core/src/common/inversify-lite/annotation/named.ts +++ /dev/null @@ -1,10 +0,0 @@ -import * as METADATA_KEY from '../constants/metadata_keys'; -import { Metadata } from '../planning/metadata'; -import { createTaggedDecorator } from './decorator_utils'; - -// Used to add named metadata which is used to resolve name-based contextual bindings. -function named(name: string | number | symbol) { - return createTaggedDecorator(new Metadata(METADATA_KEY.NAMED_TAG, name)); -} - -export { named }; diff --git a/packages/vrender-core/src/common/inversify-lite/annotation/property_event_decorator.ts b/packages/vrender-core/src/common/inversify-lite/annotation/property_event_decorator.ts deleted file mode 100644 index 061fc3a59..000000000 --- a/packages/vrender-core/src/common/inversify-lite/annotation/property_event_decorator.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Metadata } from '../planning/metadata'; -import Reflect from '../../Reflect-metadata'; - -function propertyEventDecorator(eventKey: string, errorMessage: string) { - return () => { - return (target: { constructor: NewableFunction }, propertyKey: string) => { - const metadata = new Metadata(eventKey, propertyKey); - - if ((Reflect as any).hasOwnMetadata(eventKey, target.constructor)) { - throw new Error(errorMessage); - } - (Reflect as any).defineMetadata(eventKey, metadata, target.constructor); - }; - }; -} - -export { propertyEventDecorator }; diff --git a/packages/vrender-core/src/common/inversify-lite/bindings/binding.ts b/packages/vrender-core/src/common/inversify-lite/bindings/binding.ts deleted file mode 100644 index 2e36f2322..000000000 --- a/packages/vrender-core/src/common/inversify-lite/bindings/binding.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { BindingScopeEnum, BindingTypeEnum } from '../constants/literal_types'; -import type { interfaces } from '../interfaces/interfaces'; -import { id } from '../utils/id'; - -class Binding implements interfaces.Binding { - id: number; - moduleId!: interfaces.ContainerModuleBase['id']; - - // Determines weather the bindings has been already activated - // The activation action takes place when an instance is resolved - // If the scope is singleton it only happens once - activated: boolean; - - // A runtime identifier because at runtime we don't have interfaces - serviceIdentifier: interfaces.ServiceIdentifier; - - // constructor from binding to or toConstructor - implementationType: interfaces.Newable | TActivated | null; - - // Cache used to allow singleton scope and BindingType.ConstantValue bindings - cache: TActivated | Promise | null; - - // Cache used to allow BindingType.DynamicValue bindings - dynamicValue: interfaces.DynamicValue | null; - - // The scope mode to be used - scope: interfaces.BindingScope; - - // The kind of binding - type: interfaces.BindingType; - - // A factory method used in BindingType.Factory bindings - factory: interfaces.FactoryCreator | null; - - // An async factory method used in BindingType.Provider bindings - provider: interfaces.ProviderCreator | null; - - // A constraint used to limit the contexts in which this binding is applicable - constraint: interfaces.ConstraintFunction; - - // On activation handler (invoked just before an instance is added to cache and injected) - onActivation: interfaces.BindingActivation | null; - - // On deactivation handler (invoked just before an instance is unbinded and removed from container) - onDeactivation: interfaces.BindingDeactivation | null; - - constructor(serviceIdentifier: interfaces.ServiceIdentifier, scope: interfaces.BindingScope) { - this.id = id(); - this.activated = false; - this.serviceIdentifier = serviceIdentifier; - this.scope = scope; - this.type = BindingTypeEnum.Invalid; - this.constraint = (request: interfaces.Request | null) => true; - this.implementationType = null; - this.cache = null; - this.factory = null; - this.provider = null; - this.onActivation = null; - this.onDeactivation = null; - this.dynamicValue = null; - } - - clone(): interfaces.Binding { - const clone = new Binding(this.serviceIdentifier, this.scope); - clone.activated = clone.scope === BindingScopeEnum.Singleton ? this.activated : false; - clone.implementationType = this.implementationType; - clone.dynamicValue = this.dynamicValue; - clone.scope = this.scope; - clone.type = this.type; - clone.factory = this.factory; - clone.provider = this.provider; - clone.constraint = this.constraint; - clone.onActivation = this.onActivation; - clone.onDeactivation = this.onDeactivation; - clone.cache = this.cache; - return clone; - } -} - -export { Binding }; diff --git a/packages/vrender-core/src/common/inversify-lite/bindings/binding_count.ts b/packages/vrender-core/src/common/inversify-lite/bindings/binding_count.ts deleted file mode 100644 index cc0913b70..000000000 --- a/packages/vrender-core/src/common/inversify-lite/bindings/binding_count.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const BindingCount = { - MultipleBindingsAvailable: 2, - NoBindingsAvailable: 0, - OnlyOneBindingAvailable: 1 -}; diff --git a/packages/vrender-core/src/common/inversify-lite/constants/error_msgs.ts b/packages/vrender-core/src/common/inversify-lite/constants/error_msgs.ts deleted file mode 100644 index e368a56f6..000000000 --- a/packages/vrender-core/src/common/inversify-lite/constants/error_msgs.ts +++ /dev/null @@ -1,61 +0,0 @@ -export const DUPLICATED_INJECTABLE_DECORATOR = 'Cannot apply @injectable decorator multiple times.'; -export const DUPLICATED_METADATA = 'Metadata key was used more than once in a parameter:'; -export const NULL_ARGUMENT = 'NULL argument'; -export const KEY_NOT_FOUND = 'Key Not Found'; -export const AMBIGUOUS_MATCH = 'Ambiguous match found for serviceIdentifier:'; -export const CANNOT_UNBIND = 'Could not unbind serviceIdentifier:'; -export const NOT_REGISTERED = 'No matching bindings found for serviceIdentifier:'; -export const MISSING_INJECTABLE_ANNOTATION = 'Missing required @injectable annotation in:'; -export const MISSING_INJECT_ANNOTATION = 'Missing required @inject or @multiInject annotation in:'; -export const UNDEFINED_INJECT_ANNOTATION = (name: string) => - `@inject called with undefined this could mean that the class ${name} has ` + - 'a circular dependency problem. You can use a LazyServiceIdentifer to ' + - 'overcome this limitation.'; -export const CIRCULAR_DEPENDENCY = 'Circular dependency found:'; -export const NOT_IMPLEMENTED = 'Sorry, this feature is not fully implemented yet.'; -export const INVALID_BINDING_TYPE = 'Invalid binding type:'; -export const NO_MORE_SNAPSHOTS_AVAILABLE = 'No snapshot available to restore.'; -export const INVALID_MIDDLEWARE_RETURN = 'Invalid return type in middleware. Middleware must return!'; -export const INVALID_FUNCTION_BINDING = 'Value provided to function binding must be a function!'; -export const LAZY_IN_SYNC = (key: unknown) => `You are attempting to construct '${key}' in a synchronous way - but it has asynchronous dependencies.`; - -export const INVALID_TO_SELF_VALUE = - 'The toSelf function can only be applied when a constructor is ' + 'used as service identifier'; - -export const INVALID_DECORATOR_OPERATION = - 'The @inject @multiInject @tagged and @named decorators ' + - 'must be applied to the parameters of a class constructor or a class property.'; - -export const ARGUMENTS_LENGTH_MISMATCH = (...values: unknown[]) => - 'The number of constructor arguments in the derived class ' + - `${values[0]} must be >= than the number of constructor arguments of its base class.`; - -export const CONTAINER_OPTIONS_MUST_BE_AN_OBJECT = - 'Invalid Container constructor argument. Container options ' + 'must be an object.'; - -export const CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE = - 'Invalid Container option. Default scope must ' + 'be a string ("singleton" or "transient").'; - -export const CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = - 'Invalid Container option. Auto bind injectable must ' + 'be a boolean'; - -export const CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK = - 'Invalid Container option. Skip base check must ' + 'be a boolean'; - -export const MULTIPLE_PRE_DESTROY_METHODS = 'Cannot apply @preDestroy decorator multiple times in the same class'; -export const MULTIPLE_POST_CONSTRUCT_METHODS = 'Cannot apply @postConstruct decorator multiple times in the same class'; -export const ASYNC_UNBIND_REQUIRED = - 'Attempting to unbind dependency with asynchronous destruction (@preDestroy or onDeactivation)'; -export const POST_CONSTRUCT_ERROR = (clazz: string, errorMessage: string) => - `@postConstruct error in class ${clazz}: ${errorMessage}`; -export const PRE_DESTROY_ERROR = (clazz: string, errorMessage: string) => - `@preDestroy error in class ${clazz}: ${errorMessage}`; -export const ON_DEACTIVATION_ERROR = (clazz: string, errorMessage: string) => - `onDeactivation() error in class ${clazz}: ${errorMessage}`; - -export const CIRCULAR_DEPENDENCY_IN_FACTORY = (factoryType: string, serviceIdentifier: string) => - `It looks like there is a circular dependency in one of the '${factoryType}' bindings. Please investigate bindings with ` + - `service identifier '${serviceIdentifier}'.`; - -export const STACK_OVERFLOW = 'Maximum call stack size exceeded'; diff --git a/packages/vrender-core/src/common/inversify-lite/constants/literal_types.ts b/packages/vrender-core/src/common/inversify-lite/constants/literal_types.ts deleted file mode 100644 index 8d0a70b17..000000000 --- a/packages/vrender-core/src/common/inversify-lite/constants/literal_types.ts +++ /dev/null @@ -1,26 +0,0 @@ -import type { interfaces } from '../interfaces/interfaces'; - -const BindingScopeEnum: interfaces.BindingScopeEnum = { - Request: 'Request', - Singleton: 'Singleton', - Transient: 'Transient' -}; - -const BindingTypeEnum: interfaces.BindingTypeEnum = { - ConstantValue: 'ConstantValue', - Constructor: 'Constructor', - DynamicValue: 'DynamicValue', - Factory: 'Factory', - Function: 'Function', - Instance: 'Instance', - Invalid: 'Invalid', - Provider: 'Provider' -}; - -const TargetTypeEnum: interfaces.TargetTypeEnum = { - ClassProperty: 'ClassProperty', - ConstructorArgument: 'ConstructorArgument', - Variable: 'Variable' -}; - -export { BindingScopeEnum, BindingTypeEnum, TargetTypeEnum }; diff --git a/packages/vrender-core/src/common/inversify-lite/constants/metadata_keys.ts b/packages/vrender-core/src/common/inversify-lite/constants/metadata_keys.ts deleted file mode 100644 index 5bf09bccf..000000000 --- a/packages/vrender-core/src/common/inversify-lite/constants/metadata_keys.ts +++ /dev/null @@ -1,41 +0,0 @@ -// Used for named bindings -export const NAMED_TAG = 'named'; - -// The name of the target at design time -export const NAME_TAG = 'name'; - -// The for unmanaged injections (in base classes when using inheritance) -export const UNMANAGED_TAG = 'unmanaged'; - -// The for optional injections -export const OPTIONAL_TAG = 'optional'; - -// The type of the binding at design time -export const INJECT_TAG = 'inject'; - -// The type of the binding at design type for multi-injections -export const MULTI_INJECT_TAG = 'multi_inject'; - -// used to store constructor arguments tags -export const TAGGED = 'inversify:tagged'; - -// used to store class properties tags -export const TAGGED_PROP = 'inversify:tagged_props'; - -// used to store types to be injected -export const PARAM_TYPES = 'inversify:paramtypes'; - -// used to access design time types -export const DESIGN_PARAM_TYPES = 'design:paramtypes'; - -// used to identify postConstruct functions -export const POST_CONSTRUCT = 'post_construct'; - -// used to identify preDestroy functions -export const PRE_DESTROY = 'pre_destroy'; - -function getNonCustomTagKeys(): string[] { - return [INJECT_TAG, MULTI_INJECT_TAG, NAME_TAG, UNMANAGED_TAG, NAMED_TAG, OPTIONAL_TAG]; -} - -export const NON_CUSTOM_TAG_KEYS: string[] = getNonCustomTagKeys(); diff --git a/packages/vrender-core/src/common/inversify-lite/container/container.ts b/packages/vrender-core/src/common/inversify-lite/container/container.ts deleted file mode 100644 index 189e1b9f5..000000000 --- a/packages/vrender-core/src/common/inversify-lite/container/container.ts +++ /dev/null @@ -1,698 +0,0 @@ -import { Binding } from '../bindings/binding'; -import * as ERROR_MSGS from '../constants/error_msgs'; -import { BindingScopeEnum, TargetTypeEnum } from '../constants/literal_types'; -import * as METADATA_KEY from '../constants/metadata_keys'; -import type { interfaces } from '../interfaces/interfaces'; -import { MetadataReader } from '../planning/metadata_reader'; -import { createMockRequest, getBindingDictionary, plan } from '../planning/planner'; -import { resolve } from '../resolution/resolver'; -import { BindingToSyntax } from '../syntax/binding_to_syntax'; -import { isPromise, isPromiseOrContainsPromise } from '../utils/async'; -import { id } from '../utils/id'; -import { getServiceIdentifierAsString } from '../utils/serialization'; -import { Lookup } from './lookup'; -import Reflect from '../../Reflect-metadata'; -// import { ModuleActivationStore } from './module_activation_store'; - -type GetArgs = Omit, 'contextInterceptor' | 'targetType'>; - -class Container implements interfaces.Container { - id: number; - parent: interfaces.Container | null; - readonly options: interfaces.ContainerOptions; - // private _middleware: interfaces.Next | null; - private _bindingDictionary: interfaces.Lookup>; - // private _activations: interfaces.Lookup>; - // private _deactivations: interfaces.Lookup>; - private _metadataReader: interfaces.MetadataReader; - // private _moduleActivationStore: interfaces.ModuleActivationStore; - - static merge( - container1: interfaces.Container, - container2: interfaces.Container, - ...containers: interfaces.Container[] - ): interfaces.Container { - const container = new Container(); - const targetContainers: interfaces.Lookup>[] = [ - container1, - container2, - ...containers - ].map(targetContainer => getBindingDictionary(targetContainer)); - const bindingDictionary: interfaces.Lookup> = getBindingDictionary(container); - - function copyDictionary( - origin: interfaces.Lookup>, - destination: interfaces.Lookup> - ) { - origin.traverse((_key, value) => { - value.forEach(binding => { - destination.add(binding.serviceIdentifier, binding.clone()); - }); - }); - } - - targetContainers.forEach(targetBindingDictionary => { - copyDictionary(targetBindingDictionary, bindingDictionary); - }); - - return container; - } - - constructor(containerOptions?: interfaces.ContainerOptions) { - const options = containerOptions || {}; - if (typeof options !== 'object') { - throw new Error(`${ERROR_MSGS.CONTAINER_OPTIONS_MUST_BE_AN_OBJECT}`); - } - - if (options.defaultScope === undefined) { - options.defaultScope = BindingScopeEnum.Transient; - } else if ( - options.defaultScope !== BindingScopeEnum.Singleton && - options.defaultScope !== BindingScopeEnum.Transient && - options.defaultScope !== BindingScopeEnum.Request - ) { - throw new Error(`${ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE}`); - } - - if (options.autoBindInjectable === undefined) { - options.autoBindInjectable = false; - } else if (typeof options.autoBindInjectable !== 'boolean') { - throw new Error(`${ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE}`); - } - - if (options.skipBaseClassChecks === undefined) { - options.skipBaseClassChecks = false; - } else if (typeof options.skipBaseClassChecks !== 'boolean') { - throw new Error(`${ERROR_MSGS.CONTAINER_OPTIONS_INVALID_SKIP_BASE_CHECK}`); - } - - this.options = { - autoBindInjectable: options.autoBindInjectable, - defaultScope: options.defaultScope, - skipBaseClassChecks: options.skipBaseClassChecks - }; - - this.id = id(); - this._bindingDictionary = new Lookup>(); - // this._middleware = null; - // this._activations = new Lookup>(); - // this._deactivations = new Lookup>(); - this.parent = null; - this._metadataReader = new MetadataReader(); - // this._moduleActivationStore = new ModuleActivationStore(); - } - - load(...modules: interfaces.ContainerModule[]) { - const getHelpers = this._getContainerModuleHelpersFactory(); - - for (const currentModule of modules) { - const containerModuleHelpers = getHelpers(currentModule.id); - - currentModule.registry( - containerModuleHelpers.bindFunction as interfaces.Bind, - containerModuleHelpers.unbindFunction, - containerModuleHelpers.isboundFunction, - containerModuleHelpers.rebindFunction as interfaces.Rebind - // containerModuleHelpers.unbindAsyncFunction, - // containerModuleHelpers.onActivationFunction as interfaces.Container['onActivation'], - // containerModuleHelpers.onDeactivationFunction as interfaces.Container['onDeactivation'] - ); - } - } - - unload(...modules: interfaces.ContainerModuleBase[]): void { - modules.forEach(module => { - const deactivations = this._removeModuleBindings(module.id); - this._deactivateSingletons(deactivations); - - // this._removeModuleHandlers(module.id); - }); - } - - // Registers a type binding - bind(serviceIdentifier: interfaces.ServiceIdentifier): interfaces.BindingToSyntax { - const scope = this.options.defaultScope || BindingScopeEnum.Transient; - const binding = new Binding(serviceIdentifier, scope); - this._bindingDictionary.add(serviceIdentifier, binding as Binding); - return new BindingToSyntax(binding); - } - - rebind(serviceIdentifier: interfaces.ServiceIdentifier): interfaces.BindingToSyntax { - this.unbind(serviceIdentifier); - return this.bind(serviceIdentifier); - } - - // public async rebindAsync( - // serviceIdentifier: interfaces.ServiceIdentifier - // ): Promise> { - // await this.unbindAsync(serviceIdentifier); - // return this.bind(serviceIdentifier); - // } - - // Removes a type binding from the registry by its key - unbind(serviceIdentifier: interfaces.ServiceIdentifier): void { - if (this._bindingDictionary.hasKey(serviceIdentifier)) { - const bindings = this._bindingDictionary.get(serviceIdentifier); - - this._deactivateSingletons(bindings); - } - - this._removeServiceFromDictionary(serviceIdentifier); - } - - // public async unbindAsync(serviceIdentifier: interfaces.ServiceIdentifier): Promise { - // if (this._bindingDictionary.hasKey(serviceIdentifier)) { - // const bindings = this._bindingDictionary.get(serviceIdentifier); - - // await this._deactivateSingletonsAsync(bindings); - // } - - // this._removeServiceFromDictionary(serviceIdentifier); - // } - - // Removes all the type bindings from the registry - unbindAll(): void { - this._bindingDictionary.traverse((_key, value) => { - this._deactivateSingletons(value); - }); - - this._bindingDictionary = new Lookup>(); - } - - // public async unbindAllAsync(): Promise { - // const promises: Promise[] = []; - - // this._bindingDictionary.traverse((_key, value) => { - // promises.push(this._deactivateSingletonsAsync(value)); - // }); - - // await Promise.all(promises); - - // this._bindingDictionary = new Lookup>(); - // } - - // public onActivation( - // serviceIdentifier: interfaces.ServiceIdentifier, - // onActivation: interfaces.BindingActivation - // ) { - // this._activations.add(serviceIdentifier, onActivation as interfaces.BindingActivation); - // } - - // public onDeactivation( - // serviceIdentifier: interfaces.ServiceIdentifier, - // onDeactivation: interfaces.BindingDeactivation - // ) { - // this._deactivations.add(serviceIdentifier, onDeactivation as interfaces.BindingDeactivation); - // } - - // Allows to check if there are bindings available for serviceIdentifier - isBound(serviceIdentifier: interfaces.ServiceIdentifier): boolean { - let bound = this._bindingDictionary.hasKey(serviceIdentifier); - if (!bound && this.parent) { - bound = this.parent.isBound(serviceIdentifier); - } - return bound; - } - - // check binding dependency only in current container - isCurrentBound(serviceIdentifier: interfaces.ServiceIdentifier): boolean { - return this._bindingDictionary.hasKey(serviceIdentifier); - } - - isBoundNamed(serviceIdentifier: interfaces.ServiceIdentifier, named: string | number | symbol): boolean { - return this.isBoundTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named); - } - - // Check if a binding with a complex constraint is available without throwing a error. Ancestors are also verified. - isBoundTagged( - serviceIdentifier: interfaces.ServiceIdentifier, - key: string | number | symbol, - value: unknown - ): boolean { - let bound = false; - - // verify if there are bindings available for serviceIdentifier on current binding dictionary - if (this._bindingDictionary.hasKey(serviceIdentifier)) { - const bindings = this._bindingDictionary.get(serviceIdentifier); - const request = createMockRequest(this, serviceIdentifier, key, value); - bound = bindings.some(b => b.constraint(request)); - } - - // verify if there is a parent container that could solve the request - if (!bound && this.parent) { - bound = this.parent.isBoundTagged(serviceIdentifier, key, value); - } - - return bound; - } - - applyCustomMetadataReader(metadataReader: interfaces.MetadataReader) { - this._metadataReader = metadataReader; - } - - // Resolves a dependency by its runtime identifier - // The runtime identifier must be associated with only one binding - // use getAll when the runtime identifier is associated with multiple bindings - get(serviceIdentifier: interfaces.ServiceIdentifier): T { - // if (!window.aaa) { - // window.aaa = 0; - // } - // const t = performance.now(); - const getArgs = this._getNotAllArgs(serviceIdentifier, false); - // const getArgs = { - // avoidConstraints: false, - // isMultiInject: false, - // serviceIdentifier - // }; - - const data = this._getButThrowIfAsync(getArgs) as T; - // const delta = performance.now() - t; - // window.aaa += delta; - - return data; - } - - async getAsync(serviceIdentifier: interfaces.ServiceIdentifier): Promise { - const getArgs = this._getNotAllArgs(serviceIdentifier, false); - - return this._get(getArgs) as Promise | T; - } - - getTagged(serviceIdentifier: interfaces.ServiceIdentifier, key: string | number | symbol, value: unknown): T { - const getArgs = this._getNotAllArgs(serviceIdentifier, false, key, value); - - return this._getButThrowIfAsync(getArgs) as T; - } - - // public async getTaggedAsync( - // serviceIdentifier: interfaces.ServiceIdentifier, - // key: string | number | symbol, - // value: unknown - // ): Promise { - // const getArgs = this._getNotAllArgs(serviceIdentifier, false, key, value); - - // return this._get(getArgs) as Promise | T; - // } - - getNamed(serviceIdentifier: interfaces.ServiceIdentifier, named: string | number | symbol): T { - return this.getTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named); - } - - // public getNamedAsync( - // serviceIdentifier: interfaces.ServiceIdentifier, - // named: string | number | symbol - // ): Promise { - // return this.getTaggedAsync(serviceIdentifier, METADATA_KEY.NAMED_TAG, named); - // } - - // Resolves a dependency by its runtime identifier - // The runtime identifier can be associated with one or multiple bindings - getAll(serviceIdentifier: interfaces.ServiceIdentifier): T[] { - const getArgs = this._getAllArgs(serviceIdentifier); - - return this._getButThrowIfAsync(getArgs) as T[]; - } - - // public getAllAsync(serviceIdentifier: interfaces.ServiceIdentifier): Promise { - // const getArgs = this._getAllArgs(serviceIdentifier); - - // return this._getAll(getArgs); - // } - - getAllTagged( - serviceIdentifier: interfaces.ServiceIdentifier, - key: string | number | symbol, - value: unknown - ): T[] { - const getArgs = this._getNotAllArgs(serviceIdentifier, true, key, value); - - return this._getButThrowIfAsync(getArgs) as T[]; - } - - // public getAllTaggedAsync( - // serviceIdentifier: interfaces.ServiceIdentifier, - // key: string | number | symbol, - // value: unknown - // ): Promise { - // const getArgs = this._getNotAllArgs(serviceIdentifier, true, key, value); - - // return this._getAll(getArgs); - // } - - getAllNamed(serviceIdentifier: interfaces.ServiceIdentifier, named: string | number | symbol): T[] { - return this.getAllTagged(serviceIdentifier, METADATA_KEY.NAMED_TAG, named); - } - - // public getAllNamedAsync( - // serviceIdentifier: interfaces.ServiceIdentifier, - // named: string | number | symbol - // ): Promise { - // return this.getAllTaggedAsync(serviceIdentifier, METADATA_KEY.NAMED_TAG, named); - // } - - resolve(constructorFunction: interfaces.Newable) { - const isBound = this.isBound(constructorFunction); - if (!isBound) { - this.bind(constructorFunction).toSelf(); - } - const resolved = this.get(constructorFunction); - if (!isBound) { - this.unbind(constructorFunction); - } - return resolved; - } - - private _preDestroy(constructor: NewableFunction, instance: T): Promise | void { - if ((Reflect as any).hasMetadata(METADATA_KEY.PRE_DESTROY, constructor)) { - const data: interfaces.Metadata = (Reflect as any).getMetadata(METADATA_KEY.PRE_DESTROY, constructor); - return (instance as interfaces.Instance)[data.value as string]?.(); - } - } - // private _removeModuleHandlers(moduleId: number): void { - // const moduleActivationsHandlers = this._moduleActivationStore.remove(moduleId); - - // this._activations.removeIntersection(moduleActivationsHandlers.onActivations); - // this._deactivations.removeIntersection(moduleActivationsHandlers.onDeactivations); - // } - - private _removeModuleBindings(moduleId: number): interfaces.Binding[] { - return this._bindingDictionary.removeByCondition(binding => binding.moduleId === moduleId); - } - - private _deactivate(binding: Binding, instance: T): void | Promise { - const constructor: NewableFunction = Object.getPrototypeOf(instance).constructor; - try { - // if (this._deactivations.hasKey(binding.serviceIdentifier)) { - // const result = this._deactivateContainer(instance, this._deactivations.get(binding.serviceIdentifier).values()); - - // if (isPromise(result)) { - // return this._handleDeactivationError( - // result.then(() => - // this._propagateContainerDeactivationThenBindingAndPreDestroyAsync(binding, instance, constructor) - // ), - // constructor - // ); - // } - // } - - const propagateDeactivationResult = this._propagateContainerDeactivationThenBindingAndPreDestroy( - binding, - instance, - constructor - ); - - if (isPromise(propagateDeactivationResult)) { - return this._handleDeactivationError(propagateDeactivationResult, constructor); - } - } catch (ex) { - if (ex instanceof Error) { - throw new Error(ERROR_MSGS.ON_DEACTIVATION_ERROR(constructor.name, ex.message)); - } - } - } - - private async _handleDeactivationError(asyncResult: Promise, constructor: NewableFunction): Promise { - try { - await asyncResult; - } catch (ex) { - if (ex instanceof Error) { - throw new Error(ERROR_MSGS.ON_DEACTIVATION_ERROR(constructor.name, ex.message)); - } - } - } - - // private _deactivateContainer( - // instance: T, - // deactivationsIterator: IterableIterator> - // ): void | Promise { - // let deactivation = deactivationsIterator.next(); - - // while (deactivation.value) { - // const result = deactivation.value(instance); - - // if (isPromise(result)) { - // return result.then(() => this._deactivateContainerAsync(instance, deactivationsIterator)); - // } - - // deactivation = deactivationsIterator.next(); - // } - // } - - // private async _deactivateContainerAsync( - // instance: T, - // deactivationsIterator: IterableIterator> - // ): Promise { - // let deactivation = deactivationsIterator.next(); - - // while (deactivation.value) { - // await deactivation.value(instance); - // deactivation = deactivationsIterator.next(); - // } - // } - - private _getContainerModuleHelpersFactory() { - const setModuleId = ( - bindingToSyntax: interfaces.BindingToSyntax, - moduleId: interfaces.ContainerModuleBase['id'] - ) => { - // TODO: Implement an internal type `_BindingToSyntax` wherein this member - // can be public. Let `BindingToSyntax` be the presentational type that - // depends on it, and does not expose this member as public. - ( - bindingToSyntax as unknown as { _binding: { moduleId: interfaces.ContainerModuleBase['id'] } } - )._binding.moduleId = moduleId; - }; - - const getBindFunction = - (moduleId: interfaces.ContainerModuleBase['id']) => - (serviceIdentifier: interfaces.ServiceIdentifier) => { - const bindingToSyntax = this.bind(serviceIdentifier); - setModuleId(bindingToSyntax, moduleId); - return bindingToSyntax as BindingToSyntax; - }; - - const getUnbindFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => { - return this.unbind(serviceIdentifier); - }; - - const getUnbindAsyncFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => { - return null as any; - // return this.unbindAsync(serviceIdentifier); - }; - - const getIsboundFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => { - return this.isBound(serviceIdentifier); - }; - - const getRebindFunction = - (moduleId: interfaces.ContainerModuleBase['id']) => - (serviceIdentifier: interfaces.ServiceIdentifier) => { - const bindingToSyntax = this.rebind(serviceIdentifier); - setModuleId(bindingToSyntax, moduleId); - return bindingToSyntax as BindingToSyntax; - }; - - // const getOnActivationFunction = - // (moduleId: interfaces.ContainerModuleBase['id']) => - // (serviceIdentifier: interfaces.ServiceIdentifier, onActivation: interfaces.BindingActivation) => { - // this._moduleActivationStore.addActivation(moduleId, serviceIdentifier, onActivation); - // this.onActivation(serviceIdentifier, onActivation); - // }; - - // const getOnDeactivationFunction = - // (moduleId: interfaces.ContainerModuleBase['id']) => - // (serviceIdentifier: interfaces.ServiceIdentifier, onDeactivation: interfaces.BindingDeactivation) => { - // this._moduleActivationStore.addDeactivation(moduleId, serviceIdentifier, onDeactivation); - // this.onDeactivation(serviceIdentifier, onDeactivation); - // }; - - return (mId: interfaces.ContainerModuleBase['id']) => ({ - bindFunction: getBindFunction(mId), - isboundFunction: getIsboundFunction(), - // onActivationFunction: getOnActivationFunction(mId), - // onDeactivationFunction: getOnDeactivationFunction(mId), - rebindFunction: getRebindFunction(mId), - unbindFunction: getUnbindFunction(), - unbindAsyncFunction: getUnbindAsyncFunction() - }); - } - // private _getAll(getArgs: GetArgs): Promise { - // return Promise.all(this._get(getArgs) as (Promise | T)[]); - // } - // Prepares arguments required for resolution and - // delegates resolution to _middleware if available - // otherwise it delegates resolution to _planAndResolve - private _get(getArgs: GetArgs): interfaces.ContainerResolution { - const planAndResolveArgs: interfaces.NextArgs = { - ...getArgs, - contextInterceptor: context => context, - targetType: TargetTypeEnum.Variable - }; - // if (this._middleware) { - // const middlewareResult = this._middleware(planAndResolveArgs); - // if (middlewareResult === undefined || middlewareResult === null) { - // throw new Error(ERROR_MSGS.INVALID_MIDDLEWARE_RETURN); - // } - // return middlewareResult as interfaces.ContainerResolution; - // } - - return this._planAndResolve()(planAndResolveArgs); - } - - private _getButThrowIfAsync(getArgs: GetArgs): T | T[] { - // console.count('_getButThrowIfAsync'); - const result = this._get(getArgs); - - // if (isPromiseOrContainsPromise(result)) { - // throw new Error(ERROR_MSGS.LAZY_IN_SYNC(getArgs.serviceIdentifier)); - // } - - return result as T | T[]; - } - - private _getAllArgs(serviceIdentifier: interfaces.ServiceIdentifier): GetArgs { - const getAllArgs: GetArgs = { - avoidConstraints: true, - isMultiInject: true, - serviceIdentifier - }; - - return getAllArgs; - } - - private _getNotAllArgs( - serviceIdentifier: interfaces.ServiceIdentifier, - isMultiInject: boolean, - key?: string | number | symbol | undefined, - value?: unknown - ): GetArgs { - const getNotAllArgs: GetArgs = { - avoidConstraints: false, - isMultiInject, - serviceIdentifier, - key, - value - }; - - return getNotAllArgs; - } - - // Planner creates a plan and Resolver resolves a plan - // one of the jobs of the Container is to links the Planner - // with the Resolver and that is what this function is about - private _planAndResolve(): (args: interfaces.NextArgs) => interfaces.ContainerResolution { - return (args: interfaces.NextArgs) => { - // create a plan - // if (!window.aaa) { - // window.aaa = 0; - // } - // const t = performance.now(); - // debugger; - let context = plan( - this._metadataReader, - this, - args.isMultiInject, - args.targetType, - args.serviceIdentifier, - args.key, - args.value, - args.avoidConstraints - ); - - // apply context interceptor - context = args.contextInterceptor(context); - // window.aaa += performance.now() - t; - // resolve plan - const result = resolve(context); - - return result; - }; - } - - private _deactivateIfSingleton(binding: Binding): Promise | void { - if (!binding.activated) { - return; - } - - if (isPromise(binding.cache)) { - return binding.cache.then(resolved => this._deactivate(binding, resolved)); - } - - return this._deactivate(binding, binding.cache); - } - - private _deactivateSingletons(bindings: Binding[]): void { - for (const binding of bindings) { - const result = this._deactivateIfSingleton(binding); - - if (isPromise(result)) { - throw new Error(ERROR_MSGS.ASYNC_UNBIND_REQUIRED); - } - } - } - - // private async _deactivateSingletonsAsync(bindings: Binding[]): Promise { - // await Promise.all(bindings.map(b => this._deactivateIfSingleton(b))); - // } - - private _propagateContainerDeactivationThenBindingAndPreDestroy( - binding: Binding, - instance: T, - constructor: NewableFunction - ): void | Promise { - if (this.parent) { - return this._deactivate.bind(this.parent)(binding, instance); - } - return this._bindingDeactivationAndPreDestroy(binding, instance, constructor); - } - - // private async _propagateContainerDeactivationThenBindingAndPreDestroyAsync( - // binding: Binding, - // instance: T, - // constructor: NewableFunction - // ): Promise { - // if (this.parent) { - // await this._deactivate.bind(this.parent)(binding, instance); - // } else { - // await this._bindingDeactivationAndPreDestroyAsync(binding, instance, constructor); - // } - // } - - private _removeServiceFromDictionary(serviceIdentifier: interfaces.ServiceIdentifier): void { - try { - this._bindingDictionary.remove(serviceIdentifier); - } catch (e) { - throw new Error(`${ERROR_MSGS.CANNOT_UNBIND} ${getServiceIdentifierAsString(serviceIdentifier)}`); - } - } - - private _bindingDeactivationAndPreDestroy( - binding: Binding, - instance: T, - constructor: NewableFunction - ): void | Promise { - if (typeof binding.onDeactivation === 'function') { - const result = binding.onDeactivation(instance); - - if (isPromise(result)) { - return result.then(() => this._preDestroy(constructor, instance)); - } - } - - return this._preDestroy(constructor, instance); - } - - private async _bindingDeactivationAndPreDestroyAsync( - binding: Binding, - instance: T, - constructor: NewableFunction - ): Promise { - if (typeof binding.onDeactivation === 'function') { - await binding.onDeactivation(instance); - } - - await this._preDestroy(constructor, instance); - } -} - -export { Container }; diff --git a/packages/vrender-core/src/common/inversify-lite/container/container_module.ts b/packages/vrender-core/src/common/inversify-lite/container/container_module.ts deleted file mode 100644 index 2d926c966..000000000 --- a/packages/vrender-core/src/common/inversify-lite/container/container_module.ts +++ /dev/null @@ -1,22 +0,0 @@ -import type { interfaces } from '../interfaces/interfaces'; -import { id } from '../utils/id'; - -export class ContainerModule implements interfaces.ContainerModule { - id: number; - registry: interfaces.ContainerModuleCallBack; - - constructor(registry: interfaces.ContainerModuleCallBack) { - this.id = id(); - this.registry = registry; - } -} - -export class AsyncContainerModule implements interfaces.AsyncContainerModule { - id: number; - registry: interfaces.AsyncContainerModuleCallBack; - - constructor(registry: interfaces.AsyncContainerModuleCallBack) { - this.id = id(); - this.registry = registry; - } -} diff --git a/packages/vrender-core/src/common/inversify-lite/container/lookup.ts b/packages/vrender-core/src/common/inversify-lite/container/lookup.ts deleted file mode 100644 index 0f395e380..000000000 --- a/packages/vrender-core/src/common/inversify-lite/container/lookup.ts +++ /dev/null @@ -1,129 +0,0 @@ -import * as ERROR_MSGS from '../constants/error_msgs'; -import type { interfaces } from '../interfaces/interfaces'; -import { isClonable } from '../utils/clonable'; - -class Lookup implements interfaces.Lookup { - // dictionary used store multiple values for each key - private _map: Map; - - constructor() { - this._map = new Map(); - } - - getMap() { - return this._map; - } - - // adds a new entry to _map - add(serviceIdentifier: interfaces.ServiceIdentifier, value: T): void { - if (serviceIdentifier === null || serviceIdentifier === undefined) { - throw new Error(ERROR_MSGS.NULL_ARGUMENT); - } - - if (value === null || value === undefined) { - throw new Error(ERROR_MSGS.NULL_ARGUMENT); - } - - const entry = this._map.get(serviceIdentifier); - if (entry !== undefined) { - entry.push(value); - } else { - this._map.set(serviceIdentifier, [value]); - } - } - - // gets the value of a entry by its key (serviceIdentifier) - get(serviceIdentifier: interfaces.ServiceIdentifier): T[] { - if (serviceIdentifier === null || serviceIdentifier === undefined) { - throw new Error(ERROR_MSGS.NULL_ARGUMENT); - } - - const entry = this._map.get(serviceIdentifier); - - if (entry !== undefined) { - return entry; - } - throw new Error(ERROR_MSGS.KEY_NOT_FOUND); - } - - // removes a entry from _map by its key (serviceIdentifier) - remove(serviceIdentifier: interfaces.ServiceIdentifier): void { - if (serviceIdentifier === null || serviceIdentifier === undefined) { - throw new Error(ERROR_MSGS.NULL_ARGUMENT); - } - - if (!this._map.delete(serviceIdentifier)) { - throw new Error(ERROR_MSGS.KEY_NOT_FOUND); - } - } - - removeIntersection(lookup: interfaces.Lookup): void { - this.traverse((serviceIdentifier: interfaces.ServiceIdentifier, value: T[]) => { - const lookupActivations = lookup.hasKey(serviceIdentifier) ? lookup.get(serviceIdentifier) : undefined; - if (lookupActivations !== undefined) { - const filteredValues = value.filter( - lookupValue => !lookupActivations.some(moduleActivation => lookupValue === moduleActivation) - ); - - this._setValue(serviceIdentifier, filteredValues); - } - }); - } - - removeByCondition(condition: (item: T) => boolean): T[] { - const removals: T[] = []; - this._map.forEach((entries, key) => { - const updatedEntries: T[] = []; - - for (const entry of entries) { - const remove = condition(entry); - if (remove) { - removals.push(entry); - } else { - updatedEntries.push(entry); - } - } - - this._setValue(key, updatedEntries); - }); - - return removals; - } - - // returns true if _map contains a key (serviceIdentifier) - hasKey(serviceIdentifier: interfaces.ServiceIdentifier): boolean { - if (serviceIdentifier === null || serviceIdentifier === undefined) { - throw new Error(ERROR_MSGS.NULL_ARGUMENT); - } - - return this._map.has(serviceIdentifier); - } - - // returns a new Lookup instance; note: this is not a deep clone, only Lookup related data structure (dictionary) is - // cloned, content remains the same - clone(): interfaces.Lookup { - const copy = new Lookup(); - - this._map.forEach((value, key) => { - value.forEach(b => copy.add(key, isClonable(b) ? b.clone() : b)); - }); - - return copy; - } - - traverse(func: (key: interfaces.ServiceIdentifier, value: T[]) => void): void { - this._map.forEach((value, key) => { - func(key, value); - }); - } - - private _setValue(serviceIdentifier: interfaces.ServiceIdentifier, value: T[]): void { - if (value.length > 0) { - this._map.set(serviceIdentifier, value); - } else { - this._map.delete(serviceIdentifier); - } - } -} - -export { Lookup }; diff --git a/packages/vrender-core/src/common/inversify-lite/index.ts b/packages/vrender-core/src/common/inversify-lite/index.ts deleted file mode 100644 index 238b0b0d1..000000000 --- a/packages/vrender-core/src/common/inversify-lite/index.ts +++ /dev/null @@ -1,36 +0,0 @@ -// /** -// * 该文件夹下所有文件来源于inversify -// * https://github.com/inversify/InversifyJS -// * The MIT License (MIT) - -// Copyright (c) 2015-2017 Remo H. Jansen - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// */ - -// export { ContainerModule } from './container/container_module'; -// export { inject } from './annotation/inject'; -// export { multiInject } from './annotation/multi_inject'; -// export { injectable } from './annotation/injectable'; -// export { named } from './annotation/named'; -// export { Container } from './container/container'; -// // export { postConstruct } from './annotation/post_construct'; -// export * from './interfaces/interfaces'; - -export * from '../inversify'; diff --git a/packages/vrender-core/src/common/inversify-lite/interfaces/interfaces.ts b/packages/vrender-core/src/common/inversify-lite/interfaces/interfaces.ts deleted file mode 100644 index 2fdf0b866..000000000 --- a/packages/vrender-core/src/common/inversify-lite/interfaces/interfaces.ts +++ /dev/null @@ -1,393 +0,0 @@ -// @ts-nocheck -/* eslint-disable */ -import { FactoryType } from '../utils/factory_type'; - -export namespace interfaces { - export type DynamicValue = (context: interfaces.Context) => T | Promise; - export type ContainerResolution = T | Promise | (T | Promise)[]; - - type AsyncCallback = TCallback extends (...args: infer TArgs) => infer TResult - ? (...args: TArgs) => Promise - : never; - - export type BindingScope = 'Singleton' | 'Transient' | 'Request'; - - export type BindingType = - | 'ConstantValue' - | 'Constructor' - | 'DynamicValue' - | 'Factory' - | 'Function' - | 'Instance' - | 'Invalid' - | 'Provider'; - - export type TargetType = 'ConstructorArgument' | 'ClassProperty' | 'Variable'; - - export interface BindingScopeEnum { - Request: interfaces.BindingScope; - Singleton: interfaces.BindingScope; - Transient: interfaces.BindingScope; - } - - export interface BindingTypeEnum { - ConstantValue: interfaces.BindingType; - Constructor: interfaces.BindingType; - DynamicValue: interfaces.BindingType; - Factory: interfaces.BindingType; - Function: interfaces.BindingType; - Instance: interfaces.BindingType; - Invalid: interfaces.BindingType; - Provider: interfaces.BindingType; - } - - export interface TargetTypeEnum { - ConstructorArgument: interfaces.TargetType; - ClassProperty: interfaces.TargetType; - Variable: interfaces.TargetType; - } - - export type Newable = new (...args: any[]) => T; - - export type Instance = T & Record void>; - - export interface Abstract { - prototype: T; - } - - export type ServiceIdentifier = string | symbol | Newable | Abstract; - - export interface Clonable { - clone(): T; - } - - export type BindingActivation = (context: interfaces.Context, injectable: T) => T | Promise; - - export type BindingDeactivation = (injectable: T) => void | Promise; - - export interface Binding extends Clonable> { - id: number; - moduleId: ContainerModuleBase['id']; - activated: boolean; - serviceIdentifier: ServiceIdentifier; - constraint: ConstraintFunction; - dynamicValue: DynamicValue | null; - scope: BindingScope; - type: BindingType; - implementationType: Newable | TActivated | null; - factory: FactoryCreator | null; - provider: ProviderCreator | null; - onActivation: BindingActivation | null; - onDeactivation: BindingDeactivation | null; - cache: null | TActivated | Promise; - } - - export type SimpleFactory = (...args: U) => T; - - export type MultiFactory = ( - ...args: U - ) => SimpleFactory; - - export type Factory = - | SimpleFactory - | MultiFactory; - - export type FactoryCreator = ( - context: Context - ) => Factory; - - export type AutoNamedFactory = SimpleFactory; - - export type AutoFactory = SimpleFactory; - - export type FactoryTypeFunction = (context: interfaces.Context) => T | Promise; - - export interface FactoryDetails { - factoryType: FactoryType; - factory: FactoryTypeFunction | null; - } - - export type Provider = (...args: any[]) => ((...args: any[]) => Promise) | Promise; - - export type ProviderCreator = (context: Context) => Provider; - - export interface NextArgs { - avoidConstraints: boolean; - contextInterceptor: (contexts: Context) => Context; - isMultiInject: boolean; - targetType: TargetType; - serviceIdentifier: interfaces.ServiceIdentifier; - key?: string | number | symbol | undefined; - value?: unknown; - } - - export type Next = (args: NextArgs) => unknown | unknown[]; - - export type Middleware = (next: Next) => Next; - - export type ContextInterceptor = (context: interfaces.Context) => interfaces.Context; - - export interface Context { - id: number; - container: Container; - plan: Plan; - currentRequest: Request; - addPlan(plan: Plan): void; - setCurrentRequest(request: Request): void; - } - - export type MetadataOrMetadataArray = Metadata | Metadata[]; - - export interface Metadata { - key: string | number | symbol; - value: TValue; - } - - export interface Plan { - parentContext: Context; - rootRequest: Request; - } - - export interface QueryableString { - // startsWith(searchString: string): boolean; - // endsWith(searchString: string): boolean; - contains(searchString: string): boolean; - equals(compareString: string): boolean; - value(): string; - } - - export type ResolveRequestHandler = (request: interfaces.Request) => unknown; - - export type RequestScope = Map; - - export interface Request { - id: number; - serviceIdentifier: ServiceIdentifier; - parentContext: Context; - parentRequest: Request | null; - childRequests: Request[]; - target: Target; - bindings: Binding[]; - requestScope: RequestScope | null; - addChildRequest( - serviceIdentifier: ServiceIdentifier, - bindings: Binding | Binding[], - target: Target - ): Request; - } - - export interface Target { - id: number; - serviceIdentifier: ServiceIdentifier; - type: TargetType; - name: QueryableString; - identifier: string | symbol; - metadata: Metadata[]; - getNamedTag(): interfaces.Metadata | null; - getCustomTags(): interfaces.Metadata[] | null; - hasTag(key: string | number | symbol): boolean; - isArray(): boolean; - matchesArray(name: interfaces.ServiceIdentifier): boolean; - isNamed(): boolean; - isTagged(): boolean; - isOptional(): boolean; - matchesNamedTag(name: string): boolean; - matchesTag(key: string | number | symbol): (value: unknown) => boolean; - } - - export interface ContainerOptions { - autoBindInjectable?: boolean; - defaultScope?: BindingScope | undefined; - skipBaseClassChecks?: boolean; - } - - export interface Container { - id: number; - parent: Container | null; - options: ContainerOptions; - bind(serviceIdentifier: ServiceIdentifier): BindingToSyntax; - rebind(serviceIdentifier: interfaces.ServiceIdentifier): interfaces.BindingToSyntax; - // rebindAsync(serviceIdentifier: interfaces.ServiceIdentifier): Promise>; - unbind(serviceIdentifier: ServiceIdentifier): void; - // unbindAsync(serviceIdentifier: interfaces.ServiceIdentifier): Promise; - unbindAll(): void; - // unbindAllAsync(): Promise; - isBound(serviceIdentifier: ServiceIdentifier): boolean; - isCurrentBound(serviceIdentifier: ServiceIdentifier): boolean; - isBoundNamed(serviceIdentifier: ServiceIdentifier, named: string | number | symbol): boolean; - isBoundTagged(serviceIdentifier: ServiceIdentifier, key: string | number | symbol, value: unknown): boolean; - get(serviceIdentifier: ServiceIdentifier): T; - getNamed(serviceIdentifier: ServiceIdentifier, named: string | number | symbol): T; - getTagged(serviceIdentifier: ServiceIdentifier, key: string | number | symbol, value: unknown): T; - getAll(serviceIdentifier: ServiceIdentifier): T[]; - getAllTagged(serviceIdentifier: ServiceIdentifier, key: string | number | symbol, value: unknown): T[]; - getAllNamed(serviceIdentifier: ServiceIdentifier, named: string | number | symbol): T[]; - getAsync(serviceIdentifier: ServiceIdentifier): Promise; - // getNamedAsync(serviceIdentifier: ServiceIdentifier, named: string | number | symbol): Promise; - // getTaggedAsync( - // serviceIdentifier: ServiceIdentifier, - // key: string | number | symbol, - // value: unknown - // ): Promise; - // getAllAsync(serviceIdentifier: ServiceIdentifier): Promise; - // getAllTaggedAsync( - // serviceIdentifier: ServiceIdentifier, - // key: string | number | symbol, - // value: unknown - // ): Promise; - // getAllNamedAsync(serviceIdentifier: ServiceIdentifier, named: string | number | symbol): Promise; - // onActivation(serviceIdentifier: ServiceIdentifier, onActivation: BindingActivation): void; - // onDeactivation(serviceIdentifier: ServiceIdentifier, onDeactivation: BindingDeactivation): void; - resolve(constructorFunction: interfaces.Newable): T; - load(...modules: ContainerModule[]): void; - // loadAsync(...modules: AsyncContainerModule[]): Promise; - unload(...modules: ContainerModuleBase[]): void; - // unloadAsync(...modules: ContainerModuleBase[]): Promise; - applyCustomMetadataReader(metadataReader: MetadataReader): void; - // applyMiddleware(...middleware: Middleware[]): void; - // snapshot(): void; - // restore(): void; - // createChild(): Container; - } - - export type Bind = (serviceIdentifier: ServiceIdentifier) => BindingToSyntax; - - export type Rebind = (serviceIdentifier: ServiceIdentifier) => BindingToSyntax; - - export type Unbind = (serviceIdentifier: ServiceIdentifier) => void; - - export type UnbindAsync = (serviceIdentifier: ServiceIdentifier) => Promise; - - export type IsBound = (serviceIdentifier: ServiceIdentifier) => boolean; - - export interface ContainerModuleBase { - id: number; - } - - export interface ContainerModule extends ContainerModuleBase { - registry: ContainerModuleCallBack; - } - - export interface AsyncContainerModule extends ContainerModuleBase { - registry: AsyncContainerModuleCallBack; - } - - export interface ModuleActivationHandlers { - onActivations: Lookup>; - onDeactivations: Lookup>; - } - - // export interface ModuleActivationStore extends Clonable { - // addDeactivation( - // moduleId: ContainerModuleBase['id'], - // serviceIdentifier: ServiceIdentifier, - // onDeactivation: interfaces.BindingDeactivation - // ): void; - // addActivation( - // moduleId: ContainerModuleBase['id'], - // serviceIdentifier: ServiceIdentifier, - // onActivation: interfaces.BindingActivation - // ): void; - // remove(moduleId: ContainerModuleBase['id']): ModuleActivationHandlers; - // } - - export type ContainerModuleCallBack = ( - bind: interfaces.Bind, - unbind: interfaces.Unbind, - isBound: interfaces.IsBound, - rebind: interfaces.Rebind - // unbindAsync: interfaces.UnbindAsync, - // onActivation: interfaces.Container['onActivation'], - // onDeactivation: interfaces.Container['onDeactivation'] - ) => void; - - export type AsyncContainerModuleCallBack = AsyncCallback; - - // export interface ContainerSnapshot { - // bindings: Lookup>; - // activations: Lookup>; - // deactivations: Lookup>; - // middleware: Next | null; - // moduleActivationStore: interfaces.ModuleActivationStore; - // } - - export interface Lookup extends Clonable> { - add(serviceIdentifier: ServiceIdentifier, value: T): void; - getMap(): Map; - get(serviceIdentifier: ServiceIdentifier): T[]; - remove(serviceIdentifier: interfaces.ServiceIdentifier): void; - removeByCondition(condition: (item: T) => boolean): T[]; - removeIntersection(lookup: interfaces.Lookup): void; - hasKey(serviceIdentifier: ServiceIdentifier): boolean; - clone(): Lookup; - traverse(func: (key: interfaces.ServiceIdentifier, value: T[]) => void): void; - } - - export interface BindingOnSyntax { - // onActivation(fn: (context: Context, injectable: T) => T | Promise): BindingWhenSyntax; - // onDeactivation(fn: (injectable: T) => void | Promise): BindingWhenSyntax; - } - - export interface BindingWhenSyntax { - // when(constraint: (request: Request) => boolean): BindingOnSyntax; - whenTargetNamed(name: string | number | symbol): BindingOnSyntax; - // whenTargetIsDefault(): BindingOnSyntax; - // whenTargetTagged(tag: string | number | symbol, value: unknown): BindingOnSyntax; - // whenInjectedInto(parent: NewableFunction | string): BindingOnSyntax; - // whenParentNamed(name: string | number | symbol): BindingOnSyntax; - // whenParentTagged(tag: string | number | symbol, value: unknown): BindingOnSyntax; - // whenAnyAncestorIs(ancestor: NewableFunction | string): BindingOnSyntax; - // whenNoAncestorIs(ancestor: NewableFunction | string): BindingOnSyntax; - // whenAnyAncestorNamed(name: string | number | symbol): BindingOnSyntax; - // whenAnyAncestorTagged(tag: string | number | symbol, value: unknown): BindingOnSyntax; - // whenNoAncestorNamed(name: string | number | symbol): BindingOnSyntax; - // whenNoAncestorTagged(tag: string | number | symbol, value: unknown): BindingOnSyntax; - // whenAnyAncestorMatches(constraint: (request: Request) => boolean): BindingOnSyntax; - // whenNoAncestorMatches(constraint: (request: Request) => boolean): BindingOnSyntax; - } - - export interface BindingWhenOnSyntax extends BindingWhenSyntax, BindingOnSyntax {} - - export interface BindingInSyntax { - inSingletonScope(): BindingWhenOnSyntax; - inTransientScope(): BindingWhenOnSyntax; - inRequestScope(): BindingWhenOnSyntax; - } - - export interface BindingInWhenOnSyntax extends BindingInSyntax, BindingWhenOnSyntax {} - - export interface BindingToSyntax { - to(constructor: Newable): BindingInWhenOnSyntax; - toSelf(): BindingInWhenOnSyntax; - toConstantValue(value: T): BindingWhenOnSyntax; - toDynamicValue(func: DynamicValue): BindingInWhenOnSyntax; - toConstructor(constructor: Newable): BindingWhenOnSyntax; - toFactory( - factory: FactoryCreator - ): BindingWhenOnSyntax; - toFunction(func: T): BindingWhenOnSyntax; - toAutoFactory(serviceIdentifier: ServiceIdentifier): BindingWhenOnSyntax; - toAutoNamedFactory(serviceIdentifier: ServiceIdentifier): BindingWhenOnSyntax; - toProvider(provider: ProviderCreator): BindingWhenOnSyntax; - toService(service: ServiceIdentifier): void; - } - - export interface ConstraintFunction { - metaData?: Metadata; - (request: Request | null): boolean; - } - - export interface MetadataReader { - getConstructorMetadata(constructorFunc: NewableFunction): ConstructorMetadata; - getPropertiesMetadata(constructorFunc: NewableFunction): MetadataMap; - } - - export interface MetadataMap { - [propertyNameOrArgumentIndex: string | symbol]: Metadata[]; - } - - export interface ConstructorMetadata { - compilerGeneratedMetadata: NewableFunction[] | undefined; - userGeneratedMetadata: MetadataMap; - } -} diff --git a/packages/vrender-core/src/common/inversify-lite/planning/context.ts b/packages/vrender-core/src/common/inversify-lite/planning/context.ts deleted file mode 100644 index 3ebc80509..000000000 --- a/packages/vrender-core/src/common/inversify-lite/planning/context.ts +++ /dev/null @@ -1,24 +0,0 @@ -import type { interfaces } from '../interfaces/interfaces'; -import { id } from '../utils/id'; - -class Context implements interfaces.Context { - id: number; - container: interfaces.Container; - plan!: interfaces.Plan; - currentRequest!: interfaces.Request; - - constructor(container: interfaces.Container) { - this.id = id(); - this.container = container; - } - - addPlan(plan: interfaces.Plan) { - this.plan = plan; - } - - setCurrentRequest(currentRequest: interfaces.Request) { - this.currentRequest = currentRequest; - } -} - -export { Context }; diff --git a/packages/vrender-core/src/common/inversify-lite/planning/metadata.ts b/packages/vrender-core/src/common/inversify-lite/planning/metadata.ts deleted file mode 100644 index 673997d70..000000000 --- a/packages/vrender-core/src/common/inversify-lite/planning/metadata.ts +++ /dev/null @@ -1,21 +0,0 @@ -import * as METADATA_KEY from '../constants/metadata_keys'; -import type { interfaces } from '../interfaces/interfaces'; - -class Metadata implements interfaces.Metadata { - key: string | number | symbol; - value: unknown; - - constructor(key: string | number | symbol, value: unknown) { - this.key = key; - this.value = value; - } - - toString() { - if (this.key === METADATA_KEY.NAMED_TAG) { - return `named: ${String(this.value).toString()} `; - } - return `tagged: { key:${this.key.toString()}, value: ${String(this.value)} }`; - } -} - -export { Metadata }; diff --git a/packages/vrender-core/src/common/inversify-lite/planning/metadata_reader.ts b/packages/vrender-core/src/common/inversify-lite/planning/metadata_reader.ts deleted file mode 100644 index 705022926..000000000 --- a/packages/vrender-core/src/common/inversify-lite/planning/metadata_reader.ts +++ /dev/null @@ -1,26 +0,0 @@ -import * as METADATA_KEY from '../constants/metadata_keys'; -import type { interfaces } from '../interfaces/interfaces'; -import Reflect from '../../Reflect-metadata'; - -class MetadataReader implements interfaces.MetadataReader { - getConstructorMetadata(constructorFunc: NewableFunction): interfaces.ConstructorMetadata { - // TypeScript compiler generated annotations - const compilerGeneratedMetadata = (Reflect as any).getMetadata(METADATA_KEY.PARAM_TYPES, constructorFunc); - - // User generated constructor annotations - const userGeneratedMetadata = (Reflect as any).getMetadata(METADATA_KEY.TAGGED, constructorFunc); - - return { - compilerGeneratedMetadata, - userGeneratedMetadata: userGeneratedMetadata || {} - }; - } - - getPropertiesMetadata(constructorFunc: NewableFunction): interfaces.MetadataMap { - // User generated properties annotations - const userGeneratedMetadata = (Reflect as any).getMetadata(METADATA_KEY.TAGGED_PROP, constructorFunc) || []; - return userGeneratedMetadata; - } -} - -export { MetadataReader }; diff --git a/packages/vrender-core/src/common/inversify-lite/planning/plan.ts b/packages/vrender-core/src/common/inversify-lite/planning/plan.ts deleted file mode 100644 index 929fa21c9..000000000 --- a/packages/vrender-core/src/common/inversify-lite/planning/plan.ts +++ /dev/null @@ -1,13 +0,0 @@ -import type { interfaces } from '../interfaces/interfaces'; - -class Plan implements interfaces.Plan { - parentContext: interfaces.Context; - rootRequest: interfaces.Request; - - constructor(parentContext: interfaces.Context, rootRequest: interfaces.Request) { - this.parentContext = parentContext; - this.rootRequest = rootRequest; - } -} - -export { Plan }; diff --git a/packages/vrender-core/src/common/inversify-lite/planning/planner.ts b/packages/vrender-core/src/common/inversify-lite/planning/planner.ts deleted file mode 100644 index 4726b2ef2..000000000 --- a/packages/vrender-core/src/common/inversify-lite/planning/planner.ts +++ /dev/null @@ -1,233 +0,0 @@ -import { BindingCount } from '../bindings/binding_count'; -import * as ERROR_MSGS from '../constants/error_msgs'; -import { BindingTypeEnum, TargetTypeEnum } from '../constants/literal_types'; -import * as METADATA_KEY from '../constants/metadata_keys'; -import type { interfaces } from '../interfaces/interfaces'; -// import { isStackOverflowExeption } from '../utils/exceptions'; -import { - // circularDependencyToException, - getServiceIdentifierAsString, - listMetadataForTarget, - listRegisteredBindingsForServiceIdentifier -} from '../utils/serialization'; -import { Context } from './context'; -import { Metadata } from './metadata'; -import { Plan } from './plan'; -import { getBaseClassDependencyCount, getDependencies, getFunctionName } from './reflection_utils'; -import { Request } from './request'; -import { Target } from './target'; - -function getBindingDictionary(cntnr: interfaces.Container): interfaces.Lookup> { - return (cntnr as unknown as { _bindingDictionary: interfaces.Lookup> }) - ._bindingDictionary; -} - -function _createTarget( - isMultiInject: boolean, - targetType: interfaces.TargetType, - serviceIdentifier: interfaces.ServiceIdentifier, - name: string, - key?: string | number | symbol, - value?: unknown -): interfaces.Target { - const metadataKey = isMultiInject ? METADATA_KEY.MULTI_INJECT_TAG : METADATA_KEY.INJECT_TAG; - const injectMetadata = new Metadata(metadataKey, serviceIdentifier); - const target = new Target(targetType, name, serviceIdentifier, injectMetadata); - - if (key !== undefined) { - const tagMetadata = new Metadata(key, value); - target.metadata.push(tagMetadata); - } - - return target; -} - -function _getActiveBindings( - metadataReader: interfaces.MetadataReader, - avoidConstraints: boolean, - context: interfaces.Context, - parentRequest: interfaces.Request | null, - target: interfaces.Target -): interfaces.Binding[] { - let bindings = getBindings(context.container, target.serviceIdentifier); - let activeBindings: interfaces.Binding[] = []; - - // automatic binding - if ( - bindings.length === BindingCount.NoBindingsAvailable && - context.container.options.autoBindInjectable && - typeof target.serviceIdentifier === 'function' && - metadataReader.getConstructorMetadata(target.serviceIdentifier).compilerGeneratedMetadata - ) { - context.container.bind(target.serviceIdentifier).toSelf(); - bindings = getBindings(context.container, target.serviceIdentifier); - } - - // multiple bindings available - if (!avoidConstraints) { - // apply constraints if available to reduce the number of active bindings - activeBindings = bindings.filter(binding => { - const request = new Request(binding.serviceIdentifier, context, parentRequest, binding, target); - - return binding.constraint(request); - }); - } else { - // simple injection or multi-injection without constraints - activeBindings = bindings; - } - - // validate active bindings - _validateActiveBindingCount(target.serviceIdentifier, activeBindings, target, context.container); - - return activeBindings; -} - -function _validateActiveBindingCount( - serviceIdentifier: interfaces.ServiceIdentifier, - bindings: interfaces.Binding[], - target: interfaces.Target, - container: interfaces.Container -): interfaces.Binding[] { - switch (bindings.length) { - case BindingCount.NoBindingsAvailable: - if (target.isOptional()) { - return bindings; - } - const serviceIdentifierString = getServiceIdentifierAsString(serviceIdentifier); - let msg = ERROR_MSGS.NOT_REGISTERED; - msg += listMetadataForTarget(serviceIdentifierString, target); - msg += listRegisteredBindingsForServiceIdentifier(container, serviceIdentifierString, getBindings); - throw new Error(msg); - - case BindingCount.OnlyOneBindingAvailable: - return bindings; - case BindingCount.MultipleBindingsAvailable: - default: - if (!target.isArray()) { - const serviceIdentifierString = getServiceIdentifierAsString(serviceIdentifier); - let msg = `${ERROR_MSGS.AMBIGUOUS_MATCH} ${serviceIdentifierString}`; - msg += listRegisteredBindingsForServiceIdentifier(container, serviceIdentifierString, getBindings); - throw new Error(msg); - } else { - return bindings; - } - } -} - -function _createSubRequests( - metadataReader: interfaces.MetadataReader, - avoidConstraints: boolean, - serviceIdentifier: interfaces.ServiceIdentifier, - context: interfaces.Context, - parentRequest: interfaces.Request | null, - target: interfaces.Target -) { - let activeBindings: interfaces.Binding[]; - let childRequest: interfaces.Request; - - if (parentRequest === null) { - activeBindings = _getActiveBindings(metadataReader, avoidConstraints, context, null, target); - - childRequest = new Request(serviceIdentifier, context, null, activeBindings, target); - - const thePlan = new Plan(context, childRequest); - context.addPlan(thePlan); - } else { - activeBindings = _getActiveBindings(metadataReader, avoidConstraints, context, parentRequest, target); - childRequest = parentRequest.addChildRequest(target.serviceIdentifier, activeBindings, target); - } - - activeBindings.forEach(binding => { - let subChildRequest: interfaces.Request | null = null; - - if (target.isArray()) { - subChildRequest = childRequest.addChildRequest(binding.serviceIdentifier, binding, target); - } else { - if (binding.cache) { - return; - } - subChildRequest = childRequest; - } - - if (binding.type === BindingTypeEnum.Instance && binding.implementationType !== null) { - const dependencies = getDependencies(metadataReader, binding.implementationType as NewableFunction); - - if (!context.container.options.skipBaseClassChecks) { - // Throw if a derived class does not implement its constructor explicitly - // We do this to prevent errors when a base class (parent) has dependencies - // and one of the derived classes (children) has no dependencies - const baseClassDependencyCount = getBaseClassDependencyCount( - metadataReader, - binding.implementationType as NewableFunction - ); - - if (dependencies.length < baseClassDependencyCount) { - const error = ERROR_MSGS.ARGUMENTS_LENGTH_MISMATCH( - getFunctionName(binding.implementationType as NewableFunction) - ); - throw new Error(error); - } - } - - dependencies.forEach((dependency: interfaces.Target) => { - _createSubRequests(metadataReader, false, dependency.serviceIdentifier, context, subChildRequest, dependency); - }); - } - }); -} - -function getBindings( - container: interfaces.Container, - serviceIdentifier: interfaces.ServiceIdentifier -): interfaces.Binding[] { - let bindings: interfaces.Binding[] = []; - const bindingDictionary = getBindingDictionary(container); - - if (bindingDictionary.hasKey(serviceIdentifier)) { - bindings = bindingDictionary.get(serviceIdentifier) as interfaces.Binding[]; - } else if (container.parent !== null) { - // recursively try to get bindings from parent container - bindings = getBindings(container.parent, serviceIdentifier); - } - - return bindings; -} - -function plan( - metadataReader: interfaces.MetadataReader, - container: interfaces.Container, - isMultiInject: boolean, - targetType: interfaces.TargetType, - serviceIdentifier: interfaces.ServiceIdentifier, - key?: string | number | symbol, - value?: unknown, - avoidConstraints = false -): interfaces.Context { - const context = new Context(container); - const target = _createTarget(isMultiInject, targetType, serviceIdentifier, '', key, value); - _createSubRequests(metadataReader, avoidConstraints, serviceIdentifier, context, null, target); - return context; - // try { - // _createSubRequests(metadataReader, avoidConstraints, serviceIdentifier, context, null, target); - // return context; - // } catch (error) { - // if (isStackOverflowExeption(error)) { - // circularDependencyToException(context.plan.rootRequest); - // } - // throw error; - // } -} - -function createMockRequest( - container: interfaces.Container, - serviceIdentifier: interfaces.ServiceIdentifier, - key: string | number | symbol, - value: unknown -): interfaces.Request { - const target = new Target(TargetTypeEnum.Variable, '', serviceIdentifier, new Metadata(key, value)); - const context = new Context(container); - const request = new Request(serviceIdentifier, context, null, [], target); - return request; -} - -export { plan, createMockRequest, getBindingDictionary }; diff --git a/packages/vrender-core/src/common/inversify-lite/planning/queryable_string.ts b/packages/vrender-core/src/common/inversify-lite/planning/queryable_string.ts deleted file mode 100644 index ae26efcd4..000000000 --- a/packages/vrender-core/src/common/inversify-lite/planning/queryable_string.ts +++ /dev/null @@ -1,34 +0,0 @@ -import type { interfaces } from '../interfaces/interfaces'; - -class QueryableString implements interfaces.QueryableString { - private str: string; - - constructor(str: string) { - this.str = str; - } - - // startsWith(searchString: string): boolean { - // return this.str.indexOf(searchString) === 0; - // } - - // endsWith(searchString: string): boolean { - // let reverseString = ''; - // const reverseSearchString = searchString.split('').reverse().join(''); - // reverseString = this.str.split('').reverse().join(''); - // return this.startsWith.call({ str: reverseString }, reverseSearchString); - // } - - contains(searchString: string): boolean { - return this.str.indexOf(searchString) !== -1; - } - - equals(compareString: string): boolean { - return this.str === compareString; - } - - value(): string { - return this.str; - } -} - -export { QueryableString }; diff --git a/packages/vrender-core/src/common/inversify-lite/planning/reflection_utils.ts b/packages/vrender-core/src/common/inversify-lite/planning/reflection_utils.ts deleted file mode 100644 index 666b4a533..000000000 --- a/packages/vrender-core/src/common/inversify-lite/planning/reflection_utils.ts +++ /dev/null @@ -1,239 +0,0 @@ -import { LazyServiceIdentifer } from '../annotation/lazy_service_identifier'; -import * as ERROR_MSGS from '../constants/error_msgs'; -import { TargetTypeEnum } from '../constants/literal_types'; -import * as METADATA_KEY from '../constants/metadata_keys'; -import type { interfaces } from '../interfaces/interfaces'; -import { getFunctionName } from '../utils/serialization'; -import type { Metadata } from './metadata'; -import { Target } from './target'; - -function getDependencies(metadataReader: interfaces.MetadataReader, func: NewableFunction): interfaces.Target[] { - const constructorName = getFunctionName(func); - return getTargets(metadataReader, constructorName, func, false); -} - -function getTargets( - metadataReader: interfaces.MetadataReader, - constructorName: string, - func: NewableFunction, - isBaseClass: boolean -): interfaces.Target[] { - const metadata = metadataReader.getConstructorMetadata(func); - - // TypeScript compiler generated annotations - const serviceIdentifiers = metadata.compilerGeneratedMetadata; - - // All types resolved must be annotated with @injectable - if (serviceIdentifiers === undefined) { - const msg = `${ERROR_MSGS.MISSING_INJECTABLE_ANNOTATION} ${constructorName}.`; - throw new Error(msg); - } - - // User generated annotations - const constructorArgsMetadata = metadata.userGeneratedMetadata; - - const keys = Object.keys(constructorArgsMetadata); - const hasUserDeclaredUnknownInjections = func.length === 0 && keys.length > 0; - const hasOptionalParameters = keys.length > func.length; - - const iterations = hasUserDeclaredUnknownInjections || hasOptionalParameters ? keys.length : func.length; - - // Target instances that represent constructor arguments to be injected - const constructorTargets = getConstructorArgsAsTargets( - isBaseClass, - constructorName, - serviceIdentifiers, - constructorArgsMetadata, - iterations - ); - - // Target instances that represent properties to be injected - const propertyTargets = getClassPropsAsTargets(metadataReader, func, constructorName); - - const targets = [...constructorTargets, ...propertyTargets]; - - return targets; -} -function getConstructorArgsAsTarget( - index: number, - isBaseClass: boolean, - constructorName: string, - serviceIdentifiers: interfaces.ServiceIdentifier[], - constructorArgsMetadata: interfaces.MetadataMap -): Target | null { - // Create map from array of metadata for faster access to metadata - const targetMetadata = constructorArgsMetadata[index.toString()] || []; - const metadata = formatTargetMetadata(targetMetadata); - const isManaged = metadata.unmanaged !== true; - - // Take types to be injected from user-generated metadata - // if not available use compiler-generated metadata - let serviceIdentifier = serviceIdentifiers[index]; - const injectIdentifier = metadata.inject || metadata.multiInject; - serviceIdentifier = (injectIdentifier ? injectIdentifier : serviceIdentifier) as - | interfaces.ServiceIdentifier - | undefined; - - // we unwrap LazyServiceIdentifer wrappers to allow circular dependencies on symbols - if (serviceIdentifier instanceof LazyServiceIdentifer) { - serviceIdentifier = serviceIdentifier.unwrap(); - } - - // Types Object and Function are too ambiguous to be resolved - // user needs to generate metadata manually for those - if (isManaged) { - const isObject = serviceIdentifier === Object; - const isFunction = serviceIdentifier === Function; - const isUndefined = serviceIdentifier === undefined; - const isUnknownType = isObject || isFunction || isUndefined; - - if (!isBaseClass && isUnknownType) { - const msg = `${ERROR_MSGS.MISSING_INJECT_ANNOTATION} argument ${index} in class ${constructorName}.`; - throw new Error(msg); - } - - const target = new Target( - TargetTypeEnum.ConstructorArgument, - metadata.targetName as string | symbol, - serviceIdentifier as interfaces.ServiceIdentifier - ); - target.metadata = targetMetadata; - return target; - } - - return null; -} - -function getConstructorArgsAsTargets( - isBaseClass: boolean, - constructorName: string, - serviceIdentifiers: interfaces.ServiceIdentifier[], - constructorArgsMetadata: interfaces.MetadataMap, - iterations: number -): interfaces.Target[] { - const targets: interfaces.Target[] = []; - for (let i = 0; i < iterations; i++) { - const index = i; - const target = getConstructorArgsAsTarget( - index, - isBaseClass, - constructorName, - serviceIdentifiers, - constructorArgsMetadata - ); - if (target !== null) { - targets.push(target); - } - } - - return targets; -} - -function _getServiceIdentifierForProperty( - inject: string | symbol | unknown, - multiInject: object | unknown, - propertyName: string | symbol, - className: string -) { - const serviceIdentifier = inject || multiInject; - if (serviceIdentifier === undefined) { - const msg = `${ERROR_MSGS.MISSING_INJECTABLE_ANNOTATION} for property ${String( - propertyName - )} in class ${className}.`; - throw new Error(msg); - } - return serviceIdentifier; -} - -function getClassPropsAsTargets( - metadataReader: interfaces.MetadataReader, - constructorFunc: NewableFunction, - constructorName: string -) { - const classPropsMetadata = metadataReader.getPropertiesMetadata(constructorFunc); - let targets: interfaces.Target[] = []; - const symbolKeys = Object.getOwnPropertySymbols(classPropsMetadata); - const stringKeys: (string | symbol)[] = Object.keys(classPropsMetadata); - const keys: (string | symbol)[] = stringKeys.concat(symbolKeys); - - for (const key of keys) { - // the metadata for the property being injected - const targetMetadata = classPropsMetadata[key] as interfaces.Metadata[]; - - // the metadata formatted for easier access - const metadata = formatTargetMetadata(targetMetadata); - - const identifier = metadata.targetName || key; - - // Take types to be injected from user-generated metadata - const serviceIdentifier = _getServiceIdentifierForProperty( - metadata.inject, - metadata.multiInject, - key, - constructorName - ); - - // The property target - const target = new Target( - TargetTypeEnum.ClassProperty, - identifier as string | symbol, - serviceIdentifier as interfaces.ServiceIdentifier - ); - target.metadata = targetMetadata; - targets.push(target); - } - - // Check if base class has injected properties - const baseConstructor = Object.getPrototypeOf(constructorFunc.prototype).constructor; - - if (baseConstructor !== Object) { - const baseTargets = getClassPropsAsTargets(metadataReader, baseConstructor, constructorName); - - targets = [...targets, ...baseTargets]; - } - - return targets; -} - -function getBaseClassDependencyCount(metadataReader: interfaces.MetadataReader, func: NewableFunction): number { - const baseConstructor = Object.getPrototypeOf(func.prototype).constructor; - - if (baseConstructor !== Object) { - // get targets for base class - const baseConstructorName = getFunctionName(baseConstructor); - - const targets = getTargets(metadataReader, baseConstructorName, baseConstructor, true); - - // get unmanaged metadata - const metadata = targets.map(t => t.metadata.filter(m => m.key === METADATA_KEY.UNMANAGED_TAG)); - - // Compare the number of constructor arguments with the number of - // unmanaged dependencies unmanaged dependencies are not required - const unmanagedCount = ([] as Metadata[]).concat.apply([], metadata).length; - const dependencyCount = targets.length - unmanagedCount; - - if (dependencyCount > 0) { - return dependencyCount; - } - return getBaseClassDependencyCount(metadataReader, baseConstructor); - } - return 0; -} - -function formatTargetMetadata(targetMetadata: interfaces.Metadata[]) { - // Create map from array of metadata for faster access to metadata - const targetMetadataMap: Record = {}; - targetMetadata.forEach((m: interfaces.Metadata) => { - targetMetadataMap[m.key.toString()] = m.value; - }); - - // user generated metadata - return { - inject: targetMetadataMap[METADATA_KEY.INJECT_TAG], - multiInject: targetMetadataMap[METADATA_KEY.MULTI_INJECT_TAG], - targetName: targetMetadataMap[METADATA_KEY.NAME_TAG], - unmanaged: targetMetadataMap[METADATA_KEY.UNMANAGED_TAG] - }; -} - -export { getDependencies, getBaseClassDependencyCount, getFunctionName }; diff --git a/packages/vrender-core/src/common/inversify-lite/planning/request.ts b/packages/vrender-core/src/common/inversify-lite/planning/request.ts deleted file mode 100644 index 66e100121..000000000 --- a/packages/vrender-core/src/common/inversify-lite/planning/request.ts +++ /dev/null @@ -1,44 +0,0 @@ -import type { interfaces } from '../interfaces/interfaces'; -import { id } from '../utils/id'; - -class Request implements interfaces.Request { - id: number; - serviceIdentifier: interfaces.ServiceIdentifier; - parentContext: interfaces.Context; - parentRequest: interfaces.Request | null; - bindings: interfaces.Binding[]; - childRequests: interfaces.Request[]; - target: interfaces.Target; - requestScope: interfaces.RequestScope | null; - - constructor( - serviceIdentifier: interfaces.ServiceIdentifier, - parentContext: interfaces.Context, - parentRequest: interfaces.Request | null, - bindings: interfaces.Binding | interfaces.Binding[], - target: interfaces.Target - ) { - this.id = id(); - this.serviceIdentifier = serviceIdentifier; - this.parentContext = parentContext; - this.parentRequest = parentRequest; - this.target = target; - this.childRequests = []; - this.bindings = Array.isArray(bindings) ? bindings : [bindings]; - - // Set requestScope if Request is the root request - this.requestScope = parentRequest === null ? new Map() : null; - } - - addChildRequest( - serviceIdentifier: interfaces.ServiceIdentifier, - bindings: interfaces.Binding | interfaces.Binding[], - target: interfaces.Target - ): interfaces.Request { - const child = new Request(serviceIdentifier, this.parentContext, this, bindings, target); - this.childRequests.push(child); - return child; - } -} - -export { Request }; diff --git a/packages/vrender-core/src/common/inversify-lite/planning/target.ts b/packages/vrender-core/src/common/inversify-lite/planning/target.ts deleted file mode 100644 index 595f25518..000000000 --- a/packages/vrender-core/src/common/inversify-lite/planning/target.ts +++ /dev/null @@ -1,106 +0,0 @@ -import * as METADATA_KEY from '../constants/metadata_keys'; -import type { interfaces } from '../interfaces/interfaces'; -import { id } from '../utils/id'; -import { getSymbolDescription } from '../utils/serialization'; -import { Metadata } from './metadata'; -import { QueryableString } from './queryable_string'; - -class Target implements interfaces.Target { - id: number; - type: interfaces.TargetType; - serviceIdentifier: interfaces.ServiceIdentifier; - name: interfaces.QueryableString; - identifier: string | symbol; - key!: string | symbol; - metadata!: Metadata[]; - - constructor( - type: interfaces.TargetType, - identifier: string | symbol, - serviceIdentifier: interfaces.ServiceIdentifier, - namedOrTagged?: string | Metadata - ) { - this.id = id(); - this.type = type; - this.serviceIdentifier = serviceIdentifier; - const queryableName = typeof identifier === 'symbol' ? getSymbolDescription(identifier) : identifier; - this.name = new QueryableString(queryableName || ''); - this.identifier = identifier; - this.metadata = []; - - let metadataItem: interfaces.Metadata | null = null; - - // is named target - if (typeof namedOrTagged === 'string') { - metadataItem = new Metadata(METADATA_KEY.NAMED_TAG, namedOrTagged); - } else if (namedOrTagged instanceof Metadata) { - // is target with metadata - metadataItem = namedOrTagged; - } - - // target has metadata - if (metadataItem !== null) { - this.metadata.push(metadataItem); - } - } - - hasTag(key: string): boolean { - for (const m of this.metadata) { - if (m.key === key) { - return true; - } - } - return false; - } - - isArray(): boolean { - return this.hasTag(METADATA_KEY.MULTI_INJECT_TAG); - } - - matchesArray(name: interfaces.ServiceIdentifier): boolean { - return this.matchesTag(METADATA_KEY.MULTI_INJECT_TAG)(name); - } - - isNamed(): boolean { - return this.hasTag(METADATA_KEY.NAMED_TAG); - } - - isTagged(): boolean { - return this.metadata.some(metadata => METADATA_KEY.NON_CUSTOM_TAG_KEYS.every(key => metadata.key !== key)); - } - - isOptional(): boolean { - return this.matchesTag(METADATA_KEY.OPTIONAL_TAG)(true); - } - - getNamedTag(): interfaces.Metadata | null { - if (this.isNamed()) { - return this.metadata.filter(m => m.key === METADATA_KEY.NAMED_TAG)[0] as interfaces.Metadata; - } - return null; - } - - getCustomTags(): interfaces.Metadata[] | null { - if (this.isTagged()) { - return this.metadata.filter(metadata => METADATA_KEY.NON_CUSTOM_TAG_KEYS.every(key => metadata.key !== key)); - } - return null; - } - - matchesNamedTag(name: string): boolean { - return this.matchesTag(METADATA_KEY.NAMED_TAG)(name); - } - - matchesTag(key: string) { - return (value: unknown) => { - for (const m of this.metadata) { - if (m.key === key && m.value === value) { - return true; - } - } - return false; - }; - } -} - -export { Target }; diff --git a/packages/vrender-core/src/common/inversify-lite/resolution/instantiation.ts b/packages/vrender-core/src/common/inversify-lite/resolution/instantiation.ts deleted file mode 100644 index 1d9375fc2..000000000 --- a/packages/vrender-core/src/common/inversify-lite/resolution/instantiation.ts +++ /dev/null @@ -1,157 +0,0 @@ -import { ON_DEACTIVATION_ERROR, POST_CONSTRUCT_ERROR, PRE_DESTROY_ERROR } from '../constants/error_msgs'; -import { BindingScopeEnum, TargetTypeEnum } from '../constants/literal_types'; -import * as METADATA_KEY from '../constants/metadata_keys'; -import type { interfaces } from '../interfaces/interfaces'; -import type { Metadata } from '../planning/metadata'; -import { isPromise, isPromiseOrContainsPromise } from '../utils/async'; -import Reflect from '../../Reflect-metadata'; - -interface InstanceCreationInstruction { - constructorInjections: unknown[]; - propertyInjections: unknown[]; - propertyRequests: interfaces.Request[]; -} - -interface ResolvedRequests extends InstanceCreationInstruction { - isAsync: boolean; -} - -interface CreateInstanceWithInjectionArg extends InstanceCreationInstruction { - constr: interfaces.Newable; -} - -function _resolveRequests( - childRequests: interfaces.Request[], - resolveRequest: interfaces.ResolveRequestHandler -): ResolvedRequests { - return childRequests.reduce( - (resolvedRequests, childRequest) => { - const injection = resolveRequest(childRequest); - const targetType = childRequest.target.type; - if (targetType === TargetTypeEnum.ConstructorArgument) { - resolvedRequests.constructorInjections.push(injection); - } else { - resolvedRequests.propertyRequests.push(childRequest); - resolvedRequests.propertyInjections.push(injection); - } - if (!resolvedRequests.isAsync) { - resolvedRequests.isAsync = isPromiseOrContainsPromise(injection); - } - return resolvedRequests; - }, - { constructorInjections: [], propertyInjections: [], propertyRequests: [], isAsync: false } - ); -} - -function _createInstance( - constr: interfaces.Newable, - childRequests: interfaces.Request[], - resolveRequest: interfaces.ResolveRequestHandler -): T | Promise { - let result: T | Promise; - - if (childRequests.length > 0) { - const resolved = _resolveRequests(childRequests, resolveRequest); - const createInstanceWithInjectionsArg: CreateInstanceWithInjectionArg = { ...resolved, constr }; - if (resolved.isAsync) { - result = createInstanceWithInjectionsAsync(createInstanceWithInjectionsArg); - } else { - result = createInstanceWithInjections(createInstanceWithInjectionsArg); - } - } else { - result = new constr(); - } - - return result; -} - -function createInstanceWithInjections(args: CreateInstanceWithInjectionArg): T { - const instance = new args.constr(...args.constructorInjections); - args.propertyRequests.forEach((r: interfaces.Request, index: number) => { - const property = r.target.identifier; - const injection = args.propertyInjections[index]; - (instance as Record)[property] = injection; - }); - return instance; -} - -async function createInstanceWithInjectionsAsync(args: CreateInstanceWithInjectionArg): Promise { - const constructorInjections = await possiblyWaitInjections(args.constructorInjections); - const propertyInjections = await possiblyWaitInjections(args.propertyInjections); - return createInstanceWithInjections({ ...args, constructorInjections, propertyInjections }); -} - -async function possiblyWaitInjections(possiblePromiseinjections: unknown[]) { - const injections: unknown[] = []; - for (const injection of possiblePromiseinjections) { - if (Array.isArray(injection)) { - injections.push(Promise.all(injection)); - } else { - injections.push(injection); - } - } - return Promise.all(injections); -} - -function _getInstanceAfterPostConstruct(constr: interfaces.Newable, result: T): T | Promise { - const postConstructResult = _postConstruct(constr, result); - - if (isPromise(postConstructResult)) { - return postConstructResult.then(() => result); - } - return result; -} - -function _postConstruct(constr: interfaces.Newable, instance: T): void | Promise { - if ((Reflect as any).hasMetadata(METADATA_KEY.POST_CONSTRUCT, constr)) { - const data: Metadata = (Reflect as any).getMetadata(METADATA_KEY.POST_CONSTRUCT, constr); - return (instance as interfaces.Instance)[data.value as string]?.(); - // try { - // return (instance as interfaces.Instance)[data.value as string]?.(); - // } catch (e) { - // if (e instanceof Error) { - // throw new Error(POST_CONSTRUCT_ERROR(constr.name, e.message)); - // } - // } - } -} - -function _validateInstanceResolution(binding: interfaces.Binding, constr: interfaces.Newable): void { - if (binding.scope !== BindingScopeEnum.Singleton) { - _throwIfHandlingDeactivation(binding, constr); - } -} - -function _throwIfHandlingDeactivation( - binding: interfaces.Binding, - constr: interfaces.Newable -): void { - const scopeErrorMessage = `Class cannot be instantiated in ${ - binding.scope === BindingScopeEnum.Request ? 'request' : 'transient' - } scope.`; - if (typeof binding.onDeactivation === 'function') { - throw new Error(ON_DEACTIVATION_ERROR(constr.name, scopeErrorMessage)); - } - - if ((Reflect as any).hasMetadata(METADATA_KEY.PRE_DESTROY, constr)) { - throw new Error(PRE_DESTROY_ERROR(constr.name, scopeErrorMessage)); - } -} - -function resolveInstance( - binding: interfaces.Binding, - constr: interfaces.Newable, - childRequests: interfaces.Request[], - resolveRequest: interfaces.ResolveRequestHandler -): T | Promise { - _validateInstanceResolution(binding, constr); - - const result = _createInstance(constr, childRequests, resolveRequest); - - if (isPromise(result)) { - return result.then(resolvedResult => _getInstanceAfterPostConstruct(constr, resolvedResult)); - } - return _getInstanceAfterPostConstruct(constr, result); -} - -export { resolveInstance }; diff --git a/packages/vrender-core/src/common/inversify-lite/resolution/resolver.ts b/packages/vrender-core/src/common/inversify-lite/resolution/resolver.ts deleted file mode 100644 index b284a9d25..000000000 --- a/packages/vrender-core/src/common/inversify-lite/resolution/resolver.ts +++ /dev/null @@ -1,262 +0,0 @@ -import * as ERROR_MSGS from '../constants/error_msgs'; -import { BindingTypeEnum } from '../constants/literal_types'; -import type { interfaces } from '../interfaces/interfaces'; -// import { getBindingDictionary } from '../planning/planner'; -import { saveToScope, tryGetFromScope } from '../scope/scope'; -// import { isPromise } from '../utils/async'; -import { getFactoryDetails, ensureFullyBound } from '../utils/binding_utils'; -import { tryAndThrowErrorIfStackOverflow } from '../utils/exceptions'; -import { resolveInstance } from './instantiation'; - -const _resolveRequest = - (requestScope: interfaces.RequestScope) => - (request: interfaces.Request): undefined | T | Promise | (T | Promise)[] => { - request.parentContext.setCurrentRequest(request); - - const bindings = request.bindings; - const childRequests = request.childRequests; - - const targetIsAnArray = request.target && request.target.isArray(); - - const targetParentIsNotAnArray = - !request.parentRequest || - !request.parentRequest.target || - !request.target || - !request.parentRequest.target.matchesArray(request.target.serviceIdentifier); - - if (targetIsAnArray && targetParentIsNotAnArray) { - // Create an array instead of creating an instance - return childRequests.map((childRequest: interfaces.Request) => { - const _f = _resolveRequest(requestScope); - return _f(childRequest) as T | Promise; - }); - } - if (request.target.isOptional() && bindings.length === 0) { - return undefined; - } - - const binding = bindings[0]; - - return _resolveBinding(requestScope, request, binding as unknown as interfaces.Binding); - }; - -const _resolveFactoryFromBinding = (binding: interfaces.Binding, context: interfaces.Context): T | Promise => { - // console.count('_resolveFactoryFromBinding'); - const factoryDetails = getFactoryDetails(binding); - return tryAndThrowErrorIfStackOverflow( - () => (factoryDetails.factory as interfaces.FactoryTypeFunction).bind(binding)(context), - () => - new Error( - ERROR_MSGS.CIRCULAR_DEPENDENCY_IN_FACTORY( - factoryDetails.factoryType, - context.currentRequest.serviceIdentifier.toString() - ) - ) - ); -}; - -const _getResolvedFromBinding = ( - requestScope: interfaces.RequestScope, - request: interfaces.Request, - binding: interfaces.Binding -): T | Promise => { - // console.count('_getResolvedFromBinding'); - // console.log('_getResolvedFromBinding', binding); - // if (!(window as any).map) { - // (window as any).map = new Map(); - // } - // const d = (window as any).map.get(binding.serviceIdentifier) || []; - // (window as any).map.set(binding.serviceIdentifier, [...d, binding]); - let result: T | Promise | undefined; - const childRequests = request.childRequests; - - ensureFullyBound(binding); - - switch (binding.type) { - case BindingTypeEnum.ConstantValue: - case BindingTypeEnum.Function: - result = binding.cache as T | Promise; - break; - case BindingTypeEnum.Constructor: - result = binding.implementationType as T; - break; - case BindingTypeEnum.Instance: - result = resolveInstance( - binding, - binding.implementationType as interfaces.Newable, - childRequests, - _resolveRequest(requestScope) - ); - break; - default: - result = _resolveFactoryFromBinding(binding, request.parentContext); - } - - return result as T | Promise; -}; - -const _resolveInScope = ( - requestScope: interfaces.RequestScope, - binding: interfaces.Binding, - resolveFromBinding: () => T | Promise -): T | Promise => { - let result = tryGetFromScope(requestScope, binding); - if (result !== null) { - return result; - } - result = resolveFromBinding(); - saveToScope(requestScope, binding, result); - return result; -}; - -const _resolveBinding = ( - requestScope: interfaces.RequestScope, - request: interfaces.Request, - binding: interfaces.Binding -): T | Promise => { - return _resolveInScope(requestScope, binding, () => { - const result = _getResolvedFromBinding(requestScope, request, binding); - // if (isPromise(result)) { - // result = result.then(resolved => _onActivation(request, binding, resolved)); - // } else { - // result = _onActivation(request, binding, result); - // } - return result; - }); -}; - -// function _onActivation(request: interfaces.Request, binding: interfaces.Binding, resolved: T): T | Promise { -// let result = _bindingActivation(request.parentContext, binding, resolved); - -// const containersIterator = _getContainersIterator(request.parentContext.container); - -// let container: interfaces.Container; -// let containersIteratorResult = containersIterator.next(); - -// do { -// container = containersIteratorResult.value; -// // const context = request.parentContext; -// // const serviceIdentifier = request.serviceIdentifier; -// // const activationsIterator = _getContainerActivationsForService(container, serviceIdentifier); - -// // if (isPromise(result)) { -// // result = _activateContainerAsync( -// // activationsIterator as Iterator>, -// // context, -// // result -// // ); -// // } else { -// // result = _activateContainer(activationsIterator as Iterator>, context, result); -// // } - -// containersIteratorResult = containersIterator.next(); - -// // make sure if we are currently on the container that owns the binding, not to keep looping down to child containers -// } while ( -// containersIteratorResult.done !== true && -// !getBindingDictionary(container).hasKey(request.serviceIdentifier) -// ); - -// return result; -// } - -// const _bindingActivation = ( -// context: interfaces.Context, -// binding: interfaces.Binding, -// previousResult: T -// ): T | Promise => { -// let result: T | Promise; - -// // use activation handler if available -// if (typeof binding.onActivation === 'function') { -// result = binding.onActivation(context, previousResult); -// } else { -// result = previousResult; -// } - -// return result; -// }; - -// const _activateContainer = ( -// activationsIterator: Iterator>, -// context: interfaces.Context, -// result: T -// ): T | Promise => { -// let activation = activationsIterator.next(); - -// while (!activation.done) { -// result = activation.value(context, result) as T; - -// if (isPromise(result)) { -// return _activateContainerAsync(activationsIterator, context, result); -// } - -// activation = activationsIterator.next(); -// } - -// return result; -// }; - -// const _activateContainerAsync = async ( -// activationsIterator: Iterator>, -// context: interfaces.Context, -// resultPromise: Promise -// ): Promise => { -// let result = await resultPromise; -// let activation = activationsIterator.next(); - -// while (!activation.done) { -// result = await activation.value(context, result); - -// activation = activationsIterator.next(); -// } - -// return result; -// }; - -// const _getContainerActivationsForService = ( -// container: interfaces.Container, -// serviceIdentifier: interfaces.ServiceIdentifier -// ) => { -// // smell accessing _activations, but similar pattern is done in planner.getBindingDictionary() -// const activations = ( -// container as unknown as { _activations: interfaces.Lookup> } -// )._activations; - -// return activations.hasKey(serviceIdentifier) ? activations.get(serviceIdentifier).values() : [].values(); -// }; - -// const _getContainersIterator = (container: interfaces.Container): Iterator => { -// const containersStack: interfaces.Container[] = [container]; - -// let parent = container.parent; - -// while (parent !== null) { -// containersStack.push(parent); - -// parent = parent.parent; -// } - -// const getNextContainer: () => IteratorResult = () => { -// const nextContainer = containersStack.pop(); - -// if (nextContainer !== undefined) { -// return { done: false, value: nextContainer }; -// } else { -// return { done: true, value: undefined }; -// } -// }; - -// const containersIterator: Iterator = { -// next: getNextContainer -// }; - -// return containersIterator; -// }; - -function resolve(context: interfaces.Context): T | Promise | (T | Promise)[] { - const _f = _resolveRequest(context.plan.rootRequest.requestScope as interfaces.RequestScope); - return _f(context.plan.rootRequest) as T | Promise | (T | Promise)[]; -} - -export { resolve }; diff --git a/packages/vrender-core/src/common/inversify-lite/scope/scope.ts b/packages/vrender-core/src/common/inversify-lite/scope/scope.ts deleted file mode 100644 index 13ee3c37e..000000000 --- a/packages/vrender-core/src/common/inversify-lite/scope/scope.ts +++ /dev/null @@ -1,69 +0,0 @@ -// import { BindingScopeEnum, interfaces } from '../inversify'; -import { BindingScopeEnum } from '../constants/literal_types'; -import type { interfaces } from '../interfaces/interfaces'; -import { isPromise } from '../utils/async'; - -export const tryGetFromScope = ( - requestScope: interfaces.RequestScope, - binding: interfaces.Binding -): T | Promise | null => { - if (binding.scope === BindingScopeEnum.Singleton && binding.activated) { - return binding.cache!; - } - - if (binding.scope === BindingScopeEnum.Request && requestScope.has(binding.id)) { - return requestScope.get(binding.id) as T | Promise; - } - return null; -}; - -export const saveToScope = ( - requestScope: interfaces.RequestScope, - binding: interfaces.Binding, - result: T | Promise -): void => { - if (binding.scope === BindingScopeEnum.Singleton) { - _saveToSingletonScope(binding, result); - } - - if (binding.scope === BindingScopeEnum.Request) { - _saveToRequestScope(requestScope, binding, result); - } -}; - -const _saveToRequestScope = ( - requestScope: interfaces.RequestScope, - binding: interfaces.Binding, - result: T | Promise -): void => { - if (!requestScope.has(binding.id)) { - requestScope.set(binding.id, result); - } -}; - -const _saveToSingletonScope = (binding: interfaces.Binding, result: T | Promise): void => { - // store in cache if scope is singleton - binding.cache = result; - binding.activated = true; - - if (isPromise(result)) { - void _saveAsyncResultToSingletonScope(binding, result); - } -}; - -const _saveAsyncResultToSingletonScope = async ( - binding: interfaces.Binding, - asyncResult: Promise -): Promise => { - try { - const result = await asyncResult; - - binding.cache = result; - } catch (ex: unknown) { - // allow binding to retry in future - binding.cache = null; - binding.activated = false; - - throw ex; - } -}; diff --git a/packages/vrender-core/src/common/inversify-lite/syntax/binding_in_syntax.ts b/packages/vrender-core/src/common/inversify-lite/syntax/binding_in_syntax.ts deleted file mode 100644 index f66da0abb..000000000 --- a/packages/vrender-core/src/common/inversify-lite/syntax/binding_in_syntax.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { BindingScopeEnum } from '../constants/literal_types'; -import type { interfaces } from '../interfaces/interfaces'; -import { BindingWhenOnSyntax } from './binding_when_on_syntax'; - -class BindingInSyntax implements interfaces.BindingInSyntax { - private _binding: interfaces.Binding; - - constructor(binding: interfaces.Binding) { - this._binding = binding; - } - - inRequestScope(): interfaces.BindingWhenOnSyntax { - this._binding.scope = BindingScopeEnum.Request; - return new BindingWhenOnSyntax(this._binding); - } - - inSingletonScope(): interfaces.BindingWhenOnSyntax { - this._binding.scope = BindingScopeEnum.Singleton; - return new BindingWhenOnSyntax(this._binding); - } - - inTransientScope(): interfaces.BindingWhenOnSyntax { - this._binding.scope = BindingScopeEnum.Transient; - return new BindingWhenOnSyntax(this._binding); - } -} - -export { BindingInSyntax }; diff --git a/packages/vrender-core/src/common/inversify-lite/syntax/binding_in_when_on_syntax.ts b/packages/vrender-core/src/common/inversify-lite/syntax/binding_in_when_on_syntax.ts deleted file mode 100644 index 8584edf24..000000000 --- a/packages/vrender-core/src/common/inversify-lite/syntax/binding_in_when_on_syntax.ts +++ /dev/null @@ -1,102 +0,0 @@ -import type { interfaces } from '../interfaces/interfaces'; -import { BindingInSyntax } from './binding_in_syntax'; -// import { BindingOnSyntax } from './binding_on_syntax'; -import { BindingWhenSyntax } from './binding_when_syntax'; - -class BindingInWhenOnSyntax - implements interfaces.BindingInSyntax, interfaces.BindingWhenSyntax, interfaces.BindingOnSyntax -{ - private _bindingInSyntax: interfaces.BindingInSyntax; - private _bindingWhenSyntax: interfaces.BindingWhenSyntax; - // private _bindingOnSyntax: interfaces.BindingOnSyntax; - private _binding: interfaces.Binding; - - constructor(binding: interfaces.Binding) { - this._binding = binding; - this._bindingWhenSyntax = new BindingWhenSyntax(this._binding); - // this._bindingOnSyntax = new BindingOnSyntax(this._binding); - this._bindingInSyntax = new BindingInSyntax(binding); - } - - inRequestScope(): interfaces.BindingWhenOnSyntax { - return this._bindingInSyntax.inRequestScope(); - } - - inSingletonScope(): interfaces.BindingWhenOnSyntax { - return this._bindingInSyntax.inSingletonScope(); - } - - inTransientScope(): interfaces.BindingWhenOnSyntax { - return this._bindingInSyntax.inTransientScope(); - } - - // public when(constraint: (request: interfaces.Request) => boolean): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.when(constraint); - // } - - whenTargetNamed(name: string): interfaces.BindingOnSyntax { - return this._bindingWhenSyntax.whenTargetNamed(name); - } - - // public whenTargetIsDefault(): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenTargetIsDefault(); - // } - - // public whenTargetTagged(tag: string, value: unknown): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenTargetTagged(tag, value); - // } - - // public whenInjectedInto(parent: NewableFunction | string): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenInjectedInto(parent); - // } - - // public whenParentNamed(name: string): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenParentNamed(name); - // } - - // public whenParentTagged(tag: string, value: unknown): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenParentTagged(tag, value); - // } - - // public whenAnyAncestorIs(ancestor: NewableFunction | string): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenAnyAncestorIs(ancestor); - // } - - // public whenNoAncestorIs(ancestor: NewableFunction | string): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenNoAncestorIs(ancestor); - // } - - // public whenAnyAncestorNamed(name: string): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenAnyAncestorNamed(name); - // } - - // public whenAnyAncestorTagged(tag: string, value: unknown): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenAnyAncestorTagged(tag, value); - // } - - // public whenNoAncestorNamed(name: string): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenNoAncestorNamed(name); - // } - - // public whenNoAncestorTagged(tag: string, value: unknown): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenNoAncestorTagged(tag, value); - // } - - // public whenAnyAncestorMatches(constraint: (request: interfaces.Request) => boolean): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenAnyAncestorMatches(constraint); - // } - - // public whenNoAncestorMatches(constraint: (request: interfaces.Request) => boolean): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenNoAncestorMatches(constraint); - // } - - // public onActivation(handler: (context: interfaces.Context, injectable: T) => T | Promise): interfaces.BindingWhenSyntax { - // return this._bindingOnSyntax.onActivation(handler); - // } - - // public onDeactivation(handler: (injectable: T) => void | Promise): interfaces.BindingWhenSyntax { - // return this._bindingOnSyntax.onDeactivation(handler); - // } -} - -export { BindingInWhenOnSyntax }; diff --git a/packages/vrender-core/src/common/inversify-lite/syntax/binding_on_syntax.ts b/packages/vrender-core/src/common/inversify-lite/syntax/binding_on_syntax.ts deleted file mode 100644 index 0b13e30ee..000000000 --- a/packages/vrender-core/src/common/inversify-lite/syntax/binding_on_syntax.ts +++ /dev/null @@ -1,24 +0,0 @@ -import type { interfaces } from '../interfaces/interfaces'; -// import { BindingWhenSyntax } from './binding_when_syntax'; - -class BindingOnSyntax implements interfaces.BindingOnSyntax { - private _binding: interfaces.Binding; - - constructor(binding: interfaces.Binding) { - this._binding = binding; - } - - // public onActivation(handler: interfaces.BindingActivation): interfaces.BindingWhenSyntax { - // console.log('onActivation'); - // this._binding.onActivation = handler; - // return new BindingWhenSyntax(this._binding); - // } - - // public onDeactivation(handler: interfaces.BindingDeactivation): interfaces.BindingWhenSyntax { - // console.log('onDeactivation'); - // this._binding.onDeactivation = handler; - // return new BindingWhenSyntax(this._binding); - // } -} - -export { BindingOnSyntax }; diff --git a/packages/vrender-core/src/common/inversify-lite/syntax/binding_to_syntax.ts b/packages/vrender-core/src/common/inversify-lite/syntax/binding_to_syntax.ts deleted file mode 100644 index 73a542aac..000000000 --- a/packages/vrender-core/src/common/inversify-lite/syntax/binding_to_syntax.ts +++ /dev/null @@ -1,103 +0,0 @@ -import * as ERROR_MSGS from '../constants/error_msgs'; -import { BindingScopeEnum, BindingTypeEnum } from '../constants/literal_types'; -import type { interfaces } from '../interfaces/interfaces'; -import { BindingInWhenOnSyntax } from './binding_in_when_on_syntax'; -import { BindingWhenOnSyntax } from './binding_when_on_syntax'; - -class BindingToSyntax implements interfaces.BindingToSyntax { - // TODO: Implement an internal type `_BindingToSyntax` wherein this member - // can be public. Let `BindingToSyntax` be the presentational type that - // depends on it, and does not expose this member as public. - private _binding: interfaces.Binding; - - constructor(binding: interfaces.Binding) { - this._binding = binding; - } - - to(constructor: interfaces.Newable): interfaces.BindingInWhenOnSyntax { - this._binding.type = BindingTypeEnum.Instance; - this._binding.implementationType = constructor; - return new BindingInWhenOnSyntax(this._binding); - } - - toSelf(): interfaces.BindingInWhenOnSyntax { - if (typeof this._binding.serviceIdentifier !== 'function') { - throw new Error(`${ERROR_MSGS.INVALID_TO_SELF_VALUE}`); - } - const self = this._binding.serviceIdentifier; - return this.to(self); - } - - toConstantValue(value: T): interfaces.BindingWhenOnSyntax { - this._binding.type = BindingTypeEnum.ConstantValue; - this._binding.cache = value; - this._binding.dynamicValue = null; - this._binding.implementationType = null; - this._binding.scope = BindingScopeEnum.Singleton; - return new BindingWhenOnSyntax(this._binding); - } - - toDynamicValue(func: interfaces.DynamicValue): interfaces.BindingInWhenOnSyntax { - this._binding.type = BindingTypeEnum.DynamicValue; - this._binding.cache = null; - this._binding.dynamicValue = func; - this._binding.implementationType = null; - return new BindingInWhenOnSyntax(this._binding); - } - - toConstructor(constructor: interfaces.Newable): interfaces.BindingWhenOnSyntax { - this._binding.type = BindingTypeEnum.Constructor; - this._binding.implementationType = constructor as unknown as T; - this._binding.scope = BindingScopeEnum.Singleton; - return new BindingWhenOnSyntax(this._binding); - } - - toFactory(factory: interfaces.FactoryCreator): interfaces.BindingWhenOnSyntax { - this._binding.type = BindingTypeEnum.Factory; - this._binding.factory = factory; - this._binding.scope = BindingScopeEnum.Singleton; - return new BindingWhenOnSyntax(this._binding); - } - - toFunction(func: T): interfaces.BindingWhenOnSyntax { - // toFunction is an alias of toConstantValue - if (typeof func !== 'function') { - throw new Error(ERROR_MSGS.INVALID_FUNCTION_BINDING); - } - const bindingWhenOnSyntax = this.toConstantValue(func); - this._binding.type = BindingTypeEnum.Function; - this._binding.scope = BindingScopeEnum.Singleton; - return bindingWhenOnSyntax; - } - - toAutoFactory(serviceIdentifier: interfaces.ServiceIdentifier): interfaces.BindingWhenOnSyntax { - this._binding.type = BindingTypeEnum.Factory; - this._binding.factory = context => { - const autofactory = () => context.container.get(serviceIdentifier); - return autofactory; - }; - this._binding.scope = BindingScopeEnum.Singleton; - return new BindingWhenOnSyntax(this._binding); - } - - toAutoNamedFactory(serviceIdentifier: interfaces.ServiceIdentifier): BindingWhenOnSyntax { - this._binding.type = BindingTypeEnum.Factory; - this._binding.factory = context => { - return (named: unknown) => context.container.getNamed(serviceIdentifier, named as string); - }; - return new BindingWhenOnSyntax(this._binding); - } - - toProvider(provider: interfaces.ProviderCreator): interfaces.BindingWhenOnSyntax { - this._binding.type = BindingTypeEnum.Provider; - this._binding.provider = provider; - this._binding.scope = BindingScopeEnum.Singleton; - return new BindingWhenOnSyntax(this._binding); - } - - toService(service: string | symbol | interfaces.Newable | interfaces.Abstract): void { - this.toDynamicValue(context => context.container.get(service)); - } -} - -export { BindingToSyntax }; diff --git a/packages/vrender-core/src/common/inversify-lite/syntax/binding_when_on_syntax.ts b/packages/vrender-core/src/common/inversify-lite/syntax/binding_when_on_syntax.ts deleted file mode 100644 index 4a49a1e1e..000000000 --- a/packages/vrender-core/src/common/inversify-lite/syntax/binding_when_on_syntax.ts +++ /dev/null @@ -1,85 +0,0 @@ -import type { interfaces } from '../interfaces/interfaces'; -// import { BindingOnSyntax } from './binding_on_syntax'; -import { BindingWhenSyntax } from './binding_when_syntax'; - -class BindingWhenOnSyntax implements interfaces.BindingWhenSyntax, interfaces.BindingOnSyntax { - private _bindingWhenSyntax: interfaces.BindingWhenSyntax; - // private _bindingOnSyntax: interfaces.BindingOnSyntax; - private _binding: interfaces.Binding; - - constructor(binding: interfaces.Binding) { - this._binding = binding; - this._bindingWhenSyntax = new BindingWhenSyntax(this._binding); - // this._bindingOnSyntax = new BindingOnSyntax(this._binding); - } - - // public when(constraint: (request: interfaces.Request) => boolean): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.when(constraint); - // } - - whenTargetNamed(name: string): interfaces.BindingOnSyntax { - return this._bindingWhenSyntax.whenTargetNamed(name); - } - - // public whenTargetIsDefault(): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenTargetIsDefault(); - // } - - // public whenTargetTagged(tag: string, value: unknown): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenTargetTagged(tag, value); - // } - - // public whenInjectedInto(parent: NewableFunction | string): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenInjectedInto(parent); - // } - - // public whenParentNamed(name: string): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenParentNamed(name); - // } - - // public whenParentTagged(tag: string, value: unknown): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenParentTagged(tag, value); - // } - - // public whenAnyAncestorIs(ancestor: NewableFunction | string): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenAnyAncestorIs(ancestor); - // } - - // public whenNoAncestorIs(ancestor: NewableFunction | string): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenNoAncestorIs(ancestor); - // } - - // public whenAnyAncestorNamed(name: string): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenAnyAncestorNamed(name); - // } - - // public whenAnyAncestorTagged(tag: string, value: unknown): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenAnyAncestorTagged(tag, value); - // } - - // public whenNoAncestorNamed(name: string): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenNoAncestorNamed(name); - // } - - // public whenNoAncestorTagged(tag: string, value: unknown): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenNoAncestorTagged(tag, value); - // } - - // public whenAnyAncestorMatches(constraint: (request: interfaces.Request) => boolean): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenAnyAncestorMatches(constraint); - // } - - // public whenNoAncestorMatches(constraint: (request: interfaces.Request) => boolean): interfaces.BindingOnSyntax { - // return this._bindingWhenSyntax.whenNoAncestorMatches(constraint); - // } - - // public onActivation(handler: (context: interfaces.Context, injectable: T) => T): interfaces.BindingWhenSyntax { - // return this._bindingOnSyntax.onActivation(handler); - // } - - // public onDeactivation(handler: (injectable: T) => Promise | void): interfaces.BindingWhenSyntax { - // return this._bindingOnSyntax.onDeactivation(handler); - // } -} - -export { BindingWhenOnSyntax }; diff --git a/packages/vrender-core/src/common/inversify-lite/syntax/binding_when_syntax.ts b/packages/vrender-core/src/common/inversify-lite/syntax/binding_when_syntax.ts deleted file mode 100644 index ec4368261..000000000 --- a/packages/vrender-core/src/common/inversify-lite/syntax/binding_when_syntax.ts +++ /dev/null @@ -1,119 +0,0 @@ -import type { interfaces } from '../interfaces/interfaces'; -import { BindingOnSyntax } from './binding_on_syntax'; -import { namedConstraint } from './constraint_helpers'; - -class BindingWhenSyntax implements interfaces.BindingWhenSyntax { - private _binding: interfaces.Binding; - - constructor(binding: interfaces.Binding) { - this._binding = binding; - } - - // public when(constraint: (request: interfaces.Request) => boolean): interfaces.BindingOnSyntax { - // this._binding.constraint = constraint as interfaces.ConstraintFunction; - // return new BindingOnSyntax(this._binding); - // } - - whenTargetNamed(name: string | number | symbol): interfaces.BindingOnSyntax { - this._binding.constraint = namedConstraint(name); - return new BindingOnSyntax(this._binding); - } - - // public whenTargetIsDefault(): interfaces.BindingOnSyntax { - // this._binding.constraint = (request: interfaces.Request | null) => { - // if (request === null) { - // return false; - // } - - // const targetIsDefault = request.target !== null && !request.target.isNamed() && !request.target.isTagged(); - - // return targetIsDefault; - // }; - - // return new BindingOnSyntax(this._binding); - // } - - // public whenTargetTagged(tag: string | number | symbol, value: unknown): interfaces.BindingOnSyntax { - // this._binding.constraint = taggedConstraint(tag)(value); - // return new BindingOnSyntax(this._binding); - // } - - // public whenInjectedInto(parent: NewableFunction | string): interfaces.BindingOnSyntax { - // this._binding.constraint = (request: interfaces.Request | null) => - // request !== null && typeConstraint(parent)(request.parentRequest); - - // return new BindingOnSyntax(this._binding); - // } - - // public whenParentNamed(name: string | number | symbol): interfaces.BindingOnSyntax { - // this._binding.constraint = (request: interfaces.Request | null) => - // request !== null && namedConstraint(name)(request.parentRequest); - - // return new BindingOnSyntax(this._binding); - // } - - // public whenParentTagged(tag: string | number | symbol, value: unknown): interfaces.BindingOnSyntax { - // this._binding.constraint = (request: interfaces.Request | null) => - // request !== null && taggedConstraint(tag)(value)(request.parentRequest); - - // return new BindingOnSyntax(this._binding); - // } - - // public whenAnyAncestorIs(ancestor: NewableFunction | string): interfaces.BindingOnSyntax { - // this._binding.constraint = (request: interfaces.Request | null) => - // request !== null && traverseAncerstors(request, typeConstraint(ancestor)); - - // return new BindingOnSyntax(this._binding); - // } - - // public whenNoAncestorIs(ancestor: NewableFunction | string): interfaces.BindingOnSyntax { - // this._binding.constraint = (request: interfaces.Request | null) => - // request !== null && !traverseAncerstors(request, typeConstraint(ancestor)); - - // return new BindingOnSyntax(this._binding); - // } - - // public whenAnyAncestorNamed(name: string | number | symbol): interfaces.BindingOnSyntax { - // this._binding.constraint = (request: interfaces.Request | null) => - // request !== null && traverseAncerstors(request, namedConstraint(name)); - - // return new BindingOnSyntax(this._binding); - // } - - // public whenNoAncestorNamed(name: string | number | symbol): interfaces.BindingOnSyntax { - // this._binding.constraint = (request: interfaces.Request | null) => - // request !== null && !traverseAncerstors(request, namedConstraint(name)); - - // return new BindingOnSyntax(this._binding); - // } - - // public whenAnyAncestorTagged(tag: string | number | symbol, value: unknown): interfaces.BindingOnSyntax { - // this._binding.constraint = (request: interfaces.Request | null) => - // request !== null && traverseAncerstors(request, taggedConstraint(tag)(value)); - - // return new BindingOnSyntax(this._binding); - // } - - // public whenNoAncestorTagged(tag: string | number | symbol, value: unknown): interfaces.BindingOnSyntax { - // this._binding.constraint = (request: interfaces.Request | null) => - // request !== null && !traverseAncerstors(request, taggedConstraint(tag)(value)); - - // return new BindingOnSyntax(this._binding); - // } - - // public whenAnyAncestorMatches(constraint: (request: interfaces.Request) => boolean): interfaces.BindingOnSyntax { - // this._binding.constraint = (request: interfaces.Request | null) => - // request !== null && traverseAncerstors(request, constraint as interfaces.ConstraintFunction); - - // return new BindingOnSyntax(this._binding); - // } - - // public whenNoAncestorMatches(constraint: (request: interfaces.Request) => boolean): interfaces.BindingOnSyntax { - // this._binding.constraint = (request: interfaces.Request | null) => - // request !== null && !traverseAncerstors(request, constraint as interfaces.ConstraintFunction); - - // return new BindingOnSyntax(this._binding); - // } -} - -export { BindingWhenSyntax }; diff --git a/packages/vrender-core/src/common/inversify-lite/syntax/constraint_helpers.ts b/packages/vrender-core/src/common/inversify-lite/syntax/constraint_helpers.ts deleted file mode 100644 index 62cc15ac7..000000000 --- a/packages/vrender-core/src/common/inversify-lite/syntax/constraint_helpers.ts +++ /dev/null @@ -1,52 +0,0 @@ -import * as METADATA_KEY from '../constants/metadata_keys'; -import type { interfaces } from '../interfaces/interfaces'; -import { Metadata } from '../planning/metadata'; - -// const traverseAncerstors = ( -// request: interfaces.Request, -// constraint: interfaces.ConstraintFunction -// ): boolean => { - -// const parent = request.parentRequest; -// if (parent !== null) { -// return constraint(parent) ? true : traverseAncerstors(parent, constraint); -// } else { -// return false; -// } -// }; - -// This helpers use currying to help you to generate constraints - -const taggedConstraint = (key: string | number | symbol) => (value: unknown) => { - const constraint: interfaces.ConstraintFunction = (request: interfaces.Request | null) => - request !== null && request.target !== null && request.target.matchesTag(key)(value); - - constraint.metaData = new Metadata(key, value); - - return constraint; -}; - -const namedConstraint = taggedConstraint(METADATA_KEY.NAMED_TAG); - -// const typeConstraint = (type: (NewableFunction | string)) => (request: interfaces.Request | null) => { - -// // Using index 0 because constraints are applied -// // to one binding at a time (see Planner class) -// let binding: interfaces.Binding | null = null; - -// if (request !== null) { -// binding = request.bindings[0] as interfaces.Binding; -// if (typeof type === 'string') { -// const serviceIdentifier = binding.serviceIdentifier; -// return serviceIdentifier === type; -// } else { -// const constructor = (request.bindings[0] as interfaces.Binding).implementationType; -// return type === constructor; -// } -// } - -// return false; -// }; - -// export { traverseAncerstors, taggedConstraint, namedConstraint, typeConstraint }; -export { namedConstraint }; diff --git a/packages/vrender-core/src/common/inversify-lite/utils/async.ts b/packages/vrender-core/src/common/inversify-lite/utils/async.ts deleted file mode 100644 index 75b1ab97b..000000000 --- a/packages/vrender-core/src/common/inversify-lite/utils/async.ts +++ /dev/null @@ -1,15 +0,0 @@ -function isPromise(object: unknown): object is Promise { - const isObjectOrFunction = (typeof object === 'object' && object !== null) || typeof object === 'function'; - - return isObjectOrFunction && typeof (object as PromiseLike).then === 'function'; -} - -function isPromiseOrContainsPromise(object: unknown): object is Promise | (T | Promise)[] { - if (isPromise(object)) { - return true; - } - - return Array.isArray(object) && object.some(isPromise); -} - -export { isPromise, isPromiseOrContainsPromise }; diff --git a/packages/vrender-core/src/common/inversify-lite/utils/binding_utils.ts b/packages/vrender-core/src/common/inversify-lite/utils/binding_utils.ts deleted file mode 100644 index f36266c03..000000000 --- a/packages/vrender-core/src/common/inversify-lite/utils/binding_utils.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { getServiceIdentifierAsString } from './serialization'; -import * as ERROR_MSGS from '../constants/error_msgs'; -import { BindingTypeEnum } from '../constants/literal_types'; -import { FactoryType } from './factory_type'; -import type { interfaces } from '../interfaces/interfaces'; - -export const multiBindToService = - (container: interfaces.Container) => - (service: interfaces.ServiceIdentifier) => - (...types: interfaces.ServiceIdentifier[]) => - types.forEach(t => container.bind(t).toService(service)); - -export const ensureFullyBound = (binding: interfaces.Binding): void => { - let boundValue: unknown = null; - - switch (binding.type) { - case BindingTypeEnum.ConstantValue: - case BindingTypeEnum.Function: - boundValue = binding.cache; - break; - case BindingTypeEnum.Constructor: - case BindingTypeEnum.Instance: - boundValue = binding.implementationType; - break; - case BindingTypeEnum.DynamicValue: - boundValue = binding.dynamicValue; - break; - case BindingTypeEnum.Provider: - boundValue = binding.provider; - break; - case BindingTypeEnum.Factory: - boundValue = binding.factory; - break; - } - if (boundValue === null) { - // The user probably created a binding but didn't finish it - // e.g. container.bind('Something'); missing BindingToSyntax - const serviceIdentifierAsString = getServiceIdentifierAsString(binding.serviceIdentifier); - throw new Error(`${ERROR_MSGS.INVALID_BINDING_TYPE} ${serviceIdentifierAsString}`); - } -}; - -export const getFactoryDetails = (binding: interfaces.Binding): interfaces.FactoryDetails => { - switch (binding.type) { - case BindingTypeEnum.Factory: - return { factory: binding.factory, factoryType: FactoryType.Factory }; - case BindingTypeEnum.Provider: - return { factory: binding.provider, factoryType: FactoryType.Provider }; - case BindingTypeEnum.DynamicValue: - return { factory: binding.dynamicValue, factoryType: FactoryType.DynamicValue }; - default: - throw new Error(`Unexpected factory type ${binding.type}`); - } -}; diff --git a/packages/vrender-core/src/common/inversify-lite/utils/clonable.ts b/packages/vrender-core/src/common/inversify-lite/utils/clonable.ts deleted file mode 100644 index df53a2dcd..000000000 --- a/packages/vrender-core/src/common/inversify-lite/utils/clonable.ts +++ /dev/null @@ -1,12 +0,0 @@ -import type { interfaces } from '../interfaces/interfaces'; - -function isClonable(obj: unknown): obj is interfaces.Clonable { - return ( - typeof obj === 'object' && - obj !== null && - 'clone' in obj && - typeof (obj as interfaces.Clonable).clone === 'function' - ); -} - -export { isClonable }; diff --git a/packages/vrender-core/src/common/inversify-lite/utils/exceptions.ts b/packages/vrender-core/src/common/inversify-lite/utils/exceptions.ts deleted file mode 100644 index 8c4f8da9d..000000000 --- a/packages/vrender-core/src/common/inversify-lite/utils/exceptions.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as ERROR_MSGS from '../constants/error_msgs'; - -export function isStackOverflowExeption(error: unknown): error is RangeError { - return error instanceof RangeError || (error as Error).message === ERROR_MSGS.STACK_OVERFLOW; -} - -export const tryAndThrowErrorIfStackOverflow = (fn: () => T, errorCallback: () => Error) => { - return fn(); - // try { - // return fn(); - // } catch (error) { - // if (isStackOverflowExeption(error)) { - // error = errorCallback(); - // } - // throw error; - // } -}; diff --git a/packages/vrender-core/src/common/inversify-lite/utils/factory_type.ts b/packages/vrender-core/src/common/inversify-lite/utils/factory_type.ts deleted file mode 100644 index 4f6320ed7..000000000 --- a/packages/vrender-core/src/common/inversify-lite/utils/factory_type.ts +++ /dev/null @@ -1,5 +0,0 @@ -export enum FactoryType { - DynamicValue = 'toDynamicValue', - Factory = 'toFactory', - Provider = 'toProvider' -} diff --git a/packages/vrender-core/src/common/inversify-lite/utils/id.ts b/packages/vrender-core/src/common/inversify-lite/utils/id.ts deleted file mode 100644 index 5eb12e5dc..000000000 --- a/packages/vrender-core/src/common/inversify-lite/utils/id.ts +++ /dev/null @@ -1,7 +0,0 @@ -let idCounter = 0; - -function id(): number { - return idCounter++; -} - -export { id }; diff --git a/packages/vrender-core/src/common/inversify-lite/utils/js.ts b/packages/vrender-core/src/common/inversify-lite/utils/js.ts deleted file mode 100644 index 96a14b6a8..000000000 --- a/packages/vrender-core/src/common/inversify-lite/utils/js.ts +++ /dev/null @@ -1,11 +0,0 @@ -export function getFirstArrayDuplicate(array: T[]): T | undefined { - const seenValues = new Set(); - - for (const entry of array) { - if (seenValues.has(entry)) { - return entry; - } - seenValues.add(entry); - } - return undefined; -} diff --git a/packages/vrender-core/src/common/inversify-lite/utils/serialization.ts b/packages/vrender-core/src/common/inversify-lite/utils/serialization.ts deleted file mode 100644 index cea151383..000000000 --- a/packages/vrender-core/src/common/inversify-lite/utils/serialization.ts +++ /dev/null @@ -1,125 +0,0 @@ -import * as ERROR_MSGS from '../constants/error_msgs'; -import type { interfaces } from '../interfaces/interfaces'; - -function getServiceIdentifierAsString(serviceIdentifier: interfaces.ServiceIdentifier): string { - if (typeof serviceIdentifier === 'function') { - const _serviceIdentifier = serviceIdentifier; - return _serviceIdentifier.name; - } else if (typeof serviceIdentifier === 'symbol') { - return serviceIdentifier.toString(); - } // string - const _serviceIdentifier = serviceIdentifier; - return _serviceIdentifier as string; -} - -function listRegisteredBindingsForServiceIdentifier( - container: interfaces.Container, - serviceIdentifier: string, - getBindings: ( - container: interfaces.Container, - serviceIdentifier: interfaces.ServiceIdentifier - ) => interfaces.Binding[] -): string { - let registeredBindingsList = ''; - const registeredBindings = getBindings(container, serviceIdentifier); - - if (registeredBindings.length !== 0) { - registeredBindingsList = '\nRegistered bindings:'; - - registeredBindings.forEach((binding: interfaces.Binding) => { - // Use 'Object as name of constant value injections' - let name = 'Object'; - - // Use function name if available - if (binding.implementationType !== null) { - name = getFunctionName(binding.implementationType as { name: string | null }); - } - - registeredBindingsList = `${registeredBindingsList}\n ${name}`; - - if (binding.constraint.metaData) { - registeredBindingsList = `${registeredBindingsList} - ${binding.constraint.metaData}`; - } - }); - } - - return registeredBindingsList; -} - -function alreadyDependencyChain(request: interfaces.Request, serviceIdentifier: interfaces.ServiceIdentifier): boolean { - if (request.parentRequest === null) { - return false; - } else if (request.parentRequest.serviceIdentifier === serviceIdentifier) { - return true; - } - return alreadyDependencyChain(request.parentRequest, serviceIdentifier); -} - -function dependencyChainToString(request: interfaces.Request) { - function _createStringArr(req: interfaces.Request, result: string[] = []): string[] { - const serviceIdentifier = getServiceIdentifierAsString(req.serviceIdentifier); - result.push(serviceIdentifier); - if (req.parentRequest !== null) { - return _createStringArr(req.parentRequest, result); - } - return result; - } - - const stringArr = _createStringArr(request); - return stringArr.reverse().join(' --> '); -} - -function circularDependencyToException(request: interfaces.Request) { - request.childRequests.forEach(childRequest => { - if (alreadyDependencyChain(childRequest, childRequest.serviceIdentifier)) { - const services = dependencyChainToString(childRequest); - throw new Error(`${ERROR_MSGS.CIRCULAR_DEPENDENCY} ${services}`); - } else { - circularDependencyToException(childRequest); - } - }); -} - -function listMetadataForTarget(serviceIdentifierString: string, target: interfaces.Target): string { - if (target.isTagged() || target.isNamed()) { - let m = ''; - - const namedTag = target.getNamedTag(); - const otherTags = target.getCustomTags(); - - if (namedTag !== null) { - m += namedTag.toString() + '\n'; - } - - if (otherTags !== null) { - otherTags.forEach(tag => { - m += tag.toString() + '\n'; - }); - } - - return ` ${serviceIdentifierString}\n ${serviceIdentifierString} - ${m}`; - } - return ` ${serviceIdentifierString}`; -} - -function getFunctionName(func: { name: string | null }): string { - if (func.name) { - return func.name; - } - const name = func.toString(); - const match = name.match(/^function\s*([^\s(]+)/); - return match ? (match[1] as string) : `Anonymous function: ${name}`; -} - -function getSymbolDescription(symbol: symbol) { - return symbol.toString().slice(7, -1); -} - -export { - getFunctionName, - getServiceIdentifierAsString, - listRegisteredBindingsForServiceIdentifier, - listMetadataForTarget, - circularDependencyToException, - getSymbolDescription -}; diff --git a/packages/vrender-core/src/common/inversify/annotation/inject.ts b/packages/vrender-core/src/common/inversify/annotation/inject.ts deleted file mode 100644 index aedac40a1..000000000 --- a/packages/vrender-core/src/common/inversify/annotation/inject.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { INJECT_TAG } from '../metadata_keys'; -import { injectBase } from './inject_base'; - -export const inject = injectBase(INJECT_TAG); diff --git a/packages/vrender-core/src/common/inversify/annotation/inject_base.ts b/packages/vrender-core/src/common/inversify/annotation/inject_base.ts deleted file mode 100644 index 05763ab96..000000000 --- a/packages/vrender-core/src/common/inversify/annotation/inject_base.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { Metadata } from '../meta-data'; -import { TAGGED } from '../metadata_keys'; -import Reflect from '../../Reflect-metadata'; - -function _tagParameterOrProperty( - metadataKey: string, - annotationTarget: NewableFunction, - key: string | symbol, - metadata: Metadata -) { - const metadatas: Metadata[] = [metadata]; - - let paramsOrPropertiesMetadata: Record = {}; - // read metadata if available - if ((Reflect as any).hasOwnMetadata(metadataKey, annotationTarget)) { - paramsOrPropertiesMetadata = (Reflect as any).getMetadata(metadataKey, annotationTarget); - } - - let paramOrPropertyMetadata: Metadata[] | undefined = paramsOrPropertiesMetadata[key as string]; - - if (paramOrPropertyMetadata === undefined) { - paramOrPropertyMetadata = []; - } - - // set metadata - paramOrPropertyMetadata.push(...metadatas); - paramsOrPropertiesMetadata[key] = paramOrPropertyMetadata; - (Reflect as any).defineMetadata(metadataKey, paramsOrPropertiesMetadata, annotationTarget); -} - -function tagParameter( - annotationTarget: DecoratorTarget, - parameterName: string | symbol | undefined, - parameterIndex: number, - metadata: Metadata -) { - _tagParameterOrProperty(TAGGED, annotationTarget as ConstructorFunction, parameterIndex.toString(), metadata); -} - -export function createTaggedDecorator(metadata: Metadata) { - return (target: DecoratorTarget, targetKey?: string | symbol, indexOrPropertyDescriptor?: number) => { - tagParameter(target, targetKey, indexOrPropertyDescriptor, metadata); - }; -} - -type Prototype = { - [Property in keyof T]: T[Property] extends NewableFunction ? T[Property] : T[Property] | undefined; -} & { constructor: NewableFunction }; - -interface ConstructorFunction> { - new (...args: unknown[]): T; - prototype: Prototype; -} - -export type DecoratorTarget = ConstructorFunction | Prototype; - -export function injectBase(metadataKey: string) { - return (serviceIdentifier: any) => { - return (target: DecoratorTarget, targetKey?: string | symbol, indexOrPropertyDescriptor?: number) => { - return createTaggedDecorator(new Metadata(metadataKey, serviceIdentifier))( - target, - targetKey, - indexOrPropertyDescriptor - ); - }; - }; -} diff --git a/packages/vrender-core/src/common/inversify/annotation/injectable.ts b/packages/vrender-core/src/common/inversify/annotation/injectable.ts deleted file mode 100644 index 852a23a7c..000000000 --- a/packages/vrender-core/src/common/inversify/annotation/injectable.ts +++ /dev/null @@ -1,10 +0,0 @@ -import * as METADATA_KEY from '../metadata_keys'; -import Reflect from '../../Reflect-metadata'; - -export function injectable() { - return function unknown>(target: T) { - (Reflect as any).defineMetadata(METADATA_KEY.PARAM_TYPES, null, target); - - return target; - }; -} diff --git a/packages/vrender-core/src/common/inversify/annotation/multi_inject.ts b/packages/vrender-core/src/common/inversify/annotation/multi_inject.ts deleted file mode 100644 index ffdf022e5..000000000 --- a/packages/vrender-core/src/common/inversify/annotation/multi_inject.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { MULTI_INJECT_TAG } from '../metadata_keys'; -import { injectBase } from './inject_base'; - -export const multiInject = injectBase(MULTI_INJECT_TAG); diff --git a/packages/vrender-core/src/common/inversify/annotation/named.ts b/packages/vrender-core/src/common/inversify/annotation/named.ts deleted file mode 100644 index 59fdba734..000000000 --- a/packages/vrender-core/src/common/inversify/annotation/named.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Metadata } from '../meta-data'; -import { NAMED_TAG } from '../metadata_keys'; -import { createTaggedDecorator } from './inject_base'; - -export function named(name: string | number | symbol) { - return createTaggedDecorator(new Metadata(NAMED_TAG, name)); -} diff --git a/packages/vrender-core/src/common/inversify/annotation/optional.ts b/packages/vrender-core/src/common/inversify/annotation/optional.ts deleted file mode 100644 index ee35ab2db..000000000 --- a/packages/vrender-core/src/common/inversify/annotation/optional.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Metadata } from '../meta-data'; -import { OPTIONAL_TAG } from '../metadata_keys'; -import { createTaggedDecorator } from './inject_base'; - -function optional() { - return createTaggedDecorator(new Metadata(OPTIONAL_TAG, true)); -} - -export { optional }; diff --git a/packages/vrender-core/src/common/inversify/binding.ts b/packages/vrender-core/src/common/inversify/binding.ts deleted file mode 100644 index bc0c9a4d0..000000000 --- a/packages/vrender-core/src/common/inversify/binding.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { Generator } from '../generator'; -import type { interfaces } from './interfaces'; -import { BindingScopeEnum, BindingTypeEnum } from './literal_types'; - -class Binding implements interfaces.Binding { - id: number; - moduleId!: interfaces.ContainerModuleBase['id']; - - // Determines weather the bindings has been already activated - // The activation action takes place when an instance is resolved - // If the scope is singleton it only happens once - activated: boolean; - - // A runtime identifier because at runtime we don't have interfaces - serviceIdentifier: interfaces.ServiceIdentifier; - - // constructor from binding to or toConstructor - implementationType: interfaces.Newable | TActivated | null; - - // Cache used to allow singleton scope and BindingType.ConstantValue bindings - cache: TActivated | null; - - // Cache used to allow BindingType.DynamicValue bindings - dynamicValue: interfaces.DynamicValue | null; - - // The scope mode to be used - scope: interfaces.BindingScope; - - // The kind of binding - type: interfaces.BindingType; - - // A factory method used in BindingType.Factory bindings - factory: interfaces.FactoryCreator | null; - - // An async factory method used in BindingType.Provider bindings - provider: interfaces.ProviderCreator | null; - - // A constraint used to limit the contexts in which this binding is applicable - constraint: interfaces.ConstraintFunction; - - // // On activation handler (invoked just before an instance is added to cache and injected) - // onActivation: interfaces.BindingActivation | null; - - // // On deactivation handler (invoked just before an instance is unbinded and removed from container) - // onDeactivation: interfaces.BindingDeactivation | null; - - constructor(serviceIdentifier: interfaces.ServiceIdentifier, scope: interfaces.BindingScope) { - this.id = Generator.GenAutoIncrementId(); - this.activated = false; - this.serviceIdentifier = serviceIdentifier; - this.scope = scope; - this.type = BindingTypeEnum.Invalid; - this.constraint = (request: interfaces.Request | null) => true; - this.implementationType = null; - this.cache = null; - this.factory = null; - this.provider = null; - // this.onActivation = null; - // this.onDeactivation = null; - this.dynamicValue = null; - } - - clone(): interfaces.Binding { - const clone = new Binding(this.serviceIdentifier, this.scope); - clone.activated = clone.scope === BindingScopeEnum.Singleton ? this.activated : false; - clone.implementationType = this.implementationType; - clone.dynamicValue = this.dynamicValue; - clone.scope = this.scope; - clone.type = this.type; - // clone.factory = this.factory; - clone.provider = this.provider; - clone.constraint = this.constraint; - // clone.onActivation = this.onActivation; - // clone.onDeactivation = this.onDeactivation; - clone.cache = this.cache; - return clone; - } -} - -export { Binding }; diff --git a/packages/vrender-core/src/common/inversify/container.ts b/packages/vrender-core/src/common/inversify/container.ts deleted file mode 100644 index 849485895..000000000 --- a/packages/vrender-core/src/common/inversify/container.ts +++ /dev/null @@ -1,278 +0,0 @@ -import { Generator } from '../generator'; -import { Binding } from './binding'; -import type { interfaces } from './interfaces'; -import { BindingScopeEnum, BindingTypeEnum } from './literal_types'; -import { Metadata } from './meta-data'; -import { INJECT_TAG, MULTI_INJECT_TAG, NAMED_TAG } from './metadata_keys'; -import { MetadataReader } from './metadata_reader'; -import { BindingToSyntax } from './syntax/binding_to_syntax'; - -interface IChildRequest { - injectIdentifier: any; - metadata: interfaces.Metadata[]; - bindings: Binding[]; -} - -interface GetArgs { - avoidConstraints: boolean; - isMultiInject: boolean; - serviceIdentifier: interfaces.ServiceIdentifier; - key: string | symbol; - value: any; -} - -export class Container { - id: number; - readonly options: interfaces.ContainerOptions; - private _bindingDictionary: Map[]>; - private _metadataReader: interfaces.MetadataReader; - - constructor(containerOptions?: interfaces.ContainerOptions) { - const options = containerOptions || {}; - options.defaultScope = options.defaultScope || BindingScopeEnum.Transient; - // console.log(this); - this.options = options; - this.id = Generator.GenAutoIncrementId(); - this._bindingDictionary = new Map(); - this._metadataReader = new MetadataReader(); - } - - load(module: interfaces.ContainerModule) { - const getHelpers = this._getContainerModuleHelpersFactory(); - - const containerModuleHelpers = getHelpers(module.id); - - module.registry( - containerModuleHelpers.bindFunction as interfaces.Bind, - containerModuleHelpers.unbindFunction, - containerModuleHelpers.isboundFunction, - containerModuleHelpers.rebindFunction as interfaces.Rebind - ); - } - - get(serviceIdentifier: interfaces.ServiceIdentifier): T { - const getArgs = this._getNotAllArgs(serviceIdentifier, false); - - return this._get(getArgs) as T; - } - - getAll(serviceIdentifier: interfaces.ServiceIdentifier): T[] { - const getArgs = this._getAllArgs(serviceIdentifier); - - return this._get(getArgs) as T[]; - } - - getTagged(serviceIdentifier: interfaces.ServiceIdentifier, key: string | number | symbol, value: unknown): T { - const getArgs = this._getNotAllArgs(serviceIdentifier, false, key, value); - - return this._get(getArgs) as T; - } - - getNamed(serviceIdentifier: interfaces.ServiceIdentifier, named: string | number | symbol): T { - return this.getTagged(serviceIdentifier, NAMED_TAG, named); - } - - isBound(serviceIdentifier: interfaces.ServiceIdentifier): boolean { - return this._bindingDictionary.has(serviceIdentifier); - } - - // Registers a type binding - bind(serviceIdentifier: interfaces.ServiceIdentifier): interfaces.BindingToSyntax { - const scope = this.options.defaultScope; - const binding = new Binding(serviceIdentifier, scope); - const list = this._bindingDictionary.get(serviceIdentifier) || []; - list.push(binding); - this._bindingDictionary.set(serviceIdentifier, list); - return new BindingToSyntax(binding); - } - - unbind(serviceIdentifier: interfaces.ServiceIdentifier): void { - this._bindingDictionary.delete(serviceIdentifier); - } - - rebind(serviceIdentifier: interfaces.ServiceIdentifier): interfaces.BindingToSyntax { - this.unbind(serviceIdentifier); - return this.bind(serviceIdentifier); - } - - private _getContainerModuleHelpersFactory() { - const setModuleId = ( - bindingToSyntax: interfaces.BindingToSyntax, - moduleId: interfaces.ContainerModuleBase['id'] - ) => { - // TODO: Implement an internal type `_BindingToSyntax` wherein this member - // can be public. Let `BindingToSyntax` be the presentational type that - // depends on it, and does not expose this member as public. - ( - bindingToSyntax as unknown as { _binding: { moduleId: interfaces.ContainerModuleBase['id'] } } - )._binding.moduleId = moduleId; - }; - - const getBindFunction = - (moduleId: interfaces.ContainerModuleBase['id']) => - (serviceIdentifier: interfaces.ServiceIdentifier) => { - const bindingToSyntax = this.bind(serviceIdentifier); - setModuleId(bindingToSyntax, moduleId); - return bindingToSyntax as BindingToSyntax; - }; - - const getUnbindFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => { - return this.unbind(serviceIdentifier); - }; - - const getUnbindAsyncFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => { - return null as any; - // return this.unbindAsync(serviceIdentifier); - }; - - const getIsboundFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => { - return this.isBound(serviceIdentifier); - }; - - const getRebindFunction = - (moduleId: interfaces.ContainerModuleBase['id']) => - (serviceIdentifier: interfaces.ServiceIdentifier) => { - const bindingToSyntax = this.rebind(serviceIdentifier); - setModuleId(bindingToSyntax, moduleId); - return bindingToSyntax as BindingToSyntax; - }; - return (mId: interfaces.ContainerModuleBase['id']) => ({ - bindFunction: getBindFunction(mId), - isboundFunction: getIsboundFunction(), - rebindFunction: getRebindFunction(mId), - unbindFunction: getUnbindFunction(), - unbindAsyncFunction: getUnbindAsyncFunction() - }); - } - - private _getNotAllArgs( - serviceIdentifier: interfaces.ServiceIdentifier, - isMultiInject: boolean, - key?: string | number | symbol | undefined, - value?: unknown - ): any { - return { - avoidConstraints: false, - isMultiInject, - serviceIdentifier, - key, - value - }; - } - - private _getAllArgs(serviceIdentifier: interfaces.ServiceIdentifier): any { - return { - avoidConstraints: true, - isMultiInject: true, - serviceIdentifier - }; - } - - private _get(getArgs: GetArgs): T | T[] { - const result: T[] = []; - const bindings = this._bindingDictionary.get(getArgs.serviceIdentifier).filter(b => { - return b.constraint(getArgs as any); - }) as Binding[]; - bindings.forEach(binding => { - result.push(this._resolveFromBinding(binding)); - }); - - return !getArgs.isMultiInject && result.length === 1 ? result[0] : result; - } - - private _getChildRequest(binding: Binding) { - const constr = binding.implementationType; - const { userGeneratedMetadata } = this._metadataReader.getConstructorMetadata(constr as any); - const keys = Object.keys(userGeneratedMetadata); - const arr = []; - for (let i = 0; i < keys.length; i++) { - const constructorArgsMetadata = userGeneratedMetadata[i]; - const targetMetadataMap = {}; - constructorArgsMetadata.forEach(md => { - targetMetadataMap[md.key] = md.value; - }); - const metadata = { - inject: targetMetadataMap[INJECT_TAG], - multiInject: targetMetadataMap[MULTI_INJECT_TAG] - }; - const injectIdentifier = metadata.inject || metadata.multiInject; - const target = { - serviceIdentifier: injectIdentifier, - constructorArgsMetadata - }; - const bindings = (this._bindingDictionary.get(injectIdentifier) || []).filter(b => { - return b.constraint(target as any); - }); - if (bindings.length) { - const request = { - injectIdentifier, - metadata: constructorArgsMetadata, - bindings: bindings - }; - - arr.push(request); - } - } - - return arr; - } - - private _resolveFromBinding(binding: Binding): T { - const result = this._getResolvedFromBinding(binding); - - this._saveToScope(binding, result); - - return result; - } - - private _getResolvedFromBinding(binding: Binding) { - let result: T; - switch (binding.type) { - case BindingTypeEnum.ConstantValue: - case BindingTypeEnum.Function: - result = binding.cache as T; - break; - case BindingTypeEnum.Instance: - result = this._resolveInstance(binding, binding.implementationType as interfaces.Newable); - break; - default: - result = binding.dynamicValue({ container: this } as any); - } - - return result; - } - - private _resolveInstance(binding: Binding, constr: interfaces.Newable): T { - if (binding.activated) { - return binding.cache; - } - - const childRequests = this._getChildRequest(binding); - return this._createInstance(constr, childRequests); - } - - private _createInstance(constr: interfaces.Newable, childRequests: IChildRequest[]) { - if (childRequests.length) { - const resolved = this._resolveRequests(childRequests); - const obj = new constr(...resolved); - return obj; - } - const obj = new constr(); - return obj; - } - - private _resolveRequests(childRequests: IChildRequest[]): any[] { - return childRequests.map(request => { - return request.bindings.length > 1 - ? request.bindings.map(binding => this._resolveFromBinding(binding)) - : this._resolveFromBinding(request.bindings[0]); - }); - } - - private _saveToScope(binding: Binding, result: any) { - if (binding.scope === BindingScopeEnum.Singleton) { - binding.cache = result; - binding.activated = true; - } - } -} diff --git a/packages/vrender-core/src/common/inversify/cotainer-module.ts b/packages/vrender-core/src/common/inversify/cotainer-module.ts deleted file mode 100644 index bfb05bfb7..000000000 --- a/packages/vrender-core/src/common/inversify/cotainer-module.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Generator } from '../generator'; -import type { interfaces } from '../inversify-lite'; - -export class ContainerModule { - id: number; - registry: interfaces.ContainerModuleCallBack; - - constructor(registry: interfaces.ContainerModuleCallBack) { - this.id = Generator.GenAutoIncrementId(); - this.registry = registry; - } -} diff --git a/packages/vrender-core/src/common/inversify/index.ts b/packages/vrender-core/src/common/inversify/index.ts deleted file mode 100644 index f1081a318..000000000 --- a/packages/vrender-core/src/common/inversify/index.ts +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 该文件夹下所有文件来源于inversify - * https://github.com/inversify/InversifyJS - * The MIT License (MIT) - -Copyright (c) 2015-2017 Remo H. Jansen - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - */ - -export { ContainerModule } from './cotainer-module'; -export { inject } from './annotation/inject'; -export { multiInject } from './annotation/multi_inject'; -export { injectable } from './annotation/injectable'; -export { named } from './annotation/named'; -export { Container } from './container'; -// export { postConstruct } from './annotation/post_construct'; -export * from './interfaces'; diff --git a/packages/vrender-core/src/common/inversify/interfaces.ts b/packages/vrender-core/src/common/inversify/interfaces.ts deleted file mode 100644 index 043f8ac31..000000000 --- a/packages/vrender-core/src/common/inversify/interfaces.ts +++ /dev/null @@ -1,360 +0,0 @@ -// @ts-nocheck -/* eslint-disable */ -import { FactoryType } from '../inversify-lite/utils/factory_type'; - -export namespace interfaces { - export type DynamicValue = (context: interfaces.Context) => T; - export type ContainerResolution = T | Promise | (T | Promise)[]; - - export type BindingScope = 'Singleton' | 'Transient' | 'Request'; - - export type BindingType = - | 'ConstantValue' - | 'Constructor' - | 'DynamicValue' - | 'Factory' - | 'Function' - | 'Instance' - | 'Invalid' - | 'Provider'; - - export type TargetType = 'ConstructorArgument' | 'ClassProperty' | 'Variable'; - - export interface BindingScopeEnum { - Singleton: interfaces.BindingScope; - Transient: interfaces.BindingScope; - } - - export interface BindingTypeEnum { - ConstantValue: interfaces.BindingType; - Constructor: interfaces.BindingType; - DynamicValue: interfaces.BindingType; - Factory: interfaces.BindingType; - Function: interfaces.BindingType; - Instance: interfaces.BindingType; - Invalid: interfaces.BindingType; - Provider: interfaces.BindingType; - } - - export interface TargetTypeEnum { - ConstructorArgument: interfaces.TargetType; - ClassProperty: interfaces.TargetType; - Variable: interfaces.TargetType; - } - - export type Newable = new (...args: any[]) => T; - - export type Instance = T & Record void>; - - export interface Abstract { - prototype: T; - } - - export type ServiceIdentifier = string | symbol | Newable | Abstract; - - export interface Clonable { - clone(): T; - } - - export type BindingActivation = (context: interfaces.Context, injectable: T) => T | Promise; - - export type BindingDeactivation = (injectable: T) => void | Promise; - - export interface Binding extends Clonable> { - id: number; - moduleId: ContainerModuleBase['id']; - activated: boolean; - serviceIdentifier: ServiceIdentifier; - constraint: ConstraintFunction; - dynamicValue: DynamicValue | null; - scope: BindingScope; - type: BindingType; - implementationType: Newable | TActivated | null; - factory: FactoryCreator | null; - provider: ProviderCreator | null; - // onActivation: BindingActivation | null; - // onDeactivation: BindingDeactivation | null; - cache: null | TActivated | Promise; - } - - export type SimpleFactory = (...args: U) => T; - - export type MultiFactory = ( - ...args: U - ) => SimpleFactory; - - export type Factory = - | SimpleFactory - | MultiFactory; - - export type FactoryCreator = ( - context: Context - ) => Factory; - - export type AutoNamedFactory = SimpleFactory; - - export type AutoFactory = SimpleFactory; - - export type FactoryTypeFunction = (context: interfaces.Context) => T | Promise; - - export interface FactoryDetails { - factoryType: FactoryType; - factory: FactoryTypeFunction | null; - } - - export type Provider = (...args: any[]) => ((...args: any[]) => Promise) | Promise; - - export type ProviderCreator = (context: Context) => Provider; - - export interface NextArgs { - avoidConstraints: boolean; - contextInterceptor: (contexts: Context) => Context; - isMultiInject: boolean; - targetType: TargetType; - serviceIdentifier: interfaces.ServiceIdentifier; - key?: string | number | symbol | undefined; - value?: unknown; - } - - export type Next = (args: NextArgs) => unknown | unknown[]; - - export type Middleware = (next: Next) => Next; - - export type ContextInterceptor = (context: interfaces.Context) => interfaces.Context; - - export interface Context { - id: number; - container: Container; - plan: Plan; - currentRequest: Request; - addPlan(plan: Plan): void; - setCurrentRequest(request: Request): void; - } - - export type MetadataOrMetadataArray = Metadata | Metadata[]; - - export interface Metadata { - key: string | number | symbol; - value: TValue; - } - - export interface Plan { - parentContext: Context; - rootRequest: Request; - } - - export interface QueryableString { - // startsWith(searchString: string): boolean; - // endsWith(searchString: string): boolean; - contains(searchString: string): boolean; - equals(compareString: string): boolean; - value(): string; - } - - export type ResolveRequestHandler = (request: interfaces.Request) => unknown; - - export type RequestScope = Map; - - export interface Request { - id: number; - serviceIdentifier: ServiceIdentifier; - parentContext: Context; - parentRequest: Request | null; - childRequests: Request[]; - target: Target; - bindings: Binding[]; - requestScope: RequestScope | null; - addChildRequest( - serviceIdentifier: ServiceIdentifier, - bindings: Binding | Binding[], - target: Target - ): Request; - } - - export interface Target { - id: number; - serviceIdentifier: ServiceIdentifier; - type: TargetType; - name: QueryableString; - identifier: string | symbol; - metadata: Metadata[]; - getNamedTag(): interfaces.Metadata | null; - getCustomTags(): interfaces.Metadata[] | null; - hasTag(key: string | number | symbol): boolean; - isArray(): boolean; - matchesArray(name: interfaces.ServiceIdentifier): boolean; - isNamed(): boolean; - isTagged(): boolean; - isOptional(): boolean; - matchesNamedTag(name: string): boolean; - matchesTag(key: string | number | symbol): (value: unknown) => boolean; - } - - export interface ContainerOptions { - autoBindInjectable?: boolean; - defaultScope?: BindingScope | undefined; - skipBaseClassChecks?: boolean; - } - - export interface Container { - id: number; - parent: Container | null; - options: ContainerOptions; - bind(serviceIdentifier: ServiceIdentifier): BindingToSyntax; - rebind(serviceIdentifier: interfaces.ServiceIdentifier): interfaces.BindingToSyntax; - // rebindAsync(serviceIdentifier: interfaces.ServiceIdentifier): Promise>; - unbind(serviceIdentifier: ServiceIdentifier): void; - // unbindAsync(serviceIdentifier: interfaces.ServiceIdentifier): Promise; - unbindAll(): void; - // unbindAllAsync(): Promise; - isBound(serviceIdentifier: ServiceIdentifier): boolean; - isCurrentBound(serviceIdentifier: ServiceIdentifier): boolean; - isBoundNamed(serviceIdentifier: ServiceIdentifier, named: string | number | symbol): boolean; - isBoundTagged(serviceIdentifier: ServiceIdentifier, key: string | number | symbol, value: unknown): boolean; - get(serviceIdentifier: ServiceIdentifier): T; - getNamed(serviceIdentifier: ServiceIdentifier, named: string | number | symbol): T; - getTagged(serviceIdentifier: ServiceIdentifier, key: string | number | symbol, value: unknown): T; - getAll(serviceIdentifier: ServiceIdentifier): T[]; - getAllTagged(serviceIdentifier: ServiceIdentifier, key: string | number | symbol, value: unknown): T[]; - getAllNamed(serviceIdentifier: ServiceIdentifier, named: string | number | symbol): T[]; - getAsync(serviceIdentifier: ServiceIdentifier): Promise; - // getNamedAsync(serviceIdentifier: ServiceIdentifier, named: string | number | symbol): Promise; - // getTaggedAsync( - // serviceIdentifier: ServiceIdentifier, - // key: string | number | symbol, - // value: unknown - // ): Promise; - // getAllAsync(serviceIdentifier: ServiceIdentifier): Promise; - // getAllTaggedAsync( - // serviceIdentifier: ServiceIdentifier, - // key: string | number | symbol, - // value: unknown - // ): Promise; - // getAllNamedAsync(serviceIdentifier: ServiceIdentifier, named: string | number | symbol): Promise; - // onActivation(serviceIdentifier: ServiceIdentifier, onActivation: BindingActivation): void; - // onDeactivation(serviceIdentifier: ServiceIdentifier, onDeactivation: BindingDeactivation): void; - resolve(constructorFunction: interfaces.Newable): T; - load(...modules: ContainerModule[]): void; - // loadAsync(...modules: AsyncContainerModule[]): Promise; - unload(...modules: ContainerModuleBase[]): void; - // unloadAsync(...modules: ContainerModuleBase[]): Promise; - applyCustomMetadataReader(metadataReader: MetadataReader): void; - // applyMiddleware(...middleware: Middleware[]): void; - // snapshot(): void; - // restore(): void; - // createChild(): Container; - } - - export type Bind = (serviceIdentifier: ServiceIdentifier) => BindingToSyntax; - - export type Rebind = (serviceIdentifier: ServiceIdentifier) => BindingToSyntax; - - export type Unbind = (serviceIdentifier: ServiceIdentifier) => void; - - export type UnbindAsync = (serviceIdentifier: ServiceIdentifier) => Promise; - - export type IsBound = (serviceIdentifier: ServiceIdentifier) => boolean; - - export interface ContainerModuleBase { - id: number; - } - - export interface ContainerModule extends ContainerModuleBase { - registry: ContainerModuleCallBack; - } - - export interface ModuleActivationHandlers { - onActivations: Lookup>; - onDeactivations: Lookup>; - } - - // export interface ModuleActivationStore extends Clonable { - // addDeactivation( - // moduleId: ContainerModuleBase['id'], - // serviceIdentifier: ServiceIdentifier, - // onDeactivation: interfaces.BindingDeactivation - // ): void; - // addActivation( - // moduleId: ContainerModuleBase['id'], - // serviceIdentifier: ServiceIdentifier, - // onActivation: interfaces.BindingActivation - // ): void; - // remove(moduleId: ContainerModuleBase['id']): ModuleActivationHandlers; - // } - - export type ContainerModuleCallBack = ( - bind: interfaces.Bind, - unbind: interfaces.Unbind, - isBound: interfaces.IsBound, - rebind: interfaces.Rebind - // unbindAsync: interfaces.UnbindAsync, - // onActivation: interfaces.Container['onActivation'], - // onDeactivation: interfaces.Container['onDeactivation'] - ) => void; - - // export interface ContainerSnapshot { - // bindings: Lookup>; - // activations: Lookup>; - // deactivations: Lookup>; - // middleware: Next | null; - // moduleActivationStore: interfaces.ModuleActivationStore; - // } - - export interface Lookup extends Clonable> { - add(serviceIdentifier: ServiceIdentifier, value: T): void; - getMap(): Map; - get(serviceIdentifier: ServiceIdentifier): T[]; - remove(serviceIdentifier: interfaces.ServiceIdentifier): void; - removeByCondition(condition: (item: T) => boolean): T[]; - removeIntersection(lookup: interfaces.Lookup): void; - hasKey(serviceIdentifier: ServiceIdentifier): boolean; - clone(): Lookup; - traverse(func: (key: interfaces.ServiceIdentifier, value: T[]) => void): void; - } - - export interface BindingOnSyntax { - // onActivation(fn: (context: Context, injectable: T) => T | Promise): BindingWhenSyntax; - // onDeactivation(fn: (injectable: T) => void | Promise): BindingWhenSyntax; - } - - // export interface BindingWhenOnSyntax extends BindingWhenSyntax, BindingOnSyntax {} - - export interface BindingInSyntax { - inSingletonScope(): BindingInSyntax; - inTransientScope(): BindingInSyntax; - whenTargetNamed(name: string | number | symbol): BindingOnSyntax; - // inRequestScope(): BindingInSyntax; - } - - export interface BindingInWhenOnSyntax extends BindingInSyntax, BindingInSyntax {} - - export interface BindingToSyntax { - to(constructor: Newable): BindingInWhenOnSyntax; - toSelf(): BindingInWhenOnSyntax; - toConstantValue(value: T): BindingInWhenOnSyntax; - toDynamicValue(func: DynamicValue): BindingInWhenOnSyntax; - toFactory( - factory: FactoryCreator - ): BindingInWhenOnSyntax; - toService(service: ServiceIdentifier): void; - } - - export interface ConstraintFunction { - metaData?: Metadata; - (request: Request | null): boolean; - } - - export interface MetadataReader { - getConstructorMetadata(constructorFunc: NewableFunction): ConstructorMetadata; - getPropertiesMetadata(constructorFunc: NewableFunction): MetadataMap; - } - - export interface MetadataMap { - [propertyNameOrArgumentIndex: string | symbol]: Metadata[]; - } - - export interface ConstructorMetadata { - compilerGeneratedMetadata: NewableFunction[] | undefined; - userGeneratedMetadata: MetadataMap; - } -} diff --git a/packages/vrender-core/src/common/inversify/literal_types.ts b/packages/vrender-core/src/common/inversify/literal_types.ts deleted file mode 100644 index 8247bbf17..000000000 --- a/packages/vrender-core/src/common/inversify/literal_types.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { interfaces } from './interfaces'; - -const BindingScopeEnum: interfaces.BindingScopeEnum = { - Singleton: 'Singleton', - Transient: 'Transient' -}; - -const BindingTypeEnum: interfaces.BindingTypeEnum = { - ConstantValue: 'ConstantValue', - Constructor: 'Constructor', - DynamicValue: 'DynamicValue', - Factory: 'Factory', - Function: 'Function', - Instance: 'Instance', - Invalid: 'Invalid', - Provider: 'Provider' -}; - -const TargetTypeEnum: interfaces.TargetTypeEnum = { - ClassProperty: 'ClassProperty', - ConstructorArgument: 'ConstructorArgument', - Variable: 'Variable' -}; - -export { BindingScopeEnum, BindingTypeEnum, TargetTypeEnum }; diff --git a/packages/vrender-core/src/common/inversify/meta-data.ts b/packages/vrender-core/src/common/inversify/meta-data.ts deleted file mode 100644 index 3d7d11683..000000000 --- a/packages/vrender-core/src/common/inversify/meta-data.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { NAMED_TAG } from './metadata_keys'; - -export class Metadata { - key: string | number | symbol; - value: unknown; - - constructor(key: string | number | symbol, value: unknown) { - this.key = key; - this.value = value; - } - - toString() { - if (this.key === NAMED_TAG) { - return `named: ${String(this.value).toString()} `; - } - return `tagged: { key:${this.key.toString()}, value: ${String(this.value)} }`; - } -} diff --git a/packages/vrender-core/src/common/inversify/metadata_keys.ts b/packages/vrender-core/src/common/inversify/metadata_keys.ts deleted file mode 100644 index 678316c06..000000000 --- a/packages/vrender-core/src/common/inversify/metadata_keys.ts +++ /dev/null @@ -1,38 +0,0 @@ -// Used for named bindings -export const NAMED_TAG = 'named'; - -// The name of the target at design time -export const NAME_TAG = 'name'; - -// The for unmanaged injections (in base classes when using inheritance) -export const UNMANAGED_TAG = 'unmanaged'; - -// The for optional injections -export const OPTIONAL_TAG = 'optional'; - -// The type of the binding at design time -export const INJECT_TAG = 'inject'; - -// The type of the binding at design type for multi-injections -export const MULTI_INJECT_TAG = 'multi_inject'; - -// used to store constructor arguments tags -export const TAGGED = 'inversify:tagged'; - -// used to store class properties tags -export const TAGGED_PROP = 'inversify:tagged_props'; - -// used to store types to be injected -export const PARAM_TYPES = 'inversify:paramtypes'; - -// used to access design time types -export const DESIGN_PARAM_TYPES = 'design:paramtypes'; - -// used to identify preDestroy functions -export const PRE_DESTROY = 'pre_destroy'; - -function getNonCustomTagKeys(): string[] { - return [INJECT_TAG, MULTI_INJECT_TAG, NAME_TAG, UNMANAGED_TAG, NAMED_TAG, OPTIONAL_TAG]; -} - -export const NON_CUSTOM_TAG_KEYS: string[] = getNonCustomTagKeys(); diff --git a/packages/vrender-core/src/common/inversify/metadata_reader.ts b/packages/vrender-core/src/common/inversify/metadata_reader.ts deleted file mode 100644 index e44d1e319..000000000 --- a/packages/vrender-core/src/common/inversify/metadata_reader.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { interfaces } from './interfaces'; -import Reflect from '../Reflect-metadata'; -import { PARAM_TYPES, TAGGED, TAGGED_PROP } from './metadata_keys'; - -class MetadataReader implements interfaces.MetadataReader { - getConstructorMetadata(constructorFunc: NewableFunction): interfaces.ConstructorMetadata { - // TypeScript compiler generated annotations - const compilerGeneratedMetadata = (Reflect as any).getMetadata(PARAM_TYPES, constructorFunc); - - // User generated constructor annotations - const userGeneratedMetadata = (Reflect as any).getMetadata(TAGGED, constructorFunc); - - return { - compilerGeneratedMetadata, - userGeneratedMetadata: userGeneratedMetadata || {} - }; - } - - getPropertiesMetadata(constructorFunc: NewableFunction): interfaces.MetadataMap { - // // User generated properties annotations - // const userGeneratedMetadata = (Reflect as any).getMetadata(TAGGED_PROP, constructorFunc) || []; - // return userGeneratedMetadata; - throw new Error('暂未实现'); - } -} - -export { MetadataReader }; diff --git a/packages/vrender-core/src/common/inversify/syntax/binding_in_syntax.ts b/packages/vrender-core/src/common/inversify/syntax/binding_in_syntax.ts deleted file mode 100644 index 5c177bc92..000000000 --- a/packages/vrender-core/src/common/inversify/syntax/binding_in_syntax.ts +++ /dev/null @@ -1,34 +0,0 @@ -import type { interfaces } from '../interfaces'; -import { BindingScopeEnum } from '../literal_types'; -import { namedConstraint } from './constraint_helpers'; - -class BindingInSyntax implements interfaces.BindingInSyntax { - private _binding: interfaces.Binding; - - constructor(binding: interfaces.Binding) { - this._binding = binding; - } - - inRequestScope(): interfaces.BindingInSyntax { - // this._binding.scope = BindingScopeEnum.Request; - // return new BindingWhenOnSyntax(this._binding); - throw new Error('暂未实现'); - } - - inSingletonScope(): interfaces.BindingInSyntax { - this._binding.scope = BindingScopeEnum.Singleton; - return this; - } - - inTransientScope(): interfaces.BindingInSyntax { - this._binding.scope = BindingScopeEnum.Transient; - return this; - } - - whenTargetNamed(name: string | number | symbol): interfaces.BindingOnSyntax { - this._binding.constraint = namedConstraint(name); - return this; - } -} - -export { BindingInSyntax }; diff --git a/packages/vrender-core/src/common/inversify/syntax/binding_to_syntax.ts b/packages/vrender-core/src/common/inversify/syntax/binding_to_syntax.ts deleted file mode 100644 index 55765ef01..000000000 --- a/packages/vrender-core/src/common/inversify/syntax/binding_to_syntax.ts +++ /dev/null @@ -1,55 +0,0 @@ -import type { interfaces } from '../interfaces'; -import { BindingScopeEnum, BindingTypeEnum } from '../literal_types'; -import { BindingInSyntax } from './binding_in_syntax'; - -class BindingToSyntax implements interfaces.BindingToSyntax { - // TODO: Implement an internal type `_BindingToSyntax` wherein this member - // can be public. Let `BindingToSyntax` be the presentational type that - // depends on it, and does not expose this member as public. - private _binding: interfaces.Binding; - - constructor(binding: interfaces.Binding) { - this._binding = binding; - } - - to(constructor: interfaces.Newable): interfaces.BindingInWhenOnSyntax { - this._binding.type = BindingTypeEnum.Instance; - this._binding.implementationType = constructor; - return new BindingInSyntax(this._binding); - } - - toSelf(): interfaces.BindingInWhenOnSyntax { - const self = this._binding.serviceIdentifier; - return this.to(self as any); - } - - toDynamicValue(func: interfaces.DynamicValue): interfaces.BindingInWhenOnSyntax { - this._binding.type = BindingTypeEnum.DynamicValue; - this._binding.cache = null; - this._binding.dynamicValue = func; - this._binding.implementationType = null; - return new BindingInSyntax(this._binding); - } - - toConstantValue(value: T): interfaces.BindingInSyntax { - this._binding.type = BindingTypeEnum.ConstantValue; - this._binding.cache = value; - this._binding.dynamicValue = null; - this._binding.implementationType = null; - this._binding.scope = BindingScopeEnum.Singleton; - return new BindingInSyntax(this._binding); - } - - toFactory(factory: interfaces.FactoryCreator): interfaces.BindingInWhenOnSyntax { - this._binding.type = BindingTypeEnum.Factory; - this._binding.factory = factory; - this._binding.scope = BindingScopeEnum.Singleton; - return new BindingInSyntax(this._binding); - } - - toService(service: string | symbol | interfaces.Newable | interfaces.Abstract): void { - this.toDynamicValue(context => context.container.get(service)); - } -} - -export { BindingToSyntax }; diff --git a/packages/vrender-core/src/common/inversify/syntax/constraint_helpers.ts b/packages/vrender-core/src/common/inversify/syntax/constraint_helpers.ts deleted file mode 100644 index 62806dd94..000000000 --- a/packages/vrender-core/src/common/inversify/syntax/constraint_helpers.ts +++ /dev/null @@ -1,31 +0,0 @@ -import type { interfaces } from '../interfaces'; -import { Metadata } from '../meta-data'; -import { NAMED_TAG } from '../metadata_keys'; - -const taggedConstraint = (key: string | number | symbol) => (value: unknown) => { - const constraint: interfaces.ConstraintFunction = (request: any) => { - if (request == null) { - return false; - } - if (request.key === key && request.value === value) { - return true; - } - if (request.constructorArgsMetadata == null) { - return false; - } - const constructorArgsMetadata = request.constructorArgsMetadata; - for (let i = 0; i < constructorArgsMetadata.length; i++) { - if (constructorArgsMetadata[i].key === key && constructorArgsMetadata[i].value === value) { - return true; - } - } - return false; - }; - // request !== null && request.target !== null && request.target.matchesTag(key)(value); - - constraint.metaData = new Metadata(key, value); - - return constraint; -}; - -export const namedConstraint = taggedConstraint(NAMED_TAG); diff --git a/packages/vrender-core/src/common/registry/contribution-registry.ts b/packages/vrender-core/src/common/registry/contribution-registry.ts new file mode 100644 index 000000000..15ce784f1 --- /dev/null +++ b/packages/vrender-core/src/common/registry/contribution-registry.ts @@ -0,0 +1,142 @@ +/** + * ContributionRegistry - 贡献/扩展注册表 + * + * 替代 inversify 的 ContributionProvider + container.getAll() 机制 + * 支持按 token 注册多个实现,获取时返回列表 + */ +import type { ServiceIdentifier } from './types'; + +export interface ContributionItem { + impl: T; + order?: number; // 可选排序优先级,数字越小越靠前 +} + +export class ContributionRegistry { + private contributions: Map = new Map(); + + /** + * 注册贡献(追加到列表) + * @param id 贡献标识符 + * @param impl 贡献实现 + * @param order 可选排序优先级 + */ + register(id: ServiceIdentifier, impl: T, order?: number): void { + let list = this.contributions.get(id); + if (!list) { + list = []; + this.contributions.set(id, list); + } + list.push({ impl, order }); + } + + /** + * 批量注册贡献 + */ + registerAll(id: ServiceIdentifier, items: Array<{ impl: T; order?: number }>): void { + for (const item of items) { + this.register(id, item.impl, item.order); + } + } + + /** + * 获取所有贡献(按 order 排序) + */ + get(id: ServiceIdentifier): T[] { + const list = this.contributions.get(id); + if (!list || list.length === 0) { + return []; + } + + // 按 order 排序(order 越小越靠前,undefined 排最后) + const sorted = [...list].sort((a, b) => { + const orderA = a.order ?? Number.MAX_SAFE_INTEGER; + const orderB = b.order ?? Number.MAX_SAFE_INTEGER; + return orderA - orderB; + }); + + return sorted.map(item => item.impl); + } + + /** + * 获取所有贡献(不排序,保持注册顺序) + */ + getUnsorted(id: ServiceIdentifier): T[] { + const list = this.contributions.get(id); + if (!list) { + return []; + } + return list.map(item => item.impl); + } + + /** + * 检查是否有贡献 + */ + has(id: ServiceIdentifier): boolean { + const list = this.contributions.get(id); + return !!list && list.length > 0; + } + + /** + * 获取贡献数量 + */ + count(id: ServiceIdentifier): number { + const list = this.contributions.get(id); + return list ? list.length : 0; + } + + /** + * 移除某个贡献 + */ + unregister(id: ServiceIdentifier, impl: T): boolean { + const list = this.contributions.get(id); + if (!list) { + return false; + } + const index = list.findIndex(item => item.impl === impl); + if (index !== -1) { + list.splice(index, 1); + return true; + } + return false; + } + + /** + * 清空某个 token 的所有贡献 + */ + clear(id: ServiceIdentifier): void { + this.contributions.delete(id); + } + + /** + * 清空所有贡献 + */ + clearAll(): void { + this.contributions.clear(); + } + + /** + * 获取所有已注册的贡献标识符 + */ + keys(): IterableIterator { + return this.contributions.keys(); + } + + /** + * 刷新某个 token 的贡献缓存(保留接口兼容) + */ + refresh(id: ServiceIdentifier): void { + // 当前实现不需要刷新,保留接口兼容 + } + + /** + * 刷新所有贡献缓存(保留接口兼容) + */ + refreshAll(): void { + // 当前实现不需要刷新,保留接口兼容 + } +} + +/** + * 全局贡献注册表实例 + */ +export const contributionRegistry = new ContributionRegistry(); diff --git a/packages/vrender-core/src/common/registry/index.ts b/packages/vrender-core/src/common/registry/index.ts new file mode 100644 index 000000000..31b993931 --- /dev/null +++ b/packages/vrender-core/src/common/registry/index.ts @@ -0,0 +1,8 @@ +/** + * 导出注册表相关的所有 API + */ +export { ServiceRegistry, serviceRegistry } from './service-registry'; +export type { ServiceFactory } from './service-registry'; +export { ContributionRegistry, contributionRegistry } from './contribution-registry'; +export type { ContributionItem } from './contribution-registry'; +export type { ServiceIdentifier } from './types'; diff --git a/packages/vrender-core/src/common/registry/service-registry.ts b/packages/vrender-core/src/common/registry/service-registry.ts new file mode 100644 index 000000000..83d7d6529 --- /dev/null +++ b/packages/vrender-core/src/common/registry/service-registry.ts @@ -0,0 +1,127 @@ +/** + * ServiceRegistry - 服务注册表 + * + * 管理单例服务与工厂服务,替代 inversify 的 container.get() 机制 + * - 单例服务:全局唯一实例(如 global、graphicService) + * - 工厂服务:每次获取都创建新实例的工厂函数(如 windowFactory、renderServiceFactory) + */ +import type { ServiceIdentifier } from './types'; + +export type ServiceFactory = (...args: any[]) => T; + +interface ServiceBinding { + type: 'singleton' | 'factory'; + value?: T; // singleton 的缓存实例 + factory?: ServiceFactory; // factory 函数 + creator?: ServiceFactory; // singleton 的创建函数(延迟创建) +} + +export class ServiceRegistry { + private bindings: Map = new Map(); + + /** + * 注册单例服务(立即提供实例) + */ + registerSingleton(id: ServiceIdentifier, instance: T): void { + this.bindings.set(id, { + type: 'singleton', + value: instance + }); + } + + /** + * 注册单例服务(延迟创建) + */ + registerSingletonFactory(id: ServiceIdentifier, creator: ServiceFactory): void { + this.bindings.set(id, { + type: 'singleton', + creator + }); + } + + /** + * 注册工厂服务(每次调用都创建新实例) + */ + registerFactory(id: ServiceIdentifier, factory: ServiceFactory): void { + this.bindings.set(id, { + type: 'factory', + factory + }); + } + + /** + * 获取单例服务 + */ + get(id: ServiceIdentifier): T | undefined { + const binding = this.bindings.get(id); + if (!binding) { + return undefined; + } + + if (binding.type === 'singleton') { + // 延迟创建单例 + if (binding.value === undefined && binding.creator) { + binding.value = binding.creator(); + } + return binding.value as T; + } + + // factory 类型不应该通过 get 获取,使用 getFactory + return undefined; + } + + /** + * 获取工厂函数 + */ + getFactory(id: ServiceIdentifier): ServiceFactory | undefined { + const binding = this.bindings.get(id); + if (!binding || binding.type !== 'factory') { + return undefined; + } + return binding.factory as ServiceFactory; + } + + /** + * 调用工厂创建实例 + */ + createInstance(id: ServiceIdentifier, ...args: any[]): T | undefined { + const factory = this.getFactory(id); + if (factory) { + return factory(...args); + } + return undefined; + } + + /** + * 检查是否已注册 + */ + has(id: ServiceIdentifier): boolean { + return this.bindings.has(id); + } + + /** + * 移除注册 + */ + unregister(id: ServiceIdentifier): boolean { + return this.bindings.delete(id); + } + + /** + * 清空所有注册 + */ + clear(): void { + this.bindings.clear(); + } + + /** + * 获取所有已注册的服务标识符 + */ + keys(): IterableIterator { + return this.bindings.keys(); + } +} + +/** + * 全局服务注册表实例 + */ +export const serviceRegistry = new ServiceRegistry(); diff --git a/packages/vrender-core/src/common/registry/types.ts b/packages/vrender-core/src/common/registry/types.ts new file mode 100644 index 000000000..aa7fd8934 --- /dev/null +++ b/packages/vrender-core/src/common/registry/types.ts @@ -0,0 +1,5 @@ +/** + * 服务标识符类型 - 用于标识服务/贡献的唯一 key + * 支持 Symbol、字符串、类构造函数 + */ +export type ServiceIdentifier = symbol | string | (new (...args: any[]) => T); diff --git a/packages/vrender-core/src/common/service-factory.ts b/packages/vrender-core/src/common/service-factory.ts new file mode 100644 index 000000000..39cc9500e --- /dev/null +++ b/packages/vrender-core/src/common/service-factory.ts @@ -0,0 +1,162 @@ +/** + * 服务工厂模块 - 创建不依赖装饰器的服务实例 + * + * 这些工厂函数显式传递依赖,替代 @inject/@multiInject/@named 装饰器 + */ +import type { application } from '../application'; +import { serviceRegistry, contributionRegistry } from './registry'; + +// ============ 类型定义 ============ + +export interface IServiceContext { + services: typeof serviceRegistry; + contributions: typeof contributionRegistry; + application: typeof application; +} + +// ============ 服务工厂 ============ + +/** + * 创建 RenderService 实例 + * 替代 @inject(DrawContribution) 装饰器 + */ +declare let require: any; +export function createRenderService() { + const { DefaultRenderService } = require('../render/render-service'); + const { DrawContribution } = require('../render/contributions/render/symbol'); + + // 获取 DrawContribution 实例 + const drawContribution = createDrawContribution(); + + return new DefaultRenderService(drawContribution); +} + +/** + * 创建 DrawContribution 实例 + * 替代 @multiInject(GraphicRender) 和 @inject(ContributionProvider) @named(DrawItemInterceptor) 装饰器 + */ +export function createDrawContribution() { + const { DefaultDrawContribution } = require('../render/contributions/render/draw-contribution'); + const { GraphicRender } = require('../render/contributions/render/symbol'); + const { DrawItemInterceptor } = require('../render/contributions/render/draw-interceptor'); + + // 获取所有 GraphicRender 贡献 + const graphicRenders = contributionRegistry.get(GraphicRender); + + // 创建 DrawItemInterceptor 的 ContributionProvider 兼容对象 + const drawItemInterceptorProvider = { + getContributions: () => contributionRegistry.get(DrawItemInterceptor) + }; + + return new DefaultDrawContribution(graphicRenders, drawItemInterceptorProvider); +} + +/** + * 创建 IncrementalDrawContribution 实例 + */ +export function createIncrementalDrawContribution() { + const { + DefaultIncrementalDrawContribution + } = require('../render/contributions/render/incremental-draw-contribution'); + const { GraphicRender } = require('../render/contributions/render/symbol'); + const { DrawItemInterceptor } = require('../render/contributions/render/draw-interceptor'); + const { DefaultIncrementalCanvasLineRender } = require('../render/contributions/render/incremental-line-render'); + const { DefaultIncrementalCanvasAreaRender } = require('../render/contributions/render/incremental-area-render'); + + // 获取所有 GraphicRender 贡献 + const graphicRenders = contributionRegistry.get(GraphicRender); + + // 获取特定的 line/area render + const lineRender = + serviceRegistry.get(DefaultIncrementalCanvasLineRender) || new DefaultIncrementalCanvasLineRender(); + const areaRender = + serviceRegistry.get(DefaultIncrementalCanvasAreaRender) || new DefaultIncrementalCanvasAreaRender(); + + // 创建 DrawItemInterceptor 的 ContributionProvider 兼容对象 + const drawItemInterceptorProvider = { + getContributions: () => contributionRegistry.get(DrawItemInterceptor) + }; + + return new DefaultIncrementalDrawContribution(graphicRenders, lineRender, areaRender, drawItemInterceptorProvider); +} + +/** + * 创建 PluginService 实例 + * 替代 @inject(ContributionProvider) @named(AutoEnablePlugins) 装饰器 + */ +export function createPluginService() { + const { DefaultPluginService } = require('../plugins/plugin-service'); + const { AutoEnablePlugins } = require('../plugins/constants'); + + // 创建 AutoEnablePlugins 的 ContributionProvider 兼容对象 + const autoEnablePluginsProvider = { + getContributions: () => contributionRegistry.get(AutoEnablePlugins) + }; + + return new DefaultPluginService(autoEnablePluginsProvider); +} + +/** + * 创建 PickerService 实例 + */ +export function createPickerService() { + const { DefaultGlobalPickerService } = require('../picker/global-picker-service'); + return new DefaultGlobalPickerService(); +} + +/** + * 创建 Global 实例 + * 替代 @inject(ContributionProvider) @named(EnvContribution) 装饰器 + */ +export function createGlobal() { + const { DefaultGlobal } = require('../core/global'); + return new DefaultGlobal(); +} + +/** + * 创建 GraphicUtil 实例 + * 替代 @inject(ContributionProvider) @named(TextMeasureContribution) 装饰器 + */ +export function createGraphicUtil() { + const { DefaultGraphicUtil } = require('../core/graphic-utils'); + const { TextMeasureContribution } = require('../core/contributions/textMeasure/textMeasure-contribution'); + + // 创建 TextMeasureContribution 的 ContributionProvider 兼容对象 + const textMeasureProvider = { + getContributions: () => contributionRegistry.get(TextMeasureContribution) + }; + + return new DefaultGraphicUtil(textMeasureProvider); +} + +/** + * 创建 LayerService 实例 + */ +export function createLayerService() { + const { DefaultLayerService } = require('../core/layer-service'); + return new DefaultLayerService(); +} + +/** + * 创建 TransformUtil 实例 + */ +export function createTransformUtil() { + const { DefaultTransformUtil } = require('../core/graphic-utils'); + return new DefaultTransformUtil(); +} + +/** + * 创建 GraphicService 实例 + */ +export function createGraphicService() { + const { DefaultGraphicService } = require('../graphic/graphic-service/graphic-service'); + return new DefaultGraphicService(); +} + +/** + * 创建 Window 实例 + */ +export function createWindow() { + const { DefaultWindow } = require('../core/window'); + return new DefaultWindow(); +} diff --git a/packages/vrender-core/src/common/service-registry.ts b/packages/vrender-core/src/common/service-registry.ts new file mode 100644 index 000000000..4295f6902 --- /dev/null +++ b/packages/vrender-core/src/common/service-registry.ts @@ -0,0 +1,94 @@ +/** + * ServiceRegistry - 服务注册表 + * 替代 inversify Container 的单例/工厂管理能力 + */ +import type { ServiceIdentifier } from './types'; + +export type ServiceFactory = () => T; + +interface ServiceBinding { + type: 'singleton' | 'factory'; + instance?: T; + factory?: ServiceFactory; +} + +export class ServiceRegistry { + private bindings: Map, ServiceBinding> = new Map(); + + /** + * 注册单例服务 + */ + registerSingleton(id: ServiceIdentifier, instance: T): void { + this.bindings.set(id, { + type: 'singleton', + instance + }); + } + + /** + * 注册工厂服务(每次 get 返回新实例) + */ + registerFactory(id: ServiceIdentifier, factory: ServiceFactory): void { + this.bindings.set(id, { + type: 'factory', + factory + }); + } + + /** + * 注册延迟单例(首次 get 时创建并缓存) + */ + registerLazySingleton(id: ServiceIdentifier, factory: ServiceFactory): void { + const binding: ServiceBinding = { + type: 'singleton', + factory + }; + this.bindings.set(id, binding); + } + + /** + * 获取服务 + */ + get(id: ServiceIdentifier): T { + const binding = this.bindings.get(id); + if (!binding) { + throw new Error(`Service not found: ${String(id)}`); + } + + if (binding.type === 'singleton') { + if (binding.instance === undefined && binding.factory) { + binding.instance = binding.factory(); + } + return binding.instance as T; + } + + // factory type + if (!binding.factory) { + throw new Error(`Factory not found for service: ${String(id)}`); + } + return binding.factory(); + } + + /** + * 检查服务是否已注册 + */ + has(id: ServiceIdentifier): boolean { + return this.bindings.has(id); + } + + /** + * 移除服务 + */ + remove(id: ServiceIdentifier): void { + this.bindings.delete(id); + } + + /** + * 清空所有注册 + */ + clear(): void { + this.bindings.clear(); + } +} + +export const serviceRegistry = new ServiceRegistry(); diff --git a/packages/vrender-core/src/common/types.ts b/packages/vrender-core/src/common/types.ts new file mode 100644 index 000000000..79ab4700e --- /dev/null +++ b/packages/vrender-core/src/common/types.ts @@ -0,0 +1,9 @@ +/** + * 通用类型定义 + */ + +/** + * 服务标识符类型 - 用于在注册表中标识服务 + * 支持 Symbol、字符串、类构造函数 + */ +export type ServiceIdentifier = symbol | string | (new (...args: any[]) => T); diff --git a/packages/vrender-core/src/container.ts b/packages/vrender-core/src/container.ts deleted file mode 100644 index 8c921aecc..000000000 --- a/packages/vrender-core/src/container.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { Container } from './common/inversify-lite'; -export const container = new Container(); diff --git a/packages/vrender-core/src/core/contributions/env/base-contribution.ts b/packages/vrender-core/src/core/contributions/env/base-contribution.ts index 805ba7ca1..9dc839241 100644 --- a/packages/vrender-core/src/core/contributions/env/base-contribution.ts +++ b/packages/vrender-core/src/core/contributions/env/base-contribution.ts @@ -1,4 +1,3 @@ -import { injectable } from '../../../common/inversify-lite'; import type { ICanvasLike, EnvType, @@ -10,7 +9,6 @@ import type { import type { IBoundsLike } from '@visactor/vutils'; import { AABBBounds } from '@visactor/vutils'; -@injectable() export abstract class BaseEnvContribution implements IEnvContribution { type: EnvType; diff --git a/packages/vrender-core/src/core/contributions/env/modules.ts b/packages/vrender-core/src/core/contributions/env/modules.ts deleted file mode 100644 index 09b60ed81..000000000 --- a/packages/vrender-core/src/core/contributions/env/modules.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { ContainerModule } from '../../../common/inversify-lite'; -import { bindContributionProvider } from '../../../common/contribution-provider'; -import { EnvContribution } from '../../../constants'; - -export default new ContainerModule(bind => { - bindContributionProvider(bind, EnvContribution); -}); diff --git a/packages/vrender-core/src/core/contributions/layerHandler/canvas2d-contribution.ts b/packages/vrender-core/src/core/contributions/layerHandler/canvas2d-contribution.ts index 8fc8a6fc5..12c7793fe 100644 --- a/packages/vrender-core/src/core/contributions/layerHandler/canvas2d-contribution.ts +++ b/packages/vrender-core/src/core/contributions/layerHandler/canvas2d-contribution.ts @@ -1,4 +1,3 @@ -import { inject, injectable } from '../../../common/inversify-lite'; import { wrapCanvas } from '../../../canvas/util'; import type { IGlobal, @@ -17,7 +16,6 @@ import type { import type { IBounds } from '@visactor/vutils'; import { application } from '../../../application'; -@injectable() export class CanvasLayerHandlerContribution implements ILayerHandlerContribution { layer: ILayer; canvas: ICanvas; diff --git a/packages/vrender-core/src/core/contributions/layerHandler/empty-contribution.ts b/packages/vrender-core/src/core/contributions/layerHandler/empty-contribution.ts index ad1f55fc2..ba65e6584 100644 --- a/packages/vrender-core/src/core/contributions/layerHandler/empty-contribution.ts +++ b/packages/vrender-core/src/core/contributions/layerHandler/empty-contribution.ts @@ -1,4 +1,3 @@ -import { inject, injectable } from '../../../common/inversify-lite'; import type { IGlobal, IDrawToParams, @@ -14,7 +13,6 @@ import type { import type { IBounds } from '@visactor/vutils'; import { application } from '../../../application'; -@injectable() export class EmptyLayerHandlerContribution implements ILayerHandlerContribution { declare layer: ILayer; declare canvas: null; diff --git a/packages/vrender-core/src/core/contributions/layerHandler/modules.ts b/packages/vrender-core/src/core/contributions/layerHandler/modules.ts deleted file mode 100644 index af31e977d..000000000 --- a/packages/vrender-core/src/core/contributions/layerHandler/modules.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { ContainerModule } from '../../../common/inversify-lite'; -import { - // DynamicLayerHandlerContribution, - StaticLayerHandlerContribution - // VirtualLayerHandlerContribution -} from '../../constants'; -import { CanvasLayerHandlerContribution } from './canvas2d-contribution'; -// import { EmptyLayerHandlerContribution } from './empty-contribution'; -// import { OffscreenLayerHandlerContribution } from './offscreen2d-contribution'; - -export default new ContainerModule(bind => { - bind(CanvasLayerHandlerContribution).toSelf(); - // bind(OffscreenLayerHandlerContribution).toSelf(); - // bind(EmptyLayerHandlerContribution).toSelf(); - bind(StaticLayerHandlerContribution).toService(CanvasLayerHandlerContribution); - // bind(DynamicLayerHandlerContribution).toService(OffscreenLayerHandlerContribution); - // bind(VirtualLayerHandlerContribution).toService(EmptyLayerHandlerContribution); - // try { - // if (typeof OffscreenCanvas === 'function') { - // bind(LayerHandlerContribution).toService(OffscreenLayerHandlerContribution); - // } - // } catch (err) { - // bind(LayerHandlerContribution).toService(CanvasLayerHandlerContribution); - // } -}); diff --git a/packages/vrender-core/src/core/contributions/layerHandler/offscreen2d-contribution.ts b/packages/vrender-core/src/core/contributions/layerHandler/offscreen2d-contribution.ts index c3613934c..2ac1dd2af 100644 --- a/packages/vrender-core/src/core/contributions/layerHandler/offscreen2d-contribution.ts +++ b/packages/vrender-core/src/core/contributions/layerHandler/offscreen2d-contribution.ts @@ -1,4 +1,3 @@ -import { inject, injectable } from '../../../common/inversify-lite'; import { wrapCanvas } from '../../../canvas/util'; import type { IGlobal, @@ -16,7 +15,6 @@ import type { import type { IBoundsLike } from '@visactor/vutils'; import { application } from '../../../application'; -@injectable() export class OffscreenLayerHandlerContribution implements ILayerHandlerContribution { declare layer: ILayer; declare canvas: ICanvas; diff --git a/packages/vrender-core/src/core/contributions/modules.ts b/packages/vrender-core/src/core/contributions/modules.ts index 730bf10d7..b6407ce1b 100644 --- a/packages/vrender-core/src/core/contributions/modules.ts +++ b/packages/vrender-core/src/core/contributions/modules.ts @@ -1,10 +1,7 @@ -import type { Container } from '../../common/inversify-lite'; -import envModules from './env/modules'; -import textMeasureModules from './textMeasure/modules'; -import layerHandlerModules from './layerHandler/modules'; +// Registry-only stub; legacy container loader removed +// Legacy loader removed; no-op imports removed -export default function load(container: Container) { - container.load(envModules); - container.load(textMeasureModules); - container.load(layerHandlerModules); +// Legacy loader removed; no-op +export default function load() { + return; } diff --git a/packages/vrender-core/src/core/contributions/textMeasure/AtextMeasure.ts b/packages/vrender-core/src/core/contributions/textMeasure/AtextMeasure.ts index fc7025b2e..a06677611 100644 --- a/packages/vrender-core/src/core/contributions/textMeasure/AtextMeasure.ts +++ b/packages/vrender-core/src/core/contributions/textMeasure/AtextMeasure.ts @@ -1,4 +1,3 @@ -import { injectable } from '../../../common/inversify-lite'; import type { IGraphicUtil } from '../../../interface/core'; import type { ICanvas, IContext2d, EnvType } from '../../../interface'; import { MeasureModeEnum } from '../../../interface'; @@ -7,7 +6,6 @@ import { DefaultTextAttribute, DefaultTextStyle } from '../../../graphic/config' import { testLetter } from '../../../graphic/richtext/utils'; import { Logger } from '@visactor/vutils'; -@injectable() export class ATextMeasure implements ITextMeasure { id: string = 'ATextMeasure'; release: (...params: any) => void; diff --git a/packages/vrender-core/src/core/contributions/textMeasure/modules.ts b/packages/vrender-core/src/core/contributions/textMeasure/modules.ts deleted file mode 100644 index 8e532a2d9..000000000 --- a/packages/vrender-core/src/core/contributions/textMeasure/modules.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { ContainerModule } from '../../../common/inversify-lite'; -import { bindContributionProvider } from '../../../common/contribution-provider'; -import { DefaultTextMeasureContribution, TextMeasureContribution } from './textMeasure-contribution'; - -export default new ContainerModule(bind => { - bind(TextMeasureContribution).to(DefaultTextMeasureContribution).inSingletonScope(); - bindContributionProvider(bind, TextMeasureContribution); -}); diff --git a/packages/vrender-core/src/core/contributions/textMeasure/textMeasure-contribution.ts b/packages/vrender-core/src/core/contributions/textMeasure/textMeasure-contribution.ts index 0638ec51b..dc6c1f719 100644 --- a/packages/vrender-core/src/core/contributions/textMeasure/textMeasure-contribution.ts +++ b/packages/vrender-core/src/core/contributions/textMeasure/textMeasure-contribution.ts @@ -1,9 +1,7 @@ -import { injectable } from '../../../common/inversify-lite'; import { ATextMeasure } from './AtextMeasure'; export const TextMeasureContribution = Symbol.for('TextMeasureContribution'); -@injectable() export class DefaultTextMeasureContribution extends ATextMeasure { id: string = 'DefaultTextMeasureContribution'; } diff --git a/packages/vrender-core/src/core/contributions/window/base-contribution.ts b/packages/vrender-core/src/core/contributions/window/base-contribution.ts index c3e3846d7..249eb22b6 100644 --- a/packages/vrender-core/src/core/contributions/window/base-contribution.ts +++ b/packages/vrender-core/src/core/contributions/window/base-contribution.ts @@ -1,4 +1,3 @@ -import { injectable } from '../../../common/inversify-lite'; import { Generator } from '../../../common/generator'; import type { ICanvas, @@ -14,7 +13,6 @@ import { AABBBounds, Matrix, type IBounds, type IBoundsLike, type IMatrix } from type OnchangeCbType = (params?: { x?: number; y?: number; width?: number; height?: number }) => void; -@injectable() export abstract class BaseWindowHandlerContribution implements IWindowHandlerContribution { declare type: EnvType; diff --git a/packages/vrender-core/src/core/core-modules.ts b/packages/vrender-core/src/core/core-modules.ts deleted file mode 100644 index b2b601af8..000000000 --- a/packages/vrender-core/src/core/core-modules.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { ContainerModule } from '../common/inversify-lite'; -import { DefaultGlobal } from './global'; -import { DefaultGraphicUtil, DefaultTransformUtil } from './graphic-utils'; -import { DefaultLayerService } from './layer-service'; -import { DefaultWindow, VWindow } from './window'; -import { GraphicUtil, LayerService, TransformUtil } from './constants'; -import { VGlobal } from '../constants'; - -export default new ContainerModule(bind => { - // global对象,全局单例模式 - bind(VGlobal).to(DefaultGlobal).inSingletonScope(); - - bind(VWindow).to(DefaultWindow); - bind(GraphicUtil).to(DefaultGraphicUtil).inSingletonScope(); - bind(TransformUtil).to(DefaultTransformUtil).inSingletonScope(); - bind(LayerService).to(DefaultLayerService).inSingletonScope(); - - // bind(Stage).to(DefaultStage); - // bind<(params: Partial) => IStage>(StageFactory).toFactory((context: interface.Context) => { - // return (params: Partial) => { - // const g = context.container.get(Global); - // const ws = context.container.get(VWindow); - // const rs = context.container.get(RenderService); - // const layer = context.container.get(Layer); - // return new DefaultStage(params, g, ws, rs, layer); - // }; - // }); - // bind(Layer).to(DefaultLayer); -}); diff --git a/packages/vrender-core/src/core/global-module.ts b/packages/vrender-core/src/core/global-module.ts deleted file mode 100644 index 38608d4d3..000000000 --- a/packages/vrender-core/src/core/global-module.ts +++ /dev/null @@ -1,20 +0,0 @@ -// import type { IGlobal } from '../interface'; -// import { container } from '../container'; -// import { DefaultGlobal } from './global'; -// import envModules from './contributions/env/modules'; -// import { Global } from '../constants'; - -// const globalModule = new ContainerModule((bind, unbind, isBound) => { -// // global对象,全局单例模式 -// if (!isBound(Global)) { -// bind(DefaultGlobal).toSelf().inSingletonScope(); -// bind(Global).toService(DefaultGlobal); -// } -// }); - -// container.load(globalModule); -// container.load(envModules); - -// export const global = container.get(Global); - -// export default globalModule; diff --git a/packages/vrender-core/src/core/global.ts b/packages/vrender-core/src/core/global.ts index 597736668..69a2b2409 100644 --- a/packages/vrender-core/src/core/global.ts +++ b/packages/vrender-core/src/core/global.ts @@ -1,6 +1,3 @@ -import { inject, injectable, named } from '../common/inversify-lite'; -// eslint-disable-next-line @typescript-eslint/consistent-type-imports -import { ContributionProvider } from '../common/contribution-provider'; import type { CreateDOMParamsType, EnvType, @@ -14,13 +11,13 @@ import type { import { SyncHook } from '../tapable'; import { EnvContribution } from '../constants'; import type { IAABBBoundsLike } from '@visactor/vutils'; -import { container } from '../container'; import { Generator } from '../common/generator'; import { PerformanceRAF } from '../common/performance-raf'; import { EventListenerManager } from '../common/event-listener-manager'; +import { contributionRegistry } from '../common/registry'; const defaultEnv: EnvType = 'browser'; -@injectable() + export class DefaultGlobal extends EventListenerManager implements IGlobal { readonly id: number; private _env: EnvType; @@ -132,13 +129,14 @@ export class DefaultGlobal extends EventListenerManager implements IGlobal { // 注意返回的Event和原始的Event不是同一个对象,但也不能拷贝,返回的Event和原始Event是同一个Event类的实例(比如MouseEvent、FederatedPointerEvent等,不能直接拷贝或者用CustomEvent) eventListenerTransformer: (event: Event) => Event = event => event; - constructor( - // todo: 不需要创建,动态获取就行? - @inject(ContributionProvider) - @named(EnvContribution) - protected readonly contributions: IContributionProvider - ) { + protected readonly contributions: IContributionProvider; + + constructor(contributions?: IContributionProvider) { super(); + // 如果没有传入 contributions,则使用 registry 获取 + this.contributions = contributions || { + getContributions: () => contributionRegistry.get(EnvContribution) + }; this.id = Generator.GenAutoIncrementId(); this.hooks = { onSetEnv: new SyncHook<[EnvType | undefined, EnvType, IGlobal]>(['lastEnv', 'env', 'global']) diff --git a/packages/vrender-core/src/core/graphic-utils.ts b/packages/vrender-core/src/core/graphic-utils.ts index e13335abe..3dda77cef 100644 --- a/packages/vrender-core/src/core/graphic-utils.ts +++ b/packages/vrender-core/src/core/graphic-utils.ts @@ -1,4 +1,3 @@ -import { injectable, inject, named } from '../common/inversify-lite'; import type { ICanvas, IContext2d, @@ -13,18 +12,15 @@ import type { } from '../interface'; import type { ITextMeasure, TextOptionsType } from '../interface/text'; import { TextMeasureContribution } from './contributions/textMeasure/textMeasure-contribution'; -// eslint-disable-next-line @typescript-eslint/consistent-type-imports -import { ContributionProvider } from '../common/contribution-provider'; import { DefaultTextStyle } from '../graphic/config'; import type { IMatrix, IPointLike, ITextMeasureOption } from '@visactor/vutils'; import { Matrix, TextMeasure } from '@visactor/vutils'; import type { IGraphicUtil, ITransformUtil, TransformType } from '../interface/core'; import { canvasAllocate } from '../allocator/canvas-allocate'; import { application } from '../application'; -import { container } from '../container'; import { VWindow } from './window'; +import { contributionRegistry, serviceRegistry } from '../common/registry'; -@injectable() export class DefaultGraphicUtil implements IGraphicUtil { get canvas(): ICanvas { this.tryInitCanvas(); @@ -41,11 +37,15 @@ export class DefaultGraphicUtil implements IGraphicUtil { configured: boolean; global: IGlobal; - constructor( - @inject(ContributionProvider) - @named(TextMeasureContribution) - protected readonly contributions: IContributionProvider - ) { + protected readonly contributions: IContributionProvider; + + constructor(contributions?: IContributionProvider) { + // 如果没有传入 contributions,则使用 registry 获取 + this.contributions = + contributions || + ({ + getContributions: () => contributionRegistry.get(TextMeasureContribution) + } as IContributionProvider); this.configured = false; this.global = application.global; this._textMeasureMap = new Map(); @@ -142,7 +142,7 @@ export class DefaultGraphicUtil implements IGraphicUtil { if (!stage.defaultLayer) { return null; } - const window = container.get(VWindow); + const window = serviceRegistry.createInstance(VWindow); const bounds = graphic.AABBBounds; const width = bounds.width(); const height = bounds.height(); @@ -189,7 +189,6 @@ enum TransformMode { const _matrix = new Matrix(); -@injectable() export class DefaultTransformUtil implements ITransformUtil { private matrix: IMatrix; private originTransform: TransformType; diff --git a/packages/vrender-core/src/core/layer-service.ts b/packages/vrender-core/src/core/layer-service.ts index f4b012edf..a0954350e 100644 --- a/packages/vrender-core/src/core/layer-service.ts +++ b/packages/vrender-core/src/core/layer-service.ts @@ -1,16 +1,14 @@ -import { inject, injectable } from '../common/inversify-lite'; import type { ILayer, IStage, IGlobal, ILayerParams, LayerMode, ILayerHandlerContribution } from '../interface'; import { Layer } from './layer'; import type { ILayerService } from '../interface/core'; -import { container } from '../container'; import { DynamicLayerHandlerContribution, StaticLayerHandlerContribution, VirtualLayerHandlerContribution } from './constants'; import { application } from '../application'; +import { serviceRegistry } from '../common/registry'; -@injectable() export class DefaultLayerService implements ILayerService { declare layerMap: Map; declare staticLayerCountInEnv: number; @@ -57,11 +55,11 @@ export class DefaultLayerService implements ILayerService { getLayerHandler(layerMode: LayerMode) { let layerHandler: ILayerHandlerContribution; if (layerMode === 'static') { - layerHandler = container.get(StaticLayerHandlerContribution); + layerHandler = serviceRegistry.get(StaticLayerHandlerContribution); } else if (layerMode === 'dynamic') { - layerHandler = container.get(DynamicLayerHandlerContribution); + layerHandler = serviceRegistry.get(DynamicLayerHandlerContribution); } else { - layerHandler = container.get(VirtualLayerHandlerContribution); + layerHandler = serviceRegistry.get(VirtualLayerHandlerContribution); } return layerHandler; } diff --git a/packages/vrender-core/src/core/layer.ts b/packages/vrender-core/src/core/layer.ts index 39db24ea5..6ab6ca92c 100644 --- a/packages/vrender-core/src/core/layer.ts +++ b/packages/vrender-core/src/core/layer.ts @@ -1,6 +1,5 @@ import type { AABBBounds, IBoundsLike } from '@visactor/vutils'; import { application } from '../application'; -import { container } from '../container'; import type { IDrawToParams, IGraphic, diff --git a/packages/vrender-core/src/core/stage.ts b/packages/vrender-core/src/core/stage.ts index 70e1d6efc..2b05a2af0 100644 --- a/packages/vrender-core/src/core/stage.ts +++ b/packages/vrender-core/src/core/stage.ts @@ -31,7 +31,6 @@ import type { import { VWindow } from './window'; import type { Layer } from './layer'; import { EventSystem } from '../event'; -import { container } from '../container'; import { RenderService } from '../render/constants'; import { Group } from '../graphic/group'; import { Theme } from '../graphic/theme'; @@ -47,6 +46,7 @@ import { application } from '../application'; import { isBrowserEnv } from '../env-check'; import { Factory } from '../factory'; import { Graphic, GraphicService } from '../graphic'; +import { serviceRegistry } from '../common/registry'; const DefaultConfig = { WIDTH: 500, @@ -246,11 +246,11 @@ export class Stage extends Group implements IStage { // 如果是浏览器环境,默认设置env this.global.setEnv('browser'); } - this.window = container.get(VWindow); - this.renderService = container.get(RenderService); - this.pluginService = container.get(PluginService); - this.layerService = container.get(LayerService); - this.graphicService = container.get(GraphicService); + this.window = serviceRegistry.createInstance(VWindow); + this.renderService = serviceRegistry.createInstance(RenderService); + this.pluginService = serviceRegistry.createInstance(PluginService); + this.layerService = serviceRegistry.get(LayerService); + this.graphicService = serviceRegistry.get(GraphicService); this.pluginService.active(this, params); this._beforeRenderList = []; this._afterRenderList = []; @@ -1105,7 +1105,7 @@ export class Stage extends Group implements IStage { if (this.releaseStatus === 'released') { return; } - const window = container.get(VWindow); + const window = serviceRegistry.createInstance(VWindow); const x1 = viewBox ? -viewBox.x1 : 0; const y1 = viewBox ? -viewBox.y1 : 0; const x2 = viewBox ? viewBox.x2 : this.viewWidth; @@ -1174,7 +1174,7 @@ export class Stage extends Group implements IStage { getPickerService() { if (!this.pickerService) { - this.pickerService = container.get(PickerService); + this.pickerService = serviceRegistry.get(PickerService); } return this.pickerService; } diff --git a/packages/vrender-core/src/core/window.ts b/packages/vrender-core/src/core/window.ts index e0c310ec7..ec58fd3ec 100644 --- a/packages/vrender-core/src/core/window.ts +++ b/packages/vrender-core/src/core/window.ts @@ -1,4 +1,3 @@ -import { inject, injectable } from '../common/inversify-lite'; import type { IPointLike } from '@visactor/vutils'; import { Matrix, type IBoundsLike, type IMatrix, IBounds, Point, isEqual, isNumberClose } from '@visactor/vutils'; import { Generator } from '../common/generator'; @@ -11,7 +10,6 @@ import type { IWindowHandlerContribution, IWindowParams } from '../interface'; -import { container } from '../container'; import { SyncHook } from '../tapable'; import { application } from '../application'; import { EventListenerManager } from '../common/event-listener-manager'; @@ -25,7 +23,6 @@ export const WindowHandlerContribution = Symbol.for('WindowHandlerContribution') * 对于浏览器,就是管理某个Stage影响的Canvas * 对于原生,就是管理这个系统窗口 */ -@injectable() export class DefaultWindow extends EventListenerManager implements IWindow { protected _width: number; protected _height: number; @@ -116,7 +113,11 @@ export class DefaultWindow extends EventListenerManager implements IWindow { if (!global.env || this.actived) { return; } - const handler = container.getNamed(WindowHandlerContribution, global.env); + const contributions = application.contributions.get(WindowHandlerContribution); + const handler = contributions.find(c => (c as any).type === global.env) || contributions[0]; + if (!handler) { + throw new Error(`No WindowHandlerContribution registered for env: ${global.env}`); + } handler.configure(this, global); // this.contributions.getContributions().forEach((handlerContribution) => { // handlerContribution.configure(this, this.global); diff --git a/packages/vrender-core/src/graphic/graphic-service/graphic-module.ts b/packages/vrender-core/src/graphic/graphic-service/graphic-module.ts deleted file mode 100644 index d46fbfd37..000000000 --- a/packages/vrender-core/src/graphic/graphic-service/graphic-module.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ContainerModule } from '../../common/inversify-lite'; -// import { DefaultTheme } from './default-theme'; -import { DefaultGraphicService } from './graphic-service'; -import { GraphicCreator, GraphicService } from '../constants'; -import { graphicCreator } from '../graphic-creator'; -// import { DefaultThemeService, Theme, ThemeServce } from './theme-service'; - -export default new ContainerModule(bind => { - bind(GraphicService).to(DefaultGraphicService); - - bind(GraphicCreator).toConstantValue(graphicCreator); -}); diff --git a/packages/vrender-core/src/graphic/graphic-service/graphic-service.ts b/packages/vrender-core/src/graphic/graphic-service/graphic-service.ts index 38a4ad720..f54a6ff5f 100644 --- a/packages/vrender-core/src/graphic/graphic-service/graphic-service.ts +++ b/packages/vrender-core/src/graphic/graphic-service/graphic-service.ts @@ -1,4 +1,3 @@ -import { inject, injectable } from '../../common/inversify-lite'; import type { IAABBBounds } from '@visactor/vutils'; import { AABBBounds, isNumber, transformBoundsWithMatrix } from '@visactor/vutils'; import { SyncHook } from '../../tapable'; @@ -23,6 +22,7 @@ import { BoundsContext } from '../../common/bounds-context'; import { renderCommandList } from '../../common/render-command-list'; import { GraphicCreator } from '../constants'; import { identityMat4, multiplyMat4Mat4, rotateX, rotateY, rotateZ, scaleMat4, translate } from '../../common/matrix'; +import { serviceRegistry } from '../../common/registry'; export function getExtraModelMatrix(dx: number, dy: number, graphic: IGraphic): mat4 | null { const { alpha, beta } = graphic.attribute; @@ -164,7 +164,6 @@ export function shouldUseMat4(graphic: IGraphic) { } // 管理graphic -@injectable() export class DefaultGraphicService implements IGraphicService { declare hooks: { onAttributeUpdate: ISyncHook<[IGraphic]>; @@ -181,7 +180,11 @@ export class DefaultGraphicService implements IGraphicService { // 临时bounds,用作缓存 protected tempAABBBounds1: AABBBounds; protected tempAABBBounds2: AABBBounds; - constructor(@inject(GraphicCreator) public readonly creator: IGraphicCreator) { + readonly creator: IGraphicCreator; + + constructor(creator?: IGraphicCreator) { + // 如果没有传入 creator,则使用 registry 获取 + this.creator = creator || serviceRegistry.get(GraphicCreator); this.hooks = { onAttributeUpdate: new SyncHook<[IGraphic]>(['graphic']), onSetStage: new SyncHook<[IGraphic, IStage]>(['graphic', 'stage']), diff --git a/packages/vrender-core/src/index.ts b/packages/vrender-core/src/index.ts index 81f694540..75bbb79f1 100644 --- a/packages/vrender-core/src/index.ts +++ b/packages/vrender-core/src/index.ts @@ -1,10 +1,7 @@ // import 'core-js/proposals/reflect-metadata'; -import './modules'; -export * from './container'; export * from './core/global'; export * from './graphic'; -export * from './modules'; export * from './create'; export * from './event'; export * from './interface'; @@ -28,7 +25,6 @@ export * from './common/seg-context'; export * from './common/custom-path2d'; export * from './common/segment'; export * from './common/canvas-utils'; -export * from './common/contribution-provider'; export * from './common/generator'; export * from './common/utils'; export * from './common/shape/arc'; @@ -53,32 +49,13 @@ export * from './plugins/builtin-plugin/richtext-edit-plugin'; export * from './allocator/matrix-allocate'; export * from './allocator/canvas-allocate'; export * from './allocator/graphic-allocate'; -export * from './common/contribution-provider'; export { wrapCanvas, wrapContext } from './canvas/util'; export * from './common/xml'; -export * from './common/inversify-lite'; export * from './constants'; export * from './application'; export * from './env-check'; -export * from './render/contributions/render/arc-module'; -export * from './render/contributions/render/rect-module'; -export * from './render/contributions/render/line-module'; -export * from './render/contributions/render/area-module'; -export * from './render/contributions/render/symbol-module'; -export * from './render/contributions/render/circle-module'; -export * from './render/contributions/render/text-module'; -export * from './render/contributions/render/path-module'; -export * from './render/contributions/render/polygon-module'; -export * from './render/contributions/render/star-module'; -export * from './render/contributions/render/glyph-module'; -export * from './render/contributions/render/richtext-module'; -export * from './render/contributions/render/image-module'; -export * from './render/contributions/render/rect3d-module'; -export * from './render/contributions/render/arc3d-module'; -export * from './render/contributions/render/pyramid3d-module'; - export * from './register/register-arc'; export * from './register/register-arc3d'; export * from './register/register-area'; @@ -106,11 +83,3 @@ export * from './plugins/builtin-plugin/3dview-transform-plugin'; export * from './plugins/builtin-plugin/flex-layout-plugin'; export * from './plugins/builtin-plugin/edit-module'; - -// export const morphPath = {}; -// export const multiToOneMorph = {}; -// export const oneToMultiMorph = {}; -// export class ACustomAnimate {} -// export const AnimateGroup = {}; -// export const Animate = {}; -// export const defaultTicker = {}; diff --git a/packages/vrender-core/src/modules.ts b/packages/vrender-core/src/modules.ts index c52886435..ce0b4cef7 100644 --- a/packages/vrender-core/src/modules.ts +++ b/packages/vrender-core/src/modules.ts @@ -1,67 +1,42 @@ -import coreModule from './core/core-modules'; -import renderModule from './render/render-modules'; -import pickModule from './picker/pick-modules'; -// import allocatorModule from './allocator/allocator-modules'; -import graphicModule from './graphic/graphic-service/graphic-module'; -import pluginModule from './plugins/plugin-modules'; -import loadBuiltinContributions from './core/contributions/modules'; -import loadRenderContributions from './render/contributions/modules'; -// import loadPickContributions from './picker/contributions/modules'; -// import loadCanvasContributions from './canvas/contributions/modules'; +/** + * 模块预加载入口(Registry-only) + */ import { LayerService } from './core/constants'; -// import { IMat4Allocate, IMatrixAllocate, Mat4Allocate, MatrixAllocate } from './allocator/matrix-allocate'; -// import { GlobalPickerService } from './picker/constants'; -import type { IGlobal, IGraphicService, IPickerService, IRenderService } from './interface'; +import type { IGlobal, IGraphicService } from './interface'; import { application } from './application'; import type { IGraphicUtil, ILayerService, ITransformUtil } from './interface/core'; import { GraphicService } from './graphic/constants'; import { GraphicUtil, TransformUtil } from './core/constants'; -import { container } from './container'; import { VGlobal } from './constants'; +import { serviceRegistry } from './common/registry'; +import { registerAllModules } from './register-modules'; export function preLoadAllModule() { if (preLoadAllModule.__loaded) { return; } preLoadAllModule.__loaded = true; - container.load(coreModule); - container.load(graphicModule); - container.load(renderModule); - container.load(pickModule); - // container.load(allocatorModule); - container.load(pluginModule); - loadBuiltinContributions(container); - loadRenderContributions(container); + + // Registry-only + registerAllModules(); } preLoadAllModule.__loaded = false; preLoadAllModule(); -// loadPickContributions(container); -// loadCanvasContributions(container); -// 全局变量 -export const vglobal = container.get(VGlobal); +// 全局变量 - 从 serviceRegistry 获取 +export const vglobal = serviceRegistry.get(VGlobal); application.global = vglobal; -export const graphicUtil = container.get(GraphicUtil); + +export const graphicUtil = serviceRegistry.get(GraphicUtil); application.graphicUtil = graphicUtil; -export const transformUtil = container.get(TransformUtil); + +export const transformUtil = serviceRegistry.get(TransformUtil); application.transformUtil = transformUtil; -export const graphicService = container.get(GraphicService); + +export const graphicService = serviceRegistry.get(GraphicService); application.graphicService = graphicService; -// export const renderService = container.get(RenderService); -// application.renderService = renderService; -// export const matrixAllocate = container.get(MatrixAllocate); -// export const mat4Allocate = container.get(Mat4Allocate); -// export const canvasAllocate = container.get(CanvasAllocate); -// export const arcAllocate = container.get(ArcAllocate); -// export const areaAllocate = container.get(AreaAllocate); -// export const circleAllocate = container.get(CircleAllocate); -// export const lineAllocate = container.get(LineAllocate); -// export const pathAllocate = container.get(PathAllocate); -// export const rectAllocate = container.get(RectAllocate); -// export const symbolAllocate = container.get(SymbolAllocate); -// export const textAllocate = container.get(TextAllocate); -// export const pickerService = container.get(GlobalPickerService); -export const layerService = container.get(LayerService); + +export const layerService = serviceRegistry.get(LayerService); application.layerService = layerService; diff --git a/packages/vrender-core/src/picker/global-picker-service.ts b/packages/vrender-core/src/picker/global-picker-service.ts index 33eff0864..3c78c589e 100644 --- a/packages/vrender-core/src/picker/global-picker-service.ts +++ b/packages/vrender-core/src/picker/global-picker-service.ts @@ -1,6 +1,5 @@ import type { IMatrix, IPoint, IPointLike } from '@visactor/vutils'; import { Matrix, Point } from '@visactor/vutils'; -import { inject, injectable } from '../common/inversify-lite'; import type { IGraphic, IGroup, @@ -15,7 +14,6 @@ import { application } from '../application'; // 默认的pick-service,提供基本的最优选中策略,尽量不需要用户自己实现contribution // 用户可以写plugin -@injectable() export class DefaultGlobalPickerService implements IPickerService { type: 'global'; diff --git a/packages/vrender-core/src/picker/pick-interceptor.ts b/packages/vrender-core/src/picker/pick-interceptor.ts index 9dfe8e222..fcf3b4d18 100644 --- a/packages/vrender-core/src/picker/pick-interceptor.ts +++ b/packages/vrender-core/src/picker/pick-interceptor.ts @@ -1,6 +1,5 @@ import type { IMatrix, IPointLike } from '@visactor/vutils'; import { Point } from '@visactor/vutils'; -import { injectable } from '../common/inversify-lite'; import type { IContext2d, IGraphic, @@ -15,7 +14,6 @@ import { matrixAllocate } from '../allocator/matrix-allocate'; import { draw3dItem } from '../common/3d-interceptor'; import { getTheme } from '../graphic'; -@injectable() export class ShadowPickServiceInterceptorContribution implements IPickServiceInterceptorContribution { order: number = 1; afterPickItem( @@ -46,7 +44,6 @@ export class ShadowPickServiceInterceptorContribution implements IPickServiceInt /** * 影子节点拦截器,用于渲染影子节点 */ -@injectable() export class ShadowRootPickItemInterceptorContribution implements IPickItemInterceptorContribution { order: number = 1; afterPickItem( @@ -131,7 +128,6 @@ export class ShadowRootPickItemInterceptorContribution implements IPickItemInter } } -@injectable() export class InteractivePickItemInterceptorContribution implements IPickItemInterceptorContribution { order: number = 1; @@ -165,7 +161,6 @@ export class InteractivePickItemInterceptorContribution implements IPickItemInte /** * 3d拦截器,用于渲染3d视角 */ -@injectable() export class Canvas3DPickItemInterceptor implements IPickItemInterceptorContribution { // canvas?: ICanvas; order: number = 1; diff --git a/packages/vrender-core/src/picker/pick-modules.ts b/packages/vrender-core/src/picker/pick-modules.ts deleted file mode 100644 index e84b00c5f..000000000 --- a/packages/vrender-core/src/picker/pick-modules.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { ContainerModule } from '../common/inversify-lite'; -import { PickerService, GlobalPickerService, PickItemInterceptor, PickServiceInterceptor } from './constants'; -import { DefaultGlobalPickerService } from './global-picker-service'; -// import { DefaultCanvasPickerService } from './canvas-picker-service'; -// import { DefaultMathPickerService } from './math-picker-service'; -import { - Canvas3DPickItemInterceptor, - InteractivePickItemInterceptorContribution, - ShadowPickServiceInterceptorContribution, - ShadowRootPickItemInterceptorContribution -} from './pick-interceptor'; -import { bindContributionProvider } from '../common/contribution-provider'; - -export default new ContainerModule((bind, unbind, isBound) => { - if (!isBound(PickerService)) { - bind(GlobalPickerService).toSelf(); - bind(PickerService).toService(GlobalPickerService); - } - // bind(PickerService).toService(GlobalPickerService); - - // bind(DefaultGlobalPickerService).toSelf().inSingletonScope(); - // bind(GlobalPickerService).toService(DefaultGlobalPickerService); - - // interceptor - bind(Canvas3DPickItemInterceptor).toSelf().inSingletonScope(); - bind(PickItemInterceptor).toService(Canvas3DPickItemInterceptor); - - // shadow root - bind(ShadowRootPickItemInterceptorContribution).toSelf().inSingletonScope(); - bind(PickItemInterceptor).toService(ShadowRootPickItemInterceptorContribution); - - // interactive - bind(InteractivePickItemInterceptorContribution).toSelf().inSingletonScope(); - bind(PickItemInterceptor).toService(InteractivePickItemInterceptorContribution); - bindContributionProvider(bind, PickItemInterceptor); - - bind(ShadowPickServiceInterceptorContribution).toSelf().inSingletonScope(); - bind(PickServiceInterceptor).toService(ShadowPickServiceInterceptorContribution); - - bindContributionProvider(bind, PickServiceInterceptor); -}); diff --git a/packages/vrender-core/src/picker/picker-service.ts b/packages/vrender-core/src/picker/picker-service.ts index 8b0d6a397..77004304e 100644 --- a/packages/vrender-core/src/picker/picker-service.ts +++ b/packages/vrender-core/src/picker/picker-service.ts @@ -1,9 +1,6 @@ import type { IMatrix, IPoint, IPointLike } from '@visactor/vutils'; import { AABBBounds, Matrix, Point } from '@visactor/vutils'; -import { inject, injectable, named } from '../common/inversify-lite'; import { foreach } from '../common/sort'; -// eslint-disable-next-line @typescript-eslint/consistent-type-imports -import { ContributionProvider } from '../common/contribution-provider'; import type { IContext2d, IGraphic, @@ -24,8 +21,8 @@ import { mat3Tomat4, multiplyMat4Mat4 } from '../common/matrix'; import { mat4Allocate, matrixAllocate } from '../allocator/matrix-allocate'; import { application } from '../application'; import { PickItemInterceptor, PickServiceInterceptor } from './constants'; +import { contributionRegistry } from '../common/registry'; -@injectable() export abstract class DefaultPickService implements IPickerService { type: string = 'default'; declare pickerMap: Map; @@ -34,17 +31,23 @@ export abstract class DefaultPickService implements IPickerService { declare pickerServiceInterceptorContributions: IPickServiceInterceptorContribution[]; declare global: IGlobal; + protected readonly pickItemInterceptorContributions: IContributionProvider; + protected readonly pickServiceInterceptorContributions: IContributionProvider; + constructor( - // 拦截器 - // @ts-ignore - @inject(ContributionProvider) - @named(PickItemInterceptor) - protected readonly pickItemInterceptorContributions: IContributionProvider, - // @ts-ignore - @inject(ContributionProvider) - @named(PickServiceInterceptor) - protected readonly pickServiceInterceptorContributions: IContributionProvider + pickItemInterceptorContributions?: IContributionProvider, + pickServiceInterceptorContributions?: IContributionProvider ) { + this.pickItemInterceptorContributions = + pickItemInterceptorContributions || + ({ + getContributions: () => contributionRegistry.get(PickItemInterceptor) + } as IContributionProvider); + this.pickServiceInterceptorContributions = + pickServiceInterceptorContributions || + ({ + getContributions: () => contributionRegistry.get(PickServiceInterceptor) + } as IContributionProvider); this.global = application.global; } diff --git a/packages/vrender-core/src/plugins/plugin-modules.ts b/packages/vrender-core/src/plugins/plugin-modules.ts deleted file mode 100644 index ff5edd194..000000000 --- a/packages/vrender-core/src/plugins/plugin-modules.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ContainerModule } from '../common/inversify-lite'; -import { PluginService } from './constants'; -import { DefaultPluginService } from './plugin-service'; -import { bindContributionProviderNoSingletonScope } from '../common/contribution-provider'; -import { AutoEnablePlugins } from './constants'; - -export default new ContainerModule(bind => { - bind(PluginService).to(DefaultPluginService); - - // image 渲染器注入contributions - bindContributionProviderNoSingletonScope(bind, AutoEnablePlugins); -}); diff --git a/packages/vrender-core/src/plugins/plugin-service.ts b/packages/vrender-core/src/plugins/plugin-service.ts index 23506467e..d1fe9cd35 100644 --- a/packages/vrender-core/src/plugins/plugin-service.ts +++ b/packages/vrender-core/src/plugins/plugin-service.ts @@ -1,21 +1,22 @@ -import { injectable, inject, named } from '../common/inversify-lite'; import type { IContributionProvider, IPlugin, IPluginService, IStage } from '../interface'; -import { ContributionProvider } from '../common/contribution-provider'; import { AutoEnablePlugins } from './constants'; -import { container } from '../container'; +import { contributionRegistry } from '../common/registry'; -@injectable() export class DefaultPluginService implements IPluginService { declare onStartupFinishedPlugin: IPlugin[]; declare onRegisterPlugin: IPlugin[]; declare stage: IStage; declare actived: boolean; - constructor( - @inject(ContributionProvider) - @named(AutoEnablePlugins) - protected readonly autoEnablePlugins: IContributionProvider - ) { + protected readonly autoEnablePlugins: IContributionProvider; + + constructor(autoEnablePlugins?: IContributionProvider) { + // 如果没有传入,则使用 registry 获取 + this.autoEnablePlugins = + autoEnablePlugins || + ({ + getContributions: () => contributionRegistry.get(AutoEnablePlugins) + } as IContributionProvider); this.onStartupFinishedPlugin = []; this.onRegisterPlugin = []; this.actived = false; @@ -27,7 +28,7 @@ export class DefaultPluginService implements IPluginService { // 启动插件 const { pluginList } = params; - if (pluginList && container.isBound(AutoEnablePlugins)) { + if (pluginList && contributionRegistry.has(AutoEnablePlugins)) { this.autoEnablePlugins.getContributions().forEach(p => { if (pluginList.includes(p.name)) { this.register(p); diff --git a/packages/vrender-core/src/register-modules.ts b/packages/vrender-core/src/register-modules.ts new file mode 100644 index 000000000..341f9f408 --- /dev/null +++ b/packages/vrender-core/src/register-modules.ts @@ -0,0 +1,178 @@ +/** + * 新的模块注册系统 - 替代 ContainerModule 模式 + * + * 这个文件将所有服务注册到 serviceRegistry 和 contributionRegistry + */ +declare let require: any; +import { serviceRegistry, contributionRegistry } from './common/registry'; +import { VGlobal, EnvContribution } from './constants'; +import { GraphicUtil, LayerService, TransformUtil } from './core/constants'; +import { VWindow } from './core/window'; +import { GraphicService, GraphicCreator } from './graphic/constants'; +import { RenderService } from './render/constants'; +import { + DrawContribution, + GraphicRender, + IncrementalDrawContribution, + GroupRender +} from './render/contributions/render/symbol'; +import { DrawItemInterceptor } from './render/contributions/render/draw-interceptor'; +import { PickerService, GlobalPickerService, PickItemInterceptor, PickServiceInterceptor } from './picker/constants'; +import { PluginService, AutoEnablePlugins } from './plugins/constants'; +import { + DynamicLayerHandlerContribution, + StaticLayerHandlerContribution, + VirtualLayerHandlerContribution +} from './core/constants'; +import { + GroupRenderContribution, + InteractiveSubRenderContribution +} from './render/contributions/render/contributions/constants'; + +// ============ Core 模块注册 ============ + +export function registerCoreModule() { + const { DefaultGlobal } = require('./core/global'); + const { DefaultGraphicUtil, DefaultTransformUtil } = require('./core/graphic-utils'); + const { DefaultLayerService } = require('./core/layer-service'); + const { DefaultWindow } = require('./core/window'); + + // 单例服务 + serviceRegistry.registerSingletonFactory(VGlobal, () => new DefaultGlobal()); + serviceRegistry.registerSingletonFactory(GraphicUtil, () => new DefaultGraphicUtil()); + serviceRegistry.registerSingletonFactory(TransformUtil, () => new DefaultTransformUtil()); + serviceRegistry.registerSingletonFactory(LayerService, () => new DefaultLayerService()); + + // 工厂服务 - Window 每次创建新实例 + serviceRegistry.registerFactory(VWindow, () => new DefaultWindow()); +} + +// ============ Graphic 模块注册 ============ + +export function registerGraphicModule() { + const { DefaultGraphicService } = require('./graphic/graphic-service/graphic-service'); + const { graphicCreator } = require('./graphic/graphic-creator'); + + serviceRegistry.registerSingletonFactory(GraphicService, () => new DefaultGraphicService()); + serviceRegistry.registerSingleton(GraphicCreator, graphicCreator); +} + +// ============ Render 模块注册 ============ + +export function registerRenderModule() { + const { DefaultRenderService } = require('./render/render-service'); + const { DefaultDrawContribution } = require('./render/contributions/render/draw-contribution'); + const { DefaultIncrementalDrawContribution } = require('./render/contributions/render/incremental-draw-contribution'); + + // DrawContribution 单例 + serviceRegistry.registerSingletonFactory(DrawContribution, () => new DefaultDrawContribution()); + + // IncrementalDrawContribution 单例 + serviceRegistry.registerSingletonFactory(IncrementalDrawContribution, () => new DefaultIncrementalDrawContribution()); + + // RenderService 工厂 - 每个 Stage 一个实例 + serviceRegistry.registerFactory(RenderService, () => { + const drawContribution = serviceRegistry.get(DrawContribution); + return new DefaultRenderService(drawContribution); + }); +} + +// ============ Render Contributions 注册 ============ + +export function registerRenderContributions() { + const { DefaultCanvasGroupRender } = require('./render/contributions/render/group-render'); + const { CommonDrawItemInterceptorContribution } = require('./render/contributions/render/draw-interceptor'); + const { + DefaultBaseBackgroundRenderContribution, + DefaultBaseInteractiveRenderContribution, + DefaultBaseTextureRenderContribution + } = require('./render/contributions/render/contributions'); + + // Group 渲染器 + const groupRender = new DefaultCanvasGroupRender(); + serviceRegistry.registerSingleton(GroupRender, groupRender); + contributionRegistry.register(GraphicRender, groupRender); + + // DrawItemInterceptor + const commonInterceptor = new CommonDrawItemInterceptorContribution(); + contributionRegistry.register(DrawItemInterceptor, commonInterceptor); + + // 基础贡献 - 单例 + serviceRegistry.registerSingleton( + DefaultBaseBackgroundRenderContribution, + new DefaultBaseBackgroundRenderContribution() + ); + serviceRegistry.registerSingleton(DefaultBaseTextureRenderContribution, new DefaultBaseTextureRenderContribution()); + serviceRegistry.registerSingleton( + DefaultBaseInteractiveRenderContribution, + new DefaultBaseInteractiveRenderContribution() + ); +} + +// ============ Picker 模块注册 ============ + +export function registerPickerModule() { + const { DefaultGlobalPickerService } = require('./picker/global-picker-service'); + const { + Canvas3DPickItemInterceptor, + InteractivePickItemInterceptorContribution, + ShadowPickServiceInterceptorContribution, + ShadowRootPickItemInterceptorContribution + } = require('./picker/pick-interceptor'); + + // GlobalPickerService 单例 + serviceRegistry.registerSingletonFactory(GlobalPickerService, () => new DefaultGlobalPickerService()); + serviceRegistry.registerSingletonFactory(PickerService, () => serviceRegistry.get(GlobalPickerService)); + + // PickItemInterceptor 贡献 + contributionRegistry.register(PickItemInterceptor, new Canvas3DPickItemInterceptor()); + contributionRegistry.register(PickItemInterceptor, new ShadowRootPickItemInterceptorContribution()); + contributionRegistry.register(PickItemInterceptor, new InteractivePickItemInterceptorContribution()); + + // PickServiceInterceptor 贡献 + contributionRegistry.register(PickServiceInterceptor, new ShadowPickServiceInterceptorContribution()); +} + +// ============ Plugin 模块注册 ============ + +export function registerPluginModule() { + const { DefaultPluginService } = require('./plugins/plugin-service'); + + // PluginService 工厂 - 每个 Stage 一个实例 + serviceRegistry.registerFactory(PluginService, () => new DefaultPluginService()); +} + +// ============ 内置 Contributions 注册 ============ + +export function registerBuiltinContributions() { + // 这里将加载 env、textMeasure、layerHandler 等贡献 + // 暂时保持空实现,后续需要根据实际情况注册 +} + +// ============ 统一注册入口 ============ + +let _registered = false; + +export function registerAllModules() { + if (_registered) { + return; + } + _registered = true; + + registerCoreModule(); + registerGraphicModule(); + registerRenderModule(); + registerRenderContributions(); + registerPickerModule(); + registerPluginModule(); + registerBuiltinContributions(); +} + +/** + * 重置注册状态(用于测试) + */ +export function resetModuleRegistration() { + _registered = false; + serviceRegistry.clear(); + contributionRegistry.clearAll(); +} diff --git a/packages/vrender-core/src/render/contributions/modules.ts b/packages/vrender-core/src/render/contributions/modules.ts deleted file mode 100644 index f1856ffca..000000000 --- a/packages/vrender-core/src/render/contributions/modules.ts +++ /dev/null @@ -1,6 +0,0 @@ -import type { Container } from '../../common/inversify-lite'; -import renderModule from './render/module'; - -export default function load(container: Container) { - container.load(renderModule); -} diff --git a/packages/vrender-core/src/render/contributions/render/arc-module.ts b/packages/vrender-core/src/render/contributions/render/arc-module.ts deleted file mode 100644 index 4b41d2fb2..000000000 --- a/packages/vrender-core/src/render/contributions/render/arc-module.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { bindContributionProvider } from '../../../common/contribution-provider'; -import { ContainerModule } from '../../../common/inversify'; -import { DefaultCanvasArcRender } from './arc-render'; -import { DefaultBaseInteractiveRenderContribution } from './contributions'; -import { ArcRenderContribution } from './contributions/constants'; -import { ArcRender, GraphicRender } from './symbol'; - -let loadArcModule = false; -export const arcModule = new ContainerModule(bind => { - if (loadArcModule) { - return; - } - loadArcModule = true; - // arc 渲染器 - bind(DefaultCanvasArcRender).toSelf().inSingletonScope(); - bind(ArcRender).to(DefaultCanvasArcRender).inSingletonScope(); - bind(GraphicRender).toService(ArcRender); - bind(ArcRenderContribution).toService(DefaultBaseInteractiveRenderContribution); - // arc 渲染器注入contributions - bindContributionProvider(bind, ArcRenderContribution); -}); diff --git a/packages/vrender-core/src/render/contributions/render/arc-render.ts b/packages/vrender-core/src/render/contributions/render/arc-render.ts index d9f964f7c..d293a5b16 100644 --- a/packages/vrender-core/src/render/contributions/render/arc-render.ts +++ b/packages/vrender-core/src/render/contributions/render/arc-render.ts @@ -1,9 +1,6 @@ import { abs, atan2, cos, epsilon, min, sin, pi2, isBoolean } from '@visactor/vutils'; -import { inject, injectable, named } from '../../../common/inversify-lite'; import { getTheme } from '../../../graphic/theme'; import { parseStroke } from '../../../common/utils'; -// eslint-disable-next-line @typescript-eslint/consistent-type-imports -import { ContributionProvider } from '../../../common/contribution-provider'; import { calculateArcCornerRadius } from '../render/utils'; import type { IContext2d, @@ -32,6 +29,7 @@ import { defaultArcRenderContribution, defaultArcTextureRenderContribution } from './contributions'; +import { contributionRegistry } from '../../../common/registry'; /** * 部分源码参考 https://github.com/d3/d3-shape/ * Copyright 2010-2022 Mike Bostock @@ -49,23 +47,25 @@ import { THIS SOFTWARE. */ -@injectable() export class DefaultCanvasArcRender extends BaseRender implements IGraphicRender { type: 'arc'; numberType: number = ARC_NUMBER_TYPE; - constructor( - @inject(ContributionProvider) - @named(ArcRenderContribution) - protected readonly graphicRenderContributions: IContributionProvider - ) { + protected readonly graphicRenderContributions: IContributionProvider; + + constructor(graphicRenderContributions?: IContributionProvider) { super(); + this.graphicRenderContributions = + graphicRenderContributions || + ({ + getContributions: () => contributionRegistry.get(ArcRenderContribution) + } as IContributionProvider); this.builtinContributions = [ defaultArcRenderContribution, defaultArcBackgroundRenderContribution, defaultArcTextureRenderContribution ]; - this.init(graphicRenderContributions); + this.init(this.graphicRenderContributions); } // 绘制尾部cap diff --git a/packages/vrender-core/src/render/contributions/render/arc3d-module.ts b/packages/vrender-core/src/render/contributions/render/arc3d-module.ts deleted file mode 100644 index 29a00ccb3..000000000 --- a/packages/vrender-core/src/render/contributions/render/arc3d-module.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { ContainerModule } from '../../../common/inversify'; -import { DefaultCanvasArcRender } from './arc-render'; -import { DefaultCanvasArc3DRender } from './arc3d-render'; -import { DefaultBaseInteractiveRenderContribution } from './contributions'; -import { ArcRenderContribution } from './contributions/constants'; -import { Arc3dRender, ArcRender, GraphicRender } from './symbol'; - -let loadArc3dModule = false; -export const arc3dModule = new ContainerModule(bind => { - if (loadArc3dModule) { - return; - } - loadArc3dModule = true; - // arc3d 渲染器 - bind(Arc3dRender).to(DefaultCanvasArc3DRender).inSingletonScope(); - bind(GraphicRender).toService(Arc3dRender); -}); diff --git a/packages/vrender-core/src/render/contributions/render/arc3d-render.ts b/packages/vrender-core/src/render/contributions/render/arc3d-render.ts index ce91506e3..e10cd49ac 100644 --- a/packages/vrender-core/src/render/contributions/render/arc3d-render.ts +++ b/packages/vrender-core/src/render/contributions/render/arc3d-render.ts @@ -1,6 +1,5 @@ import type { vec3 } from '@visactor/vutils'; import { abs, cos, epsilon, sin, pi2, pi } from '@visactor/vutils'; -import { injectable } from '../../../common/inversify-lite'; import { getTheme } from '../../../graphic/theme'; import type { IContext2d, @@ -164,7 +163,6 @@ function drawInnerOuterArcPath( return collapsedToLine; } -@injectable() export class DefaultCanvasArc3DRender extends BaseRender implements IGraphicRender { type: 'arc3d'; numberType: number = ARC3D_NUMBER_TYPE; diff --git a/packages/vrender-core/src/render/contributions/render/area-module.ts b/packages/vrender-core/src/render/contributions/render/area-module.ts deleted file mode 100644 index 021ada370..000000000 --- a/packages/vrender-core/src/render/contributions/render/area-module.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { bindContributionProvider } from '../../../common/contribution-provider'; -import { ContainerModule } from '../../../common/inversify'; -import { DefaultCanvasAreaRender } from './area-render'; -import { DefaultBaseInteractiveRenderContribution } from './contributions'; -import { AreaRenderContribution } from './contributions/constants'; -import { DefaultIncrementalCanvasAreaRender } from './incremental-area-render'; -import { AreaRender, GraphicRender } from './symbol'; - -let loadAreaModule = false; -export const areaModule = new ContainerModule(bind => { - if (loadAreaModule) { - return; - } - loadAreaModule = true; - // area渲染器 - bind(DefaultCanvasAreaRender).toSelf().inSingletonScope(); - bind(AreaRender).to(DefaultCanvasAreaRender).inSingletonScope(); - bind(GraphicRender).toService(AreaRender); - bind(AreaRenderContribution).toService(DefaultBaseInteractiveRenderContribution); - - // area 渲染器注入contributions - bindContributionProvider(bind, AreaRenderContribution); - - // incremental-line渲染器 - bind(DefaultIncrementalCanvasAreaRender).toSelf().inSingletonScope(); -}); diff --git a/packages/vrender-core/src/render/contributions/render/area-render.ts b/packages/vrender-core/src/render/contributions/render/area-render.ts index cc0792f25..6fdc73789 100644 --- a/packages/vrender-core/src/render/contributions/render/area-render.ts +++ b/packages/vrender-core/src/render/contributions/render/area-render.ts @@ -1,6 +1,5 @@ import type { IPointLike } from '@visactor/vutils'; import { abs, isArray, min } from '@visactor/vutils'; -import { inject, injectable, named } from '../../../common/inversify-lite'; import type { IArea, IAreaCacheItem, @@ -17,8 +16,6 @@ import type { IGraphicRenderDrawParams, IContributionProvider } from '../../../interface'; -// eslint-disable-next-line @typescript-eslint/consistent-type-imports -import { ContributionProvider } from '../../../common/contribution-provider'; import { calcLineCache } from '../../../common/segment'; import { getTheme } from '../../../graphic/theme'; @@ -32,20 +29,23 @@ import { defaultAreaBackgroundRenderContribution, defaultAreaTextureRenderContribution } from './contributions/area-contribution-render'; +import { contributionRegistry } from '../../../common/registry'; -@injectable() export class DefaultCanvasAreaRender extends BaseRender implements IGraphicRender { type: 'area'; numberType: number = AREA_NUMBER_TYPE; - constructor( - @inject(ContributionProvider) - @named(AreaRenderContribution) - protected readonly graphicRenderContributions: IContributionProvider - ) { + protected readonly graphicRenderContributions: IContributionProvider; + + constructor(graphicRenderContributions?: IContributionProvider) { super(); + this.graphicRenderContributions = + graphicRenderContributions || + ({ + getContributions: () => contributionRegistry.get(AreaRenderContribution) + } as IContributionProvider); this.builtinContributions = [defaultAreaTextureRenderContribution, defaultAreaBackgroundRenderContribution]; - this.init(graphicRenderContributions); + this.init(this.graphicRenderContributions); } drawLinearAreaHighPerformance( diff --git a/packages/vrender-core/src/render/contributions/render/base-render.ts b/packages/vrender-core/src/render/contributions/render/base-render.ts index c306a8f0d..5447f309c 100644 --- a/packages/vrender-core/src/render/contributions/render/base-render.ts +++ b/packages/vrender-core/src/render/contributions/render/base-render.ts @@ -29,7 +29,7 @@ export abstract class BaseRender { declare z: number; builtinContributions: IBaseRenderContribution[]; - declare protected graphicRenderContributions: IContributionProvider>; + protected declare graphicRenderContributions: IContributionProvider>; // declare renderContribitions: IContributionProvider> | null; @@ -40,7 +40,7 @@ export abstract class BaseRender { init(contributions?: IContributionProvider>) { if (contributions) { // this.renderContribitions = contributions; - this._renderContribitions = contributions.getContributions(); + this._renderContribitions = (contributions?.getContributions && contributions.getContributions()) || []; } if (!this._renderContribitions) { this._renderContribitions = []; diff --git a/packages/vrender-core/src/render/contributions/render/circle-module.ts b/packages/vrender-core/src/render/contributions/render/circle-module.ts deleted file mode 100644 index e49896c3a..000000000 --- a/packages/vrender-core/src/render/contributions/render/circle-module.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { bindContributionProvider } from '../../../common/contribution-provider'; -import { ContainerModule } from '../../../common/inversify'; -import { DefaultCanvasCircleRender } from './circle-render'; -import { DefaultBaseInteractiveRenderContribution } from './contributions'; -import { CircleRenderContribution } from './contributions/constants'; -import { CircleRender, GraphicRender } from './symbol'; - -let loadCircleModule = false; -export const circleModule = new ContainerModule(bind => { - if (loadCircleModule) { - return; - } - loadCircleModule = true; - // circle 渲染器 - bind(DefaultCanvasCircleRender).toSelf().inSingletonScope(); - bind(CircleRender).to(DefaultCanvasCircleRender).inSingletonScope(); - bind(GraphicRender).toService(CircleRender); - bind(CircleRenderContribution).toService(DefaultBaseInteractiveRenderContribution); - - // circle 渲染器注入contributions - bindContributionProvider(bind, CircleRenderContribution); -}); diff --git a/packages/vrender-core/src/render/contributions/render/circle-render.ts b/packages/vrender-core/src/render/contributions/render/circle-render.ts index 8854a0d60..c37181923 100644 --- a/packages/vrender-core/src/render/contributions/render/circle-render.ts +++ b/packages/vrender-core/src/render/contributions/render/circle-render.ts @@ -1,4 +1,3 @@ -import { inject, injectable, named } from '../../../common/inversify-lite'; import type { IGraphicAttribute, ICircle, @@ -15,32 +14,34 @@ import type { import { getTheme } from '../../../graphic/theme'; import { CIRCLE_NUMBER_TYPE } from '../../../graphic/constants'; import { CircleRenderContribution } from './contributions/constants'; -// eslint-disable-next-line @typescript-eslint/consistent-type-imports -import { ContributionProvider } from '../../../common/contribution-provider'; import { BaseRender } from './base-render'; import { defaultCircleBackgroundRenderContribution, defaultCircleRenderContribution, defaultCircleTextureRenderContribution } from './contributions'; +import { contributionRegistry } from '../../../common/registry'; -@injectable() export class DefaultCanvasCircleRender extends BaseRender implements IGraphicRender { type: 'circle'; numberType: number = CIRCLE_NUMBER_TYPE; - constructor( - @inject(ContributionProvider) - @named(CircleRenderContribution) - protected readonly graphicRenderContributions: IContributionProvider - ) { + protected readonly graphicRenderContributions: IContributionProvider; + + constructor(graphicRenderContributions?: IContributionProvider) { super(); + // 如果没有传入,则使用 registry 获取 + this.graphicRenderContributions = + graphicRenderContributions || + ({ + getContributions: () => contributionRegistry.get(CircleRenderContribution) + } as IContributionProvider); this.builtinContributions = [ defaultCircleRenderContribution, defaultCircleBackgroundRenderContribution, defaultCircleTextureRenderContribution ]; - this.init(graphicRenderContributions); + this.init(this.graphicRenderContributions); } drawShape( diff --git a/packages/vrender-core/src/render/contributions/render/contributions/base-contribution-render.ts b/packages/vrender-core/src/render/contributions/render/contributions/base-contribution-render.ts index 171dd12a6..3d571b5f3 100644 --- a/packages/vrender-core/src/render/contributions/render/contributions/base-contribution-render.ts +++ b/packages/vrender-core/src/render/contributions/render/contributions/base-contribution-render.ts @@ -11,12 +11,11 @@ import type { ISymbolGraphicAttribute } from '../../../../interface'; import type { IBounds } from '@visactor/vutils'; -import { inject, injectable, named } from '../../../../common/inversify-lite'; import { getTheme } from '../../../../graphic/theme'; import { canvasAllocate } from '../../../../allocator/canvas-allocate'; import { BaseRenderContributionTime } from '../../../../common/enums'; -import { ContributionProvider } from '../../../../common/contribution-provider'; import { InteractiveSubRenderContribution } from './constants'; +import { contributionRegistry } from '../../../../common/registry'; export class DefaultBaseBackgroundRenderContribution implements IBaseRenderContribution { time: BaseRenderContributionTime = BaseRenderContributionTime.beforeFillStroke; @@ -200,18 +199,22 @@ export interface IInteractiveSubRenderContribution { ) => void; } -@injectable() export class DefaultBaseInteractiveRenderContribution implements IBaseRenderContribution { time: BaseRenderContributionTime = BaseRenderContributionTime.afterFillStroke; useStyle: boolean = true; order: number = 0; _subRenderContribitions?: IInteractiveSubRenderContribution[]; - constructor( - @inject(ContributionProvider) - @named(InteractiveSubRenderContribution) - protected readonly subRenderContribitions: IContributionProvider - ) {} + protected readonly subRenderContribitions: IContributionProvider; + + constructor(subRenderContribitions?: IContributionProvider) { + this.subRenderContribitions = + subRenderContribitions || + ({ + getContributions: () => + contributionRegistry.get(InteractiveSubRenderContribution) + } as IContributionProvider); + } drawShape( graphic: IGraphic, diff --git a/packages/vrender-core/src/render/contributions/render/contributions/rect-contribution-render.ts b/packages/vrender-core/src/render/contributions/render/contributions/rect-contribution-render.ts index ad560f4cc..f127ae0c9 100644 --- a/packages/vrender-core/src/render/contributions/render/contributions/rect-contribution-render.ts +++ b/packages/vrender-core/src/render/contributions/render/contributions/rect-contribution-render.ts @@ -1,5 +1,4 @@ import { isArray } from '@visactor/vutils'; -import { injectable } from '../../../../common/inversify-lite'; import type { IGraphicAttribute, IContext2d, @@ -121,7 +120,6 @@ export class DefaultRectRenderContribution implements IRectRenderContribution { } } -@injectable() export class SplitRectBeforeRenderContribution implements IRectRenderContribution { time: BaseRenderContributionTime = BaseRenderContributionTime.beforeFillStroke; useStyle: boolean = true; @@ -158,7 +156,6 @@ export class SplitRectBeforeRenderContribution implements IRectRenderContributio } } -@injectable() export class SplitRectAfterRenderContribution implements IRectRenderContribution { time: BaseRenderContributionTime = BaseRenderContributionTime.afterFillStroke; useStyle: boolean = true; diff --git a/packages/vrender-core/src/render/contributions/render/draw-contribution.ts b/packages/vrender-core/src/render/contributions/render/draw-contribution.ts index 59b6b1248..9d2e48424 100644 --- a/packages/vrender-core/src/render/contributions/render/draw-contribution.ts +++ b/packages/vrender-core/src/render/contributions/render/draw-contribution.ts @@ -1,4 +1,3 @@ -import { injectable, inject, named, multiInject } from '../../../common/inversify-lite'; import type { IContext2d, MaybePromise, @@ -14,12 +13,9 @@ import type { IGlobal } from '../../../interface'; import { findNextGraphic, foreach } from '../../../common/sort'; -// eslint-disable-next-line @typescript-eslint/consistent-type-imports -import { ContributionProvider } from '../../../common/contribution-provider'; import { DefaultAttribute } from '../../../graphic/config'; import type { IAABBBounds, IBounds, IMatrix } from '@visactor/vutils'; import { Bounds, Logger, getRectIntersect, isArray, isRectIntersect } from '@visactor/vutils'; -import { container } from '../../../container'; import { GraphicRender, IncrementalDrawContribution } from './symbol'; import { DrawItemInterceptor } from './draw-interceptor'; import { createColor } from '../../../common/canvas-utils'; @@ -27,11 +23,11 @@ import type { ILayerService } from '../../../interface/core'; import { boundsAllocate } from '../../../allocator/bounds-allocate'; import { matrixAllocate } from '../../../allocator/matrix-allocate'; import { application } from '../../../application'; +import { contributionRegistry, serviceRegistry } from '../../../common/registry'; /** * 默认的渲染contribution,基于树状结构针对图元的渲染 */ -@injectable() export class DefaultDrawContribution implements IDrawContribution { declare currentRenderMap: Map; declare defaultRenderMap: Map; @@ -48,17 +44,21 @@ export class DefaultDrawContribution implements IDrawContribution { declare scrollMatrix?: IMatrix; + protected readonly contributions: IGraphicRender[]; + protected readonly drawItemInterceptorContributions: IContributionProvider; + constructor( - // @inject(ContributionProvider) - // @named(GraphicRender) - // protected readonly contributions: ContributionProvider, - @multiInject(GraphicRender) protected readonly contributions: IGraphicRender[], - // @inject(RenderSelector) protected readonly renderSelector: IRenderSelector, // 根据图元类型选择对应的renderItem进行渲染 - // 拦截器 - @inject(ContributionProvider) - @named(DrawItemInterceptor) - protected readonly drawItemInterceptorContributions: IContributionProvider + contributions?: IGraphicRender[], + drawItemInterceptorContributions?: IContributionProvider ) { + // 如果没有传入,则使用 registry 获取 + this.contributions = contributions || contributionRegistry.get(GraphicRender); + this.drawItemInterceptorContributions = + drawItemInterceptorContributions || + ({ + getContributions: () => contributionRegistry.get(DrawItemInterceptor) + } as IContributionProvider); + this.currentRenderMap = new Map(); this.defaultRenderMap = new Map(); this.styleRenderMap = new Map(); @@ -67,7 +67,7 @@ export class DefaultDrawContribution implements IDrawContribution { this.global = application.global; this.layerService = application.layerService; if (!isArray(this.contributions)) { - this.contributions = [this.contributions]; + (this as any).contributions = [this.contributions]; } this.init(); } @@ -303,7 +303,7 @@ export class DefaultDrawContribution implements IDrawContribution { } // 渲染 const incrementalContext = incrementalLayer.layer.getNativeHandler().getContext(); - const idc = incrementalLayer.drawContribution || container.get(IncrementalDrawContribution); + const idc = incrementalLayer.drawContribution || serviceRegistry.get(IncrementalDrawContribution); idc.dirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity); idc.backupDirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity); (idc as any).draw(this.currentRenderService, { diff --git a/packages/vrender-core/src/render/contributions/render/draw-interceptor.ts b/packages/vrender-core/src/render/contributions/render/draw-interceptor.ts index 7dbe9ce4b..a7dfb1b01 100644 --- a/packages/vrender-core/src/render/contributions/render/draw-interceptor.ts +++ b/packages/vrender-core/src/render/contributions/render/draw-interceptor.ts @@ -1,4 +1,3 @@ -import { injectable } from '../../../common/inversify-lite'; import { AABBBounds } from '@visactor/vutils'; import { mat3Tomat4, multiplyMat4Mat4 } from '../../../common/matrix'; import { graphicCreator } from '../../../graphic/graphic-creator'; @@ -168,7 +167,6 @@ export class DebugDrawItemInterceptorContribution implements IDrawItemIntercepto } } -@injectable() export class CommonDrawItemInterceptorContribution implements IDrawItemInterceptorContribution { order: number = 1; interceptors: IDrawItemInterceptorContribution[]; diff --git a/packages/vrender-core/src/render/contributions/render/glyph-module.ts b/packages/vrender-core/src/render/contributions/render/glyph-module.ts deleted file mode 100644 index 3bda8a23d..000000000 --- a/packages/vrender-core/src/render/contributions/render/glyph-module.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ContainerModule } from '../../../common/inversify'; -import { DefaultCanvasGlyphRender } from './glyph-render'; -import { GlyphRender, GraphicRender } from './symbol'; - -let loadGlyphModule = false; -export const glyphModule = new ContainerModule(bind => { - if (loadGlyphModule) { - return; - } - loadGlyphModule = true; - // glyph渲染器 - bind(GlyphRender).to(DefaultCanvasGlyphRender).inSingletonScope(); - bind(GraphicRender).toService(GlyphRender); -}); diff --git a/packages/vrender-core/src/render/contributions/render/glyph-render.ts b/packages/vrender-core/src/render/contributions/render/glyph-render.ts index 33381aa60..53213ae49 100644 --- a/packages/vrender-core/src/render/contributions/render/glyph-render.ts +++ b/packages/vrender-core/src/render/contributions/render/glyph-render.ts @@ -1,4 +1,3 @@ -import { injectable } from '../../../common/inversify-lite'; import { getTheme } from '../../../graphic/theme'; import { GLYPH_NUMBER_TYPE } from '../../../graphic/constants'; import type { @@ -13,7 +12,6 @@ import type { IGraphicRenderDrawParams } from '../../../interface'; -@injectable() export class DefaultCanvasGlyphRender implements IGraphicRender { type: 'glyph'; numberType: number = GLYPH_NUMBER_TYPE; diff --git a/packages/vrender-core/src/render/contributions/render/graphic-render.ts b/packages/vrender-core/src/render/contributions/render/graphic-render.ts index 92ff262b4..989c4dbf8 100644 --- a/packages/vrender-core/src/render/contributions/render/graphic-render.ts +++ b/packages/vrender-core/src/render/contributions/render/graphic-render.ts @@ -1,7 +1,5 @@ -import { injectable } from '../../../common/inversify-lite'; import type { IGraphic, IGraphicRender, IRenderService } from '../../../interface'; -@injectable() export abstract class AbstractGraphicRender implements IGraphicRender { type: string; // 图元类型 numberType: number; diff --git a/packages/vrender-core/src/render/contributions/render/group-render.ts b/packages/vrender-core/src/render/contributions/render/group-render.ts index c74f08d7c..faff6fe8e 100644 --- a/packages/vrender-core/src/render/contributions/render/group-render.ts +++ b/packages/vrender-core/src/render/contributions/render/group-render.ts @@ -1,4 +1,3 @@ -import { inject, injectable, named } from '../../../common/inversify-lite'; import type { IGraphicAttribute, IContext2d, @@ -16,8 +15,6 @@ import type { import { getTheme } from '../../../graphic/theme'; import { getModelMatrix } from '../../../graphic/graphic-service/graphic-service'; import { isArray } from '@visactor/vutils'; -// eslint-disable-next-line @typescript-eslint/consistent-type-imports -import { ContributionProvider } from '../../../common/contribution-provider'; import { createRectPath } from '../../../common/shape/rect'; import { rectFillVisible, rectStrokeVisible, runFill, runStroke } from './utils'; import { GroupRenderContribution } from './contributions/constants'; @@ -27,19 +24,23 @@ import { BaseRenderContributionTime } from '../../../common/enums'; import { defaultGroupBackgroundRenderContribution } from './contributions'; import { multiplyMat4Mat4 } from '../../../common/matrix'; import { application } from '../../../application'; +import { contributionRegistry } from '../../../common/registry'; -@injectable() export class DefaultCanvasGroupRender implements IGraphicRender { type: 'group'; numberType: number = GROUP_NUMBER_TYPE; _groupRenderContribitions: IGroupRenderContribution[]; - - constructor( - @inject(ContributionProvider) - @named(GroupRenderContribution) - protected readonly groupRenderContribitions: IContributionProvider - ) {} + protected readonly groupRenderContribitions: IContributionProvider; + + constructor(groupRenderContribitions?: IContributionProvider) { + // 如果没有传入,则使用 registry 获取 + this.groupRenderContribitions = + groupRenderContribitions || + ({ + getContributions: () => contributionRegistry.get(GroupRenderContribution) + } as IContributionProvider); + } reInit() { this._groupRenderContribitions = this.groupRenderContribitions.getContributions() || []; diff --git a/packages/vrender-core/src/render/contributions/render/image-module.ts b/packages/vrender-core/src/render/contributions/render/image-module.ts deleted file mode 100644 index 51e57ac6f..000000000 --- a/packages/vrender-core/src/render/contributions/render/image-module.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { bindContributionProvider } from '../../../common/contribution-provider'; -import { ContainerModule } from '../../../common/inversify'; -import { DefaultBaseInteractiveRenderContribution } from './contributions'; -import { ImageRenderContribution } from './contributions/constants'; -import { DefaultCanvasImageRender } from './image-render'; -import { GraphicRender, ImageRender } from './symbol'; - -let loadImageModule = false; -export const imageModule = new ContainerModule(bind => { - if (loadImageModule) { - return; - } - loadImageModule = true; - // image渲染器 - bind(ImageRender).to(DefaultCanvasImageRender).inSingletonScope(); - bind(GraphicRender).toService(ImageRender); - bind(ImageRenderContribution).toService(DefaultBaseInteractiveRenderContribution); - // image 渲染器注入contributions - bindContributionProvider(bind, ImageRenderContribution); -}); diff --git a/packages/vrender-core/src/render/contributions/render/image-render.ts b/packages/vrender-core/src/render/contributions/render/image-render.ts index 83c4cac25..db9c5fa33 100644 --- a/packages/vrender-core/src/render/contributions/render/image-render.ts +++ b/packages/vrender-core/src/render/contributions/render/image-render.ts @@ -1,6 +1,3 @@ -import { inject, injectable, named } from '../../../common/inversify-lite'; -// eslint-disable-next-line @typescript-eslint/consistent-type-imports -import { ContributionProvider } from '../../../common/contribution-provider'; import { getTheme } from '../../../graphic/theme'; import type { IGraphicAttribute, @@ -24,22 +21,25 @@ import { createRectPath } from '../../../common/shape/rect'; import { BaseRender } from './base-render'; import { defaultImageBackgroundRenderContribution, defaultImageRenderContribution } from './contributions'; import { ResourceLoader } from '../../../resource-loader/loader'; +import { contributionRegistry } from '../../../common/registry'; const repeatStr = ['', 'repeat-x', 'repeat-y', 'repeat']; -@injectable() export class DefaultCanvasImageRender extends BaseRender implements IGraphicRender { type: 'image'; numberType: number = IMAGE_NUMBER_TYPE; - constructor( - @inject(ContributionProvider) - @named(ImageRenderContribution) - protected readonly graphicRenderContributions: IContributionProvider - ) { + protected readonly graphicRenderContributions: IContributionProvider; + + constructor(graphicRenderContributions?: IContributionProvider) { super(); + this.graphicRenderContributions = + graphicRenderContributions || + ({ + getContributions: () => contributionRegistry.get(ImageRenderContribution) + } as IContributionProvider); this.builtinContributions = [defaultImageRenderContribution, defaultImageBackgroundRenderContribution]; - this.init(graphicRenderContributions); + this.init(this.graphicRenderContributions); } drawShape( diff --git a/packages/vrender-core/src/render/contributions/render/incremental-area-render.ts b/packages/vrender-core/src/render/contributions/render/incremental-area-render.ts index f83c98de1..17e713671 100644 --- a/packages/vrender-core/src/render/contributions/render/incremental-area-render.ts +++ b/packages/vrender-core/src/render/contributions/render/incremental-area-render.ts @@ -1,4 +1,3 @@ -import { injectable } from '../../../common/inversify-lite'; import type { IArea, IAreaGraphicAttribute, @@ -21,7 +20,6 @@ import { drawIncrementalAreaSegments } from '../../../common/render-curve'; * 默认的基于canvas的line渲染器 * 单例 */ -@injectable() export class DefaultIncrementalCanvasAreaRender extends DefaultCanvasAreaRender implements IGraphicRender { declare type: 'area'; numberType: number = AREA_NUMBER_TYPE; diff --git a/packages/vrender-core/src/render/contributions/render/incremental-draw-contribution.ts b/packages/vrender-core/src/render/contributions/render/incremental-draw-contribution.ts index f28c604ae..1eef3c0b9 100644 --- a/packages/vrender-core/src/render/contributions/render/incremental-draw-contribution.ts +++ b/packages/vrender-core/src/render/contributions/render/incremental-draw-contribution.ts @@ -1,4 +1,3 @@ -import { injectable, inject, named, multiInject } from '../../../common/inversify-lite'; import type { IGraphic, IGroup, @@ -16,9 +15,8 @@ import { GraphicRender } from './symbol'; import { DefaultIncrementalCanvasLineRender } from './incremental-line-render'; import { DefaultIncrementalCanvasAreaRender } from './incremental-area-render'; import { DrawItemInterceptor } from './draw-interceptor'; -// eslint-disable-next-line @typescript-eslint/consistent-type-imports -import { ContributionProvider } from '../../../common/contribution-provider'; import { foreachAsync } from '../../../common/sort'; +import { contributionRegistry } from '../../../common/registry'; enum STATUS { NORMAL = 0, @@ -29,7 +27,6 @@ enum STATUS { * 增量渲染的contribution,基于树状结构针对图元的渲染 * 不是单例模式 */ -@injectable() export class DefaultIncrementalDrawContribution extends DefaultDrawContribution implements IDrawContribution { rendering: boolean = false; protected currFrameStartAt: number = 0; @@ -43,20 +40,24 @@ export class DefaultIncrementalDrawContribution extends DefaultDrawContribution protected lastDrawContext: IDrawContext; protected count: number; + protected readonly lineRender: IGraphicRender; + protected readonly areaRender: IGraphicRender; + constructor( - // @inject(ContributionProvider) - // @named(GraphicRender) - // protected readonly contributions: ContributionProvider, - @multiInject(GraphicRender) protected readonly contributions: IGraphicRender[], - // @inject(RenderSelector) protected readonly renderSelector: IRenderSelector, // 根据图元类型选择对应的renderItem进行渲染 - @inject(DefaultIncrementalCanvasLineRender) protected readonly lineRender: IGraphicRender, // 默认的lineRender - @inject(DefaultIncrementalCanvasAreaRender) protected readonly areaRender: IGraphicRender, // 默认的lineRender - // 拦截器 - @inject(ContributionProvider) - @named(DrawItemInterceptor) - protected readonly drawItemInterceptorContributions: IContributionProvider + contributions?: IGraphicRender[], + lineRender?: IGraphicRender, + areaRender?: IGraphicRender, + drawItemInterceptorContributions?: IContributionProvider ) { - super(contributions, drawItemInterceptorContributions); + const defaultContributions = contributions || contributionRegistry.get(GraphicRender); + const defaultDrawItemInterceptor = + drawItemInterceptorContributions || + ({ + getContributions: () => contributionRegistry.get(DrawItemInterceptor) + } as IContributionProvider); + super(defaultContributions, defaultDrawItemInterceptor); + this.lineRender = lineRender || new DefaultIncrementalCanvasLineRender(); + this.areaRender = areaRender || new DefaultIncrementalCanvasAreaRender(); this.defaultRenderMap.set(this.lineRender.numberType, this.lineRender); this.defaultRenderMap.set(this.areaRender.numberType, this.areaRender); } diff --git a/packages/vrender-core/src/render/contributions/render/incremental-line-render.ts b/packages/vrender-core/src/render/contributions/render/incremental-line-render.ts index bfcfaa174..b8c146eb8 100644 --- a/packages/vrender-core/src/render/contributions/render/incremental-line-render.ts +++ b/packages/vrender-core/src/render/contributions/render/incremental-line-render.ts @@ -1,4 +1,3 @@ -import { injectable } from '../../../common/inversify-lite'; import type { IContext2d, ILine, @@ -21,7 +20,6 @@ import { drawIncrementalSegments } from '../../../common/render-curve'; * 默认的基于canvas的line渲染器 * 单例 */ -@injectable() export class DefaultIncrementalCanvasLineRender extends DefaultCanvasLineRender implements IGraphicRender { declare type: 'line'; numberType: number = LINE_NUMBER_TYPE; diff --git a/packages/vrender-core/src/render/contributions/render/line-module.ts b/packages/vrender-core/src/render/contributions/render/line-module.ts deleted file mode 100644 index 91aaa3c2e..000000000 --- a/packages/vrender-core/src/render/contributions/render/line-module.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { ContainerModule } from '../../../common/inversify'; -import { DefaultIncrementalCanvasLineRender } from './incremental-line-render'; -import { DefaultCanvasLineRender } from './line-render'; -import { GraphicRender, LineRender } from './symbol'; - -let loadLineModule = false; -export const lineModule = new ContainerModule(bind => { - if (loadLineModule) { - return; - } - loadLineModule = true; - // line渲染器 - bind(DefaultCanvasLineRender).toSelf().inSingletonScope(); - bind(DefaultIncrementalCanvasLineRender).toSelf().inSingletonScope(); - bind(LineRender).to(DefaultCanvasLineRender).inSingletonScope(); - bind(GraphicRender).toService(LineRender); -}); diff --git a/packages/vrender-core/src/render/contributions/render/line-render.ts b/packages/vrender-core/src/render/contributions/render/line-render.ts index 55ba43608..ba08b091e 100644 --- a/packages/vrender-core/src/render/contributions/render/line-render.ts +++ b/packages/vrender-core/src/render/contributions/render/line-render.ts @@ -1,6 +1,5 @@ import type { IPointLike } from '@visactor/vutils'; import { min, isArray } from '@visactor/vutils'; -import { injectable } from '../../../common/inversify-lite'; import type { IContext2d, ILine, @@ -25,7 +24,6 @@ import { calcLineCache } from '../../../common/segment'; * 默认的基于canvas的line渲染器 * 单例 */ -@injectable() export class DefaultCanvasLineRender extends BaseRender implements IGraphicRender { type: 'line'; numberType: number = LINE_NUMBER_TYPE; diff --git a/packages/vrender-core/src/render/contributions/render/module.ts b/packages/vrender-core/src/render/contributions/render/module.ts deleted file mode 100644 index d3d02cffb..000000000 --- a/packages/vrender-core/src/render/contributions/render/module.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { ContainerModule } from '../../../common/inversify-lite'; -import { bindContributionProvider } from '../../../common/contribution-provider'; -import { DefaultDrawContribution } from './draw-contribution'; -import { DefaultCanvasGroupRender } from './group-render'; -import { DefaultIncrementalDrawContribution } from './incremental-draw-contribution'; -import { DrawContribution, GraphicRender, GroupRender, IncrementalDrawContribution, RenderSelector } from './symbol'; -import { CommonDrawItemInterceptorContribution, DrawItemInterceptor } from './draw-interceptor'; -import { GroupRenderContribution, InteractiveSubRenderContribution } from './contributions/constants'; -import { - DefaultBaseBackgroundRenderContribution, - DefaultBaseInteractiveRenderContribution, - DefaultBaseTextureRenderContribution -} from './contributions'; - -export default new ContainerModule(bind => { - bind(DefaultBaseBackgroundRenderContribution).toSelf().inSingletonScope(); - bind(DefaultBaseTextureRenderContribution).toSelf().inSingletonScope(); - - bind(DrawContribution).to(DefaultDrawContribution); - bind(IncrementalDrawContribution).to(DefaultIncrementalDrawContribution); - - // bind(RenderSelector).to(DefaultRenderSelector).inSingletonScope(); - - // group渲染器 - bind(GroupRender).to(DefaultCanvasGroupRender).inSingletonScope(); - bind(GraphicRender).toService(GroupRender); - - // group 渲染器注入contributions - bindContributionProvider(bind, GroupRenderContribution); - - // 绑定通用interactive contribution - bind(DefaultBaseInteractiveRenderContribution).toSelf().inSingletonScope(); - bindContributionProvider(bind, InteractiveSubRenderContribution); - bindContributionProvider(bind, GraphicRender); - - // interceptor - // bind(ShadowRootDrawItemInterceptorContribution).toSelf().inSingletonScope(); - // bind(DrawItemInterceptor).toService(ShadowRootDrawItemInterceptorContribution); - bind(CommonDrawItemInterceptorContribution).toSelf().inSingletonScope(); - bind(DrawItemInterceptor).toService(CommonDrawItemInterceptorContribution); - // bind(RenderSelector).toService() - // bind(Canvas3DDrawItemInterceptor).toSelf().inSingletonScope(); - // bind(DrawItemInterceptor).toService(Canvas3DDrawItemInterceptor); - // bind(InteractiveDrawItemInterceptorContribution).toSelf().inSingletonScope(); - // bind(DrawItemInterceptor).toService(InteractiveDrawItemInterceptorContribution); - bindContributionProvider(bind, DrawItemInterceptor); -}); diff --git a/packages/vrender-core/src/render/contributions/render/path-module.ts b/packages/vrender-core/src/render/contributions/render/path-module.ts deleted file mode 100644 index 1aaf45475..000000000 --- a/packages/vrender-core/src/render/contributions/render/path-module.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { bindContributionProvider } from '../../../common/contribution-provider'; -import { ContainerModule } from '../../../common/inversify'; -import { DefaultBaseInteractiveRenderContribution } from './contributions'; -import { PathRenderContribution } from './contributions/constants'; -import { DefaultCanvasPathRender } from './path-render'; -import { GraphicRender, PathRender } from './symbol'; - -let loadPathModule = false; -export const pathModule = new ContainerModule(bind => { - if (loadPathModule) { - return; - } - loadPathModule = true; - // path 渲染器 - bind(DefaultCanvasPathRender).toSelf().inSingletonScope(); - bind(PathRender).to(DefaultCanvasPathRender).inSingletonScope(); - bind(GraphicRender).toService(PathRender); - bind(PathRenderContribution).toService(DefaultBaseInteractiveRenderContribution); - - // path 渲染器注入contributions - bindContributionProvider(bind, PathRenderContribution); -}); diff --git a/packages/vrender-core/src/render/contributions/render/path-render.ts b/packages/vrender-core/src/render/contributions/render/path-render.ts index 974b8807f..3bac88ca8 100644 --- a/packages/vrender-core/src/render/contributions/render/path-render.ts +++ b/packages/vrender-core/src/render/contributions/render/path-render.ts @@ -1,6 +1,3 @@ -import { inject, injectable, named } from '../../../common/inversify-lite'; -// eslint-disable-next-line @typescript-eslint/consistent-type-imports -import { ContributionProvider } from '../../../common/contribution-provider'; import { renderCommandList } from '../../../common/render-command-list'; import type { IPath, @@ -25,21 +22,24 @@ import { defaultPathBackgroundRenderContribution, defaultPathTextureRenderContribution } from './contributions/path-contribution-render'; +import { contributionRegistry } from '../../../common/registry'; -@injectable() export class DefaultCanvasPathRender extends BaseRender implements IGraphicRender { type: 'path'; numberType: number = PATH_NUMBER_TYPE; tempTheme: Required; - constructor( - @inject(ContributionProvider) - @named(PathRenderContribution) - protected readonly graphicRenderContributions: IContributionProvider - ) { + protected readonly graphicRenderContributions: IContributionProvider; + + constructor(graphicRenderContributions?: IContributionProvider) { super(); + this.graphicRenderContributions = + graphicRenderContributions || + ({ + getContributions: () => contributionRegistry.get(PathRenderContribution) + } as IContributionProvider); this.builtinContributions = [defaultPathBackgroundRenderContribution, defaultPathTextureRenderContribution]; - this.init(graphicRenderContributions); + this.init(this.graphicRenderContributions); } drawShape( diff --git a/packages/vrender-core/src/render/contributions/render/polygon-module.ts b/packages/vrender-core/src/render/contributions/render/polygon-module.ts deleted file mode 100644 index a97b0cc38..000000000 --- a/packages/vrender-core/src/render/contributions/render/polygon-module.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { bindContributionProvider } from '../../../common/contribution-provider'; -import { ContainerModule } from '../../../common/inversify'; -import { DefaultBaseInteractiveRenderContribution } from './contributions'; -import { PathRenderContribution, PolygonRenderContribution } from './contributions/constants'; -import { DefaultCanvasPathRender } from './path-render'; -import { DefaultCanvasPolygonRender } from './polygon-render'; -import { GraphicRender, PathRender, PolygonRender } from './symbol'; - -let loadPolygonModule = false; -export const polygonModule = new ContainerModule(bind => { - if (loadPolygonModule) { - return; - } - loadPolygonModule = true; - // polygon渲染器 - bind(PolygonRender).to(DefaultCanvasPolygonRender).inSingletonScope(); - bind(GraphicRender).toService(PolygonRender); - bind(PolygonRenderContribution).toService(DefaultBaseInteractiveRenderContribution); - - // polygon 渲染器注入contributions - bindContributionProvider(bind, PolygonRenderContribution); -}); diff --git a/packages/vrender-core/src/render/contributions/render/polygon-render.ts b/packages/vrender-core/src/render/contributions/render/polygon-render.ts index eeb15856f..269e09a5f 100644 --- a/packages/vrender-core/src/render/contributions/render/polygon-render.ts +++ b/packages/vrender-core/src/render/contributions/render/polygon-render.ts @@ -1,5 +1,4 @@ import { isArray } from '@visactor/vutils'; -import { inject, injectable, named } from '../../../common/inversify-lite'; import { getTheme } from '../../../graphic/theme'; import { POLYGON_NUMBER_TYPE } from '../../../graphic/constants'; import type { @@ -17,27 +16,28 @@ import type { } from '../../../interface'; import { drawPolygon, drawRoundedPolygon } from '../../../common/polygon'; import { PolygonRenderContribution } from './contributions/constants'; -// eslint-disable-next-line @typescript-eslint/consistent-type-imports -import { ContributionProvider } from '../../../common/contribution-provider'; import { BaseRender } from './base-render'; import { defaultPolygonBackgroundRenderContribution, defaultPolygonTextureRenderContribution } from './contributions/polygon-contribution-render'; +import { contributionRegistry } from '../../../common/registry'; -@injectable() export class DefaultCanvasPolygonRender extends BaseRender implements IGraphicRender { type: 'polygon'; numberType: number = POLYGON_NUMBER_TYPE; - constructor( - @inject(ContributionProvider) - @named(PolygonRenderContribution) - protected readonly graphicRenderContributions: IContributionProvider - ) { + protected readonly graphicRenderContributions: IContributionProvider; + + constructor(graphicRenderContributions?: IContributionProvider) { super(); + this.graphicRenderContributions = + graphicRenderContributions || + ({ + getContributions: () => contributionRegistry.get(PolygonRenderContribution) + } as IContributionProvider); this.builtinContributions = [defaultPolygonBackgroundRenderContribution, defaultPolygonTextureRenderContribution]; - this.init(graphicRenderContributions); + this.init(this.graphicRenderContributions); } drawShape( diff --git a/packages/vrender-core/src/render/contributions/render/pyramid3d-module.ts b/packages/vrender-core/src/render/contributions/render/pyramid3d-module.ts deleted file mode 100644 index 522c70281..000000000 --- a/packages/vrender-core/src/render/contributions/render/pyramid3d-module.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ContainerModule } from '../../../common/inversify'; -import { DefaultCanvasPyramid3dRender } from './pyramid3d-render'; -import { GraphicRender, Pyramid3dRender, Rect3DRender } from './symbol'; - -let loadPyramid3dModule = false; -export const pyramid3dModule = new ContainerModule(bind => { - if (loadPyramid3dModule) { - return; - } - loadPyramid3dModule = true; - // pyramid3d 渲染器 - bind(Pyramid3dRender).to(DefaultCanvasPyramid3dRender).inSingletonScope(); - bind(GraphicRender).toService(Pyramid3dRender); -}); diff --git a/packages/vrender-core/src/render/contributions/render/pyramid3d-render.ts b/packages/vrender-core/src/render/contributions/render/pyramid3d-render.ts index 56b0b13fd..6dec1c36c 100644 --- a/packages/vrender-core/src/render/contributions/render/pyramid3d-render.ts +++ b/packages/vrender-core/src/render/contributions/render/pyramid3d-render.ts @@ -1,4 +1,3 @@ -import { injectable } from '../../../common/inversify-lite'; import { getTheme } from '../../../graphic/theme'; import { PYRAMID3D_NUMBER_TYPE } from '../../../graphic/constants'; import type { @@ -14,7 +13,6 @@ import type { } from '../../../interface'; import { Base3dRender } from './base-3d-render'; -@injectable() export class DefaultCanvasPyramid3dRender extends Base3dRender implements IGraphicRender { type = 'pyramid3d'; numberType: number = PYRAMID3D_NUMBER_TYPE; diff --git a/packages/vrender-core/src/render/contributions/render/rect-module.ts b/packages/vrender-core/src/render/contributions/render/rect-module.ts deleted file mode 100644 index 5a4aa25c8..000000000 --- a/packages/vrender-core/src/render/contributions/render/rect-module.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { bindContributionProvider } from '../../../common/contribution-provider'; -import { ContainerModule } from '../../../common/inversify'; -import { DefaultCanvasArcRender } from './arc-render'; -import { - DefaultBaseInteractiveRenderContribution, - SplitRectAfterRenderContribution, - SplitRectBeforeRenderContribution -} from './contributions'; -import { ArcRenderContribution, RectRenderContribution } from './contributions/constants'; -import { DefaultCanvasRectRender } from './rect-render'; -import { ArcRender, GraphicRender, RectRender } from './symbol'; - -let loadRectModule = false; -export const rectModule = new ContainerModule(bind => { - if (loadRectModule) { - return; - } - loadRectModule = true; - // rect 渲染器 - bind(DefaultCanvasRectRender).toSelf().inSingletonScope(); - bind(RectRender).to(DefaultCanvasRectRender).inSingletonScope(); - bind(GraphicRender).toService(RectRender); - bind(SplitRectAfterRenderContribution).toSelf(); - bind(SplitRectBeforeRenderContribution).toSelf(); - bind(RectRenderContribution).toService(SplitRectAfterRenderContribution); - bind(RectRenderContribution).toService(SplitRectBeforeRenderContribution); - bind(RectRenderContribution).toService(DefaultBaseInteractiveRenderContribution); - // rect 渲染器注入contributions - bindContributionProvider(bind, RectRenderContribution); -}); diff --git a/packages/vrender-core/src/render/contributions/render/rect-render.ts b/packages/vrender-core/src/render/contributions/render/rect-render.ts index 156bf7038..f9929213e 100644 --- a/packages/vrender-core/src/render/contributions/render/rect-render.ts +++ b/packages/vrender-core/src/render/contributions/render/rect-render.ts @@ -1,10 +1,7 @@ import { isArray } from '@visactor/vutils'; -import { inject, injectable, named } from '../../../common/inversify-lite'; import { getTheme } from '../../../graphic/theme'; import { RECT_NUMBER_TYPE } from '../../../graphic/constants'; import { createRectPath } from '../../../common/shape/rect'; -// eslint-disable-next-line @typescript-eslint/consistent-type-imports -import { ContributionProvider } from '../../../common/contribution-provider'; import type { IGraphicAttribute, IContext2d, @@ -27,25 +24,28 @@ import { defaultRectRenderContribution, defaultRectTextureRenderContribution } from './contributions'; +import { contributionRegistry } from '../../../common/registry'; -@injectable() export class DefaultCanvasRectRender extends BaseRender implements IGraphicRender { type = 'rect'; numberType: number = RECT_NUMBER_TYPE; tempTheme: Required; - constructor( - @inject(ContributionProvider) - @named(RectRenderContribution) - protected readonly graphicRenderContributions: IContributionProvider - ) { + protected readonly graphicRenderContributions: IContributionProvider; + + constructor(graphicRenderContributions?: IContributionProvider) { super(); + this.graphicRenderContributions = + graphicRenderContributions || + ({ + getContributions: () => contributionRegistry.get(RectRenderContribution) + } as IContributionProvider); this.builtinContributions = [ defaultRectRenderContribution, defaultRectBackgroundRenderContribution, defaultRectTextureRenderContribution ]; - this.init(graphicRenderContributions); + this.init(this.graphicRenderContributions); } drawShape( diff --git a/packages/vrender-core/src/render/contributions/render/rect3d-module.ts b/packages/vrender-core/src/render/contributions/render/rect3d-module.ts deleted file mode 100644 index 9bb294506..000000000 --- a/packages/vrender-core/src/render/contributions/render/rect3d-module.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ContainerModule } from '../../../common/inversify'; -import { DefaultCanvasRect3dRender } from './rect3d-render'; -import { GraphicRender, Rect3DRender } from './symbol'; - -let loadRect3dModule = false; -export const rect3dModule = new ContainerModule(bind => { - if (loadRect3dModule) { - return; - } - loadRect3dModule = true; - // rect3d 渲染器 - bind(Rect3DRender).to(DefaultCanvasRect3dRender).inSingletonScope(); - bind(GraphicRender).toService(Rect3DRender); -}); diff --git a/packages/vrender-core/src/render/contributions/render/rect3d-render.ts b/packages/vrender-core/src/render/contributions/render/rect3d-render.ts index 434c417d5..055eb2ffb 100644 --- a/packages/vrender-core/src/render/contributions/render/rect3d-render.ts +++ b/packages/vrender-core/src/render/contributions/render/rect3d-render.ts @@ -1,4 +1,3 @@ -import { injectable } from '../../../common/inversify-lite'; import { getTheme } from '../../../graphic/theme'; import type { IGraphicAttribute, @@ -15,7 +14,7 @@ import type { import { rectFillVisible, rectStrokeVisible, runFill, runStroke } from './utils'; import { RECT3D_NUMBER_TYPE } from '../../../graphic/constants'; import { Base3dRender } from './base-3d-render'; -@injectable() + export class DefaultCanvasRect3dRender extends Base3dRender implements IGraphicRender { type = 'rect3d'; numberType: number = RECT3D_NUMBER_TYPE; diff --git a/packages/vrender-core/src/render/contributions/render/richtext-module.ts b/packages/vrender-core/src/render/contributions/render/richtext-module.ts deleted file mode 100644 index 96e90c2d5..000000000 --- a/packages/vrender-core/src/render/contributions/render/richtext-module.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ContainerModule } from '../../../common/inversify'; -import { DefaultCanvasRichTextRender } from './richtext-render'; -import { GraphicRender, RichTextRender } from './symbol'; - -let loadRichtextModule = false; -export const richtextModule = new ContainerModule(bind => { - if (loadRichtextModule) { - return; - } - loadRichtextModule = true; - // richtext渲染器 - bind(RichTextRender).to(DefaultCanvasRichTextRender).inSingletonScope(); - bind(GraphicRender).toService(RichTextRender); -}); diff --git a/packages/vrender-core/src/render/contributions/render/richtext-render.ts b/packages/vrender-core/src/render/contributions/render/richtext-render.ts index 2bcc943e9..8f6a1c2bf 100644 --- a/packages/vrender-core/src/render/contributions/render/richtext-render.ts +++ b/packages/vrender-core/src/render/contributions/render/richtext-render.ts @@ -1,4 +1,3 @@ -import { injectable } from '../../../common/inversify-lite'; import { createRectPath } from '../../../common/shape/rect'; import { getTheme } from '../../../graphic/theme'; import { RICHTEXT_NUMBER_TYPE } from '../../../graphic/constants'; @@ -14,7 +13,6 @@ import { fillVisible } from './utils'; import { BaseRender } from './base-render'; import { defaultTextBackgroundRenderContribution } from './contributions/text-contribution-render'; -@injectable() export class DefaultCanvasRichTextRender extends BaseRender implements IGraphicRender { type: 'richtext'; numberType: number = RICHTEXT_NUMBER_TYPE; diff --git a/packages/vrender-core/src/render/contributions/render/star-module.ts b/packages/vrender-core/src/render/contributions/render/star-module.ts deleted file mode 100644 index 6082f04ab..000000000 --- a/packages/vrender-core/src/render/contributions/render/star-module.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ContainerModule } from '../../../common/inversify'; -import { DefaultCanvasStarRender } from './star-render'; -import { GraphicRender, StarRender } from './symbol'; - -let loadStarModule = false; -export const starModule = new ContainerModule(bind => { - if (loadStarModule) { - return; - } - loadStarModule = true; - // Star renderer - bind(StarRender).to(DefaultCanvasStarRender).inSingletonScope(); - bind(GraphicRender).toService(StarRender); -}); diff --git a/packages/vrender-core/src/render/contributions/render/star-render.ts b/packages/vrender-core/src/render/contributions/render/star-render.ts index cfa257a7e..9a9ae3534 100644 --- a/packages/vrender-core/src/render/contributions/render/star-render.ts +++ b/packages/vrender-core/src/render/contributions/render/star-render.ts @@ -1,5 +1,4 @@ import { isArray } from '@visactor/vutils'; -import { inject, injectable, named } from '../../../common/inversify-lite'; import { getTheme } from '../../../graphic/theme'; import { STAR_NUMBER_TYPE } from '../../../graphic/constants'; import type { @@ -16,24 +15,25 @@ import type { IStarRenderContribution } from '../../../interface'; import { StarRenderContribution } from './contributions/constants'; -// eslint-disable-next-line @typescript-eslint/consistent-type-imports -import { ContributionProvider } from '../../../common/contribution-provider'; import { BaseRender } from './base-render'; import { defaultStarBackgroundRenderContribution, defaultStarTextureRenderContribution } from './contributions'; +import { contributionRegistry } from '../../../common/registry'; -@injectable() export class DefaultCanvasStarRender extends BaseRender implements IGraphicRender { type: 'star'; numberType: number = STAR_NUMBER_TYPE; - constructor( - @inject(ContributionProvider) - @named(StarRenderContribution) - protected readonly starRenderContribitions: IContributionProvider - ) { + protected readonly starRenderContribitions: IContributionProvider; + + constructor(starRenderContribitions?: IContributionProvider) { super(); + this.starRenderContribitions = + starRenderContribitions || + ({ + getContributions: () => contributionRegistry.get(StarRenderContribution) + } as IContributionProvider); this.builtinContributions = [defaultStarBackgroundRenderContribution, defaultStarTextureRenderContribution]; - this.init(starRenderContribitions); + this.init(this.starRenderContribitions); } drawShape( diff --git a/packages/vrender-core/src/render/contributions/render/symbol-module.ts b/packages/vrender-core/src/render/contributions/render/symbol-module.ts deleted file mode 100644 index 406e1357e..000000000 --- a/packages/vrender-core/src/render/contributions/render/symbol-module.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { bindContributionProvider } from '../../../common/contribution-provider'; -import { ContainerModule } from '../../../common/inversify'; -import { DefaultBaseInteractiveRenderContribution } from './contributions'; -import { SymbolRenderContribution } from './contributions/constants'; -import { GraphicRender, SymbolRender } from './symbol'; -import { DefaultCanvasSymbolRender } from './symbol-render'; - -let loadSymbolModule = false; -export const symbolModule = new ContainerModule(bind => { - if (loadSymbolModule) { - return; - } - loadSymbolModule = true; - // symbol渲染器 - bind(DefaultCanvasSymbolRender).toSelf().inSingletonScope(); - bind(SymbolRender).to(DefaultCanvasSymbolRender).inSingletonScope(); - bind(GraphicRender).toService(SymbolRender); - bind(SymbolRenderContribution).toService(DefaultBaseInteractiveRenderContribution); - // symbol 渲染器注入contributions - bindContributionProvider(bind, SymbolRenderContribution); -}); diff --git a/packages/vrender-core/src/render/contributions/render/symbol-render.ts b/packages/vrender-core/src/render/contributions/render/symbol-render.ts index 258de80cb..4ee5cc5a3 100644 --- a/packages/vrender-core/src/render/contributions/render/symbol-render.ts +++ b/packages/vrender-core/src/render/contributions/render/symbol-render.ts @@ -1,6 +1,3 @@ -import { inject, injectable, named } from '../../../common/inversify-lite'; -// eslint-disable-next-line -import { ContributionProvider } from '../../../common/contribution-provider'; import { getTheme } from '../../../graphic/theme'; import { SYMBOL_NUMBER_TYPE } from '../../../graphic/constants'; import type { @@ -28,25 +25,28 @@ import { defaultSymbolRenderContribution, defaultSymbolTextureRenderContribution } from './contributions'; +import { contributionRegistry } from '../../../common/registry'; -@injectable() export class DefaultCanvasSymbolRender extends BaseRender implements IGraphicRender { type: 'symbol'; numberType: number = SYMBOL_NUMBER_TYPE; - constructor( - @inject(ContributionProvider) - @named(SymbolRenderContribution) - protected readonly graphicRenderContributions: IContributionProvider - ) { + protected readonly graphicRenderContributions: IContributionProvider; + + constructor(graphicRenderContributions?: IContributionProvider) { super(); + this.graphicRenderContributions = + graphicRenderContributions || + ({ + getContributions: () => contributionRegistry.get(SymbolRenderContribution) + } as IContributionProvider); this.builtinContributions = [ defaultSymbolRenderContribution, defaultSymbolBackgroundRenderContribution, defaultSymbolTextureRenderContribution, defaultSymbolClipRangeStrokeRenderContribution ]; - this.init(graphicRenderContributions); + this.init(this.graphicRenderContributions); } drawShape( diff --git a/packages/vrender-core/src/render/contributions/render/text-module.ts b/packages/vrender-core/src/render/contributions/render/text-module.ts deleted file mode 100644 index be762fd78..000000000 --- a/packages/vrender-core/src/render/contributions/render/text-module.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { bindContributionProvider } from '../../../common/contribution-provider'; -import { ContainerModule } from '../../../common/inversify'; -import { DefaultCanvasCircleRender } from './circle-render'; -import { DefaultBaseInteractiveRenderContribution } from './contributions'; -import { CircleRenderContribution, TextRenderContribution } from './contributions/constants'; -import { CircleRender, GraphicRender, TextRender } from './symbol'; -import { DefaultCanvasTextRender } from './text-render'; - -let loadTextModule = false; -export const textModule = new ContainerModule(bind => { - if (loadTextModule) { - return; - } - loadTextModule = true; - // text 渲染器 - bind(TextRender).to(DefaultCanvasTextRender).inSingletonScope(); - bind(GraphicRender).toService(TextRender); - bind(TextRenderContribution).toService(DefaultBaseInteractiveRenderContribution); - - bindContributionProvider(bind, TextRenderContribution); -}); diff --git a/packages/vrender-core/src/render/contributions/render/text-render.ts b/packages/vrender-core/src/render/contributions/render/text-render.ts index a6df7f3a6..fc6856789 100644 --- a/packages/vrender-core/src/render/contributions/render/text-render.ts +++ b/packages/vrender-core/src/render/contributions/render/text-render.ts @@ -1,4 +1,3 @@ -import { inject, injectable, named } from '../../../common/inversify-lite'; import { getTheme } from '../../../graphic/theme'; import { TEXT_NUMBER_TYPE } from '../../../graphic/constants'; import type { @@ -16,26 +15,28 @@ import type { import { textDrawOffsetX, textDrawOffsetY, textLayoutOffsetY } from '../../../common/text'; import type { IText, ITextGraphicAttribute } from '../../../interface/graphic/text'; import { BaseRender } from './base-render'; -import { ContributionProvider } from '../../../common/contribution-provider'; import { TextRenderContribution } from './contributions/constants'; import { matrixAllocate } from '../../../allocator/matrix-allocate'; import { isNil, max } from '@visactor/vutils'; import { calculateLineHeight } from '../../../common/utils'; import { defaultTextBackgroundRenderContribution } from './contributions/text-contribution-render'; +import { contributionRegistry } from '../../../common/registry'; -@injectable() export class DefaultCanvasTextRender extends BaseRender implements IGraphicRender { type: 'text'; numberType: number = TEXT_NUMBER_TYPE; - constructor( - @inject(ContributionProvider) - @named(TextRenderContribution) - protected readonly graphicRenderContributions: IContributionProvider - ) { + protected readonly graphicRenderContributions: IContributionProvider; + + constructor(graphicRenderContributions?: IContributionProvider) { super(); + this.graphicRenderContributions = + graphicRenderContributions || + ({ + getContributions: () => contributionRegistry.get(TextRenderContribution) + } as IContributionProvider); this.builtinContributions = [defaultTextBackgroundRenderContribution as any]; - this.init(graphicRenderContributions); + this.init(this.graphicRenderContributions); } drawShape( diff --git a/packages/vrender-core/src/render/render-modules.ts b/packages/vrender-core/src/render/render-modules.ts deleted file mode 100644 index cb1ce1ca7..000000000 --- a/packages/vrender-core/src/render/render-modules.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { ContainerModule } from '../common/inversify-lite'; -import { DefaultRenderService } from './render-service'; -import { RenderService } from './constants'; - -export default new ContainerModule(bind => { - bind(RenderService).to(DefaultRenderService); -}); diff --git a/packages/vrender-core/src/render/render-service.ts b/packages/vrender-core/src/render/render-service.ts index 6e7c8ca93..c2e871191 100644 --- a/packages/vrender-core/src/render/render-service.ts +++ b/packages/vrender-core/src/render/render-service.ts @@ -1,13 +1,10 @@ -import { injectable, inject } from '../common/inversify-lite'; import type { IAABBBounds, IBounds } from '@visactor/vutils'; import type { IGroup, IGraphic, IRenderService, IRenderServiceDrawParams, IDrawContribution } from '../interface'; -import { DrawContribution } from './contributions/render'; /** * 渲染用的service,通常和stage一一绑定, * 并不是单例模式,所以会绑定此次渲染的一些数据 */ -@injectable() export class DefaultRenderService implements IRenderService { // 每次render都会变的数据 dirtyBounds: IBounds; @@ -15,10 +12,7 @@ export class DefaultRenderService implements IRenderService { renderLists: IGraphic[]; drawParams: IRenderServiceDrawParams; - constructor( - @inject(DrawContribution) - public readonly drawContribution: IDrawContribution - ) {} + constructor(public readonly drawContribution: IDrawContribution) {} // 渲染前准备工作,计算bounds等逻辑 prepare(updateBounds: boolean): void { diff --git a/packages/vrender-kits/src/canvas/contributions/browser/canvas.ts b/packages/vrender-kits/src/canvas/contributions/browser/canvas.ts index 74dc91f00..0e46dcd9e 100644 --- a/packages/vrender-kits/src/canvas/contributions/browser/canvas.ts +++ b/packages/vrender-kits/src/canvas/contributions/browser/canvas.ts @@ -1,8 +1,7 @@ -import { injectable, application, BaseCanvas } from '@visactor/vrender-core'; +import { application, BaseCanvas } from '@visactor/vrender-core'; import type { CanvasConfigType, ICanvas, EnvType } from '@visactor/vrender-core'; import { BrowserContext2d } from './context'; -@injectable() export class BrowserCanvas extends BaseCanvas implements ICanvas { static env: EnvType = 'browser'; diff --git a/packages/vrender-kits/src/canvas/contributions/browser/context.ts b/packages/vrender-kits/src/canvas/contributions/browser/context.ts index acfc8be43..63cfd66d0 100644 --- a/packages/vrender-kits/src/canvas/contributions/browser/context.ts +++ b/packages/vrender-kits/src/canvas/contributions/browser/context.ts @@ -26,7 +26,6 @@ import type { IPointLike, TextMeasure, ITextMeasureSpec, IMatrix } from '@visactor/vutils'; import { Matrix, pi, pi2, Logger, getContextFont } from '@visactor/vutils'; import { - injectable, DefaultFillStyle, DefaultStrokeStyle, DefaultTextStyle, @@ -104,7 +103,6 @@ const addArcToBezierPath = ( } }; -@injectable() export class BrowserContext2d implements IContext2d { static env: EnvType = 'browser'; baseGlobalAlpha: number; diff --git a/packages/vrender-kits/src/canvas/contributions/browser/modules.ts b/packages/vrender-kits/src/canvas/contributions/browser/modules.ts index d5447123f..5de0096b7 100644 --- a/packages/vrender-kits/src/canvas/contributions/browser/modules.ts +++ b/packages/vrender-kits/src/canvas/contributions/browser/modules.ts @@ -1,5 +1,7 @@ import { BrowserCanvas } from './canvas'; import { BrowserContext2d } from './context'; -import { createModule } from '../create-canvas-module'; +import { registerCanvasFactories } from '../create-canvas-module'; -export const browserCanvasModule = createModule(BrowserCanvas, BrowserContext2d); +export function registerBrowserCanvasFactories() { + registerCanvasFactories(BrowserCanvas, BrowserContext2d); +} diff --git a/packages/vrender-kits/src/canvas/contributions/create-canvas-module.ts b/packages/vrender-kits/src/canvas/contributions/create-canvas-module.ts index fe2f6ac7c..9f827ec43 100644 --- a/packages/vrender-kits/src/canvas/contributions/create-canvas-module.ts +++ b/packages/vrender-kits/src/canvas/contributions/create-canvas-module.ts @@ -1,18 +1,15 @@ -import { ContainerModule, CanvasFactory, Context2dFactory } from '@visactor/vrender-core'; +import { application, CanvasFactory, Context2dFactory } from '@visactor/vrender-core'; import type { CanvasConfigType, ICanvas } from '@visactor/vrender-core'; -export function createModule(CanvasConstructor: any, ContextConstructor: any) { - return new ContainerModule(bind => { - bind(CanvasFactory) - .toDynamicValue(() => { - return (params: CanvasConfigType) => new CanvasConstructor(params); - }) - .whenTargetNamed(CanvasConstructor.env); +// Register canvas/context factories via application.services (no inversify) +export function registerCanvasFactories(CanvasConstructor: any, ContextConstructor: any) { + // Canvas factory + application.services.registerFactory(CanvasFactory, () => { + return (params: CanvasConfigType) => new CanvasConstructor(params); + }); - bind(Context2dFactory) - .toDynamicValue(() => { - return (params: ICanvas, dpr: number) => new ContextConstructor(params, dpr); - }) - .whenTargetNamed(ContextConstructor.env); + // Context2d factory + application.services.registerFactory(Context2dFactory, () => { + return (canvas: ICanvas, dpr: number) => new ContextConstructor(canvas, dpr); }); } diff --git a/packages/vrender-kits/src/canvas/contributions/feishu/canvas.ts b/packages/vrender-kits/src/canvas/contributions/feishu/canvas.ts index 80e5770b1..399fa7b48 100644 --- a/packages/vrender-kits/src/canvas/contributions/feishu/canvas.ts +++ b/packages/vrender-kits/src/canvas/contributions/feishu/canvas.ts @@ -1,8 +1,7 @@ -import { injectable, BaseCanvas } from '@visactor/vrender-core'; +import { BaseCanvas } from '@visactor/vrender-core'; import type { ICanvas, CanvasConfigType, EnvType } from '@visactor/vrender-core'; import { FeishuContext2d } from './context'; -@injectable() export class FeishuCanvas extends BaseCanvas implements ICanvas { static env: EnvType = 'feishu'; diff --git a/packages/vrender-kits/src/canvas/contributions/feishu/context.ts b/packages/vrender-kits/src/canvas/contributions/feishu/context.ts index fb0dac34b..d9d6339ac 100644 --- a/packages/vrender-kits/src/canvas/contributions/feishu/context.ts +++ b/packages/vrender-kits/src/canvas/contributions/feishu/context.ts @@ -1,5 +1,4 @@ // 参考konva -import { injectable } from '@visactor/vrender-core'; import type { IContext2d, EnvType } from '@visactor/vrender-core'; import { BrowserContext2d } from '../browser'; @@ -7,7 +6,6 @@ declare const tt: { canvasGetImageData: (d: any) => any; }; -@injectable() export class FeishuContext2d extends BrowserContext2d implements IContext2d { static env: EnvType = 'feishu'; diff --git a/packages/vrender-kits/src/canvas/contributions/feishu/modules.ts b/packages/vrender-kits/src/canvas/contributions/feishu/modules.ts index b7c8cc805..f43c31a73 100644 --- a/packages/vrender-kits/src/canvas/contributions/feishu/modules.ts +++ b/packages/vrender-kits/src/canvas/contributions/feishu/modules.ts @@ -1,5 +1,7 @@ import { FeishuCanvas } from './canvas'; import { FeishuContext2d } from './context'; -import { createModule } from '../create-canvas-module'; +import { registerCanvasFactories } from '../create-canvas-module'; -export const feishuCanvasModule = createModule(FeishuCanvas, FeishuContext2d); +export function registerFeishuCanvasFactories() { + registerCanvasFactories(FeishuCanvas, FeishuContext2d); +} diff --git a/packages/vrender-kits/src/canvas/contributions/harmony/canvas.ts b/packages/vrender-kits/src/canvas/contributions/harmony/canvas.ts index e12b8910a..322942b15 100644 --- a/packages/vrender-kits/src/canvas/contributions/harmony/canvas.ts +++ b/packages/vrender-kits/src/canvas/contributions/harmony/canvas.ts @@ -1,8 +1,7 @@ -import { injectable, BaseCanvas } from '@visactor/vrender-core'; +import { BaseCanvas } from '@visactor/vrender-core'; import type { ICanvas, CanvasConfigType, EnvType } from '@visactor/vrender-core'; import { HarmonyContext2d } from './context'; -@injectable() export class HarmonyCanvas extends BaseCanvas implements ICanvas { static env: EnvType = 'harmony'; diff --git a/packages/vrender-kits/src/canvas/contributions/harmony/context.ts b/packages/vrender-kits/src/canvas/contributions/harmony/context.ts index 8fa335dd1..75caec68a 100644 --- a/packages/vrender-kits/src/canvas/contributions/harmony/context.ts +++ b/packages/vrender-kits/src/canvas/contributions/harmony/context.ts @@ -1,5 +1,5 @@ // 参考konva -import { injectable, createColor, getScaledStroke, application } from '@visactor/vrender-core'; +import { createColor, getScaledStroke, application } from '@visactor/vrender-core'; import type { IContext2d, EnvType, @@ -10,7 +10,6 @@ import type { import { BrowserContext2d } from '../browser'; import { getContextFont } from '@visactor/vutils'; -@injectable() export class HarmonyContext2d extends BrowserContext2d implements IContext2d { static env: EnvType = 'harmony'; diff --git a/packages/vrender-kits/src/canvas/contributions/harmony/modules.ts b/packages/vrender-kits/src/canvas/contributions/harmony/modules.ts index 5eba78c09..8f4a4afee 100644 --- a/packages/vrender-kits/src/canvas/contributions/harmony/modules.ts +++ b/packages/vrender-kits/src/canvas/contributions/harmony/modules.ts @@ -1,5 +1,7 @@ import { HarmonyCanvas } from './canvas'; import { HarmonyContext2d } from './context'; -import { createModule } from '../create-canvas-module'; +import { registerCanvasFactories } from '../create-canvas-module'; -export const harmonyCanvasModule = createModule(HarmonyCanvas, HarmonyContext2d); +export function registerHarmonyCanvasFactories() { + registerCanvasFactories(HarmonyCanvas, HarmonyContext2d); +} diff --git a/packages/vrender-kits/src/canvas/contributions/lynx/canvas.ts b/packages/vrender-kits/src/canvas/contributions/lynx/canvas.ts index e3ef817bc..a81b5efb0 100644 --- a/packages/vrender-kits/src/canvas/contributions/lynx/canvas.ts +++ b/packages/vrender-kits/src/canvas/contributions/lynx/canvas.ts @@ -1,8 +1,7 @@ -import { injectable, BaseCanvas } from '@visactor/vrender-core'; +import { BaseCanvas } from '@visactor/vrender-core'; import type { ICanvas, CanvasConfigType, EnvType } from '@visactor/vrender-core'; import { LynxContext2d } from './context'; -@injectable() export class LynxCanvas extends BaseCanvas implements ICanvas { static env: EnvType = 'lynx'; diff --git a/packages/vrender-kits/src/canvas/contributions/lynx/context.ts b/packages/vrender-kits/src/canvas/contributions/lynx/context.ts index e0bbde6a5..95d45e801 100644 --- a/packages/vrender-kits/src/canvas/contributions/lynx/context.ts +++ b/packages/vrender-kits/src/canvas/contributions/lynx/context.ts @@ -1,9 +1,8 @@ // 参考konva -import { injectable, createColor, getScaledStroke, application } from '@visactor/vrender-core'; +import { createColor, getScaledStroke, application } from '@visactor/vrender-core'; import type { IContext2d, EnvType, ISetStrokeStyleParams, IStrokeStyleParams } from '@visactor/vrender-core'; import { BrowserContext2d } from '../browser'; -@injectable() export class LynxContext2d extends BrowserContext2d implements IContext2d { static env: EnvType = 'lynx'; diff --git a/packages/vrender-kits/src/canvas/contributions/lynx/modules.ts b/packages/vrender-kits/src/canvas/contributions/lynx/modules.ts index b79f2c5ee..7b711747f 100644 --- a/packages/vrender-kits/src/canvas/contributions/lynx/modules.ts +++ b/packages/vrender-kits/src/canvas/contributions/lynx/modules.ts @@ -1,5 +1,7 @@ import { LynxCanvas } from './canvas'; import { LynxContext2d } from './context'; -import { createModule } from '../create-canvas-module'; +import { registerCanvasFactories } from '../create-canvas-module'; -export const lynxCanvasModule = createModule(LynxCanvas, LynxContext2d); +export function registerLynxCanvasFactories() { + registerCanvasFactories(LynxCanvas, LynxContext2d); +} diff --git a/packages/vrender-kits/src/canvas/contributions/modules.ts b/packages/vrender-kits/src/canvas/contributions/modules.ts index ee4aa5f85..10a4f10ac 100644 --- a/packages/vrender-kits/src/canvas/contributions/modules.ts +++ b/packages/vrender-kits/src/canvas/contributions/modules.ts @@ -1,46 +1,45 @@ -import type { Container } from '@visactor/vrender-core'; -import { browserCanvasModule } from './browser/modules'; -import { feishuCanvasModule } from './feishu/modules'; -import { lynxCanvasModule } from './lynx/modules'; -import { nodeCanvasModule } from './node/modules'; -import { taroCanvasModule } from './taro/modules'; -import { ttCanvasModule } from './tt/modules'; -import { wxCanvasModule } from './wx/modules'; +import { registerBrowserCanvasFactories } from './browser/modules'; +import { registerFeishuCanvasFactories } from './feishu/modules'; +import { registerLynxCanvasFactories } from './lynx/modules'; +import { registerNodeCanvasFactories } from './node/modules'; +import { registerTaroCanvasFactories } from './taro/modules'; +import { registerTTCanvasFactories } from './tt/modules'; +import { registerWxCanvasFactories } from './wx/modules'; -export function loadAllCavnvas(container: Container) { - container.load(browserCanvasModule); - container.load(feishuCanvasModule); - container.load(lynxCanvasModule); - container.load(nodeCanvasModule); - container.load(taroCanvasModule); - container.load(ttCanvasModule); - container.load(wxCanvasModule); +export function loadAllCavnvas() { + registerBrowserCanvasFactories(); + registerFeishuCanvasFactories(); + registerLynxCanvasFactories(); + registerNodeCanvasFactories(); + registerTaroCanvasFactories(); + registerTTCanvasFactories(); + registerWxCanvasFactories(); } -export function loadBrowserCanvas(container: Container) { - container.load(browserCanvasModule); +export function loadBrowserCanvas() { + registerBrowserCanvasFactories(); } -export function loadFeishuCanvas(container: Container) { - container.load(feishuCanvasModule); +export function loadFeishuCanvas() { + registerFeishuCanvasFactories(); } -export function loadLynxCanvas(container: Container) { - container.load(lynxCanvasModule); +export function loadLynxCanvas() { + registerLynxCanvasFactories(); } -export function loadNodeCanvas(container: Container) { - container.load(nodeCanvasModule); +export function loadNodeCanvas() { + registerNodeCanvasFactories(); } -export function loadTaroCanvas(container: Container) { - container.load(taroCanvasModule); +export function loadTaroCanvas() { + registerTaroCanvasFactories(); } -export function loadTTCanvas(container: Container) { - container.load(ttCanvasModule); +export function loadTTCanvas() { + registerTTCanvasFactories(); } -export function loadWxCanvas(container: Container) { - container.load(wxCanvasModule); +export function loadWxCanvas() { + registerWxCanvasFactories(); } diff --git a/packages/vrender-kits/src/canvas/contributions/node/canvas.ts b/packages/vrender-kits/src/canvas/contributions/node/canvas.ts index 15f5c31c0..3f31cd247 100644 --- a/packages/vrender-kits/src/canvas/contributions/node/canvas.ts +++ b/packages/vrender-kits/src/canvas/contributions/node/canvas.ts @@ -1,9 +1,8 @@ -import { injectable, BaseCanvas } from '@visactor/vrender-core'; +import { BaseCanvas } from '@visactor/vrender-core'; import type { ICanvas, CanvasConfigType, EnvType } from '@visactor/vrender-core'; import { NodeContext2d } from './context'; import { isFunction } from '@visactor/vutils'; -@injectable() export class NodeCanvas extends BaseCanvas implements ICanvas { static env: EnvType = 'node'; diff --git a/packages/vrender-kits/src/canvas/contributions/node/context.ts b/packages/vrender-kits/src/canvas/contributions/node/context.ts index bfae05a30..508d34dcb 100644 --- a/packages/vrender-kits/src/canvas/contributions/node/context.ts +++ b/packages/vrender-kits/src/canvas/contributions/node/context.ts @@ -1,10 +1,8 @@ // 参考konva import { Matrix } from '@visactor/vutils'; -import { injectable } from '@visactor/vrender-core'; import type { IContext2d, EnvType, ICanvas } from '@visactor/vrender-core'; import { BrowserContext2d } from '../browser'; -@injectable() export class NodeContext2d extends BrowserContext2d implements IContext2d { static env: EnvType = 'node'; diff --git a/packages/vrender-kits/src/canvas/contributions/node/modules.ts b/packages/vrender-kits/src/canvas/contributions/node/modules.ts index 80dbe7fff..9d1743889 100644 --- a/packages/vrender-kits/src/canvas/contributions/node/modules.ts +++ b/packages/vrender-kits/src/canvas/contributions/node/modules.ts @@ -1,5 +1,7 @@ import { NodeCanvas } from './canvas'; import { NodeContext2d } from './context'; -import { createModule } from '../create-canvas-module'; +import { registerCanvasFactories } from '../create-canvas-module'; -export const nodeCanvasModule = createModule(NodeCanvas, NodeContext2d); +export function registerNodeCanvasFactories() { + registerCanvasFactories(NodeCanvas, NodeContext2d); +} diff --git a/packages/vrender-kits/src/canvas/contributions/taro/canvas.ts b/packages/vrender-kits/src/canvas/contributions/taro/canvas.ts index dde0d8468..732c1f207 100644 --- a/packages/vrender-kits/src/canvas/contributions/taro/canvas.ts +++ b/packages/vrender-kits/src/canvas/contributions/taro/canvas.ts @@ -1,9 +1,7 @@ -import { injectable } from '@visactor/vrender-core'; import type { ICanvas, CanvasConfigType, EnvType } from '@visactor/vrender-core'; import { BaseCanvas } from '@visactor/vrender-core'; import { TaroContext2d } from './context'; -@injectable() export class TaroCanvas extends BaseCanvas implements ICanvas { static env: EnvType = 'taro'; diff --git a/packages/vrender-kits/src/canvas/contributions/taro/context.ts b/packages/vrender-kits/src/canvas/contributions/taro/context.ts index c2af91c08..49a9f2d83 100644 --- a/packages/vrender-kits/src/canvas/contributions/taro/context.ts +++ b/packages/vrender-kits/src/canvas/contributions/taro/context.ts @@ -1,5 +1,5 @@ // 参考konva -import { injectable, createColor, getScaledStroke } from '@visactor/vrender-core'; +import { createColor, getScaledStroke } from '@visactor/vrender-core'; import type { ICommonStyleParams, IContext2d, @@ -29,7 +29,6 @@ interface ITTContext { font: string; } -@injectable() export class TaroContext2d extends BrowserContext2d implements IContext2d { static env: EnvType = 'taro'; diff --git a/packages/vrender-kits/src/canvas/contributions/taro/modules.ts b/packages/vrender-kits/src/canvas/contributions/taro/modules.ts index 2acbb5dee..cd2690802 100644 --- a/packages/vrender-kits/src/canvas/contributions/taro/modules.ts +++ b/packages/vrender-kits/src/canvas/contributions/taro/modules.ts @@ -1,5 +1,7 @@ import { TaroCanvas } from './canvas'; import { TaroContext2d } from './context'; -import { createModule } from '../create-canvas-module'; +import { registerCanvasFactories } from '../create-canvas-module'; -export const taroCanvasModule = createModule(TaroCanvas, TaroContext2d); +export function registerTaroCanvasFactories() { + registerCanvasFactories(TaroCanvas, TaroContext2d); +} diff --git a/packages/vrender-kits/src/canvas/contributions/tt/canvas.ts b/packages/vrender-kits/src/canvas/contributions/tt/canvas.ts index f2d9ac921..a7f8ed047 100644 --- a/packages/vrender-kits/src/canvas/contributions/tt/canvas.ts +++ b/packages/vrender-kits/src/canvas/contributions/tt/canvas.ts @@ -1,8 +1,7 @@ -import { injectable, BaseCanvas } from '@visactor/vrender-core'; +import { BaseCanvas } from '@visactor/vrender-core'; import type { ICanvas, CanvasConfigType, EnvType } from '@visactor/vrender-core'; import { TTContext2d } from './context'; -@injectable() export class TTCanvas extends BaseCanvas implements ICanvas { static env: EnvType = 'tt'; diff --git a/packages/vrender-kits/src/canvas/contributions/tt/context.ts b/packages/vrender-kits/src/canvas/contributions/tt/context.ts index 44d6c6ffd..be34f02a3 100644 --- a/packages/vrender-kits/src/canvas/contributions/tt/context.ts +++ b/packages/vrender-kits/src/canvas/contributions/tt/context.ts @@ -1,8 +1,6 @@ -import { injectable } from '@visactor/vrender-core'; import type { IContext2d, EnvType } from '@visactor/vrender-core'; import { FeishuContext2d } from '../feishu'; -@injectable() export class TTContext2d extends FeishuContext2d implements IContext2d { static env: EnvType = 'tt'; } diff --git a/packages/vrender-kits/src/canvas/contributions/tt/modules.ts b/packages/vrender-kits/src/canvas/contributions/tt/modules.ts index 02db9659a..4c842b479 100644 --- a/packages/vrender-kits/src/canvas/contributions/tt/modules.ts +++ b/packages/vrender-kits/src/canvas/contributions/tt/modules.ts @@ -1,5 +1,7 @@ import { TTCanvas } from './canvas'; import { TTContext2d } from './context'; -import { createModule } from '../create-canvas-module'; +import { registerCanvasFactories } from '../create-canvas-module'; -export const ttCanvasModule = createModule(TTCanvas, TTContext2d); +export function registerTTCanvasFactories() { + registerCanvasFactories(TTCanvas, TTContext2d); +} diff --git a/packages/vrender-kits/src/canvas/contributions/wx/canvas.ts b/packages/vrender-kits/src/canvas/contributions/wx/canvas.ts index 413701acf..2ea2d4179 100644 --- a/packages/vrender-kits/src/canvas/contributions/wx/canvas.ts +++ b/packages/vrender-kits/src/canvas/contributions/wx/canvas.ts @@ -1,8 +1,7 @@ -import { injectable, BaseCanvas } from '@visactor/vrender-core'; +import { BaseCanvas } from '@visactor/vrender-core'; import type { ICanvas, CanvasConfigType, EnvType } from '@visactor/vrender-core'; import { WxContext2d } from './context'; -@injectable() export class WxCanvas extends BaseCanvas implements ICanvas { static env: EnvType = 'wx'; diff --git a/packages/vrender-kits/src/canvas/contributions/wx/context.ts b/packages/vrender-kits/src/canvas/contributions/wx/context.ts index e556715ae..4741eb045 100644 --- a/packages/vrender-kits/src/canvas/contributions/wx/context.ts +++ b/packages/vrender-kits/src/canvas/contributions/wx/context.ts @@ -1,9 +1,7 @@ // 参考konva -import { injectable } from '@visactor/vrender-core'; import type { IContext2d, EnvType } from '@visactor/vrender-core'; import { BrowserContext2d } from '../browser'; -@injectable() export class WxContext2d extends BrowserContext2d implements IContext2d { static env: EnvType = 'wx'; diff --git a/packages/vrender-kits/src/canvas/contributions/wx/modules.ts b/packages/vrender-kits/src/canvas/contributions/wx/modules.ts index 86540288a..5b60c42ad 100644 --- a/packages/vrender-kits/src/canvas/contributions/wx/modules.ts +++ b/packages/vrender-kits/src/canvas/contributions/wx/modules.ts @@ -1,5 +1,7 @@ import { WxCanvas } from './canvas'; import { WxContext2d } from './context'; -import { createModule } from '../create-canvas-module'; +import { registerCanvasFactories } from '../create-canvas-module'; -export const wxCanvasModule = createModule(WxCanvas, WxContext2d); +export function registerWxCanvasFactories() { + registerCanvasFactories(WxCanvas, WxContext2d); +} diff --git a/packages/vrender-kits/src/env/all.ts b/packages/vrender-kits/src/env/all.ts index 4f421c291..01348b9b7 100644 --- a/packages/vrender-kits/src/env/all.ts +++ b/packages/vrender-kits/src/env/all.ts @@ -1,30 +1,30 @@ -import { container, vglobal, type Container } from '@visactor/vrender-core'; -import { loadBrowserEnv } from './browser'; -import { loadFeishuEnv } from './feishu'; -import { loadLynxEnv } from './lynx'; -import { loadNodeEnv } from './node'; -import { loadTaroEnv } from './taro'; -import { loadWxEnv } from './wx'; -import { loadCanvasPicker } from '../picker/canvas-module'; -import { loadMathPicker } from '../picker/math-module'; +import { application } from '@visactor/vrender-core'; +import { registerBrowserEnvRegistry } from './browser'; +import { registerFeishuEnvRegistry } from './feishu'; +import { registerLynxEnvRegistry } from './lynx'; +import { registerNodeEnvRegistry } from './node'; +import { registerTaroEnvRegistry } from './taro'; +import { registerWxEnvRegistry } from './wx'; +import { registerCanvasPickerService } from '../picker/canvas-module'; +import { registerMathPickerService } from '../picker/math-module'; // import { loadMathPicker } from '../picker'; -export function loadAllEnv(container: Container) { - loadAllModule(container); +export function loadAllEnv() { + loadAllModule(); } -export function loadAllModule(container: Container) { +export function loadAllModule() { if (!loadAllModule.__loaded) { loadAllModule.__loaded = true; - loadBrowserEnv(container, false); - loadFeishuEnv(container, false); - loadLynxEnv(container, false); - loadNodeEnv(container, false); - loadTaroEnv(container, false); - loadWxEnv(container, false); - loadCanvasPicker(container); - vglobal.hooks.onSetEnv.tap('loadMathPicker', (lastEnv, env) => { - env !== 'browser' && loadMathPicker(container); + registerBrowserEnvRegistry(); + registerFeishuEnvRegistry(); + registerLynxEnvRegistry(); + registerNodeEnvRegistry(); + registerTaroEnvRegistry(); + registerWxEnvRegistry(); + registerCanvasPickerService(); + application.global.hooks.onSetEnv.tap('registerMathPickerService', (lastEnv, env) => { + env !== 'browser' && registerMathPickerService(); }); } } @@ -32,5 +32,5 @@ export function loadAllModule(container: Container) { loadAllModule.__loaded = false; export function initAllEnv() { - loadAllEnv(container); + loadAllEnv(); } diff --git a/packages/vrender-kits/src/env/browser.ts b/packages/vrender-kits/src/env/browser.ts index 4f246dad8..a5de6a1b6 100644 --- a/packages/vrender-kits/src/env/browser.ts +++ b/packages/vrender-kits/src/env/browser.ts @@ -1,33 +1,17 @@ -import { container, ContainerModule, type Container, EnvContribution } from '@visactor/vrender-core'; +import { EnvContribution, application } from '@visactor/vrender-core'; // import { browserEnvModule } from './contributions/module'; -import { browserCanvasModule } from '../canvas/contributions/browser/modules'; -import { loadCanvasPicker } from '../picker/canvas-module'; -import { browserWindowModule } from '../window/contributions/browser-contribution'; import { BrowserEnvContribution } from './contributions/browser-contribution'; +import { BrowserWindowHandlerContribution } from '../window/contributions/browser-contribution'; +import { WindowHandlerContribution } from '@visactor/vrender-core'; -export const browserEnvModule = new ContainerModule(bind => { - // browser - if (!(browserEnvModule as any).isBrowserBound) { - (browserEnvModule as any).isBrowserBound = true; - bind(BrowserEnvContribution).toSelf().inSingletonScope(); - bind(EnvContribution).toService(BrowserEnvContribution); - } -}); +// Legacy ContainerModule and loaders removed (registry-only) -(browserEnvModule as any).isBrowserBound = false; - -export function loadBrowserEnv(container: Container, loadPicker: boolean = true) { - if (!loadBrowserEnv.__loaded) { - loadBrowserEnv.__loaded = true; - container.load(browserEnvModule); - container.load(browserCanvasModule); - container.load(browserWindowModule); - loadPicker && loadCanvasPicker(container); - } -} - -loadBrowserEnv.__loaded = false; - -export function initBrowserEnv() { - loadBrowserEnv(container); +/** + * Registry-based registration for browser env/window + */ +export function registerBrowserEnvRegistry() { + // Env contribution + application.contributions.register(EnvContribution, new BrowserEnvContribution()); + // Window handler contribution + application.contributions.register(WindowHandlerContribution, new BrowserWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/contributions/browser-contribution.ts b/packages/vrender-kits/src/env/contributions/browser-contribution.ts index 11f47f778..be3e7881a 100644 --- a/packages/vrender-kits/src/env/contributions/browser-contribution.ts +++ b/packages/vrender-kits/src/env/contributions/browser-contribution.ts @@ -1,4 +1,4 @@ -import { injectable, Generator, BaseEnvContribution, application } from '@visactor/vrender-core'; +import { Generator, BaseEnvContribution, application } from '@visactor/vrender-core'; import type { ICanvasLike, EnvType, @@ -60,7 +60,6 @@ export function createImageElement(src: string, isSvg: boolean = false): Promise return promise; } -@injectable() export class BrowserEnvContribution extends BaseEnvContribution implements IEnvContribution { type: EnvType = 'browser'; supportEvent: boolean = true; diff --git a/packages/vrender-kits/src/env/contributions/feishu-contribution.ts b/packages/vrender-kits/src/env/contributions/feishu-contribution.ts index 8c218695b..c0077b108 100644 --- a/packages/vrender-kits/src/env/contributions/feishu-contribution.ts +++ b/packages/vrender-kits/src/env/contributions/feishu-contribution.ts @@ -1,4 +1,4 @@ -import { injectable, BaseEnvContribution, rafBasedSto } from '@visactor/vrender-core'; +import { BaseEnvContribution, rafBasedSto } from '@visactor/vrender-core'; // import { loadFeishuContributions } from '../../../kits'; import type { ICanvasLike, @@ -41,7 +41,6 @@ function makeUpCanvas( }); } -@injectable() export class FeishuEnvContribution extends BaseEnvContribution implements IEnvContribution { type: EnvType = 'feishu'; supportEvent: boolean = true; diff --git a/packages/vrender-kits/src/env/contributions/harmony-contribution.ts b/packages/vrender-kits/src/env/contributions/harmony-contribution.ts index 5fac04571..c7f672d68 100644 --- a/packages/vrender-kits/src/env/contributions/harmony-contribution.ts +++ b/packages/vrender-kits/src/env/contributions/harmony-contribution.ts @@ -1,4 +1,4 @@ -import { injectable, BaseEnvContribution, RafBasedSTO } from '@visactor/vrender-core'; +import { BaseEnvContribution, RafBasedSTO } from '@visactor/vrender-core'; // import { loadFeishuContributions } from '../../../kits'; import type { ICanvasLike, @@ -34,7 +34,6 @@ function createCanvas(width: number, height: number, id?: string) { return new CanvasWrapDisableWH(nativeCanvas, context, 1, width, height, id); } -@injectable() export class HarmonyEnvContribution extends BaseEnvContribution implements IEnvContribution { type: EnvType = 'harmony'; supportEvent: boolean = true; diff --git a/packages/vrender-kits/src/env/contributions/lynx-contribution.ts b/packages/vrender-kits/src/env/contributions/lynx-contribution.ts index 5fffa4fbe..c9916b74f 100644 --- a/packages/vrender-kits/src/env/contributions/lynx-contribution.ts +++ b/packages/vrender-kits/src/env/contributions/lynx-contribution.ts @@ -1,4 +1,4 @@ -import { injectable, BaseEnvContribution, rafBasedSto } from '@visactor/vrender-core'; +import { BaseEnvContribution, rafBasedSto } from '@visactor/vrender-core'; // import { loadFeishuContributions } from '../../../kits'; import type { ICanvasLike, @@ -99,7 +99,6 @@ export function createImageElement(src: string, isSvg: boolean = false): Promise return promise; } -@injectable() export class LynxEnvContribution extends BaseEnvContribution implements IEnvContribution { type: EnvType = 'lynx'; supportEvent: boolean = true; diff --git a/packages/vrender-kits/src/env/contributions/node-contribution.ts b/packages/vrender-kits/src/env/contributions/node-contribution.ts index 5862deea9..706df10c2 100644 --- a/packages/vrender-kits/src/env/contributions/node-contribution.ts +++ b/packages/vrender-kits/src/env/contributions/node-contribution.ts @@ -1,4 +1,4 @@ -import { injectable, BaseEnvContribution, rafBasedSto } from '@visactor/vrender-core'; +import { BaseEnvContribution, rafBasedSto } from '@visactor/vrender-core'; // import { loadTaroContributions } from '../../../kits'; import type { EnvType, ICreateCanvasParams, IEnvContribution, IGlobal } from '@visactor/vrender-core'; @@ -22,7 +22,6 @@ type NodePkg = { // return id; // } -@injectable() export class NodeEnvContribution extends BaseEnvContribution implements IEnvContribution { type: EnvType = 'node'; pkg: NodePkg; diff --git a/packages/vrender-kits/src/env/contributions/taro-contribution.ts b/packages/vrender-kits/src/env/contributions/taro-contribution.ts index 971a797b4..ff28e98b6 100644 --- a/packages/vrender-kits/src/env/contributions/taro-contribution.ts +++ b/packages/vrender-kits/src/env/contributions/taro-contribution.ts @@ -1,4 +1,4 @@ -import { injectable, BaseEnvContribution } from '@visactor/vrender-core'; +import { BaseEnvContribution } from '@visactor/vrender-core'; import type { ICanvasLike, EnvType, @@ -55,7 +55,6 @@ interface IConfigureParams { pixelRatio: number; // taro需要小程序自己处理pixelRatio } -@injectable() export class TaroEnvContribution extends BaseEnvContribution implements IEnvContribution { type: EnvType = 'taro'; supportEvent: boolean = true; diff --git a/packages/vrender-kits/src/env/contributions/tt-contribution.ts b/packages/vrender-kits/src/env/contributions/tt-contribution.ts index 1f36ceaee..dffede0b7 100644 --- a/packages/vrender-kits/src/env/contributions/tt-contribution.ts +++ b/packages/vrender-kits/src/env/contributions/tt-contribution.ts @@ -1,4 +1,4 @@ -import { injectable, BaseEnvContribution, rafBasedSto } from '@visactor/vrender-core'; +import { BaseEnvContribution, rafBasedSto } from '@visactor/vrender-core'; // import { loadFeishuContributions } from '../../../kits'; import type { ICanvasLike, @@ -106,7 +106,6 @@ async function makeUpCanvas( // }); } -@injectable() export class TTEnvContribution extends BaseEnvContribution implements IEnvContribution { type: EnvType = 'tt'; supportEvent: boolean = true; diff --git a/packages/vrender-kits/src/env/contributions/wx-contribution.ts b/packages/vrender-kits/src/env/contributions/wx-contribution.ts index 06f236d0f..7c0986142 100644 --- a/packages/vrender-kits/src/env/contributions/wx-contribution.ts +++ b/packages/vrender-kits/src/env/contributions/wx-contribution.ts @@ -1,4 +1,4 @@ -import { injectable, BaseEnvContribution, rafBasedSto } from '@visactor/vrender-core'; +import { BaseEnvContribution, rafBasedSto } from '@visactor/vrender-core'; // import { loadFeishuContributions } from '../../../kits'; import type { ICanvasLike, @@ -111,7 +111,6 @@ async function makeUpCanvas( // }); } -@injectable() export class WxEnvContribution extends BaseEnvContribution implements IEnvContribution { type: EnvType = 'wx'; supportEvent: boolean = true; diff --git a/packages/vrender-kits/src/env/feishu.ts b/packages/vrender-kits/src/env/feishu.ts index a5b9fb99d..1bd74c8ed 100644 --- a/packages/vrender-kits/src/env/feishu.ts +++ b/packages/vrender-kits/src/env/feishu.ts @@ -1,32 +1,11 @@ -import { container, ContainerModule, type Container, EnvContribution } from '@visactor/vrender-core'; -import { feishuCanvasModule } from '../canvas/contributions/feishu/modules'; -import { feishuWindowModule } from '../window/contributions/feishu-contribution'; -import { loadMathPicker } from '../picker/math-module'; +import { EnvContribution, application, WindowHandlerContribution } from '@visactor/vrender-core'; +import { FeishuWindowHandlerContribution } from '../window/contributions/feishu-contribution'; import { FeishuEnvContribution } from './contributions/feishu-contribution'; -export const feishuEnvModule = new ContainerModule(bind => { - // feishu - if (!(feishuEnvModule as any).isFeishuBound) { - (feishuEnvModule as any).isFeishuBound = true; - bind(FeishuEnvContribution).toSelf().inSingletonScope(); - bind(EnvContribution).toService(FeishuEnvContribution); - } -}); +// Legacy ContainerModule and loaders removed (registry-only) -(feishuEnvModule as any).isFeishuBound = false; - -export function loadFeishuEnv(container: Container, loadPicker: boolean = true) { - if (!loadFeishuEnv.__loaded) { - loadFeishuEnv.__loaded = true; - container.load(feishuEnvModule); - container.load(feishuCanvasModule); - container.load(feishuWindowModule); - loadPicker && loadMathPicker(container); - } -} - -loadFeishuEnv.__loaded = false; - -export function initFeishuEnv() { - loadFeishuEnv(container); +/** Registry-based registration for feishu env/window */ +export function registerFeishuEnvRegistry() { + application.contributions.register(EnvContribution, new FeishuEnvContribution()); + application.contributions.register(WindowHandlerContribution, new FeishuWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/harmony.ts b/packages/vrender-kits/src/env/harmony.ts index f5cf55cf2..94dac0d78 100644 --- a/packages/vrender-kits/src/env/harmony.ts +++ b/packages/vrender-kits/src/env/harmony.ts @@ -1,32 +1,9 @@ -import { container, ContainerModule, type Container, EnvContribution } from '@visactor/vrender-core'; -import { loadMathPicker } from '../picker/math-module'; -import { harmonyWindowModule } from '../window/contributions/harmony-contribution'; -import { harmonyCanvasModule } from '../canvas/contributions/harmony/modules'; +import { EnvContribution, application, WindowHandlerContribution } from '@visactor/vrender-core'; +import { HarmonyWindowHandlerContribution } from '../window/contributions/harmony-contribution'; import { HarmonyEnvContribution } from './contributions/harmony-contribution'; -export const harmonyEnvModule = new ContainerModule(bind => { - // harmony - if (!(harmonyEnvModule as any).isHarmonyBound) { - (harmonyEnvModule as any).isHarmonyBound = true; - bind(HarmonyEnvContribution).toSelf().inSingletonScope(); - bind(EnvContribution).toService(HarmonyEnvContribution); - } -}); - -(harmonyEnvModule as any).isHarmonyBound = false; - -export function loadHarmonyEnv(container: Container, loadPicker: boolean = true) { - if (!loadHarmonyEnv.__loaded) { - loadHarmonyEnv.__loaded = true; - container.load(harmonyEnvModule); - container.load(harmonyCanvasModule); - container.load(harmonyWindowModule); - loadPicker && loadMathPicker(container); - } -} - -loadHarmonyEnv.__loaded = false; - -export function initHarmonyEnv() { - loadHarmonyEnv(container); +/** Registry-based registration for harmony env/window */ +export function registerHarmonyEnvRegistry() { + application.contributions.register(EnvContribution, new HarmonyEnvContribution()); + application.contributions.register(WindowHandlerContribution, new HarmonyWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/lynx.ts b/packages/vrender-kits/src/env/lynx.ts index a0aced6a5..6390b5496 100644 --- a/packages/vrender-kits/src/env/lynx.ts +++ b/packages/vrender-kits/src/env/lynx.ts @@ -1,33 +1,12 @@ -import { container, ContainerModule, type Container, EnvContribution } from '@visactor/vrender-core'; -import { loadMathPicker } from '../picker/math-module'; -import { lynxWindowModule } from '../window/contributions/lynx-contribution'; -import { lynxCanvasModule } from '../canvas/contributions/lynx/modules'; +import { EnvContribution, application, WindowHandlerContribution } from '@visactor/vrender-core'; +import { LynxWindowHandlerContribution } from '../window/contributions/lynx-contribution'; import { LynxEnvContribution } from './contributions/lynx-contribution'; // import { lynxEnvModule } from './contributions/module'; -export const lynxEnvModule = new ContainerModule(bind => { - // lynx - if (!(lynxEnvModule as any).isLynxBound) { - (lynxEnvModule as any).isLynxBound = true; - bind(LynxEnvContribution).toSelf().inSingletonScope(); - bind(EnvContribution).toService(LynxEnvContribution); - } -}); +// Legacy ContainerModule and loaders removed (registry-only) -(lynxEnvModule as any).isLynxBound = false; - -export function loadLynxEnv(container: Container, loadPicker: boolean = true) { - if (!loadLynxEnv.__loaded) { - loadLynxEnv.__loaded = true; - container.load(lynxEnvModule); - container.load(lynxCanvasModule); - container.load(lynxWindowModule); - loadPicker && loadMathPicker(container); - } -} - -loadLynxEnv.__loaded = false; - -export function initLynxEnv() { - loadLynxEnv(container); +/** Registry-based registration for lynx env/window */ +export function registerLynxEnvRegistry() { + application.contributions.register(EnvContribution, new LynxEnvContribution()); + application.contributions.register(WindowHandlerContribution, new LynxWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/node.ts b/packages/vrender-kits/src/env/node.ts index a30b89ad3..349207b88 100644 --- a/packages/vrender-kits/src/env/node.ts +++ b/packages/vrender-kits/src/env/node.ts @@ -1,32 +1,18 @@ -import { container, ContainerModule, type Container, EnvContribution } from '@visactor/vrender-core'; +import { EnvContribution, application } from '@visactor/vrender-core'; // import { loadMathPicker } from '../picker/math-module'; // import { nodeEnvModule } from './contributions/module'; -import { nodeCanvasModule } from '../canvas/contributions/node/modules'; -import { nodeWindowModule } from '../window/contributions/node-contribution'; import { NodeEnvContribution } from './contributions/node-contribution'; +import { NodeWindowHandlerContribution } from '../window/contributions/node-contribution'; +import { WindowHandlerContribution } from '@visactor/vrender-core'; -export const nodeEnvModule = new ContainerModule(bind => { - // node - if (!(nodeEnvModule as any).isNodeBound) { - (nodeEnvModule as any).isNodeBound = true; - bind(NodeEnvContribution).toSelf().inSingletonScope(); - bind(EnvContribution).toService(NodeEnvContribution); - } -}); +// Legacy ContainerModule and loaders removed (registry-only) -(nodeEnvModule as any).isNodeBound = false; - -export function loadNodeEnv(container: Container, loadPicker: boolean = true) { - if (!loadNodeEnv.__loaded) { - loadNodeEnv.__loaded = true; - container.load(nodeEnvModule); - container.load(nodeCanvasModule); - container.load(nodeWindowModule); - // loadPicker && loadMathPicker(container); - } -} -loadNodeEnv.__loaded = false; - -export function initNodeEnv() { - loadNodeEnv(container); +/** + * Registry-based registration for node env/window + */ +export function registerNodeEnvRegistry() { + // Env contribution + application.contributions.register(EnvContribution, new NodeEnvContribution()); + // Window handler contribution + application.contributions.register(WindowHandlerContribution, new NodeWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/taro.ts b/packages/vrender-kits/src/env/taro.ts index ce107936c..dac6198e3 100644 --- a/packages/vrender-kits/src/env/taro.ts +++ b/packages/vrender-kits/src/env/taro.ts @@ -1,33 +1,11 @@ -import { container, ContainerModule, type Container, EnvContribution } from '@visactor/vrender-core'; -import { loadMathPicker } from '../picker/math-module'; -// import { taroEnvModule } from './contributions/module'; -import { taroCanvasModule } from '../canvas/contributions/taro/modules'; -import { taroWindowModule } from '../window/contributions/taro-contribution'; +import { EnvContribution, application, WindowHandlerContribution } from '@visactor/vrender-core'; +import { TaroWindowHandlerContribution } from '../window/contributions/taro-contribution'; import { TaroEnvContribution } from './contributions/taro-contribution'; -export const taroEnvModule = new ContainerModule(bind => { - // taro - if (!(taroEnvModule as any).isTaroBound) { - (taroEnvModule as any).isTaroBound = true; - bind(TaroEnvContribution).toSelf().inSingletonScope(); - bind(EnvContribution).toService(TaroEnvContribution); - } -}); +// Legacy ContainerModule and loaders removed (registry-only) -(taroEnvModule as any).isTaroBound = false; - -export function loadTaroEnv(container: Container, loadPicker: boolean = true) { - if (!loadTaroEnv.__loaded) { - loadTaroEnv.__loaded = true; - container.load(taroEnvModule); - container.load(taroCanvasModule); - container.load(taroWindowModule); - loadPicker && loadMathPicker(container); - } -} - -loadTaroEnv.__loaded = false; - -export function initTaroEnv() { - loadTaroEnv(container); +/** Registry-based registration for taro env/window */ +export function registerTaroEnvRegistry() { + application.contributions.register(EnvContribution, new TaroEnvContribution()); + application.contributions.register(WindowHandlerContribution, new TaroWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/tt.ts b/packages/vrender-kits/src/env/tt.ts index 12d3a8449..9792dcd2a 100644 --- a/packages/vrender-kits/src/env/tt.ts +++ b/packages/vrender-kits/src/env/tt.ts @@ -1,32 +1,9 @@ -import { container, ContainerModule, type Container, EnvContribution } from '@visactor/vrender-core'; -import { ttCanvasModule } from '../canvas/contributions/tt/modules'; -import { ttWindowModule } from '../window/contributions/tt-contribution'; -import { loadMathPicker } from '../picker/math-module'; +import { EnvContribution, application, WindowHandlerContribution } from '@visactor/vrender-core'; +import { TTWindowHandlerContribution } from '../window/contributions/tt-contribution'; import { TTEnvContribution } from './contributions/tt-contribution'; -export const ttEnvModule = new ContainerModule(bind => { - // feishu - if (!(ttEnvModule as any).isTTBound) { - (ttEnvModule as any).isTTBound = true; - bind(TTEnvContribution).toSelf().inSingletonScope(); - bind(EnvContribution).toService(TTEnvContribution); - } -}); - -(ttEnvModule as any).isTTBound = false; - -export function loadTTEnv(container: Container, loadPicker: boolean = true) { - if (!loadTTEnv.__loaded) { - loadTTEnv.__loaded = true; - container.load(ttEnvModule); - container.load(ttCanvasModule); - container.load(ttWindowModule); - loadPicker && loadMathPicker(container); - } -} - -loadTTEnv.__loaded = false; - -export function initTTEnv() { - loadTTEnv(container); +/** Registry-based registration for tt env/window */ +export function registerTtEnvRegistry() { + application.contributions.register(EnvContribution, new TTEnvContribution()); + application.contributions.register(WindowHandlerContribution, new TTWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/wx.ts b/packages/vrender-kits/src/env/wx.ts index 685baa817..12110edfe 100644 --- a/packages/vrender-kits/src/env/wx.ts +++ b/packages/vrender-kits/src/env/wx.ts @@ -1,33 +1,16 @@ -import { container, ContainerModule, type Container, EnvContribution } from '@visactor/vrender-core'; -import { loadMathPicker } from '../picker/math-module'; +import { EnvContribution, application, WindowHandlerContribution } from '@visactor/vrender-core'; +// import { loadMathPicker } from '../picker/math-module'; // import { wxEnvModule } from './contributions/module'; -import { wxCanvasModule } from '../canvas/contributions/wx/modules'; -import { wxWindowModule } from '../window/contributions/wx-contribution'; +import { registerWxCanvasFactories } from '../canvas/contributions/wx/modules'; +import { WxWindowHandlerContribution } from '../window/contributions/wx-contribution'; import { WxEnvContribution } from './contributions/wx-contribution'; -export const wxEnvModule = new ContainerModule(bind => { - // wx - if (!(wxEnvModule as any)._isWxBound) { - (wxEnvModule as any)._isWxBound = true; - bind(WxEnvContribution).toSelf().inSingletonScope(); - bind(EnvContribution).toService(WxEnvContribution); - } -}); +// Legacy ContainerModule and loaders removed (registry-only) -(wxEnvModule as any)._isWxBound = false; - -export function loadWxEnv(container: Container, loadPicker: boolean = true) { - if (!loadWxEnv.__loaded) { - loadWxEnv.__loaded = true; - container.load(wxEnvModule); - container.load(wxCanvasModule); - container.load(wxWindowModule); - loadPicker && loadMathPicker(container); - } -} - -loadWxEnv.__loaded = false; - -export function initWxEnv() { - loadWxEnv(container); +/** Registry-based registration for wx env/window */ +export function registerWxEnvRegistry() { + application.contributions.register(EnvContribution, new WxEnvContribution()); + // ensure canvas factories for wx are registered + registerWxCanvasFactories(); + application.contributions.register(WindowHandlerContribution, new WxWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/graphic/Lottie.ts b/packages/vrender-kits/src/graphic/Lottie.ts index 1c8582174..edb858e4b 100644 --- a/packages/vrender-kits/src/graphic/Lottie.ts +++ b/packages/vrender-kits/src/graphic/Lottie.ts @@ -1,7 +1,7 @@ import { min } from '@visactor/vutils'; import { LOTTIE_NUMBER_TYPE } from './constants'; import type { IRectGraphicAttribute } from '@visactor/vrender-core'; -import { getTheme, GraphicType, IContext2d, NOWORK_ANIMATE_ATTR, Rect, vglobal } from '@visactor/vrender-core'; +import { getTheme, GraphicType, IContext2d, NOWORK_ANIMATE_ATTR, Rect, application } from '@visactor/vrender-core'; import type { ILottie, ILottieGraphicAttribute } from './interface/lottie'; import type { AnimationItem } from 'lottie-web'; import bodymovin from 'lottie-web'; @@ -40,7 +40,7 @@ export class Lottie extends Rect implements ILottie { initLottieWeb(data: string) { // 必须是浏览器环境才行 - if (vglobal.env !== 'browser') { + if (application.global.env !== 'browser') { return; } if (this.lottieInstance) { @@ -48,7 +48,7 @@ export class Lottie extends Rect implements ILottie { } const theme = this.getGraphicTheme(); const { width = theme.width, height = theme.height } = this.attribute; - const canvas = vglobal.createCanvas({ width, height, dpr: vglobal.devicePixelRatio }); + const canvas = application.global.createCanvas({ width, height, dpr: application.global.devicePixelRatio }); const params: any = { // wrapper: svgContainer, rendererSettings: { diff --git a/packages/vrender-kits/src/index-node.ts b/packages/vrender-kits/src/index-node.ts index 40eabea39..d0b96efd8 100644 --- a/packages/vrender-kits/src/index-node.ts +++ b/packages/vrender-kits/src/index-node.ts @@ -1,6 +1,6 @@ -import _roughModule from './render/contributions/rough/module'; +import { registerRoughCanvasRenders as _registerRoughCanvasRenders } from './render/contributions/rough/module'; // import _canvasModuleLoader from './canvas/contributions/canvas-module'; -export const roughModule = _roughModule; +export const registerRoughCanvasRenders = _registerRoughCanvasRenders; // export const canvasModuleLoader = _canvasModuleLoader; // export { nodeLoader } from './node-bind'; diff --git a/packages/vrender-kits/src/index.ts b/packages/vrender-kits/src/index.ts index 8aa9561fd..64ca94e76 100644 --- a/packages/vrender-kits/src/index.ts +++ b/packages/vrender-kits/src/index.ts @@ -1,7 +1,7 @@ -import _roughModule from './render/contributions/rough/module'; +import { registerRoughCanvasRenders as _registerRoughCanvasRenders } from './render/contributions/rough/module'; // import _canvasModuleLoader from './canvas/contributions/canvas-module'; -export const roughModule = _roughModule; +export const registerRoughCanvasRenders = _registerRoughCanvasRenders; export * from './picker/contributions/constants'; export * from './jsx'; diff --git a/packages/vrender-kits/src/picker/canvas-module.ts b/packages/vrender-kits/src/picker/canvas-module.ts index c2e5eb591..ef7e61741 100644 --- a/packages/vrender-kits/src/picker/canvas-module.ts +++ b/packages/vrender-kits/src/picker/canvas-module.ts @@ -1,21 +1,14 @@ -import type { container } from '@visactor/vrender-core'; -import { ContainerModule, PickerService } from '@visactor/vrender-core'; +import { application, PickerService } from '@visactor/vrender-core'; import { DefaultCanvasPickerService } from './canvas-picker-service'; -import canvasModule from './contributions/canvas-picker/module'; +import { registerCanvasGroupPicker } from './contributions/canvas-picker/module'; -// canvas -export const canvasPickerModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (!isBound(DefaultCanvasPickerService)) { - bind(DefaultCanvasPickerService).toSelf().inSingletonScope(); +export function registerCanvasPickerService() { + if ((registerCanvasPickerService as any).__loaded) { + return; } - if (isBound(PickerService)) { - rebind(PickerService).toService(DefaultCanvasPickerService); - } else { - bind(PickerService).toService(DefaultCanvasPickerService); - } -}); - -export function loadCanvasPicker(c: typeof container) { - c.load(canvasModule); - c.load(canvasPickerModule); + (registerCanvasPickerService as any).__loaded = true; + // Override PickerService to use canvas-based service + application.services.registerSingletonFactory(PickerService, () => new DefaultCanvasPickerService()); + // Ensure group picker is registered + registerCanvasGroupPicker(); } diff --git a/packages/vrender-kits/src/picker/canvas-picker-service.ts b/packages/vrender-kits/src/picker/canvas-picker-service.ts index f9d4b3514..dab05c724 100644 --- a/packages/vrender-kits/src/picker/canvas-picker-service.ts +++ b/packages/vrender-kits/src/picker/canvas-picker-service.ts @@ -1,74 +1,39 @@ import type { IMatrix, IPointLike } from '@visactor/vutils'; -// eslint-disable-next-line import { - ContributionProvider, - inject, - injectable, - named, DefaultPickService, - DrawContribution, - PickItemInterceptor, canvasAllocate, - application, - PickServiceInterceptor + type ICanvas, + type IContext2d, + type IGraphic, + type EnvType, + type IGlobal, + type IGraphicPicker, + type IPickerService, + type IContributionProvider, + type IPickParams, + type PickResult, + application } from '@visactor/vrender-core'; -import type { - ICanvas, - IContext2d, - IGraphic, - EnvType, - IGlobal, - IGraphicPicker, - IPickerService, - IDrawContribution, - IContributionProvider, - IPickItemInterceptorContribution, - IPickParams, - PickResult, - IPickServiceInterceptorContribution -} from '@visactor/vrender-core'; -import { - CanvasArcPicker, - CanvasAreaPicker, - CanvasCirclePicker, - CanvasImagePicker, - CanvasLinePicker, - CanvasPathPicker, - CanvasPickerContribution, - CanvasPolygonPicker, - CanvasRectPicker, - CanvasSymbolPicker, - CanvasTextPicker, - CanvasRichTextPicker -} from './contributions/constants'; +import { CanvasPickerContribution } from './contributions/constants'; // 默认的pick-service,提供基本的最优选中策略,尽量不需要用户自己实现contribution // 用户可以写plugin -@injectable() export class DefaultCanvasPickerService extends DefaultPickService implements IPickerService { declare type: 'default'; - // pcik canvas + // pick canvas declare pickCanvas: ICanvas; declare pickContext: IContext2d; declare pickerMap: Map; - constructor( - @inject(ContributionProvider) - @named(CanvasPickerContribution) - protected readonly contributions: IContributionProvider, + protected readonly contributions: IContributionProvider; - @inject(DrawContribution) - public readonly drawContribution: IDrawContribution, - // 拦截器 - @inject(ContributionProvider) - @named(PickItemInterceptor) - protected readonly pickItemInterceptorContributions: IContributionProvider, + constructor() { + super(); + // Use registry-only provider for canvas pickers + this.contributions = { + getContributions: () => application.contributions.get(CanvasPickerContribution) + } as IContributionProvider; - @inject(ContributionProvider) - @named(PickServiceInterceptor) - protected readonly pickServiceInterceptorContributions: IContributionProvider - ) { - super(pickItemInterceptorContributions, pickServiceInterceptorContributions); this.global.hooks.onSetEnv.tap('canvas-picker-service', (_, env, global) => { this.configure(global, env); }); @@ -85,11 +50,6 @@ export class DefaultCanvasPickerService extends DefaultPickService implements IP } configure(global: IGlobal, env: EnvType) { - // if (!this.global.env) return; - // this.contributions.getContributions().forEach(handlerContribution => { - // handlerContribution.configure(this, this.global); - // }); - // 创建pick canvas this.pickCanvas = canvasAllocate.shareCanvas(); this.pickContext = this.pickCanvas.getContext('2d'); diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/arc-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/arc-module.ts index ffdbc8c2e..b603b567f 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/arc-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/arc-module.ts @@ -1,13 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; +import { application } from '@visactor/vrender-core'; import { DefaultCanvasArcPicker } from './arc-picker'; -import { CanvasArcPicker, CanvasPickerContribution } from '../constants'; +import { CanvasPickerContribution } from '../constants'; -let loadArcPick = false; -export const arcCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadArcPick) { +let _registered = false; +export function registerCanvasArcPicker() { + if (_registered) { return; } - loadArcPick = true; - bind(CanvasArcPicker).to(DefaultCanvasArcPicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasArcPicker); -}); + _registered = true; + application.contributions.register(CanvasPickerContribution, new DefaultCanvasArcPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/arc-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/arc-picker.ts index 62b18077e..03d93f29c 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/arc-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/arc-picker.ts @@ -1,13 +1,14 @@ -import { inject, injectable, ArcRender, ARC_NUMBER_TYPE } from '@visactor/vrender-core'; +import { application, ArcRender, ARC_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; -@injectable() export class DefaultCanvasArcPicker extends PickerBase implements IGraphicPicker { type: string = 'arc'; numberType: number = ARC_NUMBER_TYPE; - constructor(@inject(ArcRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + const render = application.contributions.get(ArcRender)[0]; + this.canvasRenderer = render; } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/arc3d-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/arc3d-module.ts index e3a318ae4..66fc6d623 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/arc3d-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/arc3d-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { CanvasArc3dPicker, CanvasPickerContribution } from '../constants'; +import { application } from '@visactor/vrender-core'; +import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasArc3dPicker } from './arc3d-picker'; -let loadArc3dPick = false; -export const arc3dCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadArc3dPick) { +let _registeredArc3d = false; +export function registerCanvasArc3dPicker() { + if (_registeredArc3d) { return; } - loadArc3dPick = true; - // arc3d picker - bind(CanvasArc3dPicker).to(DefaultCanvasArc3dPicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasArc3dPicker); -}); + _registeredArc3d = true; + application.contributions.register(CanvasPickerContribution, new DefaultCanvasArc3dPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/arc3d-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/arc3d-picker.ts index 70834fb6e..74cfc672d 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/arc3d-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/arc3d-picker.ts @@ -1,14 +1,18 @@ -import { inject, injectable, Arc3dRender, ARC3D_NUMBER_TYPE } from '@visactor/vrender-core'; +import { application, Arc3dRender, ARC3D_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IArc3d, IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { Base3dPicker } from '../common/base-3d-picker'; -@injectable() export class DefaultCanvasArc3dPicker extends Base3dPicker implements IGraphicPicker { type: string = 'arc3d'; numberType: number = ARC3D_NUMBER_TYPE; themeType: string = 'arc'; - constructor(@inject(Arc3dRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(Arc3dRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(Arc3dRender)[0]; + } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/area-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/area-module.ts index 2ec29a079..ac5f963d1 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/area-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/area-module.ts @@ -1,14 +1,13 @@ -import { ContainerModule } from '@visactor/vrender-core'; +import { application } from '@visactor/vrender-core'; import { CanvasAreaPicker, CanvasPickerContribution } from '../constants'; import { DefaultCanvasAreaPicker } from './area-picker'; let loadAreaPick = false; -export const areaCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { +export function registerCanvasAreaPicker() { if (loadAreaPick) { return; } loadAreaPick = true; // area picker - bind(CanvasAreaPicker).to(DefaultCanvasAreaPicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasAreaPicker); -}); + application.contributions.register(CanvasPickerContribution, new DefaultCanvasAreaPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/area-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/area-picker.ts index c3cea6cc6..41af478d1 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/area-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/area-picker.ts @@ -1,13 +1,17 @@ -import { inject, injectable, AreaRender, AREA_NUMBER_TYPE } from '@visactor/vrender-core'; +import { AreaRender, AREA_NUMBER_TYPE, application } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; -@injectable() export class DefaultCanvasAreaPicker extends PickerBase implements IGraphicPicker { type: string = 'area'; numberType: number = AREA_NUMBER_TYPE; - constructor(@inject(AreaRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(AreaRender); + } catch (_) { + this.canvasRenderer = application.contributions.get(AreaRender)[0]; + } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/circle-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/circle-module.ts index 028834bf1..d601ed110 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/circle-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/circle-module.ts @@ -1,16 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { CanvasCirclePicker, CanvasLinePicker, CanvasPickerContribution, CanvasTextPicker } from '../constants'; -import { DefaultCanvasLinePicker } from './line-picker'; -import { DefaultCanvasTextPicker } from './text-picker'; +import { application } from '@visactor/vrender-core'; +import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasCirclePicker } from './circle-picker'; -let loadCirclePick = false; -export const circleCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadCirclePick) { +let _registeredCircle = false; +export function registerCanvasCirclePicker() { + if (_registeredCircle) { return; } - loadCirclePick = true; - // circle picker - bind(CanvasCirclePicker).to(DefaultCanvasCirclePicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasCirclePicker); -}); + _registeredCircle = true; + application.contributions.register(CanvasPickerContribution, new DefaultCanvasCirclePicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/circle-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/circle-picker.ts index 087cdc9b0..3466ee38f 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/circle-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/circle-picker.ts @@ -1,13 +1,17 @@ -import { inject, injectable, CircleRender, CIRCLE_NUMBER_TYPE } from '@visactor/vrender-core'; +import { CircleRender, CIRCLE_NUMBER_TYPE, application } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; -@injectable() export class DefaultCanvasCirclePicker extends PickerBase implements IGraphicPicker { type: string = 'circle'; numberType: number = CIRCLE_NUMBER_TYPE; - constructor(@inject(CircleRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(CircleRender); + } catch (_) { + this.canvasRenderer = application.contributions.get(CircleRender)[0]; + } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/gif-image-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/gif-image-module.ts index 755c5eec0..0c4628008 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/gif-image-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/gif-image-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { CanvasGifImagePicker, CanvasPickerContribution } from '../constants'; +import { application } from '@visactor/vrender-core'; +import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasGifImagePicker } from './gif-image-picker'; -let loadGifImagePick = false; -export const gifImageCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadGifImagePick) { +let _registeredGifImage = false; +export function registerCanvasGifImagePicker() { + if (_registeredGifImage) { return; } - loadGifImagePick = true; - // gifGifImage picker - bind(CanvasGifImagePicker).to(DefaultCanvasGifImagePicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasGifImagePicker); -}); + _registeredGifImage = true; + application.contributions.register(CanvasPickerContribution, new DefaultCanvasGifImagePicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/gif-image-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/gif-image-picker.ts index 4a7634db5..9d16a87ec 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/gif-image-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/gif-image-picker.ts @@ -1,21 +1,13 @@ import type { IPoint } from '@visactor/vutils'; -import { injectable } from '@visactor/vrender-core'; import type { IGraphicPicker, IPickParams } from '@visactor/vrender-core'; import type { IGifImage } from '../../../interface/gif-image'; import { GIFIMAGE_NUMBER_TYPE } from '../../../graphic/constants'; -@injectable() export class DefaultCanvasGifImagePicker implements IGraphicPicker { type: string = 'gif-image'; numberType: number = GIFIMAGE_NUMBER_TYPE; contains(gifImage: IGifImage, point: IPoint, params?: IPickParams): boolean { - // const { gifImageAttribute } = graphicService.themeService.getCurrentTheme(); - // const { - // x = gifImageAttribute.x, - // y = gifImageAttribute.y, - // } = gifImage.attribute; - const { pickContext } = params ?? {}; if (!pickContext) { return false; diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/glyph-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/glyph-module.ts index 04ea64981..60440caeb 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/glyph-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/glyph-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { CanvasGlyphPicker, CanvasPickerContribution } from '../constants'; +import { application } from '@visactor/vrender-core'; +import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasGlyphPicker } from './glyph-picker'; -let loadGlyphPick = false; -export const glyphCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadGlyphPick) { +let _registeredGlyph = false; +export function registerCanvasGlyphPicker() { + if (_registeredGlyph) { return; } - loadGlyphPick = true; - // glyph picker - bind(CanvasGlyphPicker).to(DefaultCanvasGlyphPicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasGlyphPicker); -}); + _registeredGlyph = true; + application.contributions.register(CanvasPickerContribution, new DefaultCanvasGlyphPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/glyph-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/glyph-picker.ts index f3386728f..b2e73825d 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/glyph-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/glyph-picker.ts @@ -1,10 +1,14 @@ -import { inject, injectable, GlyphRender } from '@visactor/vrender-core'; +import { GlyphRender, application } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { GlyphPickerBase } from '../common/glyph-picker-base'; -@injectable() export class DefaultCanvasGlyphPicker extends GlyphPickerBase implements IGraphicPicker { - constructor(@inject(GlyphRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(GlyphRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(GlyphRender)[0]; + } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/group-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/group-picker.ts index 448822f0f..78911efc7 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/group-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/group-picker.ts @@ -1,20 +1,14 @@ import type { IPoint } from '@visactor/vutils'; -import { injectable, GROUP_NUMBER_TYPE } from '@visactor/vrender-core'; +import { GROUP_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IGraphicPicker, IPickParams, IGroup } from '@visactor/vrender-core'; -@injectable() export class DefaultCanvasGroupPicker implements IGraphicPicker { type: string = 'group'; numberType: number = GROUP_NUMBER_TYPE; - // constructor(@inject(RectRender) public readonly canvasRenderer: IGraphicRender) {} - contains(group: IGroup, point: IPoint, params?: IPickParams): boolean { // Group作为特殊节点,本身不支持被pick // 存在shadowDOM的group,它的shadow可以被pick,但是不会冒泡到场景树中 return false; - // if (group.attribute.pickMode === 'imprecise') { - // return true; - // } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/image-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/image-module.ts index 7eb0658b6..3d9abfe7d 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/image-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/image-module.ts @@ -1,15 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { CanvasGlyphPicker, CanvasImagePicker, CanvasPickerContribution } from '../constants'; -import { DefaultCanvasGlyphPicker } from './glyph-picker'; +import { application } from '@visactor/vrender-core'; +import { CanvasImagePicker, CanvasPickerContribution } from '../constants'; import { DefaultCanvasImagePicker } from './image-picker'; -let loadImagePick = false; -export const imageCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadImagePick) { +let _registered = false; +export function registerCanvasImagePicker() { + if (_registered) { return; } - loadImagePick = true; - // image picker - bind(CanvasImagePicker).to(DefaultCanvasImagePicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasImagePicker); -}); + _registered = true; + application.contributions.register(CanvasPickerContribution, new DefaultCanvasImagePicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/image-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/image-picker.ts index 2696c7483..047efff25 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/image-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/image-picker.ts @@ -1,14 +1,15 @@ import type { IPoint } from '@visactor/vutils'; -import { injectable, IMAGE_NUMBER_TYPE, inject, ImageRender } from '@visactor/vrender-core'; +import { IMAGE_NUMBER_TYPE, ImageRender, application } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender, IImage, IPickParams } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; -@injectable() export class DefaultCanvasImagePicker extends PickerBase implements IGraphicPicker { type: string = 'image'; numberType: number = IMAGE_NUMBER_TYPE; - constructor(@inject(ImageRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + const render = application.contributions.get(ImageRender)[0]; + this.canvasRenderer = render; } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/line-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/line-module.ts index b6f7c0927..beab37809 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/line-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/line-module.ts @@ -1,13 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { CanvasLinePicker, CanvasPickerContribution } from '../constants'; +import { application } from '@visactor/vrender-core'; +import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasLinePicker } from './line-picker'; -let loadLinePick = false; -export const lineCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadLinePick) { +let _registered = false; +export function registerCanvasLinePicker() { + if (_registered) { return; } - loadLinePick = true; - bind(CanvasLinePicker).to(DefaultCanvasLinePicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasLinePicker); -}); + _registered = true; + application.contributions.register(CanvasPickerContribution, new DefaultCanvasLinePicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/line-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/line-picker.ts index 402e0636d..53a613267 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/line-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/line-picker.ts @@ -1,13 +1,14 @@ -import { inject, injectable, LineRender, LINE_NUMBER_TYPE } from '@visactor/vrender-core'; +import { application, LineRender, LINE_NUMBER_TYPE } from '@visactor/vrender-core'; import type { ILine, IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { BaseLinePicker } from '../common/base-line-picker'; -@injectable() export class DefaultCanvasLinePicker extends BaseLinePicker implements IGraphicPicker { type: string = 'line'; numberType: number = LINE_NUMBER_TYPE; - constructor(@inject(LineRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + const render = application.contributions.get(LineRender)[0]; + this.canvasRenderer = render; } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/lottie-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/lottie-module.ts index 5e500c8f9..2214bcad7 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/lottie-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/lottie-module.ts @@ -1,13 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { CanvasLottiePicker, CanvasPickerContribution } from '../constants'; +import { application } from '@visactor/vrender-core'; +import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasLottiePicker } from './lottie-picker'; -let loadLottiePick = false; -export const lottieCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadLottiePick) { +let _registeredLottie = false; +export function registerCanvasLottiePicker() { + if (_registeredLottie) { return; } - loadLottiePick = true; - bind(CanvasLottiePicker).to(DefaultCanvasLottiePicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasLottiePicker); -}); + _registeredLottie = true; + application.contributions.register(CanvasPickerContribution, new DefaultCanvasLottiePicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/lottie-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/lottie-picker.ts index e81d1ae5a..a90e0d0cc 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/lottie-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/lottie-picker.ts @@ -1,10 +1,14 @@ -import { inject, injectable, RectRender } from '@visactor/vrender-core'; +import { application, RectRender } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { RectPickerBase } from '../common/rect-picker-base'; -@injectable() export class DefaultCanvasLottiePicker extends RectPickerBase implements IGraphicPicker { - constructor(@inject(RectRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(RectRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(RectRender)[0]; + } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/module.ts index c54e76de2..5a7164727 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/module.ts @@ -1,19 +1,12 @@ -import { ContainerModule, bindContributionProvider } from '@visactor/vrender-core'; +import { application } from '@visactor/vrender-core'; import { CanvasGroupPicker, CanvasPickerContribution } from '../constants'; import { DefaultCanvasGroupPicker } from './group-picker'; -const m = new ContainerModule((bind, unbind, isBound, rebind) => { - if ((m as any).__vloaded) { +let _registered = false; +export function registerCanvasGroupPicker() { + if (_registered) { return; } - (m as any).__vloaded = true; - // group picker - bind(CanvasGroupPicker).to(DefaultCanvasGroupPicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasGroupPicker); - - bindContributionProvider(bind, CanvasPickerContribution); -}); - -(m as any).__vloaded = false; - -export default m; + _registered = true; + application.contributions.register(CanvasPickerContribution, new DefaultCanvasGroupPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/path-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/path-module.ts index 7a03d2ed6..730e8afc9 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/path-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/path-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; +import { application } from '@visactor/vrender-core'; import { CanvasPathPicker, CanvasPickerContribution } from '../constants'; import { DefaultCanvasPathPicker } from './path-picker'; let loadPathPick = false; -export const pathCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { +export function registerCanvasPathPicker() { if (loadPathPick) { return; } loadPathPick = true; - // path picker - bind(CanvasPathPicker).to(DefaultCanvasPathPicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasPathPicker); -}); + application.contributions.register(CanvasPickerContribution, new DefaultCanvasPathPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/path-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/path-picker.ts index 7423494c4..9f19d4045 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/path-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/path-picker.ts @@ -1,13 +1,14 @@ -import { inject, injectable, PathRender, PATH_NUMBER_TYPE } from '@visactor/vrender-core'; +import { application, PathRender, PATH_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IPath, IGraphicRender, IGraphicPicker } from '@visactor/vrender-core'; import { BaseLinePicker } from '../common/base-line-picker'; -@injectable() export class DefaultCanvasPathPicker extends BaseLinePicker implements IGraphicPicker { type: string = 'path'; numberType: number = PATH_NUMBER_TYPE; - constructor(@inject(PathRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + const render = application.contributions.get(PathRender)[0]; + this.canvasRenderer = render; } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/polygon-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/polygon-module.ts index 8a7ac8a89..8a4b73dc1 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/polygon-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/polygon-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { CanvasPickerContribution, CanvasPolygonPicker } from '../constants'; +import { application } from '@visactor/vrender-core'; +import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasPolygonPicker } from './polygon-picker'; -let loadPolygonPick = false; -export const polygonCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadPolygonPick) { +let _registeredPolygon = false; +export function registerCanvasPolygonPicker() { + if (_registeredPolygon) { return; } - loadPolygonPick = true; - // polygon picker - bind(CanvasPolygonPicker).to(DefaultCanvasPolygonPicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasPolygonPicker); -}); + _registeredPolygon = true; + application.contributions.register(CanvasPickerContribution, new DefaultCanvasPolygonPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/polygon-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/polygon-picker.ts index 1df71470d..ffba45e72 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/polygon-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/polygon-picker.ts @@ -1,13 +1,17 @@ -import { inject, injectable, PolygonRender, POLYGON_NUMBER_TYPE } from '@visactor/vrender-core'; +import { PolygonRender, POLYGON_NUMBER_TYPE, application } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; -@injectable() export class DefaultCanvasPolygonPicker extends PickerBase implements IGraphicPicker { type: string = 'polygon'; numberType: number = POLYGON_NUMBER_TYPE; - constructor(@inject(PolygonRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(PolygonRender); + } catch (_) { + this.canvasRenderer = application.contributions.get(PolygonRender)[0]; + } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/pyramid3d-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/pyramid3d-module.ts index 1cbf201d0..efe572082 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/pyramid3d-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/pyramid3d-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { CanvasPickerContribution, CanvasPyramid3dPicker } from '../constants'; +import { application } from '@visactor/vrender-core'; +import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasPyramid3dPicker } from './pyramid3d-picker'; -let loadPyramid3dPick = false; -export const pyramid3dCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadPyramid3dPick) { +let _registeredPyramid3d = false; +export function registerCanvasPyramid3dPicker() { + if (_registeredPyramid3d) { return; } - loadPyramid3dPick = true; - // pyramid3d picker - bind(CanvasPyramid3dPicker).to(DefaultCanvasPyramid3dPicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasPyramid3dPicker); -}); + _registeredPyramid3d = true; + application.contributions.register(CanvasPickerContribution, new DefaultCanvasPyramid3dPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/pyramid3d-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/pyramid3d-picker.ts index 586a01770..9e9000b13 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/pyramid3d-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/pyramid3d-picker.ts @@ -1,15 +1,19 @@ -import { inject, injectable, Pyramid3dRender, PYRAMID3D_NUMBER_TYPE } from '@visactor/vrender-core'; +import { application, Pyramid3dRender, PYRAMID3D_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IPyramid3d, IGraphicRender, IGraphicPicker } from '@visactor/vrender-core'; import { Base3dPicker } from '../common/base-3d-picker'; -@injectable() export class DefaultCanvasPyramid3dPicker extends Base3dPicker implements IGraphicPicker { type: string = 'pyramid3d'; numberType: number = PYRAMID3D_NUMBER_TYPE; themeType: string = 'polygon'; - constructor(@inject(Pyramid3dRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(Pyramid3dRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(Pyramid3dRender)[0]; + } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/rect-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/rect-module.ts index b4f71e2d1..9ce999959 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/rect-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/rect-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { DefaultCanvasArcPicker } from './arc-picker'; -import { CanvasArcPicker, CanvasPickerContribution, CanvasRectPicker } from '../constants'; +import { application } from '@visactor/vrender-core'; +import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasRectPicker } from './rect-picker'; -let loadRectPick = false; -export const rectCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadRectPick) { +let _registeredRect = false; +export function registerCanvasRectPicker() { + if (_registeredRect) { return; } - loadRectPick = true; - bind(CanvasRectPicker).to(DefaultCanvasRectPicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasRectPicker); -}); + _registeredRect = true; + application.contributions.register(CanvasPickerContribution, new DefaultCanvasRectPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/rect-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/rect-picker.ts index 300ba5cd0..a310e9a25 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/rect-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/rect-picker.ts @@ -1,10 +1,11 @@ -import { inject, injectable, RectRender } from '@visactor/vrender-core'; +import { application, RectRender } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { RectPickerBase } from '../common/rect-picker-base'; -@injectable() export class DefaultCanvasRectPicker extends RectPickerBase implements IGraphicPicker { - constructor(@inject(RectRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + const render = application.contributions.get(RectRender)[0]; + this.canvasRenderer = render; } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/rect3d-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/rect3d-module.ts index db220dcfc..d4e8d709a 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/rect3d-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/rect3d-module.ts @@ -1,16 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { DefaultCanvasArcPicker } from './arc-picker'; -import { CanvasArcPicker, CanvasPickerContribution, CanvasRect3dPicker, CanvasRectPicker } from '../constants'; -import { DefaultCanvasRectPicker } from './rect-picker'; +import { application } from '@visactor/vrender-core'; +import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasRect3dPicker } from './rect3d-picker'; -let loadRect3dPick = false; -export const rect3dCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadRect3dPick) { +let _registeredRect3d = false; +export function registerCanvasRect3dPicker() { + if (_registeredRect3d) { return; } - loadRect3dPick = true; - // reat3d picker - bind(CanvasRect3dPicker).to(DefaultCanvasRect3dPicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasRect3dPicker); -}); + _registeredRect3d = true; + application.contributions.register(CanvasPickerContribution, new DefaultCanvasRect3dPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/rect3d-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/rect3d-picker.ts index ad764758f..3f30d175e 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/rect3d-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/rect3d-picker.ts @@ -1,14 +1,18 @@ -import { inject, injectable, Rect3DRender, RECT3D_NUMBER_TYPE } from '@visactor/vrender-core'; +import { application, Rect3DRender, RECT3D_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IRect3d, IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { Base3dPicker } from '../common/base-3d-picker'; -@injectable() export class DefaultCanvasRect3dPicker extends Base3dPicker implements IGraphicPicker { type: string = 'rect3d'; numberType: number = RECT3D_NUMBER_TYPE; themeType: string = 'rect'; - constructor(@inject(Rect3DRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(Rect3DRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(Rect3DRender)[0]; + } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/richtext-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/richtext-module.ts index ea2936dab..40962a298 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/richtext-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/richtext-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; +import { application } from '@visactor/vrender-core'; import { CanvasPickerContribution, CanvasRichTextPicker } from '../constants'; import { DefaultCanvasRichTextPicker } from './richtext-picker'; let loadRichtextPick = false; -export const richtextCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { +export function registerCanvasRichtextPicker() { if (loadRichtextPick) { return; } loadRichtextPick = true; - // richtext picker - bind(CanvasRichTextPicker).to(DefaultCanvasRichTextPicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasRichTextPicker); -}); + application.contributions.register(CanvasPickerContribution, new DefaultCanvasRichTextPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/richtext-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/richtext-picker.ts index 9aa1c540a..c1d05fd2e 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/richtext-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/richtext-picker.ts @@ -1,12 +1,17 @@ import type { IPoint } from '@visactor/vutils'; -import { inject, injectable, RICHTEXT_NUMBER_TYPE, RichTextRender } from '@visactor/vrender-core'; +import { application, RICHTEXT_NUMBER_TYPE, RichTextRender } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender, IPickParams, IRichText } from '@visactor/vrender-core'; -@injectable() export class DefaultCanvasRichTextPicker implements IGraphicPicker { type: string = 'richtext'; numberType: number = RICHTEXT_NUMBER_TYPE; - constructor(@inject(RichTextRender) public readonly canvasRenderer: IGraphicRender) {} + constructor() { + try { + (this as any).canvasRenderer = application.services.get(RichTextRender) as IGraphicRender; + } catch (_) { + (this as any).canvasRenderer = application.contributions.get(RichTextRender)[0]; + } + } contains(richtext: IRichText, point: IPoint, params?: IPickParams): boolean { if (richtext.AABBBounds.containsPoint(point)) { diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/star-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/star-module.ts index 4019cd954..acc01b3c8 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/star-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/star-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; +import { application } from '@visactor/vrender-core'; import { CanvasPickerContribution, CanvasStarPicker } from '../constants'; import { DefaultCanvasStarPicker } from './star-picker'; let loadStarPick = false; -export const starCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { +export function registerCanvasStarPicker() { if (loadStarPick) { return; } loadStarPick = true; - // star picker - bind(CanvasStarPicker).to(DefaultCanvasStarPicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasStarPicker); -}); + application.contributions.register(CanvasPickerContribution, new DefaultCanvasStarPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/star-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/star-picker.ts index 94d65f98e..2e658baad 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/star-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/star-picker.ts @@ -1,13 +1,17 @@ -import { inject, injectable, StarRender, STAR_NUMBER_TYPE } from '@visactor/vrender-core'; +import { StarRender, STAR_NUMBER_TYPE, application } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; -@injectable() export class DefaultCanvasStarPicker extends PickerBase implements IGraphicPicker { type: string = 'star'; numberType: number = STAR_NUMBER_TYPE; - constructor(@inject(StarRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(StarRender); + } catch (_) { + this.canvasRenderer = application.contributions.get(StarRender)[0]; + } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/symbol-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/symbol-module.ts index 4acb5e7f3..849abc449 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/symbol-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/symbol-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; +import { application } from '@visactor/vrender-core'; import { CanvasPickerContribution, CanvasSymbolPicker } from '../constants'; import { DefaultCanvasSymbolPicker } from './symbol-picker'; let loadSymbolPick = false; -export const symbolCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { +export function registerCanvasSymbolPicker() { if (loadSymbolPick) { return; } loadSymbolPick = true; - // symbol picker - bind(CanvasSymbolPicker).to(DefaultCanvasSymbolPicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasSymbolPicker); -}); + application.contributions.register(CanvasPickerContribution, new DefaultCanvasSymbolPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/symbol-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/symbol-picker.ts index 1d5403621..c3bf0929e 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/symbol-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/symbol-picker.ts @@ -1,11 +1,4 @@ -import { - inject, - injectable, - SymbolRender, - mat4Allocate, - getScaledStroke, - SYMBOL_NUMBER_TYPE -} from '@visactor/vrender-core'; +import { SymbolRender, mat4Allocate, getScaledStroke, SYMBOL_NUMBER_TYPE, application } from '@visactor/vrender-core'; import type { IPoint } from '@visactor/vutils'; import type { IGraphicAttribute, @@ -19,13 +12,17 @@ import type { } from '@visactor/vrender-core'; import { Base3dPicker } from '../common/base-3d-picker'; -@injectable() export class DefaultCanvasSymbolPicker extends Base3dPicker implements IGraphicPicker { type: string = 'symbol'; numberType: number = SYMBOL_NUMBER_TYPE; - constructor(@inject(SymbolRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(SymbolRender); + } catch (_) { + this.canvasRenderer = application.contributions.get(SymbolRender)[0]; + } } contains(symbol: ISymbol, point: IPoint, params?: IPickParams): boolean { diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/text-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/text-module.ts index 29084cdd3..72adcd351 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/text-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/text-module.ts @@ -1,15 +1,13 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { CanvasLinePicker, CanvasPickerContribution, CanvasTextPicker } from '../constants'; -import { DefaultCanvasLinePicker } from './line-picker'; +import { application } from '@visactor/vrender-core'; +import { CanvasPickerContribution, CanvasTextPicker } from '../constants'; import { DefaultCanvasTextPicker } from './text-picker'; -let loadTextPick = false; -export const textCanvasPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadTextPick) { +let _registeredText = false; +export function registerCanvasTextPicker() { + if (_registeredText) { return; } - loadTextPick = true; - // text picker - bind(CanvasTextPicker).to(DefaultCanvasTextPicker).inSingletonScope(); - bind(CanvasPickerContribution).toService(CanvasTextPicker); -}); + _registeredText = true; + // Register picker implementation in contribution registry + application.contributions.register(CanvasPickerContribution, new DefaultCanvasTextPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/text-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/text-picker.ts index 59bcfea46..a224c09de 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/text-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/text-picker.ts @@ -1,12 +1,11 @@ import { - inject, - injectable, getTheme, TextRender, textDrawOffsetX, textLayoutOffsetY, mat4Allocate, - TEXT_NUMBER_TYPE + TEXT_NUMBER_TYPE, + application } from '@visactor/vrender-core'; import type { IPoint } from '@visactor/vutils'; import type { @@ -21,13 +20,17 @@ import type { } from '@visactor/vrender-core'; import { Base3dPicker } from '../common/base-3d-picker'; -@injectable() export class DefaultCanvasTextPicker extends Base3dPicker implements IGraphicPicker { type: string = 'text'; numberType: number = TEXT_NUMBER_TYPE; - constructor(@inject(TextRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + // text picker depends on TextRender via registry + // TextRender is a token exported by core + // Select first registered contribution + const render = application.contributions.get(TextRender)[0]; + this.canvasRenderer = render; } contains(text: IText, point: IPoint, params?: IPickParams): boolean { diff --git a/packages/vrender-kits/src/picker/contributions/common/glyph-picker-base.ts b/packages/vrender-kits/src/picker/contributions/common/glyph-picker-base.ts index c26ff99fc..f6605f0b1 100644 --- a/packages/vrender-kits/src/picker/contributions/common/glyph-picker-base.ts +++ b/packages/vrender-kits/src/picker/contributions/common/glyph-picker-base.ts @@ -1,8 +1,10 @@ import type { IPoint } from '@visactor/vutils'; import { GLYPH_NUMBER_TYPE } from '@visactor/vrender-core'; +import type { IGraphicRender } from '@visactor/vrender-core'; import type { IGlyph, IPickParams } from '@visactor/vrender-core'; export class GlyphPickerBase { + protected canvasRenderer!: IGraphicRender; type: string = 'glyph'; numberType: number = GLYPH_NUMBER_TYPE; diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/arc-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/arc-module.ts index 3919602e4..94fa662b8 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/arc-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/arc-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; +import { application } from '@visactor/vrender-core'; import { DefaultMathArcPicker } from './arc-picker'; -import { MathArcPicker, MathPickerContribution } from '../constants'; +import { MathPickerContribution } from '../constants'; -let loadArcPick = false; -export const arcMathPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadArcPick) { +let _registered = false; +export function registerMathArcPicker() { + if (_registered) { return; } - loadArcPick = true; - // arc picker - bind(MathArcPicker).to(DefaultMathArcPicker).inSingletonScope(); - bind(MathPickerContribution).toService(MathArcPicker); -}); + _registered = true; + application.contributions.register(MathPickerContribution, new DefaultMathArcPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/arc-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/arc-picker.ts index 333ff76e6..fff068bd9 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/arc-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/arc-picker.ts @@ -1,13 +1,17 @@ -import { inject, injectable, ArcRender, ARC_NUMBER_TYPE } from '@visactor/vrender-core'; +import { application, ArcRender, ARC_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; -@injectable() export class DefaultMathArcPicker extends PickerBase implements IGraphicPicker { type: string = 'arc'; numberType: number = ARC_NUMBER_TYPE; - constructor(@inject(ArcRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(ArcRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(ArcRender)[0]; + } } } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/area-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/area-module.ts index 46ad149ac..53ca6ff81 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/area-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/area-module.ts @@ -1,15 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { MathAreaPicker, MathLinePicker, MathPickerContribution } from '../constants'; -import { DefaultMathLinePicker } from './line-picker'; +import { application } from '@visactor/vrender-core'; +import { MathPickerContribution } from '../constants'; import { DefaultMathAreaPicker } from './area-picker'; -let loadAreaPick = false; -export const areaMathPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadAreaPick) { +let _registered = false; +export function registerMathAreaPicker() { + if (_registered) { return; } - loadAreaPick = true; - // area picker - bind(MathAreaPicker).to(DefaultMathAreaPicker).inSingletonScope(); - bind(MathPickerContribution).toService(MathAreaPicker); -}); + _registered = true; + application.contributions.register(MathPickerContribution, new DefaultMathAreaPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/area-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/area-picker.ts index b21ed6604..502ccf987 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/area-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/area-picker.ts @@ -1,14 +1,18 @@ -import { inject, injectable, AreaRender, AREA_NUMBER_TYPE } from '@visactor/vrender-core'; +import { application, AreaRender, AREA_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; -@injectable() export class DefaultMathAreaPicker extends PickerBase implements IGraphicPicker { type: string = 'area'; numberType: number = AREA_NUMBER_TYPE; - constructor(@inject(AreaRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(AreaRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(AreaRender)[0]; + } } } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/circle-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/circle-module.ts index f7c4b702c..26d04e583 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/circle-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/circle-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { MathCirclePicker, MathPickerContribution } from '../constants'; +import { application } from '@visactor/vrender-core'; +import { MathPickerContribution } from '../constants'; import { DefaultMathCirclePicker } from './circle-picker'; -let loadCirclePick = false; -export const circleMathPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadCirclePick) { +let _registered = false; +export function registerMathCirclePicker() { + if (_registered) { return; } - loadCirclePick = true; - // circle picker - bind(MathCirclePicker).to(DefaultMathCirclePicker).inSingletonScope(); - bind(MathPickerContribution).toService(MathCirclePicker); -}); + _registered = true; + application.contributions.register(MathPickerContribution, new DefaultMathCirclePicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/circle-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/circle-picker.ts index c5a573d7f..474de270c 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/circle-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/circle-picker.ts @@ -1,12 +1,16 @@ -import { inject, injectable, CircleRender, CIRCLE_NUMBER_TYPE } from '@visactor/vrender-core'; +import { application, CircleRender, CIRCLE_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; -@injectable() export class DefaultMathCirclePicker extends PickerBase implements IGraphicPicker { type: string = 'circle'; numberType: number = CIRCLE_NUMBER_TYPE; - constructor(@inject(CircleRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(CircleRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(CircleRender)[0]; + } } } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/glyph-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/glyph-module.ts index 55b4a0c7d..b867f64e0 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/glyph-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/glyph-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { MathGlyphPicker } from '../constants'; +import { application } from '@visactor/vrender-core'; +import { MathPickerContribution } from '../constants'; import { DefaultMathGlyphPicker } from './glyph-picker'; -let loadGlyphPick = false; -export const glyphMathPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadGlyphPick) { +let _registered = false; +export function registerMathGlyphPicker() { + if (_registered) { return; } - loadGlyphPick = true; - // glyph picker - bind(MathGlyphPicker).to(DefaultMathGlyphPicker).inSingletonScope(); - bind(DefaultMathGlyphPicker).toService(MathGlyphPicker); -}); + _registered = true; + application.contributions.register(MathPickerContribution, new DefaultMathGlyphPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/glyph-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/glyph-picker.ts index e11e67eaa..8d0b37cf1 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/glyph-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/glyph-picker.ts @@ -1,10 +1,14 @@ -import { inject, injectable, GlyphRender } from '@visactor/vrender-core'; +import { application, GlyphRender } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { GlyphPickerBase } from '../common/glyph-picker-base'; -@injectable() export class DefaultMathGlyphPicker extends GlyphPickerBase implements IGraphicPicker { - constructor(@inject(GlyphRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(GlyphRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(GlyphRender)[0]; + } } } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/image-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/image-module.ts index 58b91fee3..8b435fd9d 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/image-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/image-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { MathImagePicker } from '../constants'; +import { application } from '@visactor/vrender-core'; +import { MathPickerContribution } from '../constants'; import { DefaultMathImagePicker } from './image-picker'; -let loadImagePick = false; -export const imageMathPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadImagePick) { +let _registered = false; +export function registerMathImagePicker() { + if (_registered) { return; } - loadImagePick = true; - // glyph picker - bind(MathImagePicker).to(DefaultMathImagePicker).inSingletonScope(); - bind(DefaultMathImagePicker).toService(MathImagePicker); -}); + _registered = true; + application.contributions.register(MathPickerContribution, new DefaultMathImagePicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/image-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/image-picker.ts index e8fb299a5..4dc15d1e6 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/image-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/image-picker.ts @@ -1,19 +1,12 @@ import type { IPoint } from '@visactor/vutils'; -import { injectable, IMAGE_NUMBER_TYPE } from '@visactor/vrender-core'; +import { IMAGE_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IGraphicPicker, IImage, IPickParams } from '@visactor/vrender-core'; -@injectable() export class DefaultMathImagePicker implements IGraphicPicker { type: string = 'image'; numberType: number = IMAGE_NUMBER_TYPE; contains(image: IImage, point: IPoint, params?: IPickParams): boolean { - // const { imageAttribute } = graphicService.themeService.getCurrentTheme(); - // const { - // x = imageAttribute.x, - // y = imageAttribute.y, - // } = image.attribute; - const { pickContext } = params ?? {}; if (!pickContext) { return false; diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/line-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/line-module.ts index 460576235..3c5ea7d02 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/line-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/line-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { MathLinePicker, MathPickerContribution } from '../constants'; +import { application } from '@visactor/vrender-core'; +import { MathPickerContribution } from '../constants'; import { DefaultMathLinePicker } from './line-picker'; -let loadLinePick = false; -export const lineMathPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadLinePick) { +let _registered = false; +export function registerMathLinePicker() { + if (_registered) { return; } - loadLinePick = true; - // line picker - bind(MathLinePicker).to(DefaultMathLinePicker).inSingletonScope(); - bind(MathPickerContribution).toService(MathLinePicker); -}); + _registered = true; + application.contributions.register(MathPickerContribution, new DefaultMathLinePicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/line-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/line-picker.ts index c2145631e..38b643e0a 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/line-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/line-picker.ts @@ -1,13 +1,19 @@ -import { inject, injectable, LineRender, LINE_NUMBER_TYPE } from '@visactor/vrender-core'; +import { LineRender, LINE_NUMBER_TYPE, application } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; -@injectable() export class DefaultMathLinePicker extends PickerBase implements IGraphicPicker { type: string = 'line'; numberType: number = LINE_NUMBER_TYPE; - constructor(@inject(LineRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + // Acquire renderer via services (no inversify) + try { + this.canvasRenderer = application.services.get(LineRender) as IGraphicRender; + } catch (_) { + // fallback to contributions if services not registered yet + this.canvasRenderer = application.contributions.get(LineRender)[0]; + } } // numberType?: number = LINE_NUMBER_TYPE; } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/module.ts index e00147bf9..a4591f752 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/module.ts @@ -1,40 +1,4 @@ -import { ContainerModule, bindContributionProvider } from '@visactor/vrender-core'; -import { DefaultMathPathPicker } from './path-picker'; -import { - MathArcPicker, - MathAreaPicker, - MathCirclePicker, - MathGlyphPicker, - MathLinePicker, - MathPathPicker, - MathPickerContribution, - MathPolygonPicker, - MathRectPicker, - MathSymbolPicker, - MathTextPicker -} from '../constants'; -import { DefaultMathCirclePicker } from './circle-picker'; -import { DefaultMathRectPicker } from './rect-picker'; -import { DefaultMathAreaPicker } from './area-picker'; -import { DefaultMathLinePicker } from './line-picker'; -import { DefaultMathSymbolPicker } from './symbol-picker'; -import { DefaultMathTextPicker } from './text-picker'; -import { DefaultMathPolygonPicker } from './polygon-picker'; -import { DefaultMathGlyphPicker } from './glyph-picker'; - -const m = new ContainerModule(bind => { - if ((m as any).__vloaded) { - return; - } - (m as any).__vloaded = true; - // // image picker - // bind(DefaultCanvasImagePicker).toSelf().inSingletonScope(); - // bind(ImagePicker).toService(DefaultCanvasImagePicker); - // bind(PickerContribution).toService(ImagePicker); - - bindContributionProvider(bind, MathPickerContribution); -}); - -(m as any).__vloaded = false; - -export default m; +// Legacy ContainerModule-based provider removed. +// Math pickers are now registered via per-shape registerMathXxxPicker functions. +// This file can be removed or left empty to avoid import errors. +export default {} as unknown as void; diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/path-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/path-module.ts index 1dd8caa7f..97a7560a3 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/path-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/path-module.ts @@ -1,16 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { MathCirclePicker, MathPathPicker, MathPickerContribution, MathPolygonPicker } from '../constants'; -import { DefaultMathCirclePicker } from './circle-picker'; -import { DefaultMathPolygonPicker } from './polygon-picker'; +import { application } from '@visactor/vrender-core'; +import { MathPickerContribution } from '../constants'; import { DefaultMathPathPicker } from './path-picker'; -let loadPathPick = false; -export const pathMathPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadPathPick) { +let _registered = false; +export function registerMathPathPicker() { + if (_registered) { return; } - loadPathPick = true; - // path picker - bind(MathPathPicker).to(DefaultMathPathPicker).inSingletonScope(); - bind(MathPickerContribution).toService(MathPathPicker); -}); + _registered = true; + application.contributions.register(MathPickerContribution, new DefaultMathPathPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/path-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/path-picker.ts index 576caef66..2ab9a8c83 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/path-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/path-picker.ts @@ -1,13 +1,17 @@ -import { inject, injectable, PathRender, PATH_NUMBER_TYPE } from '@visactor/vrender-core'; +import { application, PathRender, PATH_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; -@injectable() export class DefaultMathPathPicker extends PickerBase implements IGraphicPicker { type: string = 'path'; numberType: number = PATH_NUMBER_TYPE; - constructor(@inject(PathRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(PathRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(PathRender)[0]; + } } } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/polygon-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/polygon-module.ts index a087d657b..9ef297437 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/polygon-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/polygon-module.ts @@ -1,15 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { MathCirclePicker, MathPickerContribution, MathPolygonPicker } from '../constants'; -import { DefaultMathCirclePicker } from './circle-picker'; +import { application } from '@visactor/vrender-core'; +import { MathPickerContribution } from '../constants'; import { DefaultMathPolygonPicker } from './polygon-picker'; -let loadPolygonPick = false; -export const polygonMathPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadPolygonPick) { +let _registered = false; +export function registerMathPolygonPicker() { + if (_registered) { return; } - loadPolygonPick = true; - // polygon picker - bind(MathPolygonPicker).to(DefaultMathPolygonPicker).inSingletonScope(); - bind(MathPickerContribution).toService(MathPolygonPicker); -}); + _registered = true; + application.contributions.register(MathPickerContribution, new DefaultMathPolygonPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/polygon-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/polygon-picker.ts index 76e936e09..79bfe4938 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/polygon-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/polygon-picker.ts @@ -1,13 +1,17 @@ -import { inject, injectable, PolygonRender, POLYGON_NUMBER_TYPE } from '@visactor/vrender-core'; +import { application, PolygonRender, POLYGON_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; -@injectable() export class DefaultMathPolygonPicker extends PickerBase implements IGraphicPicker { type: string = 'polygon'; numberType: number = POLYGON_NUMBER_TYPE; - constructor(@inject(PolygonRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(PolygonRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(PolygonRender)[0]; + } } } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/rect-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/rect-module.ts index bd234a0bd..8fa04f346 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/rect-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/rect-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { MathPickerContribution, MathRectPicker } from '../constants'; +import { application } from '@visactor/vrender-core'; +import { MathPickerContribution } from '../constants'; import { DefaultMathRectPicker } from './rect-picker'; -let loadRectPick = false; -export const rectMathPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadRectPick) { +let _registered = false; +export function registerMathRectPicker() { + if (_registered) { return; } - loadRectPick = true; - // rect picker - bind(MathRectPicker).to(DefaultMathRectPicker).inSingletonScope(); - bind(MathPickerContribution).toService(MathRectPicker); -}); + _registered = true; + application.contributions.register(MathPickerContribution, new DefaultMathRectPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/rect-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/rect-picker.ts index 5d9a0f1b4..e49942eea 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/rect-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/rect-picker.ts @@ -1,10 +1,14 @@ -import { inject, injectable, RectRender } from '@visactor/vrender-core'; +import { application, RectRender } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { RectPickerBase } from '../common/rect-picker-base'; -@injectable() export class DefaultMathRectPicker extends RectPickerBase implements IGraphicPicker { - constructor(@inject(RectRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(RectRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(RectRender)[0]; + } } } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/richtext-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/richtext-module.ts index af64ba450..2f821183f 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/richtext-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/richtext-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { MathImagePicker } from '../constants'; -import { DefaultMathImagePicker } from './image-picker'; +import { application } from '@visactor/vrender-core'; +import { MathPickerContribution } from '../constants'; +import { DefaultMathRichTextPicker } from './richtext-picker'; -let loadRichTextPick = false; -export const richTextMathPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadRichTextPick) { +let _registered = false; +export function registerMathRichTextPicker() { + if (_registered) { return; } - loadRichTextPick = true; - // glyph picker - bind(MathImagePicker).to(DefaultMathImagePicker).inSingletonScope(); - bind(DefaultMathImagePicker).toService(MathImagePicker); -}); + _registered = true; + application.contributions.register(MathPickerContribution, new DefaultMathRichTextPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/richtext-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/richtext-picker.ts index be49a1515..306281acb 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/richtext-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/richtext-picker.ts @@ -1,12 +1,17 @@ import type { IPoint } from '@visactor/vutils'; -import { inject, injectable, RICHTEXT_NUMBER_TYPE, RichTextRender } from '@visactor/vrender-core'; +import { application, RICHTEXT_NUMBER_TYPE, RichTextRender } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender, IPickParams, IRichText } from '@visactor/vrender-core'; -@injectable() export class DefaultMathRichTextPicker implements IGraphicPicker { type: string = 'richtext'; numberType: number = RICHTEXT_NUMBER_TYPE; - constructor(@inject(RichTextRender) public readonly canvasRenderer: IGraphicRender) {} + constructor() { + try { + (this as any).canvasRenderer = application.services.get(RichTextRender) as IGraphicRender; + } catch (_) { + (this as any).canvasRenderer = application.contributions.get(RichTextRender)[0]; + } + } contains(richtext: IRichText, point: IPoint, params?: IPickParams): boolean { if (richtext.AABBBounds.containsPoint(point)) { diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/symbol-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/symbol-module.ts index 220b7c98e..9402f9e6a 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/symbol-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/symbol-module.ts @@ -1,14 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { MathPickerContribution, MathSymbolPicker } from '../constants'; +import { application } from '@visactor/vrender-core'; +import { MathPickerContribution } from '../constants'; import { DefaultMathSymbolPicker } from './symbol-picker'; -let loadSymbolPick = false; -export const symbolMathPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadSymbolPick) { +let _registered = false; +export function registerMathSymbolPicker() { + if (_registered) { return; } - loadSymbolPick = true; - // symbol picker - bind(MathSymbolPicker).to(DefaultMathSymbolPicker).inSingletonScope(); - bind(MathPickerContribution).toService(MathSymbolPicker); -}); + _registered = true; + application.contributions.register(MathPickerContribution, new DefaultMathSymbolPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/symbol-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/symbol-picker.ts index d549b3d45..5ba729229 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/symbol-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/symbol-picker.ts @@ -1,14 +1,18 @@ -import { inject, injectable, SymbolRender, SYMBOL_NUMBER_TYPE } from '@visactor/vrender-core'; +import { application, SymbolRender, SYMBOL_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; -@injectable() export class DefaultMathSymbolPicker extends PickerBase implements IGraphicPicker { type: string = 'symbol'; numberType: number = SYMBOL_NUMBER_TYPE; - constructor(@inject(SymbolRender) public readonly canvasRenderer: IGraphicRender) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(SymbolRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(SymbolRender)[0]; + } } } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/text-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/text-module.ts index 0890742cc..99e9cb3c6 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/text-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/text-module.ts @@ -1,15 +1,12 @@ -import { ContainerModule } from '@visactor/vrender-core'; -import { DefaultMathArcPicker } from './arc-picker'; -import { MathArcPicker, MathPickerContribution, MathTextPicker } from '../constants'; +import { application } from '@visactor/vrender-core'; +import { MathPickerContribution } from '../constants'; import { DefaultMathTextPicker } from './text-picker'; -let loadTextPick = false; -export const textMathPickModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (loadTextPick) { +let _registered = false; +export function registerMathTextPicker() { + if (_registered) { return; } - loadTextPick = true; - // text picker - bind(MathTextPicker).to(DefaultMathTextPicker).inSingletonScope(); - bind(MathPickerContribution).toService(MathTextPicker); -}); + _registered = true; + application.contributions.register(MathPickerContribution, new DefaultMathTextPicker()); +} diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/text-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/text-picker.ts index 2c6339699..a5b54aa94 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/text-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/text-picker.ts @@ -1,8 +1,7 @@ -import { injectable, TEXT_NUMBER_TYPE } from '@visactor/vrender-core'; +import { TEXT_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IPoint } from '@visactor/vutils'; import type { IGraphicPicker, IPickParams, IText } from '@visactor/vrender-core'; -@injectable() export class DefaultMathTextPicker implements IGraphicPicker { type: string = 'text'; numberType: number = TEXT_NUMBER_TYPE; diff --git a/packages/vrender-kits/src/picker/math-module.ts b/packages/vrender-kits/src/picker/math-module.ts index 6f7054cd5..3db4fb23e 100644 --- a/packages/vrender-kits/src/picker/math-module.ts +++ b/packages/vrender-kits/src/picker/math-module.ts @@ -1,45 +1,11 @@ -import type { container } from '@visactor/vrender-core'; -import { ContainerModule, PickerService } from '@visactor/vrender-core'; +import { application, PickerService } from '@visactor/vrender-core'; import { DefaultMathPickerService } from './math-picker-service'; -import mathModule from './contributions/math-picker/module'; -import { arcMathPickModule } from './contributions/math-picker/arc-module'; -import { areaMathPickModule } from './contributions/math-picker/area-module'; -import { circleMathPickModule } from './contributions/math-picker/circle-module'; -import { glyphMathPickModule } from './contributions/math-picker/glyph-module'; -import { imageMathPickModule } from './contributions/math-picker/image-module'; -import { lineMathPickModule } from './contributions/math-picker/line-module'; -import { polygonMathPickModule } from './contributions/math-picker/polygon-module'; -import { pathMathPickModule } from './contributions/math-picker/path-module'; -import { rectMathPickModule } from './contributions/math-picker/rect-module'; -import { richTextMathPickModule } from './contributions/math-picker/richtext-module'; -import { symbolMathPickModule } from './contributions/math-picker/symbol-module'; -import { textMathPickModule } from './contributions/math-picker/text-module'; -// math -export const mathPickerModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (!isBound(DefaultMathPickerService)) { - bind(DefaultMathPickerService).toSelf().inSingletonScope(); +export function registerMathPickerService() { + if ((registerMathPickerService as any).__loaded) { + return; } - if (isBound(PickerService)) { - rebind(PickerService).toService(DefaultMathPickerService); - } else { - bind(PickerService).toService(DefaultMathPickerService); - } -}); - -export function loadMathPicker(c: typeof container) { - c.load(mathModule); - c.load(mathPickerModule); - c.load(arcMathPickModule); - c.load(areaMathPickModule); - c.load(circleMathPickModule); - c.load(glyphMathPickModule); - c.load(imageMathPickModule); - c.load(lineMathPickModule); - c.load(polygonMathPickModule); - c.load(pathMathPickModule); - c.load(rectMathPickModule); - c.load(richTextMathPickModule); - c.load(symbolMathPickModule); - c.load(textMathPickModule); + (registerMathPickerService as any).__loaded = true; + // Override PickerService to use math-based service (no canvas) + application.services.registerSingletonFactory(PickerService, () => new DefaultMathPickerService()); } diff --git a/packages/vrender-kits/src/picker/math-picker-service.ts b/packages/vrender-kits/src/picker/math-picker-service.ts index 7f69f0b40..d8448729c 100644 --- a/packages/vrender-kits/src/picker/math-picker-service.ts +++ b/packages/vrender-kits/src/picker/math-picker-service.ts @@ -1,54 +1,38 @@ import type { IMatrix, IPointLike } from '@visactor/vutils'; -// eslint-disable-next-line import { - ContributionProvider, - inject, - injectable, - named, DefaultPickService, EmptyContext2d, - PickItemInterceptor, - PickServiceInterceptor -} from '@visactor/vrender-core'; -import type { - ICanvas, - IContext2d, - IGraphic, - EnvType, - IGlobal, - IGraphicPicker, - IPickerService, - IContributionProvider, - IPickItemInterceptorContribution, - IPickParams, - PickResult, - IPickServiceInterceptorContribution + type ICanvas, + type IContext2d, + type IGraphic, + type EnvType, + type IGlobal, + type IGraphicPicker, + type IPickerService, + type IContributionProvider, + type IPickParams, + type PickResult, + application } from '@visactor/vrender-core'; import { MathPickerContribution } from './contributions/constants'; // 默认的pick-service,提供基本的最优选中策略,尽量不需要用户自己实现contribution // 用户可以写plugin -@injectable() export class DefaultMathPickerService extends DefaultPickService implements IPickerService { declare type: 'default'; - // pcik canvas + // pick canvas declare pickCanvas: ICanvas; declare pickContext: IContext2d; declare pickerMap: Map; - constructor( - @inject(ContributionProvider) - @named(MathPickerContribution) - protected readonly contributions: IContributionProvider, - // 拦截器 - @inject(ContributionProvider) - @named(PickItemInterceptor) - protected readonly pickItemInterceptorContributions: IContributionProvider, - @inject(ContributionProvider) - @named(PickServiceInterceptor) - protected readonly pickServiceInterceptorContributions: IContributionProvider - ) { - super(pickItemInterceptorContributions, pickServiceInterceptorContributions); + protected readonly contributions: IContributionProvider; + + constructor() { + super(); + this.contributions = { + getContributions: () => application.contributions.get(MathPickerContribution) + } as IContributionProvider; + this.global.hooks.onSetEnv.tap('math-picker-service', (lastEnv, env, global) => { this.configure(global, env); }); diff --git a/packages/vrender-kits/src/register/register-arc.ts b/packages/vrender-kits/src/register/register-arc.ts index 1a9fed289..7d571e25d 100644 --- a/packages/vrender-kits/src/register/register-arc.ts +++ b/packages/vrender-kits/src/register/register-arc.ts @@ -1,7 +1,7 @@ -import { arcModule, container, registerArcGraphic } from '@visactor/vrender-core'; +import { registerArcGraphic } from '@visactor/vrender-core'; import { browser } from './env'; -import { arcCanvasPickModule } from '../picker/contributions/canvas-picker/arc-module'; -import { arcMathPickModule } from '../picker/contributions/math-picker/arc-module'; +import { registerCanvasArcPicker } from '../picker/contributions/canvas-picker/arc-module'; +import { registerMathArcPicker } from '../picker/contributions/math-picker/arc-module'; export function _registerArc() { if (_registerArc.__loaded) { @@ -9,8 +9,11 @@ export function _registerArc() { } _registerArc.__loaded = true; registerArcGraphic(); - container.load(arcModule); - container.load(browser ? arcCanvasPickModule : arcMathPickModule); + if (browser) { + registerCanvasArcPicker(); + } else { + registerMathArcPicker(); + } } _registerArc.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-arc3d.ts b/packages/vrender-kits/src/register/register-arc3d.ts index 2b7774beb..6df908572 100644 --- a/packages/vrender-kits/src/register/register-arc3d.ts +++ b/packages/vrender-kits/src/register/register-arc3d.ts @@ -1,12 +1,6 @@ -import { - arc3dModule, - container, - registerArc3dGraphic, - registerDirectionalLight, - registerOrthoCamera -} from '@visactor/vrender-core'; +import { registerArc3dGraphic, registerDirectionalLight, registerOrthoCamera } from '@visactor/vrender-core'; import { browser } from './env'; -import { arc3dCanvasPickModule } from '../picker/contributions/canvas-picker/arc3d-module'; +import { registerCanvasArc3dPicker } from '../picker/contributions/canvas-picker/arc3d-module'; function _registerArc3d() { if (_registerArc3d.__loaded) { @@ -16,8 +10,10 @@ function _registerArc3d() { registerArc3dGraphic(); registerDirectionalLight(); registerOrthoCamera(); - container.load(arc3dModule); - container.load(browser ? arc3dCanvasPickModule : arc3dCanvasPickModule); + // arc3d renderer registered via core; no /* removed container */ usage + if (browser) { + registerCanvasArc3dPicker(); + } } _registerArc3d.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-area.ts b/packages/vrender-kits/src/register/register-area.ts index 0465c5427..2f8c94183 100644 --- a/packages/vrender-kits/src/register/register-area.ts +++ b/packages/vrender-kits/src/register/register-area.ts @@ -1,7 +1,7 @@ -import { areaModule, container, registerAreaGraphic } from '@visactor/vrender-core'; +import { registerAreaGraphic } from '@visactor/vrender-core'; import { browser } from './env'; -import { areaCanvasPickModule } from '../picker/contributions/canvas-picker/area-module'; -import { areaMathPickModule } from '../picker/contributions/math-picker/area-module'; +import { registerCanvasAreaPicker } from '../picker/contributions/canvas-picker/area-module'; +import { registerMathAreaPicker } from '../picker/contributions/math-picker/area-module'; function _registerArea() { if (_registerArea.__loaded) { @@ -9,8 +9,12 @@ function _registerArea() { } _registerArea.__loaded = true; registerAreaGraphic(); - container.load(areaModule); - container.load(browser ? areaCanvasPickModule : areaMathPickModule); + // area renderer registered via core; no container usage + if (browser) { + registerCanvasAreaPicker(); + } else { + registerMathAreaPicker(); + } } _registerArea.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-circle.ts b/packages/vrender-kits/src/register/register-circle.ts index c59844dc9..ec279dcf2 100644 --- a/packages/vrender-kits/src/register/register-circle.ts +++ b/packages/vrender-kits/src/register/register-circle.ts @@ -1,7 +1,7 @@ -import { circleModule, container, registerCircleGraphic } from '@visactor/vrender-core'; +import { registerCircleGraphic } from '@visactor/vrender-core'; import { browser } from './env'; -import { circleCanvasPickModule } from '../picker/contributions/canvas-picker/circle-module'; -import { circleMathPickModule } from '../picker/contributions/math-picker/circle-module'; +import { registerCanvasCirclePicker } from '../picker/contributions/canvas-picker/circle-module'; +import { registerMathCirclePicker } from '../picker/contributions/math-picker/circle-module'; function _registerCircle() { if (_registerCircle.__loaded) { @@ -9,8 +9,12 @@ function _registerCircle() { } _registerCircle.__loaded = true; registerCircleGraphic(); - container.load(circleModule); - container.load(browser ? circleCanvasPickModule : circleMathPickModule); + // circle renderer registered via core; no container usage + if (browser) { + registerCanvasCirclePicker(); + } else { + registerMathCirclePicker(); + } } _registerCircle.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-gif.ts b/packages/vrender-kits/src/register/register-gif.ts index 80b600cf1..5fd477ebe 100644 --- a/packages/vrender-kits/src/register/register-gif.ts +++ b/packages/vrender-kits/src/register/register-gif.ts @@ -1,7 +1,7 @@ -import { container, graphicCreator } from '@visactor/vrender-core'; +import { graphicCreator } from '@visactor/vrender-core'; import { createGifImage } from '../graphic/gif-image'; -import { gifImageModule } from '../render/contributions/canvas/gif-image-module'; -import { gifImageCanvasPickModule } from '../picker/contributions/canvas-picker/gif-image-module'; +import { registerCanvasGifImageRender } from '../render/contributions/canvas/gif-image-module'; +import { registerCanvasGifImagePicker } from '../picker/contributions/canvas-picker/gif-image-module'; export function registerGifGraphic() { graphicCreator.RegisterGraphicCreator('gif', createGifImage); @@ -13,8 +13,8 @@ function _registerGifImage() { } _registerGifImage.__loaded = true; registerGifGraphic(); - container.load(gifImageModule); - container.load(gifImageCanvasPickModule); + registerCanvasGifImageRender(); + registerCanvasGifImagePicker(); } _registerGifImage.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-glyph.ts b/packages/vrender-kits/src/register/register-glyph.ts index 46c2f1233..155888014 100644 --- a/packages/vrender-kits/src/register/register-glyph.ts +++ b/packages/vrender-kits/src/register/register-glyph.ts @@ -1,7 +1,7 @@ -import { container, glyphModule, registerGlyphGraphic } from '@visactor/vrender-core'; +import { registerGlyphGraphic } from '@visactor/vrender-core'; import { browser } from './env'; -import { glyphCanvasPickModule } from '../picker/contributions/canvas-picker/glyph-module'; -import { glyphMathPickModule } from '../picker/contributions/math-picker/glyph-module'; +import { registerCanvasGlyphPicker } from '../picker/contributions/canvas-picker/glyph-module'; +import { registerMathGlyphPicker } from '../picker/contributions/math-picker/glyph-module'; function _registerGlyph() { if (_registerGlyph.__loaded) { @@ -9,8 +9,12 @@ function _registerGlyph() { } _registerGlyph.__loaded = true; registerGlyphGraphic(); - container.load(glyphModule); - container.load(browser ? glyphCanvasPickModule : glyphMathPickModule); + // glyph renderer registered via core; no container usage + if (browser) { + registerCanvasGlyphPicker(); + } else { + registerMathGlyphPicker(); + } } _registerGlyph.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-image.ts b/packages/vrender-kits/src/register/register-image.ts index 67e0387ce..7e3e19dda 100644 --- a/packages/vrender-kits/src/register/register-image.ts +++ b/packages/vrender-kits/src/register/register-image.ts @@ -1,7 +1,7 @@ -import { container, imageModule, registerImageGraphic } from '@visactor/vrender-core'; +import { registerImageGraphic } from '@visactor/vrender-core'; import { browser } from './env'; -import { imageCanvasPickModule } from '../picker/contributions/canvas-picker/image-module'; -import { imageMathPickModule } from '../picker/contributions/math-picker/image-module'; +import { registerCanvasImagePicker } from '../picker/contributions/canvas-picker/image-module'; +import { registerMathImagePicker } from '../picker/contributions/math-picker/image-module'; function _registerImage() { if (_registerImage.__loaded) { @@ -9,8 +9,12 @@ function _registerImage() { } _registerImage.__loaded = true; registerImageGraphic(); - container.load(imageModule); - container.load(browser ? imageCanvasPickModule : imageMathPickModule); + // image renderer registered via core; no /* removed container */ usage + if (browser) { + registerCanvasImagePicker(); + } else { + registerMathImagePicker(); + } } _registerImage.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-line.ts b/packages/vrender-kits/src/register/register-line.ts index 082fbc24f..13d78540c 100644 --- a/packages/vrender-kits/src/register/register-line.ts +++ b/packages/vrender-kits/src/register/register-line.ts @@ -1,7 +1,7 @@ -import { container, lineModule, registerLineGraphic } from '@visactor/vrender-core'; +import { registerLineGraphic } from '@visactor/vrender-core'; import { browser } from './env'; -import { lineCanvasPickModule } from '../picker/contributions/canvas-picker/line-module'; -import { lineMathPickModule } from '../picker/contributions/math-picker/line-module'; +import { registerCanvasLinePicker } from '../picker/contributions/canvas-picker/line-module'; +import { registerMathLinePicker } from '../picker/contributions/math-picker/line-module'; function _registerLine() { if (_registerLine.__loaded) { @@ -9,8 +9,11 @@ function _registerLine() { } _registerLine.__loaded = true; registerLineGraphic(); - container.load(lineModule); - container.load(browser ? lineCanvasPickModule : lineMathPickModule); + if (browser) { + registerCanvasLinePicker(); + } else { + registerMathLinePicker(); + } } _registerLine.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-path.ts b/packages/vrender-kits/src/register/register-path.ts index dcffe64cf..9f8ab44ce 100644 --- a/packages/vrender-kits/src/register/register-path.ts +++ b/packages/vrender-kits/src/register/register-path.ts @@ -1,7 +1,7 @@ -import { container, pathModule, registerPathGraphic } from '@visactor/vrender-core'; +import { registerPathGraphic } from '@visactor/vrender-core'; import { browser } from './env'; -import { pathCanvasPickModule } from '../picker/contributions/canvas-picker/path-module'; -import { pathMathPickModule } from '../picker/contributions/math-picker/path-module'; +import { registerCanvasPathPicker } from '../picker/contributions/canvas-picker/path-module'; +import { registerMathPathPicker } from '../picker/contributions/math-picker/path-module'; function _registerPath() { if (_registerPath.__loaded) { @@ -9,8 +9,12 @@ function _registerPath() { } _registerPath.__loaded = true; registerPathGraphic(); - container.load(pathModule); - container.load(browser ? pathCanvasPickModule : pathMathPickModule); + // path renderer registered via core; no container usage + if (browser) { + registerCanvasPathPicker(); + } else { + registerMathPathPicker(); + } } _registerPath.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-polygon.ts b/packages/vrender-kits/src/register/register-polygon.ts index 2f903f4d5..158ae144d 100644 --- a/packages/vrender-kits/src/register/register-polygon.ts +++ b/packages/vrender-kits/src/register/register-polygon.ts @@ -1,7 +1,7 @@ -import { container, polygonModule, registerPolygonGraphic } from '@visactor/vrender-core'; +import { registerPolygonGraphic } from '@visactor/vrender-core'; import { browser } from './env'; -import { polygonCanvasPickModule } from '../picker/contributions/canvas-picker/polygon-module'; -import { polygonMathPickModule } from '../picker/contributions/math-picker/polygon-module'; +import { registerCanvasPolygonPicker } from '../picker/contributions/canvas-picker/polygon-module'; +import { registerMathPolygonPicker } from '../picker/contributions/math-picker/polygon-module'; function _registerPolygon() { if (_registerPolygon.__loaded) { @@ -9,8 +9,12 @@ function _registerPolygon() { } _registerPolygon.__loaded = true; registerPolygonGraphic(); - container.load(polygonModule); - container.load(browser ? polygonCanvasPickModule : polygonMathPickModule); + // polygon renderer registered via core; no container usage + if (browser) { + registerCanvasPolygonPicker(); + } else { + registerMathPolygonPicker(); + } } _registerPolygon.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-pyramid3d.ts b/packages/vrender-kits/src/register/register-pyramid3d.ts index 43508178e..011f26887 100644 --- a/packages/vrender-kits/src/register/register-pyramid3d.ts +++ b/packages/vrender-kits/src/register/register-pyramid3d.ts @@ -1,12 +1,6 @@ -import { - container, - pyramid3dModule, - registerDirectionalLight, - registerOrthoCamera, - registerPyramid3dGraphic -} from '@visactor/vrender-core'; +import { registerDirectionalLight, registerOrthoCamera, registerPyramid3dGraphic } from '@visactor/vrender-core'; import { browser } from './env'; -import { pyramid3dCanvasPickModule } from '../picker/contributions/canvas-picker/pyramid3d-module'; +import { registerCanvasPyramid3dPicker } from '../picker/contributions/canvas-picker/pyramid3d-module'; function _registerPyramid3d() { if (_registerPyramid3d.__loaded) { @@ -16,8 +10,10 @@ function _registerPyramid3d() { registerPyramid3dGraphic(); registerDirectionalLight(); registerOrthoCamera(); - container.load(pyramid3dModule); - container.load(browser ? pyramid3dCanvasPickModule : pyramid3dCanvasPickModule); + // pyramid3d renderer registered via core; no /* removed container */ usage + if (browser) { + registerCanvasPyramid3dPicker(); + } } _registerPyramid3d.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-rect.ts b/packages/vrender-kits/src/register/register-rect.ts index 4e8316bed..21fbdb7f4 100644 --- a/packages/vrender-kits/src/register/register-rect.ts +++ b/packages/vrender-kits/src/register/register-rect.ts @@ -1,7 +1,7 @@ -import { container, rectModule, registerRectGraphic } from '@visactor/vrender-core'; +import { registerRectGraphic } from '@visactor/vrender-core'; import { browser } from './env'; -import { rectCanvasPickModule } from '../picker/contributions/canvas-picker/rect-module'; -import { rectMathPickModule } from '../picker/contributions/math-picker/rect-module'; +import { registerCanvasRectPicker } from '../picker/contributions/canvas-picker/rect-module'; +import { registerMathRectPicker } from '../picker/contributions/math-picker/rect-module'; function _registerRect() { if (_registerRect.__loaded) { @@ -9,8 +9,12 @@ function _registerRect() { } _registerRect.__loaded = true; registerRectGraphic(); - container.load(rectModule); - container.load(browser ? rectCanvasPickModule : rectMathPickModule); + // rect renderer registered via core; no container usage + if (browser) { + registerCanvasRectPicker(); + } else { + registerMathRectPicker(); + } } _registerRect.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-rect3d.ts b/packages/vrender-kits/src/register/register-rect3d.ts index 892df7ea2..93c5939d8 100644 --- a/packages/vrender-kits/src/register/register-rect3d.ts +++ b/packages/vrender-kits/src/register/register-rect3d.ts @@ -1,6 +1,6 @@ -import { container, rect3dModule, registerRect3dGraphic } from '@visactor/vrender-core'; +import { registerRect3dGraphic } from '@visactor/vrender-core'; import { browser } from './env'; -import { rect3dCanvasPickModule } from '../picker/contributions/canvas-picker/rect3d-module'; +import { registerCanvasRect3dPicker } from '../picker/contributions/canvas-picker/rect3d-module'; function _registerRect3d() { if (_registerRect3d.__loaded) { @@ -8,8 +8,10 @@ function _registerRect3d() { } _registerRect3d.__loaded = true; registerRect3dGraphic(); - container.load(rect3dModule); - container.load(browser ? rect3dCanvasPickModule : rect3dCanvasPickModule); + // rect3d renderer registered via core; no /* removed container */ usage + if (browser) { + registerCanvasRect3dPicker(); + } } _registerRect3d.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-richtext.ts b/packages/vrender-kits/src/register/register-richtext.ts index 8d2bd33c4..d5020fce6 100644 --- a/packages/vrender-kits/src/register/register-richtext.ts +++ b/packages/vrender-kits/src/register/register-richtext.ts @@ -1,7 +1,7 @@ -import { container, registerRichtextGraphic, richtextModule } from '@visactor/vrender-core'; +import { registerRichtextGraphic } from '@visactor/vrender-core'; import { browser } from './env'; -import { richtextCanvasPickModule } from '../picker/contributions/canvas-picker/richtext-module'; -import { richTextMathPickModule } from '../picker/contributions/math-picker/richtext-module'; +import { registerCanvasRichtextPicker } from '../picker/contributions/canvas-picker/richtext-module'; +import { registerMathRichTextPicker } from '../picker/contributions/math-picker/richtext-module'; function _registerRichtext() { if (_registerRichtext.__loaded) { @@ -9,8 +9,12 @@ function _registerRichtext() { } _registerRichtext.__loaded = true; registerRichtextGraphic(); - container.load(richtextModule); - container.load(browser ? richtextCanvasPickModule : richTextMathPickModule); + // richtext renderer registered via core; no container usage + if (browser) { + registerCanvasRichtextPicker(); + } else { + registerMathRichTextPicker(); + } } _registerRichtext.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-star.ts b/packages/vrender-kits/src/register/register-star.ts index 81255d396..19aa03bc5 100644 --- a/packages/vrender-kits/src/register/register-star.ts +++ b/packages/vrender-kits/src/register/register-star.ts @@ -1,6 +1,6 @@ -import { container, starModule, registerStarGraphic } from '@visactor/vrender-core'; +import { registerStarGraphic } from '@visactor/vrender-core'; import { browser } from './env'; -import { starCanvasPickModule } from '../picker/contributions/canvas-picker/star-module'; +import { registerCanvasStarPicker } from '../picker/contributions/canvas-picker/star-module'; function _registerStar() { if (_registerStar.__loaded) { @@ -8,8 +8,8 @@ function _registerStar() { } _registerStar.__loaded = true; registerStarGraphic(); - container.load(starModule); - container.load(browser ? starCanvasPickModule : starCanvasPickModule); + // star renderer registered via core; no container usage + registerCanvasStarPicker(); } _registerStar.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-symbol.ts b/packages/vrender-kits/src/register/register-symbol.ts index 2b31a1deb..0a082aecb 100644 --- a/packages/vrender-kits/src/register/register-symbol.ts +++ b/packages/vrender-kits/src/register/register-symbol.ts @@ -1,7 +1,7 @@ -import { container, registerSymbolGraphic, symbolModule } from '@visactor/vrender-core'; +import { registerSymbolGraphic } from '@visactor/vrender-core'; import { browser } from './env'; -import { symbolCanvasPickModule } from '../picker/contributions/canvas-picker/symbol-module'; -import { symbolMathPickModule } from '../picker/contributions/math-picker/symbol-module'; +import { registerCanvasSymbolPicker } from '../picker/contributions/canvas-picker/symbol-module'; +import { registerMathSymbolPicker } from '../picker/contributions/math-picker/symbol-module'; function _registerSymbol() { if (_registerSymbol.__loaded) { @@ -9,8 +9,12 @@ function _registerSymbol() { } _registerSymbol.__loaded = true; registerSymbolGraphic(); - container.load(symbolModule); - container.load(browser ? symbolCanvasPickModule : symbolMathPickModule); + // symbol renderer registered via core; no container usage + if (browser) { + registerCanvasSymbolPicker(); + } else { + registerMathSymbolPicker(); + } } _registerSymbol.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-text.ts b/packages/vrender-kits/src/register/register-text.ts index 37c836945..c1954cbf7 100644 --- a/packages/vrender-kits/src/register/register-text.ts +++ b/packages/vrender-kits/src/register/register-text.ts @@ -1,15 +1,19 @@ -import { container, registerTextGraphic, textModule } from '@visactor/vrender-core'; +import { registerTextGraphic } from '@visactor/vrender-core'; import { browser } from './env'; -import { textCanvasPickModule } from '../picker/contributions/canvas-picker/text-module'; -import { textMathPickModule } from '../picker/contributions/math-picker/text-module'; +import { registerCanvasTextPicker } from '../picker/contributions/canvas-picker/text-module'; +import { registerMathTextPicker } from '../picker/contributions/math-picker/text-module'; function _registerText() { if (_registerText.__loaded) { return; } _registerText.__loaded = true; registerTextGraphic(); - container.load(textModule); - container.load(browser ? textCanvasPickModule : textMathPickModule); + // text renderer registered via core; no container usage + if (browser) { + registerCanvasTextPicker(); + } else { + registerMathTextPicker(); + } } _registerText.__loaded = false; diff --git a/packages/vrender-kits/src/render/contributions/canvas/gif-image-module.ts b/packages/vrender-kits/src/render/contributions/canvas/gif-image-module.ts index be568f750..2a376d00b 100644 --- a/packages/vrender-kits/src/render/contributions/canvas/gif-image-module.ts +++ b/packages/vrender-kits/src/render/contributions/canvas/gif-image-module.ts @@ -1,13 +1,11 @@ -import { ContainerModule, GraphicRender } from '@visactor/vrender-core'; +import { application, GraphicRender } from '@visactor/vrender-core'; import { DefaultCanvasGifImageRender } from './gif-image-render'; -let loadGifImageModule = false; -export const gifImageModule = new ContainerModule(bind => { - if (loadGifImageModule) { +let _registered = false; +export function registerCanvasGifImageRender() { + if (_registered) { return; } - loadGifImageModule = true; - // gifImage渲染器 - bind(DefaultCanvasGifImageRender).toSelf().inSingletonScope(); - bind(GraphicRender).toService(DefaultCanvasGifImageRender); -}); + _registered = true; + application.contributions.register(GraphicRender, new DefaultCanvasGifImageRender()); +} diff --git a/packages/vrender-kits/src/render/contributions/canvas/gif-image-render.ts b/packages/vrender-kits/src/render/contributions/canvas/gif-image-render.ts index 47b6cda79..e4a4e6c82 100644 --- a/packages/vrender-kits/src/render/contributions/canvas/gif-image-render.ts +++ b/packages/vrender-kits/src/render/contributions/canvas/gif-image-render.ts @@ -1,6 +1,5 @@ import type { IContext2d, - IContributionProvider, IDrawContext, IGraphicAttribute, IGraphicRender, @@ -12,32 +11,21 @@ import type { } from '@visactor/vrender-core'; import { BaseRenderContributionTime, - ContributionProvider, DefaultCanvasImageRender, DefaultRectRenderContribution, - getTheme, - ImageRenderContribution, - inject, - injectable, - named + getTheme } from '@visactor/vrender-core'; import { GIFIMAGE_NUMBER_TYPE } from '../../../graphic/constants'; import type { IGifImage } from '../../../interface/gif-image'; -@injectable() export class DefaultCanvasGifImageRender extends DefaultCanvasImageRender implements IGraphicRender { type: 'image'; numberType: number = GIFIMAGE_NUMBER_TYPE; - constructor( - @inject(ContributionProvider) - @named(ImageRenderContribution) - protected readonly imageRenderContribitions: IContributionProvider - ) { - super(imageRenderContribitions); + constructor() { + super(); this._renderContribitions = undefined; this.builtinContributions = [defaultGifImageRenderContribution]; - this.init(imageRenderContribitions); } drawShape( @@ -58,7 +46,6 @@ export class DefaultCanvasGifImageRender extends DefaultCanvasImageRender implem themeAttribute: IThemeAttribute ) => boolean ) { - // const imageAttribute = graphicService.themeService.getCurrentTheme().imageAttribute; const imageAttribute = getTheme(image).image; const { x: originX = imageAttribute.x, @@ -72,7 +59,6 @@ export class DefaultCanvasGifImageRender extends DefaultCanvasImageRender implem } const { fVisible, sVisible, doFill, doStroke } = data; - // deal with cornerRadius const needRestore = true; const _runFill = () => { diff --git a/packages/vrender-kits/src/render/contributions/canvas/lottie-module.ts b/packages/vrender-kits/src/render/contributions/canvas/lottie-module.ts index 037e0fea4..fa066578e 100644 --- a/packages/vrender-kits/src/render/contributions/canvas/lottie-module.ts +++ b/packages/vrender-kits/src/render/contributions/canvas/lottie-module.ts @@ -1,13 +1,13 @@ -import { ContainerModule, GraphicRender } from '@visactor/vrender-core'; +import { application, GraphicRender } from '@visactor/vrender-core'; import { DefaultCanvasLottieRender } from './lottie-render'; -let loadLottieModule = false; -export const lottieModule = new ContainerModule(bind => { - if (loadLottieModule) { +let _registered = false; +export function registerCanvasLottieRender() { + if (_registered) { return; } - loadLottieModule = true; - // lottie渲染器 - bind(DefaultCanvasLottieRender).toSelf().inSingletonScope(); - bind(GraphicRender).toService(DefaultCanvasLottieRender); -}); + _registered = true; + const render = new DefaultCanvasLottieRender(); + application.services.registerSingleton(GraphicRender, render); + application.contributions.register(GraphicRender, render); +} diff --git a/packages/vrender-kits/src/render/contributions/canvas/lottie-render.ts b/packages/vrender-kits/src/render/contributions/canvas/lottie-render.ts index 5998b0c40..ab402a49d 100644 --- a/packages/vrender-kits/src/render/contributions/canvas/lottie-render.ts +++ b/packages/vrender-kits/src/render/contributions/canvas/lottie-render.ts @@ -7,11 +7,10 @@ import type { IMarkAttribute, IThemeAttribute } from '@visactor/vrender-core'; -import { DefaultCanvasRectRender, getTheme, injectable } from '@visactor/vrender-core'; +import { DefaultCanvasRectRender, getTheme } from '@visactor/vrender-core'; import { LOTTIE_NUMBER_TYPE } from '../../../graphic/constants'; import type { ILottie } from '../../../graphic/interface/lottie'; -@injectable() export class DefaultCanvasLottieRender extends DefaultCanvasRectRender implements IGraphicRender { type: 'glyph'; numberType: number = LOTTIE_NUMBER_TYPE; @@ -49,10 +48,8 @@ export class DefaultCanvasLottieRender extends DefaultCanvasRectRender implement const lottieAttribute = this.tempTheme ?? getTheme(lottie, params?.theme).rect; const { x: originX = lottieAttribute.x, y: originY = lottieAttribute.y } = lottie.attribute; context.setCommonStyle(lottie, lottie.attribute, originX - x, originY - y, lottieAttribute); - // 设置pattern,绘制lottie const canvas = lottie.canvas; if (canvas) { - // const _ctx = canvas.getContext('2d'); const pattern = context.createPattern(canvas, 'no-repeat'); const dpr = context.dpr; pattern.setTransform && pattern.setTransform(new DOMMatrix([1 / dpr, 0, 0, 1 / dpr, x, y])); diff --git a/packages/vrender-kits/src/render/contributions/rough/module.ts b/packages/vrender-kits/src/render/contributions/rough/module.ts index 10fd7c74b..026d19781 100644 --- a/packages/vrender-kits/src/render/contributions/rough/module.ts +++ b/packages/vrender-kits/src/render/contributions/rough/module.ts @@ -1,4 +1,4 @@ -import { ContainerModule, GraphicRender } from '@visactor/vrender-core'; +import { application, GraphicRender } from '@visactor/vrender-core'; import { RoughCanvasArcRender } from './rough-arc'; import { RoughCanvasAreaRender } from './rough-area'; import { RoughCanvasCircleRender } from './rough-circle'; @@ -7,32 +7,22 @@ import { RoughCanvasPathRender } from './rough-path'; import { RoughCanvasRectRender } from './rough-rect'; import { RoughCanvasSymbolRender } from './rough-symbol'; -export default new ContainerModule(bind => { - // circle - bind(RoughCanvasCircleRender).toSelf().inSingletonScope(); - bind(GraphicRender).to(RoughCanvasCircleRender); - - // rect - bind(RoughCanvasRectRender).toSelf().inSingletonScope(); - bind(GraphicRender).to(RoughCanvasRectRender); - - // path - bind(RoughCanvasPathRender).toSelf().inSingletonScope(); - bind(GraphicRender).to(RoughCanvasPathRender); - - // symbol - bind(RoughCanvasSymbolRender).toSelf().inSingletonScope(); - bind(GraphicRender).to(RoughCanvasSymbolRender); - - // line - bind(RoughCanvasLineRender).toSelf().inSingletonScope(); - bind(GraphicRender).to(RoughCanvasLineRender); - - // area - bind(RoughCanvasAreaRender).toSelf().inSingletonScope(); - bind(GraphicRender).to(RoughCanvasAreaRender); - - // area - bind(RoughCanvasArcRender).toSelf().inSingletonScope(); - bind(GraphicRender).to(RoughCanvasArcRender); -}); +let _registered = false; +export function registerRoughCanvasRenders() { + if (_registered) { + return; + } + _registered = true; + const renders = [ + new RoughCanvasCircleRender(), + new RoughCanvasRectRender(), + new RoughCanvasPathRender(), + new RoughCanvasSymbolRender(), + new RoughCanvasLineRender(), + new RoughCanvasAreaRender(), + new RoughCanvasArcRender() + ]; + for (const render of renders) { + application.contributions.register(GraphicRender, render); + } +} diff --git a/packages/vrender-kits/src/render/contributions/rough/rough-arc.ts b/packages/vrender-kits/src/render/contributions/rough/rough-arc.ts index 9080f9801..6238c2857 100644 --- a/packages/vrender-kits/src/render/contributions/rough/rough-arc.ts +++ b/packages/vrender-kits/src/render/contributions/rough/rough-arc.ts @@ -16,24 +16,24 @@ import { getTheme, CustomPath2D, drawArcPath, - inject, - injectable + application } from '@visactor/vrender-core'; import rough from 'roughjs'; import { defaultRouthThemeSpec } from './config'; import { RoughBaseRender } from './base-render'; -@injectable() export class RoughCanvasArcRender extends RoughBaseRender implements IGraphicRender { type: 'arc'; numberType: number; style: 'rough' = 'rough'; - constructor( - @inject(DefaultCanvasArcRender) - public readonly canvasRenderer: IGraphicRender - ) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(DefaultCanvasArcRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(DefaultCanvasArcRender)[0]; + } this.type = 'arc'; this.numberType = ARC_NUMBER_TYPE; } diff --git a/packages/vrender-kits/src/render/contributions/rough/rough-area.ts b/packages/vrender-kits/src/render/contributions/rough/rough-area.ts index 63754d2e7..3e6710feb 100644 --- a/packages/vrender-kits/src/render/contributions/rough/rough-area.ts +++ b/packages/vrender-kits/src/render/contributions/rough/rough-area.ts @@ -9,11 +9,10 @@ import type { IAreaGraphicAttribute, IDrawContext } from '@visactor/vrender-core'; -import { drawAreaSegments, DefaultCanvasAreaRender, CustomPath2D, injectable } from '@visactor/vrender-core'; +import { drawAreaSegments, DefaultCanvasAreaRender, CustomPath2D } from '@visactor/vrender-core'; import rough from 'roughjs'; import { defaultRouthThemeSpec } from './config'; -@injectable() export class RoughCanvasAreaRender extends DefaultCanvasAreaRender implements IGraphicRender { declare type: 'area'; declare numberType: number; diff --git a/packages/vrender-kits/src/render/contributions/rough/rough-circle.ts b/packages/vrender-kits/src/render/contributions/rough/rough-circle.ts index db0701c81..ebbba72b0 100644 --- a/packages/vrender-kits/src/render/contributions/rough/rough-circle.ts +++ b/packages/vrender-kits/src/render/contributions/rough/rough-circle.ts @@ -5,21 +5,22 @@ import type { IDrawContext, IGraphicRenderDrawParams } from '@visactor/vrender-core'; -import { CIRCLE_NUMBER_TYPE, DefaultCanvasCircleRender, getTheme, inject, injectable } from '@visactor/vrender-core'; +import { CIRCLE_NUMBER_TYPE, DefaultCanvasCircleRender, getTheme, application } from '@visactor/vrender-core'; import rough from 'roughjs'; import { RoughBaseRender } from './base-render'; -@injectable() export class RoughCanvasCircleRender extends RoughBaseRender implements IGraphicRender { declare type: 'circle'; declare numberType: number; style: 'rough' = 'rough'; - constructor( - @inject(DefaultCanvasCircleRender) - public readonly canvasRenderer: IGraphicRender - ) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(DefaultCanvasCircleRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(DefaultCanvasCircleRender)[0]; + } this.type = 'circle'; this.numberType = CIRCLE_NUMBER_TYPE; } diff --git a/packages/vrender-kits/src/render/contributions/rough/rough-line.ts b/packages/vrender-kits/src/render/contributions/rough/rough-line.ts index 02fe6ea48..9aa3d3706 100644 --- a/packages/vrender-kits/src/render/contributions/rough/rough-line.ts +++ b/packages/vrender-kits/src/render/contributions/rough/rough-line.ts @@ -12,22 +12,23 @@ import type { IGraphicRenderDrawParams, IRenderService } from '@visactor/vrender-core'; -import { DefaultCanvasLineRender, injectable, inject, LINE_NUMBER_TYPE } from '@visactor/vrender-core'; +import { DefaultCanvasLineRender, LINE_NUMBER_TYPE, application } from '@visactor/vrender-core'; import { RoughBaseRender } from './base-render'; -@injectable() export class RoughCanvasLineRender extends RoughBaseRender implements IGraphicRender { declare type: 'line'; declare numberType: number; style: 'rough' = 'rough'; - constructor( - @inject(DefaultCanvasLineRender) - public readonly canvasRenderer: IGraphicRender - ) { + constructor() { super(); this.type = 'line'; this.numberType = LINE_NUMBER_TYPE; + try { + this.canvasRenderer = application.services.get(DefaultCanvasLineRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(DefaultCanvasLineRender)[0]; + } } draw(line: ILine, renderService: IRenderService, drawContext: IDrawContext, params?: IGraphicRenderDrawParams) { diff --git a/packages/vrender-kits/src/render/contributions/rough/rough-path.ts b/packages/vrender-kits/src/render/contributions/rough/rough-path.ts index 54b25807c..8c3649a3c 100644 --- a/packages/vrender-kits/src/render/contributions/rough/rough-path.ts +++ b/packages/vrender-kits/src/render/contributions/rough/rough-path.ts @@ -5,22 +5,23 @@ import type { IDrawContext, IGraphicRenderDrawParams } from '@visactor/vrender-core'; -import { PATH_NUMBER_TYPE, DefaultCanvasPathRender, getTheme, inject, injectable } from '@visactor/vrender-core'; +import { PATH_NUMBER_TYPE, DefaultCanvasPathRender, getTheme, application } from '@visactor/vrender-core'; import rough from 'roughjs'; import { defaultRouthThemeSpec } from './config'; import { RoughBaseRender } from './base-render'; -@injectable() export class RoughCanvasPathRender extends RoughBaseRender implements IGraphicRender { type: 'path'; numberType: number; style: 'rough' = 'rough'; - constructor( - @inject(DefaultCanvasPathRender) - public readonly canvasRenderer: IGraphicRender - ) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(DefaultCanvasPathRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(DefaultCanvasPathRender)[0]; + } this.type = 'path'; this.numberType = PATH_NUMBER_TYPE; } diff --git a/packages/vrender-kits/src/render/contributions/rough/rough-rect.ts b/packages/vrender-kits/src/render/contributions/rough/rough-rect.ts index a6c76cf1a..70dcf90b6 100644 --- a/packages/vrender-kits/src/render/contributions/rough/rough-rect.ts +++ b/packages/vrender-kits/src/render/contributions/rough/rough-rect.ts @@ -6,8 +6,7 @@ import { type IGraphicRenderDrawParams, RECT_NUMBER_TYPE, DefaultCanvasRectRender, - inject, - injectable, + application, CustomPath2D } from '@visactor/vrender-core'; @@ -16,17 +15,18 @@ import { defaultRouthThemeSpec } from './config'; import { RoughBaseRender } from './base-render'; import { RoughContext2d } from './context'; -@injectable() export class RoughCanvasRectRender extends RoughBaseRender implements IGraphicRender { type: 'rect'; numberType: number; style: 'rough' = 'rough'; - constructor( - @inject(DefaultCanvasRectRender) - public readonly canvasRenderer: IGraphicRender - ) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(DefaultCanvasRectRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(DefaultCanvasRectRender)[0]; + } this.type = 'rect'; this.numberType = RECT_NUMBER_TYPE; } diff --git a/packages/vrender-kits/src/render/contributions/rough/rough-symbol.ts b/packages/vrender-kits/src/render/contributions/rough/rough-symbol.ts index f338efe17..22d5adc85 100644 --- a/packages/vrender-kits/src/render/contributions/rough/rough-symbol.ts +++ b/packages/vrender-kits/src/render/contributions/rough/rough-symbol.ts @@ -16,25 +16,25 @@ import { BaseRender, getTheme, CustomPath2D, - inject, - injectable + application } from '@visactor/vrender-core'; import rough from 'roughjs'; import { defaultRouthThemeSpec } from './config'; import { RoughContext2d } from './context'; import { RoughBaseRender } from './base-render'; -@injectable() export class RoughCanvasSymbolRender extends RoughBaseRender implements IGraphicRender { type: 'symbol'; numberType: number; style: 'rough'; - constructor( - @inject(DefaultCanvasSymbolRender) - public readonly canvasRenderer: IGraphicRender - ) { + constructor() { super(); + try { + this.canvasRenderer = application.services.get(DefaultCanvasSymbolRender) as IGraphicRender; + } catch (_) { + this.canvasRenderer = application.contributions.get(DefaultCanvasSymbolRender)[0]; + } this.type = 'symbol'; this.numberType = SYMBOL_NUMBER_TYPE; this.style = 'rough'; diff --git a/packages/vrender-kits/src/window/contributions/browser-contribution.ts b/packages/vrender-kits/src/window/contributions/browser-contribution.ts index 4a8664840..de8143bc6 100644 --- a/packages/vrender-kits/src/window/contributions/browser-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/browser-contribution.ts @@ -1,12 +1,4 @@ -import { - inject, - injectable, - Generator, - BaseWindowHandlerContribution, - ContainerModule, - WindowHandlerContribution, - application -} from '@visactor/vrender-core'; +import { Generator, BaseWindowHandlerContribution, application } from '@visactor/vrender-core'; import type { IContext2d, ICanvas, @@ -20,7 +12,6 @@ import type { IBoundsLike, IMatrix, IBounds } from '@visactor/vutils'; import { Matrix, AABBBounds } from '@visactor/vutils'; import { BrowserCanvas } from '../../canvas/contributions/browser'; -@injectable() export class BrowserWindowHandlerContribution extends BaseWindowHandlerContribution implements IWindowHandlerContribution @@ -328,10 +319,4 @@ export class BrowserWindowHandlerContribution } } -export const browserWindowModule = new ContainerModule(bind => { - // browser - bind(BrowserWindowHandlerContribution).toSelf(); - bind(WindowHandlerContribution) - .toDynamicValue(ctx => ctx.container.get(BrowserWindowHandlerContribution)) - .whenTargetNamed(BrowserWindowHandlerContribution.env); -}); +// Legacy ContainerModule removed (registry-only) diff --git a/packages/vrender-kits/src/window/contributions/feishu-contribution.ts b/packages/vrender-kits/src/window/contributions/feishu-contribution.ts index beaa50ce0..8ad143d33 100644 --- a/packages/vrender-kits/src/window/contributions/feishu-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/feishu-contribution.ts @@ -1,12 +1,4 @@ -import { - inject, - injectable, - Generator, - BaseWindowHandlerContribution, - VGlobal, - ContainerModule, - WindowHandlerContribution -} from '@visactor/vrender-core'; +import { Generator, BaseWindowHandlerContribution, application } from '@visactor/vrender-core'; import type { EnvType, IGlobal, @@ -47,7 +39,6 @@ class MiniAppEventManager { cache: Record = {}; } -@injectable() export class FeishuWindowHandlerContribution extends BaseWindowHandlerContribution implements IWindowHandlerContribution @@ -62,8 +53,11 @@ export class FeishuWindowHandlerContribution return null; } - constructor(@inject(VGlobal) private readonly global: IGlobal) { + private readonly global: IGlobal; + + constructor() { super(); + this.global = application.global; } getTitle(): string { @@ -241,10 +235,4 @@ export class FeishuWindowHandlerContribution } } -export const feishuWindowModule = new ContainerModule(bind => { - // feishu - bind(FeishuWindowHandlerContribution).toSelf(); - bind(WindowHandlerContribution) - .toDynamicValue(ctx => ctx.container.get(FeishuWindowHandlerContribution)) - .whenTargetNamed(FeishuWindowHandlerContribution.env); -}); +// Legacy ContainerModule removed (registry-only) diff --git a/packages/vrender-kits/src/window/contributions/harmony-contribution.ts b/packages/vrender-kits/src/window/contributions/harmony-contribution.ts index 56ff30f01..1771cf1a1 100644 --- a/packages/vrender-kits/src/window/contributions/harmony-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/harmony-contribution.ts @@ -1,12 +1,4 @@ -import { - inject, - injectable, - Generator, - BaseWindowHandlerContribution, - VGlobal, - ContainerModule, - WindowHandlerContribution -} from '@visactor/vrender-core'; +import { Generator, BaseWindowHandlerContribution, application } from '@visactor/vrender-core'; import type { EnvType, IGlobal, @@ -46,7 +38,6 @@ class MiniAppEventManager { cache: Record = {}; } -@injectable() export class HarmonyWindowHandlerContribution extends BaseWindowHandlerContribution implements IWindowHandlerContribution @@ -61,8 +52,11 @@ export class HarmonyWindowHandlerContribution return null; } - constructor(@inject(VGlobal) private readonly global: IGlobal) { + private readonly global: IGlobal; + + constructor() { super(); + this.global = application.global; } getTitle(): string { @@ -235,10 +229,4 @@ export class HarmonyWindowHandlerContribution } } -export const harmonyWindowModule = new ContainerModule(bind => { - // harmony - bind(HarmonyWindowHandlerContribution).toSelf(); - bind(WindowHandlerContribution) - .toDynamicValue(ctx => ctx.container.get(HarmonyWindowHandlerContribution)) - .whenTargetNamed(HarmonyWindowHandlerContribution.env); -}); +// Legacy ContainerModule removed (registry-only) diff --git a/packages/vrender-kits/src/window/contributions/lynx-contribution.ts b/packages/vrender-kits/src/window/contributions/lynx-contribution.ts index ca78202c2..6d5da51fb 100644 --- a/packages/vrender-kits/src/window/contributions/lynx-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/lynx-contribution.ts @@ -1,12 +1,4 @@ -import { - inject, - injectable, - Generator, - BaseWindowHandlerContribution, - VGlobal, - ContainerModule, - WindowHandlerContribution -} from '@visactor/vrender-core'; +import { Generator, BaseWindowHandlerContribution, application } from '@visactor/vrender-core'; import type { EnvType, IGlobal, @@ -47,7 +39,6 @@ class MiniAppEventManager { cache: Record = {}; } -@injectable() export class LynxWindowHandlerContribution extends BaseWindowHandlerContribution implements IWindowHandlerContribution { static env: EnvType = 'lynx'; type: EnvType = 'lynx'; @@ -59,8 +50,11 @@ export class LynxWindowHandlerContribution extends BaseWindowHandlerContribution return null; } - constructor(@inject(VGlobal) private readonly global: IGlobal) { + private readonly global: IGlobal; + + constructor() { super(); + this.global = application.global; } getTitle(): string { @@ -238,10 +232,4 @@ export class LynxWindowHandlerContribution extends BaseWindowHandlerContribution } } -export const lynxWindowModule = new ContainerModule(bind => { - // lynx - bind(LynxWindowHandlerContribution).toSelf(); - bind(WindowHandlerContribution) - .toDynamicValue(ctx => ctx.container.get(LynxWindowHandlerContribution)) - .whenTargetNamed(LynxWindowHandlerContribution.env); -}); +// Legacy ContainerModule removed (registry-only) diff --git a/packages/vrender-kits/src/window/contributions/node-contribution.ts b/packages/vrender-kits/src/window/contributions/node-contribution.ts index 77c79c27c..acad696ac 100644 --- a/packages/vrender-kits/src/window/contributions/node-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/node-contribution.ts @@ -1,12 +1,4 @@ -import { - inject, - injectable, - Generator, - BaseWindowHandlerContribution, - VGlobal, - ContainerModule, - WindowHandlerContribution -} from '@visactor/vrender-core'; +import { Generator, BaseWindowHandlerContribution, application } from '@visactor/vrender-core'; import type { IBoundsLike } from '@visactor/vutils'; import type { EnvType, @@ -19,7 +11,6 @@ import type { } from '@visactor/vrender-core'; import { NodeCanvas } from '../../canvas/contributions/node'; -@injectable() export class NodeWindowHandlerContribution extends BaseWindowHandlerContribution implements IWindowHandlerContribution { static env: EnvType = 'node'; type: EnvType = 'node'; @@ -29,8 +20,11 @@ export class NodeWindowHandlerContribution extends BaseWindowHandlerContribution return null; } - constructor(@inject(VGlobal) private readonly global: IGlobal) { + private readonly global: IGlobal; + + constructor() { super(); + this.global = application.global; } getTitle(): string { @@ -164,10 +158,4 @@ export class NodeWindowHandlerContribution extends BaseWindowHandlerContribution } } -export const nodeWindowModule = new ContainerModule(bind => { - // node - bind(NodeWindowHandlerContribution).toSelf(); - bind(WindowHandlerContribution) - .toDynamicValue(ctx => ctx.container.get(NodeWindowHandlerContribution)) - .whenTargetNamed(NodeWindowHandlerContribution.env); -}); +// Legacy ContainerModule removed (registry-only) diff --git a/packages/vrender-kits/src/window/contributions/taro-contribution.ts b/packages/vrender-kits/src/window/contributions/taro-contribution.ts index cea900f37..29c60ff97 100644 --- a/packages/vrender-kits/src/window/contributions/taro-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/taro-contribution.ts @@ -1,12 +1,4 @@ -import { - inject, - injectable, - Generator, - BaseWindowHandlerContribution, - VGlobal, - ContainerModule, - WindowHandlerContribution -} from '@visactor/vrender-core'; +import { Generator, BaseWindowHandlerContribution, application } from '@visactor/vrender-core'; import type { EnvType, IGlobal, @@ -47,7 +39,6 @@ class MiniAppEventManager { cache: Record = {}; } -@injectable() export class TaroWindowHandlerContribution extends BaseWindowHandlerContribution implements IWindowHandlerContribution { static env: EnvType = 'taro'; type: EnvType = 'taro'; @@ -59,8 +50,11 @@ export class TaroWindowHandlerContribution extends BaseWindowHandlerContribution return null; } - constructor(@inject(VGlobal) private readonly global: IGlobal) { + private readonly global: IGlobal; + + constructor() { super(); + this.global = application.global; } getTitle(): string { @@ -255,10 +249,4 @@ export class TaroWindowHandlerContribution extends BaseWindowHandlerContribution } } -export const taroWindowModule = new ContainerModule(bind => { - // taro - bind(TaroWindowHandlerContribution).toSelf(); - bind(WindowHandlerContribution) - .toDynamicValue(ctx => ctx.container.get(TaroWindowHandlerContribution)) - .whenTargetNamed(TaroWindowHandlerContribution.env); -}); +// Legacy ContainerModule removed (registry-only) diff --git a/packages/vrender-kits/src/window/contributions/tt-contribution.ts b/packages/vrender-kits/src/window/contributions/tt-contribution.ts index ae836f4bc..6b54b40a3 100644 --- a/packages/vrender-kits/src/window/contributions/tt-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/tt-contribution.ts @@ -1,12 +1,4 @@ -import { - inject, - injectable, - Generator, - BaseWindowHandlerContribution, - VGlobal, - ContainerModule, - WindowHandlerContribution -} from '@visactor/vrender-core'; +import { Generator, BaseWindowHandlerContribution, application } from '@visactor/vrender-core'; import type { EnvType, IGlobal, @@ -47,7 +39,6 @@ class MiniAppEventManager { cache: Record = {}; } -@injectable() export class TTWindowHandlerContribution extends BaseWindowHandlerContribution implements IWindowHandlerContribution { static env: EnvType = 'tt'; type: EnvType = 'tt'; @@ -59,8 +50,11 @@ export class TTWindowHandlerContribution extends BaseWindowHandlerContribution i return null; } - constructor(@inject(VGlobal) private readonly global: IGlobal) { + private readonly global: IGlobal; + + constructor() { super(); + this.global = application.global; } getTitle(): string { @@ -238,10 +232,4 @@ export class TTWindowHandlerContribution extends BaseWindowHandlerContribution i } } -export const ttWindowModule = new ContainerModule(bind => { - // tt - bind(TTWindowHandlerContribution).toSelf(); - bind(WindowHandlerContribution) - .toDynamicValue(ctx => ctx.container.get(TTWindowHandlerContribution)) - .whenTargetNamed(TTWindowHandlerContribution.env); -}); +// Legacy ContainerModule removed (registry-only) diff --git a/packages/vrender-kits/src/window/contributions/wx-contribution.ts b/packages/vrender-kits/src/window/contributions/wx-contribution.ts index 2b573c0cd..2b2fc34ec 100644 --- a/packages/vrender-kits/src/window/contributions/wx-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/wx-contribution.ts @@ -1,12 +1,4 @@ -import { - inject, - injectable, - Generator, - BaseWindowHandlerContribution, - VGlobal, - ContainerModule, - WindowHandlerContribution -} from '@visactor/vrender-core'; +import { Generator, BaseWindowHandlerContribution, application } from '@visactor/vrender-core'; import type { EnvType, IGlobal, @@ -47,7 +39,6 @@ class MiniAppEventManager { cache: Record = {}; } -@injectable() export class WxWindowHandlerContribution extends BaseWindowHandlerContribution implements IWindowHandlerContribution { static env: EnvType = 'wx'; type: EnvType = 'wx'; @@ -59,8 +50,11 @@ export class WxWindowHandlerContribution extends BaseWindowHandlerContribution i return null; } - constructor(@inject(VGlobal) private readonly global: IGlobal) { + private readonly global: IGlobal; + + constructor() { super(); + this.global = application.global; } getTitle(): string { @@ -238,10 +232,4 @@ export class WxWindowHandlerContribution extends BaseWindowHandlerContribution i } } -export const wxWindowModule = new ContainerModule(bind => { - // wx - bind(WxWindowHandlerContribution).toSelf(); - bind(WindowHandlerContribution) - .toDynamicValue(ctx => ctx.container.get(WxWindowHandlerContribution)) - .whenTargetNamed(WxWindowHandlerContribution.env); -}); +// Legacy ContainerModule removed (registry-only) diff --git a/packages/vrender/src/index.ts b/packages/vrender/src/index.ts index 36973c6ff..a52b7a5ca 100644 --- a/packages/vrender/src/index.ts +++ b/packages/vrender/src/index.ts @@ -11,7 +11,9 @@ import { registerDirectionalLight, registerOrthoCamera } from '@visactor/vrender-core'; -import { loadBrowserEnv, loadNodeEnv, registerStar } from '@visactor/vrender-kits'; +import { registerStar } from '@visactor/vrender-kits'; +import { registerBrowserEnvRegistry } from '@visactor/vrender-kits/esm/env/browser'; +import { registerNodeEnvRegistry } from '@visactor/vrender-kits/esm/env/node'; import { registerArc, registerArc3d, @@ -38,11 +40,13 @@ export const version = __VERSION__; preLoadAllModule(); +// Registry-based registration only (drop legacy ContainerModule loaders) if (isBrowserEnv()) { - loadBrowserEnv(container); + registerBrowserEnvRegistry(); } else if (isNodeEnv()) { - loadNodeEnv(container); + registerNodeEnvRegistry(); } + registerArc(); registerArc3d(); registerArea(); diff --git a/rush.json b/rush.json index 82285353f..d38aa9836 100644 --- a/rush.json +++ b/rush.json @@ -2,7 +2,7 @@ "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush.schema.json", "rushVersion": "5.148.0", "pnpmVersion": "10.7.0", - "nodeSupportedVersionRange": ">=14.15.0 <15.0.0 || >=16.13.0 <17.0.0 || >=18.15.0 <19.0.0 || >=20.0.0 <21.0.0", + "nodeSupportedVersionRange": ">=14.15.0 <15.0.0 || >=16.13.0 <17.0.0 || >=18.15.0 <19.0.0 || >=20.0.0 <25.0.0", "suppressNodeLtsWarning": true, "ensureConsistentVersions": true, "projectFolderMinDepth": 1, From 96b7a29c0a39c3b2185fd38bfe74af742a7087a5 Mon Sep 17 00:00:00 2001 From: xile611 Date: Mon, 12 Jan 2026 19:59:09 +0800 Subject: [PATCH 2/6] refactor: fix refactor error and remove application --- packages/vrender-animate/src/animate.ts | 12 +- .../src/custom/clip-graphic.ts | 8 +- .../disappear/base/DisappearAnimateBase.ts | 2 +- .../disappear/base/ImageProcessUtils.ts | 2 +- .../src/custom/disappear/gaussian-blur.ts | 2 +- .../src/custom/disappear/pixelation.ts | 2 +- .../vrender-animate/src/custom/morphing.ts | 42 ++-- .../vrender-animate/src/custom/streamLight.ts | 6 +- packages/vrender-animate/src/register.ts | 4 +- .../src/ticker/default-ticker.ts | 6 +- .../src/poptip/contribution.ts | 2 - .../vrender-components/src/poptip/module.ts | 31 +-- .../src/poptip/poptip-plugin.ts | 10 +- .../vrender-components/src/poptip/register.ts | 3 +- .../src/scrollbar/module.ts | 16 +- .../src/scrollbar/scrollbar-plugin.ts | 3 +- .../vrender-components/src/slider/slider.ts | 2 +- .../src/table-series-number/event-manager.ts | 2 +- .../src/allocator/canvas-allocate.ts | 19 +- .../src/allocator/graphic-allocate.ts | 34 +-- packages/vrender-core/src/application.ts | 55 ++++- .../src/canvas/conical-gradient.ts | 4 +- .../src/canvas/contributions/base-canvas.ts | 4 +- packages/vrender-core/src/canvas/util.ts | 13 +- .../src/common/contribution-registry.ts | 90 -------- .../src/common/performance-raf.ts | 4 +- .../src/common/service-factory.ts | 162 -------------- .../src/common/service-registry.ts | 94 -------- packages/vrender-core/src/common/types.ts | 9 - .../layerHandler/canvas2d-contribution.ts | 4 +- .../layerHandler/empty-contribution.ts | 4 +- .../layerHandler/offscreen2d-contribution.ts | 4 +- .../vrender-core/src/core/graphic-utils.ts | 4 +- .../vrender-core/src/core/layer-service.ts | 10 +- packages/vrender-core/src/core/layer.ts | 6 +- packages/vrender-core/src/core/stage.ts | 6 +- packages/vrender-core/src/core/window.ts | 7 +- packages/vrender-core/src/env-check.ts | 6 +- packages/vrender-core/src/graphic/arc.ts | 6 +- packages/vrender-core/src/graphic/arc3d.ts | 6 +- packages/vrender-core/src/graphic/area.ts | 6 +- packages/vrender-core/src/graphic/circle.ts | 6 +- packages/vrender-core/src/graphic/glyph.ts | 2 +- .../graphic-service/graphic-service.ts | 2 +- packages/vrender-core/src/graphic/graphic.ts | 24 ++- packages/vrender-core/src/graphic/group.ts | 8 +- packages/vrender-core/src/graphic/image.ts | 6 +- packages/vrender-core/src/graphic/line.ts | 6 +- packages/vrender-core/src/graphic/path.ts | 6 +- packages/vrender-core/src/graphic/polygon.ts | 6 +- .../vrender-core/src/graphic/pyramid3d.ts | 6 +- packages/vrender-core/src/graphic/rect.ts | 6 +- packages/vrender-core/src/graphic/richtext.ts | 8 +- .../src/graphic/richtext/utils.ts | 6 +- packages/vrender-core/src/graphic/star.ts | 6 +- packages/vrender-core/src/graphic/symbol.ts | 6 +- packages/vrender-core/src/graphic/text.ts | 14 +- packages/vrender-core/src/graphic/tools.ts | 4 +- .../vrender-core/src/graphic/wrap-text.ts | 4 +- packages/vrender-core/src/index.ts | 6 +- packages/vrender-core/src/interface/canvas.ts | 2 +- packages/vrender-core/src/modules.ts | 12 +- .../src/picker/global-picker-service.ts | 4 +- .../vrender-core/src/picker/picker-service.ts | 4 +- .../builtin-plugin/auto-refresh-plugin.ts | 12 +- .../builtin-plugin/auto-render-plugin.ts | 2 +- .../builtin-plugin/dirty-bounds-plugin.ts | 2 +- .../src/plugins/builtin-plugin/edit-module.ts | 6 +- .../builtin-plugin/flex-layout-plugin.ts | 2 +- .../builtin-plugin/html-attribute-plugin.ts | 22 +- .../incremental-auto-render-plugin.ts | 4 +- .../builtin-plugin/react-attribute-plugin.ts | 6 +- .../builtin-plugin/richtext-edit-plugin.ts | 24 +-- packages/vrender-core/src/register-modules.ts | 119 ++++++---- .../contributions/render/draw-contribution.ts | 6 +- .../contributions/render/group-render.ts | 4 +- .../src/resource-loader/loader.ts | 18 +- .../canvas/contributions/browser/canvas.ts | 7 +- .../canvas/contributions/browser/context.ts | 13 +- .../contributions/create-canvas-module.ts | 16 +- .../canvas/contributions/harmony/context.ts | 9 +- .../src/canvas/contributions/lynx/context.ts | 9 +- packages/vrender-kits/src/env/all.ts | 4 +- packages/vrender-kits/src/env/browser.ts | 8 +- .../env/contributions/browser-contribution.ts | 4 +- packages/vrender-kits/src/env/feishu.ts | 6 +- packages/vrender-kits/src/env/harmony.ts | 6 +- packages/vrender-kits/src/env/lynx.ts | 6 +- packages/vrender-kits/src/env/node.ts | 6 +- packages/vrender-kits/src/env/taro.ts | 6 +- packages/vrender-kits/src/env/tt.ts | 6 +- packages/vrender-kits/src/env/wx.ts | 6 +- .../src/event/extension/gesture.ts | 6 +- packages/vrender-kits/src/graphic/Lottie.ts | 6 +- .../vrender-kits/src/graphic/gif-image.ts | 6 +- .../vrender-kits/src/picker/canvas-module.ts | 4 +- .../src/picker/canvas-picker-service.ts | 6 +- .../contributions/canvas-picker/arc-module.ts | 4 +- .../contributions/canvas-picker/arc-picker.ts | 4 +- .../canvas-picker/arc3d-module.ts | 4 +- .../canvas-picker/arc3d-picker.ts | 6 +- .../canvas-picker/area-module.ts | 4 +- .../canvas-picker/area-picker.ts | 6 +- .../canvas-picker/circle-module.ts | 4 +- .../canvas-picker/circle-picker.ts | 6 +- .../canvas-picker/gif-image-module.ts | 4 +- .../canvas-picker/glyph-module.ts | 4 +- .../canvas-picker/glyph-picker.ts | 6 +- .../canvas-picker/image-module.ts | 6 +- .../canvas-picker/image-picker.ts | 6 +- .../canvas-picker/line-module.ts | 4 +- .../canvas-picker/line-picker.ts | 4 +- .../canvas-picker/lottie-module.ts | 4 +- .../canvas-picker/lottie-picker.ts | 6 +- .../contributions/canvas-picker/module.ts | 4 +- .../canvas-picker/path-module.ts | 4 +- .../canvas-picker/path-picker.ts | 4 +- .../canvas-picker/polygon-module.ts | 4 +- .../canvas-picker/polygon-picker.ts | 6 +- .../canvas-picker/pyramid3d-module.ts | 4 +- .../canvas-picker/pyramid3d-picker.ts | 6 +- .../canvas-picker/rect-module.ts | 4 +- .../canvas-picker/rect-picker.ts | 4 +- .../canvas-picker/rect3d-module.ts | 4 +- .../canvas-picker/rect3d-picker.ts | 6 +- .../canvas-picker/richtext-module.ts | 4 +- .../canvas-picker/richtext-picker.ts | 6 +- .../canvas-picker/star-module.ts | 4 +- .../canvas-picker/star-picker.ts | 6 +- .../canvas-picker/symbol-module.ts | 4 +- .../canvas-picker/symbol-picker.ts | 13 +- .../canvas-picker/text-module.ts | 4 +- .../canvas-picker/text-picker.ts | 4 +- .../contributions/math-picker/arc-module.ts | 4 +- .../contributions/math-picker/arc-picker.ts | 6 +- .../contributions/math-picker/area-module.ts | 4 +- .../contributions/math-picker/area-picker.ts | 6 +- .../math-picker/circle-module.ts | 4 +- .../math-picker/circle-picker.ts | 6 +- .../contributions/math-picker/glyph-module.ts | 4 +- .../contributions/math-picker/glyph-picker.ts | 6 +- .../contributions/math-picker/image-module.ts | 4 +- .../contributions/math-picker/line-module.ts | 4 +- .../contributions/math-picker/line-picker.ts | 6 +- .../contributions/math-picker/path-module.ts | 4 +- .../contributions/math-picker/path-picker.ts | 6 +- .../math-picker/polygon-module.ts | 4 +- .../math-picker/polygon-picker.ts | 6 +- .../contributions/math-picker/rect-module.ts | 4 +- .../contributions/math-picker/rect-picker.ts | 6 +- .../math-picker/richtext-module.ts | 4 +- .../math-picker/richtext-picker.ts | 6 +- .../math-picker/symbol-module.ts | 4 +- .../math-picker/symbol-picker.ts | 6 +- .../contributions/math-picker/text-module.ts | 4 +- .../vrender-kits/src/picker/math-module.ts | 4 +- .../src/picker/math-picker-service.ts | 6 +- .../contributions/canvas/gif-image-module.ts | 4 +- .../contributions/canvas/lottie-module.ts | 6 +- .../src/render/contributions/rough/module.ts | 4 +- .../render/contributions/rough/rough-arc.ts | 7 +- .../contributions/rough/rough-circle.ts | 12 +- .../render/contributions/rough/rough-line.ts | 11 +- .../render/contributions/rough/rough-path.ts | 12 +- .../render/contributions/rough/rough-rect.ts | 7 +- .../contributions/rough/rough-symbol.ts | 7 +- .../contributions/browser-contribution.ts | 4 +- .../contributions/feishu-contribution.ts | 4 +- .../contributions/harmony-contribution.ts | 4 +- .../window/contributions/lynx-contribution.ts | 4 +- .../window/contributions/node-contribution.ts | 4 +- .../window/contributions/taro-contribution.ts | 4 +- .../window/contributions/tt-contribution.ts | 4 +- .../window/contributions/wx-contribution.ts | 4 +- .../src/contribution/env-canvas/canvas.ts | 147 ------------- .../src/contribution/env-canvas/context.ts | 31 --- .../env-canvas/env-contribution.ts | 176 --------------- .../src/contribution/env-canvas/module.ts | 42 ---- .../env-canvas/window-contribution.ts | 157 -------------- .../browser/src/inversify_test/index.ts | 37 ---- .../browser/src/pages/animate-next.ts | 1 - .../src/pages/editor/draggable-plugin.ts | 3 +- .../browser/src/pages/editor/register.ts | 12 +- .../__tests__/browser/src/pages/glyph.ts | 7 +- .../__tests__/browser/src/pages/pick-test.ts | 12 +- .../__tests__/browser/src/pages/rect.ts | 203 +++++++++++++++++- packages/vrender/src/index.ts | 8 +- 187 files changed, 875 insertions(+), 1591 deletions(-) delete mode 100644 packages/vrender-core/src/common/contribution-registry.ts delete mode 100644 packages/vrender-core/src/common/service-factory.ts delete mode 100644 packages/vrender-core/src/common/service-registry.ts delete mode 100644 packages/vrender-core/src/common/types.ts delete mode 100644 packages/vrender/__tests__/browser/src/contribution/env-canvas/canvas.ts delete mode 100644 packages/vrender/__tests__/browser/src/contribution/env-canvas/context.ts delete mode 100644 packages/vrender/__tests__/browser/src/contribution/env-canvas/env-contribution.ts delete mode 100644 packages/vrender/__tests__/browser/src/contribution/env-canvas/module.ts delete mode 100644 packages/vrender/__tests__/browser/src/contribution/env-canvas/window-contribution.ts delete mode 100644 packages/vrender/__tests__/browser/src/inversify_test/index.ts diff --git a/packages/vrender-animate/src/animate.ts b/packages/vrender-animate/src/animate.ts index 3161aba52..fbda43784 100644 --- a/packages/vrender-animate/src/animate.ts +++ b/packages/vrender-animate/src/animate.ts @@ -263,17 +263,9 @@ export class Animate implements IAnimate { // 创建新的step const step = new Step(AnimateStepType.from, props, duration, easing); - // 如果是第一个step - if (!this._firstStep) { - this._firstStep = step; - this._lastStep = step; - } else { - // 添加到链表末尾 - this._lastStep.append(step); - this._lastStep = step; - } + step.bind(this.target, this); - this.updateDuration(); + this.updateStepAfterAppend(step); return this; } diff --git a/packages/vrender-animate/src/custom/clip-graphic.ts b/packages/vrender-animate/src/custom/clip-graphic.ts index ffd05dee9..ae7dbf5ac 100644 --- a/packages/vrender-animate/src/custom/clip-graphic.ts +++ b/packages/vrender-animate/src/custom/clip-graphic.ts @@ -1,5 +1,5 @@ import type { IArcGraphicAttribute, IGraphic, IGroup, IRectGraphicAttribute } from '@visactor/vrender-core'; -import { application, AttributeUpdateType, type EasingType } from '@visactor/vrender-core'; +import { AttributeUpdateType, type EasingType, graphicService } from '@visactor/vrender-core'; import { ACustomAnimate } from './custom-animate'; export class ClipGraphicAnimate extends ACustomAnimate { @@ -102,7 +102,7 @@ export class ClipAngleAnimate extends ClipGraphicAnimate { arcStartAngle = startAngle; arcEndAngle = animationType === 'out' ? startAngle + Math.PI * 2 : startAngle; } - const arc = application.graphicService.creator.arc({ + const arc = graphicService.creator.arc({ x: params?.center?.x ?? width / 2, y: params?.center?.y ?? height / 2, outerRadius: params?.radius ?? (width + height) / 2, @@ -152,7 +152,7 @@ export class ClipRadiusAnimate extends ClipGraphicAnimate { const startRadius = params?.startRadius ?? 0; const endRadius = params?.endRadius ?? Math.sqrt((width / 2) ** 2 + (height / 2) ** 2); - const arc = application.graphicService.creator.arc({ + const arc = graphicService.creator.arc({ x: params?.center?.x ?? width / 2, y: params?.center?.y ?? height / 2, outerRadius: animationType === 'out' ? endRadius : startRadius, @@ -196,7 +196,7 @@ export class ClipDirectionAnimate extends ClipGraphicAnimate { const direction = params?.direction ?? 'x'; const orient = params?.orient ?? 'positive'; - const rect = application.graphicService.creator.rect({ + const rect = graphicService.creator.rect({ x: 0, y: 0, width: animationType === 'in' && direction === 'x' ? 0 : width, diff --git a/packages/vrender-animate/src/custom/disappear/base/DisappearAnimateBase.ts b/packages/vrender-animate/src/custom/disappear/base/DisappearAnimateBase.ts index 150757763..d3269b861 100644 --- a/packages/vrender-animate/src/custom/disappear/base/DisappearAnimateBase.ts +++ b/packages/vrender-animate/src/custom/disappear/base/DisappearAnimateBase.ts @@ -1,5 +1,5 @@ import type { EasingType } from '@visactor/vrender-core'; -import { vglobal } from '@visactor/vrender-core'; +import { VGlobal, vglobal } from '@visactor/vrender-core'; import { AStageAnimate } from '../../custom-animate'; /** diff --git a/packages/vrender-animate/src/custom/disappear/base/ImageProcessUtils.ts b/packages/vrender-animate/src/custom/disappear/base/ImageProcessUtils.ts index 1581db091..113448d42 100644 --- a/packages/vrender-animate/src/custom/disappear/base/ImageProcessUtils.ts +++ b/packages/vrender-animate/src/custom/disappear/base/ImageProcessUtils.ts @@ -1,4 +1,4 @@ -import { vglobal } from '@visactor/vrender-core'; +import { VGlobal, vglobal } from '@visactor/vrender-core'; /** * 图像处理工具类,公共的图像处理逻辑 diff --git a/packages/vrender-animate/src/custom/disappear/gaussian-blur.ts b/packages/vrender-animate/src/custom/disappear/gaussian-blur.ts index dbaab4ddf..7a9eba7cf 100644 --- a/packages/vrender-animate/src/custom/disappear/gaussian-blur.ts +++ b/packages/vrender-animate/src/custom/disappear/gaussian-blur.ts @@ -1,5 +1,5 @@ import type { EasingType } from '@visactor/vrender-core'; -import { vglobal } from '@visactor/vrender-core'; +import { VGlobal, vglobal } from '@visactor/vrender-core'; import { AStageAnimate } from '../custom-animate'; // 模糊效果配置接口 diff --git a/packages/vrender-animate/src/custom/disappear/pixelation.ts b/packages/vrender-animate/src/custom/disappear/pixelation.ts index 8696b0844..05fc7427b 100644 --- a/packages/vrender-animate/src/custom/disappear/pixelation.ts +++ b/packages/vrender-animate/src/custom/disappear/pixelation.ts @@ -1,5 +1,5 @@ import type { EasingType } from '@visactor/vrender-core'; -import { vglobal } from '@visactor/vrender-core'; +import { VGlobal, vglobal } from '@visactor/vrender-core'; import { DisappearAnimateBase } from './base/DisappearAnimateBase'; export interface PixelationConfig { diff --git a/packages/vrender-animate/src/custom/morphing.ts b/packages/vrender-animate/src/custom/morphing.ts index a0efb9fdf..3e296ccc8 100644 --- a/packages/vrender-animate/src/custom/morphing.ts +++ b/packages/vrender-animate/src/custom/morphing.ts @@ -7,7 +7,7 @@ import { splitArea, splitPath, CustomPath2D, - application, + graphicService, interpolateColor, ColorStore, ColorType, @@ -377,7 +377,7 @@ export const oneToMultiMorph = ( } const childGraphics: IGraphic[] = ( - animationConfig?.splitPath === 'clone' ? cloneGraphic : (animationConfig?.splitPath ?? splitGraphic) + animationConfig?.splitPath === 'clone' ? cloneGraphic : animationConfig?.splitPath ?? splitGraphic )(fromGraphic, validateToGraphics.length, false); const oldOnEnd = animationConfig?.onEnd; @@ -541,7 +541,7 @@ const appendShadowChildrenToGraphic = (graphic: IGraphic, children: IGraphic[], rect: childAttrs }); new Array(count).fill(0).forEach(el => { - const child = application.graphicService.creator.rect({ + const child = graphicService.creator.rect({ x: 0, y: 0, width, @@ -571,9 +571,7 @@ export const cloneGraphic = (graphic: IGraphic, count: number, needAppend?: bool path: new CustomPath2D().fromCustomPath2D(path) }; - children.push( - application.graphicService.creator.path(needAppend ? element : Object.assign({}, childAttrs, element)) - ); + children.push(graphicService.creator.path(needAppend ? element : Object.assign({}, childAttrs, element))); } if (needAppend) { @@ -597,23 +595,17 @@ export const splitGraphic = (graphic: IGraphic, count: number, needAppend?: bool if (graphic.type === 'rect') { const childrenAttrs = splitRect(graphic as IRect, count); childrenAttrs.forEach(element => { - children.push( - application.graphicService.creator.rect(needAppend ? element : Object.assign({}, childAttrs, element)) - ); + children.push(graphicService.creator.rect(needAppend ? element : Object.assign({}, childAttrs, element))); }); } else if (graphic.type === 'arc') { const childrenAttrs = splitArc(graphic as IArc, count); childrenAttrs.forEach(element => { - children.push( - application.graphicService.creator.arc(needAppend ? element : Object.assign({}, childAttrs, element)) - ); + children.push(graphicService.creator.arc(needAppend ? element : Object.assign({}, childAttrs, element))); }); } else if (graphic.type === 'circle') { const childrenAttrs = splitCircle(graphic as ICircle, count); childrenAttrs.forEach(element => { - children.push( - application.graphicService.creator.arc(needAppend ? element : Object.assign({}, childAttrs, element)) - ); + children.push(graphicService.creator.arc(needAppend ? element : Object.assign({}, childAttrs, element))); }); } else if (graphic.type === 'line') { const childrenAttrs = splitLine(graphic as ILine, count); @@ -621,7 +613,7 @@ export const splitGraphic = (graphic: IGraphic, count: number, needAppend?: bool childrenAttrs.forEach(element => { children.push( - application.graphicService.creator.symbol( + graphicService.creator.symbol( needAppend ? Object.assign({}, element, defaultSymbol) : Object.assign({}, childAttrs, element, defaultSymbol) ) ); @@ -629,28 +621,20 @@ export const splitGraphic = (graphic: IGraphic, count: number, needAppend?: bool } else if (graphic.type === 'polygon') { const childrenAttrs = splitPolygon(graphic as IPolygon, count); childrenAttrs.forEach(element => { - children.push( - application.graphicService.creator.polygon(needAppend ? element : Object.assign({}, childAttrs, element)) - ); + children.push(graphicService.creator.polygon(needAppend ? element : Object.assign({}, childAttrs, element))); }); } else if (graphic.type === 'area') { const childrenAttrs = splitArea(graphic as IArea, count); childrenAttrs.forEach(element => { - children.push( - application.graphicService.creator.polygon(needAppend ? element : Object.assign({}, childAttrs, element)) - ); + children.push(graphicService.creator.polygon(needAppend ? element : Object.assign({}, childAttrs, element))); }); } else if (graphic.type === 'path') { const childrenAttrs = splitPath(graphic as IPath, count); childrenAttrs.forEach(element => { if ('path' in element) { - children.push( - application.graphicService.creator.path(needAppend ? element : Object.assign({}, childAttrs, element)) - ); + children.push(graphicService.creator.path(needAppend ? element : Object.assign({}, childAttrs, element))); } else { - children.push( - application.graphicService.creator.polygon(needAppend ? element : Object.assign({}, childAttrs, element)) - ); + children.push(graphicService.creator.polygon(needAppend ? element : Object.assign({}, childAttrs, element))); } }); } @@ -687,7 +671,7 @@ export const multiToOneMorph = ( } const childGraphics: IGraphic[] = ( - animationConfig?.splitPath === 'clone' ? cloneGraphic : (animationConfig?.splitPath ?? splitGraphic) + animationConfig?.splitPath === 'clone' ? cloneGraphic : animationConfig?.splitPath ?? splitGraphic )(toGraphic, validateFromGraphics.length, true); const toAttrs = toGraphic.attribute; diff --git a/packages/vrender-animate/src/custom/streamLight.ts b/packages/vrender-animate/src/custom/streamLight.ts index ae0c60159..472c171c0 100644 --- a/packages/vrender-animate/src/custom/streamLight.ts +++ b/packages/vrender-animate/src/custom/streamLight.ts @@ -11,7 +11,7 @@ import type { IRect, IRectAttribute } from '@visactor/vrender-core'; -import { application, AttributeUpdateType, CustomPath2D, divideCubic } from '@visactor/vrender-core'; +import { AttributeUpdateType, CustomPath2D, divideCubic, graphicService } from '@visactor/vrender-core'; import { ACustomAnimate } from './custom-animate'; import type { IPoint } from '@visactor/vutils'; import { PointService } from '@visactor/vutils'; @@ -52,7 +52,7 @@ export class StreamLight extends ACustomAnimate { onStartLineOrArea(type: 'line' | 'area') { const root = this.target.attachShadow(); - const line = application.graphicService.creator[type]({ + const line = graphicService.creator[type]({ ...this.params?.attribute }); this[type] = line; @@ -69,7 +69,7 @@ export class StreamLight extends ACustomAnimate { const size = this.target.AABBBounds[sizeAttr](); const y = isHorizontal ? 0 : this.target.AABBBounds.y1; - const rect = application.graphicService.creator.rect({ + const rect = graphicService.creator.rect({ [sizeAttr]: size, fill: '#bcdeff', shadowBlur: 30, diff --git a/packages/vrender-animate/src/register.ts b/packages/vrender-animate/src/register.ts index fc7266b38..3a11a5d50 100644 --- a/packages/vrender-animate/src/register.ts +++ b/packages/vrender-animate/src/register.ts @@ -1,4 +1,4 @@ -import { Graphic } from '@visactor/vrender-core'; +import { Graphic, Stage } from '@visactor/vrender-core'; import { mixin } from '@visactor/vutils'; import { GraphicStateExtension } from './state/graphic-extension'; import { AnimateExtension } from './animate-extension'; @@ -7,4 +7,6 @@ export function registerAnimate() { // Mix in animation state methods to Graphic prototype mixin(Graphic, GraphicStateExtension); mixin(Graphic, AnimateExtension); + // Mix in animation methods to Stage prototype (for createTimeline and createTicker) + mixin(Stage, AnimateExtension); } diff --git a/packages/vrender-animate/src/ticker/default-ticker.ts b/packages/vrender-animate/src/ticker/default-ticker.ts index 21908779e..1602fa9f1 100644 --- a/packages/vrender-animate/src/ticker/default-ticker.ts +++ b/packages/vrender-animate/src/ticker/default-ticker.ts @@ -1,6 +1,6 @@ import { EventEmitter } from '@visactor/vutils'; import type { IStage, ITimeline } from '@visactor/vrender-core'; -import { application, PerformanceRAF, type ITickHandler, type ITicker, STATUS } from '@visactor/vrender-core'; +import { PerformanceRAF, type ITickHandler, type ITicker, STATUS, vglobal } from '@visactor/vrender-core'; const performanceRAF = new PerformanceRAF(); @@ -70,10 +70,10 @@ export class DefaultTicker extends EventEmitter implements ITicker { init(): void { this.interval = 16; this.status = STATUS.INITIAL; - application.global.hooks.onSetEnv.tap('graph-ticker', () => { + vglobal.hooks.onSetEnv.tap('graph-ticker', () => { this.initHandler(false); }); - if (application.global.env) { + if (vglobal.env) { this.initHandler(false); } } diff --git a/packages/vrender-components/src/poptip/contribution.ts b/packages/vrender-components/src/poptip/contribution.ts index 30d2496ef..e3bf03171 100644 --- a/packages/vrender-components/src/poptip/contribution.ts +++ b/packages/vrender-components/src/poptip/contribution.ts @@ -6,7 +6,6 @@ import type { IThemeAttribute, IDrawContext } from '@visactor/vrender-core'; -import { injectable } from '@visactor/vrender-core'; import { PopTip } from './poptip'; import { merge } from '@visactor/vutils'; import { theme } from './theme'; @@ -16,7 +15,6 @@ function wrapPoptip(target: Record, source: Record) { return target; } -@injectable() export class PopTipRenderContribution implements IInteractiveSubRenderContribution { declare poptipComponent: PopTip; render( diff --git a/packages/vrender-components/src/poptip/module.ts b/packages/vrender-components/src/poptip/module.ts index 82d4df958..5cd0bf493 100644 --- a/packages/vrender-components/src/poptip/module.ts +++ b/packages/vrender-components/src/poptip/module.ts @@ -1,27 +1,14 @@ -import { - InteractiveSubRenderContribution, - AutoEnablePlugins, - ContainerModule, - container -} from '@visactor/vrender-core'; +import { InteractiveSubRenderContribution, AutoEnablePlugins, contributionRegistry } from '@visactor/vrender-core'; import { PopTipRenderContribution } from './contribution'; import { PopTipPlugin, PopTipForClipedTextPlugin } from './poptip-plugin'; -export const popTipModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (!isBound(PopTipRenderContribution)) { - bind(PopTipRenderContribution).toSelf().inSingletonScope(); - bind(InteractiveSubRenderContribution).toService(PopTipRenderContribution); - } - if (!isBound(PopTipPlugin)) { - bind(PopTipPlugin).toSelf(); - bind(AutoEnablePlugins).toService(PopTipPlugin); - } - if (!isBound(PopTipForClipedTextPlugin)) { - bind(PopTipForClipedTextPlugin).toSelf(); - bind(AutoEnablePlugins).toService(PopTipForClipedTextPlugin); - } -}); - +let _registered = false; export function loadPoptip() { - container.load(popTipModule); + if (_registered) { + return; + } + _registered = true; + contributionRegistry.register(InteractiveSubRenderContribution, new PopTipRenderContribution()); + contributionRegistry.register(AutoEnablePlugins, new PopTipPlugin()); + contributionRegistry.register(AutoEnablePlugins, new PopTipForClipedTextPlugin()); } diff --git a/packages/vrender-components/src/poptip/poptip-plugin.ts b/packages/vrender-components/src/poptip/poptip-plugin.ts index 68ea88177..72a68b0cc 100644 --- a/packages/vrender-components/src/poptip/poptip-plugin.ts +++ b/packages/vrender-components/src/poptip/poptip-plugin.ts @@ -1,5 +1,5 @@ import type { FederatedPointerEvent, IGraphic, IPlugin, IPluginService } from '@visactor/vrender-core'; -import { Generator, injectable } from '@visactor/vrender-core'; +import { Generator } from '@visactor/vrender-core'; // _showPoptip: 0-没有,1-添加,2-删除 @@ -36,12 +36,12 @@ export abstract class PopTipPluginBase { } if (this.needShow(graphic)) { graphic.setAttributes({}); - graphic._showPoptip = 1; + (graphic as any)._showPoptip = 1; } if (this.activeGraphic) { this.activeGraphic.setAttributes({}); - this.activeGraphic._showPoptip = 2; + (this.activeGraphic as any)._showPoptip = 2; } // console.log(graphic) this.setActiveGraphic(graphic, true); @@ -52,7 +52,7 @@ export abstract class PopTipPluginBase { return; } this.activeGraphic.setAttributes({}); - this.activeGraphic._showPoptip = 2; + (this.activeGraphic as any)._showPoptip = 2; this.setActiveGraphic(null, true); }; @@ -68,13 +68,11 @@ export abstract class PopTipPluginBase { } } -@injectable() export class PopTipPlugin extends PopTipPluginBase implements IPlugin { name: 'poptip' = 'poptip'; key: string = this.name + this._uid; } -@injectable() export class PopTipForClipedTextPlugin extends PopTipPluginBase implements IPlugin { name: 'poptipForText' = 'poptipForText'; key: string = this.name + this._uid; diff --git a/packages/vrender-components/src/poptip/register.ts b/packages/vrender-components/src/poptip/register.ts index 9e91d66a9..1cff13837 100644 --- a/packages/vrender-components/src/poptip/register.ts +++ b/packages/vrender-components/src/poptip/register.ts @@ -1,9 +1,10 @@ -import { container } from '@visactor/vrender-core'; +import { InteractiveSubRenderContribution, AutoEnablePlugins } from '@visactor/vrender-core'; import { merge } from '@visactor/vutils'; import type { PopTipAttributes } from './type'; import { DEFAULT_THEME, theme } from './theme'; import { registerGroup, registerRect, registerSymbol, registerText } from '@visactor/vrender-kits'; +const _registered = false; export function loadPoptipComponent() { registerGroup(); registerText(); diff --git a/packages/vrender-components/src/scrollbar/module.ts b/packages/vrender-components/src/scrollbar/module.ts index 0db67f781..fb7c1079c 100644 --- a/packages/vrender-components/src/scrollbar/module.ts +++ b/packages/vrender-components/src/scrollbar/module.ts @@ -1,13 +1,11 @@ -import { AutoEnablePlugins, ContainerModule, container } from '@visactor/vrender-core'; +import { AutoEnablePlugins, contributionRegistry } from '@visactor/vrender-core'; import { ScrollBarPlugin } from './scrollbar-plugin'; -export const scrollbarModule = new ContainerModule((bind, unbind, isBound, rebind) => { - if (!isBound(ScrollBarPlugin)) { - bind(ScrollBarPlugin).toSelf(); - bind(AutoEnablePlugins).toService(ScrollBarPlugin); - } -}); - +let _registered = false; export function loadScrollbar() { - container.load(scrollbarModule); + if (_registered) { + return; + } + _registered = true; + contributionRegistry.register(AutoEnablePlugins, new ScrollBarPlugin()); } diff --git a/packages/vrender-components/src/scrollbar/scrollbar-plugin.ts b/packages/vrender-components/src/scrollbar/scrollbar-plugin.ts index 6201ce2bf..32149b788 100644 --- a/packages/vrender-components/src/scrollbar/scrollbar-plugin.ts +++ b/packages/vrender-components/src/scrollbar/scrollbar-plugin.ts @@ -1,5 +1,5 @@ import type { IGraphic, IGroup, IPlugin, IPluginService } from '@visactor/vrender-core'; -import { Generator, injectable } from '@visactor/vrender-core'; +import { Generator } from '@visactor/vrender-core'; import { ScrollBar } from './scrollbar'; import type { IAABBBounds } from '@visactor/vutils'; import { AABBBounds, abs, Bounds } from '@visactor/vutils'; @@ -14,7 +14,6 @@ type IParams = { bufferH?: number; // 判定是否出现滚动条的buffer }; -@injectable() export class ScrollBarPlugin implements IPlugin { name: 'scrollbar' = 'scrollbar'; activeEvent: 'onRegister' = 'onRegister'; diff --git a/packages/vrender-components/src/slider/slider.ts b/packages/vrender-components/src/slider/slider.ts index bf0cc5e37..830de9f74 100644 --- a/packages/vrender-components/src/slider/slider.ts +++ b/packages/vrender-components/src/slider/slider.ts @@ -15,7 +15,7 @@ import type { Cursor } from '@visactor/vrender-core'; import { isNil, merge, clamp, isValid, array, isObject, isArray, clampRange, debounce } from '@visactor/vutils'; -import { graphicCreator, vglobal, CustomEvent } from '@visactor/vrender-core'; +import { graphicCreator, CustomEvent, vglobal } from '@visactor/vrender-core'; import { AbstractComponent } from '../core/base'; import { SLIDER_ELEMENT_NAME } from './constant'; diff --git a/packages/vrender-components/src/table-series-number/event-manager.ts b/packages/vrender-components/src/table-series-number/event-manager.ts index 9fb610d5c..ba6efa66f 100644 --- a/packages/vrender-components/src/table-series-number/event-manager.ts +++ b/packages/vrender-components/src/table-series-number/event-manager.ts @@ -1,5 +1,5 @@ import type { TableSeriesNumber } from './table-series-number'; -import { vglobal, type FederatedPointerEvent, type Group, type IGroup, type IText } from '@visactor/vrender-core'; +import { type FederatedPointerEvent, type Group, type IGroup, type IText, vglobal } from '@visactor/vrender-core'; import { SeriesNumberCellStateValue, SeriesNumberEvent } from './type'; export class TableSeriesNumberEventManager { diff --git a/packages/vrender-core/src/allocator/canvas-allocate.ts b/packages/vrender-core/src/allocator/canvas-allocate.ts index e6b0d236d..bb77971e4 100644 --- a/packages/vrender-core/src/allocator/canvas-allocate.ts +++ b/packages/vrender-core/src/allocator/canvas-allocate.ts @@ -1,6 +1,7 @@ -import { application } from '../application'; -import type { ICanvas, Releaseable, IAllocate } from '../interface'; +import type { ICanvas, Releaseable, IAllocate, IGlobal } from '../interface'; import { wrapCanvas } from '../canvas/util'; +import { serviceRegistry } from '../common/registry/service-registry'; +import { VGlobal } from '../constants'; export class DefaultCanvasAllocate implements IAllocate, Releaseable { protected pools: ICanvas[] = []; @@ -21,10 +22,9 @@ export class DefaultCanvasAllocate implements IAllocate, Releaseable { } allocate(data: { width: number; height: number; dpr: number }): ICanvas { if (!this.pools.length) { - const c = wrapCanvas({ - nativeCanvas: application.global.createCanvas(data), - ...data - }); + const global = serviceRegistry.get(VGlobal) as IGlobal; + const nativeCanvas = global.createCanvas(data); + const c = wrapCanvas({ nativeCanvas, ...data }); this.allocatedCanvas.push(c); return c; } @@ -40,10 +40,9 @@ export class DefaultCanvasAllocate implements IAllocate, Releaseable { height: canvas.height / canvas.dpr, dpr: canvas.dpr }; - const c = wrapCanvas({ - nativeCanvas: application.global.createCanvas(data), - ...data - }); + const global = serviceRegistry.get(VGlobal) as IGlobal; + const nativeCanvas = global.createCanvas(data); + const c = wrapCanvas({ nativeCanvas, ...data }); this.allocatedCanvas.push(c); return c; } diff --git a/packages/vrender-core/src/allocator/graphic-allocate.ts b/packages/vrender-core/src/allocator/graphic-allocate.ts index 8f4338d64..c864179c6 100644 --- a/packages/vrender-core/src/allocator/graphic-allocate.ts +++ b/packages/vrender-core/src/allocator/graphic-allocate.ts @@ -20,7 +20,7 @@ import type { ITextGraphicAttribute, Releaseable } from '../interface'; -import { application } from '../application'; +import { vglobal, graphicService } from '../modules'; export abstract class DefaultGraphicAllocate implements IAllocate, Releaseable @@ -42,7 +42,7 @@ export abstract class DefaultGraphicAllocate { allocate(attribute: IRectGraphicAttribute): IRect { if (!this.pools.length) { - return application.graphicService.creator.rect(attribute); + return graphicService.creator.rect(attribute); } const g = this.pools.pop(); g.initAttributes(attribute); @@ -51,7 +51,7 @@ export class DefaultRectAllocate extends DefaultGraphicAllocate { allocate(attribute: IArcGraphicAttribute): IArc { if (!this.pools.length) { - return application.graphicService.creator.arc(attribute); + return graphicService.creator.arc(attribute); } const g = this.pools.pop(); g.initAttributes(attribute); @@ -72,7 +72,7 @@ export class DefaultArcAllocate extends DefaultGraphicAllocate { allocate(attribute: IAreaGraphicAttribute): IArea { if (!this.pools.length) { - return application.graphicService.creator.area(attribute); + return graphicService.creator.area(attribute); } const g = this.pools.pop(); g.initAttributes(attribute); @@ -94,7 +94,7 @@ export class DefaultAreaAllocate extends DefaultGraphicAllocate { allocate(attribute: ICircleGraphicAttribute): ICircle { if (!this.pools.length) { - return application.graphicService.creator.circle(attribute); + return graphicService.creator.circle(attribute); } const g = this.pools.pop(); g.initAttributes(attribute); @@ -116,7 +116,7 @@ export class DefaultCircleAllocate extends DefaultGraphicAllocate { allocate(attribute: ILineGraphicAttribute): ILine { if (!this.pools.length) { - return application.graphicService.creator.line(attribute); + return graphicService.creator.line(attribute); } const g = this.pools.pop(); g.initAttributes(attribute); @@ -138,7 +138,7 @@ export class DefaultLineAllocate extends DefaultGraphicAllocate { allocate(attribute: IPathGraphicAttribute): IPath { if (!this.pools.length) { - return application.graphicService.creator.path(attribute); + return graphicService.creator.path(attribute); } const g = this.pools.pop(); g.initAttributes(attribute); @@ -160,7 +160,7 @@ export class DefaultPathAllocate extends DefaultGraphicAllocate { allocate(attribute: ISymbolGraphicAttribute): ISymbol { if (!this.pools.length) { - return application.graphicService.creator.symbol(attribute); + return graphicService.creator.symbol(attribute); } const g = this.pools.pop(); g.initAttributes(attribute); @@ -182,7 +182,7 @@ export class DefaultSymbolAllocate extends DefaultGraphicAllocate { allocate(attribute: ITextGraphicAttribute): IText { if (!this.pools.length) { - return application.graphicService.creator.text(attribute); + return graphicService.creator.text(attribute); } const g = this.pools.pop(); g.initAttributes(attribute); @@ -204,7 +204,7 @@ export class DefaultTextAllocate extends DefaultGraphicAllocate(RenderService); @@ -16,12 +44,27 @@ export class Application { return this._renderService; } private _renderService: IRenderService; - transformUtil: ITransformUtil; - layerService: ILayerService; + + get transformUtil(): ITransformUtil { + return serviceRegistry.get(TransformUtil); + } + set transformUtil(value: ITransformUtil) { + // 向后兼容,但不做任何事 + } + + get layerService(): ILayerService { + return serviceRegistry.get(LayerService); + } + set layerService(value: ILayerService) { + // 向后兼容,但不做任何事 + } // 新的注册表系统 readonly services: ServiceRegistry = serviceRegistry; readonly contributions: ContributionRegistry = contributionRegistry; } +/** + * @deprecated 使用 serviceRegistry 和 contributionRegistry 直接访问,或使用 application-helpers 中的函数 + */ export const application = new Application(); diff --git a/packages/vrender-core/src/canvas/conical-gradient.ts b/packages/vrender-core/src/canvas/conical-gradient.ts index f9f3f07f3..5d0987d35 100644 --- a/packages/vrender-core/src/canvas/conical-gradient.ts +++ b/packages/vrender-core/src/canvas/conical-gradient.ts @@ -23,7 +23,7 @@ * SOFTWARE. */ import { pi2, LRU } from '@visactor/vutils'; -import { application } from '../application'; +import { vglobal } from '../modules'; import type { IConicalGradient, IContext2d } from '../interface'; import { interpolateColor } from '../color-string'; @@ -34,7 +34,7 @@ class ConicalCanvas { static GetCanvas() { try { if (!ConicalCanvas.canvas) { - ConicalCanvas.canvas = application.global.createCanvas({}); + ConicalCanvas.canvas = vglobal.createCanvas({}); } return ConicalCanvas.canvas; } catch (err) { diff --git a/packages/vrender-core/src/canvas/contributions/base-canvas.ts b/packages/vrender-core/src/canvas/contributions/base-canvas.ts index bfdcc4e64..36f54ca2d 100644 --- a/packages/vrender-core/src/canvas/contributions/base-canvas.ts +++ b/packages/vrender-core/src/canvas/contributions/base-canvas.ts @@ -124,8 +124,8 @@ export abstract class BaseCanvas implements ICanvas { this._displayHeight = height; this._dpr = dpr; this._nativeCanvas = nativeCanvas; - this._id = nativeCanvas.id ?? id; - if (id) { + this._id = nativeCanvas?.id ?? id; + if (nativeCanvas && id) { nativeCanvas.id = id; } diff --git a/packages/vrender-core/src/canvas/util.ts b/packages/vrender-core/src/canvas/util.ts index 22f759e95..3f8afab0f 100644 --- a/packages/vrender-core/src/canvas/util.ts +++ b/packages/vrender-core/src/canvas/util.ts @@ -2,13 +2,15 @@ import type { IPointLike, vec2 } from '@visactor/vutils'; import { isPointInLine, pi, pi2 } from '@visactor/vutils'; import { enumCommandMap as CMD } from '../common/path-svg'; import type { CommandType, IContext2d } from '../interface'; -import { application } from '../application'; +import { contributionRegistry } from '../common/registry/contribution-registry'; +import { serviceRegistry } from '../common/registry/service-registry'; +import { VGlobal } from '../constants'; +import type { IGlobal } from '../interface/global'; import { CanvasFactory, Context2dFactory } from './constants'; import type { CanvasConfigType, ICanvas, ICanvasFactory, IContext2dFactory } from '../interface'; -export function wrapCanvas(params: CanvasConfigType) { - const factories = application.contributions.get(CanvasFactory); - const factory = factories.find((f: any) => (f as any).env === application.global.env) ?? factories[0]; +export function wrapCanvas(params: CanvasConfigType): ICanvas { + const factory = serviceRegistry.getFactory(CanvasFactory) as ICanvasFactory; if (!factory) { throw new Error('No CanvasFactory registered'); } @@ -16,8 +18,7 @@ export function wrapCanvas(params: CanvasConfigType) { } export function wrapContext(canvas: ICanvas, dpr: number) { - const factories = application.contributions.get(Context2dFactory); - const factory = factories.find((f: any) => (f as any).env === application.global.env) ?? factories[0]; + const factory = serviceRegistry.getFactory(Context2dFactory) as IContext2dFactory; if (!factory) { throw new Error('No Context2dFactory registered'); } diff --git a/packages/vrender-core/src/common/contribution-registry.ts b/packages/vrender-core/src/common/contribution-registry.ts deleted file mode 100644 index 5331943cc..000000000 --- a/packages/vrender-core/src/common/contribution-registry.ts +++ /dev/null @@ -1,90 +0,0 @@ -/** - * ContributionRegistry - 贡献/扩展注册表 - * 替代 ContributionProvider + container.getAll() 的多实现聚合能力 - */ -import type { ServiceIdentifier } from './types'; - -export interface ContributionItem { - contribution: T; - order?: number; -} - -export class ContributionRegistry { - private contributions: Map, ContributionItem[]> = new Map(); - - /** - * 注册一个贡献实现 - */ - register(id: ServiceIdentifier, contribution: T, order: number = 0): void { - let list = this.contributions.get(id); - if (!list) { - list = []; - this.contributions.set(id, list); - } - list.push({ contribution, order }); - } - - /** - * 获取所有贡献(按 order 排序) - */ - getContributions(id: ServiceIdentifier): T[] { - const list = this.contributions.get(id); - if (!list || list.length === 0) { - return []; - } - // 按 order 升序排序 - return list.sort((a, b) => (a.order ?? 0) - (b.order ?? 0)).map(item => item.contribution); - } - - /** - * 检查是否有贡献注册 - */ - has(id: ServiceIdentifier): boolean { - const list = this.contributions.get(id); - return list !== undefined && list.length > 0; - } - - /** - * 移除某个 token 下的所有贡献 - */ - remove(id: ServiceIdentifier): void { - this.contributions.delete(id); - } - - /** - * 移除某个具体的贡献实例 - */ - removeContribution(id: ServiceIdentifier, contribution: T): void { - const list = this.contributions.get(id); - if (list) { - const index = list.findIndex(item => item.contribution === contribution); - if (index !== -1) { - list.splice(index, 1); - } - } - } - - /** - * 刷新指定 token 的贡献列表(清空缓存,下次 get 时重新排序) - */ - refresh(id: ServiceIdentifier): void { - // 当前实现不需要特殊处理,因为每次 getContributions 都会重新排序 - // 保留此方法以兼容 ContributionProvider 的 refresh 语义 - } - - /** - * 刷新所有贡献列表 - */ - refreshAll(): void { - // 同上 - } - - /** - * 清空所有注册 - */ - clear(): void { - this.contributions.clear(); - } -} - -export const contributionRegistry = new ContributionRegistry(); diff --git a/packages/vrender-core/src/common/performance-raf.ts b/packages/vrender-core/src/common/performance-raf.ts index d9d2bae09..edc41bbea 100644 --- a/packages/vrender-core/src/common/performance-raf.ts +++ b/packages/vrender-core/src/common/performance-raf.ts @@ -1,4 +1,4 @@ -import { application } from '../application'; +import { vglobal } from '../modules'; let idx = 0; @@ -40,6 +40,6 @@ export class PerformanceRAF { if (this._rafHandle !== null || this.nextAnimationFrameCbs.size === 0) { return; } - this._rafHandle = application.global.getRequestAnimationFrame()(this.runAnimationFrame); + this._rafHandle = vglobal.getRequestAnimationFrame()(this.runAnimationFrame); }; } diff --git a/packages/vrender-core/src/common/service-factory.ts b/packages/vrender-core/src/common/service-factory.ts deleted file mode 100644 index 39cc9500e..000000000 --- a/packages/vrender-core/src/common/service-factory.ts +++ /dev/null @@ -1,162 +0,0 @@ -/** - * 服务工厂模块 - 创建不依赖装饰器的服务实例 - * - * 这些工厂函数显式传递依赖,替代 @inject/@multiInject/@named 装饰器 - */ -import type { application } from '../application'; -import { serviceRegistry, contributionRegistry } from './registry'; - -// ============ 类型定义 ============ - -export interface IServiceContext { - services: typeof serviceRegistry; - contributions: typeof contributionRegistry; - application: typeof application; -} - -// ============ 服务工厂 ============ - -/** - * 创建 RenderService 实例 - * 替代 @inject(DrawContribution) 装饰器 - */ -declare let require: any; -export function createRenderService() { - const { DefaultRenderService } = require('../render/render-service'); - const { DrawContribution } = require('../render/contributions/render/symbol'); - - // 获取 DrawContribution 实例 - const drawContribution = createDrawContribution(); - - return new DefaultRenderService(drawContribution); -} - -/** - * 创建 DrawContribution 实例 - * 替代 @multiInject(GraphicRender) 和 @inject(ContributionProvider) @named(DrawItemInterceptor) 装饰器 - */ -export function createDrawContribution() { - const { DefaultDrawContribution } = require('../render/contributions/render/draw-contribution'); - const { GraphicRender } = require('../render/contributions/render/symbol'); - const { DrawItemInterceptor } = require('../render/contributions/render/draw-interceptor'); - - // 获取所有 GraphicRender 贡献 - const graphicRenders = contributionRegistry.get(GraphicRender); - - // 创建 DrawItemInterceptor 的 ContributionProvider 兼容对象 - const drawItemInterceptorProvider = { - getContributions: () => contributionRegistry.get(DrawItemInterceptor) - }; - - return new DefaultDrawContribution(graphicRenders, drawItemInterceptorProvider); -} - -/** - * 创建 IncrementalDrawContribution 实例 - */ -export function createIncrementalDrawContribution() { - const { - DefaultIncrementalDrawContribution - } = require('../render/contributions/render/incremental-draw-contribution'); - const { GraphicRender } = require('../render/contributions/render/symbol'); - const { DrawItemInterceptor } = require('../render/contributions/render/draw-interceptor'); - const { DefaultIncrementalCanvasLineRender } = require('../render/contributions/render/incremental-line-render'); - const { DefaultIncrementalCanvasAreaRender } = require('../render/contributions/render/incremental-area-render'); - - // 获取所有 GraphicRender 贡献 - const graphicRenders = contributionRegistry.get(GraphicRender); - - // 获取特定的 line/area render - const lineRender = - serviceRegistry.get(DefaultIncrementalCanvasLineRender) || new DefaultIncrementalCanvasLineRender(); - const areaRender = - serviceRegistry.get(DefaultIncrementalCanvasAreaRender) || new DefaultIncrementalCanvasAreaRender(); - - // 创建 DrawItemInterceptor 的 ContributionProvider 兼容对象 - const drawItemInterceptorProvider = { - getContributions: () => contributionRegistry.get(DrawItemInterceptor) - }; - - return new DefaultIncrementalDrawContribution(graphicRenders, lineRender, areaRender, drawItemInterceptorProvider); -} - -/** - * 创建 PluginService 实例 - * 替代 @inject(ContributionProvider) @named(AutoEnablePlugins) 装饰器 - */ -export function createPluginService() { - const { DefaultPluginService } = require('../plugins/plugin-service'); - const { AutoEnablePlugins } = require('../plugins/constants'); - - // 创建 AutoEnablePlugins 的 ContributionProvider 兼容对象 - const autoEnablePluginsProvider = { - getContributions: () => contributionRegistry.get(AutoEnablePlugins) - }; - - return new DefaultPluginService(autoEnablePluginsProvider); -} - -/** - * 创建 PickerService 实例 - */ -export function createPickerService() { - const { DefaultGlobalPickerService } = require('../picker/global-picker-service'); - return new DefaultGlobalPickerService(); -} - -/** - * 创建 Global 实例 - * 替代 @inject(ContributionProvider) @named(EnvContribution) 装饰器 - */ -export function createGlobal() { - const { DefaultGlobal } = require('../core/global'); - return new DefaultGlobal(); -} - -/** - * 创建 GraphicUtil 实例 - * 替代 @inject(ContributionProvider) @named(TextMeasureContribution) 装饰器 - */ -export function createGraphicUtil() { - const { DefaultGraphicUtil } = require('../core/graphic-utils'); - const { TextMeasureContribution } = require('../core/contributions/textMeasure/textMeasure-contribution'); - - // 创建 TextMeasureContribution 的 ContributionProvider 兼容对象 - const textMeasureProvider = { - getContributions: () => contributionRegistry.get(TextMeasureContribution) - }; - - return new DefaultGraphicUtil(textMeasureProvider); -} - -/** - * 创建 LayerService 实例 - */ -export function createLayerService() { - const { DefaultLayerService } = require('../core/layer-service'); - return new DefaultLayerService(); -} - -/** - * 创建 TransformUtil 实例 - */ -export function createTransformUtil() { - const { DefaultTransformUtil } = require('../core/graphic-utils'); - return new DefaultTransformUtil(); -} - -/** - * 创建 GraphicService 实例 - */ -export function createGraphicService() { - const { DefaultGraphicService } = require('../graphic/graphic-service/graphic-service'); - return new DefaultGraphicService(); -} - -/** - * 创建 Window 实例 - */ -export function createWindow() { - const { DefaultWindow } = require('../core/window'); - return new DefaultWindow(); -} diff --git a/packages/vrender-core/src/common/service-registry.ts b/packages/vrender-core/src/common/service-registry.ts deleted file mode 100644 index 4295f6902..000000000 --- a/packages/vrender-core/src/common/service-registry.ts +++ /dev/null @@ -1,94 +0,0 @@ -/** - * ServiceRegistry - 服务注册表 - * 替代 inversify Container 的单例/工厂管理能力 - */ -import type { ServiceIdentifier } from './types'; - -export type ServiceFactory = () => T; - -interface ServiceBinding { - type: 'singleton' | 'factory'; - instance?: T; - factory?: ServiceFactory; -} - -export class ServiceRegistry { - private bindings: Map, ServiceBinding> = new Map(); - - /** - * 注册单例服务 - */ - registerSingleton(id: ServiceIdentifier, instance: T): void { - this.bindings.set(id, { - type: 'singleton', - instance - }); - } - - /** - * 注册工厂服务(每次 get 返回新实例) - */ - registerFactory(id: ServiceIdentifier, factory: ServiceFactory): void { - this.bindings.set(id, { - type: 'factory', - factory - }); - } - - /** - * 注册延迟单例(首次 get 时创建并缓存) - */ - registerLazySingleton(id: ServiceIdentifier, factory: ServiceFactory): void { - const binding: ServiceBinding = { - type: 'singleton', - factory - }; - this.bindings.set(id, binding); - } - - /** - * 获取服务 - */ - get(id: ServiceIdentifier): T { - const binding = this.bindings.get(id); - if (!binding) { - throw new Error(`Service not found: ${String(id)}`); - } - - if (binding.type === 'singleton') { - if (binding.instance === undefined && binding.factory) { - binding.instance = binding.factory(); - } - return binding.instance as T; - } - - // factory type - if (!binding.factory) { - throw new Error(`Factory not found for service: ${String(id)}`); - } - return binding.factory(); - } - - /** - * 检查服务是否已注册 - */ - has(id: ServiceIdentifier): boolean { - return this.bindings.has(id); - } - - /** - * 移除服务 - */ - remove(id: ServiceIdentifier): void { - this.bindings.delete(id); - } - - /** - * 清空所有注册 - */ - clear(): void { - this.bindings.clear(); - } -} - -export const serviceRegistry = new ServiceRegistry(); diff --git a/packages/vrender-core/src/common/types.ts b/packages/vrender-core/src/common/types.ts deleted file mode 100644 index 79ab4700e..000000000 --- a/packages/vrender-core/src/common/types.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * 通用类型定义 - */ - -/** - * 服务标识符类型 - 用于在注册表中标识服务 - * 支持 Symbol、字符串、类构造函数 - */ -export type ServiceIdentifier = symbol | string | (new (...args: any[]) => T); diff --git a/packages/vrender-core/src/core/contributions/layerHandler/canvas2d-contribution.ts b/packages/vrender-core/src/core/contributions/layerHandler/canvas2d-contribution.ts index 12c7793fe..c4afa22b3 100644 --- a/packages/vrender-core/src/core/contributions/layerHandler/canvas2d-contribution.ts +++ b/packages/vrender-core/src/core/contributions/layerHandler/canvas2d-contribution.ts @@ -14,7 +14,7 @@ import type { LayerMode } from '../../../interface'; import type { IBounds } from '@visactor/vutils'; -import { application } from '../../../application'; +import { vglobal } from '../../../modules'; export class CanvasLayerHandlerContribution implements ILayerHandlerContribution { layer: ILayer; @@ -30,7 +30,7 @@ export class CanvasLayerHandlerContribution implements ILayerHandlerContribution constructor() { this.offscreen = false; - this.global = application.global; + this.global = vglobal; } setDpr(dpr: number) { diff --git a/packages/vrender-core/src/core/contributions/layerHandler/empty-contribution.ts b/packages/vrender-core/src/core/contributions/layerHandler/empty-contribution.ts index ba65e6584..14f3caf96 100644 --- a/packages/vrender-core/src/core/contributions/layerHandler/empty-contribution.ts +++ b/packages/vrender-core/src/core/contributions/layerHandler/empty-contribution.ts @@ -11,7 +11,7 @@ import type { LayerMode } from '../../../interface'; import type { IBounds } from '@visactor/vutils'; -import { application } from '../../../application'; +import { vglobal } from '../../../modules'; export class EmptyLayerHandlerContribution implements ILayerHandlerContribution { declare layer: ILayer; @@ -28,7 +28,7 @@ export class EmptyLayerHandlerContribution implements ILayerHandlerContribution constructor() { this.offscreen = false; this.type = 'virtual'; - this.global = application.global; + this.global = vglobal; } setDpr(dpr: number) { diff --git a/packages/vrender-core/src/core/contributions/layerHandler/offscreen2d-contribution.ts b/packages/vrender-core/src/core/contributions/layerHandler/offscreen2d-contribution.ts index 2ac1dd2af..78fa93d2a 100644 --- a/packages/vrender-core/src/core/contributions/layerHandler/offscreen2d-contribution.ts +++ b/packages/vrender-core/src/core/contributions/layerHandler/offscreen2d-contribution.ts @@ -13,7 +13,7 @@ import type { LayerMode } from '../../../interface'; import type { IBoundsLike } from '@visactor/vutils'; -import { application } from '../../../application'; +import { vglobal } from '../../../modules'; export class OffscreenLayerHandlerContribution implements ILayerHandlerContribution { declare layer: ILayer; @@ -28,7 +28,7 @@ export class OffscreenLayerHandlerContribution implements ILayerHandlerContribut constructor() { this.offscreen = true; this.type = 'dynamic'; - this.global = application.global; + this.global = vglobal; } setDpr(dpr: number) { diff --git a/packages/vrender-core/src/core/graphic-utils.ts b/packages/vrender-core/src/core/graphic-utils.ts index 3dda77cef..0c30cc42c 100644 --- a/packages/vrender-core/src/core/graphic-utils.ts +++ b/packages/vrender-core/src/core/graphic-utils.ts @@ -17,7 +17,7 @@ import type { IMatrix, IPointLike, ITextMeasureOption } from '@visactor/vutils'; import { Matrix, TextMeasure } from '@visactor/vutils'; import type { IGraphicUtil, ITransformUtil, TransformType } from '../interface/core'; import { canvasAllocate } from '../allocator/canvas-allocate'; -import { application } from '../application'; +import { VGlobal } from '../constants'; import { VWindow } from './window'; import { contributionRegistry, serviceRegistry } from '../common/registry'; @@ -47,7 +47,7 @@ export class DefaultGraphicUtil implements IGraphicUtil { getContributions: () => contributionRegistry.get(TextMeasureContribution) } as IContributionProvider); this.configured = false; - this.global = application.global; + this.global = serviceRegistry.get(VGlobal) as IGlobal; this._textMeasureMap = new Map(); this.global.hooks.onSetEnv.tap('graphic-util', (lastEnv, env, global) => { this.configured = false; diff --git a/packages/vrender-core/src/core/layer-service.ts b/packages/vrender-core/src/core/layer-service.ts index a0954350e..760f39f73 100644 --- a/packages/vrender-core/src/core/layer-service.ts +++ b/packages/vrender-core/src/core/layer-service.ts @@ -6,7 +6,7 @@ import { StaticLayerHandlerContribution, VirtualLayerHandlerContribution } from './constants'; -import { application } from '../application'; +import { vglobal } from '../modules'; import { serviceRegistry } from '../common/registry'; export class DefaultLayerService implements ILayerService { @@ -24,7 +24,7 @@ export class DefaultLayerService implements ILayerService { constructor() { this.layerMap = new Map(); - this.global = application.global; + this.global = vglobal; } tryInit() { @@ -55,11 +55,11 @@ export class DefaultLayerService implements ILayerService { getLayerHandler(layerMode: LayerMode) { let layerHandler: ILayerHandlerContribution; if (layerMode === 'static') { - layerHandler = serviceRegistry.get(StaticLayerHandlerContribution); + layerHandler = serviceRegistry.createInstance(StaticLayerHandlerContribution); } else if (layerMode === 'dynamic') { - layerHandler = serviceRegistry.get(DynamicLayerHandlerContribution); + layerHandler = serviceRegistry.createInstance(DynamicLayerHandlerContribution); } else { - layerHandler = serviceRegistry.get(VirtualLayerHandlerContribution); + layerHandler = serviceRegistry.createInstance(VirtualLayerHandlerContribution); } return layerHandler; } diff --git a/packages/vrender-core/src/core/layer.ts b/packages/vrender-core/src/core/layer.ts index 6ab6ca92c..bfcfa53d6 100644 --- a/packages/vrender-core/src/core/layer.ts +++ b/packages/vrender-core/src/core/layer.ts @@ -1,5 +1,5 @@ import type { AABBBounds, IBoundsLike } from '@visactor/vutils'; -import { application } from '../application'; +import { vglobal, layerService } from '../modules'; import type { IDrawToParams, IGraphic, @@ -138,7 +138,7 @@ export class Layer extends Group implements ILayer { } subLayers.forEach(l => { // l.layer.release(); - application.layerService.releaseLayer(this.stage, l.layer); + layerService.releaseLayer(this.stage, l.layer); }); this.subLayers.clear(); } @@ -230,7 +230,7 @@ export class Layer extends Group implements ILayer { if (this.subLayers) { this.subLayers.forEach(l => { // l.layer.release(); - application.layerService.releaseLayer(this.stage, l.layer); + layerService.releaseLayer(this.stage, l.layer); }); } } diff --git a/packages/vrender-core/src/core/stage.ts b/packages/vrender-core/src/core/stage.ts index 2b05a2af0..50567aa71 100644 --- a/packages/vrender-core/src/core/stage.ts +++ b/packages/vrender-core/src/core/stage.ts @@ -42,11 +42,11 @@ import { IncrementalAutoRenderPlugin } from '../plugins/builtin-plugin/increment import { DirtyBoundsPlugin } from '../plugins/builtin-plugin/dirty-bounds-plugin'; import { SyncHook } from '../tapable'; import { LayerService } from './constants'; -import { application } from '../application'; import { isBrowserEnv } from '../env-check'; import { Factory } from '../factory'; -import { Graphic, GraphicService } from '../graphic'; +import { GraphicService } from '../graphic'; import { serviceRegistry } from '../common/registry'; +import { VGlobal } from '../constants'; const DefaultConfig = { WIDTH: 500, @@ -241,7 +241,7 @@ export class Stage extends Group implements IStage { afterClearScreen: new SyncHook(['stage']), afterClearRect: new SyncHook(['stage']) }; - this.global = application.global; + this.global = serviceRegistry.get(VGlobal); if (!this.global.env && isBrowserEnv()) { // 如果是浏览器环境,默认设置env this.global.setEnv('browser'); diff --git a/packages/vrender-core/src/core/window.ts b/packages/vrender-core/src/core/window.ts index ec58fd3ec..55ad9d414 100644 --- a/packages/vrender-core/src/core/window.ts +++ b/packages/vrender-core/src/core/window.ts @@ -11,7 +11,8 @@ import type { IWindowParams } from '../interface'; import { SyncHook } from '../tapable'; -import { application } from '../application'; +import { vglobal } from '../modules'; +import { contributionRegistry } from '../common/registry'; import { EventListenerManager } from '../common/event-listener-manager'; export const VWindow = Symbol.for('VWindow'); @@ -76,7 +77,7 @@ export class DefaultWindow extends EventListenerManager implements IWindow { constructor() { super(); this._uid = Generator.GenAutoIncrementId(); - this.global = application.global; + this.global = vglobal; this.postInit(); } @@ -113,7 +114,7 @@ export class DefaultWindow extends EventListenerManager implements IWindow { if (!global.env || this.actived) { return; } - const contributions = application.contributions.get(WindowHandlerContribution); + const contributions = contributionRegistry.get(WindowHandlerContribution); const handler = contributions.find(c => (c as any).type === global.env) || contributions[0]; if (!handler) { throw new Error(`No WindowHandlerContribution registered for env: ${global.env}`); diff --git a/packages/vrender-core/src/env-check.ts b/packages/vrender-core/src/env-check.ts index 27cdbe405..9fe42fedc 100644 --- a/packages/vrender-core/src/env-check.ts +++ b/packages/vrender-core/src/env-check.ts @@ -1,4 +1,4 @@ -import { application } from './application'; +import { vglobal } from './modules'; let _isBrowserEnv: boolean | undefined; @@ -34,13 +34,13 @@ function initIsBrowserEnv() { export function isBrowserEnv(): boolean { initIsBrowserEnv(); - const env = application.global && application.global.env; + const env = vglobal && vglobal.env; return env ? env === 'browser' : _isBrowserEnv; } export function isNodeEnv() { initIsBrowserEnv(); - const env = application.global && application.global.env; + const env = vglobal && vglobal.env; return env ? env === 'node' : !_isBrowserEnv; } diff --git a/packages/vrender-core/src/graphic/arc.ts b/packages/vrender-core/src/graphic/arc.ts index 2e69dce91..bfb9a3fd2 100644 --- a/packages/vrender-core/src/graphic/arc.ts +++ b/packages/vrender-core/src/graphic/arc.ts @@ -5,7 +5,7 @@ import { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic' import { CustomPath2D } from '../common/custom-path2d'; import { circleBounds } from '../common/utils'; import { getTheme } from './theme'; -import { application } from '../application'; +import { vglobal, graphicService } from '../modules'; import type { GraphicType } from '../interface'; import { ARC_NUMBER_TYPE } from './constants'; import { updateBoundsOfCommonOuterBorder } from './graphic-service/common-outer-boder-bounds'; @@ -268,7 +268,7 @@ export class Arc extends Graphic implements IArc { : this.updateArcAABBBoundsAccurate(attribute, arcTheme, aabbBounds); } - const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds); + const { tb1, tb2 } = graphicService.updateTempAABBBounds(aabbBounds); updateBoundsOfCommonOuterBorder(attribute, arcTheme, tb1); aabbBounds.union(tb1); @@ -277,7 +277,7 @@ export class Arc extends Graphic implements IArc { this.setWidthHeightWithoutTransform(aabbBounds); const { lineJoin = arcTheme.lineJoin } = attribute; - application.graphicService.transformAABBBounds(attribute, aabbBounds, arcTheme, lineJoin === 'miter', this); + graphicService.transformAABBBounds(attribute, aabbBounds, arcTheme, lineJoin === 'miter', this); return aabbBounds; } diff --git a/packages/vrender-core/src/graphic/arc3d.ts b/packages/vrender-core/src/graphic/arc3d.ts index 863c7bf8d..cbb7198a7 100644 --- a/packages/vrender-core/src/graphic/arc3d.ts +++ b/packages/vrender-core/src/graphic/arc3d.ts @@ -1,7 +1,7 @@ import type { IAABBBounds } from '@visactor/vutils'; import type { GraphicType, IArc3d, IArc3dGraphicAttribute } from '../interface'; import { Arc } from './arc'; -import { application } from '../application'; +import { vglobal, graphicService } from '../modules'; import { ARC3D_NUMBER_TYPE } from './constants'; import { NOWORK_ANIMATE_ATTR } from './graphic'; @@ -57,8 +57,8 @@ export class Arc3d extends Arc implements IArc3d { // } // aabbBounds.add(x, y); // }); - application.graphicService.updateTempAABBBounds(aabbBounds); - application.graphicService.transformAABBBounds(attribute, aabbBounds, arcTheme, false, this); + graphicService.updateTempAABBBounds(aabbBounds); + graphicService.transformAABBBounds(attribute, aabbBounds, arcTheme, false, this); return aabbBounds; } diff --git a/packages/vrender-core/src/graphic/area.ts b/packages/vrender-core/src/graphic/area.ts index 391da50be..79dd3481b 100644 --- a/packages/vrender-core/src/graphic/area.ts +++ b/packages/vrender-core/src/graphic/area.ts @@ -4,7 +4,7 @@ import { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic' import { CustomPath2D } from '../common/custom-path2d'; import { pointsInterpolation } from '../common/utils'; import { getTheme } from './theme'; -import { application } from '../application'; +import { vglobal, graphicService } from '../modules'; import { AREA_NUMBER_TYPE } from './constants'; const AREA_UPDATE_TAG_KEY = ['segments', 'points', 'curveType', 'curveTension', ...GRAPHIC_UPDATE_TAG_KEY]; @@ -61,7 +61,7 @@ export class Area extends Graphic implements IArea { ? this.updateAreaAABBBoundsBySegments(attribute, areaTheme, aabbBounds) : this.updateAreaAABBBoundsByPoints(attribute, areaTheme, aabbBounds); } - application.graphicService.updateTempAABBBounds(aabbBounds); + graphicService.updateTempAABBBounds(aabbBounds); // if (!this._rectBoundsContribitions) { // this._rectBoundsContribitions = this.rectBoundsContribitions.getContributions() || []; // } @@ -75,7 +75,7 @@ export class Area extends Graphic implements IArea { this.setWidthHeightWithoutTransform(aabbBounds); const { lineJoin = areaTheme.lineJoin } = attribute; - application.graphicService.transformAABBBounds(attribute, aabbBounds, areaTheme, lineJoin === 'miter', this); + graphicService.transformAABBBounds(attribute, aabbBounds, areaTheme, lineJoin === 'miter', this); return aabbBounds; } diff --git a/packages/vrender-core/src/graphic/circle.ts b/packages/vrender-core/src/graphic/circle.ts index 1b07cd925..ae9810145 100644 --- a/packages/vrender-core/src/graphic/circle.ts +++ b/packages/vrender-core/src/graphic/circle.ts @@ -4,7 +4,7 @@ import { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic' import { CustomPath2D } from '../common/custom-path2d'; import { circleBounds } from '../common/utils'; import { getTheme } from './theme'; -import { application } from '../application'; +import { vglobal, graphicService } from '../modules'; import { CIRCLE_NUMBER_TYPE } from './constants'; import { updateBoundsOfCommonOuterBorder } from './graphic-service/common-outer-boder-bounds'; @@ -48,7 +48,7 @@ export class Circle extends Graphic implements ICircle : this.updateCircleAABBBoundsAccurate(attribute, circleTheme, aabbBounds); } - const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds); + const { tb1, tb2 } = graphicService.updateTempAABBBounds(aabbBounds); updateBoundsOfCommonOuterBorder(attribute, circleTheme, tb1); aabbBounds.union(tb1); @@ -57,7 +57,7 @@ export class Circle extends Graphic implements ICircle this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1; this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1; - application.graphicService.transformAABBBounds(attribute, aabbBounds, circleTheme, false, this); + graphicService.transformAABBBounds(attribute, aabbBounds, circleTheme, false, this); return aabbBounds; } diff --git a/packages/vrender-core/src/graphic/glyph.ts b/packages/vrender-core/src/graphic/glyph.ts index a70d567d4..ef633b79d 100644 --- a/packages/vrender-core/src/graphic/glyph.ts +++ b/packages/vrender-core/src/graphic/glyph.ts @@ -9,7 +9,7 @@ import type { ISetAttributeContext } from '../interface'; import { getTheme } from './theme'; -import { application } from '../application'; +import { vglobal } from '../modules'; import { GLYPH_NUMBER_TYPE } from './constants'; export class Glyph extends Graphic implements IGlyph { diff --git a/packages/vrender-core/src/graphic/graphic-service/graphic-service.ts b/packages/vrender-core/src/graphic/graphic-service/graphic-service.ts index f54a6ff5f..ee78a4b01 100644 --- a/packages/vrender-core/src/graphic/graphic-service/graphic-service.ts +++ b/packages/vrender-core/src/graphic/graphic-service/graphic-service.ts @@ -380,7 +380,7 @@ export class DefaultGraphicService implements IGraphicService { const { visible = theme.visible } = attribute; if (!(graphic.valid && visible)) { - // application.graphicService.beforeUpdateAABBBounds(graphic, graphic.stage, true, aabbBounds); + // graphicService.beforeUpdateAABBBounds(graphic, graphic.stage, true, aabbBounds); if (!aabbBounds.empty()) { graphic.parent && aabbBounds.transformWithMatrix((graphic.parent as IGroup).globalTransMatrix); this.clearAABBBounds(graphic, graphic.stage, aabbBounds); diff --git a/packages/vrender-core/src/graphic/graphic.ts b/packages/vrender-core/src/graphic/graphic.ts index 7283c99b4..fa8e1d4bc 100644 --- a/packages/vrender-core/src/graphic/graphic.ts +++ b/packages/vrender-core/src/graphic/graphic.ts @@ -39,7 +39,9 @@ import type { } from '../interface'; import { EventTarget, CustomEvent } from '../event'; import { DefaultTransform } from './config'; -import { application } from '../application'; +import { vglobal, graphicService, transformUtil } from '../modules'; +import { serviceRegistry } from '../common/registry'; +import { RenderService } from '../render/constants'; import { interpolateColor } from '../color-string/interpolate'; import { CustomPath2D } from '../common/custom-path2d'; import { ResourceLoader } from '../resource-loader/loader'; @@ -339,7 +341,7 @@ export abstract class Graphic = Partial = Partial = Partial = Partial = Partial = Partial = Partial = Partial implements IGroup { const { scrollX = 0, scrollY = 0 } = attribute; aabbBounds.translate(scrollX, scrollY); } - application.graphicService.updateTempAABBBounds(aabbBounds); + graphicService.updateTempAABBBounds(aabbBounds); - application.graphicService.transformAABBBounds(attribute, aabbBounds, groupTheme, false, this); + graphicService.transformAABBBounds(attribute, aabbBounds, groupTheme, false, this); originalAABBBounds.copy(aabbBounds); return originalAABBBounds; @@ -399,7 +399,7 @@ export class Group extends Graphic implements IGroup { if (graphic) { graphic.setAttributes(attributes); } else { - graphic = application.graphicService.creator[graphicType](attributes as any); + graphic = graphicService.creator[graphicType](attributes as any); graphic.name = graphicName; this.add(graphic); } diff --git a/packages/vrender-core/src/graphic/image.ts b/packages/vrender-core/src/graphic/image.ts index 6fca34ba5..01c9b3e8c 100644 --- a/packages/vrender-core/src/graphic/image.ts +++ b/packages/vrender-core/src/graphic/image.ts @@ -3,7 +3,7 @@ import type { IImage, IImageGraphicAttribute, IRepeatType, ISetAttributeContext import { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic'; import { DefaultImageAttribute } from './config'; import { getTheme } from './theme'; -import { application } from '../application'; +import { vglobal, graphicService } from '../modules'; import { IMAGE_NUMBER_TYPE } from './constants'; import { updateBoundsOfCommonOuterBorder } from './graphic-service/common-outer-boder-bounds'; @@ -174,7 +174,7 @@ export class Image extends Graphic implements IImage { aabbBounds.set(0, 0, width, height); } - const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds); + const { tb1, tb2 } = graphicService.updateTempAABBBounds(aabbBounds); updateBoundsOfCommonOuterBorder(attribute, imageTheme, tb1); aabbBounds.union(tb1); @@ -183,7 +183,7 @@ export class Image extends Graphic implements IImage { this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1; this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1; - application.graphicService.transformAABBBounds(attribute, aabbBounds, imageTheme, false, this); + graphicService.transformAABBBounds(attribute, aabbBounds, imageTheme, false, this); return aabbBounds; } diff --git a/packages/vrender-core/src/graphic/line.ts b/packages/vrender-core/src/graphic/line.ts index b69d6a2c8..7ca0c74af 100644 --- a/packages/vrender-core/src/graphic/line.ts +++ b/packages/vrender-core/src/graphic/line.ts @@ -2,7 +2,7 @@ import type { IAABBBounds, IPointLike } from '@visactor/vutils'; import type { ILine, ILineGraphicAttribute } from '../interface'; import { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic'; import { getTheme } from './theme'; -import { application } from '../application'; +import { vglobal, graphicService } from '../modules'; import { pointsInterpolation } from '../common/utils'; import { CustomPath2D } from '../common/custom-path2d'; import { LINE_NUMBER_TYPE } from './constants'; @@ -66,13 +66,13 @@ export class Line extends Graphic implements ILine { : this.updateLineAABBBoundsByPoints(attribute, lineTheme, aabbBounds); } - application.graphicService.updateTempAABBBounds(aabbBounds); + graphicService.updateTempAABBBounds(aabbBounds); this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1; this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1; const { lineJoin = lineTheme.lineJoin } = attribute; - application.graphicService.transformAABBBounds(attribute, aabbBounds, lineTheme, lineJoin === 'miter', this); + graphicService.transformAABBBounds(attribute, aabbBounds, lineTheme, lineJoin === 'miter', this); return aabbBounds; } diff --git a/packages/vrender-core/src/graphic/path.ts b/packages/vrender-core/src/graphic/path.ts index 20a352a46..84202f818 100644 --- a/packages/vrender-core/src/graphic/path.ts +++ b/packages/vrender-core/src/graphic/path.ts @@ -4,7 +4,7 @@ import { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic' import type { ICustomPath2D, IPath, IPathGraphicAttribute } from '../interface'; import { CustomPath2D } from '../common/custom-path2d'; import { getTheme } from './theme'; -import { application } from '../application'; +import { vglobal, graphicService } from '../modules'; import { PATH_NUMBER_TYPE } from './constants'; import { updateBoundsOfCommonOuterBorder } from './graphic-service/common-outer-boder-bounds'; @@ -72,7 +72,7 @@ export class Path extends Graphic implements IPath { aabbBounds.union(pathShape.getBounds()); } - const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds); + const { tb1, tb2 } = graphicService.updateTempAABBBounds(aabbBounds); updateBoundsOfCommonOuterBorder(attribute, pathTheme, tb1); aabbBounds.union(tb1); @@ -82,7 +82,7 @@ export class Path extends Graphic implements IPath { this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1; const { lineJoin = pathTheme.lineJoin } = attribute; - application.graphicService.transformAABBBounds(attribute, aabbBounds, pathTheme, lineJoin === 'miter', this); + graphicService.transformAABBBounds(attribute, aabbBounds, pathTheme, lineJoin === 'miter', this); return aabbBounds; } diff --git a/packages/vrender-core/src/graphic/polygon.ts b/packages/vrender-core/src/graphic/polygon.ts index ca75b5e78..4bac44d38 100644 --- a/packages/vrender-core/src/graphic/polygon.ts +++ b/packages/vrender-core/src/graphic/polygon.ts @@ -4,7 +4,7 @@ import type { IPolygon, IPolygonGraphicAttribute } from '../interface/graphic/po import { getTheme } from './theme'; import { pointsInterpolation } from '../common/utils'; import { CustomPath2D } from '../common/custom-path2d'; -import { application } from '../application'; +import { vglobal, graphicService } from '../modules'; import type { GraphicType } from '../interface'; import { POLYGON_NUMBER_TYPE } from './constants'; @@ -40,13 +40,13 @@ export class Polygon extends Graphic implements IPolyg if (!this.updatePathProxyAABBBounds(aabbBounds)) { this.updatePolygonAABBBoundsImprecise(attribute, polygonTheme, aabbBounds); } - application.graphicService.updateTempAABBBounds(aabbBounds); + graphicService.updateTempAABBBounds(aabbBounds); this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1; this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1; const { lineJoin = polygonTheme.lineJoin } = attribute; - application.graphicService.transformAABBBounds(attribute, aabbBounds, polygonTheme, lineJoin === 'miter', this); + graphicService.transformAABBBounds(attribute, aabbBounds, polygonTheme, lineJoin === 'miter', this); return aabbBounds; } diff --git a/packages/vrender-core/src/graphic/pyramid3d.ts b/packages/vrender-core/src/graphic/pyramid3d.ts index 4f9830267..9949a7275 100644 --- a/packages/vrender-core/src/graphic/pyramid3d.ts +++ b/packages/vrender-core/src/graphic/pyramid3d.ts @@ -2,7 +2,7 @@ import type { IAABBBounds, IPointLike } from '@visactor/vutils'; import { max, PointService } from '@visactor/vutils'; import type { GraphicType, IPyramid3d, IPyramid3dGraphicAttribute } from '../interface'; import type { IFace3d } from '../interface/graphic/face3d'; -import { application } from '../application'; +import { vglobal, graphicService } from '../modules'; import { Polygon } from './polygon'; import { PYRAMID3D_NUMBER_TYPE } from './constants'; import { NOWORK_ANIMATE_ATTR } from './graphic'; @@ -35,8 +35,8 @@ export class Pyramid3d extends Polygon implements IPyramid3d { const y = v[1]; aabbBounds.add(x, y); }); - application.graphicService.updateTempAABBBounds(aabbBounds); - application.graphicService.transformAABBBounds(attribute, aabbBounds, polygonTheme, false, this); + graphicService.updateTempAABBBounds(aabbBounds); + graphicService.transformAABBBounds(attribute, aabbBounds, polygonTheme, false, this); return aabbBounds; } diff --git a/packages/vrender-core/src/graphic/rect.ts b/packages/vrender-core/src/graphic/rect.ts index b586a79d1..db7da2834 100644 --- a/packages/vrender-core/src/graphic/rect.ts +++ b/packages/vrender-core/src/graphic/rect.ts @@ -3,7 +3,7 @@ import { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic' import type { GraphicType, ICustomPath2D, IRect, IRectGraphicAttribute } from '../interface'; import { CustomPath2D } from '../common/custom-path2d'; import { getTheme } from './theme'; -import { application } from '../application'; +import { vglobal, graphicService } from '../modules'; import { RECT_NUMBER_TYPE } from './constants'; import { normalizeRectAttributes } from '../common/rect-utils'; import { updateBoundsOfCommonOuterBorder } from './graphic-service/common-outer-boder-bounds'; @@ -50,7 +50,7 @@ export class Rect extends Graphic implements IRect { } } - const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds); + const { tb1, tb2 } = graphicService.updateTempAABBBounds(aabbBounds); updateBoundsOfCommonOuterBorder(attribute, rectTheme, tb1); aabbBounds.union(tb1); @@ -59,7 +59,7 @@ export class Rect extends Graphic implements IRect { this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1; this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1; - application.graphicService.transformAABBBounds(attribute, aabbBounds, rectTheme, false, this); + graphicService.transformAABBBounds(attribute, aabbBounds, rectTheme, false, this); return aabbBounds; } diff --git a/packages/vrender-core/src/graphic/richtext.ts b/packages/vrender-core/src/graphic/richtext.ts index 7cc11baf0..53a0d65e5 100644 --- a/packages/vrender-core/src/graphic/richtext.ts +++ b/packages/vrender-core/src/graphic/richtext.ts @@ -25,7 +25,7 @@ import Wrapper from './richtext/wrapper'; import { getTheme } from './theme'; import { RichTextIcon } from './richtext/icon'; import type { FederatedMouseEvent } from '../event'; -import { application } from '../application'; +import { vglobal, graphicService } from '../modules'; import { RICHTEXT_NUMBER_TYPE } from './constants'; let supportIntl = false; @@ -319,15 +319,15 @@ export class RichText extends Graphic implements IRic } aabbBounds.translate(deltaX, deltaY); - application.graphicService.updateTempAABBBounds(aabbBounds); + graphicService.updateTempAABBBounds(aabbBounds); if (attribute.forceBoundsHeight != null || attribute.forceBoundsWidth != null) { - application.graphicService.updateHTMLTextAABBBounds(attribute, richtextTheme, aabbBounds); + graphicService.updateHTMLTextAABBBounds(attribute, richtextTheme, aabbBounds); } this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1; this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1; - application.graphicService.transformAABBBounds(attribute, aabbBounds, richtextTheme, false, this); + graphicService.transformAABBBounds(attribute, aabbBounds, richtextTheme, false, this); // 都为0的话,就直接clear if (aabbBounds.width() === 0 && aabbBounds.height() === 0) { aabbBounds.clear(); diff --git a/packages/vrender-core/src/graphic/richtext/utils.ts b/packages/vrender-core/src/graphic/richtext/utils.ts index f01fca5b7..58e0845a7 100644 --- a/packages/vrender-core/src/graphic/richtext/utils.ts +++ b/packages/vrender-core/src/graphic/richtext/utils.ts @@ -1,5 +1,5 @@ import type { IBoundsLike } from '@visactor/vutils'; -import { application } from '../../application'; +import { vglobal, graphicUtil } from '../../modules'; import { createColor } from '../../common/canvas-utils'; import type { IContext2d, ITextStyleParams, IRichTextParagraphCharacter } from '../../interface'; import { DEFAULT_TEXT_FONT_FAMILY } from '../../constants'; @@ -167,7 +167,7 @@ export function getStrByWithCanvas( if (!width || width <= 0) { return 0; } - const textMeasure = application.graphicUtil.textMeasure; + const textMeasure = graphicUtil.textMeasure; // const measurement = textMeasure.measureText(text, character); // 测量从头到当前位置宽度以及从头到下一个字符位置宽度 @@ -355,7 +355,7 @@ export function measureTextCanvas( width: 0 }; } - const textMeasure = application.graphicUtil.textMeasure; + const textMeasure = graphicUtil.textMeasure; const measurement = textMeasure.measureText(text, character as any) as TextMetrics; const result: { ascent: number; height: number; descent: number; width: number } = { ascent: 0, diff --git a/packages/vrender-core/src/graphic/star.ts b/packages/vrender-core/src/graphic/star.ts index 7bfdbefad..0cbeba565 100644 --- a/packages/vrender-core/src/graphic/star.ts +++ b/packages/vrender-core/src/graphic/star.ts @@ -2,7 +2,7 @@ import type { IAABBBounds, IPointLike } from '@visactor/vutils'; import { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic'; import type { IStar, IStarGraphicAttribute } from '../interface/graphic/star'; import { getTheme } from './theme'; -import { application } from '../application'; +import { vglobal, graphicService } from '../modules'; import type { GraphicType } from '../interface'; import { CustomPath2D } from '../common/custom-path2d'; import { STAR_NUMBER_TYPE } from './constants'; @@ -50,7 +50,7 @@ export class Star extends Graphic implements IStar { } } - const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds); + const { tb1, tb2 } = graphicService.updateTempAABBBounds(aabbBounds); aabbBounds.union(tb1); tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2); @@ -58,7 +58,7 @@ export class Star extends Graphic implements IStar { this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1; this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1; - application.graphicService.transformAABBBounds(attribute, aabbBounds, rectTheme, false, this); + graphicService.transformAABBBounds(attribute, aabbBounds, rectTheme, false, this); return aabbBounds; } diff --git a/packages/vrender-core/src/graphic/symbol.ts b/packages/vrender-core/src/graphic/symbol.ts index 99433b694..01aab6a3c 100644 --- a/packages/vrender-core/src/graphic/symbol.ts +++ b/packages/vrender-core/src/graphic/symbol.ts @@ -3,7 +3,7 @@ import { isArray } from '@visactor/vutils'; import type { ISymbol, ISymbolClass, ISymbolGraphicAttribute } from '../interface'; import { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic'; import { getTheme } from './theme'; -import { application } from '../application'; +import { vglobal, graphicService } from '../modules'; import { CustomPath2D } from '../common/custom-path2d'; import { SYMBOL_NUMBER_TYPE } from './constants'; import { updateBoundsOfSymbolOuterBorder } from './graphic-service/symbol-outer-border-bounds'; @@ -79,7 +79,7 @@ export class Symbol extends Graphic implements ISymbol : this.updateSymbolAABBBoundsAccurate(attribute, symbolTheme, aabbBounds); } - const { tb1, tb2 } = application.graphicService.updateTempAABBBounds(aabbBounds); + const { tb1, tb2 } = graphicService.updateTempAABBBounds(aabbBounds); updateBoundsOfSymbolOuterBorder(attribute, symbolTheme, tb1); aabbBounds.union(tb1); @@ -91,7 +91,7 @@ export class Symbol extends Graphic implements ISymbol this.y1WithoutTransform = aabbBounds.y1; const { lineJoin = symbolTheme.lineJoin } = attribute; - application.graphicService.transformAABBBounds(attribute, aabbBounds, symbolTheme, lineJoin === 'miter', this); + graphicService.transformAABBBounds(attribute, aabbBounds, symbolTheme, lineJoin === 'miter', this); return aabbBounds; } diff --git a/packages/vrender-core/src/graphic/text.ts b/packages/vrender-core/src/graphic/text.ts index fc7afe336..955a9a876 100644 --- a/packages/vrender-core/src/graphic/text.ts +++ b/packages/vrender-core/src/graphic/text.ts @@ -2,7 +2,7 @@ import type { IAABBBounds, IOBBBounds } from '@visactor/vutils'; import { max, isArray, getContextFont, transformBoundsWithMatrix, rotatePoint } from '@visactor/vutils'; import { textDrawOffsetX, textLayoutOffsetY } from '../common/text'; import { CanvasTextLayout } from '../core/contributions/textMeasure/layout'; -import { application } from '../application'; +import { vglobal, graphicService, graphicUtil } from '../modules'; import type { IText, ITextCache, ITextGraphicAttribute, LayoutItemType, LayoutType } from '../interface'; import { Graphic, GRAPHIC_UPDATE_TAG_KEY, NOWORK_ANIMATE_ATTR } from './graphic'; import { getTheme } from './theme'; @@ -181,7 +181,7 @@ export class Text extends Graphic implements IText { this.updateSingallineAABBBounds(text as number | string); } - const { tb1 } = application.graphicService.updateTempAABBBounds(aabbBounds); + const { tb1 } = graphicService.updateTempAABBBounds(aabbBounds); const { scaleX = textTheme.scaleX, @@ -195,10 +195,10 @@ export class Text extends Graphic implements IText { aabbBounds.union(tb1); } // 合并shadowRoot的bounds - application.graphicService.combindShadowAABBBounds(aabbBounds, this); + graphicService.combindShadowAABBBounds(aabbBounds, this); if (attribute.forceBoundsHeight != null || attribute.forceBoundsWidth != null) { - application.graphicService.updateHTMLTextAABBBounds(attribute, textTheme, aabbBounds); + graphicService.updateHTMLTextAABBBounds(attribute, textTheme, aabbBounds); } this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1; @@ -288,7 +288,7 @@ export class Text extends Graphic implements IText { } return this._AABBBounds; } - const textMeasure = application.graphicUtil.getTextMeasureInstance(this.textMeasureId || this.stage?.textMeasureId); + const textMeasure = graphicUtil.getTextMeasureInstance(this.textMeasureId || this.stage?.textMeasureId); const layoutObj = new CanvasTextLayout(fontFamily, { fontSize, fontWeight, fontFamily, lineHeight }, textMeasure); const layoutData = layoutObj.GetLayoutByLines( text, @@ -356,7 +356,7 @@ export class Text extends Graphic implements IText { return this._AABBBounds; } - const textMeasure = application.graphicUtil.getTextMeasureInstance(this.textMeasureId || this.stage?.textMeasureId); + const textMeasure = graphicUtil.getTextMeasureInstance(this.textMeasureId || this.stage?.textMeasureId); const textOptions = { fontSize, fontWeight, fontFamily, lineHeight }; const layoutObj = new CanvasTextLayout(fontFamily, textOptions, textMeasure as any); @@ -529,7 +529,7 @@ export class Text extends Graphic implements IText { */ updateVerticalMultilineAABBBounds(text: (number | string)[]): IAABBBounds { const textTheme = this.getGraphicTheme(); - const textMeasure = application.graphicUtil.getTextMeasureInstance(this.textMeasureId || this.stage?.textMeasureId); + const textMeasure = graphicUtil.getTextMeasureInstance(this.textMeasureId || this.stage?.textMeasureId); let width: number; const attribute = this.attribute; const { diff --git a/packages/vrender-core/src/graphic/tools.ts b/packages/vrender-core/src/graphic/tools.ts index 1811fa23a..be8c2f5c9 100644 --- a/packages/vrender-core/src/graphic/tools.ts +++ b/packages/vrender-core/src/graphic/tools.ts @@ -1,4 +1,4 @@ -import { application } from '../application'; +import { vglobal } from '../modules'; import { isXML } from '../common/xml/parser'; import type { IGraphic, IGroup, ILayer, IRichTextCharacter, IRichTextImageCharacter, IStage } from '../interface'; import { isArray, type IAABBBounds } from '@visactor/vutils'; @@ -16,7 +16,7 @@ export async function waitForAllSubLayers(stage: IStage) { const promiseList: Promise[] = []; const layers = stage.getChildren() as ILayer[]; await new Promise(resolve => { - application.global.getRequestAnimationFrame()(() => { + vglobal.getRequestAnimationFrame()(() => { resolve(null); }); }); diff --git a/packages/vrender-core/src/graphic/wrap-text.ts b/packages/vrender-core/src/graphic/wrap-text.ts index cb078f832..624bb9f0c 100644 --- a/packages/vrender-core/src/graphic/wrap-text.ts +++ b/packages/vrender-core/src/graphic/wrap-text.ts @@ -1,7 +1,7 @@ import { isArray } from '@visactor/vutils'; import { CanvasTextLayout } from '../core/contributions/textMeasure/layout'; import type { IText, ITextGraphicAttribute, IWrapTextGraphicAttribute, LayoutItemType } from '../interface'; -import { application } from '../application'; +import { vglobal, graphicUtil } from '../modules'; import { Text } from './text'; import { getTheme } from './theme'; import { calculateLineHeight } from '../common/utils'; @@ -65,7 +65,7 @@ export class WrapText extends Text { return this._AABBBounds; } - const textMeasure = application.graphicUtil.getTextMeasureInstance(this.textMeasureId || this.stage?.textMeasureId); + const textMeasure = graphicUtil.getTextMeasureInstance(this.textMeasureId || this.stage?.textMeasureId); const layoutObj = new CanvasTextLayout(fontFamily, { fontSize, fontWeight, fontFamily }, textMeasure as any) as any; // layoutObj内逻辑 diff --git a/packages/vrender-core/src/index.ts b/packages/vrender-core/src/index.ts index 75bbb79f1..001f3bbc1 100644 --- a/packages/vrender-core/src/index.ts +++ b/packages/vrender-core/src/index.ts @@ -1,5 +1,8 @@ // import 'core-js/proposals/reflect-metadata'; +// 必须在所有其他导出之前加载,确保服务注册表被初始化 +import './modules'; + export * from './core/global'; export * from './graphic'; export * from './create'; @@ -53,8 +56,9 @@ export * from './allocator/graphic-allocate'; export { wrapCanvas, wrapContext } from './canvas/util'; export * from './common/xml'; export * from './constants'; -export * from './application'; export * from './env-check'; +export * from './common/registry'; // 导出 registry +export { vglobal, graphicService, graphicUtil, transformUtil, layerService } from './modules'; // 导出全局服务 export * from './register/register-arc'; export * from './register/register-arc3d'; diff --git a/packages/vrender-core/src/interface/canvas.ts b/packages/vrender-core/src/interface/canvas.ts index 2516a828f..017f40985 100644 --- a/packages/vrender-core/src/interface/canvas.ts +++ b/packages/vrender-core/src/interface/canvas.ts @@ -12,7 +12,7 @@ export type CanvasConfigType = { y?: number; container?: HTMLElement | string; visiable?: boolean; - nativeCanvas: HTMLCanvasElement | any; + nativeCanvas?: HTMLCanvasElement | any; canvasControled?: boolean; id?: string; }; diff --git a/packages/vrender-core/src/modules.ts b/packages/vrender-core/src/modules.ts index ce0b4cef7..3254a52d1 100644 --- a/packages/vrender-core/src/modules.ts +++ b/packages/vrender-core/src/modules.ts @@ -3,7 +3,6 @@ */ import { LayerService } from './core/constants'; import type { IGlobal, IGraphicService } from './interface'; -import { application } from './application'; import type { IGraphicUtil, ILayerService, ITransformUtil } from './interface/core'; import { GraphicService } from './graphic/constants'; import { GraphicUtil, TransformUtil } from './core/constants'; @@ -25,18 +24,9 @@ preLoadAllModule.__loaded = false; preLoadAllModule(); -// 全局变量 - 从 serviceRegistry 获取 +// 全局变量 - 从 serviceRegistry 获取(替代 application) export const vglobal = serviceRegistry.get(VGlobal); -application.global = vglobal; - export const graphicUtil = serviceRegistry.get(GraphicUtil); -application.graphicUtil = graphicUtil; - export const transformUtil = serviceRegistry.get(TransformUtil); -application.transformUtil = transformUtil; - export const graphicService = serviceRegistry.get(GraphicService); -application.graphicService = graphicService; - export const layerService = serviceRegistry.get(LayerService); -application.layerService = layerService; diff --git a/packages/vrender-core/src/picker/global-picker-service.ts b/packages/vrender-core/src/picker/global-picker-service.ts index 3c78c589e..67cc6b89e 100644 --- a/packages/vrender-core/src/picker/global-picker-service.ts +++ b/packages/vrender-core/src/picker/global-picker-service.ts @@ -10,7 +10,7 @@ import type { IPickParams, PickResult } from '../interface'; -import { application } from '../application'; +import { vglobal } from '../modules'; // 默认的pick-service,提供基本的最优选中策略,尽量不需要用户自己实现contribution // 用户可以写plugin @@ -21,7 +21,7 @@ export class DefaultGlobalPickerService implements IPickerService { declare global: IGlobal; constructor() { - this.global = application.global; + this.global = vglobal; this.global.hooks.onSetEnv.tap('global-picker-service', (lastEnv, env, global) => { this.configure(global, env); }); diff --git a/packages/vrender-core/src/picker/picker-service.ts b/packages/vrender-core/src/picker/picker-service.ts index 77004304e..2bb4776a4 100644 --- a/packages/vrender-core/src/picker/picker-service.ts +++ b/packages/vrender-core/src/picker/picker-service.ts @@ -19,7 +19,7 @@ import { getTheme } from '../graphic/theme'; import { DefaultAttribute } from '../graphic/config'; import { mat3Tomat4, multiplyMat4Mat4 } from '../common/matrix'; import { mat4Allocate, matrixAllocate } from '../allocator/matrix-allocate'; -import { application } from '../application'; +import { vglobal } from '../modules'; import { PickItemInterceptor, PickServiceInterceptor } from './constants'; import { contributionRegistry } from '../common/registry'; @@ -48,7 +48,7 @@ export abstract class DefaultPickService implements IPickerService { ({ getContributions: () => contributionRegistry.get(PickServiceInterceptor) } as IContributionProvider); - this.global = application.global; + this.global = vglobal; } reInit() { diff --git a/packages/vrender-core/src/plugins/builtin-plugin/auto-refresh-plugin.ts b/packages/vrender-core/src/plugins/builtin-plugin/auto-refresh-plugin.ts index 0821b46ef..1b57aabdf 100644 --- a/packages/vrender-core/src/plugins/builtin-plugin/auto-refresh-plugin.ts +++ b/packages/vrender-core/src/plugins/builtin-plugin/auto-refresh-plugin.ts @@ -1,5 +1,5 @@ import { Generator } from '../../common/generator'; -import { application } from '../../application'; +import { vglobal } from '../../modules'; import type { IGraphic, IPlugin, IPluginService } from '../../interface'; export class AutoRefreshPlugin implements IPlugin { @@ -23,7 +23,7 @@ export class AutoRefreshPlugin implements IPlugin { activate(context: IPluginService): void { this.pluginService = context; - this.dpr = application.global.devicePixelRatio; + this.dpr = vglobal.devicePixelRatio; this.refresh(); } @@ -33,10 +33,10 @@ export class AutoRefreshPlugin implements IPlugin { } } protected _refreshByRaf() { - const raf = application.global.getRequestAnimationFrame(); + const raf = vglobal.getRequestAnimationFrame(); this.rafId = raf(() => { - if (application.global.devicePixelRatio !== this.dpr) { - this.dpr = application.global.devicePixelRatio; + if (vglobal.devicePixelRatio !== this.dpr) { + this.dpr = vglobal.devicePixelRatio; this.pluginService.stage.setDpr(this.dpr, true); } this.refresh(); @@ -66,7 +66,7 @@ export class AutoRefreshPlugin implements IPlugin { return true; } deactivate(context: IPluginService): void { - const craf = application.global.getCancelAnimationFrame(); + const craf = vglobal.getCancelAnimationFrame(); craf && this.rafId && craf(this.rafId); this.autoRefreshCbs?.forEach(cb => { cb(); diff --git a/packages/vrender-core/src/plugins/builtin-plugin/auto-render-plugin.ts b/packages/vrender-core/src/plugins/builtin-plugin/auto-render-plugin.ts index 758d5854d..493e5e96c 100644 --- a/packages/vrender-core/src/plugins/builtin-plugin/auto-render-plugin.ts +++ b/packages/vrender-core/src/plugins/builtin-plugin/auto-render-plugin.ts @@ -1,5 +1,5 @@ import { Generator } from '../../common/generator'; -import { application } from '../../application'; +import { vglobal } from '../../modules'; import type { FullTap, IGraphic, IPlugin, IPluginService } from '../../interface'; export class AutoRenderPlugin implements IPlugin { diff --git a/packages/vrender-core/src/plugins/builtin-plugin/dirty-bounds-plugin.ts b/packages/vrender-core/src/plugins/builtin-plugin/dirty-bounds-plugin.ts index cec9c9226..a09b856fe 100644 --- a/packages/vrender-core/src/plugins/builtin-plugin/dirty-bounds-plugin.ts +++ b/packages/vrender-core/src/plugins/builtin-plugin/dirty-bounds-plugin.ts @@ -2,7 +2,7 @@ import type { IAABBBounds } from '@visactor/vutils'; import { AABBBounds } from '@visactor/vutils'; import { Generator } from '../../common/generator'; import type { IGraphic, IStage, IPlugin, IPluginService } from '../../interface'; -import { application } from '../../application'; +import { vglobal } from '../../modules'; const globalBounds = new AABBBounds(); diff --git a/packages/vrender-core/src/plugins/builtin-plugin/edit-module.ts b/packages/vrender-core/src/plugins/builtin-plugin/edit-module.ts index 6e230027e..a765ea9ee 100644 --- a/packages/vrender-core/src/plugins/builtin-plugin/edit-module.ts +++ b/packages/vrender-core/src/plugins/builtin-plugin/edit-module.ts @@ -1,4 +1,4 @@ -import { application } from '../../application'; +import { vglobal } from '../../modules'; import type { IRichText, IRichTextCharacter, @@ -196,7 +196,7 @@ export class EditModule { // 监听焦点 textAreaDom.addEventListener('focusin', this.handleFocusIn); textAreaDom.addEventListener('focusout', this.handleFocusOut); - application.global.addEventListener('keydown', this.handleKeyDown); + vglobal.addEventListener('keydown', this.handleKeyDown); } handleFocusIn = () => { @@ -422,7 +422,7 @@ export class EditModule { this.textAreaDom.removeEventListener('compositionend', this.handleCompositionEnd); this.textAreaDom.removeEventListener('focusin', this.handleFocusOut); this.textAreaDom.removeEventListener('focusout', this.handleFocusOut); - application.global.removeEventListener('keydown', this.handleKeyDown); + vglobal.removeEventListener('keydown', this.handleKeyDown); this.textAreaDom.parentElement?.removeChild(this.textAreaDom); this.textAreaDom = null; diff --git a/packages/vrender-core/src/plugins/builtin-plugin/flex-layout-plugin.ts b/packages/vrender-core/src/plugins/builtin-plugin/flex-layout-plugin.ts index 752281ea7..7df3738f5 100644 --- a/packages/vrender-core/src/plugins/builtin-plugin/flex-layout-plugin.ts +++ b/packages/vrender-core/src/plugins/builtin-plugin/flex-layout-plugin.ts @@ -4,7 +4,7 @@ import type { IPlugin, IPluginService } from '../../interface'; import { Generator } from '../../common/generator'; import type { IAABBBounds } from '@visactor/vutils'; import { AABBBounds } from '@visactor/vutils'; -import { application } from '../../application'; +import { vglobal } from '../../modules'; import { Factory } from '../../factory'; const _tempBounds = new AABBBounds(); diff --git a/packages/vrender-core/src/plugins/builtin-plugin/html-attribute-plugin.ts b/packages/vrender-core/src/plugins/builtin-plugin/html-attribute-plugin.ts index d0104d318..06e857ad3 100644 --- a/packages/vrender-core/src/plugins/builtin-plugin/html-attribute-plugin.ts +++ b/packages/vrender-core/src/plugins/builtin-plugin/html-attribute-plugin.ts @@ -12,7 +12,7 @@ import type { IText, ILayer } from '../../interface'; -import { application } from '../../application'; +import { vglobal } from '../../modules'; import { getTheme } from '../../graphic/theme'; import { DefaultAttribute } from '../../graphic/config'; import { textAttributesToStyle } from '../../common/text'; @@ -52,8 +52,8 @@ export class HtmlAttributePlugin implements IPlugin { context.stage.hooks.afterRender.taps = context.stage.hooks.afterRender.taps.filter(item => { return item.name !== this.key; }); - // application.graphicService.hooks.onRemove.unTap(this.key); - // application.graphicService.hooks.onRelease.unTap(this.key); + // graphicService.hooks.onRemove.unTap(this.key); + // graphicService.hooks.onRelease.unTap(this.key); this.release(); } @@ -61,7 +61,7 @@ export class HtmlAttributePlugin implements IPlugin { let nativeContainer; if (userContainer) { if (typeof userContainer === 'string') { - nativeContainer = application.global.getElementById(userContainer); + nativeContainer = vglobal.getElementById(userContainer); } else { nativeContainer = userContainer; } @@ -70,7 +70,7 @@ export class HtmlAttributePlugin implements IPlugin { } // 创建wrapGroup return { - wrapContainer: application.global.createDom({ tagName: 'div', parent: nativeContainer, ...domParams }), + wrapContainer: vglobal.createDom({ tagName: 'div', parent: nativeContainer, ...domParams }), nativeContainer }; } @@ -184,8 +184,8 @@ export class HtmlAttributePlugin implements IPlugin { } // 查看wrapGroup的位置 - // const wrapGroupTL = application.global.getElementTopLeft(wrapGroup, false); - const containerTL = application.global.getElementTopLeft(nativeContainer, false); + // const wrapGroupTL = vglobal.getElementTopLeft(wrapGroup, false); + const containerTL = vglobal.getElementTopLeft(nativeContainer, false); const windowTL = stage.window.getTopLeft(false); const viewBox = stage.viewBox; const offsetX = left + windowTL.left - containerTL.left + viewBox.x1; @@ -218,7 +218,7 @@ export class HtmlAttributePlugin implements IPlugin { } // 更新样式 - application.global.updateDom(wrapContainer, { + vglobal.updateDom(wrapContainer, { width: options.width, height: options.height, style: calculateStyle @@ -238,7 +238,7 @@ export class HtmlAttributePlugin implements IPlugin { } protected drawHTML(layers: ILayer[]) { - if (application.global.env === 'browser') { + if (vglobal.env === 'browser') { layers .sort((a, b) => { return (a.attribute.zIndex ?? DefaultAttribute.zIndex) - (b.attribute.zIndex ?? DefaultAttribute.zIndex); @@ -269,7 +269,7 @@ export class HtmlAttributePlugin implements IPlugin { const { wrapContainer } = this.htmlMap[id]; if (wrapContainer) { - application.global.removeDom(wrapContainer); + vglobal.removeDom(wrapContainer); } this.htmlMap[id] = null; @@ -339,7 +339,7 @@ export class HtmlAttributePlugin implements IPlugin { } release() { - if (application.global.env === 'browser') { + if (vglobal.env === 'browser') { this.removeAllDom(this.pluginService.stage.defaultLayer); } } diff --git a/packages/vrender-core/src/plugins/builtin-plugin/incremental-auto-render-plugin.ts b/packages/vrender-core/src/plugins/builtin-plugin/incremental-auto-render-plugin.ts index 598569818..1a75e4555 100644 --- a/packages/vrender-core/src/plugins/builtin-plugin/incremental-auto-render-plugin.ts +++ b/packages/vrender-core/src/plugins/builtin-plugin/incremental-auto-render-plugin.ts @@ -1,5 +1,5 @@ import type { IGroup, IPlugin, IPluginService, IDrawContext } from '../../interface'; -import { application } from '../../application'; +import { vglobal } from '../../modules'; import { Generator } from '../../common/generator'; export class IncrementalAutoRenderPlugin implements IPlugin { @@ -54,7 +54,7 @@ export class IncrementalAutoRenderPlugin implements IPlugin { this.nextFrameRenderGroupSet.add(group); if (!this.willNextFrameRender) { this.willNextFrameRender = true; - application.global.getRequestAnimationFrame()(() => { + vglobal.getRequestAnimationFrame()(() => { this._doRenderInThisFrame(); this.willNextFrameRender = false; }); diff --git a/packages/vrender-core/src/plugins/builtin-plugin/react-attribute-plugin.ts b/packages/vrender-core/src/plugins/builtin-plugin/react-attribute-plugin.ts index a57b312ed..8b2abfece 100644 --- a/packages/vrender-core/src/plugins/builtin-plugin/react-attribute-plugin.ts +++ b/packages/vrender-core/src/plugins/builtin-plugin/react-attribute-plugin.ts @@ -1,6 +1,6 @@ import { Generator } from '../../common/generator'; import type { IGraphic, IPlugin, IPluginService } from '../../interface'; -import { application } from '../../application'; +import { vglobal } from '../../modules'; import { HtmlAttributePlugin } from './html-attribute-plugin'; import { isNil } from '@visactor/vutils'; import { Factory } from '../../factory'; @@ -32,7 +32,7 @@ export class ReactAttributePlugin extends HtmlAttributePlugin implements IPlugin const { root, wrapContainer, unmount } = this.htmlMap[id]; if (root) { - const raf = application.global.getRequestAnimationFrame(); + const raf = vglobal.getRequestAnimationFrame(); raf(() => { root.unmount(); }); @@ -40,7 +40,7 @@ export class ReactAttributePlugin extends HtmlAttributePlugin implements IPlugin unmount(); } - wrapContainer && application.global.removeDom(wrapContainer); + wrapContainer && vglobal.removeDom(wrapContainer); this.htmlMap[id] = null; } diff --git a/packages/vrender-core/src/plugins/builtin-plugin/richtext-edit-plugin.ts b/packages/vrender-core/src/plugins/builtin-plugin/richtext-edit-plugin.ts index a1633805a..58535b56d 100644 --- a/packages/vrender-core/src/plugins/builtin-plugin/richtext-edit-plugin.ts +++ b/packages/vrender-core/src/plugins/builtin-plugin/richtext-edit-plugin.ts @@ -29,7 +29,7 @@ import type { ITimeline } from '../../interface'; import { EditModule, findConfigIndexByCursorIdx, getDefaultCharacterConfig } from './edit-module'; -import { application } from '../../application'; +import { vglobal } from '../../modules'; import { getWordStartEndIdx } from '../../graphic/richtext/utils'; // import { testLetter, testLetter2 } from '../../graphic/richtext/utils'; @@ -117,7 +117,7 @@ class Selection { } for (let i = Math.ceil(minCursorIdx); i <= Math.floor(maxCursorIdx); i++) { const val = supportOutAttr - ? (this._getFormat(key, i) ?? (this.rt?.attribute as any)[key]) + ? this._getFormat(key, i) ?? (this.rt?.attribute as any)[key] : this._getFormat(key, i); val && valSet.add(val); } @@ -166,8 +166,8 @@ export class RichTextEditPlugin implements IPlugin { protected updateCbs: Array<(type: UpdateType, p: RichTextEditPlugin, params?: any) => void>; // 富文本外部有align或者baseline的时候,需要对光标做偏移 - declare protected deltaX: number; - declare protected deltaY: number; + protected declare deltaX: number; + protected declare deltaY: number; // static splitText(text: string) { // // 😁这种emoji长度算两个,所以得处理一下 @@ -303,7 +303,7 @@ export class RichTextEditPlugin implements IPlugin { context.stage.on('pointerup', this.handlePointerUp, { capture: true }); context.stage.on('pointerleave', this.handlePointerUp, { capture: true }); context.stage.on('dblclick', this.handleDBLClick, { capture: true }); - application.global.addEventListener('keydown', this.handleKeyDown); + vglobal.addEventListener('keydown', this.handleKeyDown); this.editModule.onInput(this.handleInput); this.editModule.onChange(this.handleChange); @@ -314,13 +314,10 @@ export class RichTextEditPlugin implements IPlugin { } copyToClipboard(e: KeyboardEvent): boolean { - if ( - (application.global.isMacOS() && e.metaKey && e.key === 'c') || - (!application.global.isMacOS() && e.ctrlKey && e.key === 'c') - ) { + if ((vglobal.isMacOS() && e.metaKey && e.key === 'c') || (!vglobal.isMacOS() && e.ctrlKey && e.key === 'c')) { const selection = this.getSelection(); const text = selection.getSelectionPureText(); - application.global.copyToClipBoard(text); + vglobal.copyToClipBoard(text); e.preventDefault(); return true; } @@ -383,10 +380,7 @@ export class RichTextEditPlugin implements IPlugin { } protected fullSelectionKeyHandler(e: KeyboardEvent) { - if ( - (application.global.isMacOS() && e.metaKey && e.key === 'a') || - (!application.global.isMacOS() && e.ctrlKey && e.key === 'a') - ) { + if ((vglobal.isMacOS() && e.metaKey && e.key === 'a') || (!vglobal.isMacOS() && e.ctrlKey && e.key === 'a')) { this.fullSelection(); e.preventDefault(); return true; @@ -693,7 +687,7 @@ export class RichTextEditPlugin implements IPlugin { context.stage.off('pointerleave', this.handlePointerUp, { capture: true }); context.stage.off('dblclick', this.handleDBLClick, { capture: true }); - application.global.addEventListener('keydown', this.handleKeyDown); + vglobal.addEventListener('keydown', this.handleKeyDown); } handleMove = (e: PointerEvent) => { diff --git a/packages/vrender-core/src/register-modules.ts b/packages/vrender-core/src/register-modules.ts index 341f9f408..b4f2e9297 100644 --- a/packages/vrender-core/src/register-modules.ts +++ b/packages/vrender-core/src/register-modules.ts @@ -3,46 +3,88 @@ * * 这个文件将所有服务注册到 serviceRegistry 和 contributionRegistry */ -declare let require: any; import { serviceRegistry, contributionRegistry } from './common/registry'; -import { VGlobal, EnvContribution } from './constants'; -import { GraphicUtil, LayerService, TransformUtil } from './core/constants'; -import { VWindow } from './core/window'; +import { VGlobal } from './constants'; +import { + GraphicUtil, + LayerService, + TransformUtil, + StaticLayerHandlerContribution, + DynamicLayerHandlerContribution, + VirtualLayerHandlerContribution +} from './core/constants'; +import { DefaultWindow, VWindow } from './core/window'; import { GraphicService, GraphicCreator } from './graphic/constants'; import { RenderService } from './render/constants'; +import type { IDrawContribution } from './interface/render'; import { DrawContribution, GraphicRender, IncrementalDrawContribution, GroupRender } from './render/contributions/render/symbol'; -import { DrawItemInterceptor } from './render/contributions/render/draw-interceptor'; +import { + CommonDrawItemInterceptorContribution, + DrawItemInterceptor +} from './render/contributions/render/draw-interceptor'; import { PickerService, GlobalPickerService, PickItemInterceptor, PickServiceInterceptor } from './picker/constants'; -import { PluginService, AutoEnablePlugins } from './plugins/constants'; +import { PluginService } from './plugins/constants'; +import { DefaultGlobal } from './core/global'; +import { DefaultGraphicUtil, DefaultTransformUtil } from './core/graphic-utils'; +import { DefaultLayerService } from './core/layer-service'; +import { DefaultGraphicService } from './graphic/graphic-service/graphic-service'; +import { graphicCreator } from './graphic/graphic-creator'; +import { DefaultDrawContribution } from './render/contributions/render/draw-contribution'; +import { DefaultIncrementalDrawContribution } from './render/contributions/render/incremental-draw-contribution'; +import { DefaultRenderService } from './render/render-service'; +import { DefaultCanvasGroupRender } from './render/contributions/render/group-render'; +import { DefaultCanvasRectRender } from './render/contributions/render/rect-render'; +import { DefaultCanvasArcRender } from './render/contributions/render/arc-render'; +import { DefaultCanvasCircleRender } from './render/contributions/render/circle-render'; +import { DefaultCanvasLineRender } from './render/contributions/render/line-render'; +import { DefaultCanvasAreaRender } from './render/contributions/render/area-render'; +import { DefaultCanvasPathRender } from './render/contributions/render/path-render'; +import { DefaultCanvasTextRender } from './render/contributions/render/text-render'; +import { DefaultCanvasSymbolRender } from './render/contributions/render/symbol-render'; +import { DefaultCanvasPolygonRender } from './render/contributions/render/polygon-render'; +import { DefaultCanvasImageRender } from './render/contributions/render/image-render'; import { - DynamicLayerHandlerContribution, - StaticLayerHandlerContribution, - VirtualLayerHandlerContribution -} from './core/constants'; + DefaultBaseBackgroundRenderContribution, + DefaultBaseInteractiveRenderContribution +} from './render/contributions/render/contributions/base-contribution-render'; +import { DefaultBaseTextureRenderContribution } from './render/contributions/render/contributions/base-texture-contribution-render'; +import { DefaultGlobalPickerService } from './picker/global-picker-service'; +import { + Canvas3DPickItemInterceptor, + InteractivePickItemInterceptorContribution, + ShadowRootPickItemInterceptorContribution +} from './picker/pick-interceptor'; +import { DefaultPluginService } from './plugins/plugin-service'; +import { CanvasLayerHandlerContribution } from './core/contributions/layerHandler/canvas2d-contribution'; +import { OffscreenLayerHandlerContribution } from './core/contributions/layerHandler/offscreen2d-contribution'; +import { EmptyLayerHandlerContribution } from './core/contributions/layerHandler/empty-contribution'; import { - GroupRenderContribution, - InteractiveSubRenderContribution -} from './render/contributions/render/contributions/constants'; + TextMeasureContribution, + DefaultTextMeasureContribution +} from './core/contributions/textMeasure/textMeasure-contribution'; // ============ Core 模块注册 ============ export function registerCoreModule() { - const { DefaultGlobal } = require('./core/global'); - const { DefaultGraphicUtil, DefaultTransformUtil } = require('./core/graphic-utils'); - const { DefaultLayerService } = require('./core/layer-service'); - const { DefaultWindow } = require('./core/window'); - // 单例服务 serviceRegistry.registerSingletonFactory(VGlobal, () => new DefaultGlobal()); serviceRegistry.registerSingletonFactory(GraphicUtil, () => new DefaultGraphicUtil()); serviceRegistry.registerSingletonFactory(TransformUtil, () => new DefaultTransformUtil()); serviceRegistry.registerSingletonFactory(LayerService, () => new DefaultLayerService()); + // LayerHandler 工厂 - 每个 Layer 一个实例 + serviceRegistry.registerFactory(StaticLayerHandlerContribution, () => new CanvasLayerHandlerContribution()); + serviceRegistry.registerFactory(DynamicLayerHandlerContribution, () => new OffscreenLayerHandlerContribution()); + serviceRegistry.registerFactory(VirtualLayerHandlerContribution, () => new EmptyLayerHandlerContribution()); + + // TextMeasure 贡献 + contributionRegistry.register(TextMeasureContribution, new DefaultTextMeasureContribution()); + // 工厂服务 - Window 每次创建新实例 serviceRegistry.registerFactory(VWindow, () => new DefaultWindow()); } @@ -50,9 +92,6 @@ export function registerCoreModule() { // ============ Graphic 模块注册 ============ export function registerGraphicModule() { - const { DefaultGraphicService } = require('./graphic/graphic-service/graphic-service'); - const { graphicCreator } = require('./graphic/graphic-creator'); - serviceRegistry.registerSingletonFactory(GraphicService, () => new DefaultGraphicService()); serviceRegistry.registerSingleton(GraphicCreator, graphicCreator); } @@ -60,10 +99,6 @@ export function registerGraphicModule() { // ============ Render 模块注册 ============ export function registerRenderModule() { - const { DefaultRenderService } = require('./render/render-service'); - const { DefaultDrawContribution } = require('./render/contributions/render/draw-contribution'); - const { DefaultIncrementalDrawContribution } = require('./render/contributions/render/incremental-draw-contribution'); - // DrawContribution 单例 serviceRegistry.registerSingletonFactory(DrawContribution, () => new DefaultDrawContribution()); @@ -72,7 +107,7 @@ export function registerRenderModule() { // RenderService 工厂 - 每个 Stage 一个实例 serviceRegistry.registerFactory(RenderService, () => { - const drawContribution = serviceRegistry.get(DrawContribution); + const drawContribution = serviceRegistry.get(DrawContribution) as IDrawContribution; return new DefaultRenderService(drawContribution); }); } @@ -80,19 +115,23 @@ export function registerRenderModule() { // ============ Render Contributions 注册 ============ export function registerRenderContributions() { - const { DefaultCanvasGroupRender } = require('./render/contributions/render/group-render'); - const { CommonDrawItemInterceptorContribution } = require('./render/contributions/render/draw-interceptor'); - const { - DefaultBaseBackgroundRenderContribution, - DefaultBaseInteractiveRenderContribution, - DefaultBaseTextureRenderContribution - } = require('./render/contributions/render/contributions'); - // Group 渲染器 const groupRender = new DefaultCanvasGroupRender(); serviceRegistry.registerSingleton(GroupRender, groupRender); contributionRegistry.register(GraphicRender, groupRender); + // 基础图形渲染器 + contributionRegistry.register(GraphicRender, new DefaultCanvasRectRender()); + contributionRegistry.register(GraphicRender, new DefaultCanvasCircleRender()); + contributionRegistry.register(GraphicRender, new DefaultCanvasArcRender()); + contributionRegistry.register(GraphicRender, new DefaultCanvasLineRender()); + contributionRegistry.register(GraphicRender, new DefaultCanvasAreaRender()); + contributionRegistry.register(GraphicRender, new DefaultCanvasPathRender()); + contributionRegistry.register(GraphicRender, new DefaultCanvasTextRender()); + contributionRegistry.register(GraphicRender, new DefaultCanvasSymbolRender()); + contributionRegistry.register(GraphicRender, new DefaultCanvasPolygonRender()); + contributionRegistry.register(GraphicRender, new DefaultCanvasImageRender()); + // DrawItemInterceptor const commonInterceptor = new CommonDrawItemInterceptorContribution(); contributionRegistry.register(DrawItemInterceptor, commonInterceptor); @@ -112,14 +151,6 @@ export function registerRenderContributions() { // ============ Picker 模块注册 ============ export function registerPickerModule() { - const { DefaultGlobalPickerService } = require('./picker/global-picker-service'); - const { - Canvas3DPickItemInterceptor, - InteractivePickItemInterceptorContribution, - ShadowPickServiceInterceptorContribution, - ShadowRootPickItemInterceptorContribution - } = require('./picker/pick-interceptor'); - // GlobalPickerService 单例 serviceRegistry.registerSingletonFactory(GlobalPickerService, () => new DefaultGlobalPickerService()); serviceRegistry.registerSingletonFactory(PickerService, () => serviceRegistry.get(GlobalPickerService)); @@ -130,14 +161,12 @@ export function registerPickerModule() { contributionRegistry.register(PickItemInterceptor, new InteractivePickItemInterceptorContribution()); // PickServiceInterceptor 贡献 - contributionRegistry.register(PickServiceInterceptor, new ShadowPickServiceInterceptorContribution()); + contributionRegistry.register(PickServiceInterceptor, new ShadowRootPickItemInterceptorContribution()); } // ============ Plugin 模块注册 ============ export function registerPluginModule() { - const { DefaultPluginService } = require('./plugins/plugin-service'); - // PluginService 工厂 - 每个 Stage 一个实例 serviceRegistry.registerFactory(PluginService, () => new DefaultPluginService()); } diff --git a/packages/vrender-core/src/render/contributions/render/draw-contribution.ts b/packages/vrender-core/src/render/contributions/render/draw-contribution.ts index 9d2e48424..5717b95de 100644 --- a/packages/vrender-core/src/render/contributions/render/draw-contribution.ts +++ b/packages/vrender-core/src/render/contributions/render/draw-contribution.ts @@ -22,7 +22,7 @@ import { createColor } from '../../../common/canvas-utils'; import type { ILayerService } from '../../../interface/core'; import { boundsAllocate } from '../../../allocator/bounds-allocate'; import { matrixAllocate } from '../../../allocator/matrix-allocate'; -import { application } from '../../../application'; +import { vglobal, layerService } from '../../../modules'; import { contributionRegistry, serviceRegistry } from '../../../common/registry'; /** @@ -64,8 +64,8 @@ export class DefaultDrawContribution implements IDrawContribution { this.styleRenderMap = new Map(); this.dirtyBounds = new Bounds(); this.backupDirtyBounds = new Bounds(); - this.global = application.global; - this.layerService = application.layerService; + this.global = vglobal; + this.layerService = layerService; if (!isArray(this.contributions)) { (this as any).contributions = [this.contributions]; } diff --git a/packages/vrender-core/src/render/contributions/render/group-render.ts b/packages/vrender-core/src/render/contributions/render/group-render.ts index faff6fe8e..647e30597 100644 --- a/packages/vrender-core/src/render/contributions/render/group-render.ts +++ b/packages/vrender-core/src/render/contributions/render/group-render.ts @@ -23,7 +23,7 @@ import { GROUP_NUMBER_TYPE } from '../../../graphic/constants'; import { BaseRenderContributionTime } from '../../../common/enums'; import { defaultGroupBackgroundRenderContribution } from './contributions'; import { multiplyMat4Mat4 } from '../../../common/matrix'; -import { application } from '../../../application'; +import { vglobal } from '../../../modules'; import { contributionRegistry } from '../../../common/registry'; export class DefaultCanvasGroupRender implements IGraphicRender { @@ -241,7 +241,7 @@ export class DefaultCanvasGroupRender implements IGraphicRender { const { x, y, width, height } = group.attribute; // 绘制到新的Canvas上,然后再绘制回来 const canvas = context.canvas; - const newCanvas = application.global.createCanvas({ width: canvas.width, height: canvas.height, dpr: 1 }); + const newCanvas = vglobal.createCanvas({ width: canvas.width, height: canvas.height, dpr: 1 }); const newContext = newCanvas.getContext('2d'); const transform = context.nativeContext.getTransform(); // 首先应用transform diff --git a/packages/vrender-core/src/resource-loader/loader.ts b/packages/vrender-core/src/resource-loader/loader.ts index 758c7bc5a..eb44d7224 100644 --- a/packages/vrender-core/src/resource-loader/loader.ts +++ b/packages/vrender-core/src/resource-loader/loader.ts @@ -1,5 +1,5 @@ import type { IImage, ImagePayload, ResourceData } from '../interface'; -import { application } from '../application'; +import { vglobal } from '../modules'; const PARALLEL_NUMBER = 10; export class ResourceLoader { @@ -14,7 +14,7 @@ export class ResourceLoader { // 存在缓存 if (data.loadState === 'fail') { // 资源请求失败,修改mark状态 - application.global.getRequestAnimationFrame()(() => { + vglobal.getRequestAnimationFrame()(() => { mark.imageLoadFail(url); }); } else if (data.loadState === 'init' || data.loadState === 'loading') { @@ -28,7 +28,7 @@ export class ResourceLoader { // data = { type: 'image', loadState: 'init' }; // ResourceLoader.cache.set(url, data); - // data.dataPromise = application.global.loadImage(url); + // data.dataPromise = vglobal.loadImage(url); // if (!data.dataPromise) { // // 无法获取资源,修改缓存和mark状态 // data.loadState = 'fail'; @@ -62,7 +62,7 @@ export class ResourceLoader { // 存在缓存 if (data.loadState === 'fail') { // 资源请求失败,修改mark状态 - application.global.getRequestAnimationFrame()(() => { + vglobal.getRequestAnimationFrame()(() => { mark.imageLoadFail(svgStr); }); } else if (data.loadState === 'init' || data.loadState === 'loading') { @@ -75,7 +75,7 @@ export class ResourceLoader { data = { type: 'image', loadState: 'init' }; ResourceLoader.cache.set(svgStr, data); - data.dataPromise = application.global.loadSvg(svgStr); + data.dataPromise = vglobal.loadSvg(svgStr); if (!data.dataPromise) { // 无法获取资源,修改缓存和mark状态 data.loadState = 'fail'; @@ -119,11 +119,11 @@ export class ResourceLoader { ResourceLoader.cache.set(url, data); if (type === 'arrayBuffer') { - data.dataPromise = application.global.loadArrayBuffer(url); + data.dataPromise = vglobal.loadArrayBuffer(url); } else if (type === 'blob') { - data.dataPromise = application.global.loadBlob(url); + data.dataPromise = vglobal.loadBlob(url); } else if (type === 'json') { - data.dataPromise = application.global.loadJson(url); + data.dataPromise = vglobal.loadJson(url); } return data.dataPromise.then(data => data.data); @@ -140,7 +140,7 @@ export class ResourceLoader { const data: ResourceData = { type: 'image', loadState: 'init' }; ResourceLoader.cache.set(url, data); - data.dataPromise = application.global.loadImage(url); + data.dataPromise = vglobal.loadImage(url); if (!data.dataPromise) { // 无法获取资源,修改缓存和mark状态 data.loadState = 'fail'; diff --git a/packages/vrender-kits/src/canvas/contributions/browser/canvas.ts b/packages/vrender-kits/src/canvas/contributions/browser/canvas.ts index 0e46dcd9e..571603b67 100644 --- a/packages/vrender-kits/src/canvas/contributions/browser/canvas.ts +++ b/packages/vrender-kits/src/canvas/contributions/browser/canvas.ts @@ -1,5 +1,5 @@ -import { application, BaseCanvas } from '@visactor/vrender-core'; -import type { CanvasConfigType, ICanvas, EnvType } from '@visactor/vrender-core'; +import { BaseCanvas, serviceRegistry, VGlobal } from '@visactor/vrender-core'; +import type { CanvasConfigType, ICanvas, EnvType, IGlobal } from '@visactor/vrender-core'; import { BrowserContext2d } from './context'; export class BrowserCanvas extends BaseCanvas implements ICanvas { @@ -16,7 +16,8 @@ export class BrowserCanvas extends BaseCanvas implements ICanvas { init(params: CanvasConfigType) { const { container } = params; if (typeof container === 'string') { - const _c = application.global.getElementById(container); + const global = serviceRegistry.get(VGlobal) as IGlobal; + const _c = global.getElementById(container); if (_c) { this._container = _c; } diff --git a/packages/vrender-kits/src/canvas/contributions/browser/context.ts b/packages/vrender-kits/src/canvas/contributions/browser/context.ts index 63cfd66d0..e7c935bd6 100644 --- a/packages/vrender-kits/src/canvas/contributions/browser/context.ts +++ b/packages/vrender-kits/src/canvas/contributions/browser/context.ts @@ -31,7 +31,9 @@ import { DefaultTextStyle, createColor, getScaledStroke, - application, + serviceRegistry, + VGlobal, + GraphicUtil, matrixAllocate, transformMat4, createConicalGradient @@ -48,7 +50,9 @@ import type { ITextStyleParams, mat4, EnvType, - vec3 + vec3, + IGlobal, + IGraphicUtil } from '@visactor/vrender-core'; const outP: [number, number, number] = [0, 0, 0]; @@ -856,13 +860,14 @@ export class BrowserContext2d implements IContext2d { measureText( text: string, - method: 'native' | 'simple' | 'quick' = application.global.measureTextMethod + method: 'native' | 'simple' | 'quick' = (serviceRegistry.get(VGlobal) as any).measureTextMethod ): { width: number } { if (!method || method === 'native') { return this.nativeContext.measureText(text); } if (!this.mathTextMeasure) { - this.mathTextMeasure = application.graphicUtil.createTextMeasureInstance({}, {}, () => this.canvas.nativeCanvas); + const graphicUtil = serviceRegistry.get(GraphicUtil) as IGraphicUtil; + this.mathTextMeasure = graphicUtil.createTextMeasureInstance({}, {}, () => this.canvas.nativeCanvas); } const fontFamily = this.fontFamily ?? DefaultTextStyle.fontFamily; diff --git a/packages/vrender-kits/src/canvas/contributions/create-canvas-module.ts b/packages/vrender-kits/src/canvas/contributions/create-canvas-module.ts index 9f827ec43..34b6207ec 100644 --- a/packages/vrender-kits/src/canvas/contributions/create-canvas-module.ts +++ b/packages/vrender-kits/src/canvas/contributions/create-canvas-module.ts @@ -1,15 +1,15 @@ -import { application, CanvasFactory, Context2dFactory } from '@visactor/vrender-core'; +import { serviceRegistry, CanvasFactory, Context2dFactory } from '@visactor/vrender-core'; import type { CanvasConfigType, ICanvas } from '@visactor/vrender-core'; -// Register canvas/context factories via application.services (no inversify) +// Register canvas/context factories via serviceRegistry (no inversify) export function registerCanvasFactories(CanvasConstructor: any, ContextConstructor: any) { - // Canvas factory - application.services.registerFactory(CanvasFactory, () => { - return (params: CanvasConfigType) => new CanvasConstructor(params); + // Canvas factory - directly register the factory function that creates Canvas instances + serviceRegistry.registerFactory(CanvasFactory, (params: CanvasConfigType) => { + return new CanvasConstructor(params); }); - // Context2d factory - application.services.registerFactory(Context2dFactory, () => { - return (canvas: ICanvas, dpr: number) => new ContextConstructor(canvas, dpr); + // Context2d factory - directly register the factory function that creates Context instances + serviceRegistry.registerFactory(Context2dFactory, (canvas: ICanvas, dpr: number) => { + return new ContextConstructor(canvas, dpr); }); } diff --git a/packages/vrender-kits/src/canvas/contributions/harmony/context.ts b/packages/vrender-kits/src/canvas/contributions/harmony/context.ts index 75caec68a..7c58a105e 100644 --- a/packages/vrender-kits/src/canvas/contributions/harmony/context.ts +++ b/packages/vrender-kits/src/canvas/contributions/harmony/context.ts @@ -1,5 +1,5 @@ // 参考konva -import { createColor, getScaledStroke, application } from '@visactor/vrender-core'; +import { createColor, getScaledStroke, vglobal } from '@visactor/vrender-core'; import type { IContext2d, EnvType, @@ -77,11 +77,8 @@ export class HarmonyContext2d extends BrowserContext2d implements IContext2d { } } - measureText( - text: string, - method: 'native' | 'simple' | 'quick' = application.global.measureTextMethod - ): { width: number } { - this.setTransform(1, 0, 0, 1, 0, 0, true, application.global.devicePixelRatio); + measureText(text: string, method: 'native' | 'simple' | 'quick' = vglobal.measureTextMethod): { width: number } { + this.setTransform(1, 0, 0, 1, 0, 0, true, vglobal.devicePixelRatio); const data = super.measureText(text, method); return data; } diff --git a/packages/vrender-kits/src/canvas/contributions/lynx/context.ts b/packages/vrender-kits/src/canvas/contributions/lynx/context.ts index 95d45e801..c66e1d8d6 100644 --- a/packages/vrender-kits/src/canvas/contributions/lynx/context.ts +++ b/packages/vrender-kits/src/canvas/contributions/lynx/context.ts @@ -1,5 +1,5 @@ // 参考konva -import { createColor, getScaledStroke, application } from '@visactor/vrender-core'; +import { createColor, getScaledStroke, vglobal } from '@visactor/vrender-core'; import type { IContext2d, EnvType, ISetStrokeStyleParams, IStrokeStyleParams } from '@visactor/vrender-core'; import { BrowserContext2d } from '../browser'; @@ -70,11 +70,8 @@ export class LynxContext2d extends BrowserContext2d implements IContext2d { } } - measureText( - text: string, - method: 'native' | 'simple' | 'quick' = application.global.measureTextMethod - ): { width: number } { - this.setTransform(1, 0, 0, 1, 0, 0, true, application.global.devicePixelRatio); + measureText(text: string, method: 'native' | 'simple' | 'quick' = vglobal.measureTextMethod): { width: number } { + this.setTransform(1, 0, 0, 1, 0, 0, true, vglobal.devicePixelRatio); const data: any = super.measureText(text, method); // lynx环境中的fontBoundingBoxDescent和fontBoundingBoxAscent有严重偏移,暂时规避 return { diff --git a/packages/vrender-kits/src/env/all.ts b/packages/vrender-kits/src/env/all.ts index 01348b9b7..988c2e1e0 100644 --- a/packages/vrender-kits/src/env/all.ts +++ b/packages/vrender-kits/src/env/all.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry, vglobal } from '@visactor/vrender-core'; import { registerBrowserEnvRegistry } from './browser'; import { registerFeishuEnvRegistry } from './feishu'; import { registerLynxEnvRegistry } from './lynx'; @@ -23,7 +23,7 @@ export function loadAllModule() { registerTaroEnvRegistry(); registerWxEnvRegistry(); registerCanvasPickerService(); - application.global.hooks.onSetEnv.tap('registerMathPickerService', (lastEnv, env) => { + vglobal.hooks.onSetEnv.tap('registerMathPickerService', (lastEnv, env) => { env !== 'browser' && registerMathPickerService(); }); } diff --git a/packages/vrender-kits/src/env/browser.ts b/packages/vrender-kits/src/env/browser.ts index a5de6a1b6..3e95555a6 100644 --- a/packages/vrender-kits/src/env/browser.ts +++ b/packages/vrender-kits/src/env/browser.ts @@ -1,8 +1,9 @@ -import { EnvContribution, application } from '@visactor/vrender-core'; +import { EnvContribution, contributionRegistry } from '@visactor/vrender-core'; // import { browserEnvModule } from './contributions/module'; import { BrowserEnvContribution } from './contributions/browser-contribution'; import { BrowserWindowHandlerContribution } from '../window/contributions/browser-contribution'; import { WindowHandlerContribution } from '@visactor/vrender-core'; +import { registerBrowserCanvasFactories } from '../canvas/contributions/browser/modules'; // Legacy ContainerModule and loaders removed (registry-only) @@ -10,8 +11,9 @@ import { WindowHandlerContribution } from '@visactor/vrender-core'; * Registry-based registration for browser env/window */ export function registerBrowserEnvRegistry() { + registerBrowserCanvasFactories(); // Env contribution - application.contributions.register(EnvContribution, new BrowserEnvContribution()); + contributionRegistry.register(EnvContribution, new BrowserEnvContribution()); // Window handler contribution - application.contributions.register(WindowHandlerContribution, new BrowserWindowHandlerContribution()); + contributionRegistry.register(WindowHandlerContribution, new BrowserWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/contributions/browser-contribution.ts b/packages/vrender-kits/src/env/contributions/browser-contribution.ts index be3e7881a..4ff466e7d 100644 --- a/packages/vrender-kits/src/env/contributions/browser-contribution.ts +++ b/packages/vrender-kits/src/env/contributions/browser-contribution.ts @@ -1,4 +1,4 @@ -import { Generator, BaseEnvContribution, application } from '@visactor/vrender-core'; +import { Generator, BaseEnvContribution, vglobal } from '@visactor/vrender-core'; import type { ICanvasLike, EnvType, @@ -38,7 +38,7 @@ class DynamicB { export function createImageElement(src: string, isSvg: boolean = false): Promise { const img = document.createElement('img'); - if (application.global.isImageAnonymous) { + if (vglobal.isImageAnonymous) { img.crossOrigin = 'anonymous'; } if (isSvg) { diff --git a/packages/vrender-kits/src/env/feishu.ts b/packages/vrender-kits/src/env/feishu.ts index 1bd74c8ed..929bfffdd 100644 --- a/packages/vrender-kits/src/env/feishu.ts +++ b/packages/vrender-kits/src/env/feishu.ts @@ -1,4 +1,4 @@ -import { EnvContribution, application, WindowHandlerContribution } from '@visactor/vrender-core'; +import { EnvContribution, contributionRegistry, WindowHandlerContribution } from '@visactor/vrender-core'; import { FeishuWindowHandlerContribution } from '../window/contributions/feishu-contribution'; import { FeishuEnvContribution } from './contributions/feishu-contribution'; @@ -6,6 +6,6 @@ import { FeishuEnvContribution } from './contributions/feishu-contribution'; /** Registry-based registration for feishu env/window */ export function registerFeishuEnvRegistry() { - application.contributions.register(EnvContribution, new FeishuEnvContribution()); - application.contributions.register(WindowHandlerContribution, new FeishuWindowHandlerContribution()); + contributionRegistry.register(EnvContribution, new FeishuEnvContribution()); + contributionRegistry.register(WindowHandlerContribution, new FeishuWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/harmony.ts b/packages/vrender-kits/src/env/harmony.ts index 94dac0d78..dfc217b9d 100644 --- a/packages/vrender-kits/src/env/harmony.ts +++ b/packages/vrender-kits/src/env/harmony.ts @@ -1,9 +1,9 @@ -import { EnvContribution, application, WindowHandlerContribution } from '@visactor/vrender-core'; +import { EnvContribution, contributionRegistry, WindowHandlerContribution } from '@visactor/vrender-core'; import { HarmonyWindowHandlerContribution } from '../window/contributions/harmony-contribution'; import { HarmonyEnvContribution } from './contributions/harmony-contribution'; /** Registry-based registration for harmony env/window */ export function registerHarmonyEnvRegistry() { - application.contributions.register(EnvContribution, new HarmonyEnvContribution()); - application.contributions.register(WindowHandlerContribution, new HarmonyWindowHandlerContribution()); + contributionRegistry.register(EnvContribution, new HarmonyEnvContribution()); + contributionRegistry.register(WindowHandlerContribution, new HarmonyWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/lynx.ts b/packages/vrender-kits/src/env/lynx.ts index 6390b5496..0cfe4c20d 100644 --- a/packages/vrender-kits/src/env/lynx.ts +++ b/packages/vrender-kits/src/env/lynx.ts @@ -1,4 +1,4 @@ -import { EnvContribution, application, WindowHandlerContribution } from '@visactor/vrender-core'; +import { EnvContribution, contributionRegistry, WindowHandlerContribution } from '@visactor/vrender-core'; import { LynxWindowHandlerContribution } from '../window/contributions/lynx-contribution'; import { LynxEnvContribution } from './contributions/lynx-contribution'; // import { lynxEnvModule } from './contributions/module'; @@ -7,6 +7,6 @@ import { LynxEnvContribution } from './contributions/lynx-contribution'; /** Registry-based registration for lynx env/window */ export function registerLynxEnvRegistry() { - application.contributions.register(EnvContribution, new LynxEnvContribution()); - application.contributions.register(WindowHandlerContribution, new LynxWindowHandlerContribution()); + contributionRegistry.register(EnvContribution, new LynxEnvContribution()); + contributionRegistry.register(WindowHandlerContribution, new LynxWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/node.ts b/packages/vrender-kits/src/env/node.ts index 349207b88..16e7fa8ed 100644 --- a/packages/vrender-kits/src/env/node.ts +++ b/packages/vrender-kits/src/env/node.ts @@ -1,4 +1,4 @@ -import { EnvContribution, application } from '@visactor/vrender-core'; +import { EnvContribution, contributionRegistry } from '@visactor/vrender-core'; // import { loadMathPicker } from '../picker/math-module'; // import { nodeEnvModule } from './contributions/module'; import { NodeEnvContribution } from './contributions/node-contribution'; @@ -12,7 +12,7 @@ import { WindowHandlerContribution } from '@visactor/vrender-core'; */ export function registerNodeEnvRegistry() { // Env contribution - application.contributions.register(EnvContribution, new NodeEnvContribution()); + contributionRegistry.register(EnvContribution, new NodeEnvContribution()); // Window handler contribution - application.contributions.register(WindowHandlerContribution, new NodeWindowHandlerContribution()); + contributionRegistry.register(WindowHandlerContribution, new NodeWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/taro.ts b/packages/vrender-kits/src/env/taro.ts index dac6198e3..59fdd89a1 100644 --- a/packages/vrender-kits/src/env/taro.ts +++ b/packages/vrender-kits/src/env/taro.ts @@ -1,4 +1,4 @@ -import { EnvContribution, application, WindowHandlerContribution } from '@visactor/vrender-core'; +import { EnvContribution, contributionRegistry, WindowHandlerContribution } from '@visactor/vrender-core'; import { TaroWindowHandlerContribution } from '../window/contributions/taro-contribution'; import { TaroEnvContribution } from './contributions/taro-contribution'; @@ -6,6 +6,6 @@ import { TaroEnvContribution } from './contributions/taro-contribution'; /** Registry-based registration for taro env/window */ export function registerTaroEnvRegistry() { - application.contributions.register(EnvContribution, new TaroEnvContribution()); - application.contributions.register(WindowHandlerContribution, new TaroWindowHandlerContribution()); + contributionRegistry.register(EnvContribution, new TaroEnvContribution()); + contributionRegistry.register(WindowHandlerContribution, new TaroWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/tt.ts b/packages/vrender-kits/src/env/tt.ts index 9792dcd2a..7fe1d9047 100644 --- a/packages/vrender-kits/src/env/tt.ts +++ b/packages/vrender-kits/src/env/tt.ts @@ -1,9 +1,9 @@ -import { EnvContribution, application, WindowHandlerContribution } from '@visactor/vrender-core'; +import { EnvContribution, contributionRegistry, WindowHandlerContribution } from '@visactor/vrender-core'; import { TTWindowHandlerContribution } from '../window/contributions/tt-contribution'; import { TTEnvContribution } from './contributions/tt-contribution'; /** Registry-based registration for tt env/window */ export function registerTtEnvRegistry() { - application.contributions.register(EnvContribution, new TTEnvContribution()); - application.contributions.register(WindowHandlerContribution, new TTWindowHandlerContribution()); + contributionRegistry.register(EnvContribution, new TTEnvContribution()); + contributionRegistry.register(WindowHandlerContribution, new TTWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/wx.ts b/packages/vrender-kits/src/env/wx.ts index 12110edfe..0ac62508f 100644 --- a/packages/vrender-kits/src/env/wx.ts +++ b/packages/vrender-kits/src/env/wx.ts @@ -1,4 +1,4 @@ -import { EnvContribution, application, WindowHandlerContribution } from '@visactor/vrender-core'; +import { EnvContribution, contributionRegistry, WindowHandlerContribution } from '@visactor/vrender-core'; // import { loadMathPicker } from '../picker/math-module'; // import { wxEnvModule } from './contributions/module'; import { registerWxCanvasFactories } from '../canvas/contributions/wx/modules'; @@ -9,8 +9,8 @@ import { WxEnvContribution } from './contributions/wx-contribution'; /** Registry-based registration for wx env/window */ export function registerWxEnvRegistry() { - application.contributions.register(EnvContribution, new WxEnvContribution()); + contributionRegistry.register(EnvContribution, new WxEnvContribution()); // ensure canvas factories for wx are registered registerWxCanvasFactories(); - application.contributions.register(WindowHandlerContribution, new WxWindowHandlerContribution()); + contributionRegistry.register(WindowHandlerContribution, new WxWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/event/extension/gesture.ts b/packages/vrender-kits/src/event/extension/gesture.ts index fb66cd7f4..527249599 100644 --- a/packages/vrender-kits/src/event/extension/gesture.ts +++ b/packages/vrender-kits/src/event/extension/gesture.ts @@ -1,4 +1,4 @@ -import { application, clock, WILDCARD } from '@visactor/vrender-core'; +import { clock, WILDCARD, vglobal } from '@visactor/vrender-core'; import type { IEventTarget, IFederatedPointerEvent, FederatedPointerEvent, INode } from '@visactor/vrender-core'; import type { IPointLike } from '@visactor/vutils'; import { EventEmitter } from '@visactor/vutils'; @@ -394,8 +394,8 @@ export class Gesture extends EventEmitter { return; } - this.throttleTimer = application.global.getRequestAnimationFrame()(() => { - application.global.getCancelAnimationFrame()(this.throttleTimer); + this.throttleTimer = vglobal.getRequestAnimationFrame()(() => { + vglobal.getCancelAnimationFrame()(this.throttleTimer); this.throttleTimer = null; for (let i = 0, len = emitThrottles.length; i < len; i++) { diff --git a/packages/vrender-kits/src/graphic/Lottie.ts b/packages/vrender-kits/src/graphic/Lottie.ts index edb858e4b..1c8582174 100644 --- a/packages/vrender-kits/src/graphic/Lottie.ts +++ b/packages/vrender-kits/src/graphic/Lottie.ts @@ -1,7 +1,7 @@ import { min } from '@visactor/vutils'; import { LOTTIE_NUMBER_TYPE } from './constants'; import type { IRectGraphicAttribute } from '@visactor/vrender-core'; -import { getTheme, GraphicType, IContext2d, NOWORK_ANIMATE_ATTR, Rect, application } from '@visactor/vrender-core'; +import { getTheme, GraphicType, IContext2d, NOWORK_ANIMATE_ATTR, Rect, vglobal } from '@visactor/vrender-core'; import type { ILottie, ILottieGraphicAttribute } from './interface/lottie'; import type { AnimationItem } from 'lottie-web'; import bodymovin from 'lottie-web'; @@ -40,7 +40,7 @@ export class Lottie extends Rect implements ILottie { initLottieWeb(data: string) { // 必须是浏览器环境才行 - if (application.global.env !== 'browser') { + if (vglobal.env !== 'browser') { return; } if (this.lottieInstance) { @@ -48,7 +48,7 @@ export class Lottie extends Rect implements ILottie { } const theme = this.getGraphicTheme(); const { width = theme.width, height = theme.height } = this.attribute; - const canvas = application.global.createCanvas({ width, height, dpr: application.global.devicePixelRatio }); + const canvas = vglobal.createCanvas({ width, height, dpr: vglobal.devicePixelRatio }); const params: any = { // wrapper: svgContainer, rendererSettings: { diff --git a/packages/vrender-kits/src/graphic/gif-image.ts b/packages/vrender-kits/src/graphic/gif-image.ts index 2e930233d..eb4991b95 100644 --- a/packages/vrender-kits/src/graphic/gif-image.ts +++ b/packages/vrender-kits/src/graphic/gif-image.ts @@ -1,5 +1,5 @@ import type { IImageGraphicAttribute, ISetAttributeContext } from '@visactor/vrender-core'; -import { application, Image, ResourceLoader } from '@visactor/vrender-core'; +import { Image, ResourceLoader, vglobal } from '@visactor/vrender-core'; import type { ITimeline } from '@visactor/vrender-core'; import { isString } from '@visactor/vutils'; import type { ParsedFrame } from 'gifuct-js'; @@ -50,12 +50,12 @@ export class GifImage extends Image implements IGifImage { this.frameIndex = 0; if (!this.tempCanvas) { - this.tempCanvas = application.global.createCanvas({}); + this.tempCanvas = vglobal.createCanvas({}); this.tempCtx = this.tempCanvas.getContext('2d'); } if (!this.gifCanvas) { - this.gifCanvas = application.global.createCanvas({}); + this.gifCanvas = vglobal.createCanvas({}); this.gifCtx = this.gifCanvas.getContext('2d'); } diff --git a/packages/vrender-kits/src/picker/canvas-module.ts b/packages/vrender-kits/src/picker/canvas-module.ts index ef7e61741..ed04581e8 100644 --- a/packages/vrender-kits/src/picker/canvas-module.ts +++ b/packages/vrender-kits/src/picker/canvas-module.ts @@ -1,4 +1,4 @@ -import { application, PickerService } from '@visactor/vrender-core'; +import { serviceRegistry, PickerService } from '@visactor/vrender-core'; import { DefaultCanvasPickerService } from './canvas-picker-service'; import { registerCanvasGroupPicker } from './contributions/canvas-picker/module'; @@ -8,7 +8,7 @@ export function registerCanvasPickerService() { } (registerCanvasPickerService as any).__loaded = true; // Override PickerService to use canvas-based service - application.services.registerSingletonFactory(PickerService, () => new DefaultCanvasPickerService()); + serviceRegistry.registerSingletonFactory(PickerService, () => new DefaultCanvasPickerService()); // Ensure group picker is registered registerCanvasGroupPicker(); } diff --git a/packages/vrender-kits/src/picker/canvas-picker-service.ts b/packages/vrender-kits/src/picker/canvas-picker-service.ts index dab05c724..362ee12b7 100644 --- a/packages/vrender-kits/src/picker/canvas-picker-service.ts +++ b/packages/vrender-kits/src/picker/canvas-picker-service.ts @@ -2,6 +2,7 @@ import type { IMatrix, IPointLike } from '@visactor/vutils'; import { DefaultPickService, canvasAllocate, + contributionRegistry, type ICanvas, type IContext2d, type IGraphic, @@ -11,8 +12,7 @@ import { type IPickerService, type IContributionProvider, type IPickParams, - type PickResult, - application + type PickResult } from '@visactor/vrender-core'; import { CanvasPickerContribution } from './contributions/constants'; @@ -31,7 +31,7 @@ export class DefaultCanvasPickerService extends DefaultPickService implements IP super(); // Use registry-only provider for canvas pickers this.contributions = { - getContributions: () => application.contributions.get(CanvasPickerContribution) + getContributions: () => contributionRegistry.get(CanvasPickerContribution) } as IContributionProvider; this.global.hooks.onSetEnv.tap('canvas-picker-service', (_, env, global) => { diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/arc-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/arc-module.ts index b603b567f..5f9dcfa08 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/arc-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/arc-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { DefaultCanvasArcPicker } from './arc-picker'; import { CanvasPickerContribution } from '../constants'; @@ -8,5 +8,5 @@ export function registerCanvasArcPicker() { return; } _registered = true; - application.contributions.register(CanvasPickerContribution, new DefaultCanvasArcPicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasArcPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/arc-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/arc-picker.ts index 03d93f29c..723e3a45b 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/arc-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/arc-picker.ts @@ -1,4 +1,4 @@ -import { application, ArcRender, ARC_NUMBER_TYPE } from '@visactor/vrender-core'; +import { contributionRegistry, ArcRender, ARC_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; @@ -8,7 +8,7 @@ export class DefaultCanvasArcPicker extends PickerBase implements IGraphicPicker constructor() { super(); - const render = application.contributions.get(ArcRender)[0]; + const render = contributionRegistry.get(ArcRender)[0]; this.canvasRenderer = render; } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/arc3d-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/arc3d-module.ts index 66fc6d623..da08adb66 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/arc3d-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/arc3d-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasArc3dPicker } from './arc3d-picker'; @@ -8,5 +8,5 @@ export function registerCanvasArc3dPicker() { return; } _registeredArc3d = true; - application.contributions.register(CanvasPickerContribution, new DefaultCanvasArc3dPicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasArc3dPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/arc3d-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/arc3d-picker.ts index 74cfc672d..00c9ff9dc 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/arc3d-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/arc3d-picker.ts @@ -1,4 +1,4 @@ -import { application, Arc3dRender, ARC3D_NUMBER_TYPE } from '@visactor/vrender-core'; +import { serviceRegistry, contributionRegistry, Arc3dRender, ARC3D_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IArc3d, IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { Base3dPicker } from '../common/base-3d-picker'; @@ -10,9 +10,9 @@ export class DefaultCanvasArc3dPicker extends Base3dPicker implements IG constructor() { super(); try { - this.canvasRenderer = application.services.get(Arc3dRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(Arc3dRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(Arc3dRender)[0]; + this.canvasRenderer = contributionRegistry.get(Arc3dRender)[0]; } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/area-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/area-module.ts index ac5f963d1..9010a2ef9 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/area-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/area-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { CanvasAreaPicker, CanvasPickerContribution } from '../constants'; import { DefaultCanvasAreaPicker } from './area-picker'; @@ -9,5 +9,5 @@ export function registerCanvasAreaPicker() { } loadAreaPick = true; // area picker - application.contributions.register(CanvasPickerContribution, new DefaultCanvasAreaPicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasAreaPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/area-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/area-picker.ts index 41af478d1..56484b9c0 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/area-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/area-picker.ts @@ -1,4 +1,4 @@ -import { AreaRender, AREA_NUMBER_TYPE, application } from '@visactor/vrender-core'; +import { serviceRegistry, AreaRender, AREA_NUMBER_TYPE, contributionRegistry } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; @@ -9,9 +9,9 @@ export class DefaultCanvasAreaPicker extends PickerBase implements IGraphicPicke constructor() { super(); try { - this.canvasRenderer = application.services.get(AreaRender); + this.canvasRenderer = serviceRegistry.get(AreaRender); } catch (_) { - this.canvasRenderer = application.contributions.get(AreaRender)[0]; + this.canvasRenderer = contributionRegistry.get(AreaRender)[0]; } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/circle-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/circle-module.ts index d601ed110..da40786b2 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/circle-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/circle-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasCirclePicker } from './circle-picker'; @@ -8,5 +8,5 @@ export function registerCanvasCirclePicker() { return; } _registeredCircle = true; - application.contributions.register(CanvasPickerContribution, new DefaultCanvasCirclePicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasCirclePicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/circle-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/circle-picker.ts index 3466ee38f..afb181cf8 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/circle-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/circle-picker.ts @@ -1,4 +1,4 @@ -import { CircleRender, CIRCLE_NUMBER_TYPE, application } from '@visactor/vrender-core'; +import { serviceRegistry, CircleRender, CIRCLE_NUMBER_TYPE, contributionRegistry } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; @@ -9,9 +9,9 @@ export class DefaultCanvasCirclePicker extends PickerBase implements IGraphicPic constructor() { super(); try { - this.canvasRenderer = application.services.get(CircleRender); + this.canvasRenderer = serviceRegistry.get(CircleRender); } catch (_) { - this.canvasRenderer = application.contributions.get(CircleRender)[0]; + this.canvasRenderer = contributionRegistry.get(CircleRender)[0]; } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/gif-image-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/gif-image-module.ts index 0c4628008..198521eda 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/gif-image-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/gif-image-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasGifImagePicker } from './gif-image-picker'; @@ -8,5 +8,5 @@ export function registerCanvasGifImagePicker() { return; } _registeredGifImage = true; - application.contributions.register(CanvasPickerContribution, new DefaultCanvasGifImagePicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasGifImagePicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/glyph-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/glyph-module.ts index 60440caeb..346eef069 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/glyph-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/glyph-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasGlyphPicker } from './glyph-picker'; @@ -8,5 +8,5 @@ export function registerCanvasGlyphPicker() { return; } _registeredGlyph = true; - application.contributions.register(CanvasPickerContribution, new DefaultCanvasGlyphPicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasGlyphPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/glyph-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/glyph-picker.ts index b2e73825d..e81802c94 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/glyph-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/glyph-picker.ts @@ -1,4 +1,4 @@ -import { GlyphRender, application } from '@visactor/vrender-core'; +import { serviceRegistry, GlyphRender, contributionRegistry } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { GlyphPickerBase } from '../common/glyph-picker-base'; @@ -6,9 +6,9 @@ export class DefaultCanvasGlyphPicker extends GlyphPickerBase implements IGraphi constructor() { super(); try { - this.canvasRenderer = application.services.get(GlyphRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(GlyphRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(GlyphRender)[0]; + this.canvasRenderer = contributionRegistry.get(GlyphRender)[0]; } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/image-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/image-module.ts index 3d9abfe7d..d883463a0 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/image-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/image-module.ts @@ -1,5 +1,5 @@ -import { application } from '@visactor/vrender-core'; -import { CanvasImagePicker, CanvasPickerContribution } from '../constants'; +import { contributionRegistry } from '@visactor/vrender-core'; +import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasImagePicker } from './image-picker'; let _registered = false; @@ -8,5 +8,5 @@ export function registerCanvasImagePicker() { return; } _registered = true; - application.contributions.register(CanvasPickerContribution, new DefaultCanvasImagePicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasImagePicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/image-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/image-picker.ts index 047efff25..e218c6af9 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/image-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/image-picker.ts @@ -1,6 +1,6 @@ import type { IPoint } from '@visactor/vutils'; -import { IMAGE_NUMBER_TYPE, ImageRender, application } from '@visactor/vrender-core'; -import type { IGraphicPicker, IGraphicRender, IImage, IPickParams } from '@visactor/vrender-core'; +import { contributionRegistry, IMAGE_NUMBER_TYPE, ImageRender } from '@visactor/vrender-core'; +import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; export class DefaultCanvasImagePicker extends PickerBase implements IGraphicPicker { @@ -9,7 +9,7 @@ export class DefaultCanvasImagePicker extends PickerBase implements IGraphicPick constructor() { super(); - const render = application.contributions.get(ImageRender)[0]; + const render = contributionRegistry.get(ImageRender)[0]; this.canvasRenderer = render; } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/line-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/line-module.ts index beab37809..fca5fefba 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/line-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/line-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasLinePicker } from './line-picker'; @@ -8,5 +8,5 @@ export function registerCanvasLinePicker() { return; } _registered = true; - application.contributions.register(CanvasPickerContribution, new DefaultCanvasLinePicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasLinePicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/line-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/line-picker.ts index 53a613267..14e224609 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/line-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/line-picker.ts @@ -1,4 +1,4 @@ -import { application, LineRender, LINE_NUMBER_TYPE } from '@visactor/vrender-core'; +import { contributionRegistry, LineRender, LINE_NUMBER_TYPE } from '@visactor/vrender-core'; import type { ILine, IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { BaseLinePicker } from '../common/base-line-picker'; @@ -8,7 +8,7 @@ export class DefaultCanvasLinePicker extends BaseLinePicker implements IG constructor() { super(); - const render = application.contributions.get(LineRender)[0]; + const render = contributionRegistry.get(LineRender)[0]; this.canvasRenderer = render; } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/lottie-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/lottie-module.ts index 2214bcad7..e50939652 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/lottie-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/lottie-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasLottiePicker } from './lottie-picker'; @@ -8,5 +8,5 @@ export function registerCanvasLottiePicker() { return; } _registeredLottie = true; - application.contributions.register(CanvasPickerContribution, new DefaultCanvasLottiePicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasLottiePicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/lottie-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/lottie-picker.ts index a90e0d0cc..e2474fa9b 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/lottie-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/lottie-picker.ts @@ -1,4 +1,4 @@ -import { application, RectRender } from '@visactor/vrender-core'; +import { serviceRegistry, contributionRegistry, RectRender } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { RectPickerBase } from '../common/rect-picker-base'; @@ -6,9 +6,9 @@ export class DefaultCanvasLottiePicker extends RectPickerBase implements IGraphi constructor() { super(); try { - this.canvasRenderer = application.services.get(RectRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(RectRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(RectRender)[0]; + this.canvasRenderer = contributionRegistry.get(RectRender)[0]; } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/module.ts index 5a7164727..c47d17ed3 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { CanvasGroupPicker, CanvasPickerContribution } from '../constants'; import { DefaultCanvasGroupPicker } from './group-picker'; @@ -8,5 +8,5 @@ export function registerCanvasGroupPicker() { return; } _registered = true; - application.contributions.register(CanvasPickerContribution, new DefaultCanvasGroupPicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasGroupPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/path-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/path-module.ts index 730e8afc9..ffb0a9709 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/path-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/path-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { CanvasPathPicker, CanvasPickerContribution } from '../constants'; import { DefaultCanvasPathPicker } from './path-picker'; @@ -8,5 +8,5 @@ export function registerCanvasPathPicker() { return; } loadPathPick = true; - application.contributions.register(CanvasPickerContribution, new DefaultCanvasPathPicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasPathPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/path-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/path-picker.ts index 9f19d4045..341d8eb67 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/path-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/path-picker.ts @@ -1,4 +1,4 @@ -import { application, PathRender, PATH_NUMBER_TYPE } from '@visactor/vrender-core'; +import { contributionRegistry, PathRender, PATH_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IPath, IGraphicRender, IGraphicPicker } from '@visactor/vrender-core'; import { BaseLinePicker } from '../common/base-line-picker'; @@ -8,7 +8,7 @@ export class DefaultCanvasPathPicker extends BaseLinePicker implements IG constructor() { super(); - const render = application.contributions.get(PathRender)[0]; + const render = contributionRegistry.get(PathRender)[0]; this.canvasRenderer = render; } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/polygon-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/polygon-module.ts index 8a4b73dc1..70ba38a88 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/polygon-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/polygon-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasPolygonPicker } from './polygon-picker'; @@ -8,5 +8,5 @@ export function registerCanvasPolygonPicker() { return; } _registeredPolygon = true; - application.contributions.register(CanvasPickerContribution, new DefaultCanvasPolygonPicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasPolygonPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/polygon-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/polygon-picker.ts index ffba45e72..d1239891f 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/polygon-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/polygon-picker.ts @@ -1,4 +1,4 @@ -import { PolygonRender, POLYGON_NUMBER_TYPE, application } from '@visactor/vrender-core'; +import { serviceRegistry, PolygonRender, POLYGON_NUMBER_TYPE, contributionRegistry } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; @@ -9,9 +9,9 @@ export class DefaultCanvasPolygonPicker extends PickerBase implements IGraphicPi constructor() { super(); try { - this.canvasRenderer = application.services.get(PolygonRender); + this.canvasRenderer = serviceRegistry.get(PolygonRender); } catch (_) { - this.canvasRenderer = application.contributions.get(PolygonRender)[0]; + this.canvasRenderer = contributionRegistry.get(PolygonRender)[0]; } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/pyramid3d-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/pyramid3d-module.ts index efe572082..97361cc2b 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/pyramid3d-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/pyramid3d-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasPyramid3dPicker } from './pyramid3d-picker'; @@ -8,5 +8,5 @@ export function registerCanvasPyramid3dPicker() { return; } _registeredPyramid3d = true; - application.contributions.register(CanvasPickerContribution, new DefaultCanvasPyramid3dPicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasPyramid3dPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/pyramid3d-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/pyramid3d-picker.ts index 9e9000b13..6d43cdc24 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/pyramid3d-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/pyramid3d-picker.ts @@ -1,4 +1,4 @@ -import { application, Pyramid3dRender, PYRAMID3D_NUMBER_TYPE } from '@visactor/vrender-core'; +import { serviceRegistry, contributionRegistry, Pyramid3dRender, PYRAMID3D_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IPyramid3d, IGraphicRender, IGraphicPicker } from '@visactor/vrender-core'; import { Base3dPicker } from '../common/base-3d-picker'; @@ -11,9 +11,9 @@ export class DefaultCanvasPyramid3dPicker extends Base3dPicker imple constructor() { super(); try { - this.canvasRenderer = application.services.get(Pyramid3dRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(Pyramid3dRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(Pyramid3dRender)[0]; + this.canvasRenderer = contributionRegistry.get(Pyramid3dRender)[0]; } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/rect-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/rect-module.ts index 9ce999959..bcd5e085c 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/rect-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/rect-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasRectPicker } from './rect-picker'; @@ -8,5 +8,5 @@ export function registerCanvasRectPicker() { return; } _registeredRect = true; - application.contributions.register(CanvasPickerContribution, new DefaultCanvasRectPicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasRectPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/rect-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/rect-picker.ts index a310e9a25..2b3764773 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/rect-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/rect-picker.ts @@ -1,11 +1,11 @@ -import { application, RectRender } from '@visactor/vrender-core'; +import { contributionRegistry, RectRender } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { RectPickerBase } from '../common/rect-picker-base'; export class DefaultCanvasRectPicker extends RectPickerBase implements IGraphicPicker { constructor() { super(); - const render = application.contributions.get(RectRender)[0]; + const render = contributionRegistry.get(RectRender)[0]; this.canvasRenderer = render; } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/rect3d-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/rect3d-module.ts index d4e8d709a..291f60237 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/rect3d-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/rect3d-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { CanvasPickerContribution } from '../constants'; import { DefaultCanvasRect3dPicker } from './rect3d-picker'; @@ -8,5 +8,5 @@ export function registerCanvasRect3dPicker() { return; } _registeredRect3d = true; - application.contributions.register(CanvasPickerContribution, new DefaultCanvasRect3dPicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasRect3dPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/rect3d-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/rect3d-picker.ts index 3f30d175e..6adc9e09f 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/rect3d-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/rect3d-picker.ts @@ -1,4 +1,4 @@ -import { application, Rect3DRender, RECT3D_NUMBER_TYPE } from '@visactor/vrender-core'; +import { serviceRegistry, contributionRegistry, Rect3DRender, RECT3D_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IRect3d, IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { Base3dPicker } from '../common/base-3d-picker'; @@ -10,9 +10,9 @@ export class DefaultCanvasRect3dPicker extends Base3dPicker implements constructor() { super(); try { - this.canvasRenderer = application.services.get(Rect3DRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(Rect3DRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(Rect3DRender)[0]; + this.canvasRenderer = contributionRegistry.get(Rect3DRender)[0]; } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/richtext-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/richtext-module.ts index 40962a298..e4072b82b 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/richtext-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/richtext-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { CanvasPickerContribution, CanvasRichTextPicker } from '../constants'; import { DefaultCanvasRichTextPicker } from './richtext-picker'; @@ -8,5 +8,5 @@ export function registerCanvasRichtextPicker() { return; } loadRichtextPick = true; - application.contributions.register(CanvasPickerContribution, new DefaultCanvasRichTextPicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasRichTextPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/richtext-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/richtext-picker.ts index c1d05fd2e..26ff73dd4 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/richtext-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/richtext-picker.ts @@ -1,5 +1,5 @@ import type { IPoint } from '@visactor/vutils'; -import { application, RICHTEXT_NUMBER_TYPE, RichTextRender } from '@visactor/vrender-core'; +import { serviceRegistry, contributionRegistry, RICHTEXT_NUMBER_TYPE, RichTextRender } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender, IPickParams, IRichText } from '@visactor/vrender-core'; export class DefaultCanvasRichTextPicker implements IGraphicPicker { type: string = 'richtext'; @@ -7,9 +7,9 @@ export class DefaultCanvasRichTextPicker implements IGraphicPicker { constructor() { try { - (this as any).canvasRenderer = application.services.get(RichTextRender) as IGraphicRender; + (this as any).canvasRenderer = serviceRegistry.get(RichTextRender) as IGraphicRender; } catch (_) { - (this as any).canvasRenderer = application.contributions.get(RichTextRender)[0]; + (this as any).canvasRenderer = contributionRegistry.get(RichTextRender)[0]; } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/star-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/star-module.ts index acc01b3c8..d645b839b 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/star-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/star-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { CanvasPickerContribution, CanvasStarPicker } from '../constants'; import { DefaultCanvasStarPicker } from './star-picker'; @@ -8,5 +8,5 @@ export function registerCanvasStarPicker() { return; } loadStarPick = true; - application.contributions.register(CanvasPickerContribution, new DefaultCanvasStarPicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasStarPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/star-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/star-picker.ts index 2e658baad..616665e65 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/star-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/star-picker.ts @@ -1,4 +1,4 @@ -import { StarRender, STAR_NUMBER_TYPE, application } from '@visactor/vrender-core'; +import { serviceRegistry, StarRender, STAR_NUMBER_TYPE, contributionRegistry } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; @@ -9,9 +9,9 @@ export class DefaultCanvasStarPicker extends PickerBase implements IGraphicPicke constructor() { super(); try { - this.canvasRenderer = application.services.get(StarRender); + this.canvasRenderer = serviceRegistry.get(StarRender); } catch (_) { - this.canvasRenderer = application.contributions.get(StarRender)[0]; + this.canvasRenderer = contributionRegistry.get(StarRender)[0]; } } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/symbol-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/symbol-module.ts index 849abc449..be8138a9c 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/symbol-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/symbol-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { CanvasPickerContribution, CanvasSymbolPicker } from '../constants'; import { DefaultCanvasSymbolPicker } from './symbol-picker'; @@ -8,5 +8,5 @@ export function registerCanvasSymbolPicker() { return; } loadSymbolPick = true; - application.contributions.register(CanvasPickerContribution, new DefaultCanvasSymbolPicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasSymbolPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/symbol-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/symbol-picker.ts index c3bf0929e..867a21c26 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/symbol-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/symbol-picker.ts @@ -1,4 +1,11 @@ -import { SymbolRender, mat4Allocate, getScaledStroke, SYMBOL_NUMBER_TYPE, application } from '@visactor/vrender-core'; +import { + serviceRegistry, + SymbolRender, + mat4Allocate, + getScaledStroke, + SYMBOL_NUMBER_TYPE, + contributionRegistry +} from '@visactor/vrender-core'; import type { IPoint } from '@visactor/vutils'; import type { IGraphicAttribute, @@ -19,9 +26,9 @@ export class DefaultCanvasSymbolPicker extends Base3dPicker implements constructor() { super(); try { - this.canvasRenderer = application.services.get(SymbolRender); + this.canvasRenderer = serviceRegistry.get(SymbolRender); } catch (_) { - this.canvasRenderer = application.contributions.get(SymbolRender)[0]; + this.canvasRenderer = contributionRegistry.get(SymbolRender)[0]; } } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/text-module.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/text-module.ts index 72adcd351..a2b4b87c4 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/text-module.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/text-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { CanvasPickerContribution, CanvasTextPicker } from '../constants'; import { DefaultCanvasTextPicker } from './text-picker'; @@ -9,5 +9,5 @@ export function registerCanvasTextPicker() { } _registeredText = true; // Register picker implementation in contribution registry - application.contributions.register(CanvasPickerContribution, new DefaultCanvasTextPicker()); + contributionRegistry.register(CanvasPickerContribution, new DefaultCanvasTextPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/canvas-picker/text-picker.ts b/packages/vrender-kits/src/picker/contributions/canvas-picker/text-picker.ts index a224c09de..e9753d879 100644 --- a/packages/vrender-kits/src/picker/contributions/canvas-picker/text-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/canvas-picker/text-picker.ts @@ -5,7 +5,7 @@ import { textLayoutOffsetY, mat4Allocate, TEXT_NUMBER_TYPE, - application + contributionRegistry } from '@visactor/vrender-core'; import type { IPoint } from '@visactor/vutils'; import type { @@ -29,7 +29,7 @@ export class DefaultCanvasTextPicker extends Base3dPicker implements IGra // text picker depends on TextRender via registry // TextRender is a token exported by core // Select first registered contribution - const render = application.contributions.get(TextRender)[0]; + const render = contributionRegistry.get(TextRender)[0]; this.canvasRenderer = render; } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/arc-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/arc-module.ts index 94fa662b8..48046c853 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/arc-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/arc-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { DefaultMathArcPicker } from './arc-picker'; import { MathPickerContribution } from '../constants'; @@ -8,5 +8,5 @@ export function registerMathArcPicker() { return; } _registered = true; - application.contributions.register(MathPickerContribution, new DefaultMathArcPicker()); + contributionRegistry.register(MathPickerContribution, new DefaultMathArcPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/arc-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/arc-picker.ts index fff068bd9..f1e22f571 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/arc-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/arc-picker.ts @@ -1,4 +1,4 @@ -import { application, ArcRender, ARC_NUMBER_TYPE } from '@visactor/vrender-core'; +import { serviceRegistry, contributionRegistry, ArcRender, ARC_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; @@ -9,9 +9,9 @@ export class DefaultMathArcPicker extends PickerBase implements IGraphicPicker { constructor() { super(); try { - this.canvasRenderer = application.services.get(ArcRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(ArcRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(ArcRender)[0]; + this.canvasRenderer = contributionRegistry.get(ArcRender)[0]; } } } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/area-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/area-module.ts index 53ca6ff81..bbe126ebb 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/area-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/area-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { MathPickerContribution } from '../constants'; import { DefaultMathAreaPicker } from './area-picker'; @@ -8,5 +8,5 @@ export function registerMathAreaPicker() { return; } _registered = true; - application.contributions.register(MathPickerContribution, new DefaultMathAreaPicker()); + contributionRegistry.register(MathPickerContribution, new DefaultMathAreaPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/area-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/area-picker.ts index 502ccf987..59b73f75b 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/area-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/area-picker.ts @@ -1,4 +1,4 @@ -import { application, AreaRender, AREA_NUMBER_TYPE } from '@visactor/vrender-core'; +import { serviceRegistry, contributionRegistry, AreaRender, AREA_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; @@ -10,9 +10,9 @@ export class DefaultMathAreaPicker extends PickerBase implements IGraphicPicker constructor() { super(); try { - this.canvasRenderer = application.services.get(AreaRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(AreaRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(AreaRender)[0]; + this.canvasRenderer = contributionRegistry.get(AreaRender)[0]; } } } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/circle-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/circle-module.ts index 26d04e583..febe8a227 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/circle-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/circle-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { MathPickerContribution } from '../constants'; import { DefaultMathCirclePicker } from './circle-picker'; @@ -8,5 +8,5 @@ export function registerMathCirclePicker() { return; } _registered = true; - application.contributions.register(MathPickerContribution, new DefaultMathCirclePicker()); + contributionRegistry.register(MathPickerContribution, new DefaultMathCirclePicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/circle-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/circle-picker.ts index 474de270c..52665e315 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/circle-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/circle-picker.ts @@ -1,4 +1,4 @@ -import { application, CircleRender, CIRCLE_NUMBER_TYPE } from '@visactor/vrender-core'; +import { serviceRegistry, contributionRegistry, CircleRender, CIRCLE_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; @@ -8,9 +8,9 @@ export class DefaultMathCirclePicker extends PickerBase implements IGraphicPicke constructor() { super(); try { - this.canvasRenderer = application.services.get(CircleRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(CircleRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(CircleRender)[0]; + this.canvasRenderer = contributionRegistry.get(CircleRender)[0]; } } } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/glyph-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/glyph-module.ts index b867f64e0..51e1f45d0 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/glyph-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/glyph-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { MathPickerContribution } from '../constants'; import { DefaultMathGlyphPicker } from './glyph-picker'; @@ -8,5 +8,5 @@ export function registerMathGlyphPicker() { return; } _registered = true; - application.contributions.register(MathPickerContribution, new DefaultMathGlyphPicker()); + contributionRegistry.register(MathPickerContribution, new DefaultMathGlyphPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/glyph-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/glyph-picker.ts index 8d0b37cf1..f3909b056 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/glyph-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/glyph-picker.ts @@ -1,4 +1,4 @@ -import { application, GlyphRender } from '@visactor/vrender-core'; +import { serviceRegistry, contributionRegistry, GlyphRender } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { GlyphPickerBase } from '../common/glyph-picker-base'; @@ -6,9 +6,9 @@ export class DefaultMathGlyphPicker extends GlyphPickerBase implements IGraphicP constructor() { super(); try { - this.canvasRenderer = application.services.get(GlyphRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(GlyphRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(GlyphRender)[0]; + this.canvasRenderer = contributionRegistry.get(GlyphRender)[0]; } } } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/image-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/image-module.ts index 8b435fd9d..728a8b5e3 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/image-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/image-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { MathPickerContribution } from '../constants'; import { DefaultMathImagePicker } from './image-picker'; @@ -8,5 +8,5 @@ export function registerMathImagePicker() { return; } _registered = true; - application.contributions.register(MathPickerContribution, new DefaultMathImagePicker()); + contributionRegistry.register(MathPickerContribution, new DefaultMathImagePicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/line-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/line-module.ts index 3c5ea7d02..4287df352 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/line-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/line-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { MathPickerContribution } from '../constants'; import { DefaultMathLinePicker } from './line-picker'; @@ -8,5 +8,5 @@ export function registerMathLinePicker() { return; } _registered = true; - application.contributions.register(MathPickerContribution, new DefaultMathLinePicker()); + contributionRegistry.register(MathPickerContribution, new DefaultMathLinePicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/line-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/line-picker.ts index 38b643e0a..d2ce719f2 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/line-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/line-picker.ts @@ -1,4 +1,4 @@ -import { LineRender, LINE_NUMBER_TYPE, application } from '@visactor/vrender-core'; +import { serviceRegistry, LineRender, LINE_NUMBER_TYPE, contributionRegistry } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; export class DefaultMathLinePicker extends PickerBase implements IGraphicPicker { @@ -9,10 +9,10 @@ export class DefaultMathLinePicker extends PickerBase implements IGraphicPicker super(); // Acquire renderer via services (no inversify) try { - this.canvasRenderer = application.services.get(LineRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(LineRender) as IGraphicRender; } catch (_) { // fallback to contributions if services not registered yet - this.canvasRenderer = application.contributions.get(LineRender)[0]; + this.canvasRenderer = contributionRegistry.get(LineRender)[0]; } } // numberType?: number = LINE_NUMBER_TYPE; diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/path-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/path-module.ts index 97a7560a3..02030a085 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/path-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/path-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { MathPickerContribution } from '../constants'; import { DefaultMathPathPicker } from './path-picker'; @@ -8,5 +8,5 @@ export function registerMathPathPicker() { return; } _registered = true; - application.contributions.register(MathPickerContribution, new DefaultMathPathPicker()); + contributionRegistry.register(MathPickerContribution, new DefaultMathPathPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/path-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/path-picker.ts index 2ab9a8c83..262b442a5 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/path-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/path-picker.ts @@ -1,4 +1,4 @@ -import { application, PathRender, PATH_NUMBER_TYPE } from '@visactor/vrender-core'; +import { serviceRegistry, contributionRegistry, PathRender, PATH_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; @@ -9,9 +9,9 @@ export class DefaultMathPathPicker extends PickerBase implements IGraphicPicker constructor() { super(); try { - this.canvasRenderer = application.services.get(PathRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(PathRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(PathRender)[0]; + this.canvasRenderer = contributionRegistry.get(PathRender)[0]; } } } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/polygon-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/polygon-module.ts index 9ef297437..7440a71d2 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/polygon-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/polygon-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { MathPickerContribution } from '../constants'; import { DefaultMathPolygonPicker } from './polygon-picker'; @@ -8,5 +8,5 @@ export function registerMathPolygonPicker() { return; } _registered = true; - application.contributions.register(MathPickerContribution, new DefaultMathPolygonPicker()); + contributionRegistry.register(MathPickerContribution, new DefaultMathPolygonPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/polygon-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/polygon-picker.ts index 79bfe4938..8b306e0bf 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/polygon-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/polygon-picker.ts @@ -1,4 +1,4 @@ -import { application, PolygonRender, POLYGON_NUMBER_TYPE } from '@visactor/vrender-core'; +import { serviceRegistry, contributionRegistry, PolygonRender, POLYGON_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; @@ -9,9 +9,9 @@ export class DefaultMathPolygonPicker extends PickerBase implements IGraphicPick constructor() { super(); try { - this.canvasRenderer = application.services.get(PolygonRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(PolygonRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(PolygonRender)[0]; + this.canvasRenderer = contributionRegistry.get(PolygonRender)[0]; } } } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/rect-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/rect-module.ts index 8fa04f346..a9a2d4c19 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/rect-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/rect-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { MathPickerContribution } from '../constants'; import { DefaultMathRectPicker } from './rect-picker'; @@ -8,5 +8,5 @@ export function registerMathRectPicker() { return; } _registered = true; - application.contributions.register(MathPickerContribution, new DefaultMathRectPicker()); + contributionRegistry.register(MathPickerContribution, new DefaultMathRectPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/rect-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/rect-picker.ts index e49942eea..055c7ed38 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/rect-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/rect-picker.ts @@ -1,4 +1,4 @@ -import { application, RectRender } from '@visactor/vrender-core'; +import { serviceRegistry, contributionRegistry, RectRender } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { RectPickerBase } from '../common/rect-picker-base'; @@ -6,9 +6,9 @@ export class DefaultMathRectPicker extends RectPickerBase implements IGraphicPic constructor() { super(); try { - this.canvasRenderer = application.services.get(RectRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(RectRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(RectRender)[0]; + this.canvasRenderer = contributionRegistry.get(RectRender)[0]; } } } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/richtext-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/richtext-module.ts index 2f821183f..befd815b1 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/richtext-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/richtext-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { MathPickerContribution } from '../constants'; import { DefaultMathRichTextPicker } from './richtext-picker'; @@ -8,5 +8,5 @@ export function registerMathRichTextPicker() { return; } _registered = true; - application.contributions.register(MathPickerContribution, new DefaultMathRichTextPicker()); + contributionRegistry.register(MathPickerContribution, new DefaultMathRichTextPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/richtext-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/richtext-picker.ts index 306281acb..cc7a5b1ea 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/richtext-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/richtext-picker.ts @@ -1,5 +1,5 @@ import type { IPoint } from '@visactor/vutils'; -import { application, RICHTEXT_NUMBER_TYPE, RichTextRender } from '@visactor/vrender-core'; +import { serviceRegistry, contributionRegistry, RICHTEXT_NUMBER_TYPE, RichTextRender } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender, IPickParams, IRichText } from '@visactor/vrender-core'; export class DefaultMathRichTextPicker implements IGraphicPicker { type: string = 'richtext'; @@ -7,9 +7,9 @@ export class DefaultMathRichTextPicker implements IGraphicPicker { constructor() { try { - (this as any).canvasRenderer = application.services.get(RichTextRender) as IGraphicRender; + (this as any).canvasRenderer = serviceRegistry.get(RichTextRender) as IGraphicRender; } catch (_) { - (this as any).canvasRenderer = application.contributions.get(RichTextRender)[0]; + (this as any).canvasRenderer = contributionRegistry.get(RichTextRender)[0]; } } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/symbol-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/symbol-module.ts index 9402f9e6a..afb1cdf8a 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/symbol-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/symbol-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { MathPickerContribution } from '../constants'; import { DefaultMathSymbolPicker } from './symbol-picker'; @@ -8,5 +8,5 @@ export function registerMathSymbolPicker() { return; } _registered = true; - application.contributions.register(MathPickerContribution, new DefaultMathSymbolPicker()); + contributionRegistry.register(MathPickerContribution, new DefaultMathSymbolPicker()); } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/symbol-picker.ts b/packages/vrender-kits/src/picker/contributions/math-picker/symbol-picker.ts index 5ba729229..02adb5b0d 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/symbol-picker.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/symbol-picker.ts @@ -1,4 +1,4 @@ -import { application, SymbolRender, SYMBOL_NUMBER_TYPE } from '@visactor/vrender-core'; +import { serviceRegistry, contributionRegistry, SymbolRender, SYMBOL_NUMBER_TYPE } from '@visactor/vrender-core'; import type { IGraphicPicker, IGraphicRender } from '@visactor/vrender-core'; import { PickerBase } from '../common/base'; @@ -10,9 +10,9 @@ export class DefaultMathSymbolPicker extends PickerBase implements IGraphicPicke constructor() { super(); try { - this.canvasRenderer = application.services.get(SymbolRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(SymbolRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(SymbolRender)[0]; + this.canvasRenderer = contributionRegistry.get(SymbolRender)[0]; } } } diff --git a/packages/vrender-kits/src/picker/contributions/math-picker/text-module.ts b/packages/vrender-kits/src/picker/contributions/math-picker/text-module.ts index 99e9cb3c6..dd03f62a9 100644 --- a/packages/vrender-kits/src/picker/contributions/math-picker/text-module.ts +++ b/packages/vrender-kits/src/picker/contributions/math-picker/text-module.ts @@ -1,4 +1,4 @@ -import { application } from '@visactor/vrender-core'; +import { contributionRegistry } from '@visactor/vrender-core'; import { MathPickerContribution } from '../constants'; import { DefaultMathTextPicker } from './text-picker'; @@ -8,5 +8,5 @@ export function registerMathTextPicker() { return; } _registered = true; - application.contributions.register(MathPickerContribution, new DefaultMathTextPicker()); + contributionRegistry.register(MathPickerContribution, new DefaultMathTextPicker()); } diff --git a/packages/vrender-kits/src/picker/math-module.ts b/packages/vrender-kits/src/picker/math-module.ts index 3db4fb23e..a29d419fd 100644 --- a/packages/vrender-kits/src/picker/math-module.ts +++ b/packages/vrender-kits/src/picker/math-module.ts @@ -1,4 +1,4 @@ -import { application, PickerService } from '@visactor/vrender-core'; +import { serviceRegistry, PickerService } from '@visactor/vrender-core'; import { DefaultMathPickerService } from './math-picker-service'; export function registerMathPickerService() { @@ -7,5 +7,5 @@ export function registerMathPickerService() { } (registerMathPickerService as any).__loaded = true; // Override PickerService to use math-based service (no canvas) - application.services.registerSingletonFactory(PickerService, () => new DefaultMathPickerService()); + serviceRegistry.registerSingletonFactory(PickerService, () => new DefaultMathPickerService()); } diff --git a/packages/vrender-kits/src/picker/math-picker-service.ts b/packages/vrender-kits/src/picker/math-picker-service.ts index d8448729c..5ff20189c 100644 --- a/packages/vrender-kits/src/picker/math-picker-service.ts +++ b/packages/vrender-kits/src/picker/math-picker-service.ts @@ -1,6 +1,7 @@ import type { IMatrix, IPointLike } from '@visactor/vutils'; import { DefaultPickService, + contributionRegistry, EmptyContext2d, type ICanvas, type IContext2d, @@ -11,8 +12,7 @@ import { type IPickerService, type IContributionProvider, type IPickParams, - type PickResult, - application + type PickResult } from '@visactor/vrender-core'; import { MathPickerContribution } from './contributions/constants'; @@ -30,7 +30,7 @@ export class DefaultMathPickerService extends DefaultPickService implements IPic constructor() { super(); this.contributions = { - getContributions: () => application.contributions.get(MathPickerContribution) + getContributions: () => contributionRegistry.get(MathPickerContribution) } as IContributionProvider; this.global.hooks.onSetEnv.tap('math-picker-service', (lastEnv, env, global) => { diff --git a/packages/vrender-kits/src/render/contributions/canvas/gif-image-module.ts b/packages/vrender-kits/src/render/contributions/canvas/gif-image-module.ts index 2a376d00b..1da8851b4 100644 --- a/packages/vrender-kits/src/render/contributions/canvas/gif-image-module.ts +++ b/packages/vrender-kits/src/render/contributions/canvas/gif-image-module.ts @@ -1,4 +1,4 @@ -import { application, GraphicRender } from '@visactor/vrender-core'; +import { contributionRegistry, GraphicRender } from '@visactor/vrender-core'; import { DefaultCanvasGifImageRender } from './gif-image-render'; let _registered = false; @@ -7,5 +7,5 @@ export function registerCanvasGifImageRender() { return; } _registered = true; - application.contributions.register(GraphicRender, new DefaultCanvasGifImageRender()); + contributionRegistry.register(GraphicRender, new DefaultCanvasGifImageRender()); } diff --git a/packages/vrender-kits/src/render/contributions/canvas/lottie-module.ts b/packages/vrender-kits/src/render/contributions/canvas/lottie-module.ts index fa066578e..2db3509a3 100644 --- a/packages/vrender-kits/src/render/contributions/canvas/lottie-module.ts +++ b/packages/vrender-kits/src/render/contributions/canvas/lottie-module.ts @@ -1,4 +1,4 @@ -import { application, GraphicRender } from '@visactor/vrender-core'; +import { serviceRegistry, contributionRegistry, GraphicRender } from '@visactor/vrender-core'; import { DefaultCanvasLottieRender } from './lottie-render'; let _registered = false; @@ -8,6 +8,6 @@ export function registerCanvasLottieRender() { } _registered = true; const render = new DefaultCanvasLottieRender(); - application.services.registerSingleton(GraphicRender, render); - application.contributions.register(GraphicRender, render); + serviceRegistry.registerSingleton(GraphicRender, render); + contributionRegistry.register(GraphicRender, render); } diff --git a/packages/vrender-kits/src/render/contributions/rough/module.ts b/packages/vrender-kits/src/render/contributions/rough/module.ts index 026d19781..b5b33cc45 100644 --- a/packages/vrender-kits/src/render/contributions/rough/module.ts +++ b/packages/vrender-kits/src/render/contributions/rough/module.ts @@ -1,4 +1,4 @@ -import { application, GraphicRender } from '@visactor/vrender-core'; +import { contributionRegistry, GraphicRender } from '@visactor/vrender-core'; import { RoughCanvasArcRender } from './rough-arc'; import { RoughCanvasAreaRender } from './rough-area'; import { RoughCanvasCircleRender } from './rough-circle'; @@ -23,6 +23,6 @@ export function registerRoughCanvasRenders() { new RoughCanvasArcRender() ]; for (const render of renders) { - application.contributions.register(GraphicRender, render); + contributionRegistry.register(GraphicRender, render); } } diff --git a/packages/vrender-kits/src/render/contributions/rough/rough-arc.ts b/packages/vrender-kits/src/render/contributions/rough/rough-arc.ts index 6238c2857..a7867e020 100644 --- a/packages/vrender-kits/src/render/contributions/rough/rough-arc.ts +++ b/packages/vrender-kits/src/render/contributions/rough/rough-arc.ts @@ -16,7 +16,8 @@ import { getTheme, CustomPath2D, drawArcPath, - application + serviceRegistry, + contributionRegistry } from '@visactor/vrender-core'; import rough from 'roughjs'; import { defaultRouthThemeSpec } from './config'; @@ -30,9 +31,9 @@ export class RoughCanvasArcRender extends RoughBaseRender implements IGraphicRen constructor() { super(); try { - this.canvasRenderer = application.services.get(DefaultCanvasArcRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(DefaultCanvasArcRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(DefaultCanvasArcRender)[0]; + this.canvasRenderer = contributionRegistry.get(DefaultCanvasArcRender)[0]; } this.type = 'arc'; this.numberType = ARC_NUMBER_TYPE; diff --git a/packages/vrender-kits/src/render/contributions/rough/rough-circle.ts b/packages/vrender-kits/src/render/contributions/rough/rough-circle.ts index ebbba72b0..12a2b460a 100644 --- a/packages/vrender-kits/src/render/contributions/rough/rough-circle.ts +++ b/packages/vrender-kits/src/render/contributions/rough/rough-circle.ts @@ -5,7 +5,13 @@ import type { IDrawContext, IGraphicRenderDrawParams } from '@visactor/vrender-core'; -import { CIRCLE_NUMBER_TYPE, DefaultCanvasCircleRender, getTheme, application } from '@visactor/vrender-core'; +import { + CIRCLE_NUMBER_TYPE, + DefaultCanvasCircleRender, + getTheme, + serviceRegistry, + contributionRegistry +} from '@visactor/vrender-core'; import rough from 'roughjs'; import { RoughBaseRender } from './base-render'; @@ -17,9 +23,9 @@ export class RoughCanvasCircleRender extends RoughBaseRender implements IGraphic constructor() { super(); try { - this.canvasRenderer = application.services.get(DefaultCanvasCircleRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(DefaultCanvasCircleRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(DefaultCanvasCircleRender)[0]; + this.canvasRenderer = contributionRegistry.get(DefaultCanvasCircleRender)[0]; } this.type = 'circle'; this.numberType = CIRCLE_NUMBER_TYPE; diff --git a/packages/vrender-kits/src/render/contributions/rough/rough-line.ts b/packages/vrender-kits/src/render/contributions/rough/rough-line.ts index 9aa3d3706..50c7f3ee6 100644 --- a/packages/vrender-kits/src/render/contributions/rough/rough-line.ts +++ b/packages/vrender-kits/src/render/contributions/rough/rough-line.ts @@ -12,7 +12,12 @@ import type { IGraphicRenderDrawParams, IRenderService } from '@visactor/vrender-core'; -import { DefaultCanvasLineRender, LINE_NUMBER_TYPE, application } from '@visactor/vrender-core'; +import { + DefaultCanvasLineRender, + LINE_NUMBER_TYPE, + serviceRegistry, + contributionRegistry +} from '@visactor/vrender-core'; import { RoughBaseRender } from './base-render'; export class RoughCanvasLineRender extends RoughBaseRender implements IGraphicRender { @@ -25,9 +30,9 @@ export class RoughCanvasLineRender extends RoughBaseRender implements IGraphicRe this.type = 'line'; this.numberType = LINE_NUMBER_TYPE; try { - this.canvasRenderer = application.services.get(DefaultCanvasLineRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(DefaultCanvasLineRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(DefaultCanvasLineRender)[0]; + this.canvasRenderer = contributionRegistry.get(DefaultCanvasLineRender)[0]; } } diff --git a/packages/vrender-kits/src/render/contributions/rough/rough-path.ts b/packages/vrender-kits/src/render/contributions/rough/rough-path.ts index 8c3649a3c..7c94fbfc8 100644 --- a/packages/vrender-kits/src/render/contributions/rough/rough-path.ts +++ b/packages/vrender-kits/src/render/contributions/rough/rough-path.ts @@ -5,7 +5,13 @@ import type { IDrawContext, IGraphicRenderDrawParams } from '@visactor/vrender-core'; -import { PATH_NUMBER_TYPE, DefaultCanvasPathRender, getTheme, application } from '@visactor/vrender-core'; +import { + PATH_NUMBER_TYPE, + DefaultCanvasPathRender, + getTheme, + serviceRegistry, + contributionRegistry +} from '@visactor/vrender-core'; import rough from 'roughjs'; import { defaultRouthThemeSpec } from './config'; import { RoughBaseRender } from './base-render'; @@ -18,9 +24,9 @@ export class RoughCanvasPathRender extends RoughBaseRender implements IGraphicRe constructor() { super(); try { - this.canvasRenderer = application.services.get(DefaultCanvasPathRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(DefaultCanvasPathRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(DefaultCanvasPathRender)[0]; + this.canvasRenderer = contributionRegistry.get(DefaultCanvasPathRender)[0]; } this.type = 'path'; this.numberType = PATH_NUMBER_TYPE; diff --git a/packages/vrender-kits/src/render/contributions/rough/rough-rect.ts b/packages/vrender-kits/src/render/contributions/rough/rough-rect.ts index 70dcf90b6..8b5b23d73 100644 --- a/packages/vrender-kits/src/render/contributions/rough/rough-rect.ts +++ b/packages/vrender-kits/src/render/contributions/rough/rough-rect.ts @@ -6,7 +6,8 @@ import { type IGraphicRenderDrawParams, RECT_NUMBER_TYPE, DefaultCanvasRectRender, - application, + serviceRegistry, + contributionRegistry, CustomPath2D } from '@visactor/vrender-core'; @@ -23,9 +24,9 @@ export class RoughCanvasRectRender extends RoughBaseRender implements IGraphicRe constructor() { super(); try { - this.canvasRenderer = application.services.get(DefaultCanvasRectRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(DefaultCanvasRectRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(DefaultCanvasRectRender)[0]; + this.canvasRenderer = contributionRegistry.get(DefaultCanvasRectRender)[0]; } this.type = 'rect'; this.numberType = RECT_NUMBER_TYPE; diff --git a/packages/vrender-kits/src/render/contributions/rough/rough-symbol.ts b/packages/vrender-kits/src/render/contributions/rough/rough-symbol.ts index 22d5adc85..5cf004511 100644 --- a/packages/vrender-kits/src/render/contributions/rough/rough-symbol.ts +++ b/packages/vrender-kits/src/render/contributions/rough/rough-symbol.ts @@ -16,7 +16,8 @@ import { BaseRender, getTheme, CustomPath2D, - application + serviceRegistry, + contributionRegistry } from '@visactor/vrender-core'; import rough from 'roughjs'; import { defaultRouthThemeSpec } from './config'; @@ -31,9 +32,9 @@ export class RoughCanvasSymbolRender extends RoughBaseRender implements IGraphic constructor() { super(); try { - this.canvasRenderer = application.services.get(DefaultCanvasSymbolRender) as IGraphicRender; + this.canvasRenderer = serviceRegistry.get(DefaultCanvasSymbolRender) as IGraphicRender; } catch (_) { - this.canvasRenderer = application.contributions.get(DefaultCanvasSymbolRender)[0]; + this.canvasRenderer = contributionRegistry.get(DefaultCanvasSymbolRender)[0]; } this.type = 'symbol'; this.numberType = SYMBOL_NUMBER_TYPE; diff --git a/packages/vrender-kits/src/window/contributions/browser-contribution.ts b/packages/vrender-kits/src/window/contributions/browser-contribution.ts index de8143bc6..d6978033f 100644 --- a/packages/vrender-kits/src/window/contributions/browser-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/browser-contribution.ts @@ -1,4 +1,4 @@ -import { Generator, BaseWindowHandlerContribution, application } from '@visactor/vrender-core'; +import { Generator, BaseWindowHandlerContribution, vglobal } from '@visactor/vrender-core'; import type { IContext2d, ICanvas, @@ -43,7 +43,7 @@ export class BrowserWindowHandlerContribution constructor() { super(); this._canvasIsIntersecting = true; - this.global = application.global; + this.global = vglobal; this.viewBox = new AABBBounds(); this.modelMatrix = new Matrix(1, 0, 0, 1, 0, 0); } diff --git a/packages/vrender-kits/src/window/contributions/feishu-contribution.ts b/packages/vrender-kits/src/window/contributions/feishu-contribution.ts index 8ad143d33..ce14383d1 100644 --- a/packages/vrender-kits/src/window/contributions/feishu-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/feishu-contribution.ts @@ -1,4 +1,4 @@ -import { Generator, BaseWindowHandlerContribution, application } from '@visactor/vrender-core'; +import { Generator, BaseWindowHandlerContribution, vglobal } from '@visactor/vrender-core'; import type { EnvType, IGlobal, @@ -57,7 +57,7 @@ export class FeishuWindowHandlerContribution constructor() { super(); - this.global = application.global; + this.global = vglobal; } getTitle(): string { diff --git a/packages/vrender-kits/src/window/contributions/harmony-contribution.ts b/packages/vrender-kits/src/window/contributions/harmony-contribution.ts index 1771cf1a1..cb62cbf9f 100644 --- a/packages/vrender-kits/src/window/contributions/harmony-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/harmony-contribution.ts @@ -1,4 +1,4 @@ -import { Generator, BaseWindowHandlerContribution, application } from '@visactor/vrender-core'; +import { Generator, BaseWindowHandlerContribution, vglobal } from '@visactor/vrender-core'; import type { EnvType, IGlobal, @@ -56,7 +56,7 @@ export class HarmonyWindowHandlerContribution constructor() { super(); - this.global = application.global; + this.global = vglobal; } getTitle(): string { diff --git a/packages/vrender-kits/src/window/contributions/lynx-contribution.ts b/packages/vrender-kits/src/window/contributions/lynx-contribution.ts index 6d5da51fb..f972464ef 100644 --- a/packages/vrender-kits/src/window/contributions/lynx-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/lynx-contribution.ts @@ -1,4 +1,4 @@ -import { Generator, BaseWindowHandlerContribution, application } from '@visactor/vrender-core'; +import { Generator, BaseWindowHandlerContribution, vglobal } from '@visactor/vrender-core'; import type { EnvType, IGlobal, @@ -54,7 +54,7 @@ export class LynxWindowHandlerContribution extends BaseWindowHandlerContribution constructor() { super(); - this.global = application.global; + this.global = vglobal; } getTitle(): string { diff --git a/packages/vrender-kits/src/window/contributions/node-contribution.ts b/packages/vrender-kits/src/window/contributions/node-contribution.ts index acad696ac..9f0056840 100644 --- a/packages/vrender-kits/src/window/contributions/node-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/node-contribution.ts @@ -1,4 +1,4 @@ -import { Generator, BaseWindowHandlerContribution, application } from '@visactor/vrender-core'; +import { Generator, BaseWindowHandlerContribution, vglobal } from '@visactor/vrender-core'; import type { IBoundsLike } from '@visactor/vutils'; import type { EnvType, @@ -24,7 +24,7 @@ export class NodeWindowHandlerContribution extends BaseWindowHandlerContribution constructor() { super(); - this.global = application.global; + this.global = vglobal; } getTitle(): string { diff --git a/packages/vrender-kits/src/window/contributions/taro-contribution.ts b/packages/vrender-kits/src/window/contributions/taro-contribution.ts index 29c60ff97..0911cecc0 100644 --- a/packages/vrender-kits/src/window/contributions/taro-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/taro-contribution.ts @@ -1,4 +1,4 @@ -import { Generator, BaseWindowHandlerContribution, application } from '@visactor/vrender-core'; +import { Generator, BaseWindowHandlerContribution, vglobal } from '@visactor/vrender-core'; import type { EnvType, IGlobal, @@ -54,7 +54,7 @@ export class TaroWindowHandlerContribution extends BaseWindowHandlerContribution constructor() { super(); - this.global = application.global; + this.global = vglobal; } getTitle(): string { diff --git a/packages/vrender-kits/src/window/contributions/tt-contribution.ts b/packages/vrender-kits/src/window/contributions/tt-contribution.ts index 6b54b40a3..8f240f949 100644 --- a/packages/vrender-kits/src/window/contributions/tt-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/tt-contribution.ts @@ -1,4 +1,4 @@ -import { Generator, BaseWindowHandlerContribution, application } from '@visactor/vrender-core'; +import { Generator, BaseWindowHandlerContribution, vglobal } from '@visactor/vrender-core'; import type { EnvType, IGlobal, @@ -54,7 +54,7 @@ export class TTWindowHandlerContribution extends BaseWindowHandlerContribution i constructor() { super(); - this.global = application.global; + this.global = vglobal; } getTitle(): string { diff --git a/packages/vrender-kits/src/window/contributions/wx-contribution.ts b/packages/vrender-kits/src/window/contributions/wx-contribution.ts index 2b2fc34ec..51035a0c2 100644 --- a/packages/vrender-kits/src/window/contributions/wx-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/wx-contribution.ts @@ -1,4 +1,4 @@ -import { Generator, BaseWindowHandlerContribution, application } from '@visactor/vrender-core'; +import { Generator, BaseWindowHandlerContribution, vglobal } from '@visactor/vrender-core'; import type { EnvType, IGlobal, @@ -54,7 +54,7 @@ export class WxWindowHandlerContribution extends BaseWindowHandlerContribution i constructor() { super(); - this.global = application.global; + this.global = vglobal; } getTitle(): string { diff --git a/packages/vrender/__tests__/browser/src/contribution/env-canvas/canvas.ts b/packages/vrender/__tests__/browser/src/contribution/env-canvas/canvas.ts deleted file mode 100644 index 5b13cdacf..000000000 --- a/packages/vrender/__tests__/browser/src/contribution/env-canvas/canvas.ts +++ /dev/null @@ -1,147 +0,0 @@ -import { injectable } from 'inversify'; -import type { Canvas } from 'canvas'; -import type { EnvType, CanvasConfigType, ICanvas, IContext2d } from '@visactor/vrender'; -import { NodeContext2d } from './context'; - -const DefaultConfig = { - WIDTH: 500, - HEIGHT: 500, - DPR: 1 -}; - -@injectable() -export class NodeCanvas implements ICanvas { - static env: EnvType = 'node'; - // 显示的宽高,如果是离屏canvas,就是pixelWidth / pixelRatio - private _width: number; // 显示的宽度 - private _height: number; // 显示的高度 - private _id: number | string; - - private _nativeCanvas: Canvas; - private _context: IContext2d; - private _visiable: boolean; - private controled: boolean; - - get id(): number | string { - return this._id; - } - get x(): number { - return 0; - } - get y(): number { - return 0; - } - get nativeCanvas(): Canvas { - return this._nativeCanvas; - } - - get width(): number { - return this._width; - } - set width(width: number) { - this._width = width; - } - get displayWidth(): number { - return this._width; - } - get displayHeight(): number { - return this._height; - } - - get height(): number { - return this._height; - } - set height(height: number) { - this._height = height; - } - getContext(str?: string): IContext2d { - return this._context; - } - - get visiable(): boolean { - return this._visiable; - } - set visiable(visiable: boolean) { - this._visiable = visiable; - visiable ? this.show() : this.hide(); - } - - get dpr(): number { - return 1; - } - set dpr(dpr: number) { - return; - } - - /** - * 通过canvas生成一个wrap对象,初始化时不会再设置canvas的属性 - * @param params - */ - constructor(params: CanvasConfigType) { - const { nativeCanvas, width = DefaultConfig.WIDTH, height = DefaultConfig.HEIGHT, canvasControled = true } = params; - this._visiable = params.visiable !== false; - this.controled = canvasControled; - - // 离屏canvas - this._width = width; - this._height = height; - this._nativeCanvas = nativeCanvas as unknown as Canvas; - this._context = new NodeContext2d(this, params.dpr); - this._id = nativeCanvas.id; - } - - applyPosition() { - return; - } - - getNativeCanvas(): Canvas { - return this._nativeCanvas; - } - - resetStyle(params: Partial) { - return; - } - - hide() { - return; - } - show() { - return; - } - - /** - * 设置canvas的size大小,设置context的scale - * @param width - * @param height - */ - resize(width: number, height: number) { - if (this._nativeCanvas) { - this._nativeCanvas.width = width; - this._nativeCanvas.height = height; - } - return; - } - - toDataURL(): string; - toDataURL(mimeType: 'image/png'): string; - toDataURL(mimeType: 'image/jpeg', quality: number): string; - toDataURL(mimeType?: string, quality?: number) { - return ''; - } - - readPixels(x: number, y: number, w: number, h: number): ImageData | Promise { - return this._context.getImageData(x, y, w, h); - } - - convertToBlob(options?: { type?: string | undefined; quality?: number | undefined } | undefined): Promise { - throw new Error('暂未实现'); - } - - transferToImageBitmap(): ImageBitmap { - throw new Error('暂未实现'); - } - - release(...params: any): void { - throw new Error('暂不支持release'); - } -} diff --git a/packages/vrender/__tests__/browser/src/contribution/env-canvas/context.ts b/packages/vrender/__tests__/browser/src/contribution/env-canvas/context.ts deleted file mode 100644 index a4247b9a9..000000000 --- a/packages/vrender/__tests__/browser/src/contribution/env-canvas/context.ts +++ /dev/null @@ -1,31 +0,0 @@ -// 参考konva -import { Matrix } from '@visactor/vutils'; -import { injectable } from 'inversify'; -import type { EnvType, ICanvas, IContext2d } from '@visactor/vrender'; -import { BrowserContext2d } from '@visactor/vrender'; -import { CanvasRenderingContext2D, Image, CanvasPattern } from 'canvas'; - -// https://github.com/konvajs/konva/blob/master/src/Context.ts -const initMatrix = new Matrix(1, 0, 0, 1, 0, 0); - -@injectable() -export class NodeContext2d extends BrowserContext2d implements IContext2d { - static env: EnvType = 'node'; - - constructor(canvas: ICanvas, dpr: number) { - super(canvas, dpr); - const context = canvas.nativeCanvas.getContext('2d'); - if (!context) { - throw new Error('发生错误,获取2d上下文失败'); - } - this.nativeContext = context; - this.canvas = canvas; - this.matrix = new Matrix(1, 0, 0, 1, 0, 0); - this.stack = []; - this.dpr = 1; - } - - release(...params: any): void { - return; - } -} diff --git a/packages/vrender/__tests__/browser/src/contribution/env-canvas/env-contribution.ts b/packages/vrender/__tests__/browser/src/contribution/env-canvas/env-contribution.ts deleted file mode 100644 index c935a6904..000000000 --- a/packages/vrender/__tests__/browser/src/contribution/env-canvas/env-contribution.ts +++ /dev/null @@ -1,176 +0,0 @@ -import { injectable } from 'inversify'; -import type { EnvType, IEnvContribution, IGlobal, ICreateCanvasParams } from '@visactor/vrender'; -import { BaseEnvContribution } from '@visactor/vrender'; - -let last = 0; -function nodeRequestAnimationFrame(callback: FrameRequestCallback) { - const now = Date.now(); - const timeLeft = Math.max(0, 16 - (now - last)); - const id = setTimeout(function () { - callback(now + timeLeft); - }, timeLeft); - last = now + timeLeft; - return id; -} - -@injectable() -export class NodeEnvContribution extends BaseEnvContribution implements IEnvContribution { - type: EnvType = 'node'; - pkg: any; - _lastTime: number = 0; - supportEvent: boolean = false; - - configure(service: IGlobal, pkg: any) { - if (service.env === this.type) { - service.setActiveEnvContribution(this); - this.pkg = pkg; - } - } - - loadJson(url: string): Promise<{ - loadState: 'success' | 'fail'; - data: Record | null; - }> { - const jsonPromise = fetch(url).then(data => data.json()) as Promise; // ignore_security_alert - jsonPromise - .then(json => { - return { - data: json, - state: 'success' - }; - }) - .catch(() => { - return { - data: null, - state: 'fail' - }; - }); - return jsonPromise; - } - - loadArrayBuffer(url: string): Promise<{ - loadState: 'success' | 'fail'; - data: ArrayBuffer | null; - }> { - const arrayBufferPromise = fetch(url).then(data => data.arrayBuffer()); // ignore_security_alert - return arrayBufferPromise - .then((arrayBuffer: ArrayBuffer) => { - return { - data: arrayBuffer, - loadState: 'success' as const - }; - }) - .catch(() => { - return { - data: null, - loadState: 'fail' - }; - }); - } - - loadImage(url: string): Promise<{ - loadState: 'success' | 'fail'; - data: HTMLImageElement | null; - }> { - const { loadImage } = this.pkg; - if (loadImage) { - return loadImage(url) - .then((image: any) => { - const loadState: 'success' | 'fail' = image ? 'success' : 'fail'; - return { - loadState, - data: image as HTMLImageElement - }; - }) - .catch(() => { - return { - loadState: 'fail', - data: null - } as any; - }); - } - return Promise.reject(new Error('node-canvas loadImage could not be found!')); - } - - // 此处的 - loadSvg(svgStr: string): Promise<{ - loadState: 'success' | 'fail'; - data: HTMLImageElement | null; - }> { - return Promise.reject(); - } - - createCanvas(params: any): any { - // const canvas = this.pkg.createCanvas(params.width, params.height); - const canvas = document.createElement('canvas'); - console.log('创建canvas'); - canvas.width = params.width; - canvas.height = params.height; - return canvas; - } - - releaseCanvas(canvas: any | any) { - return; - } - - getDevicePixelRatio(): number { - return 0; - } - - getRequestAnimationFrame(): (callback: FrameRequestCallback) => number { - // return requestAnimationFrame; - return nodeRequestAnimationFrame as any; - } - - addEventListener( - type: K, - listener: (this: Document, ev: DocumentEventMap[K]) => any, - options?: boolean | AddEventListenerOptions | undefined - ): void; - addEventListener( - type: string, - listener: EventListenerOrEventListenerObject, - options?: boolean | AddEventListenerOptions | undefined - ): void; - addEventListener(type: unknown, listener: unknown, options?: unknown): void { - return; - } - - removeEventListener( - type: K, - listener: (this: Document, ev: DocumentEventMap[K]) => any, - options?: boolean | EventListenerOptions | undefined - ): void; - removeEventListener( - type: string, - listener: EventListenerOrEventListenerObject, - options?: boolean | EventListenerOptions | undefined - ): void; - removeEventListener(type: unknown, listener: unknown, options?: unknown): void { - return; - } - - getElementById(str: string): HTMLElement | null { - return null; - } - - getRootElement(): HTMLElement | null { - return null; - } - - dispatchEvent(event: any): boolean { - return false; - } - - getCancelAnimationFrame(): (h: number) => void { - return () => {}; - } - - release(...params: any): void { - return; - } - - createOffscreenCanvas(params: ICreateCanvasParams) { - return; - } -} diff --git a/packages/vrender/__tests__/browser/src/contribution/env-canvas/module.ts b/packages/vrender/__tests__/browser/src/contribution/env-canvas/module.ts deleted file mode 100644 index 53b37811b..000000000 --- a/packages/vrender/__tests__/browser/src/contribution/env-canvas/module.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { ContainerModule } from 'inversify'; -import type { CanvasConfigType, ICanvas } from '@visactor/vrender'; -import { - CanvasFactory, - Context2dFactory, - EnvContribution, - WindowHandlerContribution, - container -} from '@visactor/vrender'; -import { NodeCanvas } from './canvas'; -import { NodeContext2d } from './context'; -import { NodeEnvContribution } from './env-contribution'; -import { NodeWindowHandlerContribution } from './window-contribution'; - -const windowModule = new ContainerModule(bind => { - bind(NodeWindowHandlerContribution).toSelf().inSingletonScope(); - bind(WindowHandlerContribution).toService(NodeWindowHandlerContribution); - // bindContributionProvider(bind, WindowHandlerContribution); -}); - -const envModule = new ContainerModule(bind => { - bind(NodeEnvContribution).toSelf().inSingletonScope(); - bind(EnvContribution).toService(NodeEnvContribution); -}); - -const canvasModule = new ContainerModule(bind => { - bind(CanvasFactory) - .toDynamicValue(() => { - return (params: CanvasConfigType) => new NodeCanvas(params); - }) - .whenTargetNamed(NodeContext2d.env); - - bind(Context2dFactory) - .toDynamicValue(() => { - return (params: ICanvas) => new NodeContext2d(params, params.dpr); - }) - .whenTargetNamed(NodeContext2d.env); -}); - -container.load(envModule); -container.load(canvasModule); -container.load(windowModule); diff --git a/packages/vrender/__tests__/browser/src/contribution/env-canvas/window-contribution.ts b/packages/vrender/__tests__/browser/src/contribution/env-canvas/window-contribution.ts deleted file mode 100644 index 995d9130d..000000000 --- a/packages/vrender/__tests__/browser/src/contribution/env-canvas/window-contribution.ts +++ /dev/null @@ -1,157 +0,0 @@ -import { inject, injectable } from 'inversify'; -import type { - EnvType, - IGlobal, - IWindowHandlerContribution, - IWindowParams, - IContext2d, - ICanvas, - IDomRectLike -} from '@visactor/vrender'; -import { Generator, VGlobal, BaseWindowHandlerContribution } from '@visactor/vrender'; -import { NodeCanvas } from './canvas'; -import type { IBoundsLike } from '@visactor/vutils'; - -@injectable() -export class NodeWindowHandlerContribution extends BaseWindowHandlerContribution implements IWindowHandlerContribution { - type: EnvType = 'node'; - - canvas: ICanvas; - get container(): HTMLElement | null { - return null; - } - - constructor(@inject(VGlobal) private readonly global: IGlobal) { - super(); - } - - getTitle(): string { - return ''; - } - - getWH(): { width: number; height: number } { - return { - width: this.canvas.displayWidth, - height: this.canvas.displayHeight - }; - } - - getXY(): { x: number; y: number } { - return { x: 0, y: 0 }; - } - - createWindow(params: IWindowParams): void { - // 如果没有传入canvas,那么就创建一个canvas - if (!params.canvas) { - this.createWindowByConfig(params); - } else { - this.createWindowByCanvas(params); - } - } - private createWindowByConfig(params: IWindowParams) { - // 创建canvas - const nativeCanvas = this.global.createCanvas({ width: params.width, height: params.height }); - - // 绑定 - const options = { - width: params.width, - height: params.height, - dpr: params.dpr, - nativeCanvas, - id: Generator.GenAutoIncrementId().toString(), - canvasControled: true - }; - this.canvas = new NodeCanvas(options); - } - private createWindowByCanvas(params: IWindowParams) { - // 获取canvas - const canvas = params!.canvas as HTMLCanvasElement | null; - - // 如果没有传入wh,或者是不受控制的canvas,那就用canvas的原始wh - let width = params.width; - let height = params.height; - if (width == null || height == null || !params.canvasControled) { - width = canvas.width; - height = canvas.height; - } - - this.canvas = new NodeCanvas({ - width: width, - height: height, - dpr: 1, - nativeCanvas: canvas, - canvasControled: params.canvasControled - }); - } - releaseWindow(): void { - this.canvas.release(); - } - resizeWindow(width: number, height: number): void { - this.canvas.resize(width, height); - } - setDpr(dpr: number): void { - this.canvas.dpr = dpr; - } - - getContext(): IContext2d { - return this.canvas.getContext('2d'); - } - getNativeHandler(): ICanvas { - return this.canvas; - } - getDpr(): number { - return this.canvas.dpr; - } - - getImageBuffer(type: string = 'image/png'): any { - const canvas = this.canvas.nativeCanvas; - return canvas.toBuffer(type); - } - - addEventListener( - type: K, - listener: (this: Document, ev: DocumentEventMap[K]) => any, - options?: boolean | AddEventListenerOptions - ): void; - addEventListener( - type: string, - listener: EventListenerOrEventListenerObject, - options?: boolean | AddEventListenerOptions - ): void; - addEventListener(type: unknown, listener: unknown, options?: unknown): void { - return; - } - - dispatchEvent(event: any): boolean { - return true; - } - - removeEventListener( - type: K, - listener: (this: Document, ev: DocumentEventMap[K]) => any, - options?: boolean | EventListenerOptions - ): void; - removeEventListener( - type: string, - listener: EventListenerOrEventListenerObject, - options?: boolean | EventListenerOptions - ): void; - removeEventListener(type: unknown, listener: unknown, options?: unknown): void { - return; - } - - getStyle(): CSSStyleDeclaration | Record { - return; - } - setStyle(style: CSSStyleDeclaration | Record): void { - return; - } - - getBoundingClientRect(): IDomRectLike { - return null; - } - - clearViewBox(vb: IBoundsLike, color?: string): void { - return; - } -} diff --git a/packages/vrender/__tests__/browser/src/inversify_test/index.ts b/packages/vrender/__tests__/browser/src/inversify_test/index.ts deleted file mode 100644 index 26d7f04e2..000000000 --- a/packages/vrender/__tests__/browser/src/inversify_test/index.ts +++ /dev/null @@ -1,37 +0,0 @@ -import 'core-js/proposals/reflect-metadata'; -import { ContainerModule, inject, injectable, Container, multiInject } from 'inversify'; -@injectable() -class GlobalGun {} - -const rect = Symbol.for('rect'); - -@injectable() -class DefaultRect {} - -@injectable() -class RoughRect {} - -@injectable() -class APP { - constructor(@inject(GlobalGun) public globalGun: GlobalGun, @multiInject(rect) public rects: any) {} -} - -const container = new Container(); - -const globalContainer = new ContainerModule(bind => { - bind(APP).toSelf(); - bind(GlobalGun).toSelf(); - bind(DefaultRect).toSelf(); - bind(RoughRect).toSelf(); - - bind(rect).to(DefaultRect); - bind(rect).to(RoughRect); -}); - -container.load(globalContainer); - -const app1 = container.get(APP); - -const app2 = container.get(APP); - -console.log(app1, app1.globalGun, app2, app1.globalGun); diff --git a/packages/vrender/__tests__/browser/src/pages/animate-next.ts b/packages/vrender/__tests__/browser/src/pages/animate-next.ts index 09b392831..7e4f1a68b 100644 --- a/packages/vrender/__tests__/browser/src/pages/animate-next.ts +++ b/packages/vrender/__tests__/browser/src/pages/animate-next.ts @@ -15,7 +15,6 @@ import { createStage, createSymbol, IGraphic, - vglobal, createCircle, createText, createGroup, diff --git a/packages/vrender/__tests__/browser/src/pages/editor/draggable-plugin.ts b/packages/vrender/__tests__/browser/src/pages/editor/draggable-plugin.ts index 14b8eda31..e173e2697 100644 --- a/packages/vrender/__tests__/browser/src/pages/editor/draggable-plugin.ts +++ b/packages/vrender/__tests__/browser/src/pages/editor/draggable-plugin.ts @@ -1,9 +1,8 @@ import type { FederatedPointerEvent, IGraphic, IPlugin, IPluginService } from '@visactor/vrender'; -import { Generator, DragNDrop, injectable } from '@visactor/vrender'; +import { Generator, DragNDrop } from '@visactor/vrender'; // _showPoptip: 0-没有,1-添加,2-删除 -@injectable() export class DraggablePlugin implements IPlugin { name: 'DraggablePlugin' = 'DraggablePlugin'; activeEvent: 'onRegister' = 'onRegister'; diff --git a/packages/vrender/__tests__/browser/src/pages/editor/register.ts b/packages/vrender/__tests__/browser/src/pages/editor/register.ts index db1a938fe..2ca9a29b1 100644 --- a/packages/vrender/__tests__/browser/src/pages/editor/register.ts +++ b/packages/vrender/__tests__/browser/src/pages/editor/register.ts @@ -1,11 +1,9 @@ -import { container, AutoEnablePlugins, ContainerModule } from '@visactor/vrender'; +import { application, AutoEnablePlugins } from '@visactor/vrender'; import { DraggablePlugin } from './draggable-plugin'; -export const editableModule = new ContainerModule(bind => { - bind(DraggablePlugin).toSelf().inSingletonScope(); - bind(AutoEnablePlugins).toService(DraggablePlugin); -}); - +let _registered = false; export function loadEditable() { - container.load(editableModule); + if (_registered) return; + _registered = true; + application.contributions.register(AutoEnablePlugins, new DraggablePlugin()); } diff --git a/packages/vrender/__tests__/browser/src/pages/glyph.ts b/packages/vrender/__tests__/browser/src/pages/glyph.ts index 14b9a9ccf..02679b6b0 100644 --- a/packages/vrender/__tests__/browser/src/pages/glyph.ts +++ b/packages/vrender/__tests__/browser/src/pages/glyph.ts @@ -6,16 +6,11 @@ import { createSymbol, createGroup, FederatedEvent, - initBrowserEnv, - initAllEnv, - initFeishuEnv + initAllEnv } from '@visactor/vrender'; import { addShapesToStage, colorPools } from '../utils'; // container.load(roughModule); -initBrowserEnv(); -initFeishuEnv(); -initAllEnv(); export const page = () => { const shapes = []; diff --git a/packages/vrender/__tests__/browser/src/pages/pick-test.ts b/packages/vrender/__tests__/browser/src/pages/pick-test.ts index 328a66205..5775a39dd 100644 --- a/packages/vrender/__tests__/browser/src/pages/pick-test.ts +++ b/packages/vrender/__tests__/browser/src/pages/pick-test.ts @@ -1,14 +1,4 @@ -import { - loadFeishuContributions, - createStage, - Stage, - createCircle, - createGroup, - createText, - createRect -} from '@visactor/vrender'; - -loadFeishuContributions(); +import { createStage, Stage, createCircle, createGroup, createText, createRect } from '@visactor/vrender'; export const page = () => { const div = document.createElement('div'); diff --git a/packages/vrender/__tests__/browser/src/pages/rect.ts b/packages/vrender/__tests__/browser/src/pages/rect.ts index bfe6d7d67..30fde2fcc 100644 --- a/packages/vrender/__tests__/browser/src/pages/rect.ts +++ b/packages/vrender/__tests__/browser/src/pages/rect.ts @@ -1,9 +1,210 @@ -import { createStage, container, createRect, IGraphic, createGroup, createSymbol } from '@visactor/vrender'; +import { + createStage, + container, + createRect, + IGraphic, + createGroup, + createSymbol, + serviceRegistry, + contributionRegistry, + VGlobal, + EnvContribution, + CanvasFactory, + Context2dFactory, + GraphicRender +} from '@visactor/vrender'; import { roughModule } from '@visactor/vrender-kits'; // container.load(roughModule); export const page = () => { + // ===== 调试代码开始 ===== + console.log('===== VRender Debug ====='); + console.log('1. VGlobal 检查:'); + const global = serviceRegistry.get(VGlobal); + console.log(' global:', global); + console.log(' global.env:', global.env); + console.log(' global.envContribution:', global.envContribution); + console.log(' global.envContribution?.type:', global.envContribution?.type); + + console.log('\n2. EnvContribution 检查:'); + const envContribs = contributionRegistry.get(EnvContribution); + console.log(' EnvContribution 数量:', envContribs.length); + envContribs.forEach((c, i) => console.log(` [${i}] type: ${c.type}`)); + + console.log('\n3. Canvas 工厂检查:'); + const canvasFactory = serviceRegistry.getFactory(CanvasFactory); + const contextFactory = serviceRegistry.getFactory(Context2dFactory); + console.log(' CanvasFactory:', typeof canvasFactory); + console.log(' Context2dFactory:', typeof contextFactory); + + console.log('\n4. 测试 createCanvas:'); + try { + const testCanvas = global.createCanvas({ width: 100, height: 100 }); + console.log(' createCanvas 成功:', testCanvas); + console.log(' canvas.width:', testCanvas.width); + } catch (e) { + console.error(' createCanvas 失败:', e); + } + + console.log('\n5. 测试 Canvas 工厂:'); + try { + const nativeCanvas = global.createCanvas({ width: 200, height: 150 }); + const wrapped = canvasFactory({ + nativeCanvas, + width: 200, + height: 150, + dpr: window.devicePixelRatio + }); + console.log(' 工厂包装成功:', wrapped); + console.log(' wrapped.nativeCanvas:', wrapped.nativeCanvas); + } catch (e) { + console.error(' 工厂包装失败:', e); + console.error(' 错误堆栈:', e.stack); + } + console.log('===== Debug End =====\n'); + // ===== 调试代码结束 ===== + const graphics: IGraphic[] = []; + + // ===== 继续测试:创建 Stage 后检查 ===== + console.log('===== 创建 Stage 前后对比 ====='); + console.log('创建前 - global.env:', global.env); + console.log('创建前 - global.envContribution:', global.envContribution); + + const testStage = createStage({ + canvas: 'main', + autoRender: false + }); + + console.log('\n创建后 - global.env:', global.env); + console.log('创建后 - global.envContribution:', global.envContribution); + console.log('创建后 - global.envContribution?.type:', global.envContribution?.type); + console.log('创建后 - Stage:', testStage); + const canvas = testStage.window.getNativeHandler(); + console.log('创建后 - canvas:', canvas); + console.log('创建后 - canvas.nativeCanvas:', canvas?.nativeCanvas); + + // 测试绘制 + const testRect = createRect({ + x: 100, + y: 100, + width: 200, + height: 150, + fill: 'red', + stroke: 'blue', + lineWidth: 3 + }); + + testStage.defaultLayer.add(testRect); + console.log('添加矩形到 defaultLayer,准备渲染...'); + console.log('testRect:', testRect); + console.log('testStage.defaultLayer.children:', testStage.defaultLayer.children); + + // 检查渲染相关对象 + console.log('\n检查渲染对象:'); + console.log(' testStage.renderService:', testStage.renderService); + console.log(' testStage.defaultLayer.getNativeHandler():', testStage.defaultLayer.getNativeHandler()); + const layerHandler = testStage.defaultLayer.getNativeHandler(); + console.log(' layerHandler.canvas:', layerHandler.canvas); + console.log(' layerHandler.context:', layerHandler.context); + console.log(' layerHandler.context.nativeContext:', layerHandler.context?.nativeContext); + + // 测试直接在 context 上绘制 + console.log('\n测试直接在 context 绘制:'); + const ctx = layerHandler.context.nativeContext; + if (ctx) { + ctx.fillStyle = 'green'; + ctx.fillRect(50, 50, 100, 100); + console.log(' 直接绘制绿色矩形完成'); + + // 立即检查是否绘制成功(在 render() 之前) + const immediateCheck = ctx.getImageData(75, 75, 1, 1).data; + console.log( + ` 立即检查 (75,75): RGBA(${immediateCheck[0]}, ${immediateCheck[1]}, ${immediateCheck[2]}, ${immediateCheck[3]})` + ); + if (immediateCheck[1] > 200 && immediateCheck[0] < 50 && immediateCheck[2] < 50) { + console.log(' ✓ 绿色矩形立即可见'); + } else { + console.log(' ✗ 绿色矩形不可见(可能 canvas 有问题)'); + } + } + + console.log('\n准备调用 render()...'); + console.log('renderService:', testStage.renderService); + console.log('graphicService:', testStage.graphicService); + + // 手动获取渲染器检查 + const renders = contributionRegistry.get(GraphicRender); + console.log('注册的 GraphicRender 数量:', renders.length); + renders.forEach((r, i) => console.log(` [${i}] type: ${r.type}`)); + + // 检查 Rect 的渲染器 + const rectRender = renders.find(r => r.type === 'rect'); + console.log('Rect 渲染器:', rectRender); + + testStage.render(); + console.log('render() 调用完成'); + + // render() 后立即检查 + const afterRender = ctx.getImageData(75, 75, 1, 1).data; + console.log( + `render() 后检查 (75,75): RGBA(${afterRender[0]}, ${afterRender[1]}, ${afterRender[2]}, ${afterRender[3]})` + ); + if (afterRender[1] > 200 && afterRender[0] < 50 && afterRender[2] < 50) { + console.log(' 绿色矩形仍然存在'); + } else { + console.log(' 绿色矩形被清除了(render() 清空了 canvas)'); + } + + console.log('\n渲染完成,检查 canvas 内容...'); + setTimeout(() => { + const nativeCanvas = testStage.window.getNativeHandler().nativeCanvas; + const ctx = nativeCanvas.getContext('2d'); + + // 先检查直接绘制的绿色矩形 + console.log('500ms 后检查直接绘制的绿色矩形:'); + const greenData = ctx.getImageData(75, 75, 1, 1).data; + console.log(` 位置(75,75): RGBA(${greenData[0]}, ${greenData[1]}, ${greenData[2]}, ${greenData[3]})`); + // 正确检测绿色:G>200, R<50, B<50 + if (greenData[1] > 200 && greenData[0] < 50 && greenData[2] < 50) { + console.log(' ✓ 检测到绿色'); + } else { + console.log(' ✗ 未检测到绿色'); + } + + // 再检查通过 VRender 渲染的红色矩形 + console.log('\n检查 VRender 渲染的红色矩形:'); + const imageData = ctx.getImageData(150, 150, 1, 1); + console.log( + ` 位置(150,150): RGBA(${imageData.data[0]}, ${imageData.data[1]}, ${imageData.data[2]}, ${imageData.data[3]})` + ); + + // 正确检测红色:R>200, G<50, B<50 + if (imageData.data[0] > 200 && imageData.data[1] < 50 && imageData.data[2] < 50) { + console.log(' ✓ 检测到红色像素,VRender 渲染成功!'); + } else { + console.log(' ✗ 未检测到红色像素,VRender 渲染失败'); + console.log(' 检查其他位置...'); + + // 检查多个位置 + const positions = [ + [100, 100], + [200, 200], + [250, 150], + [150, 175] + ]; + positions.forEach(([x, y]) => { + const data = ctx.getImageData(x, y, 1, 1).data; + console.log(` 位置(${x},${y}): RGBA(${data[0]}, ${data[1]}, ${data[2]}, ${data[3]})`); + }); + } + + console.log('\n===== Stage 测试完成 =====\n'); + + // 不要 release,让原始代码继续使用这个 canvas + // testStage.release(); + }, 500); + // ===== Stage 测试结束 ===== // graphics.push( // createRect({ // x: 100, diff --git a/packages/vrender/src/index.ts b/packages/vrender/src/index.ts index a52b7a5ca..e429143a0 100644 --- a/packages/vrender/src/index.ts +++ b/packages/vrender/src/index.ts @@ -1,9 +1,7 @@ import '@visactor/vrender-core'; import { - container, isBrowserEnv, isNodeEnv, - preLoadAllModule, registerFlexLayoutPlugin, registerViewTransform3dPlugin, registerHtmlAttributePlugin, @@ -11,9 +9,7 @@ import { registerDirectionalLight, registerOrthoCamera } from '@visactor/vrender-core'; -import { registerStar } from '@visactor/vrender-kits'; -import { registerBrowserEnvRegistry } from '@visactor/vrender-kits/esm/env/browser'; -import { registerNodeEnvRegistry } from '@visactor/vrender-kits/esm/env/node'; +import { registerStar, registerBrowserEnvRegistry, registerNodeEnvRegistry } from '@visactor/vrender-kits'; import { registerArc, registerArc3d, @@ -38,7 +34,7 @@ import { registerCustomAnimate, registerAnimate } from '@visactor/vrender-animat // 导出版本号 export const version = __VERSION__; -preLoadAllModule(); +// Core is initialized via side-effects and per-package register functions // Registry-based registration only (drop legacy ContainerModule loaders) if (isBrowserEnv()) { From 595455298f031b055a88008e6054b1cdbd192ab3 Mon Sep 17 00:00:00 2001 From: xile611 Date: Tue, 13 Jan 2026 11:31:43 +0800 Subject: [PATCH 3/6] refactor: update env functions --- .../{contributions => }/browser/canvas.ts | 0 .../{contributions => }/browser/context.ts | 0 .../browser/modules.ts => browser/index.ts} | 2 + .../src/canvas/contributions/browser/index.ts | 3 -- .../src/canvas/contributions/feishu/index.ts | 3 -- .../src/canvas/contributions/harmony/index.ts | 3 -- .../src/canvas/contributions/lynx/index.ts | 3 -- .../src/canvas/contributions/modules.ts | 45 ------------------- .../src/canvas/contributions/node/index.ts | 3 -- .../src/canvas/contributions/taro/index.ts | 3 -- .../src/canvas/contributions/tt/index.ts | 3 -- .../src/canvas/contributions/wx/index.ts | 3 -- .../create-canvas-module.ts | 0 .../{contributions => }/feishu/canvas.ts | 0 .../{contributions => }/feishu/context.ts | 2 +- .../feishu/modules.ts => feishu/index.ts} | 2 + .../{contributions => }/harmony/canvas.ts | 0 .../{contributions => }/harmony/context.ts | 0 .../harmony/modules.ts => harmony/index.ts} | 2 + packages/vrender-kits/src/canvas/index.ts | 9 +++- .../canvas/{contributions => }/lynx/canvas.ts | 0 .../{contributions => }/lynx/context.ts | 0 .../lynx/modules.ts => lynx/index.ts} | 2 + .../{contributions => }/node-canvas.d.ts | 0 .../canvas/{contributions => }/node/canvas.ts | 0 .../{contributions => }/node/context.ts | 2 +- .../node/modules.ts => node/index.ts} | 2 + .../canvas/{contributions => }/taro/canvas.ts | 0 .../{contributions => }/taro/context.ts | 2 +- .../taro/modules.ts => taro/index.ts} | 2 + .../canvas/{contributions => }/tt/canvas.ts | 0 .../canvas/{contributions => }/tt/context.ts | 0 .../tt/modules.ts => tt/index.ts} | 2 + .../canvas/{contributions => }/wx/canvas.ts | 0 .../canvas/{contributions => }/wx/context.ts | 2 +- .../wx/modules.ts => wx/index.ts} | 2 + packages/vrender-kits/src/env/all.ts | 24 +++++----- packages/vrender-kits/src/env/browser.ts | 7 +-- packages/vrender-kits/src/env/feishu.ts | 6 +-- packages/vrender-kits/src/env/harmony.ts | 4 +- packages/vrender-kits/src/env/lynx.ts | 4 +- packages/vrender-kits/src/env/node.ts | 4 +- packages/vrender-kits/src/env/taro.ts | 6 +-- packages/vrender-kits/src/env/tt.ts | 4 +- packages/vrender-kits/src/env/wx.ts | 4 +- .../render/contributions/rough/rough-arc.ts | 5 --- .../contributions/browser-contribution.ts | 2 +- .../contributions/feishu-contribution.ts | 2 +- .../contributions/harmony-contribution.ts | 2 +- .../window/contributions/lynx-contribution.ts | 2 +- .../window/contributions/node-contribution.ts | 2 +- .../window/contributions/taro-contribution.ts | 2 +- .../window/contributions/tt-contribution.ts | 2 +- .../window/contributions/wx-contribution.ts | 3 +- packages/vrender/src/index.ts | 6 +-- 55 files changed, 73 insertions(+), 120 deletions(-) rename packages/vrender-kits/src/canvas/{contributions => }/browser/canvas.ts (100%) rename packages/vrender-kits/src/canvas/{contributions => }/browser/context.ts (100%) rename packages/vrender-kits/src/canvas/{contributions/browser/modules.ts => browser/index.ts} (85%) delete mode 100644 packages/vrender-kits/src/canvas/contributions/browser/index.ts delete mode 100644 packages/vrender-kits/src/canvas/contributions/feishu/index.ts delete mode 100644 packages/vrender-kits/src/canvas/contributions/harmony/index.ts delete mode 100644 packages/vrender-kits/src/canvas/contributions/lynx/index.ts delete mode 100644 packages/vrender-kits/src/canvas/contributions/modules.ts delete mode 100644 packages/vrender-kits/src/canvas/contributions/node/index.ts delete mode 100644 packages/vrender-kits/src/canvas/contributions/taro/index.ts delete mode 100644 packages/vrender-kits/src/canvas/contributions/tt/index.ts delete mode 100644 packages/vrender-kits/src/canvas/contributions/wx/index.ts rename packages/vrender-kits/src/canvas/{contributions => }/create-canvas-module.ts (100%) rename packages/vrender-kits/src/canvas/{contributions => }/feishu/canvas.ts (100%) rename packages/vrender-kits/src/canvas/{contributions => }/feishu/context.ts (96%) rename packages/vrender-kits/src/canvas/{contributions/feishu/modules.ts => feishu/index.ts} (85%) rename packages/vrender-kits/src/canvas/{contributions => }/harmony/canvas.ts (100%) rename packages/vrender-kits/src/canvas/{contributions => }/harmony/context.ts (100%) rename packages/vrender-kits/src/canvas/{contributions/harmony/modules.ts => harmony/index.ts} (85%) rename packages/vrender-kits/src/canvas/{contributions => }/lynx/canvas.ts (100%) rename packages/vrender-kits/src/canvas/{contributions => }/lynx/context.ts (100%) rename packages/vrender-kits/src/canvas/{contributions/lynx/modules.ts => lynx/index.ts} (86%) rename packages/vrender-kits/src/canvas/{contributions => }/node-canvas.d.ts (100%) rename packages/vrender-kits/src/canvas/{contributions => }/node/canvas.ts (100%) rename packages/vrender-kits/src/canvas/{contributions => }/node/context.ts (92%) rename packages/vrender-kits/src/canvas/{contributions/node/modules.ts => node/index.ts} (86%) rename packages/vrender-kits/src/canvas/{contributions => }/taro/canvas.ts (100%) rename packages/vrender-kits/src/canvas/{contributions => }/taro/context.ts (99%) rename packages/vrender-kits/src/canvas/{contributions/taro/modules.ts => taro/index.ts} (86%) rename packages/vrender-kits/src/canvas/{contributions => }/tt/canvas.ts (100%) rename packages/vrender-kits/src/canvas/{contributions => }/tt/context.ts (100%) rename packages/vrender-kits/src/canvas/{contributions/tt/modules.ts => tt/index.ts} (87%) rename packages/vrender-kits/src/canvas/{contributions => }/wx/canvas.ts (100%) rename packages/vrender-kits/src/canvas/{contributions => }/wx/context.ts (86%) rename packages/vrender-kits/src/canvas/{contributions/wx/modules.ts => wx/index.ts} (87%) diff --git a/packages/vrender-kits/src/canvas/contributions/browser/canvas.ts b/packages/vrender-kits/src/canvas/browser/canvas.ts similarity index 100% rename from packages/vrender-kits/src/canvas/contributions/browser/canvas.ts rename to packages/vrender-kits/src/canvas/browser/canvas.ts diff --git a/packages/vrender-kits/src/canvas/contributions/browser/context.ts b/packages/vrender-kits/src/canvas/browser/context.ts similarity index 100% rename from packages/vrender-kits/src/canvas/contributions/browser/context.ts rename to packages/vrender-kits/src/canvas/browser/context.ts diff --git a/packages/vrender-kits/src/canvas/contributions/browser/modules.ts b/packages/vrender-kits/src/canvas/browser/index.ts similarity index 85% rename from packages/vrender-kits/src/canvas/contributions/browser/modules.ts rename to packages/vrender-kits/src/canvas/browser/index.ts index 5de0096b7..23039e527 100644 --- a/packages/vrender-kits/src/canvas/contributions/browser/modules.ts +++ b/packages/vrender-kits/src/canvas/browser/index.ts @@ -5,3 +5,5 @@ import { registerCanvasFactories } from '../create-canvas-module'; export function registerBrowserCanvasFactories() { registerCanvasFactories(BrowserCanvas, BrowserContext2d); } + +export { BrowserCanvas, BrowserContext2d }; diff --git a/packages/vrender-kits/src/canvas/contributions/browser/index.ts b/packages/vrender-kits/src/canvas/contributions/browser/index.ts deleted file mode 100644 index c50b6c64d..000000000 --- a/packages/vrender-kits/src/canvas/contributions/browser/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -// 依然导出canvas和context,便于指定环境直接使用 -export * from './canvas'; -export * from './context'; diff --git a/packages/vrender-kits/src/canvas/contributions/feishu/index.ts b/packages/vrender-kits/src/canvas/contributions/feishu/index.ts deleted file mode 100644 index c50b6c64d..000000000 --- a/packages/vrender-kits/src/canvas/contributions/feishu/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -// 依然导出canvas和context,便于指定环境直接使用 -export * from './canvas'; -export * from './context'; diff --git a/packages/vrender-kits/src/canvas/contributions/harmony/index.ts b/packages/vrender-kits/src/canvas/contributions/harmony/index.ts deleted file mode 100644 index c50b6c64d..000000000 --- a/packages/vrender-kits/src/canvas/contributions/harmony/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -// 依然导出canvas和context,便于指定环境直接使用 -export * from './canvas'; -export * from './context'; diff --git a/packages/vrender-kits/src/canvas/contributions/lynx/index.ts b/packages/vrender-kits/src/canvas/contributions/lynx/index.ts deleted file mode 100644 index c50b6c64d..000000000 --- a/packages/vrender-kits/src/canvas/contributions/lynx/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -// 依然导出canvas和context,便于指定环境直接使用 -export * from './canvas'; -export * from './context'; diff --git a/packages/vrender-kits/src/canvas/contributions/modules.ts b/packages/vrender-kits/src/canvas/contributions/modules.ts deleted file mode 100644 index 10a4f10ac..000000000 --- a/packages/vrender-kits/src/canvas/contributions/modules.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { registerBrowserCanvasFactories } from './browser/modules'; -import { registerFeishuCanvasFactories } from './feishu/modules'; -import { registerLynxCanvasFactories } from './lynx/modules'; -import { registerNodeCanvasFactories } from './node/modules'; -import { registerTaroCanvasFactories } from './taro/modules'; -import { registerTTCanvasFactories } from './tt/modules'; -import { registerWxCanvasFactories } from './wx/modules'; - -export function loadAllCavnvas() { - registerBrowserCanvasFactories(); - registerFeishuCanvasFactories(); - registerLynxCanvasFactories(); - registerNodeCanvasFactories(); - registerTaroCanvasFactories(); - registerTTCanvasFactories(); - registerWxCanvasFactories(); -} - -export function loadBrowserCanvas() { - registerBrowserCanvasFactories(); -} - -export function loadFeishuCanvas() { - registerFeishuCanvasFactories(); -} - -export function loadLynxCanvas() { - registerLynxCanvasFactories(); -} - -export function loadNodeCanvas() { - registerNodeCanvasFactories(); -} - -export function loadTaroCanvas() { - registerTaroCanvasFactories(); -} - -export function loadTTCanvas() { - registerTTCanvasFactories(); -} - -export function loadWxCanvas() { - registerWxCanvasFactories(); -} diff --git a/packages/vrender-kits/src/canvas/contributions/node/index.ts b/packages/vrender-kits/src/canvas/contributions/node/index.ts deleted file mode 100644 index c50b6c64d..000000000 --- a/packages/vrender-kits/src/canvas/contributions/node/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -// 依然导出canvas和context,便于指定环境直接使用 -export * from './canvas'; -export * from './context'; diff --git a/packages/vrender-kits/src/canvas/contributions/taro/index.ts b/packages/vrender-kits/src/canvas/contributions/taro/index.ts deleted file mode 100644 index c50b6c64d..000000000 --- a/packages/vrender-kits/src/canvas/contributions/taro/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -// 依然导出canvas和context,便于指定环境直接使用 -export * from './canvas'; -export * from './context'; diff --git a/packages/vrender-kits/src/canvas/contributions/tt/index.ts b/packages/vrender-kits/src/canvas/contributions/tt/index.ts deleted file mode 100644 index c50b6c64d..000000000 --- a/packages/vrender-kits/src/canvas/contributions/tt/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -// 依然导出canvas和context,便于指定环境直接使用 -export * from './canvas'; -export * from './context'; diff --git a/packages/vrender-kits/src/canvas/contributions/wx/index.ts b/packages/vrender-kits/src/canvas/contributions/wx/index.ts deleted file mode 100644 index c50b6c64d..000000000 --- a/packages/vrender-kits/src/canvas/contributions/wx/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -// 依然导出canvas和context,便于指定环境直接使用 -export * from './canvas'; -export * from './context'; diff --git a/packages/vrender-kits/src/canvas/contributions/create-canvas-module.ts b/packages/vrender-kits/src/canvas/create-canvas-module.ts similarity index 100% rename from packages/vrender-kits/src/canvas/contributions/create-canvas-module.ts rename to packages/vrender-kits/src/canvas/create-canvas-module.ts diff --git a/packages/vrender-kits/src/canvas/contributions/feishu/canvas.ts b/packages/vrender-kits/src/canvas/feishu/canvas.ts similarity index 100% rename from packages/vrender-kits/src/canvas/contributions/feishu/canvas.ts rename to packages/vrender-kits/src/canvas/feishu/canvas.ts diff --git a/packages/vrender-kits/src/canvas/contributions/feishu/context.ts b/packages/vrender-kits/src/canvas/feishu/context.ts similarity index 96% rename from packages/vrender-kits/src/canvas/contributions/feishu/context.ts rename to packages/vrender-kits/src/canvas/feishu/context.ts index d9d6339ac..cd157f902 100644 --- a/packages/vrender-kits/src/canvas/contributions/feishu/context.ts +++ b/packages/vrender-kits/src/canvas/feishu/context.ts @@ -1,6 +1,6 @@ // 参考konva import type { IContext2d, EnvType } from '@visactor/vrender-core'; -import { BrowserContext2d } from '../browser'; +import { BrowserContext2d } from '../browser/context'; declare const tt: { canvasGetImageData: (d: any) => any; diff --git a/packages/vrender-kits/src/canvas/contributions/feishu/modules.ts b/packages/vrender-kits/src/canvas/feishu/index.ts similarity index 85% rename from packages/vrender-kits/src/canvas/contributions/feishu/modules.ts rename to packages/vrender-kits/src/canvas/feishu/index.ts index f43c31a73..743036554 100644 --- a/packages/vrender-kits/src/canvas/contributions/feishu/modules.ts +++ b/packages/vrender-kits/src/canvas/feishu/index.ts @@ -5,3 +5,5 @@ import { registerCanvasFactories } from '../create-canvas-module'; export function registerFeishuCanvasFactories() { registerCanvasFactories(FeishuCanvas, FeishuContext2d); } + +export { FeishuCanvas, FeishuContext2d }; diff --git a/packages/vrender-kits/src/canvas/contributions/harmony/canvas.ts b/packages/vrender-kits/src/canvas/harmony/canvas.ts similarity index 100% rename from packages/vrender-kits/src/canvas/contributions/harmony/canvas.ts rename to packages/vrender-kits/src/canvas/harmony/canvas.ts diff --git a/packages/vrender-kits/src/canvas/contributions/harmony/context.ts b/packages/vrender-kits/src/canvas/harmony/context.ts similarity index 100% rename from packages/vrender-kits/src/canvas/contributions/harmony/context.ts rename to packages/vrender-kits/src/canvas/harmony/context.ts diff --git a/packages/vrender-kits/src/canvas/contributions/harmony/modules.ts b/packages/vrender-kits/src/canvas/harmony/index.ts similarity index 85% rename from packages/vrender-kits/src/canvas/contributions/harmony/modules.ts rename to packages/vrender-kits/src/canvas/harmony/index.ts index 8f4a4afee..5ef4e8348 100644 --- a/packages/vrender-kits/src/canvas/contributions/harmony/modules.ts +++ b/packages/vrender-kits/src/canvas/harmony/index.ts @@ -5,3 +5,5 @@ import { registerCanvasFactories } from '../create-canvas-module'; export function registerHarmonyCanvasFactories() { registerCanvasFactories(HarmonyCanvas, HarmonyContext2d); } + +export { HarmonyCanvas, HarmonyContext2d }; diff --git a/packages/vrender-kits/src/canvas/index.ts b/packages/vrender-kits/src/canvas/index.ts index 34b40bff0..800e9a1c6 100644 --- a/packages/vrender-kits/src/canvas/index.ts +++ b/packages/vrender-kits/src/canvas/index.ts @@ -1 +1,8 @@ -export * from './contributions/modules'; +export { registerBrowserCanvasFactories } from './browser'; +export { registerFeishuCanvasFactories } from './feishu'; +export { registerHarmonyCanvasFactories } from './harmony'; +export { registerLynxCanvasFactories } from './lynx'; +export { registerNodeCanvasFactories } from './node'; +export { registerTaroCanvasFactories } from './taro'; +export { registerTTCanvasFactories } from './tt'; +export { registerWxCanvasFactories } from './wx'; diff --git a/packages/vrender-kits/src/canvas/contributions/lynx/canvas.ts b/packages/vrender-kits/src/canvas/lynx/canvas.ts similarity index 100% rename from packages/vrender-kits/src/canvas/contributions/lynx/canvas.ts rename to packages/vrender-kits/src/canvas/lynx/canvas.ts diff --git a/packages/vrender-kits/src/canvas/contributions/lynx/context.ts b/packages/vrender-kits/src/canvas/lynx/context.ts similarity index 100% rename from packages/vrender-kits/src/canvas/contributions/lynx/context.ts rename to packages/vrender-kits/src/canvas/lynx/context.ts diff --git a/packages/vrender-kits/src/canvas/contributions/lynx/modules.ts b/packages/vrender-kits/src/canvas/lynx/index.ts similarity index 86% rename from packages/vrender-kits/src/canvas/contributions/lynx/modules.ts rename to packages/vrender-kits/src/canvas/lynx/index.ts index 7b711747f..eb51dafb9 100644 --- a/packages/vrender-kits/src/canvas/contributions/lynx/modules.ts +++ b/packages/vrender-kits/src/canvas/lynx/index.ts @@ -5,3 +5,5 @@ import { registerCanvasFactories } from '../create-canvas-module'; export function registerLynxCanvasFactories() { registerCanvasFactories(LynxCanvas, LynxContext2d); } + +export { LynxCanvas, LynxContext2d }; diff --git a/packages/vrender-kits/src/canvas/contributions/node-canvas.d.ts b/packages/vrender-kits/src/canvas/node-canvas.d.ts similarity index 100% rename from packages/vrender-kits/src/canvas/contributions/node-canvas.d.ts rename to packages/vrender-kits/src/canvas/node-canvas.d.ts diff --git a/packages/vrender-kits/src/canvas/contributions/node/canvas.ts b/packages/vrender-kits/src/canvas/node/canvas.ts similarity index 100% rename from packages/vrender-kits/src/canvas/contributions/node/canvas.ts rename to packages/vrender-kits/src/canvas/node/canvas.ts diff --git a/packages/vrender-kits/src/canvas/contributions/node/context.ts b/packages/vrender-kits/src/canvas/node/context.ts similarity index 92% rename from packages/vrender-kits/src/canvas/contributions/node/context.ts rename to packages/vrender-kits/src/canvas/node/context.ts index 508d34dcb..34e93f785 100644 --- a/packages/vrender-kits/src/canvas/contributions/node/context.ts +++ b/packages/vrender-kits/src/canvas/node/context.ts @@ -1,7 +1,7 @@ // 参考konva import { Matrix } from '@visactor/vutils'; import type { IContext2d, EnvType, ICanvas } from '@visactor/vrender-core'; -import { BrowserContext2d } from '../browser'; +import { BrowserContext2d } from '../browser/context'; export class NodeContext2d extends BrowserContext2d implements IContext2d { static env: EnvType = 'node'; diff --git a/packages/vrender-kits/src/canvas/contributions/node/modules.ts b/packages/vrender-kits/src/canvas/node/index.ts similarity index 86% rename from packages/vrender-kits/src/canvas/contributions/node/modules.ts rename to packages/vrender-kits/src/canvas/node/index.ts index 9d1743889..17e6b1a3f 100644 --- a/packages/vrender-kits/src/canvas/contributions/node/modules.ts +++ b/packages/vrender-kits/src/canvas/node/index.ts @@ -5,3 +5,5 @@ import { registerCanvasFactories } from '../create-canvas-module'; export function registerNodeCanvasFactories() { registerCanvasFactories(NodeCanvas, NodeContext2d); } + +export { NodeCanvas, NodeContext2d }; diff --git a/packages/vrender-kits/src/canvas/contributions/taro/canvas.ts b/packages/vrender-kits/src/canvas/taro/canvas.ts similarity index 100% rename from packages/vrender-kits/src/canvas/contributions/taro/canvas.ts rename to packages/vrender-kits/src/canvas/taro/canvas.ts diff --git a/packages/vrender-kits/src/canvas/contributions/taro/context.ts b/packages/vrender-kits/src/canvas/taro/context.ts similarity index 99% rename from packages/vrender-kits/src/canvas/contributions/taro/context.ts rename to packages/vrender-kits/src/canvas/taro/context.ts index 49a9f2d83..07e7014fd 100644 --- a/packages/vrender-kits/src/canvas/contributions/taro/context.ts +++ b/packages/vrender-kits/src/canvas/taro/context.ts @@ -10,7 +10,7 @@ import type { IConicalGradientData, EnvType } from '@visactor/vrender-core'; -import { BrowserContext2d } from '../browser'; +import { BrowserContext2d } from '../browser/context'; import { getContextFont } from '@visactor/vutils'; // 考虑taro-feishu等环境 diff --git a/packages/vrender-kits/src/canvas/contributions/taro/modules.ts b/packages/vrender-kits/src/canvas/taro/index.ts similarity index 86% rename from packages/vrender-kits/src/canvas/contributions/taro/modules.ts rename to packages/vrender-kits/src/canvas/taro/index.ts index cd2690802..c98b4c91f 100644 --- a/packages/vrender-kits/src/canvas/contributions/taro/modules.ts +++ b/packages/vrender-kits/src/canvas/taro/index.ts @@ -5,3 +5,5 @@ import { registerCanvasFactories } from '../create-canvas-module'; export function registerTaroCanvasFactories() { registerCanvasFactories(TaroCanvas, TaroContext2d); } + +export { TaroCanvas, TaroContext2d }; diff --git a/packages/vrender-kits/src/canvas/contributions/tt/canvas.ts b/packages/vrender-kits/src/canvas/tt/canvas.ts similarity index 100% rename from packages/vrender-kits/src/canvas/contributions/tt/canvas.ts rename to packages/vrender-kits/src/canvas/tt/canvas.ts diff --git a/packages/vrender-kits/src/canvas/contributions/tt/context.ts b/packages/vrender-kits/src/canvas/tt/context.ts similarity index 100% rename from packages/vrender-kits/src/canvas/contributions/tt/context.ts rename to packages/vrender-kits/src/canvas/tt/context.ts diff --git a/packages/vrender-kits/src/canvas/contributions/tt/modules.ts b/packages/vrender-kits/src/canvas/tt/index.ts similarity index 87% rename from packages/vrender-kits/src/canvas/contributions/tt/modules.ts rename to packages/vrender-kits/src/canvas/tt/index.ts index 4c842b479..443980537 100644 --- a/packages/vrender-kits/src/canvas/contributions/tt/modules.ts +++ b/packages/vrender-kits/src/canvas/tt/index.ts @@ -5,3 +5,5 @@ import { registerCanvasFactories } from '../create-canvas-module'; export function registerTTCanvasFactories() { registerCanvasFactories(TTCanvas, TTContext2d); } + +export { TTCanvas, TTContext2d }; diff --git a/packages/vrender-kits/src/canvas/contributions/wx/canvas.ts b/packages/vrender-kits/src/canvas/wx/canvas.ts similarity index 100% rename from packages/vrender-kits/src/canvas/contributions/wx/canvas.ts rename to packages/vrender-kits/src/canvas/wx/canvas.ts diff --git a/packages/vrender-kits/src/canvas/contributions/wx/context.ts b/packages/vrender-kits/src/canvas/wx/context.ts similarity index 86% rename from packages/vrender-kits/src/canvas/contributions/wx/context.ts rename to packages/vrender-kits/src/canvas/wx/context.ts index 4741eb045..3d05f87b3 100644 --- a/packages/vrender-kits/src/canvas/contributions/wx/context.ts +++ b/packages/vrender-kits/src/canvas/wx/context.ts @@ -1,6 +1,6 @@ // 参考konva import type { IContext2d, EnvType } from '@visactor/vrender-core'; -import { BrowserContext2d } from '../browser'; +import { BrowserContext2d } from '../browser/context'; export class WxContext2d extends BrowserContext2d implements IContext2d { static env: EnvType = 'wx'; diff --git a/packages/vrender-kits/src/canvas/contributions/wx/modules.ts b/packages/vrender-kits/src/canvas/wx/index.ts similarity index 87% rename from packages/vrender-kits/src/canvas/contributions/wx/modules.ts rename to packages/vrender-kits/src/canvas/wx/index.ts index 5b60c42ad..e4707eda6 100644 --- a/packages/vrender-kits/src/canvas/contributions/wx/modules.ts +++ b/packages/vrender-kits/src/canvas/wx/index.ts @@ -5,3 +5,5 @@ import { registerCanvasFactories } from '../create-canvas-module'; export function registerWxCanvasFactories() { registerCanvasFactories(WxCanvas, WxContext2d); } + +export { WxCanvas, WxContext2d }; diff --git a/packages/vrender-kits/src/env/all.ts b/packages/vrender-kits/src/env/all.ts index 988c2e1e0..d0210bca7 100644 --- a/packages/vrender-kits/src/env/all.ts +++ b/packages/vrender-kits/src/env/all.ts @@ -1,10 +1,10 @@ import { contributionRegistry, vglobal } from '@visactor/vrender-core'; -import { registerBrowserEnvRegistry } from './browser'; -import { registerFeishuEnvRegistry } from './feishu'; -import { registerLynxEnvRegistry } from './lynx'; -import { registerNodeEnvRegistry } from './node'; -import { registerTaroEnvRegistry } from './taro'; -import { registerWxEnvRegistry } from './wx'; +import { loadBrowserEnv } from './browser'; +import { loadFeishuEnv } from './feishu'; +import { loadLynxEnv } from './lynx'; +import { loadNodeEnv } from './node'; +import { loadTaroEnv } from './taro'; +import { loadWxEnv } from './wx'; import { registerCanvasPickerService } from '../picker/canvas-module'; import { registerMathPickerService } from '../picker/math-module'; // import { loadMathPicker } from '../picker'; @@ -16,12 +16,12 @@ export function loadAllEnv() { export function loadAllModule() { if (!loadAllModule.__loaded) { loadAllModule.__loaded = true; - registerBrowserEnvRegistry(); - registerFeishuEnvRegistry(); - registerLynxEnvRegistry(); - registerNodeEnvRegistry(); - registerTaroEnvRegistry(); - registerWxEnvRegistry(); + loadBrowserEnv(); + loadFeishuEnv(); + loadLynxEnv(); + loadNodeEnv(); + loadTaroEnv(); + loadWxEnv(); registerCanvasPickerService(); vglobal.hooks.onSetEnv.tap('registerMathPickerService', (lastEnv, env) => { env !== 'browser' && registerMathPickerService(); diff --git a/packages/vrender-kits/src/env/browser.ts b/packages/vrender-kits/src/env/browser.ts index 3e95555a6..f30876b25 100644 --- a/packages/vrender-kits/src/env/browser.ts +++ b/packages/vrender-kits/src/env/browser.ts @@ -1,16 +1,13 @@ import { EnvContribution, contributionRegistry } from '@visactor/vrender-core'; -// import { browserEnvModule } from './contributions/module'; import { BrowserEnvContribution } from './contributions/browser-contribution'; import { BrowserWindowHandlerContribution } from '../window/contributions/browser-contribution'; import { WindowHandlerContribution } from '@visactor/vrender-core'; -import { registerBrowserCanvasFactories } from '../canvas/contributions/browser/modules'; - -// Legacy ContainerModule and loaders removed (registry-only) +import { registerBrowserCanvasFactories } from '../canvas/browser/'; /** * Registry-based registration for browser env/window */ -export function registerBrowserEnvRegistry() { +export function loadBrowserEnv() { registerBrowserCanvasFactories(); // Env contribution contributionRegistry.register(EnvContribution, new BrowserEnvContribution()); diff --git a/packages/vrender-kits/src/env/feishu.ts b/packages/vrender-kits/src/env/feishu.ts index 929bfffdd..78dd7081a 100644 --- a/packages/vrender-kits/src/env/feishu.ts +++ b/packages/vrender-kits/src/env/feishu.ts @@ -1,11 +1,11 @@ import { EnvContribution, contributionRegistry, WindowHandlerContribution } from '@visactor/vrender-core'; import { FeishuWindowHandlerContribution } from '../window/contributions/feishu-contribution'; import { FeishuEnvContribution } from './contributions/feishu-contribution'; - -// Legacy ContainerModule and loaders removed (registry-only) +import { registerFeishuCanvasFactories } from '../canvas'; /** Registry-based registration for feishu env/window */ -export function registerFeishuEnvRegistry() { +export function loadFeishuEnv() { + registerFeishuCanvasFactories(); contributionRegistry.register(EnvContribution, new FeishuEnvContribution()); contributionRegistry.register(WindowHandlerContribution, new FeishuWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/harmony.ts b/packages/vrender-kits/src/env/harmony.ts index dfc217b9d..2cc519dc1 100644 --- a/packages/vrender-kits/src/env/harmony.ts +++ b/packages/vrender-kits/src/env/harmony.ts @@ -1,9 +1,11 @@ import { EnvContribution, contributionRegistry, WindowHandlerContribution } from '@visactor/vrender-core'; import { HarmonyWindowHandlerContribution } from '../window/contributions/harmony-contribution'; import { HarmonyEnvContribution } from './contributions/harmony-contribution'; +import { registerHarmonyCanvasFactories } from '../canvas'; /** Registry-based registration for harmony env/window */ -export function registerHarmonyEnvRegistry() { +export function loadHarmonyEnv() { + registerHarmonyCanvasFactories(); contributionRegistry.register(EnvContribution, new HarmonyEnvContribution()); contributionRegistry.register(WindowHandlerContribution, new HarmonyWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/lynx.ts b/packages/vrender-kits/src/env/lynx.ts index 0cfe4c20d..012fc07a4 100644 --- a/packages/vrender-kits/src/env/lynx.ts +++ b/packages/vrender-kits/src/env/lynx.ts @@ -1,12 +1,14 @@ import { EnvContribution, contributionRegistry, WindowHandlerContribution } from '@visactor/vrender-core'; import { LynxWindowHandlerContribution } from '../window/contributions/lynx-contribution'; import { LynxEnvContribution } from './contributions/lynx-contribution'; +import { registerLynxCanvasFactories } from '../canvas'; // import { lynxEnvModule } from './contributions/module'; // Legacy ContainerModule and loaders removed (registry-only) /** Registry-based registration for lynx env/window */ -export function registerLynxEnvRegistry() { +export function loadLynxEnv() { + registerLynxCanvasFactories(); contributionRegistry.register(EnvContribution, new LynxEnvContribution()); contributionRegistry.register(WindowHandlerContribution, new LynxWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/node.ts b/packages/vrender-kits/src/env/node.ts index 16e7fa8ed..bf576a4b0 100644 --- a/packages/vrender-kits/src/env/node.ts +++ b/packages/vrender-kits/src/env/node.ts @@ -4,13 +4,15 @@ import { EnvContribution, contributionRegistry } from '@visactor/vrender-core'; import { NodeEnvContribution } from './contributions/node-contribution'; import { NodeWindowHandlerContribution } from '../window/contributions/node-contribution'; import { WindowHandlerContribution } from '@visactor/vrender-core'; +import { registerNodeCanvasFactories } from '../canvas'; // Legacy ContainerModule and loaders removed (registry-only) /** * Registry-based registration for node env/window */ -export function registerNodeEnvRegistry() { +export function loadNodeEnv() { + registerNodeCanvasFactories; // Env contribution contributionRegistry.register(EnvContribution, new NodeEnvContribution()); // Window handler contribution diff --git a/packages/vrender-kits/src/env/taro.ts b/packages/vrender-kits/src/env/taro.ts index 59fdd89a1..f6cc4bc0a 100644 --- a/packages/vrender-kits/src/env/taro.ts +++ b/packages/vrender-kits/src/env/taro.ts @@ -1,11 +1,11 @@ import { EnvContribution, contributionRegistry, WindowHandlerContribution } from '@visactor/vrender-core'; import { TaroWindowHandlerContribution } from '../window/contributions/taro-contribution'; import { TaroEnvContribution } from './contributions/taro-contribution'; - -// Legacy ContainerModule and loaders removed (registry-only) +import { registerTaroCanvasFactories } from '../canvas'; /** Registry-based registration for taro env/window */ -export function registerTaroEnvRegistry() { +export function loadTaroEnv() { + registerTaroCanvasFactories(); contributionRegistry.register(EnvContribution, new TaroEnvContribution()); contributionRegistry.register(WindowHandlerContribution, new TaroWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/tt.ts b/packages/vrender-kits/src/env/tt.ts index 7fe1d9047..ed84fd775 100644 --- a/packages/vrender-kits/src/env/tt.ts +++ b/packages/vrender-kits/src/env/tt.ts @@ -1,9 +1,11 @@ import { EnvContribution, contributionRegistry, WindowHandlerContribution } from '@visactor/vrender-core'; import { TTWindowHandlerContribution } from '../window/contributions/tt-contribution'; import { TTEnvContribution } from './contributions/tt-contribution'; +import { registerTTCanvasFactories } from '../canvas'; /** Registry-based registration for tt env/window */ -export function registerTtEnvRegistry() { +export function loadTtEnv() { + registerTTCanvasFactories(); contributionRegistry.register(EnvContribution, new TTEnvContribution()); contributionRegistry.register(WindowHandlerContribution, new TTWindowHandlerContribution()); } diff --git a/packages/vrender-kits/src/env/wx.ts b/packages/vrender-kits/src/env/wx.ts index 0ac62508f..d478de92b 100644 --- a/packages/vrender-kits/src/env/wx.ts +++ b/packages/vrender-kits/src/env/wx.ts @@ -1,14 +1,14 @@ import { EnvContribution, contributionRegistry, WindowHandlerContribution } from '@visactor/vrender-core'; // import { loadMathPicker } from '../picker/math-module'; // import { wxEnvModule } from './contributions/module'; -import { registerWxCanvasFactories } from '../canvas/contributions/wx/modules'; +import { registerWxCanvasFactories } from '../canvas/wx'; import { WxWindowHandlerContribution } from '../window/contributions/wx-contribution'; import { WxEnvContribution } from './contributions/wx-contribution'; // Legacy ContainerModule and loaders removed (registry-only) /** Registry-based registration for wx env/window */ -export function registerWxEnvRegistry() { +export function loadWxEnv() { contributionRegistry.register(EnvContribution, new WxEnvContribution()); // ensure canvas factories for wx are registered registerWxCanvasFactories(); diff --git a/packages/vrender-kits/src/render/contributions/rough/rough-arc.ts b/packages/vrender-kits/src/render/contributions/rough/rough-arc.ts index a7867e020..d79c6fa6d 100644 --- a/packages/vrender-kits/src/render/contributions/rough/rough-arc.ts +++ b/packages/vrender-kits/src/render/contributions/rough/rough-arc.ts @@ -2,11 +2,6 @@ import type { IGraphicRender, IRenderService, IArc, - IGraphicAttribute, - IContext2d, - IGraphic, - IMarkAttribute, - IThemeAttribute, IDrawContext, IGraphicRenderDrawParams } from '@visactor/vrender-core'; diff --git a/packages/vrender-kits/src/window/contributions/browser-contribution.ts b/packages/vrender-kits/src/window/contributions/browser-contribution.ts index d6978033f..b7a191960 100644 --- a/packages/vrender-kits/src/window/contributions/browser-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/browser-contribution.ts @@ -10,7 +10,7 @@ import type { } from '@visactor/vrender-core'; import type { IBoundsLike, IMatrix, IBounds } from '@visactor/vutils'; import { Matrix, AABBBounds } from '@visactor/vutils'; -import { BrowserCanvas } from '../../canvas/contributions/browser'; +import { BrowserCanvas } from '../../canvas/browser'; export class BrowserWindowHandlerContribution extends BaseWindowHandlerContribution diff --git a/packages/vrender-kits/src/window/contributions/feishu-contribution.ts b/packages/vrender-kits/src/window/contributions/feishu-contribution.ts index ce14383d1..2af38c0df 100644 --- a/packages/vrender-kits/src/window/contributions/feishu-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/feishu-contribution.ts @@ -9,7 +9,7 @@ import type { IWindowParams } from '@visactor/vrender-core'; import type { IBoundsLike } from '@visactor/vutils'; -import { FeishuCanvas } from '../../canvas/contributions/feishu'; +import { FeishuCanvas } from '../../canvas/feishu'; class MiniAppEventManager { addEventListener(type: string, func: EventListenerOrEventListenerObject) { diff --git a/packages/vrender-kits/src/window/contributions/harmony-contribution.ts b/packages/vrender-kits/src/window/contributions/harmony-contribution.ts index cb62cbf9f..0cf8b1be5 100644 --- a/packages/vrender-kits/src/window/contributions/harmony-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/harmony-contribution.ts @@ -8,7 +8,7 @@ import type { IWindowParams, IWindowHandlerContribution } from '@visactor/vrender-core'; -import { HarmonyCanvas } from '../../canvas/contributions/harmony'; +import { HarmonyCanvas } from '../../canvas/harmony'; class MiniAppEventManager { addEventListener(type: string, func: EventListenerOrEventListenerObject) { diff --git a/packages/vrender-kits/src/window/contributions/lynx-contribution.ts b/packages/vrender-kits/src/window/contributions/lynx-contribution.ts index f972464ef..1a933d803 100644 --- a/packages/vrender-kits/src/window/contributions/lynx-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/lynx-contribution.ts @@ -9,7 +9,7 @@ import type { IWindowHandlerContribution } from '@visactor/vrender-core'; import type { IBoundsLike } from '@visactor/vutils'; -import { LynxCanvas } from '../../canvas/contributions/lynx'; +import { LynxCanvas } from '../../canvas/lynx'; class MiniAppEventManager { addEventListener(type: string, func: EventListenerOrEventListenerObject) { diff --git a/packages/vrender-kits/src/window/contributions/node-contribution.ts b/packages/vrender-kits/src/window/contributions/node-contribution.ts index 9f0056840..3a699e2de 100644 --- a/packages/vrender-kits/src/window/contributions/node-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/node-contribution.ts @@ -9,7 +9,7 @@ import type { IWindowHandlerContribution, IWindowParams } from '@visactor/vrender-core'; -import { NodeCanvas } from '../../canvas/contributions/node'; +import { NodeCanvas } from '../../canvas/node'; export class NodeWindowHandlerContribution extends BaseWindowHandlerContribution implements IWindowHandlerContribution { static env: EnvType = 'node'; diff --git a/packages/vrender-kits/src/window/contributions/taro-contribution.ts b/packages/vrender-kits/src/window/contributions/taro-contribution.ts index 0911cecc0..6b57d5003 100644 --- a/packages/vrender-kits/src/window/contributions/taro-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/taro-contribution.ts @@ -9,7 +9,7 @@ import type { IWindowHandlerContribution } from '@visactor/vrender-core'; import type { IBoundsLike } from '@visactor/vutils'; -import { TaroCanvas } from '../../canvas/contributions/taro'; +import { TaroCanvas } from '../../canvas/taro'; class MiniAppEventManager { addEventListener(type: string, func: EventListenerOrEventListenerObject) { diff --git a/packages/vrender-kits/src/window/contributions/tt-contribution.ts b/packages/vrender-kits/src/window/contributions/tt-contribution.ts index 8f240f949..e718d3e92 100644 --- a/packages/vrender-kits/src/window/contributions/tt-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/tt-contribution.ts @@ -9,7 +9,7 @@ import type { IWindowParams } from '@visactor/vrender-core'; import type { IBoundsLike } from '@visactor/vutils'; -import { TTCanvas } from '../../canvas/contributions/tt'; +import { TTCanvas } from '../../canvas/tt'; class MiniAppEventManager { addEventListener(type: string, func: EventListenerOrEventListenerObject) { diff --git a/packages/vrender-kits/src/window/contributions/wx-contribution.ts b/packages/vrender-kits/src/window/contributions/wx-contribution.ts index 51035a0c2..4836b3495 100644 --- a/packages/vrender-kits/src/window/contributions/wx-contribution.ts +++ b/packages/vrender-kits/src/window/contributions/wx-contribution.ts @@ -8,8 +8,7 @@ import type { IWindowHandlerContribution, IWindowParams } from '@visactor/vrender-core'; -import type { IBoundsLike } from '@visactor/vutils'; -import { WxCanvas } from '../../canvas/contributions/wx'; +import { WxCanvas } from '../../canvas/wx'; class MiniAppEventManager { addEventListener(type: string, func: EventListenerOrEventListenerObject) { diff --git a/packages/vrender/src/index.ts b/packages/vrender/src/index.ts index e429143a0..6423b0cd5 100644 --- a/packages/vrender/src/index.ts +++ b/packages/vrender/src/index.ts @@ -9,7 +9,7 @@ import { registerDirectionalLight, registerOrthoCamera } from '@visactor/vrender-core'; -import { registerStar, registerBrowserEnvRegistry, registerNodeEnvRegistry } from '@visactor/vrender-kits'; +import { registerStar, loadBrowserEnv, loadNodeEnv } from '@visactor/vrender-kits'; import { registerArc, registerArc3d, @@ -38,9 +38,9 @@ export const version = __VERSION__; // Registry-based registration only (drop legacy ContainerModule loaders) if (isBrowserEnv()) { - registerBrowserEnvRegistry(); + loadBrowserEnv(); } else if (isNodeEnv()) { - registerNodeEnvRegistry(); + loadNodeEnv(); } registerArc(); From e3b45a815f1b2f126fce1fa83dd1c1b0e794d366 Mon Sep 17 00:00:00 2001 From: xile611 Date: Wed, 14 Jan 2026 11:21:21 +0800 Subject: [PATCH 4/6] test: update test case and fix inversify --- .../browser/examples/axis-autoWrap.ts | 4 +- .../browser/examples/axis-label-limit.ts | 4 +- .../__tests__/browser/examples/axis-labels.ts | 4 +- .../__tests__/browser/examples/poptip.ts | 4 +- .../__tests__/unit/axis/circle.test.ts | 4 +- .../__tests__/unit/axis/line.test.ts | 4 +- .../unit/axis/overlap/auto-limit.test.ts | 4 +- .../unit/bugfix/legend-focus-layout.test.ts | 4 +- .../__tests__/unit/crosshair.test.ts | 4 +- .../__tests__/unit/data-zoom.test.ts | 4 +- .../__tests__/unit/legend/discrete.test.ts | 4 +- .../__tests__/unit/marker/arc-area.test.ts | 4 +- .../__tests__/unit/marker/arc-line.test.ts | 4 +- .../__tests__/unit/marker/area.test.ts | 4 +- .../__tests__/unit/marker/line.test.ts | 4 +- .../__tests__/unit/marker/point.test.ts | 4 +- .../__tests__/unit/pager.test.ts | 4 +- .../__tests__/unit/player/controller.test.ts | 4 +- .../__tests__/unit/segment.test.ts | 4 +- .../__tests__/unit/slider.test.ts | 4 +- .../__tests__/unit/tag.test.ts | 4 +- .../__tests__/util/render.ts | 4 +- packages/vrender-components/setup-mock.js | 94 +------------------ packages/vrender-core/src/index.ts | 1 + 24 files changed, 46 insertions(+), 137 deletions(-) diff --git a/packages/vrender-components/__tests__/browser/examples/axis-autoWrap.ts b/packages/vrender-components/__tests__/browser/examples/axis-autoWrap.ts index e36c21c5e..c502ae932 100644 --- a/packages/vrender-components/__tests__/browser/examples/axis-autoWrap.ts +++ b/packages/vrender-components/__tests__/browser/examples/axis-autoWrap.ts @@ -1,6 +1,6 @@ import { createStage } from '@visactor/vrender-core'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); import render from '../../util/render'; import { LineAxis } from '../../../src'; diff --git a/packages/vrender-components/__tests__/browser/examples/axis-label-limit.ts b/packages/vrender-components/__tests__/browser/examples/axis-label-limit.ts index f93d668f8..41f547f42 100644 --- a/packages/vrender-components/__tests__/browser/examples/axis-label-limit.ts +++ b/packages/vrender-components/__tests__/browser/examples/axis-label-limit.ts @@ -1,6 +1,6 @@ import { createStage } from '@visactor/vrender-core'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); import { PointScale } from '@visactor/vscale'; import { LineAxis } from '../../../src'; diff --git a/packages/vrender-components/__tests__/browser/examples/axis-labels.ts b/packages/vrender-components/__tests__/browser/examples/axis-labels.ts index 765dd682f..98b483e73 100644 --- a/packages/vrender-components/__tests__/browser/examples/axis-labels.ts +++ b/packages/vrender-components/__tests__/browser/examples/axis-labels.ts @@ -1,6 +1,6 @@ import { createStage } from '@visactor/vrender-core'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); import render from '../../util/render'; import { LineAxis } from '../../../src'; diff --git a/packages/vrender-components/__tests__/browser/examples/poptip.ts b/packages/vrender-components/__tests__/browser/examples/poptip.ts index 604aa865c..7b5c76e12 100644 --- a/packages/vrender-components/__tests__/browser/examples/poptip.ts +++ b/packages/vrender-components/__tests__/browser/examples/poptip.ts @@ -8,8 +8,8 @@ import { registerAnimate, registerCustomAnimate } from '@visactor/vrender-animat registerAnimate(); registerCustomAnimate(); -// import { initBrowserEnv } from '@visactor/vrender-kits'; -// initBrowserEnv(); +// import { loadBrowserEnv } from '@visactor/vrender-kits'; +// loadBrowserEnv(); loadPoptip(); export function run() { diff --git a/packages/vrender-components/__tests__/unit/axis/circle.test.ts b/packages/vrender-components/__tests__/unit/axis/circle.test.ts index 7ca2016e1..d2da4d2b3 100644 --- a/packages/vrender-components/__tests__/unit/axis/circle.test.ts +++ b/packages/vrender-components/__tests__/unit/axis/circle.test.ts @@ -5,8 +5,8 @@ import { createCanvas } from '../../util/dom'; import { createStage } from '../../util/vrender'; import type { Tag } from '../../../src/tag/tag'; import { AXIS_ELEMENT_NAME } from '../../../src/axis/constant'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); describe('Circle Axis', () => { let stage: Stage; diff --git a/packages/vrender-components/__tests__/unit/axis/line.test.ts b/packages/vrender-components/__tests__/unit/axis/line.test.ts index 11e61dc75..8c5ea7b69 100644 --- a/packages/vrender-components/__tests__/unit/axis/line.test.ts +++ b/packages/vrender-components/__tests__/unit/axis/line.test.ts @@ -5,8 +5,8 @@ import { createCanvas } from '../../util/dom'; import { createStage } from '../../util/vrender'; import { AXIS_ELEMENT_NAME } from '../../../src/axis/constant'; import { Tag } from './../../../src/tag/tag'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); describe('Line Axis', () => { let stage: Stage; diff --git a/packages/vrender-components/__tests__/unit/axis/overlap/auto-limit.test.ts b/packages/vrender-components/__tests__/unit/axis/overlap/auto-limit.test.ts index 194538286..9233f981c 100644 --- a/packages/vrender-components/__tests__/unit/axis/overlap/auto-limit.test.ts +++ b/packages/vrender-components/__tests__/unit/axis/overlap/auto-limit.test.ts @@ -3,8 +3,8 @@ import { LineAxis } from '../../../../src'; import { createCanvas } from '../../../util/dom'; import { createStage } from '../../../util/vrender'; import { AXIS_ELEMENT_NAME } from '../../../../src/axis/constant'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); describe('Auto Limit', () => { let stage: Stage; diff --git a/packages/vrender-components/__tests__/unit/bugfix/legend-focus-layout.test.ts b/packages/vrender-components/__tests__/unit/bugfix/legend-focus-layout.test.ts index cd95fe201..d496ff085 100644 --- a/packages/vrender-components/__tests__/unit/bugfix/legend-focus-layout.test.ts +++ b/packages/vrender-components/__tests__/unit/bugfix/legend-focus-layout.test.ts @@ -2,8 +2,8 @@ import type { IGraphic, ISymbol, Stage } from '@visactor/vrender-core'; import { DiscreteLegend, LEGEND_ELEMENT_NAME } from '../../../src'; import { createCanvas } from '../../util/dom'; import { createStage } from '../../util/vrender'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); describe('Legend focus layout', () => { let stage: Stage; diff --git a/packages/vrender-components/__tests__/unit/crosshair.test.ts b/packages/vrender-components/__tests__/unit/crosshair.test.ts index 1fbfd2cb3..cc95bc139 100644 --- a/packages/vrender-components/__tests__/unit/crosshair.test.ts +++ b/packages/vrender-components/__tests__/unit/crosshair.test.ts @@ -3,8 +3,8 @@ import type { IGraphic, Stage, Arc, Path, Rect } from '@visactor/vrender-core'; import { LineCrosshair, CircleCrosshair, PolygonCrosshair, RectCrosshair, SectorCrosshair, Tag } from '../../src'; import { createCanvas } from '../util/dom'; import { createStage } from '../util/vrender'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); describe('Crosshair', () => { let stage: Stage; diff --git a/packages/vrender-components/__tests__/unit/data-zoom.test.ts b/packages/vrender-components/__tests__/unit/data-zoom.test.ts index 20faa0c6b..cd6be9f32 100644 --- a/packages/vrender-components/__tests__/unit/data-zoom.test.ts +++ b/packages/vrender-components/__tests__/unit/data-zoom.test.ts @@ -4,8 +4,8 @@ import type { Tag } from '../../src'; import { DataZoom } from '../../src'; import { createCanvas } from '../util/dom'; import { createStage } from '../util/vrender'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); describe('DataZoom component test', () => { let stage: Stage; diff --git a/packages/vrender-components/__tests__/unit/legend/discrete.test.ts b/packages/vrender-components/__tests__/unit/legend/discrete.test.ts index 42c876851..90f6a95d7 100644 --- a/packages/vrender-components/__tests__/unit/legend/discrete.test.ts +++ b/packages/vrender-components/__tests__/unit/legend/discrete.test.ts @@ -2,8 +2,8 @@ import type { IGraphic, IGroup, IText, Stage } from '@visactor/vrender-core'; import { DiscreteLegend } from '../../../src'; import { createCanvas } from '../../util/dom'; import { createStage } from '../../util/vrender'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); describe('DiscreteLegend', () => { let stage: Stage; diff --git a/packages/vrender-components/__tests__/unit/marker/arc-area.test.ts b/packages/vrender-components/__tests__/unit/marker/arc-area.test.ts index 2e3864309..ca52d948d 100644 --- a/packages/vrender-components/__tests__/unit/marker/arc-area.test.ts +++ b/packages/vrender-components/__tests__/unit/marker/arc-area.test.ts @@ -3,8 +3,8 @@ import type { Tag } from '../../../src'; import { MarkArcArea } from '../../../src'; import { createCanvas } from '../../util/dom'; import { createStage } from '../../util/vrender'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); describe('Marker', () => { let stage: Stage; diff --git a/packages/vrender-components/__tests__/unit/marker/arc-line.test.ts b/packages/vrender-components/__tests__/unit/marker/arc-line.test.ts index dcbcdfc78..6fa60f338 100644 --- a/packages/vrender-components/__tests__/unit/marker/arc-line.test.ts +++ b/packages/vrender-components/__tests__/unit/marker/arc-line.test.ts @@ -5,8 +5,8 @@ import type { ArcSegment, Tag } from '../../../src'; import { MarkArcLine } from '../../../src'; import { createCanvas } from '../../util/dom'; import { createStage } from '../../util/vrender'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); describe('Marker', () => { let stage: Stage; diff --git a/packages/vrender-components/__tests__/unit/marker/area.test.ts b/packages/vrender-components/__tests__/unit/marker/area.test.ts index 2e8a18070..4bd8235eb 100644 --- a/packages/vrender-components/__tests__/unit/marker/area.test.ts +++ b/packages/vrender-components/__tests__/unit/marker/area.test.ts @@ -3,8 +3,8 @@ import type { Tag } from '../../../src'; import { MarkArea } from '../../../src'; import { createCanvas } from '../../util/dom'; import { createStage } from '../../util/vrender'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); describe('Marker', () => { let stage: Stage; diff --git a/packages/vrender-components/__tests__/unit/marker/line.test.ts b/packages/vrender-components/__tests__/unit/marker/line.test.ts index d12e331a5..70beb8771 100644 --- a/packages/vrender-components/__tests__/unit/marker/line.test.ts +++ b/packages/vrender-components/__tests__/unit/marker/line.test.ts @@ -4,8 +4,8 @@ import type { Tag, Segment } from '../../../src'; import { createCanvas } from '../../util/dom'; import { createStage } from '../../util/vrender'; import { MarkLine } from '../../../src/marker/line'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); describe('Marker', () => { let stage: Stage; diff --git a/packages/vrender-components/__tests__/unit/marker/point.test.ts b/packages/vrender-components/__tests__/unit/marker/point.test.ts index 129f1ae51..00df98236 100644 --- a/packages/vrender-components/__tests__/unit/marker/point.test.ts +++ b/packages/vrender-components/__tests__/unit/marker/point.test.ts @@ -3,8 +3,8 @@ import type { Tag, Segment } from '../../../src'; import { MarkPoint } from '../../../src'; import { createCanvas } from '../../util/dom'; import { createStage } from '../../util/vrender'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); describe('Marker', () => { let stage: Stage; diff --git a/packages/vrender-components/__tests__/unit/pager.test.ts b/packages/vrender-components/__tests__/unit/pager.test.ts index 0bf4009bf..8d48600c0 100644 --- a/packages/vrender-components/__tests__/unit/pager.test.ts +++ b/packages/vrender-components/__tests__/unit/pager.test.ts @@ -2,8 +2,8 @@ import type { IGraphic, Stage, ISymbol } from '@visactor/vrender-core'; import { Pager } from '../../src'; import { createCanvas } from '../util/dom'; import { createStage } from '../util/vrender'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); describe('Pager', () => { let stage: Stage; diff --git a/packages/vrender-components/__tests__/unit/player/controller.test.ts b/packages/vrender-components/__tests__/unit/player/controller.test.ts index 24eed11c1..44292edf5 100644 --- a/packages/vrender-components/__tests__/unit/player/controller.test.ts +++ b/packages/vrender-components/__tests__/unit/player/controller.test.ts @@ -1,10 +1,10 @@ import type { IGraphic, Stage } from '@visactor/vrender-core'; import { createCanvas } from '../../util/dom'; import { createStage } from '../../util/vrender'; -import { initBrowserEnv } from '@visactor/vrender-kits'; +import { loadBrowserEnv } from '@visactor/vrender-kits'; import { Controller } from '../../../src/player/controller'; import { ControllerEventEnum, ControllerTypeEnum } from '../../../src/player/controller/constant'; -initBrowserEnv(); +loadBrowserEnv(); describe('PlayerController', () => { let stage: Stage; diff --git a/packages/vrender-components/__tests__/unit/segment.test.ts b/packages/vrender-components/__tests__/unit/segment.test.ts index b327da445..f55fa42ff 100644 --- a/packages/vrender-components/__tests__/unit/segment.test.ts +++ b/packages/vrender-components/__tests__/unit/segment.test.ts @@ -2,8 +2,8 @@ import type { IGraphic, ILine, ILineGraphicAttribute, Stage } from '@visactor/vr import { Segment } from '../../src'; import { createCanvas } from '../util/dom'; import { createStage } from '../util/vrender'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); describe('Segment', () => { let stage: Stage; diff --git a/packages/vrender-components/__tests__/unit/slider.test.ts b/packages/vrender-components/__tests__/unit/slider.test.ts index a74723a39..2f1e82eef 100644 --- a/packages/vrender-components/__tests__/unit/slider.test.ts +++ b/packages/vrender-components/__tests__/unit/slider.test.ts @@ -7,8 +7,8 @@ import type { IGraphic, Stage, ISymbol, IGroup, IRect, IText } from '@visactor/v import { Slider, SLIDER_ELEMENT_NAME } from '../../src'; import { createCanvas } from '../util/dom'; import { createStage } from '../util/vrender'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); describe('Slider', () => { let stage: Stage; diff --git a/packages/vrender-components/__tests__/unit/tag.test.ts b/packages/vrender-components/__tests__/unit/tag.test.ts index 03cbc3dc6..2228ec3f9 100644 --- a/packages/vrender-components/__tests__/unit/tag.test.ts +++ b/packages/vrender-components/__tests__/unit/tag.test.ts @@ -2,8 +2,8 @@ import type { IGraphic, Stage, IRect } from '@visactor/vrender-core'; import { Tag } from '../../src'; import { createCanvas } from '../util/dom'; import { createStage } from '../util/vrender'; -import { initBrowserEnv } from '@visactor/vrender-kits'; -initBrowserEnv(); +import { loadBrowserEnv } from '@visactor/vrender-kits'; +loadBrowserEnv(); describe('Tag', () => { let stage: Stage; diff --git a/packages/vrender-components/__tests__/util/render.ts b/packages/vrender-components/__tests__/util/render.ts index 22fa3d04c..af695deca 100644 --- a/packages/vrender-components/__tests__/util/render.ts +++ b/packages/vrender-components/__tests__/util/render.ts @@ -3,9 +3,9 @@ import type { IGraphic, IStageParams } from '@visactor/vrender-core'; import { Group, Line, Text, createStage, Symbol, Rect, Path, Arc, Area, Circle, Polygon } from '@visactor/vrender-core'; import { array } from '@visactor/vutils'; -import { initBrowserEnv } from '@visactor/vrender-kits'; +import { loadBrowserEnv } from '@visactor/vrender-kits'; import { loadScrollbar } from '../../src'; -initBrowserEnv(); +loadBrowserEnv(); loadScrollbar(); diff --git a/packages/vrender-components/setup-mock.js b/packages/vrender-components/setup-mock.js index cfa30c306..5d4f326bb 100644 --- a/packages/vrender-components/setup-mock.js +++ b/packages/vrender-components/setup-mock.js @@ -18,53 +18,8 @@ const { Pyramid3d, WrapText, graphicCreator, - arcModule, - container, - rectModule, - lineModule, - areaModule, - symbolModule, - textModule, - circleModule, - pathModule, - richtextModule, - polygonModule, - isBrowserEnv, - imageModule, - glyphModule, - rect3dModule, - arc3dModule, - pyramid3dModule + isBrowserEnv } = require('@visactor/vrender-core'); -const { - arc3dCanvasPickModule, - arcCanvasPickModule, - arcMathPickModule, - areaCanvasPickModule, - areaMathPickModule, - circleCanvasPickModule, - circleMathPickModule, - glyphCanvasPickModule, - glyphMathPickModule, - imageCanvasPickModule, - imageMathPickModule, - lineCanvasPickModule, - lineMathPickModule, - pathCanvasPickModule, - pathMathPickModule, - polygonCanvasPickModule, - polygonMathPickModule, - pyramid3dCanvasPickModule, - rect3dCanvasPickModule, - rectCanvasPickModule, - rectMathPickModule, - richTextMathPickModule, - richtextCanvasPickModule, - symbolCanvasPickModule, - symbolMathPickModule, - textCanvasPickModule, - textMathPickModule -} = require('@visactor/vrender-kits'); global.__DEV__ = true; global.__VERSION__ = true; @@ -147,50 +102,3 @@ const obj = { Object.keys(obj).forEach(k => { graphicCreator.RegisterGraphicCreator(k, obj[k]); }); - -const browser = isBrowserEnv(); - -container.load(arcModule); -container.load(browser ? arcCanvasPickModule : arcMathPickModule); - -container.load(rectModule); -container.load(browser ? rectCanvasPickModule : rectMathPickModule); - -container.load(lineModule); -container.load(browser ? lineCanvasPickModule : lineMathPickModule); - -container.load(areaModule); -container.load(browser ? areaCanvasPickModule : areaMathPickModule); - -container.load(symbolModule); -container.load(browser ? symbolCanvasPickModule : symbolMathPickModule); - -container.load(textModule); -container.load(browser ? textCanvasPickModule : textMathPickModule); - -container.load(circleModule); -container.load(browser ? circleCanvasPickModule : circleMathPickModule); - -container.load(pathModule); -container.load(browser ? pathCanvasPickModule : pathMathPickModule); - -container.load(richtextModule); -container.load(browser ? richtextCanvasPickModule : richTextMathPickModule); - -container.load(polygonModule); -container.load(browser ? polygonCanvasPickModule : polygonMathPickModule); - -container.load(imageModule); -container.load(browser ? imageCanvasPickModule : imageMathPickModule); - -container.load(glyphModule); -container.load(browser ? glyphCanvasPickModule : glyphMathPickModule); - -container.load(rect3dModule); -container.load(browser ? rect3dCanvasPickModule : rect3dCanvasPickModule); - -container.load(arc3dModule); -container.load(browser ? arc3dCanvasPickModule : arc3dCanvasPickModule); - -container.load(pyramid3dModule); -container.load(browser ? pyramid3dCanvasPickModule : pyramid3dCanvasPickModule); diff --git a/packages/vrender-core/src/index.ts b/packages/vrender-core/src/index.ts index 001f3bbc1..391582b56 100644 --- a/packages/vrender-core/src/index.ts +++ b/packages/vrender-core/src/index.ts @@ -59,6 +59,7 @@ export * from './constants'; export * from './env-check'; export * from './common/registry'; // 导出 registry export { vglobal, graphicService, graphicUtil, transformUtil, layerService } from './modules'; // 导出全局服务 +export { serviceRegistry, contributionRegistry } from './common/registry'; // 导出注册表以供测试使用 export * from './register/register-arc'; export * from './register/register-arc3d'; From 48d35c266400f7a727d1ced22af5cf0257d491b1 Mon Sep 17 00:00:00 2001 From: xile611 Date: Wed, 14 Jan 2026 19:00:37 +0800 Subject: [PATCH 5/6] fix: fix render of graphics --- packages/vrender-core/src/register-modules.ts | 12 ------------ .../src/render/contributions/render/index.ts | 14 ++++++++++---- packages/vrender-kits/src/register/register-arc.ts | 10 +++++++++- .../vrender-kits/src/register/register-arc3d.ts | 12 ++++++++++-- .../vrender-kits/src/register/register-area.ts | 10 ++++++++-- .../vrender-kits/src/register/register-circle.ts | 10 ++++++++-- .../vrender-kits/src/register/register-glyph.ts | 10 ++++++++-- .../vrender-kits/src/register/register-group.ts | 9 ++++++++- .../vrender-kits/src/register/register-image.ts | 10 ++++++++-- .../vrender-kits/src/register/register-line.ts | 9 ++++++++- .../vrender-kits/src/register/register-path.ts | 10 ++++++++-- .../vrender-kits/src/register/register-polygon.ts | 10 ++++++++-- .../src/register/register-pyramid3d.ts | 12 ++++++++++-- .../vrender-kits/src/register/register-rect.ts | 10 ++++++++-- .../vrender-kits/src/register/register-rect3d.ts | 10 ++++++++-- .../vrender-kits/src/register/register-richtext.ts | 10 ++++++++-- .../vrender-kits/src/register/register-star.ts | 10 ++++++++-- .../vrender-kits/src/register/register-symbol.ts | 10 ++++++++-- .../vrender-kits/src/register/register-text.ts | 10 ++++++++-- 19 files changed, 151 insertions(+), 47 deletions(-) diff --git a/packages/vrender-core/src/register-modules.ts b/packages/vrender-core/src/register-modules.ts index b4f2e9297..23e497c8a 100644 --- a/packages/vrender-core/src/register-modules.ts +++ b/packages/vrender-core/src/register-modules.ts @@ -120,18 +120,6 @@ export function registerRenderContributions() { serviceRegistry.registerSingleton(GroupRender, groupRender); contributionRegistry.register(GraphicRender, groupRender); - // 基础图形渲染器 - contributionRegistry.register(GraphicRender, new DefaultCanvasRectRender()); - contributionRegistry.register(GraphicRender, new DefaultCanvasCircleRender()); - contributionRegistry.register(GraphicRender, new DefaultCanvasArcRender()); - contributionRegistry.register(GraphicRender, new DefaultCanvasLineRender()); - contributionRegistry.register(GraphicRender, new DefaultCanvasAreaRender()); - contributionRegistry.register(GraphicRender, new DefaultCanvasPathRender()); - contributionRegistry.register(GraphicRender, new DefaultCanvasTextRender()); - contributionRegistry.register(GraphicRender, new DefaultCanvasSymbolRender()); - contributionRegistry.register(GraphicRender, new DefaultCanvasPolygonRender()); - contributionRegistry.register(GraphicRender, new DefaultCanvasImageRender()); - // DrawItemInterceptor const commonInterceptor = new CommonDrawItemInterceptorContribution(); contributionRegistry.register(DrawItemInterceptor, commonInterceptor); diff --git a/packages/vrender-core/src/render/contributions/render/index.ts b/packages/vrender-core/src/render/contributions/render/index.ts index d8e303f51..66f59f9bc 100644 --- a/packages/vrender-core/src/render/contributions/render/index.ts +++ b/packages/vrender-core/src/render/contributions/render/index.ts @@ -1,15 +1,21 @@ export * from './arc-render'; +export * from './arc3d-render'; +export * from './area-render'; export * from './circle-render'; +export * from './group-render'; +export * from './glyph-render'; +export * from './image-render'; export * from './line-render'; -export * from './area-render'; export * from './path-render'; +export * from './polygon-render'; +export * from './pyramid3d-render'; export * from './rect-render'; +export * from './rect3d-render'; +export * from './richtext-render'; +export * from './star-render'; export * from './symbol-render'; export * from './text-render'; export * from './graphic-render'; -export * from './polygon-render'; -export * from './group-render'; -export * from './image-render'; export * from './symbol'; export * from './contributions'; export * from './utils'; diff --git a/packages/vrender-kits/src/register/register-arc.ts b/packages/vrender-kits/src/register/register-arc.ts index 7d571e25d..2b4905efd 100644 --- a/packages/vrender-kits/src/register/register-arc.ts +++ b/packages/vrender-kits/src/register/register-arc.ts @@ -1,4 +1,9 @@ -import { registerArcGraphic } from '@visactor/vrender-core'; +import { + contributionRegistry, + DefaultCanvasArcRender, + GraphicRender, + registerArcGraphic +} from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasArcPicker } from '../picker/contributions/canvas-picker/arc-module'; import { registerMathArcPicker } from '../picker/contributions/math-picker/arc-module'; @@ -9,11 +14,14 @@ export function _registerArc() { } _registerArc.__loaded = true; registerArcGraphic(); + if (browser) { registerCanvasArcPicker(); } else { registerMathArcPicker(); } + + contributionRegistry.register(GraphicRender, new DefaultCanvasArcRender()); } _registerArc.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-arc3d.ts b/packages/vrender-kits/src/register/register-arc3d.ts index 6df908572..d05be9e4a 100644 --- a/packages/vrender-kits/src/register/register-arc3d.ts +++ b/packages/vrender-kits/src/register/register-arc3d.ts @@ -1,4 +1,11 @@ -import { registerArc3dGraphic, registerDirectionalLight, registerOrthoCamera } from '@visactor/vrender-core'; +import { + contributionRegistry, + DefaultCanvasArc3DRender, + GraphicRender, + registerArc3dGraphic, + registerDirectionalLight, + registerOrthoCamera +} from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasArc3dPicker } from '../picker/contributions/canvas-picker/arc3d-module'; @@ -10,10 +17,11 @@ function _registerArc3d() { registerArc3dGraphic(); registerDirectionalLight(); registerOrthoCamera(); - // arc3d renderer registered via core; no /* removed container */ usage if (browser) { registerCanvasArc3dPicker(); } + + contributionRegistry.register(GraphicRender, new DefaultCanvasArc3DRender()); } _registerArc3d.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-area.ts b/packages/vrender-kits/src/register/register-area.ts index 2f8c94183..3e8765186 100644 --- a/packages/vrender-kits/src/register/register-area.ts +++ b/packages/vrender-kits/src/register/register-area.ts @@ -1,4 +1,9 @@ -import { registerAreaGraphic } from '@visactor/vrender-core'; +import { + contributionRegistry, + DefaultCanvasAreaRender, + GraphicRender, + registerAreaGraphic +} from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasAreaPicker } from '../picker/contributions/canvas-picker/area-module'; import { registerMathAreaPicker } from '../picker/contributions/math-picker/area-module'; @@ -9,12 +14,13 @@ function _registerArea() { } _registerArea.__loaded = true; registerAreaGraphic(); - // area renderer registered via core; no container usage if (browser) { registerCanvasAreaPicker(); } else { registerMathAreaPicker(); } + + contributionRegistry.register(GraphicRender, new DefaultCanvasAreaRender()); } _registerArea.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-circle.ts b/packages/vrender-kits/src/register/register-circle.ts index ec279dcf2..4e7fa5e87 100644 --- a/packages/vrender-kits/src/register/register-circle.ts +++ b/packages/vrender-kits/src/register/register-circle.ts @@ -1,4 +1,9 @@ -import { registerCircleGraphic } from '@visactor/vrender-core'; +import { + contributionRegistry, + DefaultCanvasCircleRender, + GraphicRender, + registerCircleGraphic +} from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasCirclePicker } from '../picker/contributions/canvas-picker/circle-module'; import { registerMathCirclePicker } from '../picker/contributions/math-picker/circle-module'; @@ -9,12 +14,13 @@ function _registerCircle() { } _registerCircle.__loaded = true; registerCircleGraphic(); - // circle renderer registered via core; no container usage if (browser) { registerCanvasCirclePicker(); } else { registerMathCirclePicker(); } + + contributionRegistry.register(GraphicRender, new DefaultCanvasCircleRender()); } _registerCircle.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-glyph.ts b/packages/vrender-kits/src/register/register-glyph.ts index 155888014..848d7e913 100644 --- a/packages/vrender-kits/src/register/register-glyph.ts +++ b/packages/vrender-kits/src/register/register-glyph.ts @@ -1,4 +1,9 @@ -import { registerGlyphGraphic } from '@visactor/vrender-core'; +import { + contributionRegistry, + DefaultCanvasGlyphRender, + GraphicRender, + registerGlyphGraphic +} from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasGlyphPicker } from '../picker/contributions/canvas-picker/glyph-module'; import { registerMathGlyphPicker } from '../picker/contributions/math-picker/glyph-module'; @@ -9,12 +14,13 @@ function _registerGlyph() { } _registerGlyph.__loaded = true; registerGlyphGraphic(); - // glyph renderer registered via core; no container usage if (browser) { registerCanvasGlyphPicker(); } else { registerMathGlyphPicker(); } + + contributionRegistry.register(GraphicRender, new DefaultCanvasGlyphRender()); } _registerGlyph.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-group.ts b/packages/vrender-kits/src/register/register-group.ts index e07be7e1e..f59a9d6af 100644 --- a/packages/vrender-kits/src/register/register-group.ts +++ b/packages/vrender-kits/src/register/register-group.ts @@ -1,4 +1,9 @@ -import { registerGroupGraphic } from '@visactor/vrender-core'; +import { + contributionRegistry, + DefaultCanvasGroupRender, + GraphicRender, + registerGroupGraphic +} from '@visactor/vrender-core'; function _registerGroup() { if (_registerGroup.__loaded) { @@ -6,6 +11,8 @@ function _registerGroup() { } _registerGroup.__loaded = true; registerGroupGraphic(); + + contributionRegistry.register(GraphicRender, new DefaultCanvasGroupRender()); } _registerGroup.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-image.ts b/packages/vrender-kits/src/register/register-image.ts index 7e3e19dda..76ba1d6ec 100644 --- a/packages/vrender-kits/src/register/register-image.ts +++ b/packages/vrender-kits/src/register/register-image.ts @@ -1,4 +1,9 @@ -import { registerImageGraphic } from '@visactor/vrender-core'; +import { + contributionRegistry, + DefaultCanvasImageRender, + GraphicRender, + registerImageGraphic +} from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasImagePicker } from '../picker/contributions/canvas-picker/image-module'; import { registerMathImagePicker } from '../picker/contributions/math-picker/image-module'; @@ -9,12 +14,13 @@ function _registerImage() { } _registerImage.__loaded = true; registerImageGraphic(); - // image renderer registered via core; no /* removed container */ usage if (browser) { registerCanvasImagePicker(); } else { registerMathImagePicker(); } + + contributionRegistry.register(GraphicRender, new DefaultCanvasImageRender()); } _registerImage.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-line.ts b/packages/vrender-kits/src/register/register-line.ts index 13d78540c..3b7d0dfcb 100644 --- a/packages/vrender-kits/src/register/register-line.ts +++ b/packages/vrender-kits/src/register/register-line.ts @@ -1,4 +1,9 @@ -import { registerLineGraphic } from '@visactor/vrender-core'; +import { + contributionRegistry, + DefaultCanvasLineRender, + GraphicRender, + registerLineGraphic +} from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasLinePicker } from '../picker/contributions/canvas-picker/line-module'; import { registerMathLinePicker } from '../picker/contributions/math-picker/line-module'; @@ -14,6 +19,8 @@ function _registerLine() { } else { registerMathLinePicker(); } + + contributionRegistry.register(GraphicRender, new DefaultCanvasLineRender()); } _registerLine.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-path.ts b/packages/vrender-kits/src/register/register-path.ts index 9f8ab44ce..8b7f14045 100644 --- a/packages/vrender-kits/src/register/register-path.ts +++ b/packages/vrender-kits/src/register/register-path.ts @@ -1,4 +1,9 @@ -import { registerPathGraphic } from '@visactor/vrender-core'; +import { + contributionRegistry, + DefaultCanvasPathRender, + GraphicRender, + registerPathGraphic +} from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasPathPicker } from '../picker/contributions/canvas-picker/path-module'; import { registerMathPathPicker } from '../picker/contributions/math-picker/path-module'; @@ -9,12 +14,13 @@ function _registerPath() { } _registerPath.__loaded = true; registerPathGraphic(); - // path renderer registered via core; no container usage if (browser) { registerCanvasPathPicker(); } else { registerMathPathPicker(); } + + contributionRegistry.register(GraphicRender, new DefaultCanvasPathRender()); } _registerPath.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-polygon.ts b/packages/vrender-kits/src/register/register-polygon.ts index 158ae144d..7d31751f8 100644 --- a/packages/vrender-kits/src/register/register-polygon.ts +++ b/packages/vrender-kits/src/register/register-polygon.ts @@ -1,4 +1,9 @@ -import { registerPolygonGraphic } from '@visactor/vrender-core'; +import { + contributionRegistry, + DefaultCanvasPolygonRender, + GraphicRender, + registerPolygonGraphic +} from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasPolygonPicker } from '../picker/contributions/canvas-picker/polygon-module'; import { registerMathPolygonPicker } from '../picker/contributions/math-picker/polygon-module'; @@ -9,12 +14,13 @@ function _registerPolygon() { } _registerPolygon.__loaded = true; registerPolygonGraphic(); - // polygon renderer registered via core; no container usage if (browser) { registerCanvasPolygonPicker(); } else { registerMathPolygonPicker(); } + + contributionRegistry.register(GraphicRender, new DefaultCanvasPolygonRender()); } _registerPolygon.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-pyramid3d.ts b/packages/vrender-kits/src/register/register-pyramid3d.ts index 011f26887..755160837 100644 --- a/packages/vrender-kits/src/register/register-pyramid3d.ts +++ b/packages/vrender-kits/src/register/register-pyramid3d.ts @@ -1,4 +1,11 @@ -import { registerDirectionalLight, registerOrthoCamera, registerPyramid3dGraphic } from '@visactor/vrender-core'; +import { + contributionRegistry, + DefaultCanvasPyramid3dRender, + GraphicRender, + registerDirectionalLight, + registerOrthoCamera, + registerPyramid3dGraphic +} from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasPyramid3dPicker } from '../picker/contributions/canvas-picker/pyramid3d-module'; @@ -10,10 +17,11 @@ function _registerPyramid3d() { registerPyramid3dGraphic(); registerDirectionalLight(); registerOrthoCamera(); - // pyramid3d renderer registered via core; no /* removed container */ usage if (browser) { registerCanvasPyramid3dPicker(); } + + contributionRegistry.register(GraphicRender, new DefaultCanvasPyramid3dRender()); } _registerPyramid3d.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-rect.ts b/packages/vrender-kits/src/register/register-rect.ts index 21fbdb7f4..368a0bd49 100644 --- a/packages/vrender-kits/src/register/register-rect.ts +++ b/packages/vrender-kits/src/register/register-rect.ts @@ -1,4 +1,9 @@ -import { registerRectGraphic } from '@visactor/vrender-core'; +import { + contributionRegistry, + DefaultCanvasRectRender, + GraphicRender, + registerRectGraphic +} from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasRectPicker } from '../picker/contributions/canvas-picker/rect-module'; import { registerMathRectPicker } from '../picker/contributions/math-picker/rect-module'; @@ -9,12 +14,13 @@ function _registerRect() { } _registerRect.__loaded = true; registerRectGraphic(); - // rect renderer registered via core; no container usage if (browser) { registerCanvasRectPicker(); } else { registerMathRectPicker(); } + + contributionRegistry.register(GraphicRender, new DefaultCanvasRectRender()); } _registerRect.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-rect3d.ts b/packages/vrender-kits/src/register/register-rect3d.ts index 93c5939d8..0a5b91913 100644 --- a/packages/vrender-kits/src/register/register-rect3d.ts +++ b/packages/vrender-kits/src/register/register-rect3d.ts @@ -1,4 +1,9 @@ -import { registerRect3dGraphic } from '@visactor/vrender-core'; +import { + contributionRegistry, + DefaultCanvasRect3dRender, + GraphicRender, + registerRect3dGraphic +} from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasRect3dPicker } from '../picker/contributions/canvas-picker/rect3d-module'; @@ -8,10 +13,11 @@ function _registerRect3d() { } _registerRect3d.__loaded = true; registerRect3dGraphic(); - // rect3d renderer registered via core; no /* removed container */ usage if (browser) { registerCanvasRect3dPicker(); } + + contributionRegistry.register(GraphicRender, new DefaultCanvasRect3dRender()); } _registerRect3d.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-richtext.ts b/packages/vrender-kits/src/register/register-richtext.ts index d5020fce6..2669ca2fd 100644 --- a/packages/vrender-kits/src/register/register-richtext.ts +++ b/packages/vrender-kits/src/register/register-richtext.ts @@ -1,4 +1,9 @@ -import { registerRichtextGraphic } from '@visactor/vrender-core'; +import { + contributionRegistry, + DefaultCanvasRichTextRender, + GraphicRender, + registerRichtextGraphic +} from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasRichtextPicker } from '../picker/contributions/canvas-picker/richtext-module'; import { registerMathRichTextPicker } from '../picker/contributions/math-picker/richtext-module'; @@ -9,12 +14,13 @@ function _registerRichtext() { } _registerRichtext.__loaded = true; registerRichtextGraphic(); - // richtext renderer registered via core; no container usage if (browser) { registerCanvasRichtextPicker(); } else { registerMathRichTextPicker(); } + + contributionRegistry.register(GraphicRender, new DefaultCanvasRichTextRender()); } _registerRichtext.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-star.ts b/packages/vrender-kits/src/register/register-star.ts index 19aa03bc5..3672328fa 100644 --- a/packages/vrender-kits/src/register/register-star.ts +++ b/packages/vrender-kits/src/register/register-star.ts @@ -1,4 +1,9 @@ -import { registerStarGraphic } from '@visactor/vrender-core'; +import { + contributionRegistry, + DefaultCanvasStarRender, + GraphicRender, + registerStarGraphic +} from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasStarPicker } from '../picker/contributions/canvas-picker/star-module'; @@ -8,8 +13,9 @@ function _registerStar() { } _registerStar.__loaded = true; registerStarGraphic(); - // star renderer registered via core; no container usage registerCanvasStarPicker(); + + contributionRegistry.register(GraphicRender, new DefaultCanvasStarRender()); } _registerStar.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-symbol.ts b/packages/vrender-kits/src/register/register-symbol.ts index 0a082aecb..631bd6440 100644 --- a/packages/vrender-kits/src/register/register-symbol.ts +++ b/packages/vrender-kits/src/register/register-symbol.ts @@ -1,4 +1,9 @@ -import { registerSymbolGraphic } from '@visactor/vrender-core'; +import { + contributionRegistry, + DefaultCanvasSymbolRender, + GraphicRender, + registerSymbolGraphic +} from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasSymbolPicker } from '../picker/contributions/canvas-picker/symbol-module'; import { registerMathSymbolPicker } from '../picker/contributions/math-picker/symbol-module'; @@ -9,12 +14,13 @@ function _registerSymbol() { } _registerSymbol.__loaded = true; registerSymbolGraphic(); - // symbol renderer registered via core; no container usage if (browser) { registerCanvasSymbolPicker(); } else { registerMathSymbolPicker(); } + + contributionRegistry.register(GraphicRender, new DefaultCanvasSymbolRender()); } _registerSymbol.__loaded = false; diff --git a/packages/vrender-kits/src/register/register-text.ts b/packages/vrender-kits/src/register/register-text.ts index c1954cbf7..503f6435d 100644 --- a/packages/vrender-kits/src/register/register-text.ts +++ b/packages/vrender-kits/src/register/register-text.ts @@ -1,4 +1,9 @@ -import { registerTextGraphic } from '@visactor/vrender-core'; +import { + contributionRegistry, + DefaultCanvasTextRender, + GraphicRender, + registerTextGraphic +} from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasTextPicker } from '../picker/contributions/canvas-picker/text-module'; import { registerMathTextPicker } from '../picker/contributions/math-picker/text-module'; @@ -8,12 +13,13 @@ function _registerText() { } _registerText.__loaded = true; registerTextGraphic(); - // text renderer registered via core; no container usage if (browser) { registerCanvasTextPicker(); } else { registerMathTextPicker(); } + + contributionRegistry.register(GraphicRender, new DefaultCanvasTextRender()); } _registerText.__loaded = false; From 2e22798f01485503b68e245966d436f512ca9d76 Mon Sep 17 00:00:00 2001 From: xile611 Date: Fri, 16 Jan 2026 15:35:07 +0800 Subject: [PATCH 6/6] fix: fix contribution of graphics --- packages/vrender-core/src/register-modules.ts | 10 -- .../image-contribution-render.ts | 137 +----------------- .../render/incremental-draw-contribution.ts | 10 +- .../src/render/contributions/render/index.ts | 2 + .../src/render/contributions/render/symbol.ts | 2 + .../vrender-kits/src/register/register-arc.ts | 6 +- .../src/register/register-area.ts | 12 +- .../src/register/register-circle.ts | 9 +- .../src/register/register-image.ts | 7 +- .../src/register/register-line.ts | 10 +- .../src/register/register-path.ts | 6 +- .../src/register/register-polygon.ts | 10 +- .../src/register/register-rect.ts | 10 +- .../src/register/register-symbol.ts | 10 +- .../src/register/register-text.ts | 7 +- 15 files changed, 83 insertions(+), 165 deletions(-) diff --git a/packages/vrender-core/src/register-modules.ts b/packages/vrender-core/src/register-modules.ts index 23e497c8a..37985754e 100644 --- a/packages/vrender-core/src/register-modules.ts +++ b/packages/vrender-core/src/register-modules.ts @@ -38,16 +38,6 @@ import { DefaultDrawContribution } from './render/contributions/render/draw-cont import { DefaultIncrementalDrawContribution } from './render/contributions/render/incremental-draw-contribution'; import { DefaultRenderService } from './render/render-service'; import { DefaultCanvasGroupRender } from './render/contributions/render/group-render'; -import { DefaultCanvasRectRender } from './render/contributions/render/rect-render'; -import { DefaultCanvasArcRender } from './render/contributions/render/arc-render'; -import { DefaultCanvasCircleRender } from './render/contributions/render/circle-render'; -import { DefaultCanvasLineRender } from './render/contributions/render/line-render'; -import { DefaultCanvasAreaRender } from './render/contributions/render/area-render'; -import { DefaultCanvasPathRender } from './render/contributions/render/path-render'; -import { DefaultCanvasTextRender } from './render/contributions/render/text-render'; -import { DefaultCanvasSymbolRender } from './render/contributions/render/symbol-render'; -import { DefaultCanvasPolygonRender } from './render/contributions/render/polygon-render'; -import { DefaultCanvasImageRender } from './render/contributions/render/image-render'; import { DefaultBaseBackgroundRenderContribution, DefaultBaseInteractiveRenderContribution diff --git a/packages/vrender-core/src/render/contributions/render/contributions/image-contribution-render.ts b/packages/vrender-core/src/render/contributions/render/contributions/image-contribution-render.ts index dd3309aba..2341b7065 100644 --- a/packages/vrender-core/src/render/contributions/render/contributions/image-contribution-render.ts +++ b/packages/vrender-core/src/render/contributions/render/contributions/image-contribution-render.ts @@ -1,150 +1,15 @@ import type { IGraphicAttribute, IContext2d, - IImage, IThemeAttribute, IImageRenderContribution, IDrawContext, - IBackgroundConfig, - IGraphic, IMarkAttribute } from '../../../../interface'; -import { getTheme } from '../../../../graphic/theme'; -import { - defaultBaseBackgroundRenderContribution, - DefaultBaseBackgroundRenderContribution -} from './base-contribution-render'; +import { defaultBaseBackgroundRenderContribution } from './base-contribution-render'; import { BaseRenderContributionTime } from '../../../../common/enums'; -import { isNumber, isObject } from '@visactor/vutils'; -import { parsePadding } from '../../../../common/utils'; -import { createRectPath } from '../../../../common/shape/rect'; import { DefaultRectRenderContribution } from './rect-contribution-render'; -// export class DefaultImageBackgroundRenderContribution -// extends DefaultBaseBackgroundRenderContribution -// implements IImageRenderContribution -// { -// time: BaseRenderContributionTime = BaseRenderContributionTime.beforeFillStroke; - -// drawShape( -// graphic: IImage, -// context: IContext2d, -// x: number, -// y: number, -// doFill: boolean, -// doStroke: boolean, -// fVisible: boolean, -// sVisible: boolean, -// graphicAttribute: Required, -// drawContext: IDrawContext, -// fillCb?: (ctx: IContext2d, markAttribute: Partial, themeAttribute: IThemeAttribute) => boolean, -// strokeCb?: (ctx: IContext2d, markAttribute: Partial, themeAttribute: IThemeAttribute) => boolean -// ) { -// const { -// background, -// backgroundMode = graphicAttribute.backgroundMode, -// backgroundFit = graphicAttribute.backgroundFit, -// width, -// height -// } = graphic.attribute; -// if (!background) { -// return; -// } - -// if (!graphic.backgroundImg) { -// if (isObject(background)) { -// const { -// stroke, -// fill, -// lineWidth = 1, -// cornerRadius = 0, -// expandX = 0, -// expandY = 0 -// } = background as IBackgroundConfig; - -// if (!stroke && !fill) { -// return; -// } - -// context.beginPath(); -// const { x, y, width, height } = getActualPosition(graphic); -// if (cornerRadius) { -// createRectPath(context, x - expandX, y - expandY, width + expandX * 2, height + expandY * 2, cornerRadius); -// } else { -// context.rect(x - expandX, y - expandY, width + expandX * 2, height + expandY * 2); -// } - -// context.globalAlpha = 1; -// if (fill) { -// context.fillStyle = fill as string; -// context.fill(); -// } - -// if (stroke && lineWidth > 0) { -// context.lineWidth = lineWidth; -// context.strokeStyle = stroke as string; -// context.stroke(); -// } -// } else { -// context.beginPath(); -// // const b = graphic.AABBBounds; -// // image的背景不包括Bounds了 -// context.rect(x, y, width || 0, height || 0); -// context.fillStyle = background as string; -// context.globalAlpha = 1; -// context.fill(); -// } -// } else { -// const res = graphic.resources.get(background as any); -// if (res.state !== 'success' || !res.data) { -// return; -// } -// context.save(); -// if (graphic.parent && !graphic.transMatrix.onlyTranslate()) { -// const groupAttribute = getTheme(graphic.parent).group; -// const { scrollX = groupAttribute.scrollX, scrollY = groupAttribute.scrollY } = graphic.parent.attribute; -// context.setTransformFromMatrix(graphic.parent.globalTransMatrix, true); -// context.translate(scrollX, scrollY); -// } -// // context.clip(); -// const b = graphic.AABBBounds; -// this.doDrawImage(context, res.data, b, backgroundMode, backgroundFit); -// context.restore(); -// if (!graphic.transMatrix.onlyTranslate()) { -// context.setTransformForCurrent(); -// } -// } -// } -// } - -// function getActualPosition(graphic: IGraphic) { -// const boundsPadding = parsePadding(graphic.attribute.boundsPadding); -// const bounds = graphic.AABBBounds; -// let x = bounds.x1; -// let y = bounds.y1; -// let width = bounds.width(); -// let height = bounds.height(); - -// if (isNumber(boundsPadding)) { -// x += boundsPadding; -// y += boundsPadding; -// width -= boundsPadding * 2; -// height -= boundsPadding * 2; -// } else { -// x += boundsPadding[3]; -// y += boundsPadding[0]; -// width -= boundsPadding[1] + boundsPadding[3]; -// height -= boundsPadding[0] + boundsPadding[2]; -// } - -// return { -// x, -// y, -// width, -// height -// }; -// } - export class DefaultImageRenderContribution extends DefaultRectRenderContribution implements IImageRenderContribution { time: BaseRenderContributionTime = BaseRenderContributionTime.afterFillStroke; useStyle: boolean = true; diff --git a/packages/vrender-core/src/render/contributions/render/incremental-draw-contribution.ts b/packages/vrender-core/src/render/contributions/render/incremental-draw-contribution.ts index 1eef3c0b9..5df73e5de 100644 --- a/packages/vrender-core/src/render/contributions/render/incremental-draw-contribution.ts +++ b/packages/vrender-core/src/render/contributions/render/incremental-draw-contribution.ts @@ -11,12 +11,10 @@ import type { import { DefaultAttribute } from '../../../graphic/config'; import { DefaultDrawContribution } from './draw-contribution'; import { SyncHook } from '../../../tapable'; -import { GraphicRender } from './symbol'; -import { DefaultIncrementalCanvasLineRender } from './incremental-line-render'; -import { DefaultIncrementalCanvasAreaRender } from './incremental-area-render'; +import { AreaIncrementalDrawContribution, GraphicRender, LineIncrementalDrawContribution } from './symbol'; import { DrawItemInterceptor } from './draw-interceptor'; import { foreachAsync } from '../../../common/sort'; -import { contributionRegistry } from '../../../common/registry'; +import { contributionRegistry, serviceRegistry } from '../../../common/registry'; enum STATUS { NORMAL = 0, @@ -56,8 +54,8 @@ export class DefaultIncrementalDrawContribution extends DefaultDrawContribution getContributions: () => contributionRegistry.get(DrawItemInterceptor) } as IContributionProvider); super(defaultContributions, defaultDrawItemInterceptor); - this.lineRender = lineRender || new DefaultIncrementalCanvasLineRender(); - this.areaRender = areaRender || new DefaultIncrementalCanvasAreaRender(); + this.lineRender = lineRender || serviceRegistry.get(LineIncrementalDrawContribution); + this.areaRender = areaRender || serviceRegistry.get(AreaIncrementalDrawContribution); this.defaultRenderMap.set(this.lineRender.numberType, this.lineRender); this.defaultRenderMap.set(this.areaRender.numberType, this.areaRender); } diff --git a/packages/vrender-core/src/render/contributions/render/index.ts b/packages/vrender-core/src/render/contributions/render/index.ts index 66f59f9bc..b220ed0f6 100644 --- a/packages/vrender-core/src/render/contributions/render/index.ts +++ b/packages/vrender-core/src/render/contributions/render/index.ts @@ -20,3 +20,5 @@ export * from './symbol'; export * from './contributions'; export * from './utils'; export * from './draw-interceptor'; +export * from './incremental-line-render'; +export * from './incremental-area-render'; diff --git a/packages/vrender-core/src/render/contributions/render/symbol.ts b/packages/vrender-core/src/render/contributions/render/symbol.ts index 2d9a3621c..156ffbd96 100644 --- a/packages/vrender-core/src/render/contributions/render/symbol.ts +++ b/packages/vrender-core/src/render/contributions/render/symbol.ts @@ -1,3 +1,5 @@ +export const AreaIncrementalDrawContribution = Symbol.for('AreaIncrementalDrawContribution'); +export const LineIncrementalDrawContribution = Symbol.for('LineIncrementalDrawContribution'); export const IncrementalDrawContribution = Symbol.for('IncrementalDrawContribution'); export const ArcRender = Symbol.for('ArcRender'); export const Arc3dRender = Symbol.for('Arc3dRender'); diff --git a/packages/vrender-kits/src/register/register-arc.ts b/packages/vrender-kits/src/register/register-arc.ts index 2b4905efd..45a5464c9 100644 --- a/packages/vrender-kits/src/register/register-arc.ts +++ b/packages/vrender-kits/src/register/register-arc.ts @@ -1,8 +1,11 @@ import { + AreaRenderContribution, contributionRegistry, + DefaultBaseInteractiveRenderContribution, DefaultCanvasArcRender, GraphicRender, - registerArcGraphic + registerArcGraphic, + serviceRegistry } from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasArcPicker } from '../picker/contributions/canvas-picker/arc-module'; @@ -21,6 +24,7 @@ export function _registerArc() { registerMathArcPicker(); } + contributionRegistry.register(AreaRenderContribution, serviceRegistry.get(DefaultBaseInteractiveRenderContribution)); contributionRegistry.register(GraphicRender, new DefaultCanvasArcRender()); } diff --git a/packages/vrender-kits/src/register/register-area.ts b/packages/vrender-kits/src/register/register-area.ts index 3e8765186..b22443f55 100644 --- a/packages/vrender-kits/src/register/register-area.ts +++ b/packages/vrender-kits/src/register/register-area.ts @@ -1,8 +1,13 @@ import { + AreaIncrementalDrawContribution, + AreaRenderContribution, contributionRegistry, + DefaultBaseInteractiveRenderContribution, DefaultCanvasAreaRender, + DefaultIncrementalCanvasAreaRender, GraphicRender, - registerAreaGraphic + registerAreaGraphic, + serviceRegistry } from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasAreaPicker } from '../picker/contributions/canvas-picker/area-module'; @@ -19,7 +24,12 @@ function _registerArea() { } else { registerMathAreaPicker(); } + serviceRegistry.registerSingletonFactory( + AreaIncrementalDrawContribution, + () => new DefaultIncrementalCanvasAreaRender() + ); + contributionRegistry.register(AreaRenderContribution, serviceRegistry.get(DefaultBaseInteractiveRenderContribution)); contributionRegistry.register(GraphicRender, new DefaultCanvasAreaRender()); } diff --git a/packages/vrender-kits/src/register/register-circle.ts b/packages/vrender-kits/src/register/register-circle.ts index 4e7fa5e87..1abc756e8 100644 --- a/packages/vrender-kits/src/register/register-circle.ts +++ b/packages/vrender-kits/src/register/register-circle.ts @@ -1,8 +1,11 @@ import { + CircleRenderContribution, contributionRegistry, + DefaultBaseInteractiveRenderContribution, DefaultCanvasCircleRender, GraphicRender, - registerCircleGraphic + registerCircleGraphic, + serviceRegistry } from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasCirclePicker } from '../picker/contributions/canvas-picker/circle-module'; @@ -20,6 +23,10 @@ function _registerCircle() { registerMathCirclePicker(); } + contributionRegistry.register( + CircleRenderContribution, + serviceRegistry.get(DefaultBaseInteractiveRenderContribution) + ); contributionRegistry.register(GraphicRender, new DefaultCanvasCircleRender()); } diff --git a/packages/vrender-kits/src/register/register-image.ts b/packages/vrender-kits/src/register/register-image.ts index 76ba1d6ec..6dc5294dc 100644 --- a/packages/vrender-kits/src/register/register-image.ts +++ b/packages/vrender-kits/src/register/register-image.ts @@ -1,8 +1,11 @@ import { contributionRegistry, + DefaultBaseInteractiveRenderContribution, DefaultCanvasImageRender, GraphicRender, - registerImageGraphic + ImageRenderContribution, + registerImageGraphic, + serviceRegistry } from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasImagePicker } from '../picker/contributions/canvas-picker/image-module'; @@ -19,7 +22,7 @@ function _registerImage() { } else { registerMathImagePicker(); } - + contributionRegistry.register(ImageRenderContribution, serviceRegistry.get(DefaultBaseInteractiveRenderContribution)); contributionRegistry.register(GraphicRender, new DefaultCanvasImageRender()); } diff --git a/packages/vrender-kits/src/register/register-line.ts b/packages/vrender-kits/src/register/register-line.ts index 3b7d0dfcb..cc1f266fa 100644 --- a/packages/vrender-kits/src/register/register-line.ts +++ b/packages/vrender-kits/src/register/register-line.ts @@ -1,8 +1,11 @@ import { + DefaultIncrementalCanvasLineRender, contributionRegistry, DefaultCanvasLineRender, GraphicRender, - registerLineGraphic + LineIncrementalDrawContribution, + registerLineGraphic, + serviceRegistry } from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasLinePicker } from '../picker/contributions/canvas-picker/line-module'; @@ -20,6 +23,11 @@ function _registerLine() { registerMathLinePicker(); } + serviceRegistry.registerSingletonFactory( + LineIncrementalDrawContribution, + () => new DefaultIncrementalCanvasLineRender() + ); + contributionRegistry.register(GraphicRender, new DefaultCanvasLineRender()); } diff --git a/packages/vrender-kits/src/register/register-path.ts b/packages/vrender-kits/src/register/register-path.ts index 8b7f14045..b660fe710 100644 --- a/packages/vrender-kits/src/register/register-path.ts +++ b/packages/vrender-kits/src/register/register-path.ts @@ -1,8 +1,11 @@ import { contributionRegistry, + DefaultBaseInteractiveRenderContribution, DefaultCanvasPathRender, GraphicRender, - registerPathGraphic + PathRenderContribution, + registerPathGraphic, + serviceRegistry } from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasPathPicker } from '../picker/contributions/canvas-picker/path-module'; @@ -20,6 +23,7 @@ function _registerPath() { registerMathPathPicker(); } + contributionRegistry.register(PathRenderContribution, serviceRegistry.get(DefaultBaseInteractiveRenderContribution)); contributionRegistry.register(GraphicRender, new DefaultCanvasPathRender()); } diff --git a/packages/vrender-kits/src/register/register-polygon.ts b/packages/vrender-kits/src/register/register-polygon.ts index 7d31751f8..bdc539ddf 100644 --- a/packages/vrender-kits/src/register/register-polygon.ts +++ b/packages/vrender-kits/src/register/register-polygon.ts @@ -1,8 +1,11 @@ import { contributionRegistry, + DefaultBaseInteractiveRenderContribution, DefaultCanvasPolygonRender, GraphicRender, - registerPolygonGraphic + PolygonRenderContribution, + registerPolygonGraphic, + serviceRegistry } from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasPolygonPicker } from '../picker/contributions/canvas-picker/polygon-module'; @@ -20,6 +23,11 @@ function _registerPolygon() { registerMathPolygonPicker(); } + contributionRegistry.register( + PolygonRenderContribution, + serviceRegistry.get(DefaultBaseInteractiveRenderContribution) + ); + contributionRegistry.register(GraphicRender, new DefaultCanvasPolygonRender()); } diff --git a/packages/vrender-kits/src/register/register-rect.ts b/packages/vrender-kits/src/register/register-rect.ts index 368a0bd49..10f68cd7c 100644 --- a/packages/vrender-kits/src/register/register-rect.ts +++ b/packages/vrender-kits/src/register/register-rect.ts @@ -1,8 +1,13 @@ import { contributionRegistry, + DefaultBaseInteractiveRenderContribution, DefaultCanvasRectRender, GraphicRender, - registerRectGraphic + RectRenderContribution, + registerRectGraphic, + serviceRegistry, + SplitRectAfterRenderContribution, + SplitRectBeforeRenderContribution } from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasRectPicker } from '../picker/contributions/canvas-picker/rect-module'; @@ -19,6 +24,9 @@ function _registerRect() { } else { registerMathRectPicker(); } + contributionRegistry.register(RectRenderContribution, new SplitRectAfterRenderContribution()); + contributionRegistry.register(RectRenderContribution, new SplitRectBeforeRenderContribution()); + contributionRegistry.register(RectRenderContribution, serviceRegistry.get(DefaultBaseInteractiveRenderContribution)); contributionRegistry.register(GraphicRender, new DefaultCanvasRectRender()); } diff --git a/packages/vrender-kits/src/register/register-symbol.ts b/packages/vrender-kits/src/register/register-symbol.ts index 631bd6440..0275e5ad4 100644 --- a/packages/vrender-kits/src/register/register-symbol.ts +++ b/packages/vrender-kits/src/register/register-symbol.ts @@ -1,8 +1,11 @@ import { contributionRegistry, + DefaultBaseInteractiveRenderContribution, DefaultCanvasSymbolRender, GraphicRender, - registerSymbolGraphic + registerSymbolGraphic, + serviceRegistry, + SymbolRenderContribution } from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasSymbolPicker } from '../picker/contributions/canvas-picker/symbol-module'; @@ -19,7 +22,10 @@ function _registerSymbol() { } else { registerMathSymbolPicker(); } - + contributionRegistry.register( + SymbolRenderContribution, + serviceRegistry.get(DefaultBaseInteractiveRenderContribution) + ); contributionRegistry.register(GraphicRender, new DefaultCanvasSymbolRender()); } diff --git a/packages/vrender-kits/src/register/register-text.ts b/packages/vrender-kits/src/register/register-text.ts index 503f6435d..8c70b91f3 100644 --- a/packages/vrender-kits/src/register/register-text.ts +++ b/packages/vrender-kits/src/register/register-text.ts @@ -1,8 +1,11 @@ import { contributionRegistry, + DefaultBaseInteractiveRenderContribution, DefaultCanvasTextRender, GraphicRender, - registerTextGraphic + registerTextGraphic, + serviceRegistry, + TextRenderContribution } from '@visactor/vrender-core'; import { browser } from './env'; import { registerCanvasTextPicker } from '../picker/contributions/canvas-picker/text-module'; @@ -18,7 +21,7 @@ function _registerText() { } else { registerMathTextPicker(); } - + contributionRegistry.register(TextRenderContribution, serviceRegistry.get(DefaultBaseInteractiveRenderContribution)); contributionRegistry.register(GraphicRender, new DefaultCanvasTextRender()); }