@speclynx/apidom-datamodel 4.0.2 → 4.0.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.
- package/CHANGELOG.md +12 -0
- package/package.json +3 -3
- package/src/KeyValuePair.cjs +31 -0
- package/src/KeyValuePair.mjs +27 -0
- package/src/Metadata.cjs +91 -0
- package/src/Metadata.mjs +87 -0
- package/src/Namespace.cjs +212 -0
- package/src/Namespace.mjs +206 -0
- package/src/ObjectSlice.cjs +199 -0
- package/src/ObjectSlice.mjs +195 -0
- package/src/clone/errors/CloneError.cjs +22 -0
- package/src/clone/errors/CloneError.mjs +19 -0
- package/src/clone/errors/DeepCloneError.cjs +11 -0
- package/src/clone/errors/DeepCloneError.mjs +6 -0
- package/src/clone/errors/ShallowCloneError.cjs +11 -0
- package/src/clone/errors/ShallowCloneError.mjs +6 -0
- package/src/clone/index.cjs +188 -0
- package/src/clone/index.mjs +178 -0
- package/src/elements/Annotation.cjs +35 -0
- package/src/elements/Annotation.mjs +30 -0
- package/src/elements/Comment.cjs +18 -0
- package/src/elements/Comment.mjs +13 -0
- package/src/elements/LinkElement.cjs +50 -0
- package/src/elements/LinkElement.mjs +45 -0
- package/src/elements/ParseResult.cjs +91 -0
- package/src/elements/ParseResult.mjs +86 -0
- package/src/elements/RefElement.cjs +34 -0
- package/src/elements/RefElement.mjs +29 -0
- package/src/elements/SourceMap.cjs +140 -0
- package/src/elements/SourceMap.mjs +134 -0
- package/src/elements/Style.cjs +54 -0
- package/src/elements/Style.mjs +48 -0
- package/src/index.cjs +58 -0
- package/src/index.mjs +11 -0
- package/src/predicates/elements.cjs +46 -0
- package/src/predicates/elements.mjs +35 -0
- package/src/predicates/index.cjs +77 -0
- package/src/predicates/index.mjs +56 -0
- package/src/predicates/primitives.cjs +69 -0
- package/src/predicates/primitives.mjs +56 -0
- package/src/primitives/ArrayElement.cjs +155 -0
- package/src/primitives/ArrayElement.mjs +148 -0
- package/src/primitives/BooleanElement.cjs +20 -0
- package/src/primitives/BooleanElement.mjs +15 -0
- package/src/primitives/CollectionElement.cjs +180 -0
- package/src/primitives/CollectionElement.mjs +173 -0
- package/src/primitives/Element.cjs +510 -0
- package/src/primitives/Element.mjs +505 -0
- package/src/primitives/MemberElement.cjs +58 -0
- package/src/primitives/MemberElement.mjs +53 -0
- package/src/primitives/NullElement.cjs +28 -0
- package/src/primitives/NullElement.mjs +23 -0
- package/src/primitives/NumberElement.cjs +20 -0
- package/src/primitives/NumberElement.mjs +15 -0
- package/src/primitives/ObjectElement.cjs +220 -0
- package/src/primitives/ObjectElement.mjs +214 -0
- package/src/primitives/StringElement.cjs +27 -0
- package/src/primitives/StringElement.mjs +22 -0
- package/src/registration.cjs +101 -0
- package/src/registration.mjs +79 -0
- package/src/serialisers/JSONSerialiser.cjs +230 -0
- package/src/serialisers/JSONSerialiser.mjs +221 -0
- package/src/types.cjs +3 -0
- package/src/types.mjs +1 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _StringElement = _interopRequireDefault(require("../primitives/StringElement.cjs"));
|
|
7
|
+
/**
|
|
8
|
+
* Shape with optional source position properties.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* SourceMapElement stores source position as a compact VLQ-encoded string.
|
|
14
|
+
*
|
|
15
|
+
* The encoded string contains 6 values: startLine, startCharacter, startOffset,
|
|
16
|
+
* endLine, endCharacter, endOffset. All values use UTF-16 code units,
|
|
17
|
+
* compatible with LSP, TextDocument, and JavaScript string indexing.
|
|
18
|
+
*
|
|
19
|
+
* web-tree-sitter automatically provides position data in UTF-16 code units.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
class SourceMapElement extends _StringElement.default {
|
|
24
|
+
constructor(content, meta, attributes) {
|
|
25
|
+
super(content, meta, attributes);
|
|
26
|
+
this.element = 'sourceMap';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Transfers source position properties from one object to another.
|
|
31
|
+
*/
|
|
32
|
+
static transfer(from, to) {
|
|
33
|
+
to.startLine = from.startLine;
|
|
34
|
+
to.startCharacter = from.startCharacter;
|
|
35
|
+
to.startOffset = from.startOffset;
|
|
36
|
+
to.endLine = from.endLine;
|
|
37
|
+
to.endCharacter = from.endCharacter;
|
|
38
|
+
to.endOffset = from.endOffset;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Creates a SourceMapElement from source position properties.
|
|
43
|
+
* Returns undefined if any position property is not a number.
|
|
44
|
+
* Also assigns position properties to the instance for inspection.
|
|
45
|
+
*/
|
|
46
|
+
static from(source) {
|
|
47
|
+
const {
|
|
48
|
+
startLine,
|
|
49
|
+
startCharacter,
|
|
50
|
+
startOffset,
|
|
51
|
+
endLine,
|
|
52
|
+
endCharacter,
|
|
53
|
+
endOffset
|
|
54
|
+
} = source;
|
|
55
|
+
if (typeof startLine !== 'number' || typeof startCharacter !== 'number' || typeof startOffset !== 'number' || typeof endLine !== 'number' || typeof endCharacter !== 'number' || typeof endOffset !== 'number') {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const packed = packSourceMap([startLine, startCharacter, startOffset, endLine, endCharacter, endOffset]);
|
|
59
|
+
const sourceMap = new SourceMapElement(packed);
|
|
60
|
+
sourceMap.startLine = startLine;
|
|
61
|
+
sourceMap.startCharacter = startCharacter;
|
|
62
|
+
sourceMap.startOffset = startOffset;
|
|
63
|
+
sourceMap.endLine = endLine;
|
|
64
|
+
sourceMap.endCharacter = endCharacter;
|
|
65
|
+
sourceMap.endOffset = endOffset;
|
|
66
|
+
return sourceMap;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Decodes the VLQ string and applies source position properties to the target.
|
|
71
|
+
*/
|
|
72
|
+
applyTo(target) {
|
|
73
|
+
if (!this.content) return;
|
|
74
|
+
[target.startLine, target.startCharacter, target.startOffset, target.endLine, target.endCharacter, target.endOffset] = unpackSourceMap(this.content);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const BASE64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
78
|
+
|
|
79
|
+
// Encode one unsigned integer to Base64-VLQ
|
|
80
|
+
function vlqEncodeInt(value) {
|
|
81
|
+
let vlq = value >>> 0; // ensure unsigned 32-bit
|
|
82
|
+
let out = '';
|
|
83
|
+
do {
|
|
84
|
+
let digit = vlq & 31; // 5 bits
|
|
85
|
+
vlq >>>= 5;
|
|
86
|
+
if (vlq !== 0) digit |= 32; // continuation bit
|
|
87
|
+
out += BASE64[digit];
|
|
88
|
+
} while (vlq !== 0);
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Decode one unsigned integer from Base64-VLQ, starting at `index`
|
|
93
|
+
function vlqDecodeInt(str, index = 0) {
|
|
94
|
+
let result = 0;
|
|
95
|
+
let shift = 0;
|
|
96
|
+
let i = index;
|
|
97
|
+
while (true) {
|
|
98
|
+
const ch = str[i++];
|
|
99
|
+
const digit = BASE64.indexOf(ch);
|
|
100
|
+
if (digit === -1) throw new Error(`Invalid Base64 VLQ char: ${ch}`);
|
|
101
|
+
const cont = (digit & 32) !== 0;
|
|
102
|
+
result |= (digit & 31) << shift;
|
|
103
|
+
shift += 5;
|
|
104
|
+
if (!cont) break;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
value: result >>> 0,
|
|
108
|
+
next: i
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Span of 6 position values: [startLine, startCharacter, startOffset, endLine, endCharacter, endOffset]
|
|
114
|
+
* @public
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Encodes 6 position values into a compact VLQ string.
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
121
|
+
function packSourceMap(v) {
|
|
122
|
+
return 'sm1:' + v.map(vlqEncodeInt).join('');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Decodes a VLQ string into 6 position values.
|
|
127
|
+
* @public
|
|
128
|
+
*/
|
|
129
|
+
function unpackSourceMap(packed) {
|
|
130
|
+
const s = packed.startsWith('sm1:') ? packed.slice(4) : packed;
|
|
131
|
+
const out = [];
|
|
132
|
+
let i = 0;
|
|
133
|
+
for (let k = 0; k < 6; k++) {
|
|
134
|
+
const r = vlqDecodeInt(s, i);
|
|
135
|
+
out.push(r.value);
|
|
136
|
+
i = r.next;
|
|
137
|
+
}
|
|
138
|
+
return out;
|
|
139
|
+
}
|
|
140
|
+
var _default = exports.default = SourceMapElement;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import StringElement from "../primitives/StringElement.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Shape with optional source position properties.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* SourceMapElement stores source position as a compact VLQ-encoded string.
|
|
8
|
+
*
|
|
9
|
+
* The encoded string contains 6 values: startLine, startCharacter, startOffset,
|
|
10
|
+
* endLine, endCharacter, endOffset. All values use UTF-16 code units,
|
|
11
|
+
* compatible with LSP, TextDocument, and JavaScript string indexing.
|
|
12
|
+
*
|
|
13
|
+
* web-tree-sitter automatically provides position data in UTF-16 code units.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
class SourceMapElement extends StringElement {
|
|
18
|
+
constructor(content, meta, attributes) {
|
|
19
|
+
super(content, meta, attributes);
|
|
20
|
+
this.element = 'sourceMap';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Transfers source position properties from one object to another.
|
|
25
|
+
*/
|
|
26
|
+
static transfer(from, to) {
|
|
27
|
+
to.startLine = from.startLine;
|
|
28
|
+
to.startCharacter = from.startCharacter;
|
|
29
|
+
to.startOffset = from.startOffset;
|
|
30
|
+
to.endLine = from.endLine;
|
|
31
|
+
to.endCharacter = from.endCharacter;
|
|
32
|
+
to.endOffset = from.endOffset;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Creates a SourceMapElement from source position properties.
|
|
37
|
+
* Returns undefined if any position property is not a number.
|
|
38
|
+
* Also assigns position properties to the instance for inspection.
|
|
39
|
+
*/
|
|
40
|
+
static from(source) {
|
|
41
|
+
const {
|
|
42
|
+
startLine,
|
|
43
|
+
startCharacter,
|
|
44
|
+
startOffset,
|
|
45
|
+
endLine,
|
|
46
|
+
endCharacter,
|
|
47
|
+
endOffset
|
|
48
|
+
} = source;
|
|
49
|
+
if (typeof startLine !== 'number' || typeof startCharacter !== 'number' || typeof startOffset !== 'number' || typeof endLine !== 'number' || typeof endCharacter !== 'number' || typeof endOffset !== 'number') {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
const packed = packSourceMap([startLine, startCharacter, startOffset, endLine, endCharacter, endOffset]);
|
|
53
|
+
const sourceMap = new SourceMapElement(packed);
|
|
54
|
+
sourceMap.startLine = startLine;
|
|
55
|
+
sourceMap.startCharacter = startCharacter;
|
|
56
|
+
sourceMap.startOffset = startOffset;
|
|
57
|
+
sourceMap.endLine = endLine;
|
|
58
|
+
sourceMap.endCharacter = endCharacter;
|
|
59
|
+
sourceMap.endOffset = endOffset;
|
|
60
|
+
return sourceMap;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Decodes the VLQ string and applies source position properties to the target.
|
|
65
|
+
*/
|
|
66
|
+
applyTo(target) {
|
|
67
|
+
if (!this.content) return;
|
|
68
|
+
[target.startLine, target.startCharacter, target.startOffset, target.endLine, target.endCharacter, target.endOffset] = unpackSourceMap(this.content);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const BASE64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
72
|
+
|
|
73
|
+
// Encode one unsigned integer to Base64-VLQ
|
|
74
|
+
function vlqEncodeInt(value) {
|
|
75
|
+
let vlq = value >>> 0; // ensure unsigned 32-bit
|
|
76
|
+
let out = '';
|
|
77
|
+
do {
|
|
78
|
+
let digit = vlq & 31; // 5 bits
|
|
79
|
+
vlq >>>= 5;
|
|
80
|
+
if (vlq !== 0) digit |= 32; // continuation bit
|
|
81
|
+
out += BASE64[digit];
|
|
82
|
+
} while (vlq !== 0);
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Decode one unsigned integer from Base64-VLQ, starting at `index`
|
|
87
|
+
function vlqDecodeInt(str, index = 0) {
|
|
88
|
+
let result = 0;
|
|
89
|
+
let shift = 0;
|
|
90
|
+
let i = index;
|
|
91
|
+
while (true) {
|
|
92
|
+
const ch = str[i++];
|
|
93
|
+
const digit = BASE64.indexOf(ch);
|
|
94
|
+
if (digit === -1) throw new Error(`Invalid Base64 VLQ char: ${ch}`);
|
|
95
|
+
const cont = (digit & 32) !== 0;
|
|
96
|
+
result |= (digit & 31) << shift;
|
|
97
|
+
shift += 5;
|
|
98
|
+
if (!cont) break;
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
value: result >>> 0,
|
|
102
|
+
next: i
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Span of 6 position values: [startLine, startCharacter, startOffset, endLine, endCharacter, endOffset]
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Encodes 6 position values into a compact VLQ string.
|
|
113
|
+
* @public
|
|
114
|
+
*/
|
|
115
|
+
function packSourceMap(v) {
|
|
116
|
+
return 'sm1:' + v.map(vlqEncodeInt).join('');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Decodes a VLQ string into 6 position values.
|
|
121
|
+
* @public
|
|
122
|
+
*/
|
|
123
|
+
function unpackSourceMap(packed) {
|
|
124
|
+
const s = packed.startsWith('sm1:') ? packed.slice(4) : packed;
|
|
125
|
+
const out = [];
|
|
126
|
+
let i = 0;
|
|
127
|
+
for (let k = 0; k < 6; k++) {
|
|
128
|
+
const r = vlqDecodeInt(s, i);
|
|
129
|
+
out.push(r.value);
|
|
130
|
+
i = r.next;
|
|
131
|
+
}
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
export default SourceMapElement;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _ObjectElement = _interopRequireDefault(require("../primitives/ObjectElement.cjs"));
|
|
7
|
+
/**
|
|
8
|
+
* Shape with optional style property.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* StyleElement stores format-specific style information for round-trip preservation.
|
|
14
|
+
*
|
|
15
|
+
* The style data is stored as a plain object with format-specific namespaces
|
|
16
|
+
* (e.g., `yaml`, `json`). This element exists only during serialization/deserialization
|
|
17
|
+
* (refract format) - in memory, style lives directly on `element.style`.
|
|
18
|
+
*
|
|
19
|
+
* Follows the same pattern as SourceMapElement with __mappings__.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
class StyleElement extends _ObjectElement.default {
|
|
24
|
+
constructor(content, meta, attributes) {
|
|
25
|
+
super(content, meta, attributes);
|
|
26
|
+
this.element = '__styles__';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Transfers style property from one element to another.
|
|
31
|
+
*/
|
|
32
|
+
static transfer(from, to) {
|
|
33
|
+
to.style = from.style;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creates a StyleElement from an element's style property.
|
|
38
|
+
* Returns undefined if the element has no style.
|
|
39
|
+
*/
|
|
40
|
+
static from(source) {
|
|
41
|
+
if (!source.style) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
return new StyleElement(source.style);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Restores the style property on the target element from this StyleElement.
|
|
49
|
+
*/
|
|
50
|
+
applyTo(target) {
|
|
51
|
+
target.style = this.toValue();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
var _default = exports.default = StyleElement;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import ObjectElement from "../primitives/ObjectElement.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Shape with optional style property.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* StyleElement stores format-specific style information for round-trip preservation.
|
|
8
|
+
*
|
|
9
|
+
* The style data is stored as a plain object with format-specific namespaces
|
|
10
|
+
* (e.g., `yaml`, `json`). This element exists only during serialization/deserialization
|
|
11
|
+
* (refract format) - in memory, style lives directly on `element.style`.
|
|
12
|
+
*
|
|
13
|
+
* Follows the same pattern as SourceMapElement with __mappings__.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
class StyleElement extends ObjectElement {
|
|
18
|
+
constructor(content, meta, attributes) {
|
|
19
|
+
super(content, meta, attributes);
|
|
20
|
+
this.element = '__styles__';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Transfers style property from one element to another.
|
|
25
|
+
*/
|
|
26
|
+
static transfer(from, to) {
|
|
27
|
+
to.style = from.style;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates a StyleElement from an element's style property.
|
|
32
|
+
* Returns undefined if the element has no style.
|
|
33
|
+
*/
|
|
34
|
+
static from(source) {
|
|
35
|
+
if (!source.style) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
return new StyleElement(source.style);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Restores the style property on the target element from this StyleElement.
|
|
43
|
+
*/
|
|
44
|
+
applyTo(target) {
|
|
45
|
+
target.style = this.toValue();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export default StyleElement;
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.refract = exports.isStringElement = exports.isSourceMapElement = exports.isRefElement = exports.isPrimitiveElement = exports.isParseResultElement = exports.isObjectElement = exports.isNumberElement = exports.isNullElement = exports.isMemberElement = exports.isLinkElement = exports.isElement = exports.isCommentElement = exports.isBooleanElement = exports.isArrayElement = exports.isAnnotationElement = exports.includesSymbols = exports.includesClasses = exports.hasElementStyle = exports.hasElementSourceMap = exports.cloneShallow = exports.cloneDeep = exports.StyleElement = exports.StringElement = exports.SourceMapElement = exports.ShallowCloneError = exports.RefElement = exports.ParseResultElement = exports.ObjectSlice = exports.ObjectElement = exports.NumberElement = exports.NullElement = exports.Namespace = exports.Metadata = exports.MemberElement = exports.LinkElement = exports.KeyValuePair = exports.JSONSerialiser = exports.Element = exports.DeepCloneError = exports.CommentElement = exports.CollectionElement = exports.CloneError = exports.BooleanElement = exports.ArrayElement = exports.AnnotationElement = void 0;
|
|
6
|
+
var _Namespace = _interopRequireDefault(require("./Namespace.cjs"));
|
|
7
|
+
exports.Namespace = _Namespace.default;
|
|
8
|
+
var _KeyValuePair = _interopRequireDefault(require("./KeyValuePair.cjs"));
|
|
9
|
+
exports.KeyValuePair = _KeyValuePair.default;
|
|
10
|
+
var _Metadata = _interopRequireDefault(require("./Metadata.cjs"));
|
|
11
|
+
exports.Metadata = _Metadata.default;
|
|
12
|
+
var _index = require("./clone/index.cjs");
|
|
13
|
+
exports.cloneShallow = _index.cloneShallow;
|
|
14
|
+
exports.cloneDeep = _index.cloneDeep;
|
|
15
|
+
exports.CloneError = _index.CloneError;
|
|
16
|
+
exports.DeepCloneError = _index.DeepCloneError;
|
|
17
|
+
exports.ShallowCloneError = _index.ShallowCloneError;
|
|
18
|
+
var _registration = require("./registration.cjs");
|
|
19
|
+
exports.ObjectSlice = _registration.ObjectSlice;
|
|
20
|
+
exports.Element = _registration.Element;
|
|
21
|
+
exports.CollectionElement = _registration.CollectionElement;
|
|
22
|
+
exports.StringElement = _registration.StringElement;
|
|
23
|
+
exports.NumberElement = _registration.NumberElement;
|
|
24
|
+
exports.BooleanElement = _registration.BooleanElement;
|
|
25
|
+
exports.NullElement = _registration.NullElement;
|
|
26
|
+
exports.ArrayElement = _registration.ArrayElement;
|
|
27
|
+
exports.ObjectElement = _registration.ObjectElement;
|
|
28
|
+
exports.MemberElement = _registration.MemberElement;
|
|
29
|
+
exports.RefElement = _registration.RefElement;
|
|
30
|
+
exports.LinkElement = _registration.LinkElement;
|
|
31
|
+
exports.AnnotationElement = _registration.AnnotationElement;
|
|
32
|
+
exports.CommentElement = _registration.CommentElement;
|
|
33
|
+
exports.ParseResultElement = _registration.ParseResultElement;
|
|
34
|
+
exports.SourceMapElement = _registration.SourceMapElement;
|
|
35
|
+
exports.StyleElement = _registration.StyleElement;
|
|
36
|
+
exports.refract = _registration.refract;
|
|
37
|
+
var _JSONSerialiser = _interopRequireDefault(require("./serialisers/JSONSerialiser.cjs"));
|
|
38
|
+
exports.JSONSerialiser = _JSONSerialiser.default;
|
|
39
|
+
var _index2 = require("./predicates/index.cjs");
|
|
40
|
+
exports.isElement = _index2.isElement;
|
|
41
|
+
exports.isStringElement = _index2.isStringElement;
|
|
42
|
+
exports.isNumberElement = _index2.isNumberElement;
|
|
43
|
+
exports.isNullElement = _index2.isNullElement;
|
|
44
|
+
exports.isBooleanElement = _index2.isBooleanElement;
|
|
45
|
+
exports.isObjectElement = _index2.isObjectElement;
|
|
46
|
+
exports.isArrayElement = _index2.isArrayElement;
|
|
47
|
+
exports.isMemberElement = _index2.isMemberElement;
|
|
48
|
+
exports.isLinkElement = _index2.isLinkElement;
|
|
49
|
+
exports.isRefElement = _index2.isRefElement;
|
|
50
|
+
exports.isAnnotationElement = _index2.isAnnotationElement;
|
|
51
|
+
exports.isCommentElement = _index2.isCommentElement;
|
|
52
|
+
exports.isParseResultElement = _index2.isParseResultElement;
|
|
53
|
+
exports.isSourceMapElement = _index2.isSourceMapElement;
|
|
54
|
+
exports.isPrimitiveElement = _index2.isPrimitiveElement;
|
|
55
|
+
exports.hasElementStyle = _index2.hasElementStyle;
|
|
56
|
+
exports.hasElementSourceMap = _index2.hasElementSourceMap;
|
|
57
|
+
exports.includesSymbols = _index2.includesSymbols;
|
|
58
|
+
exports.includesClasses = _index2.includesClasses;
|
package/src/index.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { default as Namespace } from "./Namespace.mjs";
|
|
2
|
+
export { default as KeyValuePair } from "./KeyValuePair.mjs";
|
|
3
|
+
export { default as Metadata } from "./Metadata.mjs"; // Clone utilities
|
|
4
|
+
export { cloneShallow, cloneDeep, CloneError, DeepCloneError, ShallowCloneError } from "./clone/index.mjs";
|
|
5
|
+
// Re-export elements directly to preserve JSDoc
|
|
6
|
+
export { ObjectSlice, Element, CollectionElement, StringElement, NumberElement, BooleanElement, NullElement, ArrayElement, ObjectElement, MemberElement, RefElement, LinkElement, AnnotationElement, CommentElement, ParseResultElement, SourceMapElement, StyleElement, refract } from "./registration.mjs";
|
|
7
|
+
export { default as JSONSerialiser } from "./serialisers/JSONSerialiser.mjs"; // Re-export types - essential public API
|
|
8
|
+
// Re-export types - for advanced users extending the library
|
|
9
|
+
// Re-export types - used in public method signatures
|
|
10
|
+
// Re-export predicates
|
|
11
|
+
export { isElement, isStringElement, isNumberElement, isNullElement, isBooleanElement, isObjectElement, isArrayElement, isMemberElement, isLinkElement, isRefElement, isAnnotationElement, isCommentElement, isParseResultElement, isSourceMapElement, isPrimitiveElement, hasElementStyle, hasElementSourceMap, includesSymbols, includesClasses } from "./predicates/index.mjs";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.isSourceMapElement = exports.isRefElement = exports.isParseResultElement = exports.isLinkElement = exports.isCommentElement = exports.isAnnotationElement = void 0;
|
|
6
|
+
var _LinkElement = _interopRequireDefault(require("../elements/LinkElement.cjs"));
|
|
7
|
+
var _RefElement = _interopRequireDefault(require("../elements/RefElement.cjs"));
|
|
8
|
+
var _Annotation = _interopRequireDefault(require("../elements/Annotation.cjs"));
|
|
9
|
+
var _Comment = _interopRequireDefault(require("../elements/Comment.cjs"));
|
|
10
|
+
var _ParseResult = _interopRequireDefault(require("../elements/ParseResult.cjs"));
|
|
11
|
+
var _SourceMap = _interopRequireDefault(require("../elements/SourceMap.cjs"));
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
const isLinkElement = element => element instanceof _LinkElement.default;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
exports.isLinkElement = isLinkElement;
|
|
21
|
+
const isRefElement = element => element instanceof _RefElement.default;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
exports.isRefElement = isRefElement;
|
|
27
|
+
const isAnnotationElement = element => element instanceof _Annotation.default;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
exports.isAnnotationElement = isAnnotationElement;
|
|
33
|
+
const isCommentElement = element => element instanceof _Comment.default;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
exports.isCommentElement = isCommentElement;
|
|
39
|
+
const isParseResultElement = element => element instanceof _ParseResult.default;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
exports.isParseResultElement = isParseResultElement;
|
|
45
|
+
const isSourceMapElement = element => element instanceof _SourceMap.default;
|
|
46
|
+
exports.isSourceMapElement = isSourceMapElement;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import LinkElement from "../elements/LinkElement.mjs";
|
|
2
|
+
import RefElement from "../elements/RefElement.mjs";
|
|
3
|
+
import AnnotationElement from "../elements/Annotation.mjs";
|
|
4
|
+
import CommentElement from "../elements/Comment.mjs";
|
|
5
|
+
import ParseResultElement from "../elements/ParseResult.mjs";
|
|
6
|
+
import SourceMapElement from "../elements/SourceMap.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export const isLinkElement = element => element instanceof LinkElement;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export const isRefElement = element => element instanceof RefElement;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export const isAnnotationElement = element => element instanceof AnnotationElement;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export const isCommentElement = element => element instanceof CommentElement;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export const isParseResultElement = element => element instanceof ParseResultElement;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export const isSourceMapElement = element => element instanceof SourceMapElement;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.isStringElement = exports.isSourceMapElement = exports.isRefElement = exports.isPrimitiveElement = exports.isParseResultElement = exports.isObjectElement = exports.isNumberElement = exports.isNullElement = exports.isMemberElement = exports.isLinkElement = exports.isCommentElement = exports.isBooleanElement = exports.isAnnotationElement = exports.includesSymbols = exports.includesClasses = exports.hasElementStyle = exports.hasElementSourceMap = void 0;
|
|
5
|
+
var _primitives = require("./primitives.cjs");
|
|
6
|
+
exports.isArrayElement = _primitives.isArrayElement;
|
|
7
|
+
exports.isElement = _primitives.isElement;
|
|
8
|
+
exports.isStringElement = _primitives.isStringElement;
|
|
9
|
+
exports.isNumberElement = _primitives.isNumberElement;
|
|
10
|
+
exports.isNullElement = _primitives.isNullElement;
|
|
11
|
+
exports.isBooleanElement = _primitives.isBooleanElement;
|
|
12
|
+
exports.isObjectElement = _primitives.isObjectElement;
|
|
13
|
+
exports.isMemberElement = _primitives.isMemberElement;
|
|
14
|
+
exports.isPrimitiveElement = _primitives.isPrimitiveElement;
|
|
15
|
+
var _elements = require("./elements.cjs");
|
|
16
|
+
exports.isLinkElement = _elements.isLinkElement;
|
|
17
|
+
exports.isRefElement = _elements.isRefElement;
|
|
18
|
+
exports.isAnnotationElement = _elements.isAnnotationElement;
|
|
19
|
+
exports.isCommentElement = _elements.isCommentElement;
|
|
20
|
+
exports.isParseResultElement = _elements.isParseResultElement;
|
|
21
|
+
exports.isSourceMapElement = _elements.isSourceMapElement;
|
|
22
|
+
/**
|
|
23
|
+
* Checks if an element has format-specific style information.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
const hasElementStyle = element => {
|
|
27
|
+
return element.style !== undefined;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Checks if an element has complete source position information.
|
|
32
|
+
* Returns true only if all 6 position properties are numbers.
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
exports.hasElementStyle = hasElementStyle;
|
|
36
|
+
const hasElementSourceMap = element => {
|
|
37
|
+
return typeof element.startLine === 'number' && typeof element.startCharacter === 'number' && typeof element.startOffset === 'number' && typeof element.endLine === 'number' && typeof element.endCharacter === 'number' && typeof element.endOffset === 'number';
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
exports.hasElementSourceMap = hasElementSourceMap;
|
|
44
|
+
const includesSymbols = (element, symbols) => {
|
|
45
|
+
if (symbols.length === 0) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
if (!element.hasAttributesProperty('symbols')) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const elementSymbols = element.attributes.get('symbols');
|
|
52
|
+
if (!(0, _primitives.isArrayElement)(elementSymbols)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return symbols.every(symbol => elementSymbols.includes(symbol));
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
exports.includesSymbols = includesSymbols;
|
|
62
|
+
const includesClasses = (element, classes) => {
|
|
63
|
+
if (classes.length === 0) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
if (!(0, _primitives.isElement)(element)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
if (element.isMetaEmpty) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
if (!element.hasMetaProperty('classes')) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
return classes.every(cls => element.classes.includes(cls));
|
|
76
|
+
};
|
|
77
|
+
exports.includesClasses = includesClasses;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { isArrayElement, isElement } from "./primitives.mjs";
|
|
2
|
+
export { isStringElement, isNumberElement, isNullElement, isBooleanElement, isArrayElement, isObjectElement, isMemberElement, isPrimitiveElement } from "./primitives.mjs";
|
|
3
|
+
export { isElement };
|
|
4
|
+
export { isLinkElement, isRefElement, isAnnotationElement, isCommentElement, isParseResultElement, isSourceMapElement } from "./elements.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* Checks if an element has format-specific style information.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export const hasElementStyle = element => {
|
|
10
|
+
return element.style !== undefined;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Checks if an element has complete source position information.
|
|
15
|
+
* Returns true only if all 6 position properties are numbers.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export const hasElementSourceMap = element => {
|
|
19
|
+
return typeof element.startLine === 'number' && typeof element.startCharacter === 'number' && typeof element.startOffset === 'number' && typeof element.endLine === 'number' && typeof element.endCharacter === 'number' && typeof element.endOffset === 'number';
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export const includesSymbols = (element, symbols) => {
|
|
26
|
+
if (symbols.length === 0) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
if (!element.hasAttributesProperty('symbols')) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const elementSymbols = element.attributes.get('symbols');
|
|
33
|
+
if (!isArrayElement(elementSymbols)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return symbols.every(symbol => elementSymbols.includes(symbol));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export const includesClasses = (element, classes) => {
|
|
43
|
+
if (classes.length === 0) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
if (!isElement(element)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (element.isMetaEmpty) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (!element.hasMetaProperty('classes')) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return classes.every(cls => element.classes.includes(cls));
|
|
56
|
+
};
|