@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,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Animation Utilities
|
|
3
|
+
*
|
|
4
|
+
* Helper functions for mapping Doc animations to CSS classes and styles.
|
|
5
|
+
* Generates the appropriate animation class names and CSS custom properties
|
|
6
|
+
* for duration, delay, and easing.
|
|
7
|
+
*
|
|
8
|
+
* This is shared code used by both site and efb-app doc renderers.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { Animation, AnimationType, TransitionType } from '../../schemas/Doc.js';
|
|
12
|
+
|
|
13
|
+
interface AnimationResult {
|
|
14
|
+
/** CSS class name to apply */
|
|
15
|
+
className: string;
|
|
16
|
+
/** Inline styles for CSS custom properties */
|
|
17
|
+
style: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get CSS class and styles for an animation.
|
|
22
|
+
*/
|
|
23
|
+
export function getAnimationStyle(
|
|
24
|
+
animation: Animation | undefined,
|
|
25
|
+
_currentTime: number = 0,
|
|
26
|
+
): AnimationResult {
|
|
27
|
+
if (!animation || animation.type === 'none') {
|
|
28
|
+
return { className: '', style: {} };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const className = getAnimationClassName(animation);
|
|
32
|
+
const style = getAnimationCSSVars(animation);
|
|
33
|
+
|
|
34
|
+
return { className, style };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Map animation type to CSS class name.
|
|
39
|
+
*/
|
|
40
|
+
function getAnimationClassName(animation: Animation): string {
|
|
41
|
+
const { type, direction, panDirection } = animation;
|
|
42
|
+
|
|
43
|
+
switch (type) {
|
|
44
|
+
case 'fadeIn':
|
|
45
|
+
return 'anim-fadeIn';
|
|
46
|
+
case 'fadeOut':
|
|
47
|
+
return 'anim-fadeOut';
|
|
48
|
+
case 'slowZoom':
|
|
49
|
+
// Slow zoom (Ken Burns style) has variants based on direction and pan
|
|
50
|
+
if (panDirection === 'left') return 'anim-slowZoom-panLeft';
|
|
51
|
+
if (panDirection === 'right') return 'anim-slowZoom-panRight';
|
|
52
|
+
if (direction === 'out') return 'anim-slowZoom-out';
|
|
53
|
+
return 'anim-slowZoom-in';
|
|
54
|
+
case 'zoomIn':
|
|
55
|
+
return 'anim-zoomIn';
|
|
56
|
+
case 'zoomOut':
|
|
57
|
+
return 'anim-zoomOut';
|
|
58
|
+
case 'panLeft':
|
|
59
|
+
return 'anim-panLeft';
|
|
60
|
+
case 'panRight':
|
|
61
|
+
return 'anim-panRight';
|
|
62
|
+
case 'typewriter':
|
|
63
|
+
return 'anim-typewriter';
|
|
64
|
+
default:
|
|
65
|
+
return '';
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Generate CSS custom properties for animation timing.
|
|
71
|
+
*/
|
|
72
|
+
function getAnimationCSSVars(animation: Animation): Record<string, string> {
|
|
73
|
+
const vars: Record<string, string> = {};
|
|
74
|
+
|
|
75
|
+
if (animation.duration !== undefined) {
|
|
76
|
+
vars['--anim-duration'] = `${animation.duration}s`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (animation.delay !== undefined) {
|
|
80
|
+
vars['--anim-delay'] = `${animation.delay}s`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (animation.easing) {
|
|
84
|
+
vars['--anim-easing'] = animation.easing;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return vars;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get default duration for an animation type.
|
|
92
|
+
*/
|
|
93
|
+
export function getDefaultAnimationDuration(type: AnimationType): number {
|
|
94
|
+
switch (type) {
|
|
95
|
+
case 'slowZoom':
|
|
96
|
+
case 'panLeft':
|
|
97
|
+
case 'panRight':
|
|
98
|
+
return 8; // Long, slow animations
|
|
99
|
+
case 'typewriter':
|
|
100
|
+
return 3;
|
|
101
|
+
case 'fadeIn':
|
|
102
|
+
case 'fadeOut':
|
|
103
|
+
return 1;
|
|
104
|
+
case 'zoomIn':
|
|
105
|
+
case 'zoomOut':
|
|
106
|
+
return 0.5;
|
|
107
|
+
default:
|
|
108
|
+
return 1;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Get transition class for slide entry/exit.
|
|
114
|
+
*/
|
|
115
|
+
export function getTransitionClass(type: TransitionType, entering: boolean): string {
|
|
116
|
+
const mode = entering ? 'enter' : 'exit';
|
|
117
|
+
return `transition-${type}-${mode}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Calculate animation progress (0-1) based on current time.
|
|
122
|
+
*/
|
|
123
|
+
export function getAnimationProgress(
|
|
124
|
+
animation: Animation,
|
|
125
|
+
currentTime: number,
|
|
126
|
+
slideDuration: number,
|
|
127
|
+
): number {
|
|
128
|
+
const delay = animation.delay || 0;
|
|
129
|
+
const duration = animation.duration || slideDuration;
|
|
130
|
+
|
|
131
|
+
if (currentTime < delay) return 0;
|
|
132
|
+
if (currentTime >= delay + duration) return 1;
|
|
133
|
+
|
|
134
|
+
return (currentTime - delay) / duration;
|
|
135
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme Utilities
|
|
3
|
+
*
|
|
4
|
+
* Template-facing helpers that read from the Theme object on the
|
|
5
|
+
* TemplateContext. Templates call these instead of hard-coding style
|
|
6
|
+
* decisions, so the same template code adapts to any theme.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { TemplateContext } from '../../schemas/BlockTemplates.js';
|
|
10
|
+
import type { ThemeColorScheme, RenderStyle } from '../../schemas/Theme.js';
|
|
11
|
+
import type { AnimationType } from '../../schemas/Doc.js';
|
|
12
|
+
|
|
13
|
+
// ============================================
|
|
14
|
+
// Color Scheme Resolution
|
|
15
|
+
// ============================================
|
|
16
|
+
|
|
17
|
+
/** Fallback color scheme when a name is not found in the theme. */
|
|
18
|
+
const FALLBACK_COLOR_SCHEME: ThemeColorScheme = {
|
|
19
|
+
bg: '#1a365d',
|
|
20
|
+
text: '#63b3ed',
|
|
21
|
+
accent: '#90cdf4',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Resolve a named color scheme from the theme, with a safe fallback.
|
|
26
|
+
* Templates call this instead of `COLOR_SCHEMES[name]`.
|
|
27
|
+
*/
|
|
28
|
+
export function resolveColorScheme(
|
|
29
|
+
context: TemplateContext,
|
|
30
|
+
name: string | undefined,
|
|
31
|
+
): ThemeColorScheme {
|
|
32
|
+
const schemes = context.theme.colorSchemes;
|
|
33
|
+
if (name && name in schemes) return schemes[name];
|
|
34
|
+
// Fall back to first defined scheme, then hard fallback
|
|
35
|
+
const keys = Object.keys(schemes);
|
|
36
|
+
if (keys.length > 0) return schemes[keys[0]];
|
|
37
|
+
return FALLBACK_COLOR_SCHEME;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// ============================================
|
|
41
|
+
// Font Sizing
|
|
42
|
+
// ============================================
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Calculate a theme-aware scaled font size.
|
|
46
|
+
* Applies the theme's typography scale multipliers on top of the
|
|
47
|
+
* viewport-based font scale from LayoutStrategy.
|
|
48
|
+
*
|
|
49
|
+
* @param basePx Base font size designed for 1920×1080
|
|
50
|
+
* @param context Template context (includes fontScale, layout, theme)
|
|
51
|
+
* @param isTitle Whether this is title text (uses titleScale) or body (bodyScale)
|
|
52
|
+
*/
|
|
53
|
+
export function themedFontSize(
|
|
54
|
+
basePx: number,
|
|
55
|
+
context: TemplateContext,
|
|
56
|
+
isTitle: boolean = false,
|
|
57
|
+
): number {
|
|
58
|
+
const { fontScale, layout, theme } = context;
|
|
59
|
+
|
|
60
|
+
// Base scale from viewport + orientation
|
|
61
|
+
const layoutScale = isTitle ? layout.titleScale : layout.bodyScale;
|
|
62
|
+
|
|
63
|
+
// Theme multiplier (defaults to 1.0 when not set)
|
|
64
|
+
const themeScale = isTitle
|
|
65
|
+
? (theme.typography.titleScale ?? 1.0)
|
|
66
|
+
: (theme.typography.bodyScale ?? 1.0);
|
|
67
|
+
|
|
68
|
+
return Math.round(basePx * fontScale * layoutScale * themeScale);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ============================================
|
|
72
|
+
// Animation Helpers
|
|
73
|
+
// ============================================
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Scale an animation duration by the theme's animationSpeed multiplier.
|
|
77
|
+
* A speed of 1.0 returns the base duration unchanged.
|
|
78
|
+
*/
|
|
79
|
+
export function scaleAnimationDuration(baseDuration: number, context: TemplateContext): number {
|
|
80
|
+
const speed = context.theme.style.animationSpeed ?? 1.0;
|
|
81
|
+
return baseDuration * speed;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Get the theme's default animation type for a layer kind.
|
|
86
|
+
* Returns `undefined` when the theme doesn't specify one (template picks its own).
|
|
87
|
+
*/
|
|
88
|
+
export function getDefaultAnimation(
|
|
89
|
+
context: TemplateContext,
|
|
90
|
+
layerType: 'text' | 'image',
|
|
91
|
+
): AnimationType | undefined {
|
|
92
|
+
const rs: RenderStyle = context.theme.renderStyle;
|
|
93
|
+
return layerType === 'text' ? rs.defaultTextAnimation : rs.defaultImageAnimation;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// ============================================
|
|
97
|
+
// Style Helpers
|
|
98
|
+
// ============================================
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Whether the theme defaults to text shadows.
|
|
102
|
+
* Templates should consult this when choosing `shadow: true/false`.
|
|
103
|
+
*/
|
|
104
|
+
export function shouldUseShadow(context: TemplateContext): boolean {
|
|
105
|
+
return context.theme.style.textShadow ?? true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Get the theme's overlay opacity for image-backed blocks.
|
|
110
|
+
*/
|
|
111
|
+
export function getOverlayOpacity(context: TemplateContext): number {
|
|
112
|
+
return context.theme.style.overlayOpacity ?? 0.5;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// ============================================
|
|
116
|
+
// Template Hint Access
|
|
117
|
+
// ============================================
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Read a per-template hint from the theme's renderStyle.
|
|
121
|
+
* Returns `fallback` when the hint isn't defined.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* const entrance = getTemplateHint(context, 'statHighlight', 'entrance', 'subtle');
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export function getTemplateHint<T extends string | number | boolean>(
|
|
129
|
+
context: TemplateContext,
|
|
130
|
+
templateName: string,
|
|
131
|
+
key: string,
|
|
132
|
+
fallback: T,
|
|
133
|
+
): T {
|
|
134
|
+
const hints = context.theme.renderStyle.templateHints;
|
|
135
|
+
if (!hints) return fallback;
|
|
136
|
+
const tplHints = hints[templateName];
|
|
137
|
+
if (!tplHints || !(key in tplHints)) return fallback;
|
|
138
|
+
return tplHints[key] as T;
|
|
139
|
+
}
|