UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

198 lines 19.7 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @license * Copyright Alibaba.com All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ // from https://github.com/component/textarea-caret-position // We'll copy the properties below into the mirror div. // Note that some browsers, such as Firefox, do not concatenate properties // into their shorthand (e.g. padding-top, padding-bottom etc. -> padding), // so we have to list every single property explicitly. /** @type {?} */ export const properties = [ 'direction', 'boxSizing', 'width', 'height', 'overflowX', 'overflowY', 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth', 'borderStyle', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', // https://developer.mozilla.org/en-US/docs/Web/CSS/font 'fontStyle', 'fontVariant', 'fontWeight', 'fontStretch', 'fontSize', 'fontSizeAdjust', 'lineHeight', 'fontFamily', 'textAlign', 'textTransform', 'textIndent', 'textDecoration', 'letterSpacing', 'wordSpacing', 'tabSize', 'MozTabSize' ]; /** @type {?} */ const isBrowser = typeof window !== 'undefined'; // tslint:disable-next-line:no-any /** @type {?} */ const isFirefox = isBrowser && ((/** @type {?} */ (window))).mozInnerScreenX != null; /** @type {?} */ const _parseInt = (/** * @param {?} str * @return {?} */ (str) => parseInt(str, 10)); const ɵ0 = _parseInt; /** * @record */ export function Coordinates() { } if (false) { /** @type {?} */ Coordinates.prototype.top; /** @type {?} */ Coordinates.prototype.left; /** @type {?} */ Coordinates.prototype.height; } /** * @param {?} element * @param {?} position * @param {?=} options * @return {?} */ export function getCaretCoordinates(element, position, options) { if (!isBrowser) { throw new Error('textarea-caret-position#getCaretCoordinates should only be called in a browser'); } /** @type {?} */ const debug = (options && options.debug) || false; if (debug) { /** @type {?} */ const el = document.querySelector('#input-textarea-caret-position-mirror-div'); if (el) { (/** @type {?} */ (el.parentNode)).removeChild(el); } } // The mirror div will replicate the textarea's style /** @type {?} */ const div = document.createElement('div'); div.id = 'input-textarea-caret-position-mirror-div'; document.body.appendChild(div); /** @type {?} */ const style = div.style; // tslint:disable-next-line:no-any /** @type {?} */ const computed = window.getComputedStyle ? window.getComputedStyle(element) : ((/** @type {?} */ (element))).currentStyle; // currentStyle for IE < 9 /** @type {?} */ const isInput = element.nodeName === 'INPUT'; // Default textarea styles style.whiteSpace = 'pre-wrap'; if (!isInput) { style.wordWrap = 'break-word'; // only for textarea-s } // Position off-screen style.position = 'absolute'; // required to return coordinates properly if (!debug) { style.visibility = 'hidden'; } // not 'display: none' because we want rendering // Transfer the element's properties to the div properties.forEach((/** * @param {?} prop * @return {?} */ (prop) => { if (isInput && prop === 'lineHeight') { // Special case for <input>s because text is rendered centered and line height may be != height style.lineHeight = computed.height; } else { // @ts-ignore style[prop] = computed[prop]; } })); if (isFirefox) { // Firefox lies about the overflow property for textareas: https://bugzilla.mozilla.org/show_bug.cgi?id=984275 if (element.scrollHeight > _parseInt(computed.height)) { style.overflowY = 'scroll'; } } else { style.overflow = 'hidden'; // for Chrome to not render a scrollbar; IE keeps overflowY = 'scroll' } div.textContent = element.value.substring(0, position); // The second special handling for input type="text" vs textarea: // spaces need to be replaced with non-breaking spaces - http://stackoverflow.com/a/13402035/1269037 if (isInput) { div.textContent = div.textContent.replace(/\s/g, '\u00a0'); } /** @type {?} */ const span = document.createElement('span'); // Wrapping must be replicated *exactly*, including when a long word gets // onto the next line, with whitespace at the end of the line before (#7). // The *only* reliable way to do that is to copy the *entire* rest of the // textarea's content into the <span> created at the caret position. // For inputs, just '.' would be enough, but no need to bother. span.textContent = element.value.substring(position) || '.'; // || because a completely empty faux span doesn't render at all div.appendChild(span); /** @type {?} */ const coordinates = { top: span.offsetTop + _parseInt(computed.borderTopWidth), left: span.offsetLeft + _parseInt(computed.borderLeftWidth), height: _parseInt(computed.lineHeight) }; if (debug) { span.style.backgroundColor = '#eee'; createDebugEle(element, coordinates); } else { document.body.removeChild(div); } return coordinates; } /** * @param {?} element * @param {?} coordinates * @return {?} */ export function createDebugEle(element, coordinates) { /** @type {?} */ const fontSize = getComputedStyle(element).getPropertyValue('font-size'); /** @type {?} */ const rect = ((/** @type {?} */ (document.querySelector('#DEBUG')))) || document.createElement('div'); document.body.appendChild(rect); rect.id = 'DEBUG'; rect.style.position = 'absolute'; rect.style.backgroundColor = 'red'; rect.style.height = fontSize; rect.style.width = '1px'; rect.style.top = `${element.getBoundingClientRect().top - element.scrollTop + window.pageYOffset + coordinates.top}px`; rect.style.left = `${element.getBoundingClientRect().left - element.scrollLeft + window.pageXOffset + coordinates.left}px`; } export { ɵ0 }; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGV4dGFyZWEtY2FyZXQtcG9zaXRpb24uanMiLCJzb3VyY2VSb290Ijoibmc6Ly9uZy16b3Jyby1hbnRkL2NvcmUvIiwic291cmNlcyI6WyJ1dGlsL3RleHRhcmVhLWNhcmV0LXBvc2l0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBY0EsTUFBTSxPQUFPLFVBQVUsR0FBRztJQUN4QixXQUFXO0lBQ1gsV0FBVztJQUNYLE9BQU87SUFDUCxRQUFRO0lBQ1IsV0FBVztJQUNYLFdBQVc7SUFFWCxnQkFBZ0I7SUFDaEIsa0JBQWtCO0lBQ2xCLG1CQUFtQjtJQUNuQixpQkFBaUI7SUFDakIsYUFBYTtJQUViLFlBQVk7SUFDWixjQUFjO0lBQ2QsZUFBZTtJQUNmLGFBQWE7SUFFYix3REFBd0Q7SUFDeEQsV0FBVztJQUNYLGFBQWE7SUFDYixZQUFZO0lBQ1osYUFBYTtJQUNiLFVBQVU7SUFDVixnQkFBZ0I7SUFDaEIsWUFBWTtJQUNaLFlBQVk7SUFFWixXQUFXO0lBQ1gsZ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