@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,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Haversine Distance Calculation
|
|
3
|
+
*
|
|
4
|
+
* Provides accurate distance calculation between two geographic coordinates
|
|
5
|
+
* using the Haversine formula, which accounts for Earth's curvature.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Coordinates } from '../schemas/Types.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Calculate distance between two coordinates using Haversine formula.
|
|
12
|
+
*
|
|
13
|
+
* @param from Start coordinates
|
|
14
|
+
* @param to End coordinates
|
|
15
|
+
* @returns Distance in kilometers
|
|
16
|
+
*/
|
|
17
|
+
export function haversineDistance(from: Coordinates, to: Coordinates): number {
|
|
18
|
+
const R = 6371; // Earth's radius in kilometers
|
|
19
|
+
|
|
20
|
+
const dLat = toRadians(to.lat - from.lat);
|
|
21
|
+
const dLng = toRadians(to.lng - from.lng);
|
|
22
|
+
|
|
23
|
+
const a =
|
|
24
|
+
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
|
25
|
+
Math.cos(toRadians(from.lat)) *
|
|
26
|
+
Math.cos(toRadians(to.lat)) *
|
|
27
|
+
Math.sin(dLng / 2) *
|
|
28
|
+
Math.sin(dLng / 2);
|
|
29
|
+
|
|
30
|
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
31
|
+
|
|
32
|
+
return R * c;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Calculate bearing from one coordinate to another.
|
|
37
|
+
*
|
|
38
|
+
* @param from Start coordinates
|
|
39
|
+
* @param to End coordinates
|
|
40
|
+
* @returns Bearing in degrees (0-360, where 0 = north, 90 = east)
|
|
41
|
+
*/
|
|
42
|
+
export function calculateBearing(from: Coordinates, to: Coordinates): number {
|
|
43
|
+
const dLng = toRadians(to.lng - from.lng);
|
|
44
|
+
const lat1 = toRadians(from.lat);
|
|
45
|
+
const lat2 = toRadians(to.lat);
|
|
46
|
+
|
|
47
|
+
const x = Math.sin(dLng) * Math.cos(lat2);
|
|
48
|
+
const y = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLng);
|
|
49
|
+
|
|
50
|
+
const bearing = Math.atan2(x, y);
|
|
51
|
+
return ((bearing * 180) / Math.PI + 360) % 360;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Convert degrees to radians.
|
|
56
|
+
*/
|
|
57
|
+
function toRadians(degrees: number): number {
|
|
58
|
+
return (degrees * Math.PI) / 180;
|
|
59
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LocalForage adapter - IndexedDB storage with automatic fallbacks.
|
|
3
|
+
*
|
|
4
|
+
* Uses localforage which provides IndexedDB storage with automatic
|
|
5
|
+
* fallbacks to WebSQL and localStorage. This allows storing much more
|
|
6
|
+
* data than raw localStorage (which is limited to ~5MB).
|
|
7
|
+
*
|
|
8
|
+
* Unlike LocalStorageAdapter, this adapter can store binary data
|
|
9
|
+
* (ArrayBuffer, Blob, Uint8Array) natively without JSON serialization.
|
|
10
|
+
*
|
|
11
|
+
* Ported from qualla-internal/shared/services/StorageAdapters.ts with
|
|
12
|
+
* configurable store name and key prefix.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import localforage from 'localforage';
|
|
16
|
+
import type { StorageAdapter } from './Storage.js';
|
|
17
|
+
|
|
18
|
+
export interface LocalForageAdapterOptions {
|
|
19
|
+
/** IndexedDB database name (default: 'squisq') */
|
|
20
|
+
name?: string;
|
|
21
|
+
/** IndexedDB object store name (default: 'data') */
|
|
22
|
+
storeName?: string;
|
|
23
|
+
/** Key prefix for namespacing (default: '') */
|
|
24
|
+
prefix?: string;
|
|
25
|
+
/** Human-readable description (default: 'Squisq storage') */
|
|
26
|
+
description?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class LocalForageAdapter implements StorageAdapter {
|
|
30
|
+
readonly supportsEnumeration = true;
|
|
31
|
+
private store: LocalForage;
|
|
32
|
+
private prefix: string;
|
|
33
|
+
|
|
34
|
+
constructor(options: LocalForageAdapterOptions = {}) {
|
|
35
|
+
const {
|
|
36
|
+
name = 'squisq',
|
|
37
|
+
storeName = 'data',
|
|
38
|
+
prefix = '',
|
|
39
|
+
description = 'Squisq storage',
|
|
40
|
+
} = options;
|
|
41
|
+
|
|
42
|
+
this.prefix = prefix;
|
|
43
|
+
this.store = localforage.createInstance({ name, storeName, description });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async get<T>(key: string): Promise<T | null> {
|
|
47
|
+
try {
|
|
48
|
+
const value = await this.store.getItem<T>(this.prefix + key);
|
|
49
|
+
return value;
|
|
50
|
+
} catch (e: unknown) {
|
|
51
|
+
console.warn('[Storage] get (IndexedDB) failed:', key, e);
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async set<T>(key: string, value: T): Promise<void> {
|
|
57
|
+
try {
|
|
58
|
+
await this.store.setItem(this.prefix + key, value);
|
|
59
|
+
} catch (e: unknown) {
|
|
60
|
+
console.error('[Storage] set (IndexedDB) failed:', key, e);
|
|
61
|
+
throw e;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async remove(key: string): Promise<void> {
|
|
66
|
+
try {
|
|
67
|
+
await this.store.removeItem(this.prefix + key);
|
|
68
|
+
} catch (e: unknown) {
|
|
69
|
+
console.warn('[Storage] remove (IndexedDB) failed:', key, e);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async clear(): Promise<void> {
|
|
74
|
+
try {
|
|
75
|
+
if (this.prefix) {
|
|
76
|
+
// Only remove keys with our prefix
|
|
77
|
+
const keys = await this.store.keys();
|
|
78
|
+
const keysToRemove = keys.filter((k) => k.startsWith(this.prefix));
|
|
79
|
+
await Promise.all(keysToRemove.map((k) => this.store.removeItem(k)));
|
|
80
|
+
} else {
|
|
81
|
+
// No prefix — clear the entire store
|
|
82
|
+
await this.store.clear();
|
|
83
|
+
}
|
|
84
|
+
} catch (e: unknown) {
|
|
85
|
+
console.error('[Storage] clear (IndexedDB) failed:', e);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async keys(): Promise<string[]> {
|
|
90
|
+
try {
|
|
91
|
+
const allKeys = await this.store.keys();
|
|
92
|
+
if (this.prefix) {
|
|
93
|
+
return allKeys
|
|
94
|
+
.filter((k) => k.startsWith(this.prefix))
|
|
95
|
+
.map((k) => k.slice(this.prefix.length));
|
|
96
|
+
}
|
|
97
|
+
return allKeys;
|
|
98
|
+
} catch (e: unknown) {
|
|
99
|
+
console.warn('[Storage] keys (IndexedDB) failed:', e);
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* localStorage adapter for web browsers.
|
|
3
|
+
* Supports a configurable key prefix to namespace stored data.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { StorageAdapter } from './Storage.js';
|
|
7
|
+
|
|
8
|
+
export class LocalStorageAdapter implements StorageAdapter {
|
|
9
|
+
readonly supportsEnumeration = true;
|
|
10
|
+
private prefix: string;
|
|
11
|
+
|
|
12
|
+
constructor(prefix = '') {
|
|
13
|
+
this.prefix = prefix;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async get<T>(key: string): Promise<T | null> {
|
|
17
|
+
try {
|
|
18
|
+
const raw = localStorage.getItem(this.prefix + key);
|
|
19
|
+
if (raw === null) return null;
|
|
20
|
+
return JSON.parse(raw) as T;
|
|
21
|
+
} catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async set<T>(key: string, value: T): Promise<void> {
|
|
27
|
+
localStorage.setItem(this.prefix + key, JSON.stringify(value));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async remove(key: string): Promise<void> {
|
|
31
|
+
localStorage.removeItem(this.prefix + key);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async clear(): Promise<void> {
|
|
35
|
+
const keysToRemove: string[] = [];
|
|
36
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
37
|
+
const k = localStorage.key(i);
|
|
38
|
+
if (k && k.startsWith(this.prefix)) {
|
|
39
|
+
keysToRemove.push(k);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
for (const k of keysToRemove) {
|
|
43
|
+
localStorage.removeItem(k);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async keys(): Promise<string[]> {
|
|
48
|
+
const result: string[] = [];
|
|
49
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
50
|
+
const k = localStorage.key(i);
|
|
51
|
+
if (k && k.startsWith(this.prefix)) {
|
|
52
|
+
result.push(k.slice(this.prefix.length));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory storage adapter for testing and SSR environments.
|
|
3
|
+
* Data does not persist across page reloads.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { StorageAdapter } from './Storage.js';
|
|
7
|
+
|
|
8
|
+
export class MemoryStorageAdapter implements StorageAdapter {
|
|
9
|
+
readonly supportsEnumeration = true;
|
|
10
|
+
private store = new Map<string, string>();
|
|
11
|
+
|
|
12
|
+
async get<T>(key: string): Promise<T | null> {
|
|
13
|
+
const val = this.store.get(key);
|
|
14
|
+
if (val === undefined) return null;
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(val) as T;
|
|
17
|
+
} catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async set<T>(key: string, value: T): Promise<void> {
|
|
23
|
+
this.store.set(key, JSON.stringify(value));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async remove(key: string): Promise<void> {
|
|
27
|
+
this.store.delete(key);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async clear(): Promise<void> {
|
|
31
|
+
this.store.clear();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async keys(): Promise<string[]> {
|
|
35
|
+
return Array.from(this.store.keys());
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage - Abstract persistence interface
|
|
3
|
+
*
|
|
4
|
+
* Defines the contract for persistent storage across different environments.
|
|
5
|
+
* All values are JSON-serialized, so any serializable value can be stored.
|
|
6
|
+
* Keys can be automatically namespaced with a configurable prefix.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Storage adapter interface - implemented by environment-specific adapters */
|
|
10
|
+
export interface StorageAdapter {
|
|
11
|
+
/** Get a value by key, returns null if not found */
|
|
12
|
+
get<T>(key: string): Promise<T | null>;
|
|
13
|
+
|
|
14
|
+
/** Set a value for a key */
|
|
15
|
+
set<T>(key: string, value: T): Promise<void>;
|
|
16
|
+
|
|
17
|
+
/** Remove a value by key */
|
|
18
|
+
remove(key: string): Promise<void>;
|
|
19
|
+
|
|
20
|
+
/** Clear all stored values (within our namespace) */
|
|
21
|
+
clear(): Promise<void>;
|
|
22
|
+
|
|
23
|
+
/** Get all keys (within our namespace) */
|
|
24
|
+
keys(): Promise<string[]>;
|
|
25
|
+
|
|
26
|
+
/** Check if this adapter supports enumeration */
|
|
27
|
+
readonly supportsEnumeration: boolean;
|
|
28
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { StorageAdapter } from './Storage.js';
|
|
2
|
+
export { MemoryStorageAdapter } from './MemoryStorageAdapter.js';
|
|
3
|
+
export { LocalStorageAdapter } from './LocalStorageAdapter.js';
|
|
4
|
+
export { LocalForageAdapter } from './LocalForageAdapter.js';
|
|
5
|
+
export type { LocalForageAdapterOptions } from './LocalForageAdapter.js';
|