@wdprlib/ast 0.1.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.
package/dist/index.cjs ADDED
@@ -0,0 +1,245 @@
1
+ var import_node_module = require("node:module");
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
7
+ var __toCommonJS = (from) => {
8
+ var entry = __moduleCache.get(from), desc;
9
+ if (entry)
10
+ return entry;
11
+ entry = __defProp({}, "__esModule", { value: true });
12
+ if (from && typeof from === "object" || typeof from === "function")
13
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ }));
17
+ __moduleCache.set(from, entry);
18
+ return entry;
19
+ };
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, {
23
+ get: all[name],
24
+ enumerable: true,
25
+ configurable: true,
26
+ set: (newValue) => all[name] = () => newValue
27
+ });
28
+ };
29
+
30
+ // packages/ast/src/index.ts
31
+ var exports_src = {};
32
+ __export(exports_src, {
33
+ text: () => text,
34
+ paragraph: () => paragraph,
35
+ listItemSubList: () => listItemSubList,
36
+ listItemElements: () => listItemElements,
37
+ list: () => list,
38
+ link: () => link,
39
+ lineBreak: () => lineBreak,
40
+ italics: () => italics,
41
+ isStringContainerType: () => isStringContainerType,
42
+ isParagraphSafe: () => isParagraphSafe,
43
+ isHeaderType: () => isHeaderType,
44
+ isContainerTypeParagraphSafe: () => isContainerTypeParagraphSafe,
45
+ isAlignType: () => isAlignType,
46
+ horizontalRule: () => horizontalRule,
47
+ heading: () => heading,
48
+ createPosition: () => createPosition,
49
+ createPoint: () => createPoint,
50
+ container: () => container,
51
+ bold: () => bold
52
+ });
53
+ module.exports = __toCommonJS(exports_src);
54
+
55
+ // packages/ast/src/position.ts
56
+ function createPoint(line, column, offset) {
57
+ return { line, column, offset };
58
+ }
59
+ function createPosition(start, end) {
60
+ return { start, end };
61
+ }
62
+ // packages/ast/src/element.ts
63
+ function isStringContainerType(type) {
64
+ return typeof type === "string";
65
+ }
66
+ function isHeaderType(type) {
67
+ return typeof type === "object" && type !== null && "header" in type;
68
+ }
69
+ function isAlignType(type) {
70
+ return typeof type === "object" && type !== null && "align" in type;
71
+ }
72
+ function text(value) {
73
+ return { element: "text", data: value };
74
+ }
75
+ function container(type, elements, attributes = {}) {
76
+ return {
77
+ element: "container",
78
+ data: { type, attributes, elements }
79
+ };
80
+ }
81
+ function paragraph(elements, attributes = {}) {
82
+ return container("paragraph", elements, attributes);
83
+ }
84
+ function bold(elements, attributes = {}) {
85
+ return container("bold", elements, attributes);
86
+ }
87
+ function italics(elements, attributes = {}) {
88
+ return container("italics", elements, attributes);
89
+ }
90
+ function heading(level, elements, hasToc = true, attributes = {}) {
91
+ return container({ header: { level, "has-toc": hasToc } }, elements, attributes);
92
+ }
93
+ function lineBreak() {
94
+ return { element: "line-break" };
95
+ }
96
+ function horizontalRule() {
97
+ return { element: "horizontal-rule" };
98
+ }
99
+ function link(linkLocation, label, options = {}) {
100
+ return {
101
+ element: "link",
102
+ data: {
103
+ type: options.type ?? (typeof linkLocation === "string" ? "direct" : "page"),
104
+ link: linkLocation,
105
+ extra: options.extra ?? null,
106
+ label,
107
+ target: options.target ?? null
108
+ }
109
+ };
110
+ }
111
+ function list(type, items, attributes = {}) {
112
+ return {
113
+ element: "list",
114
+ data: { type, attributes, items }
115
+ };
116
+ }
117
+ function listItemElements(elements, attributes = {}) {
118
+ return {
119
+ "item-type": "elements",
120
+ attributes,
121
+ elements
122
+ };
123
+ }
124
+ function listItemSubList(data) {
125
+ return {
126
+ "item-type": "sub-list",
127
+ element: "list",
128
+ data
129
+ };
130
+ }
131
+ function isContainerTypeParagraphSafe(type) {
132
+ if (isHeaderType(type))
133
+ return false;
134
+ if (isAlignType(type))
135
+ return false;
136
+ switch (type) {
137
+ case "bold":
138
+ case "italics":
139
+ case "underline":
140
+ case "superscript":
141
+ case "subscript":
142
+ case "strikethrough":
143
+ case "monospace":
144
+ case "span":
145
+ case "size":
146
+ return true;
147
+ case "div":
148
+ case "blockquote":
149
+ case "paragraph":
150
+ case "heading":
151
+ case "collapsible":
152
+ case "definition-list":
153
+ case "definition-list-item":
154
+ case "definition-list-key":
155
+ case "definition-list-value":
156
+ case "table-row":
157
+ case "table-cell":
158
+ return false;
159
+ default:
160
+ return false;
161
+ }
162
+ }
163
+ function isParagraphSafe(element) {
164
+ switch (element.element) {
165
+ case "container": {
166
+ const data = element.data;
167
+ return isContainerTypeParagraphSafe(data.type);
168
+ }
169
+ case "module":
170
+ return false;
171
+ case "text":
172
+ case "raw":
173
+ case "variable":
174
+ case "email":
175
+ return true;
176
+ case "table":
177
+ return false;
178
+ case "tab-view":
179
+ return false;
180
+ case "anchor":
181
+ case "anchor-name":
182
+ case "link":
183
+ return true;
184
+ case "image":
185
+ return true;
186
+ case "list":
187
+ return false;
188
+ case "definition-list":
189
+ return false;
190
+ case "collapsible":
191
+ return false;
192
+ case "table-of-contents":
193
+ return false;
194
+ case "footnote":
195
+ return true;
196
+ case "footnote-ref":
197
+ return true;
198
+ case "footnote-block":
199
+ return false;
200
+ case "bibliography-cite":
201
+ return true;
202
+ case "bibliography-block":
203
+ return false;
204
+ case "user":
205
+ return true;
206
+ case "date":
207
+ return true;
208
+ case "color":
209
+ return true;
210
+ case "code":
211
+ return false;
212
+ case "math":
213
+ return false;
214
+ case "math-inline":
215
+ return true;
216
+ case "embed":
217
+ return false;
218
+ case "html":
219
+ case "iframe":
220
+ return false;
221
+ case "include": {
222
+ const data = element.data;
223
+ return data["paragraph-safe"];
224
+ }
225
+ case "style":
226
+ return false;
227
+ case "line-break":
228
+ case "line-breaks":
229
+ return true;
230
+ case "clear-float":
231
+ return false;
232
+ case "horizontal-rule":
233
+ return false;
234
+ case "content-separator":
235
+ return false;
236
+ case "if-tags":
237
+ return false;
238
+ case "expr":
239
+ case "if":
240
+ case "ifexpr":
241
+ return true;
242
+ default:
243
+ return false;
244
+ }
245
+ }