├── .gitignore ├── screenshot.png ├── src ├── fonts │ ├── montserrat │ │ ├── Montserrat-Bold.otf │ │ ├── Montserrat-Black.otf │ │ ├── Montserrat-Light.otf │ │ ├── Montserrat-Regular.otf │ │ ├── Montserrat-Hairline.otf │ │ └── SIL Open Font License.txt │ └── dancing-script-ot │ │ ├── DancingScript-Regular.otf │ │ └── SIL Open Font License.txt ├── mode │ └── vfl │ │ ├── vfl.css │ │ └── vfl.js ├── index.html ├── views │ ├── InputView.js │ ├── EditorView.js │ ├── SettingsView.js │ ├── OutputView.js │ └── VisualOutputView.js ├── styles.css ├── vflToLayout.js └── main.js ├── dist ├── fonts │ ├── montserrat │ │ ├── Montserrat-Light.otf │ │ └── Montserrat-Hairline.otf │ └── dancing-script-ot │ │ └── DancingScript-Regular.otf └── index.html ├── .eslintrc ├── .editorconfig ├── .jscsrc ├── LICENSE ├── package.json ├── Gruntfile.js ├── webpack.config.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | bower_components 3 | npm-debug.log 4 | .ftppass 5 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IjzerenHein/visualformat-editor/HEAD/screenshot.png -------------------------------------------------------------------------------- /src/fonts/montserrat/Montserrat-Bold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IjzerenHein/visualformat-editor/HEAD/src/fonts/montserrat/Montserrat-Bold.otf -------------------------------------------------------------------------------- /dist/fonts/montserrat/Montserrat-Light.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IjzerenHein/visualformat-editor/HEAD/dist/fonts/montserrat/Montserrat-Light.otf -------------------------------------------------------------------------------- /src/fonts/montserrat/Montserrat-Black.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IjzerenHein/visualformat-editor/HEAD/src/fonts/montserrat/Montserrat-Black.otf -------------------------------------------------------------------------------- /src/fonts/montserrat/Montserrat-Light.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IjzerenHein/visualformat-editor/HEAD/src/fonts/montserrat/Montserrat-Light.otf -------------------------------------------------------------------------------- /src/fonts/montserrat/Montserrat-Regular.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IjzerenHein/visualformat-editor/HEAD/src/fonts/montserrat/Montserrat-Regular.otf -------------------------------------------------------------------------------- /dist/fonts/montserrat/Montserrat-Hairline.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IjzerenHein/visualformat-editor/HEAD/dist/fonts/montserrat/Montserrat-Hairline.otf -------------------------------------------------------------------------------- /src/fonts/montserrat/Montserrat-Hairline.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IjzerenHein/visualformat-editor/HEAD/src/fonts/montserrat/Montserrat-Hairline.otf -------------------------------------------------------------------------------- /src/fonts/dancing-script-ot/DancingScript-Regular.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IjzerenHein/visualformat-editor/HEAD/src/fonts/dancing-script-ot/DancingScript-Regular.otf -------------------------------------------------------------------------------- /dist/fonts/dancing-script-ot/DancingScript-Regular.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IjzerenHein/visualformat-editor/HEAD/dist/fonts/dancing-script-ot/DancingScript-Regular.otf -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "node": true, 5 | "amd": true 6 | }, 7 | "ecmaFeatures": { 8 | "classes": true, 9 | "modules": true, 10 | "blockBindings": true, 11 | "arrowFunctions": true, 12 | "templateStrings": true 13 | }, 14 | "rules": { 15 | "quotes": [2, "single"], 16 | "no-underscore-dangle": false 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/mode/vfl/vfl.css: -------------------------------------------------------------------------------- 1 | .cm-s-vfl span.cm-def {color: #D8D8D8;} 2 | .cm-s-vfl span.cm-atom {color: #62a35c;} 3 | .cm-s-vfl span.cm-meta {color: #a71d5d;} 4 | .cm-s-vfl span.cm-number {color: #0086b3;} 5 | .cm-s-vfl span.cm-bracket {color: #193691;} 6 | .cm-s-vfl span.cm-keyword {color: #193691; font-weight: bold;} 7 | .cm-s-vfl span.cm-variable {color: #f09e53;} 8 | .cm-s-vfl span.cm-operator {color: #795da3;} 9 | .cm-s-vfl span.cm-comment {color: #999999;} 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig: http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | indent_style = space 7 | indent_size = 4 8 | end_of_line = lf 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | 16 | [*.js] 17 | indent_style = space 18 | indent_size = 4 19 | 20 | [Gruntfile.js] 21 | indent_style = space 22 | indent_size = 2 23 | 24 | [grunt/*.js] 25 | indent_style = space 26 | indent_size = 2 27 | 28 | [*.json] 29 | indent_style = space 30 | indent_size = 2 31 | 32 | [*.css] 33 | indent_style = space 34 | indent_size = 2 35 | -------------------------------------------------------------------------------- /dist/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |' + JSON.stringify(constraints, undefined, 2) + ''); 76 | // update raw 77 | const raw = AutoLayout.VisualFormat.parse(visualFormat, {extended: extended, outFormat: 'raw'}); 78 | this.raw.setContent('
' + JSON.stringify(raw, undefined, 2) + ''); 79 | // update log 80 | this._log('
Visual format parsed successfully.' +
91 | 'ERROR: ' +
92 | '' + err.source.substring(0, err.column - 1) + '' +
93 | err.source.substring(err.column - 1) + '\n' +
94 | 'line ' + err.line + arrow + (new Array(2 + err.column - arrow.length - ('' + err.line).length)).join(' ') + '^ ' + err.message +
95 | ''
96 | );
97 | }
98 | else {
99 | this._log('ERROR: ' + err.toString() + ''); 100 | } 101 | } 102 | } 103 | } 104 | 105 | export {OutputView as default}; 106 | -------------------------------------------------------------------------------- /src/fonts/dancing-script-ot/SIL Open Font License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010, Pablo Impallari (www.impallari.com|impallari@gmail.com), 2 | Copyright (c) 2010, Igino Marini. (www.ikern.com|mail@iginomarini.com), 3 | with Reserved Font Name Dancing Script. 4 | 5 | This Font Software is licensed under the SIL Open Font License, Version 1.1. 6 | This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL 7 | 8 | ----------------------------------------------------------- 9 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 10 | ----------------------------------------------------------- 11 | 12 | PREAMBLE 13 | The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others. 14 | 15 | The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives. 16 | 17 | DEFINITIONS 18 | "Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation. 19 | 20 | "Reserved Font Name" refers to any names specified as such after the copyright statement(s). 21 | 22 | "Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s). 23 | 24 | "Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment. 25 | 26 | "Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software. 27 | 28 | PERMISSION & CONDITIONS 29 | Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions: 30 | 31 | 1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself. 32 | 33 | 2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user. 34 | 35 | 3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users. 36 | 37 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission. 38 | 39 | 5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software. 40 | 41 | TERMINATION 42 | This license becomes null and void if any of the above conditions are not met. 43 | 44 | DISCLAIMER 45 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE. -------------------------------------------------------------------------------- /src/fonts/montserrat/SIL Open Font License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2012, Julieta Ulanovsky (julieta.ulanovsky@gmail.com), with Reserved Font Names 'Montserrat' 2 | This Font Software is licensed under the SIL Open Font License, Version 1.1. 3 | This license is copied below, and is also available with a FAQ at: 4 | http://scripts.sil.org/OFL 5 | 6 | This Font Software is licensed under the SIL Open Font License, Version 1.1. 7 | This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL 8 | 9 | ----------------------------------------------------------- 10 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 11 | ----------------------------------------------------------- 12 | 13 | PREAMBLE 14 | The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others. 15 | 16 | The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives. 17 | 18 | DEFINITIONS 19 | "Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation. 20 | 21 | "Reserved Font Name" refers to any names specified as such after the copyright statement(s). 22 | 23 | "Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s). 24 | 25 | "Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment. 26 | 27 | "Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software. 28 | 29 | PERMISSION & CONDITIONS 30 | Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions: 31 | 32 | 1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself. 33 | 34 | 2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user. 35 | 36 | 3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users. 37 | 38 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission. 39 | 40 | 5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software. 41 | 42 | TERMINATION 43 | This license becomes null and void if any of the above conditions are not met. 44 | 45 | DISCLAIMER 46 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE. -------------------------------------------------------------------------------- /src/vflToLayout.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This Source Code is licensed under the MIT license. If a copy of the 3 | * MIT-license was not distributed with this file, You can obtain one at: 4 | * http://opensource.org/licenses/mit-license.html. 5 | * 6 | * @author: Hein Rutjes (IjzerenHein) 7 | * @license MIT 8 | * @copyright Gloey Apps, 2015 9 | */ 10 | 11 | // import dependencies 12 | var AutoLayout = require('autolayout'); 13 | 14 | function _setSpacing(view, spacing) { 15 | view.setSpacing(spacing); 16 | } 17 | 18 | function _setIntrinsicWidths(context, view, widths) { 19 | for (var key in widths) { 20 | var subView = view.subViews[key]; 21 | if (subView) { 22 | subView.intrinsicWidth = (widths[key] === true) ? context.resolveSize(key, context.size)[0] : widths[key]; 23 | } 24 | } 25 | } 26 | 27 | function _setIntrinsicHeights(context, view, heights) { 28 | for (var key in heights) { 29 | var subView = view.subViews[key]; 30 | if (subView) { 31 | subView.intrinsicHeight = (heights[key] === true) ? context.resolveSize(key, context.size)[1] : heights[key]; 32 | } 33 | } 34 | } 35 | 36 | function _setViewPortSize(context, view, vp) { 37 | var size = [ 38 | ((vp.width !== undefined) && (vp.width !== true)) ? vp.width : Math.max(Math.min(context.size[0], vp['max-width'] || context.size[0]), vp['min-width'] || 0), 39 | ((vp.height !== undefined) && (vp.height !== true)) ? vp.height : Math.max(Math.min(context.size[1], vp['max-height'] || context.size[1]), vp['min-height'] || 0) 40 | ]; 41 | if ((vp.width === true) && (vp.height === true)) { 42 | size[0] = view.fittingWidth; 43 | size[1] = view.fittingHeight; 44 | } 45 | else if (vp.width === true) { 46 | view.setSize(undefined, size[1]); 47 | size[0] = view.fittingWidth; 48 | // TODO ASPECT RATIO? 49 | } 50 | else if (vp.height === true) { 51 | view.setSize(size[0], undefined); 52 | size[1] = view.fittingHeight; 53 | // TODO ASPECT RATIO? 54 | } 55 | else { 56 | size = vp['aspect-ratio'] ? [ 57 | Math.min(size[0], size[1] * vp['aspect-ratio']), 58 | Math.min(size[1], size[0] / vp['aspect-ratio']) 59 | ] : size; 60 | view.setSize(size[0], size[1]); 61 | } 62 | return size; 63 | } 64 | 65 | function vflToLayout(visualFormat, viewOptions) { 66 | var view = new AutoLayout.View(viewOptions); 67 | try { 68 | var constraints = AutoLayout.VisualFormat.parse(visualFormat, {extended: true, strict: false}); 69 | var metaInfo = AutoLayout.VisualFormat.parseMetaInfo ? AutoLayout.VisualFormat.parseMetaInfo(visualFormat) : {}; 70 | view.addConstraints(constraints); 71 | var dummyOptions = {}; 72 | return function(context, options) { 73 | options = options || dummyOptions; 74 | var key; 75 | var subView; 76 | var x; 77 | var y; 78 | var zIndex = options.zIndex || 0; 79 | if (options.spacing || metaInfo.spacing) { 80 | _setSpacing(view, options.spacing || metaInfo.spacing); 81 | } 82 | if (options.widths || metaInfo.widths) { 83 | _setIntrinsicWidths(context, view, options.widths || metaInfo.widths); 84 | } 85 | if (options.heights || metaInfo.heights) { 86 | _setIntrinsicHeights(context, view, options.heights || metaInfo.heights); 87 | } 88 | if (options.viewport || metaInfo.viewport) { 89 | var size = _setViewPortSize(context, view, options.viewport || metaInfo.viewport); 90 | x = (context.size[0] - size[0]) / 2; 91 | y = (context.size[1] - size[1]) / 2; 92 | } 93 | else { 94 | view.setSize(context.size[0], context.size[1]); 95 | x = 0; 96 | y = 0; 97 | } 98 | for (key in view.subViews) { 99 | subView = view.subViews[key]; 100 | if ((key.indexOf('_') !== 0) && (subView.type !== 'stack')) { 101 | context.set(subView.name, { 102 | size: [subView.width, subView.height], 103 | translate: [x + subView.left, y + subView.top, zIndex + (subView.zIndex * 5)] 104 | }); 105 | } 106 | } 107 | }; 108 | } 109 | catch (err) { 110 | console.log(err); //eslint-disable-line no-console 111 | } 112 | } 113 | 114 | module.exports = vflToLayout; 115 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This Source Code is licensed under the MIT license. If a copy of the 3 | * MIT-license was not distributed with this file, You can obtain one at: 4 | * http://opensource.org/licenses/mit-license.html. 5 | * 6 | * @author: Hein Rutjes (IjzerenHein) 7 | * @license MIT 8 | * @copyright Gloey Apps, 2015 9 | */ 10 | 11 | //
' : ''),
87 | size: [undefined, 124]
88 | });
89 | mainLC.insert('banner', banner);
90 |
91 | // Create input view
92 | var inputView = new InputView();
93 | mainLC.insert('input', inputView);
94 | inputView.editor.on('update', _update); //eslint-disable-line no-use-before-define
95 | inputView.settings.on('update', _updateSettings); //eslint-disable-line no-use-before-define
96 |
97 | // Create output view
98 | var outputView = new OutputView();
99 | mainLC.insert('output', outputView);
100 |
101 | // Create visualoutput view
102 | var visualOutputView = new VisualOutputView();
103 | mainLC.insert('visualOutput', visualOutputView);
104 |
105 | // Update handling
106 | function _update() {
107 | var constraints = outputView.parse(inputView.editor.visualFormat, inputView.settings.getExtended());
108 | if (constraints) {
109 | var view = new AutoLayout.View();
110 | view.addConstraints(constraints);
111 | visualOutputView.view = view;
112 | }
113 | _updateSettings(); //eslint-disable-line no-use-before-define
114 | _updateMetaInfo(); //eslint-disable-line no-use-before-define
115 | }
116 | function _updateMetaInfo() {
117 | var metaInfo = AutoLayout.VisualFormat.parseMetaInfo(inputView.editor.visualFormat, {prefix: '-'});
118 | visualOutputView.viewPort = metaInfo.viewport;
119 | visualOutputView.spacing = metaInfo.spacing;
120 | visualOutputView.colors = metaInfo.colors;
121 | visualOutputView.shapes = metaInfo.shapes;
122 | visualOutputView.widths = metaInfo.widths;
123 | visualOutputView.heights = metaInfo.heights;
124 | }
125 | function _updateSettings(forceParse) {
126 | if (forceParse) {
127 | return _update.call(this);
128 | }
129 | var view = visualOutputView.view;
130 | if (view) {
131 | inputView.settings.updateAutoLayoutView(view);
132 | visualOutputView.view = view;
133 | }
134 | }
135 | _update();
136 |
--------------------------------------------------------------------------------
/src/views/VisualOutputView.js:
--------------------------------------------------------------------------------
1 | import View from 'famous/core/View';
2 | import Surface from 'famous/core/Surface';
3 | import LayoutController from 'famous-flex/LayoutController';
4 | import Colors from 'colors.js';
5 |
6 | class VisualOutputView extends View {
7 | constructor(options) {
8 | super(options);
9 |
10 | this._spacing = undefined;
11 | this._viewPort = {};
12 | this._colors = {};
13 | this._shapes = {};
14 | this._intrinsicWidths = {};
15 | this._intrinsicHeight = {};
16 |
17 | this.layout = new LayoutController({
18 | flow: true,
19 | flowOptions: {
20 | reflowOnResize: false
21 | },
22 | layout: (context) => {
23 | if (!this.alView) {
24 | return;
25 | }
26 | if (this._spacing) {
27 | this.alView.setSpacing(this._spacing);
28 | }
29 | const iw = this._widths;
30 | var key;
31 | for (key in iw) {
32 | const subView = this.alView.subViews[key];
33 | if (subView) {
34 | subView.intrinsicWidth = iw[key];
35 | }
36 | }
37 | const ih = this._heights;
38 | for (key in ih) {
39 | const subView = this.alView.subViews[key];
40 | if (subView) {
41 | subView.intrinsicHeight = ih[key];
42 | }
43 | }
44 | const vp = this._viewPort;
45 | var contentSize = [
46 | ((vp.width !== undefined) && (vp.width !== true)) ? vp.width : Math.max(Math.min(context.size[0], vp['max-width'] || context.size[0]), vp['min-width'] || 0),
47 | ((vp.height !== undefined) && (vp.height !== true)) ? vp.height : Math.max(Math.min(context.size[1], vp['max-height'] || context.size[1]), vp['min-height'] || 0)
48 | ];
49 | if ((vp.width === true) && (vp.height === true)) {
50 | contentSize[0] = this.alView.fittingWidth;
51 | contentSize[1] = this.alView.fittingHeight;
52 | }
53 | else if (vp.width === true) {
54 | this.alView.setSize(undefined, contentSize[1]);
55 | contentSize[0] = this.alView.fittingWidth;
56 | // TODO ASPECT RATIO?
57 | }
58 | else if (vp.height === true) {
59 | this.alView.setSize(contentSize[0], undefined);
60 | contentSize[1] = this.alView.fittingHeight;
61 | // TODO ASPECT RATIO?
62 | }
63 | else {
64 | contentSize = vp['aspect-ratio'] ? [
65 | Math.min(contentSize[0], contentSize[1] * vp['aspect-ratio']),
66 | Math.min(contentSize[1], contentSize[0] / vp['aspect-ratio'])
67 | ] : contentSize;
68 | this.alView.setSize(contentSize[0], contentSize[1]);
69 | }
70 | var left = (context.size[0] - contentSize[0]) / 2;
71 | var top = (context.size[1] - contentSize[1]) / 2;
72 | for (key in this.alView.subViews) {
73 | const subView = this.alView.subViews[key];
74 | if ((subView.type !== 'stack') && (key.indexOf('_') !== 0)) {
75 | const node = context.get(subView.name);
76 | context.set(node, {
77 | size: [subView.width, subView.height],
78 | translate: [left + subView.left, top + subView.top, subView.zIndex * 5]
79 | });
80 | var color = 204 - (subView.zIndex * 20);
81 | var backgroundColor = this._colors[key] || Colors.rgb2hex(color, color, color);
82 | var textColor = Colors.complement(backgroundColor);
83 | node.renderNode.setProperties({
84 | backgroundColor: backgroundColor,
85 | color: textColor
86 | });
87 | }
88 | }
89 | }
90 | });
91 | this.add(this.layout);
92 | };
93 |
94 | set view(alView) {
95 | this.alView = alView;
96 | this.contentRenderables = this.contentRenderables || {};
97 | this.contentPool = this.contentPool || {};
98 | for (var key in this.contentRenderables) {
99 | this.contentPool[key] = this.contentRenderables[key];
100 | }
101 | this.contentRenderables = {};
102 | if (this.alView) {
103 | for (var subView in this.alView.subViews) {
104 | if (subView.indexOf('_') !== 0) {
105 | this.contentRenderables[subView] = this.contentPool[subView] || new Surface({
106 | content: '