-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
general.blend.ts
110 lines (95 loc) 路 3.29 KB
/
general.blend.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { convertFigmaRemoteEffectsToFigma } from "../converters/effect.convert";
import { convertFigmaRemoteFillsToFigma } from "../converters/fills.convert";
import { convertFigmaRemoteLayoutConstraintsToFigmaConstraints } from "../converters/layout-constraints.convert";
import { convertFigmaRemoteStrokesToFigma } from "../converters/strokes.convert";
import { MappingBlendInput } from "./_in";
import { Transform } from "@design-sdk/figma-remote-types";
type Transform2DMatrix = [[number, number, number], [number, number, number]];
export function blendBaseNode(p: MappingBlendInput) {
const { target, source } = p;
// @ts-ignore
target.id = source.id;
// @ts-ignore
target.parentId = p.parent?.id ?? null;
target.name = source.name;
target.visible = source.visible ?? true;
target.opacity = source.opacity ?? 1;
target.layoutAlign = source.layoutAlign;
target.layoutGrow = source.layoutGrow ?? 0;
target.exportSettings = source.exportSettings;
target.blendMode = source.blendMode ?? "NORMAL";
target.isMask = source.isMask ?? false;
if (target.type !== "GROUP") {
target.strokes = convertFigmaRemoteStrokesToFigma(...source.strokes);
target.strokeWeight = source.strokeWeight;
target.strokeAlign = source.strokeAlign;
target.fills = convertFigmaRemoteFillsToFigma(...source.fills);
target.constraints = convertFigmaRemoteLayoutConstraintsToFigmaConstraints(
source.constraints
);
}
target.effects = convertFigmaRemoteEffectsToFigma(...source.effects);
target.relativeTransform = source.relativeTransform as Transform2DMatrix;
target.x = source.relativeTransform?.[0]?.[2];
target.y = source.relativeTransform?.[1]?.[2];
// @ts-ignore
target.width = source.size?.x;
// @ts-ignore
target.height = source.size?.y;
// static override --------------------
target.effectStyleId = undefined;
// target.removed = false;
// target.parent = undefined;
target.locked = false;
target.constrainProportions = undefined;
if (target.type !== "GROUP") {
target.strokeStyleId = undefined;
target.fillStyleId = undefined;
target.strokeMiterLimit = undefined;
target.strokeCap = undefined;
target.dashPattern = undefined;
target.strokeJoin = undefined;
}
// -------------------------------------
// reaction are not supported via remote api - https://github.com/gridaco/designto-code/issues/157
// target.reactions;
target.rotation = angleFromTransform(source.relativeTransform); // calculate with transform: ;
// @ts-ignore
target.absoluteTransform = [
// TODO: support rotation
[1, 0, source.absoluteBoundingBox.x],
[0, 1, source.absoluteBoundingBox.y],
]; // calculate with transform
}
/**
* @deprecated
*/
function xy_as_relative(
parent: { x: number; y: number },
child: { x: number; y: number },
isRoot = false
) {
if (isRoot) {
return {
x: child.x,
y: child.y,
};
}
return {
x: child?.x - parent?.x ?? 0,
y: child?.y - parent?.y ?? 0,
};
}
function angleFromTransform(transform?: Readonly<Transform>): number {
if (!transform) {
return 0;
}
try {
const [a, b, c] = transform[0];
const [d, e, f] = transform[1];
var angle = Math.round(Math.atan2(b, a) * (180 / Math.PI));
return angle < 0 ? angle + 360 : angle;
} catch (e) {
return 0;
}
}