Added utils for check types of draw objects
This commit is contained in:
parent
4965f1715a
commit
e055142988
5 changed files with 28 additions and 11 deletions
|
|
@ -37,3 +37,5 @@ export interface IRadialGradient {
|
||||||
export interface IConicGradient {
|
export interface IConicGradient {
|
||||||
type: "conic";
|
type: "conic";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type Fill = ISolidFill | ITextureFill | ILinerGradient | IRadialGradient | IConicGradient;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { IPoint } from "@gxc-solutions/math";
|
import { IPoint } from "@gxc-solutions/math";
|
||||||
import { IRgbColor } from "./color";
|
import { IRgbColor } from "./color";
|
||||||
import { IBaseFill } from "./fill";
|
import { Fill } from "./fill";
|
||||||
|
|
||||||
export interface IRectangle {
|
export interface IRectangle {
|
||||||
x: number;
|
x: number;
|
||||||
|
|
@ -34,7 +34,7 @@ export interface IStroke {
|
||||||
dash: number[];
|
dash: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DrawObjectType = "rectangle" | "ellipse" | "image" | "text" | "path" | "line" | "group";
|
export type DrawObjectType = "rectangle" | "ellipse" | "image" | "text" | "path" | "line" | "node";
|
||||||
|
|
||||||
export interface IBaseDrawObject {
|
export interface IBaseDrawObject {
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
|
|
@ -44,7 +44,7 @@ export interface IBaseDrawObject {
|
||||||
|
|
||||||
export interface IRectangleDrawObject extends IBaseDrawObject {
|
export interface IRectangleDrawObject extends IBaseDrawObject {
|
||||||
readonly type: "rectangle";
|
readonly type: "rectangle";
|
||||||
fill: IBaseFill;
|
fill: Fill;
|
||||||
stroke: IStroke;
|
stroke: IStroke;
|
||||||
blendMode: string;
|
blendMode: string;
|
||||||
opacity: number;
|
opacity: number;
|
||||||
|
|
@ -52,9 +52,9 @@ export interface IRectangleDrawObject extends IBaseDrawObject {
|
||||||
transform: ITransform;
|
transform: ITransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IEllipseDrawObject {
|
export interface IEllipseDrawObject extends IBaseDrawObject {
|
||||||
readonly type: "ellipse";
|
readonly type: "ellipse";
|
||||||
fill: IBaseFill;
|
fill: Fill;
|
||||||
stroke: IStroke;
|
stroke: IStroke;
|
||||||
ellipse: IEllipse;
|
ellipse: IEllipse;
|
||||||
blendMode: string;
|
blendMode: string;
|
||||||
|
|
@ -62,11 +62,11 @@ export interface IEllipseDrawObject {
|
||||||
transform: ITransform;
|
transform: ITransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IImageDrawObject {
|
export interface IImageDrawObject extends IBaseDrawObject {
|
||||||
readonly type: "image";
|
readonly type: "image";
|
||||||
source: HTMLImageElement;
|
source: HTMLImageElement;
|
||||||
stroke: IStroke;
|
stroke: IStroke;
|
||||||
fill: IBaseFill;
|
fill: Fill;
|
||||||
blendMode: string;
|
blendMode: string;
|
||||||
opacity: number;
|
opacity: number;
|
||||||
transform: ITransform;
|
transform: ITransform;
|
||||||
|
|
@ -78,10 +78,10 @@ export interface IFont {
|
||||||
color: IRgbColor;
|
color: IRgbColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ITextDrawObject {
|
export interface ITextDrawObject extends IBaseDrawObject {
|
||||||
readonly type: "text";
|
readonly type: "text";
|
||||||
stroke: IStroke;
|
stroke: IStroke;
|
||||||
fill: IBaseFill;
|
fill: Fill;
|
||||||
blendMode: string;
|
blendMode: string;
|
||||||
rectangle?: IRectangle;
|
rectangle?: IRectangle;
|
||||||
text: string;
|
text: string;
|
||||||
|
|
@ -94,7 +94,7 @@ export interface ITextDrawObject {
|
||||||
export type DrawLeafs = IRectangleDrawObject | IEllipseDrawObject | IImageDrawObject | ITextDrawObject;
|
export type DrawLeafs = IRectangleDrawObject | IEllipseDrawObject | IImageDrawObject | ITextDrawObject;
|
||||||
|
|
||||||
export interface IDrawNode extends IBaseDrawObject {
|
export interface IDrawNode extends IBaseDrawObject {
|
||||||
readonly type: "group";
|
readonly type: "node";
|
||||||
children: Array<IDrawNode | DrawLeafs>;
|
children: Array<IDrawNode | DrawLeafs>;
|
||||||
transform: ITransform;
|
transform: ITransform;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@gxc-solutions/renderer-base",
|
"name": "@gxc-solutions/renderer-base",
|
||||||
"version": "0.0.5",
|
"version": "0.0.6",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"author": "GXC Solutions",
|
"author": "GXC Solutions",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
|
|
|
||||||
14
lib/src/utils/draw-object.ts
Normal file
14
lib/src/utils/draw-object.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import {
|
||||||
|
IRectangleDrawObject,
|
||||||
|
IEllipseDrawObject,
|
||||||
|
IImageDrawObject,
|
||||||
|
ITextDrawObject,
|
||||||
|
IDrawNode,
|
||||||
|
IBaseDrawObject,
|
||||||
|
} from "../interfaces/objects";
|
||||||
|
|
||||||
|
export const isEllipseDrawObject = (drawObject: IBaseDrawObject): drawObject is IEllipseDrawObject => drawObject?.type === "ellipse";
|
||||||
|
export const isRectangleDrawObject = (drawObject: IBaseDrawObject): drawObject is IRectangleDrawObject => drawObject?.type === "rectangle";
|
||||||
|
export const isImageDrawObject = (drawObject: IBaseDrawObject): drawObject is IImageDrawObject => drawObject?.type === "image";
|
||||||
|
export const isTextDrawObject = (drawObject: IBaseDrawObject): drawObject is ITextDrawObject => drawObject?.type === "text";
|
||||||
|
export const isDrawNode = (drawObject: IBaseDrawObject): drawObject is IDrawNode => drawObject?.type === "node";
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
export * from "./fill";
|
export * from "./fill";
|
||||||
|
export * from "./draw-object";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue