slidev-addon-bpmn 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Marco Stephan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # πŸ“Š slidev-addon-bpmn
2
+
3
+ [![npm version](https://img.shields.io/npm/v/slidev-addon-bpmn)](https://www.npmjs.com/package/slidev-addon-bpmn)
4
+ [![license](https://img.shields.io/npm/l/slidev-addon-bpmn)](https://github.com/emaarco/slidev-addon-bpmn/blob/main/LICENSE)
5
+
6
+ Display BPMN 2.0 diagrams in your [Slidev](https://sli.dev/) presentations. Whether you're presenting workflow designs, explaining process automation, or teaching BPMN concepts β€” this addon has you covered! πŸ’‘
7
+
8
+ Powered by [bpmn-js](https://bpmn.io/toolkit/bpmn-js/) from bpmn.io.
9
+
10
+ ![Example BPMN diagram in Slidev](./public/example-slide.png)
11
+
12
+ ## πŸš€ Quick Start
13
+
14
+ 1. Install the addon in your Slidev project
15
+ 2. Place your `.bpmn` files in the `public/` folder
16
+ 3. Use the `<Bpmn>` component in your slides
17
+
18
+ That's it β€” your BPMN diagrams are ready to present!
19
+
20
+ ## πŸ“¦ Installation
21
+
22
+ ```bash
23
+ npm install slidev-addon-bpmn
24
+ ```
25
+
26
+ Then register the addon in your slide's frontmatter:
27
+
28
+ ```yaml
29
+ ---
30
+ addons:
31
+ - slidev-addon-bpmn
32
+ ---
33
+ ```
34
+
35
+ Or in your `package.json`:
36
+
37
+ ```json
38
+ {
39
+ "slidev": {
40
+ "addons": ["slidev-addon-bpmn"]
41
+ }
42
+ }
43
+ ```
44
+
45
+ ## πŸ”§ Usage
46
+
47
+ ```vue
48
+ <Bpmn
49
+ bpmnFilePath="./my-process.bpmn"
50
+ class="w-[800px]"
51
+ />
52
+ ```
53
+
54
+ The component fetches your BPMN file, renders it using bpmn-js, and exports it as a crisp SVG that scales beautifully at any size.
55
+
56
+ ## βš™οΈ Props
57
+
58
+ | Name | Type | Default | Description |
59
+ |------|------|---------|-------------|
60
+ | `bpmnFilePath` | `string` | *required* | Path to the `.bpmn` file (relative to `public/`) |
61
+ | `width` | `string` | `'100%'` | Maximum width of the diagram |
62
+ | `height` | `string` | `'auto'` | Height of the diagram |
63
+
64
+ ## πŸ’‘ Tips
65
+
66
+ - **File location**: BPMN files must be placed in the `public/` folder
67
+ - **Supported formats**: Standard BPMN 2.0 XML files (exported from Camunda Modeler, bpmn.io, etc.)
68
+ - **Styling**: Use Tailwind classes via the `class` prop to control sizing
69
+ - **Export**: Works seamlessly with Slidev's PDF/PNG export features
70
+
71
+ ## 🀝 Contributing
72
+
73
+ Contributions are welcome! Feel free to report bugs, suggest features via [issues](https://github.com/emaarco/slidev-addon-bpmn/issues), submit pull requests with improvements, or share your ideas and use cases.
74
+
75
+ To develop locally: clone the repo, run `npm install`, then `npm run dev` to test your changes.
76
+
77
+ ## πŸ™ Credits
78
+
79
+ - [bpmn-js](https://github.com/bpmn-io/bpmn-js) by [bpmn.io](https://bpmn.io/)
80
+ - Inspired by [slidev-addon-excalidraw](https://github.com/haydenull/slidev-addon-excalidraw)
@@ -0,0 +1,82 @@
1
+ <template>
2
+ <div>
3
+ <p v-if="loading">Loading BPMN diagram...</p>
4
+ <p v-if="error" class="text-red-500">{{ error }}</p>
5
+ <div v-if="svg" v-html="svg"></div>
6
+ </div>
7
+ </template>
8
+
9
+ <script setup lang="ts">
10
+ import { onMounted, ref } from 'vue'
11
+ import BpmnViewer from 'bpmn-js/lib/Viewer'
12
+ import 'bpmn-js/dist/assets/bpmn-js.css'
13
+
14
+ const loading = ref(false)
15
+ const error = ref<string | null>(null)
16
+ const svg = ref<string | null>(null)
17
+
18
+ const props = withDefaults(defineProps<{
19
+ bpmnFilePath: string
20
+ width?: string
21
+ height?: string
22
+ }>(), {
23
+ width: '100%',
24
+ height: 'auto',
25
+ })
26
+
27
+ onMounted(async () => {
28
+ loading.value = true
29
+ error.value = null
30
+
31
+ try {
32
+ await loadAndRenderBpmn(props.bpmnFilePath)
33
+ } catch (err) {
34
+ error.value = `Failed to load BPMN: ${err instanceof Error ? err.message : String(err)}`
35
+ console.error('BPMN loading error:', err)
36
+ } finally {
37
+ loading.value = false
38
+ }
39
+ })
40
+
41
+ async function loadAndRenderBpmn(path: string): Promise<void> {
42
+ const url = new URL(path, window.location.origin + import.meta.env.BASE_URL).href
43
+ const response = await fetch(url)
44
+
45
+ if (!response.ok) {
46
+ throw new Error(`Failed to fetch BPMN file: ${response.status}`)
47
+ }
48
+
49
+ const bpmnXml = await response.text()
50
+
51
+ // Create off-screen container for bpmn-js rendering (requires DOM element)
52
+ // Fixed 1920x1080 size may clip large diagrams or waste space for small ones
53
+ // If this causes issues, we should consider auto-detecting diagram bounds or using viewBox-based sizing
54
+ const container = document.createElement('div')
55
+ container.style.width = '1920px'
56
+ container.style.height = '1080px'
57
+ container.style.position = 'absolute'
58
+ container.style.left = '-9999px'
59
+ document.body.appendChild(container)
60
+
61
+ try {
62
+ const viewer = new BpmnViewer({ container })
63
+ await viewer.importXML(bpmnXml)
64
+
65
+ const { svg: svgContent } = await viewer.saveSVG()
66
+
67
+ const parser = new DOMParser()
68
+ const svgDoc = parser.parseFromString(svgContent, 'image/svg+xml')
69
+ const svgElement = svgDoc.documentElement
70
+
71
+ svgElement.style.maxWidth = props.width
72
+ svgElement.style.height = props.height
73
+ svgElement.setAttribute('preserveAspectRatio', 'xMidYMid meet')
74
+
75
+ svg.value = svgElement.outerHTML
76
+
77
+ viewer.destroy()
78
+ } finally {
79
+ document.body.removeChild(container)
80
+ }
81
+ }
82
+ </script>
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "slidev-addon-bpmn",
3
+ "version": "0.0.1",
4
+ "description": "Display BPMN 2.0 diagrams in Slidev presentations",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "slidev example.md",
8
+ "build": "slidev build example.md",
9
+ "export": "slidev export example.md",
10
+ "screenshot": "slidev export example.md --format png"
11
+ },
12
+ "author": "Marco SchΓ€ck (https://github.com/emaarco)",
13
+ "license": "MIT",
14
+ "devDependencies": {
15
+ "@slidev/cli": "0.49.11",
16
+ "@slidev/theme-default": "0.25.0"
17
+ },
18
+ "keywords": [
19
+ "slidev",
20
+ "slidev-addon",
21
+ "bpmn",
22
+ "bpmn-js",
23
+ "bpmn.io",
24
+ "diagram",
25
+ "workflow",
26
+ "process"
27
+ ],
28
+ "files": [
29
+ "components"
30
+ ],
31
+ "sideEffects": false,
32
+ "engines": {
33
+ "node": ">=18"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/emaarco/slidev-addon-bpmn.git"
38
+ },
39
+ "bugs": {
40
+ "url": "https://github.com/emaarco/slidev-addon-bpmn/issues"
41
+ },
42
+ "homepage": "https://github.com/emaarco/slidev-addon-bpmn#readme",
43
+ "dependencies": {
44
+ "bpmn-js": "^18.11.0"
45
+ }
46
+ }