@bendyline/squisq 0.1.1
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/Types-sh2VRxfo.d.ts +15 -0
- package/dist/chunk-7UDSRZKG.js +103 -0
- package/dist/chunk-7UDSRZKG.js.map +1 -0
- package/dist/chunk-O5HCIUAD.js +577 -0
- package/dist/chunk-O5HCIUAD.js.map +1 -0
- package/dist/chunk-PJ7AODIM.js +3040 -0
- package/dist/chunk-PJ7AODIM.js.map +1 -0
- package/dist/chunk-QWVRN6I4.js +81 -0
- package/dist/chunk-QWVRN6I4.js.map +1 -0
- package/dist/chunk-S4F2RY37.js +92 -0
- package/dist/chunk-S4F2RY37.js.map +1 -0
- package/dist/chunk-URU6QMLY.js +888 -0
- package/dist/chunk-URU6QMLY.js.map +1 -0
- package/dist/chunk-VJN7UB2Z.js +145 -0
- package/dist/chunk-VJN7UB2Z.js.map +1 -0
- package/dist/doc/index.d.ts +3 -0
- package/dist/doc/index.js +126 -0
- package/dist/doc/index.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +217 -0
- package/dist/index.js.map +1 -0
- package/dist/markdown/index.d.ts +237 -0
- package/dist/markdown/index.js +33 -0
- package/dist/markdown/index.js.map +1 -0
- package/dist/schemas/index.d.ts +70 -0
- package/dist/schemas/index.js +61 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/spatial/index.d.ts +111 -0
- package/dist/spatial/index.js +25 -0
- package/dist/spatial/index.js.map +1 -0
- package/dist/storage/index.d.ts +91 -0
- package/dist/storage/index.js +11 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/story/index.d.ts +691 -0
- package/dist/story/index.js +126 -0
- package/dist/story/index.js.map +1 -0
- package/dist/themeLibrary-DySHPcgj.d.ts +1352 -0
- package/dist/types-DHiv_Pnm.d.ts +496 -0
- package/package.json +91 -0
- package/src/__tests__/animationUtils.test.ts +77 -0
- package/src/__tests__/geohash.test.ts +109 -0
- package/src/__tests__/getLayers.test.ts +200 -0
- package/src/__tests__/haversine.test.ts +63 -0
- package/src/__tests__/localForageAdapter.test.ts +155 -0
- package/src/__tests__/markdown.test.ts +806 -0
- package/src/__tests__/markdownToDoc.test.ts +374 -0
- package/src/__tests__/storage.test.ts +60 -0
- package/src/__tests__/templates.test.ts +247 -0
- package/src/doc/docToMarkdown.ts +98 -0
- package/src/doc/getLayers.ts +152 -0
- package/src/doc/index.ts +8 -0
- package/src/doc/markdownToDoc.ts +277 -0
- package/src/doc/templates/accentImage.ts +338 -0
- package/src/doc/templates/captionUtils.ts +33 -0
- package/src/doc/templates/comparisonBar.ts +140 -0
- package/src/doc/templates/coverBlock.ts +156 -0
- package/src/doc/templates/dateEvent.ts +122 -0
- package/src/doc/templates/definitionCard.ts +129 -0
- package/src/doc/templates/factCard.ts +114 -0
- package/src/doc/templates/fullBleedQuote.ts +59 -0
- package/src/doc/templates/imageWithCaption.ts +167 -0
- package/src/doc/templates/index.ts +571 -0
- package/src/doc/templates/listBlock.ts +101 -0
- package/src/doc/templates/mapBlock.ts +132 -0
- package/src/doc/templates/persistentLayers.ts +522 -0
- package/src/doc/templates/photoGrid.ts +199 -0
- package/src/doc/templates/pullQuote.ts +119 -0
- package/src/doc/templates/quoteBlock.ts +112 -0
- package/src/doc/templates/sectionHeader.ts +105 -0
- package/src/doc/templates/statHighlight.ts +113 -0
- package/src/doc/templates/titleBlock.ts +100 -0
- package/src/doc/templates/twoColumn.ts +239 -0
- package/src/doc/templates/videoPullQuote.ts +128 -0
- package/src/doc/templates/videoWithCaption.ts +126 -0
- package/src/doc/utils/animationUtils.ts +135 -0
- package/src/doc/utils/themeUtils.ts +139 -0
- package/src/index.ts +5 -0
- package/src/markdown/convert.ts +897 -0
- package/src/markdown/htmlParse.ts +212 -0
- package/src/markdown/index.ts +110 -0
- package/src/markdown/parse.ts +103 -0
- package/src/markdown/stringify.ts +122 -0
- package/src/markdown/types.ts +605 -0
- package/src/markdown/utils.ts +165 -0
- package/src/ngeohash.d.ts +11 -0
- package/src/schemas/BlockTemplates.ts +706 -0
- package/src/schemas/Doc.ts +565 -0
- package/src/schemas/LayoutStrategy.ts +178 -0
- package/src/schemas/MediaProvider.ts +70 -0
- package/src/schemas/Theme.ts +235 -0
- package/src/schemas/Types.ts +15 -0
- package/src/schemas/Viewport.ts +91 -0
- package/src/schemas/index.ts +14 -0
- package/src/schemas/themeLibrary.ts +492 -0
- package/src/spatial/Geohash.ts +168 -0
- package/src/spatial/Haversine.ts +59 -0
- package/src/spatial/index.ts +2 -0
- package/src/storage/LocalForageAdapter.ts +103 -0
- package/src/storage/LocalStorageAdapter.ts +57 -0
- package/src/storage/MemoryStorageAdapter.ts +37 -0
- package/src/storage/Storage.ts +28 -0
- package/src/storage/index.ts +5 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown Tree Utilities
|
|
3
|
+
*
|
|
4
|
+
* Helper functions for traversing and querying the MarkdownDocument tree.
|
|
5
|
+
* All functions are pure and operate on the JSON node interfaces.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { MarkdownNode, MarkdownDocument } from './types.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get the children of any markdown node, if it has children.
|
|
12
|
+
* Returns an empty array for leaf nodes (text, code, break, etc.).
|
|
13
|
+
*
|
|
14
|
+
* This is useful for generic tree walking where you don't want to
|
|
15
|
+
* check the specific node type.
|
|
16
|
+
*/
|
|
17
|
+
export function getChildren(node: MarkdownNode): MarkdownNode[] {
|
|
18
|
+
if ('children' in node && Array.isArray(node.children)) {
|
|
19
|
+
return node.children as MarkdownNode[];
|
|
20
|
+
}
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Walk the markdown tree depth-first, calling the visitor for each node.
|
|
26
|
+
*
|
|
27
|
+
* The visitor receives the current node and its parent. Return `true`
|
|
28
|
+
* from the visitor to skip the node's children (prune).
|
|
29
|
+
*
|
|
30
|
+
* @param node - The root node to start walking from
|
|
31
|
+
* @param visitor - Called for each node; return true to skip children
|
|
32
|
+
* @param parent - (internal) Parent node
|
|
33
|
+
*/
|
|
34
|
+
export function walkMarkdownTree(
|
|
35
|
+
node: MarkdownNode,
|
|
36
|
+
visitor: (node: MarkdownNode, parent?: MarkdownNode) => void | boolean,
|
|
37
|
+
parent?: MarkdownNode,
|
|
38
|
+
): void {
|
|
39
|
+
const skip = visitor(node, parent);
|
|
40
|
+
if (skip === true) return;
|
|
41
|
+
|
|
42
|
+
const children = getChildren(node);
|
|
43
|
+
for (const child of children) {
|
|
44
|
+
walkMarkdownTree(child, visitor, node);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Find all nodes of a specific type in the tree.
|
|
50
|
+
*
|
|
51
|
+
* @param root - The document or node to search within
|
|
52
|
+
* @param type - The node type to find (e.g., 'heading', 'link', 'text')
|
|
53
|
+
* @returns Array of matching nodes
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const headings = findNodesByType(doc, 'heading');
|
|
58
|
+
* const links = findNodesByType(doc, 'link');
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export function findNodesByType<T extends MarkdownNode>(root: MarkdownNode, type: T['type']): T[] {
|
|
62
|
+
const results: T[] = [];
|
|
63
|
+
walkMarkdownTree(root, (node) => {
|
|
64
|
+
if (node.type === type) {
|
|
65
|
+
results.push(node as T);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return results;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Extract all plain text content from a node and its descendants.
|
|
73
|
+
* Concatenates text values, ignoring formatting, links, etc.
|
|
74
|
+
*
|
|
75
|
+
* @param node - The node to extract text from
|
|
76
|
+
* @returns Plain text content
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* const heading = doc.children[0]; // { type: 'heading', children: [{ type: 'text', value: 'Hello' }] }
|
|
81
|
+
* extractPlainText(heading); // 'Hello'
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export function extractPlainText(node: MarkdownNode): string {
|
|
85
|
+
if ('value' in node && typeof node.value === 'string') {
|
|
86
|
+
return node.value;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const children = getChildren(node);
|
|
90
|
+
return children.map(extractPlainText).join('');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Count the total number of nodes in the tree.
|
|
95
|
+
*
|
|
96
|
+
* @param node - The root node
|
|
97
|
+
* @returns Total node count (including the root)
|
|
98
|
+
*/
|
|
99
|
+
export function countNodes(node: MarkdownNode): number {
|
|
100
|
+
let count = 1;
|
|
101
|
+
const children = getChildren(node);
|
|
102
|
+
for (const child of children) {
|
|
103
|
+
count += countNodes(child);
|
|
104
|
+
}
|
|
105
|
+
return count;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Parse a YAML frontmatter string into a key-value record.
|
|
110
|
+
*
|
|
111
|
+
* Handles simple `key: value` pairs common in markdown frontmatter.
|
|
112
|
+
* Values are trimmed; quoted strings have their quotes removed.
|
|
113
|
+
* Returns `null` if parsing fails or the input is empty.
|
|
114
|
+
*
|
|
115
|
+
* @param yaml - The raw YAML string (without the `---` delimiters)
|
|
116
|
+
* @returns A record of string keys to parsed values, or null
|
|
117
|
+
*/
|
|
118
|
+
export function parseFrontmatter(yaml: string): Record<string, unknown> | null {
|
|
119
|
+
if (!yaml || !yaml.trim()) return null;
|
|
120
|
+
|
|
121
|
+
const result: Record<string, unknown> = {};
|
|
122
|
+
|
|
123
|
+
for (const line of yaml.split('\n')) {
|
|
124
|
+
const trimmed = line.trim();
|
|
125
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
126
|
+
|
|
127
|
+
const colonIdx = trimmed.indexOf(':');
|
|
128
|
+
if (colonIdx < 1) continue;
|
|
129
|
+
|
|
130
|
+
const key = trimmed.slice(0, colonIdx).trim();
|
|
131
|
+
let value: string | boolean | number = trimmed.slice(colonIdx + 1).trim();
|
|
132
|
+
|
|
133
|
+
// Remove surrounding quotes
|
|
134
|
+
if (
|
|
135
|
+
(value.startsWith('"') && value.endsWith('"')) ||
|
|
136
|
+
(value.startsWith("'") && value.endsWith("'"))
|
|
137
|
+
) {
|
|
138
|
+
value = value.slice(1, -1);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Parse booleans and numbers
|
|
142
|
+
if (value === 'true') {
|
|
143
|
+
result[key] = true;
|
|
144
|
+
} else if (value === 'false') {
|
|
145
|
+
result[key] = false;
|
|
146
|
+
} else if (value !== '' && !isNaN(Number(value))) {
|
|
147
|
+
result[key] = Number(value);
|
|
148
|
+
} else {
|
|
149
|
+
result[key] = value;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return Object.keys(result).length > 0 ? result : null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Create a minimal MarkdownDocument from a list of block nodes.
|
|
158
|
+
* Convenience function for programmatic document construction.
|
|
159
|
+
*/
|
|
160
|
+
export function createDocument(...children: MarkdownDocument['children']): MarkdownDocument {
|
|
161
|
+
return {
|
|
162
|
+
type: 'document',
|
|
163
|
+
children,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare module 'ngeohash' {
|
|
2
|
+
export function encode(latitude: number, longitude: number, precision?: number): string;
|
|
3
|
+
export function decode(hashstring: string): {
|
|
4
|
+
latitude: number;
|
|
5
|
+
longitude: number;
|
|
6
|
+
error: { latitude: number; longitude: number };
|
|
7
|
+
};
|
|
8
|
+
export function neighbors(hashstring: string): string[];
|
|
9
|
+
export function decode_bbox(hashstring: string): [number, number, number, number];
|
|
10
|
+
export default { encode, decode, neighbors, decode_bbox };
|
|
11
|
+
}
|