Skip to content

Commit

Permalink
feat: 优化svg解析,新增psd前端解析
Browse files Browse the repository at this point in the history
  • Loading branch information
LarryHangFan committed Oct 4, 2024
1 parent d49e1a0 commit 76de974
Show file tree
Hide file tree
Showing 7 changed files with 1,476 additions and 4 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@vueuse/shared": "^10.11.0",
"axios": "^1.7.2",
"beautify-qrcode": "^1.0.3",
"buffer": "^6.0.3",
"canvas": "^2.11.2",
"changedpi": "^1.0.4",
"chroma-js": "^2.4.2",
Expand All @@ -46,6 +47,7 @@
"pinia": "^2.1.7",
"pixi-filters": "^5.2.1",
"pixi.js": "^7.3.3",
"psd.js": "^3.9.0",
"raphael": "^2.3.0",
"register-service-worker": "^1.7.2",
"tinycolor2": "^1.6.0",
Expand All @@ -63,6 +65,7 @@
"@types/hammerjs": "^2.0.45",
"@types/lodash-es": "^4.17.12",
"@types/mousetrap": "^1.6.15",
"@types/node": "^22.7.4",
"@types/opentype.js": "^1.3.8",
"@types/pako": "^2.0.3",
"@types/pdfkit": "^0.13.3",
Expand Down
13 changes: 12 additions & 1 deletion src/components/FileUpload/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import useHandleCreate from '@/hooks/useHandleCreate'
import useHandleTemplate from '@/hooks/useHandleTemplate'
import useCanvas from '@/views/Canvas/useCanvas'
import usePixi from '@/views/Canvas/usePixi';
import { getObjectsFromSvgContent } from '@/extension/parse/svg'
import { getObjectsFromPsd } from '@/extension/parse/psd'
const templatesStore = useTemplatesStore()
Expand Down Expand Up @@ -67,7 +69,8 @@ const closeUpload = () => {
}
const generateSVGTemplate = async (dataText: string) => {
const content = await loadSVGFromString(dataText)
let content = await loadSVGFromString(dataText)
content = await getObjectsFromSvgContent(content);
const options = content.options
const svgData: any[] = []
content.objects.slice(0, 1000).forEach(ele => svgData.push((ele as FabricObject).toObject(propertiesToInclude)))
Expand Down Expand Up @@ -107,6 +110,14 @@ const uploadHandle = async (option: any) => {
emit('close')
return
}
if (fileSuffix === 'psd') {
const templete: any = await getObjectsFromPsd({ file:option.file });
templete.id = nanoid(10)
addTemplate(templete)
emit('close')
return
}
if (fileSuffix === 'json') {
const dataText = await getImageText(option.file)
const template = JSON.parse(dataText)
Expand Down
Loading

0 comments on commit 76de974

Please sign in to comment.