@sccharts-lab/diagram 0.0.0-stage → 0.1.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.
Files changed (44) hide show
  1. package/LICENSE +277 -0
  2. package/README.md +169 -2
  3. package/dist/dataflow.d.ts +18 -0
  4. package/dist/dataflow.js +216 -0
  5. package/dist/dataflow.js.map +1 -0
  6. package/dist/diagram.css +521 -0
  7. package/dist/elk-types.d.ts +50 -0
  8. package/dist/elk-types.js +5 -0
  9. package/dist/elk-types.js.map +1 -0
  10. package/dist/elk-worker.d.ts +10 -0
  11. package/dist/elk-worker.js +18 -0
  12. package/dist/elk-worker.js.map +1 -0
  13. package/dist/font-metrics.d.ts +13 -0
  14. package/dist/font-metrics.js +23 -0
  15. package/dist/font-metrics.js.map +1 -0
  16. package/dist/fonts/atkinson-hyperlegible-mono-latin-ext-wght-normal.woff2 +0 -0
  17. package/dist/fonts/atkinson-hyperlegible-mono-latin-wght-normal.woff2 +0 -0
  18. package/dist/fonts/atkinson-hyperlegible-mono.LICENSE.txt +93 -0
  19. package/dist/fonts/atkinson-hyperlegible-next-latin-ext-wght-normal.woff2 +0 -0
  20. package/dist/fonts/atkinson-hyperlegible-next-latin-wght-normal.woff2 +0 -0
  21. package/dist/fonts/atkinson-hyperlegible-next.LICENSE.txt +93 -0
  22. package/dist/fonts.css +42 -0
  23. package/dist/geometry.d.ts +24 -0
  24. package/dist/geometry.js +115 -0
  25. package/dist/geometry.js.map +1 -0
  26. package/dist/highlight.d.ts +35 -0
  27. package/dist/highlight.js +83 -0
  28. package/dist/highlight.js.map +1 -0
  29. package/dist/index.d.ts +16 -0
  30. package/dist/index.js +32 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/layout.d.ts +6 -0
  33. package/dist/layout.js +838 -0
  34. package/dist/layout.js.map +1 -0
  35. package/dist/measure.d.ts +23 -0
  36. package/dist/measure.js +73 -0
  37. package/dist/measure.js.map +1 -0
  38. package/dist/render.d.ts +3 -0
  39. package/dist/render.js +327 -0
  40. package/dist/render.js.map +1 -0
  41. package/dist/types.d.ts +221 -0
  42. package/dist/types.js +4 -0
  43. package/dist/types.js.map +1 -0
  44. package/package.json +70 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,wDAAwD","sourcesContent":["// The diagram's data: options and the laid-out diagram that renderSvg draws. Plain JSON, so a layout can be\n// computed in a Web Worker or at build time and cached.\n\nimport type { ElkNode } from './elk-types'\nimport type { FormatContext, TextFormat } from '@sccharts-lab/engine/format'\nimport type { Program, Span, State } from '@sccharts-lab/engine/types'\nimport type { TextMeasurer } from './measure'\n\nexport interface Point {\n x: number\n y: number\n}\n\nexport interface Box {\n x: number\n y: number\n width: number\n height: number\n}\n\n/** A run of text on a line, `dx` from the line's start. Keywords are bold and coloured. */\nexport interface TextRun {\n text: string\n dx: number\n width: number\n format: TextFormat\n}\n\nexport type TextRole = 'title' | 'state-label' | 'declaration' | 'action' | 'region-label' | 'edge-label' | 'equation' | 'comment'\n\n/** One line of text. Coordinates are absolute: `x` is the left end, `y` the baseline. */\nexport interface TextLine {\n x: number\n y: number\n width: number\n /** Font size in diagram units. */\n size: number\n /** The whole line is bold (state names, transition labels). Keyword runs are bold anyway. */\n bold?: boolean\n mono?: boolean\n runs: TextRun[]\n role: TextRole\n /** Model elements the line shows: the action's id, or the ids of a declaration's valued objects. */\n ids?: string[]\n}\n\nexport type StateShape = 'root' | 'superstate' | 'simple' | 'connector'\n\nexport interface StateLayout extends Box {\n kind: 'state'\n id: string\n name: string\n shape: StateShape\n initial: boolean\n final: boolean\n violation: boolean\n /** `state S is Other(...)`. */\n reference: boolean\n /** Corner radius of the outer figure. */\n radius: number\n /** Border width of the outer figure: 1, or 3 for an initial state. */\n lineWidth: number\n /** Final states (and violation states that cannot be left): distance between the outer and the inner\n * border. */\n finalInset?: number\n /** The name (simple states) or the title row and the declaration and action lines (superstates). */\n lines: TextLine[]\n regions: RegionLayout[]\n comments: CommentLayout[]\n span?: Span\n}\n\nexport interface RegionLayout extends Box {\n kind: 'region'\n id: string\n name?: string\n dataflow: boolean\n /** Drawn as a closed box with only its label (`@collapse`, or the region of a reference state). */\n collapsed: boolean\n final: boolean\n abort: boolean\n override: boolean\n /** `region R is Other(...)`: drawn collapsed with KIELER's reference style. */\n reference?: boolean\n /** A control-flow region without states: KIELER draws a bare frame, without label or button. */\n empty?: boolean\n /** A method of the state, drawn as KIELER does: a collapsed grey region labelled with the signature (its\n * id is the method's valued object id). 'abstract' when it has no body. */\n method?: 'implemented' | 'abstract'\n /** ELK layout direction of the region's states. */\n direction: 'RIGHT' | 'DOWN' | 'LEFT' | 'UP'\n label?: TextLine\n /** Region-level declarations and actions; for a dataflow region drawn as a list, its equations. */\n lines: TextLine[]\n states: StateLayout[]\n transitions: TransitionLayout[]\n /** Dataflow regions drawn as a circuit. */\n circuit?: DataflowLayout\n comments: CommentLayout[]\n span?: Span\n}\n\nexport type LabelDirection = 'right' | 'left' | 'down' | 'up'\n\nexport interface TransitionLabelLayout extends Box {\n lines: TextLine[]\n /** Direction of the edge at the label, for KIELER's on-edge label decoration. */\n direction: LabelDirection\n}\n\nexport interface TransitionLayout {\n kind: 'transition'\n id: string\n source: string\n target: string\n priority: number\n /** ELK's routing points: start, cubic Bézier control points, end (1 + 3k points when splines are used). */\n points: Point[]\n immediate: boolean\n preemption: 'weak' | 'strong' | 'termination'\n history?: 'shallow' | 'deep'\n deferred?: 'shallow' | 'deep'\n nondeterministic?: boolean\n probability?: number\n label?: TransitionLabelLayout\n /** The transition's doc comments, each an extra label stacked in front of the main one (KIELER's\n * \"Comment Nodes\" option). */\n comments?: TransitionLabelLayout[]\n span?: Span\n}\n\nexport interface CommentLayout extends Box {\n id: string\n lines: TextLine[]\n /** Connection from the element it documents to the comment (a state's comments; a region's have none). */\n points?: Point[]\n}\n\n/** A dataflow region as a small circuit: inputs, operators and outputs joined by wires. */\nexport interface DataflowLayout {\n nodes: DataflowNodeLayout[]\n wires: { id: string; points: Point[] }[]\n}\n\nexport interface DataflowNodeLayout extends Box {\n id: string\n kind: 'input' | 'output' | 'operator' | 'constant' | 'actor'\n text: string\n lines: TextLine[]\n}\n\nexport interface DiagramLayout {\n /** Bumped when the shape of this data changes. */\n version: 1\n /** Id (and name) of the chart. */\n chart: string\n width: number\n height: number\n root: StateLayout\n /** The direction setting the layout was made with. */\n direction: LayoutDirection\n /** `@diagram[shadows] false` on the chart: renderSvg draws no shadows unless told otherwise. */\n shadows?: false\n}\n\nexport type LayoutDirection = 'HV' | 'VH' | 'down' | 'right'\n\n/** What `layoutChart` needs from ELK: elkjs's `ELK` instance, possibly backed by a Web Worker. */\nexport interface ElkLike {\n layout(graph: ElkNode): Promise<ElkNode>\n}\n\nexport interface LayoutOptions {\n /** The ELK instance: elkjs's `ELK`, e.g. `new ELK({ workerFactory })` from `elkjs/lib/elk-api.js` to lay out in a Web\n * Worker. `layoutChart` from `@sccharts-lab/diagram` defaults to a shared `elkjs/lib/elk.bundled.js` instance (on\n * the calling thread, loaded on first use); the one from `@sccharts-lab/diagram/layout` needs it, so a bundle that\n * only imports that never contains the 1.4 MB bundled build. */\n elk?: ElkLike\n /** Text measurement. Default: the generated width table of the diagram font (identical in Node and the\n * browser). */\n measure?: TextMeasurer\n /** The program the chart belongs to: its other charts give referenced instances in dataflow regions their\n * ports, and its declarations and pragmas the formatter's context. */\n program?: Program\n /** Charts of other files (`import`ed), for references to them (e.g. `compile(...).index.programs`' charts).\n * `program`'s own charts come first. */\n charts?: State[]\n /** Declaration lookup and symbol table for the formatter. Default: built from `program`, or from the chart\n * itself. */\n format?: FormatContext\n /** KIELER's \"User Labels\": show `label \"...\"` instead of trigger and effects. Default true. */\n userLabels?: boolean\n /** KIELER's \"Comment Nodes\": `/** doc comments *\\/` of the chart, states and regions as comment boxes, those of\n * transitions as extra labels. Default true (as in KIELER). */\n comments?: boolean\n /** Show declarations. Default true. */\n declarations?: boolean\n /** Show entry/during/exit/suspend actions. Default true. */\n actions?: boolean\n /** Layout direction: 'HV' (KIELER's default: top level left to right, alternating with depth), 'VH',\n * 'down' or 'right'. */\n direction?: LayoutDirection\n /** Soft-wrap width of transition label lines (KIELER: 200). 0 disables wrapping. */\n labelWidth?: number\n /** Region ids to draw collapsed, in addition to regions annotated `@collapse`. */\n collapsed?: Iterable<string>\n /** Reference states (`state S is Other(...)`): 'collapsed' (KIELER's initial view, default), 'expanded'\n * (the referenced chart drawn inside, needs `program`), or the ids of the reference states to expand.\n * Elements of an expanded chart get ids `<reference state id>/<id in the referenced chart>`. */\n references?: 'collapsed' | 'expanded' | Iterable<string>\n /** Draw dataflow regions as a circuit (true, default) or as a list of equations (false). */\n dataflowCircuit?: boolean\n}\n\nexport interface RenderOptions {\n /** How the SVG sizes itself: 'natural' (default: width 100%, at most the natural width), 'width'\n * (always fills the container's width), or 'none' (fixed natural size, for a scrolling frame). */\n fit?: 'natural' | 'width' | 'none'\n /** With fit 'natural' or 'width': never shrink below this fraction of the natural size (sets min-width), so\n * a wide chart scrolls inside an `overflow-x: auto` frame instead of becoming unreadable on a phone. */\n minScale?: number\n /** Natural size relative to diagram units. Default 1.25 (KIELER's 11 px names show at about 14 px). */\n scale?: number\n /** Prefix for ids inside the SVG (gradients). Default derived from the chart name. Must be unique\n * among different charts on one page. */\n idPrefix?: string\n /** Accessible name. Default \"SCChart <name>\". */\n title?: string\n /** Extra classes on the root <svg>. */\n className?: string\n /** Initial highlight classes per element id, e.g. { 'ABRO.WaitAB': ['is-active'] }. */\n classes?: Record<string, string[]>\n /** Draw the KIELER region \"collapse\" corner (default true). */\n regionCorner?: boolean\n /** Draw state shadows (default true). */\n shadows?: boolean\n /** CSS to embed in the SVG as a `<style>` element: diagram.css's text makes a standalone .svg file that looks the\n * same in any viewer. Leave it out for an SVG inside a page that loads diagram.css. */\n stylesheet?: string\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,73 @@
