Skip to content

Commit

Permalink
feat: 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lijunchang committed Dec 6, 2023
1 parent bc42f54 commit 86df9bd
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 11 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## 1.0.1 - 2023-12-06

### Features

* Update document


## 1.0.0 - 2023-12-06

### Features

* Refactor dom-to-svg

### Bug Fixes

* Safari returns 2 DOMRects when wrapping text.
35 changes: 25 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
# DOM to SVG
<h1 align="center">dom2svg</h1>

[![npm](https://img.shields.io/npm/v/dom2svg)](https://www.npmjs.com/package/dom2svg)
[![CI status](https://github.com/felixfbecker/dom2svg/workflows/test/badge.svg?branch=main)](https://github.com/felixfbecker/dom2svg/actions)
![license: MIT](https://img.shields.io/npm/l/dom2svg)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
<p align="center">
<a href="https://www.npmjs.com/package/dom2svg">
<img src="https://img.shields.io/npm/v/dom2svg.svg" alt="Version">
</a>
<a href="https://www.npmjs.com/package/dom2svg">
<img src="https://img.shields.io/npm/dm/dom2svg" alt="Downloads">
</a>
<a href="https://github.com/xiashui1994/dom2svg/issues">
<img src="https://img.shields.io/github/issues/xiashui1994/dom2svg" alt="Issues">
</a>
<a href="https://github.com/xiashui1994/dom2svg/blob/main/LICENSE">
<img src="https://img.shields.io/npm/l/dom2svg.svg" alt="License">
</a>
</p>

Library to convert a given HTML DOM node into an accessible SVG "screenshot".
<p align="center">Library to convert a given HTML DOM node into an accessible SVG "screenshot".</p>

## Demo 📸
<p align="center">Fork from <a href="https://github.com/felixfbecker/dom-to-svg">dom-to-svg</a></p>

Try out the [SVG Screenshots Chrome extension](https://chrome.google.com/webstore/detail/svg-screenshot/nfakpcpmhhilkdpphcjgnokknpbpdllg) which uses this library to allow you to take SVG screenshots of any webpage.
You can find the source code at [github.com/felixfbecker/svg-screenshots](https://github.com/felixfbecker/svg-screenshots).
<p align="center">English | <a href="README.zh-CN.md">简体中文</a></p>

## Install

```sh
pnpm/npm/yarn i dom2svg
```

## Usage

Expand Down Expand Up @@ -44,4 +59,4 @@ The output can be used as-is as valid SVG or easily passed to other packages to

## Caveats

- Designed to run in the browser. Using JSDOM on the server will likely not work, but it can easily run inside Puppeteer.
- Designed to run in the browser. Using JSDOM on the server will likely not work, but it can easily run inside Puppeteer.
62 changes: 62 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<h1 align="center">dom2svg</h1>

<p align="center">
<a href="https://www.npmjs.com/package/dom2svg">
<img src="https://img.shields.io/npm/v/dom2svg.svg" alt="Version">
</a>
<a href="https://www.npmjs.com/package/dom2svg">
<img src="https://img.shields.io/npm/dm/dom2svg" alt="Downloads">
</a>
<a href="https://github.com/xiashui1994/dom2svg/issues">
<img src="https://img.shields.io/github/issues/xiashui1994/dom2svg" alt="Issues">
</a>
<a href="https://github.com/xiashui1994/dom2svg/blob/main/LICENSE">
<img src="https://img.shields.io/npm/l/dom2svg.svg" alt="License">
</a>
</p>

<p align="center">将给定的 HTML DOM 节点转换为可访问的 SVG "屏幕截图" 的库。</p>

<p align="center">复刻自 <a href="https://github.com/felixfbecker/dom-to-svg">dom-to-svg</a></p>

<p align="center"><a href="README.md">English</a> | 简体中文</p>

## 安装

```sh
pnpm/npm/yarn i dom2svg
```

## 使用

```js
import { documentToSVG, elementToSVG, inlineResources, formatXML } from 'dom2svg'

// 捕获整个文档
const svgDocument = documentToSVG(document)

// 捕获指定元素
const svgDocument = elementToSVG(document.querySelector('#my-element'))

// 内联资源
await inlineResources(svgDocument.documentElement)

// 格式化输出
const svgString = new XMLSerializer().serializeToString(svgDocument)
```

输出结果可以直接作为 SVG 使用,也可以给其他包进行美化或压缩处理。

## 特点

- 不依赖 `<foreignObject>` - 输出的 SVG 在设计工具(如 Illustrator、Figma 等)中可以正常使用。
- 使用了正确的 ARIA 属性对 SVG 进行注释,可访问 DOM 树。
- 链接可以交互。
- 文本内容可以复制到剪贴板。
- 可以内联外部资源,如图像、字体等,SVG 文件自包含。
- 元素的 CSS 层叠顺序不变。
- 在 SVG 上输出调试属性,能够追溯元素的 DOM 节点。

## 注意

- 为浏览器开发的库,可以在浏览器中运行。在服务器上使用 JSDOM 可能无法正常使用,不过可以在 Puppeteer 中运行。
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dom2svg",
"type": "module",
"version": "1.0.0",
"version": "1.0.1",
"description": "Take SVG screenshots of DOM elements",
"author": "xiashui",
"license": "MIT",
Expand Down

0 comments on commit 86df9bd

Please sign in to comment.