@bpmn-nova/studio 0.3.8-preview → 0.4.0
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 +2 -2
- package/dist/canvas.js +97 -25
- package/dist/config.js +42 -0
- package/dist/context-menu.js +41 -32
- package/dist/controller.js +45 -19
- package/dist/index.d.ts +59 -2
- package/dist/index.js +1 -0
- package/dist/interactions.js +6 -1
- package/dist/modules/bpmn-model/index.d.ts +2 -1
- package/dist/modules/bpmn-model/index.js +12 -10
- package/dist/modules/core/gateway.js +16 -13
- package/dist/modules/core/index.d.ts +6 -4
- package/dist/modules/core/model.js +12 -7
- package/dist/modules/designer/index.d.ts +5 -1
- package/dist/modules/designer/index.js +36 -15
- package/dist/modules/export-svg/index.d.ts +12 -5
- package/dist/modules/export-svg/preview.js +34 -24
- package/dist/modules/export-svg/render.js +102 -50
- package/dist/modules/i18n/index.d.ts +647 -0
- package/dist/modules/i18n/index.js +247 -0
- package/dist/modules/i18n/locales/en-US.js +823 -0
- package/dist/modules/i18n/locales/zh-CN.js +805 -0
- package/dist/modules/node-presentation/index.d.ts +3 -2
- package/dist/modules/node-presentation/index.js +14 -11
- package/dist/modules/palette/index.d.ts +6 -1
- package/dist/modules/palette/index.js +26 -8
- package/dist/modules/palette/panel.js +44 -6
- package/dist/modules/properties/index.d.ts +2 -1
- package/dist/modules/properties/index.js +2 -2
- package/dist/modules/properties-activiti/index.js +84 -59
- package/dist/modules/properties-bpmn/index.js +151 -128
- package/dist/modules/properties-core/index.d.ts +9 -3
- package/dist/modules/properties-core/index.js +16 -4
- package/dist/modules/properties-flowable/index.js +55 -34
- package/dist/modules/properties-renderer/index.d.ts +5 -1
- package/dist/modules/properties-renderer/index.js +110 -42
- package/dist/modules/renderer-svg/index.d.ts +6 -2
- package/dist/modules/renderer-svg/index.js +113 -38
- package/dist/modules/runtime/index.d.ts +33 -5
- package/dist/modules/runtime/index.js +97 -73
- package/dist/modules/runtime/time.js +89 -4
- package/dist/modules/runtime/visits.js +6 -4
- package/dist/modules/theme/index.d.ts +5 -2
- package/dist/modules/theme/index.js +8 -4
- package/dist/modules/viewer/index.d.ts +28 -7
- package/dist/modules/viewer/index.js +213 -56
- package/dist/modules/viewer/runtime-content.js +26 -20
- package/dist/modules/viewer/runtime-trace.js +43 -25
- package/dist/modules/viewer/timeline.js +103 -36
- package/dist/shell.js +279 -75
- package/dist/sidebars.js +3 -1
- package/dist/styles.css +6 -3
- package/llms-full.txt +296 -49
- package/llms.txt +4 -4
- package/package.json +2 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NODE_DEFINITIONS, edgeWaypoints, roundedPath, routeRuntimeTransition, smoothPath } from '../core/index.js';
|
|
2
|
+
import { DEFAULT_I18N, resolveI18n } from '../i18n/index.js';
|
|
2
3
|
import { createDefaultIconRegistry, resolveNodeVisual } from '../icons/index.js';
|
|
3
4
|
import { resolveNodeSubtitle, supportsNodeSubtitle } from '../node-presentation/index.js';
|
|
4
5
|
import { resolveNodeGeometry, resolvePresentationWaypoints } from '../node-geometry/index.js';
|
|
@@ -169,8 +170,21 @@ function finite(value, fallback = 0) {
|
|
|
169
170
|
return Number.isFinite(number) ? number : fallback;
|
|
170
171
|
}
|
|
171
172
|
|
|
172
|
-
function formatTime(value) {
|
|
173
|
-
return formatRuntimeInstant(value
|
|
173
|
+
function formatTime(value, field = 'occurred', timeConfig = null) {
|
|
174
|
+
return formatRuntimeInstant(value, timeConfig ? {
|
|
175
|
+
formatRuntimeTime: timeConfig.formatRuntimeTime,
|
|
176
|
+
runtimeTimeFormat: timeConfig.runtimeTimeFormat,
|
|
177
|
+
surface: 'svg',
|
|
178
|
+
field,
|
|
179
|
+
locale: timeConfig.locale,
|
|
180
|
+
} : null);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function resolveExportI18n(context = {}, options = {}) {
|
|
184
|
+
if (options?.i18n || options?.locale !== undefined || options?.messages !== undefined) return resolveI18n(options);
|
|
185
|
+
if (context?.i18n || context?.locale !== undefined || context?.messages !== undefined) return resolveI18n(context);
|
|
186
|
+
if (context?.runtimeAppearance?.i18n) return resolveI18n(context.runtimeAppearance.i18n);
|
|
187
|
+
return DEFAULT_I18N;
|
|
174
188
|
}
|
|
175
189
|
|
|
176
190
|
function formatSize(value) {
|
|
@@ -330,18 +344,19 @@ function renderGeometryShape(document, group, geometry, fill, stroke) {
|
|
|
330
344
|
group.appendChild(shape);
|
|
331
345
|
}
|
|
332
346
|
|
|
333
|
-
function renderDefaultNode({ document, group, node, definition, geometry, visual, presentation, subtitle: definitionSubtitle, theme, iconRegistry }) {
|
|
347
|
+
function renderDefaultNode({ document, group, node, definition, geometry, visual, presentation, subtitle: definitionSubtitle, theme, iconRegistry, i18n = DEFAULT_I18N }) {
|
|
334
348
|
const colors = theme.colors;
|
|
335
349
|
const statusTone = tone(theme, presentation?.status === 'rejected' ? 'danger' : presentation?.status === 'active' ? 'primary' : presentation?.status === 'completed' ? 'success' : 'neutral');
|
|
336
350
|
const typeTone = tone(theme, nodeToneName(node));
|
|
337
351
|
const icon = iconRegistry.resolve(visual.iconId, null);
|
|
352
|
+
const typeLabel = node.type ? i18n.elementTypeLabel(node.type, definition.label) : definition.label;
|
|
338
353
|
const { x, y, width, height } = node;
|
|
339
354
|
if (['event', 'boundary'].includes(definition.kind)) {
|
|
340
355
|
const radius = Math.min(width, height) / 2 - 2;
|
|
341
356
|
group.appendChild(svgElement(document, 'circle', { cx: x + width / 2, cy: y + height / 2, r: radius, fill: colors.surface, stroke: presentation?.status && presentation.status !== 'idle' ? statusTone.strong : colors.borderStrong, 'stroke-width': definition.eventStage === 'end' ? 3 : 2, 'stroke-dasharray': definition.kind === 'boundary' && node.properties?.cancelActivity === false ? '5 3' : null }));
|
|
342
357
|
if (definition.eventStage === 'intermediate' || definition.kind === 'boundary') group.appendChild(svgElement(document, 'circle', { cx: x + width / 2, cy: y + height / 2, r: radius - 5, fill: 'none', stroke: colors.borderStrong, 'stroke-width': 1.4 }));
|
|
343
358
|
appendIcon(document, group, icon, { x: x + width * 0.3, y: y + height * 0.3, width: width * 0.4, height: height * 0.4 }, colors.textSecondary);
|
|
344
|
-
appendTextLines(document, group, wrapText(node.name ||
|
|
359
|
+
appendTextLines(document, group, wrapText(node.name || typeLabel, 150, 12), { x: x + width / 2, y: y + height + 20, lineHeight: 15, attributes: { 'text-anchor': 'middle', fill: colors.textSecondary, 'font-size': 12, 'font-family': theme.fontFamily } });
|
|
345
360
|
return;
|
|
346
361
|
}
|
|
347
362
|
if (['gateway', 'data', 'dataStore'].includes(definition.kind)) {
|
|
@@ -349,25 +364,25 @@ function renderDefaultNode({ document, group, node, definition, geometry, visual
|
|
|
349
364
|
const stroke = definition.kind === 'gateway' && presentation?.status && presentation.status !== 'idle' ? statusTone.strong : colors.borderStrong;
|
|
350
365
|
renderGeometryShape(document, group, geometry, colors.surface, stroke);
|
|
351
366
|
appendIcon(document, group, icon, geometry.iconBounds, colors.textSecondary);
|
|
352
|
-
appendTextLines(document, group, wrapText(node.name ||
|
|
367
|
+
appendTextLines(document, group, wrapText(node.name || typeLabel, definition.kind === 'gateway' ? 160 : 150, 12), { x: geometry.label.x, y: geometry.label.y + 12, lineHeight: geometry.label.lineHeight, attributes: { 'text-anchor': 'middle', fill: colors.textSecondary, 'font-size': 12, 'font-family': theme.fontFamily } });
|
|
353
368
|
return;
|
|
354
369
|
}
|
|
355
370
|
if (definition.kind === 'participant' || definition.kind === 'lane') {
|
|
356
371
|
group.appendChild(svgElement(document, 'rect', { x, y, width, height, rx: 4, fill: colors.surfaceSubtle, stroke: colors.borderStrong, 'stroke-width': 1.3 }));
|
|
357
372
|
const rail = Math.min(42, Math.max(30, width * 0.08));
|
|
358
373
|
group.appendChild(svgElement(document, 'line', { x1: x + rail, y1: y, x2: x + rail, y2: y + height, stroke: colors.borderStrong, 'stroke-width': 1.2 }));
|
|
359
|
-
const title = svgElement(document, 'text', { x: x + rail / 2, y: y + height / 2, transform: `rotate(-90 ${x + rail / 2} ${y + height / 2})`, 'text-anchor': 'middle', fill: colors.textSecondary, 'font-size': 12, 'font-weight': 600, 'font-family': theme.fontFamily }, node.name ||
|
|
374
|
+
const title = svgElement(document, 'text', { x: x + rail / 2, y: y + height / 2, transform: `rotate(-90 ${x + rail / 2} ${y + height / 2})`, 'text-anchor': 'middle', fill: colors.textSecondary, 'font-size': 12, 'font-weight': 600, 'font-family': theme.fontFamily }, node.name || typeLabel);
|
|
360
375
|
group.appendChild(title);
|
|
361
376
|
return;
|
|
362
377
|
}
|
|
363
378
|
if (definition.kind === 'group') {
|
|
364
379
|
group.appendChild(svgElement(document, 'rect', { x, y, width, height, rx: 10, fill: 'none', stroke: colors.borderStrong, 'stroke-width': 1.2, 'stroke-dasharray': '7 5' }));
|
|
365
|
-
group.appendChild(svgElement(document, 'text', { x: x + 12, y: y + 22, fill: colors.textSecondary, 'font-size': 12, 'font-weight': 600, 'font-family': theme.fontFamily }, node.properties?.categoryValue || node.name || '
|
|
380
|
+
group.appendChild(svgElement(document, 'text', { x: x + 12, y: y + 22, fill: colors.textSecondary, 'font-size': 12, 'font-weight': 600, 'font-family': theme.fontFamily }, node.properties?.categoryValue || node.name || i18n.t('canvas.defaultGroupCaption')));
|
|
366
381
|
return;
|
|
367
382
|
}
|
|
368
383
|
if (definition.kind === 'annotation') {
|
|
369
384
|
group.appendChild(svgElement(document, 'path', { d: `M ${x + 10} ${y} H ${x} V ${y + height} H ${x + 10}`, fill: 'none', stroke: colors.borderStrong, 'stroke-width': 1.5 }));
|
|
370
|
-
appendTextLines(document, group, wrapText(node.properties?.text || node.name || '
|
|
385
|
+
appendTextLines(document, group, wrapText(node.properties?.text || node.name || i18n.t('canvas.defaultAnnotationCaption'), width - 24, 12), { x: x + 16, y: y + 20, lineHeight: 17, attributes: { fill: colors.textSecondary, 'font-size': 12, 'font-family': theme.fontFamily } });
|
|
371
386
|
return;
|
|
372
387
|
}
|
|
373
388
|
|
|
@@ -375,7 +390,7 @@ function renderDefaultNode({ document, group, node, definition, geometry, visual
|
|
|
375
390
|
const iconX = x + 14;
|
|
376
391
|
const iconY = y + (height - iconSize) / 2;
|
|
377
392
|
const copyX = iconX + iconSize + 12;
|
|
378
|
-
const title = node.name ||
|
|
393
|
+
const title = node.name || typeLabel;
|
|
379
394
|
const subtitle = definitionSubtitle === undefined
|
|
380
395
|
? presentation?.actionSummary || presentation?.summary || (node.properties?.assignee || node.properties?.candidateGroups || node.properties?.candidateUsers || '')
|
|
381
396
|
: definitionSubtitle;
|
|
@@ -416,7 +431,7 @@ function renderDefaultNode({ document, group, node, definition, geometry, visual
|
|
|
416
431
|
}
|
|
417
432
|
}
|
|
418
433
|
|
|
419
|
-
function prepareNodes({ document, context, options, model, presentation, theme, iconRegistry, warnings }) {
|
|
434
|
+
function prepareNodes({ document, context, options, model, presentation, theme, iconRegistry, warnings, i18n }) {
|
|
420
435
|
const nodeLayer = svgElement(document, 'g', { 'data-layer': 'nodes' });
|
|
421
436
|
const geometries = new Map();
|
|
422
437
|
const runtimeMode = context.mode === 'instance' || Boolean(context.runtime);
|
|
@@ -437,18 +452,18 @@ function prepareNodes({ document, context, options, model, presentation, theme,
|
|
|
437
452
|
if (!rendered) group.replaceChildren();
|
|
438
453
|
} catch (error) {
|
|
439
454
|
group.replaceChildren();
|
|
440
|
-
warnings.push({ code: 'custom-node-renderer-failed', message:
|
|
455
|
+
warnings.push({ code: 'custom-node-renderer-failed', message: i18n.t('exportSvg.warnings.customNodeRendererFailed', { name: node.name || node.id }), elementId: node.id });
|
|
441
456
|
}
|
|
442
457
|
} else if (context.htmlNodeRenderers?.[node.type] || context.htmlNodeRenderers?.[definition.kind] || context.htmlNodeRenderer) {
|
|
443
|
-
warnings.push({ code: 'custom-node-renderer-fallback', message:
|
|
458
|
+
warnings.push({ code: 'custom-node-renderer-fallback', message: i18n.t('exportSvg.warnings.customNodeRendererFallback', { name: node.name || node.id }), elementId: node.id });
|
|
444
459
|
}
|
|
445
460
|
if (!rendered) {
|
|
446
461
|
const geometry = resolveNodeGeometry(node, definition);
|
|
447
462
|
geometries.set(node.id, geometry);
|
|
448
463
|
const subtitle = !runtimeMode && supportsNodeSubtitle(definition)
|
|
449
|
-
? resolveNodeSubtitle({ node, definition, model, mode: definitionMode, surface: 'svg-export', resolver: context.nodeSubtitleResolver })
|
|
464
|
+
? resolveNodeSubtitle({ node, definition, model, mode: definitionMode, surface: 'svg-export', resolver: context.nodeSubtitleResolver, i18n })
|
|
450
465
|
: undefined;
|
|
451
|
-
renderDefaultNode({ document, group, node, definition, geometry, visual, presentation: nodePresentation, subtitle, theme, iconRegistry });
|
|
466
|
+
renderDefaultNode({ document, group, node, definition, geometry, visual, presentation: nodePresentation, subtitle, theme, iconRegistry, i18n });
|
|
452
467
|
}
|
|
453
468
|
nodeLayer.appendChild(group);
|
|
454
469
|
}
|
|
@@ -458,10 +473,11 @@ function prepareNodes({ document, context, options, model, presentation, theme,
|
|
|
458
473
|
export async function exportDiagramSvg(context = {}, options = {}) {
|
|
459
474
|
options.signal?.throwIfAborted?.();
|
|
460
475
|
const document = resolvedDocument(context);
|
|
476
|
+
const i18n = resolveExportI18n(context, options);
|
|
461
477
|
const model = context.model || { id: 'Process', name: 'BPMN Nova', nodes: [], edges: [], settings: {} };
|
|
462
478
|
const theme = themeSnapshot(context, options);
|
|
463
|
-
const appearance = context.runtimeAppearance?.resolveStatus ? context.runtimeAppearance : createRuntimeAppearance(context.runtimeAppearance || {});
|
|
464
|
-
const presentation = context.runtimePresentation || createRuntimePresentation({ model, runtime: context.runtime || null, appearance });
|
|
479
|
+
const appearance = context.runtimeAppearance?.resolveStatus ? context.runtimeAppearance : createRuntimeAppearance(context.runtimeAppearance || {}, { i18n });
|
|
480
|
+
const presentation = context.runtimePresentation || createRuntimePresentation({ model, runtime: context.runtime || null, appearance, i18n });
|
|
465
481
|
const iconRegistry = context.iconRegistry || createDefaultIconRegistry();
|
|
466
482
|
const warnings = [];
|
|
467
483
|
const bounds = { left: Infinity, top: Infinity, right: -Infinity, bottom: -Infinity };
|
|
@@ -490,7 +506,7 @@ export async function exportDiagramSvg(context = {}, options = {}) {
|
|
|
490
506
|
addDefinitions(document, svg, theme);
|
|
491
507
|
|
|
492
508
|
// Resolve custom renderers once before docking edges, without changing the final layer order.
|
|
493
|
-
const { nodeLayer, geometries } = prepareNodes({ document, context, options, model, presentation, theme, iconRegistry, warnings });
|
|
509
|
+
const { nodeLayer, geometries } = prepareNodes({ document, context, options, model, presentation, theme, iconRegistry, warnings, i18n });
|
|
494
510
|
|
|
495
511
|
const edgeLayer = svgElement(document, 'g', { 'data-layer': 'edges' });
|
|
496
512
|
for (const edge of model.edges || []) {
|
|
@@ -534,7 +550,7 @@ export async function exportDiagramSvg(context = {}, options = {}) {
|
|
|
534
550
|
const transitionTone = tone(theme, toneName);
|
|
535
551
|
const markerTone = Object.hasOwn(theme.tones || {}, toneName) && /^[a-z][a-z0-9-]{0,47}$/.test(toneName) ? toneName : 'neutral';
|
|
536
552
|
transitionLayer.appendChild(svgElement(document, 'path', { d: routePath(display.points, model.settings?.edgeStyle || 'rounded', model.settings?.cornerRadius || 14), fill: 'none', stroke: transitionTone.strong, 'stroke-width': 2.2, 'stroke-dasharray': '8 6', 'stroke-linecap': 'round', 'stroke-linejoin': 'round', 'marker-end': `url(#nova-arrow-${markerTone}${display.targetDocked ? '-docked' : ''})`, opacity: transition.latest ? 1 : 0.42 }));
|
|
537
|
-
const label = transition.label || (transition.type === 'reject' ? '
|
|
553
|
+
const label = transition.label || i18n.t(transition.type === 'reject' ? 'runtime.transitions.reject' : 'runtime.transitions.return');
|
|
538
554
|
const labelTypography = { fontSize: 11, fontWeight: 650, fontFamily: theme.fontFamily };
|
|
539
555
|
const labelWidth = Math.max(68, Math.min(210, Math.ceil(measureText(document, label, labelTypography) + 20)));
|
|
540
556
|
const fittedLabel = fitText(document, label, labelWidth - 16, labelTypography);
|
|
@@ -548,11 +564,12 @@ export async function exportDiagramSvg(context = {}, options = {}) {
|
|
|
548
564
|
}
|
|
549
565
|
|
|
550
566
|
svg.appendChild(nodeLayer);
|
|
551
|
-
const
|
|
567
|
+
const defaultLabel = i18n.t(context.mode === 'instance' ? 'exportSvg.defaultLabels.instance' : context.mode === 'viewer' ? 'exportSvg.defaultLabels.viewer' : 'exportSvg.defaultLabels.design');
|
|
568
|
+
const filename = sanitizeSvgFilename(options.filename || `${model.name || model.id || 'process'}-${context.label || defaultLabel}`);
|
|
552
569
|
return serializeArtifact(document, svg, { filename, width, height, viewBox: { x: minX, y: minY, width, height }, warnings });
|
|
553
570
|
}
|
|
554
571
|
|
|
555
|
-
async function resolvedImageData(asset, action, context, warnings, signal) {
|
|
572
|
+
async function resolvedImageData(asset, action, context, warnings, signal, i18n = DEFAULT_I18N) {
|
|
556
573
|
const cache = context.assetCache || new Map();
|
|
557
574
|
const key = `${asset.id}:export`;
|
|
558
575
|
const cached = cache.get(key);
|
|
@@ -583,7 +600,7 @@ async function resolvedImageData(asset, action, context, warnings, signal) {
|
|
|
583
600
|
} catch (error) {
|
|
584
601
|
cache.delete(key);
|
|
585
602
|
if (signal?.aborted) throw error;
|
|
586
|
-
warnings.push({ code: 'asset-unavailable', message:
|
|
603
|
+
warnings.push({ code: 'asset-unavailable', message: i18n.t('exportSvg.warnings.assetUnavailable', { name: asset.name }), assetId: asset.id, elementId: action.elementId });
|
|
587
604
|
return null;
|
|
588
605
|
}
|
|
589
606
|
}
|
|
@@ -602,7 +619,7 @@ function participantInitial(participant) {
|
|
|
602
619
|
return String(participant?.name || '').trim().slice(0, 1) || '?';
|
|
603
620
|
}
|
|
604
621
|
|
|
605
|
-
async function resolvedAvatarData(url, context, warnings, signal, item) {
|
|
622
|
+
async function resolvedAvatarData(url, context, warnings, signal, item, i18n = DEFAULT_I18N) {
|
|
606
623
|
const source = String(url || '').trim();
|
|
607
624
|
if (!source) return null;
|
|
608
625
|
const cache = context.avatarCache || (context.avatarCache = new Map());
|
|
@@ -630,12 +647,12 @@ async function resolvedAvatarData(url, context, warnings, signal, item) {
|
|
|
630
647
|
} catch (error) {
|
|
631
648
|
cache.delete(source);
|
|
632
649
|
if (signal?.aborted) throw error;
|
|
633
|
-
warnings.push({ code: 'avatar-unavailable', message: '
|
|
650
|
+
warnings.push({ code: 'avatar-unavailable', message: i18n.t('exportSvg.warnings.avatarUnavailable'), elementId: item?.elementId });
|
|
634
651
|
return null;
|
|
635
652
|
}
|
|
636
653
|
}
|
|
637
654
|
|
|
638
|
-
async function renderTimelineAvatars({ document, parent, people, x, y, theme, context, warnings, signal, item }) {
|
|
655
|
+
async function renderTimelineAvatars({ document, parent, people, x, y, theme, context, warnings, signal, item, i18n = DEFAULT_I18N }) {
|
|
639
656
|
const visible = people.slice(0, AVATAR_VISIBLE_LIMIT);
|
|
640
657
|
const overflow = people.length - AVATAR_VISIBLE_LIMIT;
|
|
641
658
|
const count = visible.length + (overflow > 0 ? 1 : 0);
|
|
@@ -645,7 +662,7 @@ async function renderTimelineAvatars({ document, parent, people, x, y, theme, co
|
|
|
645
662
|
const cx = left + AVATAR_SIZE / 2;
|
|
646
663
|
const cy = y + AVATAR_SIZE / 2;
|
|
647
664
|
const person = visible[index];
|
|
648
|
-
const data = await resolvedAvatarData(person.avatarUrl, context, warnings, signal, item);
|
|
665
|
+
const data = await resolvedAvatarData(person.avatarUrl, context, warnings, signal, item, i18n);
|
|
649
666
|
parent.appendChild(svgElement(document, 'circle', {
|
|
650
667
|
cx, cy, r: AVATAR_SIZE / 2, fill: theme.colors.primarySoft, stroke: theme.colors.surface, 'stroke-width': 2,
|
|
651
668
|
}));
|
|
@@ -694,18 +711,19 @@ function actionHeight(action) {
|
|
|
694
711
|
return 52 + targets + Math.max(1, blockParagraphs || paragraphLines) * 17 + (images ? 68 : 0) + files * 40;
|
|
695
712
|
}
|
|
696
713
|
|
|
697
|
-
async function renderTimelineAction({ document, parent, action, x, y, width, theme, appearance, context, warnings, signal }) {
|
|
714
|
+
async function renderTimelineAction({ document, parent, action, x, y, width, theme, appearance, context, warnings, signal, i18n = DEFAULT_I18N, timeConfig = null }) {
|
|
698
715
|
const actionAppearance = appearance.resolveAction(action);
|
|
699
716
|
const actionTone = tone(theme, actionAppearance.tone);
|
|
700
717
|
const height = actionHeight(action);
|
|
701
718
|
parent.appendChild(svgElement(document, 'rect', { x, y, width, height, rx: 9, fill: theme.colors.surfaceSubtle }));
|
|
702
|
-
const
|
|
719
|
+
const labelTypography = { fontSize: 11, fontWeight: 650, fontFamily: theme.fontFamily };
|
|
720
|
+
const labelWidth = Math.max(42, Math.min(132, Math.ceil(measureText(document, actionAppearance.label, labelTypography) + 20)));
|
|
703
721
|
parent.appendChild(svgElement(document, 'rect', { x: x + 12, y: y + 10, width: labelWidth, height: 22, rx: 11, fill: actionTone.background }));
|
|
704
722
|
parent.appendChild(svgElement(document, 'text', { x: x + 12 + labelWidth / 2, y: y + 25, 'text-anchor': 'middle', fill: actionTone.foreground, 'font-size': 11, 'font-weight': 650, 'font-family': theme.fontFamily }, actionAppearance.label));
|
|
705
|
-
parent.appendChild(svgElement(document, 'text', { x: x + 22 + labelWidth, y: y + 25, fill: theme.colors.textMuted, 'font-size': 11, 'font-family': theme.fontFamily }, [action.actor?.name, formatTime(action.occurredAt)].filter(Boolean).join(' · ')));
|
|
723
|
+
parent.appendChild(svgElement(document, 'text', { x: x + 22 + labelWidth, y: y + 25, fill: theme.colors.textMuted, 'font-size': 11, 'font-family': theme.fontFamily }, [action.actor?.name, formatTime(action.occurredAt, 'occurred', timeConfig)].filter(Boolean).join(' · ')));
|
|
706
724
|
let cursorY = y + 48;
|
|
707
725
|
if (action.targets?.length) {
|
|
708
|
-
parent.appendChild(svgElement(document, 'text', { x: x + 12, y: cursorY, fill: theme.colors.textSecondary, 'font-size': 11, 'font-family': theme.fontFamily },
|
|
726
|
+
parent.appendChild(svgElement(document, 'text', { x: x + 12, y: cursorY, fill: theme.colors.textSecondary, 'font-size': 11, 'font-family': theme.fontFamily }, i18n.t('timeline.targets', { names: action.targets.map((item) => item.name).join(i18n.t('common.listSeparator')) })));
|
|
709
727
|
cursorY += 18;
|
|
710
728
|
}
|
|
711
729
|
const paragraphBlocks = (action.content?.blocks || []).filter((block) => block.type === 'paragraph' && block.text);
|
|
@@ -723,10 +741,10 @@ async function renderTimelineAction({ document, parent, action, x, y, width, the
|
|
|
723
741
|
for (const block of imageBlocks) {
|
|
724
742
|
const asset = assets.get(block.assetId);
|
|
725
743
|
if (!asset || !asset.mediaType?.startsWith('image/')) {
|
|
726
|
-
warnings.push({ code: 'asset-invalid', message: '
|
|
744
|
+
warnings.push({ code: 'asset-invalid', message: i18n.t('exportSvg.warnings.assetInvalid'), assetId: block.assetId, elementId: action.elementId });
|
|
727
745
|
parent.appendChild(svgElement(document, 'rect', { x: mediaX, y: cursorY, width: 88, height: 58, rx: 7, fill: theme.colors.surfaceMuted, stroke: theme.colors.border }));
|
|
728
746
|
} else {
|
|
729
|
-
const data = await resolvedImageData(asset, action, context, warnings, signal);
|
|
747
|
+
const data = await resolvedImageData(asset, action, context, warnings, signal, i18n);
|
|
730
748
|
if (data) parent.appendChild(svgElement(document, 'image', { x: mediaX, y: cursorY, width: 88, height: 58, preserveAspectRatio: 'xMidYMid slice', href: data }));
|
|
731
749
|
else parent.appendChild(svgElement(document, 'rect', { x: mediaX, y: cursorY, width: 88, height: 58, rx: 7, fill: theme.colors.surfaceMuted, stroke: theme.colors.border }));
|
|
732
750
|
}
|
|
@@ -737,18 +755,34 @@ async function renderTimelineAction({ document, parent, action, x, y, width, the
|
|
|
737
755
|
const asset = assets.get(block.assetId);
|
|
738
756
|
const fileY = cursorY;
|
|
739
757
|
parent.appendChild(svgElement(document, 'rect', { x: x + 12, y: fileY, width: width - 24, height: 34, rx: 7, fill: theme.colors.surfaceRaised, stroke: theme.colors.border }));
|
|
740
|
-
parent.appendChild(svgElement(document, 'text', { x: x + 22, y: fileY + 15, fill: theme.colors.textSecondary, 'font-size': 11, 'font-weight': 600, 'font-family': theme.fontFamily }, asset?.name || '
|
|
758
|
+
parent.appendChild(svgElement(document, 'text', { x: x + 22, y: fileY + 15, fill: theme.colors.textSecondary, 'font-size': 11, 'font-weight': 600, 'font-family': theme.fontFamily }, asset?.name || i18n.t('exportSvg.fileUnavailable')));
|
|
741
759
|
parent.appendChild(svgElement(document, 'text', { x: x + 22, y: fileY + 28, fill: theme.colors.textMuted, 'font-size': 9.5, 'font-family': theme.fontFamily }, asset ? [asset.mediaType, formatSize(asset.size)].filter(Boolean).join(' · ') : ''));
|
|
742
760
|
cursorY += 40;
|
|
743
761
|
}
|
|
744
762
|
return height;
|
|
745
763
|
}
|
|
746
764
|
|
|
747
|
-
|
|
748
|
-
|
|
765
|
+
const TIMELINE_RESULT_KEYS = Object.freeze({
|
|
766
|
+
approved: 'timeline.results.approved',
|
|
767
|
+
rejected: 'timeline.results.rejected',
|
|
768
|
+
returned: 'timeline.results.returned',
|
|
769
|
+
submitted: 'timeline.results.submitted',
|
|
770
|
+
pending: 'timeline.results.pending',
|
|
771
|
+
});
|
|
772
|
+
|
|
773
|
+
function resultLabel(item, i18n = DEFAULT_I18N) {
|
|
774
|
+
const key = TIMELINE_RESULT_KEYS[item.outcome];
|
|
775
|
+
return (key ? i18n.t(key) : '') || item.statusLabel || '';
|
|
749
776
|
}
|
|
750
777
|
|
|
751
|
-
|
|
778
|
+
function timelineItemTimeField(item) {
|
|
779
|
+
if (item?.timeField) return item.timeField;
|
|
780
|
+
if (item?.kind === 'transition') return 'occurred';
|
|
781
|
+
if (item?.status === 'active') return 'start';
|
|
782
|
+
return 'end';
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
async function renderTimelineItem({ document, parent, item, x, y, width, theme, appearance, context, warnings, signal, i18n = DEFAULT_I18N, timeConfig = null }) {
|
|
752
786
|
const itemTone = tone(theme, appearance.resolveStatus(item.status));
|
|
753
787
|
const actions = item.actions || [];
|
|
754
788
|
const actionTotal = actions.reduce((sum, action) => sum + actionHeight(action) + 8, 0);
|
|
@@ -763,17 +797,17 @@ async function renderTimelineItem({ document, parent, item, x, y, width, theme,
|
|
|
763
797
|
let textX = contentX;
|
|
764
798
|
if (people.length) {
|
|
765
799
|
const stackWidth = await renderTimelineAvatars({
|
|
766
|
-
document, parent, people, x: contentX, y: y + 6, theme, context, warnings, signal, item,
|
|
800
|
+
document, parent, people, x: contentX, y: y + 6, theme, context, warnings, signal, item, i18n,
|
|
767
801
|
});
|
|
768
802
|
textX = contentX + stackWidth + 8;
|
|
769
803
|
}
|
|
770
|
-
parent.appendChild(svgElement(document, 'text', { x: textX, y: y + 20, fill: theme.colors.text, 'font-size': 15, 'font-weight': 650, 'font-family': theme.fontFamily }, `${item.name}${item.round > 1 ? `
|
|
771
|
-
parent.appendChild(svgElement(document, 'text', { x: contentX + contentWidth, y: y + 20, 'text-anchor': 'end', fill: itemTone.foreground, 'font-size': 12, 'font-weight': 600, 'font-family': theme.fontFamily }, resultLabel(item)));
|
|
804
|
+
parent.appendChild(svgElement(document, 'text', { x: textX, y: y + 20, fill: theme.colors.text, 'font-size': 15, 'font-weight': 650, 'font-family': theme.fontFamily }, `${item.name}${item.round > 1 ? ` ${i18n.t('timeline.round', { round: item.round })}` : ''}`));
|
|
805
|
+
parent.appendChild(svgElement(document, 'text', { x: contentX + contentWidth, y: y + 20, 'text-anchor': 'end', fill: itemTone.foreground, 'font-size': 12, 'font-weight': 600, 'font-family': theme.fontFamily }, resultLabel(item, i18n)));
|
|
772
806
|
parent.appendChild(svgElement(document, 'text', { x: textX, y: y + 42, fill: theme.colors.textSecondary, 'font-size': 11.5, 'font-family': theme.fontFamily }, item.summary || ''));
|
|
773
|
-
parent.appendChild(svgElement(document, 'text', { x: contentX + contentWidth, y: y + 42, 'text-anchor': 'end', fill: theme.colors.textMuted, 'font-size': 11, 'font-family': theme.fontFamily }, formatTime(item.time)));
|
|
807
|
+
parent.appendChild(svgElement(document, 'text', { x: contentX + contentWidth, y: y + 42, 'text-anchor': 'end', fill: theme.colors.textMuted, 'font-size': 11, 'font-family': theme.fontFamily }, formatTime(item.time, timelineItemTimeField(item), timeConfig)));
|
|
774
808
|
let actionY = y + 56;
|
|
775
809
|
for (const action of actions) {
|
|
776
|
-
const actionHeightValue = await renderTimelineAction({ document, parent, action, x: contentX, y: actionY, width: contentWidth, theme, appearance, context, warnings, signal });
|
|
810
|
+
const actionHeightValue = await renderTimelineAction({ document, parent, action, x: contentX, y: actionY, width: contentWidth, theme, appearance, context, warnings, signal, i18n, timeConfig });
|
|
777
811
|
actionY += actionHeightValue + 8;
|
|
778
812
|
}
|
|
779
813
|
return height;
|
|
@@ -782,14 +816,20 @@ async function renderTimelineItem({ document, parent, item, x, y, width, theme,
|
|
|
782
816
|
export async function exportRuntimeTimelineSvg(context = {}, options = {}) {
|
|
783
817
|
options.signal?.throwIfAborted?.();
|
|
784
818
|
const document = resolvedDocument(context);
|
|
819
|
+
const i18n = resolveExportI18n(context, options);
|
|
820
|
+
const timeConfig = {
|
|
821
|
+
formatRuntimeTime: options.formatRuntimeTime ?? context.formatRuntimeTime ?? null,
|
|
822
|
+
runtimeTimeFormat: options.runtimeTimeFormat ?? context.runtimeTimeFormat ?? null,
|
|
823
|
+
locale: i18n.locale,
|
|
824
|
+
};
|
|
785
825
|
const projection = context.projection || { items: [], groups: [], links: [] };
|
|
786
826
|
const theme = themeSnapshot(context, options);
|
|
787
|
-
const appearance = context.runtimeAppearance?.resolveStatus ? context.runtimeAppearance : createRuntimeAppearance(context.runtimeAppearance || {});
|
|
827
|
+
const appearance = context.runtimeAppearance?.resolveStatus ? context.runtimeAppearance : createRuntimeAppearance(context.runtimeAppearance || {}, { i18n });
|
|
788
828
|
const warnings = [];
|
|
789
829
|
const width = Math.max(640, finite(options.width, 960));
|
|
790
830
|
const padding = Math.max(0, finite(options.padding, DEFAULT_PADDING));
|
|
791
|
-
const title = options.title ?? context.title ?? context.model?.name ?? '
|
|
792
|
-
const description = options.description ?? context.description ?? '
|
|
831
|
+
const title = options.title ?? context.title ?? context.model?.name ?? i18n.t('timeline.defaultTitle');
|
|
832
|
+
const description = options.description ?? context.description ?? i18n.t('timeline.defaultDescription');
|
|
793
833
|
const sequence = timelineSequence(projection);
|
|
794
834
|
const contentHeight = sequence.reduce((sum, entry) => {
|
|
795
835
|
if (entry.kind === 'parallel-group') {
|
|
@@ -800,7 +840,7 @@ export async function exportRuntimeTimelineSvg(context = {}, options = {}) {
|
|
|
800
840
|
}, 0);
|
|
801
841
|
const headerHeight = title || description ? 74 : 0;
|
|
802
842
|
const height = Math.max(240, padding * 2 + headerHeight + contentHeight);
|
|
803
|
-
const svg = createRoot(document, { minX: 0, minY: 0, width, height, title: title || '
|
|
843
|
+
const svg = createRoot(document, { minX: 0, minY: 0, width, height, title: title || i18n.t('timeline.defaultTitle'), theme, transparentBackground: options.transparentBackground === true });
|
|
804
844
|
addDefinitions(document, svg, theme);
|
|
805
845
|
const root = svgElement(document, 'g', { 'data-layer': 'runtime-timeline' });
|
|
806
846
|
if (title) root.appendChild(svgElement(document, 'text', { x: padding, y: padding + 20, fill: theme.colors.text, 'font-size': 20, 'font-weight': 700, 'font-family': theme.fontFamily }, title));
|
|
@@ -811,11 +851,23 @@ export async function exportRuntimeTimelineSvg(context = {}, options = {}) {
|
|
|
811
851
|
if (typeof customRenderer === 'function') {
|
|
812
852
|
const customLayer = svgElement(document, 'g', { 'data-layer': 'custom-runtime-timeline' });
|
|
813
853
|
try {
|
|
814
|
-
const result = await customRenderer({
|
|
854
|
+
const result = await customRenderer({
|
|
855
|
+
container: customLayer,
|
|
856
|
+
document,
|
|
857
|
+
projection,
|
|
858
|
+
model: context.model,
|
|
859
|
+
runtime: context.runtime,
|
|
860
|
+
themeSnapshot: theme,
|
|
861
|
+
appearance,
|
|
862
|
+
resolveAsset: context.resolveAsset,
|
|
863
|
+
formatTime: (value, field = 'occurred') => formatTime(value, field, timeConfig),
|
|
864
|
+
i18n,
|
|
865
|
+
signal: options.signal,
|
|
866
|
+
});
|
|
815
867
|
if (result?.height) customHeight = Math.max(0, finite(result.height));
|
|
816
868
|
root.appendChild(customLayer);
|
|
817
869
|
} catch (error) {
|
|
818
|
-
warnings.push({ code: 'custom-timeline-renderer-failed', message: '
|
|
870
|
+
warnings.push({ code: 'custom-timeline-renderer-failed', message: i18n.t('exportSvg.warnings.customTimelineRendererFailed') });
|
|
819
871
|
}
|
|
820
872
|
}
|
|
821
873
|
if (!customRenderer || warnings.some((warning) => warning.code === 'custom-timeline-renderer-failed')) {
|
|
@@ -824,12 +876,12 @@ export async function exportRuntimeTimelineSvg(context = {}, options = {}) {
|
|
|
824
876
|
if (entry.kind === 'parallel-group') {
|
|
825
877
|
const groupTone = tone(theme, appearance.resolveStatus(entry.status));
|
|
826
878
|
root.appendChild(svgElement(document, 'rect', { x: padding, y, width: width - padding * 2, height: 36, rx: 8, fill: theme.colors.surfaceSubtle }));
|
|
827
|
-
root.appendChild(svgElement(document, 'text', { x: padding + 14, y: y + 23, fill: groupTone.foreground, 'font-size': 13, 'font-weight': 650, 'font-family': theme.fontFamily },
|
|
879
|
+
root.appendChild(svgElement(document, 'text', { x: padding + 14, y: y + 23, fill: groupTone.foreground, 'font-size': 13, 'font-weight': 650, 'font-family': theme.fontFamily }, i18n.t('timeline.parallelSvgHeader', { label: entry.label, completed: entry.completed, total: entry.total })));
|
|
828
880
|
y += 50;
|
|
829
881
|
const children = (entry.itemIds || []).map((id) => projection.items.find((item) => item.id === id)).filter(Boolean).sort((a, b) => a.order - b.order);
|
|
830
|
-
for (const child of children) y += await renderTimelineItem({ document, parent: root, item: child, x: padding + 18, y, width: width - padding * 2 - 18, theme, appearance, context, warnings, signal: options.signal }) + 16;
|
|
882
|
+
for (const child of children) y += await renderTimelineItem({ document, parent: root, item: child, x: padding + 18, y, width: width - padding * 2 - 18, theme, appearance, context, warnings, signal: options.signal, i18n, timeConfig }) + 16;
|
|
831
883
|
} else {
|
|
832
|
-
y += await renderTimelineItem({ document, parent: root, item: entry, x: padding, y, width: width - padding * 2, theme, appearance, context, warnings, signal: options.signal }) + 16;
|
|
884
|
+
y += await renderTimelineItem({ document, parent: root, item: entry, x: padding, y, width: width - padding * 2, theme, appearance, context, warnings, signal: options.signal, i18n, timeConfig }) + 16;
|
|
833
885
|
}
|
|
834
886
|
}
|
|
835
887
|
}
|
|
@@ -839,7 +891,7 @@ export async function exportRuntimeTimelineSvg(context = {}, options = {}) {
|
|
|
839
891
|
svg.setAttribute('viewBox', `0 0 ${width} ${actualHeight}`);
|
|
840
892
|
const background = svg.querySelector(':scope > rect');
|
|
841
893
|
if (background) background.setAttribute('height', String(actualHeight));
|
|
842
|
-
const filename = sanitizeSvgFilename(options.filename || `${context.model?.name || 'process'}-${context.label || '
|
|
894
|
+
const filename = sanitizeSvgFilename(options.filename || `${context.model?.name || 'process'}-${context.label || i18n.t('exportSvg.defaultLabels.timeline')}`);
|
|
843
895
|
return serializeArtifact(document, svg, { filename, width, height: actualHeight, viewBox: { x: 0, y: 0, width, height: actualHeight }, warnings });
|
|
844
896
|
}
|
|
845
897
|
|