MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //home/cafsindia/snap.cafsinfotech.in/node_modules/caret-pos/src/mirror.js
const attributes = [
  'borderBottomWidth',
  'borderLeftWidth',
  'borderRightWidth',
  'borderTopStyle',
  'borderRightStyle',
  'borderBottomStyle',
  'borderLeftStyle',
  'borderTopWidth',
  'boxSizing',
  'fontFamily',
  'fontSize',
  'fontWeight',
  'height',
  'letterSpacing',
  'lineHeight',
  'marginBottom',
  'marginLeft',
  'marginRight',
  'marginTop',
  'outlineWidth',
  'overflow',
  'overflowX',
  'overflowY',
  'paddingBottom',
  'paddingLeft',
  'paddingRight',
  'paddingTop',
  'textAlign',
  'textOverflow',
  'textTransform',
  'whiteSpace',
  'wordBreak',
  'wordWrap',
];

/**
 * Create a mirror
 *
 * @param {Element} element The element
 * @param {string} html The html
 *
 * @return {object} The mirror object
 */
const createMirror = (element, html) => {

  /**
   * The mirror element
   */
  const mirror = document.createElement('div');

  /**
   * Create the CSS for the mirror object
   *
   * @return {object} The style object
   */
  const mirrorCss = () => {
    const css = {
      position: 'absolute',
      left: -9999,
      top: 0,
      zIndex: -2000
    };

    if (element.tagName === 'TEXTAREA') {
      attributes.push('width');
    }

    attributes.forEach((attr) => {
      css[attr] = getComputedStyle(element)[attr];
    });

    return css;
  };

  /**
   * Initialize the mirror
   *
   * @param {string} html The html
   *
   * @return {void}
   */
  const initialize = (html) => {
    const styles = mirrorCss();
    Object.keys(styles).forEach(key => {
      mirror.style[key] = styles[key];
    });
    mirror.innerHTML = html;
    element.parentNode.insertBefore(mirror, element.nextSibling);
  };

  /**
   * Get the rect
   *
   * @return {Rect} The bounding rect
   */
  const rect = () => {
    const marker = mirror.ownerDocument.getElementById('caret-position-marker');
    const boundingRect = {
      left: marker.offsetLeft,
      top: marker.offsetTop,
      height: marker.offsetHeight
    };
    mirror.parentNode.removeChild(mirror);

    return boundingRect;
  };

  initialize(html);

  return {
    rect,
  };
};

export default createMirror;