You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3 lines
12 KiB
3 lines
12 KiB
import t from"react-fast-compare";import e from"invariant";import r from"prop-types";import n,{Component as o}from"react";import i from"shallowequal";var a={BASE:"base",BODY:"body",HEAD:"head",HTML:"html",LINK:"link",META:"meta",NOSCRIPT:"noscript",SCRIPT:"script",STYLE:"style",TITLE:"title",FRAGMENT:"Symbol(react.fragment)"},s=Object.keys(a).map(function(t){return a[t]}),c={accesskey:"accessKey",charset:"charSet",class:"className",contenteditable:"contentEditable",contextmenu:"contextMenu","http-equiv":"httpEquiv",itemprop:"itemProp",tabindex:"tabIndex"},u=Object.keys(c).reduce(function(t,e){return t[c[e]]=e,t},{}),l=function(t,e){for(var r=t.length-1;r>=0;r-=1){var n=t[r];if(Object.prototype.hasOwnProperty.call(n,e))return n[e]}return null},p=function(t){var e=l(t,a.TITLE),r=l(t,"titleTemplate");if(Array.isArray(e)&&(e=e.join("")),r&&e)return r.replace(/%s/g,function(){return e});var n=l(t,"defaultTitle");return e||n||void 0},f=function(t){return l(t,"onChangeClientState")||function(){}},d=function(t,e){return e.filter(function(e){return void 0!==e[t]}).map(function(e){return e[t]}).reduce(function(t,e){return Object.assign({},t,e)},{})},h=function(t,e){return e.filter(function(t){return void 0!==t[a.BASE]}).map(function(t){return t[a.BASE]}).reverse().reduce(function(e,r){if(!e.length)for(var n=Object.keys(r),o=0;o<n.length;o+=1){var i=n[o].toLowerCase();if(-1!==t.indexOf(i)&&r[i])return e.concat(r)}return e},[])},y=function(t,e,r){var n={};return r.filter(function(e){return!!Array.isArray(e[t])||(void 0!==e[t]&&console&&"function"==typeof console.warn&&console.warn("Helmet: "+t+' should be of type "Array". Instead found type "'+typeof e[t]+'"'),!1)}).map(function(e){return e[t]}).reverse().reduce(function(t,r){var o={};r.filter(function(t){for(var r,i=Object.keys(t),a=0;a<i.length;a+=1){var s=i[a],c=s.toLowerCase();-1===e.indexOf(c)||"rel"===r&&"canonical"===t[r].toLowerCase()||"rel"===c&&"stylesheet"===t[c].toLowerCase()||(r=c),-1===e.indexOf(s)||"innerHTML"!==s&&"cssText"!==s&&"itemprop"!==s||(r=s)}if(!r||!t[r])return!1;var u=t[r].toLowerCase();return n[r]||(n[r]={}),o[r]||(o[r]={}),!n[r][u]&&(o[r][u]=!0,!0)}).reverse().forEach(function(e){return t.push(e)});for(var i=Object.keys(o),a=0;a<i.length;a+=1){var s=i[a],c=Object.assign({},n[s],o[s]);n[s]=c}return t},[]).reverse()},m=function(t){return Array.isArray(t)?t.join(""):t},T=[a.NOSCRIPT,a.SCRIPT,a.STYLE],b=function(t,e){return void 0===e&&(e=!0),!1===e?String(t):String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")},g=function(t){return Object.keys(t).reduce(function(e,r){var n=void 0!==t[r]?r+'="'+t[r]+'"':""+r;return e?e+" "+n:n},"")},v=function(t,e){return void 0===e&&(e={}),Object.keys(t).reduce(function(e,r){return e[c[r]||r]=t[r],e},e)},A=function(t,e,r){switch(t){case a.TITLE:return{toComponent:function(){return r=v(e.titleAttributes,{key:t=e.title,"data-rh":!0}),[n.createElement(a.TITLE,r,t)];var t,r},toString:function(){return function(t,r,n,o){var i=g(e.titleAttributes),a=m(r);return i?"<"+t+' data-rh="true" '+i+">"+b(a,o)+"</"+t+">":"<"+t+' data-rh="true">'+b(a,o)+"</"+t+">"}(t,e.title,0,r)}};case"bodyAttributes":case"htmlAttributes":return{toComponent:function(){return v(e)},toString:function(){return g(e)}};default:return{toComponent:function(){return function(t,e){return e.map(function(e,r){var o={key:r,"data-rh":!0};return Object.keys(e).forEach(function(t){var r=c[t]||t;"innerHTML"===r||"cssText"===r?o.dangerouslySetInnerHTML={__html:e.innerHTML||e.cssText}:o[r]=e[t]}),n.createElement(t,o)})}(t,e)},toString:function(){return function(t,e,r){return e.reduce(function(e,n){var o=Object.keys(n).filter(function(t){return!("innerHTML"===t||"cssText"===t)}).reduce(function(t,e){var o=void 0===n[e]?e:e+'="'+b(n[e],r)+'"';return t?t+" "+o:o},""),i=n.innerHTML||n.cssText||"",a=-1===T.indexOf(t);return e+"<"+t+' data-rh="true" '+o+(a?"/>":">"+i+"</"+t+">")},"")}(t,e,r)}}}},O=function(t){var e=t.bodyAttributes,r=t.encode,n=t.htmlAttributes,o=t.linkTags,i=t.metaTags,s=t.noscriptTags,c=t.scriptTags,u=t.styleTags,l=t.title;void 0===l&&(l="");var p=t.titleAttributes;return{base:A(a.BASE,t.baseTag,r),bodyAttributes:A("bodyAttributes",e,r),htmlAttributes:A("htmlAttributes",n,r),link:A(a.LINK,o,r),meta:A(a.META,i,r),noscript:A(a.NOSCRIPT,s,r),script:A(a.SCRIPT,c,r),style:A(a.STYLE,u,r),title:A(a.TITLE,{title:l,titleAttributes:p},r)}},C=n.createContext({}),j=r.shape({setHelmet:r.func,helmetInstances:r.shape({get:r.func,add:r.func,remove:r.func})}),E="undefined"!=typeof document,S=function(t){function e(r){var n=this;t.call(this,r),this.instances=[],this.value={setHelmet:function(t){n.props.context.helmet=t},helmetInstances:{get:function(){return n.instances},add:function(t){n.instances.push(t)},remove:function(t){var e=n.instances.indexOf(t);n.instances.splice(e,1)}}},e.canUseDOM||(r.context.helmet=O({baseTag:[],bodyAttributes:{},encodeSpecialCharacters:!0,htmlAttributes:{},linkTags:[],metaTags:[],noscriptTags:[],scriptTags:[],styleTags:[],title:"",titleAttributes:{}}))}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.render=function(){return n.createElement(C.Provider,{value:this.value},this.props.children)},e}(o);S.canUseDOM=E,S.propTypes={context:r.shape({helmet:r.shape()}),children:r.node.isRequired},S.defaultProps={context:{}},S.displayName="HelmetProvider";var I=function(t,e){var r,n=document.head||document.querySelector(a.HEAD),o=n.querySelectorAll(t+"[data-rh]"),i=[].slice.call(o),s=[];return e&&e.length&&e.forEach(function(e){var n=document.createElement(t);for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&("innerHTML"===o?n.innerHTML=e.innerHTML:"cssText"===o?n.styleSheet?n.styleSheet.cssText=e.cssText:n.appendChild(document.createTextNode(e.cssText)):n.setAttribute(o,void 0===e[o]?"":e[o]));n.setAttribute("data-rh","true"),i.some(function(t,e){return r=e,n.isEqualNode(t)})?i.splice(r,1):s.push(n)}),i.forEach(function(t){return t.parentNode.removeChild(t)}),s.forEach(function(t){return n.appendChild(t)}),{oldTags:i,newTags:s}},P=function(t,e){var r=document.getElementsByTagName(t)[0];if(r){for(var n=r.getAttribute("data-rh"),o=n?n.split(","):[],i=[].concat(o),a=Object.keys(e),s=0;s<a.length;s+=1){var c=a[s],u=e[c]||"";r.getAttribute(c)!==u&&r.setAttribute(c,u),-1===o.indexOf(c)&&o.push(c);var l=i.indexOf(c);-1!==l&&i.splice(l,1)}for(var p=i.length-1;p>=0;p-=1)r.removeAttribute(i[p]);o.length===i.length?r.removeAttribute("data-rh"):r.getAttribute("data-rh")!==a.join(",")&&r.setAttribute("data-rh",a.join(","))}},L=function(t,e){var r=t.baseTag,n=t.htmlAttributes,o=t.linkTags,i=t.metaTags,s=t.noscriptTags,c=t.onChangeClientState,u=t.scriptTags,l=t.styleTags,p=t.title,f=t.titleAttributes;P(a.BODY,t.bodyAttributes),P(a.HTML,n),function(t,e){void 0!==t&&document.title!==t&&(document.title=m(t)),P(a.TITLE,e)}(p,f);var d={baseTag:I(a.BASE,r),linkTags:I(a.LINK,o),metaTags:I(a.META,i),noscriptTags:I(a.NOSCRIPT,s),scriptTags:I(a.SCRIPT,u),styleTags:I(a.STYLE,l)},h={},y={};Object.keys(d).forEach(function(t){var e=d[t],r=e.newTags,n=e.oldTags;r.length&&(h[t]=r),n.length&&(y[t]=d[t].oldTags)}),e&&e(),c(t,h,y)},x=null,w=function(t){function e(){for(var e=[],r=arguments.length;r--;)e[r]=arguments[r];t.apply(this,e),this.rendered=!1}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.shouldComponentUpdate=function(t){return!i(t,this.props)},e.prototype.componentDidUpdate=function(){this.emitChange()},e.prototype.componentWillUnmount=function(){this.props.context.helmetInstances.remove(this),this.emitChange()},e.prototype.emitChange=function(){var t,e,r=this.props.context,n=r.setHelmet,o=null,i=(t=r.helmetInstances.get().map(function(t){var e=Object.assign({},t.props);return delete e.context,e}),{baseTag:h(["href"],t),bodyAttributes:d("bodyAttributes",t),defer:l(t,"defer"),encode:l(t,"encodeSpecialCharacters"),htmlAttributes:d("htmlAttributes",t),linkTags:y(a.LINK,["rel","href"],t),metaTags:y(a.META,["name","charset","http-equiv","property","itemprop"],t),noscriptTags:y(a.NOSCRIPT,["innerHTML"],t),onChangeClientState:f(t),scriptTags:y(a.SCRIPT,["src","innerHTML"],t),styleTags:y(a.STYLE,["cssText"],t),title:p(t),titleAttributes:d("titleAttributes",t)});S.canUseDOM?(e=i,x&&cancelAnimationFrame(x),e.defer?x=requestAnimationFrame(function(){L(e,function(){x=null})}):(L(e),x=null)):O&&(o=O(i)),n(o)},e.prototype.init=function(){this.rendered||(this.rendered=!0,this.props.context.helmetInstances.add(this),this.emitChange())},e.prototype.render=function(){return this.init(),null},e}(o);function H(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&-1===e.indexOf(n)&&(r[n]=t[n]);return r}w.propTypes={context:j.isRequired},w.displayName="HelmetDispatcher";var k=function(r){function o(){r.apply(this,arguments)}return r&&(o.__proto__=r),(o.prototype=Object.create(r&&r.prototype)).constructor=o,o.prototype.shouldComponentUpdate=function(e){return!t(this.props,e)},o.prototype.mapNestedChildrenToProps=function(t,e){if(!e)return null;switch(t.type){case a.SCRIPT:case a.NOSCRIPT:return{innerHTML:e};case a.STYLE:return{cssText:e};default:throw new Error("<"+t.type+" /> elements are self-closing and can not contain children. Refer to our API for more information.")}},o.prototype.flattenArrayTypeChildren=function(t){var e,r=t.child,n=t.arrayTypeChildren;return Object.assign({},n,((e={})[r.type]=(n[r.type]||[]).concat([Object.assign({},t.newChildProps,this.mapNestedChildrenToProps(r,t.nestedChildren))]),e))},o.prototype.mapObjectTypeChildren=function(t){var e,r,n=t.child,o=t.newProps,i=t.newChildProps,s=t.nestedChildren;switch(n.type){case a.TITLE:return Object.assign({},o,((e={})[n.type]=s,e),{titleAttributes:Object.assign({},i)});case a.BODY:return Object.assign({},o,{bodyAttributes:Object.assign({},i)});case a.HTML:return Object.assign({},o,{htmlAttributes:Object.assign({},i)});default:return Object.assign({},o,((r={})[n.type]=Object.assign({},i),r))}},o.prototype.mapArrayTypeChildrenToProps=function(t,e){var r=Object.assign({},e);return Object.keys(t).forEach(function(e){var n;r=Object.assign({},r,((n={})[e]=t[e],n))}),r},o.prototype.warnOnInvalidChildren=function(t,r){return e(s.some(function(e){return t.type===e}),"function"==typeof t.type?"You may be attempting to nest <Helmet> components within each other, which is not allowed. Refer to our API for more information.":"Only elements types "+s.join(", ")+" are allowed. Helmet does not support rendering <"+t.type+"> elements. Refer to our API for more information."),e(!r||"string"==typeof r||Array.isArray(r)&&!r.some(function(t){return"string"!=typeof t}),"Helmet expects a string as a child of <"+t.type+">. Did you forget to wrap your children in braces? ( <"+t.type+">{``}</"+t.type+"> ) Refer to our API for more information."),!0},o.prototype.mapChildrenToProps=function(t,e){var r=this,o={};return n.Children.forEach(t,function(t){if(t&&t.props){var n=t.props,i=n.children,s=H(n,["children"]),c=Object.keys(s).reduce(function(t,e){return t[u[e]||e]=s[e],t},{}),l=t.type;switch("symbol"==typeof l?l=l.toString():r.warnOnInvalidChildren(t,i),l){case a.FRAGMENT:e=r.mapChildrenToProps(i,e);break;case a.LINK:case a.META:case a.NOSCRIPT:case a.SCRIPT:case a.STYLE:o=r.flattenArrayTypeChildren({child:t,arrayTypeChildren:o,newChildProps:c,nestedChildren:i});break;default:e=r.mapObjectTypeChildren({child:t,newProps:e,newChildProps:c,nestedChildren:i})}}}),this.mapArrayTypeChildrenToProps(o,e)},o.prototype.render=function(){var t=this.props,e=t.children,r=H(t,["children"]),o=Object.assign({},r);return e&&(o=this.mapChildrenToProps(e,o)),n.createElement(C.Consumer,null,function(t){return n.createElement(w,Object.assign({},o,{context:t}))})},o}(o);k.propTypes={base:r.object,bodyAttributes:r.object,children:r.oneOfType([r.arrayOf(r.node),r.node]),defaultTitle:r.string,defer:r.bool,encodeSpecialCharacters:r.bool,htmlAttributes:r.object,link:r.arrayOf(r.object),meta:r.arrayOf(r.object),noscript:r.arrayOf(r.object),onChangeClientState:r.func,script:r.arrayOf(r.object),style:r.arrayOf(r.object),title:r.string,titleAttributes:r.object,titleTemplate:r.string},k.defaultProps={defer:!0,encodeSpecialCharacters:!0},k.displayName="Helmet";export{k as Helmet,S as HelmetProvider};
|
|
//# sourceMappingURL=index.module.js.map
|