MCPcopy Create free account
hub / github.com/editablejs/editable / transformOrigin

Function transformOrigin

packages/ui/src/popper.tsx:420–455  ·  view source on GitHub ↗
(options: { arrowWidth: number; arrowHeight: number })

Source from the content-addressed store, hash-verified

418}
419
420const transformOrigin = (options: { arrowWidth: number; arrowHeight: number }): Middleware => ({
421 name: 'transformOrigin',
422 options,
423 fn(data) {
424 const { placement, rects, middlewareData } = data
425
426 const cannotCenterArrow = middlewareData.arrow?.centerOffset !== 0
427 const isArrowHidden = cannotCenterArrow
428 const arrowWidth = isArrowHidden ? 0 : options.arrowWidth
429 const arrowHeight = isArrowHidden ? 0 : options.arrowHeight
430
431 const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement)
432 const noArrowAlign = { start: '0%', center: '50%', end: '100%' }[placedAlign]
433
434 const arrowXCenter = (middlewareData.arrow?.x ?? 0) + arrowWidth / 2
435 const arrowYCenter = (middlewareData.arrow?.y ?? 0) + arrowHeight / 2
436
437 let x = ''
438 let y = ''
439
440 if (placedSide === 'bottom') {
441 x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`
442 y = `${-arrowHeight}px`
443 } else if (placedSide === 'top') {
444 x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`
445 y = `${rects.floating.height + arrowHeight}px`
446 } else if (placedSide === 'right') {
447 x = `${-arrowHeight}px`
448 y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`
449 } else if (placedSide === 'left') {
450 x = `${rects.floating.width + arrowHeight}px`
451 y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`
452 }
453 return { data: { x, y } }
454 },
455})
456
457function getSideAndAlignFromPlacement(placement: Placement) {
458 const [side, align = 'center'] = placement.split('-')

Callers 1

popper.tsxFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…