@adeu/core 1.6.2 → 1.6.5
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/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +38 -38
- package/src/comments.test.ts +37 -37
- package/src/comments.ts +450 -450
- package/src/diff.test.ts +61 -61
- package/src/diff.ts +250 -250
- package/src/docx/bridge.ts +188 -188
- package/src/docx/dom.ts +53 -53
- package/src/docx/primitives.ts +64 -64
- package/src/domain.ts +10 -10
- package/src/engine.atomic.test.ts +57 -57
- package/src/engine.batch.test.ts +92 -92
- package/src/engine.safety.test.ts +41 -41
- package/src/engine.tables.test.ts +165 -165
- package/src/engine.ts +734 -734
- package/src/index.test.ts +7 -7
- package/src/index.ts +13 -13
- package/src/ingest.test.ts +43 -43
- package/src/ingest.ts +399 -399
- package/src/mapper.test.ts +65 -65
- package/src/mapper.ts +834 -834
- package/src/markup.test.ts +149 -149
- package/src/markup.ts +322 -322
- package/src/models.ts +50 -50
- package/src/outline.ts +376 -376
- package/src/pagination.ts +238 -238
- package/src/test-utils.ts +141 -141
- package/src/utils/docx.ts +477 -477
- package/tsconfig.json +21 -21
- package/tsup.config.ts +9 -9
- package/vitest.config.ts +11 -11
package/src/mapper.test.ts
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { readFileSync } from 'node:fs';
|
|
3
|
-
import { resolve, dirname } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { DocumentObject } from './docx/bridge.js';
|
|
6
|
-
import { DocumentMapper } from './mapper.js';
|
|
7
|
-
|
|
8
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
-
const __dirname = dirname(__filename);
|
|
10
|
-
|
|
11
|
-
describe('Virtual DOM Mapper (Node.js Port)', () => {
|
|
12
|
-
it('should construct a full virtual map from the DOCX', async () => {
|
|
13
|
-
const fixturePath = resolve(__dirname, '../../../../shared/fixtures/golden.docx');
|
|
14
|
-
const buf = readFileSync(fixturePath);
|
|
15
|
-
const doc = await DocumentObject.load(buf);
|
|
16
|
-
|
|
17
|
-
const mapper = new DocumentMapper(doc);
|
|
18
|
-
|
|
19
|
-
// Verify full_text was structurally mapped identically to what `ingest.ts` would produce
|
|
20
|
-
// for the body.
|
|
21
|
-
expect(mapper.full_text).toContain('golden');
|
|
22
|
-
expect(mapper.full_text).toContain('document');
|
|
23
|
-
expect(mapper.spans.length).toBeGreaterThan(0);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should locate target string matches via find_match_index', async () => {
|
|
27
|
-
const fixturePath = resolve(__dirname, '../../../../shared/fixtures/golden.docx');
|
|
28
|
-
const buf = readFileSync(fixturePath);
|
|
29
|
-
const doc = await DocumentObject.load(buf);
|
|
30
|
-
const mapper = new DocumentMapper(doc);
|
|
31
|
-
|
|
32
|
-
// Search for a word we know exists in golden.docx
|
|
33
|
-
const [startIdx, len] = mapper.find_match_index('golden');
|
|
34
|
-
|
|
35
|
-
expect(startIdx).toBeGreaterThan(0);
|
|
36
|
-
expect(len).toBe(6); // 'golden'.length
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should resolve strings back to physical Run elements', async () => {
|
|
40
|
-
const fixturePath = resolve(__dirname, '../../../../shared/fixtures/golden.docx');
|
|
41
|
-
const buf = readFileSync(fixturePath);
|
|
42
|
-
const doc = await DocumentObject.load(buf);
|
|
43
|
-
const mapper = new DocumentMapper(doc);
|
|
44
|
-
|
|
45
|
-
// Find the backing physical Run elements for the target string
|
|
46
|
-
const runs = mapper.find_target_runs('golden');
|
|
47
|
-
|
|
48
|
-
// Ensure we successfully crossed the Virtual DOM boundary
|
|
49
|
-
expect(runs.length).toBeGreaterThan(0);
|
|
50
|
-
expect(runs[0].constructor.name).toBe('Run');
|
|
51
|
-
|
|
52
|
-
// Underneath, the Run must contain the real xmldom Element reference
|
|
53
|
-
expect(runs[0]._element).toBeDefined();
|
|
54
|
-
expect(runs[0]._element.tagName).toBe('w:r');
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should safely return empty arrays for non-existent text', async () => {
|
|
58
|
-
const fixturePath = resolve(__dirname, '../../../../shared/fixtures/golden.docx');
|
|
59
|
-
const buf = readFileSync(fixturePath);
|
|
60
|
-
const doc = await DocumentObject.load(buf);
|
|
61
|
-
const mapper = new DocumentMapper(doc);
|
|
62
|
-
|
|
63
|
-
const runs = mapper.find_target_runs('NON_EXISTENT_TEXT_12345');
|
|
64
|
-
expect(runs.length).toBe(0);
|
|
65
|
-
});
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { resolve, dirname } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { DocumentObject } from './docx/bridge.js';
|
|
6
|
+
import { DocumentMapper } from './mapper.js';
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = dirname(__filename);
|
|
10
|
+
|
|
11
|
+
describe('Virtual DOM Mapper (Node.js Port)', () => {
|
|
12
|
+
it('should construct a full virtual map from the DOCX', async () => {
|
|
13
|
+
const fixturePath = resolve(__dirname, '../../../../shared/fixtures/golden.docx');
|
|
14
|
+
const buf = readFileSync(fixturePath);
|
|
15
|
+
const doc = await DocumentObject.load(buf);
|
|
16
|
+
|
|
17
|
+
const mapper = new DocumentMapper(doc);
|
|
18
|
+
|
|
19
|
+
// Verify full_text was structurally mapped identically to what `ingest.ts` would produce
|
|
20
|
+
// for the body.
|
|
21
|
+
expect(mapper.full_text).toContain('golden');
|
|
22
|
+
expect(mapper.full_text).toContain('document');
|
|
23
|
+
expect(mapper.spans.length).toBeGreaterThan(0);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should locate target string matches via find_match_index', async () => {
|
|
27
|
+
const fixturePath = resolve(__dirname, '../../../../shared/fixtures/golden.docx');
|
|
28
|
+
const buf = readFileSync(fixturePath);
|
|
29
|
+
const doc = await DocumentObject.load(buf);
|
|
30
|
+
const mapper = new DocumentMapper(doc);
|
|
31
|
+
|
|
32
|
+
// Search for a word we know exists in golden.docx
|
|
33
|
+
const [startIdx, len] = mapper.find_match_index('golden');
|
|
34
|
+
|
|
35
|
+
expect(startIdx).toBeGreaterThan(0);
|
|
36
|
+
expect(len).toBe(6); // 'golden'.length
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should resolve strings back to physical Run elements', async () => {
|
|
40
|
+
const fixturePath = resolve(__dirname, '../../../../shared/fixtures/golden.docx');
|
|
41
|
+
const buf = readFileSync(fixturePath);
|
|
42
|
+
const doc = await DocumentObject.load(buf);
|
|
43
|
+
const mapper = new DocumentMapper(doc);
|
|
44
|
+
|
|
45
|
+
// Find the backing physical Run elements for the target string
|
|
46
|
+
const runs = mapper.find_target_runs('golden');
|
|
47
|
+
|
|
48
|
+
// Ensure we successfully crossed the Virtual DOM boundary
|
|
49
|
+
expect(runs.length).toBeGreaterThan(0);
|
|
50
|
+
expect(runs[0].constructor.name).toBe('Run');
|
|
51
|
+
|
|
52
|
+
// Underneath, the Run must contain the real xmldom Element reference
|
|
53
|
+
expect(runs[0]._element).toBeDefined();
|
|
54
|
+
expect(runs[0]._element.tagName).toBe('w:r');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should safely return empty arrays for non-existent text', async () => {
|
|
58
|
+
const fixturePath = resolve(__dirname, '../../../../shared/fixtures/golden.docx');
|
|
59
|
+
const buf = readFileSync(fixturePath);
|
|
60
|
+
const doc = await DocumentObject.load(buf);
|
|
61
|
+
const mapper = new DocumentMapper(doc);
|
|
62
|
+
|
|
63
|
+
const runs = mapper.find_target_runs('NON_EXISTENT_TEXT_12345');
|
|
64
|
+
expect(runs.length).toBe(0);
|
|
65
|
+
});
|
|
66
66
|
});
|