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 {
|
||||
type: "conic";
|
||||
}
|
||||
|
||||
export type Fill = ISolidFill | ITextureFill | ILinerGradient | IRadialGradient | IConicGradient;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { IPoint } from "@gxc-solutions/math";
|
||||
import { IRgbColor } from "./color";
|
||||
import { IBaseFill } from "./fill";
|
||||
import { Fill } from "./fill";
|
||||
|
||||
export interface IRectangle {
|
||||
x: number;
|
||||
|
|
@ -34,7 +34,7 @@ export interface IStroke {
|
|||
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 {
|
||||
readonly id: string;
|
||||
|
|
@ -44,7 +44,7 @@ export interface IBaseDrawObject {
|
|||
|
||||
export interface IRectangleDrawObject extends IBaseDrawObject {
|
||||
readonly type: "rectangle";
|
||||
fill: IBaseFill;
|
||||
fill: Fill;
|
||||
stroke: IStroke;
|
||||
blendMode: string;
|
||||
opacity: number;
|
||||
|
|
@ -52,9 +52,9 @@ export interface IRectangleDrawObject extends IBaseDrawObject {
|
|||
transform: ITransform;
|
||||
}
|
||||
|
||||
export interface IEllipseDrawObject {
|
||||
export interface IEllipseDrawObject extends IBaseDrawObject {
|
||||
readonly type: "ellipse";
|
||||
fill: IBaseFill;
|
||||
fill: Fill;
|
||||
stroke: IStroke;
|
||||
ellipse: IEllipse;
|
||||
blendMode: string;
|
||||
|
|
@ -62,11 +62,11 @@ export interface IEllipseDrawObject {
|
|||
transform: ITransform;
|
||||
}
|
||||
|
||||
export interface IImageDrawObject {
|
||||
export interface IImageDrawObject extends IBaseDrawObject {
|
||||
readonly type: "image";
|
||||
source: HTMLImageElement;
|
||||
stroke: IStroke;
|
||||
fill: IBaseFill;
|
||||
fill: Fill;
|
||||
blendMode: string;
|
||||
opacity: number;
|
||||
transform: ITransform;
|
||||
|
|
@ -78,10 +78,10 @@ export interface IFont {
|
|||
color: IRgbColor;
|
||||
}
|
||||
|
||||
export interface ITextDrawObject {
|
||||
export interface ITextDrawObject extends IBaseDrawObject {
|
||||
readonly type: "text";
|
||||
stroke: IStroke;
|
||||
fill: IBaseFill;
|
||||
fill: Fill;
|
||||
blendMode: string;
|
||||
rectangle?: IRectangle;
|
||||
text: string;
|
||||
|
|
@ -94,7 +94,7 @@ export interface ITextDrawObject {
|
|||
export type DrawLeafs = IRectangleDrawObject | IEllipseDrawObject | IImageDrawObject | ITextDrawObject;
|
||||
|
||||
export interface IDrawNode extends IBaseDrawObject {
|
||||
readonly type: "group";
|
||||
readonly type: "node";
|
||||
children: Array<IDrawNode | DrawLeafs>;
|
||||
transform: ITransform;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@gxc-solutions/renderer-base",
|
||||
"version": "0.0.5",
|
||||
"version": "0.0.6",
|
||||
"main": "index.js",
|
||||
"author": "GXC Solutions",
|
||||
"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 "./draw-object";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue