@bpmnkit/core 0.2.0 → 0.3.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/dist/bpmn/bpmn-serializer.js +70 -0
- package/dist/bpmn/diagram-diff.d.ts +71 -0
- package/dist/bpmn/diagram-diff.js +124 -0
- package/dist/bpmn/lint.d.ts +97 -0
- package/dist/bpmn/lint.js +135 -0
- package/dist/bpmn/preserving-writer.d.ts +64 -0
- package/dist/bpmn/preserving-writer.js +70 -0
- package/dist/dmn/dmn-serializer.js +7 -2
- package/dist/dmn/preserving-writer.d.ts +31 -0
- package/dist/dmn/preserving-writer.js +36 -0
- package/dist/form/preserving-writer.d.ts +47 -0
- package/dist/form/preserving-writer.js +50 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.js +7 -1
- package/dist/json/index.d.ts +5 -0
- package/dist/json/index.js +3 -0
- package/dist/json/json-patch.d.ts +65 -0
- package/dist/json/json-patch.js +416 -0
- package/dist/json/json-spans.d.ts +48 -0
- package/dist/json/json-spans.js +153 -0
- package/dist/xml/index.d.ts +5 -1
- package/dist/xml/index.js +2 -0
- package/dist/xml/xml-parser.d.ts +39 -0
- package/dist/xml/xml-parser.js +43 -2
- package/dist/xml/xml-patch.d.ts +109 -0
- package/dist/xml/xml-patch.js +459 -0
- package/dist/xml/xml-spans.d.ts +45 -0
- package/dist/xml/xml-spans.js +74 -0
- package/package.json +1 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An XML document parsed into a tree that remembers where everything was.
|
|
3
|
+
*
|
|
4
|
+
* `parseXml` builds a clean tree with the source thrown away, which is right
|
|
5
|
+
* for everything that reads a document. Rewriting one in place needs the
|
|
6
|
+
* opposite: the exact offsets of each tag and each attribute value, so an edit
|
|
7
|
+
* can replace four characters instead of regenerating the file.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
/** An attribute, and where its value sits between the quotes. */
|
|
12
|
+
export interface SpannedAttribute {
|
|
13
|
+
/** The value with entities decoded — what a comparison should use. */
|
|
14
|
+
readonly value: string;
|
|
15
|
+
/** Offset of the first character of the value, inside the quotes. */
|
|
16
|
+
readonly start: number;
|
|
17
|
+
/** Offset just past the last character of the value. */
|
|
18
|
+
readonly end: number;
|
|
19
|
+
}
|
|
20
|
+
/** An element, and where it was written. */
|
|
21
|
+
export interface SpannedElement {
|
|
22
|
+
/** Qualified name, e.g. `bpmn:serviceTask`. */
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly attributes: Map<string, SpannedAttribute>;
|
|
25
|
+
readonly children: SpannedElement[];
|
|
26
|
+
/** Character data directly inside, entities decoded, concatenated. */
|
|
27
|
+
text: string;
|
|
28
|
+
/** Offset of the `<` opening the start tag. */
|
|
29
|
+
readonly start: number;
|
|
30
|
+
/** Offset just past the `>` closing the whole element. */
|
|
31
|
+
end: number;
|
|
32
|
+
/** Offset just past the `>` closing the start tag. */
|
|
33
|
+
readonly contentStart: number;
|
|
34
|
+
/** Offset of the `<` opening the end tag; equals {@link end} when self-closing. */
|
|
35
|
+
contentEnd: number;
|
|
36
|
+
readonly selfClosing: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Parses a document into a tree that knows its own offsets.
|
|
40
|
+
*
|
|
41
|
+
* @param xml - A well-formed XML document.
|
|
42
|
+
* @throws Error when there is no root element, or the document is malformed.
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseXmlSpans(xml: string): SpannedElement;
|
|
45
|
+
//# sourceMappingURL=xml-spans.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An XML document parsed into a tree that remembers where everything was.
|
|
3
|
+
*
|
|
4
|
+
* `parseXml` builds a clean tree with the source thrown away, which is right
|
|
5
|
+
* for everything that reads a document. Rewriting one in place needs the
|
|
6
|
+
* opposite: the exact offsets of each tag and each attribute value, so an edit
|
|
7
|
+
* can replace four characters instead of regenerating the file.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
import { Visit, scanXml } from "./xml-parser.js";
|
|
12
|
+
class SpanBuilder {
|
|
13
|
+
root;
|
|
14
|
+
position;
|
|
15
|
+
stack = [];
|
|
16
|
+
cursor(cursor) {
|
|
17
|
+
this.position = cursor;
|
|
18
|
+
}
|
|
19
|
+
start(name, _local, attributes, selfClosing) {
|
|
20
|
+
const spans = new Map();
|
|
21
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
22
|
+
const span = this.position.attributeSpan(key);
|
|
23
|
+
// A span is always there for an attribute the scanner just read; the
|
|
24
|
+
// fallback keeps the tree usable rather than asserting about it.
|
|
25
|
+
spans.set(key, {
|
|
26
|
+
value,
|
|
27
|
+
start: span?.start ?? this.position.tagStart,
|
|
28
|
+
end: span?.end ?? this.position.tagStart,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const element = {
|
|
32
|
+
name,
|
|
33
|
+
attributes: spans,
|
|
34
|
+
children: [],
|
|
35
|
+
text: "",
|
|
36
|
+
start: this.position.tagStart,
|
|
37
|
+
end: this.position.tagEnd,
|
|
38
|
+
contentStart: this.position.tagEnd,
|
|
39
|
+
contentEnd: this.position.tagEnd,
|
|
40
|
+
selfClosing,
|
|
41
|
+
};
|
|
42
|
+
this.stack[this.stack.length - 1]?.children.push(element);
|
|
43
|
+
if (this.root === undefined)
|
|
44
|
+
this.root = element;
|
|
45
|
+
this.stack.push(element);
|
|
46
|
+
return Visit.All;
|
|
47
|
+
}
|
|
48
|
+
text(text) {
|
|
49
|
+
const element = this.stack[this.stack.length - 1];
|
|
50
|
+
if (element !== undefined)
|
|
51
|
+
element.text += text;
|
|
52
|
+
}
|
|
53
|
+
end() {
|
|
54
|
+
const element = this.stack.pop();
|
|
55
|
+
if (element === undefined)
|
|
56
|
+
return;
|
|
57
|
+
element.contentEnd = this.position.endTagStart;
|
|
58
|
+
element.end = this.position.endTagEnd;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Parses a document into a tree that knows its own offsets.
|
|
63
|
+
*
|
|
64
|
+
* @param xml - A well-formed XML document.
|
|
65
|
+
* @throws Error when there is no root element, or the document is malformed.
|
|
66
|
+
*/
|
|
67
|
+
export function parseXmlSpans(xml) {
|
|
68
|
+
const builder = new SpanBuilder();
|
|
69
|
+
if (!scanXml(xml, builder) || builder.root === undefined) {
|
|
70
|
+
throw new Error("Failed to parse XML: no root element found");
|
|
71
|
+
}
|
|
72
|
+
return builder.root;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=xml-spans.js.map
|