Code Monkey home page Code Monkey logo

haixin-fang / tojson.js Goto Github PK

View Code? Open in Web Editor NEW
39.0 2.0 5.0 3.61 MB

tojson.js is a class library that supports parsing Psd, Sketch, and PPT to JSON. This JSON conforms to the data format of fabric.js rendering. (tojson.js 是一个支持解析 Psd、Sketch、PPT转 json 的类库, 该 json 满足 fabric.js 渲染的数据格式)

Home Page: https://haixin-fang.github.io/tojson.js/playground/

JavaScript 84.72% Shell 0.12% HTML 2.42% Vue 11.75% CSS 0.98%
ai pdf photoshop ppt pptx psd sketch vite vue3

tojson.js's Issues

bug: pptx自定义形状解析

定位到错误:
/pptx-json/src/index.js

不能正确解析常规形状之外的图形:

line 750

  if (custShapType && type !== "diagram") {
    const ext = getTextByPathList(slideXfrmNode, ["a:ext", "attrs"]);
    const cx = parseInt(ext["cx"]) * SLIDE_FACTOR;
    const cy = parseInt(ext["cy"]) * SLIDE_FACTOR;
    const w = parseInt(ext["cx"]) * SLIDE_FACTOR;
    const h = parseInt(ext["cy"]) * SLIDE_FACTOR;
    // TypeError: Cannot read properties of undefined (reading 'w')
    let d = '';
    console.log(custShapType, w, h)
    try {
      d = getCustomShapePath(custShapType, w, h);

    } catch (e) {
      console.log(e, 'Error')
      d = '';
    }
    return {
      ...data,
      type: "shape",
      cx,
      cy,
      shapType: "custom",
      path: d,
    };
  }

shape.js

这里忽略了数组这种情况

export function getCustomShapePath(custShapType, w, h) {
  const pathLstNode = getTextByPathList(custShapType, ['a:pathLst'])
  let pathNodes = getTextByPathList(pathLstNode, ['a:path'])

  if (Array.isArray(pathNodes)) {
    pathNodes = pathNodes.pop()
  }
  const maxX = parseInt(pathNodes['attrs']['w'])
  const maxY = parseInt(pathNodes['attrs']['h'])
  ....
  ...
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.