-
Notifications
You must be signed in to change notification settings - Fork 18
/
deserialize-embedded-layer.ts
86 lines (78 loc) · 2.88 KB
/
deserialize-embedded-layer.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
/*
* Copyright (C) 2019 Toshiba Corporation
* SPDX-License-Identifier: Apache-2.0
*/
import { DDiagramSerializedLayer } from "../../d-diagram-serialized";
import { isString } from "../../util/is-string";
import { EShapeActionValueGesture } from "../action/e-shape-action-value-gesture";
import { EShapeActionValueGestureOperationType } from "../action/e-shape-action-value-gesture-operation-type";
import { EShapeActionValueGestureType } from "../action/e-shape-action-value-gesture-type";
import { EShapeLayerState } from "../e-shape-layer-state";
import { EShapeResourceManagerDeserialization } from "../e-shape-resource-manager-deserialization";
import { EShapeResourceManagerDeserializationMode } from "../e-shape-resource-manager-deserialization-mode";
import { EShapeEmbeddedLayer } from "./e-shape-embedded-layer";
const deserializeEmbeddedLayerName = (
target: string | number,
manager: EShapeResourceManagerDeserialization
): string => {
if (isString(target)) {
return target;
} else {
const resources = manager.resources;
if (0 <= target && target <= resources.length) {
return resources[target];
}
return "";
}
};
export const deserializeEmbeddedLayer = (
serialized: DDiagramSerializedLayer,
manager: EShapeResourceManagerDeserialization,
width: number,
height: number,
creator?: (name: string, manager: EShapeResourceManagerDeserialization) => EShapeEmbeddedLayer
): EShapeEmbeddedLayer => {
const name = deserializeEmbeddedLayerName(serialized[0], manager);
const result = creator
? creator(name, manager)
: new EShapeEmbeddedLayer(name, manager.mode, manager.depth);
const visibility = serialized[1];
const visible = visibility == null || !!(visibility & 0x2);
if (!visible) {
result.visible = false;
result.state.add(EShapeLayerState.INVISIBLE);
}
const positionX = -0.5 * width + (serialized[2] || 0);
const positionY = -0.5 * height + (serialized[3] || 0);
result.transform.position.set(positionX, positionY);
const sizeX = serialized[4] ?? width;
const sizeY = serialized[5] ?? height;
result.size.set(sizeX, sizeY);
result.size.init();
const fillId = serialized[6];
if (fillId != null) {
result.fill.deserialize(fillId, manager);
}
if (manager.mode === EShapeResourceManagerDeserializationMode.VIEWER) {
const state = serialized[7] ?? 1;
const isInteractive = state & 0x1;
const isDraggable = state & 0x2;
const isPinchable = state & 0x4;
if (isDraggable || isPinchable) {
const gestureType =
(isDraggable
? EShapeActionValueGestureOperationType.DRAG
: EShapeActionValueGestureOperationType.NONE) |
(isPinchable
? EShapeActionValueGestureOperationType.PINCH
: EShapeActionValueGestureOperationType.NONE);
result.action.add(
new EShapeActionValueGesture("", EShapeActionValueGestureType.LAYER, gestureType)
);
}
if (isInteractive || isDraggable || isPinchable) {
result.interactive = true;
}
}
return result;
};