├── .gitignore
├── LICENSE
├── README.md
├── VERSIONS.md
├── bower.json
├── build
├── react-autolayout.js
└── react-autolayout.map
├── index.js
├── package.json
├── styles.css
└── webpack.config.js
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | *.log
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014-2015 Entrendipity Pty Ltd
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | React-Autolayout
2 | =====
3 |
4 | Auto layout for React using Apple's Visual Format Language. React-Autolayout is a wrapper around the [AutoLayout.js](http://ijzerenhein.github.io/autolayout.js/) library.
5 |
6 | NPM:
7 | `npm install react-autolayout`
8 |
9 | Bower:
10 | `bower install react-autolayout`
11 |
12 | Script Tag:
13 | ``
14 | (Module exposed as `ReactAutoLayout`)
15 |
16 | ## API
17 |
18 | ### Sample Usage
19 |
20 | ```js
21 | class Demo extends React.Component {
22 |
23 | query(constraints) {
24 | if('demo' in constraints){
25 | if(constraints.demo.page.width < 600){
26 | return 'narrow';
27 | } else {
28 | return 'default';
29 | }
30 | }
31 | return 'default';
32 | }
33 |
34 | render() {
35 | return (
36 |
51 |
52 | ...
53 |
54 |
55 | );
56 | }
57 | }
58 | ```
59 |
60 | ### <AutoLayout /> props
61 |
62 | #### `name: string`
63 | The `name` prop defines a region that will have auto layout applied and is used to identify the region. It is **required and must be unique**.
64 |
65 | #### `layout: array[object]`
66 | `layout` holds an array of layout configuration objects. The different configurations get applied in response to `query` changes (see next). Each configuration object **must** have the following 3 properties:
67 |
68 | - `name: string` is used to identify the configuration.
69 | - `constrainTo: string | array` specifies which view the layout region should be contrained to. There are three possible values:
70 | - `'viewport'` contrain to the window
71 | - `'${name}.${viewKey}'` constrain to another view
72 | - `[width, height]` constrain to a fixed width and height in `px`. Width and height are specified as a **number** without the `px` suffix
73 | - `format: array[string]` takes an array of string specified by the Visual Format Language. Please refer to [AutoLayout.js](http://ijzerenhein.github.io/autolayout.js/) documentation for usage.
74 |
75 | #### `query: function -> string`
76 |
77 | ```js
78 | query(constraints, currentFormat){
79 | if('demo' in constraints){
80 | if(constraints.demo.page.width < 600){
81 | return 'narrow';
82 | } else {
83 | return 'default';
84 | }
85 | }
86 | return 'default';
87 | }
88 | ```
89 |
90 | The `query` prop takes a function that returns a string representing the name of the layout to be applied. It can be thought of as a custom media query in which you specify the break points based on the criteria you determine.
91 |
92 | The query function will receive two parameters.
93 |
94 | The first is `constraints`. `constraints` holds the current state of all autolayout objects. You are able to reference view width and height to determine break points. The shape of `constraints` is ${name}.${viewKey}.width|height
95 |
96 | The second is `currentFormat`. This is a string that stores the format currently applied to the region.
97 |
98 | #### `htmlTag: string`
99 |
100 | This is an optional prop that allows you to specify the type of html element to use for the region.
101 |
102 |
103 | ### child element props
104 |
105 | ```js
106 |
107 |
108 | ...
109 |
110 |
111 | ...
112 |
113 |
114 | ...
115 |
116 |
117 | ```
118 | Child elements define the view to be laid out. You can have as many child views as required. Child elements cannot be React Components and must be the first level element within AutoLayout. A view has the following props:
119 |
120 | - `viewKey: string` The `viewKey` is used within the Visual Format to identify the view. `viewKey`'s must be unique within a Component and is a required prop.
121 | - `formatStyle: object` is an optional prop that specifies styles to be applied to certain layouts. You do not need to specify every layout, only the ones that you would like a style aplied to. The format style is then merge with any existing styles set on the view.
122 |
123 | An example of a `formatStyle` prop within a view is:
124 |
125 | ```js
126 |
136 | ```
137 |
138 | ## Caveats
139 |
140 | - Setting the following styles on child elements have no effect as they are overridden. Default values are displayed.
141 | + top: dynamically set
142 | + left: dynamically set
143 | + width: dynamically set
144 | + height: dynamically set
145 | + margin: 0
146 | + padding: 0
147 | + position: absolute
148 | + transform: dynamically set
149 | - box-sizing: border-box; is the default
150 | - Visual Format `Z` property is not available
151 |
152 | ## ToDo
153 |
154 | - More Example Code
155 | - Tests
156 |
157 | ## Author
158 | Frank Panetta - [Follow @fattenap](https://twitter.com/intent/follow?screen_name=fattenap)
159 |
160 | ## License
161 | ### The MIT License (MIT)
162 |
163 | Copyright (c) 2015-2016 Frank Panetta
164 |
165 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
166 |
167 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
168 |
169 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
170 |
--------------------------------------------------------------------------------
/VERSIONS.md:
--------------------------------------------------------------------------------
1 | This library has the following policy about versions.
2 |
3 | - Presently, all planned versions have a major version number of 0.
4 | - The minor version number increases for every backward-incompatible
5 | change to a documented behavior.
6 | - The patch version number increases for every added feature,
7 | backward-incompatible changes to undocumented features, and
8 | bug-fixes.
9 |
10 | Upon the release of a version 1.0.0, the strategy will be revised.
11 |
12 | - The major version will increase for any backward-incompatible
13 | changes.
14 | - The minor version will increase for added features.
15 | - The patch version will increase for bug-fixes.
16 |
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-autolayout",
3 | "version": "0.1.4-alpha3",
4 | "description": "Auto layout for React using Apple's Visual Format Language",
5 | "main": "./build/react-autolayout.js",
6 | "homepage": "https://github.com/fattenap/react-autolayout",
7 | "authors": ["Frank Panetta"],
8 | "repository": {
9 | "type": "git",
10 | "url": "https://github.com/fattenap/react-autolayout.git"
11 | },
12 | "moduleType": [
13 | "amd",
14 | "globals",
15 | "node"
16 | ],
17 | "keywords": [
18 | "react",
19 | "autolayout",
20 | "visual format",
21 | "auto layout"
22 | ],
23 | "license": "MIT",
24 | "ignore": [
25 | "**/.*",
26 | "node_modules",
27 | "bower_components",
28 | "test"
29 | ]
30 | }
31 |
--------------------------------------------------------------------------------
/build/react-autolayout.js:
--------------------------------------------------------------------------------
1 | !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports.ReactAutoLayout=e(require("react")):t.ReactAutoLayout=e(t.React)}(this,function(t){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="build/",e(0)}([function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function a(t,e){if(t)throw new Error("Invariant Violation: "+e)}function o(){var t={};return Array.prototype.slice.call(arguments).forEach(function(e){for(var n in e)"top"!==n&&"left"!==n&&e.hasOwnProperty(n)&&(t[n]=e[n])}),t}function l(t,e){var n={},r=void 0,i=t.layouts[e].constrainTo,s=t.layouts[e].constrainToIsFixed;if(s)t.view.setSize(i[0],i[1]);else if("viewport"!=t.layouts[e].constrainTo[0]&&i[0]in A){var a=i[0],o=i[1],l=A[a][o].style,u=V[a][o].borderWidth,c=V[a][o].borderHeight;"format"in V[a][o]&&e in V[a][o].format&&(u=V[a][o].format[e].borderWidth,c=V[a][o].format[e].borderHeight),t.view.setSize(l.width-u,l.height-c)}else t.view.setSize(window.innerWidth,window.innerHeight);n[t.viewName]={},n[t.viewName].currentFormat=e;for(var h in t.view.subViews)t.view.subViews.hasOwnProperty(h)&&"_"!==h[0]&&(r=t.view.subViews[h],n[t.viewName][h]={style:{width:r.width,height:r.height,transform:"translate3d("+r.left+"px, "+r.top+"px, 0)",position:"absolute",padding:0,margin:0},width:r.width,height:r.height});return n}function u(t,e,n){for(var r=void 0,i=0,s=x.length;s>i;i++)r=x[i].query(A,x[i].currentFormat),x[i].currentFormat!==r&&(x[i].view=new m["default"].View,x[i].view.addConstraints(x[i].layouts[r].constraints)),x[i].currentFormat=r,A=o(A,l(x[i],r));for(var a in _)_.hasOwnProperty(a)&&_[a]()}function c(t,e,n){var r=void 0,i=e||0,s=n||0,a=void 0;return"border"in t?(r=t.border.match(C),i=2*r[0],s=2*r[0]):"borderTop"in t||"borderBottom"in t?(s=0,"borderTop"in t&&(r=t.borderTop.match(C),s+=r[0]),"borderBottom"in t&&(r=t.borderBottom.match(C),s+=r[0])):"borderRight"in t||"borderLeft"in t?(i=0,"borderRight"in t&&(r=t.borderRight.match(C),i+=r[0]),"borderLeft"in t&&(r=t.borderLeft.match(C),i+=r[0])):"borderWidth"in t?(r=t.borderWidth.match(C),a=r.length,1===a&&(i=2*r[0],s=2*r[0]),2===a&&(i=2*r[1],s=2*r[0]),3===a&&(i=2*r[1],s=r[0]*r[2]),4===a&&(i=r[1]*r[4],s=r[0]*r[2])):"borderTopWidth"in t||"borderBottomWidth"in t?(s=0,"borderTopWidth"in t&&(r=t.borderTopWidth.match(C),s+=r[0]),"borderBottomWidth"in t&&(r=t.borderBottomWidth.match(C),s+=r[0])):("borderRightWidth"in t||"borderLeftWidth"in t)&&(i=0,"borderRightWidth"in t&&(r=t.borderRightWidth.match(C),i+=r[0]),"borderLeftWidth"in t&&(r=t.borderLeftWidth.match(C),i+=r[0])),{width:i,height:s}}function h(t,e){var n=t.props.name,r=void 0;a(void 0===n,"name is required!"),a(n in E,n+" name must be unique."),V[n]={};var i=w["default"].Children.toArray(t.props.children);i.forEach(function(t){if(V[n][t.props.viewKey]={},V[n][t.props.viewKey].borderWidth=0,V[n][t.props.viewKey].borderHeight=0,"style"in t.props){var e=c(t.props.style),r=e.width,i=e.height;V[n][t.props.viewKey].borderWidth=r,V[n][t.props.viewKey].borderHeight=i}if("formatStyle"in t.props){V[n][t.props.viewKey].format=V[n][t.props.viewKey].format||{};for(var s in t.props.formatStyle)if(t.props.formatStyle.hasOwnProperty(s)){V[n][t.props.viewKey].format[s]={};var a=c(t.props.formatStyle[s],V[n][t.props.viewKey].borderWidth,V[n][t.props.viewKey].borderHeight),r=a.width,i=a.height;V[n][t.props.viewKey].format[s].borderWidth=r,V[n][t.props.viewKey].format[s].borderHeight=i}}}),_[n]=function(){t.forceUpdate()},E[n]={},E[n].layouts={},E[n].query=e.query,E[n].viewName=n,E[n].view=new m["default"].View,r=e.query(A),E[n].currentFormat=r;for(var s=0,h=e.layouts.length;h>s;s++){var f=e.layouts[s];E[n].layouts[f.name]={},E[n].layouts[f.name].htmlTag=f.htmlTag,"[object Array]"===Object.prototype.toString.call(f.constrainTo)?(E[n].layouts[f.name].constrainToIsFixed=!0,E[n].layouts[f.name].constrainTo=f.constrainTo):(E[n].layouts[f.name].constrainToIsFixed=!1,E[n].layouts[f.name].constrainTo=f.constrainTo.split(".")),E[n].layouts[f.name].constraints=m["default"].VisualFormat.parse(f.format,{extended:!0})}E[n].view.addConstraints(E[n].layouts[r].constraints),A=o(A,l(E[n],r)),x.push(E[n]);for(var s=0,p=x.length;p>s;s++)A=o(A,l(x[s],x[s].currentFormat));u()}function f(t){t in _&&delete _[t],t in A&&delete A[t],t in E&&(E[t].view=null,delete E[t]),t in V&&delete V[t],x=x.filter(function(e){return e.viewName!==t}),u()}function p(t,e){var n=t&&e?e.props.viewKey:void 0;return void 0!==n&&t in A&&n in A[t]?A[t][n].style:void 0}function d(t){return void 0!==t&&null!==t&&t in A?A[t].currentFormat:void 0}Object.defineProperty(e,"__esModule",{value:!0});var v=function(){function t(t,e){for(var n=0;n1&&t.constraints.push({view1:"_~"+t.lineIndex+":1~",attr1:t.horizontal?g.WIDTH:g.HEIGHT,relation:t.relation.relation||b.EQU,view2:n,attr2:t.horizontal?g.WIDTH:g.HEIGHT,priority:t.relation.priority}),t.equalSpacerIndex++,t.relation.view||t.relation.multiplier&&1!==t.relation.multiplier?(t.constraints.push({view1:n,attr1:t.horizontal?g.WIDTH:g.HEIGHT,relation:t.relation.relation||b.EQU,view2:t.relation.view,attr2:t.horizontal?g.WIDTH:g.HEIGHT,priority:t.relation.priority,multiplier:t.relation.multiplier}),t.relation.multiplier=void 0):t.relation.constant&&(t.constraints.push({view1:n,attr1:t.horizontal?g.WIDTH:g.HEIGHT,relation:b.EQU,view2:null,attr2:g.CONST,priority:t.relation.priority,constant:t.relation.constant}),t.relation.constant=void 0);for(var r=0;r=i;i*=2)if(n.orientations&i&&n.stack.orientation!==i&&!(n.stack.processedOrientations&i)){n.stack.processedOrientations=n.stack.processedOrientations|i,r=r||{name:e,type:"stack"};for(var s=0,a=n.stack.subViews.length;a>s;s++)i===_.ZINDEX?t.constraints.push({view1:r,attr1:g.ZINDEX,relation:b.EQU,view2:n.stack.subViews[s],attr2:g.ZINDEX}):(t.constraints.push({view1:r,attr1:i===_.VERTICAL?g.HEIGHT:g.WIDTH,relation:b.EQU,view2:n.stack.subViews[s],attr2:i===_.VERTICAL?g.HEIGHT:g.WIDTH}),t.constraints.push({view1:r,attr1:i===_.VERTICAL?g.TOP:g.LEFT,relation:b.EQU,view2:n.stack.subViews[s],attr2:i===_.VERTICAL?g.TOP:g.LEFT}))}}function o(t,e){if(e===!0&&(e=t.match(/\.\.\d+$/),e&&(t=t.substring(0,t.length-e[0].length),e=parseInt(e[0].substring(2)))),!e)return[t];var n,r=t.match(/\d+$/),i=[];if(r)for(t=t.substring(0,t.length-r[0].length),n=parseInt(r);e>=n;n++)i.push(t+n);else for(i.push(t),n=2;e>=n;n++)i.push(t+n);return i}function l(t,e,n){var r=n?n.view:null,u=[],c=[],h=void 0;r&&(e.push({view:r}),c.push(r));for(var f=0;fn;n++)if(t[n]!==e[n])return!1;return!0}var d=function(){function t(t,e){for(var n=0;ni;i++)s=t.charAt(i),"\n"===s?(e.seenCR||e.line++,e.column=1,e.seenCR=!1):"\r"===s||"\u2028"===s||"\u2029"===s?(e.line++,e.column=1,e.seenCR=!0):(e.column++,e.seenCR=!1)}return kt!==e&&(kt>e&&(kt=0,zt={line:1,column:1,seenCR:!1}),n(zt,kt,e),kt=e),zt}function i(t){Ht>Ot||(Ot>Ht&&(Ht=Ot,Nt=[]),Nt.push(t))}function s(n,i,s){function a(t){var e=1;for(t.sort(function(t,e){return t.descriptione.description?1:0});e1?a.slice(0,-1).join(", ")+" or "+a[t.length-1]:a[0],i=e?'"'+n(e)+'"':"end of input","Expected "+r+" but "+i+" found."}var l=r(s),u=s1?arguments[1]:{},A={},V={visualFormatString:a},C=a,S=A,T=null,I=":",O={type:"literal",value:":",description:'":"'},R=function(t,e,n,r,i){return{orientation:t?t[0]:"horizontal",cascade:(e||[]).concat([n],[].concat.apply([],r),i||[])}},k="H",z={type:"literal",value:"H",description:'"H"'},H="V",N={type:"literal",value:"V",description:'"V"'},j=function(t){return"H"==t?"horizontal":"vertical"},q="|",L={type:"literal",value:"|",description:'"|"'},M=function(){return{view:null}},F="[",P={type:"literal",value:"[",description:'"["'},W="]",D={type:"literal",value:"]",description:'"]"'},U=function(t,e){return _(t,e?{constraints:e}:{})},Z="-",G={type:"literal",value:"-",description:'"-"'},X=function(t){return t},B=function(){return[{relation:"equ",constant:"default",$parserOffset:n()}]},Q="",K=function(){return[{relation:"equ",constant:0,$parserOffset:n()}]},J=function(t){return[{relation:"equ",constant:t,$parserOffset:n()}]},$="(",Y={type:"literal",value:"(",description:'"("'},tt=",",et={type:"literal",value:",",description:'","'},nt=")",rt={type:"literal",value:")",description:'")"'},it=function(t,e){return[t].concat(e.map(function(t){return t[1]}))},st="@",at={type:"literal",value:"@",description:'"@"'},ot=function(t,e,n){return _({relation:"equ"},t||{},e,n?n[1]:{})},lt="==",ut={type:"literal",value:"==",description:'"=="'},ct=function(){return{relation:"equ",$parserOffset:n()}},ht="<=",ft={type:"literal",value:"<=",description:'"<="'},pt=function(){return{relation:"leq",$parserOffset:n()}},dt=">=",vt={type:"literal",value:">=",description:'">="'},gt=function(){return{relation:"geq",$parserOffset:n()}},bt=/^[0-9]/,mt={type:"class",value:"[0-9]",description:"[0-9]"},yt=function(t){return{priority:parseInt(t.join(""),10)}},wt=function(t){return{constant:t}},_t=/^[a-zA-Z_]/,Et={type:"class",value:"[a-zA-Z_]",description:"[a-zA-Z_]"},xt=/^[a-zA-Z0-9_]/,At={type:"class",value:"[a-zA-Z0-9_]",description:"[a-zA-Z0-9_]"},Vt=function(t,e){return{view:t+e}},Ct=".",St={type:"literal",value:".",description:'"."'},Tt=function(t,e){return parseFloat(t.concat(".").concat(e).join(""),10)},It=function(t){return parseInt(t.join(""),10)},Ot=0,Rt=0,kt=0,zt={line:1,column:1,seenCR:!1},Ht=0,Nt=[],jt=0;if("startRule"in x){if(!(x.startRule in V))throw new Error("Can't start parsing from rule \""+x.startRule+'".');C=V[x.startRule]}if(E=C(),E!==A&&Ot===t.length)return E;throw E!==A&&Oti;i++)s=t.charAt(i),"\n"===s?(e.seenCR||e.line++,e.column=1,e.seenCR=!1):"\r"===s||"\u2028"===s||"\u2029"===s?(e.line++,e.column=1,e.seenCR=!0):(e.column++,e.seenCR=!1)}return Ye!==e&&(Ye>e&&(Ye=0,tn={line:1,column:1,seenCR:!1}),n(tn,Ye,e),Ye=e),tn}function i(t){en>Je||(Je>en&&(en=Je,nn=[]),nn.push(t))}function s(n,i,s){function a(t){var e=1;for(t.sort(function(t,e){return t.descriptione.description?1:0});e1?a.slice(0,-1).join(", ")+" or "+a[t.length-1]:a[0],i=e?'"'+n(e)+'"':"end of input","Expected "+r+" but "+i+" found."}var l=r(s),u=sJe?(a=t.charAt(Je),Je++):(a=j,0===rn&&i(at));a!==j;)s.push(a),t.length>Je?(a=t.charAt(Je),Je++):(a=j,0===rn&&i(at));s!==j?(n=[n,r,s],e=n):(Je=e,e=M)}else Je=e,e=M;else Je=e,e=M;return e}function u(){var e,n;return e=Je,124===t.charCodeAt(Je)?(n=ot,Je++):(n=j,0===rn&&i(lt)),n!==j&&($e=e,n=ut()),e=n}function c(){var e,n,r,s,a,o,l;if(e=Je,91===t.charCodeAt(Je)?(n=ct,Je++):(n=j,0===rn&&i(ht)),n!==j)if(r=h(),r!==j){for(s=[],a=Je,44===t.charCodeAt(Je)?(o=ft,Je++):(o=j,0===rn&&i(pt)),o!==j?(l=h(),l!==j?(o=[o,l],a=o):(Je=a,a=M)):(Je=a,a=M);a!==j;)s.push(a),a=Je,44===t.charCodeAt(Je)?(o=ft,Je++):(o=j,0===rn&&i(pt)),o!==j?(l=h(),l!==j?(o=[o,l],a=o):(Je=a,a=M)):(Je=a,a=M);s!==j?(93===t.charCodeAt(Je)?(a=dt,Je++):(a=j,0===rn&&i(vt)),a!==j?($e=e,n=gt(r,s),e=n):(Je=e,e=M)):(Je=e,e=M)}else Je=e,e=M;else Je=e,e=M;return e}function h(){var t,e,n,r;return t=Je,e=I(),e!==j?(n=g(),n===j&&(n=F),n!==j?(r=f(),r===j&&(r=F),r!==j?($e=t,e=bt(e,n,r),t=e):(Je=t,t=M)):(Je=t,t=M)):(Je=t,t=M),t}function f(){var e,n,r,s,a,o;if(e=Je,58===t.charCodeAt(Je)?(n=P,Je++):(n=j,0===rn&&i(W)),n!==j){if(r=[],s=Je,a=p(),a!==j?(o=c(),o!==j?(a=[a,o],s=a):(Je=s,s=M)):(Je=s,s=M),s!==j)for(;s!==j;)r.push(s),s=Je,a=p(),a!==j?(o=c(),o!==j?(a=[a,o],s=a):(Je=s,s=M)):(Je=s,s=M);else r=M;r!==j?(s=p(),s!==j?($e=e,n=mt(r,s),e=n):(Je=e,e=M)):(Je=e,e=M)}else Je=e,e=M;return e}function p(){var e,n,r,s;return e=Je,t.substr(Je,2)===yt?(n=yt,Je+=2):(n=j,0===rn&&i(wt)),n!==j&&($e=e,n=_t()),e=n,e===j&&(e=Je,45===t.charCodeAt(Je)?(n=Et,Je++):(n=j,0===rn&&i(xt)),n!==j?(r=d(),r!==j?(45===t.charCodeAt(Je)?(s=Et,Je++):(s=j,0===rn&&i(xt)),s!==j?($e=e,n=At(r),e=n):(Je=e,e=M)):(Je=e,e=M)):(Je=e,e=M),e===j&&(e=Je,45===t.charCodeAt(Je)?(n=Et,Je++):(n=j,0===rn&&i(xt)),n!==j&&($e=e,n=Vt()),e=n,e===j&&(e=Je,126===t.charCodeAt(Je)?(n=Ct,Je++):(n=j,0===rn&&i(St)),n!==j?(r=m(),r!==j?(126===t.charCodeAt(Je)?(s=Ct,Je++):(s=j,0===rn&&i(St)),s!==j?($e=e,n=At(r),e=n):(Je=e,e=M)):(Je=e,e=M)):(Je=e,e=M),e===j&&(e=Je,126===t.charCodeAt(Je)?(n=Ct,Je++):(n=j,0===rn&&i(St)),n!==j&&($e=e,n=Tt()),e=n,e===j&&(e=Je,n=It,n!==j&&($e=e,n=Ot()),e=n))))),e}function d(){var t;return t=v(),t===j&&(t=g()),t}function v(){var t,e;return t=Je,e=A(),e!==j&&($e=t,e=Rt(e)),t=e,t===j&&(t=Je,e=k(),e!==j&&($e=t,e=kt(e)),t=e),t}function g(){var e,n,r,s,a,o,l;if(e=Je,40===t.charCodeAt(Je)?(n=zt,Je++):(n=j,0===rn&&i(Ht)),n!==j)if(r=b(),r!==j){for(s=[],a=Je,44===t.charCodeAt(Je)?(o=ft,Je++):(o=j,0===rn&&i(pt)),o!==j?(l=b(),l!==j?(o=[o,l],a=o):(Je=a,a=M)):(Je=a,a=M);a!==j;)s.push(a),a=Je,44===t.charCodeAt(Je)?(o=ft,Je++):(o=j,0===rn&&i(pt)),o!==j?(l=b(),l!==j?(o=[o,l],a=o):(Je=a,a=M)):(Je=a,a=M);s!==j?(41===t.charCodeAt(Je)?(a=Nt,Je++):(a=j,0===rn&&i(jt)),a!==j?($e=e,n=qt(r,s),e=n):(Je=e,e=M)):(Je=e,e=M)}else Je=e,e=M;else Je=e,e=M;return e}function b(){var e,n,r,s,a,o;return e=Je,n=w(),n===j&&(n=F),n!==j?(r=_(),r!==j?(s=Je,64===t.charCodeAt(Je)?(a=Lt,Je++):(a=j,0===rn&&i(Mt)),a!==j?(o=E(),o!==j?(a=[a,o],s=a):(Je=s,s=M)):(Je=s,s=M),s===j&&(s=F),s!==j?($e=e,n=Ft(n,r,s),e=n):(Je=e,e=M)):(Je=e,e=M)):(Je=e,e=M),e}function m(){var e,n,r,s,a,o,l;if(e=Je,40===t.charCodeAt(Je)?(n=zt,Je++):(n=j,0===rn&&i(Ht)),n!==j)if(r=y(),r!==j){for(s=[],a=Je,44===t.charCodeAt(Je)?(o=ft,Je++):(o=j,0===rn&&i(pt)),o!==j?(l=y(),l!==j?(o=[o,l],a=o):(Je=a,a=M)):(Je=a,a=M);a!==j;)s.push(a),a=Je,44===t.charCodeAt(Je)?(o=ft,Je++):(o=j,0===rn&&i(pt)),o!==j?(l=y(),l!==j?(o=[o,l],a=o):(Je=a,a=M)):(Je=a,a=M);s!==j?(41===t.charCodeAt(Je)?(a=Nt,Je++):(a=j,0===rn&&i(jt)),a!==j?($e=e,n=qt(r,s),e=n):(Je=e,e=M)):(Je=e,e=M)}else Je=e,e=M;else Je=e,e=M;return e}function y(){var e,n,r,s,a,o;return e=Je,n=w(),n===j&&(n=F),n!==j?(r=_(),r!==j?(s=Je,64===t.charCodeAt(Je)?(a=Lt,Je++):(a=j,0===rn&&i(Mt)),a!==j?(o=E(),o!==j?(a=[a,o],s=a):(Je=s,s=M)):(Je=s,s=M),s===j&&(s=F),s!==j?($e=e,n=Pt(n,r,s),e=n):(Je=e,e=M)):(Je=e,e=M)):(Je=e,e=M),e}function w(){var e,n;return e=Je,t.substr(Je,2)===Wt?(n=Wt,Je+=2):(n=j,0===rn&&i(Dt)),n!==j&&($e=e,n=Ut()),e=n,e===j&&(e=Je,t.substr(Je,2)===Zt?(n=Zt,Je+=2):(n=j,0===rn&&i(Gt)),n!==j&&($e=e,n=Xt()),e=n,e===j&&(e=Je,t.substr(Je,2)===Bt?(n=Bt,Je+=2):(n=j,0===rn&&i(Qt)),n!==j&&($e=e,n=Kt()),e=n)),e}function _(){var t;return t=A(),t===j&&(t=x(),t===j&&(t=V())),t}function E(){var e,n,r;if(e=Je,n=[],Jt.test(t.charAt(Je))?(r=t.charAt(Je),Je++):(r=j,0===rn&&i($t)),r!==j)for(;r!==j;)n.push(r),Jt.test(t.charAt(Je))?(r=t.charAt(Je),Je++):(r=j,0===rn&&i($t));else n=M;return n!==j&&($e=e,n=Yt(n)),e=n}function x(){var t,e;return t=Je,e=k(),e!==j&&($e=t,e=te(e)),t=e}function A(){var e,n,r;return e=Je,n=k(),n!==j?(37===t.charCodeAt(Je)?(r=ee,Je++):(r=j,0===rn&&i(ne)),r!==j?($e=e,n=re(n),e=n):(Je=e,e=M)):(Je=e,e=M),e}function V(){var t,e,n,r,i;return t=Je,e=O(),e!==j?(n=C(),n===j&&(n=F),n!==j?(r=S(),r===j&&(r=F),r!==j?(i=T(),i===j&&(i=F),i!==j?($e=t,e=ie(e,n,r,i),t=e):(Je=t,t=M)):(Je=t,t=M)):(Je=t,t=M)):(Je=t,t=M),t}function C(){var e,n;return e=Je,t.substr(Je,5)===se?(n=se,Je+=5):(n=j,0===rn&&i(ae)),n!==j&&($e=e,n=oe()),e=n,e===j&&(e=Je,t.substr(Je,6)===le?(n=le,Je+=6):(n=j,0===rn&&i(ue)),n!==j&&($e=e,n=ce()),e=n,e===j&&(e=Je,t.substr(Je,4)===he?(n=he,Je+=4):(n=j,0===rn&&i(fe)),n!==j&&($e=e,n=pe()),e=n,e===j&&(e=Je,t.substr(Je,7)===de?(n=de,Je+=7):(n=j,0===rn&&i(ve)),n!==j&&($e=e,n=ge()),e=n,e===j&&(e=Je,t.substr(Je,6)===be?(n=be,Je+=6):(n=j,0===rn&&i(me)),n!==j&&($e=e,n=ye()),e=n,e===j&&(e=Je,t.substr(Je,7)===we?(n=we,Je+=7):(n=j,0===rn&&i(_e)),n!==j&&($e=e,n=Ee()),e=n,e===j&&(e=Je,t.substr(Je,8)===xe?(n=xe,Je+=8):(n=j,0===rn&&i(Ae)),n!==j&&($e=e,n=Ve()),e=n,e===j&&(e=Je,t.substr(Je,8)===Ce?(n=Ce,Je+=8):(n=j,0===rn&&i(Se)),n!==j&&($e=e,n=Te()),e=n))))))),e}function S(){var e,n,r;return e=Je,47===t.charCodeAt(Je)?(n=Ie,Je++):(n=j,0===rn&&i(Oe)),n!==j?(r=k(),r!==j?($e=e,n=Re(r),e=n):(Je=e,e=M)):(Je=e,e=M),e===j&&(e=Je,42===t.charCodeAt(Je)?(n=ke,Je++):(n=j,0===rn&&i(ze)),n!==j?(r=k(),r!==j?($e=e,n=He(r),e=n):(Je=e,e=M)):(Je=e,e=M)),e}function T(){var e,n,r;return e=Je,45===t.charCodeAt(Je)?(n=Et,Je++):(n=j,0===rn&&i(xt)),n!==j?(r=k(),r!==j?($e=e,n=Ne(r),e=n):(Je=e,e=M)):(Je=e,e=M),e===j&&(e=Je,43===t.charCodeAt(Je)?(n=je,Je++):(n=j,0===rn&&i(qe)),n!==j?(r=k(),r!==j?($e=e,n=He(r),e=n):(Je=e,e=M)):(Je=e,e=M)),e}function I(){var e,n,r,s,a;if(e=Je,n=Je,r=[],Le.test(t.charAt(Je))?(s=t.charAt(Je),Je++):(s=j,0===rn&&i(Me)),s!==j)for(;s!==j;)r.push(s),Le.test(t.charAt(Je))?(s=t.charAt(Je),Je++):(s=j,0===rn&&i(Me));else r=M;if(r!==j&&(r=t.substring(n,Je)),n=r,n!==j){for(r=Je,s=[],Fe.test(t.charAt(Je))?(a=t.charAt(Je),Je++):(a=j,0===rn&&i(Pe));a!==j;)s.push(a),Fe.test(t.charAt(Je))?(a=t.charAt(Je),Je++):(a=j,0===rn&&i(Pe));s!==j&&(s=t.substring(r,Je)),r=s,r!==j?(s=R(),s!==j?($e=e,n=We(n,r,s),e=n):(Je=e,e=M)):(Je=e,e=M)}else Je=e,e=M;if(e===j){if(e=Je,n=Je,r=[],Le.test(t.charAt(Je))?(s=t.charAt(Je),Je++):(s=j,0===rn&&i(Me)),s!==j)for(;s!==j;)r.push(s),Le.test(t.charAt(Je))?(s=t.charAt(Je),Je++):(s=j,0===rn&&i(Me));else r=M;if(r!==j&&(r=t.substring(n,Je)),n=r,n!==j){for(r=Je,s=[],Fe.test(t.charAt(Je))?(a=t.charAt(Je),Je++):(a=j,0===rn&&i(Pe));a!==j;)s.push(a),Fe.test(t.charAt(Je))?(a=t.charAt(Je),Je++):(a=j,0===rn&&i(Pe));s!==j&&(s=t.substring(r,Je)),r=s,r!==j?($e=e,n=De(n,r),e=n):(Je=e,e=M)}else Je=e,e=M}return e}function O(){var e,n,r,s,a;if(e=Je,n=Je,r=[],Le.test(t.charAt(Je))?(s=t.charAt(Je),Je++):(s=j,0===rn&&i(Me)),s!==j)for(;s!==j;)r.push(s),Le.test(t.charAt(Je))?(s=t.charAt(Je),Je++):(s=j,0===rn&&i(Me));else r=M;if(r!==j&&(r=t.substring(n,Je)),n=r,n!==j){for(r=Je,s=[],Fe.test(t.charAt(Je))?(a=t.charAt(Je),Je++):(a=j,0===rn&&i(Pe));a!==j;)s.push(a),Fe.test(t.charAt(Je))?(a=t.charAt(Je),Je++):(a=j,0===rn&&i(Pe));s!==j&&(s=t.substring(r,Je)),r=s,r!==j?($e=e,n=De(n,r),e=n):(Je=e,e=M)}else Je=e,e=M;return e}function R(){var e,n,r,s;if(e=Je,t.substr(Je,2)===Ue?(n=Ue,Je+=2):(n=j,0===rn&&i(Ze)),n!==j){if(r=[],Jt.test(t.charAt(Je))?(s=t.charAt(Je),Je++):(s=j,0===rn&&i($t)),s!==j)for(;s!==j;)r.push(s),Jt.test(t.charAt(Je))?(s=t.charAt(Je),Je++):(s=j,0===rn&&i($t));else r=M;r!==j?($e=e,n=Ge(r),e=n):(Je=e,e=M)}else Je=e,e=M;return e}function k(){var e,n,r,s,a;if(e=Je,n=[],Jt.test(t.charAt(Je))?(r=t.charAt(Je),Je++):(r=j,0===rn&&i($t)),r!==j)for(;r!==j;)n.push(r),Jt.test(t.charAt(Je))?(r=t.charAt(Je),Je++):(r=j,0===rn&&i($t));else n=M;if(n!==j)if(46===t.charCodeAt(Je)?(r=Xe,Je++):(r=j,0===rn&&i(Be)),r!==j){if(s=[],Jt.test(t.charAt(Je))?(a=t.charAt(Je),Je++):(a=j,0===rn&&i($t)),a!==j)for(;a!==j;)s.push(a),Jt.test(t.charAt(Je))?(a=t.charAt(Je),Je++):(a=j,0===rn&&i($t));else s=M;s!==j?($e=e,n=Qe(n,s),e=n):(Je=e,e=M)}else Je=e,e=M;else Je=e,e=M;if(e===j){if(e=Je,n=[],Jt.test(t.charAt(Je))?(r=t.charAt(Je),Je++):(r=j,0===rn&&i($t)),r!==j)for(;r!==j;)n.push(r),Jt.test(t.charAt(Je))?(r=t.charAt(Je),Je++):(r=j,0===rn&&i($t));else n=M;n!==j&&($e=e,n=Ke(n)),e=n}return e}function z(t){for(var e=1;e1?arguments[1]:{},j={},q={visualFormatString:a},L=a,M=j,F=null,P=":",W={type:"literal",value:":",description:'":"'},D=function(t,e,n,r,i,s){return{orientation:t?t[0]:"horizontal",cascade:(e||[]).concat(n,[].concat.apply([],r),i||[])}},U="HV",Z={type:"literal",value:"HV",description:'"HV"'},G=function(){return"horzvert"},X="H",B={type:"literal",value:"H",description:'"H"'},Q=function(){return"horizontal"},K="V",J={type:"literal",value:"V",description:'"V"'},$=function(){return"vertical"},Y="Z",tt={type:"literal",value:"Z",description:'"Z"'},et=function(){return"zIndex"},nt=" ",rt={type:"literal",value:" ",description:'" "'},it="//",st={type:"literal",value:"//",description:'"//"'},at={type:"any",description:"any character"},ot="|",lt={type:"literal",value:"|",description:'"|"'},ut=function(){return{view:null}},ct="[",ht={type:"literal",value:"[",description:'"["'},ft=",",pt={type:"literal",value:",",description:'","'},dt="]",vt={type:"literal",value:"]",description:'"]"'},gt=function(t,e){return e.length?[t].concat([].concat.apply([],e)):t},bt=function(t,e,n){return z(z(t,e?{constraints:e}:{}),n?{cascade:n}:{})},mt=function(t,e){return[].concat([].concat.apply([],t),[e])},yt="->",wt={type:"literal",value:"->",description:'"->"'},_t=function(){return[{relation:"none"}]},Et="-",xt={type:"literal",value:"-",description:'"-"'},At=function(t){return t},Vt=function(){return[{relation:"equ",constant:"default"}]},Ct="~",St={type:"literal",value:"~",description:'"~"'},Tt=function(){return[{relation:"equ",equalSpacing:!0}]},It="",Ot=function(){return[{relation:"equ",constant:0}]},Rt=function(t){return[{relation:"equ",multiplier:t.multiplier}]},kt=function(t){return[{relation:"equ",constant:t}]},zt="(",Ht={type:"literal",value:"(",description:'"("'},Nt=")",jt={type:"literal",value:")",description:'")"'},qt=function(t,e){return[t].concat(e.map(function(t){return t[1]}))},Lt="@",Mt={type:"literal",value:"@",description:'"@"'},Ft=function(t,e,n){return z({relation:"equ"},t||{},e,n?n[1]:{})},Pt=function(t,e,n){return z({relation:"equ",equalSpacing:!0},t||{},e,n?n[1]:{})},Wt="==",Dt={type:"literal",value:"==",description:'"=="'},Ut=function(){return{relation:"equ"}},Zt="<=",Gt={type:"literal",value:"<=",description:'"<="'},Xt=function(){return{relation:"leq"}},Bt=">=",Qt={type:"literal",value:">=",description:'">="'},Kt=function(){return{relation:"geq"}},Jt=/^[0-9]/,$t={type:"class",value:"[0-9]",description:"[0-9]"},Yt=function(t){return{priority:parseInt(t.join(""),10)}},te=function(t){return{constant:t}},ee="%",ne={type:"literal",value:"%",description:'"%"'},re=function(t){return{view:null,multiplier:t/100}},ie=function(t,e,n,r){return{view:t.view,attribute:e?e:void 0,multiplier:n?n:1,constant:r?r:void 0}},se=".left",ae={type:"literal",value:".left",description:'".left"'},oe=function(){return"left"},le=".right",ue={type:"literal",value:".right",description:'".right"'},ce=function(){return"right"},he=".top",fe={type:"literal",value:".top",description:'".top"'},pe=function(){return"top"},de=".bottom",ve={type:"literal",value:".bottom",description:'".bottom"'},ge=function(){return"bottom"},be=".width",me={type:"literal",value:".width",description:'".width"'},ye=function(){return"width"},we=".height",_e={type:"literal",value:".height",description:'".height"'},Ee=function(){return"height"},xe=".centerX",Ae={type:"literal",
14 | value:".centerX",description:'".centerX"'},Ve=function(){return"centerX"},Ce=".centerY",Se={type:"literal",value:".centerY",description:'".centerY"'},Te=function(){return"centerY"},Ie="/",Oe={type:"literal",value:"/",description:'"/"'},Re=function(t){return 1/t},ke="*",ze={type:"literal",value:"*",description:'"*"'},He=function(t){return t},Ne=function(t){return-t},je="+",qe={type:"literal",value:"+",description:'"+"'},Le=/^[a-zA-Z_]/,Me={type:"class",value:"[a-zA-Z_]",description:"[a-zA-Z_]"},Fe=/^[a-zA-Z0-9_]/,Pe={type:"class",value:"[a-zA-Z0-9_]",description:"[a-zA-Z0-9_]"},We=function(t,e,r){return{view:t+e,range:r,$parserOffset:n()}},De=function(t,e){return{view:t+e,$parserOffset:n()}},Ue="..",Ze={type:"literal",value:"..",description:'".."'},Ge=function(t){return parseInt(t)},Xe=".",Be={type:"literal",value:".",description:'"."'},Qe=function(t,e){return parseFloat(t.concat(".").concat(e).join(""),10)},Ke=function(t){return parseInt(t.join(""),10)},Je=0,$e=0,Ye=0,tn={line:1,column:1,seenCR:!1},en=0,nn=[],rn=0;if("startRule"in N){if(!(N.startRule in q))throw new Error("Can't start parsing from rule \""+N.startRule+'".');L=q[N.startRule]}if(H=L(),H!==j&&Je===t.length)return H;throw H!==j&&Jef;f++){var p=E[h],d=(0===f?"":r)+p;if(0===c.indexOf("//"+d+" "))for(var v=c.substring(3+d.length).split(" "),g=0;g1?b[1]:""}else 0===c.indexOf("//"+d+":")&&(s[p]=c.substring(3+d.length))}if(s.viewport){var w=s.viewport,_=w["aspect-ratio"];_&&(_=_.split("/"),w["aspect-ratio"]=parseInt(_[0])/parseInt(_[1])),void 0!==w.height&&(w.height="intrinsic"===w.height?!0:parseInt(w.height)),void 0!==w.width&&(w.width="intrinsic"===w.width?!0:parseInt(w.width)),void 0!==w["max-height"]&&(w["max-height"]=parseInt(w["max-height"])),void 0!==w["max-width"]&&(w["max-width"]=parseInt(w["max-width"])),void 0!==w["min-height"]&&(w["min-height"]=parseInt(w["min-height"])),void 0!==w["min-width"]&&(w["min-width"]=parseInt(w["min-width"]))}if(s.widths)for(i in s.widths){var x="intrinsic"===s.widths[i]?!0:parseInt(s.widths[i]);s.widths[i]=x,(void 0===x||isNaN(x))&&delete s.widths[i]}if(s.heights)for(i in s.heights){var A="intrinsic"===s.heights[i]?!0:parseInt(s.heights[i]);s.heights[i]=A,(void 0===A||isNaN(A))&&delete s.heights[i]}if(s.spacing){var V=JSON.parse(s.spacing);s.spacing=V,(void 0===V||isNaN(V))&&delete s.spacing}return s}}]),t}(),A=function(){function t(e){r(this,t),this._name=e.name,this._type=e.type,this._solver=e.solver,this._attr={},e.name||(this._attr[g.LEFT]=new v.Variable,this._solver.addConstraint(new v.StayConstraint(this._attr[g.LEFT],v.Strength.required)),this._attr[g.TOP]=new v.Variable,this._solver.addConstraint(new v.StayConstraint(this._attr[g.TOP],v.Strength.required)),this._attr[g.ZINDEX]=new v.Variable,this._solver.addConstraint(new v.StayConstraint(this._attr[g.ZINDEX],v.Strength.required)))}return d(t,[{key:"toJSON",value:function(){return{name:this.name,left:this.left,top:this.top,width:this.width,height:this.height}}},{key:"toString",value:function(){JSON.stringify(this.toJSON(),void 0,2)}},{key:"getValue",value:function(t){return this._attr[t]?this._attr[t].value():void 0}},{key:"_getAttr",value:function(t){if(this._attr[t])return this._attr[t];switch(this._attr[t]=new v.Variable,t){case g.RIGHT:this._getAttr(g.LEFT),this._getAttr(g.WIDTH),this._solver.addConstraint(new v.Equation(this._attr[t],v.plus(this._attr[g.LEFT],this._attr[g.WIDTH])));break;case g.BOTTOM:this._getAttr(g.TOP),this._getAttr(g.HEIGHT),this._solver.addConstraint(new v.Equation(this._attr[t],v.plus(this._attr[g.TOP],this._attr[g.HEIGHT])));break;case g.CENTERX:this._getAttr(g.LEFT),this._getAttr(g.WIDTH),this._solver.addConstraint(new v.Equation(this._attr[t],v.plus(this._attr[g.LEFT],v.divide(this._attr[g.WIDTH],2))));break;case g.CENTERY:this._getAttr(g.TOP),this._getAttr(g.HEIGHT),this._solver.addConstraint(new v.Equation(this._attr[t],v.plus(this._attr[g.TOP],v.divide(this._attr[g.HEIGHT],2))))}return this._attr[t]}},{key:"_getAttrValue",value:function(t){return this._getAttr(t).value}},{key:"name",get:function(){return this._name}},{key:"left",get:function(){return this._getAttrValue(g.LEFT)}},{key:"right",get:function(){return this._getAttrValue(g.RIGHT)}},{key:"width",get:function(){return this._getAttrValue(g.WIDTH)}},{key:"height",get:function(){return this._getAttrValue(g.HEIGHT)}},{key:"intrinsicWidth",get:function(){return this._intrinsicWidth},set:function(t){if(void 0!==t&&t!==this._intrinsicWidth){var e=this._getAttr(g.WIDTH);void 0===this._intrinsicWidth&&this._solver.addEditVar(e,new v.Strength("required",this._name?998:999,1e3,1e3)),this._intrinsicWidth=t,this._solver.suggestValue(e,t),this._solver.resolve()}}},{key:"intrinsicHeight",get:function(){return this._intrinsicHeight},set:function(t){if(void 0!==t&&t!==this._intrinsicHeight){var e=this._getAttr(g.HEIGHT);void 0===this._intrinsicHeight&&this._solver.addEditVar(e,new v.Strength("required",this._name?998:999,1e3,1e3)),this._intrinsicHeight=t,this._solver.suggestValue(e,t),this._solver.resolve()}}},{key:"top",get:function(){return this._getAttrValue(g.TOP)}},{key:"bottom",get:function(){return this._getAttrValue(g.BOTTOM)}},{key:"centerX",get:function(){return this._getAttrValue(g.CENTERX)}},{key:"centerY",get:function(){return this._getAttrValue(g.CENTERY)}},{key:"zIndex",get:function(){return this._getAttrValue(g.ZINDEX)}},{key:"type",get:function(){return this._type}}]),t}(),V=new v.Strength("defaultPriority",0,1e3,1e3),C=function(){function t(e){r(this,t),this._solver=new v.SimplexSolver,this._subViews={},this._parentSubView=new A({solver:this._solver}),this.setSpacing(e&&void 0!==e.spacing?e.spacing:8),e&&((void 0!==e.width||void 0!==e.height)&&this.setSize(e.width,e.height),e.constraints&&this.addConstraints(e.constraints))}return d(t,[{key:"setSize",value:function(t,e){return this._parentSubView.intrinsicWidth=t,this._parentSubView.intrinsicHeight=e,this}},{key:"setSpacing",value:function(t){switch(Array.isArray(t)?t.length:-1){case-1:t=[t,t,t,t,t,t,1];break;case 1:t=[t[0],t[0],t[0],t[0],t[0],t[0],1];break;case 2:t=[t[1],t[0],t[1],t[0],t[0],t[1],1];break;case 3:t=[t[1],t[0],t[1],t[0],t[0],t[1],t[2]];break;case 6:t=[t[0],t[1],t[2],t[3],t[4],t[5],1];break;case 7:break;default:throw"Invalid spacing syntax"}if(!p(this._spacing,t)&&(this._spacing=t,this._spacingVars)){for(var e=0;eMath.abs(r):0==r?a>Math.abs(n):Math.abs(n-r)64||this._deleted>this._compactThreshold&&(this._compact(),this._deleted=0)},"delete":function(t){t=e(t),this._store.hasOwnProperty(t)&&(this._deleted++,delete this._store[t],this.size>0&&this.size--)},each:function(t,e){if(this.size){this._perhapsCompact();var n=this._store,r=this._keyStrMap;Object.keys(this._store).forEach(function(i){t.call(e||null,r[i],n[i])},this)}},escapingEach:function(t,e){if(this.size){this._perhapsCompact();for(var n=this,i=this._store,s=this._keyStrMap,a=r,o=Object.keys(i),l=0;o.length>l;l++)if(function(r){n._store.hasOwnProperty(r)&&(a=t.call(e||null,s[r],i[r]))}(o[l]),a){if(void 0!==a.retval)return a;if(a.brk)break}}},clone:function(){var e=new t.HashTable;return this.size&&(e.size=this.size,n(this._store,e._store),n(this._keyStrMap,e._keyStrMap)),e},equals:function(e){if(e===this)return!0;if(!(e instanceof t.HashTable)||e._size!==this._size)return!1;for(var n=Object.keys(this._store),r=0;n.length>r;r++){var i=n[r];if(this._keyStrMap[i]!==e._keyStrMap[i]||this._store[i]!==e._store[i])return!1}return!0},toString:function(){var t="";return this.each(function(e,n){t+=e+" => "+n+"\n"}),t}})}(this.c||e.parent.exports||{}),function(t){"use strict";t.HashSet=t.inherit({_t:"c.HashSet",initialize:function(){this.storage=[],this.size=0},add:function(t){var e=this.storage;e.indexOf(t),-1==e.indexOf(t)&&e.push(t),this.size=this.storage.length},values:function(){return this.storage},has:function(t){var e=this.storage;return-1!=e.indexOf(t)},"delete":function(t){var e=this.storage.indexOf(t);return-1==e?null:(this.storage.splice(e,1)[0],void(this.size=this.storage.length))},clear:function(){this.storage.length=0},each:function(t,e){this.size&&this.storage.forEach(t,e)},escapingEach:function(t,e){this.size&&this.storage.forEach(t,e)},toString:function(){var t=this.size+" {",e=!0;return this.each(function(n){e?e=!1:t+=", ",t+=n}),t+="}\n"},toJSON:function(){var t=[];return this.each(function(e){t.push(e.toJSON())}),{_t:"c.HashSet",data:t}},fromJSON:function(e){var n=new t.HashSet;return e.data&&(n.size=e.data.length,n.storage=e.data),n}})}(this.c||e.parent.exports||{}),function(t){"use strict";t.Error=t.inherit({initialize:function(t){t&&(this._description=t)},_name:"c.Error",_description:"An error has occured in Cassowary",set description(t){this._description=t},get description(){return"("+this._name+") "+this._description},get message(){return this.description},toString:function(){return this.description}});var e=function(e,n){return t.inherit({"extends":t.Error,initialize:function(){t.Error.apply(this,arguments)},_name:e||"",_description:n||""})};t.ConstraintNotFound=e("c.ConstraintNotFound","Tried to remove a constraint never added to the tableu"),t.InternalError=e("c.InternalError"),t.NonExpression=e("c.NonExpression","The resulting expression would be non"),t.NotEnoughStays=e("c.NotEnoughStays","There are not enough stays to give specific values to every variable"),t.RequiredFailure=e("c.RequiredFailure","A required constraint cannot be satisfied"),t.TooDifficult=e("c.TooDifficult","The constraints are too difficult to solve")}(this.c||e.parent.exports||{}),function(t){"use strict";var e=1e3;t.SymbolicWeight=t.inherit({_t:"c.SymbolicWeight",initialize:function(){this.value=0;for(var t=1,n=arguments.length-1;n>=0;--n)this.value+=arguments[n]*t,t*=e},toJSON:function(){return{_t:this._t,value:this.value}}})}(this.c||e.parent.exports||{}),function(t){t.Strength=t.inherit({initialize:function(e,n,r,i){this.name=e,this.symbolicWeight=n instanceof t.SymbolicWeight?n:new t.SymbolicWeight(n,r,i)},get required(){return this===t.Strength.required},toString:function(){return this.name+(this.isRequired?"":":"+this.symbolicWeight)}}),t.Strength.required=new t.Strength("",1e3,1e3,1e3),t.Strength.strong=new t.Strength("strong",1,0,0),t.Strength.medium=new t.Strength("medium",0,1,0),t.Strength.weak=new t.Strength("weak",0,0,1)}(this.c||("undefined"!=typeof e?e.parent.exports.c:{})),function(t){"use strict";t.AbstractVariable=t.inherit({isDummy:!1,isExternal:!1,isPivotable:!1,isRestricted:!1,_init:function(e,n){this.hashCode=t._inc(),this.name=(n||"")+this.hashCode,e&&(void 0!==e.name&&(this.name=e.name),void 0!==e.value&&(this.value=e.value),void 0!==e.prefix&&(this._prefix=e.prefix))},_prefix:"",name:"",value:0,toJSON:function(){var t={};return this._t&&(t._t=this._t),this.name&&(t.name=this.name),void 0!==this.value&&(t.value=this.value),this._prefix&&(t._prefix=this._prefix),this._t&&(t._t=this._t),t},fromJSON:function(e,n){var r=new n;return t.extend(r,e),r},toString:function(){return this._prefix+"["+this.name+":"+this.value+"]"}}),t.Variable=t.inherit({_t:"c.Variable","extends":t.AbstractVariable,initialize:function(e){this._init(e,"v");var n=t.Variable._map;n&&(n[this.name]=this)},isExternal:!0}),t.DummyVariable=t.inherit({_t:"c.DummyVariable","extends":t.AbstractVariable,initialize:function(t){this._init(t,"d")},isDummy:!0,isRestricted:!0,value:"dummy"}),t.ObjectiveVariable=t.inherit({_t:"c.ObjectiveVariable","extends":t.AbstractVariable,initialize:function(t){this._init(t,"o")},value:"obj"}),t.SlackVariable=t.inherit({_t:"c.SlackVariable","extends":t.AbstractVariable,initialize:function(t){this._init(t,"s")},isPivotable:!0,isRestricted:!0,value:"slack"})}(this.c||e.parent.exports||{}),function(t){"use strict";t.Point=t.inherit({initialize:function(e,n,r){if(e instanceof t.Variable)this._x=e;else{var i={value:e};r&&(i.name="x"+r),this._x=new t.Variable(i)}if(n instanceof t.Variable)this._y=n;else{var s={value:n};r&&(s.name="y"+r),this._y=new t.Variable(s)}},get x(){return this._x},set x(e){e instanceof t.Variable?this._x=e:this._x.value=e},get y(){return this._y},set y(e){e instanceof t.Variable?this._y=e:this._y.value=e},toString:function(){return"("+this.x+", "+this.y+")"}})}(this.c||e.parent.exports||{}),function(t){"use strict";t.Expression=t.inherit({initialize:function(e,n,r){t.GC&&console.log("new c.Expression"),this.constant="number"!=typeof r||isNaN(r)?0:r,this.terms=new t.HashTable,e instanceof t.AbstractVariable?this.setVariable(e,"number"==typeof n?n:1):"number"==typeof e&&(isNaN(e)?console.trace():this.constant=e)},initializeFromHash:function(e,n){return t.verbose&&(console.log("*******************************"),console.log("clone c.initializeFromHash"),console.log("*******************************")),t.GC&&console.log("clone c.Expression"),this.constant=e,this.terms=n.clone(),this},multiplyMe:function(t){this.constant*=t;var e=this.terms;return e.each(function(n,r){e.set(n,r*t)}),this},clone:function(){t.verbose&&(console.log("*******************************"),console.log("clone c.Expression"),console.log("*******************************"));var e=new t.Expression;return e.initializeFromHash(this.constant,this.terms),e},times:function(e){if("number"==typeof e)return this.clone().multiplyMe(e);if(this.isConstant)return e.times(this.constant);if(e.isConstant)return this.times(e.constant);throw new t.NonExpression},plus:function(e){return e instanceof t.Expression?this.clone().addExpression(e,1):e instanceof t.Variable?this.clone().addVariable(e,1):void 0},minus:function(e){return e instanceof t.Expression?this.clone().addExpression(e,-1):e instanceof t.Variable?this.clone().addVariable(e,-1):void 0},divide:function(e){if("number"==typeof e){if(t.approx(e,0))throw new t.NonExpression;return this.times(1/e)}if(e instanceof t.Expression){if(!e.isConstant)throw new t.NonExpression;return this.times(1/e.constant)}},addExpression:function(e,n,r,i){return e instanceof t.AbstractVariable&&(e=new t.Expression(e),t.trace&&console.log("addExpression: Had to cast a var to an expression")),n=n||1,this.constant+=n*e.constant,e.terms.each(function(t,e){this.addVariable(t,e*n,r,i)},this),this},addVariable:function(e,n,r,i){null==n&&(n=1),t.trace&&console.log("c.Expression::addVariable():",e,n);var s=this.terms.get(e);if(s){var a=s+n;0==a||t.approx(a,0)?(i&&i.noteRemovedVariable(e,r),this.terms["delete"](e)):this.setVariable(e,a)}else t.approx(n,0)||(this.setVariable(e,n),i&&i.noteAddedVariable(e,r));return this},setVariable:function(t,e){return this.terms.set(t,e),this},anyPivotableVariable:function(){if(this.isConstant)throw new t.InternalError("anyPivotableVariable called on a constant");var e=this.terms.escapingEach(function(t){return t.isPivotable?{retval:t}:void 0});return e&&void 0!==e.retval?e.retval:null},substituteOut:function(e,n,r,i){t.trace&&(t.fnenterprint("CLE:substituteOut: "+e+", "+n+", "+r+", ..."),t.traceprint("this = "+this));var s=this.setVariable.bind(this),a=this.terms,o=a.get(e);a["delete"](e),this.constant+=o*n.constant,n.terms.each(function(e,n){var l=a.get(e);if(l){var u=l+o*n;t.approx(u,0)?(i.noteRemovedVariable(e,r),a["delete"](e)):s(e,u)}else s(e,o*n),i&&i.noteAddedVariable(e,r)}),t.trace&&t.traceprint("Now this is "+this)},changeSubject:function(t,e){this.setVariable(t,this.newSubject(e))},newSubject:function(e){t.trace&&t.fnenterprint("newSubject:"+e);var n=1/this.terms.get(e);return this.terms["delete"](e),this.multiplyMe(-n),n},coefficientFor:function(t){return this.terms.get(t)||0},get isConstant(){return 0==this.terms.size},toString:function(){var e="",n=!1;if(!t.approx(this.constant,0)||this.isConstant){if(e+=this.constant,this.isConstant)return e;n=!0}return this.terms.each(function(t,r){n&&(e+=" + "),e+=r+"*"+t,n=!0}),e},equals:function(e){return e===this?!0:e instanceof t.Expression&&e.constant===this.constant&&e.terms.equals(this.terms)},Plus:function(t,e){return t.plus(e)},Minus:function(t,e){return t.minus(e)},Times:function(t,e){return t.times(e)},Divide:function(t,e){return t.divide(e)}})}(this.c||e.parent.exports||{}),function(t){"use strict";t.AbstractConstraint=t.inherit({initialize:function(e,n){this.hashCode=t._inc(),this.strength=e||t.Strength.required,this.weight=n||1},isEditConstraint:!1,isInequality:!1,isStayConstraint:!1,get required(){return this.strength===t.Strength.required},toString:function(){return this.strength+" {"+this.weight+"} ("+this.expression+")"}});var e=t.AbstractConstraint.prototype.toString,n=function(e,n,r){t.AbstractConstraint.call(this,n||t.Strength.strong,r),this.variable=e,this.expression=new t.Expression(e,-1,e.value)};t.EditConstraint=t.inherit({"extends":t.AbstractConstraint,initialize:function(){n.apply(this,arguments)},isEditConstraint:!0,toString:function(){return"edit:"+e.call(this)}}),t.StayConstraint=t.inherit({"extends":t.AbstractConstraint,initialize:function(){n.apply(this,arguments)},isStayConstraint:!0,toString:function(){return"stay:"+e.call(this)}});var r=t.Constraint=t.inherit({"extends":t.AbstractConstraint,initialize:function(e,n,r){t.AbstractConstraint.call(this,n,r),this.expression=e}});t.Inequality=t.inherit({"extends":t.Constraint,_cloneOrNewCle:function(e){return e.clone?e.clone():new t.Expression(e)},initialize:function(e,n,i,s,a){var o=e instanceof t.Expression,l=i instanceof t.Expression,u=e instanceof t.AbstractVariable,c=i instanceof t.AbstractVariable,h="number"==typeof e,f="number"==typeof i;if((o||h)&&c){var p=e,d=n,v=i,g=s,b=a;if(r.call(this,this._cloneOrNewCle(p),g,b),d==t.LEQ)this.expression.multiplyMe(-1),this.expression.addVariable(v);else{if(d!=t.GEQ)throw new t.InternalError("Invalid operator in c.Inequality constructor");this.expression.addVariable(v,-1)}}else if(u&&(l||f)){var p=i,d=n,v=e,g=s,b=a;if(r.call(this,this._cloneOrNewCle(p),g,b),d==t.GEQ)this.expression.multiplyMe(-1),this.expression.addVariable(v);else{if(d!=t.LEQ)throw new t.InternalError("Invalid operator in c.Inequality constructor");this.expression.addVariable(v,-1)}}else{if(o&&f){var m=e,d=n,y=i,g=s,b=a;if(r.call(this,this._cloneOrNewCle(m),g,b),d==t.LEQ)this.expression.multiplyMe(-1),this.expression.addExpression(this._cloneOrNewCle(y));else{if(d!=t.GEQ)throw new t.InternalError("Invalid operator in c.Inequality constructor");this.expression.addExpression(this._cloneOrNewCle(y),-1)}return this}if(h&&l){var m=i,d=n,y=e,g=s,b=a;if(r.call(this,this._cloneOrNewCle(m),g,b),d==t.GEQ)this.expression.multiplyMe(-1),this.expression.addExpression(this._cloneOrNewCle(y));else{if(d!=t.LEQ)throw new t.InternalError("Invalid operator in c.Inequality constructor");this.expression.addExpression(this._cloneOrNewCle(y),-1)}return this}if(o&&l){var m=e,d=n,y=i,g=s,b=a;if(r.call(this,this._cloneOrNewCle(y),g,b),d==t.GEQ)this.expression.multiplyMe(-1),this.expression.addExpression(this._cloneOrNewCle(m));else{if(d!=t.LEQ)throw new t.InternalError("Invalid operator in c.Inequality constructor");this.expression.addExpression(this._cloneOrNewCle(m),-1)}}else{if(o)return r.call(this,e,n,i);if(n==t.GEQ)r.call(this,new t.Expression(i),s,a),this.expression.multiplyMe(-1),this.expression.addVariable(e);else{if(n!=t.LEQ)throw new t.InternalError("Invalid operator in c.Inequality constructor");r.call(this,new t.Expression(i),s,a),this.expression.addVariable(e,-1)}}}},isInequality:!0,toString:function(){return r.prototype.toString.call(this)+" >= 0) id: "+this.hashCode}}),t.Equation=t.inherit({"extends":t.Constraint,initialize:function(e,n,i,s){if(e instanceof t.Expression&&!n||n instanceof t.Strength)r.call(this,e,n,i);else if(e instanceof t.AbstractVariable&&n instanceof t.Expression){var a=e,o=n,l=i,u=s;r.call(this,o.clone(),l,u),this.expression.addVariable(a,-1)}else if(e instanceof t.AbstractVariable&&"number"==typeof n){var a=e,c=n,l=i,u=s;r.call(this,new t.Expression(c),l,u),this.expression.addVariable(a,-1)}else if(e instanceof t.Expression&&n instanceof t.AbstractVariable){var o=e,a=n,l=i,u=s;r.call(this,o.clone(),l,u),this.expression.addVariable(a,-1)}else{if(!(e instanceof t.Expression||e instanceof t.AbstractVariable||"number"==typeof e)||!(n instanceof t.Expression||n instanceof t.AbstractVariable||"number"==typeof n))throw"Bad initializer to c.Equation";e=e instanceof t.Expression?e.clone():new t.Expression(e),n=n instanceof t.Expression?n.clone():new t.Expression(n),r.call(this,e,i,s),this.expression.addExpression(n,-1)}t.assert(this.strength instanceof t.Strength,"_strength not set")},toString:function(){return r.prototype.toString.call(this)+" = 0)"}})}(this.c||e.parent.exports||{}),function(t){"use strict";t.EditInfo=t.inherit({initialize:function(t,e,n,r,i){this.constraint=t,this.editPlus=e,this.editMinus=n,this.prevEditConstant=r,this.index=i},toString:function(){return""}})}(this.c||e.parent.exports||{}),function(t){"use strict";t.Tableau=t.inherit({initialize:function(){this.columns=new t.HashTable,this.rows=new t.HashTable,this._infeasibleRows=new t.HashSet,this._externalRows=new t.HashSet,this._externalParametricVars=new t.HashSet},noteRemovedVariable:function(e,n){t.trace&&console.log("c.Tableau::noteRemovedVariable: ",e,n);var r=this.columns.get(e);n&&r&&r["delete"](n)},noteAddedVariable:function(t,e){e&&this.insertColVar(t,e)},getInternalInfo:function(){var t="Tableau Information:\n";return t+="Rows: "+this.rows.size,t+=" (= "+(this.rows.size-1)+" constraints)",t+="\nColumns: "+this.columns.size,t+="\nInfeasible Rows: "+this._infeasibleRows.size,t+="\nExternal basic variables: "+this._externalRows.size,t+="\nExternal parametric variables: ",t+=this._externalParametricVars.size,t+="\n"},toString:function(){var t="Tableau:\n";return this.rows.each(function(e,n){t+=e,t+=" <==> ",t+=n,t+="\n"}),t+="\nColumns:\n",t+=this.columns,t+="\nInfeasible rows: ",t+=this._infeasibleRows,t+="External basic variables: ",t+=this._externalRows,t+="External parametric variables: ",t+=this._externalParametricVars},insertColVar:function(e,n){var r=this.columns.get(e);r||(r=new t.HashSet,this.columns.set(e,r)),r.add(n)},addRow:function(e,n){t.trace&&t.fnenterprint("addRow: "+e+", "+n),this.rows.set(e,n),n.terms.each(function(t){this.insertColVar(t,e),t.isExternal&&this._externalParametricVars.add(t)},this),e.isExternal&&this._externalRows.add(e),t.trace&&t.traceprint(""+this)},removeColumn:function(e){t.trace&&t.fnenterprint("removeColumn:"+e);var n=this.columns.get(e);n?(this.columns["delete"](e),n.each(function(t){var n=this.rows.get(t);n.terms["delete"](e)},this)):t.trace&&console.log("Could not find var",e,"in columns"),e.isExternal&&(this._externalRows["delete"](e),this._externalParametricVars["delete"](e))},removeRow:function(e){t.trace&&t.fnenterprint("removeRow:"+e);var n=this.rows.get(e);return t.assert(null!=n),n.terms.each(function(n){var r=this.columns.get(n);null!=r&&(t.trace&&console.log("removing from varset:",e),r["delete"](e))},this),this._infeasibleRows["delete"](e),e.isExternal&&this._externalRows["delete"](e),this.rows["delete"](e),t.trace&&t.fnexitprint("returning "+n),n},substituteOut:function(e,n){t.trace&&t.fnenterprint("substituteOut:"+e+", "+n),t.trace&&t.traceprint(""+this);var r=this.columns.get(e);r.each(function(t){var r=this.rows.get(t);r.substituteOut(e,n,t,this),t.isRestricted&&0>r.constant&&this._infeasibleRows.add(t)},this),e.isExternal&&(this._externalRows.add(e),this._externalParametricVars["delete"](e)),this.columns["delete"](e)},columnsHasKey:function(t){return!!this.columns.get(t)}})}(this.c||e.parent.exports||{}),function(t){var e=t.Tableau,n=e.prototype,r=1e-8,i=t.Strength.weak;t.SimplexSolver=t.inherit({"extends":t.Tableau,initialize:function(){t.Tableau.call(this),this._stayMinusErrorVars=[],this._stayPlusErrorVars=[],this._errorVars=new t.HashTable,this._markerVars=new t.HashTable,this._objective=new t.ObjectiveVariable({name:"Z"}),this._editVarMap=new t.HashTable,this._editVarList=[],this._slackCounter=0,this._artificialCounter=0,this._dummyCounter=0,this.autoSolve=!0,this._fNeedsSolving=!1,this._optimizeCount=0,this.rows.set(this._objective,new t.Expression),this._stkCedcns=[0],t.trace&&t.traceprint("objective expr == "+this.rows.get(this._objective))},addLowerBound:function(e,n){var r=new t.Inequality(e,t.GEQ,new t.Expression(n));return this.addConstraint(r)},addUpperBound:function(e,n){var r=new t.Inequality(e,t.LEQ,new t.Expression(n));return this.addConstraint(r)},addBounds:function(t,e,n){return this.addLowerBound(t,e),this.addUpperBound(t,n),this},add:function(){for(var t=0;arguments.length>t;t++)this.addConstraint(arguments[t]);return this},addConstraint:function(e){t.trace&&t.fnenterprint("addConstraint: "+e);var n=Array(2),r=Array(1),i=this.newExpression(e,n,r);if(r=r[0],this.tryAddingDirectly(i)||this.addWithArtificialVariable(i),this._fNeedsSolving=!0,e.isEditConstraint){var s=this._editVarMap.size,a=n[0],o=n[1];!a instanceof t.SlackVariable&&console.warn("cvEplus not a slack variable =",a),!o instanceof t.SlackVariable&&console.warn("cvEminus not a slack variable =",o),t.debug&&console.log("new c.EditInfo("+e+", "+a+", "+o+", "+r+", "+s+")");var l=new t.EditInfo(e,a,o,r,s);this._editVarMap.set(e.variable,l),this._editVarList[s]={v:e.variable,info:l}}return this.autoSolve&&(this.optimize(this._objective),this._setExternalVariables()),this},addConstraintNoException:function(e){t.trace&&t.fnenterprint("addConstraintNoException: "+e);try{return this.addConstraint(e),!0}catch(n){return!1;
15 | }},addEditVar:function(e,n){return t.trace&&t.fnenterprint("addEditVar: "+e+" @ "+n),this.addConstraint(new t.EditConstraint(e,n||t.Strength.strong))},beginEdit:function(){return t.assert(this._editVarMap.size>0,"_editVarMap.size > 0"),this._infeasibleRows.clear(),this._resetStayConstants(),this._stkCedcns.push(this._editVarMap.size),this},endEdit:function(){return t.assert(this._editVarMap.size>0,"_editVarMap.size > 0"),this.resolve(),this._stkCedcns.pop(),this.removeEditVarsTo(this._stkCedcns[this._stkCedcns.length-1]),this},removeAllEditVars:function(){return this.removeEditVarsTo(0)},removeEditVarsTo:function(e){try{for(var n=this._editVarList.length,r=e;n>r;r++)this._editVarList[r]&&this.removeConstraint(this._editVarMap.get(this._editVarList[r].v).constraint);return this._editVarList.length=e,t.assert(this._editVarMap.size==e,"_editVarMap.size == n"),this}catch(i){throw new t.InternalError("Constraint not found in removeEditVarsTo")}},addPointStays:function(e){return t.trace&&console.log("addPointStays",e),e.forEach(function(t,e){this.addStay(t.x,i,Math.pow(2,e)),this.addStay(t.y,i,Math.pow(2,e))},this),this},addStay:function(e,n,r){var s=new t.StayConstraint(e,n||i,r||1);return this.addConstraint(s)},removeConstraint:function(t){return this.removeConstraintInternal(t),this},removeConstraintInternal:function(e){t.trace&&t.fnenterprint("removeConstraintInternal: "+e),t.trace&&t.traceprint(""+this),this._fNeedsSolving=!0,this._resetStayConstants();var n=this.rows.get(this._objective),r=this._errorVars.get(e);t.trace&&t.traceprint("eVars == "+r),null!=r&&r.each(function(i){var s=this.rows.get(i);null==s?n.addVariable(i,-e.weight*e.strength.symbolicWeight.value,this._objective,this):n.addExpression(s,-e.weight*e.strength.symbolicWeight.value,this._objective,this),t.trace&&t.traceprint("now eVars == "+r)},this);var i=this._markerVars.get(e);if(this._markerVars["delete"](e),null==i)throw new t.InternalError("Constraint not found in removeConstraintInternal");if(t.trace&&t.traceprint("Looking to remove var "+i),null==this.rows.get(i)){var s=this.columns.get(i);t.trace&&t.traceprint("Must pivot -- columns are "+s);var a=null,o=0;s.each(function(e){if(e.isRestricted){var n=this.rows.get(e),r=n.coefficientFor(i);if(t.trace&&t.traceprint("Marker "+i+"'s coefficient in "+n+" is "+r),0>r){var s=-n.constant/r;(null==a||o>s||t.approx(s,o)&&e.hashCoder)&&(o=r,a=t)}},this)),null==a&&(0==s.size?this.removeColumn(i):s.escapingEach(function(t){return t!=this._objective?(a=t,{brk:!0}):void 0},this)),null!=a&&this.pivot(i,a)}if(null!=this.rows.get(i)&&this.removeRow(i),null!=r&&r.each(function(t){t!=i&&this.removeColumn(t)},this),e.isStayConstraint){if(null!=r)for(var l=0;this._stayPlusErrorVars.length>l;l++)r["delete"](this._stayPlusErrorVars[l]),r["delete"](this._stayMinusErrorVars[l])}else if(e.isEditConstraint){t.assert(null!=r,"eVars != null");var u=this._editVarMap.get(e.variable);this.removeColumn(u.editMinus),this._editVarMap["delete"](e.variable)}return null!=r&&this._errorVars["delete"](r),this.autoSolve&&(this.optimize(this._objective),this._setExternalVariables()),this},reset:function(){throw t.trace&&t.fnenterprint("reset"),new t.InternalError("reset not implemented")},resolveArray:function(e){t.trace&&t.fnenterprint("resolveArray"+e);var n=e.length;this._editVarMap.each(function(t,r){var i=r.index;n>i&&this.suggestValue(t,e[i])},this),this.resolve()},resolvePair:function(t,e){this.suggestValue(this._editVarList[0].v,t),this.suggestValue(this._editVarList[1].v,e),this.resolve()},resolve:function(){t.trace&&t.fnenterprint("resolve()"),this.dualOptimize(),this._setExternalVariables(),this._infeasibleRows.clear(),this._resetStayConstants()},suggestValue:function(e,n){t.trace&&console.log("suggestValue("+e+", "+n+")");var r=this._editVarMap.get(e);if(!r)throw new t.Error("suggestValue for variable "+e+", but var is not an edit variable");var i=n-r.prevEditConstant;return r.prevEditConstant=n,this.deltaEditConstant(i,r.editPlus,r.editMinus),this},solve:function(){return this._fNeedsSolving&&(this.optimize(this._objective),this._setExternalVariables()),this},setEditedValue:function(e,n){if(!this.columnsHasKey(e)&&null==this.rows.get(e))return e.value=n,this;if(!t.approx(n,e.value)){this.addEditVar(e),this.beginEdit();try{this.suggestValue(e,n)}catch(r){throw new t.InternalError("Error in setEditedValue")}this.endEdit()}return this},addVar:function(e){if(!this.columnsHasKey(e)&&null==this.rows.get(e)){try{this.addStay(e)}catch(n){throw new t.InternalError("Error in addVar -- required failure is impossible")}t.trace&&t.traceprint("added initial stay on "+e)}return this},getInternalInfo:function(){var t=n.getInternalInfo.call(this);return t+="\nSolver info:\n",t+="Stay Error Variables: ",t+=this._stayPlusErrorVars.length+this._stayMinusErrorVars.length,t+=" ("+this._stayPlusErrorVars.length+" +, ",t+=this._stayMinusErrorVars.length+" -)\n",t+="Edit Variables: "+this._editVarMap.size,t+="\n"},getDebugInfo:function(){return""+this+this.getInternalInfo()+"\n"},toString:function(){var t=n.getInternalInfo.call(this);return t+="\n_stayPlusErrorVars: ",t+="["+this._stayPlusErrorVars+"]",t+="\n_stayMinusErrorVars: ",t+="["+this._stayMinusErrorVars+"]",t+="\n",t+="_editVarMap:\n"+this._editVarMap,t+="\n"},getConstraintMap:function(){return this._markerVars},addWithArtificialVariable:function(e){t.trace&&t.fnenterprint("addWithArtificialVariable: "+e);var n=new t.SlackVariable({value:++this._artificialCounter,prefix:"a"}),r=new t.ObjectiveVariable({name:"az"}),i=e.clone();t.trace&&t.traceprint("before addRows:\n"+this),this.addRow(r,i),this.addRow(n,e),t.trace&&t.traceprint("after addRows:\n"+this),this.optimize(r);var s=this.rows.get(r);if(t.trace&&t.traceprint("azTableauRow.constant == "+s.constant),!t.approx(s.constant,0))throw this.removeRow(r),this.removeColumn(n),new t.RequiredFailure;var a=this.rows.get(n);if(null!=a){if(a.isConstant)return this.removeRow(n),void this.removeRow(r);var o=a.anyPivotableVariable();this.pivot(o,n)}t.assert(null==this.rows.get(n),"rowExpression(av) == null"),this.removeColumn(n),this.removeRow(r)},tryAddingDirectly:function(e){t.trace&&t.fnenterprint("tryAddingDirectly: "+e);var n=this.chooseSubject(e);return null==n?(t.trace&&t.fnexitprint("returning false"),!1):(e.newSubject(n),this.columnsHasKey(n)&&this.substituteOut(n,e),this.addRow(n,e),t.trace&&t.fnexitprint("returning true"),!0)},chooseSubject:function(e){t.trace&&t.fnenterprint("chooseSubject: "+e);var n=null,r=!1,i=!1,s=e.terms,a=s.escapingEach(function(t,e){if(r){if(!t.isRestricted&&!this.columnsHasKey(t))return{retval:t}}else if(t.isRestricted){if(!i&&!t.isDummy&&0>e){var s=this.columns.get(t);(null==s||1==s.size&&this.columnsHasKey(this._objective))&&(n=t,i=!0)}}else n=t,r=!0},this);if(a&&void 0!==a.retval)return a.retval;if(null!=n)return n;var o=0,a=s.escapingEach(function(t,e){return t.isDummy?void(this.columnsHasKey(t)||(n=t,o=e)):{retval:null}},this);if(a&&void 0!==a.retval)return a.retval;if(!t.approx(e.constant,0))throw new t.RequiredFailure;return o>0&&e.multiplyMe(-1),n},deltaEditConstant:function(e,n,r){t.trace&&t.fnenterprint("deltaEditConstant :"+e+", "+n+", "+r);var i=this.rows.get(n);if(null!=i)return i.constant+=e,void(0>i.constant&&this._infeasibleRows.add(n));var s=this.rows.get(r);if(null!=s)return s.constant+=-e,void(0>s.constant&&this._infeasibleRows.add(r));var a=this.columns.get(r);a||console.log("columnVars is null -- tableau is:\n"+this),a.each(function(t){var n=this.rows.get(t),i=n.coefficientFor(r);n.constant+=i*e,t.isRestricted&&0>n.constant&&this._infeasibleRows.add(t)},this)},dualOptimize:function(){t.trace&&t.fnenterprint("dualOptimize:");for(var e=this.rows.get(this._objective);this._infeasibleRows.size;){var n=this._infeasibleRows.values()[0];this._infeasibleRows["delete"](n);var r=null,i=this.rows.get(n);if(i&&0>i.constant){var s,a=Number.MAX_VALUE,o=i.terms;if(o.each(function(n,i){if(i>0&&n.isPivotable){var o=e.coefficientFor(n);s=o/i,(a>s||t.approx(s,a)&&n.hashCodes.constant&&s.multiplyMe(-1),t.trace&&t.fnexitprint("returning "+s),s},optimize:function(e){t.trace&&t.fnenterprint("optimize: "+e),t.trace&&t.traceprint(""+this),this._optimizeCount++;var n=this.rows.get(e);t.assert(null!=n,"zRow != null");for(var i,s,a=null,o=null;;){if(i=0,s=n.terms,s.escapingEach(function(t,e){return t.isPivotable&&i>e?(i=e,a=t,{brk:1}):void 0},this),i>=-r)return;t.trace&&console.log("entryVar:",a,"objectiveCoeff:",i);var l=Number.MAX_VALUE,u=this.columns.get(a),c=0;if(u.each(function(e){if(t.trace&&t.traceprint("Checking "+e),e.isPivotable){var n=this.rows.get(e),r=n.coefficientFor(a);t.trace&&t.traceprint("pivotable, coeff = "+r),0>r&&(c=-n.constant/r,(l>c||t.approx(c,l)&&e.hashCodee;e++){var n=this.rows.get(this._stayPlusErrorVars[e]);null==n&&(n=this.rows.get(this._stayMinusErrorVars[e])),null!=n&&(n.constant=0)}},_setExternalVariables:function(){t.trace&&t.fnenterprint("_setExternalVariables:"),t.trace&&t.traceprint(""+this),this._externalParametricVars.each(function(e){null!=this.rows.get(e)?t.trace&&console.log("Error: variable"+e+" in _externalParametricVars is basic"):e.value=0},this),this._externalRows.each(function(t){var e=this.rows.get(t);t.value!=e.constant&&(t.value=e.constant)},this),this._fNeedsSolving=!1,this.onsolved()},onsolved:function(){},insertErrorVar:function(e,n){t.trace&&t.fnenterprint("insertErrorVar:"+e+", "+n);var r=this._errorVars.get(n);r||(r=new t.HashSet,this._errorVars.set(e,r)),r.add(n)}})}(this.c||e.parent.exports||{}),function(t){"use strict";t.Timer=t.inherit({initialize:function(){this.isRunning=!1,this._elapsedMs=0},start:function(){return this.isRunning=!0,this._startReading=new Date,this},stop:function(){return this.isRunning=!1,this._elapsedMs+=new Date-this._startReading,this},reset:function(){return this.isRunning=!1,this._elapsedMs=0,this},elapsedTime:function(){return this.isRunning?(this._elapsedMs+(new Date-this._startReading))/1e3:this._elapsedMs/1e3}})}(this.c||e.parent.exports||{}),__cassowary_parser=function(){function t(t){return'"'+t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var e={parse:function(e,n){function r(t){F>L||(L>F&&(F=L,P=[]),P.push(t))}function i(){var t,e,n,r,i;if(r=L,i=L,t=m(),null!==t){if(n=s(),null!==n)for(e=[];null!==n;)e.push(n),n=s();else e=null;null!==e?(n=m(),null!==n?t=[t,e,n]:(t=null,L=i)):(t=null,L=i)}else t=null,L=i;return null!==t&&(t=function(t,e){return e}(r,t[1])),null===t&&(L=r),t}function s(){var t,e,n,r;return n=L,r=L,t=H(),null!==t?(e=h(),null!==e?t=[t,e]:(t=null,L=r)):(t=null,L=r),null!==t&&(t=function(t,e){return e}(n,t[0])),null===t&&(L=n),t}function a(){var t;return e.length>L?(t=e.charAt(L),L++):(t=null,0===M&&r("any character")),t}function o(){var t;return/^[a-zA-Z]/.test(e.charAt(L))?(t=e.charAt(L),L++):(t=null,0===M&&r("[a-zA-Z]")),null===t&&(36===e.charCodeAt(L)?(t="$",L++):(t=null,0===M&&r('"$"')),null===t&&(95===e.charCodeAt(L)?(t="_",L++):(t=null,0===M&&r('"_"')))),t}function l(){var t;return M++,/^[\t\x0B\f \xA0\uFEFF]/.test(e.charAt(L))?(t=e.charAt(L),L++):(t=null,0===M&&r("[\\t\\x0B\\f \\xA0\\uFEFF]")),M--,0===M&&null===t&&r("whitespace"),t}function u(){var t;return/^[\n\r\u2028\u2029]/.test(e.charAt(L))?(t=e.charAt(L),L++):(t=null,0===M&&r("[\\n\\r\\u2028\\u2029]")),t}function c(){var t;return M++,10===e.charCodeAt(L)?(t="\n",L++):(t=null,0===M&&r('"\\n"')),null===t&&("\r\n"===e.substr(L,2)?(t="\r\n",L+=2):(t=null,0===M&&r('"\\r\\n"')),null===t&&(13===e.charCodeAt(L)?(t="\r",L++):(t=null,0===M&&r('"\\r"')),null===t&&(8232===e.charCodeAt(L)?(t="\u2028",L++):(t=null,0===M&&r('"\\u2028"')),null===t&&(8233===e.charCodeAt(L)?(t="\u2029",L++):(t=null,0===M&&r('"\\u2029"')))))),M--,0===M&&null===t&&r("end of line"),t}function h(){var t,n,i;return i=L,t=m(),null!==t?(59===e.charCodeAt(L)?(n=";",L++):(n=null,0===M&&r('";"')),null!==n?t=[t,n]:(t=null,L=i)):(t=null,L=i),null===t&&(i=L,t=b(),null!==t?(n=c(),null!==n?t=[t,n]:(t=null,L=i)):(t=null,L=i),null===t&&(i=L,t=m(),null!==t?(n=f(),null!==n?t=[t,n]:(t=null,L=i)):(t=null,L=i))),t}function f(){var t,n;return n=L,M++,e.length>L?(t=e.charAt(L),L++):(t=null,0===M&&r("any character")),M--,null===t?t="":(t=null,L=n),t}function p(){var t;return M++,t=d(),null===t&&(t=g()),M--,0===M&&null===t&&r("comment"),t}function d(){var t,n,i,s,o,l,u;if(o=L,"/*"===e.substr(L,2)?(t="/*",L+=2):(t=null,0===M&&r('"/*"')),null!==t){for(n=[],l=L,u=L,M++,"*/"===e.substr(L,2)?(i="*/",L+=2):(i=null,0===M&&r('"*/"')),M--,null===i?i="":(i=null,L=u),null!==i?(s=a(),null!==s?i=[i,s]:(i=null,L=l)):(i=null,L=l);null!==i;)n.push(i),l=L,u=L,M++,"*/"===e.substr(L,2)?(i="*/",L+=2):(i=null,0===M&&r('"*/"')),M--,null===i?i="":(i=null,L=u),null!==i?(s=a(),null!==s?i=[i,s]:(i=null,L=l)):(i=null,L=l);null!==n?("*/"===e.substr(L,2)?(i="*/",L+=2):(i=null,0===M&&r('"*/"')),null!==i?t=[t,n,i]:(t=null,L=o)):(t=null,L=o)}else t=null,L=o;return t}function v(){var t,n,i,s,o,l,c;if(o=L,"/*"===e.substr(L,2)?(t="/*",L+=2):(t=null,0===M&&r('"/*"')),null!==t){for(n=[],l=L,c=L,M++,"*/"===e.substr(L,2)?(i="*/",L+=2):(i=null,0===M&&r('"*/"')),null===i&&(i=u()),M--,null===i?i="":(i=null,L=c),null!==i?(s=a(),null!==s?i=[i,s]:(i=null,L=l)):(i=null,L=l);null!==i;)n.push(i),l=L,c=L,M++,"*/"===e.substr(L,2)?(i="*/",L+=2):(i=null,0===M&&r('"*/"')),null===i&&(i=u()),M--,null===i?i="":(i=null,L=c),null!==i?(s=a(),null!==s?i=[i,s]:(i=null,L=l)):(i=null,L=l);null!==n?("*/"===e.substr(L,2)?(i="*/",L+=2):(i=null,0===M&&r('"*/"')),null!==i?t=[t,n,i]:(t=null,L=o)):(t=null,L=o)}else t=null,L=o;return t}function g(){var t,n,i,s,o,l,c;if(o=L,"//"===e.substr(L,2)?(t="//",L+=2):(t=null,0===M&&r('"//"')),null!==t){for(n=[],l=L,c=L,M++,i=u(),M--,null===i?i="":(i=null,L=c),null!==i?(s=a(),null!==s?i=[i,s]:(i=null,L=l)):(i=null,L=l);null!==i;)n.push(i),l=L,c=L,M++,i=u(),M--,null===i?i="":(i=null,L=c),null!==i?(s=a(),null!==s?i=[i,s]:(i=null,L=l)):(i=null,L=l);null!==n?t=[t,n]:(t=null,L=o)}else t=null,L=o;return t}function b(){var t,e;for(t=[],e=l(),null===e&&(e=v(),null===e&&(e=g()));null!==e;)t.push(e),e=l(),null===e&&(e=v(),null===e&&(e=g()));return t}function m(){var t,e;for(t=[],e=l(),null===e&&(e=c(),null===e&&(e=p()));null!==e;)t.push(e),e=l(),null===e&&(e=c(),null===e&&(e=p()));return t}function y(){var t,e;return e=L,t=_(),null===t&&(t=w()),null!==t&&(t=function(t,e){return{type:"NumericLiteral",value:e}}(e,t)),null===t&&(L=e),t}function w(){var t,n,i;if(i=L,/^[0-9]/.test(e.charAt(L))?(n=e.charAt(L),L++):(n=null,0===M&&r("[0-9]")),null!==n)for(t=[];null!==n;)t.push(n),/^[0-9]/.test(e.charAt(L))?(n=e.charAt(L),L++):(n=null,0===M&&r("[0-9]"));else t=null;return null!==t&&(t=function(t,e){return parseInt(e.join(""))}(i,t)),null===t&&(L=i),t}function _(){var t,n,i,s,a;return s=L,a=L,t=w(),null!==t?(46===e.charCodeAt(L)?(n=".",L++):(n=null,0===M&&r('"."')),null!==n?(i=w(),null!==i?t=[t,n,i]:(t=null,L=a)):(t=null,L=a)):(t=null,L=a),null!==t&&(t=function(t,e){return parseFloat(e.join(""))}(s,t)),null===t&&(L=s),t}function E(){var t,n,i,s;if(s=L,/^[\-+]/.test(e.charAt(L))?(t=e.charAt(L),L++):(t=null,0===M&&r("[\\-+]")),t=null!==t?t:"",null!==t){if(/^[0-9]/.test(e.charAt(L))?(i=e.charAt(L),L++):(i=null,0===M&&r("[0-9]")),null!==i)for(n=[];null!==i;)n.push(i),/^[0-9]/.test(e.charAt(L))?(i=e.charAt(L),L++):(i=null,0===M&&r("[0-9]"));else n=null;null!==n?t=[t,n]:(t=null,L=s)}else t=null,L=s;return t}function x(){var t,e;return M++,e=L,t=A(),null!==t&&(t=function(t,e){return e}(e,t)),null===t&&(L=e),M--,0===M&&null===t&&r("identifier"),t}function A(){var t,e,n,i,s;if(M++,i=L,s=L,t=o(),null!==t){for(e=[],n=o();null!==n;)e.push(n),n=o();null!==e?t=[t,e]:(t=null,L=s)}else t=null,L=s;return null!==t&&(t=function(t,e,n){return e+n.join("")}(i,t[0],t[1])),null===t&&(L=i),M--,0===M&&null===t&&r("identifier"),t}function V(){var t,n,i,s,a,o,l;return o=L,t=x(),null!==t&&(t=function(t,e){return{type:"Variable",name:e}}(o,t)),null===t&&(L=o),null===t&&(t=y(),null===t&&(o=L,l=L,40===e.charCodeAt(L)?(t="(",L++):(t=null,0===M&&r('"("')),null!==t?(n=m(),null!==n?(i=H(),null!==i?(s=m(),null!==s?(41===e.charCodeAt(L)?(a=")",L++):(a=null,0===M&&r('")"')),null!==a?t=[t,n,i,s,a]:(t=null,L=l)):(t=null,L=l)):(t=null,L=l)):(t=null,L=l)):(t=null,L=l),null!==t&&(t=function(t,e){return e}(o,t[2])),null===t&&(L=o))),t}function C(){var t,e,n,r,i;return t=V(),null===t&&(r=L,i=L,t=S(),null!==t?(e=m(),null!==e?(n=C(),null!==n?t=[t,e,n]:(t=null,L=i)):(t=null,L=i)):(t=null,L=i),null!==t&&(t=function(t,e,n){return{type:"UnaryExpression",operator:e,expression:n}}(r,t[0],t[2])),null===t&&(L=r)),t}function S(){var t;return 43===e.charCodeAt(L)?(t="+",L++):(t=null,0===M&&r('"+"')),null===t&&(45===e.charCodeAt(L)?(t="-",L++):(t=null,0===M&&r('"-"')),null===t&&(33===e.charCodeAt(L)?(t="!",L++):(t=null,0===M&&r('"!"')))),t}function T(){var t,e,n,r,i,s,a,o,l;if(a=L,o=L,t=C(),null!==t){for(e=[],l=L,n=m(),null!==n?(r=I(),null!==r?(i=m(),null!==i?(s=C(),null!==s?n=[n,r,i,s]:(n=null,L=l)):(n=null,L=l)):(n=null,L=l)):(n=null,L=l);null!==n;)e.push(n),l=L,n=m(),null!==n?(r=I(),null!==r?(i=m(),null!==i?(s=C(),null!==s?n=[n,r,i,s]:(n=null,L=l)):(n=null,L=l)):(n=null,L=l)):(n=null,L=l);null!==e?t=[t,e]:(t=null,L=o)}else t=null,L=o;return null!==t&&(t=function(t,e,n){for(var r=e,i=0;n.length>i;i++)r={type:"MultiplicativeExpression",operator:n[i][1],left:r,right:n[i][3]};return r}(a,t[0],t[1])),null===t&&(L=a),t}function I(){var t;return 42===e.charCodeAt(L)?(t="*",L++):(t=null,0===M&&r('"*"')),null===t&&(47===e.charCodeAt(L)?(t="/",L++):(t=null,0===M&&r('"/"'))),t}function O(){var t,e,n,r,i,s,a,o,l;if(a=L,o=L,t=T(),null!==t){for(e=[],l=L,n=m(),null!==n?(r=R(),null!==r?(i=m(),null!==i?(s=T(),null!==s?n=[n,r,i,s]:(n=null,L=l)):(n=null,L=l)):(n=null,L=l)):(n=null,L=l);null!==n;)e.push(n),l=L,n=m(),null!==n?(r=R(),null!==r?(i=m(),null!==i?(s=T(),null!==s?n=[n,r,i,s]:(n=null,L=l)):(n=null,L=l)):(n=null,L=l)):(n=null,L=l);null!==e?t=[t,e]:(t=null,L=o)}else t=null,L=o;return null!==t&&(t=function(t,e,n){for(var r=e,i=0;n.length>i;i++)r={type:"AdditiveExpression",operator:n[i][1],left:r,right:n[i][3]};return r}(a,t[0],t[1])),null===t&&(L=a),t}function R(){var t;return 43===e.charCodeAt(L)?(t="+",L++):(t=null,0===M&&r('"+"')),null===t&&(45===e.charCodeAt(L)?(t="-",L++):(t=null,0===M&&r('"-"'))),t}function k(){var t,e,n,r,i,s,a,o,l;if(a=L,o=L,t=O(),null!==t){for(e=[],l=L,n=m(),null!==n?(r=z(),null!==r?(i=m(),null!==i?(s=O(),null!==s?n=[n,r,i,s]:(n=null,L=l)):(n=null,L=l)):(n=null,L=l)):(n=null,L=l);null!==n;)e.push(n),l=L,n=m(),null!==n?(r=z(),null!==r?(i=m(),null!==i?(s=O(),null!==s?n=[n,r,i,s]:(n=null,L=l)):(n=null,L=l)):(n=null,L=l)):(n=null,L=l);null!==e?t=[t,e]:(t=null,L=o)}else t=null,L=o;return null!==t&&(t=function(t,e,n){for(var r=e,i=0;n.length>i;i++)r={type:"Inequality",operator:n[i][1],left:r,right:n[i][3]};return r}(a,t[0],t[1])),null===t&&(L=a),t}function z(){var t;return"<="===e.substr(L,2)?(t="<=",L+=2):(t=null,0===M&&r('"<="')),null===t&&(">="===e.substr(L,2)?(t=">=",L+=2):(t=null,0===M&&r('">="')),null===t&&(60===e.charCodeAt(L)?(t="<",L++):(t=null,0===M&&r('"<"')),null===t&&(62===e.charCodeAt(L)?(t=">",L++):(t=null,0===M&&r('">"'))))),t}function H(){var t,n,i,s,a,o,l,u,c;if(l=L,u=L,t=k(),null!==t){for(n=[],c=L,i=m(),null!==i?("=="===e.substr(L,2)?(s="==",L+=2):(s=null,0===M&&r('"=="')),null!==s?(a=m(),null!==a?(o=k(),null!==o?i=[i,s,a,o]:(i=null,L=c)):(i=null,L=c)):(i=null,L=c)):(i=null,L=c);null!==i;)n.push(i),c=L,i=m(),null!==i?("=="===e.substr(L,2)?(s="==",L+=2):(s=null,0===M&&r('"=="')),null!==s?(a=m(),null!==a?(o=k(),null!==o?i=[i,s,a,o]:(i=null,L=c)):(i=null,L=c)):(i=null,L=c)):(i=null,L=c);null!==n?t=[t,n]:(t=null,L=u)}else t=null,L=u;return null!==t&&(t=function(t,e,n){for(var r=e,i=0;n.length>i;i++)r={type:"Equality",operator:n[i][1],left:r,right:n[i][3]};return r}(l,t[0],t[1])),null===t&&(L=l),t}function N(t){t.sort();for(var e=null,n=[],r=0;t.length>r;r++)t[r]!==e&&(n.push(t[r]),e=t[r]);return n}function j(){for(var t=1,n=1,r=!1,i=0;Math.max(L,F)>i;i++){var s=e.charAt(i);"\n"===s?(r||t++,n=1,r=!1):"\r"===s||"\u2028"===s||"\u2029"===s?(t++,n=1,r=!0):(n++,r=!1)}return{line:t,column:n}}var q={start:i,Statement:s,SourceCharacter:a,IdentifierStart:o,WhiteSpace:l,LineTerminator:u,LineTerminatorSequence:c,EOS:h,EOF:f,Comment:p,MultiLineComment:d,MultiLineCommentNoLineTerminator:v,SingleLineComment:g,_:b,__:m,Literal:y,Integer:w,Real:_,SignedInteger:E,Identifier:x,IdentifierName:A,PrimaryExpression:V,UnaryExpression:C,UnaryOperator:S,MultiplicativeExpression:T,MultiplicativeOperator:I,AdditiveExpression:O,AdditiveOperator:R,InequalityExpression:k,InequalityOperator:z,LinearExpression:H};if(void 0!==n){if(void 0===q[n])throw Error("Invalid rule name: "+t(n)+".")}else n="start";var L=0,M=0,F=0,P=[],W=q[n]();if(null===W||L!==e.length){var D=Math.max(L,F),U=e.length>D?e.charAt(D):null,Z=j();throw new this.SyntaxError(N(P),U,D,Z.line,Z.column)}return W},toSource:function(){return this._source}};return e.SyntaxError=function(e,n,r,i,s){function a(e,n){var r,i;switch(e.length){case 0:r="end of input";break;case 1:r=e[0];break;default:r=e.slice(0,e.length-1).join(", ")+" or "+e[e.length-1]}return i=n?t(n):"end of input","Expected "+r+" but "+i+" found."}this.name="SyntaxError",this.expected=e,this.found=n,this.message=a(e,n),this.offset=r,this.line=i,this.column=s},e.SyntaxError.prototype=Error.prototype,e}()}).call("undefined"!=typeof e?e.compiled=e:this)},{}]},{},[1])(1)})},function(t,e,n){e=t.exports=n(3)(),e.push([t.id,"html{box-sizing:border-box}body,html{padding:0;margin:0}*,:after,:before{box-sizing:inherit}",""])},function(t,e){t.exports=function(){var t=[];return t.toString=function(){for(var t=[],e=0;e{
283 | return config.viewName !== viewName
284 | });
285 |
286 | updateLayout();
287 |
288 | }
289 |
290 | function getContraints(viewName, view){
291 | let viewKey = !!viewName && !!view ? view.props.viewKey : void(0);
292 | if(viewKey === void(0) ||
293 | !(viewName in constraints) ||
294 | !(viewKey in constraints[viewName])){
295 | return void(0);
296 | }
297 | return constraints[viewName][viewKey].style;
298 | }
299 |
300 | function getCurrentFormat(viewName){
301 | if(viewName === void(0) ||
302 | viewName === null ||
303 | !(viewName in constraints)){
304 | return void(0);
305 | }
306 | return constraints[viewName].currentFormat;
307 | }
308 |
309 | window.addEventListener('resize', updateLayout);
310 |
311 | //Layout Component
312 | export default class AutoLayout extends React.Component {
313 | constructor(props){
314 | super(props);
315 | }
316 |
317 | componentWillMount(){
318 | addVisualFormat(this, {
319 | query: this.props.query,
320 | layouts: this.props.layout
321 | });
322 | }
323 |
324 | componentWillUnmount() {
325 | removeVisualFormat(this.props.name);
326 | }
327 |
328 | render(){
329 | let viewName = this.props.name;
330 | let htmlTag = this.props.htmlTag || 'div';
331 | let newChildren = React.Children.map(this.props.children, function(child) {
332 | let constraints = getContraints(viewName, child);
333 | //check to see if the element was specified in the layout.
334 | if(constraints === void(0)) {
335 | return child;
336 | }
337 | if('formatStyle' in child.props){
338 | let currentFormat = getCurrentFormat(viewName);
339 | if(currentFormat !== void(0) && (currentFormat in child.props.formatStyle)){
340 | return React.cloneElement(child, {
341 | style: merge(child.props.style, child.props.formatStyle[currentFormat], constraints)
342 | });
343 | }
344 | }
345 | return React.cloneElement(child, { style: merge(child.props.style, constraints) });
346 | });
347 | return React.createElement(htmlTag, null, newChildren);
348 | }
349 | }
350 |
351 | AutoLayout.propTypes = {
352 | name: React.PropTypes.string.isRequired,
353 | query: React.PropTypes.func.isRequried,
354 | layout: React.PropTypes.arrayOf(React.PropTypes.shape({
355 | name: React.PropTypes.string.isRequired,
356 | constrainTo: React.PropTypes.oneOfType([
357 | React.PropTypes.arrayOf(React.PropTypes.number),
358 | React.PropTypes.string
359 | ]).isRequired,
360 | format: React.PropTypes.arrayOf(React.PropTypes.string).isRequired
361 | })
362 | ).isRequired,
363 | htmlTag: React.PropTypes.string,
364 | children: React.PropTypes.any.isRequired
365 | }
366 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-autolayout",
3 | "version": "0.1.4-alpha3",
4 | "description": "Auto layout for React using Apple's Visual Format Language",
5 | "main": "./build/react-autolayout.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [
10 | "react",
11 | "autolayout",
12 | "visual format",
13 | "auto layout"
14 | ],
15 | "homepage": "https://github.com/fattenap/react-autolayout",
16 | "author": "Frank Panetta",
17 | "repository": {
18 | "type": "git",
19 | "url": "https://github.com/fattenap/react-autolayout.git"
20 | },
21 | "devDependencies": {
22 | "babel-core": "^5.6.15",
23 | "babel-loader": "^5.2.2",
24 | "css-loader": "^0.18.0",
25 | "style-loader": "^0.12.3",
26 | "webpack": "^1.10.0",
27 | "webpack-dev-server": "^1.10.1"
28 | },
29 | "license": "MIT",
30 | "dependencies": {
31 | "autolayout": "^0.5.1"
32 | },
33 | "peerDependencies": {
34 | "react": "0.14.0-rc1",
35 | "react-dom": "0.14.0-rc1"
36 | }
37 | }
--------------------------------------------------------------------------------
/styles.css:
--------------------------------------------------------------------------------
1 | html {
2 | box-sizing: border-box;
3 | }
4 |
5 | html, body {
6 | padding: 0;
7 | margin: 0;
8 | }
9 |
10 | *, *:before, *:after {
11 | box-sizing: inherit;
12 | }
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | var webpack = require('webpack');
2 | var path = require('path');
3 |
4 | var config = {
5 | devtool: 'sourcemap',
6 | entry: {
7 | index: './index.js'
8 | },
9 | output: {
10 | path: path.join(__dirname, 'build'),
11 | publicPath: 'build/',
12 | filename: 'react-autolayout.js',
13 | sourceMapFilename: 'react-autolayout.map',
14 | library: 'ReactAutoLayout',
15 | libraryTarget: 'umd',
16 | },
17 | module: {
18 | loaders: [{
19 | test: /\.(js|jsx)/,
20 | loader: 'babel',
21 | exclude: /node_modules/
22 | }, {
23 | test: /\.css$/, loader: "style-loader!css-loader"
24 | }],
25 | },
26 | resolve: {
27 | extensions: ['', '.js']
28 | },
29 | externals: {
30 | 'react': {
31 | root: 'React',
32 | commonjs2: 'react',
33 | commonjs: 'react',
34 | amd: 'react'
35 | }
36 | },
37 | };
38 |
39 | module.exports = config;
--------------------------------------------------------------------------------