@ifc-lite/bcf 1.18.1 → 2.0.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.
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Reading text back out of BCF's XML.
3
+ *
4
+ * Split out of `reader.ts` so the component parsers can share it without a
5
+ * cycle. `writer.ts::escapeXml` is the inverse of `unescapeXml` here, and the
6
+ * two are pinned against each other in `writer.test.ts`.
7
+ */
8
+ /**
9
+ * Extract a simple element value from XML
10
+ *
11
+ * Values are unescaped so writer.ts's escapeXml() round-trips correctly
12
+ * (see escapeXml/unescapeXml regression: & < > " ' in titles/descriptions/
13
+ * comments must come back exactly as written, not as literal entities).
14
+ */
15
+ export declare function extractElement(content: string, elementName: string): string | undefined;
16
+ /**
17
+ * Decode XML character references: the five named entities `escapeXml` writes,
18
+ * and the numeric forms `&#38;` / `&#x26;` that other authoring tools emit.
19
+ *
20
+ * ONE pass, not a chain of `replace` calls. A chain has to decode `&amp;` last,
21
+ * or a literal `&lt;` written as `&amp;lt;` is corrupted into `<` by the
22
+ * earlier pass -- and adding numeric references to a chain reintroduces that
23
+ * hazard from a second direction, since `&#38;lt;` decodes to `&lt;` and would
24
+ * then be re-scanned. A single pass never looks at its own output, so the
25
+ * ordering question does not arise at all.
26
+ *
27
+ * An unrecognised or out-of-range reference is returned untouched rather than
28
+ * dropped: this reads other tools' archives, and losing a character is worse
29
+ * than leaving one encoded.
30
+ */
31
+ export declare function unescapeXml(str: string): string;
32
+ //# sourceMappingURL=xml-text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xml-text.d.ts","sourceRoot":"","sources":["../src/xml-text.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGvF;AAWD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAW/C"}
@@ -0,0 +1,55 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+ /**
5
+ * Reading text back out of BCF's XML.
6
+ *
7
+ * Split out of `reader.ts` so the component parsers can share it without a
8
+ * cycle. `writer.ts::escapeXml` is the inverse of `unescapeXml` here, and the
9
+ * two are pinned against each other in `writer.test.ts`.
10
+ */
11
+ /**
12
+ * Extract a simple element value from XML
13
+ *
14
+ * Values are unescaped so writer.ts's escapeXml() round-trips correctly
15
+ * (see escapeXml/unescapeXml regression: & < > " ' in titles/descriptions/
16
+ * comments must come back exactly as written, not as literal entities).
17
+ */
18
+ export function extractElement(content, elementName) {
19
+ const match = content.match(new RegExp(`<${elementName}>([^<]*)<\\/${elementName}>`));
20
+ return match?.[1] !== undefined ? unescapeXml(match[1]) : undefined;
21
+ }
22
+ /** The five entities `writer.ts::escapeXml` produces. */
23
+ const NAMED_ENTITIES = {
24
+ lt: '<',
25
+ gt: '>',
26
+ quot: '"',
27
+ apos: "'",
28
+ amp: '&',
29
+ };
30
+ /**
31
+ * Decode XML character references: the five named entities `escapeXml` writes,
32
+ * and the numeric forms `&#38;` / `&#x26;` that other authoring tools emit.
33
+ *
34
+ * ONE pass, not a chain of `replace` calls. A chain has to decode `&amp;` last,
35
+ * or a literal `&lt;` written as `&amp;lt;` is corrupted into `<` by the
36
+ * earlier pass -- and adding numeric references to a chain reintroduces that
37
+ * hazard from a second direction, since `&#38;lt;` decodes to `&lt;` and would
38
+ * then be re-scanned. A single pass never looks at its own output, so the
39
+ * ordering question does not arise at all.
40
+ *
41
+ * An unrecognised or out-of-range reference is returned untouched rather than
42
+ * dropped: this reads other tools' archives, and losing a character is worse
43
+ * than leaving one encoded.
44
+ */
45
+ export function unescapeXml(str) {
46
+ return str.replace(/&(?:#(\d+)|#[xX]([0-9a-fA-F]+)|(lt|gt|quot|apos|amp));/g, (whole, dec, hex, name) => {
47
+ if (name !== undefined)
48
+ return NAMED_ENTITIES[name];
49
+ const code = Number.parseInt(dec ?? hex ?? '', dec !== undefined ? 10 : 16);
50
+ return Number.isFinite(code) && code >= 0 && code <= 0x10ffff
51
+ ? String.fromCodePoint(code)
52
+ : whole;
53
+ });
54
+ }
55
+ //# sourceMappingURL=xml-text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xml-text.js","sourceRoot":"","sources":["../src/xml-text.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAE/D;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe,EAAE,WAAmB;IACjE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,IAAI,WAAW,eAAe,WAAW,GAAG,CAAC,CAAC,CAAC;IACtF,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACtE,CAAC;AAED,yDAAyD;AACzD,MAAM,cAAc,GAA2B;IAC7C,EAAE,EAAE,GAAG;IACP,EAAE,EAAE,GAAG;IACP,IAAI,EAAE,GAAG;IACT,IAAI,EAAE,GAAG;IACT,GAAG,EAAE,GAAG;CACT,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,OAAO,GAAG,CAAC,OAAO,CAChB,yDAAyD,EACzD,CAAC,KAAK,EAAE,GAAuB,EAAE,GAAuB,EAAE,IAAwB,EAAE,EAAE;QACpF,IAAI,IAAI,KAAK,SAAS;YAAE,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC;QACpD,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,GAAG,IAAI,EAAE,EAAE,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC5E,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,QAAQ;YAC3D,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC;YAC5B,CAAC,CAAC,KAAK,CAAC;IACZ,CAAC,CACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ifc-lite/bcf",
3
- "version": "1.18.1",
3
+ "version": "2.0.0",
4
4
  "description": "BIM Collaboration Format (BCF) support for IFC-Lite",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -14,11 +14,12 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "jszip": "^3.10.0",
17
- "@ifc-lite/encoding": "^2.0.0"
17
+ "@ifc-lite/encoding": "^2.1.0"
18
18
  },
19
19
  "devDependencies": {
20
20
  "typescript": "^6.0.3",
21
- "vitest": "^4.1.10"
21
+ "vitest": "^4.1.10",
22
+ "xmllint-wasm": "5.3.0"
22
23
  },
23
24
  "license": "MPL-2.0",
24
25
  "author": "Louis True",