mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
export const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
|
|
export const MATH_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
|
|
export const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
|
|
|
|
// Assumes there is no parent namespace.
|
|
export function getIntrinsicNamespace(type: string): string {
|
|
switch (type) {
|
|
case 'svg':
|
|
return SVG_NAMESPACE;
|
|
case 'math':
|
|
return MATH_NAMESPACE;
|
|
default:
|
|
return HTML_NAMESPACE;
|
|
}
|
|
}
|
|
|
|
export function getChildNamespace(
|
|
parentNamespace: string | null,
|
|
type: string,
|
|
): string {
|
|
if (parentNamespace == null || parentNamespace === HTML_NAMESPACE) {
|
|
// No (or default) parent namespace: potential entry point.
|
|
return getIntrinsicNamespace(type);
|
|
}
|
|
if (parentNamespace === SVG_NAMESPACE && type === 'foreignObject') {
|
|
// We're leaving SVG.
|
|
return HTML_NAMESPACE;
|
|
}
|
|
// By default, pass namespace below.
|
|
return parentNamespace;
|
|
}
|