• Stars
    star
    150
  • Rank 238,630 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 4 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

parser HTML to Sketch JSON

English | ็ฎ€ไฝ“ไธญๆ–‡

html2sketch

html2sketch

NPM version NPM version NPM downloads install size

Test CI status Deploy CI Coverage

 docs by dumi Build With father

Gitpod ready-to-code

Introduction

A module that transform HTML into Sketch JSON

Quick Guide

Install

npm i html2sketch --save

or

yarn add html2sketch

Usage

html2sketch includes three methods nodeToLayer ใ€ nodeToGroup ๅ’Œ nodeToSymbol ใ€‚

nodeToLayer

this method transforms a DOM node into Sketch Objects without processing children of nodes

import { nodeToLayer } from 'html2sketch';

const fn = async () => {
  // 1. get DOM node
  const node = document.getElementById('id');

  // 2. run nodeToLayer method
  const layer = await nodeToLayer(node);

  // 3. generate Sketch JSON
  const sketchJSON = layer.toSketchJSON();

  return sketchJSON;
};

fn().then((json) => {
  console.log(json);
});

nodeToGroup

This method transforms a DOM node and its children into a Sketch Group Object

import { nodeToGroup } from 'html2sketch';

const fn = async () => {
  // 1. get DOM node
  const node = document.getElementById('id');

  // 2. run nodeToGroup method
  const group = await nodeToGroup(node);

  // 3. generate Sketch JSON
  const sketchJSON = group.toSketchJSON();

  return sketchJSON;
};

fn().then((json) => {
  console.log(json);
});

nodeToSymbol

This method transforms a DOM node and its children into a Sketch Symbol Object

import { nodeToSymbol } from 'html2sketch';

const fn = async () => {
  // 1. get DOM node
  const node = document.getElementById('id');

  // 2. run nodeToSymbol method
  const symbol = await nodeToSymbol(node);

  // 3. generate Sketch JSON
  const sketchJSON = symbol.toSketchJSON();

  return sketchJSON;
};

fn().then((json) => {
  console.log(json);
});

What's next step with Sketch JSON?

the generated Sketch JSON strictly match with Sketch File Format Schema, So you can just synthesize the JSON according to the Sketch File Format into a '. Sketch 'file .

So the Sketch file can be obtained simply by synthesizing the corresponding JSON into a '. Sketch 'file according to the Sketch file specification

There is some community modules of synthesizing:

If you want to use the JSON object directly in sketch, you can use the Sketch JSON Plugin,which will allow you just paste JSON into Sketch.

Why?

The main application of this module focus on C2D (Code to Design).This module mainly refers to html-sketchapp.

html-sketchapp can directly transforms any HTML page into a Sketch document without framework limit, but there are significant limitations:

  • Not supported pseudoelements, overflow,some kind of gradient, transform, and other properties: As a result, many web pages transformed by html-sketchapp are not visually restored;

  • Although html-sketchapp don't dependent on the framework, it fully dependent on the Sketch App: Because JSON structure generated by html-sketchapp does not strictly match Sketch File Format ,it can't generate sketch document directly.What's more,it also lead to lacking of the ability to integrate on the server side.

  • html-sketchapp developed by JS ,lacking perfect type definition, the project architecture is not reasonable, the secondary development is difficult

What html2sketch do?

html2sketch makes a lot of optimization on the basis of html-sketchapp, and takes the essence to discard the dross:

Enhancement of parsing ability

html2sketch supports most web page styles which is not supported by html-sketchapp, such as pseudo-elements,radial gradient, text overflows, and so on.This is important for transforming result.Perhaps reproducing 80% using html-sketchapp, but 95% or more using html2sketch. Of course, the parsing capability of the module also needs to be improved step by step by covering the parsing scene. If you encounter any incorrect parsing situation under the real word, please be sure to submit an issue, I will solve it as soon as possible. The styles supported by this module are currently available on ่งฃๆž็”จไพ‹.

Decouple from the Sketch App

The biggest difference at the functional level of html2sketch is its decoupling from the Sketch App.The relevant parsing capabilities (Svg, image, font, and so on) are all built from scratch.

Thanks to the JSON generated by html2Sketch will strictly match Sketch File Format , you can directly synthesize it into a legal .sketch file by using sketch-json-api or node-sketch . Therefore,based on html2sketch, it is possible to parse a web page and generate the Sketch file using any normal server.

Development based on Typescript

Developed with Typescript makes it a good experience for both consumers and producers.Whether it's in the organization of the project, code comments, or unit testing, there are guarantees.

Develop

Refer to Develop Guidelines

License

MIT

More Repositories

1

ant-design

An enterprise-class UI design language and React UI library
TypeScript
89,408
star
2

ant-design-pro

๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป Use Ant Design like a Pro!
TypeScript
35,716
star
3

ant-design-mobile

Essential UI blocks for building mobile web apps.
TypeScript
11,415
star
4

ant-design-landing

๐Ÿšต Landing Pages of Ant Design System
JavaScript
5,928
star
5

ant-motion

๐Ÿšด Animate specification and components of Ant Design
JavaScript
4,563
star
6

pro-components

๐Ÿ† Use Ant Design like a Pro!
TypeScript
3,981
star
7

ant-design-mobile-rn

Ant Design for React Native
TypeScript
2,925
star
8

ant-design-charts

A React Chart Library
JavaScript
1,802
star
9

antd-mobile-samples

antd-mobile samples
HTML
1,142
star
10

ant-ux

๐ŸŽธ A sitemap template for ux design
JavaScript
1,136
star
11

ant-design-pro-layout

๐ŸŒƒ Powerful and easy to use beautiful layout
TypeScript
998
star
12

ant-design-icons

โญ Ant Design SVG Icons
TypeScript
901
star
13

antd-init

๐Ÿ”ฐ Ant Design boilerplate generator.
JavaScript
816
star
14

pro-blocks

Blocks of Ant Design Pro.
TypeScript
710
star
15

ant-design-web3

๐Ÿฅณ Efficient react components for building dapps easier | Connect crypto wallets and more Web3 UI components | Web3 icons | Supports Ethereum, Solana, Bitcoin and others.
TypeScript
703
star
16

ant-design-colors

๐ŸŽจ Color Palettes Calculator of Ant Design
TypeScript
612
star
17

create-react-app-antd

Use antd in create-react-app without ejecting โœจ
JavaScript
583
star
18

pro-table

๐Ÿ† Use Ant Design Table like a Pro!
TypeScript
560
star
19

sunflower

๐Ÿฆน Process components for antd4 & antd3 by alipay industry technology
TypeScript
499
star
20

ant-design-dark-theme

๐ŸŒš Dark theme variables of Ant Design
TypeScript
481
star
21

react-tutorial

ๅŸบไบŽ umi ็š„ Ant Design ๅฎžๆˆ˜ๆ•™็จ‹้…ๅฅ—ไปฃ็  https://www.yuque.com/ant-design/course
JavaScript
434
star
22

pro-chat

๐Ÿค– Components Library for Quickly Building LLM Chat Interfaces.
TypeScript
400
star
23

ant-design-pro-site

TypeScript
393
star
24

antd-tools

๐Ÿ”ง Cli Tools for Ant Design React
JavaScript
393
star
25

ant-design-mini

Ant Design for Alipay Mini Program
TypeScript
368
star
26

ant-design-aliyun-theme

โš™ Ant Design Theme for console.aliyun.com
TypeScript
305
star
27

antd-dayjs-webpack-plugin

โฐ Day.js webpack plugin for Ant Design
JavaScript
287
star
28

ant-design-pro-cli

Cli tool of Ant Design Pro
JavaScript
259
star
29

cssinjs

TypeScript
219
star
30

intl-example

๐ŸŒ example about`antd`/`antd-mobile` internationalization
JavaScript
205
star
31

antd-sketchapp

โš›๏ธ๐Ÿ’Ž๐Ÿœ Render Ant Design components to Sketch.
HTML
201
star
32

antd-style

css-in-js library with antd v5 token system
TypeScript
166
star
33

pro-flow

๐Ÿชข A React based Flow Framework, include Flow View and Flow Editor
TypeScript
159
star
34

pro-editor

๐Ÿ•น๏ธ The Ultimate Editor UI Framework and Components
TypeScript
145
star
35

scaffold-market

scaffold market for single page application
JavaScript
127
star
36

kitchen

Powerful sketch plugin for design cooperation ๐Ÿณ๐Ÿณ๐Ÿณ
121
star
37

ant-design-mobile-chart

Ant Design Mobile Chart based on F2
JavaScript
103
star
38

codemod-v4

codemod cli for antd v4 upgrade
JavaScript
92
star
39

compatible

TypeScript
89
star
40

ant-bot

JavaScript
78
star
41

parcel-antd

Use antd with parcel
TypeScript
75
star
42

antd-library

Axure library for Ant Design
HTML
75
star
43

v2.preview.pro.ant.design

v2.preview.pro.ant.design
JavaScript
72
star
44

antd-token-previewer

TypeScript
63
star
45

antd-mobile-pro

๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป Use Antd Mobile like a Pro!
TypeScript
53
star
46

ant-design-blocks

umi blocks of Ant Design.
TypeScript
50
star
47

antd-mobile-icons-v2

svg icons for ant-design-mobile
45
star
48

antd-issue-helper

TypeScript
43
star
49

