@martin-hillford/markdown-ts-react
Version:
This is a React wrapper for the markdown-ts library. Please, see <https://github.com/martin-hillford/markdown-ts> for more information on the supported syntax.
172 lines (152 loc) • 12.5 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@martin-hillford/markdown-ts"),N=require("react"),T=require("styled-components");var k={exports:{}},E={};/**
* @license React
* react-jsx-runtime.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var F;function ie(){if(F)return E;F=1;var r=Symbol.for("react.transitional.element"),n=Symbol.for("react.fragment");function o(a,l,i){var c=null;if(i!==void 0&&(c=""+i),l.key!==void 0&&(c=""+l.key),"key"in l){i={};for(var f in l)f!=="key"&&(i[f]=l[f])}else i=l;return l=i.ref,{$$typeof:r,type:a,key:c,ref:l!==void 0?l:null,props:i}}return E.Fragment=n,E.jsx=o,E.jsxs=o,E}var v={};/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var q;function ce(){return q||(q=1,process.env.NODE_ENV!=="production"&&function(){function r(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ae?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case j:return"Fragment";case Z:return"Profiler";case X:return"StrictMode";case re:return"Suspense";case ne:return"SuspenseList";case oe:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case B:return"Portal";case K:return(e.displayName||"Context")+".Provider";case Q:return(e._context.displayName||"Context")+".Consumer";case ee:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case te:return t=e.displayName||null,t!==null?t:r(e.type)||"Memo";case V:t=e._payload,e=e._init;try{return r(e(t))}catch{}}return null}function n(e){return""+e}function o(e){try{n(e);var t=!1}catch{t=!0}if(t){t=console;var s=t.error,u=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return s.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",u),n(e)}}function a(e){if(e===j)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===V)return"<...>";try{var t=r(e);return t?"<"+t+">":"<...>"}catch{return"<...>"}}function l(){var e=S.A;return e===null?null:e.getOwner()}function i(){return Error("react-stack-top-frame")}function c(e){if(M.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function f(e,t){function s(){L||(L=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}s.isReactWarning=!0,Object.defineProperty(e,"key",{get:s,configurable:!0})}function h(){var e=r(this.type);return U[e]||(U[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function x(e,t,s,u,p,g,P,A){return s=g.ref,e={$$typeof:Y,type:e,key:t,props:g,_owner:p},(s!==void 0?s:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:h}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:P}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:A}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function I(e,t,s,u,p,g,P,A){var d=t.children;if(d!==void 0)if(u)if(se(d)){for(u=0;u<d.length;u++)$(d[u]);Object.freeze&&Object.freeze(d)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else $(d);if(M.call(t,"key")){d=r(e);var _=Object.keys(t).filter(function(le){return le!=="key"});u=0<_.length?"{key: someKey, "+_.join(": ..., ")+": ...}":"{key: someKey}",D[d+u]||(_=0<_.length?"{"+_.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,u,d,_,d),D[d+u]=!0)}if(d=null,s!==void 0&&(o(s),d=""+s),c(t)&&(o(t.key),d=""+t.key),"key"in t){s={};for(var C in t)C!=="key"&&(s[C]=t[C])}else s=t;return d&&f(s,typeof e=="function"?e.displayName||e.name||"Unknown":e),x(e,d,g,p,l(),s,P,A)}function $(e){typeof e=="object"&&e!==null&&e.$$typeof===Y&&e._store&&(e._store.validated=1)}var y=N,Y=Symbol.for("react.transitional.element"),B=Symbol.for("react.portal"),j=Symbol.for("react.fragment"),X=Symbol.for("react.strict_mode"),Z=Symbol.for("react.profiler"),Q=Symbol.for("react.consumer"),K=Symbol.for("react.context"),ee=Symbol.for("react.forward_ref"),re=Symbol.for("react.suspense"),ne=Symbol.for("react.suspense_list"),te=Symbol.for("react.memo"),V=Symbol.for("react.lazy"),oe=Symbol.for("react.activity"),ae=Symbol.for("react.client.reference"),S=y.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,M=Object.prototype.hasOwnProperty,se=Array.isArray,O=console.createTask?console.createTask:function(){return null};y={"react-stack-bottom-frame":function(e){return e()}};var L,U={},z=y["react-stack-bottom-frame"].bind(y,i)(),H=O(a(i)),D={};v.Fragment=j,v.jsx=function(e,t,s,u,p){var g=1e4>S.recentlyCreatedOwnerStacks++;return I(e,t,s,!1,u,p,g?Error("react-stack-top-frame"):z,g?O(a(e)):H)},v.jsxs=function(e,t,s,u,p){var g=1e4>S.recentlyCreatedOwnerStacks++;return I(e,t,s,!0,u,p,g?Error("react-stack-top-frame"):z,g?O(a(e)):H)}}()),v}var W;function ue(){return W||(W=1,process.env.NODE_ENV==="production"?k.exports=ie():k.exports=ce()),k.exports}var b=ue();const de=r=>{const{markdown:n,options:o}=r,a=m.markdownToHtml(n,o);return b.jsx("div",{dangerouslySetInnerHTML:{__html:a}})},fe=r=>{const{url:n}=r;if(!n||n==="")return null;const o=m.getYouTubeId(n);if(!o)return null;const a=m.renderYoutube(o);return b.jsx("div",{dangerouslySetInnerHTML:{__html:a}})},me=r=>{const{url:n}=r;if(!n||n==="")return null;const o=m.getVimeoVideoId(n);if(!o)return null;const a=m.renderVimeo(o);return b.jsx("div",{dangerouslySetInnerHTML:{__html:a}})},ge=r=>{const{url:n}=r;if(!n||n==="")return null;const o=m.renderVideo(n);return b.jsx("div",{dangerouslySetInnerHTML:{__html:o}})},pe=r=>{const{text:n,styled:o,enabled:a,inline:l=[]}=r,i=l.map(f=>f.parser),c=_e(n,a,i);return be(l),N.useEffect(()=>()=>{var f;(f=document.getElementById("highlighter-style"))==null||f.remove()},[]),b.jsx(he,{spellCheck:!1,$styled:o,dangerouslySetInnerHTML:{__html:c}})},be=r=>{if(r.length===0)return;const n=r.map(a=>`span.${a.class} { color: ${a.color}; }`).join(`
`);let o=document.getElementById("highlighter-style");o||(o=document.createElement("style"),o.id="highlighter-style",document.head.appendChild(o)),o.innerHTML=n},he=T.div`
${r=>r.$styled};
width: 100%;
height: 100%;
font-family: 'ecs-editor-font', ui-monospace, 'Courier New', Courier, monospace;
span.header { color : #154879; }
span.bold { color: #154879; }
span.italic { color:#154879 }
span.emphasis { color:#154879 }
span.align { color:rgb(251, 0, 7)}
span.link { color:rgb(140, 3, 18) }
span.image { color:rgb(140, 3, 18) }
span.notes { color:rgb(140, 3, 18) }
span.notes { color:rgb(204, 119, 34) }
`,_e=(r,n,o)=>r?(n===!1||(r=Re(r),r=ye(r),r=Te(r),r=we(r),r=xe(r),r=je(r),r=ke(r),r=ve(r),o.forEach(a=>{r=J(r,a)})),r):"",J=(r,n)=>{if(!r)return"";const o=n.parse(r);return o===null?r:(o.head??"")+Ee(o)+J(o.tail,n)},Ee=r=>(r.render?r.render():null)??r.content??"",ve=r=>R(r,[/\[\^.+?]:/gm,/\[\^.+?]:/gm],"notes"),Te=r=>R(r,[/\[[^\n^\]?]+]\([^\n^)?]+\)/gm],"link"),ye=r=>R(r,[/!\[[^\n^\]?]*]\([^\n^)?]+\)/gm],"image"),ke=r=>R(r,[/^\[right]/gm,/^\[center]/gm,/^\[justify]/gm,/^\[clear]$/gm],"align"),Re=r=>w(r,[/^#{1,6} .+\n\n/gm,/^.+$\n-{3,}\n\n/gm,/^.+$\n={3,}\n\n/gm],"header",0,1),we=r=>w(r,[/[^*]\*{3}[^*^<]+?\*{3}[^*]/gm,/[^_]_{3}[^_^<]+?_{3}[^_]/gm],"emphasis",1,1),xe=r=>w(r,[/[^*]\*{2}[^*^<]+?\*{2}[^*]/gm,/[^_]_{2}[^_^<]+?_{2}[^_]/gm],"bold",1,1),je=r=>w(r,[/[^*]\*[^*^<]+?\*[^*]/gm,/[^_]_[^_^<]+?_[^_]/gm],"italic",1,1),R=(r,n,o)=>(n.forEach(a=>{r=r.replaceAll(a,`<span class="${o}">$&</span>`)}),r),w=(r,n,o,a,l)=>(n.forEach(i=>{r=r.replaceAll(i,c=>{const f=c.substring(0,a),h=c.substring(a,c.length-l),x=c.substring(c.length-l);return`${f}<span class="${o}">${h}</span>${x}`})}),r),Se=r=>{const{onCursorMove:n,highlighted:o,value:a,inline:l=[]}=r,i=N.useRef(null),c=()=>{if(!n||!i.current)return;const h={start:i.current.selectionStart,end:i.current.selectionEnd};n(h)},f=h=>{r.onChange(h.target.value),c()};return b.jsxs(Oe,{children:[b.jsx(pe,{inline:l,enabled:o,text:a+`
`,styled:G}),b.jsx(Pe,{spellCheck:!1,value:a,onChange:f,onKeyUp:c,onClick:c,ref:i})]})},Oe=T.div`
padding:0;
width:100%;
position: relative;
`,G=T.css`
padding: 15px;
box-sizing: border-box;
font-size: 14px;
border:0;
margin:0;
white-space: pre-wrap;
min-height:25px;
`,Pe=T.textarea`
${G}
&:focus { outline: none; }
&:-internal-autofill-selected { outline: none; }
font-family: 'ecs-editor-font', ui-monospace, 'Courier New', Courier, monospace;
content: attr(data-replicated-value) " ";
display: block;
resize: none;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background-color: transparent;
top: 0;
left: 0;
right: 0;
bottom: 0;
color: transparent;
caret-color: black;
`,Ae=T.div`
font-family: "Roboto", "Helvetica Neue", ui-sans-serif, Helvetica, Arial, sans-serif;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 300;
overflow-wrap: break-word;
-webkit-font-smoothing: antialiased;
letter-spacing: 1px;
color: #3d3d3d;
img {
max-width: calc(100vw - 220px);
}
ul, ol {
padding-inline-start: 20px;
}
h1, h2, h3, h4, h5, h6 {
color: #3d3d3d;
}
h1, h2, h3, h4 {
font-weight: 100;
text-align: center;
word-break: break-word;
hyphens: auto;
}
h1, h2 {
font-size: 2.8rem;
margin: 2.4rem 0;
line-height: 4.2rem;
}
h3 {
font-size: 2rem;
margin: 1.8rem 0;
line-height: 3rem;
}
h4 {
font-size: 1.25rem;
font-weight: bold;
line-height: 1.875rem;
letter-spacing: 1px;
}
h5 {
font-size: 1rem;
font-weight: bold;
line-height: 1.5rem;
letter-spacing: 1px;
}
code {
padding:2px;
background-color:lightgray;
font-family: 'Courier New', Courier, monospace;
}
blockquote {
border-left: 2px solid #3fab49;
margin: 0 0 2rem;
padding: 0 16px;
clear:both;
}
a.reference, a.footnote {
color : #0c497a;
text-decoration: none;
}
table {
border : 1px solid rgba(0, 0, 0, 0.1);
border-spacing: 0;
border-collapse: collapse;
margin: 14px 0;
tr.header td {
background-color: #0c497a;
color:white
}
td {
padding: 2px 6px;
border : 1px solid rgba(0, 0, 0, 0.1);
}
}
img {
padding-top: 1rem;
padding-bottom: 1rem;
}
div.footnote {
font-size: 12px;
}
`;Object.defineProperty(exports,"getVimeoUrl",{enumerable:!0,get:()=>m.getVimeoUrl});Object.defineProperty(exports,"getVimeoVideoId",{enumerable:!0,get:()=>m.getVimeoVideoId});Object.defineProperty(exports,"getYouTubeId",{enumerable:!0,get:()=>m.getYouTubeId});Object.defineProperty(exports,"getYouTubeUrl",{enumerable:!0,get:()=>m.getYouTubeUrl});Object.defineProperty(exports,"isVimeoUrl",{enumerable:!0,get:()=>m.isVimeoUrl});Object.defineProperty(exports,"markdownToHtml",{enumerable:!0,get:()=>m.markdownToHtml});exports.BaseStyle=Ae;exports.MarkDown=de;exports.TextEditor=Se;exports.Video=ge;exports.Vimeo=me;exports.YouTube=fe;
//# sourceMappingURL=index.cjs.js.map