@visactor/vrender-core 0.21.11 → 0.21.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/animate/custom-animate.js +2 -1
- package/cjs/animate/custom-animate.js.map +1 -1
- package/cjs/common/inversify/annotation/optional.d.ts +2 -0
- package/cjs/common/inversify/annotation/optional.js +14 -0
- package/cjs/common/inversify/annotation/optional.js.map +1 -0
- package/cjs/common/inversify/container.js +9 -6
- package/cjs/common/inversify/container.js.map +1 -1
- package/cjs/render/contributions/render/draw-contribution.js +1 -0
- package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
- package/dist/index.es.js +14 -8
- package/es/animate/custom-animate.js +2 -1
- package/es/animate/custom-animate.js.map +1 -1
- package/es/common/inversify/annotation/optional.d.ts +2 -0
- package/es/common/inversify/annotation/optional.js +12 -0
- package/es/common/inversify/annotation/optional.js.map +1 -0
- package/es/common/inversify/container.js +9 -6
- package/es/common/inversify/container.js.map +1 -1
- package/es/render/contributions/render/draw-contribution.js +3 -2
- package/es/render/contributions/render/draw-contribution.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Metadata } from "../meta-data";
|
|
2
|
+
|
|
3
|
+
import { OPTIONAL_TAG } from "../metadata_keys";
|
|
4
|
+
|
|
5
|
+
import { createTaggedDecorator } from "./inject_base";
|
|
6
|
+
|
|
7
|
+
function optional() {
|
|
8
|
+
return createTaggedDecorator(new Metadata(OPTIONAL_TAG, !0));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { optional };
|
|
12
|
+
//# sourceMappingURL=optional.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/common/inversify/annotation/optional.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,SAAS,QAAQ;IACf,OAAO,qBAAqB,CAAC,IAAI,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;AACjE,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC","file":"optional.js","sourcesContent":["import { Metadata } from '../meta-data';\nimport { OPTIONAL_TAG } from '../metadata_keys';\nimport { createTaggedDecorator } from './inject_base';\n\nfunction optional() {\n return createTaggedDecorator(new Metadata(OPTIONAL_TAG, true));\n}\n\nexport { optional };\n"]}
|
|
@@ -102,12 +102,15 @@ export class Container {
|
|
|
102
102
|
}, injectIdentifier = metadata.inject || metadata.multiInject, target = {
|
|
103
103
|
serviceIdentifier: injectIdentifier,
|
|
104
104
|
constructorArgsMetadata: constructorArgsMetadata
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
105
|
+
}, bindings = (this._bindingDictionary.get(injectIdentifier) || []).filter((b => b.constraint(target)));
|
|
106
|
+
if (bindings.length) {
|
|
107
|
+
const request = {
|
|
108
|
+
injectIdentifier: injectIdentifier,
|
|
109
|
+
metadata: constructorArgsMetadata,
|
|
110
|
+
bindings: bindings
|
|
111
|
+
};
|
|
112
|
+
arr.push(request);
|
|
113
|
+
}
|
|
111
114
|
}
|
|
112
115
|
return arr;
|
|
113
116
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/common/inversify/container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,mBAA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;IACL,CAAC;IAEO,YAAY,CAAC,OAAyB,EAAE,MAAW;QACzD,IAAI,OAAO,CAAC,KAAK,KAAK,gBAAgB,CAAC,SAAS,EAAE;YAChD,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC;YACvB,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;SAC1B;IACH,CAAC;CACF","file":"container.js","sourcesContent":["import { Generator } from '../generator';\nimport { Binding } from './binding';\nimport type { interfaces } from './interfaces';\nimport { BindingScopeEnum, BindingTypeEnum } from './literal_types';\nimport { Metadata } from './meta-data';\nimport { INJECT_TAG, MULTI_INJECT_TAG, NAMED_TAG } from './metadata_keys';\nimport { MetadataReader } from './metadata_reader';\nimport { BindingToSyntax } from './syntax/binding_to_syntax';\n\ninterface IChildRequest {\n injectIdentifier: any;\n metadata: interfaces.Metadata<unknown>[];\n bindings: Binding<unknown>[];\n}\n\ninterface GetArgs<T> {\n avoidConstraints: boolean;\n isMultiInject: boolean;\n serviceIdentifier: interfaces.ServiceIdentifier<T>;\n key: string | symbol;\n value: any;\n}\n\nexport class Container {\n id: number;\n readonly options: interfaces.ContainerOptions;\n private _bindingDictionary: Map<any, Binding<unknown>[]>;\n private _metadataReader: interfaces.MetadataReader;\n\n constructor(containerOptions?: interfaces.ContainerOptions) {\n const options = containerOptions || {};\n options.defaultScope = options.defaultScope || BindingScopeEnum.Transient;\n // console.log(this);\n this.options = options;\n this.id = Generator.GenAutoIncrementId();\n this._bindingDictionary = new Map();\n this._metadataReader = new MetadataReader();\n }\n\n load(module: interfaces.ContainerModule) {\n const getHelpers = this._getContainerModuleHelpersFactory();\n\n const containerModuleHelpers = getHelpers(module.id);\n\n module.registry(\n containerModuleHelpers.bindFunction as interfaces.Bind,\n containerModuleHelpers.unbindFunction,\n containerModuleHelpers.isboundFunction,\n containerModuleHelpers.rebindFunction as interfaces.Rebind\n );\n }\n\n get<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): T {\n const getArgs = this._getNotAllArgs(serviceIdentifier, false);\n\n return this._get<T>(getArgs) as T;\n }\n\n getAll<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): T[] {\n const getArgs = this._getAllArgs(serviceIdentifier);\n\n return this._get<T>(getArgs) as T[];\n }\n\n getTagged<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, key: string | number | symbol, value: unknown): T {\n const getArgs = this._getNotAllArgs(serviceIdentifier, false, key, value);\n\n return this._get<T>(getArgs) as T;\n }\n\n getNamed<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, named: string | number | symbol): T {\n return this.getTagged<T>(serviceIdentifier, NAMED_TAG, named);\n }\n\n isBound(serviceIdentifier: interfaces.ServiceIdentifier<unknown>): boolean {\n return this._bindingDictionary.has(serviceIdentifier);\n }\n\n // Registers a type binding\n bind<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): interfaces.BindingToSyntax<T> {\n const scope = this.options.defaultScope;\n const binding = new Binding<T>(serviceIdentifier, scope);\n const list = this._bindingDictionary.get(serviceIdentifier) || [];\n list.push(binding);\n this._bindingDictionary.set(serviceIdentifier, list);\n return new BindingToSyntax<T>(binding);\n }\n\n unbind(serviceIdentifier: interfaces.ServiceIdentifier): void {\n this._bindingDictionary.delete(serviceIdentifier);\n }\n\n rebind<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): interfaces.BindingToSyntax<T> {\n this.unbind(serviceIdentifier);\n return this.bind(serviceIdentifier);\n }\n\n private _getContainerModuleHelpersFactory() {\n const setModuleId = (\n bindingToSyntax: interfaces.BindingToSyntax<unknown>,\n moduleId: interfaces.ContainerModuleBase['id']\n ) => {\n // TODO: Implement an internal type `_BindingToSyntax<T>` wherein this member\n // can be public. Let `BindingToSyntax<T>` be the presentational type that\n // depends on it, and does not expose this member as public.\n (\n bindingToSyntax as unknown as { _binding: { moduleId: interfaces.ContainerModuleBase['id'] } }\n )._binding.moduleId = moduleId;\n };\n\n const getBindFunction =\n <T>(moduleId: interfaces.ContainerModuleBase['id']) =>\n (serviceIdentifier: interfaces.ServiceIdentifier) => {\n const bindingToSyntax = this.bind(serviceIdentifier);\n setModuleId(bindingToSyntax, moduleId);\n return bindingToSyntax as BindingToSyntax<T>;\n };\n\n const getUnbindFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => {\n return this.unbind(serviceIdentifier);\n };\n\n const getUnbindAsyncFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => {\n return null as any;\n // return this.unbindAsync(serviceIdentifier);\n };\n\n const getIsboundFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => {\n return this.isBound(serviceIdentifier);\n };\n\n const getRebindFunction =\n <T = unknown>(moduleId: interfaces.ContainerModuleBase['id']) =>\n (serviceIdentifier: interfaces.ServiceIdentifier) => {\n const bindingToSyntax = this.rebind(serviceIdentifier);\n setModuleId(bindingToSyntax, moduleId);\n return bindingToSyntax as BindingToSyntax<T>;\n };\n return (mId: interfaces.ContainerModuleBase['id']) => ({\n bindFunction: getBindFunction(mId),\n isboundFunction: getIsboundFunction(),\n rebindFunction: getRebindFunction(mId),\n unbindFunction: getUnbindFunction(),\n unbindAsyncFunction: getUnbindAsyncFunction()\n });\n }\n\n private _getNotAllArgs<T>(\n serviceIdentifier: interfaces.ServiceIdentifier<T>,\n isMultiInject: boolean,\n key?: string | number | symbol | undefined,\n value?: unknown\n ): any {\n return {\n avoidConstraints: false,\n isMultiInject,\n serviceIdentifier,\n key,\n value\n };\n }\n\n private _getAllArgs<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): any {\n return {\n avoidConstraints: true,\n isMultiInject: true,\n serviceIdentifier\n };\n }\n\n private _get<T>(getArgs: GetArgs<T>): T | T[] {\n const result: T[] = [];\n const bindings = this._bindingDictionary.get(getArgs.serviceIdentifier).filter(b => {\n return b.constraint(getArgs as any);\n }) as Binding<T>[];\n bindings.forEach(binding => {\n result.push(this._resolveFromBinding<T>(binding));\n });\n\n return !getArgs.isMultiInject && result.length === 1 ? result[0] : result;\n }\n\n private _getChildRequest(binding: Binding<unknown>) {\n const constr = binding.implementationType;\n const { userGeneratedMetadata } = this._metadataReader.getConstructorMetadata(constr as any);\n const keys = Object.keys(userGeneratedMetadata);\n const arr = [];\n for (let i = 0; i < keys.length; i++) {\n const constructorArgsMetadata = userGeneratedMetadata[i];\n const targetMetadataMap = {};\n constructorArgsMetadata.forEach(md => {\n targetMetadataMap[md.key] = md.value;\n });\n const metadata = {\n inject: targetMetadataMap[INJECT_TAG],\n multiInject: targetMetadataMap[MULTI_INJECT_TAG]\n };\n const injectIdentifier = metadata.inject || metadata.multiInject;\n const target = {\n serviceIdentifier: injectIdentifier,\n constructorArgsMetadata\n };\n const bindings = this._bindingDictionary.get(injectIdentifier).filter(b => {\n return b.constraint(target as any);\n });\n const request = {\n injectIdentifier,\n metadata: constructorArgsMetadata,\n bindings\n };\n\n arr.push(request);\n }\n\n return arr;\n }\n\n private _resolveFromBinding<T>(binding: Binding<T>): T {\n const result = this._getResolvedFromBinding<T>(binding);\n\n this._saveToScope(binding, result);\n\n return result;\n }\n\n private _getResolvedFromBinding<T>(binding: Binding<T>) {\n let result: T;\n switch (binding.type) {\n case BindingTypeEnum.ConstantValue:\n case BindingTypeEnum.Function:\n result = binding.cache as T;\n break;\n case BindingTypeEnum.Instance:\n result = this._resolveInstance<T>(binding, binding.implementationType as interfaces.Newable<T>);\n break;\n default:\n result = binding.dynamicValue({ container: this } as any);\n }\n\n return result;\n }\n\n private _resolveInstance<T>(binding: Binding<T>, constr: interfaces.Newable<T>): T {\n if (binding.activated) {\n return binding.cache;\n }\n\n const childRequests = this._getChildRequest(binding);\n return this._createInstance(constr, childRequests);\n }\n\n private _createInstance<T>(constr: interfaces.Newable<T>, childRequests: IChildRequest[]) {\n if (childRequests.length) {\n const resolved = this._resolveRequests(childRequests);\n const obj = new constr(...resolved);\n return obj;\n }\n const obj = new constr();\n return obj;\n }\n\n private _resolveRequests(childRequests: IChildRequest[]): any[] {\n return childRequests.map(request => {\n return request.bindings.length > 1\n ? request.bindings.map(binding => this._resolveFromBinding(binding))\n : this._resolveFromBinding(request.bindings[0]);\n });\n }\n\n private _saveToScope(binding: Binding<unknown>, result: any) {\n if (binding.scope === BindingScopeEnum.Singleton) {\n binding.cache = result;\n binding.activated = true;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/common/inversify/container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAgB7D,MAAM,OAAO,SAAS;IAMpB,YAAY,gBAA8C;QACxD,MAAM,OAAO,GAAG,gBAAgB,IAAI,EAAE,CAAC;QACvC,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,gBAAgB,CAAC,SAAS,CAAC;QAE1E,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC,kBAAkB,EAAE,CAAC;QACzC,IAAI,CAAC,kBAAkB,GAAG,IAAI,GAAG,EAAE,CAAC;QACpC,IAAI,CAAC,eAAe,GAAG,IAAI,cAAc,EAAE,CAAC;IAC9C,CAAC;IAED,IAAI,CAAC,MAAkC;QACrC,MAAM,UAAU,GAAG,IAAI,CAAC,iCAAiC,EAAE,CAAC;QAE5D,MAAM,sBAAsB,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAErD,MAAM,CAAC,QAAQ,CACb,sBAAsB,CAAC,YAA+B,EACtD,sBAAsB,CAAC,cAAc,EACrC,sBAAsB,CAAC,eAAe,EACtC,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B,CAAC,aAAa,CAAC,CAAC;YACtD,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC;YACpC,OAAO,GAAG,CAAC;SACZ;QACD,MAAM,GAAG,GAAG,IAAI,MAAM,EAAE,CAAC;QACzB,OAAO,GAAG,CAAC;IACb,CAAC;IAEO,gBAAgB,CAAC,aAA8B;QACrD,OAAO,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;YACjC,OAAO,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;gBAChC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;gBACpE,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,YAAY,CAAC,OAAyB,EAAE,MAAW;QACzD,IAAI,OAAO,CAAC,KAAK,KAAK,gBAAgB,CAAC,SAAS,EAAE;YAChD,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC;YACvB,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;SAC1B;IACH,CAAC;CACF","file":"container.js","sourcesContent":["import { Generator } from '../generator';\nimport { Binding } from './binding';\nimport type { interfaces } from './interfaces';\nimport { BindingScopeEnum, BindingTypeEnum } from './literal_types';\nimport { Metadata } from './meta-data';\nimport { INJECT_TAG, MULTI_INJECT_TAG, NAMED_TAG } from './metadata_keys';\nimport { MetadataReader } from './metadata_reader';\nimport { BindingToSyntax } from './syntax/binding_to_syntax';\n\ninterface IChildRequest {\n injectIdentifier: any;\n metadata: interfaces.Metadata<unknown>[];\n bindings: Binding<unknown>[];\n}\n\ninterface GetArgs<T> {\n avoidConstraints: boolean;\n isMultiInject: boolean;\n serviceIdentifier: interfaces.ServiceIdentifier<T>;\n key: string | symbol;\n value: any;\n}\n\nexport class Container {\n id: number;\n readonly options: interfaces.ContainerOptions;\n private _bindingDictionary: Map<any, Binding<unknown>[]>;\n private _metadataReader: interfaces.MetadataReader;\n\n constructor(containerOptions?: interfaces.ContainerOptions) {\n const options = containerOptions || {};\n options.defaultScope = options.defaultScope || BindingScopeEnum.Transient;\n // console.log(this);\n this.options = options;\n this.id = Generator.GenAutoIncrementId();\n this._bindingDictionary = new Map();\n this._metadataReader = new MetadataReader();\n }\n\n load(module: interfaces.ContainerModule) {\n const getHelpers = this._getContainerModuleHelpersFactory();\n\n const containerModuleHelpers = getHelpers(module.id);\n\n module.registry(\n containerModuleHelpers.bindFunction as interfaces.Bind,\n containerModuleHelpers.unbindFunction,\n containerModuleHelpers.isboundFunction,\n containerModuleHelpers.rebindFunction as interfaces.Rebind\n );\n }\n\n get<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): T {\n const getArgs = this._getNotAllArgs(serviceIdentifier, false);\n\n return this._get<T>(getArgs) as T;\n }\n\n getAll<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): T[] {\n const getArgs = this._getAllArgs(serviceIdentifier);\n\n return this._get<T>(getArgs) as T[];\n }\n\n getTagged<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, key: string | number | symbol, value: unknown): T {\n const getArgs = this._getNotAllArgs(serviceIdentifier, false, key, value);\n\n return this._get<T>(getArgs) as T;\n }\n\n getNamed<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, named: string | number | symbol): T {\n return this.getTagged<T>(serviceIdentifier, NAMED_TAG, named);\n }\n\n isBound(serviceIdentifier: interfaces.ServiceIdentifier<unknown>): boolean {\n return this._bindingDictionary.has(serviceIdentifier);\n }\n\n // Registers a type binding\n bind<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): interfaces.BindingToSyntax<T> {\n const scope = this.options.defaultScope;\n const binding = new Binding<T>(serviceIdentifier, scope);\n const list = this._bindingDictionary.get(serviceIdentifier) || [];\n list.push(binding);\n this._bindingDictionary.set(serviceIdentifier, list);\n return new BindingToSyntax<T>(binding);\n }\n\n unbind(serviceIdentifier: interfaces.ServiceIdentifier): void {\n this._bindingDictionary.delete(serviceIdentifier);\n }\n\n rebind<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): interfaces.BindingToSyntax<T> {\n this.unbind(serviceIdentifier);\n return this.bind(serviceIdentifier);\n }\n\n private _getContainerModuleHelpersFactory() {\n const setModuleId = (\n bindingToSyntax: interfaces.BindingToSyntax<unknown>,\n moduleId: interfaces.ContainerModuleBase['id']\n ) => {\n // TODO: Implement an internal type `_BindingToSyntax<T>` wherein this member\n // can be public. Let `BindingToSyntax<T>` be the presentational type that\n // depends on it, and does not expose this member as public.\n (\n bindingToSyntax as unknown as { _binding: { moduleId: interfaces.ContainerModuleBase['id'] } }\n )._binding.moduleId = moduleId;\n };\n\n const getBindFunction =\n <T>(moduleId: interfaces.ContainerModuleBase['id']) =>\n (serviceIdentifier: interfaces.ServiceIdentifier) => {\n const bindingToSyntax = this.bind(serviceIdentifier);\n setModuleId(bindingToSyntax, moduleId);\n return bindingToSyntax as BindingToSyntax<T>;\n };\n\n const getUnbindFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => {\n return this.unbind(serviceIdentifier);\n };\n\n const getUnbindAsyncFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => {\n return null as any;\n // return this.unbindAsync(serviceIdentifier);\n };\n\n const getIsboundFunction = () => (serviceIdentifier: interfaces.ServiceIdentifier) => {\n return this.isBound(serviceIdentifier);\n };\n\n const getRebindFunction =\n <T = unknown>(moduleId: interfaces.ContainerModuleBase['id']) =>\n (serviceIdentifier: interfaces.ServiceIdentifier) => {\n const bindingToSyntax = this.rebind(serviceIdentifier);\n setModuleId(bindingToSyntax, moduleId);\n return bindingToSyntax as BindingToSyntax<T>;\n };\n return (mId: interfaces.ContainerModuleBase['id']) => ({\n bindFunction: getBindFunction(mId),\n isboundFunction: getIsboundFunction(),\n rebindFunction: getRebindFunction(mId),\n unbindFunction: getUnbindFunction(),\n unbindAsyncFunction: getUnbindAsyncFunction()\n });\n }\n\n private _getNotAllArgs<T>(\n serviceIdentifier: interfaces.ServiceIdentifier<T>,\n isMultiInject: boolean,\n key?: string | number | symbol | undefined,\n value?: unknown\n ): any {\n return {\n avoidConstraints: false,\n isMultiInject,\n serviceIdentifier,\n key,\n value\n };\n }\n\n private _getAllArgs<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>): any {\n return {\n avoidConstraints: true,\n isMultiInject: true,\n serviceIdentifier\n };\n }\n\n private _get<T>(getArgs: GetArgs<T>): T | T[] {\n const result: T[] = [];\n const bindings = this._bindingDictionary.get(getArgs.serviceIdentifier).filter(b => {\n return b.constraint(getArgs as any);\n }) as Binding<T>[];\n bindings.forEach(binding => {\n result.push(this._resolveFromBinding<T>(binding));\n });\n\n return !getArgs.isMultiInject && result.length === 1 ? result[0] : result;\n }\n\n private _getChildRequest(binding: Binding<unknown>) {\n const constr = binding.implementationType;\n const { userGeneratedMetadata } = this._metadataReader.getConstructorMetadata(constr as any);\n const keys = Object.keys(userGeneratedMetadata);\n const arr = [];\n for (let i = 0; i < keys.length; i++) {\n const constructorArgsMetadata = userGeneratedMetadata[i];\n const targetMetadataMap = {};\n constructorArgsMetadata.forEach(md => {\n targetMetadataMap[md.key] = md.value;\n });\n const metadata = {\n inject: targetMetadataMap[INJECT_TAG],\n multiInject: targetMetadataMap[MULTI_INJECT_TAG]\n };\n const injectIdentifier = metadata.inject || metadata.multiInject;\n const target = {\n serviceIdentifier: injectIdentifier,\n constructorArgsMetadata\n };\n const bindings = (this._bindingDictionary.get(injectIdentifier) || []).filter(b => {\n return b.constraint(target as any);\n });\n if (bindings.length) {\n const request = {\n injectIdentifier,\n metadata: constructorArgsMetadata,\n bindings: bindings\n };\n\n arr.push(request);\n }\n }\n\n return arr;\n }\n\n private _resolveFromBinding<T>(binding: Binding<T>): T {\n const result = this._getResolvedFromBinding<T>(binding);\n\n this._saveToScope(binding, result);\n\n return result;\n }\n\n private _getResolvedFromBinding<T>(binding: Binding<T>) {\n let result: T;\n switch (binding.type) {\n case BindingTypeEnum.ConstantValue:\n case BindingTypeEnum.Function:\n result = binding.cache as T;\n break;\n case BindingTypeEnum.Instance:\n result = this._resolveInstance<T>(binding, binding.implementationType as interfaces.Newable<T>);\n break;\n default:\n result = binding.dynamicValue({ container: this } as any);\n }\n\n return result;\n }\n\n private _resolveInstance<T>(binding: Binding<T>, constr: interfaces.Newable<T>): T {\n if (binding.activated) {\n return binding.cache;\n }\n\n const childRequests = this._getChildRequest(binding);\n return this._createInstance(constr, childRequests);\n }\n\n private _createInstance<T>(constr: interfaces.Newable<T>, childRequests: IChildRequest[]) {\n if (childRequests.length) {\n const resolved = this._resolveRequests(childRequests);\n const obj = new constr(...resolved);\n return obj;\n }\n const obj = new constr();\n return obj;\n }\n\n private _resolveRequests(childRequests: IChildRequest[]): any[] {\n return childRequests.map(request => {\n return request.bindings.length > 1\n ? request.bindings.map(binding => this._resolveFromBinding(binding))\n : this._resolveFromBinding(request.bindings[0]);\n });\n }\n\n private _saveToScope(binding: Binding<unknown>, result: any) {\n if (binding.scope === BindingScopeEnum.Singleton) {\n binding.cache = result;\n binding.activated = true;\n }\n }\n}\n"]}
|
|
@@ -18,7 +18,7 @@ import { ContributionProvider } from "../../../common/contribution-provider";
|
|
|
18
18
|
|
|
19
19
|
import { DefaultAttribute } from "../../../graphic/config";
|
|
20
20
|
|
|
21
|
-
import { Bounds, Logger, getRectIntersect, isRectIntersect } from "@visactor/vutils";
|
|
21
|
+
import { Bounds, Logger, getRectIntersect, isArray, isRectIntersect } from "@visactor/vutils";
|
|
22
22
|
|
|
23
23
|
import { container } from "../../../container";
|
|
24
24
|
|
|
@@ -39,7 +39,8 @@ let DefaultDrawContribution = class {
|
|
|
39
39
|
this.contributions = contributions, this.drawItemInterceptorContributions = drawItemInterceptorContributions,
|
|
40
40
|
this.currentRenderMap = new Map, this.defaultRenderMap = new Map, this.styleRenderMap = new Map,
|
|
41
41
|
this.dirtyBounds = new Bounds, this.backupDirtyBounds = new Bounds, this.global = application.global,
|
|
42
|
-
this.layerService = application.layerService, this.
|
|
42
|
+
this.layerService = application.layerService, isArray(this.contributions) || (this.contributions = [ this.contributions ]),
|
|
43
|
+
this.init();
|
|
43
44
|
}
|
|
44
45
|
init() {
|
|
45
46
|
this.contributions.forEach((item => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/render/contributions/render/draw-contribution.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAexF,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEhE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAM5C,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAgBlC,YAIiD,aAA+B,EAK3D,gCAAyF;QAL7D,kBAAa,GAAb,aAAa,CAAkB;QAK3D,qCAAgC,GAAhC,gCAAgC,CAAyD;QAE5G,IAAI,CAAC,gB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AAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;iBAClD;aACF;iBAAM;gBACL,OAAO,CAAC,SAAS,GAAG,WAAW,CAC7B,OAAO,EACP,KAAK,EACL;oBACE,UAAU,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,KAAK,EAAE,EAAE,EAAE,CAAC,GAAG,MAAM,EAAE;iBAC5D,EACD,CAAC,EACD,CAAC,CACF,CAAC;gBACF,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;aACvC;SACF;IACH,CAAC;IAED,SAAS,CAAC,aAA6B,EAAE,UAAwB;QAC/D,OAAO;IACT,CAAC;CACF,CAAA;AAxaY,uBAAuB;IADnC,UAAU,EAAE;IAqBR,WAAA,WAAW,CAAC,aAAa,CAAC,CAAA;IAG1B,WAAA,MAAM,CAAC,oBAAoB,CAAC,CAAA;IAC5B,WAAA,KAAK,CAAC,mBAAmB,CAAC,CAAA;;GAxBlB,uBAAuB,CAwanC;SAxaY,uBAAuB","file":"draw-contribution.js","sourcesContent":["import { injectable, inject, named, multiInject } from '../../../common/inversify-lite';\nimport type {\n IContext2d,\n MaybePromise,\n IGraphic,\n IGroup,\n IDrawContext,\n IRenderService,\n IGraphicRender,\n IGraphicRenderDrawParams,\n IContributionProvider,\n IDrawItemInterceptorContribution,\n IDrawContribution,\n IGlobal\n} from '../../../interface';\nimport { findNextGraphic, foreach } from '../../../common/sort';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { ContributionProvider } from '../../../common/contribution-provider';\nimport { DefaultAttribute } from '../../../graphic/config';\nimport type { IAABBBounds, IBounds, IMatrix } from '@visactor/vutils';\nimport { Bounds, Logger, getRectIntersect, isRectIntersect } from '@visactor/vutils';\nimport { container } from '../../../container';\nimport { GraphicRender, IncrementalDrawContribution } from './symbol';\nimport { DrawItemInterceptor } from './draw-interceptor';\nimport { createColor } from '../../../common/canvas-utils';\nimport type { ILayerService } from '../../../interface/core';\nimport { boundsAllocate } from '../../../allocator/bounds-allocate';\nimport { matrixAllocate } from '../../../allocator/matrix-allocate';\nimport { application } from '../../../application';\n\n/**\n * 默认的渲染contribution,基于树状结构针对图元的渲染\n */\n@injectable()\nexport class DefaultDrawContribution implements IDrawContribution {\n declare currentRenderMap: Map<number, IGraphicRender>;\n declare defaultRenderMap: Map<number, IGraphicRender>;\n declare styleRenderMap: Map<string, Map<number, IGraphicRender>>;\n declare dirtyBounds: IBounds;\n declare backupDirtyBounds: IBounds;\n // 是否使用dirtyBounds\n declare useDirtyBounds: boolean;\n declare currentRenderService: IRenderService;\n declare InterceptorContributions: IDrawItemInterceptorContribution[];\n\n declare global: IGlobal;\n declare layerService: ILayerService;\n\n declare scrollMatrix?: IMatrix;\n\n constructor(\n // @inject(ContributionProvider)\n // @named(GraphicRender)\n // protected readonly contributions: ContributionProvider<IGraphicRender>,\n @multiInject(GraphicRender) protected readonly contributions: IGraphicRender[],\n // @inject(RenderSelector) protected readonly renderSelector: IRenderSelector, // 根据图元类型选择对应的renderItem进行渲染\n // 拦截器\n @inject(ContributionProvider)\n @named(DrawItemInterceptor)\n protected readonly drawItemInterceptorContributions: IContributionProvider<IDrawItemInterceptorContribution>\n ) {\n this.currentRenderMap = new Map();\n this.defaultRenderMap = new Map();\n this.styleRenderMap = new Map();\n this.dirtyBounds = new Bounds();\n this.backupDirtyBounds = new Bounds();\n this.global = application.global;\n this.layerService = application.layerService;\n this.init();\n }\n\n init() {\n this.contributions.forEach(item => {\n if (item.style) {\n const map = this.styleRenderMap.get(item.style) || new Map();\n map.set(item.numberType, item);\n this.styleRenderMap.set(item.style, map);\n } else {\n this.defaultRenderMap.set(item.numberType, item);\n }\n });\n this.InterceptorContributions = this.drawItemInterceptorContributions\n .getContributions()\n .sort((a, b) => a.order - b.order);\n }\n\n prepareForDraw(renderService: IRenderService, drawContext: IDrawContext) {\n // 有dirtyBounds用dirtyBounds\n if (drawContext.updateBounds) {\n this.useDirtyBounds = true;\n } else {\n // 没有的话,看看是否需要跳过outRange的渲染\n this.useDirtyBounds = !drawContext.stage.params.optimize.disableCheckGraphicWidthOutRange;\n }\n }\n\n draw(renderService: IRenderService, drawContext: IDrawContext): MaybePromise<void> {\n this.prepareForDraw(renderService, drawContext);\n drawContext.drawContribution = this;\n this.currentRenderMap = this.styleRenderMap.get(drawContext.renderStyle) || this.defaultRenderMap;\n // this.startAtId = drawParams.startAtId;\n this.currentRenderService = renderService;\n // this.drawParams = drawParams;\n const { context, stage, viewBox, transMatrix } = drawContext;\n\n if (!context) {\n return;\n }\n // if (context.drawPromise) {\n // return;\n // }\n const dirtyBounds: IBounds | undefined = this.dirtyBounds.setValue(0, 0, viewBox.width(), viewBox.height());\n if (stage.dirtyBounds && !stage.dirtyBounds.empty()) {\n const b = getRectIntersect(dirtyBounds, stage.dirtyBounds, false);\n dirtyBounds.x1 = Math.floor(b.x1);\n dirtyBounds.y1 = Math.floor(b.y1);\n dirtyBounds.x2 = Math.ceil(b.x2);\n dirtyBounds.y2 = Math.ceil(b.y2);\n }\n // 如果dpr不是整数或者.5的小数,需要格式化dirtyBounds\n const d = context.dpr % 1;\n if (d || d !== 0.5) {\n dirtyBounds.x1 = Math.floor(dirtyBounds.x1 * context.dpr) / context.dpr;\n dirtyBounds.y1 = Math.floor(dirtyBounds.y1 * context.dpr) / context.dpr;\n dirtyBounds.x2 = Math.ceil(dirtyBounds.x2 * context.dpr) / context.dpr;\n dirtyBounds.y2 = Math.ceil(dirtyBounds.y2 * context.dpr) / context.dpr;\n }\n this.backupDirtyBounds.copy(dirtyBounds);\n context.inuse = true;\n context.setClearMatrix(transMatrix.a, transMatrix.b, transMatrix.c, transMatrix.d, transMatrix.e, transMatrix.f);\n // 初始化context\n context.clearMatrix();\n context.setTransformForCurrent(true);\n\n // const drawInArea =\n // dirtyBounds.width() * context.dpr < context.canvas.width ||\n // dirtyBounds.height() * context.dpr < context.canvas.height;\n // context.save();\n\n // 设置translate\n context.translate(viewBox.x1, viewBox.y1, true);\n context.beginPath();\n context.rect(dirtyBounds.x1, dirtyBounds.y1, dirtyBounds.width(), dirtyBounds.height());\n context.clip();\n\n // 如果存在3d视角,那么不使用dirtyBounds\n if (stage.camera) {\n this.dirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity);\n this.backupDirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity);\n }\n\n this.clearScreen(renderService, context, drawContext);\n // // 渲染的时候图元的起始位置就是x,y\n // this.backupDirtyBounds.translate(-x, -y);\n // this.dirtyBounds.translate(-x, -y);\n\n // // 设置translate\n // context.translate(x, y, true);\n\n context.save();\n renderService.renderTreeRoots\n .sort((a, b) => {\n return (a.attribute.zIndex ?? DefaultAttribute.zIndex) - (b.attribute.zIndex ?? DefaultAttribute.zIndex);\n })\n .forEach(group => {\n group.isContainer\n ? this.renderGroup(group as IGroup, drawContext, matrixAllocate.allocate(1, 0, 0, 1, 0, 0))\n : this.renderItem(group as IGraphic, drawContext);\n });\n\n // context.restore();\n context.restore();\n context.setClearMatrix(1, 0, 0, 1, 0, 0);\n // this.break = false;\n context.inuse = false;\n context.draw();\n }\n\n doRegister() {\n throw new Error('暂不支持');\n }\n\n // 找到下一个graphic\n protected _findNextGraphic(group: IGroup): IGraphic | null {\n let parent = group.parent;\n let id = group._uid;\n while (parent) {\n const g = findNextGraphic(parent, id, DefaultAttribute.zIndex);\n if (g) {\n return g;\n }\n id = parent._uid;\n parent = parent.parent;\n }\n return null;\n }\n\n renderGroup(group: IGroup, drawContext: IDrawContext, parentMatrix: IMatrix, skipSort?: boolean) {\n if (drawContext.break || group.attribute.visibleAll === false) {\n return;\n }\n if (group.incremental && (drawContext.startAtId == null || drawContext.startAtId === group._uid)) {\n drawContext.break = true;\n this._increaseRender(group, drawContext);\n return;\n }\n\n if (this.useDirtyBounds && !isRectIntersect(group.AABBBounds, this.dirtyBounds, false)) {\n return;\n }\n\n let nextM: IMatrix = parentMatrix;\n let tempBounds: IBounds;\n\n if (this.useDirtyBounds) {\n tempBounds = boundsAllocate.allocateByObj(this.dirtyBounds);\n // 变换dirtyBounds\n const gm = group.transMatrix;\n nextM = matrixAllocate.allocateByObj(parentMatrix).multiply(gm.a, gm.b, gm.c, gm.d, gm.e, gm.f);\n // const m = group.globalTransMatrix.getInverse();\n this.dirtyBounds.copy(this.backupDirtyBounds).transformWithMatrix(nextM.getInverse());\n }\n\n this.renderItem(group, drawContext, {\n drawingCb: () => {\n skipSort\n ? group.forEachChildren((item: IGraphic) => {\n if (drawContext.break) {\n return;\n }\n if (item.isContainer) {\n this.renderGroup(item as IGroup, drawContext, nextM);\n } else {\n this.renderItem(item, drawContext);\n }\n })\n : foreach(\n group,\n DefaultAttribute.zIndex,\n (item: IGraphic) => {\n if (drawContext.break) {\n return;\n }\n if (item.isContainer) {\n this.renderGroup(item as IGroup, drawContext, nextM);\n } else {\n this.renderItem(item, drawContext);\n }\n },\n false,\n !!drawContext.context?.camera\n );\n }\n });\n\n if (this.useDirtyBounds) {\n this.dirtyBounds.copy(tempBounds);\n boundsAllocate.free(tempBounds);\n matrixAllocate.free(nextM);\n }\n }\n\n protected _increaseRender(group: IGroup, drawContext: IDrawContext) {\n const { layer, stage } = drawContext;\n const { subLayers } = layer;\n // 获取渐进渲染层\n let incrementalLayer = subLayers.get(group._uid);\n if (!incrementalLayer) {\n incrementalLayer = {\n layer: this.layerService.createLayer(stage),\n zIndex: subLayers.size,\n group\n };\n subLayers.set(group._uid, incrementalLayer);\n }\n // 渲染\n const incrementalContext = incrementalLayer.layer.getNativeHandler().getContext();\n const idc = incrementalLayer.drawContribution || container.get(IncrementalDrawContribution);\n idc.dirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity);\n idc.backupDirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity);\n (idc as any).draw(this.currentRenderService, {\n ...drawContext,\n drawContribution: idc,\n clear: 'transparent',\n layer: incrementalLayer.layer,\n context: incrementalContext,\n startAtId: group._uid,\n break: false\n });\n incrementalLayer.drawContribution = idc;\n // this.draw(this.currentRenderService, {...this.drawParams, startAtId: group._uid})\n // this.draw(this.currentRenderService, {...this.drawParams, clear: 'transparent', layer: incrementalContext.layer, context: incrementalContext, startAtId: group._uid})\n const nextGraphic = this._findNextGraphic(group);\n if (nextGraphic) {\n // 如果是下一个渐进渲染层,那就再来一次\n if (nextGraphic.isContainer && nextGraphic.incremental) {\n this._increaseRender(nextGraphic as IGroup, drawContext);\n } else {\n // 如果不是渐进渲染层,那就默认图层渲染\n let afterLayer = subLayers.get(nextGraphic._uid);\n if (!afterLayer) {\n afterLayer = {\n layer: this.layerService.createLayer(stage),\n zIndex: subLayers.size\n };\n subLayers.set(nextGraphic._uid, afterLayer);\n }\n const afterContext = afterLayer.layer.getNativeHandler().getContext();\n this.draw(this.currentRenderService, {\n ...drawContext,\n drawContribution: idc,\n clear: 'transparent',\n layer: afterLayer.layer,\n context: afterContext,\n startAtId: nextGraphic._uid,\n break: false\n });\n }\n }\n }\n\n getRenderContribution(graphic: IGraphic): IGraphicRender | null {\n let renderer;\n if (!renderer) {\n renderer = this.selectRenderByNumberType(graphic.numberType, graphic);\n }\n if (!renderer) {\n renderer = this.selectRenderByType(graphic.type);\n }\n return renderer;\n }\n\n renderItem(graphic: IGraphic, drawContext: IDrawContext, params?: IGraphicRenderDrawParams) {\n // 添加拦截器\n if (this.InterceptorContributions.length) {\n for (let i = 0; i < this.InterceptorContributions.length; i++) {\n const drawContribution = this.InterceptorContributions[i];\n if (\n drawContribution.beforeDrawItem &&\n drawContribution.beforeDrawItem(graphic, this.currentRenderService, drawContext, this, params)\n ) {\n return;\n }\n }\n }\n\n const renderer = this.getRenderContribution(graphic);\n if (!renderer) {\n return;\n }\n\n let retrans: boolean = this.scrollMatrix && (this.scrollMatrix.e !== 0 || this.scrollMatrix.f !== 0);\n let tempBounds: IBounds;\n\n if (graphic.parent) {\n const { scrollX = 0, scrollY = 0 } = graphic.parent.attribute;\n if (!!(scrollX || scrollY)) {\n retrans = true;\n if (!this.scrollMatrix) {\n this.scrollMatrix = matrixAllocate.allocate(1, 0, 0, 1, 0, 0);\n }\n this.scrollMatrix.translate(-scrollX, -scrollY);\n }\n }\n // 需要二次变化,那就重新算一个变换后的Bounds\n if (retrans) {\n tempBounds = this.dirtyBounds.clone().transformWithMatrix(this.scrollMatrix);\n }\n\n if (\n this.useDirtyBounds &&\n !(graphic.isContainer || isRectIntersect(graphic.AABBBounds, tempBounds ?? this.dirtyBounds, false))\n ) {\n if (retrans && graphic.parent) {\n const { scrollX = 0, scrollY = 0 } = graphic.parent.attribute;\n this.scrollMatrix && this.scrollMatrix.translate(scrollX, scrollY);\n }\n return;\n }\n\n const skipDraw = drawContext.startAtId != null && graphic._uid !== drawContext.startAtId;\n if (graphic._uid === drawContext.startAtId) {\n drawContext.startAtId = null;\n }\n params && (params.skipDraw = skipDraw);\n if (skipDraw) {\n graphic.isContainer && renderer.draw(graphic, this.currentRenderService, drawContext, params);\n } else {\n renderer.draw(graphic, this.currentRenderService, drawContext, params);\n }\n\n // retrans && this.dirtyBounds.copy(tempBounds);\n if (retrans && graphic.parent) {\n const { scrollX = 0, scrollY = 0 } = graphic.parent.attribute;\n this.scrollMatrix && this.scrollMatrix.translate(scrollX, scrollY);\n }\n\n // 添加拦截器\n if (this.InterceptorContributions.length) {\n for (let i = 0; i < this.InterceptorContributions.length; i++) {\n const drawContribution = this.InterceptorContributions[i];\n if (drawContribution.afterDrawItem) {\n if (drawContribution.afterDrawItem(graphic, this.currentRenderService, drawContext, this)) {\n return;\n }\n }\n }\n }\n }\n // 根据type选择对应的render\n protected selectRenderByType(type?: string): IGraphicRender | null {\n Logger.getInstance().warn('未知错误,不应该走到这里');\n return null;\n }\n // 根据type选择对应的render\n protected selectRenderByNumberType(type: number, graphic: IGraphic): IGraphicRender | null {\n let data;\n if (graphic.attribute.renderStyle) {\n const currentRenderMap = this.styleRenderMap.get(graphic.attribute.renderStyle);\n data = currentRenderMap && currentRenderMap.get(type);\n }\n return data || this.currentRenderMap.get(type) || this.defaultRenderMap.get(type);\n }\n\n protected clearScreen(renderService: IRenderService, context: IContext2d, drawContext: IDrawContext) {\n const { clear, viewBox } = drawContext;\n // 已经translate过了\n const x = 0;\n const y = 0;\n const width = viewBox.width();\n const height = viewBox.height();\n if (clear) {\n context.clearRect(x, y, width, height);\n const stage = renderService.drawParams?.stage;\n stage && (context.globalAlpha = (stage as any).attribute.opacity ?? 1);\n if (stage && (stage as any).backgroundImg && (stage as any).resources) {\n const res = (stage as any).resources.get(clear);\n if (res && res.state === 'success' && res.data) {\n context.drawImage(res.data, x, y, width, height);\n }\n } else {\n context.fillStyle = createColor(\n context,\n clear,\n {\n AABBBounds: { x1: x, y1: y, x2: x + width, y2: y + height }\n },\n 0,\n 0\n );\n context.fillRect(x, y, width, height);\n }\n }\n }\n\n afterDraw(renderService: IRenderService, drawParams: IDrawContext) {\n return;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/render/contributions/render/draw-contribution.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAexF,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEhE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,WAAW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iInject } from '../../../common/inversify-lite';\nimport type {\n IContext2d,\n MaybePromise,\n IGraphic,\n IGroup,\n IDrawContext,\n IRenderService,\n IGraphicRender,\n IGraphicRenderDrawParams,\n IContributionProvider,\n IDrawItemInterceptorContribution,\n IDrawContribution,\n IGlobal\n} from '../../../interface';\nimport { findNextGraphic, foreach } from '../../../common/sort';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { ContributionProvider } from '../../../common/contribution-provider';\nimport { DefaultAttribute } from '../../../graphic/config';\nimport type { IAABBBounds, IBounds, IMatrix } from '@visactor/vutils';\nimport { Bounds, Logger, getRectIntersect, isArray, isRectIntersect } from '@visactor/vutils';\nimport { container } from '../../../container';\nimport { GraphicRender, IncrementalDrawContribution } from './symbol';\nimport { DrawItemInterceptor } from './draw-interceptor';\nimport { createColor } from '../../../common/canvas-utils';\nimport type { ILayerService } from '../../../interface/core';\nimport { boundsAllocate } from '../../../allocator/bounds-allocate';\nimport { matrixAllocate } from '../../../allocator/matrix-allocate';\nimport { application } from '../../../application';\n\n/**\n * 默认的渲染contribution,基于树状结构针对图元的渲染\n */\n@injectable()\nexport class DefaultDrawContribution implements IDrawContribution {\n declare currentRenderMap: Map<number, IGraphicRender>;\n declare defaultRenderMap: Map<number, IGraphicRender>;\n declare styleRenderMap: Map<string, Map<number, IGraphicRender>>;\n declare dirtyBounds: IBounds;\n declare backupDirtyBounds: IBounds;\n // 是否使用dirtyBounds\n declare useDirtyBounds: boolean;\n declare currentRenderService: IRenderService;\n declare InterceptorContributions: IDrawItemInterceptorContribution[];\n\n declare global: IGlobal;\n declare layerService: ILayerService;\n\n declare scrollMatrix?: IMatrix;\n\n constructor(\n // @inject(ContributionProvider)\n // @named(GraphicRender)\n // protected readonly contributions: ContributionProvider<IGraphicRender>,\n @multiInject(GraphicRender) protected readonly contributions: IGraphicRender[],\n // @inject(RenderSelector) protected readonly renderSelector: IRenderSelector, // 根据图元类型选择对应的renderItem进行渲染\n // 拦截器\n @inject(ContributionProvider)\n @named(DrawItemInterceptor)\n protected readonly drawItemInterceptorContributions: IContributionProvider<IDrawItemInterceptorContribution>\n ) {\n this.currentRenderMap = new Map();\n this.defaultRenderMap = new Map();\n this.styleRenderMap = new Map();\n this.dirtyBounds = new Bounds();\n this.backupDirtyBounds = new Bounds();\n this.global = application.global;\n this.layerService = application.layerService;\n if (!isArray(this.contributions)) {\n this.contributions = [this.contributions];\n }\n this.init();\n }\n\n init() {\n this.contributions.forEach(item => {\n if (item.style) {\n const map = this.styleRenderMap.get(item.style) || new Map();\n map.set(item.numberType, item);\n this.styleRenderMap.set(item.style, map);\n } else {\n this.defaultRenderMap.set(item.numberType, item);\n }\n });\n this.InterceptorContributions = this.drawItemInterceptorContributions\n .getContributions()\n .sort((a, b) => a.order - b.order);\n }\n\n prepareForDraw(renderService: IRenderService, drawContext: IDrawContext) {\n // 有dirtyBounds用dirtyBounds\n if (drawContext.updateBounds) {\n this.useDirtyBounds = true;\n } else {\n // 没有的话,看看是否需要跳过outRange的渲染\n this.useDirtyBounds = !drawContext.stage.params.optimize.disableCheckGraphicWidthOutRange;\n }\n }\n\n draw(renderService: IRenderService, drawContext: IDrawContext): MaybePromise<void> {\n this.prepareForDraw(renderService, drawContext);\n drawContext.drawContribution = this;\n this.currentRenderMap = this.styleRenderMap.get(drawContext.renderStyle) || this.defaultRenderMap;\n // this.startAtId = drawParams.startAtId;\n this.currentRenderService = renderService;\n // this.drawParams = drawParams;\n const { context, stage, viewBox, transMatrix } = drawContext;\n\n if (!context) {\n return;\n }\n // if (context.drawPromise) {\n // return;\n // }\n const dirtyBounds: IBounds | undefined = this.dirtyBounds.setValue(0, 0, viewBox.width(), viewBox.height());\n if (stage.dirtyBounds && !stage.dirtyBounds.empty()) {\n const b = getRectIntersect(dirtyBounds, stage.dirtyBounds, false);\n dirtyBounds.x1 = Math.floor(b.x1);\n dirtyBounds.y1 = Math.floor(b.y1);\n dirtyBounds.x2 = Math.ceil(b.x2);\n dirtyBounds.y2 = Math.ceil(b.y2);\n }\n // 如果dpr不是整数或者.5的小数,需要格式化dirtyBounds\n const d = context.dpr % 1;\n if (d || d !== 0.5) {\n dirtyBounds.x1 = Math.floor(dirtyBounds.x1 * context.dpr) / context.dpr;\n dirtyBounds.y1 = Math.floor(dirtyBounds.y1 * context.dpr) / context.dpr;\n dirtyBounds.x2 = Math.ceil(dirtyBounds.x2 * context.dpr) / context.dpr;\n dirtyBounds.y2 = Math.ceil(dirtyBounds.y2 * context.dpr) / context.dpr;\n }\n this.backupDirtyBounds.copy(dirtyBounds);\n context.inuse = true;\n context.setClearMatrix(transMatrix.a, transMatrix.b, transMatrix.c, transMatrix.d, transMatrix.e, transMatrix.f);\n // 初始化context\n context.clearMatrix();\n context.setTransformForCurrent(true);\n\n // const drawInArea =\n // dirtyBounds.width() * context.dpr < context.canvas.width ||\n // dirtyBounds.height() * context.dpr < context.canvas.height;\n // context.save();\n\n // 设置translate\n context.translate(viewBox.x1, viewBox.y1, true);\n context.beginPath();\n context.rect(dirtyBounds.x1, dirtyBounds.y1, dirtyBounds.width(), dirtyBounds.height());\n context.clip();\n\n // 如果存在3d视角,那么不使用dirtyBounds\n if (stage.camera) {\n this.dirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity);\n this.backupDirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity);\n }\n\n this.clearScreen(renderService, context, drawContext);\n // // 渲染的时候图元的起始位置就是x,y\n // this.backupDirtyBounds.translate(-x, -y);\n // this.dirtyBounds.translate(-x, -y);\n\n // // 设置translate\n // context.translate(x, y, true);\n\n context.save();\n renderService.renderTreeRoots\n .sort((a, b) => {\n return (a.attribute.zIndex ?? DefaultAttribute.zIndex) - (b.attribute.zIndex ?? DefaultAttribute.zIndex);\n })\n .forEach(group => {\n group.isContainer\n ? this.renderGroup(group as IGroup, drawContext, matrixAllocate.allocate(1, 0, 0, 1, 0, 0))\n : this.renderItem(group as IGraphic, drawContext);\n });\n\n // context.restore();\n context.restore();\n context.setClearMatrix(1, 0, 0, 1, 0, 0);\n // this.break = false;\n context.inuse = false;\n context.draw();\n }\n\n doRegister() {\n throw new Error('暂不支持');\n }\n\n // 找到下一个graphic\n protected _findNextGraphic(group: IGroup): IGraphic | null {\n let parent = group.parent;\n let id = group._uid;\n while (parent) {\n const g = findNextGraphic(parent, id, DefaultAttribute.zIndex);\n if (g) {\n return g;\n }\n id = parent._uid;\n parent = parent.parent;\n }\n return null;\n }\n\n renderGroup(group: IGroup, drawContext: IDrawContext, parentMatrix: IMatrix, skipSort?: boolean) {\n if (drawContext.break || group.attribute.visibleAll === false) {\n return;\n }\n if (group.incremental && (drawContext.startAtId == null || drawContext.startAtId === group._uid)) {\n drawContext.break = true;\n this._increaseRender(group, drawContext);\n return;\n }\n\n if (this.useDirtyBounds && !isRectIntersect(group.AABBBounds, this.dirtyBounds, false)) {\n return;\n }\n\n let nextM: IMatrix = parentMatrix;\n let tempBounds: IBounds;\n\n if (this.useDirtyBounds) {\n tempBounds = boundsAllocate.allocateByObj(this.dirtyBounds);\n // 变换dirtyBounds\n const gm = group.transMatrix;\n nextM = matrixAllocate.allocateByObj(parentMatrix).multiply(gm.a, gm.b, gm.c, gm.d, gm.e, gm.f);\n // const m = group.globalTransMatrix.getInverse();\n this.dirtyBounds.copy(this.backupDirtyBounds).transformWithMatrix(nextM.getInverse());\n }\n\n this.renderItem(group, drawContext, {\n drawingCb: () => {\n skipSort\n ? group.forEachChildren((item: IGraphic) => {\n if (drawContext.break) {\n return;\n }\n if (item.isContainer) {\n this.renderGroup(item as IGroup, drawContext, nextM);\n } else {\n this.renderItem(item, drawContext);\n }\n })\n : foreach(\n group,\n DefaultAttribute.zIndex,\n (item: IGraphic) => {\n if (drawContext.break) {\n return;\n }\n if (item.isContainer) {\n this.renderGroup(item as IGroup, drawContext, nextM);\n } else {\n this.renderItem(item, drawContext);\n }\n },\n false,\n !!drawContext.context?.camera\n );\n }\n });\n\n if (this.useDirtyBounds) {\n this.dirtyBounds.copy(tempBounds);\n boundsAllocate.free(tempBounds);\n matrixAllocate.free(nextM);\n }\n }\n\n protected _increaseRender(group: IGroup, drawContext: IDrawContext) {\n const { layer, stage } = drawContext;\n const { subLayers } = layer;\n // 获取渐进渲染层\n let incrementalLayer = subLayers.get(group._uid);\n if (!incrementalLayer) {\n incrementalLayer = {\n layer: this.layerService.createLayer(stage),\n zIndex: subLayers.size,\n group\n };\n subLayers.set(group._uid, incrementalLayer);\n }\n // 渲染\n const incrementalContext = incrementalLayer.layer.getNativeHandler().getContext();\n const idc = incrementalLayer.drawContribution || container.get(IncrementalDrawContribution);\n idc.dirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity);\n idc.backupDirtyBounds.setValue(-Infinity, -Infinity, Infinity, Infinity);\n (idc as any).draw(this.currentRenderService, {\n ...drawContext,\n drawContribution: idc,\n clear: 'transparent',\n layer: incrementalLayer.layer,\n context: incrementalContext,\n startAtId: group._uid,\n break: false\n });\n incrementalLayer.drawContribution = idc;\n // this.draw(this.currentRenderService, {...this.drawParams, startAtId: group._uid})\n // this.draw(this.currentRenderService, {...this.drawParams, clear: 'transparent', layer: incrementalContext.layer, context: incrementalContext, startAtId: group._uid})\n const nextGraphic = this._findNextGraphic(group);\n if (nextGraphic) {\n // 如果是下一个渐进渲染层,那就再来一次\n if (nextGraphic.isContainer && nextGraphic.incremental) {\n this._increaseRender(nextGraphic as IGroup, drawContext);\n } else {\n // 如果不是渐进渲染层,那就默认图层渲染\n let afterLayer = subLayers.get(nextGraphic._uid);\n if (!afterLayer) {\n afterLayer = {\n layer: this.layerService.createLayer(stage),\n zIndex: subLayers.size\n };\n subLayers.set(nextGraphic._uid, afterLayer);\n }\n const afterContext = afterLayer.layer.getNativeHandler().getContext();\n this.draw(this.currentRenderService, {\n ...drawContext,\n drawContribution: idc,\n clear: 'transparent',\n layer: afterLayer.layer,\n context: afterContext,\n startAtId: nextGraphic._uid,\n break: false\n });\n }\n }\n }\n\n getRenderContribution(graphic: IGraphic): IGraphicRender | null {\n let renderer;\n if (!renderer) {\n renderer = this.selectRenderByNumberType(graphic.numberType, graphic);\n }\n if (!renderer) {\n renderer = this.selectRenderByType(graphic.type);\n }\n return renderer;\n }\n\n renderItem(graphic: IGraphic, drawContext: IDrawContext, params?: IGraphicRenderDrawParams) {\n // 添加拦截器\n if (this.InterceptorContributions.length) {\n for (let i = 0; i < this.InterceptorContributions.length; i++) {\n const drawContribution = this.InterceptorContributions[i];\n if (\n drawContribution.beforeDrawItem &&\n drawContribution.beforeDrawItem(graphic, this.currentRenderService, drawContext, this, params)\n ) {\n return;\n }\n }\n }\n\n const renderer = this.getRenderContribution(graphic);\n if (!renderer) {\n return;\n }\n\n let retrans: boolean = this.scrollMatrix && (this.scrollMatrix.e !== 0 || this.scrollMatrix.f !== 0);\n let tempBounds: IBounds;\n\n if (graphic.parent) {\n const { scrollX = 0, scrollY = 0 } = graphic.parent.attribute;\n if (!!(scrollX || scrollY)) {\n retrans = true;\n if (!this.scrollMatrix) {\n this.scrollMatrix = matrixAllocate.allocate(1, 0, 0, 1, 0, 0);\n }\n this.scrollMatrix.translate(-scrollX, -scrollY);\n }\n }\n // 需要二次变化,那就重新算一个变换后的Bounds\n if (retrans) {\n tempBounds = this.dirtyBounds.clone().transformWithMatrix(this.scrollMatrix);\n }\n\n if (\n this.useDirtyBounds &&\n !(graphic.isContainer || isRectIntersect(graphic.AABBBounds, tempBounds ?? this.dirtyBounds, false))\n ) {\n if (retrans && graphic.parent) {\n const { scrollX = 0, scrollY = 0 } = graphic.parent.attribute;\n this.scrollMatrix && this.scrollMatrix.translate(scrollX, scrollY);\n }\n return;\n }\n\n const skipDraw = drawContext.startAtId != null && graphic._uid !== drawContext.startAtId;\n if (graphic._uid === drawContext.startAtId) {\n drawContext.startAtId = null;\n }\n params && (params.skipDraw = skipDraw);\n if (skipDraw) {\n graphic.isContainer && renderer.draw(graphic, this.currentRenderService, drawContext, params);\n } else {\n renderer.draw(graphic, this.currentRenderService, drawContext, params);\n }\n\n // retrans && this.dirtyBounds.copy(tempBounds);\n if (retrans && graphic.parent) {\n const { scrollX = 0, scrollY = 0 } = graphic.parent.attribute;\n this.scrollMatrix && this.scrollMatrix.translate(scrollX, scrollY);\n }\n\n // 添加拦截器\n if (this.InterceptorContributions.length) {\n for (let i = 0; i < this.InterceptorContributions.length; i++) {\n const drawContribution = this.InterceptorContributions[i];\n if (drawContribution.afterDrawItem) {\n if (drawContribution.afterDrawItem(graphic, this.currentRenderService, drawContext, this)) {\n return;\n }\n }\n }\n }\n }\n // 根据type选择对应的render\n protected selectRenderByType(type?: string): IGraphicRender | null {\n Logger.getInstance().warn('未知错误,不应该走到这里');\n return null;\n }\n // 根据type选择对应的render\n protected selectRenderByNumberType(type: number, graphic: IGraphic): IGraphicRender | null {\n let data;\n if (graphic.attribute.renderStyle) {\n const currentRenderMap = this.styleRenderMap.get(graphic.attribute.renderStyle);\n data = currentRenderMap && currentRenderMap.get(type);\n }\n return data || this.currentRenderMap.get(type) || this.defaultRenderMap.get(type);\n }\n\n protected clearScreen(renderService: IRenderService, context: IContext2d, drawContext: IDrawContext) {\n const { clear, viewBox } = drawContext;\n // 已经translate过了\n const x = 0;\n const y = 0;\n const width = viewBox.width();\n const height = viewBox.height();\n if (clear) {\n context.clearRect(x, y, width, height);\n const stage = renderService.drawParams?.stage;\n stage && (context.globalAlpha = (stage as any).attribute.opacity ?? 1);\n if (stage && (stage as any).backgroundImg && (stage as any).resources) {\n const res = (stage as any).resources.get(clear);\n if (res && res.state === 'success' && res.data) {\n context.drawImage(res.data, x, y, width, height);\n }\n } else {\n context.fillStyle = createColor(\n context,\n clear,\n {\n AABBBounds: { x1: x, y1: y, x2: x + width, y2: y + height }\n },\n 0,\n 0\n );\n context.fillRect(x, y, width, height);\n }\n }\n }\n\n afterDraw(renderService: IRenderService, drawParams: IDrawContext) {\n return;\n }\n}\n"]}
|