Home / File/ getVendorPrefixedEventName.js — react Source File

getVendorPrefixedEventName.js — react Source File

Architecture documentation for getVendorPrefixedEventName.js, a javascript file in the react codebase. 1 imports, 1 dependents.

File javascript BabelCompiler Validation 1 imports 1 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  03fd5196_cd1d_cabf_69f7_e4ce815e6bb9["getVendorPrefixedEventName.js"]
  de79e1ff_cd82_893f_4de4_c543c7303310["ExecutionEnvironment"]
  03fd5196_cd1d_cabf_69f7_e4ce815e6bb9 --> de79e1ff_cd82_893f_4de4_c543c7303310
  4e9925e9_ca97_8d79_6ffa_a9347d262615["DOMEventNames.js"]
  4e9925e9_ca97_8d79_6ffa_a9347d262615 --> 03fd5196_cd1d_cabf_69f7_e4ce815e6bb9
  style 03fd5196_cd1d_cabf_69f7_e4ce815e6bb9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

import {canUseDOM} from 'shared/ExecutionEnvironment';

/**
 * Generate a mapping of standard vendor prefixes using the defined style property and event name.
 *
 * @param {string} styleProp
 * @param {string} eventName
 * @returns {object}
 */
function makePrefixMap(styleProp, eventName) {
  const prefixes = {};

  prefixes[styleProp.toLowerCase()] = eventName.toLowerCase();
  prefixes['Webkit' + styleProp] = 'webkit' + eventName;
  prefixes['Moz' + styleProp] = 'moz' + eventName;

  return prefixes;
}

/**
 * A list of event names to a configurable list of vendor prefixes.
 */
const vendorPrefixes = {
  animationend: makePrefixMap('Animation', 'AnimationEnd'),
  animationiteration: makePrefixMap('Animation', 'AnimationIteration'),
  animationstart: makePrefixMap('Animation', 'AnimationStart'),
  transitionrun: makePrefixMap('Transition', 'TransitionRun'),
  transitionstart: makePrefixMap('Transition', 'TransitionStart'),
  transitioncancel: makePrefixMap('Transition', 'TransitionCancel'),
  transitionend: makePrefixMap('Transition', 'TransitionEnd'),
};

/**
 * Event names that have already been detected and prefixed (if applicable).
 */
const prefixedEventNames = {};

/**
 * Element to check for prefixes on.
 */
let style = {};

/**
 * Bootstrap if a DOM exists.
 */
if (canUseDOM) {
  style = document.createElement('div').style;

  // On some platforms, in particular some releases of Android 4.x,
  // the un-prefixed "animation" and "transition" properties are defined on the
  // style object but the events that fire will still be prefixed, so we need
  // to check if the un-prefixed events are usable, and if not remove them from the map.
  if (!('AnimationEvent' in window)) {
    delete vendorPrefixes.animationend.animation;
    delete vendorPrefixes.animationiteration.animation;
    delete vendorPrefixes.animationstart.animation;
  }

  // Same as above
  if (!('TransitionEvent' in window)) {
    delete vendorPrefixes.transitionend.transition;
  }
}

/**
 * Attempts to determine the correct vendor prefixed event name.
 *
 * @param {string} eventName
 * @returns {string}
 */
function getVendorPrefixedEventName(eventName) {
  if (prefixedEventNames[eventName]) {
    return prefixedEventNames[eventName];
  } else if (!vendorPrefixes[eventName]) {
    return eventName;
  }

  const prefixMap = vendorPrefixes[eventName];

  for (const styleProp in prefixMap) {
    if (prefixMap.hasOwnProperty(styleProp) && styleProp in style) {
      return (prefixedEventNames[eventName] = prefixMap[styleProp]);
    }
  }

  return eventName;
}

export default getVendorPrefixedEventName;

Domain

Subdomains

Dependencies

  • ExecutionEnvironment

Frequently Asked Questions

What does getVendorPrefixedEventName.js do?
getVendorPrefixedEventName.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in getVendorPrefixedEventName.js?
getVendorPrefixedEventName.js defines 2 function(s): getVendorPrefixedEventName, makePrefixMap.
What does getVendorPrefixedEventName.js depend on?
getVendorPrefixedEventName.js imports 1 module(s): ExecutionEnvironment.
What files import getVendorPrefixedEventName.js?
getVendorPrefixedEventName.js is imported by 1 file(s): DOMEventNames.js.
Where is getVendorPrefixedEventName.js in the architecture?
getVendorPrefixedEventName.js is located at packages/react-dom-bindings/src/events/getVendorPrefixedEventName.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-dom-bindings/src/events).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free