/** * @license * Copyright Google LLC 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://angular.io/license */ // Helper type that ignores `readonly` properties. This is used in // `extendStyles` to ignore the readonly properties on CSSStyleDeclaration // since we won't be touching those anyway. type Writeable = { -readonly [P in keyof T]-?: T[P] }; /** * Extended CSSStyleDeclaration that includes a couple of drag-related * properties that aren't in the built-in TS typings. */ interface DragCSSStyleDeclaration extends CSSStyleDeclaration { webkitUserDrag: string; MozUserSelect: string; // For some reason the Firefox property is in PascalCase. } /** * Shallow-extends a stylesheet object with another stylesheet object. * @docs-private */ export function extendStyles( dest: Writeable, source: Partial) { for (let key in source) { if (source.hasOwnProperty(key)) { dest[key as keyof CSSStyleDeclaration] = source[key as keyof CSSStyleDeclaration]; } } return dest; } /** * Toggles whether the native drag interactions should be enabled for an element. * @param element Element on which to toggle the drag interactions. * @param enable Whether the drag interactions should be enabled. * @docs-private */ export function toggleNativeDragInteractions(element: HTMLElement, enable: boolean) { const userSelect = enable ? '' : 'none'; extendStyles(element.style, { touchAction: enable ? '' : 'none', webkitUserDrag: enable ? '' : 'none', webkitTapHighlightColor: enable ? '' : 'transparent', userSelect: userSelect, msUserSelect: userSelect, webkitUserSelect: userSelect, MozUserSelect: userSelect }); }