antd-migration-helper

CLI tool to aid in migrate antd from old version to newer version.
JavaScript
41
star
50

u.ant.design

URL shortener.
JavaScript
35
star
51

editable-table

JavaScript
33
star
52

bisheng-plugin-antd

To support ant.design-like websites.
JavaScript
33
star
53

pro-list

ๆขฆๆƒณ่ขซ antd ๅ†…็ฝฎ็š„ๅŸบไบŽ antd ไฟฎๆ”น็š„ list
TypeScript
30
star
54

antd-mobile-template

umijs@4 and antd-mobile@5 quick start project, You can click the `use template` to quickly create your own app.
TypeScript
29
star
55

functional-mini

TypeScript
26
star
56

examples

More complex demo using antd
JavaScript
25
star
57

HiTu

TypeScript
25
star
58

sketch-json-api

๐Ÿ’Ž๐Ÿ”ง Node.js Library for Editing Sketch Files.
TypeScript
24
star
59

antd-color-editor

๐ŸŽจ an open-source color editor for designing color system
TypeScript
23
star
60

static-style-extract

TypeScript
21
star
61

antd-codemod

antd codemod scripts.
JavaScript
20
star
62

happy-work-theme

TypeScript
16
star
63

use-emotion-css

A gadget that combines emotion and antd token
TypeScript
16
star
64

codemod-v5

codemod cli for antd v5 upgrade
JavaScript
16
star
65

ant-design-landing-build

JavaScript
16
star
66

antd-changelog-editor

Ant Design Changelog Editor
TypeScript
13
star
67

next-pro-components

ไธ‹ไธ€ไธช็‰ˆๆœฌ็š„ pro-components
HTML
12
star
68

antd-theme

CSS
10
star
69

antd-adapter

An adapter which makes newer antd works like old one. DIRTY HACK \ T^T /
JavaScript
9
star
70

sketch-assistant-ant-design

TypeScript
9
star
71

ant-design-analysis

bundle size analysis of ant-design-mobile
HTML
8
star
72

antd-mobile-icons

The icon set for antd-mobile.
JavaScript
7
star
73

.github

6
star
74

beta.pro.ant.design

beta for pro scaffold
HTML
6
star
75

2x.ant.design

[email protected] site
HTML
6
star
76

010x.ant.design

[email protected] site
HTML
5
star
77

1x.ant.design

[email protected] site http://1x.ant.design
HTML
5
star
78

v2.pro.ant.design

https://v2-pro.ant.design/index-cn v2 version
HTML
4
star
79

next.mobile.ant.design

This is the documentation site for antd-mobile v5.
4
star
80

beta.preview.pro.ant.design

ant.design.pro ็š„ beta ้ข„่งˆ
JavaScript
4
star
81

3x.ant.design

HTML
4
star
82

doc

antd ๆŠ€ๆœฏๆ ˆ็š„ๆ‰€ๆœ‰ๆ–‡ๆกฃ๏ผŒ็”จไบŽๅš AI ๅŠŸ่ƒฝ
JavaScript
4
star
83

1x.mobile.ant.design

[email protected] site, http://1x.mobile.ant.design
HTML
4
star
84

012x.ant.design

[email protected] site http://012x.ant.design
HTML
3
star
85

011x.ant.design

[email protected] site http://011x.ant.design
HTML
3
star
86

07x.mobile.ant.design

[email protected] site
3
star
87

v1.pro.ant.design

ant design pro document
CSS
3
star
88

08x.mobile.ant.design

[email protected] site
HTML
3
star
89

03x.pro.ant.design

Document for ant design pro 0.3.x
HTML
3
star
90

09x.mobile.ant.design

[email protected] site
HTML
3
star
91

2x.rn.mobile.ant.design

http://2x.rn.mobile.ant.design/
HTML
3
star
92

ant-design-web3-demo

A demo for Ant Design Web3 course.
TypeScript
3
star
93

09x.ant.design

document of [email protected]
JavaScript
2
star
94

v1.preview.pro.ant.design

ant design pro v1 preview
JavaScript
2
star
95

beta.mobile.ant.design

No longer use, please visitor:
HTML
2
star
96

v5.ant-design-pro-site

TypeScript
2
star
97

test-antd-locale

JavaScript
1
star
98

cssinjs-benchmark

Benchmark for ant design cssinjs
TypeScript
1
star
99

babel-plugin-antd-style

ไธบ antd-style ็”Ÿๆˆ็š„ classname ๅขžๅŠ ๆ–‡ไปถๅ๏ผŒๆ–นไพฟ debug
TypeScript
1
star
100

antd-moment-webpack-plugin

โฐ Replace Day.js to Moment.js webpack plugin for Ant Design
JavaScript
1
star