@visactor/react-vrender 0.9.0-alpha.0

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.
Files changed (52) hide show
  1. package/README.md +9 -0
  2. package/cjs/Stage.d.ts +9 -0
  3. package/cjs/Stage.js +63 -0
  4. package/cjs/Stage.js.map +1 -0
  5. package/cjs/host-elements.d.ts +34 -0
  6. package/cjs/host-elements.js +23 -0
  7. package/cjs/host-elements.js.map +1 -0
  8. package/cjs/hostConfig.d.ts +7 -0
  9. package/cjs/hostConfig.js +153 -0
  10. package/cjs/hostConfig.js.map +1 -0
  11. package/cjs/index.d.ts +3 -0
  12. package/cjs/index.js +22 -0
  13. package/cjs/index.js.map +1 -0
  14. package/cjs/processProps.d.ts +54 -0
  15. package/cjs/processProps.js +83 -0
  16. package/cjs/processProps.js.map +1 -0
  17. package/cjs/types.d.ts +62 -0
  18. package/cjs/types.js +6 -0
  19. package/cjs/types.js.map +1 -0
  20. package/cjs/util/debug.d.ts +2 -0
  21. package/cjs/util/debug.js +10 -0
  22. package/cjs/util/debug.js.map +1 -0
  23. package/cjs/util/index.d.ts +2 -0
  24. package/cjs/util/index.js +14 -0
  25. package/cjs/util/index.js.map +1 -0
  26. package/dist/reactvrender.js.js +15 -0
  27. package/dist/reactvrender.js.min.js +15 -0
  28. package/es/Stage.d.ts +9 -0
  29. package/es/Stage.js +59 -0
  30. package/es/Stage.js.map +1 -0
  31. package/es/host-elements.d.ts +34 -0
  32. package/es/host-elements.js +45 -0
  33. package/es/host-elements.js.map +1 -0
  34. package/es/hostConfig.d.ts +7 -0
  35. package/es/hostConfig.js +146 -0
  36. package/es/hostConfig.js.map +1 -0
  37. package/es/index.d.ts +3 -0
  38. package/es/index.js +6 -0
  39. package/es/index.js.map +1 -0
  40. package/es/processProps.d.ts +54 -0
  41. package/es/processProps.js +74 -0
  42. package/es/processProps.js.map +1 -0
  43. package/es/types.d.ts +62 -0
  44. package/es/types.js +2 -0
  45. package/es/types.js.map +1 -0
  46. package/es/util/debug.d.ts +2 -0
  47. package/es/util/debug.js +8 -0
  48. package/es/util/debug.js.map +1 -0
  49. package/es/util/index.d.ts +2 -0
  50. package/es/util/index.js +6 -0
  51. package/es/util/index.js.map +1 -0
  52. package/package.json +49 -0
