@bpmn-nova/studio 0.3.9-preview → 0.4.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.
Files changed (79) hide show
  1. package/README.md +2 -2
  2. package/dist/canvas.js +97 -25
  3. package/dist/config.js +13 -0
  4. package/dist/context-menu.js +41 -32
  5. package/dist/controller.js +45 -19
  6. package/dist/flow-tree.d.ts +4 -0
  7. package/dist/flow-tree.js +14 -0
  8. package/dist/index.d.ts +47 -2
  9. package/dist/index.js +1 -0
  10. package/dist/interactions.js +6 -1
  11. package/dist/modules/bpmn-model/index.d.ts +2 -1
  12. package/dist/modules/bpmn-model/index.js +12 -10
  13. package/dist/modules/core/gateway.js +16 -13
  14. package/dist/modules/core/index.d.ts +6 -4
  15. package/dist/modules/core/model.js +12 -7
  16. package/dist/modules/designer/index.d.ts +5 -1
  17. package/dist/modules/designer/index.js +36 -15
  18. package/dist/modules/export-svg/index.d.ts +12 -5
  19. package/dist/modules/export-svg/preview.js +34 -24
  20. package/dist/modules/export-svg/render.js +102 -50
  21. package/dist/modules/flow-tree/controller.js +364 -0
  22. package/dist/modules/flow-tree/index.d.ts +248 -0
  23. package/dist/modules/flow-tree/index.js +5 -0
  24. package/dist/modules/flow-tree/operations.js +484 -0
  25. package/dist/modules/flow-tree/sample.js +445 -0
  26. package/dist/modules/flow-tree/schema.js +588 -0
  27. package/dist/modules/flow-tree/validate.js +125 -0
  28. package/dist/modules/flow-tree-bpmn/compiler.js +547 -0
  29. package/dist/modules/flow-tree-bpmn/decompiler.js +524 -0
  30. package/dist/modules/flow-tree-bpmn/expression.js +135 -0
  31. package/dist/modules/flow-tree-bpmn/index.d.ts +53 -0
  32. package/dist/modules/flow-tree-bpmn/index.js +14 -0
  33. package/dist/modules/flow-tree-renderer/canvas.js +1003 -0
  34. package/dist/modules/flow-tree-renderer/export-svg.js +325 -0
  35. package/dist/modules/flow-tree-renderer/index.d.ts +143 -0
  36. package/dist/modules/flow-tree-renderer/index.js +3 -0
  37. package/dist/modules/flow-tree-renderer/shell.js +970 -0
  38. package/dist/modules/i18n/index.d.ts +647 -0
  39. package/dist/modules/i18n/index.js +247 -0
  40. package/dist/modules/i18n/locales/en-US.js +1222 -0
  41. package/dist/modules/i18n/locales/zh-CN.js +1204 -0
  42. package/dist/modules/icons/index.js +23 -0
  43. package/dist/modules/node-presentation/index.d.ts +3 -2
  44. package/dist/modules/node-presentation/index.js +14 -11
  45. package/dist/modules/palette/index.d.ts +6 -1
  46. package/dist/modules/palette/index.js +26 -8
  47. package/dist/modules/palette/panel.js +44 -6
  48. package/dist/modules/properties/index.d.ts +2 -1
  49. package/dist/modules/properties/index.js +2 -2
  50. package/dist/modules/properties-activiti/index.js +84 -59
  51. package/dist/modules/properties-bpmn/index.js +151 -128
  52. package/dist/modules/properties-core/index.d.ts +9 -3
  53. package/dist/modules/properties-core/index.js +16 -4
  54. package/dist/modules/properties-flow-tree/index.d.ts +56 -0
  55. package/dist/modules/properties-flow-tree/index.js +2 -0
  56. package/dist/modules/properties-flow-tree/panel.js +1136 -0
  57. package/dist/modules/properties-flow-tree/widgets.js +625 -0
  58. package/dist/modules/properties-flowable/index.js +55 -34
  59. package/dist/modules/properties-renderer/index.d.ts +5 -1
  60. package/dist/modules/properties-renderer/index.js +110 -42
  61. package/dist/modules/renderer-svg/index.d.ts +6 -2
  62. package/dist/modules/renderer-svg/index.js +113 -38
  63. package/dist/modules/runtime/index.d.ts +33 -5
  64. package/dist/modules/runtime/index.js +97 -73
  65. package/dist/modules/runtime/time.js +89 -4
  66. package/dist/modules/runtime/visits.js +6 -4
  67. package/dist/modules/theme/index.d.ts +5 -2
  68. package/dist/modules/theme/index.js +8 -4
  69. package/dist/modules/viewer/index.d.ts +28 -7
  70. package/dist/modules/viewer/index.js +223 -58
  71. package/dist/modules/viewer/runtime-content.js +26 -20
  72. package/dist/modules/viewer/runtime-trace.js +43 -25
  73. package/dist/modules/viewer/timeline.js +103 -36
  74. package/dist/shell.js +258 -75
  75. package/dist/sidebars.js +3 -1
  76. package/dist/styles.css +2371 -2
  77. package/llms-full.txt +586 -47
  78. package/llms.txt +6 -5
  79. package/package.json +7 -3
@@ -1,4 +1,5 @@
1
1
  import { cloneModel, createEdge, getScopeGraph, NODE_DEFINITIONS } from '../core/index.js';
2
+ import { createI18n, DEFAULT_I18N, resolveI18n } from '../i18n/index.js';
2
3
  import { createDefaultIconRegistry, createIconElement } from '../icons/index.js';
3
4
  import { DiagramRenderer } from '../renderer-svg/index.js';
4
5
  import { compareRuntimeOrder, createRuntimePresentation, formatRuntimeInstant, normalizeRuntime, parseRuntimeInstant } from '../runtime/index.js';
@@ -19,8 +20,28 @@ function element(tag, className, text) {
19
20
  return node;
20
21
  }
21
22
 
