UNPKG

botscripten

Version:

Craft rich bot conversations using the Twine/Twee format

31 lines (18 loc) 26 kB
<!doctype html><html><head><title>Test</title><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"></head><body><twine><!-- UUID://3A31AA6F-EF9A-43B1-BF53-08AF770247A8// --><tw-storydata name="Test" startnode="1" creator="Tweego" creator-version="2.0.0+089d4ca77e5b" ifid="3A31AA6F-EF9A-43B1-BF53-08AF770247A8" zoom="1" format="Botscripten" format-version="1.0.0" options="" hidden><style role="stylesheet" id="twine-user-stylesheet" type="text/twine-css"></style><script role="script" id="twine-user-script" type="text/twine-javascript"></script><tw-passagedata pid="1" name="Start" tags="speaker-bot wait" position="412,189" size="100,100">Hey there! I&#39;m the chat bot, and this is a demo! [[A demo?]]</tw-passagedata><tw-passagedata pid="2" name="A demo?" tags="speaker-bot" position="412,339" size="100,100">Yep! A demo! With choices! [[Choices are neat -&gt; Choice Good]] [[I&#39;m not a fan -&gt; Choice Bad]]</tw-passagedata><tw-passagedata pid="3" name="Choice Good" tags="speaker-bot" position="337,489" size="100,100">#@set choice good Oh, that&#39;s great! I like having choices too. [[Directives]]</tw-passagedata><tw-passagedata pid="4" name="Choice Bad" tags="speaker-bot" position="487,489" size="100,100">#@set choice bad Oh no. Well, at least there was only one of them! [[Directives]]</tw-passagedata><tw-passagedata pid="5" name="Directives" tags="speaker-bot wait" position="412,634" size="100,100">See that block above with the #@ symbol? That&#39;s a directive. Directives are how you can tell your scripting system to **DO** more than just chat like a bot. In this case, we told our scripting engine we wanted to set the &quot;choice&quot; var. [[Does it always go on one line?]]</tw-passagedata><tw-passagedata pid="6" name="Does it always go on one line?" tags="speaker-bot" position="412,784" size="100,100">###@sql SELECT * FROM users WHERE username = &quot;chatbot&quot; ### Not really. The above part is a &quot;Block Directive&quot; and everything inside is treated as a single statement. [[So, how does it run?]]</tw-passagedata><tw-passagedata pid="7" name="So, how does it run?" tags="speaker-bot" position="412,934" size="100,100">That&#39;s the fun part. It&#39;s up to you. Botscripten is meant to make it easy to put together guided conversations. You can use your own directive language to run queries, ask open ended questions, or do whatever techno-wizardry suits you. Go forth and build!</tw-passagedata></tw-storydata></twine><nav><div id="nav-reset"><h1>Test</h1><div id="toggles"><label><input type="checkbox" name="show_directives" id="show_directives" checked="checked">show directives</label><label><input type="checkbox" name="proofing" id="proofing">show proofing</label></div></div></nav><section id="runtime"><main id="chat-panel"><div id="passages"><div id="history"></div><div id="active-passage"></div><div id="animation-container"><div class="chat-passage-wrapper"><div class="chat-passage"><div class="wave"><span class="dot"></span><span class="dot"></span><span class="dot"></span></div></div></div></div></div><div id="user-response-wrapper"><div id="user-response-panel"></div></div></main></section><style>:root{--nav-height:46px;--nav-buffer:10px;--max-width:768px;--bg-color:#4d5263;--user-color:#7aaebb;--speaker-color:rgb( 136, 136, 136 );--directive-border:#c3c3c3;--navbar-bg-color:#fff;--passage-bg-color:#fff;--passage-text-color:#222}body{font-family:"Lucida Sans","Lucida Sans Regular","Lucida Grande","Lucida Sans Unicode",Geneva,Verdana,sans-serif;font-size:16px;margin:0;padding:0}body.proof twine{padding:50px;font-size:12px}#twine-user-script,#twine-user-stylesheet,.proof #runtime main,.proof #user-response-panel,twine{display:none!important}.proof twine,.proof twine *{display:block!important;font-family:monospace;white-space:pre}nav{position:fixed;z-index:1;height:var(--nav-height);background:var(--navbar-bg-color);width:100vw;max-width:var(--max-width);top:0;border:5px solid var(--speaker-color);border-top:0;border-left:0;border-right:0}nav h1{margin:0;font-size:26px;padding:10px 1em 0 1em;line-height:26px}#nav-reset{position:relative}#toggles{position:absolute;right:1em;top:50%}#toggles label{margin-left:1em}#runtime,twine{margin-top:var(--nav-height)}.proof tw-storydata::before{content:":: StoryTitle\A"attr(name);color:green}.proof tw-passagedata::before{content:":: " attr(name) " [" attr(tags) "]";color:#00f;margin:1em 0 0 0;display:block;font-weight:700}.proof tw-passagedata.start::before{content:"🚀 :: " attr(name) " [" attr(tags) "]"}.proof tw-passagedata+tw-passagedata{border-top:1pt dashed #000;padding:1em 0;margin:1em 0 0 0}.proof #runtime{position:absolute;top:0}#runtime{display:flex;flex-direction:column;height:calc(100vh - var(--nav-height));max-height:calc(100% - var(--nav-height));max-width:var(--max-width)}#runtime main{flex:1 1 auto;background-color:var(--bg-color);padding:var(--nav-buffer) 15px 15px 15px}.chat-passage-reset{position:relative}.chat-passage:before{content:attr(data-speaker);display:block;font-size:.75rem;text-transform:capitalize;color:var(--speaker-color)}.chat-passage{background:var(--passage-bg-color);margin:0 0 1em 0;padding:.33em}.chat-passage p{margin:0}.chat-passage-wrapper{display:flex;flex-direction:row}.chat-passage-wrapper[data-speaker=you]{flex-direction:row-reverse}.chat-passage-wrapper .chat-passage{margin-left:45px}.chat-passage-wrapper[data-speaker=you] .chat-passage{margin-right:45px}.chat-passage-wrapper:before{margin-right:5px;position:absolute;vertical-align:top;content:"";width:30px;height:30px;background-size:30px 30px;border-radius:15px;background-color:var(--speaker-color)}.chat-passage-wrapper[data-speaker=you]:before{display:none}.chat-passage-wrapper[data-speaker=you]:after{margin-left:-30px;position:absolute;top:0;right:0;vertical-align:top;content:"";width:30px;height:30px;background-size:30px 30px;border-radius:15px;background-color:var(--user-color)}body.show-directives .directives{display:block}.directives{display:none;font-family:Consolas,"Andale Mono WT","Andale Mono","Lucida Console","Lucida Sans Typewriter","DejaVu Sans Mono","Bitstream Vera Sans Mono","Liberation Mono","Nimbus Mono L",Monaco,"Courier New",Courier,monospace;font-size:12px}.directive{white-space:pre;border:1px dashed var(--directive-border);position:relative;overflow-x:auto;padding-top:20px;color:var(--passage-bg-color);margin-bottom:1em}.directive::after{content:attr(name);position:absolute;right:2px;top:2px;font-weight:700;font-size:14px;letter-spacing:.2em;color:var(--passage-bg-color)}#user-response-wrapper{padding-right:15px;padding-left:15px;flex:1 1 auto;display:flex;flex-direction:column;justify-content:end;border-top:3px solid var(--directive-border)}#user-response-panel{height:100px;display:flex;flex-direction:row;align-items:center;justify-content:center}#user-response-panel .user-response{display:inline-block;padding:.5rem;margin:.25rem;background-color:#fff;color:#333;border-top:2px solid transparent;transition:border-color .15s ease-in}#user-response-panel .user-response:hover{text-decoration:none;border-color:var(--user-color)}#animation-container .wave{position:relative;text-align:center;margin-left:auto;margin-right:auto}#animation-container .dot{display:inline-block;width:6px;height:6px;border-radius:50%;margin-right:2px;background:var(--passage-text-color);animation:wave 1.2s ease-in-out infinite}#animation-container .dot:nth-child(2){animation-delay:.1s}#animation-container .dot:nth-child(3){animation-delay:.2s}@keyframes wave{0%,100%,50%{transform:initial}25%{transform:translateY(-15px)}}</style><script>!function(t){"function"==typeof define&&define.amd?define(t):t()}(function(){"use strict";var a=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")};var s=function(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t};var e=function(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e<t.length;e++)r[e]=t[e];return r}};var r=function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)};var n=function(){throw new TypeError("Invalid attempt to spread non-iterable instance")};var c=function(t){return e(t)||r(t)||n()},t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var o,d=(function(t){var e=function(i){var c,t=Object.prototype,u=t.hasOwnProperty,e="function"==typeof Symbol?Symbol:{},o=e.iterator||"@@iterator",r=e.asyncIterator||"@@asyncIterator",n=e.toStringTag||"@@toStringTag";function a(t,e,r,n){var i,a,s,c,o=e&&e.prototype instanceof g?e:g,u=Object.create(o.prototype),l=new k(n||[]);return u._invoke=(i=t,a=r,s=l,c=h,function(t,e){if(c===p)throw new Error("Generator is already running");if(c===v){if("throw"===t)throw e;return P()}for(s.method=t,s.arg=e;;){var r=s.delegate;if(r){var n=E(r,s);if(n){if(n===y)continue;return n}}if("next"===s.method)s.sent=s._sent=s.arg;else if("throw"===s.method){if(c===h)throw c=v,s.arg;s.dispatchException(s.arg)}else"return"===s.method&&s.abrupt("return",s.arg);c=p;var o=f(i,a,s);if("normal"===o.type){if(c=s.done?v:d,o.arg===y)continue;return{value:o.arg,done:s.done}}"throw"===o.type&&(c=v,s.method="throw",s.arg=o.arg)}}),u}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}i.wrap=a;var h="suspendedStart",d="suspendedYield",p="executing",v="completed",y={};function g(){}function s(){}function l(){}var m={};m[o]=function(){return this};var b=Object.getPrototypeOf,w=b&&b(b(T([])));w&&w!==t&&u.call(w,o)&&(m=w);var x=l.prototype=g.prototype=Object.create(m);function L(t){["next","throw","return"].forEach(function(e){t[e]=function(t){return this._invoke(e,t)}})}function O(c){var e;this._invoke=function(r,n){function t(){return new Promise(function(t,e){!function e(t,r,n,o){var i=f(c[t],c,r);if("throw"!==i.type){var a=i.arg,s=a.value;return s&&"object"==typeof s&&u.call(s,"__await")?Promise.resolve(s.__await).then(function(t){e("next",t,n,o)},function(t){e("throw",t,n,o)}):Promise.resolve(s).then(function(t){a.value=t,n(a)},function(t){return e("throw",t,n,o)})}o(i.arg)}(r,n,t,e)})}return e=e?e.then(t,t):t()}}function E(t,e){var r=t.iterator[e.method];if(r===c){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=c,E(t,e),"throw"===e.method))return y;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var n=f(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,y;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=c),e.delegate=null,y):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,y)}function j(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function S(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function k(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(j,this),this.reset(!0)}function T(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,n=function t(){for(;++r<e.length;)if(u.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=c,t.done=!0,t};return n.next=n}}return{next:P}}function P(){return{value:c,done:!0}}return s.prototype=x.constructor=l,l.constructor=s,l[n]=s.displayName="GeneratorFunction",i.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===s||"GeneratorFunction"===(e.displayName||e.name))},i.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,n in t||(t[n]="GeneratorFunction")),t.prototype=Object.create(x),t},i.awrap=function(t){return{__await:t}},L(O.prototype),O.prototype[r]=function(){return this},i.AsyncIterator=O,i.async=function(t,e,r,n){var o=new O(a(t,e,r,n));return i.isGeneratorFunction(e)?o:o.next().then(function(t){return t.done?t.value:o.next()})},L(x),x[n]="Generator",x[o]=function(){return this},x.toString=function(){return"[object Generator]"},i.keys=function(r){var n=[];for(var t in r)n.push(t);return n.reverse(),function t(){for(;n.length;){var e=n.pop();if(e in r)return t.value=e,t.done=!1,t}return t.done=!0,t}},i.values=T,k.prototype={constructor:k,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=c,this.done=!1,this.delegate=null,this.method="next",this.arg=c,this.tryEntries.forEach(S),!t)for(var e in this)"t"===e.charAt(0)&&u.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=c)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var n=this;function t(t,e){return i.type="throw",i.arg=r,n.next=t,e&&(n.method="next",n.arg=c),!!e}for(var e=this.tryEntries.length-1;0<=e;--e){var o=this.tryEntries[e],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var a=u.call(o,"catchLoc"),s=u.call(o,"finallyLoc");if(a&&s){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;0<=r;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&u.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,y):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),y},finish:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),S(r),y}},catch:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;S(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:T(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=c),y}},i}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}(o={exports:{}}),o.exports);function u(t,e,r,n,o,i,a){try{var s=t[i](a),c=s.value}catch(t){return void r(t)}s.done?e(c):Promise.resolve(c).then(n,o)}var i=function(s){return function(){var t=this,a=arguments;return new Promise(function(e,r){var n=s.apply(t,a);function o(t){u(n,e,r,o,i,"next",t)}function i(t){u(n,e,r,o,i,"throw",t)}o(void 0)})}},l=1/0,f="[object Symbol]",h=/&(?:amp|lt|gt|quot|#39|#96);/g,p=RegExp(h.source),v="object"==typeof t&&t&&t.Object===Object&&t,y="object"==typeof self&&self&&self.Object===Object&&self,g=v||y||Function("return this")();var m,b=(m={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'","&#96;":"`"},function(t){return null==m?void 0:m[t]}),w=Object.prototype.toString,x=g.Symbol,L=x?x.prototype:void 0,O=L?L.toString:void 0;function E(t){if("string"==typeof t)return t;if("symbol"==typeof(e=t)||function(t){return t&&"object"==typeof t}(e)&&w.call(e)==f)return O?O.call(t):"";var e,r=t+"";return"0"==r&&1/t==-l?"-0":r}var j=function(t){var e;return(t=null==(e=t)?"":E(e))&&p.test(t)?t.replace(h,b):t},S=/^###@([\S]+)([\s\S]*?)###/gm,k=/^#@([\S]+)(.*)$/gm,T=/\[\[(.*?)\]\]/gm,P="__TOKEN_ESCAPED_BACKSLASH_OCTO__",_=/###[\s\S]*?###/gm,A=/^#.*$/gm;function M(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function H(r){var t=r.source,e=function(t){var n=[];for(t=t.replace("\\#","__TOKEN_ESCAPED_BACKSLASH_OCTO__");t.match(S);)t=t.replace(S,function(t,e,r){return n.push({name:"@".concat(e),content:r.trim()}),""});for(;t.match(k);)t=t.replace(k,function(t,e,r){return n.push({name:"@".concat(e),content:r.trim()}),""});return n}(t),n=t.replace("\\#",P).replace(_,"").replace(A,"").replace(P,"#").trim();r&&(r.links=[]);var o=function(t){for(var s=[],e=t;t.match(T);)t=t.replace(T,function(t,e){var r=e,n=e,o=e.indexOf("|"),i=e.indexOf("->"),a=e.indexOf("<-");switch(!0){case 0<=o:r=e.substr(0,o),n=e.substr(o+1);break;case 0<=i:r=e.substr(0,i),n=e.substr(i+2);break;case 0<=a:r=e.substr(a+2),n=e.substr(0,a)}return s.push({display:r,target:n}),""});return{links:s,updated:t,original:e}}(n);if(n=o.updated,r&&(r.links=o.links),e.forEach(function(e){r.story.directives[e.name]&&r.story.directives[e.name].forEach(function(t){n=t(e.content,n,r,r.story)})}),!r.getSpeaker())return{directives:e,text:[]};if(r){var i=r.prefixTag("prompt");i.length&&r.story.prompt(i[0])}return r.hasTag("oneline")?{directives:e,text:[n]}:{directives:e,text:(n=n.trim()).split(/[\r\n]+/g)}}function C(t,e,r,n,o){var i=this;a(this,C),s(this,"id",null),s(this,"name",null),s(this,"tags",null),s(this,"tagDict",{}),s(this,"source",null),s(this,"links",[]),s(this,"getSpeaker",function(){var t=i.tags.find(function(t){return 0===t.indexOf("speaker-")})||"";return t?t.replace(/^speaker-/,""):null}),s(this,"prefixTag",function(e,r){return i.tags.filter(function(t){return 0===t.indexOf("".concat(e,"-"))}).map(function(t){return t.replace("".concat(e,"-"),"")}).reduce(function(t,e){return r?function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?M(Object(r),!0).forEach(function(t){s(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):M(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}({},t,s({},e,1)):[].concat(c(t),[e])},r?{}:[])}),s(this,"hasTag",function(t){return i.tagDict[t]}),s(this,"render",function(){return H(i)}),this.id=t,this.name=e,this.tags=r,this.source=j(n),this.story=o,this.tags.forEach(function(t){return i.tagDict[t]=1})}s(C,"render",function(t){return H(new C(null,null,null,t,(e=window||null)&&e.story?e.story:{state:{}}));var e});var D=1/0,q="[object Symbol]",N=/[&<>"'`]/g,F=RegExp(N.source),G="object"==typeof t&&t&&t.Object===Object&&t,B="object"==typeof self&&self&&self.Object===Object&&self,I=G||B||Function("return this")();var K,R=(K={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","`":"&#96;"},function(t){return null==K?void 0:K[t]}),$=Object.prototype.toString,U=I.Symbol,Y=U?U.prototype:void 0,z=Y?Y.toString:void 0;function J(t){if("string"==typeof t)return t;if("symbol"==typeof(e=t)||function(t){return t&&"object"==typeof t}(e)&&$.call(e)==q)return z?z.call(t):"";var e,r=t+"";return"0"==r&&1/t==-D?"-0":r}function Q(t,e){return t.querySelector(e)}function V(t,e){return c(t.querySelectorAll(e))||[]}function W(t,e){var h=this;a(this,W),s(this,"version",2),s(this,"document",null),s(this,"story",null),s(this,"name",""),s(this,"startsAt",0),s(this,"current",0),s(this,"history",[]),s(this,"passages",{}),s(this,"showPrompt",!1),s(this,"errorMessage","⚠ %s"),s(this,"directives",{}),s(this,"elements",{}),s(this,"userScripts",[]),s(this,"userStyles",[]),s(this,"start",function(){h.userStyles.forEach(function(t){var e=h.document.createElement("style");e.innerHTML=t,h.document.body.appendChild(e)}),h.userScripts.forEach(function(t){globalEval(t)}),h.document.body.addEventListener("click",function(t){t.target.matches("#user-response-panel a[data-passage]")&&h.advance(h.findPassage(t.target.getAttribute("data-passage")),t.target.innerHTML)}),h.document.body.addEventListener("click",function(t){if(t.target.matches("#user-response-panel button[data-passage]")){var e=Q(h.document,"#user-response-panel input").value;h.showPrompt=!1,h.advance(h.findPassage(t.target.getAttribute("data-passage")),e)}}),h.advance(h.findPassage(h.startsAt))}),s(this,"findPassage",function(e){if(e="".concat(e).trim(),t=e,nt.test(t))return h.passages[e];var t,r=V(h.story,"tw-passagedata").filter(function(t){return j(t.getAttribute("name")).trim()===e})[0];return r?h.passages[r.getAttribute("pid")]:null}),s(this,"advance",function(){var e=i(d.mark(function t(e){var r,n,o,i=arguments;return d.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=1<i.length&&void 0!==i[1]?i[1]:null,h.history.push(e.id),n=h.current,o=h.elements.active.innerHTML,h.elements.active.innerHTML="",h.elements.history.innerHTML+=o,r&&h.renderUserMessage(n,r,function(t){return h.elements.history.innerHTML+=t}),t.next=9,h.renderPassage(e,function(t){return h.elements.active.innerHTML+=t});case 9:if(e.hasTag("wait")||1!==e.links.length){t.next=12;break}return h.advance(h.findPassage(e.links[0].target)),t.abrupt("return");case 12:h.renderChoices(e);case 13:case"end":return t.stop()}},t)}));return function(t){return e.apply(this,arguments)}}()),s(this,"renderUserMessage",function(){var n=i(d.mark(function t(o,i,a){return d.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,a((0,r=(e={id:o,text:i}).id,n=e.text,'\n <div class="chat-passage-reset">\n <div class="chat-passage-wrapper" data-speaker="you">\n <div class="chat-passage" data-speaker="you" data-upassage="'.concat(r,'">\n ').concat(n,"\n </div>\n </div>\n </div>\n")));case 2:return h.scrollToBottom(),t.abrupt("return",Promise.resolve());case 4:case"end":return t.stop()}var e,r,n},t)}));return function(t,e,r){return n.apply(this,arguments)}}()),s(this,"renderPassage",function(){var r=i(d.mark(function t(a,s){var c,u,l,f;return d.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return c=a.getSpeaker(),u=a.render(),console.log(u.directives),t.next=5,s((i=u.directives,'\n <div class="directives">\n '.concat(i.map(function(t){var e=t.name,r=t.content;return'<div class="directive" name="'.concat(e,'">').concat(r.trim(),"</div>")}).join(""),"\n </div>\n")));case 5:l=u.text.shift(),h.showTyping();case 7:if(l)return e={speaker:c,tags:a.tags,text:l},n=void 0,r=e.speaker,n=e.tags,o=e.text,f='\n <div class="chat-passage-reset">\n <div data-speaker="'.concat(r,'" class="chat-passage-wrapper ').concat(n.join(" "),'">\n <div data-speaker="').concat(r,'" class="chat-passage">\n ').concat(o,"\n </div>\n </div>\n </div>\n"),t.next=11,ot(h.calculateDelay(l));t.next=16;break;case 11:return t.next=13,s(f);case 13:l=u.text.shift(),t.next=7;break;case 16:return h.hideTyping(),h.scrollToBottom(),t.abrupt("return",Promise.resolve());case 19:case"end":return t.stop()}var e,r,n,o,i},t)}));return function(t,e){return r.apply(this,arguments)}}()),s(this,"calculateDelay",function(t){return 20*t.length*.3}),s(this,"showTyping",function(){Q(h.document,rt).style.visibility="visible"}),s(this,"hideTyping",function(){Q(h.document,rt).style.visibility="hidden"}),s(this,"scrollToBottom",function(){var t=Q(h.document,tt);document.scrollingElement.scrollTop=t.offsetHeight}),s(this,"removeChoices",function(){Q(h.document,et).innerHTML=""}),s(this,"renderChoices",function(t){h.removeChoices();var e=Q(h.document,et);t.links.forEach(function(t){e.innerHTML+='<a href="javascript:void(0)" class="user-response" data-passage="'.concat(Z(t.target),'">').concat(t.display,"</a>")})}),s(this,"directive",function(t,e){h.directives[t]||(h.directives[t]=[]),h.directives[t].push(e)}),this.window=t,this.document=e?document.implementation.createHTMLDocument("Botscripten Injected Content"):document,this.story=Q(this.document,"tw-storydata"),this.elements={active:Q(this.document,"#active-passage"),history:Q(this.document,tt)},this.name=this.story.getAttribute("name")||"",this.startsAt=this.story.getAttribute("startnode")||0,V(this.story,"tw-passagedata").forEach(function(t){var e=parseInt(t.getAttribute("pid")),r=t.getAttribute("name"),n=(t.getAttribute("tags")||"").split(/\s+/g),o=t.innerHTML||"";h.passages[e]=new C(e,r,n,o,h)}),Q(this.document,"title").innerHTML=this.name,this.userScripts=(V(this.document,'*[type="text/twine-javascript"]')||[]).map(function(t){return t.innerHTML}),this.userStyles=(V(this.document,'*[type="text/twine-css"]')||[]).map(function(t){return t.innerHTML})}var X,Z=function(t){var e;return(t=null==(e=t)?"":J(e))&&F.test(t)?t.replace(N,R):t},tt="#history",et="#user-response-panel",rt="#animation-container",nt=/^[\d]+$/,ot=function(){var t=i(d.mark(function t(){var e,r=arguments;return d.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=0<r.length&&void 0!==r[0]?r[0]:0,t.abrupt("return",new Promise(function(t){return setTimeout(t,e)}));case 2:case"end":return t.stop()}},t)}));return function(){return t.apply(this,arguments)}}();void 0!==(X=window||void 0)&&(X.document.addEventListener("DOMContentLoaded",function(t){X.globalEval=eval,X.story=new W(X),X.story.start(),X.document.querySelector("#show_directives").checked&&X.document.body.classList.add("show-directives"),X.document.querySelector("#proofing").checked?X.document.body.classList.add("proof"):X.document.body.classList.add("run")}),X.document.querySelector("#show_directives").addEventListener("change",function(t){t.target.checked?X.document.body.classList.add("show-directives"):X.document.body.classList.remove("show-directives")}),X.document.querySelector("#proofing").addEventListener("change",function(t){t.target.checked?(X.document.body.classList.add("proof"),X.document.body.classList.remove("run")):(X.document.body.classList.add("run"),X.document.body.classList.remove("proof"))}),document.querySelector("tw-passagedata[pid='"+document.querySelector("tw-storydata").getAttribute("startnode")+"']").classList.add("start"))});</script></body></html>