├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── example ├── dist │ ├── JSXTransformer.js │ ├── app.css │ ├── app.js │ ├── bundle.js │ ├── codemirror.css │ ├── codemirror.js │ ├── common.js │ ├── index.html │ └── javascript.js └── src │ ├── app.js │ ├── app.less │ └── index.html ├── gulpfile.js ├── package.json └── src ├── Boron.js ├── DropModal.js ├── FadeModal.js ├── FlyModal.js ├── OutlineModal.js ├── ScaleModal.js ├── WaveModal.js └── modalFactory.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Coverage tools 11 | lib-cov 12 | coverage 13 | 14 | # Compiled binary addons (http://nodejs.org/api/addons.html) 15 | build/Release 16 | 17 | # Dependency directory 18 | node_modules 19 | .idea 20 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | example 2 | src 3 | bower.json 4 | gulpfile.js 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-present Yuanyan Cao 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Boron [![npm version](https://badge.fury.io/js/boron.svg)](http://badge.fury.io/js/boron) 2 | ===== 3 | 4 | [![Pair on this](https://tf-assets-staging.s3.amazonaws.com/badges/thinkful_repo_badge.svg)](http://start.thinkful.com/react/?utm_source=github&utm_medium=badge&utm_campaign=boron) 5 | 6 | A collection of dialog animations with React.js. 7 | 8 | * React 0.14+ Use `boron 0.2` 9 | * React 0.12+ Use `boron 0.1` 10 | 11 | ## Demo & Examples 12 | 13 | Live demo: [yuanyan.github.io/boron](http://yuanyan.github.io/boron/) 14 | 15 | To build the examples locally, run: 16 | 17 | ``` 18 | npm install 19 | gulp dev 20 | ``` 21 | 22 | Then open [`localhost:9999`](http://localhost:9999) in a browser. 23 | 24 | ## Installation 25 | 26 | The easiest way to use `boron` is to install it from NPM and include it in your own React build process (using [Browserify](http://browserify.org), etc). 27 | 28 | You can also use the standalone build by including `dist/boron.js` in your page. If you use this, make sure you have already included React, and it is available as a global variable. 29 | 30 | ``` 31 | npm install boron --save 32 | ``` 33 | 34 | ## Usage 35 | 36 | ``` javascript 37 | var Modal = require('boron/DropModal'); 38 | var Example = React.createClass({ 39 | showModal: function(){ 40 | this.refs.modal.show(); 41 | }, 42 | hideModal: function(){ 43 | this.refs.modal.hide(); 44 | }, 45 | 46 | callback: function(event){ 47 | console.log(event); 48 | }, 49 | 50 | render: function() { 51 | return ( 52 |
53 | 54 | 55 |

I am a dialog

56 | 57 |
58 |
59 | ); 60 | } 61 | }); 62 | ``` 63 | 64 | ## Props 65 | 66 | * className - Add custom class name. 67 | * keyboard - Receive a callback function or a boolean to choose to close the modal when escape key is pressed. 68 | * backdrop - Includes a backdrop element. 69 | * closeOnClick - Close the backdrop element when clicked. 70 | * onShow - Show callback. 71 | * onHide - Hide callback. Argument is the source of the hide action, one of: 72 | * hide - hide() method is the cause of the hide. 73 | * toggle - toggle() method is the cause of the hide 74 | * keyboard - keyboard (escape key) is the cause of the hide 75 | * backdrop - backdrop click is the cause of the hide 76 | * [any] - custom argument passed by invoking code into the hide() method when called directly. 77 | * modalStyle - CSS styles to apply to the modal 78 | * backdropStyle - CSS styles to apply to the backdrop 79 | * contentStyle - CSS styles to apply to the modal's content 80 | 81 | Note: If the hide() method is called directly, a custom source string can be 82 | passed as the argument, as noted above. For example, this might be useful if 83 | if multiple actions could cause the hide and it was desirable to know which of those 84 | actions was the trigger for the given onHide callback). 85 | 86 | # Custom Styles 87 | Objects consisting of CSS properties/values can be passed as props to the Modal component. 88 | The values for the CSS properties will either add new properties or override the default property value set for that Modal type. 89 | 90 | Modal with 80% width: 91 | ``` javascript 92 | var Modal = require('boron/ScaleModal'); 93 | 94 | // Style object 95 | var modalStyle = { 96 | width: '80%' 97 | }; 98 | 99 | var Example = React.createClass({ 100 | showModal: function(){ 101 | this.refs.modal.show(); 102 | }, 103 | hideModal: function(){ 104 | this.refs.modal.hide(); 105 | }, 106 | render: function() { 107 | return ( 108 |
109 | 110 | 111 |

I am a dialog

112 | 113 |
114 |
115 | ); 116 | } 117 | }); 118 | ``` 119 | 120 | Red backdrop with a blue modal, rotated at 45 degrees: 121 | ``` javascript 122 | var Modal = require('boron/FlyModal'); 123 | 124 | // Individual styles for the modal, modal content, and backdrop 125 | var modalStyle = { 126 | transform: 'rotate(45deg) translateX(-50%)', 127 | }; 128 | 129 | var backdropStyle = { 130 | backgroundColor: 'red' 131 | }; 132 | 133 | var contentStyle = { 134 | backgroundColor: 'blue', 135 | height: '100%' 136 | }; 137 | 138 | var Example = React.createClass({ 139 | showModal: function(){ 140 | this.refs.modal.show(); 141 | }, 142 | hideModal: function(){ 143 | this.refs.modal.hide(); 144 | }, 145 | render: function() { 146 | return ( 147 |
148 | 149 | 150 |

I am a dialog

