/**
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ const TAB_DATA = "data-mdc-tabindex" ; const TAB_DATA_HANDLED = "data-mdc-tabindex-handled" ; let _storedTransformPropertyName ; let _supportsPassive ; export function remapEvent ( eventName , globalObj = window ) { if ( ! ( "ontouchstart" in globalObj . document ) ) { switch ( eventName ) { case "touchstart" : return "pointerdown" ; case "touchmove" : return "pointermove" ; case "touchend" : return "pointerup" ; default : return eventName ; } } return eventName ; } export function getTransformPropertyName ( globalObj = window , forceRefresh = false ) { if ( _storedTransformPropertyName === undefined || forceRefresh ) { const el = globalObj . document . createElement ( "div" ) ; const transformPropertyName = ( "transform" in el . style ? "transform" : "-webkit-transform" ) ; _storedTransformPropertyName = transformPropertyName ; } return _storedTransformPropertyName ; } export function supportsCssCustomProperties ( globalObj = window ) { if ( "CSS" in globalObj ) { return globalObj . CSS . supports ( "(--color: red)" ) ; } return false ; } export function applyPassive ( globalObj = window , forceRefresh = false ) { if ( _supportsPassive === undefined || forceRefresh ) { let isSupported = false ; try { const checker = { } ; Object . defineProperty ( checker , "passive" , { get : ( ) => { isSupported = true ; } } ) ; globalObj . document . addEventListener ( "test" , null , checker ) ; } catch ( e ) { } _supportsPassive = isSupported ; } return _supportsPassive ? { passive : true } : false ; } export function saveElementTabState ( el ) { if ( el . hasAttribute ( "tabindex" ) ) { el . setAttribute ( TAB_DATA , el . getAttribute ( "tabindex" ) ) ; } el . setAttribute ( TAB_DATA_HANDLED , true ) ; } export function restoreElementTabState ( el ) { if ( el . hasAttribute ( TAB_DATA_HANDLED ) ) { if ( el . hasAttribute ( TAB_DATA ) ) { el . setAttribute ( "tabindex" , el . getAttribute ( TAB_DATA ) ) ; el . removeAttribute ( TAB_DATA ) ; } else { el . removeAttribute ( "tabindex" ) ; } el . removeAttribute ( TAB_DATA_HANDLED ) ; } }