22
- function outcomeLabel(outcome) {
23
- return { approved: '通过', rejected: '驳回', returned: '退回', submitted: '提交', pending: '待处理' }[outcome] || outcome || '';
23
+ const OUTCOME_KEYS = Object.freeze({
24
+ approved: 'viewer.outcomes.approved',
25
+ rejected: 'viewer.outcomes.rejected',
26
+ returned: 'viewer.outcomes.returned',
27
+ submitted: 'viewer.outcomes.submitted',
28
+ pending: 'viewer.outcomes.pending',
29
+ });
30
+
31
+ function outcomeLabel(outcome, i18n = DEFAULT_I18N) {
32
+ const key = OUTCOME_KEYS[outcome];
33
+ return (key ? i18n.t(key) : '') || outcome || '';
34
+ }
35
+
36
+ function formatViewerTime(viewer, value, surface, field, overrides = null) {
37
+ const i18n = resolveI18n(overrides?.i18n || viewer?.i18n || overrides);
38
+ return formatRuntimeInstant(value, {
39
+ formatRuntimeTime: overrides?.formatRuntimeTime !== undefined ? overrides.formatRuntimeTime : viewer?.formatRuntimeTime,
40
+ runtimeTimeFormat: overrides?.runtimeTimeFormat !== undefined ? overrides.runtimeTimeFormat : viewer?.runtimeTimeFormat,
41
+ surface,
42
+ field,
43
+ locale: i18n.locale,
44
+ });
24
45
  }
25
46
 
26
47
  const defaultDetailsIconRegistry = createDefaultIconRegistry();
@@ -39,7 +60,7 @@ function runtimeDetailsCloseButton({ viewer, label, close }) {
39
60
  return button;
40
61
  }
41
62
 
42
- function renderRuntimeAction({ container, viewer, action, resolveAsset, compact = false }) {
63
+ function renderRuntimeAction({ container, viewer, action, resolveAsset, compact = false, i18n = DEFAULT_I18N, timeOverrides = null }) {
43
64
  const appearance = viewer?.runtimeAppearance?.resolveAction(action) || { label: action.label, tone: 'neutral' };
44
65
  const article = element('article', `mb-runtime-action type-${action.type}${compact ? ' is-compact' : ''}`);
45
66
  article.dataset.runtimeActionId = action.id;
@@ -47,41 +68,58 @@ function renderRuntimeAction({ container, viewer, action, resolveAsset, compact
47
68
  const header = element('header', 'mb-runtime-action-head');
48
69
  const heading = element('div', 'mb-runtime-action-heading');
49
70
  heading.append(
50
- element('strong', '', action.actor?.name || '系统'),
71
+ element('strong', '', action.actor?.name || i18n.t('viewer.details.systemActor')),
51
72
  element('em', '', appearance.label),
52
73
  );
53
74
  header.appendChild(heading);
54
- if (action.occurredAt) header.appendChild(element('time', '', formatRuntimeInstant(action.occurredAt)));
75
+ const occurred = formatViewerTime(viewer, action.occurredAt, 'details', 'occurred', timeOverrides);
76
+ if (occurred) header.appendChild(element('time', '', occurred));
55
77
  article.appendChild(header);
56
- if (action.targets?.length) article.appendChild(element('div', 'mb-runtime-action-targets', `目标:${action.targets.map((target) => target.name).join('、')}`));
57
- if (action.targetElementId && !action.targets?.length) article.appendChild(element('div', 'mb-runtime-action-targets', `目标节点:${action.targetElementId}`));
78
+ if (action.targets?.length) {
79
+ article.appendChild(element('div', 'mb-runtime-action-targets', i18n.t('viewer.details.targets', {
80
+ names: action.targets.map((target) => target.name).join(i18n.t('common.listSeparator')),
81
+ })));
82
+ }
83
+ if (action.targetElementId && !action.targets?.length) {
84
+ article.appendChild(element('div', 'mb-runtime-action-targets', i18n.t('viewer.details.targetElement', { id: action.targetElementId })));
85
+ }
58
86
  renderRuntimeApprovalContent({
59
87
  container: article,
60
88
  action,
61
89
  resolveAsset,
62
90
  compact,
63
91
  onPreview: (asset, sourceAction) => viewer?._openRuntimeAssetPreview(asset, sourceAction),
92
+ i18n,
64
93
  });
65
94
  container.appendChild(article);
66
95
  return article;
67
96
  }
68
97
 
69
- export function renderDefaultRuntimeDetails({ container, viewer, node, presentation, close, resolveAsset }) {
98
+ export function renderDefaultRuntimeDetails({ container, viewer, node, presentation, close, resolveAsset, i18n = null, locale, messages, formatRuntimeTime, runtimeTimeFormat }) {
99
+ const translator = resolveI18n({ i18n: i18n || viewer?.i18n, locale, messages });
100
+ const timeOverrides = { i18n: translator, formatRuntimeTime, runtimeTimeFormat };
70
101
  const popover = element('section', 'mb-runtime-details-popover');
71
102
  popover.setAttribute('role', 'dialog');
72
- popover.setAttribute('aria-label', `${node.name || '节点'}审批详情`);
103
+ popover.setAttribute('aria-label', translator.t('viewer.details.ariaLabel', { name: node.name || translator.t('viewer.details.fallbackNodeName') }));
73
104
  popover.tabIndex = -1;
74
105
  const header = element('header', 'mb-runtime-details-head');
75
106
  const heading = element('div', 'mb-runtime-details-heading');
76
- heading.append(element('strong', '', node.name || '节点详情'), element('span', '', presentation.round > 1 ? `第 ${presentation.round} 次处理` : '审批轨迹'));
107
+ heading.append(
108
+ element('strong', '', node.name || translator.t('viewer.details.fallbackTitle')),
109
+ element('span', '', presentation.round > 1 ? translator.t('viewer.details.roundLabel', { round: presentation.round }) : translator.t('viewer.details.traceSubtitle')),
110
+ );
77
111
  const status = element('em', `status-${presentation.status}`, presentation.statusLabel);
78
112
  applyRuntimeTone(status, viewer?.runtimeAppearance?.resolveStatus(presentation.status));
79
- const closeButton = runtimeDetailsCloseButton({ viewer, label: '关闭审批详情', close });
113
+ const closeButton = runtimeDetailsCloseButton({ viewer, label: translator.t('viewer.details.closeLabel'), close });
80
114
  header.append(heading, status, closeButton);
81
115
  popover.appendChild(header);
82
116
 
83
117
  if (presentation.approvalMode || presentation.total > 1) {
84
- const mode = presentation.approvalMode === 'all' ? (presentation.multiInstanceMode === 'sequential' ? '顺序会签' : '会签') : presentation.approvalMode === 'any' ? '或签' : '多人审批';
118
+ const mode = presentation.approvalMode === 'all'
119
+ ? translator.t(presentation.multiInstanceMode === 'sequential' ? 'viewer.details.approvalModeAllSequential' : 'viewer.details.approvalModeAll')
120
+ : presentation.approvalMode === 'any'
121
+ ? translator.t('viewer.details.approvalModeAny')
122
+ : translator.t('viewer.details.approvalModeMulti');
85
123
  const summary = element('div', 'mb-runtime-details-progress');
86
124
  summary.append(element('span', '', mode), element('strong', '', `${presentation.completed}/${presentation.total || presentation.required}`));
87
125
  popover.appendChild(summary);
@@ -100,11 +138,13 @@ export function renderDefaultRuntimeDetails({ container, viewer, node, presentat
100
138
  }
101
139
  const copy = element('div', 'mb-runtime-details-person-copy');
102
140
  const title = element('div', 'mb-runtime-details-person-title');
103
- const recordStatus = element('em', `status-${record.status}`, outcomeLabel(record.outcome) || presentation.statusLabel);
141
+ const recordStatus = element('em', `status-${record.status}`, outcomeLabel(record.outcome, translator) || presentation.statusLabel);
104
142
  applyRuntimeTone(recordStatus, viewer?.runtimeAppearance?.resolveStatus(record.status));
105
- title.append(element('strong', '', record.participant?.name || record.assignee || '待分配审批人'), recordStatus);
143
+ title.append(element('strong', '', record.participant?.name || record.assignee || translator.t('runtime.summary.pendingAssignee')), recordStatus);
106
144
  copy.appendChild(title);
107
- const time = [record.startTime, record.endTime].map((value) => formatRuntimeInstant(value)).filter(Boolean).join(' — ');
145
+ const startText = formatViewerTime(viewer, record.startTime, 'details', 'start', timeOverrides);
146
+ const endText = formatViewerTime(viewer, record.endTime, 'details', 'end', timeOverrides);
147
+ const time = [startText, endText].filter(Boolean).join(' — ');
108
148
  if (time) copy.appendChild(element('time', '', time));
109
149
  row.append(avatar, copy);
110
150
  body.appendChild(row);
@@ -115,16 +155,19 @@ export function renderDefaultRuntimeDetails({ container, viewer, node, presentat
115
155
  visits.forEach((visit) => {
116
156
  if (presentation.visits.length > 1) {
117
157
  const historical = visit.effective === false || visit.superseded;
118
- body.appendChild(element('div', 'mb-runtime-details-round', historical ? `第 ${visit.round} 次处理 · 历史` : `第 ${visit.round} 次处理`));
158
+ body.appendChild(element('div', 'mb-runtime-details-round', translator.t(
159
+ historical ? 'viewer.details.roundHistorical' : 'viewer.details.roundLabel',
160
+ { round: visit.round },
161
+ )));
119
162
  }
120
163
  [...visit.records].reverse().forEach(appendRecord);
121
164
  [...visit.actions].reverse().forEach((action) => {
122
- renderRuntimeAction({ container: body, viewer, action, resolveAsset });
165
+ renderRuntimeAction({ container: body, viewer, action, resolveAsset, i18n: translator, timeOverrides });
123
166
  renderedActionIds.add(action.id);
124
167
  });
125
168
  });
126
169
  [...presentation.actions].reverse().filter((action) => !renderedActionIds.has(action.id)).forEach((action) => {
127
- renderRuntimeAction({ container: body, viewer, action, resolveAsset });
170
+ renderRuntimeAction({ container: body, viewer, action, resolveAsset, i18n: translator, timeOverrides });
128
171
  renderedActionIds.add(action.id);
129
172
  });
130
173
 
@@ -132,8 +175,11 @@ export function renderDefaultRuntimeDetails({ container, viewer, node, presentat
132
175
  abnormal.forEach((transition) => {
133
176
  const block = element('article', `mb-runtime-details-transition type-${transition.type}`);
134
177
  applyRuntimeTone(block, viewer?.runtimeAppearance?.resolveTransition(transition).tone);
135
- block.appendChild(element('strong', '', transition.type === 'reject' ? `驳回至 ${transition.targetName || transition.targetElementId}` : `退回至 ${transition.targetName || transition.targetElementId}`));
136
- const meta = [transition.operator, formatRuntimeInstant(transition.occurredAt || transition.time)].filter(Boolean).join(' · ');
178
+ block.appendChild(element('strong', '', translator.t(
179
+ transition.type === 'reject' ? 'viewer.details.rejectedTo' : 'viewer.details.returnedTo',
180
+ { target: transition.targetName || transition.targetElementId },
181
+ )));
182
+ const meta = [transition.operator, formatViewerTime(viewer, transition.occurredAt || transition.time, 'details', 'occurred', timeOverrides)].filter(Boolean).join(' · ');
137
183
  if (meta) block.appendChild(element('span', '', meta));
138
184
  if (transition.action && !renderedActionIds.has(transition.action.id)) {
139
185
  renderRuntimeApprovalContent({
@@ -141,6 +187,7 @@ export function renderDefaultRuntimeDetails({ container, viewer, node, presentat
141
187
  action: transition.action,
142
188
  resolveAsset,
143
189
  onPreview: (asset, action) => viewer?._openRuntimeAssetPreview(asset, action),
190
+ i18n: translator,
144
191
  });
145
192
  } else if (!transition.action && transition.comment) block.appendChild(element('p', '', transition.comment));
146
193
  body.appendChild(block);
@@ -161,27 +208,43 @@ export function renderDefaultRuntimeTransitionDetails({
161
208
  locateSource,
162
209
  locateTarget,
163
210
  resolveAsset,
211
+ i18n = null,
212
+ locale,
213
+ messages,
214
+ formatRuntimeTime,
215
+ runtimeTimeFormat,
164
216
  }) {
165
- const actionLabel = transition.type === 'return' ? '退回' : '驳回';
217
+ const translator = resolveI18n({ i18n: i18n || viewer?.i18n, locale, messages });
218
+ const timeOverrides = { i18n: translator, formatRuntimeTime, runtimeTimeFormat };
219
+ const isReturn = transition.type === 'return';
220
+ const actionLabel = translator.t(isReturn ? 'runtime.transitions.return' : 'runtime.transitions.reject');
221
+ const sourceLabel = sourceNode?.name || transition.sourceName || translator.t('viewer.transitionDetails.fallbackNodeName');
166
222
  const popover = element('section', 'mb-runtime-details-popover mb-runtime-transition-details');
167
223
  popover.setAttribute('role', 'dialog');
168
- popover.setAttribute('aria-label', `${sourceNode?.name || transition.sourceName || '节点'}${actionLabel}记录`);
224
+ popover.setAttribute('aria-label', translator.t(
225
+ isReturn ? 'viewer.transitionDetails.returnRecordAria' : 'viewer.transitionDetails.rejectRecordAria',
226
+ { source: sourceLabel },
227
+ ));
169
228
  popover.tabIndex = -1;
170
229
 
171
230
  const header = element('header', 'mb-runtime-details-head');
172
231
  const heading = element('div', 'mb-runtime-details-heading');
173
232
  heading.append(
174
- element('strong', '', sourceNode?.name || transition.sourceName || '驳回记录'),
175
- element('span', '', `${actionLabel}记录`),
233
+ element('strong', '', sourceNode?.name || transition.sourceName || translator.t('viewer.transitionDetails.fallbackTitle')),
234
+ element('span', '', translator.t(isReturn ? 'viewer.transitionDetails.returnRecord' : 'viewer.transitionDetails.rejectRecord')),
176
235
  );
177
- const status = element('em', 'status-rejected', `已${actionLabel}`);
236
+ const status = element('em', 'status-rejected', translator.t(isReturn ? 'viewer.transitionDetails.returnedBadge' : 'viewer.transitionDetails.rejectedBadge'));
178
237
  applyRuntimeTone(status, viewer?.runtimeAppearance?.resolveTransition(transition).tone);
179
- const closeButton = runtimeDetailsCloseButton({ viewer, label: `关闭${actionLabel}详情`, close });
238
+ const closeButton = runtimeDetailsCloseButton({
239
+ viewer,
240
+ label: translator.t(isReturn ? 'viewer.transitionDetails.closeReturnDetails' : 'viewer.transitionDetails.closeRejectDetails'),
241
+ close,
242
+ });
180
243
  header.append(heading, status, closeButton);
181
244
 
182
245
  const body = element('div', 'mb-runtime-details-body');
183
246
  const actor = element('article', 'mb-runtime-transition-actor');
184
- const actorName = transition.action?.actor?.name || transition.operator || '未知处理人';
247
+ const actorName = transition.action?.actor?.name || transition.operator || translator.t('viewer.transitionDetails.unknownOperator');
185
248
  const avatar = element('span', 'mb-runtime-details-avatar', actorName.slice(0, 1));
186
249
  const actorCopy = element('div', 'mb-runtime-details-person-copy');
187
250
  const actorTitle = element('div', 'mb-runtime-details-person-title');
@@ -192,20 +255,24 @@ export function renderDefaultRuntimeTransitionDetails({
192
255
  actorStatus,
193
256
  );
194
257
  actorCopy.appendChild(actorTitle);
195
- const time = formatRuntimeInstant(transition.action?.occurredAt || transition.occurredAt || transition.time);
258
+ const time = formatViewerTime(viewer, transition.action?.occurredAt || transition.occurredAt || transition.time, 'transition', 'occurred', timeOverrides);
196
259
  if (time) actorCopy.appendChild(element('time', '', time));
197
260
  actor.append(avatar, actorCopy);
198
261
  body.appendChild(actor);
199
262
 
200
263
  const target = element('article', `mb-runtime-details-transition type-${transition.type}`);
201
264
  applyRuntimeTone(target, viewer?.runtimeAppearance?.resolveTransition(transition).tone);
202
- target.appendChild(element('strong', '', `${actionLabel}至 ${targetNode?.name || transition.targetName || transition.targetElementId}`));
265
+ target.appendChild(element('strong', '', translator.t(
266
+ isReturn ? 'viewer.transitionDetails.returnedTo' : 'viewer.transitionDetails.rejectedTo',
267
+ { target: targetNode?.name || transition.targetName || transition.targetElementId },
268
+ )));
203
269
  if (transition.action) {
204
270
  renderRuntimeApprovalContent({
205
271
  container: target,
206
272
  action: transition.action,
207
273
  resolveAsset,
208
274
  onPreview: (asset, action) => viewer?._openRuntimeAssetPreview(asset, action),
275
+ i18n: translator,
209
276
  });
210
277
  } else if (transition.comment) target.appendChild(element('p', '', transition.comment));
211
278
  body.appendChild(target);
@@ -217,11 +284,11 @@ export function renderDefaultRuntimeTransitionDetails({
217
284
  }
218
285
 
219
286
  const footer = element('footer', 'mb-runtime-transition-actions');
220
- const sourceButton = element('button', '', '定位来源');
287
+ const sourceButton = element('button', '', translator.t('viewer.transitionDetails.locateSource'));
221
288
  sourceButton.type = 'button';
222
289
  sourceButton.disabled = !sourceNode;
223
290
  sourceButton.addEventListener('click', locateSource);
224
- const targetButton = element('button', '', '定位目标');
291
+ const targetButton = element('button', '', translator.t('viewer.transitionDetails.locateTarget'));
225
292
  targetButton.type = 'button';
226
293
  targetButton.disabled = !targetNode;
227
294
  targetButton.addEventListener('click', locateTarget);
@@ -289,13 +356,21 @@ function buildVisibleGraph(model, predicate, orientation = 'horizontal') {
289
356
  return copy;
290
357
  }
291
358
 
359
+ function isApprovalProjectionNode(node) {
360
+ const def = NODE_DEFINITIONS[node.type] || {};
361
+ if (['start', 'end'].includes(def.eventStage)) return true;
362
+ if (['userTask', 'callActivity'].includes(node.type)) return true;
363
+ if (node.type === 'serviceTask' && node.properties?.extensionAttributes?.['nova:nodeKind'] === 'cc') return true;
364
+ return false;
365
+ }
366
+
292
367
  export function projectModel(model, projection = 'standard') {
293
368
  const rootGraph = getScopeGraph(model, model.id);
294
369
  if (projection === 'approval') {
295
- return buildVisibleGraph(rootGraph, (n) => { const def = NODE_DEFINITIONS[n.type] || {}; return ['start', 'end'].includes(def.eventStage) || ['userTask', 'callActivity'].includes(n.type); }, 'horizontal');
370
+ return buildVisibleGraph(rootGraph, isApprovalProjectionNode, 'horizontal');
296
371
  }
297
372
  if (projection === 'compact') {
298
- return buildVisibleGraph(rootGraph, (n) => { const def = NODE_DEFINITIONS[n.type] || {}; return ['start', 'end'].includes(def.eventStage) || ['userTask', 'callActivity'].includes(n.type); }, 'vertical');
373
+ return buildVisibleGraph(rootGraph, isApprovalProjectionNode, 'vertical');
299
374
  }
300
375
  return cloneModel(rootGraph);
301
376
  }
@@ -336,7 +411,6 @@ function projectRuntime(runtime, projectedModel) {
336
411
  return { ...normalized, transitions, edgeVisits: projectedEdgeVisits, visitedEdges: projectedVisited };
337
412
  }
338
413
 
339
- const DEFAULT_TIMELINE_DESCRIPTION = '按实际处理顺序展示';
340
414
  const DEFAULT_RUNTIME_DETAILS_LAYOUT = Object.freeze({
341
415
  desktop: Object.freeze({ placement: 'popover' }),
342
416
  mobile: Object.freeze({ placement: 'bottom' }),
@@ -366,10 +440,19 @@ export class BpmnViewer {
366
440
  this.container = options.container;
367
441
  this.themeController = options.themeController || new ThemeController({ root: this.container, theme: options.theme, onChange: options.onThemeChange });
368
442
  this._ownsThemeController = !options.themeController;
443
+ if (options.i18n) {
444
+ this.i18n = resolveI18n(options.i18n);
445
+ this._ownsI18n = false;
446
+ } else {
447
+ this.i18n = createI18n({ locale: options.locale, messages: options.messages });
448
+ this._ownsI18n = true;
449
+ }
450
+ this.formatRuntimeTime = typeof options.formatRuntimeTime === 'function' ? options.formatRuntimeTime : null;
451
+ this.runtimeTimeFormat = options.runtimeTimeFormat && typeof options.runtimeTimeFormat === 'object' ? { ...options.runtimeTimeFormat } : null;
369
452
  this.runtimeAppearanceOptions = options.runtimeAppearance || {};
370
- this.runtimeAppearance = createRuntimeAppearance(this.runtimeAppearanceOptions);
453
+ this.runtimeAppearance = createRuntimeAppearance(this.runtimeAppearanceOptions, { i18n: this.i18n });
371
454
  this.model = options.model;
372
- this.runtime = options.runtime ? normalizeRuntime(options.runtime) : null;
455
+ this.runtime = options.runtime ? normalizeRuntime(options.runtime, { i18n: this.i18n }) : null;
373
456
  this.responsive = options.responsive === true;
374
457
  this.projection = options.projection || (this.runtime && this.responsive ? 'auto' : this.runtime ? 'approval' : 'standard');
375
458
  this.activeProjection = 'standard';
@@ -435,6 +518,9 @@ export class BpmnViewer {
435
518
  if (this._ownsThemeController) this.themeController.destroy();
436
519
  throw error;
437
520
  }
521
+ this._offI18n = typeof this.i18n.subscribe === 'function'
522
+ ? this.i18n.subscribe(() => this._handleLocaleChange())
523
+ : null;
438
524
  this._resizeObserver = typeof ResizeObserver === 'function'
439
525
  ? new ResizeObserver(() => {
440
526
  this._refreshAutoProjection();
@@ -447,6 +533,30 @@ export class BpmnViewer {
447
533
  this._resizeObserver?.observe(options.container);
448
534
  }
449
535
 
536
+ _handleLocaleChange() {
537
+ this.runtimeAppearance = createRuntimeAppearance(this.runtimeAppearanceOptions, { i18n: this.i18n });
538
+ this.refresh({ preserveViewport: true });
539
+ }
540
+
541
+ setLocale(locale, messages) {
542
+ if (!this._ownsI18n) {
543
+ this._offI18n?.();
544
+ this.i18n = createI18n({ locale: locale ?? this.i18n.locale, messages });
545
+ this._ownsI18n = true;
546
+ this._offI18n = this.i18n.subscribe(() => this._handleLocaleChange());
547
+ if (this.renderer && !(this.renderer instanceof RuntimeTimelineHost)) {
548
+ this.renderer._offI18n?.();
549
+ this.renderer.i18n = this.i18n;
550
+ this.renderer._ownsI18n = false;
551
+ }
552
+ this._handleLocaleChange();
553
+ return this.i18n.getState();
554
+ }
555
+ return this.i18n.setLocale(locale, messages);
556
+ }
557
+
558
+ getLocale() { return this.i18n.locale; }
559
+
450
560
  _resolveProjection() {
451
561
  if (this.projection !== 'auto') return this.projection;
452
562
  if (!this.runtime) return 'standard';
@@ -481,8 +591,8 @@ export class BpmnViewer {
481
591
  const previousProjection = this.activeProjection;
482
592
  this.activeProjection = this._resolveProjection();
483
593
  if (this.runtime && ['approval', 'compact'].includes(this.activeProjection)) {
484
- const sourcePresentation = this.runtimePresenter({ model: this.model, runtime: this.runtime, appearance: this.runtimeAppearance });
485
- this.traceProjection = this.runtimeTraceProjector({ model: this.model, runtime: this.runtime, presentation: sourcePresentation, options: this.runtimeTraceOptions });
594
+ const sourcePresentation = this.runtimePresenter({ model: this.model, runtime: this.runtime, appearance: this.runtimeAppearance, i18n: this.i18n });
595
+ this.traceProjection = this.runtimeTraceProjector({ model: this.model, runtime: this.runtime, presentation: sourcePresentation, options: this.runtimeTraceOptions, i18n: this.i18n });
486
596
  this.projectedModel = this.traceProjection.graphModel;
487
597
  this.projectedRuntime = this.traceProjection.graphRuntime;
488
598
  } else {
@@ -490,7 +600,7 @@ export class BpmnViewer {
490
600
  this.projectedModel = projectModel(this.model, this.activeProjection);
491
601
  this.projectedRuntime = projectRuntime(this.runtime, this.projectedModel);
492
602
  }
493
- this.runtimePresentation = this.runtimePresenter({ model: this.projectedModel, runtime: this.projectedRuntime, appearance: this.runtimeAppearance });
603
+ this.runtimePresentation = this.runtimePresenter({ model: this.projectedModel, runtime: this.projectedRuntime, appearance: this.runtimeAppearance, i18n: this.i18n });
494
604
  if (previousProjection !== this.activeProjection) this.onProjectionChange({ requested: this.projection, active: this.activeProjection });
495
605
  }
496
606
 
@@ -508,8 +618,8 @@ export class BpmnViewer {
508
618
  return result == null ? null : String(result);
509
619
  };
510
620
  return {
511
- title: resolve(this.timelineOptions.title, this.model.name || '审批轨迹'),
512
- description: resolve(this.timelineOptions.description, DEFAULT_TIMELINE_DESCRIPTION),
621
+ title: resolve(this.timelineOptions.title, this.model.name || this.i18n.t('timeline.defaultTitle')),
622
+ description: resolve(this.timelineOptions.description, this.i18n.t('timeline.defaultDescription')),
513
623
  };
514
624
  }
515
625
 
@@ -599,6 +709,10 @@ export class BpmnViewer {
599
709
  iconRegistry: this.options.iconRegistry,
600
710
  appearance: this.runtimeAppearance,
601
711
  themeState: this.themeController.getState(),
712
+ i18n: this.i18n,
713
+ formatRuntimeTime: this.formatRuntimeTime,
714
+ runtimeTimeFormat: this.runtimeTimeFormat,
715
+ formatTime: (value, field = 'occurred') => formatViewerTime(this, value, 'timeline', field),
602
716
  resolveAsset: (asset, purpose, action) => this._resolveRuntimeAsset(asset, purpose, action),
603
717
  onAssetPreview: (asset, action) => this._openRuntimeAssetPreview(asset, action),
604
718
  renderer: this.runtimeTimelineRenderer,
@@ -639,6 +753,8 @@ export class BpmnViewer {
639
753
  }
640
754
  this.renderer = new DiagramRenderer(this.container, {
641
755
  themeController: this.themeController,
756
+ i18n: this.i18n,
757
+ autoSyncI18n: false,
642
758
  model: this.projectedModel,
643
759
  visualModel: this.model,
644
760
  runtime: this.projectedRuntime,
@@ -810,15 +926,15 @@ export class BpmnViewer {
810
926
  const root = element('div', 'mb-runtime-asset-preview');
811
927
  root.setAttribute('role', 'dialog');
812
928
  root.setAttribute('aria-modal', 'true');
813
- root.setAttribute('aria-label', `图片预览:${asset.name}`);
929
+ root.setAttribute('aria-label', this.i18n.t('viewer.assets.imagePreviewAria', { name: asset.name }));
814
930
  root.addEventListener('pointerdown', (event) => { if (event.target === root) this.closeRuntimeAssetPreview(); });
815
931
  const dialog = element('section', 'mb-runtime-asset-preview-dialog');
816
932
  const header = element('header', 'mb-runtime-asset-preview-head');
817
933
  header.appendChild(element('strong', '', asset.name));
818
- const close = runtimeDetailsCloseButton({ viewer: this, label: '关闭图片预览', close: () => this.closeRuntimeAssetPreview() });
934
+ const close = runtimeDetailsCloseButton({ viewer: this, label: this.i18n.t('viewer.assets.closeImagePreview'), close: () => this.closeRuntimeAssetPreview() });
819
935
  header.appendChild(close);
820
936
  const body = element('div', 'mb-runtime-asset-preview-body');
821
- const state = element('span', 'mb-runtime-asset-preview-state', '图片加载中');
937
+ const state = element('span', 'mb-runtime-asset-preview-state', this.i18n.t('viewer.assets.imageLoading'));
822
938
  body.appendChild(state);
823
939
  dialog.append(header, body);
824
940
  root.appendChild(dialog);
@@ -826,14 +942,14 @@ export class BpmnViewer {
826
942
  this._assetPreviewRoot = root;
827
943
  Promise.resolve(this._resolveRuntimeAsset(asset, 'preview', action)).then((url) => {
828
944
  if (!root.isConnected) return;
829
- if (!url) { state.textContent = '资源不可用'; return; }
945
+ if (!url) { state.textContent = this.i18n.t('viewer.assets.unavailable'); return; }
830
946
  const image = document.createElement('img');
831
947
  image.alt = asset.name;
832
948
  image.addEventListener('load', () => {
833
949
  if (root.isConnected) body.replaceChildren(image);
834
950
  }, { once: true });
835
951
  image.addEventListener('error', () => {
836
- if (root.isConnected) state.textContent = '资源不可用';
952
+ if (root.isConnected) state.textContent = this.i18n.t('viewer.assets.unavailable');
837
953
  }, { once: true });
838
954
  image.src = url;
839
955
  });
@@ -869,6 +985,8 @@ export class BpmnViewer {
869
985
  resolveAsset: (asset, purpose, action) => this._resolveRuntimeAsset(asset, purpose, action),
870
986
  themeState: this.themeController.getState(),
871
987
  runtimeAppearance: this.runtimeAppearance,
988
+ i18n: this.i18n,
989
+ formatTime: (value, field = 'occurred') => formatViewerTime(this, value, 'details', field),
872
990
  }) || null;
873
991
  this._prepareRuntimeDetailsMotion(layout);
874
992
  this._positionRuntimeDetails(anchor, layout);
@@ -911,6 +1029,8 @@ export class BpmnViewer {
911
1029
  resolveAsset: (asset, purpose, action) => this._resolveRuntimeAsset(asset, purpose, action),
912
1030
  themeState: this.themeController.getState(),
913
1031
  runtimeAppearance: this.runtimeAppearance,
1032
+ i18n: this.i18n,
1033
+ formatTime: (value, field = 'occurred') => formatViewerTime(this, value, 'transition', field),
914
1034
  locateSource: () => locate(sourceNode),
915
1035
  locateTarget: () => locate(targetNode),
916
1036
  }) || null;
@@ -949,9 +1069,10 @@ export class BpmnViewer {
949
1069
  let left = target.left - host.left + target.width / 2 - width / 2;
950
1070
  left = Math.max(12, Math.min(left, host.width - width - 12));
951
1071
  let top = target.top - host.top - height - 10;
952
- if (top < 12) top = Math.min(host.height - height - 12, target.bottom - host.top + 10);
1072
+ if (top < 12) top = target.bottom - host.top + 10;
1073
+ top = Math.max(12, Math.min(top, host.height - height - 12));
953
1074
  popover.style.left = `${Math.max(12, left)}px`;
954
- popover.style.top = `${Math.max(12, top)}px`;
1075
+ popover.style.top = `${top}px`;
955
1076
  }
956
1077
 
957
1078
  closeRuntimeDetails() {
@@ -1006,7 +1127,8 @@ export class BpmnViewer {
1006
1127
  const viewport = this.renderer?.getViewportState?.();
1007
1128
  if (viewport) this._lastViewport = viewport;
1008
1129
  } else if (kind === 'timeline') {
1009
- this._timelineScroll = this.container.scrollTop || this._timelineScroll || 0;
1130
+ const scrollTop = this.renderer?.getScrollTop?.() ?? this.container.scrollTop ?? 0;
1131
+ this._timelineScroll = this._containerHasSize() ? scrollTop : (scrollTop || this._timelineScroll || 0);
1010
1132
  }
1011
1133
  return {
1012
1134
  kind,
@@ -1033,6 +1155,10 @@ export class BpmnViewer {
1033
1155
  ...this._resolveTimelineOptions(),
1034
1156
  appearance: this.runtimeAppearance,
1035
1157
  themeState: this.themeController.getState(),
1158
+ i18n: this.i18n,
1159
+ formatRuntimeTime: this.formatRuntimeTime,
1160
+ runtimeTimeFormat: this.runtimeTimeFormat,
1161
+ formatTime: (value, field = 'occurred') => formatViewerTime(this, value, 'timeline', field),
1036
1162
  });
1037
1163
  this.renderer.render();
1038
1164
  }
@@ -1048,12 +1174,16 @@ export class BpmnViewer {
1048
1174
  if (target.kind === 'node') {
1049
1175
  const node = this.model.nodes.find((item) => item.id === target.id);
1050
1176
  const presentation = node ? this.runtimePresentation.getNode(node.id) : null;
1051
- if (node && presentation?.hasDetails) this.openRuntimeDetails(node, presentation, target.anchor || null);
1177
+ const anchor = target.anchor?.isConnected
1178
+ ? target.anchor
1179
+ : this.container?.querySelector?.(`[data-node-id="${target.id}"]`) || null;
1180
+ if (node && presentation?.hasDetails) this.openRuntimeDetails(node, presentation, anchor);
1052
1181
  return;
1053
1182
  }
1054
1183
  if (target.kind === 'transition') {
1055
1184
  const transition = this.runtimePresentation.getTransition(target.id);
1056
- if (transition) this._openRuntimeTransitionDetails(transition, target.anchor || null);
1185
+ const anchor = target.anchor?.isConnected ? target.anchor : null;
1186
+ if (transition) this._openRuntimeTransitionDetails(transition, anchor);
1057
1187
  }
1058
1188
  }
1059
1189
 
@@ -1074,7 +1204,12 @@ export class BpmnViewer {
1074
1204
  this._silentViewport = true;
1075
1205
  try {
1076
1206
  if (kind === 'diagram' && preserveViewport && this._lastViewport) this.renderer.setViewportState?.(this._lastViewport);
1077
- if (kind === 'timeline' && preserveViewport) this.container.scrollTop = this._timelineScroll || 0;
1207
+ if (kind === 'timeline') {
1208
+ const scrollTop = preserveViewport ? (this._timelineScroll || 0) : 0;
1209
+ this._timelineScroll = scrollTop;
1210
+ if (typeof this.renderer?.setScrollTop === 'function') this.renderer.setScrollTop(scrollTop);
1211
+ else this.container.scrollTop = scrollTop;
1212
+ }
1078
1213
  } finally {
1079
1214
  this._silentViewport = false;
1080
1215
  }
@@ -1088,7 +1223,7 @@ export class BpmnViewer {
1088
1223
  this.refresh({ preserveViewport: same });
1089
1224
  }
1090
1225
  setRuntime(runtime) {
1091
- const next = runtime ? normalizeRuntime(runtime) : null;
1226
+ const next = runtime ? normalizeRuntime(runtime, { i18n: this.i18n }) : null;
1092
1227
  const sameInstance = Boolean(this.runtime) && Boolean(next) && (this.runtime.processInstanceId || '') === (next.processInstanceId || '');
1093
1228
  this.runtime = next;
1094
1229
  this.mode = this.options.mode === 'instance' || this.runtime ? 'instance' : 'viewer';
@@ -1104,13 +1239,21 @@ export class BpmnViewer {
1104
1239
  else this._pendingFit = true;
1105
1240
  });
1106
1241
  }
1107
- setDisplayOptions({ timeline, runtimeDetails, runtimeTraceOptions, runtimeAssetResolver, replace = false } = {}) {
1242
+ setDisplayOptions({ timeline, runtimeDetails, runtimeTraceOptions, runtimeAssetResolver, formatRuntimeTime, runtimeTimeFormat, replace = false } = {}) {
1108
1243
  let changed = false;
1109
1244
  if (runtimeAssetResolver !== undefined) {
1110
1245
  this.runtimeAssetResolver = runtimeAssetResolver || null;
1111
1246
  this._svgExportAssetCache.clear();
1112
1247
  changed = true;
1113
1248
  }
1249
+ if (replace || formatRuntimeTime !== undefined) {
1250
+ this.formatRuntimeTime = typeof formatRuntimeTime === 'function' ? formatRuntimeTime : null;
1251
+ changed = true;
1252
+ }
1253
+ if (replace || runtimeTimeFormat !== undefined) {
1254
+ this.runtimeTimeFormat = runtimeTimeFormat && typeof runtimeTimeFormat === 'object' ? { ...runtimeTimeFormat } : null;
1255
+ changed = true;
1256
+ }
1114
1257
  if (replace || runtimeTraceOptions !== undefined) {
1115
1258
  this.runtimeTraceOptions = replace
1116
1259
  ? { ...(runtimeTraceOptions || {}) }
@@ -1132,17 +1275,33 @@ export class BpmnViewer {
1132
1275
  getThemeState() { return this.themeController.getState(); }
1133
1276
  setRuntimeAppearance(runtimeAppearance) {
1134
1277
  this.runtimeAppearanceOptions = runtimeAppearance || {};
1135
- this.runtimeAppearance = createRuntimeAppearance(this.runtimeAppearanceOptions);
1278
+ this.runtimeAppearance = createRuntimeAppearance(this.runtimeAppearanceOptions, { i18n: this.i18n });
1136
1279
  this.refresh({ preserveViewport: true });
1137
1280
  }
1138
1281
  refreshPresentation() {
1282
+ if (this.mode === 'instance') {
1283
+ this.refresh({ preserveViewport: true });
1284
+ return;
1285
+ }
1139
1286
  if (this.mode !== 'viewer' || (this.runtime && this.activeProjection === 'compact')) return;
1140
1287
  this.renderer?.refreshPresentation?.();
1141
1288
  }
1142
1289
  exportSvg(options = {}) {
1143
1290
  const isTimeline = Boolean(this.runtime && this.activeProjection === 'compact' && this.traceProjection);
1144
- const label = isTimeline ? '移动时间线' : this.activeProjection === 'approval' ? '实际路径' : this.runtime ? '完整 BPMN' : '流程展示';
1291
+ const label = isTimeline
1292
+ ? this.i18n.t('exportSvg.defaultLabels.timeline')
1293
+ : this.activeProjection === 'approval'
1294
+ ? this.i18n.t('exportSvg.defaultLabels.approval')
1295
+ : this.runtime
1296
+ ? this.i18n.t('exportSvg.defaultLabels.standard')
1297
+ : this.i18n.t('exportSvg.defaultLabels.viewer');
1145
1298
  const filename = options.filename || this.svgExportOptions.filename || `${this.model.name || this.model.id || 'process'}-${label}`;
1299
+ const formatRuntimeTime = options.formatRuntimeTime !== undefined
1300
+ ? options.formatRuntimeTime
1301
+ : (this.svgExportOptions.formatRuntimeTime !== undefined ? this.svgExportOptions.formatRuntimeTime : this.formatRuntimeTime);
1302
+ const runtimeTimeFormat = options.runtimeTimeFormat !== undefined
1303
+ ? options.runtimeTimeFormat
1304
+ : (this.svgExportOptions.runtimeTimeFormat !== undefined ? this.svgExportOptions.runtimeTimeFormat : this.runtimeTimeFormat);
1146
1305
  if (isTimeline) {
1147
1306
  const timeline = this._resolveTimelineOptions();
1148
1307
  return exportRuntimeTimelineSvg({
@@ -1155,11 +1314,14 @@ export class BpmnViewer {
1155
1314
  themeController: this.themeController,
1156
1315
  iconRegistry: this.options.iconRegistry,
1157
1316
  runtimeAppearance: this.runtimeAppearance,
1317
+ i18n: this.i18n,
1318
+ formatRuntimeTime,
1319
+ runtimeTimeFormat,
1158
1320
  resolveAsset: (asset, purpose, action) => this._resolveRuntimeAsset(asset, purpose, action, options.signal),
1159
1321
  assetCache: this._svgExportAssetCache,
1160
1322
  timelineRenderer: this.svgExportOptions.runtimeTimelineRenderer,
1161
1323
  label,
1162
- }, { ...this.svgExportOptions, ...options, filename });
1324
+ }, { ...this.svgExportOptions, ...options, filename, formatRuntimeTime, runtimeTimeFormat });
1163
1325
  }
1164
1326
  return this.renderer.exportSvg({ ...this.svgExportOptions, ...options, filename, label });
1165
1327
  }
@@ -1170,8 +1332,9 @@ export class BpmnViewer {
1170
1332
  }
1171
1333
  this._svgExportPreview = openSvgExportPreview({
1172
1334
  container: this.container,
1173
- title: options.previewTitle || '导出 SVG',
1335
+ title: options.previewTitle || this.i18n.t('exportSvg.preview.defaultTitle'),
1174
1336
  initialTheme: options.theme || 'current',
1337
+ i18n: this.i18n,
1175
1338
  createArtifact: (previewOptions) => this.exportSvg({ ...options, ...previewOptions }),
1176
1339
  onClose: () => { this._svgExportPreview = null; },
1177
1340
  onDownload: options.onDownload,
@@ -1181,6 +1344,8 @@ export class BpmnViewer {
1181
1344
  fitView() { this.renderer.fitView(); }
1182
1345
  zoomBy(delta) { this.renderer.zoomBy(delta); }
1183
1346
  destroy() {
1347
+ this._offI18n?.();
1348
+ this._offI18n = null;
1184
1349
  this._sidebarTransitionActive = false;
1185
1350
  this._sidebarViewport = null;
1186
1351
  this._svgExportPreview?.close?.({ immediate: true });