151 | 152 |
153 |
154 | ); 155 | } 156 | }); 157 | ``` 158 | 159 | 160 | ## Modals 161 | 162 | * DropModal 163 | * FadeModal 164 | * FlyModal 165 | * OutlineModal 166 | * ScaleModal 167 | * WaveModal 168 | 169 | ## Browser Support 170 | 171 | ![IE](https://raw.github.com/alrra/browser-logos/master/internet-explorer/internet-explorer_48x48.png) | ![Chrome](https://raw.github.com/alrra/browser-logos/master/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/firefox/firefox_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/opera/opera_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/safari/safari_48x48.png) 172 | --- | --- | --- | --- | --- | 173 | IE 10+ ✔ | Chrome 4.0+ ✔ | Firefox 16.0+ ✔ | Opera 15.0+ ✔ | Safari 4.0+ ✔ | 174 | 175 | ## License 176 | 177 | Boron is [MIT licensed](./LICENSE). 178 | -------------------------------------------------------------------------------- /example/dist/app.css: -------------------------------------------------------------------------------- 1 | *, 2 | *:before, 3 | *:after { 4 | -webkit-box-sizing: inherit; 5 | -moz-box-sizing: inherit; 6 | box-sizing: inherit; 7 | } 8 | html { 9 | -ms-text-size-adjust: 100%; 10 | -webkit-text-size-adjust: 100%; 11 | overflow-x: hidden; 12 | } 13 | body { 14 | background: #eee; 15 | font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 16 | margin: 0; 17 | line-height: 1.5; 18 | color: #2b303b; 19 | -webkit-box-sizing: border-box; 20 | -moz-box-sizing: border-box; 21 | box-sizing: border-box; 22 | -moz-osx-font-smoothing: grayscale; 23 | -webkit-font-smoothing: antialiased; 24 | } 25 | h1 { 26 | font-size: 2em; 27 | font-weight: 500; 28 | margin: 1em auto; 29 | text-align: center; 30 | } 31 | h2 { 32 | font-size: 32px; 33 | font-size: 2rem; 34 | } 35 | .center { 36 | text-align: center; 37 | } 38 | .example { 39 | margin-bottom: 20px; 40 | } 41 | .playground:after { 42 | content: ""; 43 | display: table; 44 | clear: both; 45 | background: white; 46 | } 47 | .playgroundTab { 48 | border-bottom: none !important; 49 | border-radius: 3px 3px 0 0; 50 | padding: 6px 8px; 51 | font-size: 12px; 52 | font-weight: bold; 53 | color: #C94E50; 54 | display: inline-block; 55 | cursor: pointer; 56 | } 57 | .playgroundCode, 58 | .playgroundTab, 59 | .playgroundPreview { 60 | border: 1px solid rgba(16, 16, 16, 0.1); 61 | background: white; 62 | } 63 | .playgroundCode, 64 | .playgroundPreview { 65 | display: block; 66 | border-radius: 0 3px 3px 3px; 67 | } 68 | /* Layout */ 69 | .container { 70 | margin: 0 auto; 71 | max-width: 960px; 72 | padding-left: 1em; 73 | padding-right: 1em; 74 | } 75 | .row { 76 | padding: 20px 0; 77 | padding: 1rem 0; 78 | } 79 | /* header */ 80 | header { 81 | position: relative; 82 | padding-top: 36px; 83 | padding-bottom: 45px; 84 | margin-bottom: 3rem; 85 | } 86 | header:before { 87 | content: ""; 88 | background: #C94E50; 89 | box-shadow: 0 15px 0 #B64042, 0 30px 0 #A33739, 0 45px 0 #942527; 90 | -webkit-transform: rotate(-5deg); 91 | -moz-transform: rotate(-5deg); 92 | transform: rotate(-5deg); 93 | margin-top: -170px; 94 | position: absolute; 95 | top: 0; 96 | right: -20%; 97 | left: -20%; 98 | bottom: 0; 99 | } 100 | .logo { 101 | font-size: 24px; 102 | font-size: 1.5rem; 103 | line-height: 1; 104 | height: 230px; 105 | margin: 0 auto; 106 | padding: 15px; 107 | position: relative; 108 | text-align: center; 109 | width: 230px; 110 | background: #C94E50; 111 | color: #fff; 112 | border: 22px solid #fff; 113 | text-rendering: optimizeLegibility; 114 | } 115 | .logo:before { 116 | content: "B"; 117 | font-size: 140px; 118 | position: absolute; 119 | right: 0; 120 | bottom: 0; 121 | left: 0; 122 | line-height: 1; 123 | pointer-events: none; 124 | } 125 | main { 126 | padding-top: 36px; 127 | } 128 | .installer { 129 | display: inline-block; 130 | background: #2b303b; 131 | border: 1px solid #16191F; 132 | color: #fff; 133 | font-family: "Source Code Pro", monospace; 134 | font-size: 18px; 135 | line-height: 1.2; 136 | margin: 0 auto; 137 | padding: 16px 32px; 138 | } 139 | footer { 140 | background: #2b303b; 141 | color: #fff; 142 | } 143 | footer a { 144 | font-weight: 700; 145 | color: #C94E50; 146 | text-decoration: none; 147 | } 148 | footer a:hover, 149 | footer a:focus { 150 | color: #fff; 151 | } 152 | .CodeMirror { 153 | height: 800px; 154 | } 155 | .blur { 156 | -webkit-animation: blur 10s 3s ease-out infinite; 157 | } 158 | @-webkit-keyframes blur { 159 | from { 160 | transform: scaleX(1.1) scaleY(1.1); 161 | opacity: 0.8; 162 | } 163 | } 164 | .demo-enter { 165 | opacity: 0.01; 166 | height: 0px; 167 | padding: 0px 10px !important; 168 | transition: opacity 500ms ease-out, padding 500ms ease-out, height 500ms ease-out; 169 | } 170 | .demo-enter.demo-enter-active { 171 | opacity: 1; 172 | height: 16px; 173 | padding: 10px !important; 174 | } 175 | .demo-leave { 176 | opacity: 1; 177 | height: 16px; 178 | transition: opacity 500ms ease-out, padding 500ms ease-out, height 500ms ease-out; 179 | } 180 | .demo-leave.demo-leave-active { 181 | opacity: 0; 182 | height: 0px; 183 | padding: 0px 10px !important; 184 | } 185 | -------------------------------------------------------------------------------- /example/dist/app.js: -------------------------------------------------------------------------------- 1 | require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o WebkitTransition) 61 | module.exports = function(prop, isSupportTest) { 62 | 63 | var vendorProp; 64 | if (prop in builtinStyle) return prop; 65 | 66 | var UpperProp = prop.charAt(0).toUpperCase() + prop.substr(1); 67 | 68 | if (domVendorPrefix) { 69 | 70 | vendorProp = domVendorPrefix + UpperProp; 71 | if (vendorProp in builtinStyle) { 72 | return vendorProp; 73 | } 74 | } else { 75 | 76 | for (var i = 0; i < prefixes.length; ++i) { 77 | vendorProp = prefixes[i] + UpperProp; 78 | if (vendorProp in builtinStyle) { 79 | domVendorPrefix = prefixes[i]; 80 | return vendorProp; 81 | } 82 | } 83 | } 84 | 85 | // if support test, not fallback to origin prop name 86 | if (!isSupportTest) { 87 | return prop; 88 | } 89 | 90 | } 91 | 92 | },{"./builtinStyle":2}],5:[function(require,module,exports){ 93 | 'use strict'; 94 | 95 | var insertRule = require('./insertRule'); 96 | var vendorPrefix = require('./getVendorPrefix')(); 97 | var index = 0; 98 | 99 | module.exports = function(keyframes) { 100 | // random name 101 | var name = 'anim_' + (++index) + (+new Date); 102 | var css = "@" + vendorPrefix + "keyframes " + name + " {"; 103 | 104 | for (var key in keyframes) { 105 | css += key + " {"; 106 | 107 | for (var property in keyframes[key]) { 108 | var part = ":" + keyframes[key][property] + ";"; 109 | // We do vendor prefix for every property 110 | css += vendorPrefix + property + part; 111 | css += property + part; 112 | } 113 | 114 | css += "}"; 115 | } 116 | 117 | css += "}"; 118 | 119 | insertRule(css); 120 | 121 | return name 122 | } 123 | 124 | },{"./getVendorPrefix":3,"./insertRule":6}],6:[function(require,module,exports){ 125 | 'use strict'; 126 | 127 | var extraSheet; 128 | 129 | module.exports = function(css) { 130 | 131 | if (!extraSheet) { 132 | // First time, create an extra stylesheet for adding rules 133 | extraSheet = document.createElement('style'); 134 | document.getElementsByTagName('head')[0].appendChild(extraSheet); 135 | // Keep reference to actual StyleSheet object (`styleSheet` for IE < 9) 136 | extraSheet = extraSheet.sheet || extraSheet.styleSheet; 137 | } 138 | 139 | var index = (extraSheet.cssRules || extraSheet.rules).length; 140 | extraSheet.insertRule(css, index); 141 | 142 | return extraSheet; 143 | } 144 | 145 | },{}],7:[function(require,module,exports){ 146 | 'use strict'; 147 | 148 | /** 149 | * EVENT_NAME_MAP is used to determine which event fired when a 150 | * transition/animation ends, based on the style property used to 151 | * define that event. 152 | */ 153 | var EVENT_NAME_MAP = { 154 | transitionend: { 155 | 'transition': 'transitionend', 156 | 'WebkitTransition': 'webkitTransitionEnd', 157 | 'MozTransition': 'mozTransitionEnd', 158 | 'OTransition': 'oTransitionEnd', 159 | 'msTransition': 'MSTransitionEnd' 160 | }, 161 | 162 | animationend: { 163 | 'animation': 'animationend', 164 | 'WebkitAnimation': 'webkitAnimationEnd', 165 | 'MozAnimation': 'mozAnimationEnd', 166 | 'OAnimation': 'oAnimationEnd', 167 | 'msAnimation': 'MSAnimationEnd' 168 | } 169 | }; 170 | 171 | var endEvents = []; 172 | 173 | function detectEvents() { 174 | var testEl = document.createElement('div'); 175 | var style = testEl.style; 176 | 177 | // On some platforms, in particular some releases of Android 4.x, 178 | // the un-prefixed "animation" and "transition" properties are defined on the 179 | // style object but the events that fire will still be prefixed, so we need 180 | // to check if the un-prefixed events are useable, and if not remove them 181 | // from the map 182 | if (!('AnimationEvent' in window)) { 183 | delete EVENT_NAME_MAP.animationend.animation; 184 | } 185 | 186 | if (!('TransitionEvent' in window)) { 187 | delete EVENT_NAME_MAP.transitionend.transition; 188 | } 189 | 190 | for (var baseEventName in EVENT_NAME_MAP) { 191 | var baseEvents = EVENT_NAME_MAP[baseEventName]; 192 | for (var styleName in baseEvents) { 193 | if (styleName in style) { 194 | endEvents.push(baseEvents[styleName]); 195 | break; 196 | } 197 | } 198 | } 199 | } 200 | 201 | if (typeof window !== 'undefined') { 202 | detectEvents(); 203 | } 204 | 205 | 206 | // We use the raw {add|remove}EventListener() call because EventListener 207 | // does not know how to remove event listeners and we really should 208 | // clean up. Also, these events are not triggered in older browsers 209 | // so we should be A-OK here. 210 | 211 | function addEventListener(node, eventName, eventListener) { 212 | node.addEventListener(eventName, eventListener, false); 213 | } 214 | 215 | function removeEventListener(node, eventName, eventListener) { 216 | node.removeEventListener(eventName, eventListener, false); 217 | } 218 | 219 | module.exports = { 220 | addEndEventListener: function(node, eventListener) { 221 | if (endEvents.length === 0) { 222 | // If CSS transitions are not supported, trigger an "end animation" 223 | // event immediately. 224 | window.setTimeout(eventListener, 0); 225 | return; 226 | } 227 | endEvents.forEach(function(endEvent) { 228 | addEventListener(node, endEvent, eventListener); 229 | }); 230 | }, 231 | 232 | removeEndEventListener: function(node, eventListener) { 233 | if (endEvents.length === 0) { 234 | return; 235 | } 236 | endEvents.forEach(function(endEvent) { 237 | removeEventListener(node, endEvent, eventListener); 238 | }); 239 | } 240 | }; 241 | 242 | },{}],8:[function(require,module,exports){ 243 | var modalFactory = require('./modalFactory'); 244 | var insertKeyframesRule = require('domkit/insertKeyframesRule'); 245 | var appendVendorPrefix = require('domkit/appendVendorPrefix'); 246 | 247 | var animation = { 248 | show: { 249 | animationDuration: '0.4s', 250 | animationTimingFunction: 'cubic-bezier(0.7,0,0.3,1)' 251 | }, 252 | 253 | hide: { 254 | animationDuration: '0.4s', 255 | animationTimingFunction: 'cubic-bezier(0.7,0,0.3,1)' 256 | }, 257 | 258 | showModalAnimation: insertKeyframesRule({ 259 | '0%': { 260 | opacity: 0, 261 | transform: 'translate3d(-50%, -300px, 0)' 262 | }, 263 | '100%': { 264 | opacity: 1, 265 | transform: 'translate3d(-50%, -50%, 0)' 266 | } 267 | }), 268 | 269 | hideModalAnimation: insertKeyframesRule({ 270 | '0%': { 271 | opacity: 1, 272 | transform: 'translate3d(-50%, -50%, 0)' 273 | }, 274 | '100%': { 275 | opacity: 0, 276 | transform: 'translate3d(-50%, 100px, 0)' 277 | } 278 | }), 279 | 280 | showBackdropAnimation: insertKeyframesRule({ 281 | '0%': { 282 | opacity: 0 283 | }, 284 | '100%': { 285 | opacity: 0.9 286 | } 287 | }), 288 | 289 | hideBackdropAnimation: insertKeyframesRule({ 290 | '0%': { 291 | opacity: 0.9 292 | }, 293 | '100%': { 294 | opacity: 0 295 | } 296 | }), 297 | 298 | showContentAnimation: insertKeyframesRule({ 299 | '0%': { 300 | opacity: 0, 301 | transform: 'translate3d(0, -20px, 0)' 302 | }, 303 | '100%': { 304 | opacity: 1, 305 | transform: 'translate3d(0, 0, 0)' 306 | } 307 | }), 308 | 309 | hideContentAnimation: insertKeyframesRule({ 310 | '0%': { 311 | opacity: 1, 312 | transform: 'translate3d(0, 0, 0)' 313 | }, 314 | '100%': { 315 | opacity: 0, 316 | transform: 'translate3d(0, 50px, 0)' 317 | } 318 | }) 319 | }; 320 | 321 | var showAnimation = animation.show; 322 | var hideAnimation = animation.hide; 323 | var showModalAnimation = animation.showModalAnimation; 324 | var hideModalAnimation = animation.hideModalAnimation; 325 | var showBackdropAnimation = animation.showBackdropAnimation; 326 | var hideBackdropAnimation = animation.hideBackdropAnimation; 327 | var showContentAnimation = animation.showContentAnimation; 328 | var hideContentAnimation = animation.hideContentAnimation; 329 | 330 | module.exports = modalFactory({ 331 | getRef: function(willHidden) { 332 | return 'modal'; 333 | }, 334 | getModalStyle: function(willHidden) { 335 | return appendVendorPrefix({ 336 | position: "fixed", 337 | width: "500px", 338 | transform: "translate3d(-50%, -50%, 0)", 339 | top: "50%", 340 | left: "50%", 341 | backgroundColor: "white", 342 | zIndex: 1050, 343 | animationDuration: (willHidden ? hideAnimation : showAnimation).animationDuration, 344 | animationFillMode: 'forwards', 345 | animationName: willHidden ? hideModalAnimation : showModalAnimation, 346 | animationTimingFunction: (willHidden ? hideAnimation : showAnimation).animationTimingFunction 347 | }) 348 | }, 349 | getBackdropStyle: function(willHidden) { 350 | return appendVendorPrefix({ 351 | position: "fixed", 352 | top: 0, 353 | right: 0, 354 | bottom: 0, 355 | left: 0, 356 | zIndex: 1040, 357 | backgroundColor: "#373A47", 358 | animationDuration: (willHidden ? hideAnimation : showAnimation).animationDuration, 359 | animationFillMode: 'forwards', 360 | animationName: willHidden ? hideBackdropAnimation : showBackdropAnimation, 361 | animationTimingFunction: (willHidden ? hideAnimation : showAnimation).animationTimingFunction 362 | }); 363 | }, 364 | getContentStyle: function(willHidden) { 365 | return appendVendorPrefix({ 366 | margin: 0, 367 | opacity: 0, 368 | animationDuration: (willHidden ? hideAnimation : showAnimation).animationDuration, 369 | animationFillMode: 'forwards', 370 | animationDelay: '0.25s', 371 | animationName: showContentAnimation, 372 | animationTimingFunction: (willHidden ? hideAnimation : showAnimation).animationTimingFunction 373 | }) 374 | } 375 | }); 376 | 377 | },{"./modalFactory":14,"domkit/appendVendorPrefix":1,"domkit/insertKeyframesRule":5}],9:[function(require,module,exports){ 378 | var modalFactory = require('./modalFactory'); 379 | var insertKeyframesRule = require('domkit/insertKeyframesRule'); 380 | var appendVendorPrefix = require('domkit/appendVendorPrefix'); 381 | 382 | var animation = { 383 | show: { 384 | animationDuration: '0.3s', 385 | animationTimingFunction: 'ease-out' 386 | }, 387 | hide: { 388 | animationDuration: '0.3s', 389 | animationTimingFunction: 'ease-out' 390 | }, 391 | showContentAnimation: insertKeyframesRule({ 392 | '0%': { 393 | opacity: 0 394 | }, 395 | '100%': { 396 | opacity: 1 397 | } 398 | }), 399 | 400 | hideContentAnimation: insertKeyframesRule({ 401 | '0%': { 402 | opacity: 1 403 | }, 404 | '100%': { 405 | opacity: 0 406 | } 407 | }), 408 | 409 | showBackdropAnimation: insertKeyframesRule({ 410 | '0%': { 411 | opacity: 0 412 | }, 413 | '100%': { 414 | opacity: 0.9 415 | }, 416 | }), 417 | 418 | hideBackdropAnimation: insertKeyframesRule({ 419 | '0%': { 420 | opacity: 0.9 421 | }, 422 | '100%': { 423 | opacity: 0 424 | } 425 | }) 426 | }; 427 | 428 | var showAnimation = animation.show; 429 | var hideAnimation = animation.hide; 430 | var showContentAnimation = animation.showContentAnimation; 431 | var hideContentAnimation = animation.hideContentAnimation; 432 | var showBackdropAnimation = animation.showBackdropAnimation; 433 | var hideBackdropAnimation = animation.hideBackdropAnimation; 434 | 435 | module.exports = modalFactory({ 436 | getRef: function(willHidden) { 437 | return 'content'; 438 | }, 439 | getModalStyle: function(willHidden) { 440 | return appendVendorPrefix({ 441 | zIndex: 1050, 442 | position: "fixed", 443 | width: "500px", 444 | transform: "translate3d(-50%, -50%, 0)", 445 | top: "50%", 446 | left: "50%" 447 | }) 448 | }, 449 | getBackdropStyle: function(willHidden) { 450 | return appendVendorPrefix({ 451 | position: "fixed", 452 | top: 0, 453 | right: 0, 454 | bottom: 0, 455 | left: 0, 456 | zIndex: 1040, 457 | backgroundColor: "#373A47", 458 | animationFillMode: 'forwards', 459 | animationDuration: '0.3s', 460 | animationName: willHidden ? hideBackdropAnimation : showBackdropAnimation, 461 | animationTimingFunction: (willHidden ? hideAnimation : showAnimation).animationTimingFunction 462 | }); 463 | }, 464 | getContentStyle: function(willHidden) { 465 | return appendVendorPrefix({ 466 | margin: 0, 467 | backgroundColor: "white", 468 | animationDuration: (willHidden ? hideAnimation : showAnimation).animationDuration, 469 | animationFillMode: 'forwards', 470 | animationName: willHidden ? hideContentAnimation : showContentAnimation, 471 | animationTimingFunction: (willHidden ? hideAnimation : showAnimation).animationTimingFunction 472 | }) 473 | } 474 | }); 475 | 476 | },{"./modalFactory":14,"domkit/appendVendorPrefix":1,"domkit/insertKeyframesRule":5}],10:[function(require,module,exports){ 477 | var modalFactory = require('./modalFactory'); 478 | var insertKeyframesRule = require('domkit/insertKeyframesRule'); 479 | var appendVendorPrefix = require('domkit/appendVendorPrefix'); 480 | 481 | var animation = { 482 | show: { 483 | animationDuration: '0.5s', 484 | animationTimingFunction: 'ease-out' 485 | }, 486 | hide: { 487 | animationDuration: '0.5s', 488 | animationTimingFunction: 'ease-out' 489 | }, 490 | showContentAnimation: insertKeyframesRule({ 491 | 492 | '0%': { 493 | opacity: 0, 494 | transform: 'translate3d(calc(-100vw - 50%), 0, 0)' 495 | }, 496 | '50%': { 497 | opacity: 1, 498 | transform: 'translate3d(100px, 0, 0)' 499 | }, 500 | '100%': { 501 | opacity: 1, 502 | transform: 'translate3d(0, 0, 0)' 503 | } 504 | }), 505 | 506 | hideContentAnimation: insertKeyframesRule({ 507 | 508 | '0%': { 509 | opacity: 1, 510 | transform: 'translate3d(0, 0, 0)' 511 | }, 512 | '50%': { 513 | opacity: 1, 514 | transform: 'translate3d(-100px, 0, 0) scale3d(1.1, 1.1, 1)' 515 | }, 516 | '100%': { 517 | opacity: 0, 518 | transform: 'translate3d(calc(100vw + 50%), 0, 0)' 519 | }, 520 | }), 521 | 522 | showBackdropAnimation: insertKeyframesRule({ 523 | '0%': { 524 | opacity: 0 525 | }, 526 | '100%': { 527 | opacity: 0.9 528 | }, 529 | }), 530 | 531 | hideBackdropAnimation: insertKeyframesRule({ 532 | '0%': { 533 | opacity: 0.9 534 | }, 535 | '90%': { 536 | opactiy: 0.9 537 | }, 538 | '100%': { 539 | opacity: 0 540 | } 541 | }) 542 | }; 543 | 544 | var showAnimation = animation.show; 545 | var hideAnimation = animation.hide; 546 | var showContentAnimation = animation.showContentAnimation; 547 | var hideContentAnimation = animation.hideContentAnimation; 548 | var showBackdropAnimation = animation.showBackdropAnimation; 549 | var hideBackdropAnimation = animation.hideBackdropAnimation; 550 | 551 | module.exports = modalFactory({ 552 | getRef: function(willHidden) { 553 | return 'content'; 554 | }, 555 | getModalStyle: function(willHidden) { 556 | return appendVendorPrefix({ 557 | zIndex: 1050, 558 | position: "fixed", 559 | width: "500px", 560 | transform: "translate3d(-50%, -50%, 0)", 561 | top: "50%", 562 | left: "50%" 563 | }) 564 | }, 565 | getBackdropStyle: function(willHidden) { 566 | return appendVendorPrefix({ 567 | position: "fixed", 568 | top: 0, 569 | right: 0, 570 | bottom: 0, 571 | left: 0, 572 | zIndex: 1040, 573 | backgroundColor: "#373A47", 574 | animationFillMode: 'forwards', 575 | animationDuration: '0.3s', 576 | animationName: willHidden ? hideBackdropAnimation : showBackdropAnimation, 577 | animationTimingFunction: (willHidden ? hideAnimation : showAnimation).animationTimingFunction 578 | }); 579 | }, 580 | getContentStyle: function(willHidden) { 581 | return appendVendorPrefix({ 582 | margin: 0, 583 | backgroundColor: "white", 584 | animationDuration: (willHidden ? hideAnimation : showAnimation).animationDuration, 585 | animationFillMode: 'forwards', 586 | animationName: willHidden ? hideContentAnimation : showContentAnimation, 587 | animationTimingFunction: (willHidden ? hideAnimation : showAnimation).animationTimingFunction 588 | }) 589 | } 590 | }); 591 | 592 | },{"./modalFactory":14,"domkit/appendVendorPrefix":1,"domkit/insertKeyframesRule":5}],11:[function(require,module,exports){ 593 | var React = require('react'); 594 | var modalFactory = require('./modalFactory'); 595 | var insertKeyframesRule = require('domkit/insertKeyframesRule'); 596 | var appendVendorPrefix = require('domkit/appendVendorPrefix'); 597 | 598 | var animation = { 599 | show: { 600 | animationDuration: '0.8s', 601 | animationTimingFunction: 'cubic-bezier(0.6,0,0.4,1)' 602 | }, 603 | hide: { 604 | animationDuration: '0.4s', 605 | animationTimingFunction: 'ease-out' 606 | }, 607 | showContentAnimation: insertKeyframesRule({ 608 | '0%': { 609 | opacity: 0, 610 | }, 611 | '40%':{ 612 | opacity: 0 613 | }, 614 | '100%': { 615 | opacity: 1, 616 | } 617 | }), 618 | 619 | hideContentAnimation: insertKeyframesRule({ 620 | '0%': { 621 | opacity: 1 622 | }, 623 | '100%': { 624 | opacity: 0, 625 | } 626 | }), 627 | 628 | showBackdropAnimation: insertKeyframesRule({ 629 | '0%': { 630 | opacity: 0 631 | }, 632 | '100%': { 633 | opacity: 0.9 634 | }, 635 | }), 636 | 637 | hideBackdropAnimation: insertKeyframesRule({ 638 | '0%': { 639 | opacity: 0.9 640 | }, 641 | '100%': { 642 | opacity: 0 643 | } 644 | }) 645 | }; 646 | 647 | var showAnimation = animation.show; 648 | var hideAnimation = animation.hide; 649 | var showContentAnimation = animation.showContentAnimation; 650 | var hideContentAnimation = animation.hideContentAnimation; 651 | var showBackdropAnimation = animation.showBackdropAnimation; 652 | var hideBackdropAnimation = animation.hideBackdropAnimation; 653 | 654 | module.exports = modalFactory({ 655 | getRef: function(willHidden) { 656 | return 'content'; 657 | }, 658 | getSharp: function(willHidden) { 659 | var strokeDashLength = 1680; 660 | 661 | var showSharpAnimation = insertKeyframesRule({ 662 | '0%': { 663 | 'stroke-dashoffset': strokeDashLength 664 | }, 665 | '100%': { 666 | 'stroke-dashoffset': 0 667 | }, 668 | }); 669 | 670 | 671 | var sharpStyle = { 672 | position: 'absolute', 673 | width: 'calc(100%)', 674 | height: 'calc(100%)', 675 | zIndex: '-1' 676 | }; 677 | 678 | var rectStyle = appendVendorPrefix({ 679 | animationDuration: willHidden? '0.4s' :'0.8s', 680 | animationFillMode: 'forwards', 681 | animationName: willHidden? hideContentAnimation: showSharpAnimation, 682 | stroke: '#ffffff', 683 | strokeWidth: '2px', 684 | strokeDasharray: strokeDashLength 685 | }); 686 | 687 | return React.createElement("div", {style: sharpStyle}, 688 | React.createElement("svg", { 689 | xmlns: "http://www.w3.org/2000/svg", 690 | width: "100%", 691 | height: "100%", 692 | viewBox: "0 0 496 136", 693 | preserveAspectRatio: "none"}, 694 | React.createElement("rect", {style: rectStyle, 695 | x: "2", 696 | y: "2", 697 | fill: "none", 698 | width: "492", 699 | height: "132"}) 700 | ) 701 | ) 702 | }, 703 | getModalStyle: function(willHidden) { 704 | return appendVendorPrefix({ 705 | zIndex: 1050, 706 | position: "fixed", 707 | width: "500px", 708 | transform: "translate3d(-50%, -50%, 0)", 709 | top: "50%", 710 | left: "50%" 711 | }) 712 | }, 713 | getBackdropStyle: function(willHidden) { 714 | return appendVendorPrefix({ 715 | position: "fixed", 716 | top: 0, 717 | right: 0, 718 | bottom: 0, 719 | left: 0, 720 | zIndex: 1040, 721 | backgroundColor: "#373A47", 722 | animationFillMode: 'forwards', 723 | animationDuration: '0.4s', 724 | animationName: willHidden ? hideBackdropAnimation : showBackdropAnimation, 725 | animationTimingFunction: (willHidden ? hideAnimation : showAnimation).animationTimingFunction 726 | }); 727 | }, 728 | getContentStyle: function(willHidden) { 729 | return appendVendorPrefix({ 730 | margin: 0, 731 | backgroundColor: "white", 732 | animationDuration: (willHidden ? hideAnimation : showAnimation).animationDuration, 733 | animationFillMode: 'forwards', 734 | animationName: willHidden ? hideContentAnimation : showContentAnimation, 735 | animationTimingFunction: (willHidden ? hideAnimation : showAnimation).animationTimingFunction 736 | }) 737 | } 738 | }); 739 | 740 | },{"./modalFactory":14,"domkit/appendVendorPrefix":1,"domkit/insertKeyframesRule":5,"react":undefined}],12:[function(require,module,exports){ 741 | var modalFactory = require('./modalFactory'); 742 | var insertKeyframesRule = require('domkit/insertKeyframesRule'); 743 | var appendVendorPrefix = require('domkit/appendVendorPrefix'); 744 | 745 | var animation = { 746 | show: { 747 | animationDuration: '0.4s', 748 | animationTimingFunction: 'cubic-bezier(0.6,0,0.4,1)' 749 | }, 750 | hide: { 751 | animationDuration: '0.4s', 752 | animationTimingFunction: 'ease-out' 753 | }, 754 | showContentAnimation: insertKeyframesRule({ 755 | '0%': { 756 | opacity: 0, 757 | transform: 'scale3d(0, 0, 1)' 758 | }, 759 | '100%': { 760 | opacity: 1, 761 | transform: 'scale3d(1, 1, 1)' 762 | } 763 | }), 764 | 765 | hideContentAnimation: insertKeyframesRule({ 766 | '0%': { 767 | opacity: 1 768 | }, 769 | '100%': { 770 | opacity: 0, 771 | transform: 'scale3d(0.5, 0.5, 1)' 772 | } 773 | }), 774 | 775 | showBackdropAnimation: insertKeyframesRule({ 776 | '0%': { 777 | opacity: 0 778 | }, 779 | '100%': { 780 | opacity: 0.9 781 | }, 782 | }), 783 | 784 | hideBackdropAnimation: insertKeyframesRule({ 785 | '0%': { 786 | opacity: 0.9 787 | }, 788 | '100%': { 789 | opacity: 0 790 | } 791 | }) 792 | }; 793 | 794 | var showAnimation = animation.show; 795 | var hideAnimation = animation.hide; 796 | var showContentAnimation = animation.showContentAnimation; 797 | var hideContentAnimation = animation.hideContentAnimation; 798 | var showBackdropAnimation = animation.showBackdropAnimation; 799 | var hideBackdropAnimation = animation.hideBackdropAnimation; 800 | 801 | module.exports = modalFactory({ 802 | getRef: function(willHidden) { 803 | return 'content'; 804 | }, 805 | getModalStyle: function(willHidden) { 806 | return appendVendorPrefix({ 807 | zIndex: 1050, 808 | position: "fixed", 809 | width: "500px", 810 | transform: "translate3d(-50%, -50%, 0)", 811 | top: "50%", 812 | left: "50%" 813 | }) 814 | }, 815 | getBackdropStyle: function(willHidden) { 816 | return appendVendorPrefix({ 817 | position: "fixed", 818 | top: 0, 819 | right: 0, 820 | bottom: 0, 821 | left: 0, 822 | zIndex: 1040, 823 | backgroundColor: "#373A47", 824 | animationFillMode: 'forwards', 825 | animationDuration: '0.4s', 826 | animationName: willHidden ? hideBackdropAnimation : showBackdropAnimation, 827 | animationTimingFunction: (willHidden ? hideAnimation : showAnimation).animationTimingFunction 828 | }); 829 | }, 830 | getContentStyle: function(willHidden) { 831 | return appendVendorPrefix({ 832 | margin: 0, 833 | backgroundColor: "white", 834 | animationDuration: (willHidden ? hideAnimation : showAnimation).animationDuration, 835 | animationFillMode: 'forwards', 836 | animationName: willHidden ? hideContentAnimation : showContentAnimation, 837 | animationTimingFunction: (willHidden ? hideAnimation : showAnimation).animationTimingFunction 838 | }) 839 | } 840 | }); 841 | 842 | },{"./modalFactory":14,"domkit/appendVendorPrefix":1,"domkit/insertKeyframesRule":5}],13:[function(require,module,exports){ 843 | var modalFactory = require('./modalFactory'); 844 | var insertKeyframesRule = require('domkit/insertKeyframesRule'); 845 | var appendVendorPrefix = require('domkit/appendVendorPrefix'); 846 | 847 | var animation = { 848 | show: { 849 | animationDuration: '1s', 850 | animationTimingFunction: 'linear' 851 | }, 852 | hide: { 853 | animationDuration: '0.3s', 854 | animationTimingFunction: 'ease-out' 855 | }, 856 | showContentAnimation: insertKeyframesRule({ 857 | '0%': { 858 | opacity: 0, 859 | transform: 'matrix3d(0.7, 0, 0, 0, 0, 0.7, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 860 | }, 861 | '2.083333%': { 862 | transform: 'matrix3d(0.75266, 0, 0, 0, 0, 0.76342, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 863 | }, 864 | '4.166667%': { 865 | transform: 'matrix3d(0.81071, 0, 0, 0, 0, 0.84545, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 866 | }, 867 | '6.25%': { 868 | transform: 'matrix3d(0.86808, 0, 0, 0, 0, 0.9286, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 869 | }, 870 | '8.333333%': { 871 | transform: 'matrix3d(0.92038, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 872 | }, 873 | '10.416667%': { 874 | transform: 'matrix3d(0.96482, 0, 0, 0, 0, 1.05202, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 875 | }, 876 | '12.5%': { 877 | transform: 'matrix3d(1, 0, 0, 0, 0, 1.08204, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 878 | }, 879 | '14.583333%': { 880 | transform: 'matrix3d(1.02563, 0, 0, 0, 0, 1.09149, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 881 | }, 882 | '16.666667%': { 883 | transform: 'matrix3d(1.04227, 0, 0, 0, 0, 1.08453, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 884 | }, 885 | '18.75%': { 886 | transform: 'matrix3d(1.05102, 0, 0, 0, 0, 1.06666, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 887 | }, 888 | '20.833333%': { 889 | transform: 'matrix3d(1.05334, 0, 0, 0, 0, 1.04355, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 890 | }, 891 | '22.916667%': { 892 | transform: 'matrix3d(1.05078, 0, 0, 0, 0, 1.02012, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 893 | }, 894 | '25%': { 895 | transform: 'matrix3d(1.04487, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 896 | }, 897 | '27.083333%': { 898 | transform: 'matrix3d(1.03699, 0, 0, 0, 0, 0.98534, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 899 | }, 900 | '29.166667%': { 901 | transform: 'matrix3d(1.02831, 0, 0, 0, 0, 0.97688, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 902 | }, 903 | '31.25%': { 904 | transform: 'matrix3d(1.01973, 0, 0, 0, 0, 0.97422, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 905 | }, 906 | '33.333333%': { 907 | transform: 'matrix3d(1.01191, 0, 0, 0, 0, 0.97618, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 908 | }, 909 | '35.416667%': { 910 | transform: 'matrix3d(1.00526, 0, 0, 0, 0, 0.98122, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 911 | }, 912 | '37.5%': { 913 | transform: 'matrix3d(1, 0, 0, 0, 0, 0.98773, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 914 | }, 915 | '39.583333%': { 916 | transform: 'matrix3d(0.99617, 0, 0, 0, 0, 0.99433, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 917 | }, 918 | '41.666667%': { 919 | transform: 'matrix3d(0.99368, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 920 | }, 921 | '43.75%': { 922 | transform: 'matrix3d(0.99237, 0, 0, 0, 0, 1.00413, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 923 | }, 924 | '45.833333%': { 925 | transform: 'matrix3d(0.99202, 0, 0, 0, 0, 1.00651, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 926 | }, 927 | '47.916667%': { 928 | transform: 'matrix3d(0.99241, 0, 0, 0, 0, 1.00726, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 929 | }, 930 | '50%': { 931 | opacity: 1, 932 | transform: 'matrix3d(0.99329, 0, 0, 0, 0, 1.00671, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 933 | }, 934 | '52.083333%': { 935 | transform: 'matrix3d(0.99447, 0, 0, 0, 0, 1.00529, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 936 | }, 937 | '54.166667%': { 938 | transform: 'matrix3d(0.99577, 0, 0, 0, 0, 1.00346, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 939 | }, 940 | '56.25%': { 941 | transform: 'matrix3d(0.99705, 0, 0, 0, 0, 1.0016, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 942 | }, 943 | '58.333333%': { 944 | transform: 'matrix3d(0.99822, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 945 | }, 946 | '60.416667%': { 947 | transform: 'matrix3d(0.99921, 0, 0, 0, 0, 0.99884, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 948 | }, 949 | '62.5%': { 950 | transform: 'matrix3d(1, 0, 0, 0, 0, 0.99816, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 951 | }, 952 | '64.583333%': { 953 | transform: 'matrix3d(1.00057, 0, 0, 0, 0, 0.99795, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 954 | }, 955 | '66.666667%': { 956 | transform: 'matrix3d(1.00095, 0, 0, 0, 0, 0.99811, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 957 | }, 958 | '68.75%': { 959 | transform: 'matrix3d(1.00114, 0, 0, 0, 0, 0.99851, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 960 | }, 961 | '70.833333%': { 962 | transform: 'matrix3d(1.00119, 0, 0, 0, 0, 0.99903, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 963 | }, 964 | '72.916667%': { 965 | transform: 'matrix3d(1.00114, 0, 0, 0, 0, 0.99955, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 966 | }, 967 | '75%': { 968 | transform: 'matrix3d(1.001, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 969 | }, 970 | '77.083333%': { 971 | transform: 'matrix3d(1.00083, 0, 0, 0, 0, 1.00033, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 972 | }, 973 | '79.166667%': { 974 | transform: 'matrix3d(1.00063, 0, 0, 0, 0, 1.00052, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 975 | }, 976 | '81.25%': { 977 | transform: 'matrix3d(1.00044, 0, 0, 0, 0, 1.00058, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 978 | }, 979 | '83.333333%': { 980 | transform: 'matrix3d(1.00027, 0, 0, 0, 0, 1.00053, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 981 | }, 982 | '85.416667%': { 983 | transform: 'matrix3d(1.00012, 0, 0, 0, 0, 1.00042, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 984 | }, 985 | '87.5%': { 986 | transform: 'matrix3d(1, 0, 0, 0, 0, 1.00027, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 987 | }, 988 | '89.583333%': { 989 | transform: 'matrix3d(0.99991, 0, 0, 0, 0, 1.00013, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 990 | }, 991 | '91.666667%': { 992 | transform: 'matrix3d(0.99986, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 993 | }, 994 | '93.75%': { 995 | transform: 'matrix3d(0.99983, 0, 0, 0, 0, 0.99991, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 996 | }, 997 | '95.833333%': { 998 | transform: 'matrix3d(0.99982, 0, 0, 0, 0, 0.99985, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 999 | }, 1000 | '97.916667%': { 1001 | transform: 'matrix3d(0.99983, 0, 0, 0, 0, 0.99984, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 1002 | }, 1003 | '100%': { 1004 | opacity: 1, 1005 | transform: 'matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' 1006 | } 1007 | }), 1008 | 1009 | hideContentAnimation: insertKeyframesRule({ 1010 | '0%': { 1011 | opacity: 1 1012 | }, 1013 | '100%': { 1014 | opacity: 0, 1015 | transform: 'scale3d(0.8, 0.8, 1)' 1016 | }, 1017 | }), 1018 | 1019 | showBackdropAnimation: insertKeyframesRule({ 1020 | '0%': { 1021 | opacity: 0 1022 | }, 1023 | '100%': { 1024 | opacity: 0.9 1025 | }, 1026 | }), 1027 | 1028 | hideBackdropAnimation: insertKeyframesRule({ 1029 | '0%': { 1030 | opacity: 0.9 1031 | }, 1032 | '100%': { 1033 | opacity: 0 1034 | } 1035 | }) 1036 | }; 1037 | 1038 | var showAnimation = animation.show; 1039 | var hideAnimation = animation.hide; 1040 | var showContentAnimation = animation.showContentAnimation; 1041 | var hideContentAnimation = animation.hideContentAnimation; 1042 | var showBackdropAnimation = animation.showBackdropAnimation; 1043 | var hideBackdropAnimation = animation.hideBackdropAnimation; 1044 | 1045 | module.exports = modalFactory({ 1046 | getRef: function(willHidden) { 1047 | return 'content'; 1048 | }, 1049 | getModalStyle: function(willHidden) { 1050 | return appendVendorPrefix({ 1051 | zIndex: 1050, 1052 | position: "fixed", 1053 | width: "500px", 1054 | transform: "translate3d(-50%, -50%, 0)", 1055 | top: "50%", 1056 | left: "50%" 1057 | }) 1058 | }, 1059 | getBackdropStyle: function(willHidden) { 1060 | return appendVendorPrefix({ 1061 | position: "fixed", 1062 | top: 0, 1063 | right: 0, 1064 | bottom: 0, 1065 | left: 0, 1066 | zIndex: 1040, 1067 | backgroundColor: "#373A47", 1068 | animationFillMode: 'forwards', 1069 | animationDuration: '0.3s', 1070 | animationName: willHidden ? hideBackdropAnimation : showBackdropAnimation, 1071 | animationTimingFunction: (willHidden ? hideAnimation : showAnimation).animationTimingFunction 1072 | }); 1073 | }, 1074 | getContentStyle: function(willHidden) { 1075 | return appendVendorPrefix({ 1076 | margin: 0, 1077 | backgroundColor: "white", 1078 | animationDuration: (willHidden ? hideAnimation : showAnimation).animationDuration, 1079 | animationFillMode: 'forwards', 1080 | animationName: willHidden ? hideContentAnimation : showContentAnimation, 1081 | animationTimingFunction: (willHidden ? hideAnimation : showAnimation).animationTimingFunction 1082 | }) 1083 | } 1084 | }); 1085 | 1086 | },{"./modalFactory":14,"domkit/appendVendorPrefix":1,"domkit/insertKeyframesRule":5}],14:[function(require,module,exports){ 1087 | var React = require('react'); 1088 | var transitionEvents = require('domkit/transitionEvents'); 1089 | var appendVendorPrefix = require('domkit/appendVendorPrefix'); 1090 | 1091 | module.exports = function(animation){ 1092 | 1093 | return React.createClass({ 1094 | propTypes: { 1095 | className: React.PropTypes.string, 1096 | // Close the modal when esc is pressed? Defaults to true. 1097 | keyboard: React.PropTypes.bool, 1098 | onShow: React.PropTypes.func, 1099 | onHide: React.PropTypes.func, 1100 | animation: React.PropTypes.object, 1101 | backdrop: React.PropTypes.bool, 1102 | closeOnClick: React.PropTypes.bool, 1103 | modalStyle: React.PropTypes.object, 1104 | backdropStyle: React.PropTypes.object, 1105 | contentStyle: React.PropTypes.object, 1106 | }, 1107 | 1108 | getDefaultProps: function() { 1109 | return { 1110 | className: "", 1111 | onShow: function(){}, 1112 | onHide: function(){}, 1113 | animation: animation, 1114 | keyboard: true, 1115 | backdrop: true, 1116 | closeOnClick: true, 1117 | modalStyle: {}, 1118 | backdropStyle: {}, 1119 | contentStyle: {}, 1120 | }; 1121 | }, 1122 | 1123 | getInitialState: function(){ 1124 | return { 1125 | willHidden: false, 1126 | hidden: true 1127 | } 1128 | }, 1129 | 1130 | hasHidden: function(){ 1131 | return this.state.hidden; 1132 | }, 1133 | 1134 | addTransitionListener: function(node, handle){ 1135 | if (node) { 1136 | var endListener = function(e) { 1137 | if (e && e.target !== node) { 1138 | return; 1139 | } 1140 | transitionEvents.removeEndEventListener(node, endListener); 1141 | handle(); 1142 | }; 1143 | transitionEvents.addEndEventListener(node, endListener); 1144 | } 1145 | }, 1146 | 1147 | handleBackdropClick: function() { 1148 | if (this.props.closeOnClick) { 1149 | this.hide(); 1150 | } 1151 | }, 1152 | 1153 | render: function() { 1154 | 1155 | var hidden = this.hasHidden(); 1156 | if (hidden) return null; 1157 | 1158 | var willHidden = this.state.willHidden; 1159 | var animation = this.props.animation; 1160 | var modalStyle = animation.getModalStyle(willHidden); 1161 | var backdropStyle = animation.getBackdropStyle(willHidden); 1162 | var contentStyle = animation.getContentStyle(willHidden); 1163 | var ref = animation.getRef(willHidden); 1164 | var sharp = animation.getSharp && animation.getSharp(willHidden); 1165 | 1166 | // Apply custom style properties 1167 | if (this.props.modalStyle) { 1168 | var prefixedModalStyle = appendVendorPrefix(this.props.modalStyle); 1169 | for (var style in prefixedModalStyle) { 1170 | modalStyle[style] = prefixedModalStyle[style]; 1171 | } 1172 | } 1173 | 1174 | if (this.props.backdropStyle) { 1175 | var prefixedBackdropStyle = appendVendorPrefix(this.props.backdropStyle); 1176 | for (var style in prefixedBackdropStyle) { 1177 | backdropStyle[style] = prefixedBackdropStyle[style]; 1178 | } 1179 | } 1180 | 1181 | if (this.props.contentStyle) { 1182 | var prefixedContentStyle = appendVendorPrefix(this.props.contentStyle); 1183 | for (var style in prefixedContentStyle) { 1184 | contentStyle[style] = prefixedContentStyle[style]; 1185 | } 1186 | } 1187 | 1188 | var backdrop = this.props.backdrop? React.createElement("div", {style: backdropStyle, onClick: this.props.closeOnClick? this.handleBackdropClick: null}): undefined; 1189 | 1190 | if(willHidden) { 1191 | var node = this.refs[ref]; 1192 | this.addTransitionListener(node, this.leave); 1193 | } 1194 | 1195 | return (React.createElement("span", null, 1196 | React.createElement("div", {ref: "modal", style: modalStyle, className: this.props.className}, 1197 | sharp, 1198 | React.createElement("div", {ref: "content", tabIndex: "-1", style: contentStyle}, 1199 | this.props.children 1200 | ) 1201 | ), 1202 | backdrop 1203 | )) 1204 | ; 1205 | }, 1206 | 1207 | leave: function(){ 1208 | this.setState({ 1209 | hidden: true 1210 | }); 1211 | this.props.onHide(); 1212 | }, 1213 | 1214 | enter: function(){ 1215 | this.props.onShow(); 1216 | }, 1217 | 1218 | show: function(){ 1219 | if (!this.hasHidden()) return; 1220 | 1221 | this.setState({ 1222 | willHidden: false, 1223 | hidden: false 1224 | }); 1225 | 1226 | setTimeout(function(){ 1227 | var ref = this.props.animation.getRef(); 1228 | var node = this.refs[ref]; 1229 | this.addTransitionListener(node, this.enter); 1230 | }.bind(this), 0); 1231 | }, 1232 | 1233 | hide: function(){ 1234 | if (this.hasHidden()) return; 1235 | 1236 | this.setState({ 1237 | willHidden: true 1238 | }); 1239 | }, 1240 | 1241 | toggle: function(){ 1242 | if (this.hasHidden()) 1243 | this.show(); 1244 | else 1245 | this.hide(); 1246 | }, 1247 | 1248 | listenKeyboard: function(event) { 1249 | if (this.props.keyboard && 1250 | (event.key === "Escape" || 1251 | event.keyCode === 27)) { 1252 | this.hide(); 1253 | } 1254 | }, 1255 | 1256 | componentDidMount: function(){ 1257 | window.addEventListener("keydown", this.listenKeyboard, true); 1258 | }, 1259 | 1260 | componentWillUnmount: function() { 1261 | window.removeEventListener("keydown", this.listenKeyboard, true); 1262 | } 1263 | }); 1264 | } 1265 | 1266 | },{"domkit/appendVendorPrefix":1,"domkit/transitionEvents":7,"react":undefined}],"boron":[function(require,module,exports){ 1267 | module.exports = { 1268 | DropModal: require('./DropModal'), 1269 | WaveModal: require('./WaveModal'), 1270 | FlyModal: require('./FlyModal'), 1271 | FadeModal: require('./FadeModal'), 1272 | ScaleModal: require('./ScaleModal'), 1273 | OutlineModal: require('./OutlineModal'), 1274 | } 1275 | 1276 | },{"./DropModal":8,"./FadeModal":9,"./FlyModal":10,"./OutlineModal":11,"./ScaleModal":12,"./WaveModal":13}]},{},[]); 1277 | -------------------------------------------------------------------------------- /example/dist/codemirror.css: -------------------------------------------------------------------------------- 1 | /* BASICS */ 2 | 3 | .CodeMirror { 4 | /* Set height, width, borders, and global font properties here */ 5 | font-family: monospace; 6 | height: 300px; 7 | color: black; 8 | } 9 | 10 | /* PADDING */ 11 | 12 | .CodeMirror-lines { 13 | padding: 4px 0; /* Vertical padding around content */ 14 | } 15 | .CodeMirror pre { 16 | padding: 0 4px; /* Horizontal padding of content */ 17 | } 18 | 19 | .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { 20 | background-color: white; /* The little square between H and V scrollbars */ 21 | } 22 | 23 | /* GUTTER */ 24 | 25 | .CodeMirror-gutters { 26 | border-right: 1px solid #ddd; 27 | background-color: #f7f7f7; 28 | white-space: nowrap; 29 | } 30 | .CodeMirror-linenumbers {} 31 | .CodeMirror-linenumber { 32 | padding: 0 3px 0 5px; 33 | min-width: 20px; 34 | text-align: right; 35 | color: #999; 36 | white-space: nowrap; 37 | } 38 | 39 | .CodeMirror-guttermarker { color: black; } 40 | .CodeMirror-guttermarker-subtle { color: #999; } 41 | 42 | /* CURSOR */ 43 | 44 | .CodeMirror-cursor { 45 | border-left: 1px solid black; 46 | border-right: none; 47 | width: 0; 48 | } 49 | /* Shown when moving in bi-directional text */ 50 | .CodeMirror div.CodeMirror-secondarycursor { 51 | border-left: 1px solid silver; 52 | } 53 | .cm-fat-cursor .CodeMirror-cursor { 54 | width: auto; 55 | border: 0; 56 | background: #7e7; 57 | } 58 | .cm-fat-cursor div.CodeMirror-cursors { 59 | z-index: 1; 60 | } 61 | 62 | .cm-animate-fat-cursor { 63 | width: auto; 64 | border: 0; 65 | -webkit-animation: blink 1.06s steps(1) infinite; 66 | -moz-animation: blink 1.06s steps(1) infinite; 67 | animation: blink 1.06s steps(1) infinite; 68 | background-color: #7e7; 69 | } 70 | @-moz-keyframes blink { 71 | 0% {} 72 | 50% { background-color: transparent; } 73 | 100% {} 74 | } 75 | @-webkit-keyframes blink { 76 | 0% {} 77 | 50% { background-color: transparent; } 78 | 100% {} 79 | } 80 | @keyframes blink { 81 | 0% {} 82 | 50% { background-color: transparent; } 83 | 100% {} 84 | } 85 | 86 | /* Can style cursor different in overwrite (non-insert) mode */ 87 | .CodeMirror-overwrite .CodeMirror-cursor {} 88 | 89 | .cm-tab { display: inline-block; text-decoration: inherit; } 90 | 91 | .CodeMirror-ruler { 92 | border-left: 1px solid #ccc; 93 | position: absolute; 94 | } 95 | 96 | /* DEFAULT THEME */ 97 | 98 | .cm-s-default .cm-header {color: blue;} 99 | .cm-s-default .cm-quote {color: #090;} 100 | .cm-negative {color: #d44;} 101 | .cm-positive {color: #292;} 102 | .cm-header, .cm-strong {font-weight: bold;} 103 | .cm-em {font-style: italic;} 104 | .cm-link {text-decoration: underline;} 105 | .cm-strikethrough {text-decoration: line-through;} 106 | 107 | .cm-s-default .cm-keyword {color: #708;} 108 | .cm-s-default .cm-atom {color: #219;} 109 | .cm-s-default .cm-number {color: #164;} 110 | .cm-s-default .cm-def {color: #00f;} 111 | .cm-s-default .cm-variable, 112 | .cm-s-default .cm-punctuation, 113 | .cm-s-default .cm-property, 114 | .cm-s-default .cm-operator {} 115 | .cm-s-default .cm-variable-2 {color: #05a;} 116 | .cm-s-default .cm-variable-3 {color: #085;} 117 | .cm-s-default .cm-comment {color: #a50;} 118 | .cm-s-default .cm-string {color: #a11;} 119 | .cm-s-default .cm-string-2 {color: #f50;} 120 | .cm-s-default .cm-meta {color: #555;} 121 | .cm-s-default .cm-qualifier {color: #555;} 122 | .cm-s-default .cm-builtin {color: #30a;} 123 | .cm-s-default .cm-bracket {color: #997;} 124 | .cm-s-default .cm-tag {color: #170;} 125 | .cm-s-default .cm-attribute {color: #00c;} 126 | .cm-s-default .cm-hr {color: #999;} 127 | .cm-s-default .cm-link {color: #00c;} 128 | 129 | .cm-s-default .cm-error {color: #f00;} 130 | .cm-invalidchar {color: #f00;} 131 | 132 | .CodeMirror-composing { border-bottom: 2px solid; } 133 | 134 | /* Default styles for common addons */ 135 | 136 | div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;} 137 | div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;} 138 | .CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); } 139 | .CodeMirror-activeline-background {background: #e8f2ff;} 140 | 141 | /* STOP */ 142 | 143 | /* The rest of this file contains styles related to the mechanics of 144 | the editor. You probably shouldn't touch them. */ 145 | 146 | .CodeMirror { 147 | position: relative; 148 | overflow: hidden; 149 | background: white; 150 | } 151 | 152 | .CodeMirror-scroll { 153 | overflow: scroll !important; /* Things will break if this is overridden */ 154 | /* 30px is the magic margin used to hide the element's real scrollbars */ 155 | /* See overflow: hidden in .CodeMirror */ 156 | margin-bottom: -30px; margin-right: -30px; 157 | padding-bottom: 30px; 158 | height: 100%; 159 | outline: none; /* Prevent dragging from highlighting the element */ 160 | position: relative; 161 | } 162 | .CodeMirror-sizer { 163 | position: relative; 164 | border-right: 30px solid transparent; 165 | } 166 | 167 | /* The fake, visible scrollbars. Used to force redraw during scrolling 168 | before actuall scrolling happens, thus preventing shaking and 169 | flickering artifacts. */ 170 | .CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { 171 | position: absolute; 172 | z-index: 6; 173 | display: none; 174 | } 175 | .CodeMirror-vscrollbar { 176 | right: 0; top: 0; 177 | overflow-x: hidden; 178 | overflow-y: scroll; 179 | } 180 | .CodeMirror-hscrollbar { 181 | bottom: 0; left: 0; 182 | overflow-y: hidden; 183 | overflow-x: scroll; 184 | } 185 | .CodeMirror-scrollbar-filler { 186 | right: 0; bottom: 0; 187 | } 188 | .CodeMirror-gutter-filler { 189 | left: 0; bottom: 0; 190 | } 191 | 192 | .CodeMirror-gutters { 193 | position: absolute; left: 0; top: 0; 194 | z-index: 3; 195 | } 196 | .CodeMirror-gutter { 197 | white-space: normal; 198 | height: 100%; 199 | display: inline-block; 200 | margin-bottom: -30px; 201 | /* Hack to make IE7 behave */ 202 | *zoom:1; 203 | *display:inline; 204 | } 205 | .CodeMirror-gutter-wrapper { 206 | position: absolute; 207 | z-index: 4; 208 | background: none !important; 209 | border: none !important; 210 | } 211 | .CodeMirror-gutter-background { 212 | position: absolute; 213 | top: 0; bottom: 0; 214 | z-index: 4; 215 | } 216 | .CodeMirror-gutter-elt { 217 | position: absolute; 218 | cursor: default; 219 | z-index: 4; 220 | } 221 | .CodeMirror-gutter-wrapper { 222 | -webkit-user-select: none; 223 | -moz-user-select: none; 224 | user-select: none; 225 | } 226 | 227 | .CodeMirror-lines { 228 | cursor: text; 229 | min-height: 1px; /* prevents collapsing before first draw */ 230 | } 231 | .CodeMirror pre { 232 | /* Reset some styles that the rest of the page might have set */ 233 | -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0; 234 | border-width: 0; 235 | background: transparent; 236 | font-family: inherit; 237 | font-size: inherit; 238 | margin: 0; 239 | white-space: pre; 240 | word-wrap: normal; 241 | line-height: inherit; 242 | color: inherit; 243 | z-index: 2; 244 | position: relative; 245 | overflow: visible; 246 | -webkit-tap-highlight-color: transparent; 247 | } 248 | .CodeMirror-wrap pre { 249 | word-wrap: break-word; 250 | white-space: pre-wrap; 251 | word-break: normal; 252 | } 253 | 254 | .CodeMirror-linebackground { 255 | position: absolute; 256 | left: 0; right: 0; top: 0; bottom: 0; 257 | z-index: 0; 258 | } 259 | 260 | .CodeMirror-linewidget { 261 | position: relative; 262 | z-index: 2; 263 | overflow: auto; 264 | } 265 | 266 | .CodeMirror-widget {} 267 | 268 | .CodeMirror-code { 269 | outline: none; 270 | } 271 | 272 | /* Force content-box sizing for the elements where we expect it */ 273 | .CodeMirror-scroll, 274 | .CodeMirror-sizer, 275 | .CodeMirror-gutter, 276 | .CodeMirror-gutters, 277 | .CodeMirror-linenumber { 278 | -moz-box-sizing: content-box; 279 | box-sizing: content-box; 280 | } 281 | 282 | .CodeMirror-measure { 283 | position: absolute; 284 | width: 100%; 285 | height: 0; 286 | overflow: hidden; 287 | visibility: hidden; 288 | } 289 | 290 | .CodeMirror-cursor { position: absolute; } 291 | .CodeMirror-measure pre { position: static; } 292 | 293 | div.CodeMirror-cursors { 294 | visibility: hidden; 295 | position: relative; 296 | z-index: 3; 297 | } 298 | div.CodeMirror-dragcursors { 299 | visibility: visible; 300 | } 301 | 302 | .CodeMirror-focused div.CodeMirror-cursors { 303 | visibility: visible; 304 | } 305 | 306 | .CodeMirror-selected { background: #d9d9d9; } 307 | .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; } 308 | .CodeMirror-crosshair { cursor: crosshair; } 309 | .CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; } 310 | .CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; } 311 | 312 | .cm-searching { 313 | background: #ffa; 314 | background: rgba(255, 255, 0, .4); 315 | } 316 | 317 | /* IE7 hack to prevent it from returning funny offsetTops on the spans */ 318 | .CodeMirror span { *vertical-align: text-bottom; } 319 | 320 | /* Used to force a border model for a node */ 321 | .cm-force-border { padding-right: .1px; } 322 | 323 | @media print { 324 | /* Hide the cursor when printing */ 325 | .CodeMirror div.CodeMirror-cursors { 326 | visibility: hidden; 327 | } 328 | } 329 | 330 | /* See issue #2901 */ 331 | .cm-tab-wrap-hack:after { content: ''; } 332 | 333 | /* Help users use markselection to safely style text background */ 334 | span.CodeMirror-selectedtext { background: none; } 335 | -------------------------------------------------------------------------------- /example/dist/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Boron 6 | 7 | 8 | 9 | 10 | 11 | 77 | 78 | 79 |
80 |
81 |

82 | Boron 83 |

84 |
85 |
86 | 87 |
88 |
89 |
90 | npm install boron 91 |
92 |
93 | 94 | 95 |
96 |
loading...
97 |
98 | 99 |
100 | 101 | 108 | 109 | Fork me on GitHub 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /example/dist/javascript.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: http://codemirror.net/LICENSE 3 | 4 | // TODO actually recognize syntax of TypeScript constructs 5 | 6 | (function(mod) { 7 | if (typeof exports == "object" && typeof module == "object") // CommonJS 8 | mod(require("../../lib/codemirror")); 9 | else if (typeof define == "function" && define.amd) // AMD 10 | define(["../../lib/codemirror"], mod); 11 | else // Plain browser env 12 | mod(CodeMirror); 13 | })(function(CodeMirror) { 14 | "use strict"; 15 | 16 | CodeMirror.defineMode("javascript", function(config, parserConfig) { 17 | var indentUnit = config.indentUnit; 18 | var statementIndent = parserConfig.statementIndent; 19 | var jsonldMode = parserConfig.jsonld; 20 | var jsonMode = parserConfig.json || jsonldMode; 21 | var isTS = parserConfig.typescript; 22 | var wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/; 23 | 24 | // Tokenizer 25 | 26 | var keywords = function(){ 27 | function kw(type) {return {type: type, style: "keyword"};} 28 | var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c"); 29 | var operator = kw("operator"), atom = {type: "atom", style: "atom"}; 30 | 31 | var jsKeywords = { 32 | "if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B, 33 | "return": C, "break": C, "continue": C, "new": kw("new"), "delete": C, "throw": C, "debugger": C, 34 | "var": kw("var"), "const": kw("var"), "let": kw("var"), 35 | "function": kw("function"), "catch": kw("catch"), 36 | "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"), 37 | "in": operator, "typeof": operator, "instanceof": operator, 38 | "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom, 39 | "this": kw("this"), "class": kw("class"), "super": kw("atom"), 40 | "yield": C, "export": kw("export"), "import": kw("import"), "extends": C 41 | }; 42 | 43 | // Extend the 'normal' keywords with the TypeScript language extensions 44 | if (isTS) { 45 | var type = {type: "variable", style: "variable-3"}; 46 | var tsKeywords = { 47 | // object-like things 48 | "interface": kw("interface"), 49 | "extends": kw("extends"), 50 | "constructor": kw("constructor"), 51 | 52 | // scope modifiers 53 | "public": kw("public"), 54 | "private": kw("private"), 55 | "protected": kw("protected"), 56 | "static": kw("static"), 57 | 58 | // types 59 | "string": type, "number": type, "boolean": type, "any": type 60 | }; 61 | 62 | for (var attr in tsKeywords) { 63 | jsKeywords[attr] = tsKeywords[attr]; 64 | } 65 | } 66 | 67 | return jsKeywords; 68 | }(); 69 | 70 | var isOperatorChar = /[+\-*&%=<>!?|~^]/; 71 | var isJsonldKeyword = /^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/; 72 | 73 | function readRegexp(stream) { 74 | var escaped = false, next, inSet = false; 75 | while ((next = stream.next()) != null) { 76 | if (!escaped) { 77 | if (next == "/" && !inSet) return; 78 | if (next == "[") inSet = true; 79 | else if (inSet && next == "]") inSet = false; 80 | } 81 | escaped = !escaped && next == "\\"; 82 | } 83 | } 84 | 85 | // Used as scratch variables to communicate multiple values without 86 | // consing up tons of objects. 87 | var type, content; 88 | function ret(tp, style, cont) { 89 | type = tp; content = cont; 90 | return style; 91 | } 92 | function tokenBase(stream, state) { 93 | var ch = stream.next(); 94 | if (ch == '"' || ch == "'") { 95 | state.tokenize = tokenString(ch); 96 | return state.tokenize(stream, state); 97 | } else if (ch == "." && stream.match(/^\d+(?:[eE][+\-]?\d+)?/)) { 98 | return ret("number", "number"); 99 | } else if (ch == "." && stream.match("..")) { 100 | return ret("spread", "meta"); 101 | } else if (/[\[\]{}\(\),;\:\.]/.test(ch)) { 102 | return ret(ch); 103 | } else if (ch == "=" && stream.eat(">")) { 104 | return ret("=>", "operator"); 105 | } else if (ch == "0" && stream.eat(/x/i)) { 106 | stream.eatWhile(/[\da-f]/i); 107 | return ret("number", "number"); 108 | } else if (ch == "0" && stream.eat(/o/i)) { 109 | stream.eatWhile(/[0-7]/i); 110 | return ret("number", "number"); 111 | } else if (ch == "0" && stream.eat(/b/i)) { 112 | stream.eatWhile(/[01]/i); 113 | return ret("number", "number"); 114 | } else if (/\d/.test(ch)) { 115 | stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/); 116 | return ret("number", "number"); 117 | } else if (ch == "/") { 118 | if (stream.eat("*")) { 119 | state.tokenize = tokenComment; 120 | return tokenComment(stream, state); 121 | } else if (stream.eat("/")) { 122 | stream.skipToEnd(); 123 | return ret("comment", "comment"); 124 | } else if (/^(?:operator|sof|keyword c|case|new|[\[{}\(,;:])$/.test(state.lastType)) { 125 | readRegexp(stream); 126 | stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/); 127 | return ret("regexp", "string-2"); 128 | } else { 129 | stream.eatWhile(isOperatorChar); 130 | return ret("operator", "operator", stream.current()); 131 | } 132 | } else if (ch == "`") { 133 | state.tokenize = tokenQuasi; 134 | return tokenQuasi(stream, state); 135 | } else if (ch == "#") { 136 | stream.skipToEnd(); 137 | return ret("error", "error"); 138 | } else if (isOperatorChar.test(ch)) { 139 | stream.eatWhile(isOperatorChar); 140 | return ret("operator", "operator", stream.current()); 141 | } else if (wordRE.test(ch)) { 142 | stream.eatWhile(wordRE); 143 | var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word]; 144 | return (known && state.lastType != ".") ? ret(known.type, known.style, word) : 145 | ret("variable", "variable", word); 146 | } 147 | } 148 | 149 | function tokenString(quote) { 150 | return function(stream, state) { 151 | var escaped = false, next; 152 | if (jsonldMode && stream.peek() == "@" && stream.match(isJsonldKeyword)){ 153 | state.tokenize = tokenBase; 154 | return ret("jsonld-keyword", "meta"); 155 | } 156 | while ((next = stream.next()) != null) { 157 | if (next == quote && !escaped) break; 158 | escaped = !escaped && next == "\\"; 159 | } 160 | if (!escaped) state.tokenize = tokenBase; 161 | return ret("string", "string"); 162 | }; 163 | } 164 | 165 | function tokenComment(stream, state) { 166 | var maybeEnd = false, ch; 167 | while (ch = stream.next()) { 168 | if (ch == "/" && maybeEnd) { 169 | state.tokenize = tokenBase; 170 | break; 171 | } 172 | maybeEnd = (ch == "*"); 173 | } 174 | return ret("comment", "comment"); 175 | } 176 | 177 | function tokenQuasi(stream, state) { 178 | var escaped = false, next; 179 | while ((next = stream.next()) != null) { 180 | if (!escaped && (next == "`" || next == "$" && stream.eat("{"))) { 181 | state.tokenize = tokenBase; 182 | break; 183 | } 184 | escaped = !escaped && next == "\\"; 185 | } 186 | return ret("quasi", "string-2", stream.current()); 187 | } 188 | 189 | var brackets = "([{}])"; 190 | // This is a crude lookahead trick to try and notice that we're 191 | // parsing the argument patterns for a fat-arrow function before we 192 | // actually hit the arrow token. It only works if the arrow is on 193 | // the same line as the arguments and there's no strange noise 194 | // (comments) in between. Fallback is to only notice when we hit the 195 | // arrow, and not declare the arguments as locals for the arrow 196 | // body. 197 | function findFatArrow(stream, state) { 198 | if (state.fatArrowAt) state.fatArrowAt = null; 199 | var arrow = stream.string.indexOf("=>", stream.start); 200 | if (arrow < 0) return; 201 | 202 | var depth = 0, sawSomething = false; 203 | for (var pos = arrow - 1; pos >= 0; --pos) { 204 | var ch = stream.string.charAt(pos); 205 | var bracket = brackets.indexOf(ch); 206 | if (bracket >= 0 && bracket < 3) { 207 | if (!depth) { ++pos; break; } 208 | if (--depth == 0) break; 209 | } else if (bracket >= 3 && bracket < 6) { 210 | ++depth; 211 | } else if (wordRE.test(ch)) { 212 | sawSomething = true; 213 | } else if (/["'\/]/.test(ch)) { 214 | return; 215 | } else if (sawSomething && !depth) { 216 | ++pos; 217 | break; 218 | } 219 | } 220 | if (sawSomething && !depth) state.fatArrowAt = pos; 221 | } 222 | 223 | // Parser 224 | 225 | var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true, "this": true, "jsonld-keyword": true}; 226 | 227 | function JSLexical(indented, column, type, align, prev, info) { 228 | this.indented = indented; 229 | this.column = column; 230 | this.type = type; 231 | this.prev = prev; 232 | this.info = info; 233 | if (align != null) this.align = align; 234 | } 235 | 236 | function inScope(state, varname) { 237 | for (var v = state.localVars; v; v = v.next) 238 | if (v.name == varname) return true; 239 | for (var cx = state.context; cx; cx = cx.prev) { 240 | for (var v = cx.vars; v; v = v.next) 241 | if (v.name == varname) return true; 242 | } 243 | } 244 | 245 | function parseJS(state, style, type, content, stream) { 246 | var cc = state.cc; 247 | // Communicate our context to the combinators. 248 | // (Less wasteful than consing up a hundred closures on every call.) 249 | cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; cx.style = style; 250 | 251 | if (!state.lexical.hasOwnProperty("align")) 252 | state.lexical.align = true; 253 | 254 | while(true) { 255 | var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement; 256 | if (combinator(type, content)) { 257 | while(cc.length && cc[cc.length - 1].lex) 258 | cc.pop()(); 259 | if (cx.marked) return cx.marked; 260 | if (type == "variable" && inScope(state, content)) return "variable-2"; 261 | return style; 262 | } 263 | } 264 | } 265 | 266 | // Combinator utils 267 | 268 | var cx = {state: null, column: null, marked: null, cc: null}; 269 | function pass() { 270 | for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]); 271 | } 272 | function cont() { 273 | pass.apply(null, arguments); 274 | return true; 275 | } 276 | function register(varname) { 277 | function inList(list) { 278 | for (var v = list; v; v = v.next) 279 | if (v.name == varname) return true; 280 | return false; 281 | } 282 | var state = cx.state; 283 | cx.marked = "def"; 284 | if (state.context) { 285 | if (inList(state.localVars)) return; 286 | state.localVars = {name: varname, next: state.localVars}; 287 | } else { 288 | if (inList(state.globalVars)) return; 289 | if (parserConfig.globalVars) 290 | state.globalVars = {name: varname, next: state.globalVars}; 291 | } 292 | } 293 | 294 | // Combinators 295 | 296 | var defaultVars = {name: "this", next: {name: "arguments"}}; 297 | function pushcontext() { 298 | cx.state.context = {prev: cx.state.context, vars: cx.state.localVars}; 299 | cx.state.localVars = defaultVars; 300 | } 301 | function popcontext() { 302 | cx.state.localVars = cx.state.context.vars; 303 | cx.state.context = cx.state.context.prev; 304 | } 305 | function pushlex(type, info) { 306 | var result = function() { 307 | var state = cx.state, indent = state.indented; 308 | if (state.lexical.type == "stat") indent = state.lexical.indented; 309 | else for (var outer = state.lexical; outer && outer.type == ")" && outer.align; outer = outer.prev) 310 | indent = outer.indented; 311 | state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info); 312 | }; 313 | result.lex = true; 314 | return result; 315 | } 316 | function poplex() { 317 | var state = cx.state; 318 | if (state.lexical.prev) { 319 | if (state.lexical.type == ")") 320 | state.indented = state.lexical.indented; 321 | state.lexical = state.lexical.prev; 322 | } 323 | } 324 | poplex.lex = true; 325 | 326 | function expect(wanted) { 327 | function exp(type) { 328 | if (type == wanted) return cont(); 329 | else if (wanted == ";") return pass(); 330 | else return cont(exp); 331 | }; 332 | return exp; 333 | } 334 | 335 | function statement(type, value) { 336 | if (type == "var") return cont(pushlex("vardef", value.length), vardef, expect(";"), poplex); 337 | if (type == "keyword a") return cont(pushlex("form"), expression, statement, poplex); 338 | if (type == "keyword b") return cont(pushlex("form"), statement, poplex); 339 | if (type == "{") return cont(pushlex("}"), block, poplex); 340 | if (type == ";") return cont(); 341 | if (type == "if") { 342 | if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex) 343 | cx.state.cc.pop()(); 344 | return cont(pushlex("form"), expression, statement, poplex, maybeelse); 345 | } 346 | if (type == "function") return cont(functiondef); 347 | if (type == "for") return cont(pushlex("form"), forspec, statement, poplex); 348 | if (type == "variable") return cont(pushlex("stat"), maybelabel); 349 | if (type == "switch") return cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"), 350 | block, poplex, poplex); 351 | if (type == "case") return cont(expression, expect(":")); 352 | if (type == "default") return cont(expect(":")); 353 | if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"), 354 | statement, poplex, popcontext); 355 | if (type == "class") return cont(pushlex("form"), className, poplex); 356 | if (type == "export") return cont(pushlex("stat"), afterExport, poplex); 357 | if (type == "import") return cont(pushlex("stat"), afterImport, poplex); 358 | return pass(pushlex("stat"), expression, expect(";"), poplex); 359 | } 360 | function expression(type) { 361 | return expressionInner(type, false); 362 | } 363 | function expressionNoComma(type) { 364 | return expressionInner(type, true); 365 | } 366 | function expressionInner(type, noComma) { 367 | if (cx.state.fatArrowAt == cx.stream.start) { 368 | var body = noComma ? arrowBodyNoComma : arrowBody; 369 | if (type == "(") return cont(pushcontext, pushlex(")"), commasep(pattern, ")"), poplex, expect("=>"), body, popcontext); 370 | else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext); 371 | } 372 | 373 | var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma; 374 | if (atomicTypes.hasOwnProperty(type)) return cont(maybeop); 375 | if (type == "function") return cont(functiondef, maybeop); 376 | if (type == "keyword c") return cont(noComma ? maybeexpressionNoComma : maybeexpression); 377 | if (type == "(") return cont(pushlex(")"), maybeexpression, comprehension, expect(")"), poplex, maybeop); 378 | if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression); 379 | if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop); 380 | if (type == "{") return contCommasep(objprop, "}", null, maybeop); 381 | if (type == "quasi") return pass(quasi, maybeop); 382 | if (type == "new") return cont(maybeTarget(noComma)); 383 | return cont(); 384 | } 385 | function maybeexpression(type) { 386 | if (type.match(/[;\}\)\],]/)) return pass(); 387 | return pass(expression); 388 | } 389 | function maybeexpressionNoComma(type) { 390 | if (type.match(/[;\}\)\],]/)) return pass(); 391 | return pass(expressionNoComma); 392 | } 393 | 394 | function maybeoperatorComma(type, value) { 395 | if (type == ",") return cont(expression); 396 | return maybeoperatorNoComma(type, value, false); 397 | } 398 | function maybeoperatorNoComma(type, value, noComma) { 399 | var me = noComma == false ? maybeoperatorComma : maybeoperatorNoComma; 400 | var expr = noComma == false ? expression : expressionNoComma; 401 | if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext); 402 | if (type == "operator") { 403 | if (/\+\+|--/.test(value)) return cont(me); 404 | if (value == "?") return cont(expression, expect(":"), expr); 405 | return cont(expr); 406 | } 407 | if (type == "quasi") { return pass(quasi, me); } 408 | if (type == ";") return; 409 | if (type == "(") return contCommasep(expressionNoComma, ")", "call", me); 410 | if (type == ".") return cont(property, me); 411 | if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me); 412 | } 413 | function quasi(type, value) { 414 | if (type != "quasi") return pass(); 415 | if (value.slice(value.length - 2) != "${") return cont(quasi); 416 | return cont(expression, continueQuasi); 417 | } 418 | function continueQuasi(type) { 419 | if (type == "}") { 420 | cx.marked = "string-2"; 421 | cx.state.tokenize = tokenQuasi; 422 | return cont(quasi); 423 | } 424 | } 425 | function arrowBody(type) { 426 | findFatArrow(cx.stream, cx.state); 427 | return pass(type == "{" ? statement : expression); 428 | } 429 | function arrowBodyNoComma(type) { 430 | findFatArrow(cx.stream, cx.state); 431 | return pass(type == "{" ? statement : expressionNoComma); 432 | } 433 | function maybeTarget(noComma) { 434 | return function(type) { 435 | if (type == ".") return cont(noComma ? targetNoComma : target); 436 | else return pass(noComma ? expressionNoComma : expression); 437 | }; 438 | } 439 | function target(_, value) { 440 | if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorComma); } 441 | } 442 | function targetNoComma(_, value) { 443 | if (value == "target") { cx.marked = "keyword"; return cont(maybeoperatorNoComma); } 444 | } 445 | function maybelabel(type) { 446 | if (type == ":") return cont(poplex, statement); 447 | return pass(maybeoperatorComma, expect(";"), poplex); 448 | } 449 | function property(type) { 450 | if (type == "variable") {cx.marked = "property"; return cont();} 451 | } 452 | function objprop(type, value) { 453 | if (type == "variable" || cx.style == "keyword") { 454 | cx.marked = "property"; 455 | if (value == "get" || value == "set") return cont(getterSetter); 456 | return cont(afterprop); 457 | } else if (type == "number" || type == "string") { 458 | cx.marked = jsonldMode ? "property" : (cx.style + " property"); 459 | return cont(afterprop); 460 | } else if (type == "jsonld-keyword") { 461 | return cont(afterprop); 462 | } else if (type == "[") { 463 | return cont(expression, expect("]"), afterprop); 464 | } else if (type == "spread") { 465 | return cont(expression); 466 | } 467 | } 468 | function getterSetter(type) { 469 | if (type != "variable") return pass(afterprop); 470 | cx.marked = "property"; 471 | return cont(functiondef); 472 | } 473 | function afterprop(type) { 474 | if (type == ":") return cont(expressionNoComma); 475 | if (type == "(") return pass(functiondef); 476 | } 477 | function commasep(what, end) { 478 | function proceed(type) { 479 | if (type == ",") { 480 | var lex = cx.state.lexical; 481 | if (lex.info == "call") lex.pos = (lex.pos || 0) + 1; 482 | return cont(what, proceed); 483 | } 484 | if (type == end) return cont(); 485 | return cont(expect(end)); 486 | } 487 | return function(type) { 488 | if (type == end) return cont(); 489 | return pass(what, proceed); 490 | }; 491 | } 492 | function contCommasep(what, end, info) { 493 | for (var i = 3; i < arguments.length; i++) 494 | cx.cc.push(arguments[i]); 495 | return cont(pushlex(end, info), commasep(what, end), poplex); 496 | } 497 | function block(type) { 498 | if (type == "}") return cont(); 499 | return pass(statement, block); 500 | } 501 | function maybetype(type) { 502 | if (isTS && type == ":") return cont(typedef); 503 | } 504 | function maybedefault(_, value) { 505 | if (value == "=") return cont(expressionNoComma); 506 | } 507 | function typedef(type) { 508 | if (type == "variable") {cx.marked = "variable-3"; return cont();} 509 | } 510 | function vardef() { 511 | return pass(pattern, maybetype, maybeAssign, vardefCont); 512 | } 513 | function pattern(type, value) { 514 | if (type == "variable") { register(value); return cont(); } 515 | if (type == "spread") return cont(pattern); 516 | if (type == "[") return contCommasep(pattern, "]"); 517 | if (type == "{") return contCommasep(proppattern, "}"); 518 | } 519 | function proppattern(type, value) { 520 | if (type == "variable" && !cx.stream.match(/^\s*:/, false)) { 521 | register(value); 522 | return cont(maybeAssign); 523 | } 524 | if (type == "variable") cx.marked = "property"; 525 | if (type == "spread") return cont(pattern); 526 | return cont(expect(":"), pattern, maybeAssign); 527 | } 528 | function maybeAssign(_type, value) { 529 | if (value == "=") return cont(expressionNoComma); 530 | } 531 | function vardefCont(type) { 532 | if (type == ",") return cont(vardef); 533 | } 534 | function maybeelse(type, value) { 535 | if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex); 536 | } 537 | function forspec(type) { 538 | if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex); 539 | } 540 | function forspec1(type) { 541 | if (type == "var") return cont(vardef, expect(";"), forspec2); 542 | if (type == ";") return cont(forspec2); 543 | if (type == "variable") return cont(formaybeinof); 544 | return pass(expression, expect(";"), forspec2); 545 | } 546 | function formaybeinof(_type, value) { 547 | if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); } 548 | return cont(maybeoperatorComma, forspec2); 549 | } 550 | function forspec2(type, value) { 551 | if (type == ";") return cont(forspec3); 552 | if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); } 553 | return pass(expression, expect(";"), forspec3); 554 | } 555 | function forspec3(type) { 556 | if (type != ")") cont(expression); 557 | } 558 | function functiondef(type, value) { 559 | if (value == "*") {cx.marked = "keyword"; return cont(functiondef);} 560 | if (type == "variable") {register(value); return cont(functiondef);} 561 | if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, statement, popcontext); 562 | } 563 | function funarg(type) { 564 | if (type == "spread") return cont(funarg); 565 | return pass(pattern, maybetype, maybedefault); 566 | } 567 | function className(type, value) { 568 | if (type == "variable") {register(value); return cont(classNameAfter);} 569 | } 570 | function classNameAfter(type, value) { 571 | if (value == "extends") return cont(expression, classNameAfter); 572 | if (type == "{") return cont(pushlex("}"), classBody, poplex); 573 | } 574 | function classBody(type, value) { 575 | if (type == "variable" || cx.style == "keyword") { 576 | if (value == "static") { 577 | cx.marked = "keyword"; 578 | return cont(classBody); 579 | } 580 | cx.marked = "property"; 581 | if (value == "get" || value == "set") return cont(classGetterSetter, functiondef, classBody); 582 | return cont(functiondef, classBody); 583 | } 584 | if (value == "*") { 585 | cx.marked = "keyword"; 586 | return cont(classBody); 587 | } 588 | if (type == ";") return cont(classBody); 589 | if (type == "}") return cont(); 590 | } 591 | function classGetterSetter(type) { 592 | if (type != "variable") return pass(); 593 | cx.marked = "property"; 594 | return cont(); 595 | } 596 | function afterExport(_type, value) { 597 | if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); } 598 | if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); } 599 | return pass(statement); 600 | } 601 | function afterImport(type) { 602 | if (type == "string") return cont(); 603 | return pass(importSpec, maybeFrom); 604 | } 605 | function importSpec(type, value) { 606 | if (type == "{") return contCommasep(importSpec, "}"); 607 | if (type == "variable") register(value); 608 | if (value == "*") cx.marked = "keyword"; 609 | return cont(maybeAs); 610 | } 611 | function maybeAs(_type, value) { 612 | if (value == "as") { cx.marked = "keyword"; return cont(importSpec); } 613 | } 614 | function maybeFrom(_type, value) { 615 | if (value == "from") { cx.marked = "keyword"; return cont(expression); } 616 | } 617 | function arrayLiteral(type) { 618 | if (type == "]") return cont(); 619 | return pass(expressionNoComma, maybeArrayComprehension); 620 | } 621 | function maybeArrayComprehension(type) { 622 | if (type == "for") return pass(comprehension, expect("]")); 623 | if (type == ",") return cont(commasep(maybeexpressionNoComma, "]")); 624 | return pass(commasep(expressionNoComma, "]")); 625 | } 626 | function comprehension(type) { 627 | if (type == "for") return cont(forspec, comprehension); 628 | if (type == "if") return cont(expression, comprehension); 629 | } 630 | 631 | function isContinuedStatement(state, textAfter) { 632 | return state.lastType == "operator" || state.lastType == "," || 633 | isOperatorChar.test(textAfter.charAt(0)) || 634 | /[,.]/.test(textAfter.charAt(0)); 635 | } 636 | 637 | // Interface 638 | 639 | return { 640 | startState: function(basecolumn) { 641 | var state = { 642 | tokenize: tokenBase, 643 | lastType: "sof", 644 | cc: [], 645 | lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false), 646 | localVars: parserConfig.localVars, 647 | context: parserConfig.localVars && {vars: parserConfig.localVars}, 648 | indented: 0 649 | }; 650 | if (parserConfig.globalVars && typeof parserConfig.globalVars == "object") 651 | state.globalVars = parserConfig.globalVars; 652 | return state; 653 | }, 654 | 655 | token: function(stream, state) { 656 | if (stream.sol()) { 657 | if (!state.lexical.hasOwnProperty("align")) 658 | state.lexical.align = false; 659 | state.indented = stream.indentation(); 660 | findFatArrow(stream, state); 661 | } 662 | if (state.tokenize != tokenComment && stream.eatSpace()) return null; 663 | var style = state.tokenize(stream, state); 664 | if (type == "comment") return style; 665 | state.lastType = type == "operator" && (content == "++" || content == "--") ? "incdec" : type; 666 | return parseJS(state, style, type, content, stream); 667 | }, 668 | 669 | indent: function(state, textAfter) { 670 | if (state.tokenize == tokenComment) return CodeMirror.Pass; 671 | if (state.tokenize != tokenBase) return 0; 672 | var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical; 673 | // Kludge to prevent 'maybelse' from blocking lexical scope pops 674 | if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) { 675 | var c = state.cc[i]; 676 | if (c == poplex) lexical = lexical.prev; 677 | else if (c != maybeelse) break; 678 | } 679 | if (lexical.type == "stat" && firstChar == "}") lexical = lexical.prev; 680 | if (statementIndent && lexical.type == ")" && lexical.prev.type == "stat") 681 | lexical = lexical.prev; 682 | var type = lexical.type, closing = firstChar == type; 683 | 684 | if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? lexical.info + 1 : 0); 685 | else if (type == "form" && firstChar == "{") return lexical.indented; 686 | else if (type == "form") return lexical.indented + indentUnit; 687 | else if (type == "stat") 688 | return lexical.indented + (isContinuedStatement(state, textAfter) ? statementIndent || indentUnit : 0); 689 | else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false) 690 | return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit); 691 | else if (lexical.align) return lexical.column + (closing ? 0 : 1); 692 | else return lexical.indented + (closing ? 0 : indentUnit); 693 | }, 694 | 695 | electricInput: /^\s*(?:case .*?:|default:|\{|\})$/, 696 | blockCommentStart: jsonMode ? null : "/*", 697 | blockCommentEnd: jsonMode ? null : "*/", 698 | lineComment: jsonMode ? null : "//", 699 | fold: "brace", 700 | closeBrackets: "()[]{}''\"\"``", 701 | 702 | helperType: jsonMode ? "json" : "javascript", 703 | jsonldMode: jsonldMode, 704 | jsonMode: jsonMode 705 | }; 706 | }); 707 | 708 | CodeMirror.registerHelper("wordChars", "javascript", /[\w$]/); 709 | 710 | CodeMirror.defineMIME("text/javascript", "javascript"); 711 | CodeMirror.defineMIME("text/ecmascript", "javascript"); 712 | CodeMirror.defineMIME("application/javascript", "javascript"); 713 | CodeMirror.defineMIME("application/x-javascript", "javascript"); 714 | CodeMirror.defineMIME("application/ecmascript", "javascript"); 715 | CodeMirror.defineMIME("application/json", {name: "javascript", json: true}); 716 | CodeMirror.defineMIME("application/x-json", {name: "javascript", json: true}); 717 | CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true}); 718 | CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true }); 719 | CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true }); 720 | 721 | }); 722 | -------------------------------------------------------------------------------- /example/src/app.js: -------------------------------------------------------------------------------- 1 | var React = require('react'); 2 | var ReactDOM = require('react-dom'); 3 | 4 | var selfCleaningTimeout = { 5 | componentDidUpdate: function() { 6 | clearTimeout(this.timeoutID); 7 | }, 8 | setTimeout: function() { 9 | clearTimeout(this.timeoutID); 10 | this.timeoutID = setTimeout.apply(null, arguments); 11 | } 12 | }; 13 | 14 | var ComponentPreview = React.createClass({ 15 | propTypes: { 16 | code: React.PropTypes.string.isRequired 17 | }, 18 | 19 | mixins: [selfCleaningTimeout], 20 | 21 | render: function() { 22 | return
; 23 | }, 24 | 25 | componentDidMount: function() { 26 | this.executeCode(); 27 | }, 28 | 29 | componentDidUpdate: function(prevProps) { 30 | // execute code only when the state's not being updated by switching tab 31 | // this avoids re-displaying the error, which comes after a certain delay 32 | if (this.props.code !== prevProps.code) { 33 | this.executeCode(); 34 | } 35 | }, 36 | 37 | compileCode: function() { 38 | return JSXTransformer.transform( 39 | '(function() {' + 40 | this.props.code + 41 | '\n})();', 42 | { harmony: true } 43 | ).code; 44 | }, 45 | 46 | executeCode: function() { 47 | var mountNode = this.refs.mount; 48 | 49 | try { 50 | ReactDOM.unmountComponentAtNode(mountNode); 51 | } catch (e) { } 52 | 53 | try { 54 | var compiledCode = this.compileCode(); 55 | ReactDOM.render(eval(compiledCode), mountNode); 56 | } catch (err) { 57 | 58 | this.setTimeout(function() { 59 | ReactDOM.render( 60 |
{ err.stack || err.toString() }
, 61 | mountNode 62 | ); 63 | }, 500); 64 | } 65 | } 66 | }); 67 | 68 | var IS_MOBILE = ( 69 | navigator.userAgent.match(/Android/i) 70 | || navigator.userAgent.match(/webOS/i) 71 | || navigator.userAgent.match(/iPhone/i) 72 | || navigator.userAgent.match(/iPad/i) 73 | || navigator.userAgent.match(/iPod/i) 74 | || navigator.userAgent.match(/BlackBerry/i) 75 | || navigator.userAgent.match(/Windows Phone/i) 76 | ); 77 | 78 | var CodeMirrorEditor = React.createClass({ 79 | componentDidMount: function() { 80 | if (IS_MOBILE) return; 81 | 82 | this.editor = CodeMirror.fromTextArea(this.refs.editor, { 83 | mode: 'javascript', 84 | //lineNumbers: true, 85 | viewportMargin: Infinity, 86 | lineWrapping: true, 87 | smartIndent: false, // javascript mode does bad things with jsx indents 88 | matchBrackets: true, 89 | readOnly: this.props.readOnly 90 | }); 91 | this.editor.on('change', this.handleChange); 92 | }, 93 | 94 | componentDidUpdate: function() { 95 | if (this.props.readOnly) { 96 | this.editor.setValue(this.props.codeText); 97 | } 98 | }, 99 | 100 | handleChange: function() { 101 | if (!this.props.readOnly && this.props.onChange) { 102 | this.props.onChange(this.editor.getValue()); 103 | } 104 | }, 105 | 106 | render: function() { 107 | // wrap in a div to fully contain CodeMirror 108 | var editor; 109 | 110 | if (IS_MOBILE) { 111 | editor =
{this.props.codeText}
; 112 | } else { 113 | editor =