1 line
14 KiB
JSON
1 line
14 KiB
JSON
{"ast":null,"code":"import _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nexport function file2Obj(file) {\n return Object.assign(Object.assign({}, file), {\n lastModified: file.lastModified,\n lastModifiedDate: file.lastModifiedDate,\n name: file.name,\n size: file.size,\n type: file.type,\n uid: file.uid,\n percent: 0,\n originFileObj: file\n });\n}\n/** Upload fileList. Replace file if exist or just push into it. */\nexport function updateFileList(file, fileList) {\n const nextFileList = _toConsumableArray(fileList);\n const fileIndex = nextFileList.findIndex(_ref => {\n let {\n uid\n } = _ref;\n return uid === file.uid;\n });\n if (fileIndex === -1) {\n nextFileList.push(file);\n } else {\n nextFileList[fileIndex] = file;\n }\n return nextFileList;\n}\nexport function getFileItem(file, fileList) {\n const matchKey = file.uid !== undefined ? 'uid' : 'name';\n return fileList.filter(item => item[matchKey] === file[matchKey])[0];\n}\nexport function removeFileItem(file, fileList) {\n const matchKey = file.uid !== undefined ? 'uid' : 'name';\n const removed = fileList.filter(item => item[matchKey] !== file[matchKey]);\n if (removed.length === fileList.length) {\n return null;\n }\n return removed;\n}\n// ==================== Default Image Preview ====================\nconst extname = function () {\n let url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';\n const temp = url.split('/');\n const filename = temp[temp.length - 1];\n const filenameWithoutSuffix = filename.split(/#|\\?/)[0];\n return (/\\.[^./\\\\]*$/.exec(filenameWithoutSuffix) || [''])[0];\n};\nconst isImageFileType = type => type.indexOf('image/') === 0;\nexport const isImageUrl = file => {\n if (file.type && !file.thumbUrl) {\n return isImageFileType(file.type);\n }\n const url = file.thumbUrl || file.url || '';\n const extension = extname(url);\n if (/^data:image\\//.test(url) || /(webp|svg|png|gif|jpg|jpeg|jfif|bmp|dpg|ico|heic|heif)$/i.test(extension)) {\n return true;\n }\n if (/^data:/.test(url)) {\n // other file types of base64\n return false;\n }\n if (extension) {\n // other file types which have extension\n return false;\n }\n return true;\n};\nconst MEASURE_SIZE = 200;\nexport function previewImage(file) {\n return new Promise(resolve => {\n if (!file.type || !isImageFileType(file.type)) {\n resolve('');\n return;\n }\n const canvas = document.createElement('canvas');\n canvas.width = MEASURE_SIZE;\n canvas.height = MEASURE_SIZE;\n canvas.style.cssText = `position: fixed; left: 0; top: 0; width: ${MEASURE_SIZE}px; height: ${MEASURE_SIZE}px; z-index: 9999; display: none;`;\n document.body.appendChild(canvas);\n const ctx = canvas.getContext('2d');\n const img = new Image();\n img.onload = () => {\n const {\n width,\n height\n } = img;\n let drawWidth = MEASURE_SIZE;\n let drawHeight = MEASURE_SIZE;\n let offsetX = 0;\n let offsetY = 0;\n if (width > height) {\n drawHeight = height * (MEASURE_SIZE / width);\n offsetY = -(drawHeight - drawWidth) / 2;\n } else {\n drawWidth = width * (MEASURE_SIZE / height);\n offsetX = -(drawWidth - drawHeight) / 2;\n }\n ctx.drawImage(img, offsetX, offsetY, drawWidth, drawHeight);\n const dataURL = canvas.toDataURL();\n document.body.removeChild(canvas);\n window.URL.revokeObjectURL(img.src);\n resolve(dataURL);\n };\n img.crossOrigin = 'anonymous';\n if (file.type.startsWith('image/svg+xml')) {\n const reader = new FileReader();\n reader.onload = () => {\n if (reader.result && typeof reader.result === 'string') {\n img.src = reader.result;\n }\n };\n reader.readAsDataURL(file);\n } else if (file.type.startsWith('image/gif')) {\n const reader = new FileReader();\n reader.onload = () => {\n if (reader.result) {\n resolve(reader.result);\n }\n };\n reader.readAsDataURL(file);\n } else {\n img.src = window.URL.createObjectURL(file);\n }\n });\n}","map":{"version":3,"names":["_toConsumableArray","file2Obj","file","Object","assign","lastModified","lastModifiedDate","name","size","type","uid","percent","originFileObj","updateFileList","fileList","nextFileList","fileIndex","findIndex","_ref","push","getFileItem","matchKey","undefined","filter","item","removeFileItem","removed","length","extname","url","arguments","temp","split","filename","filenameWithoutSuffix","exec","isImageFileType","indexOf","isImageUrl","thumbUrl","extension","test","MEASURE_SIZE","previewImage","Promise","resolve","canvas","document","createElement","width","height","style","cssText","body","appendChild","ctx","getContext","img","Image","onload","drawWidth","drawHeight","offsetX","offsetY","drawImage","dataURL","toDataURL","removeChild","window","URL","revokeObjectURL","src","crossOrigin","startsWith","reader","FileReader","result","readAsDataURL","createObjectURL"],"sources":["C:/Users/Аришина)/Desktop/promo/node_modules/antd/es/upload/utils.js"],"sourcesContent":["import _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nexport function file2Obj(file) {\n return Object.assign(Object.assign({}, file), {\n lastModified: file.lastModified,\n lastModifiedDate: file.lastModifiedDate,\n name: file.name,\n size: file.size,\n type: file.type,\n uid: file.uid,\n percent: 0,\n originFileObj: file\n });\n}\n/** Upload fileList. Replace file if exist or just push into it. */\nexport function updateFileList(file, fileList) {\n const nextFileList = _toConsumableArray(fileList);\n const fileIndex = nextFileList.findIndex(_ref => {\n let {\n uid\n } = _ref;\n return uid === file.uid;\n });\n if (fileIndex === -1) {\n nextFileList.push(file);\n } else {\n nextFileList[fileIndex] = file;\n }\n return nextFileList;\n}\nexport function getFileItem(file, fileList) {\n const matchKey = file.uid !== undefined ? 'uid' : 'name';\n return fileList.filter(item => item[matchKey] === file[matchKey])[0];\n}\nexport function removeFileItem(file, fileList) {\n const matchKey = file.uid !== undefined ? 'uid' : 'name';\n const removed = fileList.filter(item => item[matchKey] !== file[matchKey]);\n if (removed.length === fileList.length) {\n return null;\n }\n return removed;\n}\n// ==================== Default Image Preview ====================\nconst extname = function () {\n let url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';\n const temp = url.split('/');\n const filename = temp[temp.length - 1];\n const filenameWithoutSuffix = filename.split(/#|\\?/)[0];\n return (/\\.[^./\\\\]*$/.exec(filenameWithoutSuffix) || [''])[0];\n};\nconst isImageFileType = type => type.indexOf('image/') === 0;\nexport const isImageUrl = file => {\n if (file.type && !file.thumbUrl) {\n return isImageFileType(file.type);\n }\n const url = file.thumbUrl || file.url || '';\n const extension = extname(url);\n if (/^data:image\\//.test(url) || /(webp|svg|png|gif|jpg|jpeg|jfif|bmp|dpg|ico|heic|heif)$/i.test(extension)) {\n return true;\n }\n if (/^data:/.test(url)) {\n // other file types of base64\n return false;\n }\n if (extension) {\n // other file types which have extension\n return false;\n }\n return true;\n};\nconst MEASURE_SIZE = 200;\nexport function previewImage(file) {\n return new Promise(resolve => {\n if (!file.type || !isImageFileType(file.type)) {\n resolve('');\n return;\n }\n const canvas = document.createElement('canvas');\n canvas.width = MEASURE_SIZE;\n canvas.height = MEASURE_SIZE;\n canvas.style.cssText = `position: fixed; left: 0; top: 0; width: ${MEASURE_SIZE}px; height: ${MEASURE_SIZE}px; z-index: 9999; display: none;`;\n document.body.appendChild(canvas);\n const ctx = canvas.getContext('2d');\n const img = new Image();\n img.onload = () => {\n const {\n width,\n height\n } = img;\n let drawWidth = MEASURE_SIZE;\n let drawHeight = MEASURE_SIZE;\n let offsetX = 0;\n let offsetY = 0;\n if (width > height) {\n drawHeight = height * (MEASURE_SIZE / width);\n offsetY = -(drawHeight - drawWidth) / 2;\n } else {\n drawWidth = width * (MEASURE_SIZE / height);\n offsetX = -(drawWidth - drawHeight) / 2;\n }\n ctx.drawImage(img, offsetX, offsetY, drawWidth, drawHeight);\n const dataURL = canvas.toDataURL();\n document.body.removeChild(canvas);\n window.URL.revokeObjectURL(img.src);\n resolve(dataURL);\n };\n img.crossOrigin = 'anonymous';\n if (file.type.startsWith('image/svg+xml')) {\n const reader = new FileReader();\n reader.onload = () => {\n if (reader.result && typeof reader.result === 'string') {\n img.src = reader.result;\n }\n };\n reader.readAsDataURL(file);\n } else if (file.type.startsWith('image/gif')) {\n const reader = new FileReader();\n reader.onload = () => {\n if (reader.result) {\n resolve(reader.result);\n }\n };\n reader.readAsDataURL(file);\n } else {\n img.src = window.URL.createObjectURL(file);\n }\n });\n}"],"mappings":"AAAA,OAAOA,kBAAkB,MAAM,8CAA8C;AAC7E,OAAO,SAASC,QAAQA,CAACC,IAAI,EAAE;EAC7B,OAAOC,MAAM,CAACC,MAAM,CAACD,MAAM,CAACC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