UNPKG

prismic.io

Version:

JavaScript development kit for prismic.io

2 lines 174 kB
!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n||e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){(function(global){"use strict";function Api(url,options){var opts=options||{};return this.accessToken=opts.accessToken,this.url=url+(this.accessToken?(url.indexOf("?")>-1?"&":"?")+"access_token="+this.accessToken:""),this.req=opts.req,this.apiCache=opts.apiCache||globalCache(),this.requestHandler=opts.requestHandler||Requests.request,this.apiCacheKey=this.url+(this.accessToken?"#"+this.accessToken:""),this.apiDataTTL=opts.apiDataTTL||5,this}function Form(name,fields,form_method,rel,enctype,action){this.name=name,this.fields=fields,this.form_method=form_method,this.rel=rel,this.enctype=enctype,this.action=action}function SearchForm(api,form,data){this.api=api,this.form=form,this.data=data||{};for(var field in form.fields)form.fields[field].default&&(this.data[field]=[form.fields[field].default])}function Response(page,results_per_page,results_size,total_results_size,total_pages,next_page,prev_page,results){this.page=page,this.results_per_page=results_per_page,this.results_size=results_size,this.total_results_size=total_results_size,this.total_pages=total_pages,this.next_page=next_page,this.prev_page=prev_page,this.results=results}function Ref(ref,label,isMaster,scheduledAt,id){this.ref=ref,this.label=label,this.isMaster=isMaster,this.scheduledAt=scheduledAt,this.id=id}function globalCache(){var g;return g="object"==(void 0===global?"undefined":_typeof(global))?global:window,g.prismicCache||(g.prismicCache=new ApiCache),g.prismicCache}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj},Requests=require("./requests"),Cookies=require("./cookies"),documents=require("./documents"),ApiCache=require("./cache"),Predicates=require("./predicates"),experiments=require("./experiments"),Experiments=experiments.Experiments,Document=documents.Document;Api.prototype={AT:"at",ANY:"any",SIMILAR:"similar",FULLTEXT:"fulltext",NUMBER:{GT:"number.gt",LT:"number.lt"},DATE:{AFTER:"date.after",BEFORE:"date.before",BETWEEN:"date.between"},DOCUMENT:{ID:"document.id",TYPE:"document.type",TAGS:"document.tags"},data:null,get:function(callback){var self=this,cacheKey=this.apiCacheKey;return new Promise(function(resolve,reject){var cb=function(err,value,xhr,ttl){callback&&callback(err,value,xhr,ttl),value&&resolve(value),err&&reject(err)};self.apiCache.get(cacheKey,function(err,value){if(err||value)return void cb(err,value);self.requestHandler(self.url,function(err,data,xhr,ttl){if(err)return void cb(err,null,xhr,ttl);var parsed=self.parse(data);ttl=ttl||self.apiDataTTL,self.apiCache.set(cacheKey,parsed,ttl,function(err){cb(err,parsed,xhr,ttl)})})})})},refresh:function(callback){var self=this,cacheKey=this.apiCacheKey;return new Promise(function(resolve,reject){var cb=function(err,value,xhr){callback&&callback(err,value,xhr),value&&resolve(value),err&&reject(err)};self.apiCache.remove(cacheKey,function(err){if(err)return void cb(err);self.get(function(err,data){if(err)return void cb(err);self.data=data,self.bookmarks=data.bookmarks,self.experiments=new Experiments(data.experiments),cb()})})})},parse:function(data){var refs,master,form,types,tags,f,i,forms={};for(i in data.forms)data.forms.hasOwnProperty(i)&&(f=data.forms[i],this.accessToken&&(f.fields.access_token={},f.fields.access_token.type="string",f.fields.access_token.default=this.accessToken),form=new Form(f.name,f.fields,f.form_method,f.rel,f.enctype,f.action),forms[i]=form);if(refs=data.refs.map(function(r){return new Ref(r.ref,r.label,r.isMasterRef,r.scheduledAt,r.id)})||[],master=refs.filter(function(r){return!0===r.isMaster}),types=data.types,tags=data.tags,0===master.length)throw"No master ref.";return{bookmarks:data.bookmarks||{},refs:refs,forms:forms,master:master[0],types:types,tags:tags,experiments:data.experiments,oauthInitiate:data.oauth_initiate,oauthToken:data.oauth_token,quickRoutes:data.quickRoutes}},forms:function(formId){return this.form(formId)},form:function(formId){var form=this.data.forms[formId];return form?new SearchForm(this,form,{}):null},master:function(){return this.data.master.ref},ref:function(label){for(var i=0;i<this.data.refs.length;i++)if(this.data.refs[i].label==label)return this.data.refs[i].ref;return null},currentExperiment:function(){return this.experiments.current()},quickRoutesEnabled:function(){return this.data.quickRoutes.enabled},quickRoutes:function(callback){var self=this;return new Promise(function(resolve,reject){self.requestHandler(self.data.quickRoutes.url,function(err,data,xhr){callback&&callback(err,data,xhr),err&&reject(err),data&&resolve(data)})})},query:function(q,options,callback){"function"==typeof options&&(callback=options,options=void 0);var opts=options||{},form=this.form("everything");for(var key in opts)form=form.set(key,options[key]);if(!opts.ref){var cookieString="";this.req?cookieString=this.req.headers.cookie||"":"undefined"!=typeof window&&(cookieString=window.document.cookie||"");var cookies=Cookies.parse(cookieString),previewRef=cookies["io.prismic.preview"],experimentRef=this.experiments.refFromCookie(cookies["io.prismic.experiment"]);form=form.ref(previewRef||experimentRef||this.master())}return q&&form.query(q),form.submit(callback)},queryFirst:function(q,options,callback){"function"==typeof options&&(callback=options,options=void 0);var opts={};for(var key in options||{})opts[key]=options[key];return opts.page=1,opts.pageSize=1,this.query(q,opts,function(err,response){if(callback){var result=response&&response.results&&response.results[0];callback(err,result)}}).then(function(response){return response&&response.results&&response.results[0]})},getByID:function(id,options,callback){return options=options||{},options.lang||(options.lang="*"),this.queryFirst(Predicates.at("document.id",id),options,callback)},getByIDs:function(ids,options,callback){return options=options||{},options.lang||(options.lang="*"),this.query(["in","document.id",ids],options,callback)},getByUID:function(type,uid,options,callback){return options=options||{},options.lang||(options.lang="*"),this.queryFirst(Predicates.at("my."+type+".uid",uid),options,callback)},getSingle:function(type,options,callback){return this.queryFirst(Predicates.at("document.type",type),options,callback)},getBookmark:function(bookmark,options,callback){return new Promise(function(resolve,reject){var id=this.bookmarks[bookmark];if(id)resolve(id);else{var err=new Error("Error retrieving bookmarked id");callback&&callback(err),reject(err)}}).then(function(id){return this.getByID(id,options,callback)})},previewSession:function(token,linkResolver,defaultUrl,callback){var api=this;return new Promise(function(resolve,reject){var cb=function(err,value,xhr){callback&&callback(err,value,xhr),err?reject(err):resolve(value)};api.requestHandler(token,function(err,result,xhr){if(err)return void cb(err,defaultUrl,xhr);try{var mainDocumentId=result.mainDocument;mainDocumentId?api.form("everything").query(Predicates.at("document.id",mainDocumentId)).ref(token).lang("*").submit(function(err,response){err&&cb(err);try{0===response.results.length?cb(null,defaultUrl,xhr):cb(null,linkResolver(response.results[0]),xhr)}catch(e){cb(e)}}):cb(null,defaultUrl,xhr)}catch(e){cb(e,defaultUrl,xhr)}})})},request:function(url,callback){function run(cb){cache.get(cacheKey,function(err,value){if(err||value)return void cb(err,api.response(value));api.requestHandler(url,function(err,documents,xhr,ttl){if(err)return void cb(err,null,xhr);ttl?cache.set(cacheKey,documents,ttl,function(err){cb(err,api.response(documents))}):cb(null,api.response(documents))})})}var api=this,cacheKey=url+(this.accessToken?"#"+this.accessToken:""),cache=this.apiCache;return new Promise(function(resolve,reject){run(function(err,value,xhr){callback&&callback(err,value,xhr),err&&reject(err),value&&resolve(value)})})},getNextPage:function(nextPage,callback){return this.request(nextPage+(this.accessToken?"&access_token="+this.accessToken:""),callback)},response:function(documents){var results=documents.results.map(parseDoc);return new Response(documents.page,documents.results_per_page,documents.results_size,documents.total_results_size,documents.total_pages,documents.next_page,documents.prev_page,results||[])}},Form.prototype={};var parseDoc=function(json){var fragments={};for(var field in json.data[json.type])fragments[json.type+"."+field]=json.data[json.type][field];var slugs=[];if(void 0!==json.slugs)for(var i=0;i<json.slugs.length;i++)slugs.push(decodeURIComponent(json.slugs[i]));return new Document(json.id,json.uid||null,json.type,json.href,json.tags,slugs,json.first_publication_date,json.last_publication_date,json.lang,json.alternate_languages,fragments,json.data)};SearchForm.prototype={set:function(field,value){var fieldDesc=this.form.fields[field];if(!fieldDesc)throw new Error("Unknown field "+field);var values=this.data[field]||[];return""!==value&&void 0!==value||(value=null),fieldDesc.multiple?value&&values.push(value):values=value&&[value],this.data[field]=values,this},ref:function(_ref){return this.set("ref",_ref)},query:function(_query){if("string"==typeof _query)return this.set("q",_query);var predicates;predicates=_query.constructor===Array&&_query.length>0&&_query[0].constructor===Array?_query:[].slice.apply(arguments);var stringQueries=[];return predicates.forEach(function(predicate){stringQueries.push(Predicates.toQuery(predicate))}),this.query("["+stringQueries.join("")+"]")},pageSize:function(size){return this.set("pageSize",size)},fetch:function(fields){return fields instanceof Array&&(fields=fields.join(",")),this.set("fetch",fields)},fetchLinks:function(fields){return fields instanceof Array&&(fields=fields.join(",")),this.set("fetchLinks",fields)},lang:function(fields){return this.set("lang",fields)},page:function(p){return this.set("page",p)},orderings:function(_orderings){return"string"==typeof _orderings?this.set("orderings",_orderings):_orderings?this.set("orderings","["+_orderings.join(",")+"]"):this},submit:function(callback){var self=this,url=this.form.action;if(this.data){var sep=url.indexOf("?")>-1?"&":"?";for(var key in this.data)if(this.data.hasOwnProperty(key)){var values=this.data[key];if(values)for(var i=0;i<values.length;i++)url+=sep+key+"="+encodeURIComponent(values[i]),sep="&"}}return self.api.request(url,callback)}},Ref.prototype={},module.exports={experimentCookie:"io.prismic.experiment",previewCookie:"io.prismic.preview",Api:Api,Form:Form,SearchForm:SearchForm,Ref:Ref,parseDoc:parseDoc}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./cache":3,"./cookies":4,"./documents":5,"./experiments":6,"./predicates":9,"./requests":12}],2:[function(require,module,exports){"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj};require("es6-promise").polyfill(),"function"!=typeof Object.create&&(Object.create=function(){var Object=function(){};return function(prototype){if(arguments.length>1)throw Error("Second argument not supported");if("object"!=(void 0===prototype?"undefined":_typeof(prototype)))throw TypeError("Argument must be an object");Object.prototype=prototype;var result={};return Object.prototype=null,result}}()),window.Prismic=require("./prismic")},{"./prismic":10,"es6-promise":20}],3:[function(require,module,exports){"use strict";function ApiCache(limit){this.lru=new LRUCache(limit)}var LRUCache=require("./lru");ApiCache.prototype={get:function(key,cb){var maybeEntry=this.lru.get(key);return maybeEntry&&!this.isExpired(key)?cb(null,maybeEntry.data):cb()},set:function(key,value,ttl,cb){return this.lru.remove(key),this.lru.put(key,{data:value,expiredIn:ttl?Date.now()+1e3*ttl:0}),cb()},isExpired:function(key){var entry=this.lru.get(key);return!!entry&&(0!==entry.expiredIn&&entry.expiredIn<Date.now())},remove:function(key,cb){return this.lru.remove(key),cb()},clear:function(cb){return this.lru.removeAll(),cb()}},module.exports=ApiCache},{"./lru":8}],4:[function(require,module,exports){"use strict";function tryDecode(str,decode){try{return decode(str)}catch(e){return str}}function parse(str,options){if("string"!=typeof str)throw new TypeError("argument str must be a string");var obj={},opt=options||{},dec=opt.decode||decode;return str.split(/; */).forEach(function(pair){var eq_idx=pair.indexOf("=");if(!(eq_idx<0)){var key=pair.substr(0,eq_idx).trim(),val=pair.substr(++eq_idx,pair.length).trim();'"'==val[0]&&(val=val.slice(1,-1)),void 0==obj[key]&&(obj[key]=tryDecode(val,dec))}}),obj}var decode=decodeURIComponent;module.exports={parse:parse}},{}],5:[function(require,module,exports){"use strict";function WithFragments(){}function Document(id,uid,type,href,tags,slugs,firstPublicationDate,lastPublicationDate,lang,alternateLanguages,data,rawJSON){this.id=id,this.uid=uid,this.type=type,this.href=href,this.tags=tags,this.slug=slugs?slugs[0]:"-",this.slugs=slugs,this.data=data,this.rawJSON=rawJSON,this.firstPublicationDate=DateUtils.parse(firstPublicationDate),this.lastPublicationDate=DateUtils.parse(lastPublicationDate),this.lang=lang||null,this.alternateLanguages=alternateLanguages||[],this.fragments=require("./fragments").parseFragments(data)}function GroupDoc(data){this.data=data,this.fragments=require("./fragments").parseFragments(data)}function isFunction(f){var getType={};return f&&"[object Function]"===getType.toString.call(f)}var DateUtils=require("./utils/date");WithFragments.prototype={get:function(name){var frags=this._getFragments(name);return frags.length?frags[0]:null},getAll:function(name){return this._getFragments(name)},getImage:function(fragment){var Fragments=require("./fragments"),img=this.get(fragment);return img instanceof Fragments.Image?img:img instanceof Fragments.StructuredText?img:null},getAllImages:function(fragment){var Fragments=require("./fragments");return this.getAll(fragment).map(function(image){if(image instanceof Fragments.Image)return image;if(image instanceof Fragments.StructuredText)throw new Error("Not done.");return null})},getFirstImage:function(){var Fragments=require("./fragments"),fragments=this.fragments;return Object.keys(fragments).reduce(function(image,key){if(image)return image;var element=fragments[key];return"function"==typeof element.getFirstImage?element.getFirstImage():element instanceof Fragments.Image?element:null},null)},getFirstTitle:function(){var Fragments=require("./fragments"),fragments=this.fragments;return Object.keys(fragments).reduce(function(st,key){if(st)return st;var element=fragments[key];return"function"==typeof element.getFirstTitle?element.getFirstTitle():element instanceof Fragments.StructuredText?element.getTitle():null},null)},getFirstParagraph:function(){var fragments=this.fragments;return Object.keys(fragments).reduce(function(st,key){if(st)return st;var element=fragments[key];return"function"==typeof element.getFirstParagraph?element.getFirstParagraph():null},null)},getImageView:function(name,view){var Fragments=require("./fragments"),fragment=this.get(name);if(fragment instanceof Fragments.Image)return fragment.getView(view);if(fragment instanceof Fragments.StructuredText)for(var i=0;i<fragment.blocks.length;i++)if("image"==fragment.blocks[i].type)return fragment.blocks[i];return null},getAllImageViews:function(name,view){return this.getAllImages(name).map(function(image){return image.getView(view)})},getTimestamp:function(name){var Fragments=require("./fragments"),fragment=this.get(name);return fragment instanceof Fragments.Timestamp?fragment.value:null},getDate:function(name){var Fragments=require("./fragments"),fragment=this.get(name);return fragment instanceof Fragments.Date?fragment.value:null},getBoolean:function(name){var fragment=this.get(name);return fragment.value&&("yes"==fragment.value.toLowerCase()||"on"==fragment.value.toLowerCase()||"true"==fragment.value.toLowerCase())},getText:function(name,after){var Fragments=require("./fragments"),fragment=this.get(name);return fragment instanceof Fragments.StructuredText?fragment.blocks.map(function(block){return block.text?block.text+(after||""):""}).join("\n"):fragment instanceof Fragments.Text&&fragment.value?fragment.value+(after||""):fragment instanceof Fragments.Number&&fragment.value?fragment.value+(after||""):fragment instanceof Fragments.Select&&fragment.value?fragment.value+(after||""):fragment instanceof Fragments.Color&&fragment.value?fragment.value+(after||""):null},getStructuredText:function(name){var fragment=this.get(name);return fragment instanceof require("./fragments").StructuredText?fragment:null},getLink:function(name){var Fragments=require("./fragments"),fragment=this.get(name);return fragment instanceof Fragments.WebLink||fragment instanceof Fragments.DocumentLink||fragment instanceof Fragments.FileLink||fragment instanceof Fragments.ImageLink?fragment:null},getNumber:function(name){var Fragments=require("./fragments"),fragment=this.get(name);return fragment instanceof Fragments.Number?fragment.value:null},getColor:function(name){var Fragments=require("./fragments"),fragment=this.get(name);return fragment instanceof Fragments.Color?fragment.value:null},getGeoPoint:function(name){var Fragments=require("./fragments"),fragment=this.get(name);return fragment instanceof Fragments.GeoPoint?fragment:null},getGroup:function(name){var fragment=this.get(name);return fragment instanceof require("./fragments").Group?fragment:null},getHtml:function(name,linkResolver){if(!isFunction(linkResolver)){var ctx=linkResolver;linkResolver=function(doc,isBroken){return ctx.linkResolver(ctx,doc,isBroken)}}var fragment=this.get(name);return fragment&&fragment.asHtml?fragment.asHtml(linkResolver):null},asHtml:function(linkResolver){if(!isFunction(linkResolver)){var ctx=linkResolver;linkResolver=function(doc,isBroken){return ctx.linkResolver(ctx,doc,isBroken)}}var htmls=[];for(var field in this.fragments){var fragment=this.get(field);htmls.push(fragment&&fragment.asHtml?'<section data-field="'+field+'">'+fragment.asHtml(linkResolver)+"</section>":"")}return htmls.join("")},asText:function(linkResolver){if(!isFunction(linkResolver)){var ctx=linkResolver;linkResolver=function(doc,isBroken){return ctx.linkResolver(ctx,doc,isBroken)}}var texts=[];for(var field in this.fragments){var fragment=this.get(field);texts.push(fragment&&fragment.asText?fragment.asText(linkResolver):"")}return texts.join("")},linkedDocuments:function(){var i,j,link,result=[],Fragments=require("./fragments");for(var field in this.data){var fragment=this.get(field);if(fragment instanceof Fragments.DocumentLink&&result.push(fragment),fragment instanceof Fragments.StructuredText)for(i=0;i<fragment.blocks.length;i++){var block=fragment.blocks[i];"image"==block.type&&block.linkTo&&(link=Fragments.initField(block.linkTo))instanceof Fragments.DocumentLink&&result.push(link);var spans=block.spans||[];for(j=0;j<spans.length;j++){var span=spans[j];"hyperlink"==span.type&&(link=Fragments.initField(span.data))instanceof Fragments.DocumentLink&&result.push(link)}}if(fragment instanceof Fragments.Group)for(i=0;i<fragment.value.length;i++)result=result.concat(fragment.value[i].linkedDocuments());if(fragment instanceof Fragments.SliceZone)for(i=0;i<fragment.value.length;i++){var slice=fragment.value[i];slice.value instanceof Fragments.DocumentLink&&result.push(slice.value)}}return result},_getFragments:function(name){return this.fragments&&this.fragments[name]?Array.isArray(this.fragments[name])?this.fragments[name]:[this.fragments[name]]:[]}},Document.prototype=Object.create(WithFragments.prototype),Document.prototype.getSliceZone=function(name){var fragment=this.get(name);return fragment instanceof require("./fragments").SliceZone?fragment:null},GroupDoc.prototype=Object.create(WithFragments.prototype),module.exports={WithFragments:WithFragments,Document:Document,GroupDoc:GroupDoc}},{"./fragments":7,"./utils/date":13}],6:[function(require,module,exports){"use strict";function Experiments(data){var drafts=[],running=[];data&&(data.drafts&&data.drafts.forEach(function(exp){drafts.push(new Experiment(exp))}),data.running&&data.running.forEach(function(exp){running.push(new Experiment(exp))})),this.drafts=drafts,this.running=running}function Experiment(data){this.data=data;var variations=[];data.variations&&data.variations.forEach(function(v){variations.push(new Variation(v))}),this.variations=variations}function Variation(data){this.data=data}Experiments.prototype.current=function(){return this.running.length>0?this.running[0]:null},Experiments.prototype.refFromCookie=function(cookie){if(!cookie||""===cookie.trim())return null;var splitted=cookie.trim().split(" ");if(splitted.length<2)return null;var expId=splitted[0],varIndex=parseInt(splitted[1],10),exp=this.running.filter(function(exp){return exp.googleId()==expId&&exp.variations.length>varIndex})[0];return exp?exp.variations[varIndex].ref():null},Experiment.prototype.id=function(){return this.data.id},Experiment.prototype.googleId=function(){return this.data.googleId},Experiment.prototype.name=function(){return this.data.name},Variation.prototype.id=function(){return this.data.id},Variation.prototype.ref=function(){return this.data.ref},Variation.prototype.label=function(){return this.data.label},module.exports={Experiments:Experiments,Variation:Variation}},{}],7:[function(require,module,exports){"use strict";function Text(data){this.value=data}function DocumentLink(data){this.value=data,this.document=data.document,this.id=data.document.id,this.uid=data.document.uid,this.tags=data.document.tags,this.slug=data.document.slug,this.type=data.document.type,this.lang=data.document.lang;var fragmentsData={};if(data.document.data)for(var field in data.document.data[data.document.type])fragmentsData[data.document.type+"."+field]=data.document.data[data.document.type][field];this.fragments=parseFragments(fragmentsData),this.isBroken=data.isBroken}function WebLink(data){this.value=data}function FileLink(data){this.value=data}function ImageLink(data){this.value=data}function Select(data){this.value=data}function Color(data){this.value=data}function GeoPoint(data){this.latitude=data.latitude,this.longitude=data.longitude}function Num(data){this.value=data}function DateFragment(data){this.value=new Date(data)}function Timestamp(data){this.value=DateUtils.parse(data)}function Embed(data){this.value=data}function ImageEl(main,views){this.main=main,this.url=main.url,this.views=views||{}}function ImageView(url,width,height,alt,copyright){this.url=url,this.width=width,this.height=height,this.alt=alt,this.copyright=copyright}function Separator(){}function Group(data){this.value=[];for(var i=0;i<data.length;i++)this.value.push(new GroupDoc(data[i]))}function StructuredText(blocks){this.blocks=blocks}function htmlEscape(input){return input&&input.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br>")}function insertSpans(text,spans,linkResolver,htmlSerializer){if(!spans||!spans.length)return htmlEscape(text);var tagsStart={},tagsEnd={};spans.forEach(function(span){tagsStart[span.start]||(tagsStart[span.start]=[]),tagsEnd[span.end]||(tagsEnd[span.end]=[]),tagsStart[span.start].push(span),tagsEnd[span.end].unshift(span)});for(var c,html="",stack=[],pos=0,len=text.length+1;pos<len;pos++)tagsEnd[pos]&&tagsEnd[pos].forEach(function(){var tag=stack.pop();if(void 0!==tag){var innerHtml=serialize(tag.span,tag.text,htmlSerializer);0===stack.length?html+=innerHtml:stack[stack.length-1].text+=innerHtml}}),tagsStart[pos]&&(tagsStart[pos].sort(function(a,b){return b.end-b.start-(a.end-a.start)}),tagsStart[pos].forEach(function(span){var url=null;if("hyperlink"==span.type){var fragment=initField(span.data);if(!fragment)return void(console&&console.error&&console.error("Impossible to convert span.data as a Fragment",span));url=fragment.url(linkResolver),span.url=url}var elt={span:span,text:""};stack.push(elt)})),pos<text.length&&(c=text[pos],0===stack.length?html+=htmlEscape(c):stack[stack.length-1].text+=htmlEscape(c));return html}function SimpleSlice(sliceType,label,sliceValue){this.sliceType=sliceType,this.label=label,this.value=initField(sliceValue)}function CompositeSlice(sliceType,label,sliceValue){this.sliceType=sliceType,this.label=label;var nonRepeatKeys=Object.keys(sliceValue["non-repeat"]);this.nonRepeat=nonRepeatKeys.reduce(function(acc,key){var field=initField(sliceValue["non-repeat"][key]);return acc[key]=field,acc},{}),this.repeat=initField({type:"Group",value:sliceValue.repeat})}function SliceZone(data){this.value=[];for(var i=0;i<data.length;i++){var sliceType=data[i].slice_type,label=data[i].slice_label||null,value=data[i];sliceType&&value&&(value.repeat?this.value.push(new CompositeSlice(sliceType,label,value)):this.value.push(new SimpleSlice(sliceType,label,value.value)))}this.slices=this.value}function initField(field){var classForType={Color:Color,Number:Num,Date:DateFragment,Timestamp:Timestamp,Text:Text,Embed:Embed,GeoPoint:GeoPoint,Select:Select,StructuredText:StructuredText,"Link.document":DocumentLink,"Link.web":WebLink,"Link.file":FileLink,"Link.image":ImageLink,Separator:Separator,Group:Group,SliceZone:SliceZone};if(classForType[field.type])return new classForType[field.type](field.value);if("Image"===field.type){var img=field.value.main,output=new ImageEl(new ImageView(img.url,img.dimensions.width,img.dimensions.height,img.alt,img.copyright),{});for(var name in field.value.views)img=field.value.views[name],output.views[name]=new ImageView(img.url,img.dimensions.width,img.dimensions.height,img.alt,img.copyright);return output}return console&&console.log&&console.log("Fragment type not supported: ",field.type),null}function parseFragments(json){var result={};for(var key in json)json.hasOwnProperty(key)&&(Array.isArray(json[key])?result[key]=json[key].map(function(fragment){return initField(fragment)}):result[key]=initField(json[key]));return result}function isFunction(f){var getType={};return f&&"[object Function]"===getType.toString.call(f)}function serialize(element,content,htmlSerializer){if(htmlSerializer){var custom=htmlSerializer(element,content);if(custom)return custom}var TAG_NAMES={heading1:"h1",heading2:"h2",heading3:"h3",heading4:"h4",heading5:"h5",heading6:"h6",paragraph:"p",preformatted:"pre","list-item":"li","o-list-item":"li","group-list-item":"ul","group-o-list-item":"ol",strong:"strong",em:"em"};if(TAG_NAMES[element.type]){var name=TAG_NAMES[element.type];return"<"+name+(element.label?' class="'+element.label+'"':"")+">"+content+"</"+name+">"}if("image"==element.type){var label=element.label?" "+element.label:"",imgTag='<img src="'+element.url+'" alt="'+(element.alt||"")+'" copyright="'+(element.copyright||"")+'">';return'<p class="block-img'+label+'">'+(element.linkUrl?'<a href="'+element.linkUrl+'">'+imgTag+"</a>":imgTag)+"</p>"}return"embed"==element.type?'<div data-oembed="'+element.embed_url+'" data-oembed-type="'+element.type+'" data-oembed-provider="'+element.provider_name+(element.label?'" class="'+element.label:"")+'">'+element.oembed.html+"</div>":"hyperlink"===element.type?'<a href="'+element.url+'">'+content+"</a>":"label"===element.type?'<span class="'+element.data.label+'">'+content+"</span>":"\x3c!-- Warning: "+element.type+" not implemented. Upgrade the Developer Kit. --\x3e"+content}var documents=require("./documents"),DateUtils=require("./utils/date"),WithFragments=documents.WithFragments,GroupDoc=documents.GroupDoc;Text.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},DocumentLink.prototype=Object.create(WithFragments.prototype),DocumentLink.prototype.asHtml=function(ctx){return'<a href="'+this.url(ctx)+'">'+this.url(ctx)+"</a>"},DocumentLink.prototype.url=function(linkResolver){return linkResolver(this,this.isBroken)},DocumentLink.prototype.asText=function(linkResolver){return this.url(linkResolver)},WebLink.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.url()+"</a>"},url:function(){return this.value.url},asText:function(){return this.url()}},FileLink.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.value.file.name+"</a>"},url:function(){return this.value.file.url},asText:function(){return this.url()}},ImageLink.prototype={asHtml:function(){return'<a href="'+this.url()+'"><img src="'+this.url()+'" alt="'+(this.alt||"")+' copyright="'+(this.copyright||"")+'" "></a>'},url:function(){return this.value.image.url},asText:function(){return this.url()}},Select.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},Color.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},GeoPoint.prototype={asHtml:function(){return'<div class="geopoint"><span class="latitude">'+this.latitude+'</span><span class="longitude">'+this.longitude+"</span></div>"},asText:function(){return"("+this.latitude+","+this.longitude+")"}},Num.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return null===this.value?null:this.value.toString()}},DateFragment.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return null===this.value?null:this.value.toString()}},Timestamp.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return null===this.value?null:this.value.toString()}},Embed.prototype={asHtml:function(){return this.value.oembed.html},asText:function(){return""}},ImageEl.prototype={getView:function(name){return"main"===name?this.main:this.views[name]},asHtml:function(){return this.main.asHtml()},asText:function(){return""}},ImageView.prototype={ratio:function(){return this.width/this.height},asHtml:function(){return'<img src="'+this.url+'" width="'+this.width+'" height="'+this.height+'" alt="'+(this.alt||"")+'" copyright="'+(this.copyright||"")+'">'},asText:function(){return""}},Separator.prototype={asHtml:function(){return"<hr/>"},asText:function(){return"----"}},Group.prototype={asHtml:function(linkResolver){for(var output="",i=0;i<this.value.length;i++)output+=this.value[i].asHtml(linkResolver);return output},toArray:function(){return this.value},asText:function(linkResolver){for(var output="",i=0;i<this.value.length;i++)output+=this.value[i].asText(linkResolver)+"\n";return output},getFirstImage:function(){return this.toArray().reduce(function(image,fragment){return image||fragment.getFirstImage()},null)},getFirstTitle:function(){return this.toArray().reduce(function(st,fragment){return st||fragment.getFirstTitle()},null)},getFirstParagraph:function(){return this.toArray().reduce(function(st,fragment){return st||fragment.getFirstParagraph()},null)}},StructuredText.prototype={getTitle:function(){for(var i=0;i<this.blocks.length;i++){var block=this.blocks[i];if(0===block.type.indexOf("heading"))return block}return null},getFirstParagraph:function(){for(var i=0;i<this.blocks.length;i++){var block=this.blocks[i];if("paragraph"==block.type)return block}return null},getParagraphs:function(){for(var paragraphs=[],i=0;i<this.blocks.length;i++){var block=this.blocks[i];"paragraph"==block.type&&paragraphs.push(block)}return paragraphs},getParagraph:function(n){return this.getParagraphs()[n]},getFirstImage:function(){ for(var i=0;i<this.blocks.length;i++){var block=this.blocks[i];if("image"==block.type)return new ImageView(block.url,block.dimensions.width,block.dimensions.height,block.alt,block.copyright)}return null},asHtml:function(linkResolver,htmlSerializer){var blockGroup,block,blockGroups=[],html=[];if(!isFunction(linkResolver)){var ctx=linkResolver;linkResolver=function(doc,isBroken){return ctx.linkResolver(ctx,doc,isBroken)}}if(Array.isArray(this.blocks)){for(var i=0;i<this.blocks.length;i++){if(block=this.blocks[i],"image"==block.type&&block.linkTo){var link=initField(block.linkTo);block.linkUrl=link.url(linkResolver)}"list-item"!==block.type&&"o-list-item"!==block.type?(blockGroups.push(block),blockGroup=null):blockGroup&&blockGroup.type=="group-"+block.type?blockGroup.blocks.push(block):(blockGroup={type:"group-"+block.type,blocks:[block]},blockGroups.push(blockGroup))}var blockContent=function blockContent(block){var content="";return block.blocks?block.blocks.forEach(function(block2){content+=serialize(block2,blockContent(block2),htmlSerializer)}):content=insertSpans(block.text,block.spans,linkResolver,htmlSerializer),content};blockGroups.forEach(function(blockGroup){html.push(serialize(blockGroup,blockContent(blockGroup),htmlSerializer))})}return html.join("")},asText:function(){for(var output=[],i=0;i<this.blocks.length;i++){var block=this.blocks[i];block.text&&output.push(block.text)}return output.join(" ")}},SimpleSlice.prototype={asHtml:function(linkResolver){var classes=["slice"];return this.label&&classes.push(this.label),'<div data-slicetype="'+this.sliceType+'" class="'+classes.join(" ")+'">'+this.value.asHtml(linkResolver)+"</div>"},asText:function(linkResolver){return this.value.asText(linkResolver)},getFirstImage:function(){var fragment=this.value;return"function"==typeof fragment.getFirstImage?fragment.getFirstImage():fragment instanceof ImageEl?fragment:null},getFirstTitle:function(){var fragment=this.value;return"function"==typeof fragment.getFirstTitle?fragment.getFirstTitle():fragment instanceof StructuredText?fragment.getTitle():null},getFirstParagraph:function(){var fragment=this.value;return"function"==typeof fragment.getFirstParagraph?fragment.getFirstParagraph():null}},CompositeSlice.prototype={asHtml:function(linkResolver){var classes=["slice"];this.label&&classes.push(this.label);var self=this,nonRepeatHtml=Object.keys(this.nonRepeat).reduce(function(acc,key){return acc+self.nonRepeat[key].asHtml(linkResolver)},"");return'<div data-slicetype="'+this.sliceType+'" class="'+classes.join(" ")+'">'+nonRepeatHtml+this.repeat.asHtml(linkResolver)+"</div>"},asText:function(linkResolver){var self=this;return Object.keys(this.nonRepeat).reduce(function(acc,key){return acc+self.nonRepeat[key].asText(linkResolver)},"")+"\n"+this.repeat.asText(linkResolver)},getFirstImage:function(){var self=this,firstImage=Object.keys(this.nonRepeat).reduce(function(image,key){if(image)return image;var element=self.nonRepeat[key];return"function"==typeof element.getFirstImage?element.getFirstImage():element instanceof ImageEl?element:null},null);return firstImage||this.repeat.getFirstImage()},getFirstTitle:function(){var self=this;return Object.keys(this.nonRepeat).reduce(function(title,key){if(title)return title;var fragment=self.nonRepeat[key];return"function"==typeof fragment.getFirstTitle?fragment.getFirstTitle():fragment instanceof StructuredText?fragment.getTitle():null},null)||this.repeat.getFirstTitle()},getFirstParagraph:function(){var self=this;return Object.keys(this.nonRepeat).reduce(function(paragraph,key){if(paragraph)return paragraph;var fragment=self.nonRepeat[key];return"function"==typeof fragment.getFirstParagraph?fragment.getFirstParagraph():null},null)||this.repeat.getFirstParagraph()}},SliceZone.prototype={asHtml:function(linkResolver){for(var output="",i=0;i<this.value.length;i++)output+=this.value[i].asHtml(linkResolver);return output},asText:function(linkResolver){for(var output="",i=0;i<this.value.length;i++)output+=this.value[i].asText(linkResolver)+"\n";return output},getFirstImage:function(){return this.value.reduce(function(image,slice){return image||slice.getFirstImage()},null)},getFirstTitle:function(){return this.value.reduce(function(text,slice){return text||slice.getFirstTitle()},null)},getFirstParagraph:function(){return this.value.reduce(function(paragraph,slice){return paragraph||slice.getFirstParagraph()},null)}},module.exports={Embed:Embed,Image:ImageEl,ImageView:ImageView,Text:Text,Number:Num,Date:DateFragment,Timestamp:Timestamp,Select:Select,Color:Color,StructuredText:StructuredText,WebLink:WebLink,DocumentLink:DocumentLink,ImageLink:ImageLink,FileLink:FileLink,Separator:Separator,Group:Group,GeoPoint:GeoPoint,SliceZone:SliceZone,SimpleSlice:SimpleSlice,CompositeSlice:CompositeSlice,initField:initField,parseFragments:parseFragments,insertSpans:insertSpans}},{"./documents":5,"./utils/date":13}],8:[function(require,module,exports){"use strict";function LRUCache(limit){this.size=0,this.limit=limit,this._keymap={}}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj};LRUCache.prototype.put=function(key,value){var entry={key:key,value:value};return this._keymap[key]=entry,this.tail?(this.tail.newer=entry,entry.older=this.tail):this.head=entry,this.tail=entry,this.size===this.limit?this.shift():(this.size++,null)},LRUCache.prototype.shift=function(){var entry=this.head;return entry&&(this.head.newer?(this.head=this.head.newer,this.head.older=void 0):this.head=void 0,entry.newer=entry.older=void 0,delete this._keymap[entry.key]),entry},LRUCache.prototype.get=function(key,returnEntry){var entry=this._keymap[key];return void 0===entry?null:entry===this.tail?returnEntry?entry:entry.value:(entry.newer&&(entry===this.head&&(this.head=entry.newer),entry.newer.older=entry.older),entry.older&&(entry.older.newer=entry.newer),entry.newer=void 0,entry.older=this.tail,this.tail&&(this.tail.newer=entry),this.tail=entry,returnEntry?entry:entry.value)},LRUCache.prototype.find=function(key){return this._keymap[key]},LRUCache.prototype.set=function(key,value){var oldvalue,entry=this.get(key,!0);return entry?(oldvalue=entry.value,entry.value=value):(oldvalue=this.put(key,value))&&(oldvalue=oldvalue.value),oldvalue},LRUCache.prototype.remove=function(key){var entry=this._keymap[key];return entry?(delete this._keymap[entry.key],entry.newer&&entry.older?(entry.older.newer=entry.newer,entry.newer.older=entry.older):entry.newer?(entry.newer.older=void 0,this.head=entry.newer):entry.older?(entry.older.newer=void 0,this.tail=entry.older):this.head=this.tail=void 0,this.size--,entry.value):null},LRUCache.prototype.removeAll=function(){this.head=this.tail=void 0,this.size=0,this._keymap={}},"function"==typeof Object.keys?LRUCache.prototype.keys=function(){return Object.keys(this._keymap)}:LRUCache.prototype.keys=function(){var keys=[];for(var k in this._keymap)keys.push(k);return keys},LRUCache.prototype.forEach=function(fun,context,desc){var entry;if(!0===context?(desc=!0,context=void 0):"object"!==(void 0===context?"undefined":_typeof(context))&&(context=this),desc)for(entry=this.tail;entry;)fun.call(context,entry.key,entry.value,this),entry=entry.older;else for(entry=this.head;entry;)fun.call(context,entry.key,entry.value,this),entry=entry.newer},LRUCache.prototype.toJSON=function(){for(var s=[],entry=this.head;entry;)s.push({key:entry.key.toJSON(),value:entry.value.toJSON()}),entry=entry.newer;return s},LRUCache.prototype.toString=function(){for(var s="",entry=this.head;entry;)s+=String(entry.key)+":"+entry.value,(entry=entry.newer)&&(s+=" < ");return s},module.exports=LRUCache},{}],9:[function(require,module,exports){"use strict";function stripQuotes(s){return s.replace(/"/g,"")}function toQueryValue(value){return"string"==typeof value?'"'+stripQuotes(value)+'"':value instanceof Date?value.getTime():Array.isArray(value)?"["+value.map(function(item){return toQueryValue(item)}).join(",")+"]":value}module.exports={toQuery:function(predicate){var operator=stripQuotes(predicate[0]),path=stripQuotes(predicate[1]),pathArg=0===path.indexOf("my.")||0===path.indexOf("document")?path:'"'+path+'"',values=predicate.slice(2).map(toQueryValue).join(",");return"[:d = "+operator+"("+pathArg+(predicate.length>2?", ":"")+values+")]"},at:function(fragment,value){return["at",fragment,value]},not:function(fragment,value){return["not",fragment,value]},missing:function(fragment){return["missing",fragment]},has:function(fragment){return["has",fragment]},any:function(fragment,values){return["any",fragment,values]},in:function(fragment,values){return["in",fragment,values]},fulltext:function(fragment,value){return["fulltext",fragment,value]},similar:function(documentId,maxResults){return["similar",documentId,maxResults]},gt:function(fragment,value){return["number.gt",fragment,value]},lt:function(fragment,value){return["number.lt",fragment,value]},inRange:function(fragment,before,after){return["number.inRange",fragment,before,after]},dateBefore:function(fragment,before){return["date.before",fragment,before]},dateAfter:function(fragment,after){return["date.after",fragment,after]},dateBetween:function(fragment,before,after){return["date.between",fragment,before,after]},dayOfMonth:function(fragment,day){return["date.day-of-month",fragment,day]},dayOfMonthAfter:function(fragment,day){return["date.day-of-month-after",fragment,day]},dayOfMonthBefore:function(fragment,day){return["date.day-of-month-before",fragment,day]},dayOfWeek:function(fragment,day){return["date.day-of-week",fragment,day]},dayOfWeekAfter:function(fragment,day){return["date.day-of-week-after",fragment,day]},dayOfWeekBefore:function(fragment,day){return["date.day-of-week-before",fragment,day]},month:function(fragment,_month){return["date.month",fragment,_month]},monthBefore:function(fragment,month){return["date.month-before",fragment,month]},monthAfter:function(fragment,month){return["date.month-after",fragment,month]},year:function(fragment,_year){return["date.year",fragment,_year]},hour:function(fragment,_hour){return["date.hour",fragment,_hour]},hourBefore:function(fragment,hour){return["date.hour-before",fragment,hour]},hourAfter:function(fragment,hour){return["date.hour-after",fragment,hour]},near:function(fragment,latitude,longitude,radius){return["geopoint.near",fragment,latitude,longitude,radius]}}},{}],10:[function(require,module,exports){"use strict";function getApi(url,options){options=options||{},"function"==typeof arguments[1]?options={complete:arguments[1],accessToken:arguments[2],requestHandler:arguments[3],apiCache:arguments[4],apiDataTTL:arguments[5]}:"string"==typeof arguments[1]&&(options={accessToken:arguments[1],requestHandler:arguments[2],apiCache:arguments[3],apiDataTTL:arguments[4]});var api=new Api(url,options||{});return new Promise(function(resolve,reject){var cb=function(err,value,xhr){options.complete&&options.complete(err,value,xhr),err?reject(err):resolve(value)};return api.get(function(err,data){!err&&data&&(api.data=data,api.bookmarks=data.bookmarks,api.experiments=new Experiments(data.experiments)),cb(err,api)}),api})}var experiments=require("./experiments"),Predicates=require("./predicates"),api=require("./api"),Fragments=require("./fragments"),QuickRoutes=require("./quickRoutes"),documents=require("./documents"),Api=api.Api,Experiments=experiments.Experiments;module.exports={experimentCookie:api.experimentCookie,previewCookie:api.previewCookie,Document:documents.Document,SearchForm:api.SearchForm,Form:api.Form,Experiments:Experiments,Predicates:Predicates,Fragments:Fragments,QuickRoutes:QuickRoutes,api:getApi,Api:getApi,parseDoc:api.parseDoc},module.exports.Prismic=module.exports},{"./api":1,"./documents":5,"./experiments":6,"./fragments":7,"./predicates":9,"./quickRoutes":11}],11:[function(require,module,exports){"use strict";function toUrl(route,doc){return route.fragments&&0!=route.fragments.length?route.fragments.reduce(function(acc,f){switch(f.kind){case Kind.Dynamic:return doc?acc+"/"+getFragmentValue(f,doc):acc+"/:"+toKey(f.key);case Kind.Static:return acc+"/"+f.value;default:return acc}},""):"/"}function getFragmentValue(fragment,doc){var steps=fragment.key.split(".");if(steps[0]!=doc.type)throw Error("Wrong doc type error: got "+doc.type+", expected "+steps[0]);switch(steps[1]){case"uid":return doc.uid;case"id":return doc.id;default:throw Error("Unsupported dynamic fragment: "+fragment)}}function toKey(dotty){return dotty.split(".").join("_")}function fetchData(req,res,fetchers){return new Promise(function(resolve,reject){var pData=fetchers.map(function(f){return fetcherAction(f,req).then(function(doc){return{name:f.name,doc:doc}}).catch(function(err){reject(err)})});Promise.all(pData).then(function(results){var data={};results.forEach(function(result){data[result.name]=result.doc}),resolve(data)})})}function fetcherAction(f,req){switch(f.condition.kind){case Condition.ID:return req.prismic.api.getByID(f.mask,req.params[toKey(f.condition.key)]);case Condition.UID:return req.prismic.api.getByUID(f.mask,req.params[toKey(f.condition.key)]);case Condition.Singleton:return req.prismic.api.getSingle(f.mask);default:return Promise.reject(new Error("Unknown fetcher condition: "+f.condition.kind))}}function makeLinkResolver(dynRoutes,linkResolver){return function(doc){var docRoute=dynRoutes.find(function(dr){return dr.forMask===doc.type});return docRoute?toUrl(docRoute,doc):linkResolver(doc)}}var Kind={Dynamic:"dynamic",Static:"static"},Condition={ID:"withId",UID:"withUid",Singleton:"singleton"};module.exports={toUrl:toUrl,makeLinkResolver:makeLinkResolver,fetchData:fetchData}},{}],12:[function(require,module,exports){(function(process){"use strict";var createError=function(status,message){var err=new Error(message);return err.status=status,err},ajaxRequest=function(){return"undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest?function(url,callback){var xhr=new XMLHttpRequest,resolve=function(){var ttl,cacheControl=/max-age\s*=\s*(\d+)/.exec(xhr.getResponseHeader("Cache-Control"));cacheControl&&cacheControl.length>1&&(ttl=parseInt(cacheControl[1],10)),callback(null,JSON.parse(xhr.responseText),xhr,ttl)},reject=function(){var status=xhr.status;callback(createError(status,"Unexpected status code ["+status+"] on URL "+url),null,xhr)};xhr.onreadystatechange=function(){4===xhr.readyState&&(xhr.status&&200==xhr.status?resolve():reject())},xhr.open("GET",url,!0),xhr.setRequestHeader("Accept","application/json"),xhr.send()}:null},xdomainRequest=function(){return"undefined"!=typeof XDomainRequest?function(url,callback){var xdr=new XDomainRequest,resolve=function(){callback(null,JSON.parse(xdr.responseText),xdr,0)},reject=function(msg){callback(new Error(msg),null,xdr)};xdr.onload=function(){resolve()},xdr.onerror=function(){reject("Unexpected status code on URL "+url)},xdr.open("GET",url,!0),xdr.ontimeout=function(){reject("Request timeout")},xdr.onprogress=function(){},xdr.send()}:null},fetchRequest=function(){if("function"==typeof fetch){var pjson=require("../package.json");return function(requestUrl,callback){fetch(requestUrl,{headers:{Accept:"application/json","User-Agent":"Prismic-javascript-kit/"+pjson.version+" NodeJS/"+process.version}}).then(function(response){if(~~(response.status/100!=2))throw new createError(response.status,"Unexpected status code ["+response.status+"] on URL "+requestUrl);return response.json().then(function(json){return{response:response,json:json}})}).then(function(next){var response=next.response,json=next.json,cacheControl=response.headers["cache-control"],ttl=cacheControl&&/max-age=(\d+)/.test(cacheControl)?parseInt(/max-age=(\d+)/.exec(cacheControl)[1],10):void 0;callback(null,json,response,ttl)}).catch(function(error){callback(error)})}}return null},nodeJSRequest=function(){if("function"==typeof require&&require("http")){var http=require("http"),https=require("https"),url=require("url"),pjson=require("../package.json");return function(requestUrl,callback){var parsed=url.parse(requestUrl),h="https:"==parsed.protocol?https:http,options={hostname:parsed.hostname,path:parsed.path,query:parsed.query,headers:{Accept:"application/json","User-Agent":"Prismic-javascript-kit/"+pjson.version+" NodeJS/"+process.version}};if(!requestUrl){var e=new Error("dummy"),stack=e.stack.replace(/^[^\(]+?[\n$]/gm,"").replace(/^\s+at\s+/gm,"").replace(/^Object.<anonymous>\s*\(/gm,"{anonymous}()@").split("\n");console.log(stack)}h.get(options,function(response){if(response.statusCode&&200==response.statusCode){var jsonStr="";response.setEncoding("utf8"),response.on("data",function(chunk){jsonStr+=chunk}),response.on("end",function(){var json;try{json=JSON.parse(jsonStr)}catch(ex){console.log("Failed to parse json: "+jsonStr,ex)}var cacheControl=response.headers["cache-control"],ttl=cacheControl&&/max-age=(\d+)/.test(cacheControl)?parseInt(/max-age=(\d+)/.exec(cacheControl)[1],10):void 0;callback(null,json,response,ttl)})}else callback(createError(response.statusCode,"Unexpected status code ["+response.statusCode+"] on URL "+requestUrl),null,response)}).on("error",function(err){callback(new Error("Unexpected error on URL "+requestUrl),null,err)})}}return null},running=0,queue=[],processQueue=function processQueue(){if(!(0===queue.length||running>=20)){running++;var next=queue.shift();(ajaxRequest()||xdomainRequest()||fetchRequest()||nodeJSRequest()||function(){throw new Error("No request handler available (tried XMLHttpRequest, fetch & NodeJS)")}()).call(this,next.url,function(error,result,xhr,ttl){running--,next.callback(error,result,xhr,ttl),processQueue()})}},request=function(url,callback){queue.push({url:url,callback:callback}),processQueue()};module.exports={MAX_CONNECTIONS:20,request:request}}).call(this,require("_process"))},{"../package.json":51,_process:28,http:42,https:22,url:47}],13:[function(requir