package/es/Stage.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import type { IStage, IStageParams, IOption3D } from '@visactor/vrender';
2
+ import React from 'react';
3
+ export interface StageProps extends Omit<IStageParams, 'autoRender' | 'container'>, Omit<React.HTMLAttributes<HTMLDivElement>, 'id' | 'title'> {
4
+ containerId?: string | undefined;
5
+ containerTitle?: string | undefined;
6
+ children?: any;
7
+ stage3dOptions?: IOption3D;
8
+ }
9
+ export declare const Stage: React.ForwardRefExoticComponent<StageProps & React.RefAttributes<IStage>>;
package/es/Stage.js ADDED
@@ -0,0 +1,59 @@
1
+ var __rest = this && this.__rest || function(s, e) {
2
+ var t = {};
3
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]);
4
+ if (null != s && "function" == typeof Object.getOwnPropertySymbols) {
5
+ var i = 0;
6
+ for (p = Object.getOwnPropertySymbols(s); i < p.length; i++) e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]);
7
+ }
8
+ return t;
9
+ };
10
+
11
+ import { createStage } from "@visactor/vrender";
12
+
13
+ import { forwardRef, useLayoutEffect, useRef } from "react";
14
+
15
+ import React from "react";
16
+
17
+ import { reconcilor } from "./hostConfig";
18
+
19
+ import { assertRef } from "./util";
20
+
21
+ export const Stage = forwardRef(((props, ref) => {
22
+ const {viewBox: viewBox, width: width, height: height, dpr: dpr, background: background, canvasControled: canvasControled, title: title, canvas: canvas, disableDirtyBounds: disableDirtyBounds, beforeRender: beforeRender, afterRender: afterRender, renderStyle: renderStyle, stage3dOptions: stage3dOptions, containerId: containerId, containerTitle: containerTitle, children: children} = props, others = __rest(props, [ "viewBox", "width", "height", "dpr", "background", "canvasControled", "title", "canvas", "disableDirtyBounds", "beforeRender", "afterRender", "renderStyle", "stage3dOptions", "containerId", "containerTitle", "children" ]);
23
+ assertRef(ref);
24
+ const fiberRoot = useRef(), divRef = useRef(null), innerStageRef = useRef(null), stageRef = ref || innerStageRef, initedRef = useRef(!1);
25
+ return useLayoutEffect((() => {
26
+ const stage = createStage({
27
+ viewBox: viewBox,
28
+ width: width,
29
+ height: height,
30
+ dpr: dpr,
31
+ background: background,
32
+ canvasControled: canvasControled,
33
+ title: title,
34
+ autoRender: !0,
35
+ disableDirtyBounds: disableDirtyBounds,
36
+ beforeRender: beforeRender,
37
+ afterRender: afterRender,
38
+ renderStyle: renderStyle,
39
+ canvas: canvas,
40
+ container: divRef.current
41
+ });
42
+ return stage3dOptions && stage.set3dOptions(stage3dOptions), stageRef.current = stage,
43
+ fiberRoot.current = reconcilor.createContainer(stage, 1, null, !1, !1, ""), () => {
44
+ reconcilor.updateContainer(null, fiberRoot.current, null);
45
+ };
46
+ }), []), useLayoutEffect((() => {
47
+ viewBox && stageRef.current && initedRef.current && stageRef.current.setViewBox(viewBox.x1, viewBox.y1, viewBox.x2 - viewBox.x1, viewBox.y2 - viewBox.y1, !1);
48
+ }), [ stageRef, viewBox, initedRef ]), useLayoutEffect((() => {
49
+ dpr && stageRef.current && initedRef.current && stageRef.current.setDpr(dpr);
50
+ }), [ stageRef, dpr, initedRef ]), useLayoutEffect((() => {
51
+ width > 0 && height > 0 && stageRef.current && initedRef.current && stageRef.current.resize(width, height);
52
+ }), [ width, height, stageRef, initedRef ]), useLayoutEffect((() => {
53
+ initedRef.current = !0, fiberRoot.current && reconcilor.updateContainer(children, fiberRoot.current, null);
54
+ }), [ children ]), React.createElement("div", Object.assign({}, others, {
55
+ id: containerId,
56
+ title: containerTitle,
57
+ ref: divRef
58
+ }));
59
+ }));
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Stage.tsx"],"names":[],"mappings":";;;;;;;;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AE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;IAEzC,eAAe,CAAC,GAAG,EAAE;QACnB,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC;QACzB,IAAI,SAAS,CAAC,OAAO,EAAE;YACrB,UAAU,CAAC,eAAe,CAAC,QAAQ,EAAE,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;SAC/D;IACH,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO,6CAAS,MAAM,IAAE,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,IAAI,CAAC;AAClF,CAAC,CAAC,CAAC","file":"Stage.js","sourcesContent":["import { createStage } from '@visactor/vrender';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IStage, IStageParams, IOption3D } from '@visactor/vrender';\nimport { forwardRef, useLayoutEffect, useRef } from 'react';\n// eslint-disable-next-line no-duplicate-imports\nimport React from 'react';\nimport type { FiberRoot } from 'react-reconciler';\nimport { reconcilor } from './hostConfig';\nimport { assertRef } from './util';\n\nexport interface StageProps\n extends Omit<IStageParams, 'autoRender' | 'container'>,\n Omit<React.HTMLAttributes<HTMLDivElement>, 'id' | 'title'> {\n containerId?: string | undefined;\n containerTitle?: string | undefined;\n children?: any;\n stage3dOptions?: IOption3D;\n}\n\nexport const Stage = forwardRef<IStage, StageProps>((props, ref) => {\n const {\n viewBox,\n width,\n height,\n dpr,\n background,\n canvasControled,\n title,\n canvas,\n disableDirtyBounds,\n beforeRender,\n afterRender,\n renderStyle,\n stage3dOptions,\n containerId,\n containerTitle,\n children,\n ...others\n } = props;\n assertRef(ref);\n\n const fiberRoot = useRef<FiberRoot>();\n const divRef = useRef<HTMLDivElement>(null);\n const innerStageRef = useRef<IStage>(null);\n const stageRef = ref || innerStageRef;\n const initedRef = useRef(false);\n\n useLayoutEffect(() => {\n const stage = createStage({\n viewBox,\n width,\n height,\n dpr,\n background,\n canvasControled,\n title,\n autoRender: true,\n disableDirtyBounds,\n beforeRender,\n afterRender,\n renderStyle,\n canvas,\n container: divRef.current as HTMLElement\n });\n\n if (stage3dOptions) {\n stage.set3dOptions(stage3dOptions);\n }\n\n stageRef.current = stage;\n\n fiberRoot.current = (reconcilor as any).createContainer(stage as any, 1, null, false, false, '');\n\n return () => {\n reconcilor.updateContainer(null, fiberRoot.current, null);\n };\n }, []);\n\n useLayoutEffect(() => {\n if (viewBox && stageRef.current && initedRef.current) {\n stageRef.current.setViewBox(\n viewBox.x1 as any,\n viewBox.y1 as never,\n viewBox.x2 - viewBox.x1,\n viewBox.y2 - viewBox.y1,\n false\n );\n }\n }, [stageRef, viewBox, initedRef]);\n\n useLayoutEffect(() => {\n if (dpr && stageRef.current && initedRef.current) {\n stageRef.current.setDpr(dpr);\n }\n }, [stageRef, dpr, initedRef]);\n\n useLayoutEffect(() => {\n if (width > 0 && height > 0 && stageRef.current && initedRef.current) {\n stageRef.current.resize(width, height);\n }\n }, [width, height, stageRef, initedRef]);\n\n useLayoutEffect(() => {\n initedRef.current = true;\n if (fiberRoot.current) {\n reconcilor.updateContainer(children, fiberRoot.current, null);\n }\n }, [children]);\n\n return <div {...others} id={containerId} title={containerTitle} ref={divRef} />;\n});\n"]}
@@ -0,0 +1,34 @@
1
+ import type { IArc, IArcGraphicAttribute, IArea, IAreaGraphicAttribute, ICircle, ICircleGraphicAttribute, IGroup, IGroupGraphicAttribute, IImageGraphicAttribute, ILine, ILineGraphicAttribute, IPath, IPathGraphicAttribute, IPolygonGraphicAttribute, IRect, IRectGraphicAttribute, ISymbolGraphicAttribute, IText, ITextGraphicAttribute, ISymbol, IImage, IPolygon, IShadowRoot, IRichTextGraphicAttribute, IRichText, IGlyph, IGlyphGraphicAttribute, IRect3d, IRect3dGraphicAttribute } from '@visactor/vrender';
2
+ import type { Key, ReactElement, ReactNode, Ref } from 'react';
3
+ import type { VRenderEvents } from './types';
4
+ type BaseProps<Element, Prop> = {
5
+ key?: Key;
6
+ ref?: Ref<Element>;
7
+ children?: ReactNode;
8
+ } & Prop & VRenderEvents;
9
+ export declare function ElementOf<Element, Props, T extends string>(type: T): (props: BaseProps<Element, Props>) => ReactElement<Props, T>;
10
+ export declare const TYPES: {
11
+ layer: string;
12
+ arc: string;
13
+ rect: string;
14
+ circle: string;
15
+ area: string;
16
+ group: string;
17
+ };
18
+ export declare const Layer: (props: any) => ReactElement<any, "layer">;
19
+ export declare const Arc: (props: BaseProps<IArc, IArcGraphicAttribute>) => ReactElement<IArcGraphicAttribute, "arc">;
20
+ export declare const Area: (props: BaseProps<IArea, IAreaGraphicAttribute>) => ReactElement<IAreaGraphicAttribute, "area">;
21
+ export declare const Circle: (props: BaseProps<ICircle, ICircleGraphicAttribute>) => ReactElement<ICircleGraphicAttribute, "circle">;
22
+ export declare const Group: (props: BaseProps<IGroup, IGroupGraphicAttribute>) => ReactElement<IGroupGraphicAttribute, "group">;
23
+ export declare const Image: (props: BaseProps<IImage, IImageGraphicAttribute>) => ReactElement<IImageGraphicAttribute, "image">;
24
+ export declare const Line: (props: BaseProps<ILine, ILineGraphicAttribute>) => ReactElement<ILineGraphicAttribute, "line">;
25
+ export declare const Path: (props: BaseProps<IPath, IPathGraphicAttribute>) => ReactElement<IPathGraphicAttribute, "path">;
26
+ export declare const Rect: (props: BaseProps<IRect, IRectGraphicAttribute>) => ReactElement<IRectGraphicAttribute, "rect">;
27
+ export declare const Rect3d: (props: BaseProps<IRect3d, IRect3dGraphicAttribute>) => ReactElement<IRect3dGraphicAttribute, "rect3d">;
28
+ export declare const VRenderSymbol: (props: BaseProps<ISymbol, ISymbolGraphicAttribute>) => ReactElement<ISymbolGraphicAttribute, "symbol">;
29
+ export declare const Text: (props: BaseProps<IText, ITextGraphicAttribute>) => ReactElement<ITextGraphicAttribute, "text">;
30
+ export declare const RichText: (props: BaseProps<IRichText, IRichTextGraphicAttribute>) => ReactElement<IRichTextGraphicAttribute, "richtext">;
31
+ export declare const Polygon: (props: BaseProps<IPolygon, IPolygonGraphicAttribute>) => ReactElement<IPolygonGraphicAttribute, "polygon">;
32
+ export declare const Glyph: (props: BaseProps<IGlyph<Partial<import("@visactor/vrender").IGraphicAttribute>>, IGlyphGraphicAttribute>) => ReactElement<IGlyphGraphicAttribute, "glyph">;
33
+ export declare const ShadowRoot: (props: BaseProps<IShadowRoot, IGroupGraphicAttribute>) => ReactElement<IGroupGraphicAttribute, "shadowroot">;
34
+ export {};
@@ -0,0 +1,45 @@
1
+ export function ElementOf(type) {
2
+ return type;
3
+ }
4
+
5
+ export const TYPES = {
6
+ layer: "Layer",
7
+ arc: "Arc",
8
+ rect: "Rect",
9
+ circle: "Circle",
10
+ area: "Area",
11
+ group: "Group"
12
+ };
13
+
14
+ export const Layer = ElementOf("layer");
15
+
16
+ export const Arc = ElementOf("arc");
17
+
18
+ export const Area = ElementOf("area");
19
+
20
+ export const Circle = ElementOf("circle");
21
+
22
+ export const Group = ElementOf("group");
23
+
24
+ export const Image = ElementOf("image");
25
+
26
+ export const Line = ElementOf("line");
27
+
28
+ export const Path = ElementOf("path");
29
+
30
+ export const Rect = ElementOf("rect");
31
+
32
+ export const Rect3d = ElementOf("rect3d");
33
+
34
+ export const VRenderSymbol = ElementOf("symbol");
35
+
36
+ export const Text = ElementOf("text");
37
+
38
+ export const RichText = ElementOf("richtext");
39
+
40
+ export const Polygon = ElementOf("polygon");
41
+
42
+ export const Glyph = ElementOf("glyph");
43
+
44
+ export const ShadowRoot = ElementOf("shadowroot");
45
+ //# sourceMappingURL=host-elements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/host-elements.ts"],"names":[],"mappings":"AA0CA,MAAM,UAAU,SAAS,CACvB,IAAO;IAEP,OAAO,IAAW,CAAC;AACrB,CAAC;AAED,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,KAAK,EAAE,OAAO;IACd,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAA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Attribute,\n ICircle,\n ICircleGraphicAttribute,\n IGroup,\n IGroupGraphicAttribute,\n IImageGraphicAttribute,\n ILine,\n ILineGraphicAttribute,\n IPath,\n IPathGraphicAttribute,\n IPolygonGraphicAttribute,\n IRect,\n IRectGraphicAttribute,\n ISymbolGraphicAttribute,\n IText,\n ITextGraphicAttribute,\n ISymbol,\n IImage,\n IPolygon,\n IShadowRoot,\n IRichTextGraphicAttribute,\n IRichText,\n IGlyph,\n IGlyphGraphicAttribute,\n IRect3d,\n IRect3dGraphicAttribute\n} from '@visactor/vrender';\nimport type { Key, ReactElement, ReactNode, Ref } from 'react';\nimport type { VRenderEvents } from './types';\n\ntype BaseProps<Element, Prop> = {\n key?: Key;\n ref?: Ref<Element>;\n children?: ReactNode;\n} & Prop &\n VRenderEvents;\n\nexport function ElementOf<Element, Props, T extends string>(\n type: T\n): (props: BaseProps<Element, Props>) => ReactElement<Props, T> {\n return type as any;\n}\n\nexport const TYPES = {\n layer: 'Layer',\n arc: 'Arc',\n rect: 'Rect',\n circle: 'Circle',\n area: 'Area',\n group: 'Group'\n};\n\nexport const Layer = ElementOf<ILayer, any, 'layer'>('layer');\nexport const Arc = ElementOf<IArc, IArcGraphicAttribute, 'arc'>('arc');\nexport const Area = ElementOf<IArea, IAreaGraphicAttribute, 'area'>('area');\nexport const Circle = ElementOf<ICircle, ICircleGraphicAttribute, 'circle'>('circle');\nexport const Group = ElementOf<IGroup, IGroupGraphicAttribute, 'group'>('group');\nexport const Image = ElementOf<IImage, IImageGraphicAttribute, 'image'>('image');\nexport const Line = ElementOf<ILine, ILineGraphicAttribute, 'line'>('line');\nexport const Path = ElementOf<IPath, IPathGraphicAttribute, 'path'>('path');\nexport const Rect = ElementOf<IRect, IRectGraphicAttribute, 'rect'>('rect');\nexport const Rect3d = ElementOf<IRect3d, IRect3dGraphicAttribute, 'rect3d'>('rect3d');\nexport const VRenderSymbol = ElementOf<ISymbol, ISymbolGraphicAttribute, 'symbol'>('symbol');\nexport const Text = ElementOf<IText, ITextGraphicAttribute, 'text'>('text');\nexport const RichText = ElementOf<IRichText, IRichTextGraphicAttribute, 'richtext'>('richtext');\nexport const Polygon = ElementOf<IPolygon, IPolygonGraphicAttribute, 'polygon'>('polygon');\nexport const Glyph = ElementOf<IGlyph, IGlyphGraphicAttribute, 'glyph'>('glyph');\nexport const ShadowRoot = ElementOf<IShadowRoot, IGroupGraphicAttribute, 'shadowroot'>('shadowroot');\n"]}
@@ -0,0 +1,7 @@
1
+ import type { IStage, IGraphic, IGroup, ILayer, IGlyph } from '@visactor/vrender';
2
+ import React from 'react';
3
+ import ReactReconciler from 'react-reconciler';
4
+ import type { Container, Instance, Props, TextInstance, Type } from './types';
5
+ export declare const createInstance: (type: Type, props: Props, rootContainerInstance?: Container) => ILayer | IGroup | IGraphic<Partial<import("@visactor/vrender").IGraphicAttribute>> | IGlyph<Partial<import("@visactor/vrender").IGraphicAttribute>>;
6
+ export declare const reconcilor: ReactReconciler.Reconciler<Container, Instance, TextInstance, any, any>;
7
+ export declare const render: (component: React.ReactNode, target: IStage | IGroup, callback?: (() => void) | null) => void;
@@ -0,0 +1,146 @@
1
+ import { graphicCreator, createGlyph, createText, createShadowRoot } from "@visactor/vrender";
2
+
3
+ import React from "react";
4
+
5
+ import ReactReconciler from "react-reconciler";
6
+
7
+ import { DefaultEventPriority } from "react-reconciler/constants";
8
+
9
+ import { bindGraphicEvent, splitProps, updateProps } from "./processProps";
10
+
11
+ import { log, error } from "./util/debug";
12
+
13
+ const isStage = instance => instance.stage === instance, isLayer = instance => instance.layer === instance, isGlyph = instance => "glyph" === instance.type, isShadowRoot = instance => "shadowroot" === instance.type;
14
+
15
+ export const createInstance = (type, props, rootContainerInstance) => {
16
+ const graphicType = type.toLowerCase(), {graphicProps: graphicProps, eventProps: eventProps} = splitProps(props);
17
+ let instance;
18
+ return instance = "glyph" === graphicType ? createGlyph(graphicProps) : "layer" === graphicType && rootContainerInstance ? isStage(rootContainerInstance) ? rootContainerInstance.createLayer() : rootContainerInstance.stage ? rootContainerInstance.stage.createLayer() : null : "shadowroot" === graphicType ? createShadowRoot() : graphicCreator[graphicType](graphicProps),
19
+ bindGraphicEvent(eventProps, instance), log("createInstance ", graphicType, instance),
20
+ instance;
21
+ };
22
+
23
+ const appendChild = (parentInstance, child) => {
24
+ var _a;
25
+ const isParentStage = isStage(parentInstance), isChildLayer = isLayer(child);
26
+ isParentStage && !isChildLayer && parentInstance.defaultLayer ? parentInstance.defaultLayer.appendChild(child) : isGlyph(parentInstance) ? parentInstance.setSubGraphic((null !== (_a = parentInstance.getSubGraphic()) && void 0 !== _a ? _a : []).concat(child)) : isShadowRoot(child) ? isParentStage ? error("stage can not attach shadow root") : parentInstance.attachShadow(child) : parentInstance.appendChild(child);
27
+ }, insertBeforeChild = (parentInstance, child, beforeChild) => {
28
+ const isParentStage = isStage(parentInstance), isChildLayer = isLayer(child), isBeforeChildLayer = isLayer(beforeChild);
29
+ if (isParentStage) isChildLayer || isBeforeChildLayer ? isChildLayer && isBeforeChildLayer && parentInstance.insertBefore(child, beforeChild) : parentInstance.defaultLayer ? parentInstance.defaultLayer.insertBefore(child, beforeChild) : error("default layer has been removed "); else if (!isParentStage && isChildLayer) error(`layer can not be inserted into other graphic: ${parentInstance.type}`); else if (isGlyph(parentInstance)) {
30
+ const prevSubGraphics = parentInstance.getSubGraphic(), index = prevSubGraphics.indexOf(child), beforeIndex = prevSubGraphics.indexOf(beforeChild);
31
+ if (index >= 0 && beforeIndex >= 0 && index !== beforeIndex) {
32
+ const newSubGraphics = prevSubGraphics.slice();
33
+ newSubGraphics[beforeIndex] = child, newSubGraphics[index] = beforeChild, parentInstance.setSubGraphic(newSubGraphics);
34
+ }
35
+ } else parentInstance.insertBefore(child, beforeChild);
36
+ }, removeChild = (parentInstance, child) => {
37
+ const isParentStage = isStage(parentInstance), isChildLayer = isLayer(child);
38
+ if (isParentStage && !isChildLayer && parentInstance.defaultLayer) parentInstance.defaultLayer.removeChild(child); else if (isGlyph(parentInstance)) {
39
+ const prevSubGraphics = parentInstance.getSubGraphic(), index = prevSubGraphics.indexOf(child);
40
+ index >= 0 && parentInstance.setSubGraphic([ ...prevSubGraphics.slice(0, index - 1), ...prevSubGraphics.slice(index + 1) ]);
41
+ } else isShadowRoot(child) ? isParentStage ? error("stage can not attach shadow root") : parentInstance.detachShadow(child) : parentInstance.removeChild(child);
42
+ }, clearContainer = container => {
43
+ if (isStage(container)) for (container.defaultLayer && container.defaultLayer.removeAllChild(); container.childrenCount > 1; ) container.removeChild(container.getChildAt(1)); else container.removeAllChild();
44
+ };
45
+
46
+ export const reconcilor = ReactReconciler({
47
+ getPublicInstance: instance => instance,
48
+ getRootHostContext(rootContainerInstance) {},
49
+ getChildHostContext(parentHostContext, type, rootContainerInstance) {},
50
+ prepareForCommit: containerInfo => null,
51
+ resetAfterCommit(containerInfo) {},
52
+ preparePortalMount(containerInfo) {},
53
+ createInstance: (type, props, rootContainerInstance, hostContext, internalInstanceHandle) => createInstance(type, props, rootContainerInstance),
54
+ appendInitialChild(parentInstance, child) {
55
+ log("appendInitialChild", parentInstance, child), appendChild(parentInstance, child);
56
+ },
57
+ finalizeInitialChildren: (parentInstance, type, props, rootContainerInstance, hostContext) => !1,
58
+ prepareUpdate: (instance, type, oldProps, newProps, rootContainerInstance, hostContext) => !0,
59
+ shouldSetTextContent: (type, props) => !1,
60
+ createTextInstance: (text, rootContainerInstance, hostContext, internalInstanceHandle) => createText({
61
+ text: text
62
+ }),
63
+ scheduleTimeout(handler, timeout) {},
64
+ cancelTimeout(handle) {},
65
+ noTimeout: void 0,
66
+ getCurrentEventPriority: () => DefaultEventPriority,
67
+ getInstanceFromNode(node) {
68
+ throw new Error("Not implemented.");
69
+ },
70
+ beforeActiveInstanceBlur() {},
71
+ isPrimaryRenderer: !1,
72
+ supportsMutation: !0,
73
+ supportsPersistence: !1,
74
+ supportsHydration: !1,
75
+ appendChild(parentInstance, child) {
76
+ log("appendChild"), appendChild(parentInstance, child);
77
+ },
78
+ appendChildToContainer(container, child) {
79
+ log("appendChildToContainer", container, child), appendChild(container, child);
80
+ },
81
+ commitTextUpdate(textInstance, oldText, newText) {},
82
+ commitMount(instance, type, newProps, internalInstanceHandle) {},
83
+ commitUpdate(instance, updatePayload, type, oldProps, newProps, internalInstanceHandle) {
84
+ log("commitUpdate", instance, newProps), updateProps(instance, newProps, oldProps);
85
+ },
86
+ insertBefore(parentInstance, child, beforeChild) {
87
+ insertBeforeChild(parentInstance, child, beforeChild);
88
+ },
89
+ insertInContainerBefore(container, child, beforeChild) {
90
+ insertBeforeChild(container, child, beforeChild);
91
+ },
92
+ removeChild(parentInstance, child) {
93
+ log("removeChild", parentInstance, child), removeChild(parentInstance, child);
94
+ },
95
+ removeChildFromContainer(container, child) {
96
+ removeChild(container, child);
97
+ },
98
+ resetTextContent(instance) {},
99
+ hideInstance(instance) {},
100
+ hideTextInstance(textInstance) {},
101
+ unhideInstance(instance, props) {},
102
+ unhideTextInstance(textInstance, text) {},
103
+ clearContainer(container) {
104
+ clearContainer(container);
105
+ },
106
+ cloneInstance: (instance, updatePayload, type, oldProps, newProps, internalInstanceHandle, keepChildren, recyclableInstance) => instance,
107
+ createContainerChildSet(container) {},
108
+ appendChildToContainerChildSet(childSet, child) {},
109
+ finalizeContainerChildren(container, newChildren) {},
110
+ replaceContainerChildren(container, newChildren) {},
111
+ canHydrateInstance: (instance, type, props) => instance,
112
+ canHydrateTextInstance: (instance, text) => null,
113
+ getNextHydratableSibling(instance) {},
114
+ getFirstHydratableChild(parentInstance) {},
115
+ hydrateInstance(instance, type, props, rootContainerInstance, hostContext, internalInstanceHandle) {},
116
+ hydrateTextInstance: (textInstance, text, internalInstanceHandle) => !1,
117
+ didNotMatchHydratedContainerTextInstance(parentContainer, textInstance, text) {},
118
+ didNotMatchHydratedTextInstance(parentType, parentProps, parentInstance, textInstance, text) {},
119
+ didNotHydrateContainerInstance(parentContainer, instance) {},
120
+ didNotHydrateInstance(parentType, parentProps, parentInstance, instance) {},
121
+ didNotFindHydratableContainerInstance(parentContainer, type, props) {},
122
+ didNotFindHydratableContainerTextInstance(parentContainer, text) {},
123
+ didNotFindHydratableInstance(parentType, parentProps, parentInstance, type, props) {},
124
+ didNotFindHydratableTextInstance(parentType, parentProps, parentInstance, text) {},
125
+ afterActiveInstanceBlur() {},
126
+ prepareScopeUpdate() {},
127
+ getInstanceFromScope: () => null,
128
+ detachDeletedInstance() {}
129
+ });
130
+
131
+ reconcilor.injectIntoDevTools({
132
+ bundleType: "production" !== process.env.NODE_ENV ? 1 : 0,
133
+ version: React.version,
134
+ rendererPackageName: "react-g",
135
+ rendererConfig: {
136
+ getInspectorDataForViewTag: tag => {
137
+ console.log(tag);
138
+ }
139
+ }
140
+ });
141
+
142
+ export const render = (component, target, callback) => {
143
+ const container = reconcilor.createContainer(target, 1, !1, null);
144
+ reconcilor.updateContainer(component, container, null, callback);
145
+ };
146
+ //# sourceMappingURL=hostConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hostConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAG9F,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAG/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAgB3E,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAI1C,MAAM,OAAO,GAAG,CAAC,QAAkB,EAAsB,EAAE;IACzD,OAAQ,QAAgB,CAAC,KAAK,KAAK,QAAQ,CAAC;AAC9C,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG,CAAC,QAAkB,EAAsB,EAAE;IACzD,OAAQ,QAAgB,CAAC,KAAK,KAAK,QAAQ,CAAC;AA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AA8B,EAAE,EAAE;IAC5G,MAAM,SAAS,GAAI,UAAkB,CAAC,eAAe,CAAC,MAAa,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IACrF,UAAU,CAAC,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;AACnE,CAAC,CAAC","file":"hostConfig.js","sourcesContent":["import { graphicCreator, createGlyph, createText, createShadowRoot } from '@visactor/vrender';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IStage, IGraphic, IGroup, ILayer, IGlyph, IShadowRoot } from '@visactor/vrender';\nimport React from 'react';\nimport ReactReconciler from 'react-reconciler';\n// eslint-disable-next-line no-duplicate-imports\nimport type { OpaqueHandle } from 'react-reconciler';\nimport { DefaultEventPriority } from 'react-reconciler/constants';\nimport { bindGraphicEvent, splitProps, updateProps } from './processProps';\nimport type {\n ChildSet,\n Container,\n HostContext,\n HydratableInstance,\n Instance,\n NoTimeout,\n Props,\n PublicInstance,\n SuspenseInstance,\n TextInstance,\n TimeoutHandle,\n Type,\n UpdatePayload\n} from './types';\nimport { log, error } from './util/debug';\n\ndeclare const process: any;\n\nconst isStage = (instance: Instance): instance is IStage => {\n return (instance as any).stage === instance;\n};\n\nconst isLayer = (instance: Instance): instance is ILayer => {\n return (instance as any).layer === instance;\n};\n\nconst isGlyph = (instance: Instance): instance is IGlyph => {\n return (instance as any).type === 'glyph';\n};\n\nconst isShadowRoot = (instance: Instance): instance is IShadowRoot => {\n return (instance as any).type === 'shadowroot';\n};\n\nexport const createInstance = (type: Type, props: Props, rootContainerInstance?: Container) => {\n const graphicType = (type as string).toLowerCase();\n const { graphicProps, eventProps } = splitProps(props);\n\n let instance: Instance;\n\n if (graphicType === 'glyph') {\n instance = createGlyph(graphicProps);\n } else if (graphicType === 'layer' && rootContainerInstance) {\n instance = isStage(rootContainerInstance)\n ? rootContainerInstance.createLayer()\n : rootContainerInstance.stage\n ? rootContainerInstance.stage.createLayer()\n : null;\n } else if (graphicType === 'shadowroot') {\n instance = createShadowRoot();\n } else {\n instance = graphicCreator[graphicType](graphicProps) as IGraphic;\n }\n\n bindGraphicEvent(eventProps, instance);\n log('createInstance ', graphicType, instance);\n\n return instance;\n};\n\nconst appendChild = (parentInstance: Instance, child: Instance | TextInstance) => {\n const isParentStage = isStage(parentInstance);\n const isChildLayer = isLayer(child);\n if (isParentStage && !isChildLayer && (parentInstance as IStage).defaultLayer) {\n (parentInstance as IStage).defaultLayer.appendChild(child);\n } else if (isGlyph(parentInstance)) {\n parentInstance.setSubGraphic((parentInstance.getSubGraphic() ?? []).concat(child as IGraphic));\n } else if (isShadowRoot(child)) {\n if (isParentStage) {\n error('stage can not attach shadow root');\n } else {\n (parentInstance as any).attachShadow(child as IShadowRoot);\n }\n } else {\n parentInstance.appendChild(child);\n }\n};\n\nconst insertBeforeChild = (\n parentInstance: Instance,\n child: Instance | TextInstance,\n beforeChild: Instance | TextInstance\n) => {\n const isParentStage = isStage(parentInstance);\n const isChildLayer = isLayer(child);\n const isBeforeChildLayer = isLayer(beforeChild);\n\n if (isParentStage) {\n if (!isChildLayer && !isBeforeChildLayer) {\n if ((parentInstance as IStage).defaultLayer) {\n (parentInstance as IStage).defaultLayer.insertBefore(child, beforeChild);\n } else {\n error('default layer has been removed ');\n }\n } else if (isChildLayer && isBeforeChildLayer) {\n (parentInstance as IStage).insertBefore(child, beforeChild);\n }\n } else if (!isParentStage && isChildLayer) {\n error(`layer can not be inserted into other graphic: ${parentInstance.type}`);\n } else if (isGlyph(parentInstance)) {\n const prevSubGraphics = parentInstance.getSubGraphic();\n const index = prevSubGraphics.indexOf(child as IGraphic);\n const beforeIndex = prevSubGraphics.indexOf(beforeChild as IGraphic);\n\n if (index >= 0 && beforeIndex >= 0 && index !== beforeIndex) {\n const newSubGraphics: IGraphic[] = prevSubGraphics.slice();\n newSubGraphics[beforeIndex] = child as IGraphic;\n newSubGraphics[index] = beforeChild as IGraphic;\n\n parentInstance.setSubGraphic(newSubGraphics);\n }\n } else {\n parentInstance.insertBefore(child, beforeChild);\n }\n};\n\nconst removeChild = (parentInstance: Instance, child: Instance | TextInstance) => {\n const isParentStage = isStage(parentInstance);\n const isChildLayer = isLayer(child);\n\n if (isParentStage && !isChildLayer && (parentInstance as IStage).defaultLayer) {\n (parentInstance as IStage).defaultLayer.removeChild(child);\n } else if (isGlyph(parentInstance)) {\n const prevSubGraphics = parentInstance.getSubGraphic();\n const index = prevSubGraphics.indexOf(child as IGraphic);\n\n if (index >= 0) {\n parentInstance.setSubGraphic([...prevSubGraphics.slice(0, index - 1), ...prevSubGraphics.slice(index + 1)]);\n }\n } else if (isShadowRoot(child)) {\n if (isParentStage) {\n error('stage can not attach shadow root');\n } else {\n (parentInstance as any).detachShadow(child as IShadowRoot);\n }\n } else {\n parentInstance.removeChild(child);\n }\n};\n\nconst clearContainer = (container: Container) => {\n if (isStage(container)) {\n if (container.defaultLayer) {\n container.defaultLayer.removeAllChild();\n }\n\n while (container.childrenCount > 1) {\n container.removeChild(container.getChildAt(1));\n }\n } else {\n container.removeAllChild();\n }\n};\n\nexport const reconcilor = ReactReconciler<\n Type,\n Props,\n Container,\n Instance,\n TextInstance,\n SuspenseInstance,\n HydratableInstance,\n PublicInstance,\n HostContext,\n UpdatePayload,\n ChildSet,\n TimeoutHandle,\n NoTimeout\n>({\n getPublicInstance(instance: Instance | TextInstance): PublicInstance {\n return instance;\n },\n getRootHostContext(rootContainerInstance: Container): HostContext {\n return;\n },\n getChildHostContext(parentHostContext: HostContext, type: Type, rootContainerInstance: Container): HostContext {\n return;\n },\n\n prepareForCommit(containerInfo: Container): Record<string, any> {\n return null;\n },\n resetAfterCommit(containerInfo: Container): void {\n return;\n },\n preparePortalMount(containerInfo: Container): void {\n return;\n },\n\n createInstance(\n type: Type,\n props: Props,\n rootContainerInstance: Container,\n hostContext: HostContext,\n internalInstanceHandle: OpaqueHandle\n ): Instance {\n return createInstance(type, props, rootContainerInstance);\n },\n appendInitialChild(parentInstance: Instance, child: Instance | TextInstance): void {\n log('appendInitialChild', parentInstance, child);\n\n appendChild(parentInstance, child);\n },\n finalizeInitialChildren(\n parentInstance: Instance,\n type: Type,\n props: Props,\n rootContainerInstance: Container,\n hostContext: HostContext\n ): boolean {\n return false;\n },\n\n prepareUpdate(\n instance: Instance,\n type: Type,\n oldProps: Props,\n newProps: Props,\n rootContainerInstance: Container,\n hostContext: HostContext\n ): null | UpdatePayload {\n return true;\n },\n\n shouldSetTextContent(type: Type, props: Props): boolean {\n return false;\n },\n\n createTextInstance(\n text: string,\n rootContainerInstance: Container,\n hostContext: HostContext,\n internalInstanceHandle: OpaqueHandle\n ): TextInstance {\n return createText({ text });\n },\n\n scheduleTimeout(handler: (...args: any[]) => void, timeout: number): TimeoutHandle | NoTimeout {\n return;\n },\n cancelTimeout(handle: TimeoutHandle | NoTimeout): void {\n return;\n },\n noTimeout: undefined,\n\n getCurrentEventPriority() {\n return DefaultEventPriority;\n },\n\n getInstanceFromNode(node: any): ReactReconciler.Fiber {\n throw new Error('Not implemented.');\n },\n\n beforeActiveInstanceBlur(): void {\n return;\n },\n\n isPrimaryRenderer: false,\n\n supportsMutation: true,\n supportsPersistence: false,\n supportsHydration: false,\n\n appendChild(parentInstance: Instance, child: Instance | TextInstance): void {\n log('appendChild');\n appendChild(parentInstance, child);\n },\n appendChildToContainer(container: Container, child: Instance | TextInstance): void {\n log('appendChildToContainer', container, child);\n\n appendChild(container, child);\n },\n commitTextUpdate(textInstance: TextInstance, oldText: string, newText: string): void {\n return;\n },\n commitMount(instance: Instance, type: Type, newProps: Props, internalInstanceHandle: OpaqueHandle): void {\n return;\n },\n commitUpdate(\n instance: Instance,\n updatePayload: UpdatePayload,\n type: Type,\n oldProps: Props,\n newProps: Props,\n internalInstanceHandle: OpaqueHandle\n ): void {\n log('commitUpdate', instance, newProps);\n updateProps(instance, newProps, oldProps);\n },\n insertBefore(parentInstance: Instance, child: Instance | TextInstance, beforeChild: Instance | TextInstance): void {\n insertBeforeChild(parentInstance, child, beforeChild);\n },\n insertInContainerBefore(\n container: Container,\n child: Instance | TextInstance,\n beforeChild: Instance | TextInstance\n ): void {\n insertBeforeChild(container, child, beforeChild);\n },\n removeChild(parentInstance: Instance, child: Instance | TextInstance): void {\n log('removeChild', parentInstance, child);\n removeChild(parentInstance, child);\n },\n removeChildFromContainer(container: Container, child: Instance | TextInstance): void {\n removeChild(container, child);\n },\n resetTextContent(instance: Instance): void {\n return;\n },\n\n // tslint:enable:max-line-length\n hideInstance(instance: Instance): void {\n return;\n },\n\n hideTextInstance(textInstance: TextInstance): void {\n return;\n },\n\n unhideInstance(instance: Instance, props: Props): void {\n return;\n },\n\n unhideTextInstance(textInstance: TextInstance, text: string): void {\n return;\n },\n\n clearContainer(container: Container): void {\n clearContainer(container);\n },\n\n cloneInstance(\n instance: Instance,\n updatePayload: null | UpdatePayload,\n type: Type,\n oldProps: Props,\n newProps: Props,\n internalInstanceHandle: OpaqueHandle,\n keepChildren: boolean,\n recyclableInstance: Instance\n ): Instance {\n return instance;\n },\n\n createContainerChildSet(container: Container): ChildSet {\n return;\n },\n\n appendChildToContainerChildSet(childSet: ChildSet, child: Instance | TextInstance): void {\n return;\n },\n finalizeContainerChildren(container: Container, newChildren: ChildSet): void {\n return;\n },\n\n replaceContainerChildren(container: Container, newChildren: ChildSet): void {\n return;\n },\n\n canHydrateInstance(instance: HydratableInstance, type: Type, props: Props): null | Instance {\n return instance;\n },\n canHydrateTextInstance(instance: HydratableInstance, text: string): null | TextInstance {\n return null;\n },\n getNextHydratableSibling(instance: Instance | TextInstance | HydratableInstance): null | HydratableInstance {\n return;\n },\n getFirstHydratableChild(parentInstance: Instance | Container): null | HydratableInstance {\n return;\n },\n hydrateInstance(\n instance: Instance,\n type: Type,\n props: Props,\n rootContainerInstance: Container,\n hostContext: HostContext,\n internalInstanceHandle: OpaqueHandle\n ): null | UpdatePayload {\n return;\n },\n hydrateTextInstance(textInstance: TextInstance, text: string, internalInstanceHandle: OpaqueHandle): boolean {\n return false;\n },\n didNotMatchHydratedContainerTextInstance(parentContainer: Container, textInstance: TextInstance, text: string): void {\n return;\n },\n didNotMatchHydratedTextInstance(\n parentType: Type,\n parentProps: Props,\n parentInstance: Instance,\n textInstance: TextInstance,\n text: string\n ): void {\n return;\n },\n didNotHydrateContainerInstance(parentContainer: Container, instance: Instance | TextInstance): void {\n return;\n },\n didNotHydrateInstance(\n parentType: Type,\n parentProps: Props,\n parentInstance: Instance,\n instance: Instance | TextInstance\n ): void {\n return;\n },\n didNotFindHydratableContainerInstance(parentContainer: Container, type: Type, props: Props): void {\n return;\n },\n didNotFindHydratableContainerTextInstance(parentContainer: Container, text: string): void {\n return;\n },\n didNotFindHydratableInstance(\n parentType: Type,\n parentProps: Props,\n parentInstance: Instance,\n type: Type,\n props: Props\n ): void {\n return;\n },\n didNotFindHydratableTextInstance(parentType: Type, parentProps: Props, parentInstance: Instance, text: string): void {\n return;\n },\n afterActiveInstanceBlur() {\n return;\n },\n prepareScopeUpdate() {\n return;\n },\n getInstanceFromScope(): Instance {\n return null;\n },\n detachDeletedInstance() {\n return;\n }\n});\n\nreconcilor.injectIntoDevTools({\n // findFiberByHostInstance: () => {},\n\n bundleType: process.env.NODE_ENV !== 'production' ? 1 : 0,\n version: React.version,\n rendererPackageName: 'react-g',\n rendererConfig: {\n getInspectorDataForViewTag: (tag: number) => {\n // eslint-disable-next-line no-console\n console.log(tag);\n }\n }\n});\n\n/**\n * render react-vrender component to target vrender group/stage/layer\n * 将react-vrender组件渲染到group,stage, layer中\n * @param component react-g component\n * @param target g element, Canvas/Group/Shape instance\n * @param callback callback after render finished\n * @returns void\n */\nexport const render = (component: React.ReactNode, target: IStage | IGroup, callback?: (() => void) | null) => {\n const container = (reconcilor as any).createContainer(target as any, 1, false, null);\n reconcilor.updateContainer(component, container, null, callback);\n};\n"]}
package/es/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './host-elements';
2
+ export * from './Stage';
3
+ export * from './hostConfig';
package/es/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./host-elements";
2
+
3
+ export * from "./Stage";
4
+
5
+ export * from "./hostConfig";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC","file":"index.js","sourcesContent":["export * from './host-elements';\nexport * from './Stage';\nexport * from './hostConfig';\n"]}
@@ -0,0 +1,54 @@
1
+ import type { VRenderEvents, Instance, Props } from './types';
2
+ export declare const REACT_TO_CANOPUS_EVENTS: {
3
+ onPointerDown: string;
4
+ onPointerUp: string;
5
+ onPointerUpOutside: string;
6
+ onPointerTap: string;
7
+ onPointerOver: string;
8
+ onPointerMove: string;
9
+ onPointerEnter: string;
10
+ onPointerLeave: string;
11
+ onPointerOut: string;
12
+ onMouseDown: string;
13
+ onMouseUp: string;
14
+ onMouseUpOutside: string;
15
+ onMouseMove: string;
16
+ onMouseOver: string;
17
+ onMouseOut: string;
18
+ onMouseEnter: string;
19
+ onMouseLeave: string;
20
+ onPinch: string;
21
+ onPinchStart: string;
22
+ onPinchEnd: string;
23
+ onPan: string;
24
+ onPanStart: string;
25
+ onPanEnd: string;
26
+ onDrag: string;
27
+ onDragStart: string;
28
+ onDragEnter: string;
29
+ onDragLeave: string;
30
+ onDragOver: string;
31
+ onDragEnd: string;
32
+ onRightDown: string;
33
+ onRightUp: string;
34
+ onRightUpOutside: string;
35
+ onTouchStart: string;
36
+ onTouchEnd: string;
37
+ onTouchEndOutside: string;
38
+ onTouchMove: string;
39
+ onTouchCancel: string;
40
+ onPress: string;
41
+ onPressUp: string;
42
+ onPressEnd: string;
43
+ onSwipe: string;
44
+ onDrop: string;
45
+ onWeel: string;
46
+ onClick: string;
47
+ onDblClick: string;
48
+ };
49
+ export declare const splitProps: (props: Props) => {
50
+ graphicProps: Partial<Props>;
51
+ eventProps: VRenderEvents;
52
+ };
53
+ export declare const bindGraphicEvent: (eventProps: VRenderEvents, instance: Instance) => void;
54
+ export declare const updateProps: (instance: Instance, newProps: Props, oldProps?: Props) => void;
@@ -0,0 +1,74 @@
1
+ export const REACT_TO_CANOPUS_EVENTS = {
2
+ onPointerDown: "pointerdown",
3
+ onPointerUp: "pointerup",
4
+ onPointerUpOutside: "pointerupoutside",
5
+ onPointerTap: "pointertap",
6
+ onPointerOver: "pointerover",
7
+ onPointerMove: "pointermove",
8
+ onPointerEnter: "pointerenter",
9
+ onPointerLeave: "pointerleave",
10
+ onPointerOut: "pointerout",
11
+ onMouseDown: "mousedown",
12
+ onMouseUp: "mouseup",
13
+ onMouseUpOutside: "mouseupoutside",
14
+ onMouseMove: "mousemove",
15
+ onMouseOver: "mouseover",
16
+ onMouseOut: "mouseout",
17
+ onMouseEnter: "mouseenter",
18
+ onMouseLeave: "mouseleave",
19
+ onPinch: "pinch",
20
+ onPinchStart: "pinchstart",
21
+ onPinchEnd: "pinchend",
22
+ onPan: "pan",
23
+ onPanStart: "panstart",
24
+ onPanEnd: "panend",
25
+ onDrag: "drag",
26
+ onDragStart: "dragstart",
27
+ onDragEnter: "dragenter",
28
+ onDragLeave: "dragleave",
29
+ onDragOver: "dragover",
30
+ onDragEnd: "dragend",
31
+ onRightDown: "rightdown",
32
+ onRightUp: "rightup",
33
+ onRightUpOutside: "rightupoutside",
34
+ onTouchStart: "touchstart",
35
+ onTouchEnd: "touchend",
36
+ onTouchEndOutside: "touchendoutside",
37
+ onTouchMove: "touchmove",
38
+ onTouchCancel: "touchcancel",
39
+ onPress: "press",
40
+ onPressUp: "pressup",
41
+ onPressEnd: "pressend",
42
+ onSwipe: "swipe",
43
+ onDrop: "drop",
44
+ onWeel: "wheel",
45
+ onClick: "click",
46
+ onDblClick: "dblclick"
47
+ };
48
+
49
+ const isEvent = key => !!REACT_TO_CANOPUS_EVENTS[key];
50
+
51
+ export const splitProps = props => {
52
+ const eventProps = {}, graphicProps = {};
53
+ return Object.keys(props).forEach((key => {
54
+ REACT_TO_CANOPUS_EVENTS[key] ? eventProps[key] = props[key] : graphicProps[key] = props[key];
55
+ })), {
56
+ graphicProps: graphicProps,
57
+ eventProps: eventProps
58
+ };
59
+ };
60
+
61
+ export const bindGraphicEvent = (eventProps, instance) => {
62
+ Object.keys(eventProps).forEach((propKey => {
63
+ "function" == typeof eventProps[propKey] && instance.addEventListener(REACT_TO_CANOPUS_EVENTS[propKey], eventProps[propKey]);
64
+ }));
65
+ };
66
+
67
+ export const updateProps = (instance, newProps, oldProps) => {
68
+ Object.keys(oldProps).forEach((key => {
69
+ oldProps && oldProps[key] !== newProps[key] && (isEvent(key) ? instance.removeEventListener(REACT_TO_CANOPUS_EVENTS[key], oldProps[key]) : instance.setAttribute(key, void 0));
70
+ })), Object.keys(newProps).forEach((key => {
71
+ oldProps[key] !== newProps[key] && (isEvent(key) ? "function" == typeof newProps[key] && instance.addEventListener(REACT_TO_CANOPUS_EVENTS[key], newProps[key]) : instance.setAttribute(key, newProps[key]));
72
+ }));
73
+ };
74
+ //# sourceMappingURL=processProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/processProps.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,aAAa,EAAE,aAAa;IAC5B,WAAW,EAAE,WAAW;IACxB,kBAAkB,EAAE,kBAAkB;IACtC,YAAY,EAAE,YAAY;IAC1B,aAAa,EAAE,aAAa;IAC5B,aAAa,EAAE,aAAa;IAC5B,cAAc,EAAE,cAAc;IAC9B,cAAc,EAAE,cAAc;IAC9B,YAAY,EAAE,YAAY;IAC1B,WAAW,EAAE,WAAW;IACxB,SAAS,EAAE,SAAS;IACpB,gBAAgB,EAAE,gBAAgB;IAClC,WAAW,EAAE,WAAW;IACxB,WAAW,EAAE,WAAW;IACxB,UAAU,EAAE,UAAU;IACtB,YAAY,EAAE,YAAY;IAC1B,YAAY,EAAE,YAAY;IAC1B,OAAO,EAAE,OAAO;I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UAAU,EAAE;oBACvC,QAAQ,CAAC,gBAAgB,CAAC,uBAAuB,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;iBACxE;aACF;iBAAM;gBACJ,QAAgB,CAAC,YAAY,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;aACpD;SACF;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","file":"processProps.js","sourcesContent":["import type { VRenderEvents, Instance, Props } from './types';\n\nexport const REACT_TO_CANOPUS_EVENTS = {\n onPointerDown: 'pointerdown',\n onPointerUp: 'pointerup',\n onPointerUpOutside: 'pointerupoutside',\n onPointerTap: 'pointertap',\n onPointerOver: 'pointerover',\n onPointerMove: 'pointermove',\n onPointerEnter: 'pointerenter',\n onPointerLeave: 'pointerleave',\n onPointerOut: 'pointerout',\n onMouseDown: 'mousedown',\n onMouseUp: 'mouseup',\n onMouseUpOutside: 'mouseupoutside',\n onMouseMove: 'mousemove',\n onMouseOver: 'mouseover',\n onMouseOut: 'mouseout',\n onMouseEnter: 'mouseenter',\n onMouseLeave: 'mouseleave',\n onPinch: 'pinch',\n onPinchStart: 'pinchstart',\n onPinchEnd: 'pinchend',\n onPan: 'pan',\n onPanStart: 'panstart',\n onPanEnd: 'panend',\n onDrag: 'drag',\n onDragStart: 'dragstart',\n onDragEnter: 'dragenter',\n onDragLeave: 'dragleave',\n onDragOver: 'dragover',\n onDragEnd: 'dragend',\n onRightDown: 'rightdown',\n onRightUp: 'rightup',\n onRightUpOutside: 'rightupoutside',\n onTouchStart: 'touchstart',\n onTouchEnd: 'touchend',\n onTouchEndOutside: 'touchendoutside',\n onTouchMove: 'touchmove',\n onTouchCancel: 'touchcancel',\n onPress: 'press',\n onPressUp: 'pressup',\n onPressEnd: 'pressend',\n onSwipe: 'swipe',\n onDrop: 'drop',\n onWeel: 'wheel',\n onClick: 'click',\n onDblClick: 'dblclick'\n};\n\nconst isEvent = (key: string) => !!REACT_TO_CANOPUS_EVENTS[key];\n\nexport const splitProps = (props: Props) => {\n const eventProps: VRenderEvents = {};\n const graphicProps: Partial<Props> = {};\n\n Object.keys(props).forEach(key => {\n if (REACT_TO_CANOPUS_EVENTS[key]) {\n eventProps[key] = props[key];\n } else {\n graphicProps[key] = props[key];\n }\n });\n\n return { graphicProps, eventProps };\n};\n\nexport const bindGraphicEvent = (eventProps: VRenderEvents, instance: Instance) => {\n Object.keys(eventProps).forEach(propKey => {\n if (typeof eventProps[propKey] === 'function') {\n instance.addEventListener(REACT_TO_CANOPUS_EVENTS[propKey], eventProps[propKey]);\n }\n });\n};\n\nexport const updateProps = (instance: Instance, newProps: Props, oldProps?: Props) => {\n Object.keys(oldProps).forEach(key => {\n const propChanged = oldProps && oldProps[key] !== newProps[key];\n if (propChanged) {\n if (isEvent(key)) {\n instance.removeEventListener(REACT_TO_CANOPUS_EVENTS[key], oldProps[key]);\n } else {\n (instance as any).setAttribute(key, undefined);\n }\n }\n });\n\n Object.keys(newProps).forEach(key => {\n const propChanged = oldProps[key] !== newProps[key];\n\n if (propChanged) {\n if (isEvent(key)) {\n if (typeof newProps[key] === 'function') {\n instance.addEventListener(REACT_TO_CANOPUS_EVENTS[key], newProps[key]);\n }\n } else {\n (instance as any).setAttribute(key, newProps[key]);\n }\n }\n });\n};\n"]}
package/es/types.d.ts ADDED
@@ -0,0 +1,62 @@
1
+ import type { IGraphic, IGraphicAttribute, IStage, FederatedEvent, GraphicType, IGroup, ILayer, IGlyph } from '@visactor/vrender';
2
+ export type Type = GraphicType | 'layer';
3
+ export interface Props extends IGraphicAttribute, VRenderEvents {
4
+ }
5
+ export type Container = IStage | ILayer | IGroup;
6
+ export type Instance = IGraphic | IGroup | ILayer | IGlyph | IStage;
7
+ export type TextInstance = IGraphic;
8
+ export type SuspenseInstance = any;
9
+ export type HydratableInstance = any;
10
+ export type PublicInstance = any;
11
+ export type HostContext = any;
12
+ export type UpdatePayload = any;
13
+ export type ChildSet = any;
14
+ export type TimeoutHandle = any;
15
+ export type NoTimeout = any;
16
+ export interface VRenderEvents {
17
+ onPointerDown?: (evt: FederatedEvent) => void;
18
+ onPointerUp?: (evt: FederatedEvent) => void;
19
+ onPointerUpOutside?: (evt: FederatedEvent) => void;
20
+ onPointerTap?: (evt: FederatedEvent) => void;
21
+ onPointerOver?: (evt: FederatedEvent) => void;
22
+ onPointerMove?: (evt: FederatedEvent) => void;
23
+ onPointerEnter?: (evt: FederatedEvent) => void;
24
+ onPointerLeave?: (evt: FederatedEvent) => void;
25
+ onPointerOut?: (evt: FederatedEvent) => void;
26
+ onMouseDown?: (evt: FederatedEvent) => void;
27
+ onMouseUp?: (evt: FederatedEvent) => void;
28
+ onMouseUpOutside?: (evt: FederatedEvent) => void;
29
+ onMouseMove?: (evt: FederatedEvent) => void;
30
+ onMouseOver?: (evt: FederatedEvent) => void;
31
+ onMouseOut?: (evt: FederatedEvent) => void;
32
+ onMouseEnter?: (evt: FederatedEvent) => void;
33
+ onMouseLeave?: (evt: FederatedEvent) => void;
34
+ onPinch?: (evt: FederatedEvent) => void;
35
+ onPinchStart?: (evt: FederatedEvent) => void;
36
+ onPinchEnd?: (evt: FederatedEvent) => void;
37
+ onPan?: (evt: FederatedEvent) => void;
38
+ onPanStart?: (evt: FederatedEvent) => void;
39
+ onPanEnd?: (evt: FederatedEvent) => void;
40
+ onDrag?: (evt: FederatedEvent) => void;
41
+ onDragStart?: (evt: FederatedEvent) => void;
42
+ onDragEnter?: (evt: FederatedEvent) => void;
43
+ onDragLeave?: (evt: FederatedEvent) => void;
44
+ onDragOver?: (evt: FederatedEvent) => void;
45
+ onDragEnd?: (evt: FederatedEvent) => void;
46
+ onRightDown?: (evt: FederatedEvent) => void;
47
+ onRightUp?: (evt: FederatedEvent) => void;
48
+ onRightUpOutside?: (evt: FederatedEvent) => void;
49
+ onTouchStart?: (evt: FederatedEvent) => void;
50
+ onTouchEnd?: (evt: FederatedEvent) => void;
51
+ onTouchEndOutside?: (evt: FederatedEvent) => void;
52
+ onTouchMove?: (evt: FederatedEvent) => void;
53
+ onTouchCancel?: (evt: FederatedEvent) => void;
54
+ onPress?: (evt: FederatedEvent) => void;
55
+ onPressUp?: (evt: FederatedEvent) => void;
56
+ onPressEnd?: (evt: FederatedEvent) => void;
57
+ onSwipe?: (evt: FederatedEvent) => void;
58
+ onDrop?: (evt: FederatedEvent) => void;
59
+ onWeel?: (evt: FederatedEvent) => void;
60
+ onClick?: (evt: FederatedEvent) => void;
61
+ onDblClick?: (evt: FederatedEvent) => void;
62
+ }
package/es/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export { };
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"names":[],"mappings":"","file":"types.js","sourcesContent":["import type {\n IGraphic,\n IGraphicAttribute,\n IStage,\n FederatedEvent,\n GraphicType,\n IGroup,\n ILayer,\n IGlyph\n} from '@visactor/vrender';\n\n/**\n * host config type\n */\nexport type Type = GraphicType | 'layer';\nexport interface Props extends IGraphicAttribute, VRenderEvents {\n // empty\n}\nexport type Container = IStage | ILayer | IGroup;\nexport type Instance = IGraphic | IGroup | ILayer | IGlyph | IStage;\nexport type TextInstance = IGraphic;\nexport type SuspenseInstance = any;\nexport type HydratableInstance = any;\nexport type PublicInstance = any;\nexport type HostContext = any;\nexport type UpdatePayload = any;\nexport type ChildSet = any;\nexport type TimeoutHandle = any;\nexport type NoTimeout = any;\n\n/**\n * event\n */\nexport interface VRenderEvents {\n onPointerDown?: (evt: FederatedEvent) => void;\n onPointerUp?: (evt: FederatedEvent) => void;\n onPointerUpOutside?: (evt: FederatedEvent) => void;\n onPointerTap?: (evt: FederatedEvent) => void;\n onPointerOver?: (evt: FederatedEvent) => void;\n onPointerMove?: (evt: FederatedEvent) => void;\n onPointerEnter?: (evt: FederatedEvent) => void;\n onPointerLeave?: (evt: FederatedEvent) => void;\n onPointerOut?: (evt: FederatedEvent) => void;\n onMouseDown?: (evt: FederatedEvent) => void;\n onMouseUp?: (evt: FederatedEvent) => void;\n onMouseUpOutside?: (evt: FederatedEvent) => void;\n onMouseMove?: (evt: FederatedEvent) => void;\n onMouseOver?: (evt: FederatedEvent) => void;\n onMouseOut?: (evt: FederatedEvent) => void;\n onMouseEnter?: (evt: FederatedEvent) => void;\n onMouseLeave?: (evt: FederatedEvent) => void;\n onPinch?: (evt: FederatedEvent) => void;\n onPinchStart?: (evt: FederatedEvent) => void;\n onPinchEnd?: (evt: FederatedEvent) => void;\n onPan?: (evt: FederatedEvent) => void;\n onPanStart?: (evt: FederatedEvent) => void;\n onPanEnd?: (evt: FederatedEvent) => void;\n onDrag?: (evt: FederatedEvent) => void;\n onDragStart?: (evt: FederatedEvent) => void;\n onDragEnter?: (evt: FederatedEvent) => void;\n onDragLeave?: (evt: FederatedEvent) => void;\n onDragOver?: (evt: FederatedEvent) => void;\n onDragEnd?: (evt: FederatedEvent) => void;\n onRightDown?: (evt: FederatedEvent) => void;\n onRightUp?: (evt: FederatedEvent) => void;\n onRightUpOutside?: (evt: FederatedEvent) => void;\n onTouchStart?: (evt: FederatedEvent) => void;\n onTouchEnd?: (evt: FederatedEvent) => void;\n onTouchEndOutside?: (evt: FederatedEvent) => void;\n onTouchMove?: (evt: FederatedEvent) => void;\n onTouchCancel?: (evt: FederatedEvent) => void;\n onPress?: (evt: FederatedEvent) => void;\n onPressUp?: (evt: FederatedEvent) => void;\n onPressEnd?: (evt: FederatedEvent) => void;\n onSwipe?: (evt: FederatedEvent) => void;\n onDrop?: (evt: FederatedEvent) => void;\n onWeel?: (evt: FederatedEvent) => void;\n onClick?: (evt: FederatedEvent) => void;\n onDblClick?: (evt: FederatedEvent) => void;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const log: (...args: any[]) => void;
2
+ export declare const error: ((errorMsg: string) => never) | (() => void);