UNPKG

@kpi4me/golden-layout

Version:

A multi-screen javascript Layout manager https://golden-layout.com

207 lines (173 loc) 6.16 kB
/* Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /*global exports:true*/ (function () { 'use strict'; var isArray, NameSequence, ZeroSequenceCache; isArray = Array.isArray; if (!isArray) { isArray = function isArray(array) { return Object.prototype.toString.call(array) === '[object Array]'; }; } function deepCopy(obj) { function deepCopyInternal(obj, result) { var key, val; for (key in obj) { if (key.lastIndexOf('__', 0) === 0) { continue; } if (obj.hasOwnProperty(key)) { val = obj[key]; if (typeof val === 'object' && val !== null) { if (val instanceof RegExp) { val = new RegExp(val); } else { val = deepCopyInternal(val, isArray(val) ? [] : {}); } } result[key] = val; } } return result; } return deepCopyInternal(obj, isArray(obj) ? [] : {}); } function stringRepeat(str, num) { var result = ''; for (num |= 0; num > 0; num >>>= 1, str += str) { if (num & 1) { result += str; } } return result; } // generateNextName ZeroSequenceCache = []; function zeroSequence(num) { var res = ZeroSequenceCache[num]; if (res !== undefined) { return res; } res = stringRepeat('0', num); ZeroSequenceCache[num] = res; return res; } NameSequence = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$'.split(''); function generateNextName(name) { var ch, index, cur; cur = name.length - 1; do { ch = name.charAt(cur); index = NameSequence.indexOf(ch); if (index !== (NameSequence.length - 1)) { return name.substring(0, cur) + NameSequence[index + 1] + zeroSequence(name.length - (cur + 1)); } --cur; } while (cur >= 0); return 'a' + zeroSequence(name.length); } // 7.6.1.2 Future Reserved Words function isFutureReservedWord(id) { switch (id) { // Future reserved words. case 'class': case 'enum': case 'export': case 'extends': case 'import': case 'super': return true; } return false; } function isStrictModeReservedWord(id) { switch (id) { // Strict Mode reserved words. case 'implements': case 'interface': case 'package': case 'private': case 'protected': case 'public': case 'static': case 'yield': case 'let': return true; } return false; } function isRestrictedWord(id) { return id === 'eval' || id === 'arguments'; } // 7.6.1.1 Keywords function isKeyword(id) { var keyword = false; switch (id.length) { case 2: keyword = (id === 'if') || (id === 'in') || (id === 'do'); break; case 3: keyword = (id === 'var') || (id === 'for') || (id === 'new') || (id === 'try'); break; case 4: keyword = (id === 'this') || (id === 'else') || (id === 'case') || (id === 'void') || (id === 'with'); break; case 5: keyword = (id === 'while') || (id === 'break') || (id === 'catch') || (id === 'throw'); break; case 6: keyword = (id === 'return') || (id === 'typeof') || (id === 'delete') || (id === 'switch'); break; case 7: keyword = (id === 'default') || (id === 'finally'); break; case 8: keyword = (id === 'function') || (id === 'continue') || (id === 'debugger'); break; case 10: keyword = (id === 'instanceof'); break; } if (keyword) { return true; } switch (id) { // Future reserved words. // 'const' is specialized as Keyword in V8. case 'const': return true; // For compatiblity to SpiderMonkey and ES.next case 'yield': case 'let': return true; } if (isStrictModeReservedWord(id)) { return true; } return isFutureReservedWord(id); } exports.generateNextName = generateNextName; exports.deepCopy = deepCopy; exports.isKeyword = isKeyword; exports.isRestrictedWord = isRestrictedWord; }()); /* vim: set sw=4 ts=4 et tw=80 : */