@snowcone-app/ui 0.12.1 → 0.13.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.
- package/CHANGELOG.md +17 -0
- package/dist/chunk-GY6TC6M6.js +86 -0
- package/dist/chunk-GY6TC6M6.js.map +1 -0
- package/dist/index.cjs +90 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -3
- package/dist/index.d.ts +32 -3
- package/dist/index.js +61 -13
- package/dist/index.js.map +1 -1
- package/dist/personalization/bridge.cjs.map +1 -1
- package/dist/personalization/bridge.d.cts +1 -1
- package/dist/personalization/bridge.d.ts +1 -1
- package/dist/personalization/bridge.js +1 -1
- package/dist/{types-CNJT8FUd.d.cts → types-BObPMwP5.d.cts} +17 -1
- package/dist/{types-CNJT8FUd.d.ts → types-BObPMwP5.d.ts} +17 -1
- package/package.json +2 -2
- package/src/personalization/PersonalizationInputs.tsx +2 -0
- package/src/personalization/PersonalizationProvider.tsx +52 -13
- package/src/personalization/__tests__/fit.test.ts +75 -0
- package/src/personalization/index.ts +2 -1
- package/src/personalization/types.ts +16 -0
- package/src/personalization/utils.ts +68 -0
- package/dist/chunk-WDOT4BST.js +0 -50
- package/dist/chunk-WDOT4BST.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/personalization/PersonalizationBridge.tsx","../../src/personalization/utils.ts"],"sourcesContent":["\"use client\";\n\n/**\n * PersonalizationBridge — rendered inside SnowconeCanvas overlay (EditorProvider context).\n * Syncs external personalization values into canvas elements.\n *\n * INTERNAL: Not exported from the package. Used by PersonalizationProvider only.\n *\n * Text fields: finds elements by name, calls setText().\n * Color fields: finds all elements matching the original color, updates them.\n * Image fields: uses useImageBinding to update image by name.\n *\n * Key design: effects depend ONLY on the input value (text string / hex color).\n * Callbacks and element arrays are accessed via refs to avoid effect churn from\n * the canvas re-rendering after each update.\n */\n\nimport { useRef, useEffect } from \"react\";\nimport { useEditor, useCommands, useImageBinding } from \"@snowcone-app/canvas\";\nimport type { ImageFitMode } from \"@snowcone-app/canvas\";\nimport type {\n PersonalizationField,\n PersonalizationValues,\n} from \"./types\";\nimport { normalizeHex, isValidImageUrl, useDebouncedValue } from \"./utils\";\n\n// ---------------------------------------------------------------------------\n// TextBinder — syncs a single text personalization value into canvas\n// ---------------------------------------------------------------------------\n\nfunction TextBinder({ name, value }: { name: string; value: string }) {\n const { elements } = useEditor();\n const { executeElementUpdate } = useCommands();\n\n const elementsRef = useRef(elements);\n elementsRef.current = elements;\n const executeRef = useRef(executeElementUpdate);\n executeRef.current = executeElementUpdate;\n\n const hasUserInput = useRef(false);\n\n useEffect(() => {\n if (value == null) return;\n // Skip initial empty value to preserve the designer's original text\n if (value === \"\" && !hasUserInput.current) return;\n hasUserInput.current = true;\n\n const currentElements = elementsRef.current;\n const exec = executeRef.current;\n\n for (const el of currentElements) {\n if (el.name !== name) continue;\n if (!(\"setText\" in el) || typeof (el as any).setText !== \"function\")\n continue;\n const cloned = el.clone();\n (cloned as any).setText(value);\n exec(el, cloned);\n }\n }, [value, name, elements.length]); // Re-run when elements become available\n\n return null;\n}\n\n// ---------------------------------------------------------------------------\n// ColorBinder — updates all elements matching originalColor to newColor\n// ---------------------------------------------------------------------------\n\nfunction ColorBinder({\n originalColor,\n newColor,\n}: {\n originalColor: string;\n newColor: string;\n}) {\n const { elements } = useEditor();\n const { executeElementUpdate } = useCommands();\n\n const elementsRef = useRef(elements);\n elementsRef.current = elements;\n const executeRef = useRef(executeElementUpdate);\n executeRef.current = executeElementUpdate;\n\n const appliedColorRef = useRef(normalizeHex(originalColor));\n\n useEffect(() => {\n const normalizedNew = normalizeHex(newColor);\n if (normalizedNew === appliedColorRef.current) return;\n\n const matchColor = appliedColorRef.current;\n const currentElements = elementsRef.current;\n const exec = executeRef.current;\n\n for (const el of currentElements) {\n let needsUpdate = false;\n const cloned = el.clone();\n\n // Text elements: check .color\n if (\"color\" in el && typeof (el as any).color === \"string\") {\n if (normalizeHex((el as any).color) === matchColor) {\n if (typeof (cloned as any).setColor === \"function\") {\n (cloned as any).setColor(newColor);\n } else {\n (cloned as any).color = newColor;\n }\n needsUpdate = true;\n }\n }\n\n // Shape/Path elements: check transformData.fillColor\n if (\n normalizeHex((el as any).transformData?.fillColor ?? \"\") === matchColor\n ) {\n (cloned as any).transformData = {\n ...(cloned as any).transformData,\n fillColor: newColor,\n };\n needsUpdate = true;\n }\n\n // Path elements: check transformData.strokeColor\n if (\n normalizeHex((el as any).transformData?.strokeColor ?? \"\") ===\n matchColor\n ) {\n (cloned as any).transformData = {\n ...(cloned as any).transformData,\n strokeColor: newColor,\n };\n needsUpdate = true;\n }\n\n // Stroke color\n if (\n (el as any).stroke?.enabled &&\n normalizeHex((el as any).stroke?.color ?? \"\") === matchColor\n ) {\n (cloned as any).stroke = {\n ...(cloned as any).stroke,\n color: newColor,\n };\n needsUpdate = true;\n }\n\n if (needsUpdate) {\n exec(el, cloned);\n }\n }\n\n appliedColorRef.current = normalizedNew;\n }, [newColor, elements.length]); // Re-run when elements become available\n\n return null;\n}\n\n// ---------------------------------------------------------------------------\n// ImageBinder — uses useImageBinding hook from @snowcone-app/canvas\n// ---------------------------------------------------------------------------\n\nfunction ImageBinder({\n name,\n value,\n fit = \"cover\",\n}: {\n name: string;\n value: string;\n fit?: \"cover\" | \"contain\";\n}) {\n const { setImageUrl } = useImageBinding(name, {\n fit: fit as ImageFitMode,\n });\n const hasUserInput = useRef(false);\n const debouncedValue = useDebouncedValue(value, 500);\n\n const setImageUrlRef = useRef(setImageUrl);\n setImageUrlRef.current = setImageUrl;\n\n useEffect(() => {\n if (debouncedValue == null) return;\n if (debouncedValue === \"\" && !hasUserInput.current) return;\n hasUserInput.current = true;\n if (debouncedValue !== \"\" && !isValidImageUrl(debouncedValue)) return;\n\n setImageUrlRef.current(debouncedValue);\n }, [debouncedValue]);\n\n return null;\n}\n\n// ---------------------------------------------------------------------------\n// PersonalizationBridge — maps personalization fields to binder components\n// ---------------------------------------------------------------------------\n\nexport function PersonalizationBridge({\n fields,\n values,\n}: {\n fields: PersonalizationField[];\n values: PersonalizationValues;\n}) {\n return (\n <>\n {fields.map((field) => {\n if (field.type === \"text\") {\n return (\n <TextBinder\n key={`text-${field.name}`}\n name={field.name}\n value={values[field.name] ?? \"\"}\n />\n );\n }\n if (field.type === \"color\") {\n return (\n <ColorBinder\n key={`color-${field.color}`}\n originalColor={field.color}\n newColor={values[field.color] ?? field.color}\n />\n );\n }\n if (field.type === \"image\") {\n return (\n <ImageBinder\n key={`image-${field.name}`}\n name={field.name}\n value={values[field.name] ?? \"\"}\n fit={field.fit ?? \"cover\"}\n />\n );\n }\n return null;\n })}\n </>\n );\n}\n","\"use client\";\n\n/**\n * Personalization Utilities\n */\n\nimport { useEffect, useState } from \"react\";\n\n/** Normalize any hex color to uppercase 6-digit form (#RGB → #RRGGBB) */\nexport function normalizeHex(color: string): string {\n let hex = color.trim().toUpperCase();\n if (hex.length === 4 && hex.startsWith(\"#\")) {\n hex = \"#\" + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3];\n }\n return hex;\n}\n\n/** Check if a string looks like a complete, loadable URL */\nexport function isValidImageUrl(url: string): boolean {\n if (!url || url.length < 10) return false;\n try {\n const parsed = new URL(url);\n if (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") return false;\n if (!parsed.hostname.includes(\".\")) return false;\n if (parsed.pathname.length <= 1) return false;\n return true;\n } catch {\n return false;\n }\n}\n\n/** Debounce a string value — only emits after `delay` ms of inactivity */\nexport function useDebouncedValue(value: string, delay: number): string {\n const [debounced, setDebounced] = useState(value);\n useEffect(() => {\n const timer = setTimeout(() => setDebounced(value), delay);\n return () => clearTimeout(timer);\n }, [value, delay]);\n return debounced;\n}\n\n/**\n * Scroll an input to sit just above the iOS keyboard after it appears.\n * Uses visualViewport.height to determine the visible area above the keyboard.\n */\nexport function scrollInputAboveKeyboard(input: HTMLElement) {\n const position = () => {\n const rect = input.getBoundingClientRect();\n const visibleBottom =\n window.visualViewport?.height || window.innerHeight * 0.5;\n const target = visibleBottom - rect.height - 20;\n const delta = rect.top - target;\n if (Math.abs(delta) > 10) {\n window.scrollBy({ top: delta, behavior: \"smooth\" });\n }\n };\n setTimeout(position, 400);\n window.visualViewport?.addEventListener(\"resize\", position, { once: true });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,IAAAA,gBAAkC;AAClC,oBAAwD;;;ACZxD,mBAAoC;AAG7B,SAAS,aAAa,OAAuB;AAClD,MAAI,MAAM,MAAM,KAAK,EAAE,YAAY;AACnC,MAAI,IAAI,WAAW,KAAK,IAAI,WAAW,GAAG,GAAG;AAC3C,UAAM,MAAM,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC;AAAA,EAChE;AACA,SAAO;AACT;AAGO,SAAS,gBAAgB,KAAsB;AACpD,MAAI,CAAC,OAAO,IAAI,SAAS,GAAI,QAAO;AACpC,MAAI;AACF,UAAM,SAAS,IAAI,IAAI,GAAG;AAC1B,QAAI,OAAO,aAAa,WAAW,OAAO,aAAa,SAAU,QAAO;AACxE,QAAI,CAAC,OAAO,SAAS,SAAS,GAAG,EAAG,QAAO;AAC3C,QAAI,OAAO,SAAS,UAAU,EAAG,QAAO;AACxC,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGO,SAAS,kBAAkB,OAAe,OAAuB;AACtE,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,KAAK;AAChD,8BAAU,MAAM;AACd,UAAM,QAAQ,WAAW,MAAM,aAAa,KAAK,GAAG,KAAK;AACzD,WAAO,MAAM,aAAa,KAAK;AAAA,EACjC,GAAG,CAAC,OAAO,KAAK,CAAC;AACjB,SAAO;AACT;;;ADiKI;AA1KJ,SAAS,WAAW,EAAE,MAAM,MAAM,GAAoC;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AAmB,MAAM,CAAC,gBAAgB,cAAc,EAAG;AAE/D,mBAAe,QAAQ,cAAc;AAAA,EACvC,GAAG,CAAC,cAAc,CAAC;AAEnB,SAAO;AACT;AAMO,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AACF,GAGG;AACD,SACE,2EACG,iBAAO,IAAI,CAAC,UAAU;AACrB,QAAI,MAAM,SAAS,QAAQ;AACzB,aACE;AAAA,QAAC;AAAA;AAAA,UAEC,MAAM,MAAM;AAAA,UACZ,OAAO,OAAO,MAAM,IAAI,KAAK;AAAA;AAAA,QAFxB,QAAQ,MAAM,IAAI;AAAA,MAGzB;AAAA,IAEJ;AACA,QAAI,MAAM,SAAS,SAAS;AAC1B,aACE;AAAA,QAAC;AAAA;AAAA,UAEC,eAAe,MAAM;AAAA,UACrB,UAAU,OAAO,MAAM,KAAK,KAAK,MAAM;AAAA;AAAA,QAFlC,SAAS,MAAM,KAAK;AAAA,MAG3B;AAAA,IAEJ;AACA,QAAI,MAAM,SAAS,SAAS;AAC1B,aACE;AAAA,QAAC;AAAA;AAAA,UAEC,MAAM,MAAM;AAAA,UACZ,OAAO,OAAO,MAAM,IAAI,KAAK;AAAA,UAC7B,KAAK,MAAM,OAAO;AAAA;AAAA,QAHb,SAAS,MAAM,IAAI;AAAA,MAI1B;AAAA,IAEJ;AACA,WAAO;AAAA,EACT,CAAC,GACH;AAEJ;","names":["import_react"]}
|
|
1
|
+
{"version":3,"sources":["../../src/personalization/PersonalizationBridge.tsx","../../src/personalization/utils.ts"],"sourcesContent":["\"use client\";\n\n/**\n * PersonalizationBridge — rendered inside SnowconeCanvas overlay (EditorProvider context).\n * Syncs external personalization values into canvas elements.\n *\n * INTERNAL: Not exported from the package. Used by PersonalizationProvider only.\n *\n * Text fields: finds elements by name, calls setText().\n * Color fields: finds all elements matching the original color, updates them.\n * Image fields: uses useImageBinding to update image by name.\n *\n * Key design: effects depend ONLY on the input value (text string / hex color).\n * Callbacks and element arrays are accessed via refs to avoid effect churn from\n * the canvas re-rendering after each update.\n */\n\nimport { useRef, useEffect } from \"react\";\nimport { useEditor, useCommands, useImageBinding } from \"@snowcone-app/canvas\";\nimport type { ImageFitMode } from \"@snowcone-app/canvas\";\nimport type {\n PersonalizationField,\n PersonalizationValues,\n} from \"./types\";\nimport { normalizeHex, isValidImageUrl, useDebouncedValue } from \"./utils\";\n\n// ---------------------------------------------------------------------------\n// TextBinder — syncs a single text personalization value into canvas\n// ---------------------------------------------------------------------------\n\nfunction TextBinder({ name, value }: { name: string; value: string }) {\n const { elements } = useEditor();\n const { executeElementUpdate } = useCommands();\n\n const elementsRef = useRef(elements);\n elementsRef.current = elements;\n const executeRef = useRef(executeElementUpdate);\n executeRef.current = executeElementUpdate;\n\n const hasUserInput = useRef(false);\n\n useEffect(() => {\n if (value == null) return;\n // Skip initial empty value to preserve the designer's original text\n if (value === \"\" && !hasUserInput.current) return;\n hasUserInput.current = true;\n\n const currentElements = elementsRef.current;\n const exec = executeRef.current;\n\n for (const el of currentElements) {\n if (el.name !== name) continue;\n if (!(\"setText\" in el) || typeof (el as any).setText !== \"function\")\n continue;\n const cloned = el.clone();\n (cloned as any).setText(value);\n exec(el, cloned);\n }\n }, [value, name, elements.length]); // Re-run when elements become available\n\n return null;\n}\n\n// ---------------------------------------------------------------------------\n// ColorBinder — updates all elements matching originalColor to newColor\n// ---------------------------------------------------------------------------\n\nfunction ColorBinder({\n originalColor,\n newColor,\n}: {\n originalColor: string;\n newColor: string;\n}) {\n const { elements } = useEditor();\n const { executeElementUpdate } = useCommands();\n\n const elementsRef = useRef(elements);\n elementsRef.current = elements;\n const executeRef = useRef(executeElementUpdate);\n executeRef.current = executeElementUpdate;\n\n const appliedColorRef = useRef(normalizeHex(originalColor));\n\n useEffect(() => {\n const normalizedNew = normalizeHex(newColor);\n if (normalizedNew === appliedColorRef.current) return;\n\n const matchColor = appliedColorRef.current;\n const currentElements = elementsRef.current;\n const exec = executeRef.current;\n\n for (const el of currentElements) {\n let needsUpdate = false;\n const cloned = el.clone();\n\n // Text elements: check .color\n if (\"color\" in el && typeof (el as any).color === \"string\") {\n if (normalizeHex((el as any).color) === matchColor) {\n if (typeof (cloned as any).setColor === \"function\") {\n (cloned as any).setColor(newColor);\n } else {\n (cloned as any).color = newColor;\n }\n needsUpdate = true;\n }\n }\n\n // Shape/Path elements: check transformData.fillColor\n if (\n normalizeHex((el as any).transformData?.fillColor ?? \"\") === matchColor\n ) {\n (cloned as any).transformData = {\n ...(cloned as any).transformData,\n fillColor: newColor,\n };\n needsUpdate = true;\n }\n\n // Path elements: check transformData.strokeColor\n if (\n normalizeHex((el as any).transformData?.strokeColor ?? \"\") ===\n matchColor\n ) {\n (cloned as any).transformData = {\n ...(cloned as any).transformData,\n strokeColor: newColor,\n };\n needsUpdate = true;\n }\n\n // Stroke color\n if (\n (el as any).stroke?.enabled &&\n normalizeHex((el as any).stroke?.color ?? \"\") === matchColor\n ) {\n (cloned as any).stroke = {\n ...(cloned as any).stroke,\n color: newColor,\n };\n needsUpdate = true;\n }\n\n if (needsUpdate) {\n exec(el, cloned);\n }\n }\n\n appliedColorRef.current = normalizedNew;\n }, [newColor, elements.length]); // Re-run when elements become available\n\n return null;\n}\n\n// ---------------------------------------------------------------------------\n// ImageBinder — uses useImageBinding hook from @snowcone-app/canvas\n// ---------------------------------------------------------------------------\n\nfunction ImageBinder({\n name,\n value,\n fit = \"cover\",\n}: {\n name: string;\n value: string;\n fit?: \"cover\" | \"contain\";\n}) {\n const { setImageUrl } = useImageBinding(name, {\n fit: fit as ImageFitMode,\n });\n const hasUserInput = useRef(false);\n const debouncedValue = useDebouncedValue(value, 500);\n\n const setImageUrlRef = useRef(setImageUrl);\n setImageUrlRef.current = setImageUrl;\n\n useEffect(() => {\n if (debouncedValue == null) return;\n if (debouncedValue === \"\" && !hasUserInput.current) return;\n hasUserInput.current = true;\n if (debouncedValue !== \"\" && !isValidImageUrl(debouncedValue)) return;\n\n setImageUrlRef.current(debouncedValue);\n }, [debouncedValue]);\n\n return null;\n}\n\n// ---------------------------------------------------------------------------\n// PersonalizationBridge — maps personalization fields to binder components\n// ---------------------------------------------------------------------------\n\nexport function PersonalizationBridge({\n fields,\n values,\n}: {\n fields: PersonalizationField[];\n values: PersonalizationValues;\n}) {\n return (\n <>\n {fields.map((field) => {\n if (field.type === \"text\") {\n return (\n <TextBinder\n key={`text-${field.name}`}\n name={field.name}\n value={values[field.name] ?? \"\"}\n />\n );\n }\n if (field.type === \"color\") {\n return (\n <ColorBinder\n key={`color-${field.color}`}\n originalColor={field.color}\n newColor={values[field.color] ?? field.color}\n />\n );\n }\n if (field.type === \"image\") {\n return (\n <ImageBinder\n key={`image-${field.name}`}\n name={field.name}\n value={values[field.name] ?? \"\"}\n fit={field.fit ?? \"cover\"}\n />\n );\n }\n return null;\n })}\n </>\n );\n}\n","\"use client\";\n\n/**\n * Personalization Utilities\n */\n\nimport { useEffect, useState } from \"react\";\nimport type { PersonalizationField, PersonalizationTextField, PersonalizationValues } from \"./types\";\n\n/** Normalize any hex color to uppercase 6-digit form (#RGB → #RRGGBB) */\nexport function normalizeHex(color: string): string {\n let hex = color.trim().toUpperCase();\n if (hex.length === 4 && hex.startsWith(\"#\")) {\n hex = \"#\" + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3];\n }\n return hex;\n}\n\n/** Check if a string looks like a complete, loadable URL */\nexport function isValidImageUrl(url: string): boolean {\n if (!url || url.length < 10) return false;\n try {\n const parsed = new URL(url);\n if (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") return false;\n if (!parsed.hostname.includes(\".\")) return false;\n if (parsed.pathname.length <= 1) return false;\n return true;\n } catch {\n return false;\n }\n}\n\n/** Has the buyer typed into any TEXT field of the design (any non-blank text)? */\nexport function anyTyped(fields: readonly PersonalizationField[], values: PersonalizationValues): boolean {\n return fields.some((f) => f.type === \"text\" && typeof values[f.name] === \"string\" && values[f.name].trim().length > 0);\n}\n\n/**\n * What a text field's elements draw: its box's text, or null = the element's own (designed) text. A `sample` field draws\n * its sample until anything is typed in any field, then exactly its box (empty = nothing). Any other field draws its\n * box's text (\"\" until typed into, which the binder leaves alone).\n */\nexport function textValueFor(field: PersonalizationTextField, values: PersonalizationValues, typed = false): string | null {\n const v = values[field.name] ?? \"\";\n if (field.sample) return typed ? v : null;\n return v;\n}\n\n/** The font a text element draws with: the canvas's own CSS font shorthand (canvas TextMetrics buildFontString). */\nexport interface TextLineStyle {\n fontSize: number;\n fontFamily: string;\n bold?: boolean;\n italic?: boolean;\n /** Extra advance after each character, px (canvas letterSpacing). */\n letterSpacing?: number;\n}\n\n/** The canvas font shorthand for a style at a size, exactly as the canvas builds it (\"italic bold 72px Oswald\"). */\nexport function canvasFontString(style: TextLineStyle, fontSize = style.fontSize): string {\n return [style.italic ? \"italic\" : \"\", style.bold ? \"bold\" : \"\", `${fontSize}px`, style.fontFamily].filter(Boolean).join(\" \");\n}\n\n/** A share of the box kept free when fitting: measurement differs by a hair between renderers (browser, server raster). */\nexport const FIT_MARGIN = 0.03;\n\n/**\n * The font size one line of `text` is drawn at to fit `maxWidth`: `style.fontSize` when it already fits, else the\n * largest smaller size that does (text width is linear in the font size, plus a fixed letter spacing per character).\n * Never larger than the style's size; never below 1 px. `measure(text, fontSize)` is the line's width at a size.\n */\nexport function shrinkFontSizeToFit(\n text: string,\n style: TextLineStyle,\n maxWidth: number,\n measure: (text: string, fontSize: number) => number,\n): number {\n const limit = maxWidth * (1 - FIT_MARGIN);\n if (!text || !(limit > 0)) return style.fontSize;\n const at = measure(text, style.fontSize);\n if (at <= limit) return style.fontSize;\n const spacing = (style.letterSpacing ?? 0) * text.length;\n let size = Math.max(1, (style.fontSize * Math.max(1, limit - spacing)) / Math.max(1, at - spacing));\n // measurement rounding (hinting, kerning) can leave a hair over: step down until it truly fits\n for (let i = 0; i < 40 && size > 1 && measure(text, size) > limit; i++) size *= 0.98;\n return Math.max(1, Math.floor(size * 2) / 2);\n}\n\nlet measureCtx: CanvasRenderingContext2D | null = null;\n\n/** One line's width in a browser, with the canvas's own font shorthand (0 where no 2D canvas exists, e.g. on a server). */\nexport function measureTextLine(text: string, style: TextLineStyle, fontSize = style.fontSize): number {\n if (typeof document === \"undefined\") return 0;\n measureCtx ??= document.createElement(\"canvas\").getContext(\"2d\");\n if (!measureCtx) return 0;\n measureCtx.font = canvasFontString(style, fontSize);\n return measureCtx.measureText(text).width + (style.letterSpacing ?? 0) * text.length;\n}\n\n/** Debounce a string value — only emits after `delay` ms of inactivity */\nexport function useDebouncedValue(value: string, delay: number): string {\n const [debounced, setDebounced] = useState(value);\n useEffect(() => {\n const timer = setTimeout(() => setDebounced(value), delay);\n return () => clearTimeout(timer);\n }, [value, delay]);\n return debounced;\n}\n\n/**\n * Scroll an input to sit just above the iOS keyboard after it appears.\n * Uses visualViewport.height to determine the visible area above the keyboard.\n */\nexport function scrollInputAboveKeyboard(input: HTMLElement) {\n const position = () => {\n const rect = input.getBoundingClientRect();\n const visibleBottom =\n window.visualViewport?.height || window.innerHeight * 0.5;\n const target = visibleBottom - rect.height - 20;\n const delta = rect.top - target;\n if (Math.abs(delta) > 10) {\n window.scrollBy({ top: delta, behavior: \"smooth\" });\n }\n };\n setTimeout(position, 400);\n window.visualViewport?.addEventListener(\"resize\", position, { once: true });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,IAAAA,gBAAkC;AAClC,oBAAwD;;;ACZxD,mBAAoC;AAI7B,SAAS,aAAa,OAAuB;AAClD,MAAI,MAAM,MAAM,KAAK,EAAE,YAAY;AACnC,MAAI,IAAI,WAAW,KAAK,IAAI,WAAW,GAAG,GAAG;AAC3C,UAAM,MAAM,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC;AAAA,EAChE;AACA,SAAO;AACT;AAGO,SAAS,gBAAgB,KAAsB;AACpD,MAAI,CAAC,OAAO,IAAI,SA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A;AAAA,UAEC,MAAM,MAAM;AAAA,UACZ,OAAO,OAAO,MAAM,IAAI,KAAK;AAAA,UAC7B,KAAK,MAAM,OAAO;AAAA;AAAA,QAHb,SAAS,MAAM,IAAI;AAAA,MAI1B;AAAA,IAEJ;AACA,WAAO;AAAA,EACT,CAAC,GACH;AAEJ;","names":["import_react"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { P as PersonalizationField, a as PersonalizationValues } from '../types-
|
|
2
|
+
import { P as PersonalizationField, a as PersonalizationValues } from '../types-BObPMwP5.cjs';
|
|
3
3
|
|
|
4
4
|
declare function PersonalizationBridge({ fields, values, }: {
|
|
5
5
|
fields: PersonalizationField[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { P as PersonalizationField, a as PersonalizationValues } from '../types-
|
|
2
|
+
import { P as PersonalizationField, a as PersonalizationValues } from '../types-BObPMwP5.js';
|
|
3
3
|
|
|
4
4
|
declare function PersonalizationBridge({ fields, values, }: {
|
|
5
5
|
fields: PersonalizationField[];
|
|
@@ -13,6 +13,22 @@ interface PersonalizationTextField {
|
|
|
13
13
|
label: string;
|
|
14
14
|
/** Input placeholder */
|
|
15
15
|
placeholder?: string;
|
|
16
|
+
/** The longest text the input takes (the input's `maxLength`): the designer's limit for the layout. */
|
|
17
|
+
maxLength?: number;
|
|
18
|
+
/**
|
|
19
|
+
* How the buyer's text meets the element's box. `"shrink"`: the text is set at the element's own size and made
|
|
20
|
+
* smaller (never larger) until one line of it fits the box width (a custom text element's `transformData.width`), so
|
|
21
|
+
* a long name never runs past the design's edge or wraps onto a line the layout has no room for. Absent: the text
|
|
22
|
+
* keeps the element's size and wraps or overflows as the element does.
|
|
23
|
+
*/
|
|
24
|
+
fit?: "shrink";
|
|
25
|
+
/**
|
|
26
|
+
* The element's own text is a SAMPLE ("YOUR NAME"): it shows only until the buyer types into ANY field of the design;
|
|
27
|
+
* from then on this field draws exactly what is in its box, nothing when it is empty (so "Kevin" typed on line 1 of a
|
|
28
|
+
* three-line sample is engraved alone, not as "Kevin / NAME / HERE"). Every box cleared again: the samples come back.
|
|
29
|
+
* Absent: the element's own text stays until this field itself is typed into.
|
|
30
|
+
*/
|
|
31
|
+
sample?: boolean;
|
|
16
32
|
}
|
|
17
33
|
/** Color field — buyer can change a color throughout the design */
|
|
18
34
|
interface PersonalizationColorField {
|
|
@@ -39,4 +55,4 @@ type PersonalizationField = PersonalizationTextField | PersonalizationColorField
|
|
|
39
55
|
/** Buyer's current personalization values. Keys are field names (text/image) or original hex colors (color). */
|
|
40
56
|
type PersonalizationValues = Record<string, string>;
|
|
41
57
|
|
|
42
|
-
export type { PersonalizationField as P, PersonalizationValues as a,
|
|
58
|
+
export type { PersonalizationField as P, PersonalizationValues as a, PersonalizationTextField as b, PersonalizationColorField as c, PersonalizationImageField as d };
|
|
@@ -13,6 +13,22 @@ interface PersonalizationTextField {
|
|
|
13
13
|
label: string;
|
|
14
14
|
/** Input placeholder */
|
|
15
15
|
placeholder?: string;
|
|
16
|
+
/** The longest text the input takes (the input's `maxLength`): the designer's limit for the layout. */
|
|
17
|
+
maxLength?: number;
|
|
18
|
+
/**
|
|
19
|
+
* How the buyer's text meets the element's box. `"shrink"`: the text is set at the element's own size and made
|
|
20
|
+
* smaller (never larger) until one line of it fits the box width (a custom text element's `transformData.width`), so
|
|
21
|
+
* a long name never runs past the design's edge or wraps onto a line the layout has no room for. Absent: the text
|
|
22
|
+
* keeps the element's size and wraps or overflows as the element does.
|
|
23
|
+
*/
|
|
24
|
+
fit?: "shrink";
|
|
25
|
+
/**
|
|
26
|
+
* The element's own text is a SAMPLE ("YOUR NAME"): it shows only until the buyer types into ANY field of the design;
|
|
27
|
+
* from then on this field draws exactly what is in its box, nothing when it is empty (so "Kevin" typed on line 1 of a
|
|
28
|
+
* three-line sample is engraved alone, not as "Kevin / NAME / HERE"). Every box cleared again: the samples come back.
|
|
29
|
+
* Absent: the element's own text stays until this field itself is typed into.
|
|
30
|
+
*/
|
|
31
|
+
sample?: boolean;
|
|
16
32
|
}
|
|
17
33
|
/** Color field — buyer can change a color throughout the design */
|
|
18
34
|
interface PersonalizationColorField {
|
|
@@ -39,4 +55,4 @@ type PersonalizationField = PersonalizationTextField | PersonalizationColorField
|
|
|
39
55
|
/** Buyer's current personalization values. Keys are field names (text/image) or original hex colors (color). */
|
|
40
56
|
type PersonalizationValues = Record<string, string>;
|
|
41
57
|
|
|
42
|
-
export type { PersonalizationField as P, PersonalizationValues as a,
|
|
58
|
+
export type { PersonalizationField as P, PersonalizationValues as a, PersonalizationTextField as b, PersonalizationColorField as c, PersonalizationImageField as d };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snowcone-app/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "React components for merchandise visualization and customization",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"react-instantsearch": "^7.15.5",
|
|
104
104
|
"react-zoom-pan-pinch": "^3.6.4",
|
|
105
105
|
"tailwind-merge": "^3.0.0",
|
|
106
|
-
"@snowcone-app/sdk": "0.33.
|
|
106
|
+
"@snowcone-app/sdk": "0.33.4"
|
|
107
107
|
},
|
|
108
108
|
"devDependencies": {
|
|
109
109
|
"@chromatic-com/storybook": "^4.1.2",
|
|
@@ -68,7 +68,9 @@ export function PersonalizationInputs({
|
|
|
68
68
|
<input
|
|
69
69
|
key={`text-${field.name}`}
|
|
70
70
|
type="text"
|
|
71
|
+
aria-label={field.label}
|
|
71
72
|
placeholder={field.placeholder || field.label}
|
|
73
|
+
maxLength={field.maxLength}
|
|
72
74
|
value={personValues[field.name] ?? ""}
|
|
73
75
|
onChange={(e) => updateField(field.name, e.target.value)}
|
|
74
76
|
onFocus={handleFocus}
|
|
@@ -38,7 +38,7 @@ import type {
|
|
|
38
38
|
PersonalizationField,
|
|
39
39
|
PersonalizationValues,
|
|
40
40
|
} from "./types";
|
|
41
|
-
import { normalizeHex, isValidImageUrl, useDebouncedValue } from "./utils";
|
|
41
|
+
import { normalizeHex, isValidImageUrl, useDebouncedValue, canvasFontString, measureTextLine, shrinkFontSizeToFit, anyTyped, textValueFor, type TextLineStyle } from "./utils";
|
|
42
42
|
|
|
43
43
|
// ---------------------------------------------------------------------------
|
|
44
44
|
// Bridge factory — creates the PersonalizationBridge component from the canvas
|
|
@@ -52,7 +52,11 @@ function createBridgeFromCanvas(canvasModule: any): React.ComponentType<{
|
|
|
52
52
|
}> {
|
|
53
53
|
const { useEditor, useCommands, useImageBinding } = canvasModule;
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
/**
|
|
56
|
+
* One text field → its named elements. `value`: the text to draw, or null = the element's own (designed) text, put back
|
|
57
|
+
* when it was changed (a sample field whose boxes were all cleared again). fit "shrink": the size is fitted to the box.
|
|
58
|
+
*/
|
|
59
|
+
function TextBinder({ name, value, fit, sample }: { name: string; value: string | null; fit?: "shrink"; sample?: boolean }) {
|
|
56
60
|
const { elements } = useEditor();
|
|
57
61
|
const { executeElementUpdate } = useCommands();
|
|
58
62
|
const elementsRef = React.useRef(elements);
|
|
@@ -60,20 +64,53 @@ function createBridgeFromCanvas(canvasModule: any): React.ComponentType<{
|
|
|
60
64
|
const executeRef = React.useRef(executeElementUpdate);
|
|
61
65
|
executeRef.current = executeElementUpdate;
|
|
62
66
|
const hasUserInput = React.useRef(false);
|
|
67
|
+
// each element's text and size as the designer set them (by element id): what null restores, what fit shrinks from
|
|
68
|
+
const designed = React.useRef(new Map<string, { text: string; fontSize: number }>());
|
|
63
69
|
|
|
64
70
|
React.useEffect(() => {
|
|
65
|
-
if (value
|
|
66
|
-
|
|
71
|
+
if (value === null && !hasUserInput.current) return;
|
|
72
|
+
// "" before any input leaves a designer's text alone; on a sample field it means "drawn empty" (something was typed)
|
|
73
|
+
if (value === "" && !hasUserInput.current && !sample) return;
|
|
67
74
|
hasUserInput.current = true;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (!(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
let cancelled = false;
|
|
76
|
+
const bound = elementsRef.current.filter((el: any) => el.name === name && typeof el.setText === "function");
|
|
77
|
+
for (const el of bound as any[]) {
|
|
78
|
+
if (!designed.current.has(el.id)) designed.current.set(el.id, { text: typeof el.getText === "function" ? el.getText() : el.text, fontSize: el.fontSize });
|
|
79
|
+
}
|
|
80
|
+
const apply = (sizes: Map<string, number>) => {
|
|
81
|
+
if (cancelled) return;
|
|
82
|
+
const exec = executeRef.current;
|
|
83
|
+
for (const el of elementsRef.current) {
|
|
84
|
+
if (el.name !== name) continue;
|
|
85
|
+
if (!("setText" in el) || typeof (el as any).setText !== "function") continue;
|
|
86
|
+
const own = designed.current.get(el.id);
|
|
87
|
+
const cloned = el.clone();
|
|
88
|
+
(cloned as any).setText(value ?? own?.text ?? "");
|
|
89
|
+
const size = value === null ? own?.fontSize : sizes.get(el.id);
|
|
90
|
+
if (size !== undefined) (cloned as any).fontSize = size;
|
|
91
|
+
exec(el, cloned);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
if (fit !== "shrink" || value === null) {
|
|
95
|
+
apply(new Map());
|
|
96
|
+
return () => { cancelled = true; };
|
|
75
97
|
}
|
|
76
|
-
|
|
98
|
+
// Fit each bound element: its designed size, made smaller until one line of the value fits its box width. The
|
|
99
|
+
// element's own font must be loaded before it is measured (else the fallback font's widths are fitted).
|
|
100
|
+
const styled = (bound as any[]).map((el) => {
|
|
101
|
+
const style: TextLineStyle = { fontSize: designed.current.get(el.id)!.fontSize, fontFamily: el.fontFamily, bold: el.bold, italic: el.italic, letterSpacing: el.letterSpacing };
|
|
102
|
+
return { id: el.id as string, style, boxWidth: Number(el.transformData?.width) || 0 };
|
|
103
|
+
});
|
|
104
|
+
const fonts = typeof document !== "undefined" && document.fonts ? Promise.all(styled.map((st) => document.fonts.load(canvasFontString(st.style)).catch(() => []))) : Promise.resolve([]);
|
|
105
|
+
void fonts.then(() => {
|
|
106
|
+
const sizes = new Map<string, number>();
|
|
107
|
+
for (const st of styled) {
|
|
108
|
+
sizes.set(st.id, st.boxWidth > 0 ? shrinkFontSizeToFit(value, st.style, st.boxWidth, (t, size) => measureTextLine(t, st.style, size)) : st.style.fontSize);
|
|
109
|
+
}
|
|
110
|
+
apply(sizes);
|
|
111
|
+
});
|
|
112
|
+
return () => { cancelled = true; };
|
|
113
|
+
}, [value, name, fit, sample, elements.length]);
|
|
77
114
|
return null;
|
|
78
115
|
}
|
|
79
116
|
|
|
@@ -146,11 +183,13 @@ function createBridgeFromCanvas(canvasModule: any): React.ComponentType<{
|
|
|
146
183
|
}
|
|
147
184
|
|
|
148
185
|
return function PersonalizationBridge({ fields = [], values = {} }: { fields?: PersonalizationField[]; values?: PersonalizationValues } = {}) {
|
|
186
|
+
// a sample field draws its sample until anything is typed, then exactly its box (textValueFor)
|
|
187
|
+
const typed = anyTyped(fields, values);
|
|
149
188
|
return (
|
|
150
189
|
<>
|
|
151
190
|
{fields.map((field) => {
|
|
152
191
|
if (field.type === "text") {
|
|
153
|
-
return <TextBinder key={`text-${field.name}`} name={field.name} value={values
|
|
192
|
+
return <TextBinder key={`text-${field.name}`} name={field.name} value={textValueFor(field, values, typed)} fit={field.fit} sample={field.sample} />;
|
|
154
193
|
}
|
|
155
194
|
if (field.type === "color") {
|
|
156
195
|
return <ColorBinder key={`color-${field.color}`} originalColor={field.color} newColor={values[field.color] ?? field.color} />;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { shrinkFontSizeToFit, canvasFontString, FIT_MARGIN, anyTyped, textValueFor, type TextLineStyle } from "../utils";
|
|
3
|
+
|
|
4
|
+
// A stand-in font: every character is 0.5 em wide, plus the style's letter spacing (a browser measures the same way:
|
|
5
|
+
// linear in the size, a fixed advance per character).
|
|
6
|
+
const style: TextLineStyle = { fontSize: 72, fontFamily: "Oswald", bold: true };
|
|
7
|
+
const measure = (s: TextLineStyle) => (text: string, size: number) => text.length * size * 0.5 + (s.letterSpacing ?? 0) * text.length;
|
|
8
|
+
|
|
9
|
+
describe("shrinkFontSizeToFit", () => {
|
|
10
|
+
it("keeps the designed size when the text already fits", () => {
|
|
11
|
+
expect(shrinkFontSizeToFit("YOUR NAME", style, 500, measure(style))).toBe(72);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("shrinks a long name until one line of it fits the box (never past the edge)", () => {
|
|
15
|
+
const text = "Maximilian Johnson the Third";
|
|
16
|
+
const size = shrinkFontSizeToFit(text, style, 487, measure(style));
|
|
17
|
+
expect(size).toBeLessThan(72);
|
|
18
|
+
expect(measure(style)(text, size)).toBeLessThanOrEqual(487 * (1 - FIT_MARGIN));
|
|
19
|
+
// and not needlessly small: one more half-pixel would no longer fit
|
|
20
|
+
expect(measure(style)(text, size + 1)).toBeGreaterThan(487 * (1 - FIT_MARGIN));
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("never grows the text past the designed size", () => {
|
|
24
|
+
expect(shrinkFontSizeToFit("A", style, 5000, measure(style))).toBe(72);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("accounts for letter spacing (a fixed advance that does not shrink with the size)", () => {
|
|
28
|
+
const spaced = { ...style, letterSpacing: 6 };
|
|
29
|
+
const text = "CHRISTOPHER COLUMBUS";
|
|
30
|
+
const size = shrinkFontSizeToFit(text, spaced, 487, measure(spaced));
|
|
31
|
+
expect(measure(spaced)(text, size)).toBeLessThanOrEqual(487 * (1 - FIT_MARGIN));
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("leaves the size alone when nothing can be measured (a server render, no box)", () => {
|
|
35
|
+
expect(shrinkFontSizeToFit("Anything long enough to overflow", style, 487, () => 0)).toBe(72);
|
|
36
|
+
expect(shrinkFontSizeToFit("Anything", style, 0, measure(style))).toBe(72);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("canvasFontString", () => {
|
|
41
|
+
it("is the canvas's own shorthand (TextMetrics buildFontString)", () => {
|
|
42
|
+
expect(canvasFontString(style)).toBe("bold 72px Oswald");
|
|
43
|
+
expect(canvasFontString({ ...style, italic: true }, 40)).toBe("italic bold 40px Oswald");
|
|
44
|
+
expect(canvasFontString({ fontSize: 12, fontFamily: "Arial" })).toBe("12px Arial");
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("textValueFor / anyTyped (sample text)", () => {
|
|
49
|
+
const line = (n: number, sample = true) => ({ type: "text" as const, name: `line${n}`, label: `Line ${n}`, sample });
|
|
50
|
+
const fields = [line(1), line(2), line(3)];
|
|
51
|
+
|
|
52
|
+
it("draws the samples (null) until anything is typed", () => {
|
|
53
|
+
expect(anyTyped(fields, {})).toBe(false);
|
|
54
|
+
expect(fields.map((f) => textValueFor(f, {}, false))).toEqual([null, null, null]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("once one box is typed, every sample field draws exactly its box: 'Kevin' alone, not 'Kevin / NAME / HERE'", () => {
|
|
58
|
+
const values = { line1: "Kevin" };
|
|
59
|
+
const typed = anyTyped(fields, values);
|
|
60
|
+
expect(typed).toBe(true);
|
|
61
|
+
expect(fields.map((f) => textValueFor(f, values, typed))).toEqual(["Kevin", "", ""]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("brings the samples back when every box is cleared (blank counts as cleared)", () => {
|
|
65
|
+
const values = { line1: "", line2: " " };
|
|
66
|
+
expect(anyTyped(fields, values)).toBe(false);
|
|
67
|
+
expect(fields.map((f) => textValueFor(f, values, false))).toEqual([null, null, null]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("leaves a field that is not a sample as it was: its own box's text, '' until typed", () => {
|
|
71
|
+
const f = line(1, false);
|
|
72
|
+
expect(textValueFor(f, {}, true)).toBe("");
|
|
73
|
+
expect(textValueFor(f, { line1: "Ana" }, true)).toBe("Ana");
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -40,4 +40,5 @@ export { usePersonalizationShimmer } from "./usePersonalizationShimmer";
|
|
|
40
40
|
export type { UsePersonalizationShimmerReturn } from "./usePersonalizationShimmer";
|
|
41
41
|
|
|
42
42
|
// Utilities (for custom input implementations)
|
|
43
|
-
export { scrollInputAboveKeyboard, normalizeHex } from "./utils";
|
|
43
|
+
export { scrollInputAboveKeyboard, normalizeHex, shrinkFontSizeToFit, measureTextLine, canvasFontString, FIT_MARGIN, anyTyped, textValueFor } from "./utils";
|
|
44
|
+
export type { TextLineStyle } from "./utils";
|
|
@@ -14,6 +14,22 @@ export interface PersonalizationTextField {
|
|
|
14
14
|
label: string;
|
|
15
15
|
/** Input placeholder */
|
|
16
16
|
placeholder?: string;
|
|
17
|
+
/** The longest text the input takes (the input's `maxLength`): the designer's limit for the layout. */
|
|
18
|
+
maxLength?: number;
|
|
19
|
+
/**
|
|
20
|
+
* How the buyer's text meets the element's box. `"shrink"`: the text is set at the element's own size and made
|
|
21
|
+
* smaller (never larger) until one line of it fits the box width (a custom text element's `transformData.width`), so
|
|
22
|
+
* a long name never runs past the design's edge or wraps onto a line the layout has no room for. Absent: the text
|
|
23
|
+
* keeps the element's size and wraps or overflows as the element does.
|
|
24
|
+
*/
|
|
25
|
+
fit?: "shrink";
|
|
26
|
+
/**
|
|
27
|
+
* The element's own text is a SAMPLE ("YOUR NAME"): it shows only until the buyer types into ANY field of the design;
|
|
28
|
+
* from then on this field draws exactly what is in its box, nothing when it is empty (so "Kevin" typed on line 1 of a
|
|
29
|
+
* three-line sample is engraved alone, not as "Kevin / NAME / HERE"). Every box cleared again: the samples come back.
|
|
30
|
+
* Absent: the element's own text stays until this field itself is typed into.
|
|
31
|
+
*/
|
|
32
|
+
sample?: boolean;
|
|
17
33
|
}
|
|
18
34
|
|
|
19
35
|
/** Color field — buyer can change a color throughout the design */
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { useEffect, useState } from "react";
|
|
8
|
+
import type { PersonalizationField, PersonalizationTextField, PersonalizationValues } from "./types";
|
|
8
9
|
|
|
9
10
|
/** Normalize any hex color to uppercase 6-digit form (#RGB → #RRGGBB) */
|
|
10
11
|
export function normalizeHex(color: string): string {
|
|
@@ -29,6 +30,73 @@ export function isValidImageUrl(url: string): boolean {
|
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
/** Has the buyer typed into any TEXT field of the design (any non-blank text)? */
|
|
34
|
+
export function anyTyped(fields: readonly PersonalizationField[], values: PersonalizationValues): boolean {
|
|
35
|
+
return fields.some((f) => f.type === "text" && typeof values[f.name] === "string" && values[f.name].trim().length > 0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* What a text field's elements draw: its box's text, or null = the element's own (designed) text. A `sample` field draws
|
|
40
|
+
* its sample until anything is typed in any field, then exactly its box (empty = nothing). Any other field draws its
|
|
41
|
+
* box's text ("" until typed into, which the binder leaves alone).
|
|
42
|
+
*/
|
|
43
|
+
export function textValueFor(field: PersonalizationTextField, values: PersonalizationValues, typed = false): string | null {
|
|
44
|
+
const v = values[field.name] ?? "";
|
|
45
|
+
if (field.sample) return typed ? v : null;
|
|
46
|
+
return v;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The font a text element draws with: the canvas's own CSS font shorthand (canvas TextMetrics buildFontString). */
|
|
50
|
+
export interface TextLineStyle {
|
|
51
|
+
fontSize: number;
|
|
52
|
+
fontFamily: string;
|
|
53
|
+
bold?: boolean;
|
|
54
|
+
italic?: boolean;
|
|
55
|
+
/** Extra advance after each character, px (canvas letterSpacing). */
|
|
56
|
+
letterSpacing?: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The canvas font shorthand for a style at a size, exactly as the canvas builds it ("italic bold 72px Oswald"). */
|
|
60
|
+
export function canvasFontString(style: TextLineStyle, fontSize = style.fontSize): string {
|
|
61
|
+
return [style.italic ? "italic" : "", style.bold ? "bold" : "", `${fontSize}px`, style.fontFamily].filter(Boolean).join(" ");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A share of the box kept free when fitting: measurement differs by a hair between renderers (browser, server raster). */
|
|
65
|
+
export const FIT_MARGIN = 0.03;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The font size one line of `text` is drawn at to fit `maxWidth`: `style.fontSize` when it already fits, else the
|
|
69
|
+
* largest smaller size that does (text width is linear in the font size, plus a fixed letter spacing per character).
|
|
70
|
+
* Never larger than the style's size; never below 1 px. `measure(text, fontSize)` is the line's width at a size.
|
|
71
|
+
*/
|
|
72
|
+
export function shrinkFontSizeToFit(
|
|
73
|
+
text: string,
|
|
74
|
+
style: TextLineStyle,
|
|
75
|
+
maxWidth: number,
|
|
76
|
+
measure: (text: string, fontSize: number) => number,
|
|
77
|
+
): number {
|
|
78
|
+
const limit = maxWidth * (1 - FIT_MARGIN);
|
|
79
|
+
if (!text || !(limit > 0)) return style.fontSize;
|
|
80
|
+
const at = measure(text, style.fontSize);
|
|
81
|
+
if (at <= limit) return style.fontSize;
|
|
82
|
+
const spacing = (style.letterSpacing ?? 0) * text.length;
|
|
83
|
+
let size = Math.max(1, (style.fontSize * Math.max(1, limit - spacing)) / Math.max(1, at - spacing));
|
|
84
|
+
// measurement rounding (hinting, kerning) can leave a hair over: step down until it truly fits
|
|
85
|
+
for (let i = 0; i < 40 && size > 1 && measure(text, size) > limit; i++) size *= 0.98;
|
|
86
|
+
return Math.max(1, Math.floor(size * 2) / 2);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let measureCtx: CanvasRenderingContext2D | null = null;
|
|
90
|
+
|
|
91
|
+
/** One line's width in a browser, with the canvas's own font shorthand (0 where no 2D canvas exists, e.g. on a server). */
|
|
92
|
+
export function measureTextLine(text: string, style: TextLineStyle, fontSize = style.fontSize): number {
|
|
93
|
+
if (typeof document === "undefined") return 0;
|
|
94
|
+
measureCtx ??= document.createElement("canvas").getContext("2d");
|
|
95
|
+
if (!measureCtx) return 0;
|
|
96
|
+
measureCtx.font = canvasFontString(style, fontSize);
|
|
97
|
+
return measureCtx.measureText(text).width + (style.letterSpacing ?? 0) * text.length;
|
|
98
|
+
}
|
|
99
|
+
|
|
32
100
|
/** Debounce a string value — only emits after `delay` ms of inactivity */
|
|
33
101
|
export function useDebouncedValue(value: string, delay: number): string {
|
|
34
102
|
const [debounced, setDebounced] = useState(value);
|
package/dist/chunk-WDOT4BST.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// src/personalization/utils.ts
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
3
|
-
function normalizeHex(color) {
|
|
4
|
-
let hex = color.trim().toUpperCase();
|
|
5
|
-
if (hex.length === 4 && hex.startsWith("#")) {
|
|
6
|
-
hex = "#" + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3];
|
|
7
|
-
}
|
|
8
|
-
return hex;
|
|
9
|
-
}
|
|
10
|
-
function isValidImageUrl(url) {
|
|
11
|
-
if (!url || url.length < 10) return false;
|
|
12
|
-
try {
|
|
13
|
-
const parsed = new URL(url);
|
|
14
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return false;
|
|
15
|
-
if (!parsed.hostname.includes(".")) return false;
|
|
16
|
-
if (parsed.pathname.length <= 1) return false;
|
|
17
|
-
return true;
|
|
18
|
-
} catch {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function useDebouncedValue(value, delay) {
|
|
23
|
-
const [debounced, setDebounced] = useState(value);
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
const timer = setTimeout(() => setDebounced(value), delay);
|
|
26
|
-
return () => clearTimeout(timer);
|
|
27
|
-
}, [value, delay]);
|
|
28
|
-
return debounced;
|
|
29
|
-
}
|
|
30
|
-
function scrollInputAboveKeyboard(input) {
|
|
31
|
-
const position = () => {
|
|
32
|
-
const rect = input.getBoundingClientRect();
|
|
33
|
-
const visibleBottom = window.visualViewport?.height || window.innerHeight * 0.5;
|
|
34
|
-
const target = visibleBottom - rect.height - 20;
|
|
35
|
-
const delta = rect.top - target;
|
|
36
|
-
if (Math.abs(delta) > 10) {
|
|
37
|
-
window.scrollBy({ top: delta, behavior: "smooth" });
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
setTimeout(position, 400);
|
|
41
|
-
window.visualViewport?.addEventListener("resize", position, { once: true });
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export {
|
|
45
|
-
normalizeHex,
|
|
46
|
-
isValidImageUrl,
|
|
47
|
-
useDebouncedValue,
|
|
48
|
-
scrollInputAboveKeyboard
|
|
49
|
-
};
|
|
50
|
-
//# sourceMappingURL=chunk-WDOT4BST.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/personalization/utils.ts"],"sourcesContent":["\"use client\";\n\n/**\n * Personalization Utilities\n */\n\nimport { useEffect, useState } from \"react\";\n\n/** Normalize any hex color to uppercase 6-digit form (#RGB → #RRGGBB) */\nexport function normalizeHex(color: string): string {\n let hex = color.trim().toUpperCase();\n if (hex.length === 4 && hex.startsWith(\"#\")) {\n hex = \"#\" + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3];\n }\n return hex;\n}\n\n/** Check if a string looks like a complete, loadable URL */\nexport function isValidImageUrl(url: string): boolean {\n if (!url || url.length < 10) return false;\n try {\n const parsed = new URL(url);\n if (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") return false;\n if (!parsed.hostname.includes(\".\")) return false;\n if (parsed.pathname.length <= 1) return false;\n return true;\n } catch {\n return false;\n }\n}\n\n/** Debounce a string value — only emits after `delay` ms of inactivity */\nexport function useDebouncedValue(value: string, delay: number): string {\n const [debounced, setDebounced] = useState(value);\n useEffect(() => {\n const timer = setTimeout(() => setDebounced(value), delay);\n return () => clearTimeout(timer);\n }, [value, delay]);\n return debounced;\n}\n\n/**\n * Scroll an input to sit just above the iOS keyboard after it appears.\n * Uses visualViewport.height to determine the visible area above the keyboard.\n */\nexport function scrollInputAboveKeyboard(input: HTMLElement) {\n const position = () => {\n const rect = input.getBoundingClientRect();\n const visibleBottom =\n window.visualViewport?.height || window.innerHeight * 0.5;\n const target = visibleBottom - rect.height - 20;\n const delta = rect.top - target;\n if (Math.abs(delta) > 10) {\n window.scrollBy({ top: delta, behavior: \"smooth\" });\n }\n };\n setTimeout(position, 400);\n window.visualViewport?.addEventListener(\"resize\", position, { once: true });\n}\n"],"mappings":";AAMA,SAAS,WAAW,gBAAgB;AAG7B,SAAS,aAAa,OAAuB;AAClD,MAAI,MAAM,MAAM,KAAK,EAAE,YAAY;AACnC,MAAI,IAAI,WAAW,KAAK,IAAI,WAAW,GAAG,GAAG;AAC3C,UAAM,MAAM,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC;AAAA,EAChE;AACA,SAAO;AACT;AAGO,SAAS,gBAAgB,KAAsB;AACpD,MAAI,CAAC,OAAO,IAAI,SAAS,GAAI,QAAO;AACpC,MAAI;AACF,UAAM,SAAS,IAAI,IAAI,GAAG;AAC1B,QAAI,OAAO,aAAa,WAAW,OAAO,aAAa,SAAU,QAAO;AACxE,QAAI,CAAC,OAAO,SAAS,SAAS,GAAG,EAAG,QAAO;AAC3C,QAAI,OAAO,SAAS,UAAU,EAAG,QAAO;AACxC,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGO,SAAS,kBAAkB,OAAe,OAAuB;AACtE,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAChD,YAAU,MAAM;AACd,UAAM,QAAQ,WAAW,MAAM,aAAa,KAAK,GAAG,KAAK;AACzD,WAAO,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