-
Notifications
You must be signed in to change notification settings - Fork 1
/
DocPageContainerView.ts
69 lines (59 loc) · 2.44 KB
/
DocPageContainerView.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
import { Page, Container, AnyContainer, Pipeline, Shape, AnyShape, AnyShapeOrCollection,
ShapeCollection, isAnyShapeCollection, Alignment, ZoomRelativeTo, ContainerContent} from './internal'
import { checkInput } from './internal';
export class View extends Container
{
_shapes:ShapeCollection|string; // either a real reference to a ShapeCollection or the name of it that is suppose to be available after running the Doc pipeline
_style:any; // general style (TODO)
_styles:{[key:string]:any}; // style overrides (TODO)
_dimension:any; // TODO
constructor(name:string)
{
super(name);
this._type = 'view';
}
//// OUTPUT ////
toData():any // TODO
{
return {
...this._toContainerData(),
content: {
main: (ShapeCollection.isShapeCollection(this._shapes)) ?
(this._shapes as ShapeCollection)?.toSvg() :
this.resolveShapeNameToSVG(this._shapes as string),
settings: {}
} as ContainerContent,
}
}
resolveShapeNameToSVG(shapes:string):string
{
if(typeof shapes !== 'string')
{
throw new Error(`View::resolveShapeNameToSVG(): Given shapes "${shapes}" is not a string!`)
}
const workerScope = this._page._doc._ay.worker.self;
const realShapes = workerScope[shapes];
if(!Shape.isShape(realShapes) && !ShapeCollection.isShapeCollection(realShapes))
{
throw new Error(`View::resolveShapeNameToSVG(): Given shapes "{shapes}" does not refer to a valid Shape or ShapeCollection!`)
}
const s = new ShapeCollection(realShapes); // make sure we got a ShapeCollection
return s.toSvg();
}
/** Bind ShapeCollection to View */
shapes(shapes:AnyShapeOrCollection|string)
{
// a reference to a ShapeCollection from main script
if (ShapeCollection.isShapeCollection(shapes) || Shape.isShape(shapes))
{
this._shapes = new ShapeCollection(shapes) as ShapeCollection; // auto converted
}
else if(typeof shapes === 'string')
{
this._shapes = shapes as string;
}
else {
throw new Error('DocPageContainer:shapes(): Please supply either a reference to ShapeCollection or the name of one that will be available after running the pipeline!');
}
}
}