@speclynx/apidom-datamodel 4.0.2 → 4.0.3

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.
Files changed (95) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +4 -5
  3. package/src/KeyValuePair.cjs +31 -0
  4. package/src/KeyValuePair.mjs +27 -0
  5. package/src/KeyValuePair.ts +31 -0
  6. package/src/Metadata.cjs +91 -0
  7. package/src/Metadata.mjs +87 -0
  8. package/src/Metadata.ts +100 -0
  9. package/src/Namespace.cjs +212 -0
  10. package/src/Namespace.mjs +206 -0
  11. package/src/Namespace.ts +260 -0
  12. package/src/ObjectSlice.cjs +199 -0
  13. package/src/ObjectSlice.mjs +195 -0
  14. package/src/ObjectSlice.ts +228 -0
  15. package/src/clone/errors/CloneError.cjs +22 -0
  16. package/src/clone/errors/CloneError.mjs +19 -0
  17. package/src/clone/errors/CloneError.ts +26 -0
  18. package/src/clone/errors/DeepCloneError.cjs +11 -0
  19. package/src/clone/errors/DeepCloneError.mjs +6 -0
  20. package/src/clone/errors/DeepCloneError.ts +8 -0
  21. package/src/clone/errors/ShallowCloneError.cjs +11 -0
  22. package/src/clone/errors/ShallowCloneError.mjs +6 -0
  23. package/src/clone/errors/ShallowCloneError.ts +8 -0
  24. package/src/clone/index.cjs +188 -0
  25. package/src/clone/index.mjs +178 -0
  26. package/src/clone/index.ts +195 -0
  27. package/src/elements/Annotation.cjs +35 -0
  28. package/src/elements/Annotation.mjs +30 -0
  29. package/src/elements/Annotation.ts +35 -0
  30. package/src/elements/Comment.cjs +18 -0
  31. package/src/elements/Comment.mjs +13 -0
  32. package/src/elements/Comment.ts +16 -0
  33. package/src/elements/LinkElement.cjs +50 -0
  34. package/src/elements/LinkElement.mjs +45 -0
  35. package/src/elements/LinkElement.ts +49 -0
  36. package/src/elements/ParseResult.cjs +91 -0
  37. package/src/elements/ParseResult.mjs +86 -0
  38. package/src/elements/ParseResult.ts +94 -0
  39. package/src/elements/RefElement.cjs +34 -0
  40. package/src/elements/RefElement.mjs +29 -0
  41. package/src/elements/RefElement.ts +33 -0
  42. package/src/elements/SourceMap.cjs +140 -0
  43. package/src/elements/SourceMap.mjs +134 -0
  44. package/src/elements/SourceMap.ts +170 -0
  45. package/src/elements/Style.cjs +54 -0
  46. package/src/elements/Style.mjs +48 -0
  47. package/src/elements/Style.ts +56 -0
  48. package/src/index.cjs +58 -0
  49. package/src/index.mjs +11 -0
  50. package/src/index.ts +79 -0
  51. package/src/predicates/elements.cjs +46 -0
  52. package/src/predicates/elements.mjs +35 -0
  53. package/src/predicates/elements.ts +42 -0
  54. package/src/predicates/index.cjs +77 -0
  55. package/src/predicates/index.mjs +56 -0
  56. package/src/predicates/index.ts +89 -0
  57. package/src/predicates/primitives.cjs +69 -0
  58. package/src/predicates/primitives.mjs +56 -0
  59. package/src/predicates/primitives.ts +79 -0
  60. package/src/primitives/ArrayElement.cjs +155 -0
  61. package/src/primitives/ArrayElement.mjs +148 -0
  62. package/src/primitives/ArrayElement.ts +161 -0
  63. package/src/primitives/BooleanElement.cjs +20 -0
  64. package/src/primitives/BooleanElement.mjs +15 -0
  65. package/src/primitives/BooleanElement.ts +18 -0
  66. package/src/primitives/CollectionElement.cjs +180 -0
  67. package/src/primitives/CollectionElement.mjs +173 -0
  68. package/src/primitives/CollectionElement.ts +191 -0
  69. package/src/primitives/Element.cjs +510 -0
  70. package/src/primitives/Element.mjs +505 -0
  71. package/src/primitives/Element.ts +556 -0
  72. package/src/primitives/MemberElement.cjs +58 -0
  73. package/src/primitives/MemberElement.mjs +53 -0
  74. package/src/primitives/MemberElement.ts +61 -0
  75. package/src/primitives/NullElement.cjs +28 -0
  76. package/src/primitives/NullElement.mjs +23 -0
  77. package/src/primitives/NullElement.ts +26 -0
  78. package/src/primitives/NumberElement.cjs +20 -0
  79. package/src/primitives/NumberElement.mjs +15 -0
  80. package/src/primitives/NumberElement.ts +18 -0
  81. package/src/primitives/ObjectElement.cjs +220 -0
  82. package/src/primitives/ObjectElement.mjs +214 -0
  83. package/src/primitives/ObjectElement.ts +263 -0
  84. package/src/primitives/StringElement.cjs +27 -0
  85. package/src/primitives/StringElement.mjs +22 -0
  86. package/src/primitives/StringElement.ts +25 -0
  87. package/src/registration.cjs +101 -0
  88. package/src/registration.mjs +79 -0
  89. package/src/registration.ts +111 -0
  90. package/src/serialisers/JSONSerialiser.cjs +230 -0
  91. package/src/serialisers/JSONSerialiser.mjs +221 -0
  92. package/src/serialisers/JSONSerialiser.ts +295 -0
  93. package/src/types.cjs +3 -0
  94. package/src/types.mjs +1 -0
  95. package/src/types.ts +72 -0
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ exports.__esModule = true;
5
+ exports.cloneShallow = exports.cloneDeep = exports.ShallowCloneError = exports.DeepCloneError = exports.CloneError = void 0;
6
+ var _ramda = require("ramda");
7
+ var _ObjectSlice = _interopRequireDefault(require("../ObjectSlice.cjs"));
8
+ var _KeyValuePair = _interopRequireDefault(require("../KeyValuePair.cjs"));
9
+ var _index = require("../predicates/index.cjs");
10
+ var _SourceMap = _interopRequireDefault(require("../elements/SourceMap.cjs"));
11
+ var _DeepCloneError = _interopRequireDefault(require("./errors/DeepCloneError.cjs"));
12
+ exports.DeepCloneError = _DeepCloneError.default;
13
+ var _ShallowCloneError = _interopRequireDefault(require("./errors/ShallowCloneError.cjs"));
14
+ exports.ShallowCloneError = _ShallowCloneError.default;
15
+ var _CloneError = _interopRequireDefault(require("./errors/CloneError.cjs"));
16
+ exports.CloneError = _CloneError.default;
17
+ /**
18
+ * @public
19
+ */
20
+
21
+ /**
22
+ * @public
23
+ */
24
+
25
+ const cloneDeepElement = (element, options) => {
26
+ const {
27
+ visited = new WeakMap()
28
+ } = options;
29
+ const passThroughOptions = {
30
+ ...options,
31
+ visited
32
+ };
33
+
34
+ // detect cycle and return memoized value
35
+ if (visited.has(element)) {
36
+ return visited.get(element);
37
+ }
38
+ const copy = cloneShallowElement(element);
39
+ visited.set(element, copy);
40
+ const {
41
+ content
42
+ } = element;
43
+ if (Array.isArray(content)) {
44
+ copy.content = content.map(el => cloneDeepElement(el, passThroughOptions));
45
+ } else if ((0, _index.isElement)(content)) {
46
+ copy.content = cloneDeepElement(content, passThroughOptions);
47
+ } else if (content instanceof _KeyValuePair.default) {
48
+ copy.content = cloneDeepKeyValuePair(content, passThroughOptions);
49
+ } else {
50
+ copy.content = content;
51
+ }
52
+ return copy;
53
+ };
54
+ const cloneDeepKeyValuePair = (kvp, options) => {
55
+ const {
56
+ visited = new WeakMap()
57
+ } = options;
58
+ const passThroughOptions = {
59
+ ...options,
60
+ visited
61
+ };
62
+ if (visited.has(kvp)) {
63
+ return visited.get(kvp);
64
+ }
65
+ const {
66
+ key,
67
+ value
68
+ } = kvp;
69
+ const keyCopy = key !== undefined ? cloneDeepElement(key, passThroughOptions) : undefined;
70
+ const valueCopy = value !== undefined ? cloneDeepElement(value, passThroughOptions) : undefined;
71
+ const copy = new _KeyValuePair.default(keyCopy, valueCopy);
72
+ visited.set(kvp, copy);
73
+ return copy;
74
+ };
75
+ const cloneDeepObjectSlice = (slice, options) => {
76
+ const {
77
+ visited = new WeakMap()
78
+ } = options;
79
+ const passThroughOptions = {
80
+ ...options,
81
+ visited
82
+ };
83
+ if (visited.has(slice)) {
84
+ return visited.get(slice);
85
+ }
86
+ const items = [...slice].map(element => cloneDeepElement(element, passThroughOptions));
87
+ const copy = new _ObjectSlice.default(items);
88
+ visited.set(slice, copy);
89
+ return copy;
90
+ };
91
+
92
+ /**
93
+ * Creates a deep clone of an ApiDOM Element, KeyValuePair, or ObjectSlice.
94
+ * Handles cycles by memoizing visited objects.
95
+ * @public
96
+ */
97
+ const cloneDeep = (value, options = {}) => {
98
+ if (value instanceof _KeyValuePair.default) {
99
+ return cloneDeepKeyValuePair(value, options);
100
+ }
101
+ if (value instanceof _ObjectSlice.default) {
102
+ return cloneDeepObjectSlice(value, options);
103
+ }
104
+ if ((0, _index.isElement)(value)) {
105
+ return cloneDeepElement(value, options);
106
+ }
107
+ throw new _DeepCloneError.default("Value provided to cloneDeep function couldn't be cloned", {
108
+ value
109
+ });
110
+ };
111
+ exports.cloneDeep = cloneDeep;
112
+ cloneDeep.safe = value => {
113
+ try {
114
+ return cloneDeep(value);
115
+ } catch {
116
+ return value;
117
+ }
118
+ };
119
+ const cloneShallowKeyValuePair = keyValuePair => {
120
+ const {
121
+ key,
122
+ value
123
+ } = keyValuePair;
124
+ return new _KeyValuePair.default(key, value);
125
+ };
126
+ const cloneShallowObjectSlice = objectSlice => {
127
+ const items = [...objectSlice];
128
+ return new _ObjectSlice.default(items);
129
+ };
130
+ const cloneShallowElement = element => {
131
+ const Ctor = element.constructor;
132
+ const copy = new Ctor();
133
+ copy.element = element.element;
134
+ if (!element.isMetaEmpty) {
135
+ copy.meta = element.meta.cloneDeep();
136
+ }
137
+ if (!element.isAttributesEmpty) {
138
+ copy.attributes = cloneDeep(element.attributes);
139
+ }
140
+ if ((0, _index.hasElementSourceMap)(element)) {
141
+ _SourceMap.default.transfer(element, copy);
142
+ }
143
+ if ((0, _index.hasElementStyle)(element)) {
144
+ copy.style = (0, _ramda.clone)(element.style);
145
+ }
146
+ const {
147
+ content
148
+ } = element;
149
+ if ((0, _index.isElement)(content)) {
150
+ copy.content = cloneShallowElement(content);
151
+ } else if (Array.isArray(content)) {
152
+ copy.content = [...content];
153
+ } else if (content instanceof _KeyValuePair.default) {
154
+ copy.content = cloneShallowKeyValuePair(content);
155
+ } else {
156
+ copy.content = content;
157
+ }
158
+ return copy;
159
+ };
160
+
161
+ /**
162
+ * Creates a shallow clone of an ApiDOM Element, KeyValuePair, or ObjectSlice.
163
+ * The element itself is cloned, but content references are shared.
164
+ * Meta and attributes are deep cloned to preserve semantic information.
165
+ * @public
166
+ */
167
+ const cloneShallow = value => {
168
+ if (value instanceof _KeyValuePair.default) {
169
+ return cloneShallowKeyValuePair(value);
170
+ }
171
+ if (value instanceof _ObjectSlice.default) {
172
+ return cloneShallowObjectSlice(value);
173
+ }
174
+ if ((0, _index.isElement)(value)) {
175
+ return cloneShallowElement(value);
176
+ }
177
+ throw new _ShallowCloneError.default("Value provided to cloneShallow function couldn't be cloned", {
178
+ value
179
+ });
180
+ };
181
+ exports.cloneShallow = cloneShallow;
182
+ cloneShallow.safe = value => {
183
+ try {
184
+ return cloneShallow(value);
185
+ } catch {
186
+ return value;
187
+ }
188
+ };
@@ -0,0 +1,178 @@
1
+ import { clone } from 'ramda';
2
+ import ObjectSlice from "../ObjectSlice.mjs";
3
+ import KeyValuePair from "../KeyValuePair.mjs";
4
+ import { isElement, hasElementSourceMap, hasElementStyle } from "../predicates/index.mjs";
5
+ import SourceMapElement from "../elements/SourceMap.mjs";
6
+ import DeepCloneError from "./errors/DeepCloneError.mjs";
7
+ import ShallowCloneError from "./errors/ShallowCloneError.mjs";
8
+ /**
9
+ * @public
10
+ */
11
+ /**
12
+ * @public
13
+ */
14
+ const cloneDeepElement = (element, options) => {
15
+ const {
16
+ visited = new WeakMap()
17
+ } = options;
18
+ const passThroughOptions = {
19
+ ...options,
20
+ visited
21
+ };
22
+
23
+ // detect cycle and return memoized value
24
+ if (visited.has(element)) {
25
+ return visited.get(element);
26
+ }
27
+ const copy = cloneShallowElement(element);
28
+ visited.set(element, copy);
29
+ const {
30
+ content
31
+ } = element;
32
+ if (Array.isArray(content)) {
33
+ copy.content = content.map(el => cloneDeepElement(el, passThroughOptions));
34
+ } else if (isElement(content)) {
35
+ copy.content = cloneDeepElement(content, passThroughOptions);
36
+ } else if (content instanceof KeyValuePair) {
37
+ copy.content = cloneDeepKeyValuePair(content, passThroughOptions);
38
+ } else {
39
+ copy.content = content;
40
+ }
41
+ return copy;
42
+ };
43
+ const cloneDeepKeyValuePair = (kvp, options) => {
44
+ const {
45
+ visited = new WeakMap()
46
+ } = options;
47
+ const passThroughOptions = {
48
+ ...options,
49
+ visited
50
+ };
51
+ if (visited.has(kvp)) {
52
+ return visited.get(kvp);
53
+ }
54
+ const {
55
+ key,
56
+ value
57
+ } = kvp;
58
+ const keyCopy = key !== undefined ? cloneDeepElement(key, passThroughOptions) : undefined;
59
+ const valueCopy = value !== undefined ? cloneDeepElement(value, passThroughOptions) : undefined;
60
+ const copy = new KeyValuePair(keyCopy, valueCopy);
61
+ visited.set(kvp, copy);
62
+ return copy;
63
+ };
64
+ const cloneDeepObjectSlice = (slice, options) => {
65
+ const {
66
+ visited = new WeakMap()
67
+ } = options;
68
+ const passThroughOptions = {
69
+ ...options,
70
+ visited
71
+ };
72
+ if (visited.has(slice)) {
73
+ return visited.get(slice);
74
+ }
75
+ const items = [...slice].map(element => cloneDeepElement(element, passThroughOptions));
76
+ const copy = new ObjectSlice(items);
77
+ visited.set(slice, copy);
78
+ return copy;
79
+ };
80
+
81
+ /**
82
+ * Creates a deep clone of an ApiDOM Element, KeyValuePair, or ObjectSlice.
83
+ * Handles cycles by memoizing visited objects.
84
+ * @public
85
+ */
86
+ export const cloneDeep = (value, options = {}) => {
87
+ if (value instanceof KeyValuePair) {
88
+ return cloneDeepKeyValuePair(value, options);
89
+ }
90
+ if (value instanceof ObjectSlice) {
91
+ return cloneDeepObjectSlice(value, options);
92
+ }
93
+ if (isElement(value)) {
94
+ return cloneDeepElement(value, options);
95
+ }
96
+ throw new DeepCloneError("Value provided to cloneDeep function couldn't be cloned", {
97
+ value
98
+ });
99
+ };
100
+ cloneDeep.safe = value => {
101
+ try {
102
+ return cloneDeep(value);
103
+ } catch {
104
+ return value;
105
+ }
106
+ };
107
+ const cloneShallowKeyValuePair = keyValuePair => {
108
+ const {
109
+ key,
110
+ value
111
+ } = keyValuePair;
112
+ return new KeyValuePair(key, value);
113
+ };
114
+ const cloneShallowObjectSlice = objectSlice => {
115
+ const items = [...objectSlice];
116
+ return new ObjectSlice(items);
117
+ };
118
+ const cloneShallowElement = element => {
119
+ const Ctor = element.constructor;
120
+ const copy = new Ctor();
121
+ copy.element = element.element;
122
+ if (!element.isMetaEmpty) {
123
+ copy.meta = element.meta.cloneDeep();
124
+ }
125
+ if (!element.isAttributesEmpty) {
126
+ copy.attributes = cloneDeep(element.attributes);
127
+ }
128
+ if (hasElementSourceMap(element)) {
129
+ SourceMapElement.transfer(element, copy);
130
+ }
131
+ if (hasElementStyle(element)) {
132
+ copy.style = clone(element.style);
133
+ }
134
+ const {
135
+ content
136
+ } = element;
137
+ if (isElement(content)) {
138
+ copy.content = cloneShallowElement(content);
139
+ } else if (Array.isArray(content)) {
140
+ copy.content = [...content];
141
+ } else if (content instanceof KeyValuePair) {
142
+ copy.content = cloneShallowKeyValuePair(content);
143
+ } else {
144
+ copy.content = content;
145
+ }
146
+ return copy;
147
+ };
148
+
149
+ /**
150
+ * Creates a shallow clone of an ApiDOM Element, KeyValuePair, or ObjectSlice.
151
+ * The element itself is cloned, but content references are shared.
152
+ * Meta and attributes are deep cloned to preserve semantic information.
153
+ * @public
154
+ */
155
+ export const cloneShallow = value => {
156
+ if (value instanceof KeyValuePair) {
157
+ return cloneShallowKeyValuePair(value);
158
+ }
159
+ if (value instanceof ObjectSlice) {
160
+ return cloneShallowObjectSlice(value);
161
+ }
162
+ if (isElement(value)) {
163
+ return cloneShallowElement(value);
164
+ }
165
+ throw new ShallowCloneError("Value provided to cloneShallow function couldn't be cloned", {
166
+ value
167
+ });
168
+ };
169
+ cloneShallow.safe = value => {
170
+ try {
171
+ return cloneShallow(value);
172
+ } catch {
173
+ return value;
174
+ }
175
+ };
176
+ export { default as CloneError } from "./errors/CloneError.mjs";
177
+ export { default as DeepCloneError } from "./errors/DeepCloneError.mjs";
178
+ export { default as ShallowCloneError } from "./errors/ShallowCloneError.mjs";
@@ -0,0 +1,195 @@
1
+ import { clone } from 'ramda';
2
+
3
+ import ObjectSlice from '../ObjectSlice.ts';
4
+ import KeyValuePair from '../KeyValuePair.ts';
5
+ import Element from '../primitives/Element.ts';
6
+ import MemberElement from '../primitives/MemberElement.ts';
7
+ import { isElement, hasElementSourceMap, hasElementStyle } from '../predicates/index.ts';
8
+ import SourceMapElement from '../elements/SourceMap.ts';
9
+ import DeepCloneError from './errors/DeepCloneError.ts';
10
+ import ShallowCloneError from './errors/ShallowCloneError.ts';
11
+
12
+ /**
13
+ * @public
14
+ */
15
+ export type FinalCloneTypes = KeyValuePair | ObjectSlice;
16
+
17
+ /**
18
+ * @public
19
+ */
20
+ export type DeepCloneOptions = {
21
+ visited?: WeakMap<object, object>;
22
+ };
23
+
24
+ const cloneDeepElement = (element: Element, options: DeepCloneOptions): Element => {
25
+ const { visited = new WeakMap<object, object>() } = options;
26
+ const passThroughOptions = { ...options, visited };
27
+
28
+ // detect cycle and return memoized value
29
+ if (visited.has(element)) {
30
+ return visited.get(element) as Element;
31
+ }
32
+
33
+ const copy = cloneShallowElement(element);
34
+ visited.set(element, copy);
35
+
36
+ const { content } = element;
37
+ if (Array.isArray(content)) {
38
+ copy.content = content.map((el: Element) => cloneDeepElement(el, passThroughOptions));
39
+ } else if (isElement(content)) {
40
+ copy.content = cloneDeepElement(content as Element, passThroughOptions);
41
+ } else if ((content as unknown) instanceof KeyValuePair) {
42
+ copy.content = cloneDeepKeyValuePair(content as KeyValuePair, passThroughOptions);
43
+ } else {
44
+ copy.content = content;
45
+ }
46
+
47
+ return copy;
48
+ };
49
+
50
+ const cloneDeepKeyValuePair = (kvp: KeyValuePair, options: DeepCloneOptions): KeyValuePair => {
51
+ const { visited = new WeakMap<object, object>() } = options;
52
+ const passThroughOptions = { ...options, visited };
53
+
54
+ if (visited.has(kvp)) {
55
+ return visited.get(kvp) as KeyValuePair;
56
+ }
57
+
58
+ const { key, value } = kvp;
59
+ const keyCopy = key !== undefined ? cloneDeepElement(key, passThroughOptions) : undefined;
60
+ const valueCopy = value !== undefined ? cloneDeepElement(value, passThroughOptions) : undefined;
61
+ const copy = new KeyValuePair(keyCopy, valueCopy);
62
+ visited.set(kvp, copy);
63
+ return copy;
64
+ };
65
+
66
+ const cloneDeepObjectSlice = (slice: ObjectSlice, options: DeepCloneOptions): ObjectSlice => {
67
+ const { visited = new WeakMap<object, object>() } = options;
68
+ const passThroughOptions = { ...options, visited };
69
+
70
+ if (visited.has(slice)) {
71
+ return visited.get(slice) as ObjectSlice;
72
+ }
73
+
74
+ const items = [...slice].map(
75
+ (element) => cloneDeepElement(element, passThroughOptions) as MemberElement,
76
+ );
77
+ const copy = new ObjectSlice(items);
78
+ visited.set(slice, copy);
79
+ return copy;
80
+ };
81
+
82
+ /**
83
+ * Creates a deep clone of an ApiDOM Element, KeyValuePair, or ObjectSlice.
84
+ * Handles cycles by memoizing visited objects.
85
+ * @public
86
+ */
87
+ export const cloneDeep = <T extends Element | FinalCloneTypes>(
88
+ value: T,
89
+ options: DeepCloneOptions = {},
90
+ ): T => {
91
+ if (value instanceof KeyValuePair) {
92
+ return cloneDeepKeyValuePair(value, options) as T;
93
+ }
94
+
95
+ if (value instanceof ObjectSlice) {
96
+ return cloneDeepObjectSlice(value, options) as T;
97
+ }
98
+
99
+ if (isElement(value)) {
100
+ return cloneDeepElement(value, options) as T;
101
+ }
102
+
103
+ throw new DeepCloneError("Value provided to cloneDeep function couldn't be cloned", {
104
+ value,
105
+ });
106
+ };
107
+ cloneDeep.safe = <T>(value: T): T => {
108
+ try {
109
+ return cloneDeep(value as Element | FinalCloneTypes) as T;
110
+ } catch {
111
+ return value;
112
+ }
113
+ };
114
+
115
+ const cloneShallowKeyValuePair = (keyValuePair: KeyValuePair): KeyValuePair => {
116
+ const { key, value } = keyValuePair;
117
+ return new KeyValuePair(key, value);
118
+ };
119
+
120
+ const cloneShallowObjectSlice = (objectSlice: ObjectSlice): ObjectSlice => {
121
+ const items = [...objectSlice];
122
+ return new ObjectSlice(items);
123
+ };
124
+
125
+ const cloneShallowElement = <T extends Element>(element: T): T => {
126
+ const Ctor = element.constructor as new () => T;
127
+ const copy = new Ctor();
128
+
129
+ copy.element = element.element;
130
+
131
+ if (!element.isMetaEmpty) {
132
+ copy.meta = element.meta.cloneDeep();
133
+ }
134
+
135
+ if (!element.isAttributesEmpty) {
136
+ copy.attributes = cloneDeep(element.attributes);
137
+ }
138
+
139
+ if (hasElementSourceMap(element)) {
140
+ SourceMapElement.transfer(element, copy);
141
+ }
142
+
143
+ if (hasElementStyle(element)) {
144
+ copy.style = clone(element.style);
145
+ }
146
+
147
+ const { content } = element;
148
+ if (isElement(content)) {
149
+ copy.content = cloneShallowElement(content as Element);
150
+ } else if (Array.isArray(content)) {
151
+ copy.content = [...content];
152
+ } else if ((content as unknown) instanceof KeyValuePair) {
153
+ copy.content = cloneShallowKeyValuePair(content as KeyValuePair);
154
+ } else {
155
+ copy.content = content;
156
+ }
157
+
158
+ return copy;
159
+ };
160
+
161
+ /**
162
+ * Creates a shallow clone of an ApiDOM Element, KeyValuePair, or ObjectSlice.
163
+ * The element itself is cloned, but content references are shared.
164
+ * Meta and attributes are deep cloned to preserve semantic information.
165
+ * @public
166
+ */
167
+ export const cloneShallow = <T extends Element | FinalCloneTypes>(value: T): T => {
168
+ if (value instanceof KeyValuePair) {
169
+ return cloneShallowKeyValuePair(value) as T;
170
+ }
171
+
172
+ if (value instanceof ObjectSlice) {
173
+ return cloneShallowObjectSlice(value) as T;
174
+ }
175
+
176
+ if (isElement(value)) {
177
+ return cloneShallowElement(value) as T;
178
+ }
179
+
180
+ throw new ShallowCloneError("Value provided to cloneShallow function couldn't be cloned", {
181
+ value,
182
+ });
183
+ };
184
+ cloneShallow.safe = <T>(value: T): T => {
185
+ try {
186
+ return cloneShallow(value as Element | FinalCloneTypes) as T;
187
+ } catch {
188
+ return value;
189
+ }
190
+ };
191
+
192
+ export { default as CloneError } from './errors/CloneError.ts';
193
+ export type { CloneErrorOptions } from './errors/CloneError.ts';
194
+ export { default as DeepCloneError } from './errors/DeepCloneError.ts';
195
+ export { default as ShallowCloneError } from './errors/ShallowCloneError.ts';
@@ -0,0 +1,35 @@
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
+ * AnnotationElement represents a parsing annotation (warning or error).
9
+ *
10
+ * The annotation's class indicates its severity:
11
+ * - 'warning' - A non-fatal issue
12
+ * - 'error' - A fatal issue
13
+ *
14
+ * @public
15
+ */
16
+ class AnnotationElement extends _StringElement.default {
17
+ constructor(content, meta, attributes) {
18
+ super(content, meta, attributes);
19
+ this.element = 'annotation';
20
+ }
21
+
22
+ /**
23
+ * The annotation code identifying the type of annotation.
24
+ */
25
+ get code() {
26
+ if (this.hasAttributesProperty('code')) {
27
+ return this.attributes.get('code');
28
+ }
29
+ return undefined;
30
+ }
31
+ set code(value) {
32
+ this.attributes.set('code', value);
33
+ }
34
+ }
35
+ var _default = exports.default = AnnotationElement;
@@ -0,0 +1,30 @@
1
+ import StringElement from "../primitives/StringElement.mjs";
2
+ /**
3
+ * AnnotationElement represents a parsing annotation (warning or error).
4
+ *
5
+ * The annotation's class indicates its severity:
6
+ * - 'warning' - A non-fatal issue
7
+ * - 'error' - A fatal issue
8
+ *
9
+ * @public
10
+ */
11
+ class AnnotationElement extends StringElement {
12
+ constructor(content, meta, attributes) {
13
+ super(content, meta, attributes);
14
+ this.element = 'annotation';
15
+ }
16
+
17
+ /**
18
+ * The annotation code identifying the type of annotation.
19
+ */
20
+ get code() {
21
+ if (this.hasAttributesProperty('code')) {
22
+ return this.attributes.get('code');
23
+ }
24
+ return undefined;
25
+ }
26
+ set code(value) {
27
+ this.attributes.set('code', value);
28
+ }
29
+ }
30
+ export default AnnotationElement;
@@ -0,0 +1,35 @@
1
+ import StringElement from '../primitives/StringElement.ts';
2
+ import type Element from '../primitives/Element.ts';
3
+ import type { Meta, Attributes } from '../types.ts';
4
+
5
+ /**
6
+ * AnnotationElement represents a parsing annotation (warning or error).
7
+ *
8
+ * The annotation's class indicates its severity:
9
+ * - 'warning' - A non-fatal issue
10
+ * - 'error' - A fatal issue
11
+ *
12
+ * @public
13
+ */
14
+ class AnnotationElement extends StringElement {
15
+ constructor(content?: string, meta?: Meta, attributes?: Attributes) {
16
+ super(content, meta, attributes);
17
+ this.element = 'annotation';
18
+ }
19
+
20
+ /**
21
+ * The annotation code identifying the type of annotation.
22
+ */
23
+ get code(): Element | undefined {
24
+ if (this.hasAttributesProperty('code')) {
25
+ return this.attributes.get('code') as Element;
26
+ }
27
+ return undefined;
28
+ }
29
+
30
+ set code(value: unknown) {
31
+ this.attributes.set('code', value);
32
+ }
33
+ }
34
+
35
+ export default AnnotationElement;
@@ -0,0 +1,18 @@
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
+ * CommentElement represents a comment in the source document.
9
+ *
10
+ * @public
11
+ */
12
+ class CommentElement extends _StringElement.default {
13
+ constructor(content, meta, attributes) {
14
+ super(content, meta, attributes);
15
+ this.element = 'comment';
16
+ }
17
+ }
18
+ var _default = exports.default = CommentElement;
@@ -0,0 +1,13 @@
1
+ import StringElement from "../primitives/StringElement.mjs";
2
+ /**
3
+ * CommentElement represents a comment in the source document.
4
+ *
5
+ * @public
6
+ */
7
+ class CommentElement extends StringElement {
8
+ constructor(content, meta, attributes) {
9
+ super(content, meta, attributes);
10
+ this.element = 'comment';
11
+ }
12
+ }
13
+ export default CommentElement;