dba841c6dd964b39da179c169bbf67f4.json
25.6 KB
{"ast":null,"code":"/**\r\n * @author NHN Ent. FE Development Team <dl_javascript@nhn.com>\r\n * @fileoverview Util\r\n */\nimport { forEach, sendHostname, extend, isString, pick, inArray } from 'tui-code-snippet';\nimport Promise from 'core-js-pure/features/promise';\nimport { SHAPE_FILL_TYPE, SHAPE_TYPE } from './consts';\nconst FLOATING_POINT_DIGIT = 2;\nconst CSS_PREFIX = 'tui-image-editor-';\nconst {\n min,\n max\n} = Math;\nlet hostnameSent = false;\n/**\r\n * Export Promise Class (for simplified module path)\r\n * @returns {Promise} promise class\r\n */\n\nexport { Promise };\n/**\r\n * Clamp value\r\n * @param {number} value - Value\r\n * @param {number} minValue - Minimum value\r\n * @param {number} maxValue - Maximum value\r\n * @returns {number} clamped value\r\n */\n\nexport function clamp(value, minValue, maxValue) {\n let temp;\n\n if (minValue > maxValue) {\n temp = minValue;\n minValue = maxValue;\n maxValue = temp;\n }\n\n return max(minValue, min(value, maxValue));\n}\n/**\r\n * Make key-value object from arguments\r\n * @returns {object.<string, string>}\r\n */\n\nexport function keyMirror(...args) {\n const obj = {};\n forEach(args, key => {\n obj[key] = key;\n });\n return obj;\n}\n/**\r\n * Make CSSText\r\n * @param {Object} styleObj - Style info object\r\n * @returns {string} Connected string of style\r\n */\n\nexport function makeStyleText(styleObj) {\n let styleStr = '';\n forEach(styleObj, (value, prop) => {\n styleStr += `${prop}: ${value};`;\n });\n return styleStr;\n}\n/**\r\n * Get object's properties\r\n * @param {Object} obj - object\r\n * @param {Array} keys - keys\r\n * @returns {Object} properties object\r\n */\n\nexport function getProperties(obj, keys) {\n const props = {};\n const {\n length\n } = keys;\n let i = 0;\n let key;\n\n for (i = 0; i < length; i += 1) {\n key = keys[i];\n props[key] = obj[key];\n }\n\n return props;\n}\n/**\r\n * ParseInt simpliment\r\n * @param {number} value - Value\r\n * @returns {number}\r\n */\n\nexport function toInteger(value) {\n return parseInt(value, 10);\n}\n/**\r\n * String to camelcase string\r\n * @param {string} targetString - change target\r\n * @returns {string}\r\n * @private\r\n */\n\nexport function toCamelCase(targetString) {\n return targetString.replace(/-([a-z])/g, ($0, $1) => $1.toUpperCase());\n}\n/**\r\n * Check browser file api support\r\n * @returns {boolean}\r\n * @private\r\n */\n\nexport function isSupportFileApi() {\n return !!(window.File && window.FileList && window.FileReader);\n}\n/**\r\n * hex to rgb\r\n * @param {string} color - hex color\r\n * @param {string} alpha - color alpha value\r\n * @returns {string} rgb expression\r\n */\n\nexport function getRgb(color, alpha) {\n if (color.length === 4) {\n color = `${color}${color.slice(1, 4)}`;\n }\n\n const r = parseInt(color.slice(1, 3), 16);\n const g = parseInt(color.slice(3, 5), 16);\n const b = parseInt(color.slice(5, 7), 16);\n const a = alpha || 1;\n return `rgba(${r}, ${g}, ${b}, ${a})`;\n}\n/**\r\n * send hostname\r\n */\n\nexport function sendHostName() {\n if (hostnameSent) {\n return;\n }\n\n hostnameSent = true;\n sendHostname('image-editor', 'UA-129999381-1');\n}\n/**\r\n * Apply css resource\r\n * @param {string} styleBuffer - serialized css text\r\n * @param {string} tagId - style tag id\r\n */\n\nexport function styleLoad(styleBuffer, tagId) {\n const [head] = document.getElementsByTagName('head');\n const linkElement = document.createElement('link');\n const styleData = encodeURIComponent(styleBuffer);\n\n if (tagId) {\n linkElement.id = tagId; // linkElement.id = 'tui-image-editor-theme-style';\n }\n\n linkElement.setAttribute('rel', 'stylesheet');\n linkElement.setAttribute('type', 'text/css');\n linkElement.setAttribute('href', `data:text/css;charset=UTF-8,${styleData}`);\n head.appendChild(linkElement);\n}\n/**\r\n * Get selector\r\n * @param {HTMLElement} targetElement - target element\r\n * @returns {Function} selector\r\n */\n\nexport function getSelector(targetElement) {\n return str => targetElement.querySelector(str);\n}\n/**\r\n * Change base64 to blob\r\n * @param {String} data - base64 string data\r\n * @returns {Blob} Blob Data\r\n */\n\nexport function base64ToBlob(data) {\n const rImageType = /data:(image\\/.+);base64,/;\n let mimeString = '';\n let raw, uInt8Array, i;\n raw = data.replace(rImageType, (header, imageType) => {\n mimeString = imageType;\n return '';\n });\n raw = atob(raw);\n const rawLength = raw.length;\n uInt8Array = new Uint8Array(rawLength); // eslint-disable-line\n\n for (i = 0; i < rawLength; i += 1) {\n uInt8Array[i] = raw.charCodeAt(i);\n }\n\n return new Blob([uInt8Array], {\n type: mimeString\n });\n}\n/**\r\n * Fix floating point diff.\r\n * @param {number} value - original value\r\n * @returns {number} fixed value\r\n */\n\nexport function fixFloatingPoint(value) {\n return Number(value.toFixed(FLOATING_POINT_DIGIT));\n}\n/**\r\n * Assignment for destroying objects.\r\n * @param {Object} targetObject - object to be removed.\r\n */\n\nexport function assignmentForDestroy(targetObject) {\n forEach(targetObject, (value, key) => {\n targetObject[key] = null;\n });\n}\n/**\r\n * Make class name for ui\r\n * @param {String} str - main string of className\r\n * @param {String} prefix - prefix string of className\r\n * @returns {String} class name\r\n */\n\nexport function cls(str = '', prefix = '') {\n if (str.charAt(0) === '.') {\n return `.${CSS_PREFIX}${prefix}${str.slice(1)}`;\n }\n\n return `${CSS_PREFIX}${prefix}${str}`;\n}\n/**\r\n * Change object origin\r\n * @param {fabric.Object} fObject - fabric object\r\n * @param {Object} origin - origin of fabric object\r\n * @param {string} originX - horizontal basis.\r\n * @param {string} originY - vertical basis.\r\n */\n\nexport function changeOrigin(fObject, origin) {\n const {\n originX,\n originY\n } = origin;\n const {\n x: left,\n y: top\n } = fObject.getPointByOrigin(originX, originY);\n fObject.set({\n left,\n top,\n originX,\n originY\n });\n fObject.setCoords();\n}\n/**\r\n * Object key value flip\r\n * @param {Object} targetObject - The data object of the key value.\r\n * @returns {Object}\r\n */\n\nexport function flipObject(targetObject) {\n const result = {};\n Object.keys(targetObject).forEach(key => {\n result[targetObject[key]] = key;\n });\n return result;\n}\n/**\r\n * Set custom properties\r\n * @param {Object} targetObject - target object\r\n * @param {Object} props - custom props object\r\n */\n\nexport function setCustomProperty(targetObject, props) {\n targetObject.customProps = targetObject.customProps || {};\n extend(targetObject.customProps, props);\n}\n/**\r\n * Get custom property\r\n * @param {fabric.Object} fObject - fabric object\r\n * @param {Array|string} propNames - prop name array\r\n * @returns {object | number | string}\r\n */\n\nexport function getCustomProperty(fObject, propNames) {\n const resultObject = {};\n\n if (isString(propNames)) {\n propNames = [propNames];\n }\n\n forEach(propNames, propName => {\n resultObject[propName] = fObject.customProps[propName];\n });\n return resultObject;\n}\n/**\r\n * Capitalize string\r\n * @param {string} targetString - target string\r\n * @returns {string}\r\n */\n\nexport function capitalizeString(targetString) {\n return targetString.charAt(0).toUpperCase() + targetString.slice(1);\n}\n/**\r\n * Array includes check\r\n * @param {Array} targetArray - target array\r\n * @param {string|number} compareValue - compare value\r\n * @returns {boolean}\r\n */\n\nexport function includes(targetArray, compareValue) {\n return targetArray.indexOf(compareValue) >= 0;\n}\n/**\r\n * Get fill type\r\n * @param {Object | string} fillOption - shape fill option\r\n * @returns {string} 'color' or 'filter'\r\n */\n\nexport function getFillTypeFromOption(fillOption = {}) {\n return pick(fillOption, 'type') || SHAPE_FILL_TYPE.COLOR;\n}\n/**\r\n * Get fill type of shape type object\r\n * @param {fabric.Object} shapeObj - fabric object\r\n * @returns {string} 'transparent' or 'color' or 'filter'\r\n */\n\nexport function getFillTypeFromObject(shapeObj) {\n const {\n fill = {}\n } = shapeObj;\n\n if (fill.source) {\n return SHAPE_FILL_TYPE.FILTER;\n }\n\n return SHAPE_FILL_TYPE.COLOR;\n}\n/**\r\n * Check if the object is a shape object.\r\n * @param {fabric.Object} obj - fabric object\r\n * @returns {boolean}\r\n */\n\nexport function isShape(obj) {\n return inArray(obj.get('type'), SHAPE_TYPE) >= 0;\n}","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/src/js/util.js"],"names":["forEach","sendHostname","extend","isString","pick","inArray","Promise","SHAPE_FILL_TYPE","SHAPE_TYPE","FLOATING_POINT_DIGIT","CSS_PREFIX","min","max","Math","hostnameSent","clamp","value","minValue","maxValue","temp","keyMirror","args","obj","key","makeStyleText","styleObj","styleStr","prop","getProperties","keys","props","length","i","toInteger","parseInt","toCamelCase","targetString","replace","$0","$1","toUpperCase","isSupportFileApi","window","File","FileList","FileReader","getRgb","color","alpha","slice","r","g","b","a","sendHostName","styleLoad","styleBuffer","tagId","head","document","getElementsByTagName","linkElement","createElement","styleData","encodeURIComponent","id","setAttribute","appendChild","getSelector","targetElement","str","querySelector","base64ToBlob","data","rImageType","mimeString","raw","uInt8Array","header","imageType","atob","rawLength","Uint8Array","charCodeAt","Blob","type","fixFloatingPoint","Number","toFixed","assignmentForDestroy","targetObject","cls","prefix","charAt","changeOrigin","fObject","origin","originX","originY","x","left","y","top","getPointByOrigin","set","setCoords","flipObject","result","Object","setCustomProperty","customProps","getCustomProperty","propNames","resultObject","propName","capitalizeString","includes","targetArray","compareValue","indexOf","getFillTypeFromOption","fillOption","COLOR","getFillTypeFromObject","shapeObj","fill","source","FILTER","isShape","get"],"mappings":"AAAA;AACA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,YAAlB,EAAgCC,MAAhC,EAAwCC,QAAxC,EAAkDC,IAAlD,EAAwDC,OAAxD,QAAuE,kBAAvE;AACA,OAAOC,OAAP,MAAoB,+BAApB;AACA,SAASC,eAAT,EAA0BC,UAA1B,QAA4C,UAA5C;AACA,MAAMC,oBAAoB,GAAG,CAA7B;AACA,MAAMC,UAAU,GAAG,mBAAnB;AACA,MAAM;AAAEC,EAAAA,GAAF;AAAOC,EAAAA;AAAP,IAAeC,IAArB;AACA,IAAIC,YAAY,GAAG,KAAnB;AAEA;AACA;AACA;AACA;;AACA,SAASR,OAAT;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASS,KAAT,CAAeC,KAAf,EAAsBC,QAAtB,EAAgCC,QAAhC,EAA0C;AAC/C,MAAIC,IAAJ;;AACA,MAAIF,QAAQ,GAAGC,QAAf,EAAyB;AACvBC,IAAAA,IAAI,GAAGF,QAAP;AACAA,IAAAA,QAAQ,GAAGC,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AD,CAAZ,GAAyBnB,OAAO,CAACe,WAAR,CAAoBI,QAApB,CAAzB;AACD,GAFM,CAAP;AAIA,SAAOD,YAAP;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,gBAAT,CAA0B/E,YAA1B,EAAwC;AAC7C,SAAOA,YAAY,CAACyD,MAAb,CAAoB,CAApB,EAAuBrD,WAAvB,KAAuCJ,YAAY,CAACa,KAAb,CAAmB,CAAnB,CAA9C;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASmE,QAAT,CAAkBC,WAAlB,EAA+BC,YAA/B,EAA6C;AAClD,SAAOD,WAAW,CAACE,OAAZ,CAAoBD,YAApB,KAAqC,CAA5C;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,qBAAT,CAA+BC,UAAU,GAAG,EAA5C,EAAgD;AACrD,SAAOrH,IAAI,CAACqH,UAAD,EAAa,MAAb,CAAJ,IAA4BlH,eAAe,CAACmH,KAAnD;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,qBAAT,CAA+BC,QAA/B,EAAyC;AAC9C,QAAM;AAAEC,IAAAA,IAAI,GAAG;AAAT,MAAgBD,QAAtB;;AACA,MAAIC,IAAI,CAACC,MAAT,EAAiB;AACf,WAAOvH,eAAe,CAACwH,MAAvB;AACD;;AAED,SAAOxH,eAAe,CAACmH,KAAvB;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASM,OAAT,CAAiB1G,GAAjB,EAAsB;AAC3B,SAAOjB,OAAO,CAACiB,GAAG,CAAC2G,GAAJ,CAAQ,MAAR,CAAD,EAAkBzH,UAAlB,CAAP,IAAwC,CAA/C;AACD","sourcesContent":["/**\r\n * @author NHN Ent. FE Development Team <dl_javascript@nhn.com>\r\n * @fileoverview Util\r\n */\r\nimport { forEach, sendHostname, extend, isString, pick, inArray } from 'tui-code-snippet';\r\nimport Promise from 'core-js-pure/features/promise';\r\nimport { SHAPE_FILL_TYPE, SHAPE_TYPE } from './consts';\r\nconst FLOATING_POINT_DIGIT = 2;\r\nconst CSS_PREFIX = 'tui-image-editor-';\r\nconst { min, max } = Math;\r\nlet hostnameSent = false;\r\n\r\n/**\r\n * Export Promise Class (for simplified module path)\r\n * @returns {Promise} promise class\r\n */\r\nexport { Promise };\r\n\r\n/**\r\n * Clamp value\r\n * @param {number} value - Value\r\n * @param {number} minValue - Minimum value\r\n * @param {number} maxValue - Maximum value\r\n * @returns {number} clamped value\r\n */\r\nexport function clamp(value, minValue, maxValue) {\r\n let temp;\r\n if (minValue > maxValue) {\r\n temp = minValue;\r\n minValue = maxValue;\r\n maxValue = temp;\r\n }\r\n\r\n return max(minValue, min(value, maxValue));\r\n}\r\n\r\n/**\r\n * Make key-value object from arguments\r\n * @returns {object.<string, string>}\r\n */\r\nexport function keyMirror(...args) {\r\n const obj = {};\r\n\r\n forEach(args, (key) => {\r\n obj[key] = key;\r\n });\r\n\r\n return obj;\r\n}\r\n\r\n/**\r\n * Make CSSText\r\n * @param {Object} styleObj - Style info object\r\n * @returns {string} Connected string of style\r\n */\r\nexport function makeStyleText(styleObj) {\r\n let styleStr = '';\r\n\r\n forEach(styleObj, (value, prop) => {\r\n styleStr += `${prop}: ${value};`;\r\n });\r\n\r\n return styleStr;\r\n}\r\n\r\n/**\r\n * Get object's properties\r\n * @param {Object} obj - object\r\n * @param {Array} keys - keys\r\n * @returns {Object} properties object\r\n */\r\nexport function getProperties(obj, keys) {\r\n const props = {};\r\n const { length } = keys;\r\n let i = 0;\r\n let key;\r\n\r\n for (i = 0; i < length; i += 1) {\r\n key = keys[i];\r\n props[key] = obj[key];\r\n }\r\n\r\n return props;\r\n}\r\n\r\n/**\r\n * ParseInt simpliment\r\n * @param {number} value - Value\r\n * @returns {number}\r\n */\r\nexport function toInteger(value) {\r\n return parseInt(value, 10);\r\n}\r\n\r\n/**\r\n * String to camelcase string\r\n * @param {string} targetString - change target\r\n * @returns {string}\r\n * @private\r\n */\r\nexport function toCamelCase(targetString) {\r\n return targetString.replace(/-([a-z])/g, ($0, $1) => $1.toUpperCase());\r\n}\r\n\r\n/**\r\n * Check browser file api support\r\n * @returns {boolean}\r\n * @private\r\n */\r\nexport function isSupportFileApi() {\r\n return !!(window.File && window.FileList && window.FileReader);\r\n}\r\n\r\n/**\r\n * hex to rgb\r\n * @param {string} color - hex color\r\n * @param {string} alpha - color alpha value\r\n * @returns {string} rgb expression\r\n */\r\nexport function getRgb(color, alpha) {\r\n if (color.length === 4) {\r\n color = `${color}${color.slice(1, 4)}`;\r\n }\r\n const r = parseInt(color.slice(1, 3), 16);\r\n const g = parseInt(color.slice(3, 5), 16);\r\n const b = parseInt(color.slice(5, 7), 16);\r\n const a = alpha || 1;\r\n\r\n return `rgba(${r}, ${g}, ${b}, ${a})`;\r\n}\r\n\r\n/**\r\n * send hostname\r\n */\r\nexport function sendHostName() {\r\n if (hostnameSent) {\r\n return;\r\n }\r\n hostnameSent = true;\r\n\r\n sendHostname('image-editor', 'UA-129999381-1');\r\n}\r\n\r\n/**\r\n * Apply css resource\r\n * @param {string} styleBuffer - serialized css text\r\n * @param {string} tagId - style tag id\r\n */\r\nexport function styleLoad(styleBuffer, tagId) {\r\n const [head] = document.getElementsByTagName('head');\r\n const linkElement = document.createElement('link');\r\n const styleData = encodeURIComponent(styleBuffer);\r\n if (tagId) {\r\n linkElement.id = tagId;\r\n // linkElement.id = 'tui-image-editor-theme-style';\r\n }\r\n linkElement.setAttribute('rel', 'stylesheet');\r\n linkElement.setAttribute('type', 'text/css');\r\n linkElement.setAttribute('href', `data:text/css;charset=UTF-8,${styleData}`);\r\n head.appendChild(linkElement);\r\n}\r\n\r\n/**\r\n * Get selector\r\n * @param {HTMLElement} targetElement - target element\r\n * @returns {Function} selector\r\n */\r\nexport function getSelector(targetElement) {\r\n return (str) => targetElement.querySelector(str);\r\n}\r\n\r\n/**\r\n * Change base64 to blob\r\n * @param {String} data - base64 string data\r\n * @returns {Blob} Blob Data\r\n */\r\nexport function base64ToBlob(data) {\r\n const rImageType = /data:(image\\/.+);base64,/;\r\n let mimeString = '';\r\n let raw, uInt8Array, i;\r\n\r\n raw = data.replace(rImageType, (header, imageType) => {\r\n mimeString = imageType;\r\n\r\n return '';\r\n });\r\n\r\n raw = atob(raw);\r\n const rawLength = raw.length;\r\n uInt8Array = new Uint8Array(rawLength); // eslint-disable-line\r\n\r\n for (i = 0; i < rawLength; i += 1) {\r\n uInt8Array[i] = raw.charCodeAt(i);\r\n }\r\n\r\n return new Blob([uInt8Array], { type: mimeString });\r\n}\r\n\r\n/**\r\n * Fix floating point diff.\r\n * @param {number} value - original value\r\n * @returns {number} fixed value\r\n */\r\nexport function fixFloatingPoint(value) {\r\n return Number(value.toFixed(FLOATING_POINT_DIGIT));\r\n}\r\n\r\n/**\r\n * Assignment for destroying objects.\r\n * @param {Object} targetObject - object to be removed.\r\n */\r\nexport function assignmentForDestroy(targetObject) {\r\n forEach(targetObject, (value, key) => {\r\n targetObject[key] = null;\r\n });\r\n}\r\n\r\n/**\r\n * Make class name for ui\r\n * @param {String} str - main string of className\r\n * @param {String} prefix - prefix string of className\r\n * @returns {String} class name\r\n */\r\nexport function cls(str = '', prefix = '') {\r\n if (str.charAt(0) === '.') {\r\n return `.${CSS_PREFIX}${prefix}${str.slice(1)}`;\r\n }\r\n\r\n return `${CSS_PREFIX}${prefix}${str}`;\r\n}\r\n\r\n/**\r\n * Change object origin\r\n * @param {fabric.Object} fObject - fabric object\r\n * @param {Object} origin - origin of fabric object\r\n * @param {string} originX - horizontal basis.\r\n * @param {string} originY - vertical basis.\r\n */\r\nexport function changeOrigin(fObject, origin) {\r\n const { originX, originY } = origin;\r\n const { x: left, y: top } = fObject.getPointByOrigin(originX, originY);\r\n\r\n fObject.set({\r\n left,\r\n top,\r\n originX,\r\n originY,\r\n });\r\n\r\n fObject.setCoords();\r\n}\r\n\r\n/**\r\n * Object key value flip\r\n * @param {Object} targetObject - The data object of the key value.\r\n * @returns {Object}\r\n */\r\nexport function flipObject(targetObject) {\r\n const result = {};\r\n\r\n Object.keys(targetObject).forEach((key) => {\r\n result[targetObject[key]] = key;\r\n });\r\n\r\n return result;\r\n}\r\n\r\n/**\r\n * Set custom properties\r\n * @param {Object} targetObject - target object\r\n * @param {Object} props - custom props object\r\n */\r\nexport function setCustomProperty(targetObject, props) {\r\n targetObject.customProps = targetObject.customProps || {};\r\n extend(targetObject.customProps, props);\r\n}\r\n\r\n/**\r\n * Get custom property\r\n * @param {fabric.Object} fObject - fabric object\r\n * @param {Array|string} propNames - prop name array\r\n * @returns {object | number | string}\r\n */\r\nexport function getCustomProperty(fObject, propNames) {\r\n const resultObject = {};\r\n if (isString(propNames)) {\r\n propNames = [propNames];\r\n }\r\n forEach(propNames, (propName) => {\r\n resultObject[propName] = fObject.customProps[propName];\r\n });\r\n\r\n return resultObject;\r\n}\r\n\r\n/**\r\n * Capitalize string\r\n * @param {string} targetString - target string\r\n * @returns {string}\r\n */\r\nexport function capitalizeString(targetString) {\r\n return targetString.charAt(0).toUpperCase() + targetString.slice(1);\r\n}\r\n\r\n/**\r\n * Array includes check\r\n * @param {Array} targetArray - target array\r\n * @param {string|number} compareValue - compare value\r\n * @returns {boolean}\r\n */\r\nexport function includes(targetArray, compareValue) {\r\n return targetArray.indexOf(compareValue) >= 0;\r\n}\r\n\r\n/**\r\n * Get fill type\r\n * @param {Object | string} fillOption - shape fill option\r\n * @returns {string} 'color' or 'filter'\r\n */\r\nexport function getFillTypeFromOption(fillOption = {}) {\r\n return pick(fillOption, 'type') || SHAPE_FILL_TYPE.COLOR;\r\n}\r\n\r\n/**\r\n * Get fill type of shape type object\r\n * @param {fabric.Object} shapeObj - fabric object\r\n * @returns {string} 'transparent' or 'color' or 'filter'\r\n */\r\nexport function getFillTypeFromObject(shapeObj) {\r\n const { fill = {} } = shapeObj;\r\n if (fill.source) {\r\n return SHAPE_FILL_TYPE.FILTER;\r\n }\r\n\r\n return SHAPE_FILL_TYPE.COLOR;\r\n}\r\n\r\n/**\r\n * Check if the object is a shape object.\r\n * @param {fabric.Object} obj - fabric object\r\n * @returns {boolean}\r\n */\r\nexport function isShape(obj) {\r\n return inArray(obj.get('type'), SHAPE_TYPE) >= 0;\r\n}\r\n"]},"metadata":{},"sourceType":"module"}