Skip to content

WIP update to Svelte 5 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package.json
.yarn
dist
node_modules
docs
docs
**/*.svelte
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## NEXT

- **[BREAKING]** Updated to Svelte 5

## v0.3.1 - 2024-08-25

- Fixed canvas element not displayed if its height or width is based on the line width only (#5)
Expand Down
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ Otherwise, the renderer may use a fallback font depending on the fonts installed
import PdfmakeHtmlRenderer from 'pdfmake-html-renderer'
```

This library was built using the [Svelte](https://svelte.dev/) framework, which should allow integrating it into pretty much any web application:
This library was built using the [Svelte](https://svelte.dev/) framework:

- To consume it from a [Svelte](https://svelte.dev/) application, you may have to add build tooling to support TypeScript into your pipeline, as Svelte needs to compile the components from source
- For a [React](https://reactjs.org/) or [Vue.js](https://vuejs.org/) application, you can use an adapter like [`svelte-adapter`](https://github.com/pngwn/svelte-adapter)
- For other frameworks or VanillaJS, have a look at the [Svelte Component API](https://svelte.dev/docs/client-side-component-api)
- This version was built using Svelte 5. Use version <= 0.3.1 for older versions of Svelte

Check out the `/examples` folder for some example projects.

Expand All @@ -105,12 +104,9 @@ This library also provides an **experimental** server build that renders static
```js
const { PdfmakeHtmlRenderer } = require('pdfmake-html-renderer/server')

const { html, css } = PdfmakeHtmlRenderer.render({
const { body, head } = PdfmakeHtmlRenderer.render({
document: { content: ['Hello, world!'] },
})

// html contains the HTML code
// css.code contains the CSS code
```

Check out `/examples/nodejs` for an exmaple.
Expand Down
4 changes: 0 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# TODO

## Features

- Error Boundary

## Robustness

- Unit tests
Expand Down
7 changes: 6 additions & 1 deletion babel.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"presets": [
"@babel/preset-env",
[
"@babel/preset-env",
{
"modules": false
}
],
"@babel/preset-typescript"
]
}
3,603 changes: 0 additions & 3,603 deletions docs/assets/index-BePLbb_H.js

This file was deleted.

1 change: 0 additions & 1 deletion docs/assets/index-BePLbb_H.js.map

This file was deleted.

1 change: 0 additions & 1 deletion docs/assets/index-CALeJ9HK.css

This file was deleted.

3,602 changes: 3,602 additions & 0 deletions docs/assets/index-CQxVtyu3.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/assets/index-CQxVtyu3.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/assets/index-D6N9Z5Qp.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700;1,400;1,700&display=swap" rel="stylesheet">
<title>pdfmake-html-renderer</title>
<script type="module" crossorigin src="./assets/index-BePLbb_H.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-CALeJ9HK.css">
<script type="module" crossorigin src="./assets/index-CQxVtyu3.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-D6N9Z5Qp.css">
</head>

<body>
Expand Down
31 changes: 18 additions & 13 deletions examples/nodejs/index.cjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
// @ts-check

const http = require('http')

const { render } = require('svelte/server')
const { PdfmakeHtmlRenderer } = require('pdfmake-html-renderer/server')

const hostname = '127.0.0.1'
const port = 3000

const { html, css } = PdfmakeHtmlRenderer.render({
document: {
content: [
{
text: 'pdfmake-html-renderer NodeJS Example',
fontSize: 18,
bold: true,
},
'\n',
'Hello, world!',
],
const { body, head } = render(PdfmakeHtmlRenderer, {
props: {
document: {
content: [
{
text: 'pdfmake-html-renderer NodeJS Example',
fontSize: 18,
bold: true,
},
'\n',
'Hello, world!',
],
},
},
})

Expand All @@ -29,11 +34,11 @@ const server = http.createServer((req, res) => {
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>pdfmake-html-renderer NodeJS example</title>
<style>${css.code}</style>
${head}
</head>

<body>
<div>${html}</div>
<div>${body}</div>
</body>
</html>`)
})
Expand Down
29 changes: 16 additions & 13 deletions examples/nodejs/index.mjs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { createServer } from 'node:http'
import { render } from 'svelte/server'
import PdfmakeHtmlRenderer from 'pdfmake-html-renderer/server'

const hostname = '127.0.0.1'
const port = 3000

const { html, css } = PdfmakeHtmlRenderer.render({
document: {
content: [
{
text: 'pdfmake-html-renderer NodeJS Example',
fontSize: 18,
bold: true,
},
'\n',
'Hello, world!',
],
const { body, head } = render(PdfmakeHtmlRenderer, {
props: {
document: {
content: [
{
text: 'pdfmake-html-renderer NodeJS Example',
fontSize: 18,
bold: true,
},
'\n',
'Hello, world!',
],
},
},
})

Expand All @@ -28,11 +31,11 @@ const server = createServer((req, res) => {
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>pdfmake-html-renderer NodeJS example</title>
<style>${css.code}</style>
${head}
</head>

<body>
<div>${html}</div>
<div>${body}</div>
</body>
</html>`)
})
Expand Down
2 changes: 1 addition & 1 deletion examples/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"svelte-adapter": "^0.5.0",
"svelte": "^5.15.0",
"web-vitals": "^3.5.1"
},
"scripts": {
Expand Down
9 changes: 6 additions & 3 deletions examples/react-app/public/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700;1,400;1,700&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700;1,400;1,700&display=swap"
rel="stylesheet"
/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
Expand Down
31 changes: 20 additions & 11 deletions examples/react-app/src/App.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import toReact from 'svelte-adapter/react'
import { useRef, useEffect } from 'react'
import { PdfmakeHtmlRenderer } from 'pdfmake-html-renderer'

import 'pdfmake-html-renderer/dist/index.css'

const Renderer = toReact(PdfmakeHtmlRenderer)

function App() {
return (
<div>
<Renderer
document={{
const containerRef = useRef(null)

useEffect(() => {
if (!containerRef.current) return

const app = new PdfmakeHtmlRenderer({
target: containerRef.current,
props: {
document: {
content: [
{
text: 'pdfmake-html-renderer React Example',
Expand All @@ -19,10 +22,16 @@ function App() {
'\n',
'Hello, world!',
],
}}
/>
</div>
)
},
},
})

return () => {
app.$destroy()
}
}, [])

return <div ref={containerRef} />
}

export default App
9 changes: 5 additions & 4 deletions examples/react-app/src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App'
import reportWebVitals from './reportWebVitals'

ReactDOM.render(
const container = document.getElementById('root')
const root = createRoot(container)
root.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
</React.StrictMode>
)

// If you want to start measuring performance in your app, pass a function
Expand Down
Loading