How to use the hastscript/svg function in hastscript

To help you get started, we’ve selected a few hastscript examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tracespace / tracespace / packages / renderer / src / index.ts View on Github external
function mapImageTreeToSvg(node: ImageNode): SvgElement {
  switch (node.type) {
    case IMAGE: {
      let box = BBox.empty()
      unistVisit(node, IMAGE_LAYER, (layer: ImageLayer) => {
        box = BBox.add(box, layer.size)
      })
      const [xMin, yMin, width, height] = BBox.toViewBox(box)
      const props = {
        ...BASE_SVG_PROPS,
        width,
        height,
        viewBox: `${xMin} ${yMin} ${width} ${height}`,
      }
      return s('svg', props)
    }

    case IMAGE_LAYER: {
      const vbox = BBox.toViewBox(node.size)
      return s('g', {
        transform: `translate(0, ${vbox[3] + 2 * vbox[1]}) scale(1,-1)`,
      })
    }

    case IMAGE_SHAPE: {
      return renderShape(node)
    }

    case IMAGE_PATH:
    case IMAGE_REGION: {
      return renderPath(node)
github tracespace / tracespace / packages / renderer / src / index.ts View on Github external
unistVisit(node, IMAGE_LAYER, (layer: ImageLayer) => {
        box = BBox.add(box, layer.size)
      })
      const [xMin, yMin, width, height] = BBox.toViewBox(box)
      const props = {
        ...BASE_SVG_PROPS,
        width,
        height,
        viewBox: `${xMin} ${yMin} ${width} ${height}`,
      }
      return s('svg', props)
    }

    case IMAGE_LAYER: {
      const vbox = BBox.toViewBox(node.size)
      return s('g', {
        transform: `translate(0, ${vbox[3] + 2 * vbox[1]}) scale(1,-1)`,
      })
    }

    case IMAGE_SHAPE: {
      return renderShape(node)
    }

    case IMAGE_PATH:
    case IMAGE_REGION: {
      return renderPath(node)
    }
  }

  return s('metadata', [JSON.stringify(node)])
}
github tracespace / tracespace / packages / renderer / src / index.ts View on Github external
return s('g', {
        transform: `translate(0, ${vbox[3] + 2 * vbox[1]}) scale(1,-1)`,
      })
    }

    case IMAGE_SHAPE: {
      return renderShape(node)
    }

    case IMAGE_PATH:
    case IMAGE_REGION: {
      return renderPath(node)
    }
  }

  return s('metadata', [JSON.stringify(node)])
}

hastscript

hast utility to create trees

MIT
Latest version published 10 months ago

Package Health Score

77 / 100
Full package analysis

Popular hastscript functions