abstract-image 11.0.20 → 11.0.21
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/lib/abstract-image-xml/abstract-image-xml.d.ts +1 -1
- package/lib/abstract-image-xml/abstract-image-xml.d.ts.map +1 -1
- package/lib/abstract-image-xml/abstract-image-xml.js +3 -3
- package/lib/abstract-image-xml/abstract-image-xml.js.map +1 -1
- package/lib/abstract-image-xml/index.d.ts +0 -1
- package/lib/abstract-image-xml/index.d.ts.map +1 -1
- package/lib/abstract-image-xml/index.js +0 -1
- package/lib/abstract-image-xml/index.js.map +1 -1
- package/package.json +4 -3
- package/src/abstract-image-xml/abstract-image-xml.ts +2 -2
- package/src/abstract-image-xml/index.ts +0 -1
- package/lib/abstract-image-xml/handlebars-xml/helpers.d.ts +0 -2
- package/lib/abstract-image-xml/handlebars-xml/helpers.d.ts.map +0 -1
- package/lib/abstract-image-xml/handlebars-xml/helpers.js +0 -54
- package/lib/abstract-image-xml/handlebars-xml/helpers.js.map +0 -1
- package/lib/abstract-image-xml/handlebars-xml/index.d.ts +0 -3
- package/lib/abstract-image-xml/handlebars-xml/index.d.ts.map +0 -1
- package/lib/abstract-image-xml/handlebars-xml/index.js +0 -19
- package/lib/abstract-image-xml/handlebars-xml/index.js.map +0 -1
- package/lib/abstract-image-xml/handlebars-xml/parse-handlebars-xml.d.ts +0 -14
- package/lib/abstract-image-xml/handlebars-xml/parse-handlebars-xml.d.ts.map +0 -1
- package/lib/abstract-image-xml/handlebars-xml/parse-handlebars-xml.js +0 -127
- package/lib/abstract-image-xml/handlebars-xml/parse-handlebars-xml.js.map +0 -1
- package/lib/abstract-image-xml/handlebars-xml/validate-handlebars-xml.d.ts +0 -21
- package/lib/abstract-image-xml/handlebars-xml/validate-handlebars-xml.d.ts.map +0 -1
- package/lib/abstract-image-xml/handlebars-xml/validate-handlebars-xml.js +0 -195
- package/lib/abstract-image-xml/handlebars-xml/validate-handlebars-xml.js.map +0 -1
- package/lib/model/stringify-parse.d.ts +0 -4
- package/lib/model/stringify-parse.d.ts.map +0 -1
- package/lib/model/stringify-parse.js +0 -83
- package/lib/model/stringify-parse.js.map +0 -1
- package/src/abstract-image-xml/handlebars-xml/helpers.ts +0 -59
- package/src/abstract-image-xml/handlebars-xml/index.ts +0 -2
- package/src/abstract-image-xml/handlebars-xml/parse-handlebars-xml.ts +0 -137
- package/src/abstract-image-xml/handlebars-xml/validate-handlebars-xml.ts +0 -272
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractImage } from "../model/abstract-image.js";
|
|
2
|
-
import { XmlElement } from "
|
|
2
|
+
import { XmlElement } from "handlebars-xml";
|
|
3
3
|
export declare const abstractImageXml: (template: string, data: any) => AbstractImage;
|
|
4
4
|
export declare function abstractImageOfXml(el: XmlElement): unknown;
|
|
5
5
|
export declare const parsedXsd: readonly XmlElement[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-image-xml.d.ts","sourceRoot":"","sources":["../../src/abstract-image-xml/abstract-image-xml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"abstract-image-xml.d.ts","sourceRoot":"","sources":["../../src/abstract-image-xml/abstract-image-xml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAgC,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAmB1E,eAAO,MAAM,gBAAgB,GAAI,UAAU,MAAM,EAAE,MAAM,GAAG,KAAG,aACkB,CAAC;AAElF,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,UAAU,GAAG,OAAO,CA6H1D;AAED,eAAO,MAAM,SAAS,uBAAgB,CAAC"}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parsedXsd = exports.abstractImageXml = void 0;
|
|
4
4
|
exports.abstractImageOfXml = abstractImageOfXml;
|
|
5
|
+
const handlebars_xml_1 = require("handlebars-xml");
|
|
5
6
|
const color_js_1 = require("../model/color.js");
|
|
6
7
|
const abstract_image_xsd_js_1 = require("./abstract-image-xsd.js");
|
|
7
|
-
const
|
|
8
|
-
const abstractImageXml = (template, data) => abstractImageOfXml((0, index_js_1.parseHandlebarsXml)(template, data)[0]);
|
|
8
|
+
const abstractImageXml = (template, data) => abstractImageOfXml((0, handlebars_xml_1.parseHandlebarsXml)(template, data, {})[0]);
|
|
9
9
|
exports.abstractImageXml = abstractImageXml;
|
|
10
10
|
function abstractImageOfXml(el) {
|
|
11
11
|
const children = Array();
|
|
@@ -131,7 +131,7 @@ function abstractImageOfXml(el) {
|
|
|
131
131
|
throw new Error(`Could not find creator for element with name ${el.tagName}`);
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
exports.parsedXsd = (0,
|
|
134
|
+
exports.parsedXsd = (0, handlebars_xml_1.parseXsd)(abstract_image_xsd_js_1.xsd);
|
|
135
135
|
function parsePoint(pointString) {
|
|
136
136
|
const [xString, yString] = pointString?.split(" ") ?? [0, 0];
|
|
137
137
|
const [x, y] = [Number(xString ?? 0), Number(yString ?? 0)];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-image-xml.js","sourceRoot":"","sources":["../../src/abstract-image-xml/abstract-image-xml.ts"],"names":[],"mappings":";;;AAuBA,gDA6HC;AAnJD,gDAA2E;AAgB3E,mEAA8C;
|
|
1
|
+
{"version":3,"file":"abstract-image-xml.js","sourceRoot":"","sources":["../../src/abstract-image-xml/abstract-image-xml.ts"],"names":[],"mappings":";;;AAuBA,gDA6HC;AAnJD,mDAA0E;AAC1E,gDAA2E;AAgB3E,mEAA8C;AAEvC,MAAM,gBAAgB,GAAG,CAAC,QAAgB,EAAE,IAAS,EAAiB,EAAE,CAC7E,kBAAkB,CAAC,IAAA,mCAAkB,EAAC,QAAQ,EAAE,I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AE,CAAC,EAAE,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC,EAAE,CAAC;IAC9D,CAAC,CAAC,IAAI,EAAE,CACT,CAAC;AACJ,CAAC;AAED,SAAS,sBAAsB,CAAC,iBAAqC;IACnE,OAAO,iBAAiB,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;AACzD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/abstract-image-xml/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/abstract-image-xml/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
|
|
@@ -15,5 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./abstract-image-xml.js"), exports);
|
|
18
|
-
__exportStar(require("./handlebars-xml/index.js"), exports);
|
|
19
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/abstract-image-xml/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/abstract-image-xml/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "abstract-image",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.21",
|
|
4
4
|
"description": "Dynamically create images using code or JSX and render to any format",
|
|
5
5
|
"repository": "https://github.com/dividab/abstract-visuals/tree/master/packages/abstract-image",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"base64-js": "^1.5.1",
|
|
23
23
|
"fast-xml-parser": "^4.5.0",
|
|
24
|
-
"handlebars": "4.7.8"
|
|
24
|
+
"handlebars": "4.7.8",
|
|
25
|
+
"handlebars-xml": "^0.0.1"
|
|
25
26
|
},
|
|
26
27
|
"peerDependencies": {
|
|
27
28
|
"react": ">=17.0.0 <^19.0.0"
|
|
@@ -33,5 +34,5 @@
|
|
|
33
34
|
"vite": "^6.0.1",
|
|
34
35
|
"vitest": "^2.1.6"
|
|
35
36
|
},
|
|
36
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "f102f4239ef9a2f425d5006958170232eedbdd91"
|
|
37
38
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AbstractImage } from "../model/abstract-image.js";
|
|
2
|
+
import { parseHandlebarsXml, parseXsd, XmlElement } from "handlebars-xml";
|
|
2
3
|
import { black, fromString2, transparent, white } from "../model/color.js";
|
|
3
4
|
import {
|
|
4
5
|
AbstractFontWeight,
|
|
@@ -16,10 +17,9 @@ import {
|
|
|
16
17
|
} from "../model/component.js";
|
|
17
18
|
import { Point } from "../model/point.js";
|
|
18
19
|
import { xsd } from "./abstract-image-xsd.js";
|
|
19
|
-
import { parseHandlebarsXml, parseXsd, XmlElement } from "./handlebars-xml/index.js";
|
|
20
20
|
|
|
21
21
|
export const abstractImageXml = (template: string, data: any): AbstractImage =>
|
|
22
|
-
abstractImageOfXml(parseHandlebarsXml(template, data)[0]!) as AbstractImage;
|
|
22
|
+
abstractImageOfXml(parseHandlebarsXml(template, data, {})[0]!) as AbstractImage;
|
|
23
23
|
|
|
24
24
|
export function abstractImageOfXml(el: XmlElement): unknown {
|
|
25
25
|
const children = Array<Component>();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/abstract-image-xml/handlebars-xml/helpers.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe,IAAI,IAAI,CAOtC"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.registerHelpers = registerHelpers;
|
|
7
|
-
const handlebars_1 = __importDefault(require("handlebars"));
|
|
8
|
-
function registerHelpers() {
|
|
9
|
-
sortOnPathHelper();
|
|
10
|
-
equalHelper();
|
|
11
|
-
lessThanHelper();
|
|
12
|
-
greaterThanHelper();
|
|
13
|
-
lessThanOrEqualHelper();
|
|
14
|
-
greaterThanEqualHelper();
|
|
15
|
-
}
|
|
16
|
-
function sortOnPathHelper() {
|
|
17
|
-
handlebars_1.default.registerHelper("sortOnPath", function (array, key) {
|
|
18
|
-
const path = key.split(".");
|
|
19
|
-
const extractPath = (obj, path) => {
|
|
20
|
-
const [first, ...rest] = path;
|
|
21
|
-
if (first === undefined) {
|
|
22
|
-
return obj;
|
|
23
|
-
}
|
|
24
|
-
return extractPath(obj[first], rest);
|
|
25
|
-
};
|
|
26
|
-
return array.toSorted((a, b) => extractPath(a, path) - extractPath(b, path));
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
function equalHelper() {
|
|
30
|
-
handlebars_1.default.registerHelper("equal", function (a, b) {
|
|
31
|
-
return a === b;
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
function lessThanHelper() {
|
|
35
|
-
handlebars_1.default.registerHelper("lessThan", function (a, b) {
|
|
36
|
-
return a < b;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
function greaterThanHelper() {
|
|
40
|
-
handlebars_1.default.registerHelper("greaterThan", function (a, b) {
|
|
41
|
-
return a > b;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
function lessThanOrEqualHelper() {
|
|
45
|
-
handlebars_1.default.registerHelper("lessThanEqual", function (a, b) {
|
|
46
|
-
return a <= b;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
function greaterThanEqualHelper() {
|
|
50
|
-
handlebars_1.default.registerHelper("greaterThanEqual", function (a, b) {
|
|
51
|
-
return a >= b;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/abstract-image-xml/handlebars-xml/helpers.ts"],"names":[],"mappings":";;;;;AAEA,0CAOC;AATD,4DAAoC;AAEpC,SAAgB,eAAe;IAC7B,gBAAgB,EAAE,CAAC;IACnB,WAAW,EAAE,CAAC;IACd,cAAc,EAAE,CAAC;IACjB,iBAAiB,EAAE,CAAC;IACpB,qBAAqB,EAAE,CAAC;IACxB,sBAAsB,EAAE,CAAC;AAC3B,CAAC;AAED,SAAS,gBAAgB;IACvB,oBAAU,CAAC,cAAc,CAAC,YAAY,EAAE,UAAU,KAAK,EAAE,GAAG;QAC1D,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE5B,MAAM,WAAW,GAAG,CAAC,GAAwB,EAAE,IAA2B,EAAO,EAAE;YACjF,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;YAC9B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,GAAG,CAAC;YACb,CAAC;YACD,OAAO,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;QACvC,CAAC,CAAC;QAEF,OAAO,KAAK,CAAC,QAAQ,CACnB,CAAC,CAAsB,EAAE,CAAsB,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,CAChG,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,WAAW;IAClB,oBAAU,CAAC,cAAc,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,CAAC;QAC/C,OAAO,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,cAAc;IACrB,oBAAU,CAAC,cAAc,CAAC,UAAU,EAAE,UAAU,CAAC,EAAE,CAAC;QAClD,OAAO,CAAC,GAAG,CAAC,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,iBAAiB;IACxB,oBAAU,CAAC,cAAc,CAAC,aAAa,EAAE,UAAU,CAAC,EAAE,CAAC;QACrD,OAAO,CAAC,GAAG,CAAC,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,qBAAqB;IAC5B,oBAAU,CAAC,cAAc,CAAC,eAAe,EAAE,UAAU,CAAC,EAAE,CAAC;QACvD,OAAO,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,sBAAsB;IAC7B,oBAAU,CAAC,cAAc,CAAC,kBAAkB,EAAE,UAAU,CAAC,EAAE,CAAC;QAC1D,OAAO,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/abstract-image-xml/handlebars-xml/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./validate-handlebars-xml.js"), exports);
|
|
18
|
-
__exportStar(require("./parse-handlebars-xml.js"), exports);
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/abstract-image-xml/handlebars-xml/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA6C;AAC7C,4DAA0C"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { X2jOptions } from "fast-xml-parser";
|
|
2
|
-
export type XmlElement = {
|
|
3
|
-
readonly tagName: string;
|
|
4
|
-
readonly attributes: Record<string, string>;
|
|
5
|
-
readonly children: ReadonlyArray<XmlElement>;
|
|
6
|
-
readonly textContent?: string;
|
|
7
|
-
};
|
|
8
|
-
export declare const parseHandlebarsXml: (template: string, data: any) => ReadonlyArray<XmlElement>;
|
|
9
|
-
export declare function parseXmlCustom(text: string, options: Partial<X2jOptions>): ReadonlyArray<XmlElement>;
|
|
10
|
-
export declare const parseXml: (text: string) => ReadonlyArray<XmlElement>;
|
|
11
|
-
export declare const parseXsd: (text: string) => ReadonlyArray<XmlElement>;
|
|
12
|
-
export declare function findElement(elements: ReadonlyArray<XmlElement>, elementName: string | undefined): XmlElement | undefined;
|
|
13
|
-
export declare function getChildren(elements: ReadonlyArray<XmlElement>): ReadonlyArray<XmlElement>;
|
|
14
|
-
//# sourceMappingURL=parse-handlebars-xml.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse-handlebars-xml.d.ts","sourceRoot":"","sources":["../../../src/abstract-image-xml/handlebars-xml/parse-handlebars-xml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,iBAAiB,CAAC;AAIxD,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IAC7C,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,EAAE,MAAM,GAAG,KAAG,aAAa,CAAC,UAAU,CAGxF,CAAC;AAEF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAKpG;AACD,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,KAAG,aAAa,CAAC,UAAU,CAAwC,CAAC;AACzG,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,KAAG,aAAa,CAAC,UAAU,CACP,CAAC;AAgC1D,wBAAgB,WAAW,CACzB,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,EACnC,WAAW,EAAE,MAAM,GAAG,SAAS,GAC9B,UAAU,GAAG,SAAS,CAqBxB;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAc1F"}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parseXsd = exports.parseXml = exports.parseHandlebarsXml = void 0;
|
|
7
|
-
exports.parseXmlCustom = parseXmlCustom;
|
|
8
|
-
exports.findElement = findElement;
|
|
9
|
-
exports.getChildren = getChildren;
|
|
10
|
-
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
11
|
-
const handlebars_1 = __importDefault(require("handlebars"));
|
|
12
|
-
const helpers_js_1 = require("./helpers.js");
|
|
13
|
-
const parseHandlebarsXml = (template, data) => {
|
|
14
|
-
(0, helpers_js_1.registerHelpers)();
|
|
15
|
-
return (0, exports.parseXml)(handlebars_1.default.compile(template, { compat: true, preventIndent: true })(data));
|
|
16
|
-
};
|
|
17
|
-
exports.parseHandlebarsXml = parseHandlebarsXml;
|
|
18
|
-
function parseXmlCustom(text, options) {
|
|
19
|
-
const parser = new fast_xml_parser_1.XMLParser(options);
|
|
20
|
-
parser.addEntity("#x2F", "/");
|
|
21
|
-
parser.addEntity("#x3D", "=");
|
|
22
|
-
return transformFXP(parser.parse(text));
|
|
23
|
-
}
|
|
24
|
-
const parseXml = (text) => transformFXP(xmlParser.parse(text));
|
|
25
|
-
exports.parseXml = parseXml;
|
|
26
|
-
const parseXsd = (text) => transformFXP(xsdParser.parse(text.replace(/xs:/g, "")));
|
|
27
|
-
exports.parseXsd = parseXsd;
|
|
28
|
-
// Transforms fast-xml-parser format to a format that is much easier to work with
|
|
29
|
-
function transformFXP(parsedXml) {
|
|
30
|
-
return parsedXml.flatMap((element) => {
|
|
31
|
-
const key = Object.keys(element).find((k) => k !== ":@" && k !== "#text");
|
|
32
|
-
if (key === "?xml") {
|
|
33
|
-
return [];
|
|
34
|
-
}
|
|
35
|
-
const children = (element[key] || []).filter((c) => {
|
|
36
|
-
const key = Object.keys(c)[0];
|
|
37
|
-
return key !== "#text" && key !== ":@";
|
|
38
|
-
});
|
|
39
|
-
const attributes = element[":@"] || {};
|
|
40
|
-
const textChilds = (element[key] || [])
|
|
41
|
-
.filter((c) => {
|
|
42
|
-
const key = Object.keys(c)[0];
|
|
43
|
-
return key === "#text";
|
|
44
|
-
})
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
-
.flatMap((t) => t["#text"]);
|
|
47
|
-
const textContents = textChilds.flatMap((text) => {
|
|
48
|
-
const cleaned = text.replace(/\n/g, "").replace(/\t/g, "").trim();
|
|
49
|
-
return cleaned ? [text] : [];
|
|
50
|
-
});
|
|
51
|
-
const textContent = textContents.join("\n");
|
|
52
|
-
return { tagName: key, attributes: attributes, children: transformFXP(children), textContent: textContent };
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
function findElement(elements, elementName) {
|
|
56
|
-
if (!elementName) {
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|
|
59
|
-
for (const elem of elements) {
|
|
60
|
-
if (elem.tagName === "annotation" || elem.tagName === "attribute") {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
if (shouldSkipLevel(elem)) {
|
|
64
|
-
const childElement = findElement(Array.from(elem.children), elementName);
|
|
65
|
-
if (childElement) {
|
|
66
|
-
return shouldSkipLevel(childElement)
|
|
67
|
-
? findElement(Array.from(childElement.children), elementName)
|
|
68
|
-
: childElement;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (elem.attributes.name === elementName) {
|
|
72
|
-
return elem;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return undefined;
|
|
76
|
-
}
|
|
77
|
-
function getChildren(elements) {
|
|
78
|
-
for (const elem of elements) {
|
|
79
|
-
if (elem.tagName === "annotation" || elem.tagName === "attribute") {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
if (shouldSkipLevel(elem)) {
|
|
83
|
-
const child = getChildren(Array.from(elem.children));
|
|
84
|
-
if (child.length > 0) {
|
|
85
|
-
return child.flatMap((c) => (shouldSkipLevel(c) ? getChildren(Array.from(c.children)) : c));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return elements;
|
|
89
|
-
}
|
|
90
|
-
return [];
|
|
91
|
-
}
|
|
92
|
-
function shouldSkipLevel(tag) {
|
|
93
|
-
return (tag.tagName === "all" || tag.tagName === "sequence" || tag.tagName === "choice" || tag.attributes.name === undefined);
|
|
94
|
-
}
|
|
95
|
-
const xmlParser = new fast_xml_parser_1.XMLParser({
|
|
96
|
-
preserveOrder: true,
|
|
97
|
-
ignoreAttributes: false,
|
|
98
|
-
attributeNamePrefix: "",
|
|
99
|
-
allowBooleanAttributes: true,
|
|
100
|
-
trimValues: false,
|
|
101
|
-
ignoreDeclaration: true,
|
|
102
|
-
processEntities: true,
|
|
103
|
-
htmlEntities: true,
|
|
104
|
-
attributeValueProcessor: (_name, value) => {
|
|
105
|
-
if (!value?.trim()) {
|
|
106
|
-
return value;
|
|
107
|
-
}
|
|
108
|
-
const nValue = Number(value);
|
|
109
|
-
if (!Number.isNaN(nValue)) {
|
|
110
|
-
return nValue;
|
|
111
|
-
}
|
|
112
|
-
return value;
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
xmlParser.addEntity("#x2F", "/");
|
|
116
|
-
xmlParser.addEntity("#x3D", "=");
|
|
117
|
-
const xsdParser = new fast_xml_parser_1.XMLParser({
|
|
118
|
-
preserveOrder: true,
|
|
119
|
-
ignoreAttributes: false,
|
|
120
|
-
attributeNamePrefix: "",
|
|
121
|
-
allowBooleanAttributes: true,
|
|
122
|
-
trimValues: false,
|
|
123
|
-
ignoreDeclaration: true,
|
|
124
|
-
});
|
|
125
|
-
xsdParser.addEntity("#x2F", "/");
|
|
126
|
-
xsdParser.addEntity("#x3D", "=");
|
|
127
|
-
//# sourceMappingURL=parse-handlebars-xml.js.map
|
|
@@ -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;QACD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC,CAAC;AACH,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACjC,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEjC,MAAM,SAAS,GAAG,IAAI,2BAAS,CAAC;IAC9B,aAAa,EAAE,IAAI;IACnB,gBAAgB,EAAE,KAAK;IACvB,mBAAmB,EAAE,EAAE;IACvB,sBAAsB,EAAE,IAAI;IAC5B,UAAU,EAAE,KAAK;IACjB,iBAAiB,EAAE,IAAI;CACxB,CAAC,CAAC;AACH,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACjC,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { XmlElement } from "./parse-handlebars-xml.js";
|
|
2
|
-
type Range = {
|
|
3
|
-
readonly startLineNumber: number;
|
|
4
|
-
readonly startColumn: number;
|
|
5
|
-
readonly endLineNumber: number;
|
|
6
|
-
readonly endColumn: number;
|
|
7
|
-
};
|
|
8
|
-
type ErrorObject = {
|
|
9
|
-
readonly range: Range;
|
|
10
|
-
readonly options: ErrorOptions;
|
|
11
|
-
};
|
|
12
|
-
type ErrorOptions = {
|
|
13
|
-
readonly className: string;
|
|
14
|
-
readonly hoverMessage: Array<{
|
|
15
|
-
readonly value: string;
|
|
16
|
-
}>;
|
|
17
|
-
};
|
|
18
|
-
export declare function validateXml(fullXml: string, xsdSchema: ReadonlyArray<XmlElement>): Array<ErrorObject>;
|
|
19
|
-
export declare function errorToReadableText(errors: ReadonlyArray<ErrorObject>, templateName?: string): string;
|
|
20
|
-
export {};
|
|
21
|
-
//# sourceMappingURL=validate-handlebars-xml.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate-handlebars-xml.d.ts","sourceRoot":"","sources":["../../../src/abstract-image-xml/handlebars-xml/validate-handlebars-xml.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAyB,MAAM,2BAA2B,CAAC;AAO9E,KAAK,KAAK,GAAG;IACX,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,CAAC;AAMF,KAAK,WAAW,GAAG;IACjB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;CAChC,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC;QAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;KACxB,CAAC,CAAC;CACJ,CAAC;AASF,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC,CAgErG;AAoJD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,CAAC,WAAW,CAAC,EAAE,YAAY,GAAE,MAAW,GAAG,MAAM,CAYzG"}
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateXml = validateXml;
|
|
4
|
-
exports.errorToReadableText = errorToReadableText;
|
|
5
|
-
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
6
|
-
const parse_handlebars_xml_js_1 = require("./parse-handlebars-xml.js");
|
|
7
|
-
var ErrorType;
|
|
8
|
-
(function (ErrorType) {
|
|
9
|
-
ErrorType[ErrorType["warning"] = 0] = "warning";
|
|
10
|
-
ErrorType[ErrorType["error"] = 1] = "error";
|
|
11
|
-
})(ErrorType || (ErrorType = {}));
|
|
12
|
-
// eslint-disable-next-line functional/prefer-readonly-type
|
|
13
|
-
function validateXml(fullXml, xsdSchema) {
|
|
14
|
-
const errors = [];
|
|
15
|
-
// ignore all handlebars brackets
|
|
16
|
-
const matchHandlebarsBrackets = /{{.*}}(?!([\S]))/g;
|
|
17
|
-
// Ignore xml comments
|
|
18
|
-
const xmlComments = /<!--[^>]*-->/g;
|
|
19
|
-
// Replace matches with spaces of same length
|
|
20
|
-
let cleanedXml = fullXml.replace(matchHandlebarsBrackets, (m) => " ".repeat(m.length));
|
|
21
|
-
cleanedXml = cleanedXml.replace(xmlComments, (m) => {
|
|
22
|
-
const x = (m.match(/^.*$/gm) || []).map((m2) => " ".repeat(m2.length));
|
|
23
|
-
return x.join("\n");
|
|
24
|
-
});
|
|
25
|
-
const xml = `<xml>\n${cleanedXml}\n</xml>`;
|
|
26
|
-
if (xml) {
|
|
27
|
-
try {
|
|
28
|
-
const result = fast_xml_parser_1.XMLValidator.validate(xml, {
|
|
29
|
-
allowBooleanAttributes: true,
|
|
30
|
-
});
|
|
31
|
-
if (result !== true) {
|
|
32
|
-
errors.push(getErrorFromException(result, xml));
|
|
33
|
-
}
|
|
34
|
-
const entryPointXml = (0, parse_handlebars_xml_js_1.parseXml)(xml)[0];
|
|
35
|
-
const entryPointSchema = xsdSchema[0];
|
|
36
|
-
let pos = 0;
|
|
37
|
-
const lines = cleanedXml.split("\n");
|
|
38
|
-
const getRangeOfElement = (text, incrementPosition = true) => {
|
|
39
|
-
if (text === undefined) {
|
|
40
|
-
const monacoPosition = getPositionFromIndex(lines, pos);
|
|
41
|
-
return toRange(monacoPosition.lineNumber, monacoPosition.column, monacoPosition.lineNumber, monacoPosition.column + 5);
|
|
42
|
-
}
|
|
43
|
-
const position = cleanedXml.indexOf(text, pos);
|
|
44
|
-
if (incrementPosition) {
|
|
45
|
-
pos = position >= pos ? position + text.length : pos;
|
|
46
|
-
}
|
|
47
|
-
const monacoPosition = getPositionFromIndex(lines, position);
|
|
48
|
-
return toRange(monacoPosition.lineNumber, monacoPosition.column, monacoPosition.lineNumber, monacoPosition.column + text.length);
|
|
49
|
-
};
|
|
50
|
-
const validationErrors = entryPointXml.children.flatMap((child) => validateElements(child, undefined, entryPointSchema, getRangeOfElement));
|
|
51
|
-
errors.push(...validationErrors);
|
|
52
|
-
}
|
|
53
|
-
catch (e) {
|
|
54
|
-
errors.push(createError(e.message, ErrorType.error, toRange(1, 1, 1, 100)));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return errors.map((e) => getDecorationsFromError(e));
|
|
58
|
-
}
|
|
59
|
-
function validateElements(element, schemaElement, completeSchema, getRangeOfElement) {
|
|
60
|
-
const errors = [];
|
|
61
|
-
// Validate element name
|
|
62
|
-
const tagName = element.tagName;
|
|
63
|
-
const range = getRangeOfElement(tagName);
|
|
64
|
-
const slashPosition = getRangeOfElement("/", false);
|
|
65
|
-
const closingTagPosition = getRangeOfElement(">", false);
|
|
66
|
-
const isClosed = rangeLessThan(slashPosition, closingTagPosition);
|
|
67
|
-
const validElements = Object.values(completeSchema.children);
|
|
68
|
-
const schemaName = schemaElement?.attributes.type || tagName;
|
|
69
|
-
const foundSchemaElement = (0, parse_handlebars_xml_js_1.findElement)(validElements, schemaName);
|
|
70
|
-
if (!foundSchemaElement) {
|
|
71
|
-
return [createError(`"${tagName}" is not a valid element`, ErrorType.error, range)];
|
|
72
|
-
}
|
|
73
|
-
const possibleAttributes = Array.from(foundSchemaElement.children).flatMap((c) => c.tagName === "attribute" ? c : []);
|
|
74
|
-
// Validate required attributes
|
|
75
|
-
for (const possibleAttribute of possibleAttributes) {
|
|
76
|
-
const attributeName = possibleAttribute.attributes.name;
|
|
77
|
-
const isRequired = possibleAttribute.attributes.use;
|
|
78
|
-
if (attributeName && isRequired && isRequired === "required") {
|
|
79
|
-
if (element.attributes[attributeName] === undefined) {
|
|
80
|
-
errors.push(createError(`"${attributeName}" is a required attribute on "${tagName}"`, ErrorType.error, range));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
// Validate existing attributes
|
|
85
|
-
for (const [attrKey, attrVal] of Object.entries(element.attributes)) {
|
|
86
|
-
const possibleAttrNames = possibleAttributes.flatMap((p) => p.attributes.name || []);
|
|
87
|
-
const attrText = typeof attrVal === "string" ? `${attrKey}="${attrVal}"` : attrKey;
|
|
88
|
-
const attrRange = getRangeOfElement(attrText, false);
|
|
89
|
-
if (!possibleAttrNames.includes(attrKey)) {
|
|
90
|
-
errors.push(createError(`"${attrKey}" is a not a valid attribute on "${tagName}"`, ErrorType.error, attrRange));
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
// Validate that the children are allowed as a child of current element
|
|
94
|
-
// and then validate the children themselves
|
|
95
|
-
const schemaChildren = Object.values(foundSchemaElement.children);
|
|
96
|
-
for (const child of element.children) {
|
|
97
|
-
const childName = child.tagName;
|
|
98
|
-
if (!childName) {
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
const foundChild = (0, parse_handlebars_xml_js_1.findElement)(schemaChildren, childName);
|
|
102
|
-
if (!foundChild) {
|
|
103
|
-
const childRange = getRangeOfElement(childName, false);
|
|
104
|
-
if (childRange) {
|
|
105
|
-
errors.push(createError(`"${childName}" is not a valid child of "${tagName}"`, ErrorType.error, childRange));
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
const elementErrors = validateElements(child, foundChild, completeSchema, getRangeOfElement);
|
|
109
|
-
errors.push(...elementErrors);
|
|
110
|
-
}
|
|
111
|
-
if (!isClosed) {
|
|
112
|
-
// Increment position to after closing tag
|
|
113
|
-
getRangeOfElement(`</${tagName}`, true);
|
|
114
|
-
}
|
|
115
|
-
return errors;
|
|
116
|
-
}
|
|
117
|
-
function getDecorationsFromError(error) {
|
|
118
|
-
return {
|
|
119
|
-
range: error.range,
|
|
120
|
-
options: {
|
|
121
|
-
className: getErrorClassNames(error),
|
|
122
|
-
hoverMessage: [{ value: getErrorType(error) }, { value: getErrorMessage(error) }],
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
function getErrorFromException(result, xml) {
|
|
127
|
-
const { col, line, msg } = result.err;
|
|
128
|
-
const startLine = line - 1;
|
|
129
|
-
const lines = xml.split("\n");
|
|
130
|
-
const rowText = lines[startLine] || "";
|
|
131
|
-
const length = rowText.indexOf(">") - rowText.indexOf("<") || 4;
|
|
132
|
-
const range = toRange(startLine, col, startLine, col + length);
|
|
133
|
-
return createError(msg, ErrorType.error, range);
|
|
134
|
-
}
|
|
135
|
-
function getErrorClassNames(error) {
|
|
136
|
-
switch (error.type) {
|
|
137
|
-
case ErrorType.warning:
|
|
138
|
-
return "xml-lint xml-lint--warning";
|
|
139
|
-
case ErrorType.error:
|
|
140
|
-
return "xml-lint xml-lint--error";
|
|
141
|
-
default:
|
|
142
|
-
return "";
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
function getErrorType(error) {
|
|
146
|
-
switch (error.type) {
|
|
147
|
-
case ErrorType.warning:
|
|
148
|
-
return "**Warning**";
|
|
149
|
-
case ErrorType.error:
|
|
150
|
-
return "**Error**";
|
|
151
|
-
default:
|
|
152
|
-
return "";
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
const getErrorMessage = (error) => error.message.split(/[\t\n]/g)[1] ?? error.message;
|
|
156
|
-
const createError = (message, type, range) => ({ message, type, range });
|
|
157
|
-
function getPositionFromIndex(lines, index) {
|
|
158
|
-
let totalLength = 0;
|
|
159
|
-
for (const [lineNumber, line] of lines.entries()) {
|
|
160
|
-
totalLength += line.length;
|
|
161
|
-
if (totalLength >= index - lineNumber) {
|
|
162
|
-
return {
|
|
163
|
-
lineNumber: lineNumber + 1,
|
|
164
|
-
column: 1 + index - (totalLength - line.length) - lineNumber || 1, // "- lineNumber" because of \n characters
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return { lineNumber: lines.length, column: 1 };
|
|
169
|
-
}
|
|
170
|
-
const toRange = (startLineNumber, startColumn, endLineNumber, endColumn) => ({
|
|
171
|
-
startLineNumber,
|
|
172
|
-
startColumn,
|
|
173
|
-
endLineNumber,
|
|
174
|
-
endColumn,
|
|
175
|
-
});
|
|
176
|
-
function errorToReadableText(errors, templateName = "") {
|
|
177
|
-
const errorLines = [];
|
|
178
|
-
if (templateName) {
|
|
179
|
-
errorLines.push(`Error in template ${templateName} \n`);
|
|
180
|
-
}
|
|
181
|
-
for (const error of errors) {
|
|
182
|
-
const hoverErrors = error.options.hoverMessage.map((e) => e.value.replace(/\*/g, ""));
|
|
183
|
-
errorLines.push(`${hoverErrors.join("\n")}`);
|
|
184
|
-
errorLines.push(`On line ${error.range.startLineNumber}, column ${error.range.startColumn}\n`);
|
|
185
|
-
}
|
|
186
|
-
return errorLines.join("\n");
|
|
187
|
-
}
|
|
188
|
-
function rangeLessThan(range1, range2) {
|
|
189
|
-
return range1.startLineNumber < range2.startLineNumber
|
|
190
|
-
? true
|
|
191
|
-
: range1.startLineNumber > range2.startLineNumber
|
|
192
|
-
? false
|
|
193
|
-
: range1.startColumn < range2.startColumn;
|
|
194
|
-
}
|
|
195
|
-
//# sourceMappingURL=validate-handlebars-xml.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate-handlebars-xml.js","sourceRoot":"","sources":["../../../src/abstract-image-xml/handlebars-xml/validate-handlebars-xml.ts"],"names":[],"mappings":";;AAuCA,kCAgEC;AAoJD,kDAYC;AAvQD,qDAAgE;AAChE,uEAA8E;AAE9E,IAAK,SAGJ;AAHD,WAAK,SAAS;IACZ,+CAAW,CAAA;IACX,2CAAS,CAAA;AACX,CAAC,EAHI,SAAS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,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;QACtF,UAAU,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC7C,UAAU,CAAC,IAAI,CAAC,WAAW,KAAK,CAAC,KAAK,CAAC,eAAe,YAAY,KAAK,CAAC,KAAK,CAAC,WAAW,IAAI,CAAC,CAAC;IACjG,CAAC;IAED,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC;AAED,SAAS,aAAa,CAAC,MAAa,EAAE,MAAa;IACjD,OAAO,MAAM,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe;QACpD,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,MAAM,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe;YACjD,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,MAAM,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;AAC9C,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stringify-parse.d.ts","sourceRoot":"","sources":["../../src/model/stringify-parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,wBAAgB,SAAS,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAG9D;AAED,wBAAgB,KAAK,CAAC,gBAAgB,EAAE,MAAM,GAAG,aAAa,CAG7D"}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringify = stringify;
|
|
4
|
-
exports.parse = parse;
|
|
5
|
-
function stringify(abstractImage) {
|
|
6
|
-
const safe = { ...abstractImage, components: abstractImage.components.map(componentToJsonSafe) };
|
|
7
|
-
return JSON.stringify(safe);
|
|
8
|
-
}
|
|
9
|
-
function parse(stringifiedImage) {
|
|
10
|
-
const obj = JSON.parse(stringifiedImage);
|
|
11
|
-
return { ...obj, components: (obj.components ?? []).map(componentFromJsonSafe) };
|
|
12
|
-
}
|
|
13
|
-
function componentToJsonSafe(c) {
|
|
14
|
-
switch (c.type) {
|
|
15
|
-
case "binaryimage": {
|
|
16
|
-
const bi = c;
|
|
17
|
-
if (bi.data.type === "bytes") {
|
|
18
|
-
return { ...bi, data: { type: "bytes", bytes: toBase64(bi.data.bytes) } };
|
|
19
|
-
}
|
|
20
|
-
return bi;
|
|
21
|
-
}
|
|
22
|
-
case "group":
|
|
23
|
-
return { ...c, children: c.children.map(componentToJsonSafe) };
|
|
24
|
-
case "subimage":
|
|
25
|
-
return { ...c, image: componentToJsonSafe(c.image) };
|
|
26
|
-
default:
|
|
27
|
-
return c;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function componentFromJsonSafe(c) {
|
|
31
|
-
if (c?.type === "binaryimage") {
|
|
32
|
-
if (c.data?.type === "bytes") {
|
|
33
|
-
if (typeof c.data.bytes === "string") {
|
|
34
|
-
return { ...c, data: { type: "bytes", bytes: fromBase64(c.data.bytes) } };
|
|
35
|
-
}
|
|
36
|
-
// legacy fallback, will remove
|
|
37
|
-
if (c.data.bytes?.data) {
|
|
38
|
-
return {
|
|
39
|
-
...c,
|
|
40
|
-
data: { ...c.data, bytes: new Uint8Array(c.data.bytes.data) },
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
if (!Array.isArray(c.data?.bytes)) {
|
|
44
|
-
return { ...c, data: { ...c.data, bytes: new Uint8Array(Object.values(c.data.bytes)) } }; // Somtimes Uint8Array is an object instead of an array
|
|
45
|
-
}
|
|
46
|
-
return { ...c, data: { ...c.data, bytes: new Uint8Array(c.data.bytes) } };
|
|
47
|
-
}
|
|
48
|
-
return c;
|
|
49
|
-
}
|
|
50
|
-
if (c?.type === "group") {
|
|
51
|
-
return { ...c, children: Array.isArray(c.children) ? c.children.map(componentFromJsonSafe) : [] };
|
|
52
|
-
}
|
|
53
|
-
if (c?.type === "subimage") {
|
|
54
|
-
return { ...c, image: componentFromJsonSafe(c.image) };
|
|
55
|
-
}
|
|
56
|
-
return c;
|
|
57
|
-
}
|
|
58
|
-
function toBase64(u8) {
|
|
59
|
-
// Node
|
|
60
|
-
if (typeof Buffer !== "undefined") {
|
|
61
|
-
return Buffer.from(u8).toString("base64");
|
|
62
|
-
}
|
|
63
|
-
// Browser
|
|
64
|
-
let bin = "";
|
|
65
|
-
for (const e of u8) {
|
|
66
|
-
bin += String.fromCharCode(e);
|
|
67
|
-
}
|
|
68
|
-
return btoa(bin);
|
|
69
|
-
}
|
|
70
|
-
function fromBase64(b64) {
|
|
71
|
-
// Node
|
|
72
|
-
if (typeof Buffer !== "undefined") {
|
|
73
|
-
return new Uint8Array(Buffer.from(b64, "base64"));
|
|
74
|
-
}
|
|
75
|
-
// Browser
|
|
76
|
-
const bin = atob(b64);
|
|
77
|
-
const out = new Uint8Array(bin.length);
|
|
78
|
-
for (let i = 0; i < bin.length; i++) {
|
|
79
|
-
out[i] = bin.charCodeAt(i);
|
|
80
|
-
}
|
|
81
|
-
return out;
|
|
82
|
-
}
|
|
83
|
-
//# sourceMappingURL=stringify-parse.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stringify-parse.js","sourceRoot":"","sources":["../../src/model/stringify-parse.ts"],"names":[],"mappings":";;AAGA,8BAGC;AAED,sBAGC;AARD,SAAgB,SAAS,CAAC,aAA4B;IACpD,MAAM,IAAI,GAAG,EAAE,GAAG,aAAa,EAAE,UAAU,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAE,CAAC;IACjG,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED,SAAgB,KAAK,CAAC,gBAAwB;IAC5C,MAAM,GAAG,GAAG,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elper();
|
|
6
|
-
lessThanHelper();
|
|
7
|
-
greaterThanHelper();
|
|
8
|
-
lessThanOrEqualHelper();
|
|
9
|
-
greaterThanEqualHelper();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function sortOnPathHelper(): void {
|
|
13
|
-
Handlebars.registerHelper("sortOnPath", function (array, key) {
|
|
14
|
-
const path = key.split(".");
|
|
15
|
-
|
|
16
|
-
const extractPath = (obj: Record<string, any>, path: ReadonlyArray<string>): any => {
|
|
17
|
-
const [first, ...rest] = path;
|
|
18
|
-
if (first === undefined) {
|
|
19
|
-
return obj;
|
|
20
|
-
}
|
|
21
|
-
return extractPath(obj[first], rest);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
return array.toSorted(
|
|
25
|
-
(a: Record<string, any>, b: Record<string, any>) => extractPath(a, path) - extractPath(b, path)
|
|
26
|
-
);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function equalHelper(): void {
|
|
31
|
-
Handlebars.registerHelper("equal", function (a, b) {
|
|
32
|
-
return a === b;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function lessThanHelper(): void {
|
|
37
|
-
Handlebars.registerHelper("lessThan", function (a, b) {
|
|
38
|
-
return a < b;
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function greaterThanHelper(): void {
|
|
43
|
-
Handlebars.registerHelper("greaterThan", function (a, b) {
|
|
44
|
-
return a > b;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function lessThanOrEqualHelper(): void {
|
|
49
|
-
Handlebars.registerHelper("lessThanEqual", function (a, b) {
|
|
50
|
-
return a <= b;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function greaterThanEqualHelper(): void {
|
|
55
|
-
Handlebars.registerHelper("greaterThanEqual", function (a, b) {
|
|
56
|
-
return a >= b;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { X2jOptions, XMLParser } from "fast-xml-parser";
|
|
2
|
-
import Handlebars from "handlebars";
|
|
3
|
-
import { registerHelpers } from "./helpers.js";
|
|
4
|
-
|
|
5
|
-
export type XmlElement = {
|
|
6
|
-
readonly tagName: string;
|
|
7
|
-
readonly attributes: Record<string, string>;
|
|
8
|
-
readonly children: ReadonlyArray<XmlElement>;
|
|
9
|
-
readonly textContent?: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const parseHandlebarsXml = (template: string, data: any): ReadonlyArray<XmlElement> => {
|
|
13
|
-
registerHelpers();
|
|
14
|
-
return parseXml(Handlebars.compile(template, { compat: true, preventIndent: true })(data));
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export function parseXmlCustom(text: string, options: Partial<X2jOptions>): ReadonlyArray<XmlElement> {
|
|
18
|
-
const parser = new XMLParser(options);
|
|
19
|
-
parser.addEntity("#x2F", "/");
|
|
20
|
-
parser.addEntity("#x3D", "=");
|
|
21
|
-
return transformFXP(parser.parse(text));
|
|
22
|
-
}
|
|
23
|
-
export const parseXml = (text: string): ReadonlyArray<XmlElement> => transformFXP(xmlParser.parse(text));
|
|
24
|
-
export const parseXsd = (text: string): ReadonlyArray<XmlElement> =>
|
|
25
|
-
transformFXP(xsdParser.parse(text.replace(/xs:/g, "")));
|
|
26
|
-
|
|
27
|
-
type FastXmlElement = Record<string, ReadonlyArray<FastXmlElement> | Record<string, string>>;
|
|
28
|
-
|
|
29
|
-
// Transforms fast-xml-parser format to a format that is much easier to work with
|
|
30
|
-
function transformFXP(parsedXml: ReadonlyArray<FastXmlElement>): ReadonlyArray<XmlElement> {
|
|
31
|
-
return parsedXml.flatMap((element) => {
|
|
32
|
-
const key = Object.keys(element).find((k) => k !== ":@" && k !== "#text")!;
|
|
33
|
-
if (key === "?xml") {
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
const children = ((element[key] || []) as Array<FastXmlElement>).filter((c) => {
|
|
37
|
-
const key = Object.keys(c)[0];
|
|
38
|
-
return key !== "#text" && key !== ":@";
|
|
39
|
-
});
|
|
40
|
-
const attributes = (element[":@"] as Record<string, string>) || {};
|
|
41
|
-
const textChilds: Array<string> = ((element[key] || []) as Array<FastXmlElement>)
|
|
42
|
-
.filter((c) => {
|
|
43
|
-
const key = Object.keys(c)[0];
|
|
44
|
-
return key === "#text";
|
|
45
|
-
})
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
-
.flatMap((t) => t["#text"] as any as string);
|
|
48
|
-
const textContents = textChilds.flatMap((text) => {
|
|
49
|
-
const cleaned = text.replace(/\n/g, "").replace(/\t/g, "").trim();
|
|
50
|
-
return cleaned ? [text] : [];
|
|
51
|
-
});
|
|
52
|
-
const textContent = textContents.join("\n");
|
|
53
|
-
return { tagName: key, attributes: attributes, children: transformFXP(children), textContent: textContent };
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function findElement(
|
|
58
|
-
elements: ReadonlyArray<XmlElement>,
|
|
59
|
-
elementName: string | undefined
|
|
60
|
-
): XmlElement | undefined {
|
|
61
|
-
if (!elementName) {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
for (const elem of elements) {
|
|
65
|
-
if (elem.tagName === "annotation" || elem.tagName === "attribute") {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
if (shouldSkipLevel(elem)) {
|
|
69
|
-
const childElement = findElement(Array.from(elem.children), elementName);
|
|
70
|
-
if (childElement) {
|
|
71
|
-
return shouldSkipLevel(childElement)
|
|
72
|
-
? findElement(Array.from(childElement.children), elementName)
|
|
73
|
-
: childElement;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (elem.attributes.name === elementName) {
|
|
77
|
-
return elem;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return undefined;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function getChildren(elements: ReadonlyArray<XmlElement>): ReadonlyArray<XmlElement> {
|
|
84
|
-
for (const elem of elements) {
|
|
85
|
-
if (elem.tagName === "annotation" || elem.tagName === "attribute") {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
if (shouldSkipLevel(elem)) {
|
|
89
|
-
const child = getChildren(Array.from(elem.children));
|
|
90
|
-
if (child.length > 0) {
|
|
91
|
-
return child.flatMap((c) => (shouldSkipLevel(c) ? getChildren(Array.from(c.children)) : c));
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return elements;
|
|
95
|
-
}
|
|
96
|
-
return [];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function shouldSkipLevel(tag: XmlElement): boolean {
|
|
100
|
-
return (
|
|
101
|
-
tag.tagName === "all" || tag.tagName === "sequence" || tag.tagName === "choice" || tag.attributes.name === undefined
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const xmlParser = new XMLParser({
|
|
106
|
-
preserveOrder: true,
|
|
107
|
-
ignoreAttributes: false,
|
|
108
|
-
attributeNamePrefix: "",
|
|
109
|
-
allowBooleanAttributes: true,
|
|
110
|
-
trimValues: false,
|
|
111
|
-
ignoreDeclaration: true,
|
|
112
|
-
processEntities: true,
|
|
113
|
-
htmlEntities: true,
|
|
114
|
-
attributeValueProcessor: (_name, value) => {
|
|
115
|
-
if (!value?.trim()) {
|
|
116
|
-
return value;
|
|
117
|
-
}
|
|
118
|
-
const nValue = Number(value);
|
|
119
|
-
if (!Number.isNaN(nValue)) {
|
|
120
|
-
return nValue;
|
|
121
|
-
}
|
|
122
|
-
return value;
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
xmlParser.addEntity("#x2F", "/");
|
|
126
|
-
xmlParser.addEntity("#x3D", "=");
|
|
127
|
-
|
|
128
|
-
const xsdParser = new XMLParser({
|
|
129
|
-
preserveOrder: true,
|
|
130
|
-
ignoreAttributes: false,
|
|
131
|
-
attributeNamePrefix: "",
|
|
132
|
-
allowBooleanAttributes: true,
|
|
133
|
-
trimValues: false,
|
|
134
|
-
ignoreDeclaration: true,
|
|
135
|
-
});
|
|
136
|
-
xsdParser.addEntity("#x2F", "/");
|
|
137
|
-
xsdParser.addEntity("#x3D", "=");
|
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import { XMLValidator, ValidationError } from "fast-xml-parser";
|
|
2
|
-
import { XmlElement, parseXml, findElement } from "./parse-handlebars-xml.js";
|
|
3
|
-
|
|
4
|
-
enum ErrorType {
|
|
5
|
-
warning = 0,
|
|
6
|
-
error = 1,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
type Range = {
|
|
10
|
-
readonly startLineNumber: number;
|
|
11
|
-
readonly startColumn: number;
|
|
12
|
-
readonly endLineNumber: number;
|
|
13
|
-
readonly endColumn: number;
|
|
14
|
-
};
|
|
15
|
-
type Position = {
|
|
16
|
-
readonly lineNumber: number;
|
|
17
|
-
readonly column: number;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
type ErrorObject = {
|
|
21
|
-
readonly range: Range;
|
|
22
|
-
readonly options: ErrorOptions;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
type ErrorOptions = {
|
|
26
|
-
readonly className: string;
|
|
27
|
-
// eslint-disable-next-line functional/prefer-readonly-type
|
|
28
|
-
readonly hoverMessage: Array<{
|
|
29
|
-
readonly value: string;
|
|
30
|
-
}>;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
type XmlError = {
|
|
34
|
-
readonly message: string;
|
|
35
|
-
readonly type: ErrorType;
|
|
36
|
-
readonly range: Range;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// eslint-disable-next-line functional/prefer-readonly-type
|
|
40
|
-
export function validateXml(fullXml: string, xsdSchema: ReadonlyArray<XmlElement>): Array<ErrorObject> {
|
|
41
|
-
const errors: Array<XmlError> = [];
|
|
42
|
-
|
|
43
|
-
// ignore all handlebars brackets
|
|
44
|
-
const matchHandlebarsBrackets = /{{.*}}(?!([\S]))/g;
|
|
45
|
-
// Ignore xml comments
|
|
46
|
-
const xmlComments = /<!--[^>]*-->/g;
|
|
47
|
-
|
|
48
|
-
// Replace matches with spaces of same length
|
|
49
|
-
let cleanedXml = fullXml.replace(matchHandlebarsBrackets, (m) => " ".repeat(m.length));
|
|
50
|
-
cleanedXml = cleanedXml.replace(xmlComments, (m) => {
|
|
51
|
-
const x = (m.match(/^.*$/gm) || []).map((m2) => " ".repeat(m2.length));
|
|
52
|
-
return x.join("\n");
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const xml = `<xml>\n${cleanedXml}\n</xml>`;
|
|
56
|
-
|
|
57
|
-
if (xml) {
|
|
58
|
-
try {
|
|
59
|
-
const result = XMLValidator.validate(xml, {
|
|
60
|
-
allowBooleanAttributes: true,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
if (result !== true) {
|
|
64
|
-
errors.push(getErrorFromException(result, xml));
|
|
65
|
-
}
|
|
66
|
-
const entryPointXml = parseXml(xml)[0]!;
|
|
67
|
-
|
|
68
|
-
const entryPointSchema = xsdSchema[0]!;
|
|
69
|
-
let pos = 0;
|
|
70
|
-
const lines = cleanedXml.split("\n");
|
|
71
|
-
const getRangeOfElement = (text: string, incrementPosition: boolean = true): Range => {
|
|
72
|
-
if (text === undefined) {
|
|
73
|
-
const monacoPosition = getPositionFromIndex(lines, pos);
|
|
74
|
-
return toRange(
|
|
75
|
-
monacoPosition.lineNumber,
|
|
76
|
-
monacoPosition.column,
|
|
77
|
-
monacoPosition.lineNumber,
|
|
78
|
-
monacoPosition.column + 5
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
const position = cleanedXml.indexOf(text, pos);
|
|
82
|
-
if (incrementPosition) {
|
|
83
|
-
pos = position >= pos ? position + text.length : pos;
|
|
84
|
-
}
|
|
85
|
-
const monacoPosition = getPositionFromIndex(lines, position);
|
|
86
|
-
return toRange(
|
|
87
|
-
monacoPosition.lineNumber,
|
|
88
|
-
monacoPosition.column,
|
|
89
|
-
monacoPosition.lineNumber,
|
|
90
|
-
monacoPosition.column + text.length
|
|
91
|
-
);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const validationErrors = entryPointXml.children.flatMap((child) =>
|
|
95
|
-
validateElements(child, undefined, entryPointSchema, getRangeOfElement)
|
|
96
|
-
);
|
|
97
|
-
errors.push(...validationErrors);
|
|
98
|
-
} catch (e) {
|
|
99
|
-
errors.push(createError(e.message, ErrorType.error, toRange(1, 1, 1, 100)));
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return errors.map((e) => getDecorationsFromError(e));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function validateElements(
|
|
107
|
-
element: XmlElement,
|
|
108
|
-
schemaElement: XmlElement | undefined,
|
|
109
|
-
completeSchema: XmlElement,
|
|
110
|
-
getRangeOfElement: (elementName: string, incrementPosition?: boolean) => Range
|
|
111
|
-
): ReadonlyArray<XmlError> {
|
|
112
|
-
const errors: Array<XmlError> = [];
|
|
113
|
-
|
|
114
|
-
// Validate element name
|
|
115
|
-
const tagName = element.tagName;
|
|
116
|
-
const range = getRangeOfElement(tagName);
|
|
117
|
-
|
|
118
|
-
const slashPosition = getRangeOfElement("/", false);
|
|
119
|
-
const closingTagPosition = getRangeOfElement(">", false);
|
|
120
|
-
const isClosed = rangeLessThan(slashPosition, closingTagPosition);
|
|
121
|
-
|
|
122
|
-
const validElements = Object.values(completeSchema.children);
|
|
123
|
-
const schemaName = schemaElement?.attributes.type || tagName;
|
|
124
|
-
const foundSchemaElement = findElement(validElements, schemaName);
|
|
125
|
-
|
|
126
|
-
if (!foundSchemaElement) {
|
|
127
|
-
return [createError(`"${tagName}" is not a valid element`, ErrorType.error, range)];
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const possibleAttributes = Array.from(foundSchemaElement.children).flatMap((c) =>
|
|
131
|
-
c.tagName === "attribute" ? c : []
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
// Validate required attributes
|
|
135
|
-
for (const possibleAttribute of possibleAttributes) {
|
|
136
|
-
const attributeName = possibleAttribute.attributes.name;
|
|
137
|
-
const isRequired = possibleAttribute.attributes.use;
|
|
138
|
-
if (attributeName && isRequired && isRequired === "required") {
|
|
139
|
-
if (element.attributes[attributeName] === undefined) {
|
|
140
|
-
errors.push(createError(`"${attributeName}" is a required attribute on "${tagName}"`, ErrorType.error, range));
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Validate existing attributes
|
|
146
|
-
for (const [attrKey, attrVal] of Object.entries(element.attributes)) {
|
|
147
|
-
const possibleAttrNames = possibleAttributes.flatMap((p) => p.attributes.name || []);
|
|
148
|
-
const attrText = typeof attrVal === "string" ? `${attrKey}="${attrVal}"` : attrKey;
|
|
149
|
-
const attrRange = getRangeOfElement(attrText, false);
|
|
150
|
-
if (!possibleAttrNames.includes(attrKey)) {
|
|
151
|
-
errors.push(createError(`"${attrKey}" is a not a valid attribute on "${tagName}"`, ErrorType.error, attrRange));
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Validate that the children are allowed as a child of current element
|
|
156
|
-
// and then validate the children themselves
|
|
157
|
-
const schemaChildren = Object.values(foundSchemaElement.children);
|
|
158
|
-
|
|
159
|
-
for (const child of element.children) {
|
|
160
|
-
const childName = child.tagName;
|
|
161
|
-
if (!childName) {
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
const foundChild = findElement(schemaChildren, childName);
|
|
165
|
-
if (!foundChild) {
|
|
166
|
-
const childRange = getRangeOfElement(childName, false);
|
|
167
|
-
if (childRange) {
|
|
168
|
-
errors.push(createError(`"${childName}" is not a valid child of "${tagName}"`, ErrorType.error, childRange));
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const elementErrors = validateElements(child, foundChild, completeSchema, getRangeOfElement);
|
|
173
|
-
errors.push(...elementErrors);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (!isClosed) {
|
|
177
|
-
// Increment position to after closing tag
|
|
178
|
-
getRangeOfElement(`</${tagName}`, true);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return errors;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function getDecorationsFromError(error: XmlError): ErrorObject {
|
|
185
|
-
return {
|
|
186
|
-
range: error.range,
|
|
187
|
-
options: {
|
|
188
|
-
className: getErrorClassNames(error),
|
|
189
|
-
hoverMessage: [{ value: getErrorType(error) }, { value: getErrorMessage(error) }],
|
|
190
|
-
},
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function getErrorFromException(result: ValidationError, xml: string): XmlError {
|
|
195
|
-
const { col, line, msg } = result.err;
|
|
196
|
-
const startLine = line - 1;
|
|
197
|
-
const lines = xml.split("\n");
|
|
198
|
-
const rowText = lines[startLine] || "";
|
|
199
|
-
const length = rowText.indexOf(">") - rowText.indexOf("<") || 4;
|
|
200
|
-
const range = toRange(startLine, col, startLine, col + length);
|
|
201
|
-
|
|
202
|
-
return createError(msg!, ErrorType.error, range);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function getErrorClassNames(error: XmlError): string {
|
|
206
|
-
switch (error.type) {
|
|
207
|
-
case ErrorType.warning:
|
|
208
|
-
return "xml-lint xml-lint--warning";
|
|
209
|
-
case ErrorType.error:
|
|
210
|
-
return "xml-lint xml-lint--error";
|
|
211
|
-
default:
|
|
212
|
-
return "";
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function getErrorType(error: XmlError): string {
|
|
217
|
-
switch (error.type) {
|
|
218
|
-
case ErrorType.warning:
|
|
219
|
-
return "**Warning**";
|
|
220
|
-
case ErrorType.error:
|
|
221
|
-
return "**Error**";
|
|
222
|
-
default:
|
|
223
|
-
return "";
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const getErrorMessage = (error: XmlError): string => error.message.split(/[\t\n]/g)[1] ?? error.message;
|
|
228
|
-
|
|
229
|
-
const createError = (message: string, type: ErrorType, range: Range): XmlError => ({ message, type, range });
|
|
230
|
-
|
|
231
|
-
function getPositionFromIndex(lines: ReadonlyArray<string>, index: number): Position {
|
|
232
|
-
let totalLength = 0;
|
|
233
|
-
for (const [lineNumber, line] of lines.entries()) {
|
|
234
|
-
totalLength += line.length;
|
|
235
|
-
if (totalLength >= index - lineNumber) {
|
|
236
|
-
return {
|
|
237
|
-
lineNumber: lineNumber + 1,
|
|
238
|
-
column: 1 + index - (totalLength - line.length) - lineNumber || 1, // "- lineNumber" because of \n characters
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return { lineNumber: lines.length, column: 1 };
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const toRange = (startLineNumber: number, startColumn: number, endLineNumber: number, endColumn: number): Range => ({
|
|
246
|
-
startLineNumber,
|
|
247
|
-
startColumn,
|
|
248
|
-
endLineNumber,
|
|
249
|
-
endColumn,
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
export function errorToReadableText(errors: ReadonlyArray<ErrorObject>, templateName: string = ""): string {
|
|
253
|
-
const errorLines: Array<string> = [];
|
|
254
|
-
if (templateName) {
|
|
255
|
-
errorLines.push(`Error in template ${templateName} \n`);
|
|
256
|
-
}
|
|
257
|
-
for (const error of errors) {
|
|
258
|
-
const hoverErrors = error.options.hoverMessage.map((e) => e.value.replace(/\*/g, ""));
|
|
259
|
-
errorLines.push(`${hoverErrors.join("\n")}`);
|
|
260
|
-
errorLines.push(`On line ${error.range.startLineNumber}, column ${error.range.startColumn}\n`);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
return errorLines.join("\n");
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function rangeLessThan(range1: Range, range2: Range): boolean {
|
|
267
|
-
return range1.startLineNumber < range2.startLineNumber
|
|
268
|
-
? true
|
|
269
|
-
: range1.startLineNumber > range2.startLineNumber
|
|
270
|
-
? false
|
|
271
|
-
: range1.startColumn < range2.startColumn;
|
|
272
|
-
}
|