src/platforms/web/util/element.ts TYPESCRIPT 77 lines View on github.com → Search inside
1import { inBrowser } from 'core/util/env'2import { makeMap } from 'shared/util'34export const namespaceMap = {5  svg: 'http://www.w3.org/2000/svg',6  math: 'http://www.w3.org/1998/Math/MathML'7}89export const isHTMLTag = makeMap(10  'html,body,base,head,link,meta,style,title,' +11    'address,article,aside,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' +12    'div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,' +13    'a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,' +14    's,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,' +15    'embed,object,param,source,canvas,script,noscript,del,ins,' +16    'caption,col,colgroup,table,thead,tbody,td,th,tr,' +17    'button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,' +18    'output,progress,select,textarea,' +19    'details,dialog,menu,menuitem,summary,' +20    'content,element,shadow,template,blockquote,iframe,tfoot'21)2223// this map is intentionally selective, only covering SVG elements that may24// contain child elements.25export const isSVG = makeMap(26  'svg,animate,circle,clippath,cursor,defs,desc,ellipse,filter,font-face,' +27    'foreignobject,g,glyph,image,line,marker,mask,missing-glyph,path,pattern,' +28    'polygon,polyline,rect,switch,symbol,text,textpath,tspan,use,view',29  true30)3132export const isPreTag = (tag?: string): boolean => tag === 'pre'3334export const isReservedTag = (tag: string): boolean | undefined => {35  return isHTMLTag(tag) || isSVG(tag)36}3738export function getTagNamespace(tag: string): string | undefined {39  if (isSVG(tag)) {40    return 'svg'41  }42  // basic support for MathML43  // note it doesn't support other MathML elements being component roots44  if (tag === 'math') {45    return 'math'46  }47}4849const unknownElementCache = Object.create(null)50export function isUnknownElement(tag: string): boolean {51  /* istanbul ignore if */52  if (!inBrowser) {53    return true54  }55  if (isReservedTag(tag)) {56    return false57  }58  tag = tag.toLowerCase()59  /* istanbul ignore if */60  if (unknownElementCache[tag] != null) {61    return unknownElementCache[tag]62  }63  const el = document.createElement(tag)64  if (tag.indexOf('-') > -1) {65    // https://stackoverflow.com/a/28210364/107024466    return (unknownElementCache[tag] =67      el.constructor === window.HTMLUnknownElement ||68      el.constructor === window.HTMLElement)69  } else {70    return (unknownElementCache[tag] = /HTMLUnknownElement/.test(el.toString()))71  }72}7374export const isTextInputType = makeMap(75  'text,number,password,search,email,tel,url'76)

Findings

✓ No findings reported for this file.

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.