@yoamigo.com/core 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.
@@ -0,0 +1,13 @@
1
+ export { A as AssetResolverFn, C as ContentRegistry, c as contentRegistry, a as getAllContent, g as getContent, h as hasContent, r as registerContent, b as resolveAssetUrl, s as setAssetResolver } from './asset-resolver-BnIvDkVv.js';
2
+ export { C as ContactFormData, S as SiteMetadata, g as getSiteMetadata, a as submitContactForm, s as subscribeToNewsletter } from './api-client-D8FkeBAI.js';
3
+
4
+ /**
5
+ * YoAmigo Library Utilities - Production Barrel
6
+ *
7
+ * Excludes dev-only builder selection code for smaller bundle size.
8
+ * Builder selection (~21KB) is only needed in development/preview mode.
9
+ */
10
+
11
+ declare const initBuilderSelection: () => void;
12
+
13
+ export { initBuilderSelection };
@@ -0,0 +1,108 @@
1
+ // src/lib/content-registry.ts
2
+ var contentMap = /* @__PURE__ */ new Map();
3
+ function registerContent(content) {
4
+ contentMap = new Map(Object.entries(content));
5
+ }
6
+ function getContent(fieldId) {
7
+ return contentMap.get(fieldId) ?? "";
8
+ }
9
+ function getAllContent() {
10
+ return Object.fromEntries(contentMap);
11
+ }
12
+ function hasContent(fieldId) {
13
+ return contentMap.has(fieldId);
14
+ }
15
+ var contentRegistry = {
16
+ registerContent,
17
+ getContent,
18
+ getAllContent,
19
+ hasContent
20
+ };
21
+
22
+ // src/lib/asset-resolver.ts
23
+ var assetResolver = (path) => path;
24
+ function setAssetResolver(resolver) {
25
+ assetResolver = resolver;
26
+ }
27
+ function resolveAssetUrl(path) {
28
+ if (!path) return "";
29
+ if (path.startsWith("http://") || path.startsWith("https://")) {
30
+ return path;
31
+ }
32
+ return assetResolver(path);
33
+ }
34
+
35
+ // src/lib/api-client.ts
36
+ function getApiUrl() {
37
+ const runtimeConfig = window.YOAMIGO_CONFIG;
38
+ const apiUrl = runtimeConfig?.apiUrl || import.meta.env.YA_API_URL;
39
+ if (!apiUrl) {
40
+ throw new Error("API URL not configured (check YOAMIGO_CONFIG or YA_API_URL)");
41
+ }
42
+ return apiUrl;
43
+ }
44
+ function getSiteId() {
45
+ const runtimeConfig = window.YOAMIGO_CONFIG;
46
+ const siteId = runtimeConfig?.siteId || import.meta.env.YA_SITE_ID;
47
+ if (!siteId) {
48
+ throw new Error("Site ID not configured (check YOAMIGO_CONFIG or YA_SITE_ID)");
49
+ }
50
+ return siteId;
51
+ }
52
+ async function subscribeToNewsletter(email) {
53
+ const apiUrl = getApiUrl();
54
+ const siteId = getSiteId();
55
+ const response = await fetch(`${apiUrl}/api/websites/${siteId}/subscribe`, {
56
+ method: "POST",
57
+ headers: {
58
+ "Content-Type": "application/json"
59
+ },
60
+ body: JSON.stringify({
61
+ email,
62
+ emailOptIn: true,
63
+ smsOptIn: false
64
+ })
65
+ });
66
+ if (!response.ok) {
67
+ const error = await response.json().catch(() => ({ message: "Failed to subscribe" }));
68
+ throw new Error(error.message || "Failed to subscribe");
69
+ }
70
+ return response.json();
71
+ }
72
+ async function submitContactForm(data) {
73
+ const apiUrl = getApiUrl();
74
+ const siteId = getSiteId();
75
+ const response = await fetch(`${apiUrl}/api/websites/${siteId}/contact`, {
76
+ method: "POST",
77
+ headers: {
78
+ "Content-Type": "application/json"
79
+ },
80
+ body: JSON.stringify(data)
81
+ });
82
+ if (!response.ok) {
83
+ const error = await response.json().catch(() => ({ message: "Failed to submit form" }));
84
+ throw new Error(error.message || "Failed to submit form");
85
+ }
86
+ return response.json();
87
+ }
88
+ async function getSiteMetadata() {
89
+ const runtimeConfig = window.YOAMIGO_CONFIG;
90
+ return runtimeConfig || null;
91
+ }
92
+
93
+ // src/lib/index.prod.ts
94
+ var initBuilderSelection = () => {
95
+ };
96
+ export {
97
+ contentRegistry,
98
+ getAllContent,
99
+ getContent,
100
+ getSiteMetadata,
101
+ hasContent,
102
+ initBuilderSelection,
103
+ registerContent,
104
+ resolveAssetUrl,
105
+ setAssetResolver,
106
+ submitContactForm,
107
+ subscribeToNewsletter
108
+ };
package/dist/lib.d.ts ADDED
@@ -0,0 +1,84 @@
1
+ export { A as AssetResolverFn, C as ContentRegistry, c as contentRegistry, a as getAllContent, g as getContent, h as hasContent, r as registerContent, b as resolveAssetUrl, s as setAssetResolver } from './asset-resolver-BnIvDkVv.js';
2
+ export { i as initBuilderSelection } from './builder-selection-CYP91nRu.js';
3
+ export { C as ContactFormData, S as SiteMetadata, g as getSiteMetadata, a as submitContactForm, s as subscribeToNewsletter } from './api-client-D8FkeBAI.js';
4
+
5
+ /**
6
+ * Image Cache - In-memory cache for preloaded images
7
+ *
8
+ * Stores blob URLs for instant image display in the website builder.
9
+ * Populated by parent app via postMessage when builder loads.
10
+ *
11
+ * The parent app (yoamigo) caches images in IndexedDB via useAssetCache.
12
+ * This module receives those cached blob URLs and makes them available
13
+ * to YaImage components for instant rendering.
14
+ */
15
+ interface CachedImageEntry {
16
+ /** Blob URL for instant display (blob://...) */
17
+ blobUrl: string;
18
+ /** Original CDN/Supabase URL for reference */
19
+ originalUrl: string;
20
+ /** Timestamp when cached */
21
+ timestamp: number;
22
+ }
23
+ /**
24
+ * Set multiple cached images at once.
25
+ * Called when receiving cache update from parent via postMessage.
26
+ *
27
+ * @param images Array of cached images with keys and blob URLs
28
+ */
29
+ declare function setCachedImages(images: Array<{
30
+ key: string;
31
+ blobUrl: string;
32
+ originalUrl: string;
33
+ }>): void;
34
+ /**
35
+ * Get cached URL for a source.
36
+ * Returns blob URL if cached, null otherwise.
37
+ *
38
+ * Handles multiple src formats:
39
+ * - 'assets/profile.webp' (from content.json)
40
+ * - 'profile.webp' (filename only)
41
+ * - Full CDN URL (pass-through)
42
+ *
43
+ * @param src The image source path or URL
44
+ * @returns Cached blob URL or null if not cached
45
+ */
46
+ declare function getCachedUrl(src: string): string | null;
47
+ /**
48
+ * Clear all cached images.
49
+ * Called when leaving the builder or on cleanup.
50
+ */
51
+ declare function clearImageCache(): void;
52
+ /**
53
+ * Get cache statistics for debugging.
54
+ */
55
+ declare function getCacheStats(): {
56
+ count: number;
57
+ keys: string[];
58
+ };
59
+ /**
60
+ * Check if an image is cached.
61
+ */
62
+ declare function hasCachedImage(src: string): boolean;
63
+
64
+ /**
65
+ * Image Cache Listener - Receives cached images from parent app
66
+ *
67
+ * Listens for postMessage from the parent (website builder) containing
68
+ * pre-cached image blob URLs. This enables instant image loading in
69
+ * YaImage components without additional network requests.
70
+ *
71
+ * Message Protocol:
72
+ * - YA_IMAGE_CACHE_UPDATE: Parent sends cached blob URLs
73
+ * - YA_IMAGE_CACHE_CLEAR: Parent requests cache clear
74
+ * - YA_IMAGE_CACHE_REQUEST: Iframe requests cache from parent (sent on init)
75
+ */
76
+ /**
77
+ * Start listening for cache updates from parent.
78
+ * Call this when entering inline-edit mode.
79
+ *
80
+ * @returns Cleanup function to stop listening and clear cache
81
+ */
82
+ declare function initImageCacheListener(): () => void;
83
+
84
+ export { type CachedImageEntry, clearImageCache, getCacheStats, getCachedUrl, hasCachedImage, initImageCacheListener, setCachedImages };