@replohq/canopy-sdk 0.4.0 → 0.4.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/_vendor/replo-utils/lib/errors.d.ts +1 -1
- package/_vendor/replo-utils/lib/{google-fonts.d.ts → fonts.d.ts} +25 -10
- package/_vendor/replo-utils/lib/fonts.mjs +78 -0
- package/_vendor/replo-utils/lib/misc.d.ts +17 -17
- package/_vendor/replo-utils/lib/object.d.ts +3 -3
- package/_vendor/replo-utils/lib/parse.d.ts +1 -1
- package/_vendor/schemas/designLibrary.d.ts +15 -0
- package/_vendor/schemas/designLibrary.mjs +11 -1
- package/analytics/utils/analytics-utils.d.ts +1 -1
- package/analytics/utils/analytics-utils.js.map +2 -2
- package/editor/design-library-preview/DesignLibraryPreview.js +1 -1
- package/editor/design-library-preview/DesignLibraryPreview.js.map +1 -1
- package/hooks/use-client-value.d.ts +1 -1
- package/hooks/use-client-value.js.map +2 -2
- package/package.json +1 -1
- package/_vendor/replo-utils/lib/google-fonts.mjs +0 -28
|
@@ -17,18 +17,33 @@ export declare function quoteFontFamily(family: string): string;
|
|
|
17
17
|
* "DM Sans" → "dmSans". The JS const name for a `next/font` declaration.
|
|
18
18
|
*/
|
|
19
19
|
export declare function fontNameToVariableName(fontName: string): string;
|
|
20
|
-
export interface NextFontDeclaration {
|
|
21
|
-
/** Import name for `next/font/google`, e.g. "DM_Sans". */
|
|
22
|
-
importName: string;
|
|
23
|
-
/** JS const name, e.g. "dmSans". */
|
|
24
|
-
variableName: string;
|
|
25
|
-
/** CSS variable the import exposes, e.g. "--font-dm-sans". */
|
|
26
|
-
cssVar: string;
|
|
27
|
-
/** The full `const … = …({ … })` declaration. */
|
|
28
|
-
declaration: string;
|
|
29
|
-
}
|
|
30
20
|
/**
|
|
31
21
|
* Google Fonts CSS2 stylesheet URL for a family at the given weights (defaulting
|
|
32
22
|
* to 400), with `display=swap`.
|
|
33
23
|
*/
|
|
34
24
|
export declare function buildGoogleFontsCssUrl(family: string, weights?: number[]): string;
|
|
25
|
+
/**
|
|
26
|
+
* "Brand Sans-Bold.woff2" → { family: "Brand Sans Bold", mimeType: "font/woff2" }.
|
|
27
|
+
* The family is derived from the filename since Bedrock assets don't store one.
|
|
28
|
+
*/
|
|
29
|
+
export declare function describeFontFile(fileName: string): {
|
|
30
|
+
family: string;
|
|
31
|
+
mimeType: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The `format(...)` keyword for an @font-face src, from a font file extension
|
|
35
|
+
* (Bedrock's `find` returns `fileExtension`, not a MIME type).
|
|
36
|
+
*/
|
|
37
|
+
export declare function fontFormatFromExtension(extension: string): string;
|
|
38
|
+
/** The `format(...)` keyword for an @font-face src, from a font MIME type. */
|
|
39
|
+
export declare function fontFormatFromMimeType(mimeType: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* The @font-face rule that makes a custom family renderable from its asset URL.
|
|
42
|
+
*/
|
|
43
|
+
export declare function buildFontFaceCss({ family, faceUrl, format, weight, }: {
|
|
44
|
+
family: string;
|
|
45
|
+
faceUrl: string;
|
|
46
|
+
format: string;
|
|
47
|
+
weight?: number;
|
|
48
|
+
}): string;
|
|
49
|
+
export declare const escapeFontFamilyName: (fontFamily: string) => string;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// ../replo-utils/lib/fonts.ts
|
|
2
|
+
function slugifyFontFamily(family) {
|
|
3
|
+
return family.replace(/([a-z])([A-Z])/g, "$1-$2").split(/[\s_-]+/u).map((word) => word.toLowerCase()).join("-");
|
|
4
|
+
}
|
|
5
|
+
function fontNameToCssVariable(fontName) {
|
|
6
|
+
return `--font-${slugifyFontFamily(fontName)}`;
|
|
7
|
+
}
|
|
8
|
+
function quoteFontFamily(family) {
|
|
9
|
+
return /\s/u.test(family) ? `'${family}'` : family;
|
|
10
|
+
}
|
|
11
|
+
function fontNameToVariableName(fontName) {
|
|
12
|
+
const words = fontName.replace(/([a-z])([A-Z])/g, "$1 $2").split(/[\s_-]+/u);
|
|
13
|
+
return words.map((word, index) => {
|
|
14
|
+
return index === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
15
|
+
}).join("");
|
|
16
|
+
}
|
|
17
|
+
function buildGoogleFontsCssUrl(family, weights) {
|
|
18
|
+
const requested = weights && weights.length > 0 ? Array.from(new Set(weights)) : [400];
|
|
19
|
+
const sortedWeights = requested.sort(
|
|
20
|
+
(leftWeight, rightWeight) => leftWeight - rightWeight
|
|
21
|
+
);
|
|
22
|
+
const familyParam = family.trim().replace(/\s+/gu, "+");
|
|
23
|
+
return `https://fonts.googleapis.com/css2?family=${familyParam}:wght@${sortedWeights.join(
|
|
24
|
+
";"
|
|
25
|
+
)}&display=swap`;
|
|
26
|
+
}
|
|
27
|
+
var FONT_MIME_BY_EXTENSION = {
|
|
28
|
+
woff2: "font/woff2",
|
|
29
|
+
woff: "font/woff",
|
|
30
|
+
ttf: "font/ttf",
|
|
31
|
+
otf: "font/otf"
|
|
32
|
+
};
|
|
33
|
+
function describeFontFile(fileName) {
|
|
34
|
+
const lastDot = fileName.lastIndexOf(".");
|
|
35
|
+
const base = lastDot > 0 ? fileName.slice(0, lastDot) : fileName;
|
|
36
|
+
const extension = lastDot > 0 ? fileName.slice(lastDot + 1).toLowerCase() : "";
|
|
37
|
+
const family = base.replace(/[_-]+/gu, " ").replace(/\s+/gu, " ").trim() || "Custom font";
|
|
38
|
+
return {
|
|
39
|
+
family,
|
|
40
|
+
mimeType: FONT_MIME_BY_EXTENSION[extension] ?? "font/woff2"
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function fontFormatFromExtension(extension) {
|
|
44
|
+
const normalized = extension.toLowerCase().replace(/^\./u, "");
|
|
45
|
+
if (normalized === "woff2") return "woff2";
|
|
46
|
+
if (normalized === "woff") return "woff";
|
|
47
|
+
if (normalized === "otf") return "opentype";
|
|
48
|
+
if (normalized === "ttf") return "truetype";
|
|
49
|
+
return "woff2";
|
|
50
|
+
}
|
|
51
|
+
function fontFormatFromMimeType(mimeType) {
|
|
52
|
+
const normalized = mimeType.toLowerCase();
|
|
53
|
+
if (normalized.includes("woff2")) return "woff2";
|
|
54
|
+
if (normalized.includes("woff")) return "woff";
|
|
55
|
+
if (normalized.includes("otf") || normalized.includes("opentype")) {
|
|
56
|
+
return "opentype";
|
|
57
|
+
}
|
|
58
|
+
if (normalized.includes("ttf") || normalized.includes("truetype")) {
|
|
59
|
+
return "truetype";
|
|
60
|
+
}
|
|
61
|
+
return "woff2";
|
|
62
|
+
}
|
|
63
|
+
function escapeCssString(value) {
|
|
64
|
+
return value.replace(/\\/gu, "\\\\").replace(/"/gu, '\\"');
|
|
65
|
+
}
|
|
66
|
+
function buildFontFaceCss({
|
|
67
|
+
family,
|
|
68
|
+
faceUrl,
|
|
69
|
+
format,
|
|
70
|
+
weight = 400
|
|
71
|
+
}) {
|
|
72
|
+
return `@font-face{font-family:"${escapeCssString(family)}";font-weight:${weight};font-style:normal;src:url("${escapeCssString(faceUrl)}") format("${escapeCssString(format)}");font-display:swap;}`;
|
|
73
|
+
}
|
|
74
|
+
var escapeFontFamilyName = (fontFamily) => {
|
|
75
|
+
return fontFamily.replace(/"/g, '\\"').replace(/'/g, "\\'");
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export { buildFontFaceCss, buildGoogleFontsCssUrl, describeFontFile, escapeFontFamilyName, fontFormatFromExtension, fontFormatFromMimeType, fontNameToCssVariable, fontNameToVariableName, quoteFontFamily, slugifyFontFamily };
|
|
@@ -5,7 +5,7 @@ export { isFunction, isNumber, isString };
|
|
|
5
5
|
/**
|
|
6
6
|
* Checks if a value is neither `null` nor `undefined`.
|
|
7
7
|
*/
|
|
8
|
-
export declare function isNotNullish<
|
|
8
|
+
export declare function isNotNullish<ValueType>(value: ValueType): value is Exclude<ValueType, null | undefined>;
|
|
9
9
|
/**
|
|
10
10
|
* Checks if a value is either `null` or `undefined`.
|
|
11
11
|
*/
|
|
@@ -14,13 +14,13 @@ export declare function isRecord(value: unknown): value is Record<string, unknow
|
|
|
14
14
|
export declare function stringValue(value: unknown): string | null;
|
|
15
15
|
export declare function getFromRecordOrNull<RecordKey extends PropertyKey, RecordValue>(record: Record<RecordKey, RecordValue> | null | undefined, key: RecordKey | undefined | null): NonNullable<Record<RecordKey, RecordValue>[RecordKey]> | null;
|
|
16
16
|
export declare function isPrimitive(value: unknown): value is string | number | boolean;
|
|
17
|
-
type StructureRecord<
|
|
17
|
+
type StructureRecord<UnionType extends {
|
|
18
18
|
type: string;
|
|
19
|
-
},
|
|
20
|
-
[
|
|
19
|
+
}, ResultType> = {
|
|
20
|
+
[MemberType in UnionType as MemberType["type"]]: ResultType | ((value: MemberType) => ResultType);
|
|
21
21
|
};
|
|
22
|
-
type StructureRecordGeneric<
|
|
23
|
-
[
|
|
22
|
+
type StructureRecordGeneric<UnionType extends Record<KeyType, string>, ResultType, KeyType extends keyof UnionType> = {
|
|
23
|
+
[MemberType in UnionType as MemberType[KeyType]]: ResultType | ((value: MemberType) => ResultType);
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
26
|
* @returns A function which can be used to create an exhaustive switch over all
|
|
@@ -61,26 +61,26 @@ type StructureRecordGeneric<A extends Record<K, string>, R, K extends keyof A> =
|
|
|
61
61
|
*
|
|
62
62
|
* Works well for many of our types, like ComponentActionType, Action, etc
|
|
63
63
|
*/
|
|
64
|
-
export declare function exhaustiveSwitch<
|
|
64
|
+
export declare function exhaustiveSwitch<UnionType extends {
|
|
65
65
|
type: string;
|
|
66
|
-
}>(value:
|
|
67
|
-
export declare function exhaustiveSwitch<
|
|
68
|
-
type EmptyObject<
|
|
69
|
-
[
|
|
66
|
+
}>(value: UnionType): <ResultType>(cases: StructureRecord<UnionType, ResultType>) => ResultType;
|
|
67
|
+
export declare function exhaustiveSwitch<UnionType extends Record<KeyType, string>, KeyType extends keyof UnionType>(value: UnionType, key: KeyType): <ResultType>(cases: StructureRecordGeneric<UnionType, ResultType, KeyType>) => ResultType;
|
|
68
|
+
type EmptyObject<ObjectType> = {
|
|
69
|
+
[KeyType in keyof ObjectType]?: never;
|
|
70
70
|
};
|
|
71
|
-
type EmptyObjectOf<
|
|
71
|
+
type EmptyObjectOf<ObjectType> = EmptyObject<ObjectType> extends ObjectType ? EmptyObject<ObjectType> : never;
|
|
72
72
|
/**
|
|
73
73
|
* The same as `isEmpty` from lodash, but with a few additional overloads for
|
|
74
74
|
* stronger type-checking on empty arrays.
|
|
75
75
|
*/
|
|
76
76
|
export declare function isEmpty(value: string): value is "";
|
|
77
|
-
export declare function isEmpty<
|
|
78
|
-
export declare function isEmpty<
|
|
77
|
+
export declare function isEmpty<ArrayType extends any[]>(value: ArrayType | null | undefined): value is (ArrayType & []) | null | undefined;
|
|
78
|
+
export declare function isEmpty<ArrayLikeType extends ArrayLike<any>>(value: ArrayLikeType | null | undefined): value is (ArrayLikeType & {
|
|
79
79
|
length: 0;
|
|
80
80
|
}) | null | undefined;
|
|
81
81
|
export declare function isEmpty(value: Map<any, any> | Set<any> | ArrayLike<any> | null | undefined): boolean;
|
|
82
82
|
export declare function isEmpty(value: object): boolean;
|
|
83
|
-
export declare function isEmpty<
|
|
83
|
+
export declare function isEmpty<ObjectType extends object>(value: ObjectType | null | undefined): value is EmptyObjectOf<ObjectType> | null | undefined;
|
|
84
84
|
export declare function isEmpty(value?: any): boolean;
|
|
85
85
|
export declare function noop(): void;
|
|
86
86
|
export declare function preventDefault(event: {
|
|
@@ -103,13 +103,13 @@ export declare function invariant(condition: unknown, message: string | (() => s
|
|
|
103
103
|
}): asserts condition;
|
|
104
104
|
export declare const mergeReplacingObjects: (first: Object, second: Object) => void;
|
|
105
105
|
export declare const mergeReplacingArrays: (first: Object, second: Object) => void;
|
|
106
|
-
export declare const deepCloneAndMergeReplacingArrays: <
|
|
106
|
+
export declare const deepCloneAndMergeReplacingArrays: <SourceType>(source: SourceType, ...toMerge: Object[]) => SourceType;
|
|
107
107
|
/**
|
|
108
108
|
* hasOwnProperty with a type assertion. If this returns true, typescript knows that `obj`
|
|
109
109
|
* has a property called `prop` from that point forward
|
|
110
110
|
* https://fettblog.eu/typescript-hasownproperty/
|
|
111
111
|
*/
|
|
112
|
-
export declare function hasOwnProperty<
|
|
112
|
+
export declare function hasOwnProperty<ObjectType extends {} | null | undefined, PropType extends PropertyKey>(obj: ObjectType, prop: PropType): obj is ObjectType & Record<PropType, unknown>;
|
|
113
113
|
/**
|
|
114
114
|
* Given a string | number param, converts it to a string, unless it's nullish
|
|
115
115
|
* in which case it just returns it. Useful for times when you have string | number
|
|
@@ -25,7 +25,7 @@ export declare const deepEqual: typeof dequalLite;
|
|
|
25
25
|
* @param keysToOmit - Array of keys to omit from the result
|
|
26
26
|
* @returns A new object without the specified keys
|
|
27
27
|
*/
|
|
28
|
-
export declare function omit<
|
|
29
|
-
export declare function filterUndefined<
|
|
30
|
-
export declare function toNullableIfDefined<
|
|
28
|
+
export declare function omit<ObjectType extends Record<string, any>, KeyType extends keyof ObjectType>(obj: ObjectType, keysToOmit: KeyType[]): Omit<ObjectType, KeyType>;
|
|
29
|
+
export declare function filterUndefined<ObjectType extends Record<string, unknown>>(data: ObjectType): Partial<ObjectType>;
|
|
30
|
+
export declare function toNullableIfDefined<ValueType>(value: ValueType | undefined): ValueType | null | undefined;
|
|
31
31
|
export {};
|
|
@@ -4,7 +4,7 @@ import type { z } from "zod";
|
|
|
4
4
|
* environmental variables that need to be access via the full object path, like
|
|
5
5
|
* `process.env.COMMIT`.
|
|
6
6
|
*/
|
|
7
|
-
export declare function parseOrDefault<
|
|
7
|
+
export declare function parseOrDefault<SchemaType extends z.ZodType<any, any>>(value: string | undefined, schema: SchemaType, defaultValue: z.infer<SchemaType>): z.infer<SchemaType>;
|
|
8
8
|
/**
|
|
9
9
|
* Parse an arbitrary value using the zod schema, returning `null` on
|
|
10
10
|
* failure. Use this for the common pattern of validating untrusted
|
|
@@ -326,6 +326,21 @@ export declare const globalsCssSnapshotSchema: z.ZodObject<{
|
|
|
326
326
|
}, z.core.$strip>>;
|
|
327
327
|
}, z.core.$strip>>;
|
|
328
328
|
}, z.core.$strip>;
|
|
329
|
+
export declare const siteFontRoleSchema: z.ZodObject<{
|
|
330
|
+
role: z.ZodString;
|
|
331
|
+
family: z.ZodNullable<z.ZodString>;
|
|
332
|
+
cssVar: z.ZodNullable<z.ZodString>;
|
|
333
|
+
rawValue: z.ZodString;
|
|
334
|
+
}, z.core.$strip>;
|
|
335
|
+
export declare const siteFontsSnapshotSchema: z.ZodObject<{
|
|
336
|
+
roles: z.ZodArray<z.ZodObject<{
|
|
337
|
+
role: z.ZodString;
|
|
338
|
+
family: z.ZodNullable<z.ZodString>;
|
|
339
|
+
cssVar: z.ZodNullable<z.ZodString>;
|
|
340
|
+
rawValue: z.ZodString;
|
|
341
|
+
}, z.core.$strip>>;
|
|
342
|
+
defaultRole: z.ZodNullable<z.ZodString>;
|
|
343
|
+
}, z.core.$strip>;
|
|
329
344
|
export declare const DESIGN_LIBRARY_PREVIEW_MESSAGE_TYPE = "replo:design-library:applyOverrides";
|
|
330
345
|
export declare const designLibraryPreviewFontSchema: z.ZodObject<{
|
|
331
346
|
family: z.ZodString;
|
|
@@ -99,6 +99,16 @@ var globalsCssScopeSchema = z.object({
|
|
|
99
99
|
var globalsCssSnapshotSchema = z.object({
|
|
100
100
|
scopes: z.array(globalsCssScopeSchema)
|
|
101
101
|
}).describe("GlobalsCssSnapshot");
|
|
102
|
+
var siteFontRoleSchema = z.object({
|
|
103
|
+
role: z.string(),
|
|
104
|
+
family: z.string().nullable(),
|
|
105
|
+
cssVar: z.string().nullable(),
|
|
106
|
+
rawValue: z.string()
|
|
107
|
+
}).describe("SiteFontRole");
|
|
108
|
+
var siteFontsSnapshotSchema = z.object({
|
|
109
|
+
roles: z.array(siteFontRoleSchema),
|
|
110
|
+
defaultRole: z.string().nullable()
|
|
111
|
+
}).describe("SiteFontsSnapshot");
|
|
102
112
|
var DESIGN_LIBRARY_PREVIEW_MESSAGE_TYPE = "replo:design-library:applyOverrides";
|
|
103
113
|
var designLibraryPreviewFontSchema = z.object({
|
|
104
114
|
family: z.string(),
|
|
@@ -113,4 +123,4 @@ var designLibraryPreviewMessageSchema = z.object({
|
|
|
113
123
|
defaultFontCssVar: z.string().nullable()
|
|
114
124
|
}).describe("DesignLibraryPreviewMessage");
|
|
115
125
|
|
|
116
|
-
export { DESIGN_LIBRARY_PREVIEW_MESSAGE_TYPE, designLibraryPreviewFontSchema, designLibraryPreviewMessageSchema, designLibrarySavedStyleMetadataSchema, designLibrarySavedStylesSchema, designLibrarySchema, globalsCssScopeSchema, globalsCssSnapshotSchema, globalsCssTokenSchema, savedColorStyleSchema, savedTextStyleSchema };
|
|
126
|
+
export { DESIGN_LIBRARY_PREVIEW_MESSAGE_TYPE, designLibraryPreviewFontSchema, designLibraryPreviewMessageSchema, designLibrarySavedStyleMetadataSchema, designLibrarySavedStylesSchema, designLibrarySchema, globalsCssScopeSchema, globalsCssSnapshotSchema, globalsCssTokenSchema, savedColorStyleSchema, savedTextStyleSchema, siteFontRoleSchema, siteFontsSnapshotSchema };
|
|
@@ -3,5 +3,5 @@ type MethodQueueOptions = {
|
|
|
3
3
|
queueName?: string;
|
|
4
4
|
onTimeout?: () => void;
|
|
5
5
|
};
|
|
6
|
-
export declare function createMethodQueue<
|
|
6
|
+
export declare function createMethodQueue<InstanceType extends Record<string, (...args: any[]) => any>>(checkInstanceReady: () => InstanceType | null, options?: MethodQueueOptions): (method: keyof InstanceType, ...args: any[]) => void;
|
|
7
7
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../analytics/utils/analytics-utils.ts"],
|
|
4
|
-
"sourcesContent": ["// oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\ntype QueuedEvent = { event: string; params: Record<string, any> };\n\nexport function createEventQueue(\n checkPixelReady: () => boolean,\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n sendEvent: (event: string, params: Record<string, any>) => void,\n pixelName: string,\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n): (event: string, params?: Record<string, any>) => void {\n const queue: QueuedEvent[] = [];\n let flushTimer: number | null = null;\n let timeoutTimer: number | null = null;\n let permanentlyDisabled = false;\n\n const cleanup = () => {\n if (flushTimer !== null) {\n window.clearInterval(flushTimer);\n flushTimer = null;\n }\n if (timeoutTimer !== null) {\n window.clearTimeout(timeoutTimer);\n timeoutTimer = null;\n }\n };\n\n const flush = () => {\n if (!checkPixelReady()) {\n return;\n }\n console.debug(\n `[analytics] flushing ${queue.length} queued events for ${pixelName}`,\n );\n try {\n queue.forEach(({ event, params }) => sendEvent(event, params));\n } finally {\n queue.length = 0;\n cleanup();\n }\n };\n\n const scheduleFlush = () => {\n if (typeof window === \"undefined\" || flushTimer !== null) {\n return;\n }\n\n flushTimer = window.setInterval(flush, 500);\n timeoutTimer = window.setTimeout(() => {\n queue.length = 0;\n permanentlyDisabled = true;\n console.debug(\n `Analytics queue timed out after 30 seconds for ${pixelName}`,\n );\n cleanup();\n }, 30_000);\n };\n\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n return (event: string, params: Record<string, any> = {}) => {\n if (permanentlyDisabled) {\n console.debug(\n `[analytics] ${pixelName} queue is disabled, dropping event`,\n event,\n );\n return;\n }\n\n if (checkPixelReady()) {\n sendEvent(event, params);\n } else {\n queue.push({ event, params });\n scheduleFlush();\n }\n };\n}\n\ntype MethodQueueOptions = {\n queueName?: string;\n onTimeout?: () => void;\n};\n\nexport function createMethodQueue<\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n
|
|
5
|
-
"mappings": "AAGO,SAAS,iBACd,iBAEA,WACA,WAEuD;AACvD,QAAM,QAAuB,CAAC;AAC9B,MAAI,aAA4B;AAChC,MAAI,eAA8B;AAClC,MAAI,sBAAsB;AAE1B,QAAM,UAAU,MAAM;AACpB,QAAI,eAAe,MAAM;AACvB,aAAO,cAAc,UAAU;AAC/B,mBAAa;AAAA,IACf;AACA,QAAI,iBAAiB,MAAM;AACzB,aAAO,aAAa,YAAY;AAChC,qBAAe;AAAA,IACjB;AAAA,EACF;AAEA,QAAM,QAAQ,MAAM;AAClB,QAAI,CAAC,gBAAgB,GAAG;AACtB;AAAA,IACF;AACA,YAAQ;AAAA,MACN,wBAAwB,MAAM,MAAM,sBAAsB,SAAS;AAAA,IACrE;AACA,QAAI;AACF,YAAM,QAAQ,CAAC,EAAE,OAAO,OAAO,MAAM,UAAU,OAAO,MAAM,CAAC;AAAA,IAC/D,UAAE;AACA,YAAM,SAAS;AACf,cAAQ;AAAA,IACV;AAAA,EACF;AAEA,QAAM,gBAAgB,MAAM;AAC1B,QAAI,OAAO,WAAW,eAAe,eAAe,MAAM;AACxD;AAAA,IACF;AAEA,iBAAa,OAAO,YAAY,OAAO,GAAG;AAC1C,mBAAe,OAAO,WAAW,MAAM;AACrC,YAAM,SAAS;AACf,4BAAsB;AACtB,cAAQ;AAAA,QACN,kDAAkD,SAAS;AAAA,MAC7D;AACA,cAAQ;AAAA,IACV,GAAG,GAAM;AAAA,EACX;AAGA,SAAO,CAAC,OAAe,SAA8B,CAAC,MAAM;AAC1D,QAAI,qBAAqB;AACvB,cAAQ;AAAA,QACN,eAAe,SAAS;AAAA,QACxB;AAAA,MACF;AACA;AAAA,IACF;AAEA,QAAI,gBAAgB,GAAG;AACrB,gBAAU,OAAO,MAAM;AAAA,IACzB,OAAO;AACL,YAAM,KAAK,EAAE,OAAO,OAAO,CAAC;AAC5B,oBAAc;AAAA,IAChB;AAAA,EACF;AACF;AAOO,SAAS,kBAId,oBACA,
|
|
4
|
+
"sourcesContent": ["// oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\ntype QueuedEvent = { event: string; params: Record<string, any> };\n\nexport function createEventQueue(\n checkPixelReady: () => boolean,\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n sendEvent: (event: string, params: Record<string, any>) => void,\n pixelName: string,\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n): (event: string, params?: Record<string, any>) => void {\n const queue: QueuedEvent[] = [];\n let flushTimer: number | null = null;\n let timeoutTimer: number | null = null;\n let permanentlyDisabled = false;\n\n const cleanup = () => {\n if (flushTimer !== null) {\n window.clearInterval(flushTimer);\n flushTimer = null;\n }\n if (timeoutTimer !== null) {\n window.clearTimeout(timeoutTimer);\n timeoutTimer = null;\n }\n };\n\n const flush = () => {\n if (!checkPixelReady()) {\n return;\n }\n console.debug(\n `[analytics] flushing ${queue.length} queued events for ${pixelName}`,\n );\n try {\n queue.forEach(({ event, params }) => sendEvent(event, params));\n } finally {\n queue.length = 0;\n cleanup();\n }\n };\n\n const scheduleFlush = () => {\n if (typeof window === \"undefined\" || flushTimer !== null) {\n return;\n }\n\n flushTimer = window.setInterval(flush, 500);\n timeoutTimer = window.setTimeout(() => {\n queue.length = 0;\n permanentlyDisabled = true;\n console.debug(\n `Analytics queue timed out after 30 seconds for ${pixelName}`,\n );\n cleanup();\n }, 30_000);\n };\n\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n return (event: string, params: Record<string, any> = {}) => {\n if (permanentlyDisabled) {\n console.debug(\n `[analytics] ${pixelName} queue is disabled, dropping event`,\n event,\n );\n return;\n }\n\n if (checkPixelReady()) {\n sendEvent(event, params);\n } else {\n queue.push({ event, params });\n scheduleFlush();\n }\n };\n}\n\ntype MethodQueueOptions = {\n queueName?: string;\n onTimeout?: () => void;\n};\n\nexport function createMethodQueue<\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n InstanceType extends Record<string, (...args: any[]) => any>,\n>(\n checkInstanceReady: () => InstanceType | null,\n options?: MethodQueueOptions,\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n): (method: keyof InstanceType, ...args: any[]) => void {\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n const queue: { method: keyof InstanceType; args: any[] }[] = [];\n let flushTimer: number | null = null;\n let timeoutTimer: number | null = null;\n let permanentlyDisabled = false;\n const queueName = options?.queueName ?? \"method queue\";\n\n const cleanup = () => {\n if (flushTimer !== null) {\n window.clearInterval(flushTimer);\n flushTimer = null;\n }\n if (timeoutTimer !== null) {\n window.clearTimeout(timeoutTimer);\n timeoutTimer = null;\n }\n };\n\n const flush = () => {\n const instance = checkInstanceReady();\n if (!instance) {\n return;\n }\n try {\n queue.forEach(({ method, args }) => {\n const methodFunction = instance[method];\n if (typeof methodFunction === \"function\") {\n void methodFunction.apply(instance, args);\n }\n });\n } finally {\n queue.length = 0;\n cleanup();\n }\n };\n\n const scheduleFlush = () => {\n if (typeof window === \"undefined\" || flushTimer !== null) {\n return;\n }\n\n flushTimer = window.setInterval(flush, 500);\n timeoutTimer = window.setTimeout(() => {\n queue.length = 0;\n permanentlyDisabled = true;\n if (typeof window !== \"undefined\") {\n console.debug(\n `[analytics] ${queueName} timed out after 30 seconds and has been disabled`,\n );\n }\n options?.onTimeout?.();\n cleanup();\n }, 30_000);\n };\n\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n return (method: keyof InstanceType, ...args: any[]) => {\n if (permanentlyDisabled) {\n return;\n }\n\n const instance = checkInstanceReady();\n if (instance) {\n const methodFunction = instance[method];\n if (typeof methodFunction === \"function\") {\n void methodFunction.apply(instance, args);\n }\n } else {\n queue.push({ method, args });\n scheduleFlush();\n }\n };\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useRef } from "react";
|
|
3
|
-
import { buildGoogleFontsCssUrl } from "../../_vendor/replo-utils/lib/
|
|
3
|
+
import { buildGoogleFontsCssUrl } from "../../_vendor/replo-utils/lib/fonts.mjs";
|
|
4
4
|
import { designLibraryPreviewMessageSchema } from "../../_vendor/schemas/designLibrary.mjs";
|
|
5
5
|
const FONT_LINK_DATA_KEY = "reploDesignLibraryFont";
|
|
6
6
|
function escapeCssString(value) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../editor/design-library-preview/DesignLibraryPreview.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nimport { buildGoogleFontsCssUrl } from \"replo-utils/lib/
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nimport { buildGoogleFontsCssUrl } from \"replo-utils/lib/fonts\";\nimport { designLibraryPreviewMessageSchema } from \"schemas/designLibrary\";\n\nconst FONT_LINK_DATA_KEY = \"reploDesignLibraryFont\";\n\nfunction escapeCssString(value: string): string {\n return value.replace(/\\\\/gu, \"\\\\\\\\\").replace(/'/gu, \"\\\\'\");\n}\n\nexport function DesignLibraryPreview() {\n // NOTE (Ben, 2026-06-03): The custom-property keys we set last time, so on the\n // next message we remove only the ones we own that the new override set drops.\n const ownedKeys = useRef<Set<string> | null>(null);\n // NOTE (Ben, 2026-06-05): The Google Font <link> hrefs we injected, keyed by\n // href so we de-dupe and remove only our own when the override set changes.\n const ownedFontLinks = useRef<Map<string, HTMLLinkElement> | null>(null);\n // NOTE (Ben, 2026-06-05): The @font-face <style> nodes for uploaded custom\n // fonts, keyed by family with the URL we injected, so we de-dupe, re-inject\n // when a family's asset URL changes (re-upload), and remove only our own when\n // the override set changes.\n const ownedFontFaces = useRef<Map<\n string,\n { url: string; style: HTMLStyleElement }\n > | null>(null);\n // NOTE (Ben, 2026-06-05): Whether we set the document default font-family, so\n // we can clear just that.\n const ownsDefaultFont = useRef(false);\n\n // eslint-disable-next-line replo/no-use-effect -- Subscribes to window message events from the parent editor.\n useEffect(() => {\n const handleMessage = (event: MessageEvent) => {\n const parsed = designLibraryPreviewMessageSchema.safeParse(event.data);\n if (!parsed.success) return;\n const { cssVars, fonts, defaultFontCssVar } = parsed.data;\n const root = document.documentElement;\n\n // --- CSS variable overrides (colors + font role vars) ---\n const nextVars: Record<string, string> = { ...cssVars };\n for (const font of fonts) {\n nextVars[font.cssVar] = `'${escapeCssString(font.family)}'`;\n }\n const owned = ownedKeys.current ?? new Set();\n for (const key of owned) {\n if (!(key in nextVars)) root.style.removeProperty(key);\n }\n ownedKeys.current = new Set(Object.keys(nextVars));\n for (const [key, value] of Object.entries(nextVars)) {\n root.style.setProperty(key, value);\n }\n\n // Custom uploaded fonts carry a faceUrl; Google fonts don't.\n const customFonts = fonts.filter((font) => Boolean(font.faceUrl));\n const googleFonts = fonts.filter((font) => !font.faceUrl);\n\n // --- Google Font stylesheets (<link> to the CDN) ---\n const links = ownedFontLinks.current ?? new Map();\n const nextHrefs = new Set(\n googleFonts.map((font) => buildGoogleFontsCssUrl(font.family)),\n );\n for (const [href, link] of links) {\n if (!nextHrefs.has(href)) {\n link.remove();\n links.delete(href);\n }\n }\n for (const href of nextHrefs) {\n if (links.has(href)) continue;\n const link = document.createElement(\"link\");\n link.rel = \"stylesheet\";\n link.href = href;\n link.dataset[FONT_LINK_DATA_KEY] = \"\";\n document.head.append(link);\n links.set(href, link);\n }\n ownedFontLinks.current = links;\n\n // --- Custom uploaded fonts (@font-face from the asset URL) ---\n const faces = ownedFontFaces.current ?? new Map();\n const nextFamilies = new Set(customFonts.map((font) => font.family));\n for (const [family, entry] of faces) {\n if (!nextFamilies.has(family)) {\n entry.style.remove();\n faces.delete(family);\n }\n }\n for (const font of customFonts) {\n if (!font.faceUrl) continue;\n const existing = faces.get(font.family);\n // Re-upload reuses the family but changes the asset URL; replace the\n // stale node rather than skipping it.\n if (existing?.url === font.faceUrl) continue;\n existing?.style.remove();\n const style = document.createElement(\"style\");\n style.dataset[FONT_LINK_DATA_KEY] = \"\";\n const format = font.format\n ? ` format('${escapeCssString(font.format)}')`\n : \"\";\n style.textContent = `@font-face{font-family:'${escapeCssString(font.family)}';font-weight:400;font-style:normal;src:url('${escapeCssString(font.faceUrl)}')${format};font-display:swap;}`;\n document.head.append(style);\n faces.set(font.family, { url: font.faceUrl, style });\n }\n ownedFontFaces.current = faces;\n\n // --- Document default font ---\n if (defaultFontCssVar) {\n root.style.setProperty(\"font-family\", `var(${defaultFontCssVar})`);\n ownsDefaultFont.current = true;\n } else if (ownsDefaultFont.current) {\n root.style.removeProperty(\"font-family\");\n ownsDefaultFont.current = false;\n }\n };\n window.addEventListener(\"message\", handleMessage);\n return () => {\n window.removeEventListener(\"message\", handleMessage);\n };\n }, []);\n\n return null;\n}\n"],
|
|
5
5
|
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* The useEffect doesn't have any dependencies - it's designed to only run once. So if you expect your read() function to return
|
|
8
8
|
* different values through the lifecycle of the component, you should not use this hook.
|
|
9
9
|
*/
|
|
10
|
-
export declare function useClientValue<
|
|
10
|
+
export declare function useClientValue<ValueType>(readValue: () => ValueType, initialValue: ValueType): ValueType;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../hooks/use-client-value.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from \"react\";\n\n/**\n * NOTE (Max, 2025-09-15): This hook is to be used for values that aren't available on the server (such as window.location).\n *\n * This hook will use a dummy value both on the server & on hydration. Then,\n * after hydration, this useEffect will update the value to the actual value.\n *\n * The useEffect doesn't have any dependencies - it's designed to only run once. So if you expect your read() function to return\n * different values through the lifecycle of the component, you should not use this hook.\n */\n\nexport function useClientValue<
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;AAYhB,SAAS,
|
|
4
|
+
"sourcesContent": ["import * as React from \"react\";\n\n/**\n * NOTE (Max, 2025-09-15): This hook is to be used for values that aren't available on the server (such as window.location).\n *\n * This hook will use a dummy value both on the server & on hydration. Then,\n * after hydration, this useEffect will update the value to the actual value.\n *\n * The useEffect doesn't have any dependencies - it's designed to only run once. So if you expect your read() function to return\n * different values through the lifecycle of the component, you should not use this hook.\n */\n\nexport function useClientValue<ValueType>(\n readValue: () => ValueType,\n initialValue: ValueType,\n) {\n const [value, setValue] = React.useState<ValueType>(initialValue);\n\n /* eslint-disable replo/no-use-effect -- Legacy effect - may or may not be necessary */\n React.useEffect(() => {\n setValue(readValue());\n }, []);\n /* eslint-enable replo/no-use-effect */\n return value;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;AAYhB,SAAS,eACd,WACA,cACA;AACA,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAoB,YAAY;AAGhE,QAAM,UAAU,MAAM;AACpB,aAAS,UAAU,CAAC;AAAA,EACtB,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// ../replo-utils/lib/google-fonts.ts
|
|
2
|
-
function slugifyFontFamily(family) {
|
|
3
|
-
return family.replace(/([a-z])([A-Z])/g, "$1-$2").split(/[\s_-]+/u).map((word) => word.toLowerCase()).join("-");
|
|
4
|
-
}
|
|
5
|
-
function fontNameToCssVariable(fontName) {
|
|
6
|
-
return `--font-${slugifyFontFamily(fontName)}`;
|
|
7
|
-
}
|
|
8
|
-
function quoteFontFamily(family) {
|
|
9
|
-
return /\s/u.test(family) ? `'${family}'` : family;
|
|
10
|
-
}
|
|
11
|
-
function fontNameToVariableName(fontName) {
|
|
12
|
-
const words = fontName.replace(/([a-z])([A-Z])/g, "$1 $2").split(/[\s_-]+/u);
|
|
13
|
-
return words.map((word, index) => {
|
|
14
|
-
return index === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
15
|
-
}).join("");
|
|
16
|
-
}
|
|
17
|
-
function buildGoogleFontsCssUrl(family, weights) {
|
|
18
|
-
const requested = weights && weights.length > 0 ? Array.from(new Set(weights)) : [400];
|
|
19
|
-
const sortedWeights = requested.sort(
|
|
20
|
-
(leftWeight, rightWeight) => leftWeight - rightWeight
|
|
21
|
-
);
|
|
22
|
-
const familyParam = family.trim().replace(/\s+/gu, "+");
|
|
23
|
-
return `https://fonts.googleapis.com/css2?family=${familyParam}:wght@${sortedWeights.join(
|
|
24
|
-
";"
|
|
25
|
-
)}&display=swap`;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { buildGoogleFontsCssUrl, fontNameToCssVariable, fontNameToVariableName, quoteFontFamily, slugifyFontFamily };
|