@iebh/reflib 2.3.2 → 2.3.4

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,38 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "type": "node",
6
+ "request": "launch",
7
+ "name": "Debug Vite Server",
8
+ "runtimeExecutable": "/home/connor/.nvm/versions/node/v20.12.2/bin/npm",
9
+ "runtimeArgs": ["run", "dev"],
10
+ "cwd": "${workspaceFolder}/test/browser",
11
+ "console": "integratedTerminal",
12
+ "env": {
13
+ "VITE_DEV_SERVER_URL": "http://localhost:3000"
14
+ }
15
+ },
16
+ {
17
+ "name": "Debug in Chrome",
18
+ "type": "chrome",
19
+ "request": "launch",
20
+ "url": "http://localhost:3000",
21
+ "webRoot": "${workspaceFolder}",
22
+ "sourceMaps": true,
23
+ "sourceMapPathOverrides": {
24
+ "/__vite-root/*": "${webRoot}/*",
25
+ "/@fs/*": "*",
26
+ "/@vite-root/*": "${webRoot}/*",
27
+ "/src/*": "${webRoot}/src/*",
28
+ "/modules/*": "${webRoot}/modules/*"
29
+ }
30
+ }
31
+ ],
32
+ "compounds": [
33
+ {
34
+ "name": "Debug Vite + Chrome",
35
+ "configurations": ["Debug Vite Server", "Debug in Chrome"]
36
+ }
37
+ ]
38
+ }
@@ -1,56 +1,52 @@
1
- import camelCase from '../../shared/camelCase.js';
2
1
  import Emitter from '../../shared/emitter.js';
2
+ import CacxParser from '@iebh/cacx';
3
3
 
4
4
  export class WritableStream {
5
- constructor(passedParserOptions) {
6
- // Stores XML in text form once read
7
- this.text = "";
8
- this.emitter = Emitter();
9
- // Add event listeners to mimic htmlparser2 behavior in the browser
10
- this.emitter.on('opentag', passedParserOptions.onopentag);
11
- this.emitter.on('closetag', passedParserOptions.onclosetag);
12
- this.emitter.on('text', passedParserOptions.ontext);
13
- this.emitter.on('end', passedParserOptions.onend);
14
- }
15
-
16
- write(data) {
17
- // CF: TODO: Parse data as it comes in chunks for better memory efficiency
18
- this.text += data;
19
- }
20
-
21
- end() {
22
- this.parseXML(this.text);
23
- // Free memory
24
- this.text = ''
25
- this.emitter.emit('end');
26
- }
27
-
28
- parseXML(xmlString) {
29
- let parser = new DOMParser();
30
- let doc = parser.parseFromString(xmlString, 'application/xml');
31
- this.traverseNode(doc.documentElement);
32
- }
33
-
34
- traverseNode(node) {
35
- if (node.nodeType === Node.ELEMENT_NODE) {
36
- let name = camelCase(node.nodeName);
37
- let attrs = Array.from(node.attributes).reduce((acc, attr) => {
38
- acc[attr.name] = attr.value;
39
- return acc;
40
- }, {});
41
-
42
- this.emitter.emit('opentag', name, attrs);
43
-
44
- for (let child of node.childNodes) {
45
- this.traverseNode(child);
46
- }
47
-
48
- this.emitter.emit('closetag', name);
49
- } else if (node.nodeType === Node.TEXT_NODE) {
50
- let text = node.nodeValue.trim();
51
- if (text) {
52
- this.emitter.emit('text', text);
53
- }
54
- }
55
- }
5
+ constructor(passedParserOptions) {
6
+ this.emitter = Emitter();
7
+ this.parser = new CacxParser({
8
+ collect: false,
9
+ onTagOpen: (node) => {
10
+ console.log(node.tag, node.attrs);
11
+ const name = node.tag;
12
+ const attrs = node.attrs || {};
13
+ this.emitter.emit('opentag', name, attrs);
14
+ },
15
+ onTagClose: (node) => {
16
+ const name = node.tag;
17
+ // Emit text event before closing the tag
18
+ if (node.text && node.text.trim()) {
19
+ this.emitter.emit('text', node.text.trim());
20
+ }
21
+ this.emitter.emit('closetag', name);
22
+ },
23
+ flattenText: false,
24
+ keyText: 'text',
25
+ keyAttrs: 'attrs',
26
+ });
27
+
28
+ // Add event listeners to mimic htmlparser2 behavior
29
+ this.emitter.on('opentag', passedParserOptions.onopentag);
30
+ this.emitter.on('closetag', passedParserOptions.onclosetag);
31
+ this.emitter.on('text', passedParserOptions.ontext);
32
+ this.emitter.on('end', passedParserOptions.onend);
33
+ }
34
+
35
+ write(data) {
36
+ this.parser.append(data).exec();
37
+ }
38
+
39
+ end() {
40
+ // Process any remaining data
41
+ this.parser.exec();
42
+
43
+ // Emit text event for the last node if it has text
44
+ const lastNode = this.parser.stack.at(-1);
45
+ if (lastNode && lastNode.text && lastNode.text.trim()) {
46
+ this.emitter.emit('text', lastNode.text.trim());
47
+ }
48
+
49
+ // Emit end event
50
+ this.emitter.emit('end');
51
+ }
56
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iebh/reflib",
3
- "version": "2.3.2",
3
+ "version": "2.3.4",
4
4
  "description": "Reference / Citation reference library utilities",
5
5
  "scripts": {
6
6
  "lint": "eslint lib modules shared test",
@@ -53,6 +53,7 @@
53
53
  "vite-plugin-replace": "^0.1.1"
54
54
  },
55
55
  "dependencies": {
56
+ "@iebh/cacx": "^1.0.0",
56
57
  "htmlparser2": "^9.0.0",
57
58
  "JSONStream": "^1.3.5",
58
59
  "mitt": "^3.0.1"