slidev-addon-bpmn 1.2.0 → 1.2.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/README.md CHANGED
@@ -17,7 +17,7 @@ That's it — your BPMN diagrams are ready to present!
17
17
 
18
18
  ## Example Slide
19
19
 
20
- ![Example BPMN diagram in Slidev](./public/example-slide.png)
20
+ ![Example BPMN diagram in Slidev](./docs/bpmn.gif)
21
21
 
22
22
  ## 📦 Installation
23
23
 
@@ -99,7 +99,7 @@ The token simulation provides interactive controls for stepping through process
99
99
 
100
100
  - **File location**: BPMN files must be placed in the `public/` folder
101
101
  - **Supported formats**: Standard BPMN 2.0 XML files (exported from Camunda Modeler, bpmn.io, etc.)
102
- - **Styling**: Use Tailwind classes via the `class` prop to control sizing
102
+ - **Styling**: Use Tailwind classes on the component element to control sizing
103
103
  - **Export**: Each `<Bpmn>` component works seamlessly with Slidev's PDF/PNG export features
104
104
 
105
105
  ## 🤝 Contributing
@@ -11,7 +11,7 @@ import { onMounted, ref } from 'vue'
11
11
  import BpmnViewer from 'bpmn-js/lib/Viewer'
12
12
  import 'bpmn-js/dist/assets/bpmn-js.css'
13
13
 
14
- const loading = ref(false)
14
+ const loading = ref(true)
15
15
  const error = ref<string | null>(null)
16
16
  const svg = ref<string | null>(null)
17
17
 
@@ -68,6 +68,9 @@ async function loadAndRenderBpmn(path: string): Promise<void> {
68
68
  const svgDoc = parser.parseFromString(svgContent, 'image/svg+xml')
69
69
  const svgElement = svgDoc.documentElement
70
70
 
71
+ // Strip potentially dangerous elements from the SVG
72
+ svgDoc.querySelectorAll('script, foreignObject').forEach(el => el.remove())
73
+
71
74
  svgElement.style.maxWidth = props.width
72
75
  svgElement.style.height = props.height
73
76
  svgElement.setAttribute('preserveAspectRatio', 'xMidYMid meet')
@@ -1,10 +1,11 @@
1
1
  <template>
2
2
  <div :style="{ display: 'flex', alignItems: 'center', justifyContent: 'center', width: props.width, height: containerHeight }">
3
3
  <p v-if="loading">Loading BPMN diagram...</p>
4
+ <p v-if="error" class="text-red-500">{{ error }}</p>
4
5
  <div ref="containerRef" :style="{
5
- width: `calc(${props.width} - ${5* 2}px)`,
6
- height: `calc(${containerHeight} - ${5 * 2}px)`,
7
- margin: `5px`,
6
+ width: `calc(${props.width} - ${margin * 2}px)`,
7
+ height: `calc(${containerHeight} - ${margin * 2}px)`,
8
+ margin: `${margin}px`,
8
9
  }"
9
10
  ></div>
10
11
  </div>
@@ -12,16 +13,21 @@
12
13
 
13
14
  <script setup lang="ts">
14
15
 
15
- import { nextTick, onMounted, ref } from 'vue'
16
+ import { nextTick, onMounted, onUnmounted, ref } from 'vue'
16
17
  import BpmnViewer from 'bpmn-js/lib/Viewer'
17
18
  import 'bpmn-js/dist/assets/bpmn-js.css'
18
19
  import tokenSimulation from 'bpmn-js-token-simulation/lib/viewer'
19
20
  import { onSlideEnter } from '@slidev/client'
20
21
  import 'bpmn-js-token-simulation/assets/css/bpmn-js-token-simulation.css'
21
22
 
22
- const loading = ref(false)
23
+ const margin = 5
24
+ const containerWaitTimeout = 5000
25
+
26
+ const loading = ref(true)
27
+ const error = ref<string | null>(null)
23
28
  const containerRef = ref<HTMLDivElement | null>(null)
24
29
  const isRendered = ref(false)
30
+ let viewer: InstanceType<typeof BpmnViewer> | null = null
25
31
 
