diff --git a/.gitignore b/.gitignore index 2837cc3..2d94de1 100644 --- a/.gitignore +++ b/.gitignore @@ -80,7 +80,6 @@ typings/ # Nuxt.js build / generate output .nuxt -dist # Gatsby files .cache/ diff --git a/dist/macro.min.js b/dist/macro.min.js new file mode 100644 index 0000000..13e7e55 --- /dev/null +++ b/dist/macro.min.js @@ -0,0 +1,3 @@ +// Harlowe Macro Framework, by Chapel; version 0.4.0 +;!function(){"use strict";var r=Object.freeze({major:0,minor:4,patch:0,semantic:function(){return[this.major,this.minor,this.patch].join(".")}}),e=$("tw-storydata"),t=Object.freeze({name:e.attr("name"),ifid:e.attr("ifid")}),n=e.attr("format-version"),a=n.split("."),o=Object.freeze({major:a[0],minor:a[1],patch:a[2],semantic:n});window.Harlowe=window.Harlowe||{},window.Harlowe=Object.assign(window.Harlowe,{version:r,API_ACCESS:Object.freeze({MACROS:require("macros"),STATE:require("state"),CHANGER:require("datatypes/changercommand"),ENGINE:require("engine")}),engine:o,story:t})}(),function(){"use strict";window.Harlowe=Object.assign(window.Harlowe,{helpers:{isSerialisable:function r(e){return"number"==typeof e||"boolean"==typeof e||"string"==typeof e||null===e||Array.isArray(e)&&e.every(r)||e instanceof Set&&Array.from(e).every(r)||e instanceof Map&&Array.from(e.values()).every(r)||_changer.isPrototypeOf(e)},arrayify:function(r,e){if(r){var t=[].slice.call(r);return void 0!==e&&(t=t.slice(e)),t}},getPassageData:function(r){var e=$('tw-passagedata[name="'+r+'"]');if(e[0])return e}}})}(),function(){"use strict";var a=window.localStorage||!1,o=Harlowe.story.ifid+"-tw-storage";function r(){try{if(!a)throw new Error("storage is inaccessible");a.setItem(o,JSON.stringify({ifid:Harlowe.story.ifid}))}catch(r){console.warn(r)}}function i(r){try{var e;if(a)return e=JSON.parse(a.getItem(o)),r&&"string"==typeof r?e[r]:e;throw new Error("storage is inaccessible")}catch(r){console.warn(r)}}void 0===i()&&r(),Harlowe.storage={clear:r,save:function(r,e){try{if(!r||"string"!=typeof r)throw new TypeError("cannot store values without a valid storage key");if(void 0===e)throw new TypeError("cannot store undefined values");var t={};if(t[r]=e,!a)throw new Error("storage is inaccessible");var n=i();Object.assign(n,t),a.setItem(o,JSON.stringify(n))}catch(r){console.warn(r)}},load:i,remove:function(r){try{if(!r||"string"!=typeof r)throw new TypeError("cannot store values without a valid storage key");if(!a)throw new Error("storage is inaccessible");var e=i();e.hasOwnProperty(r)&&(delete e[r],a.setItem(o,JSON.stringify(e)))}catch(r){console.warn(r)}}}}(),function(){"use strict";function n(r,e,t){if(!(this instanceof n))return new n(r,e,t);this.name=r||"unknown",this.args=e||[],this.data=t||{},this.type=t&&t.type||"basic",this.fn=t&&t.fn||"handler","changer"===this.type&&("handler"===this.fn?this.instance=t&&t.instance||null:this.descriptor=t&&t.descriptor||null)}n.create=function(r,e,t){if(!r||"string"!=typeof r||!r.trim())throw new TypeError("Invalid macro name.");return e&&e instanceof Array||(e=[]),t&&"object"==typeof t||(t={type:"basic",fn:"handler"}),new n(r,e,t)},Object.assign(n.prototype,{clone:function(){return n.create(this.name,this.args,this.data)},syntax:function(){return"("+this.name+":)"},error:function(r,e){var t="Error in the "+this.syntax()+" macro: "+r;return e&&alert(t),console.warn("HARLOWE CUSTOM MACRO ERROR -> ",t),new Error(r)},typeCheck:function(r){r&&r instanceof Array||(r=Harlowe.helpers.arrayify(arguments));var a=this,o=[];if(r.forEach(function(r,e){var t=e+1,n=[];"string"==typeof r&&("any"===(n=r.includes("|")?r.split("|").map(function(r){return r.trim().toLowerCase()}):[r.trim().toLowerCase()])[0]||n.some(function(r){return typeof a.args[e]===r})||o.push("argument "+t+" should be a(n) "+n.join(" or ")))}),o.length)return a.error(o.join("; "))}}),window.Harlowe=Object.assign(window.Harlowe,{MacroContext:n})}(),function(){"use strict";var c=Harlowe.API_ACCESS.MACROS,f=Harlowe.API_ACCESS.CHANGER;window.Harlowe=Object.assign(window.Harlowe||{},{macro:function(r,e,t){if(!r||"string"!=typeof r||!r.trim())throw new TypeError("Invalid macro name.");if(!e||"function"!=typeof e)throw new TypeError("Invalid macro handler.");var n,a,o,i,s;t&&"function"==typeof t?(o=r,i=e,s=t,c.addChanger(o,function(){var r=Harlowe.helpers.arrayify(arguments,1),e=f.create(o,r),t=Harlowe.MacroContext.create(o,r,{type:"changer",fn:"handler",instance:e});return i.apply(t,r),e},function(){var r=Harlowe.helpers.arrayify(arguments),e=r.shift(),t=Harlowe.MacroContext.create(o,r,{type:"changer",fn:"changer",descriptor:e});s.apply(t,r)},c.TypeSignature.zeroOrMore(c.TypeSignature.Any))):(n=r,a=e,c.add(n,function(){var r=Harlowe.helpers.arrayify(arguments,1),e=Harlowe.MacroContext.create(n,r,{type:"basic",fn:"handler"}),t=a.apply(e,r);return null==t?"":t},c.TypeSignature.zeroOrMore(c.TypeSignature.Any)))}})}(),function(){"use strict";var t=Harlowe.API_ACCESS.STATE,e=Harlowe.API_ACCESS.ENGINE;function n(){return t.passage}window.Harlowe=Object.assign(window.Harlowe||{},{passage:n,tags:function(r){r=r||n();try{var e=Harlowe.helpers.getPassageData(r).attr("tags");return e?e.split(" "):[]}catch(r){return console.warn(r.message),[]}},goto:function(r){return e.goToPassage(r)},variable:function(r,e){if("$"!==r[0])throw new Error('cannot access variable "'+r+'"');if(r=r.substr(1),void 0!==e){if(!Harlowe.helpers.isSerialisable(e))throw new Error('The value passed to variable "'+r+'" cannot be serialized.');t.variables[r]=e}return t.variables[r]},visited:function(r){return t.passageNameVisited(r||n())},hasVisited:function(r){return 0