1- import {
2- MouseEvent ,
3- useEffect ,
4- useLayoutEffect ,
5- useRef ,
6- useState ,
7- suppressContentEditableWarningProps ,
8- } from '@framework' ;
1+ import { MouseEvent , useEffect , useRef , suppressContentEditableWarningProps } from '@framework' ;
92import {
103 PdfFreeTextAnnoObject ,
114 PdfVerticalAlignment ,
125 standardFontCssProperties ,
136 textAlignmentToCss ,
147} from '@embedpdf/models' ;
15- import { useAnnotationCapability } from '../..' ;
8+ import { useAnnotationCapability , useIOSZoomPrevention } from '../..' ;
169import { TrackedAnnotation } from '@embedpdf/plugin-annotation' ;
1710
1811interface FreeTextProps {
@@ -42,7 +35,10 @@ export function FreeText({
4235 const editingRef = useRef ( false ) ;
4336 const { provides : annotationCapability } = useAnnotationCapability ( ) ;
4437 const annotationProvides = annotationCapability ?. forDocument ( documentId ) ?? null ;
45- const [ isIOS , setIsIOS ] = useState ( false ) ;
38+ const { adjustedFontPx, wrapperStyle } = useIOSZoomPrevention (
39+ annotation . object . fontSize * scale ,
40+ isEditing ,
41+ ) ;
4642
4743 useEffect ( ( ) => {
4844 if ( isEditing && editorRef . current ) {
@@ -67,18 +63,6 @@ export function FreeText({
6763 }
6864 } , [ isEditing ] ) ;
6965
70- useLayoutEffect ( ( ) => {
71- try {
72- const nav = navigator as any ;
73- const ios =
74- / i P a d | i P h o n e | i P o d / . test ( navigator . userAgent ) ||
75- ( navigator . platform === 'MacIntel' && nav ?. maxTouchPoints > 1 ) ;
76- setIsIOS ( ios ) ;
77- } catch {
78- setIsIOS ( false ) ;
79- }
80- } , [ ] ) ;
81-
8266 const handleBlur = ( ) => {
8367 if ( ! editingRef . current ) return ;
8468 editingRef . current = false ;
@@ -89,15 +73,6 @@ export function FreeText({
8973 } ) ;
9074 } ;
9175
92- // iOS zoom prevention: keep focused font-size >= 16px, visually scale down if needed.
93- const computedFontPx = annotation . object . fontSize * scale ;
94- const MIN_IOS_FOCUS_FONT_PX = 16 ;
95- const needsComp =
96- isIOS && isEditing && computedFontPx > 0 && computedFontPx < MIN_IOS_FOCUS_FONT_PX ;
97- const adjustedFontPx = needsComp ? MIN_IOS_FOCUS_FONT_PX : computedFontPx ;
98- const scaleComp = needsComp ? computedFontPx / MIN_IOS_FOCUS_FONT_PX : 1 ;
99- const invScalePercent = needsComp ? 100 / scaleComp : 100 ;
100-
10176 return (
10277 < div
10378 style = { {
@@ -130,14 +105,13 @@ export function FreeText({
130105 display : 'flex' ,
131106 backgroundColor : annotation . object . color ?? annotation . object . backgroundColor ,
132107 opacity : annotation . object . opacity ,
133- width : needsComp ? ` ${ invScalePercent } %` : '100%' ,
134- height : needsComp ? ` ${ invScalePercent } %` : '100%' ,
108+ width : '100%' ,
109+ height : '100%' ,
135110 lineHeight : '1.18' ,
136111 overflow : 'hidden' ,
137112 cursor : isEditing ? 'text' : onClick ? 'pointer' : 'default' ,
138113 outline : 'none' ,
139- transform : needsComp ? `scale(${ scaleComp } )` : undefined ,
140- transformOrigin : 'top left' ,
114+ ...wrapperStyle ,
141115 } }
142116 contentEditable = { isEditing }
143117 { ...suppressContentEditableWarningProps }
0 commit comments