html-react-parser 0.4.3 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +81 -90
- package/dist/html-react-parser.js +144 -2222
- package/dist/html-react-parser.min.js +1 -1
- package/index.js +5 -10
- package/lib/attributes-to-props.js +53 -59
- package/lib/dom-to-react.js +60 -75
- package/lib/property-config.js +16 -28
- package/lib/utilities.js +39 -38
- package/package.json +23 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.HTMLReactParser=t(require("react")):e.HTMLReactParser=t(e.React)}("undefined"!=typeof self?self:this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=3)}([function(e,t,r){"use strict";function n(e){if("string"!=typeof e)throw new TypeError("First argument must be a string");return e.indexOf("-")<0?e:e.toLowerCase().replace(o,function(e,t){return t.toUpperCase()})}function i(e,t){if("object"!=typeof e||!e)throw new TypeError("First argument must be an object");var r,n,i="function"==typeof t,o={},a={};for(r in e)n=e[r],i&&(o=t(r,n))&&2===o.length?a[o[0]]=o[1]:"string"==typeof n&&(a[n]=r);return a}var o=/-(.)/g;e.exports={camelCase:n,invertObject:i}},function(e,t,r){"use strict";function n(e,t){return(e&t)===t}var i=r(9),o=(r(10),{MUST_USE_PROPERTY:1,HAS_BOOLEAN_VALUE:4,HAS_NUMERIC_VALUE:8,HAS_POSITIVE_NUMERIC_VALUE:24,HAS_OVERLOADED_BOOLEAN_VALUE:32,injectDOMPropertyConfig:function(e){var t=o,r=e.Properties||{},a=e.DOMAttributeNamespaces||{},l=e.DOMAttributeNames||{},u=e.DOMPropertyNames||{},c=e.DOMMutationMethods||{};e.isCustomAttribute&&s._isCustomAttributeFunctions.push(e.isCustomAttribute);for(var p in r){s.properties.hasOwnProperty(p)&&i("48",p);var f=p.toLowerCase(),m=r[p],d={attributeName:f,attributeNamespace:null,propertyName:p,mutationMethod:null,mustUseProperty:n(m,t.MUST_USE_PROPERTY),hasBooleanValue:n(m,t.HAS_BOOLEAN_VALUE),hasNumericValue:n(m,t.HAS_NUMERIC_VALUE),hasPositiveNumericValue:n(m,t.HAS_POSITIVE_NUMERIC_VALUE),hasOverloadedBooleanValue:n(m,t.HAS_OVERLOADED_BOOLEAN_VALUE)};if(d.hasBooleanValue+d.hasNumericValue+d.hasOverloadedBooleanValue<=1||i("50",p),l.hasOwnProperty(p)){var h=l[p];d.attributeName=h}a.hasOwnProperty(p)&&(d.attributeNamespace=a[p]),u.hasOwnProperty(p)&&(d.propertyName=u[p]),c.hasOwnProperty(p)&&(d.mutationMethod=c[p]),s.properties[p]=d}}}),a=":A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",s={ID_ATTRIBUTE_NAME:"data-reactid",ROOT_ATTRIBUTE_NAME:"data-reactroot",ATTRIBUTE_NAME_START_CHAR:a,ATTRIBUTE_NAME_CHAR:a+"\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040",properties:{},getPossibleStandardName:null,_isCustomAttributeFunctions:[],isCustomAttribute:function(e){for(var t=0;t<s._isCustomAttributeFunctions.length;t++){if((0,s._isCustomAttributeFunctions[t])(e))return!0}return!1},injection:o};e.exports=s},function(e,t,r){"use strict";function n(e){for(var t,r={},n=0,i=e.length;n<i;n++)t=e[n],r[t.name]=t.value;return r}function i(e,t,r){t=t||null;for(var o,a,s,l=[],u=0,c=e.length;u<c;u++){switch(o=e[u],s={next:null,prev:l[u-1]||null,parent:t},a=l[u-1],a&&(a.next=s),0!==o.nodeName.indexOf("#")&&(s.name=o.nodeName.toLowerCase(),s.attribs={},o.attributes&&o.attributes.length&&(s.attribs=n(o.attributes))),o.nodeType){case 1:"script"===s.name||"style"===s.name?s.type=s.name:s.type="tag",s.children=i(o.childNodes,s);break;case 3:s.type="text",s.data=o.nodeValue;break;case 8:s.type="comment",s.data=o.nodeValue}l.push(s)}return r&&(l.unshift({name:r.substring(0,r.indexOf(" ")).toLowerCase(),data:r,type:"directive",next:l[0]?l[0]:null,prev:null,parent:t}),l[1]&&(l[1].prev=l[0])),l}function o(e){return e?document.documentMode===e:/(MSIE |Trident\/|Edge\/)/.test(navigator.userAgent)}e.exports={formatAttributes:n,formatDOM:i,isIE:o}},function(e,t,r){"use strict";function n(e,t){if("string"!=typeof e)throw new TypeError("First argument must be a string");return i(o(e,a),t)}var i=r(4),o=r(14),a={decodeEntities:!0};e.exports=n},function(e,t,r){"use strict";function n(e,t){t=t||{};for(var r,a,s,l,u=[],c="function"==typeof t.replace,p=0,f=e.length;p<f;p++)if(r=e[p],c&&(a=t.replace(r),i.isValidElement(a)))f>1&&(a=i.cloneElement(a,{key:p})),u.push(a);else if("text"!==r.type){if(s=o(r.attribs),l=null,"script"===r.type||"style"===r.type)r.children[0]&&(s.dangerouslySetInnerHTML={__html:r.children[0].data});else{if("tag"!==r.type)continue;"textarea"===r.name&&r.children[0]?s.defaultValue=r.children[0].data:r.children&&r.children.length&&(l=n(r.children,t))}f>1&&(s.key=p),u.push(i.createElement(r.name,s,l))}else u.push(r.data);return 1===u.length?u[0]:u}var i=r(5),o=r(6);e.exports=n},function(t,r){t.exports=e},function(e,t,r){"use strict";function n(e){e=e||{};var t,r,n,o={};for(t in e)r=e[t],u(t)?o[t]=r:(n=l.html[t.toLowerCase()],n?c.properties.hasOwnProperty(n)&&c.properties[n].hasBooleanValue?o[n]=!0:o[n]=r:(n=l.svg[t])&&(o[n]=r));return null!=e.style&&(o.style=i(e.style)),o}function i(e){if("string"!=typeof e)throw new Error("`cssToJs`: first argument must be a string. ");var t={};return s(e,function(e,r){e&&r&&(t[o.camelCase(e)]=r)}),t}var o=r(0),a=r(7),s=r(12),l=a.config,u=a.HTMLDOMPropertyConfig.isCustomAttribute,c=r(1);c.injection.injectDOMPropertyConfig(a.HTMLDOMPropertyConfig),e.exports=n},function(e,t,r){"use strict";var n,i=r(0),o=r(8),a=r(11),s={html:{},svg:{}};s.html=i.invertObject(o.DOMAttributeNames);for(n in o.Properties)s.html[n.toLowerCase()]=n;s.svg=i.invertObject(a.DOMAttributeNames);for(n in a.Properties)s.html[n]=n;e.exports={config:s,HTMLDOMPropertyConfig:o,SVGDOMPropertyConfig:a}},function(e,t,r){"use strict";var n=r(1),i=n.injection.MUST_USE_PROPERTY,o=n.injection.HAS_BOOLEAN_VALUE,a=n.injection.HAS_NUMERIC_VALUE,s=n.injection.HAS_POSITIVE_NUMERIC_VALUE,l=n.injection.HAS_OVERLOADED_BOOLEAN_VALUE,u={isCustomAttribute:RegExp.prototype.test.bind(new RegExp("^(data|aria)-["+n.ATTRIBUTE_NAME_CHAR+"]*$")),Properties:{accept:0,acceptCharset:0,accessKey:0,action:0,allowFullScreen:o,allowTransparency:0,alt:0,as:0,async:o,autoComplete:0,autoPlay:o,capture:o,cellPadding:0,cellSpacing:0,charSet:0,challenge:0,checked:i|o,cite:0,classID:0,className:0,cols:s,colSpan:0,content:0,contentEditable:0,contextMenu:0,controls:o,controlsList:0,coords:0,crossOrigin:0,data:0,dateTime:0,default:o,defer:o,dir:0,disabled:o,download:l,draggable:0,encType:0,form:0,formAction:0,formEncType:0,formMethod:0,formNoValidate:o,formTarget:0,frameBorder:0,headers:0,height:0,hidden:o,high:0,href:0,hrefLang:0,htmlFor:0,httpEquiv:0,icon:0,id:0,inputMode:0,integrity:0,is:0,keyParams:0,keyType:0,kind:0,label:0,lang:0,list:0,loop:o,low:0,manifest:0,marginHeight:0,marginWidth:0,max:0,maxLength:0,media:0,mediaGroup:0,method:0,min:0,minLength:0,multiple:i|o,muted:i|o,name:0,nonce:0,noValidate:o,open:o,optimum:0,pattern:0,placeholder:0,playsInline:o,poster:0,preload:0,profile:0,radioGroup:0,readOnly:o,referrerPolicy:0,rel:0,required:o,reversed:o,role:0,rows:s,rowSpan:a,sandbox:0,scope:0,scoped:o,scrolling:0,seamless:o,selected:i|o,shape:0,size:s,sizes:0,span:s,spellCheck:0,src:0,srcDoc:0,srcLang:0,srcSet:0,start:a,step:0,style:0,summary:0,tabIndex:0,target:0,title:0,type:0,useMap:0,value:0,width:0,wmode:0,wrap:0,about:0,datatype:0,inlist:0,prefix:0,property:0,resource:0,typeof:0,vocab:0,autoCapitalize:0,autoCorrect:0,autoSave:0,color:0,itemProp:0,itemScope:o,itemType:0,itemID:0,itemRef:0,results:0,security:0,unselectable:0},DOMAttributeNames:{acceptCharset:"accept-charset",className:"class",htmlFor:"for",httpEquiv:"http-equiv"},DOMPropertyNames:{},DOMMutationMethods:{value:function(e,t){if(null==t)return e.removeAttribute("value");"number"!==e.type||!1===e.hasAttribute("value")?e.setAttribute("value",""+t):e.validity&&!e.validity.badInput&&e.ownerDocument.activeElement!==e&&e.setAttribute("value",""+t)}}};e.exports=u},function(e,t,r){"use strict";function n(e){for(var t=arguments.length-1,r="Minified React error #"+e+"; visit http://facebook.github.io/react/docs/error-decoder.html?invariant="+e,n=0;n<t;n++)r+="&args[]="+encodeURIComponent(arguments[n+1]);r+=" for the full message or use the non-minified dev environment for full errors and additional helpful warnings.";var i=new Error(r);throw i.name="Invariant Violation",i.framesToPop=1,i}e.exports=n},function(e,t,r){"use strict";function n(e,t,r,n,o,a,s,l){if(i(t),!e){var u;if(void 0===t)u=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[r,n,o,a,s,l],p=0;u=new Error(t.replace(/%s/g,function(){return c[p++]})),u.name="Invariant Violation"}throw u.framesToPop=1,u}}var i=function(e){};e.exports=n},function(e,t,r){"use strict";var n={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"},i={accentHeight:"accent-height",accumulate:0,additive:0,alignmentBaseline:"alignment-baseline",allowReorder:"allowReorder",alphabetic:0,amplitude:0,arabicForm:"arabic-form",ascent:0,attributeName:"attributeName",attributeType:"attributeType",autoReverse:"autoReverse",azimuth:0,baseFrequency:"baseFrequency",baseProfile:"baseProfile",baselineShift:"baseline-shift",bbox:0,begin:0,bias:0,by:0,calcMode:"calcMode",capHeight:"cap-height",clip:0,clipPath:"clip-path",clipRule:"clip-rule",clipPathUnits:"clipPathUnits",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",contentScriptType:"contentScriptType",contentStyleType:"contentStyleType",cursor:0,cx:0,cy:0,d:0,decelerate:0,descent:0,diffuseConstant:"diffuseConstant",direction:0,display:0,divisor:0,dominantBaseline:"dominant-baseline",dur:0,dx:0,dy:0,edgeMode:"edgeMode",elevation:0,enableBackground:"enable-background",end:0,exponent:0,externalResourcesRequired:"externalResourcesRequired",fill:0,fillOpacity:"fill-opacity",fillRule:"fill-rule",filter:0,filterRes:"filterRes",filterUnits:"filterUnits",floodColor:"flood-color",floodOpacity:"flood-opacity",focusable:0,fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",format:0,from:0,fx:0,fy:0,g1:0,g2:0,glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",glyphRef:"glyphRef",gradientTransform:"gradientTransform",gradientUnits:"gradientUnits",hanging:0,horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",ideographic:0,imageRendering:"image-rendering",in:0,in2:0,intercept:0,k:0,k1:0,k2:0,k3:0,k4:0,kernelMatrix:"kernelMatrix",kernelUnitLength:"kernelUnitLength",kerning:0,keyPoints:"keyPoints",keySplines:"keySplines",keyTimes:"keyTimes",lengthAdjust:"lengthAdjust",letterSpacing:"letter-spacing",lightingColor:"lighting-color",limitingConeAngle:"limitingConeAngle",local:0,markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",markerHeight:"markerHeight",markerUnits:"markerUnits",markerWidth:"markerWidth",mask:0,maskContentUnits:"maskContentUnits",maskUnits:"maskUnits",mathematical:0,mode:0,numOctaves:"numOctaves",offset:0,opacity:0,operator:0,order:0,orient:0,orientation:0,origin:0,overflow:0,overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pathLength:"pathLength",patternContentUnits:"patternContentUnits",patternTransform:"patternTransform",patternUnits:"patternUnits",pointerEvents:"pointer-events",points:0,pointsAtX:"pointsAtX",pointsAtY:"pointsAtY",pointsAtZ:"pointsAtZ",preserveAlpha:"preserveAlpha",preserveAspectRatio:"preserveAspectRatio",primitiveUnits:"primitiveUnits",r:0,radius:0,refX:"refX",refY:"refY",renderingIntent:"rendering-intent",repeatCount:"repeatCount",repeatDur:"repeatDur",requiredExtensions:"requiredExtensions",requiredFeatures:"requiredFeatures",restart:0,result:0,rotate:0,rx:0,ry:0,scale:0,seed:0,shapeRendering:"shape-rendering",slope:0,spacing:0,specularConstant:"specularConstant",specularExponent:"specularExponent",speed:0,spreadMethod:"spreadMethod",startOffset:"startOffset",stdDeviation:"stdDeviation",stemh:0,stemv:0,stitchTiles:"stitchTiles",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",string:0,stroke:0,strokeDasharray:"stroke-dasharray",strokeDashoffset:"stroke-dashoffset",strokeLinecap:"stroke-linecap",strokeLinejoin:"stroke-linejoin",strokeMiterlimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",surfaceScale:"surfaceScale",systemLanguage:"systemLanguage",tableValues:"tableValues",targetX:"targetX",targetY:"targetY",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",textLength:"textLength",to:0,transform:0,u1:0,u2:0,underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicode:0,unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",values:0,vectorEffect:"vector-effect",version:0,vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",viewBox:"viewBox",viewTarget:"viewTarget",visibility:0,widths:0,wordSpacing:"word-spacing",writingMode:"writing-mode",x:0,xHeight:"x-height",x1:0,x2:0,xChannelSelector:"xChannelSelector",xlinkActuate:"xlink:actuate",xlinkArcrole:"xlink:arcrole",xlinkHref:"xlink:href",xlinkRole:"xlink:role",xlinkShow:"xlink:show",xlinkTitle:"xlink:title",xlinkType:"xlink:type",xmlBase:"xml:base",xmlns:0,xmlnsXlink:"xmlns:xlink",xmlLang:"xml:lang",xmlSpace:"xml:space",y:0,y1:0,y2:0,yChannelSelector:"yChannelSelector",z:0,zoomAndPan:"zoomAndPan"},o={Properties:{},DOMAttributeNamespaces:{xlinkActuate:n.xlink,xlinkArcrole:n.xlink,xlinkHref:n.xlink,xlinkRole:n.xlink,xlinkShow:n.xlink,xlinkTitle:n.xlink,xlinkType:n.xlink,xmlBase:n.xml,xmlLang:n.xml,xmlSpace:n.xml},DOMAttributeNames:{}};Object.keys(i).forEach(function(e){o.Properties[e]=0,i[e]&&(o.DOMAttributeNames[e]=i[e])}),e.exports=o},function(e,t,r){var n=r(13);e.exports=function(e,t){if(!e||"string"!=typeof e)return null;for(var r,i,o,a=n("p{"+e+"}").stylesheet.rules[0].declarations,s=null,l="function"==typeof t,u=0,c=a.length;u<c;u++)r=a[u],i=r.property,o=r.value,l?t(i,o,r):o&&(s||(s={}),s[i]=o);return s}},function(e,t){function r(e){return e?e.replace(/^\s+|\s+$/g,""):""}function n(e,t){var r=e&&"string"==typeof e.type,i=r?e:t;for(var o in e){var a=e[o];Array.isArray(a)?a.forEach(function(e){n(e,i)}):a&&"object"==typeof a&&n(a,i)}return r&&Object.defineProperty(e,"parent",{configurable:!0,writable:!0,enumerable:!1,value:t||null}),e}var i=/\/\*[^*]*\*+([^\/*][^*]*\*+)*\//g;e.exports=function(e,t){function o(e){var t=e.match(/\n/g);t&&(S+=t.length);var r=e.lastIndexOf("\n");_=~r?e.length-r:_+e.length}function a(){var e={line:S,column:_};return function(t){return t.position=new s(e),m(),t}}function s(e){this.start=e,this.end={line:S,column:_},this.source=t.source}function l(r){var n=new Error(t.source+":"+S+":"+_+": "+r);if(n.reason=r,n.filename=t.source,n.line=S,n.column=_,n.source=e,!t.silent)throw n;R.push(n)}function u(){return f(/^{\s*/)}function c(){return f(/^}/)}function p(){var t,r=[];for(m(),d(r);e.length&&"}"!=e.charAt(0)&&(t=N()||P());)!1!==t&&(r.push(t),d(r));return r}function f(t){var r=t.exec(e);if(r){var n=r[0];return o(n),e=e.slice(n.length),r}}function m(){f(/^\s*/)}function d(e){var t;for(e=e||[];t=h();)!1!==t&&e.push(t);return e}function h(){var t=a();if("/"==e.charAt(0)&&"*"==e.charAt(1)){for(var r=2;""!=e.charAt(r)&&("*"!=e.charAt(r)||"/"!=e.charAt(r+1));)++r;if(r+=2,""===e.charAt(r-1))return l("End of comment missing");var n=e.slice(2,r-2);return _+=2,o(n),e=e.slice(r),_+=2,t({type:"comment",comment:n})}}function g(){var e=f(/^([^{]+)/);if(e)return r(e[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*\/+/g,"").replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g,function(e){return e.replace(/,/g,"")}).split(/\s*(?![^(]*\)),\s*/).map(function(e){return e.replace(/\u200C/g,",")})}function y(){var e=a(),t=f(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);if(t){if(t=r(t[0]),!f(/^:\s*/))return l("property missing ':'");var n=f(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/),o=e({type:"declaration",property:t.replace(i,""),value:n?r(n[0]).replace(i,""):""});return f(/^[;\s]*/),o}}function v(){var e=[];if(!u())return l("missing '{'");d(e);for(var t;t=y();)!1!==t&&(e.push(t),d(e));return c()?e:l("missing '}'")}function x(){for(var e,t=[],r=a();e=f(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/);)t.push(e[1]),f(/^,\s*/);if(t.length)return r({type:"keyframe",values:t,declarations:v()})}function b(){var e=a(),t=f(/^@([-\w]+)?keyframes\s*/);if(t){var r=t[1],t=f(/^([-\w]+)\s*/);if(!t)return l("@keyframes missing name");var n=t[1];if(!u())return l("@keyframes missing '{'");for(var i,o=d();i=x();)o.push(i),o=o.concat(d());return c()?e({type:"keyframes",name:n,vendor:r,keyframes:o}):l("@keyframes missing '}'")}}function k(){var e=a(),t=f(/^@supports *([^{]+)/);if(t){var n=r(t[1]);if(!u())return l("@supports missing '{'");var i=d().concat(p());return c()?e({type:"supports",supports:n,rules:i}):l("@supports missing '}'")}}function A(){var e=a();if(f(/^@host\s*/)){if(!u())return l("@host missing '{'");var t=d().concat(p());return c()?e({type:"host",rules:t}):l("@host missing '}'")}}function E(){var e=a(),t=f(/^@media *([^{]+)/);if(t){var n=r(t[1]);if(!u())return l("@media missing '{'");var i=d().concat(p());return c()?e({type:"media",media:n,rules:i}):l("@media missing '}'")}}function T(){var e=a(),t=f(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);if(t)return e({type:"custom-media",name:r(t[1]),media:r(t[2])})}function O(){var e=a();if(f(/^@page */)){var t=g()||[];if(!u())return l("@page missing '{'");for(var r,n=d();r=y();)n.push(r),n=n.concat(d());return c()?e({type:"page",selectors:t,declarations:n}):l("@page missing '}'")}}function w(){var e=a(),t=f(/^@([-\w]+)?document *([^{]+)/);if(t){var n=r(t[1]),i=r(t[2]);if(!u())return l("@document missing '{'");var o=d().concat(p());return c()?e({type:"document",document:i,vendor:n,rules:o}):l("@document missing '}'")}}function M(){var e=a();if(f(/^@font-face\s*/)){if(!u())return l("@font-face missing '{'");for(var t,r=d();t=y();)r.push(t),r=r.concat(d());return c()?e({type:"font-face",declarations:r}):l("@font-face missing '}'")}}function C(e){var t=new RegExp("^@"+e+"\\s*([^;]+);");return function(){var r=a(),n=f(t);if(n){var i={type:e};return i[e]=n[1].trim(),r(i)}}}function N(){if("@"==e[0])return b()||E()||T()||k()||L()||U()||D()||w()||O()||A()||M()}function P(){var e=a(),t=g();return t?(d(),e({type:"rule",selectors:t,declarations:v()})):l("selector missing")}t=t||{};var S=1,_=1;s.prototype.content=e;var R=[],L=C("import"),U=C("charset"),D=C("namespace");return n(function(){return{type:"stylesheet",stylesheet:{rules:p(),parsingErrors:R}}}())}},function(e,t,r){"use strict";var n=r(15),i=r(2),o=i.formatDOM,a=i.isIE(9),s=/<(![a-zA-Z\s]+)>/;e.exports=function(e){if("string"!=typeof e)throw new TypeError("First argument must be a string.");if(!e)return[];var t,r=e.match(s);return r&&r[1]&&(t=r[1],a&&(e=e.replace(r[0],""))),o(n(e),null,t)}},function(e,t,r){"use strict";var n,i=r(2),o=i.isIE,a=/<([a-zA-Z]+[0-9]?)/,s=/<\/head>/i,l=/<\/body>/i,u=/<(area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)(.*?)\/?>/gi,c=o(),p=o(9);if("function"==typeof window.DOMParser){var f=new window.DOMParser,m=p?"text/xml":"text/html";n=function(e,t){return t&&(e=["<",t,">",e,"</",t,">"].join("")),p&&(e=e.replace(u,"<$1$2$3/>")),f.parseFromString(e,m)}}var d;if("object"==typeof document.implementation){var h=document.implementation.createHTMLDocument(c?"HTML_DOM_PARSER_TITLE":void 0);d=function(e,t){if(t)return h.documentElement.getElementsByTagName(t)[0].innerHTML=e,h;try{return h.documentElement.innerHTML=e,h}catch(t){if(n)return n(e)}}}var g,y=document.createElement("template");y.content&&(g=function(e){return y.innerHTML=e,y.content.childNodes});var v=d||n;e.exports=function(e){var t,r=e.match(a);r&&r[1]&&(t=r[1].toLowerCase());var i,o,u;switch(t){case"html":if(n)return i=n(e),s.test(e)||(o=i.getElementsByTagName("head")[0])&&o.parentNode.removeChild(o),l.test(e)||(o=i.getElementsByTagName("body")[0])&&o.parentNode.removeChild(o),i.getElementsByTagName("html");break;case"head":if(v)return u=v(e).getElementsByTagName("head"),l.test(e)?u[0].parentNode.childNodes:u;break;case"body":if(v)return u=v(e).getElementsByTagName("body"),s.test(e)?u[0].parentNode.childNodes:u;break;default:if(g)return g(e);if(v)return v(e,"body").getElementsByTagName("body")[0].childNodes}return[]}}])});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.HTMLReactParser=t(require("react")):e.HTMLReactParser=t(e.React)}(window,function(e){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=3)}([function(e,t,r){"use strict";var n=r(7);r(8);function i(e,t){return(e&t)===t}var o={MUST_USE_PROPERTY:1,HAS_BOOLEAN_VALUE:4,HAS_NUMERIC_VALUE:8,HAS_POSITIVE_NUMERIC_VALUE:24,HAS_OVERLOADED_BOOLEAN_VALUE:32,injectDOMPropertyConfig:function(e){var t=o,r=e.Properties||{},a=e.DOMAttributeNamespaces||{},u=e.DOMAttributeNames||{},l=e.DOMPropertyNames||{},c=e.DOMMutationMethods||{};for(var p in e.isCustomAttribute&&s._isCustomAttributeFunctions.push(e.isCustomAttribute),r){s.properties.hasOwnProperty(p)&&n("48",p);var f=p.toLowerCase(),m=r[p],d={attributeName:f,attributeNamespace:null,propertyName:p,mutationMethod:null,mustUseProperty:i(m,t.MUST_USE_PROPERTY),hasBooleanValue:i(m,t.HAS_BOOLEAN_VALUE),hasNumericValue:i(m,t.HAS_NUMERIC_VALUE),hasPositiveNumericValue:i(m,t.HAS_POSITIVE_NUMERIC_VALUE),hasOverloadedBooleanValue:i(m,t.HAS_OVERLOADED_BOOLEAN_VALUE)};if(d.hasBooleanValue+d.hasNumericValue+d.hasOverloadedBooleanValue<=1||n("50",p),u.hasOwnProperty(p)){var h=u[p];d.attributeName=h}a.hasOwnProperty(p)&&(d.attributeNamespace=a[p]),l.hasOwnProperty(p)&&(d.propertyName=l[p]),c.hasOwnProperty(p)&&(d.mutationMethod=c[p]),s.properties[p]=d}}},a=":A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",s={ID_ATTRIBUTE_NAME:"data-reactid",ROOT_ATTRIBUTE_NAME:"data-reactroot",ATTRIBUTE_NAME_START_CHAR:a,ATTRIBUTE_NAME_CHAR:a+"\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040",properties:{},getPossibleStandardName:null,_isCustomAttributeFunctions:[],isCustomAttribute:function(e){for(var t=0;t<s._isCustomAttributeFunctions.length;t++){if((0,s._isCustomAttributeFunctions[t])(e))return!0}return!1},injection:o};e.exports=s},function(e,t){var r=/-([a-z])/g;e.exports={camelCase:function(e){if("string"!=typeof e)throw new TypeError("First argument must be a string");return-1===e.indexOf("-")?e:e.toLowerCase().replace(r,function(e,t){return t.toUpperCase()})},invertObject:function(e,t){if(!e||"object"!=typeof e)throw new TypeError("First argument must be an object");var r,n,i="function"==typeof t,o={},a={};for(r in e)n=e[r],i&&(o=t(r,n))&&2===o.length?a[o[0]]=o[1]:"string"==typeof n&&(a[n]=r);return a}}},function(e,t,r){"use strict";function n(e){for(var t,r={},n=0,i=e.length;n<i;n++)r[(t=e[n]).name]=t.value;return r}e.exports={formatAttributes:n,formatDOM:function e(t,r,i){r=r||null;for(var o,a,s,u=[],l=0,c=t.length;l<c;l++){switch(o=t[l],s={next:null,prev:u[l-1]||null,parent:r},(a=u[l-1])&&(a.next=s),0!==o.nodeName.indexOf("#")&&(s.name=o.nodeName.toLowerCase(),s.attribs={},o.attributes&&o.attributes.length&&(s.attribs=n(o.attributes))),o.nodeType){case 1:"script"===s.name||"style"===s.name?s.type=s.name:s.type="tag",s.children=e(o.childNodes,s);break;case 3:s.type="text",s.data=o.nodeValue;break;case 8:s.type="comment",s.data=o.nodeValue}u.push(s)}return i&&(u.unshift({name:i.substring(0,i.indexOf(" ")).toLowerCase(),data:i,type:"directive",next:u[0]?u[0]:null,prev:null,parent:r}),u[1]&&(u[1].prev=u[0])),u},isIE:function(e){return e?document.documentMode===e:/(MSIE |Trident\/|Edge\/)/.test(navigator.userAgent)}}},function(e,t,r){var n=r(4),i=r(14),o={decodeEntities:!0,lowerCaseAttributeNames:!1};e.exports=function(e,t){if("string"!=typeof e)throw new TypeError("First argument must be a string");return n(i(e,o),t)}},function(e,t,r){var n=r(5),i=r(6);e.exports=function e(t,r){for(var o,a,s,u,l=[],c="function"==typeof(r=r||{}).replace,p=0,f=t.length;p<f;p++)if(o=t[p],c&&(a=r.replace(o),n.isValidElement(a)))f>1&&(a=n.cloneElement(a,{key:p})),l.push(a);else if("text"!==o.type){if(s=i(o.attribs),u=null,"script"===o.type||"style"===o.type)o.children[0]&&(s.dangerouslySetInnerHTML={__html:o.children[0].data});else{if("tag"!==o.type)continue;"textarea"===o.name&&o.children[0]?s.defaultValue=o.children[0].data:o.children&&o.children.length&&(u=e(o.children,r))}f>1&&(s.key=p),l.push(n.createElement(o.name,s,u))}else l.push(o.data);return 1===l.length?l[0]:l}},function(t,r){t.exports=e},function(e,t,r){var n=r(0),i=r(9),o=r(12),a=r(1),s=i.config,u=i.HTMLDOMPropertyConfig.isCustomAttribute;n.injection.injectDOMPropertyConfig(i.HTMLDOMPropertyConfig),e.exports=function(e){e=e||{};var t,r,i,l={};for(t in e)r=e[t],u(t)?l[t]=r:(i=s.html[t.toLowerCase()])?n.properties.hasOwnProperty(i)&&n.properties[i].hasBooleanValue?l[i]=!0:l[i]=r:(i=s.svg[t])&&(l[i]=r);return null!=e.style&&(l.style=function(e){if("string"!=typeof e)throw new TypeError("First argument must be a string.");var t={};return o(e,function(e,r){e&&r&&(t[a.camelCase(e)]=r)}),t}(e.style)),l}},function(e,t,r){"use strict";e.exports=function(e){for(var t=arguments.length-1,r="Minified React error #"+e+"; visit http://facebook.github.io/react/docs/error-decoder.html?invariant="+e,n=0;n<t;n++)r+="&args[]="+encodeURIComponent(arguments[n+1]);r+=" for the full message or use the non-minified dev environment for full errors and additional helpful warnings.";var i=new Error(r);throw i.name="Invariant Violation",i.framesToPop=1,i}},function(e,t,r){"use strict";var n=function(e){};e.exports=function(e,t,r,i,o,a,s,u){if(n(t),!e){var l;if(void 0===t)l=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[r,i,o,a,s,u],p=0;(l=new Error(t.replace(/%s/g,function(){return c[p++]}))).name="Invariant Violation"}throw l.framesToPop=1,l}}},function(e,t,r){var n,i=r(10),o=r(11),a=r(1),s={html:{},svg:{}};for(n in s.html=a.invertObject(i.DOMAttributeNames),i.Properties)s.html[n.toLowerCase()]=n;for(n in s.svg=a.invertObject(o.DOMAttributeNames),o.Properties)s.html[n]=n;e.exports={config:s,HTMLDOMPropertyConfig:i,SVGDOMPropertyConfig:o}},function(e,t,r){"use strict";var n=r(0),i=n.injection.MUST_USE_PROPERTY,o=n.injection.HAS_BOOLEAN_VALUE,a=n.injection.HAS_NUMERIC_VALUE,s=n.injection.HAS_POSITIVE_NUMERIC_VALUE,u=n.injection.HAS_OVERLOADED_BOOLEAN_VALUE,l={isCustomAttribute:RegExp.prototype.test.bind(new RegExp("^(data|aria)-["+n.ATTRIBUTE_NAME_CHAR+"]*$")),Properties:{accept:0,acceptCharset:0,accessKey:0,action:0,allowFullScreen:o,allowTransparency:0,alt:0,as:0,async:o,autoComplete:0,autoPlay:o,capture:o,cellPadding:0,cellSpacing:0,charSet:0,challenge:0,checked:i|o,cite:0,classID:0,className:0,cols:s,colSpan:0,content:0,contentEditable:0,contextMenu:0,controls:o,controlsList:0,coords:0,crossOrigin:0,data:0,dateTime:0,default:o,defer:o,dir:0,disabled:o,download:u,draggable:0,encType:0,form:0,formAction:0,formEncType:0,formMethod:0,formNoValidate:o,formTarget:0,frameBorder:0,headers:0,height:0,hidden:o,high:0,href:0,hrefLang:0,htmlFor:0,httpEquiv:0,icon:0,id:0,inputMode:0,integrity:0,is:0,keyParams:0,keyType:0,kind:0,label:0,lang:0,list:0,loop:o,low:0,manifest:0,marginHeight:0,marginWidth:0,max:0,maxLength:0,media:0,mediaGroup:0,method:0,min:0,minLength:0,multiple:i|o,muted:i|o,name:0,nonce:0,noValidate:o,open:o,optimum:0,pattern:0,placeholder:0,playsInline:o,poster:0,preload:0,profile:0,radioGroup:0,readOnly:o,referrerPolicy:0,rel:0,required:o,reversed:o,role:0,rows:s,rowSpan:a,sandbox:0,scope:0,scoped:o,scrolling:0,seamless:o,selected:i|o,shape:0,size:s,sizes:0,span:s,spellCheck:0,src:0,srcDoc:0,srcLang:0,srcSet:0,start:a,step:0,style:0,summary:0,tabIndex:0,target:0,title:0,type:0,useMap:0,value:0,width:0,wmode:0,wrap:0,about:0,datatype:0,inlist:0,prefix:0,property:0,resource:0,typeof:0,vocab:0,autoCapitalize:0,autoCorrect:0,autoSave:0,color:0,itemProp:0,itemScope:o,itemType:0,itemID:0,itemRef:0,results:0,security:0,unselectable:0},DOMAttributeNames:{acceptCharset:"accept-charset",className:"class",htmlFor:"for",httpEquiv:"http-equiv"},DOMPropertyNames:{},DOMMutationMethods:{value:function(e,t){if(null==t)return e.removeAttribute("value");"number"!==e.type||!1===e.hasAttribute("value")?e.setAttribute("value",""+t):e.validity&&!e.validity.badInput&&e.ownerDocument.activeElement!==e&&e.setAttribute("value",""+t)}}};e.exports=l},function(e,t,r){"use strict";var n="http://www.w3.org/1999/xlink",i="http://www.w3.org/XML/1998/namespace",o={accentHeight:"accent-height",accumulate:0,additive:0,alignmentBaseline:"alignment-baseline",allowReorder:"allowReorder",alphabetic:0,amplitude:0,arabicForm:"arabic-form",ascent:0,attributeName:"attributeName",attributeType:"attributeType",autoReverse:"autoReverse",azimuth:0,baseFrequency:"baseFrequency",baseProfile:"baseProfile",baselineShift:"baseline-shift",bbox:0,begin:0,bias:0,by:0,calcMode:"calcMode",capHeight:"cap-height",clip:0,clipPath:"clip-path",clipRule:"clip-rule",clipPathUnits:"clipPathUnits",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",contentScriptType:"contentScriptType",contentStyleType:"contentStyleType",cursor:0,cx:0,cy:0,d:0,decelerate:0,descent:0,diffuseConstant:"diffuseConstant",direction:0,display:0,divisor:0,dominantBaseline:"dominant-baseline",dur:0,dx:0,dy:0,edgeMode:"edgeMode",elevation:0,enableBackground:"enable-background",end:0,exponent:0,externalResourcesRequired:"externalResourcesRequired",fill:0,fillOpacity:"fill-opacity",fillRule:"fill-rule",filter:0,filterRes:"filterRes",filterUnits:"filterUnits",floodColor:"flood-color",floodOpacity:"flood-opacity",focusable:0,fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",format:0,from:0,fx:0,fy:0,g1:0,g2:0,glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",glyphRef:"glyphRef",gradientTransform:"gradientTransform",gradientUnits:"gradientUnits",hanging:0,horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",ideographic:0,imageRendering:"image-rendering",in:0,in2:0,intercept:0,k:0,k1:0,k2:0,k3:0,k4:0,kernelMatrix:"kernelMatrix",kernelUnitLength:"kernelUnitLength",kerning:0,keyPoints:"keyPoints",keySplines:"keySplines",keyTimes:"keyTimes",lengthAdjust:"lengthAdjust",letterSpacing:"letter-spacing",lightingColor:"lighting-color",limitingConeAngle:"limitingConeAngle",local:0,markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",markerHeight:"markerHeight",markerUnits:"markerUnits",markerWidth:"markerWidth",mask:0,maskContentUnits:"maskContentUnits",maskUnits:"maskUnits",mathematical:0,mode:0,numOctaves:"numOctaves",offset:0,opacity:0,operator:0,order:0,orient:0,orientation:0,origin:0,overflow:0,overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pathLength:"pathLength",patternContentUnits:"patternContentUnits",patternTransform:"patternTransform",patternUnits:"patternUnits",pointerEvents:"pointer-events",points:0,pointsAtX:"pointsAtX",pointsAtY:"pointsAtY",pointsAtZ:"pointsAtZ",preserveAlpha:"preserveAlpha",preserveAspectRatio:"preserveAspectRatio",primitiveUnits:"primitiveUnits",r:0,radius:0,refX:"refX",refY:"refY",renderingIntent:"rendering-intent",repeatCount:"repeatCount",repeatDur:"repeatDur",requiredExtensions:"requiredExtensions",requiredFeatures:"requiredFeatures",restart:0,result:0,rotate:0,rx:0,ry:0,scale:0,seed:0,shapeRendering:"shape-rendering",slope:0,spacing:0,specularConstant:"specularConstant",specularExponent:"specularExponent",speed:0,spreadMethod:"spreadMethod",startOffset:"startOffset",stdDeviation:"stdDeviation",stemh:0,stemv:0,stitchTiles:"stitchTiles",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",string:0,stroke:0,strokeDasharray:"stroke-dasharray",strokeDashoffset:"stroke-dashoffset",strokeLinecap:"stroke-linecap",strokeLinejoin:"stroke-linejoin",strokeMiterlimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",surfaceScale:"surfaceScale",systemLanguage:"systemLanguage",tableValues:"tableValues",targetX:"targetX",targetY:"targetY",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",textLength:"textLength",to:0,transform:0,u1:0,u2:0,underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicode:0,unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",values:0,vectorEffect:"vector-effect",version:0,vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",viewBox:"viewBox",viewTarget:"viewTarget",visibility:0,widths:0,wordSpacing:"word-spacing",writingMode:"writing-mode",x:0,xHeight:"x-height",x1:0,x2:0,xChannelSelector:"xChannelSelector",xlinkActuate:"xlink:actuate",xlinkArcrole:"xlink:arcrole",xlinkHref:"xlink:href",xlinkRole:"xlink:role",xlinkShow:"xlink:show",xlinkTitle:"xlink:title",xlinkType:"xlink:type",xmlBase:"xml:base",xmlns:0,xmlnsXlink:"xmlns:xlink",xmlLang:"xml:lang",xmlSpace:"xml:space",y:0,y1:0,y2:0,yChannelSelector:"yChannelSelector",z:0,zoomAndPan:"zoomAndPan"},a={Properties:{},DOMAttributeNamespaces:{xlinkActuate:n,xlinkArcrole:n,xlinkHref:n,xlinkRole:n,xlinkShow:n,xlinkTitle:n,xlinkType:n,xmlBase:i,xmlLang:i,xmlSpace:i},DOMAttributeNames:{}};Object.keys(o).forEach(function(e){a.Properties[e]=0,o[e]&&(a.DOMAttributeNames[e]=o[e])}),e.exports=a},function(e,t,r){var n=r(13);e.exports=function(e,t){if(!e||"string"!=typeof e)return null;for(var r,i,o,a=n("p{"+e+"}").stylesheet.rules[0].declarations,s=null,u="function"==typeof t,l=0,c=a.length;l<c;l++)i=(r=a[l]).property,o=r.value,u?t(i,o,r):o&&(s||(s={}),s[i]=o);return s}},function(e,t){var r=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;function n(e){return e?e.replace(/^\s+|\s+$/g,""):""}e.exports=function(e,t){t=t||{};var i=1,o=1;function a(e){var t=e.match(/\n/g);t&&(i+=t.length);var r=e.lastIndexOf("\n");o=~r?e.length-r:o+e.length}function s(){var e={line:i,column:o};return function(t){return t.position=new u(e),h(),t}}function u(e){this.start=e,this.end={line:i,column:o},this.source=t.source}u.prototype.content=e;var l=[];function c(r){var n=new Error(t.source+":"+i+":"+o+": "+r);if(n.reason=r,n.filename=t.source,n.line=i,n.column=o,n.source=e,!t.silent)throw n;l.push(n)}function p(){return d(/^{\s*/)}function f(){return d(/^}/)}function m(){var t,r=[];for(h(),g(r);e.length&&"}"!=e.charAt(0)&&(t=w()||M());)!1!==t&&(r.push(t),g(r));return r}function d(t){var r=t.exec(e);if(r){var n=r[0];return a(n),e=e.slice(n.length),r}}function h(){d(/^\s*/)}function g(e){var t;for(e=e||[];t=y();)!1!==t&&e.push(t);return e}function y(){var t=s();if("/"==e.charAt(0)&&"*"==e.charAt(1)){for(var r=2;""!=e.charAt(r)&&("*"!=e.charAt(r)||"/"!=e.charAt(r+1));)++r;if(r+=2,""===e.charAt(r-1))return c("End of comment missing");var n=e.slice(2,r-2);return o+=2,a(n),e=e.slice(r),o+=2,t({type:"comment",comment:n})}}function v(){var e=d(/^([^{]+)/);if(e)return n(e[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g,"").replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g,function(e){return e.replace(/,/g,"")}).split(/\s*(?![^(]*\)),\s*/).map(function(e){return e.replace(/\u200C/g,",")})}function b(){var e=s(),t=d(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);if(t){if(t=n(t[0]),!d(/^:\s*/))return c("property missing ':'");var i=d(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/),o=e({type:"declaration",property:t.replace(r,""),value:i?n(i[0]).replace(r,""):""});return d(/^[;\s]*/),o}}function x(){var e,t=[];if(!p())return c("missing '{'");for(g(t);e=b();)!1!==e&&(t.push(e),g(t));return f()?t:c("missing '}'")}function A(){for(var e,t=[],r=s();e=d(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/);)t.push(e[1]),d(/^,\s*/);if(t.length)return r({type:"keyframe",values:t,declarations:x()})}var k=T("import"),E=T("charset"),O=T("namespace");function T(e){var t=new RegExp("^@"+e+"\\s*([^;]+);");return function(){var r=s(),n=d(t);if(n){var i={type:e};return i[e]=n[1].trim(),r(i)}}}function w(){if("@"==e[0])return function(){var e=s();if(t=d(/^@([-\w]+)?keyframes\s*/)){var t,r=t[1];if(!(t=d(/^([-\w]+)\s*/)))return c("@keyframes missing name");var n,i=t[1];if(!p())return c("@keyframes missing '{'");for(var o=g();n=A();)o.push(n),o=o.concat(g());return f()?e({type:"keyframes",name:i,vendor:r,keyframes:o}):c("@keyframes missing '}'")}}()||function(){var e=s(),t=d(/^@media *([^{]+)/);if(t){var r=n(t[1]);if(!p())return c("@media missing '{'");var i=g().concat(m());return f()?e({type:"media",media:r,rules:i}):c("@media missing '}'")}}()||function(){var e=s(),t=d(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);if(t)return e({type:"custom-media",name:n(t[1]),media:n(t[2])})}()||function(){var e=s(),t=d(/^@supports *([^{]+)/);if(t){var r=n(t[1]);if(!p())return c("@supports missing '{'");var i=g().concat(m());return f()?e({type:"supports",supports:r,rules:i}):c("@supports missing '}'")}}()||k()||E()||O()||function(){var e=s(),t=d(/^@([-\w]+)?document *([^{]+)/);if(t){var r=n(t[1]),i=n(t[2]);if(!p())return c("@document missing '{'");var o=g().concat(m());return f()?e({type:"document",document:i,vendor:r,rules:o}):c("@document missing '}'")}}()||function(){var e=s();if(d(/^@page */)){var t=v()||[];if(!p())return c("@page missing '{'");for(var r,n=g();r=b();)n.push(r),n=n.concat(g());return f()?e({type:"page",selectors:t,declarations:n}):c("@page missing '}'")}}()||function(){var e=s();if(d(/^@host\s*/)){if(!p())return c("@host missing '{'");var t=g().concat(m());return f()?e({type:"host",rules:t}):c("@host missing '}'")}}()||function(){var e=s();if(d(/^@font-face\s*/)){if(!p())return c("@font-face missing '{'");for(var t,r=g();t=b();)r.push(t),r=r.concat(g());return f()?e({type:"font-face",declarations:r}):c("@font-face missing '}'")}}()}function M(){var e=s(),t=v();return t?(g(),e({type:"rule",selectors:t,declarations:x()})):c("selector missing")}return function e(t,r){var n=t&&"string"==typeof t.type;var i=n?t:r;for(var o in t){var a=t[o];Array.isArray(a)?a.forEach(function(t){e(t,i)}):a&&"object"==typeof a&&e(a,i)}n&&Object.defineProperty(t,"parent",{configurable:!0,writable:!0,enumerable:!1,value:r||null});return t}(function(){var e=m();return{type:"stylesheet",stylesheet:{source:t.source,rules:e,parsingErrors:l}}}())}},function(e,t,r){"use strict";var n=r(15),i=r(2),o=i.formatDOM,a=i.isIE(9),s=/<(![a-zA-Z\s]+)>/;e.exports=function(e){if("string"!=typeof e)throw new TypeError("First argument must be a string.");if(!e)return[];var t,r=e.match(s);return r&&r[1]&&(t=r[1],a&&(e=e.replace(r[0],""))),o(n(e),null,t)}},function(e,t,r){"use strict";var n,i,o,a=r(2).isIE,s=/<([a-zA-Z]+[0-9]?)/,u=/<\/head>/i,l=/<\/body>/i,c=/<(area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)(.*?)\/?>/gi,p=a(),f=a(9);if("function"==typeof window.DOMParser){var m=new window.DOMParser,d=f?"text/xml":"text/html";n=function(e,t){return t&&(e=["<",t,">",e,"</",t,">"].join("")),f&&(e=e.replace(c,"<$1$2$3/>")),m.parseFromString(e,d)}}if("object"==typeof document.implementation){var h=document.implementation.createHTMLDocument(p?"HTML_DOM_PARSER_TITLE":void 0);i=function(e,t){if(t)return h.documentElement.getElementsByTagName(t)[0].innerHTML=e,h;try{return h.documentElement.innerHTML=e,h}catch(t){if(n)return n(e)}}}var g=document.createElement("template");g.content&&(o=function(e){return g.innerHTML=e,g.content.childNodes});var y=i||n;e.exports=function(e){var t,r,i,a,c=e.match(s);switch(c&&c[1]&&(t=c[1].toLowerCase()),t){case"html":if(n)return r=n(e),u.test(e)||(i=r.getElementsByTagName("head")[0])&&i.parentNode.removeChild(i),l.test(e)||(i=r.getElementsByTagName("body")[0])&&i.parentNode.removeChild(i),r.getElementsByTagName("html");break;case"head":if(y)return a=y(e).getElementsByTagName("head"),l.test(e)?a[0].parentNode.childNodes:a;break;case"body":if(y)return a=y(e).getElementsByTagName("body"),u.test(e)?a[0].parentNode.childNodes:a;break;default:if(o)return o(e);if(y)return y(e,"body").getElementsByTagName("body")[0].childNodes}return[]}}])});
|
package/index.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies.
|
|
5
|
-
*/
|
|
6
1
|
var domToReact = require('./lib/dom-to-react');
|
|
7
2
|
var htmlToDOM = require('html-dom-parser');
|
|
8
3
|
|
|
9
4
|
// decode HTML entities by default for `htmlparser2`
|
|
10
|
-
var domParserOptions = { decodeEntities: true };
|
|
5
|
+
var domParserOptions = { decodeEntities: true, lowerCaseAttributeNames: false };
|
|
11
6
|
|
|
12
7
|
/**
|
|
13
8
|
* Convert HTML string to React elements.
|
|
@@ -18,10 +13,10 @@ var domParserOptions = { decodeEntities: true };
|
|
|
18
13
|
* @return {ReactElement|Array}
|
|
19
14
|
*/
|
|
20
15
|
function HTMLReactParser(html, options) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
if (typeof html !== 'string') {
|
|
17
|
+
throw new TypeError('First argument must be a string');
|
|
18
|
+
}
|
|
19
|
+
return domToReact(htmlToDOM(html, domParserOptions), options);
|
|
25
20
|
}
|
|
26
21
|
|
|
27
22
|
/**
|
|
@@ -1,89 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies.
|
|
5
|
-
*/
|
|
6
|
-
var utilities = require('./utilities');
|
|
1
|
+
var DOMProperty = require('react-dom-core/lib/DOMProperty');
|
|
7
2
|
var propertyConfig = require('./property-config');
|
|
8
3
|
var styleToObject = require('style-to-object');
|
|
4
|
+
var utilities = require('./utilities');
|
|
5
|
+
|
|
9
6
|
var config = propertyConfig.config;
|
|
10
7
|
var isCustomAttribute = propertyConfig.HTMLDOMPropertyConfig.isCustomAttribute;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
DOMProperty.injection.injectDOMPropertyConfig(
|
|
9
|
+
propertyConfig.HTMLDOMPropertyConfig
|
|
10
|
+
);
|
|
14
11
|
|
|
15
12
|
/**
|
|
16
|
-
*
|
|
13
|
+
* Makes attributes compatible with React props.
|
|
17
14
|
*
|
|
18
15
|
* @param {Object} attributes - The attributes.
|
|
19
16
|
* @return {Object} - The props.
|
|
20
17
|
*/
|
|
21
18
|
function attributesToProps(attributes) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
attributes = attributes || {};
|
|
20
|
+
var props = {};
|
|
21
|
+
var propertyName;
|
|
22
|
+
var propertyValue;
|
|
23
|
+
var reactProperty;
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
for (propertyName in attributes) {
|
|
26
|
+
propertyValue = attributes[propertyName];
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// make HTML DOM attribute/property consistent with React attribute/property
|
|
38
|
-
reactProperty = config.html[propertyName.toLowerCase()];
|
|
39
|
-
if (reactProperty) {
|
|
40
|
-
if (DOMProperty.properties.hasOwnProperty(reactProperty) && DOMProperty.properties[reactProperty].hasBooleanValue) {
|
|
41
|
-
props[reactProperty] = true;
|
|
42
|
-
} else {
|
|
43
|
-
props[reactProperty] = propertyValue;
|
|
44
|
-
}
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
28
|
+
// custom attributes (`data-` and `aria-`)
|
|
29
|
+
if (isCustomAttribute(propertyName)) {
|
|
30
|
+
props[propertyName] = propertyValue;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
47
33
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
34
|
+
// make HTML DOM attribute/property consistent with React attribute/property
|
|
35
|
+
reactProperty = config.html[propertyName.toLowerCase()];
|
|
36
|
+
if (reactProperty) {
|
|
37
|
+
if (
|
|
38
|
+
DOMProperty.properties.hasOwnProperty(reactProperty) &&
|
|
39
|
+
DOMProperty.properties[reactProperty].hasBooleanValue
|
|
40
|
+
) {
|
|
41
|
+
props[reactProperty] = true;
|
|
42
|
+
} else {
|
|
43
|
+
props[reactProperty] = propertyValue;
|
|
44
|
+
}
|
|
45
|
+
continue;
|
|
53
46
|
}
|
|
54
47
|
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
// make SVG DOM attribute/property consistent with React attribute/property
|
|
49
|
+
reactProperty = config.svg[propertyName];
|
|
50
|
+
if (reactProperty) {
|
|
51
|
+
props[reactProperty] = propertyValue;
|
|
58
52
|
}
|
|
53
|
+
}
|
|
59
54
|
|
|
60
|
-
|
|
55
|
+
// convert inline style to object
|
|
56
|
+
if (attributes.style != null) {
|
|
57
|
+
props.style = cssToJs(attributes.style);
|
|
58
|
+
}
|
|
59
|
+
return props;
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
/**
|
|
64
|
-
*
|
|
63
|
+
* Converts CSS style string to JS style object.
|
|
65
64
|
*
|
|
66
65
|
* @param {String} style - The CSS style.
|
|
67
66
|
* @return {Object} - The JS style object.
|
|
68
67
|
*/
|
|
69
68
|
function cssToJs(style) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
var styleObj = {};
|
|
69
|
+
if (typeof style !== 'string') {
|
|
70
|
+
throw new TypeError('First argument must be a string.');
|
|
71
|
+
}
|
|
72
|
+
var styleObj = {};
|
|
75
73
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return styleObj;
|
|
74
|
+
styleToObject(style, function(propName, propValue) {
|
|
75
|
+
// Check if it's not a comment node
|
|
76
|
+
if (propName && propValue) {
|
|
77
|
+
styleObj[utilities.camelCase(propName)] = propValue;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return styleObj;
|
|
84
81
|
}
|
|
85
82
|
|
|
86
|
-
/**
|
|
87
|
-
* Export attributes to props helper.
|
|
88
|
-
*/
|
|
89
83
|
module.exports = attributesToProps;
|
package/lib/dom-to-react.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies.
|
|
5
|
-
*/
|
|
6
1
|
var React = require('react');
|
|
7
2
|
var attributesToProps = require('./attributes-to-props');
|
|
8
3
|
|
|
9
4
|
/**
|
|
10
|
-
*
|
|
5
|
+
* Converts DOM nodes to React elements.
|
|
11
6
|
*
|
|
12
7
|
* @param {Array} nodes - The DOM nodes.
|
|
13
8
|
* @param {Object} [options] - The additional options.
|
|
@@ -15,87 +10,77 @@ var attributesToProps = require('./attributes-to-props');
|
|
|
15
10
|
* @return {ReactElement|Array}
|
|
16
11
|
*/
|
|
17
12
|
function domToReact(nodes, options) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
for (var i = 0, len = nodes.length; i < len; i++) {
|
|
27
|
-
node = nodes[i];
|
|
28
|
-
|
|
29
|
-
// replace with custom React element (if applicable)
|
|
30
|
-
if (isReplacePresent) {
|
|
31
|
-
replacement = options.replace(node);
|
|
32
|
-
|
|
33
|
-
if (React.isValidElement(replacement)) {
|
|
34
|
-
// specify a "key" prop if element has siblings
|
|
35
|
-
// https://fb.me/react-warning-keys
|
|
36
|
-
if (len > 1) {
|
|
37
|
-
replacement = React.cloneElement(replacement, { key: i });
|
|
38
|
-
}
|
|
39
|
-
result.push(replacement);
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (node.type === 'text') {
|
|
45
|
-
result.push(node.data);
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
13
|
+
options = options || {};
|
|
14
|
+
var result = [];
|
|
15
|
+
var node;
|
|
16
|
+
var isReplacePresent = typeof options.replace === 'function';
|
|
17
|
+
var replacement;
|
|
18
|
+
var props;
|
|
19
|
+
var children;
|
|
48
20
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
children = null;
|
|
21
|
+
for (var i = 0, len = nodes.length; i < len; i++) {
|
|
22
|
+
node = nodes[i];
|
|
52
23
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
// prevent text in <script> or <style> from being escaped
|
|
57
|
-
// https://facebook.github.io/react/tips/dangerously-set-inner-html.html
|
|
58
|
-
if (node.children[0]) {
|
|
59
|
-
props.dangerouslySetInnerHTML = {
|
|
60
|
-
__html: node.children[0].data
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
} else if (node.type === 'tag') {
|
|
65
|
-
// setting textarea value in children is an antipattern in React
|
|
66
|
-
// https://facebook.github.io/react/docs/forms.html#why-textarea-value
|
|
67
|
-
if (node.name === 'textarea' && node.children[0]) {
|
|
68
|
-
props.defaultValue = node.children[0].data;
|
|
69
|
-
|
|
70
|
-
// continue recursion of creating React elements (if applicable)
|
|
71
|
-
} else if (node.children && node.children.length) {
|
|
72
|
-
children = domToReact(node.children, options);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// skip all other cases (e.g., comment)
|
|
76
|
-
} else {
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
24
|
+
// replace with custom React element (if applicable)
|
|
25
|
+
if (isReplacePresent) {
|
|
26
|
+
replacement = options.replace(node);
|
|
79
27
|
|
|
28
|
+
if (React.isValidElement(replacement)) {
|
|
80
29
|
// specify a "key" prop if element has siblings
|
|
81
30
|
// https://fb.me/react-warning-keys
|
|
82
31
|
if (len > 1) {
|
|
83
|
-
|
|
32
|
+
replacement = React.cloneElement(replacement, { key: i });
|
|
84
33
|
}
|
|
34
|
+
result.push(replacement);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
85
38
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
39
|
+
if (node.type === 'text') {
|
|
40
|
+
result.push(node.data);
|
|
41
|
+
continue;
|
|
89
42
|
}
|
|
90
43
|
|
|
91
|
-
|
|
92
|
-
|
|
44
|
+
// update values
|
|
45
|
+
props = attributesToProps(node.attribs);
|
|
46
|
+
children = null;
|
|
47
|
+
|
|
48
|
+
// node type for <script> is "script"
|
|
49
|
+
// node type for <style> is "style"
|
|
50
|
+
if (node.type === 'script' || node.type === 'style') {
|
|
51
|
+
// prevent text in <script> or <style> from being escaped
|
|
52
|
+
// https://facebook.github.io/react/tips/dangerously-set-inner-html.html
|
|
53
|
+
if (node.children[0]) {
|
|
54
|
+
props.dangerouslySetInnerHTML = {
|
|
55
|
+
__html: node.children[0].data
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
} else if (node.type === 'tag') {
|
|
59
|
+
// setting textarea value in children is an antipattern in React
|
|
60
|
+
// https://reactjs.org/docs/forms.html#the-textarea-tag
|
|
61
|
+
if (node.name === 'textarea' && node.children[0]) {
|
|
62
|
+
props.defaultValue = node.children[0].data;
|
|
63
|
+
|
|
64
|
+
// continue recursion of creating React elements (if applicable)
|
|
65
|
+
} else if (node.children && node.children.length) {
|
|
66
|
+
children = domToReact(node.children, options);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// skip all other cases (e.g., comment)
|
|
93
70
|
} else {
|
|
94
|
-
|
|
71
|
+
continue;
|
|
95
72
|
}
|
|
73
|
+
|
|
74
|
+
// specify a "key" prop if element has siblings
|
|
75
|
+
// https://fb.me/react-warning-keys
|
|
76
|
+
if (len > 1) {
|
|
77
|
+
props.key = i;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
result.push(React.createElement(node.name, props, children));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return result.length === 1 ? result[0] : result;
|
|
96
84
|
}
|
|
97
85
|
|
|
98
|
-
/**
|
|
99
|
-
* Export DOM to React parser.
|
|
100
|
-
*/
|
|
101
86
|
module.exports = domToReact;
|
package/lib/property-config.js
CHANGED
|
@@ -1,62 +1,50 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies.
|
|
5
|
-
*/
|
|
6
|
-
var utilities = require('./utilities');
|
|
7
|
-
|
|
8
|
-
// HTML and SVG DOM Property Configs
|
|
9
1
|
var HTMLDOMPropertyConfig = require('react-dom-core/lib/HTMLDOMPropertyConfig');
|
|
10
2
|
var SVGDOMPropertyConfig = require('react-dom-core/lib/SVGDOMPropertyConfig');
|
|
3
|
+
var utilities = require('./utilities');
|
|
11
4
|
|
|
12
5
|
var config = {
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
html: {},
|
|
7
|
+
svg: {}
|
|
15
8
|
};
|
|
16
9
|
|
|
17
10
|
var propertyName;
|
|
18
11
|
|
|
19
12
|
/**
|
|
20
13
|
* HTML DOM property config.
|
|
21
|
-
*
|
|
14
|
+
*
|
|
15
|
+
* https://github.com/facebook/react/blob/15-stable/src/renderers/dom/shared/HTMLDOMPropertyConfig.js
|
|
22
16
|
*/
|
|
23
17
|
|
|
24
18
|
// first map out the HTML attribute names
|
|
25
19
|
// e.g., { className: 'class' } => { 'class': 'className' }
|
|
26
|
-
config.html = utilities.invertObject(
|
|
27
|
-
HTMLDOMPropertyConfig.DOMAttributeNames
|
|
28
|
-
);
|
|
20
|
+
config.html = utilities.invertObject(HTMLDOMPropertyConfig.DOMAttributeNames);
|
|
29
21
|
|
|
30
22
|
// then map out the rest of the HTML properties
|
|
31
23
|
// e.g., { readOnly: 0 } => { readonly: 'readOnly' }
|
|
32
24
|
for (propertyName in HTMLDOMPropertyConfig.Properties) {
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
// lowercase to make matching property names easier
|
|
26
|
+
config.html[propertyName.toLowerCase()] = propertyName;
|
|
35
27
|
}
|
|
36
28
|
|
|
37
29
|
/**
|
|
38
30
|
* SVG DOM property config.
|
|
39
|
-
*
|
|
31
|
+
*
|
|
32
|
+
* https://github.com/facebook/react/blob/15-stable/src/renderers/dom/shared/SVGDOMPropertyConfig.js
|
|
40
33
|
*/
|
|
41
34
|
|
|
42
35
|
// first map out the SVG attribute names
|
|
43
36
|
// e.g., { fontSize: 'font-size' } => { 'font-size': 'fontSize' }
|
|
44
|
-
config.svg = utilities.invertObject(
|
|
45
|
-
SVGDOMPropertyConfig.DOMAttributeNames
|
|
46
|
-
);
|
|
37
|
+
config.svg = utilities.invertObject(SVGDOMPropertyConfig.DOMAttributeNames);
|
|
47
38
|
|
|
48
39
|
// then map out the rest of the SVG properties
|
|
49
40
|
// e.g., { fillRule: 0 } => { fillRule: 'fillRule' }
|
|
50
41
|
for (propertyName in SVGDOMPropertyConfig.Properties) {
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
// do not lowercase as some svg properties are camel cased
|
|
43
|
+
config.html[propertyName] = propertyName;
|
|
53
44
|
}
|
|
54
45
|
|
|
55
|
-
/**
|
|
56
|
-
* Export property configs.
|
|
57
|
-
*/
|
|
58
46
|
module.exports = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
47
|
+
config: config,
|
|
48
|
+
HTMLDOMPropertyConfig: HTMLDOMPropertyConfig,
|
|
49
|
+
SVGDOMPropertyConfig: SVGDOMPropertyConfig
|
|
62
50
|
};
|
package/lib/utilities.js
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _hyphenPattern = /-(.)/g;
|
|
1
|
+
var hyphenPatternRegex = /-([a-z])/g;
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
|
-
*
|
|
4
|
+
* Converts a string to camelCase.
|
|
7
5
|
*
|
|
8
6
|
* @param {String} string - The string.
|
|
9
7
|
* @return {String}
|
|
10
8
|
*/
|
|
11
9
|
function camelCase(string) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return string
|
|
19
|
-
|
|
10
|
+
if (typeof string !== 'string') {
|
|
11
|
+
throw new TypeError('First argument must be a string');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// no hyphen found
|
|
15
|
+
if (string.indexOf('-') === -1) {
|
|
16
|
+
return string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// convert to camelCase
|
|
20
|
+
return string
|
|
21
|
+
.toLowerCase()
|
|
22
|
+
.replace(hyphenPatternRegex, function(_, character) {
|
|
23
|
+
return character.toUpperCase();
|
|
20
24
|
});
|
|
21
25
|
}
|
|
22
26
|
|
|
@@ -28,39 +32,36 @@ function camelCase(string) {
|
|
|
28
32
|
* @return {Object} - The inverted object.
|
|
29
33
|
*/
|
|
30
34
|
function invertObject(obj, override) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
if (!obj || typeof obj !== 'object') {
|
|
36
|
+
throw new TypeError('First argument must be an object');
|
|
37
|
+
}
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
var key;
|
|
40
|
+
var value;
|
|
41
|
+
var isOverridePresent = typeof override === 'function';
|
|
42
|
+
var overrides = {};
|
|
43
|
+
var result = {};
|
|
40
44
|
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
for (key in obj) {
|
|
46
|
+
value = obj[key];
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
if (isOverridePresent) {
|
|
49
|
+
overrides = override(key, value);
|
|
50
|
+
if (overrides && overrides.length === 2) {
|
|
51
|
+
result[overrides[0]] = overrides[1];
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
56
|
+
if (typeof value === 'string') {
|
|
57
|
+
result[value] = key;
|
|
55
58
|
}
|
|
59
|
+
}
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
return result;
|
|
58
62
|
}
|
|
59
63
|
|
|
60
|
-
/**
|
|
61
|
-
* Export utilties.
|
|
62
|
-
*/
|
|
63
64
|
module.exports = {
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
camelCase: camelCase,
|
|
66
|
+
invertObject: invertObject
|
|
66
67
|
};
|