123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import { InteractiveMessage } from "../../hook/use-interactive.ts";
- import { Pos } from "@/utils/math.ts";
- import { themeMouseColors } from "@/constant/help-style.ts";
- import { BaseItem, generateSnapInfos, getBaseItem } from "../util.ts";
- import { getMouseColors } from "@/utils/colors.ts";
- export { default as Component } from "./triangle.vue";
- export { default as TempComponent } from "./temp-triangle.vue";
- export const shapeName = "三角形";
- export const defaultStyle = {
- stroke: themeMouseColors.theme,
- strokeWidth: 5,
- fill: "#fff",
- };
- export const addMode = "area";
- export const getMouseStyle = (data: TriangleData) => {
- const fillStatus = getMouseColors(data.fill || defaultStyle.fill);
- const strokeStatus = getMouseColors(data.stroke || defaultStyle.stroke);
- const strokeWidth = data.strokeWidth || defaultStyle.strokeWidth;
- return {
- default: { fill: fillStatus.pub, stroke: strokeStatus.pub, strokeWidth },
- hover: { fill: fillStatus.hover },
- press: { fill: fillStatus.press },
- };
- };
- export type TriangleData = Partial<typeof defaultStyle> &
- BaseItem & { points: Pos[]; attitude: number[] };
- export const getSnapInfos = (data: TriangleData) => generateSnapInfos(data.points, true, false)
- export const interactiveToData = (
- info: InteractiveMessage,
- preset: Partial<TriangleData> = {}
- ): TriangleData | undefined => {
- if (info.area) {
- const item = {
- ...getBaseItem(),
- ...preset,
- points: [],
- } as unknown as TriangleData;
- return interactiveFixData(item, info);
- }
- };
- export const interactiveFixData = (
- data: TriangleData,
- info: InteractiveMessage
- ) => {
- const area = info.area!;
- data.points[0] = {
- x: area[0].x - (area[1].x - area[0].x),
- y: area[1].y,
- };
- data.points[1] = area[0];
- data.points[2] = area[1];
- return data;
- };
|