1
1
  {
2
2
  "name": "@sccharts-lab/diagram",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "SCCharts diagrams in KIELER's notation: ELK layout and SVG rendering for charts compiled with @sccharts-lab/engine, in Node and the browser",
5
+ "keywords": [
6
+ "sccharts",
7
+ "kieler",
8
+ "diagram",
9
+ "svg",
10
+ "elk",
11
+ "elkjs",
12
+ "graph-layout",
13
+ "statecharts",
14
+ "visualization"
15
+ ],
16
+ "homepage": "https://sccharts.jmw.nz",
17
+ "bugs": "https://github.com/Fallstop/sccharts-lab/issues",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/Fallstop/sccharts-lab.git",
21
+ "directory": "site/packages/diagram"
22
+ },
23
+ "license": "EPL-2.0 AND OFL-1.1",
24
+ "type": "module",
25
+ "sideEffects": [
26
+ "*.css"
27
+ ],
28
+ "engines": {
29
+ "node": ">=20"
30
+ },
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "default": "./dist/index.js"
35
+ },
36
+ "./layout": {
37
+ "types": "./dist/layout.d.ts",
38
+ "default": "./dist/layout.js"
39
+ },
40
+ "./render": {
41
+ "types": "./dist/render.d.ts",
42
+ "default": "./dist/render.js"
43
+ },
44
+ "./highlight": {
45
+ "types": "./dist/highlight.d.ts",
46
+ "default": "./dist/highlight.js"
47
+ },
48
+ "./types": {
49
+ "types": "./dist/types.d.ts",
50
+ "default": "./dist/types.js"
51
+ },
52
+ "./diagram.css": "./dist/diagram.css",
53
+ "./fonts.css": "./dist/fonts.css",
54
+ "./package.json": "./package.json"
55
+ },
56
+ "files": [
57
+ "dist"
58
+ ],
59
+ "dependencies": {
60
+ "elkjs": "0.12.0"
61
+ },
62
+ "peerDependencies": {
63
+ "@sccharts-lab/engine": "0.1.0"
64
+ },
65
+ "devDependencies": {
66
+ "@sccharts-lab/engine": "0.1.0"
67
+ },
68
+ "publishConfig": {
69
+ "access": "public"
70
+ },
71
+ "main": "./dist/index.js",
72
+ "types": "./dist/index.d.ts"
6
73
  }