|
| 1 | +# Web2Vector — Chrome Extension |
| 2 | + |
| 3 | +A Chrome extension that exports any web page's rendered DOM to **10 output formats** using the [@node-projects/layout2vector](https://github.com/node-projects/layout2vector) library. |
| 4 | + |
| 5 | +<p align="center"> |
| 6 | + <img src="src/icons/icon.svg" width="128" alt="Web2Vector icon" /> |
| 7 | +</p> |
| 8 | + |
| 9 | +## Supported Formats |
| 10 | + |
| 11 | +| Category | Format | Extension | Writer | |
| 12 | +|----------|--------|-----------|--------| |
| 13 | +| **Vector** | SVG | `.svg` | `SVGWriter` | |
| 14 | +| | DXF (Standard) | `.dxf` | `DXFWriter` (via `@tarikjabiri/dxf`) | |
| 15 | +| | DXF (AutoCAD) | `.dxf` | `AcadDXFWriter` (via `@node-projects/acad-ts`) | |
| 16 | +| | DWG | `.dwg` | `DWGWriter` (via `@node-projects/acad-ts`) | |
| 17 | +| | EMF | `.emf` | `EMFWriter` | |
| 18 | +| **Document** | PDF | `.pdf` | `PDFWriter` | |
| 19 | +| | HTML | `.html` | `HTMLWriter` | |
| 20 | +| **Image** | PNG | `.png` | `ImageWriter` | |
| 21 | +| | JPEG | `.jpg` | `ImageWriter` | |
| 22 | +| | WebP | `.webp` | `ImageWriter` | |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +1. Click the **Web2Vector** icon in the Chrome toolbar. |
| 27 | +2. Pick an export format from the popup menu. |
| 28 | +3. A **Save As** dialog appears — choose where to save the file. |
| 29 | + |
| 30 | +You can also **right-click** on any page and use the **Web2Vector Export** context menu. |
| 31 | + |
| 32 | +## Lazy Loading |
| 33 | + |
| 34 | +Heavy third-party dependencies are split into separate bundles and only loaded when the user selects a format that needs them: |
| 35 | + |
| 36 | +| Bundle | Loaded when | Dependency | |
| 37 | +|--------|-------------|------------| |
| 38 | +| `core-lib.js` | Always (first export) | `@node-projects/layout2vector` core + built-in writers | |
| 39 | +| `dxf-writer.js` | DXF (Standard) selected | `@tarikjabiri/dxf` | |
| 40 | +| `acad-writers.js` | DXF (AutoCAD) or DWG selected | `@node-projects/acad-ts` | |
| 41 | + |
| 42 | +## Development |
| 43 | + |
| 44 | +### Prerequisites |
| 45 | + |
| 46 | +- Node.js ≥ 20 |
| 47 | +- npm |
| 48 | + |
| 49 | +### Setup |
| 50 | + |
| 51 | +```bash |
| 52 | +npm install |
| 53 | +``` |
| 54 | + |
| 55 | +### Build |
| 56 | + |
| 57 | +```bash |
| 58 | +# Generate icon PNGs from SVG source |
| 59 | +npm run build:icons |
| 60 | + |
| 61 | +# Bundle the extension into dist/ |
| 62 | +npm run build |
| 63 | + |
| 64 | +# Or both in one step |
| 65 | +npm run build:all |
| 66 | +``` |
| 67 | + |
| 68 | +### Load in Chrome |
| 69 | + |
| 70 | +1. Navigate to `chrome://extensions` |
| 71 | +2. Enable **Developer mode** (top right) |
| 72 | +3. Click **Load unpacked** → select the `dist/` folder |
| 73 | + |
| 74 | +### Test |
| 75 | + |
| 76 | +```bash |
| 77 | +npm test |
| 78 | +``` |
| 79 | + |
| 80 | +### Package for Distribution |
| 81 | + |
| 82 | +```bash |
| 83 | +npm run package # creates web2vector-<version>.zip |
| 84 | +``` |
| 85 | + |
| 86 | +## Publishing to Chrome Web Store |
| 87 | + |
| 88 | +### Manual |
| 89 | + |
| 90 | +1. Go to the [Chrome Web Store Developer Dashboard](https://chrome.google.com/webstore/devconsole). |
| 91 | +2. Upload the ZIP created by `npm run package`. |
| 92 | + |
| 93 | +### Automated (GitHub Actions) |
| 94 | + |
| 95 | +The **Publish** workflow runs on GitHub Releases or manual dispatch. Configure these repository secrets: |
| 96 | + |
| 97 | +| Secret | Description | |
| 98 | +|--------|-------------| |
| 99 | +| `CHROME_EXTENSION_ID` | Your extension ID from the CWS dashboard | |
| 100 | +| `CHROME_CLIENT_ID` | Google OAuth2 client ID | |
| 101 | +| `CHROME_CLIENT_SECRET` | Google OAuth2 client secret | |
| 102 | +| `CHROME_REFRESH_TOKEN` | OAuth2 refresh token (see [guide](https://developer.chrome.com/docs/webstore/using-api)) | |
| 103 | + |
| 104 | +Then create a GitHub Release to trigger the publish workflow, or use the manual dispatch. |
| 105 | + |
| 106 | +## Project Structure |
| 107 | + |
| 108 | +``` |
| 109 | +├── manifest.json Chrome extension manifest (v3) |
| 110 | +├── esbuild.config.mjs Build configuration |
| 111 | +├── src/ |
| 112 | +│ ├── shared/formats.js Format definitions (shared by popup + background) |
| 113 | +│ ├── popup/ Extension popup UI |
| 114 | +│ │ ├── popup.html |
| 115 | +│ │ ├── popup.css |
| 116 | +│ │ └── popup.js |
| 117 | +│ ├── background/ |
| 118 | +│ │ └── service-worker.js Background service worker |
| 119 | +│ ├── content/ |
| 120 | +│ │ ├── core-lib.js Core library bundle |
| 121 | +│ │ ├── dxf-writer.js DXF lazy chunk |
| 122 | +│ │ ├── acad-writers.js DWG / AcadDXF lazy chunk |
| 123 | +│ │ └── run-export.js Export orchestration (injected per export) |
| 124 | +│ └── icons/ |
| 125 | +│ └── icon.svg Source icon |
| 126 | +├── scripts/ |
| 127 | +│ ├── build-icons.mjs SVG → PNG conversion |
| 128 | +│ ├── package-extension.mjs ZIP packaging |
| 129 | +│ └── upload-to-store.mjs Chrome Web Store upload |
| 130 | +├── tests/ |
| 131 | +│ ├── formats.test.js |
| 132 | +│ ├── manifest.test.js |
| 133 | +│ └── service-worker.test.js |
| 134 | +└── .github/workflows/ |
| 135 | + ├── ci.yml Build + test on push/PR |
| 136 | + └── publish.yml Publish to Chrome Web Store |
| 137 | +``` |
| 138 | + |
| 139 | +## License |
| 140 | + |
| 141 | +MIT |
0 commit comments