2020-01-28 23:48:27 +00:00
|
|
|
import { makeMap } from './makeMap'
|
|
|
|
|
2020-05-07 14:32:13 +00:00
|
|
|
/**
|
|
|
|
* On the client we only need to offer special cases for boolean attributes that
|
|
|
|
* have different names from their corresponding dom properties:
|
|
|
|
* - itemscope -> N/A
|
|
|
|
* - allowfullscreen -> allowFullscreen
|
|
|
|
* - formnovalidate -> formNoValidate
|
|
|
|
* - ismap -> isMap
|
|
|
|
* - nomodule -> noModule
|
|
|
|
* - novalidate -> noValidate
|
|
|
|
* - readonly -> readOnly
|
|
|
|
*/
|
2020-01-29 03:03:53 +00:00
|
|
|
const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`
|
|
|
|
export const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs)
|
|
|
|
|
2020-05-07 14:32:13 +00:00
|
|
|
/**
|
|
|
|
* The full list is needed during SSR to produce the correct initial markup.
|
|
|
|
*/
|
2020-01-29 03:03:53 +00:00
|
|
|
export const isBooleanAttr = /*#__PURE__*/ makeMap(
|
|
|
|
specialBooleanAttrs +
|
2020-01-29 20:10:45 +00:00
|
|
|
`,async,autofocus,autoplay,controls,default,defer,disabled,hidden,` +
|
|
|
|
`loop,open,required,reversed,scoped,seamless,` +
|
2020-01-29 03:03:53 +00:00
|
|
|
`checked,muted,multiple,selected`
|
2020-01-28 23:48:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const unsafeAttrCharRE = /[>/="'\u0009\u000a\u000c\u0020]/
|
|
|
|
const attrValidationCache: Record<string, boolean> = {}
|
|
|
|
|
|
|
|
export function isSSRSafeAttrName(name: string): boolean {
|
|
|
|
if (attrValidationCache.hasOwnProperty(name)) {
|
|
|
|
return attrValidationCache[name]
|
|
|
|
}
|
|
|
|
const isUnsafe = unsafeAttrCharRE.test(name)
|
|
|
|
if (isUnsafe) {
|
|
|
|
console.error(`unsafe attribute name: ${name}`)
|
|
|
|
}
|
|
|
|
return (attrValidationCache[name] = !isUnsafe)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const propsToAttrMap: Record<string, string | undefined> = {
|
|
|
|
acceptCharset: 'accept-charset',
|
|
|
|
className: 'class',
|
|
|
|
htmlFor: 'for',
|
|
|
|
httpEquiv: 'http-equiv'
|
|
|
|
}
|
|
|
|
|
2020-05-07 14:32:13 +00:00
|
|
|
/**
|
|
|
|
* CSS properties that accept plain numbers
|
|
|
|
*/
|
2020-01-29 03:03:53 +00:00
|
|
|
export const isNoUnitNumericStyleProp = /*#__PURE__*/ makeMap(
|
2020-01-28 23:48:27 +00:00
|
|
|
`animation-iteration-count,border-image-outset,border-image-slice,` +
|
|
|
|
`border-image-width,box-flex,box-flex-group,box-ordinal-group,column-count,` +
|
|
|
|
`columns,flex,flex-grow,flex-positive,flex-shrink,flex-negative,flex-order,` +
|
|
|
|
`grid-row,grid-row-end,grid-row-span,grid-row-start,grid-column,` +
|
|
|
|
`grid-column-end,grid-column-span,grid-column-start,font-weight,line-clamp,` +
|
|
|
|
`line-height,opacity,order,orphans,tab-size,widows,z-index,zoom,` +
|
|
|
|
// SVG
|
|
|
|
`fill-opacity,flood-opacity,stop-opacity,stroke-dasharray,stroke-dashoffset,` +
|
|
|
|
`stroke-miterlimit,stroke-opacity,stroke-width`
|
|
|
|
)
|
2020-05-07 14:32:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Known attributes, this is used for stringification of runtime static nodes
|
|
|
|
* so that we don't stringify bindings that cannot be set from HTML.
|
|
|
|
* Don't also forget to allow `data-*` and `aria-*`!
|
|
|
|
* Generated from https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
|
|
|
|
*/
|
|
|
|
export const isKnownAttr = /*#__PURE__*/ makeMap(
|
|
|
|
`accept,accept-charset,accesskey,action,align,allow,alt,async,` +
|
|
|
|
`autocapitalize,autocomplete,autofocus,autoplay,background,bgcolor,` +
|
|
|
|
`border,buffered,capture,challenge,charset,checked,cite,class,code,` +
|
|
|
|
`codebase,color,cols,colspan,content,contenteditable,contextmenu,controls,` +
|
|
|
|
`coords,crossorigin,csp,data,datetime,decoding,default,defer,dir,dirname,` +
|
|
|
|
`disabled,download,draggable,dropzone,enctype,enterkeyhint,for,form,` +
|
|
|
|
`formaction,formenctype,formmethod,formnovalidate,formtarget,headers,` +
|
|
|
|
`height,hidden,high,href,hreflang,http-equiv,icon,id,importance,integrity,` +
|
|
|
|
`ismap,itemprop,keytype,kind,label,lang,language,loading,list,loop,low,` +
|
|
|
|
`manifest,max,maxlength,minlength,media,min,multiple,muted,name,novalidate,` +
|
|
|
|
`open,optimum,pattern,ping,placeholder,poster,preload,radiogroup,readonly,` +
|
|
|
|
`referrerpolicy,rel,required,reversed,rows,rowspan,sandbox,scope,scoped,` +
|
|
|
|
`selected,shape,size,sizes,slot,span,spellcheck,src,srcdoc,srclang,srcset,` +
|
|
|
|
`start,step,style,summary,tabindex,target,title,translate,type,usemap,` +
|
|
|
|
`value,width,wrap`
|
|
|
|
)
|