26
32
  const props = withDefaults(defineProps<{
27
33
  bpmnFilePath: string
@@ -39,10 +45,13 @@ const containerHeight = props.height === 'auto' ? '500px' : props.height
39
45
  * Prevents "non-finite" SVG matrix errors when canvas.zoom() is called.
40
46
  */
41
47
  async function waitForContainer(): Promise<void> {
42
- return new Promise((resolve) => {
48
+ return new Promise((resolve, reject) => {
49
+ const start = Date.now()
43
50
  const checkDimensions = () => {
44
51
  if (containerRef.value && containerRef.value.clientWidth > 0 && containerRef.value.clientHeight > 0) {
45
52
  resolve()
53
+ } else if (Date.now() - start > containerWaitTimeout) {
54
+ reject(new Error('Container dimensions not available within timeout'))
46
55
  } else {
47
56
  requestAnimationFrame(checkDimensions)
48
57
  }
@@ -61,6 +70,7 @@ async function renderBpmn() {
61
70
  if (isRendered.value) return
62
71
  isRendered.value = true
63
72
  loading.value = true
73
+ error.value = null
64
74
 
65
75
  try {
66
76
  await waitForContainer()
@@ -70,7 +80,7 @@ async function renderBpmn() {
70
80
  if (!response.ok) throw new Error(`Failed to fetch BPMN file: ${response.status}`)
71
81
 
72
82
  const disableSnackbarModule = {notifications: ['value', {showNotification: () => {}}]}
73
- const viewer = new BpmnViewer({
83
+ viewer = new BpmnViewer({
74
84
  container: containerRef.value!,
75
85
  additionalModules: [tokenSimulation, disableSnackbarModule]
76
86
  })
@@ -85,6 +95,7 @@ async function renderBpmn() {
85
95
 
86
96
  } catch (err) {
87
97
  isRendered.value = false
98
+ error.value = `Failed to load BPMN: ${err instanceof Error ? err.message : String(err)}`
88
99
  console.error('BPMN loading error:', err)
89
100
  } finally {
90
101
  loading.value = false
@@ -108,4 +119,9 @@ onSlideEnter(async () => {
108
119
  await renderBpmn()
109
120
  })
110
121
 
111
- </script>
122
+ onUnmounted(() => {
123
+ viewer?.destroy()
124
+ viewer = null
125
+ })
126
+
127
+ </script>
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "slidev-addon-bpmn",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Display BPMN 2.0 diagrams in Slidev presentations",
5
5
  "type": "module",
6
6
  "scripts": {
7
- "dev": "slidev example.md",
7
+ "dev": "portless run sh -c 'npx slidev example.md --port $PORT --remote --bind 127.0.0.1'",
8
8
  "build": "slidev build example.md",
9
9
  "export": "slidev export example.md",
10
10
  "screenshot": "slidev export example.md --format png"
@@ -12,11 +12,11 @@
12
12
  "author": "Marco Schäck (https://github.com/emaarco)",
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "bpmn-js": "18.11.0",
16
- "bpmn-js-token-simulation": "0.39.1"
15
+ "bpmn-js": "18.13.2",
16
+ "bpmn-js-token-simulation": "0.39.3"
17
17
  },
18
18
  "devDependencies": {
19
- "@slidev/cli": "52.12.0",
19
+ "@slidev/cli": "52.14.1",
20
20
  "@slidev/theme-default": "0.25.0",
21
21
  "playwright-chromium": "1.58.2"
22
22
  },
@@ -34,9 +34,19 @@
34
34
  "components",
35
35
  "vite.config.ts"
36
36
  ],
37
- "sideEffects": false,
37
+ "sideEffects": [
38
+ "**/*.css"
39
+ ],
40
+ "peerDependencies": {
41
+ "@slidev/cli": ">=50"
42
+ },
43
+ "peerDependenciesMeta": {
44
+ "@slidev/cli": {
45
+ "optional": false
46
+ }
47
+ },
38
48
  "engines": {
39
- "node": ">=18"
49
+ "node": ">=20"
40
50
  },
41
51
  "repository": {
42
52
  "type": "git",
package/vite.config.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { defineConfig } from 'vite'
2
2
 
3
3
  export default defineConfig({
4
+ server: {
5
+ allowedHosts: ['.localhost'],
6
+ },
4
7
  optimizeDeps: {
5
8
  include: [
6
9
  'bpmn-js/lib/Viewer',