diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index bdb0cab..0000000 --- a/.gitattributes +++ /dev/null @@ -1,17 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto - -# Custom for Visual Studio -*.cs diff=csharp - -# Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain -*.docx diff=astextplain -*.DOCX diff=astextplain -*.dot diff=astextplain -*.DOT diff=astextplain -*.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore index 416130f..6daf201 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -node_modules -package-lock.json - # Windows image file caches Thumbs.db ehthumbs.db @@ -53,8 +50,7 @@ Temporary Items *.zip itch* -# node -node_modules - # IDE stuff -.idea \ No newline at end of file +.idea + +/Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..d7397c1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "pixsy" +version = "0.72.0" +description = "convert images to Bitsy rooms" +authors = ["Max Bradbury "] +edition = "2018" +license = "MIT" +repository = "https://tinybird.dev/max/image-to-bitsy" + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +"base64" = "^0.12.3" +"bitsy-parser" = "^0.72.0" +"image" = "^0.23.7" +"wasm-bindgen" = "^0.2.64" + +[dependencies.web-sys] +version = "^0.3.4" +features = [ + 'Document', + 'Element', + 'HtmlElement', + 'Node', + 'Window', +] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ab3b50e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Max Bradbury + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/_config.yml b/_config.yml deleted file mode 100644 index 9da9a02..0000000 --- a/_config.yml +++ /dev/null @@ -1 +0,0 @@ -theme: jekyll-theme-dinky \ No newline at end of file diff --git a/build.sh b/build.sh index a9ef88a..ac2bd52 100644 --- a/build.sh +++ b/build.sh @@ -1,4 +1,5 @@ -#!/usr/bin/env bash +#! /usr/bin/env bash -pug index.pug index.html +pug index.pug lessc includes/style.less includes/style.css +wasm-pack build --target web diff --git a/deploy.sh b/deploy.sh index 71b88e7..23ee025 100644 --- a/deploy.sh +++ b/deploy.sh @@ -1,4 +1,6 @@ -#!/usr/bin/env bash +#! /usr/bin/env bash -zip -r image-to-bitsy.zip readme.md index.html includes/ -butler push image-to-bitsy.zip ruin/image-to-bitsy:html +./build.sh +# todo create dist directory instead of zip +zip -r tilesy.zip README.md index.html script.js background.png pkg/ includes/ +butler push tilesy.zip ruin/image-to-bitsy:html diff --git a/includes/Rubik-Regular.ttf b/includes/Rubik-Regular.ttf deleted file mode 100644 index 20100d2..0000000 Binary files a/includes/Rubik-Regular.ttf and /dev/null differ diff --git a/includes/croppie.css b/includes/croppie.css deleted file mode 100644 index 0af2e2c..0000000 --- a/includes/croppie.css +++ /dev/null @@ -1,250 +0,0 @@ -.croppie-container { - width: 100%; - height: 100%; -} - -.croppie-container .cr-image { - z-index: -1; - position: absolute; - top: 0; - left: 0; - transform-origin: 0 0; - max-height: none; - max-width: none; -} - -.croppie-container .cr-boundary { - position: relative; - overflow: hidden; - margin: 0 auto; - z-index: 1; - width: 100%; - height: 100%; -} - -.croppie-container .cr-viewport, -.croppie-container .cr-resizer { - position: absolute; - border: 2px solid #fff; - margin: auto; - top: 0; - bottom: 0; - right: 0; - left: 0; - box-shadow: 0 0 2000px 2000px rgba(0, 0, 0, 0.5); - z-index: 0; -} - -.croppie-container .cr-resizer { - z-index: 2; - box-shadow: none; - pointer-events: none; -} - -.croppie-container .cr-resizer-vertical, -.croppie-container .cr-resizer-horisontal { - position: absolute; - pointer-events: all; -} - -.croppie-container .cr-resizer-vertical::after, -.croppie-container .cr-resizer-horisontal::after { - display: block; - position: absolute; - box-sizing: border-box; - border: 1px solid black; - background: #fff; - width: 10px; - height: 10px; - content: ''; -} - -.croppie-container .cr-resizer-vertical { - bottom: -5px; - cursor: row-resize; - width: 100%; - height: 10px; -} - -.croppie-container .cr-resizer-vertical::after { - left: 50%; - margin-left: -5px; -} - -.croppie-container .cr-resizer-horisontal { - right: -5px; - cursor: col-resize; - width: 10px; - height: 100%; -} - -.croppie-container .cr-resizer-horisontal::after { - top: 50%; - margin-top: -5px; -} - -.croppie-container .cr-original-image { - display: none; -} - -.croppie-container .cr-vp-circle { - border-radius: 50%; -} - -.croppie-container .cr-overlay { - z-index: 1; - position: absolute; - cursor: move; - touch-action: none; -} - -.croppie-container .cr-slider-wrap { - width: 75%; - margin: 15px auto; - text-align: center; -} - -.croppie-result { - position: relative; - overflow: hidden; -} - -.croppie-result img { - position: absolute; -} - -.croppie-container .cr-image, -.croppie-container .cr-overlay, -.croppie-container .cr-viewport { - -webkit-transform: translateZ(0); - -moz-transform: translateZ(0); - -ms-transform: translateZ(0); - transform: translateZ(0); -} - -/*************************************/ -/***** STYLING RANGE INPUT ***********/ -/*************************************/ -/*http://brennaobrien.com/blog/2014/05/style-input-type-range-in-every-browser.html */ -/*************************************/ - -.cr-slider { - -webkit-appearance: none; -/*removes default webkit styles*/ - /*border: 1px solid white; *//*fix for FF unable to apply focus style bug */ - width: 300px; -/*required for proper track sizing in FF*/ - max-width: 100%; - padding-top: 8px; - padding-bottom: 8px; - background-color: transparent; -} - -.cr-slider::-webkit-slider-runnable-track { - width: 100%; - height: 3px; - background: rgba(0, 0, 0, 0.5); - border: 0; - border-radius: 3px; -} - -.cr-slider::-webkit-slider-thumb { - -webkit-appearance: none; - border: none; - height: 16px; - width: 16px; - border-radius: 50%; - background: #ddd; - margin-top: -6px; -} - -.cr-slider:focus { - outline: none; -} -/* -.cr-slider:focus::-webkit-slider-runnable-track { -background: #ccc; -} -*/ - -.cr-slider::-moz-range-track { - width: 100%; - height: 3px; - background: rgba(0, 0, 0, 0.5); - border: 0; - border-radius: 3px; -} - -.cr-slider::-moz-range-thumb { - border: none; - height: 16px; - width: 16px; - border-radius: 50%; - background: #ddd; - margin-top: -6px; -} - -/*hide the outline behind the border*/ -.cr-slider:-moz-focusring { - outline: 1px solid white; - outline-offset: -1px; -} - -.cr-slider::-ms-track { - width: 100%; - height: 5px; - background: transparent; -/*remove bg colour from the track, we'll use ms-fill-lower and ms-fill-upper instead */ - border-color: transparent;/*leave room for the larger thumb to overflow with a transparent border */ - border-width: 6px 0; - color: transparent;/*remove default tick marks*/ -} -.cr-slider::-ms-fill-lower { - background: rgba(0, 0, 0, 0.5); - border-radius: 10px; -} -.cr-slider::-ms-fill-upper { - background: rgba(0, 0, 0, 0.5); - border-radius: 10px; -} -.cr-slider::-ms-thumb { - border: none; - height: 16px; - width: 16px; - border-radius: 50%; - background: #ddd; - margin-top:1px; -} -.cr-slider:focus::-ms-fill-lower { - background: rgba(0, 0, 0, 0.5); -} -.cr-slider:focus::-ms-fill-upper { - background: rgba(0, 0, 0, 0.5); -} -/*******************************************/ - -/***********************************/ -/* Rotation Tools */ -/***********************************/ -.cr-rotate-controls { - position: absolute; - bottom: 5px; - left: 5px; - z-index: 1; -} -.cr-rotate-controls button { - border: 0; - background: none; -} -.cr-rotate-controls i:before { - display: inline-block; - font-style: normal; - font-weight: 900; - font-size: 22px; -} -.cr-rotate-l i:before { - content: '↺'; -} -.cr-rotate-r i:before { - content: '↻'; -} diff --git a/includes/croppie.js b/includes/croppie.js deleted file mode 100644 index f6f4671..0000000 --- a/includes/croppie.js +++ /dev/null @@ -1,1596 +0,0 @@ -/************************* - * Croppie - * Copyright 2017 - * Foliotek - * Version: 2.5.1 - *************************/ -(function (root, factory) { - if (typeof define === 'function' && define.amd) { - // AMD. Register as an anonymous module. - define(['exports'], factory); - } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') { - // CommonJS - factory(exports); - } else { - // Browser globals - factory((root.commonJsStrict = {})); - } -}(this, function (exports) { - - /* Polyfills */ - if (typeof Promise !== 'function') { - /*! promise-polyfill 3.1.0 */ - !function(a){function b(a,b){return function(){a.apply(b,arguments)}}function c(a){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof a)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],i(a,b(e,this),b(f,this))}function d(a){var b=this;return null===this._state?void this._deferreds.push(a):void k(function(){var c=b._state?a.onFulfilled:a.onRejected;if(null===c)return void(b._state?a.resolve:a.reject)(b._value);var d;try{d=c(b._value)}catch(e){return void a.reject(e)}a.resolve(d)})}function e(a){try{if(a===this)throw new TypeError("A promise cannot be resolved with itself.");if(a&&("object"==typeof a||"function"==typeof a)){var c=a.then;if("function"==typeof c)return void i(b(c,a),b(e,this),b(f,this))}this._state=!0,this._value=a,g.call(this)}catch(d){f.call(this,d)}}function f(a){this._state=!1,this._value=a,g.call(this)}function g(){for(var a=0,b=this._deferreds.length;b>a;a++)d.call(this,this._deferreds[a]);this._deferreds=null}function h(a,b,c,d){this.onFulfilled="function"==typeof a?a:null,this.onRejected="function"==typeof b?b:null,this.resolve=c,this.reject=d}function i(a,b,c){var d=!1;try{a(function(a){d||(d=!0,b(a))},function(a){d||(d=!0,c(a))})}catch(e){if(d)return;d=!0,c(e)}}var j=setTimeout,k="function"==typeof setImmediate&&setImmediate||function(a){j(a,1)},l=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)};c.prototype["catch"]=function(a){return this.then(null,a)},c.prototype.then=function(a,b){var e=this;return new c(function(c,f){d.call(e,new h(a,b,c,f))})},c.all=function(){var a=Array.prototype.slice.call(1===arguments.length&&l(arguments[0])?arguments[0]:arguments);return new c(function(b,c){function d(f,g){try{if(g&&("object"==typeof g||"function"==typeof g)){var h=g.then;if("function"==typeof h)return void h.call(g,function(a){d(f,a)},c)}a[f]=g,0===--e&&b(a)}catch(i){c(i)}}if(0===a.length)return b([]);for(var e=a.length,f=0;fd;d++)a[d].then(b,c)})},c._setImmediateFn=function(a){k=a},"undefined"!=typeof module&&module.exports?module.exports=c:a.Promise||(a.Promise=c)}(this); - } - - if ( typeof window.CustomEvent !== "function" ) { - (function(){ - function CustomEvent ( event, params ) { - params = params || { bubbles: false, cancelable: false, detail: undefined }; - var evt = document.createEvent( 'CustomEvent' ); - evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail ); - return evt; - } - CustomEvent.prototype = window.Event.prototype; - window.CustomEvent = CustomEvent; - }()); - } - - if (!HTMLCanvasElement.prototype.toBlob) { - Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', { - value: function (callback, type, quality) { - var binStr = atob( this.toDataURL(type, quality).split(',')[1] ), - len = binStr.length, - arr = new Uint8Array(len); - - for (var i=0; i= 5) { - var x= w; - w = h; - h = x; - } - return { width: w, height: h }; - } - - /* CSS Transform Prototype */ - var TRANSLATE_OPTS = { - 'translate3d': { - suffix: ', 0px' - }, - 'translate': { - suffix: '' - } - }; - var Transform = function (x, y, scale) { - this.x = parseFloat(x); - this.y = parseFloat(y); - this.scale = parseFloat(scale); - }; - - Transform.parse = function (v) { - if (v.style) { - return Transform.parse(v.style[CSS_TRANSFORM]); - } - else if (v.indexOf('matrix') > -1 || v.indexOf('none') > -1) { - return Transform.fromMatrix(v); - } - else { - return Transform.fromString(v); - } - }; - - Transform.fromMatrix = function (v) { - var vals = v.substring(7).split(','); - if (!vals.length || v === 'none') { - vals = [1, 0, 0, 1, 0, 0]; - } - - return new Transform(num(vals[4]), num(vals[5]), parseFloat(vals[0])); - }; - - Transform.fromString = function (v) { - var values = v.split(') '), - translate = values[0].substring(Croppie.globals.translate.length + 1).split(','), - scale = values.length > 1 ? values[1].substring(6) : 1, - x = translate.length > 1 ? translate[0] : 0, - y = translate.length > 1 ? translate[1] : 0; - - return new Transform(x, y, scale); - }; - - Transform.prototype.toString = function () { - var suffix = TRANSLATE_OPTS[Croppie.globals.translate].suffix || ''; - return Croppie.globals.translate + '(' + this.x + 'px, ' + this.y + 'px' + suffix + ') scale(' + this.scale + ')'; - }; - - var TransformOrigin = function (el) { - if (!el || !el.style[CSS_TRANS_ORG]) { - this.x = 0; - this.y = 0; - return; - } - var css = el.style[CSS_TRANS_ORG].split(' '); - this.x = parseFloat(css[0]); - this.y = parseFloat(css[1]); - }; - - TransformOrigin.prototype.toString = function () { - return this.x + 'px ' + this.y + 'px'; - }; - - function getExifOrientation (img) { - return img.exifdata.Orientation; - } - - function drawCanvas(canvas, img, orientation) { - var width = img.width, - height = img.height, - ctx = canvas.getContext('2d'); - - canvas.width = img.width; - canvas.height = img.height; - - ctx.save(); - switch (orientation) { - case 2: - ctx.translate(width, 0); - ctx.scale(-1, 1); - break; - - case 3: - ctx.translate(width, height); - ctx.rotate(180*Math.PI/180); - break; - - case 4: - ctx.translate(0, height); - ctx.scale(1, -1); - break; - - case 5: - canvas.width = height; - canvas.height = width; - ctx.rotate(90*Math.PI/180); - ctx.scale(1, -1); - break; - - case 6: - canvas.width = height; - canvas.height = width; - ctx.rotate(90*Math.PI/180); - ctx.translate(0, -height); - break; - - case 7: - canvas.width = height; - canvas.height = width; - ctx.rotate(-90*Math.PI/180); - ctx.translate(-width, height); - ctx.scale(1, -1); - break; - - case 8: - canvas.width = height; - canvas.height = width; - ctx.translate(0, width); - ctx.rotate(-90*Math.PI/180); - break; - } - ctx.drawImage(img, 0,0, width, height); - ctx.restore(); - } - - /* Private Methods */ - function _create() { - var self = this, - contClass = 'croppie-container', - customViewportClass = self.options.viewport.type ? 'cr-vp-' + self.options.viewport.type : null, - boundary, img, viewport, overlay, bw, bh; - - self.options.useCanvas = self.options.enableOrientation || _hasExif.call(self); - // Properties on class - self.data = {}; - self.elements = {}; - - boundary = self.elements.boundary = document.createElement('div'); - viewport = self.elements.viewport = document.createElement('div'); - img = self.elements.img = document.createElement('img'); - overlay = self.elements.overlay = document.createElement('div'); - - if (self.options.useCanvas) { - self.elements.canvas = document.createElement('canvas'); - self.elements.preview = self.elements.canvas; - } - else { - self.elements.preview = self.elements.img; - } - - addClass(boundary, 'cr-boundary'); - boundary.setAttribute('aria-dropeffect', 'none'); - bw = self.options.boundary.width; - bh = self.options.boundary.height; - css(boundary, { - width: (bw + (isNaN(bw) ? '' : 'px')), - height: (bh + (isNaN(bh) ? '' : 'px')) - }); - - addClass(viewport, 'cr-viewport'); - if (customViewportClass) { - addClass(viewport, customViewportClass); - } - css(viewport, { - width: self.options.viewport.width + 'px', - height: self.options.viewport.height + 'px' - }); - viewport.setAttribute('tabindex', 0); - - addClass(self.elements.preview, 'cr-image'); - setAttributes(self.elements.preview, { 'alt': 'preview', 'aria-grabbed': 'false' }); - addClass(overlay, 'cr-overlay'); - - self.element.appendChild(boundary); - boundary.appendChild(self.elements.preview); - boundary.appendChild(viewport); - boundary.appendChild(overlay); - - addClass(self.element, contClass); - if (self.options.customClass) { - addClass(self.element, self.options.customClass); - } - - _initDraggable.call(this); - - if (self.options.enableZoom) { - _initializeZoom.call(self); - } - - // if (self.options.enableOrientation) { - // _initRotationControls.call(self); - // } - - if (self.options.enableResize) { - _initializeResize.call(self); - } - } - - // function _initRotationControls () { - // var self = this, - // wrap, btnLeft, btnRight, iLeft, iRight; - - // wrap = document.createElement('div'); - // self.elements.orientationBtnLeft = btnLeft = document.createElement('button'); - // self.elements.orientationBtnRight = btnRight = document.createElement('button'); - - // wrap.appendChild(btnLeft); - // wrap.appendChild(btnRight); - - // iLeft = document.createElement('i'); - // iRight = document.createElement('i'); - // btnLeft.appendChild(iLeft); - // btnRight.appendChild(iRight); - - // addClass(wrap, 'cr-rotate-controls'); - // addClass(btnLeft, 'cr-rotate-l'); - // addClass(btnRight, 'cr-rotate-r'); - - // self.elements.boundary.appendChild(wrap); - - // btnLeft.addEventListener('click', function () { - // self.rotate(-90); - // }); - // btnRight.addEventListener('click', function () { - // self.rotate(90); - // }); - // } - - function _hasExif() { - return this.options.enableExif && window.EXIF; - } - - function _initializeResize () { - var self = this; - var wrap = document.createElement('div'); - var isDragging = false; - var direction; - var originalX; - var originalY; - var minSize = 50; - var maxWidth; - var maxHeight; - var vr; - var hr; - - addClass(wrap, 'cr-resizer'); - css(wrap, { - width: this.options.viewport.width + 'px', - height: this.options.viewport.height + 'px' - }); - - if (this.options.resizeControls.height) { - vr = document.createElement('div'); - addClass(vr, 'cr-resizer-vertical'); - wrap.appendChild(vr); - } - - if (this.options.resizeControls.width) { - hr = document.createElement('div'); - addClass(hr, 'cr-resizer-horisontal'); - wrap.appendChild(hr); - } - - function mouseDown(ev) { - if (ev.button !== undefined && ev.button !== 0) return; - - ev.preventDefault(); - if (isDragging) { - return; - } - - var overlayRect = self.elements.overlay.getBoundingClientRect(); - - isDragging = true; - originalX = ev.pageX; - originalY = ev.pageY; - direction = ev.currentTarget.className.indexOf('vertical') !== -1 ? 'v' : 'h'; - maxWidth = overlayRect.width; - maxHeight = overlayRect.height; - - if (ev.touches) { - var touches = ev.touches[0]; - originalX = touches.pageX; - originalY = touches.pageY; - } - - window.addEventListener('mousemove', mouseMove); - window.addEventListener('touchmove', mouseMove); - window.addEventListener('mouseup', mouseUp); - window.addEventListener('touchend', mouseUp); - document.body.style[CSS_USERSELECT] = 'none'; - } - - function mouseMove(ev) { - var pageX = ev.pageX; - var pageY = ev.pageY; - - ev.preventDefault(); - - if (ev.touches) { - var touches = ev.touches[0]; - pageX = touches.pageX; - pageY = touches.pageY; - } - - var deltaX = pageX - originalX; - var deltaY = pageY - originalY; - var newHeight = self.options.viewport.height + deltaY; - var newWidth = self.options.viewport.width + deltaX; - - if (direction === 'v' && newHeight >= minSize && newHeight <= maxHeight) { - css(wrap, { - height: newHeight + 'px' - }); - - self.options.boundary.height += deltaY; - css(self.elements.boundary, { - height: self.options.boundary.height + 'px' - }); - - self.options.viewport.height += deltaY; - css(self.elements.viewport, { - height: self.options.viewport.height + 'px' - }); - } - else if (direction === 'h' && newWidth >= minSize && newWidth <= maxWidth) { - css(wrap, { - width: newWidth + 'px' - }); - - self.options.boundary.width += deltaX; - css(self.elements.boundary, { - width: self.options.boundary.width + 'px' - }); - - self.options.viewport.width += deltaX; - css(self.elements.viewport, { - width: self.options.viewport.width + 'px' - }); - } - - _updateOverlay.call(self); - _updateZoomLimits.call(self); - _updateCenterPoint.call(self); - _triggerUpdate.call(self); - originalY = pageY; - originalX = pageX; - } - - function mouseUp() { - isDragging = false; - window.removeEventListener('mousemove', mouseMove); - window.removeEventListener('touchmove', mouseMove); - window.removeEventListener('mouseup', mouseUp); - window.removeEventListener('touchend', mouseUp); - document.body.style[CSS_USERSELECT] = ''; - } - - if (vr) { - vr.addEventListener('mousedown', mouseDown); - } - - if (hr) { - hr.addEventListener('mousedown', mouseDown); - } - - this.elements.boundary.appendChild(wrap); - } - - function _setZoomerVal(v) { - if (this.options.enableZoom) { - var z = this.elements.zoomer, - val = fix(v, 4); - - z.value = Math.max(z.min, Math.min(z.max, val)); - } - } - - function _initializeZoom() { - var self = this, - wrap = self.elements.zoomerWrap = document.createElement('div'), - zoomer = self.elements.zoomer = document.createElement('input'); - - addClass(wrap, 'cr-slider-wrap'); - addClass(zoomer, 'cr-slider'); - zoomer.type = 'range'; - zoomer.step = '0.0001'; - zoomer.value = 1; - zoomer.style.display = self.options.showZoomer ? '' : 'none'; - zoomer.setAttribute('aria-label', 'zoom'); - - self.element.appendChild(wrap); - wrap.appendChild(zoomer); - - self._currentZoom = 1; - - function change() { - _onZoom.call(self, { - value: parseFloat(zoomer.value), - origin: new TransformOrigin(self.elements.preview), - viewportRect: self.elements.viewport.getBoundingClientRect(), - transform: Transform.parse(self.elements.preview) - }); - } - - function scroll(ev) { - var delta, targetZoom; - - if (ev.wheelDelta) { - delta = ev.wheelDelta / 1200; //wheelDelta min: -120 max: 120 // max x 10 x 2 - } else if (ev.deltaY) { - delta = ev.deltaY / 1060; //deltaY min: -53 max: 53 // max x 10 x 2 - } else if (ev.detail) { - delta = ev.detail / -60; //delta min: -3 max: 3 // max x 10 x 2 - } else { - delta = 0; - } - - targetZoom = self._currentZoom + (delta * self._currentZoom); - - ev.preventDefault(); - _setZoomerVal.call(self, targetZoom); - change.call(self); - } - - self.elements.zoomer.addEventListener('input', change);// this is being fired twice on keypress - self.elements.zoomer.addEventListener('change', change); - - if (self.options.mouseWheelZoom) { - self.elements.boundary.addEventListener('mousewheel', scroll); - self.elements.boundary.addEventListener('DOMMouseScroll', scroll); - } - } - - function _onZoom(ui) { - var self = this, - transform = ui ? ui.transform : Transform.parse(self.elements.preview), - vpRect = ui ? ui.viewportRect : self.elements.viewport.getBoundingClientRect(), - origin = ui ? ui.origin : new TransformOrigin(self.elements.preview); - - function applyCss() { - var transCss = {}; - transCss[CSS_TRANSFORM] = transform.toString(); - transCss[CSS_TRANS_ORG] = origin.toString(); - css(self.elements.preview, transCss); - } - - self._currentZoom = ui ? ui.value : self._currentZoom; - transform.scale = self._currentZoom; - self.elements.zoomer.setAttribute('aria-valuenow', self._currentZoom); - applyCss(); - - if (self.options.enforceBoundary) { - var boundaries = _getVirtualBoundaries.call(self, vpRect), - transBoundaries = boundaries.translate, - oBoundaries = boundaries.origin; - - if (transform.x >= transBoundaries.maxX) { - origin.x = oBoundaries.minX; - transform.x = transBoundaries.maxX; - } - - if (transform.x <= transBoundaries.minX) { - origin.x = oBoundaries.maxX; - transform.x = transBoundaries.minX; - } - - if (transform.y >= transBoundaries.maxY) { - origin.y = oBoundaries.minY; - transform.y = transBoundaries.maxY; - } - - if (transform.y <= transBoundaries.minY) { - origin.y = oBoundaries.maxY; - transform.y = transBoundaries.minY; - } - } - applyCss(); - _debouncedOverlay.call(self); - _triggerUpdate.call(self); - } - - function _getVirtualBoundaries(viewport) { - var self = this, - scale = self._currentZoom, - vpWidth = viewport.width, - vpHeight = viewport.height, - centerFromBoundaryX = self.elements.boundary.clientWidth / 2, - centerFromBoundaryY = self.elements.boundary.clientHeight / 2, - imgRect = self.elements.preview.getBoundingClientRect(), - curImgWidth = imgRect.width, - curImgHeight = imgRect.height, - halfWidth = vpWidth / 2, - halfHeight = vpHeight / 2; - - var maxX = ((halfWidth / scale) - centerFromBoundaryX) * -1; - var minX = maxX - ((curImgWidth * (1 / scale)) - (vpWidth * (1 / scale))); - - var maxY = ((halfHeight / scale) - centerFromBoundaryY) * -1; - var minY = maxY - ((curImgHeight * (1 / scale)) - (vpHeight * (1 / scale))); - - var originMinX = (1 / scale) * halfWidth; - var originMaxX = (curImgWidth * (1 / scale)) - originMinX; - - var originMinY = (1 / scale) * halfHeight; - var originMaxY = (curImgHeight * (1 / scale)) - originMinY; - - return { - translate: { - maxX: maxX, - minX: minX, - maxY: maxY, - minY: minY - }, - origin: { - maxX: originMaxX, - minX: originMinX, - maxY: originMaxY, - minY: originMinY - } - }; - } - - function _updateCenterPoint() { - var self = this, - scale = self._currentZoom, - data = self.elements.preview.getBoundingClientRect(), - vpData = self.elements.viewport.getBoundingClientRect(), - transform = Transform.parse(self.elements.preview.style[CSS_TRANSFORM]), - pc = new TransformOrigin(self.elements.preview), - top = (vpData.top - data.top) + (vpData.height / 2), - left = (vpData.left - data.left) + (vpData.width / 2), - center = {}, - adj = {}; - - center.y = top / scale; - center.x = left / scale; - - adj.y = (center.y - pc.y) * (1 - scale); - adj.x = (center.x - pc.x) * (1 - scale); - - transform.x -= adj.x; - transform.y -= adj.y; - - var newCss = {}; - newCss[CSS_TRANS_ORG] = center.x + 'px ' + center.y + 'px'; - newCss[CSS_TRANSFORM] = transform.toString(); - css(self.elements.preview, newCss); - } - - function _initDraggable() { - var self = this, - isDragging = false, - originalX, - originalY, - originalDistance, - vpRect, - transform; - - function assignTransformCoordinates(deltaX, deltaY) { - var imgRect = self.elements.preview.getBoundingClientRect(), - top = transform.y + deltaY, - left = transform.x + deltaX; - - if (self.options.enforceBoundary) { - if (vpRect.top > imgRect.top + deltaY && vpRect.bottom < imgRect.bottom + deltaY) { - transform.y = top; - } - - if (vpRect.left > imgRect.left + deltaX && vpRect.right < imgRect.right + deltaX) { - transform.x = left; - } - } - else { - transform.y = top; - transform.x = left; - } - } - - function toggleGrabState(isDragging) { - self.elements.preview.setAttribute('aria-grabbed', isDragging); - self.elements.boundary.setAttribute('aria-dropeffect', isDragging? 'move': 'none'); - } - - function keyDown(ev) { - var LEFT_ARROW = 37, - UP_ARROW = 38, - RIGHT_ARROW = 39, - DOWN_ARROW = 40; - - if (ev.shiftKey && (ev.keyCode == UP_ARROW || ev.keyCode == DOWN_ARROW)) { - var zoom = 0.0; - if (ev.keyCode == UP_ARROW) { - zoom = parseFloat(self.elements.zoomer.value, 10) + parseFloat(self.elements.zoomer.step, 10) - } - else { - zoom = parseFloat(self.elements.zoomer.value, 10) - parseFloat(self.elements.zoomer.step, 10) - } - self.setZoom(zoom); - } - else if (self.options.enableKeyMovement && (ev.keyCode >= 37 && ev.keyCode <= 40)) { - ev.preventDefault(); - var movement = parseKeyDown(ev.keyCode); - - transform = Transform.parse(self.elements.preview); - document.body.style[CSS_USERSELECT] = 'none'; - vpRect = self.elements.viewport.getBoundingClientRect(); - keyMove(movement); - }; - - function parseKeyDown(key) { - switch (key) { - case LEFT_ARROW: - return [1, 0]; - case UP_ARROW: - return [0, 1]; - case RIGHT_ARROW: - return [-1, 0]; - case DOWN_ARROW: - return [0, -1]; - }; - }; - } - - function keyMove(movement) { - var deltaX = movement[0], - deltaY = movement[1], - newCss = {}; - - assignTransformCoordinates(deltaX, deltaY); - - newCss[CSS_TRANSFORM] = transform.toString(); - css(self.elements.preview, newCss); - _updateOverlay.call(self); - document.body.style[CSS_USERSELECT] = ''; - _updateCenterPoint.call(self); - _triggerUpdate.call(self); - originalDistance = 0; - } - - function mouseDown(ev) { - if (ev.button !== undefined && ev.button !== 0) return; - - ev.preventDefault(); - if (isDragging) return; - isDragging = true; - originalX = ev.pageX; - originalY = ev.pageY; - - if (ev.touches) { - var touches = ev.touches[0]; - originalX = touches.pageX; - originalY = touches.pageY; - } - toggleGrabState(isDragging); - transform = Transform.parse(self.elements.preview); - window.addEventListener('mousemove', mouseMove); - window.addEventListener('touchmove', mouseMove); - window.addEventListener('mouseup', mouseUp); - window.addEventListener('touchend', mouseUp); - document.body.style[CSS_USERSELECT] = 'none'; - vpRect = self.elements.viewport.getBoundingClientRect(); - } - - function mouseMove(ev) { - ev.preventDefault(); - var pageX = ev.pageX, - pageY = ev.pageY; - - if (ev.touches) { - var touches = ev.touches[0]; - pageX = touches.pageX; - pageY = touches.pageY; - } - - var deltaX = pageX - originalX, - deltaY = pageY - originalY, - newCss = {}; - - if (ev.type == 'touchmove') { - if (ev.touches.length > 1) { - var touch1 = ev.touches[0]; - var touch2 = ev.touches[1]; - var dist = Math.sqrt((touch1.pageX - touch2.pageX) * (touch1.pageX - touch2.pageX) + (touch1.pageY - touch2.pageY) * (touch1.pageY - touch2.pageY)); - - if (!originalDistance) { - originalDistance = dist / self._currentZoom; - } - - var scale = dist / originalDistance; - - _setZoomerVal.call(self, scale); - dispatchChange(self.elements.zoomer); - return; - } - } - - assignTransformCoordinates(deltaX, deltaY); - - newCss[CSS_TRANSFORM] = transform.toString(); - css(self.elements.preview, newCss); - _updateOverlay.call(self); - originalY = pageY; - originalX = pageX; - } - - function mouseUp() { - isDragging = false; - toggleGrabState(isDragging); - window.removeEventListener('mousemove', mouseMove); - window.removeEventListener('touchmove', mouseMove); - window.removeEventListener('mouseup', mouseUp); - window.removeEventListener('touchend', mouseUp); - document.body.style[CSS_USERSELECT] = ''; - _updateCenterPoint.call(self); - _triggerUpdate.call(self); - originalDistance = 0; - } - - self.elements.overlay.addEventListener('mousedown', mouseDown); - self.elements.viewport.addEventListener('keydown', keyDown); - self.elements.overlay.addEventListener('touchstart', mouseDown); - } - - function _updateOverlay() { - var self = this, - boundRect = self.elements.boundary.getBoundingClientRect(), - imgData = self.elements.preview.getBoundingClientRect(); - - css(self.elements.overlay, { - width: imgData.width + 'px', - height: imgData.height + 'px', - top: (imgData.top - boundRect.top) + 'px', - left: (imgData.left - boundRect.left) + 'px' - }); - } - var _debouncedOverlay = debounce(_updateOverlay, 500); - - function _triggerUpdate() { - var self = this, - data = self.get(), - ev; - - if (!_isVisible.call(self)) { - return; - } - - self.options.update.call(self, data); - if (self.$ && typeof Prototype == 'undefined') { - self.$(self.element).trigger('update', data); - } - else { - var ev; - if (window.CustomEvent) { - ev = new CustomEvent('update', { detail: data }); - } else { - ev = document.createEvent('CustomEvent'); - ev.initCustomEvent('update', true, true, data); - } - - self.element.dispatchEvent(ev); - } - } - - function _isVisible() { - return this.elements.preview.offsetHeight > 0 && this.elements.preview.offsetWidth > 0; - } - - function _updatePropertiesFromImage() { - var self = this, - initialZoom = 1, - cssReset = {}, - img = self.elements.preview, - imgData = null, - transformReset = new Transform(0, 0, initialZoom), - originReset = new TransformOrigin(), - isVisible = _isVisible.call(self); - - if (!isVisible || self.data.bound) { - // if the croppie isn't visible or it doesn't need binding - return; - } - - self.data.bound = true; - cssReset[CSS_TRANSFORM] = transformReset.toString(); - cssReset[CSS_TRANS_ORG] = originReset.toString(); - cssReset['opacity'] = 1; - css(img, cssReset); - - imgData = self.elements.preview.getBoundingClientRect(); - - self._originalImageWidth = imgData.width; - self._originalImageHeight = imgData.height; - - if (self.options.enableZoom) { - _updateZoomLimits.call(self, true); - } - else { - self._currentZoom = initialZoom; - } - - transformReset.scale = self._currentZoom; - cssReset[CSS_TRANSFORM] = transformReset.toString(); - css(img, cssReset); - - if (self.data.points.length) { - _bindPoints.call(self, self.data.points); - } - else { - _centerImage.call(self); - } - - _updateCenterPoint.call(self); - _updateOverlay.call(self); - } - - function _updateZoomLimits (initial) { - var self = this, - minZoom = 0, - maxZoom = 1.5, - initialZoom, - defaultInitialZoom, - zoomer = self.elements.zoomer, - scale = parseFloat(zoomer.value), - boundaryData = self.elements.boundary.getBoundingClientRect(), - imgData = self.elements.preview.getBoundingClientRect(), - vpData = self.elements.viewport.getBoundingClientRect(), - minW, - minH; - - if (self.options.enforceBoundary) { - minW = vpData.width / (initial ? imgData.width : imgData.width / scale); - minH = vpData.height / (initial ? imgData.height : imgData.height / scale); - minZoom = Math.max(minW, minH); - } - - if (minZoom >= maxZoom) { - maxZoom = minZoom + 1; - } - - zoomer.min = fix(minZoom, 4); - zoomer.max = fix(maxZoom, 4); - - if (initial) { - defaultInitialZoom = Math.max((boundaryData.width / imgData.width), (boundaryData.height / imgData.height)); - initialZoom = self.data.boundZoom !== null ? self.data.boundZoom : defaultInitialZoom; - _setZoomerVal.call(self, initialZoom); - } - - dispatchChange(zoomer); - } - - function _bindPoints(points) { - if (points.length != 4) { - throw "Croppie - Invalid number of points supplied: " + points; - } - var self = this, - pointsWidth = points[2] - points[0], - // pointsHeight = points[3] - points[1], - vpData = self.elements.viewport.getBoundingClientRect(), - boundRect = self.elements.boundary.getBoundingClientRect(), - vpOffset = { - left: vpData.left - boundRect.left, - top: vpData.top - boundRect.top - }, - scale = vpData.width / pointsWidth, - originTop = points[1], - originLeft = points[0], - transformTop = (-1 * points[1]) + vpOffset.top, - transformLeft = (-1 * points[0]) + vpOffset.left, - newCss = {}; - - newCss[CSS_TRANS_ORG] = originLeft + 'px ' + originTop + 'px'; - newCss[CSS_TRANSFORM] = new Transform(transformLeft, transformTop, scale).toString(); - css(self.elements.preview, newCss); - - _setZoomerVal.call(self, scale); - self._currentZoom = scale; - } - - function _centerImage() { - var self = this, - imgDim = self.elements.preview.getBoundingClientRect(), - vpDim = self.elements.viewport.getBoundingClientRect(), - boundDim = self.elements.boundary.getBoundingClientRect(), - vpLeft = vpDim.left - boundDim.left, - vpTop = vpDim.top - boundDim.top, - w = vpLeft - ((imgDim.width - vpDim.width) / 2), - h = vpTop - ((imgDim.height - vpDim.height) / 2), - transform = new Transform(w, h, self._currentZoom); - - css(self.elements.preview, CSS_TRANSFORM, transform.toString()); - } - - function _transferImageToCanvas(customOrientation) { - var self = this, - canvas = self.elements.canvas, - img = self.elements.img, - ctx = canvas.getContext('2d'), - exif = _hasExif.call(self), - customOrientation = self.options.enableOrientation && customOrientation; - - ctx.clearRect(0, 0, canvas.width, canvas.height); - canvas.width = img.width; - canvas.height = img.height; - - if (exif && !customOrientation) { - var orientation = getExifOrientation(img); - drawCanvas(canvas, img, num(orientation || 0, 10)); - } - else if (customOrientation) { - drawCanvas(canvas, img, customOrientation); - } - } - - function _getCanvas(data) { - var self = this, - points = data.points, - left = num(points[0]), - top = num(points[1]), - right = num(points[2]), - bottom = num(points[3]), - width = right-left, - height = bottom-top, - circle = data.circle, - canvas = document.createElement('canvas'), - ctx = canvas.getContext('2d'), - outWidth = width, - outHeight = height, - startX = 0, - startY = 0, - canvasWidth = outWidth, - canvasHeight = outHeight, - customDimensions = (data.outputWidth && data.outputHeight), - outputWidthRatio = 1; - outputHeightRatio = 1; - - if (customDimensions) { - canvasWidth = data.outputWidth; - canvasHeight = data.outputHeight; - outputWidthRatio = canvasWidth / outWidth; - outputHeightRatio = canvasHeight / outHeight; - } - - canvas.width = canvasWidth; - canvas.height = canvasHeight; - - if (data.backgroundColor) { - ctx.fillStyle = data.backgroundColor; - ctx.fillRect(0, 0, canvasWidth, canvasHeight); - } - - - // start fixing data to send to draw image for enforceBoundary: false - if (!self.options.enforceBoundary) { - if (left < 0) { - startX = Math.abs(left); - left = 0; - } - if (top < 0) { - startY = Math.abs(top); - top = 0; - } - if (right > self._originalImageWidth) { - width = self._originalImageWidth - left; - outWidth = width; - } - if (bottom > self._originalImageHeight) { - height = self._originalImageHeight - top; - outHeight = height; - } - } - else{ - width=Math.min(width, self._originalImageWidth); - height=Math.min(height, self._originalImageHeight) - } - - if (outputWidthRatio !== 1 || outputHeightRatio !== 1) { - startX *= outputWidthRatio; - startY *= outputHeightRatio; - outWidth *= outputWidthRatio; - outHeight *= outputHeightRatio; - } - ctx.drawImage(this.elements.preview, left, top, width, height, startX, startY, outWidth, outHeight); - if (circle) { - ctx.fillStyle = '#fff'; - ctx.globalCompositeOperation = 'destination-in'; - ctx.beginPath(); - ctx.arc(outWidth / 2, outHeight / 2, outWidth / 2, 0, Math.PI * 2, true); - ctx.closePath(); - ctx.fill(); - } - return canvas; - } - - function _getHtmlResult(data) { - var points = data.points, - div = document.createElement('div'), - img = document.createElement('img'), - width = points[2] - points[0], - height = points[3] - points[1]; - - addClass(div, 'croppie-result'); - div.appendChild(img); - css(img, { - left: (-1 * points[0]) + 'px', - top: (-1 * points[1]) + 'px' - }); - img.src = data.url; - css(div, { - width: width + 'px', - height: height + 'px' - }); - - return div; - } - - function _getBase64Result(data) { - return _getCanvas.call(this, data).toDataURL(data.format, data.quality); - } - - function _getBlobResult(data) { - var self = this; - return new Promise(function (resolve, reject) { - _getCanvas.call(self, data).toBlob(function (blob) { - resolve(blob); - }, data.format, data.quality); - }); - } - - function _bind(options, cb) { - var self = this, - url, - points = [], - zoom = null, - hasExif = _hasExif.call(self);; - - if (typeof (options) === 'string') { - url = options; - options = {}; - } - else if (Array.isArray(options)) { - points = options.slice(); - } - else if (typeof (options) == 'undefined' && self.data.url) { //refreshing - _updatePropertiesFromImage.call(self); - _triggerUpdate.call(self); - return null; - } - else { - url = options.url; - points = options.points || []; - zoom = typeof(options.zoom) === 'undefined' ? null : options.zoom; - } - - self.data.bound = false; - self.data.url = url || self.data.url; - self.data.boundZoom = zoom; - - return loadImage(url, self.elements.img, hasExif).then(function (img) { - if (!points.length) { - var natDim = naturalImageDimensions(img); - var rect = self.elements.viewport.getBoundingClientRect(); - var aspectRatio = rect.width / rect.height; - var imgAspectRatio = natDim.width / natDim.height; - var width, height; - - if (imgAspectRatio > aspectRatio) { - height = natDim.height; - width = height * aspectRatio; - } - else { - width = natDim.width; - height = width / aspectRatio; - } - - var x0 = (natDim.width - width) / 2; - var y0 = (natDim.height - height) / 2; - var x1 = x0 + width; - var y1 = y0 + height; - - self.data.points = [x0, y0, x1, y1]; - } - else if (self.options.relative) { - points = [ - points[0] * img.naturalWidth / 100, - points[1] * img.naturalHeight / 100, - points[2] * img.naturalWidth / 100, - points[3] * img.naturalHeight / 100 - ]; - } - - self.data.points = points.map(function (p) { - return parseFloat(p); - }); - if (self.options.useCanvas) { - _transferImageToCanvas.call(self, options.orientation || 1); - } - _updatePropertiesFromImage.call(self); - _triggerUpdate.call(self); - cb && cb(); - }); - } - - function fix(v, decimalPoints) { - return parseFloat(v).toFixed(decimalPoints || 0); - } - - function _get() { - var self = this, - imgData = self.elements.preview.getBoundingClientRect(), - vpData = self.elements.viewport.getBoundingClientRect(), - x1 = vpData.left - imgData.left, - y1 = vpData.top - imgData.top, - widthDiff = (vpData.width - self.elements.viewport.offsetWidth) / 2, //border - heightDiff = (vpData.height - self.elements.viewport.offsetHeight) / 2, - x2 = x1 + self.elements.viewport.offsetWidth + widthDiff, - y2 = y1 + self.elements.viewport.offsetHeight + heightDiff, - scale = self._currentZoom; - - if (scale === Infinity || isNaN(scale)) { - scale = 1; - } - - var max = self.options.enforceBoundary ? 0 : Number.NEGATIVE_INFINITY; - x1 = Math.max(max, x1 / scale); - y1 = Math.max(max, y1 / scale); - x2 = Math.max(max, x2 / scale); - y2 = Math.max(max, y2 / scale); - - return { - points: [fix(x1), fix(y1), fix(x2), fix(y2)], - zoom: scale - }; - } - - var RESULT_DEFAULTS = { - type: 'canvas', - format: 'png', - quality: 1 - }, - RESULT_FORMATS = ['jpeg', 'webp', 'png']; - - function _result(options) { - var self = this, - data = _get.call(self), - opts = deepExtend(RESULT_DEFAULTS, deepExtend({}, options)), - resultType = (typeof (options) === 'string' ? options : (opts.type || 'base64')), - size = opts.size || 'viewport', - format = opts.format, - quality = opts.quality, - backgroundColor = opts.backgroundColor, - circle = typeof opts.circle === 'boolean' ? opts.circle : (self.options.viewport.type === 'circle'), - vpRect = self.elements.viewport.getBoundingClientRect(), - ratio = vpRect.width / vpRect.height, - prom; - - if (size === 'viewport') { - data.outputWidth = vpRect.width; - data.outputHeight = vpRect.height; - } else if (typeof size === 'object') { - if (size.width && size.height) { - data.outputWidth = size.width; - data.outputHeight = size.height; - } else if (size.width) { - data.outputWidth = size.width; - data.outputHeight = size.width / ratio; - } else if (size.height) { - data.outputWidth = size.height * ratio; - data.outputHeight = size.height; - } - } - - if (RESULT_FORMATS.indexOf(format) > -1) { - data.format = 'image/' + format; - data.quality = quality; - } - - data.circle = circle; - data.url = self.data.url; - data.backgroundColor = backgroundColor; - - prom = new Promise(function (resolve, reject) { - switch(resultType.toLowerCase()) - { - case 'rawcanvas': - resolve(_getCanvas.call(self, data)); - break; - case 'canvas': - case 'base64': - resolve(_getBase64Result.call(self, data)); - break; - case 'blob': - _getBlobResult.call(self, data).then(resolve); - break; - default: - resolve(_getHtmlResult.call(self, data)); - break; - } - }); - return prom; - } - - function _refresh() { - _updatePropertiesFromImage.call(this); - } - - function _rotate(deg) { - if (!this.options.useCanvas) { - throw 'Croppie: Cannot rotate without enableOrientation'; - } - - var self = this, - canvas = self.elements.canvas, - copy = document.createElement('canvas'), - ornt = 1; - - copy.width = canvas.width; - copy.height = canvas.height; - var ctx = copy.getContext('2d'); - ctx.drawImage(canvas, 0, 0); - - if (deg === 90 || deg === -270) ornt = 6; - if (deg === -90 || deg === 270) ornt = 8; - if (deg === 180 || deg === -180) ornt = 3; - - drawCanvas(canvas, copy, ornt); - _onZoom.call(self); - copy = null; - } - - function _destroy() { - var self = this; - self.element.removeChild(self.elements.boundary); - removeClass(self.element, 'croppie-container'); - if (self.options.enableZoom) { - self.element.removeChild(self.elements.zoomerWrap); - } - delete self.elements; - } - - if (window.jQuery) { - var $ = window.jQuery; - $.fn.croppie = function (opts) { - var ot = typeof opts; - - if (ot === 'string') { - var args = Array.prototype.slice.call(arguments, 1); - var singleInst = $(this).data('croppie'); - - if (opts === 'get') { - return singleInst.get(); - } - else if (opts === 'result') { - return singleInst.result.apply(singleInst, args); - } - else if (opts === 'bind') { - return singleInst.bind.apply(singleInst, args); - } - - return this.each(function () { - var i = $(this).data('croppie'); - if (!i) return; - - var method = i[opts]; - if ($.isFunction(method)) { - method.apply(i, args); - if (opts === 'destroy') { - $(this).removeData('croppie'); - } - } - else { - throw 'Croppie ' + opts + ' method not found'; - } - }); - } - else { - return this.each(function () { - var i = new Croppie(this, opts); - i.$ = $; - $(this).data('croppie', i); - }); - } - }; - } - - function Croppie(element, opts) { - this.element = element; - this.options = deepExtend(deepExtend({}, Croppie.defaults), opts); - - if (this.element.tagName.toLowerCase() === 'img') { - var origImage = this.element; - addClass(origImage, 'cr-original-image'); - setAttributes(origImage, {'aria-hidden' : 'true', 'alt' : '' }); - var replacementDiv = document.createElement('div'); - this.element.parentNode.appendChild(replacementDiv); - replacementDiv.appendChild(origImage); - this.element = replacementDiv; - this.options.url = this.options.url || origImage.src; - } - - _create.call(this); - if (this.options.url) { - var bindOpts = { - url: this.options.url, - points: this.options.points - }; - delete this.options['url']; - delete this.options['points']; - _bind.call(this, bindOpts); - } - } - - Croppie.defaults = { - viewport: { - width: 100, - height: 100, - type: 'square' - }, - boundary: { }, - orientationControls: { - enabled: true, - leftClass: '', - rightClass: '' - }, - resizeControls: { - width: true, - height: true - }, - customClass: '', - showZoomer: true, - enableZoom: true, - enableResize: false, - mouseWheelZoom: true, - enableExif: false, - enforceBoundary: true, - enableOrientation: false, - enableKeyMovement: true, - update: function () { } - }; - - Croppie.globals = { - translate: 'translate3d' - }; - - deepExtend(Croppie.prototype, { - bind: function (options, cb) { - return _bind.call(this, options, cb); - }, - get: function () { - var data = _get.call(this); - var points = data.points; - if (this.options.relative) { - points[0] /= this.elements.img.naturalWidth / 100; - points[1] /= this.elements.img.naturalHeight / 100; - points[2] /= this.elements.img.naturalWidth / 100; - points[3] /= this.elements.img.naturalHeight / 100; - } - return data; - }, - result: function (type) { - return _result.call(this, type); - }, - refresh: function () { - return _refresh.call(this); - }, - setZoom: function (v) { - _setZoomerVal.call(this, v); - dispatchChange(this.elements.zoomer); - }, - rotate: function (deg) { - _rotate.call(this, deg); - }, - destroy: function () { - return _destroy.call(this); - } - }); - - exports.Croppie = window.Croppie = Croppie; - - if (typeof module === 'object' && !!module.exports) { - module.exports = Croppie; - } -})); diff --git a/includes/default.bitsy b/includes/default.bitsy deleted file mode 100644 index ebe7a54..0000000 --- a/includes/default.bitsy +++ /dev/null @@ -1,84 +0,0 @@ -Write your game's title here - -# BITSY VERSION 5.3 - -! ROOM_FORMAT 1 - -PAL 0 -0,82,204 -128,159,255 -255,255,255 - -ROOM 0 -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -0,a,a,a,a,a,a,a,a,a,a,a,a,a,a,0 -0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 -0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 -0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 -0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 -0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 -0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 -0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 -0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 -0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 -0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 -0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 -0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 -0,a,a,a,a,a,a,a,a,a,a,a,a,a,a,0 -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -PAL 0 - -TIL a -11111111 -10000001 -10000001 -10011001 -10011001 -10000001 -10000001 -11111111 - -SPR A -00011000 -00011000 -00011000 -00111100 -01111110 -10111101 -00100100 -00100100 -POS 0 4,4 - -SPR a -00000000 -00000000 -01010001 -01110001 -01110010 -01111100 -00111100 -00100100 -DLG SPR_0 -POS 0 8,12 - -ITM 0 -00000000 -00000000 -00000000 -00111100 -01100100 -00100100 -00011000 -00000000 -NAME tea -DLG ITM_0 - -DLG SPR_0 -I'm a cat - -DLG ITM_0 -You found a nice warm cup of tea - -VAR a -42 - diff --git a/includes/jquery.min.js b/includes/jquery.min.js deleted file mode 100644 index 47b6397..0000000 --- a/includes/jquery.min.js +++ /dev/null @@ -1,2 +0,0 @@ -/*! jQuery v3.5.0 | (c) JS Foundation and other contributors | jquery.org/license */ -!function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(C,e){"use strict";var t=[],r=Object.getPrototypeOf,s=t.slice,g=t.flat?function(e){return t.flat.call(e)}:function(e){return t.concat.apply([],e)},u=t.push,i=t.indexOf,n={},o=n.toString,v=n.hasOwnProperty,a=v.toString,l=a.call(Object),y={},m=function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},x=function(e){return null!=e&&e===e.window},E=C.document,c={type:!0,src:!0,nonce:!0,noModule:!0};function b(e,t,n){var r,i,o=(n=n||E).createElement("script");if(o.text=e,t)for(r in c)(i=t[r]||t.getAttribute&&t.getAttribute(r))&&o.setAttribute(r,i);n.head.appendChild(o).parentNode.removeChild(o)}function w(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?n[o.call(e)]||"object":typeof e}var f="3.5.0",S=function(e,t){return new S.fn.init(e,t)};function p(e){var t=!!e&&"length"in e&&e.length,n=w(e);return!m(e)&&!x(e)&&("array"===n||0===t||"number"==typeof t&&0+~]|"+M+")"+M+"*"),U=new RegExp(M+"|>"),X=new RegExp(F),V=new RegExp("^"+I+"$"),G={ID:new RegExp("^#("+I+")"),CLASS:new RegExp("^\\.("+I+")"),TAG:new RegExp("^("+I+"|[*])"),ATTR:new RegExp("^"+W),PSEUDO:new RegExp("^"+F),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+R+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/HTML$/i,Q=/^(?:input|select|textarea|button)$/i,J=/^h\d$/i,K=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ee=/[+~]/,te=new RegExp("\\\\[\\da-fA-F]{1,6}"+M+"?|\\\\([^\\r\\n\\f])","g"),ne=function(e,t){var n="0x"+e.slice(1)-65536;return t||(n<0?String.fromCharCode(n+65536):String.fromCharCode(n>>10|55296,1023&n|56320))},re=/([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-\uFFFF\w-]/g,ie=function(e,t){return t?"\0"===e?"\ufffd":e.slice(0,-1)+"\\"+e.charCodeAt(e.length-1).toString(16)+" ":"\\"+e},oe=function(){T()},ae=be(function(e){return!0===e.disabled&&"fieldset"===e.nodeName.toLowerCase()},{dir:"parentNode",next:"legend"});try{H.apply(t=O.call(p.childNodes),p.childNodes),t[p.childNodes.length].nodeType}catch(e){H={apply:t.length?function(e,t){L.apply(e,O.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function se(t,e,n,r){var i,o,a,s,u,l,c,f=e&&e.ownerDocument,p=e?e.nodeType:9;if(n=n||[],"string"!=typeof t||!t||1!==p&&9!==p&&11!==p)return n;if(!r&&(T(e),e=e||C,E)){if(11!==p&&(u=Z.exec(t)))if(i=u[1]){if(9===p){if(!(a=e.getElementById(i)))return n;if(a.id===i)return n.push(a),n}else if(f&&(a=f.getElementById(i))&&y(e,a)&&a.id===i)return n.push(a),n}else{if(u[2])return H.apply(n,e.getElementsByTagName(t)),n;if((i=u[3])&&d.getElementsByClassName&&e.getElementsByClassName)return H.apply(n,e.getElementsByClassName(i)),n}if(d.qsa&&!N[t+" "]&&(!v||!v.test(t))&&(1!==p||"object"!==e.nodeName.toLowerCase())){if(c=t,f=e,1===p&&(U.test(t)||z.test(t))){(f=ee.test(t)&&ye(e.parentNode)||e)===e&&d.scope||((s=e.getAttribute("id"))?s=s.replace(re,ie):e.setAttribute("id",s=S)),o=(l=h(t)).length;while(o--)l[o]=(s?"#"+s:":scope")+" "+xe(l[o]);c=l.join(",")}try{return H.apply(n,f.querySelectorAll(c)),n}catch(e){N(t,!0)}finally{s===S&&e.removeAttribute("id")}}}return g(t.replace($,"$1"),e,n,r)}function ue(){var r=[];return function e(t,n){return r.push(t+" ")>b.cacheLength&&delete e[r.shift()],e[t+" "]=n}}function le(e){return e[S]=!0,e}function ce(e){var t=C.createElement("fieldset");try{return!!e(t)}catch(e){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function fe(e,t){var n=e.split("|"),r=n.length;while(r--)b.attrHandle[n[r]]=t}function pe(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&e.sourceIndex-t.sourceIndex;if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function de(t){return function(e){return"input"===e.nodeName.toLowerCase()&&e.type===t}}function he(n){return function(e){var t=e.nodeName.toLowerCase();return("input"===t||"button"===t)&&e.type===n}}function ge(t){return function(e){return"form"in e?e.parentNode&&!1===e.disabled?"label"in e?"label"in e.parentNode?e.parentNode.disabled===t:e.disabled===t:e.isDisabled===t||e.isDisabled!==!t&&ae(e)===t:e.disabled===t:"label"in e&&e.disabled===t}}function ve(a){return le(function(o){return o=+o,le(function(e,t){var n,r=a([],e.length,o),i=r.length;while(i--)e[n=r[i]]&&(e[n]=!(t[n]=e[n]))})})}function ye(e){return e&&"undefined"!=typeof e.getElementsByTagName&&e}for(e in d=se.support={},i=se.isXML=function(e){var t=e.namespaceURI,n=(e.ownerDocument||e).documentElement;return!Y.test(t||n&&n.nodeName||"HTML")},T=se.setDocument=function(e){var t,n,r=e?e.ownerDocument||e:p;return r!=C&&9===r.nodeType&&r.documentElement&&(a=(C=r).documentElement,E=!i(C),p!=C&&(n=C.defaultView)&&n.top!==n&&(n.addEventListener?n.addEventListener("unload",oe,!1):n.attachEvent&&n.attachEvent("onunload",oe)),d.scope=ce(function(e){return a.appendChild(e).appendChild(C.createElement("div")),"undefined"!=typeof e.querySelectorAll&&!e.querySelectorAll(":scope fieldset div").length}),d.attributes=ce(function(e){return e.className="i",!e.getAttribute("className")}),d.getElementsByTagName=ce(function(e){return e.appendChild(C.createComment("")),!e.getElementsByTagName("*").length}),d.getElementsByClassName=K.test(C.getElementsByClassName),d.getById=ce(function(e){return a.appendChild(e).id=S,!C.getElementsByName||!C.getElementsByName(S).length}),d.getById?(b.filter.ID=function(e){var t=e.replace(te,ne);return function(e){return e.getAttribute("id")===t}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&E){var n=t.getElementById(e);return n?[n]:[]}}):(b.filter.ID=function(e){var n=e.replace(te,ne);return function(e){var t="undefined"!=typeof e.getAttributeNode&&e.getAttributeNode("id");return t&&t.value===n}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&E){var n,r,i,o=t.getElementById(e);if(o){if((n=o.getAttributeNode("id"))&&n.value===e)return[o];i=t.getElementsByName(e),r=0;while(o=i[r++])if((n=o.getAttributeNode("id"))&&n.value===e)return[o]}return[]}}),b.find.TAG=d.getElementsByTagName?function(e,t){return"undefined"!=typeof t.getElementsByTagName?t.getElementsByTagName(e):d.qsa?t.querySelectorAll(e):void 0}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},b.find.CLASS=d.getElementsByClassName&&function(e,t){if("undefined"!=typeof t.getElementsByClassName&&E)return t.getElementsByClassName(e)},s=[],v=[],(d.qsa=K.test(C.querySelectorAll))&&(ce(function(e){var t;a.appendChild(e).innerHTML="",e.querySelectorAll("[msallowcapture^='']").length&&v.push("[*^$]="+M+"*(?:''|\"\")"),e.querySelectorAll("[selected]").length||v.push("\\["+M+"*(?:value|"+R+")"),e.querySelectorAll("[id~="+S+"-]").length||v.push("~="),(t=C.createElement("input")).setAttribute("name",""),e.appendChild(t),e.querySelectorAll("[name='']").length||v.push("\\["+M+"*name"+M+"*="+M+"*(?:''|\"\")"),e.querySelectorAll(":checked").length||v.push(":checked"),e.querySelectorAll("a#"+S+"+*").length||v.push(".#.+[+~]"),e.querySelectorAll("\\\f"),v.push("[\\r\\n\\f]")}),ce(function(e){e.innerHTML="";var t=C.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("name","D"),e.querySelectorAll("[name=d]").length&&v.push("name"+M+"*[*^$|!~]?="),2!==e.querySelectorAll(":enabled").length&&v.push(":enabled",":disabled"),a.appendChild(e).disabled=!0,2!==e.querySelectorAll(":disabled").length&&v.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),v.push(",.*:")})),(d.matchesSelector=K.test(c=a.matches||a.webkitMatchesSelector||a.mozMatchesSelector||a.oMatchesSelector||a.msMatchesSelector))&&ce(function(e){d.disconnectedMatch=c.call(e,"*"),c.call(e,"[s!='']:x"),s.push("!=",F)}),v=v.length&&new RegExp(v.join("|")),s=s.length&&new RegExp(s.join("|")),t=K.test(a.compareDocumentPosition),y=t||K.test(a.contains)?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},D=t?function(e,t){if(e===t)return l=!0,0;var n=!e.compareDocumentPosition-!t.compareDocumentPosition;return n||(1&(n=(e.ownerDocument||e)==(t.ownerDocument||t)?e.compareDocumentPosition(t):1)||!d.sortDetached&&t.compareDocumentPosition(e)===n?e==C||e.ownerDocument==p&&y(p,e)?-1:t==C||t.ownerDocument==p&&y(p,t)?1:u?P(u,e)-P(u,t):0:4&n?-1:1)}:function(e,t){if(e===t)return l=!0,0;var n,r=0,i=e.parentNode,o=t.parentNode,a=[e],s=[t];if(!i||!o)return e==C?-1:t==C?1:i?-1:o?1:u?P(u,e)-P(u,t):0;if(i===o)return pe(e,t);n=e;while(n=n.parentNode)a.unshift(n);n=t;while(n=n.parentNode)s.unshift(n);while(a[r]===s[r])r++;return r?pe(a[r],s[r]):a[r]==p?-1:s[r]==p?1:0}),C},se.matches=function(e,t){return se(e,null,null,t)},se.matchesSelector=function(e,t){if(T(e),d.matchesSelector&&E&&!N[t+" "]&&(!s||!s.test(t))&&(!v||!v.test(t)))try{var n=c.call(e,t);if(n||d.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(e){N(t,!0)}return 0":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(te,ne),e[3]=(e[3]||e[4]||e[5]||"").replace(te,ne),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||se.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&se.error(e[0]),e},PSEUDO:function(e){var t,n=!e[6]&&e[2];return G.CHILD.test(e[0])?null:(e[3]?e[2]=e[4]||e[5]||"":n&&X.test(n)&&(t=h(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(te,ne).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=m[e+" "];return t||(t=new RegExp("(^|"+M+")"+e+"("+M+"|$)"))&&m(e,function(e){return t.test("string"==typeof e.className&&e.className||"undefined"!=typeof e.getAttribute&&e.getAttribute("class")||"")})},ATTR:function(n,r,i){return function(e){var t=se.attr(e,n);return null==t?"!="===r:!r||(t+="","="===r?t===i:"!="===r?t!==i:"^="===r?i&&0===t.indexOf(i):"*="===r?i&&-1:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i;function D(e,n,r){return m(n)?S.grep(e,function(e,t){return!!n.call(e,t,e)!==r}):n.nodeType?S.grep(e,function(e){return e===n!==r}):"string"!=typeof n?S.grep(e,function(e){return-1)[^>]*|#([\w-]+))$/;(S.fn.init=function(e,t,n){var r,i;if(!e)return this;if(n=n||j,"string"==typeof e){if(!(r="<"===e[0]&&">"===e[e.length-1]&&3<=e.length?[null,e,null]:q.exec(e))||!r[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(r[1]){if(t=t instanceof S?t[0]:t,S.merge(this,S.parseHTML(r[1],t&&t.nodeType?t.ownerDocument||t:E,!0)),N.test(r[1])&&S.isPlainObject(t))for(r in t)m(this[r])?this[r](t[r]):this.attr(r,t[r]);return this}return(i=E.getElementById(r[2]))&&(this[0]=i,this.length=1),this}return e.nodeType?(this[0]=e,this.length=1,this):m(e)?void 0!==n.ready?n.ready(e):e(S):S.makeArray(e,this)}).prototype=S.fn,j=S(E);var L=/^(?:parents|prev(?:Until|All))/,H={children:!0,contents:!0,next:!0,prev:!0};function O(e,t){while((e=e[t])&&1!==e.nodeType);return e}S.fn.extend({has:function(e){var t=S(e,this),n=t.length;return this.filter(function(){for(var e=0;e\x20\t\r\n\f]*)/i,he=/^$|^module$|\/(?:java|ecma)script/i;ce=E.createDocumentFragment().appendChild(E.createElement("div")),(fe=E.createElement("input")).setAttribute("type","radio"),fe.setAttribute("checked","checked"),fe.setAttribute("name","t"),ce.appendChild(fe),y.checkClone=ce.cloneNode(!0).cloneNode(!0).lastChild.checked,ce.innerHTML="",y.noCloneChecked=!!ce.cloneNode(!0).lastChild.defaultValue,ce.innerHTML="",y.option=!!ce.lastChild;var ge={thead:[1,"","
"],col:[2,"","
"],tr:[2,"","
"],td:[3,"","
"],_default:[0,"",""]};function ve(e,t){var n;return n="undefined"!=typeof e.getElementsByTagName?e.getElementsByTagName(t||"*"):"undefined"!=typeof e.querySelectorAll?e.querySelectorAll(t||"*"):[],void 0===t||t&&A(e,t)?S.merge([e],n):n}function ye(e,t){for(var n=0,r=e.length;n",""]);var me=/<|&#?\w+;/;function xe(e,t,n,r,i){for(var o,a,s,u,l,c,f=t.createDocumentFragment(),p=[],d=0,h=e.length;d\s*$/g;function qe(e,t){return A(e,"table")&&A(11!==t.nodeType?t:t.firstChild,"tr")&&S(e).children("tbody")[0]||e}function Le(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function He(e){return"true/"===(e.type||"").slice(0,5)?e.type=e.type.slice(5):e.removeAttribute("type"),e}function Oe(e,t){var n,r,i,o,a,s;if(1===t.nodeType){if(Y.hasData(e)&&(s=Y.get(e).events))for(i in Y.remove(t,"handle events"),s)for(n=0,r=s[i].length;n").attr(n.scriptAttrs||{}).prop({charset:n.scriptCharset,src:n.url}).on("load error",i=function(e){r.remove(),i=null,e&&t("error"===e.type?404:200,e.type)}),E.head.appendChild(r[0])},abort:function(){i&&i()}}});var Ut,Xt=[],Vt=/(=)\?(?=&|$)|\?\?/;S.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var e=Xt.pop()||S.expando+"_"+Ct.guid++;return this[e]=!0,e}}),S.ajaxPrefilter("json jsonp",function(e,t,n){var r,i,o,a=!1!==e.jsonp&&(Vt.test(e.url)?"url":"string"==typeof e.data&&0===(e.contentType||"").indexOf("application/x-www-form-urlencoded")&&Vt.test(e.data)&&"data");if(a||"jsonp"===e.dataTypes[0])return r=e.jsonpCallback=m(e.jsonpCallback)?e.jsonpCallback():e.jsonpCallback,a?e[a]=e[a].replace(Vt,"$1"+r):!1!==e.jsonp&&(e.url+=(Et.test(e.url)?"&":"?")+e.jsonp+"="+r),e.converters["script json"]=function(){return o||S.error(r+" was not called"),o[0]},e.dataTypes[0]="json",i=C[r],C[r]=function(){o=arguments},n.always(function(){void 0===i?S(C).removeProp(r):C[r]=i,e[r]&&(e.jsonpCallback=t.jsonpCallback,Xt.push(r)),o&&m(i)&&i(o[0]),o=i=void 0}),"script"}),y.createHTMLDocument=((Ut=E.implementation.createHTMLDocument("").body).innerHTML="
",2===Ut.childNodes.length),S.parseHTML=function(e,t,n){return"string"!=typeof e?[]:("boolean"==typeof t&&(n=t,t=!1),t||(y.createHTMLDocument?((r=(t=E.implementation.createHTMLDocument("")).createElement("base")).href=E.location.href,t.head.appendChild(r)):t=E),o=!n&&[],(i=N.exec(e))?[t.createElement(i[1])]:(i=xe([e],t,o),o&&o.length&&S(o).remove(),S.merge([],i.childNodes)));var r,i,o},S.fn.load=function(e,t,n){var r,i,o,a=this,s=e.indexOf(" ");return-1").append(S.parseHTML(e)).find(r):e)}).always(n&&function(e,t){a.each(function(){n.apply(this,o||[e.responseText,t,e])})}),this},S.expr.pseudos.animated=function(t){return S.grep(S.timers,function(e){return t===e.elem}).length},S.offset={setOffset:function(e,t,n){var r,i,o,a,s,u,l=S.css(e,"position"),c=S(e),f={};"static"===l&&(e.style.position="relative"),s=c.offset(),o=S.css(e,"top"),u=S.css(e,"left"),("absolute"===l||"fixed"===l)&&-1<(o+u).indexOf("auto")?(a=(r=c.position()).top,i=r.left):(a=parseFloat(o)||0,i=parseFloat(u)||0),m(t)&&(t=t.call(e,n,S.extend({},s))),null!=t.top&&(f.top=t.top-s.top+a),null!=t.left&&(f.left=t.left-s.left+i),"using"in t?t.using.call(e,f):("number"==typeof f.top&&(f.top+="px"),"number"==typeof f.left&&(f.left+="px"),c.css(f))}},S.fn.extend({offset:function(t){if(arguments.length)return void 0===t?this:this.each(function(e){S.offset.setOffset(this,t,e)});var e,n,r=this[0];return r?r.getClientRects().length?(e=r.getBoundingClientRect(),n=r.ownerDocument.defaultView,{top:e.top+n.pageYOffset,left:e.left+n.pageXOffset}):{top:0,left:0}:void 0},position:function(){if(this[0]){var e,t,n,r=this[0],i={top:0,left:0};if("fixed"===S.css(r,"position"))t=r.getBoundingClientRect();else{t=this.offset(),n=r.ownerDocument,e=r.offsetParent||n.documentElement;while(e&&(e===n.body||e===n.documentElement)&&"static"===S.css(e,"position"))e=e.parentNode;e&&e!==r&&1===e.nodeType&&((i=S(e).offset()).top+=S.css(e,"borderTopWidth",!0),i.left+=S.css(e,"borderLeftWidth",!0))}return{top:t.top-i.top-S.css(r,"marginTop",!0),left:t.left-i.left-S.css(r,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var e=this.offsetParent;while(e&&"static"===S.css(e,"position"))e=e.offsetParent;return e||re})}}),S.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(t,i){var o="pageYOffset"===i;S.fn[t]=function(e){return $(this,function(e,t,n){var r;if(x(e)?r=e:9===e.nodeType&&(r=e.defaultView),void 0===n)return r?r[i]:e[t];r?r.scrollTo(o?r.pageXOffset:n,o?n:r.pageYOffset):e[t]=n},t,e,arguments.length)}}),S.each(["top","left"],function(e,n){S.cssHooks[n]=$e(y.pixelPosition,function(e,t){if(t)return t=Be(e,n),Me.test(t)?S(e).position()[n]+"px":t})}),S.each({Height:"height",Width:"width"},function(a,s){S.each({padding:"inner"+a,content:s,"":"outer"+a},function(r,o){S.fn[o]=function(e,t){var n=arguments.length&&(r||"boolean"!=typeof e),i=r||(!0===e||!0===t?"margin":"border");return $(this,function(e,t,n){var r;return x(e)?0===o.indexOf("outer")?e["inner"+a]:e.document.documentElement["client"+a]:9===e.nodeType?(r=e.documentElement,Math.max(e.body["scroll"+a],r["scroll"+a],e.body["offset"+a],r["offset"+a],r["client"+a])):void 0===n?S.css(e,t,i):S.style(e,t,n,i)},s,n?e:void 0,n)}})}),S.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(e,t){S.fn[t]=function(e){return this.on(t,e)}}),S.fn.extend({bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return 1===arguments.length?this.off(e,"**"):this.off(t,e||"**",n)},hover:function(e,t){return this.mouseenter(e).mouseleave(t||e)}}),S.each("blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu".split(" "),function(e,n){S.fn[n]=function(e,t){return 0"']/g,J=RegExp(G.source),Y=RegExp(H.source),Q=/<%-([\s\S]+?)%>/g,X=/<%([\s\S]+?)%>/g,nn=/<%=([\s\S]+?)%>/g,tn=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,rn=/^\w*$/,en=/^\./,un=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,on=/[\\^$.*+?()[\]{}|]/g,fn=RegExp(on.source),cn=/^\s+|\s+$/g,an=/^\s+/,ln=/\s+$/,sn=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,hn=/\{\n\/\* \[wrapped with (.+)\] \*/,pn=/,? & /,_n=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,vn=/\\(\\)?/g,gn=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,dn=/\w*$/,yn=/^[-+]0x[0-9a-f]+$/i,bn=/^0b[01]+$/i,xn=/^\[object .+?Constructor\]$/,jn=/^0o[0-7]+$/i,wn=/^(?:0|[1-9]\d*)$/,mn=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,An=/($^)/,kn=/['\n\r\u2028\u2029\\]/g,En="[\\ufe0e\\ufe0f]?(?:[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]|\\ud83c[\\udffb-\\udfff])?(?:\\u200d(?:[^\\ud800-\\udfff]|(?:\\ud83c[\\udde6-\\uddff]){2}|[\\ud800-\\udbff][\\udc00-\\udfff])[\\ufe0e\\ufe0f]?(?:[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]|\\ud83c[\\udffb-\\udfff])?)*",On="(?:[\\u2700-\\u27bf]|(?:\\ud83c[\\udde6-\\uddff]){2}|[\\ud800-\\udbff][\\udc00-\\udfff])"+En,Sn="(?:[^\\ud800-\\udfff][\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]?|[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]|(?:\\ud83c[\\udde6-\\uddff]){2}|[\\ud800-\\udbff][\\udc00-\\udfff]|[\\ud800-\\udfff])",In=RegExp("['\u2019]","g"),Rn=RegExp("[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]","g"),zn=RegExp("\\ud83c[\\udffb-\\udfff](?=\\ud83c[\\udffb-\\udfff])|"+Sn+En,"g"),Wn=RegExp(["[A-Z\\xc0-\\xd6\\xd8-\\xde]?[a-z\\xdf-\\xf6\\xf8-\\xff]+(?:['\u2019](?:d|ll|m|re|s|t|ve))?(?=[\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000]|[A-Z\\xc0-\\xd6\\xd8-\\xde]|$)|(?:[A-Z\\xc0-\\xd6\\xd8-\\xde]|[^\\ud800-\\udfff\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000\\d+\\u2700-\\u27bfa-z\\xdf-\\xf6\\xf8-\\xffA-Z\\xc0-\\xd6\\xd8-\\xde])+(?:['\u2019](?:D|LL|M|RE|S|T|VE))?(?=[\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000]|[A-Z\\xc0-\\xd6\\xd8-\\xde](?:[a-z\\xdf-\\xf6\\xf8-\\xff]|[^\\ud800-\\udfff\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000\\d+\\u2700-\\u27bfa-z\\xdf-\\xf6\\xf8-\\xffA-Z\\xc0-\\xd6\\xd8-\\xde])|$)|[A-Z\\xc0-\\xd6\\xd8-\\xde]?(?:[a-z\\xdf-\\xf6\\xf8-\\xff]|[^\\ud800-\\udfff\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000\\d+\\u2700-\\u27bfa-z\\xdf-\\xf6\\xf8-\\xffA-Z\\xc0-\\xd6\\xd8-\\xde])+(?:['\u2019](?:d|ll|m|re|s|t|ve))?|[A-Z\\xc0-\\xd6\\xd8-\\xde]+(?:['\u2019](?:D|LL|M|RE|S|T|VE))?|\\d*(?:(?:1ST|2ND|3RD|(?![123])\\dTH)\\b)|\\d*(?:(?:1st|2nd|3rd|(?![123])\\dth)\\b)|\\d+",On].join("|"),"g"),Bn=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]"),Ln=/[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,Un="Array Buffer DataView Date Error Float32Array Float64Array Function Int8Array Int16Array Int32Array Map Math Object Promise RegExp Set String Symbol TypeError Uint8Array Uint8ClampedArray Uint16Array Uint32Array WeakMap _ clearTimeout isFinite parseInt setTimeout".split(" "),Cn={}; -Cn["[object Float32Array]"]=Cn["[object Float64Array]"]=Cn["[object Int8Array]"]=Cn["[object Int16Array]"]=Cn["[object Int32Array]"]=Cn["[object Uint8Array]"]=Cn["[object Uint8ClampedArray]"]=Cn["[object Uint16Array]"]=Cn["[object Uint32Array]"]=true,Cn["[object Arguments]"]=Cn["[object Array]"]=Cn["[object ArrayBuffer]"]=Cn["[object Boolean]"]=Cn["[object DataView]"]=Cn["[object Date]"]=Cn["[object Error]"]=Cn["[object Function]"]=Cn["[object Map]"]=Cn["[object Number]"]=Cn["[object Object]"]=Cn["[object RegExp]"]=Cn["[object Set]"]=Cn["[object String]"]=Cn["[object WeakMap]"]=false; -var Dn={};Dn["[object Arguments]"]=Dn["[object Array]"]=Dn["[object ArrayBuffer]"]=Dn["[object DataView]"]=Dn["[object Boolean]"]=Dn["[object Date]"]=Dn["[object Float32Array]"]=Dn["[object Float64Array]"]=Dn["[object Int8Array]"]=Dn["[object Int16Array]"]=Dn["[object Int32Array]"]=Dn["[object Map]"]=Dn["[object Number]"]=Dn["[object Object]"]=Dn["[object RegExp]"]=Dn["[object Set]"]=Dn["[object String]"]=Dn["[object Symbol]"]=Dn["[object Uint8Array]"]=Dn["[object Uint8ClampedArray]"]=Dn["[object Uint16Array]"]=Dn["[object Uint32Array]"]=true, -Dn["[object Error]"]=Dn["[object Function]"]=Dn["[object WeakMap]"]=false;var Mn,Tn={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},$n=parseFloat,Fn=parseInt,Nn=typeof global=="object"&&global&&global.Object===Object&&global,Pn=typeof self=="object"&&self&&self.Object===Object&&self,Zn=Nn||Pn||Function("return this")(),qn=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Vn=qn&&typeof module=="object"&&module&&!module.nodeType&&module,Kn=Vn&&Vn.exports===qn,Gn=Kn&&Nn.process; -n:{try{Mn=Gn&&Gn.binding&&Gn.binding("util");break n}catch(n){}Mn=void 0}var Hn=Mn&&Mn.isArrayBuffer,Jn=Mn&&Mn.isDate,Yn=Mn&&Mn.isMap,Qn=Mn&&Mn.isRegExp,Xn=Mn&&Mn.isSet,nt=Mn&&Mn.isTypedArray,tt=j("length"),rt=w({"\xc0":"A","\xc1":"A","\xc2":"A","\xc3":"A","\xc4":"A","\xc5":"A","\xe0":"a","\xe1":"a","\xe2":"a","\xe3":"a","\xe4":"a","\xe5":"a","\xc7":"C","\xe7":"c","\xd0":"D","\xf0":"d","\xc8":"E","\xc9":"E","\xca":"E","\xcb":"E","\xe8":"e","\xe9":"e","\xea":"e","\xeb":"e","\xcc":"I","\xcd":"I","\xce":"I", -"\xcf":"I","\xec":"i","\xed":"i","\xee":"i","\xef":"i","\xd1":"N","\xf1":"n","\xd2":"O","\xd3":"O","\xd4":"O","\xd5":"O","\xd6":"O","\xd8":"O","\xf2":"o","\xf3":"o","\xf4":"o","\xf5":"o","\xf6":"o","\xf8":"o","\xd9":"U","\xda":"U","\xdb":"U","\xdc":"U","\xf9":"u","\xfa":"u","\xfb":"u","\xfc":"u","\xdd":"Y","\xfd":"y","\xff":"y","\xc6":"Ae","\xe6":"ae","\xde":"Th","\xfe":"th","\xdf":"ss","\u0100":"A","\u0102":"A","\u0104":"A","\u0101":"a","\u0103":"a","\u0105":"a","\u0106":"C","\u0108":"C","\u010a":"C", -"\u010c":"C","\u0107":"c","\u0109":"c","\u010b":"c","\u010d":"c","\u010e":"D","\u0110":"D","\u010f":"d","\u0111":"d","\u0112":"E","\u0114":"E","\u0116":"E","\u0118":"E","\u011a":"E","\u0113":"e","\u0115":"e","\u0117":"e","\u0119":"e","\u011b":"e","\u011c":"G","\u011e":"G","\u0120":"G","\u0122":"G","\u011d":"g","\u011f":"g","\u0121":"g","\u0123":"g","\u0124":"H","\u0126":"H","\u0125":"h","\u0127":"h","\u0128":"I","\u012a":"I","\u012c":"I","\u012e":"I","\u0130":"I","\u0129":"i","\u012b":"i","\u012d":"i", -"\u012f":"i","\u0131":"i","\u0134":"J","\u0135":"j","\u0136":"K","\u0137":"k","\u0138":"k","\u0139":"L","\u013b":"L","\u013d":"L","\u013f":"L","\u0141":"L","\u013a":"l","\u013c":"l","\u013e":"l","\u0140":"l","\u0142":"l","\u0143":"N","\u0145":"N","\u0147":"N","\u014a":"N","\u0144":"n","\u0146":"n","\u0148":"n","\u014b":"n","\u014c":"O","\u014e":"O","\u0150":"O","\u014d":"o","\u014f":"o","\u0151":"o","\u0154":"R","\u0156":"R","\u0158":"R","\u0155":"r","\u0157":"r","\u0159":"r","\u015a":"S","\u015c":"S", -"\u015e":"S","\u0160":"S","\u015b":"s","\u015d":"s","\u015f":"s","\u0161":"s","\u0162":"T","\u0164":"T","\u0166":"T","\u0163":"t","\u0165":"t","\u0167":"t","\u0168":"U","\u016a":"U","\u016c":"U","\u016e":"U","\u0170":"U","\u0172":"U","\u0169":"u","\u016b":"u","\u016d":"u","\u016f":"u","\u0171":"u","\u0173":"u","\u0174":"W","\u0175":"w","\u0176":"Y","\u0177":"y","\u0178":"Y","\u0179":"Z","\u017b":"Z","\u017d":"Z","\u017a":"z","\u017c":"z","\u017e":"z","\u0132":"IJ","\u0133":"ij","\u0152":"Oe","\u0153":"oe", -"\u0149":"'n","\u017f":"s"}),et=w({"&":"&","<":"<",">":">",'"':""","'":"'"}),ut=w({"&":"&","<":"<",">":">",""":'"',"'":"'"}),it=function w(En){function On(n){if(xu(n)&&!af(n)&&!(n instanceof Mn)){if(n instanceof zn)return n;if(ci.call(n,"__wrapped__"))return Pe(n)}return new zn(n)}function Sn(){}function zn(n,t){this.__wrapped__=n,this.__actions__=[],this.__chain__=!!t,this.__index__=0,this.__values__=F}function Mn(n){this.__wrapped__=n,this.__actions__=[],this.__dir__=1, -this.__filtered__=false,this.__iteratees__=[],this.__takeCount__=4294967295,this.__views__=[]}function Tn(n){var t=-1,r=null==n?0:n.length;for(this.clear();++t=t?n:t)),n}function dt(n,t,r,e,i,o){var f,c=1&t,a=2&t,l=4&t;if(r&&(f=i?r(n,e,i,o):r(n)),f!==F)return f;if(!bu(n))return n;if(e=af(n)){if(f=Ee(n),!c)return Mr(n,f)}else{var s=yo(n),h="[object Function]"==s||"[object GeneratorFunction]"==s;if(sf(n))return Wr(n,c);if("[object Object]"==s||"[object Arguments]"==s||h&&!i){if(f=a||h?{}:Oe(n),!c)return a?Fr(n,pt(f,n)):$r(n,ht(f,n))}else{if(!Dn[s])return i?n:{};f=Se(n,s,dt,c)}}if(o||(o=new Vn), -i=o.get(n))return i;o.set(n,f);var a=l?a?ye:de:a?Uu:Lu,p=e?F:a(n);return u(p||n,function(e,u){p&&(u=e,e=n[u]),at(f,u,dt(e,t,r,u,n,o))}),f}function yt(n){var t=Lu(n);return function(r){return bt(r,n,t)}}function bt(n,t,r){var e=r.length;if(null==n)return!e;for(n=ni(n);e--;){var u=r[e],i=t[u],o=n[u];if(o===F&&!(u in n)||!i(o))return false}return true}function xt(n,t,r){if(typeof n!="function")throw new ei("Expected a function");return jo(function(){n.apply(F,r)},t)}function jt(n,t,r,e){var u=-1,i=c,o=true,f=n.length,s=[],h=t.length; -if(!f)return s;r&&(t=l(t,S(r))),e?(i=a,o=false):200<=t.length&&(i=R,o=false,t=new qn(t));n:for(;++ut}function Bt(n,t){return null!=n&&ci.call(n,t)}function Lt(n,t){return null!=n&&t in ni(n)}function Ut(n,t,r){for(var e=r?a:c,u=n[0].length,i=n.length,o=i,f=Hu(i),s=1/0,h=[];o--;){var p=n[o];o&&t&&(p=l(p,S(t))),s=Mi(p.length,s),f[o]=!r&&(t||120<=u&&120<=p.length)?new qn(o&&p):F}var p=n[0],_=-1,v=f[0];n:for(;++_t.length?n:It(n,vr(t,0,-1)),t=null==n?n:n[$e(Ge(t))],null==t?F:r(t,n,e)}function Mt(n){return xu(n)&&"[object Arguments]"==zt(n)}function Tt(n){return xu(n)&&"[object ArrayBuffer]"==zt(n)}function $t(n){return xu(n)&&"[object Date]"==zt(n)}function Ft(n,t,r,e,u){if(n===t)t=true;else if(null==n||null==t||!xu(n)&&!xu(t))t=n!==n&&t!==t;else n:{ -var i=af(n),o=af(t),f=i?"[object Array]":yo(n),c=o?"[object Array]":yo(t),f="[object Arguments]"==f?"[object Object]":f,c="[object Arguments]"==c?"[object Object]":c,a="[object Object]"==f,o="[object Object]"==c;if((c=f==c)&&sf(n)){if(!sf(t)){t=false;break n}i=true,a=false}if(c&&!a)u||(u=new Vn),t=i||gf(n)?_e(n,t,r,e,Ft,u):ve(n,t,f,r,e,Ft,u);else{if(!(1&r)&&(i=a&&ci.call(n,"__wrapped__"),f=o&&ci.call(t,"__wrapped__"),i||f)){n=i?n.value():n,t=f?t.value():t,u||(u=new Vn),t=Ft(n,t,r,e,u);break n}if(c)t:if(u||(u=new Vn), -i=1&r,f=de(n),o=f.length,c=de(t).length,o==c||i){for(a=o;a--;){var l=f[a];if(!(i?l in t:ci.call(t,l))){t=false;break t}}if((c=u.get(n))&&u.get(t))t=c==t;else{c=true,u.set(n,t),u.set(t,n);for(var s=i;++at?r:0,Re(t,r)?n[t]:F}function rr(n,t,r){var e=-1;return t=l(t.length?t:[Nu],S(je())),n=Yt(n,function(n){return{a:l(t,function(t){return t(n)}),b:++e,c:n}}),A(n,function(n,t){var e;n:{e=-1;for(var u=n.a,i=t.a,o=u.length,f=r.length;++e=f?c:c*("desc"==r[e]?-1:1); -break n}}e=n.b-t.b}return e})}function er(n,t){return ur(n,t,function(t,r){return Bu(n,r)})}function ur(n,t,r){for(var e=-1,u=t.length,i={};++et||9007199254740991t&&(t=-t>u?0:u+t),r=r>u?u:r,0>r&&(r+=u),u=t>r?0:r-t>>>0,t>>>=0,r=Hu(u);++e=u){for(;e>>1,o=n[i];null!==o&&!Au(o)&&(r?o<=t:ot.length?n:It(n,vr(t,0,-1)), -null==n||delete n[$e(Ge(t))]}function Ar(n,t,r,e){for(var u=n.length,i=e?u:-1;(e?i--:++ie)return e?wr(n[0]):[];for(var u=-1,i=Hu(e);++u=e?n:vr(n,t,r)}function Wr(n,t){if(t)return n.slice();var r=n.length,r=yi?yi(r):new n.constructor(r);return n.copy(r),r}function Br(n){var t=new n.constructor(n.byteLength);return new di(t).set(new di(n)),t}function Lr(n,t){return new n.constructor(t?Br(n.buffer):n.buffer,n.byteOffset,n.length)}function Ur(n,t){ -if(n!==t){var r=n!==F,e=null===n,u=n===n,i=Au(n),o=t!==F,f=null===t,c=t===t,a=Au(t);if(!f&&!a&&!i&&n>t||i&&o&&c&&!f&&!a||e&&o&&c||!r&&c||!u)return 1;if(!e&&!i&&!a&&nu?F:i,u=1),t=ni(t);++eo&&f[0]!==a&&f[o-1]!==a?[]:C(f,a),o-=c.length,or?r?ar(t,n):t:(r=ar(t,Ri(n/T(t))),Bn.test(t)?zr($(r),0,n).join(""):r.slice(0,n))}function ue(n,t,e,u){function i(){for(var t=-1,c=arguments.length,a=-1,l=u.length,s=Hu(l+c),h=this&&this!==Zn&&this instanceof i?f:n;++at||e)&&(1&n&&(i[2]=h[2],t|=1&r?0:4),(r=h[3])&&(e=i[3],i[3]=e?Cr(e,r,h[4]):r,i[4]=e?C(i[3],"__lodash_placeholder__"):h[4]),(r=h[5])&&(e=i[5],i[5]=e?Dr(e,r,h[6]):r,i[6]=e?C(i[5],"__lodash_placeholder__"):h[6]),(r=h[7])&&(i[7]=r),128&n&&(i[8]=null==i[8]?h[8]:Mi(i[8],h[8])),null==i[9]&&(i[9]=h[9]),i[0]=h[0],i[1]=t),n=i[0],t=i[1], -r=i[2],e=i[3],u=i[4],f=i[9]=i[9]===F?c?0:n.length:Di(i[9]-a,0),!f&&24&t&&(t&=-25),De((h?lo:xo)(t&&1!=t?8==t||16==t?Jr(n,t,f):32!=t&&33!=t||u.length?Xr.apply(F,i):ue(n,t,r,e):Vr(n,t,r),i),n,t)}function se(n,t,r,e){return n===F||hu(n,ii[r])&&!ci.call(e,r)?t:n}function he(n,t,r,e,u,i){return bu(n)&&bu(t)&&(i.set(t,n),nr(n,t,F,he,i),i.delete(t)),n}function pe(n){return wu(n)?F:n}function _e(n,t,r,e,u,i){var o=1&r,f=n.length,c=t.length;if(f!=c&&!(o&&c>f))return false;if((c=i.get(n))&&i.get(t))return c==t;var c=-1,a=true,l=2&r?new qn:F; -for(i.set(n,t),i.set(t,n);++cr&&(r=Di(e+r,0)),g(n,je(t,3),r)):-1}function qe(n,t,r){var e=null==n?0:n.length;if(!e)return-1;var u=e-1;return r!==F&&(u=Ou(r),u=0>r?Di(e+u,0):Mi(u,e-1)), -g(n,je(t,3),u,true)}function Ve(n){return(null==n?0:n.length)?kt(n,1):[]}function Ke(n){return n&&n.length?n[0]:F}function Ge(n){var t=null==n?0:n.length;return t?n[t-1]:F}function He(n,t){return n&&n.length&&t&&t.length?or(n,t):n}function Je(n){return null==n?n:Ni.call(n)}function Ye(n){if(!n||!n.length)return[];var t=0;return n=f(n,function(n){if(_u(n))return t=Di(n.length,t),true}),E(t,function(t){return l(n,j(t))})}function Qe(n,t){if(!n||!n.length)return[];var e=Ye(n);return null==t?e:l(e,function(n){ -return r(t,F,n)})}function Xe(n){return n=On(n),n.__chain__=true,n}function nu(n,t){return t(n)}function tu(){return this}function ru(n,t){return(af(n)?u:oo)(n,je(t,3))}function eu(n,t){return(af(n)?i:fo)(n,je(t,3))}function uu(n,t){return(af(n)?l:Yt)(n,je(t,3))}function iu(n,t,r){return t=r?F:t,t=n&&null==t?n.length:t,le(n,128,F,F,F,F,t)}function ou(n,t){var r;if(typeof t!="function")throw new ei("Expected a function");return n=Ou(n),function(){return 0<--n&&(r=t.apply(this,arguments)),1>=n&&(t=F), -r}}function fu(n,t,r){return t=r?F:t,n=le(n,8,F,F,F,F,F,t),n.placeholder=fu.placeholder,n}function cu(n,t,r){return t=r?F:t,n=le(n,16,F,F,F,F,F,t),n.placeholder=cu.placeholder,n}function au(n,t,r){function e(t){var r=c,e=a;return c=a=F,_=t,s=n.apply(e,r)}function u(n){var r=n-p;return n-=_,p===F||r>=t||0>r||g&&n>=l}function i(){var n=Jo();if(u(n))return o(n);var r,e=jo;r=n-_,n=t-(n-p),r=g?Mi(n,l-r):n,h=e(i,r)}function o(n){return h=F,d&&c?e(n):(c=a=F,s)}function f(){var n=Jo(),r=u(n);if(c=arguments, -a=this,p=n,r){if(h===F)return _=n=p,h=jo(i,t),v?e(n):s;if(g)return h=jo(i,t),e(p)}return h===F&&(h=jo(i,t)),s}var c,a,l,s,h,p,_=0,v=false,g=false,d=true;if(typeof n!="function")throw new ei("Expected a function");return t=Iu(t)||0,bu(r)&&(v=!!r.leading,l=(g="maxWait"in r)?Di(Iu(r.maxWait)||0,t):l,d="trailing"in r?!!r.trailing:d),f.cancel=function(){h!==F&&ho(h),_=0,c=p=a=h=F},f.flush=function(){return h===F?s:o(Jo())},f}function lu(n,t){function r(){var e=arguments,u=t?t.apply(this,e):e[0],i=r.cache;return i.has(u)?i.get(u):(e=n.apply(this,e), -r.cache=i.set(u,e)||i,e)}if(typeof n!="function"||null!=t&&typeof t!="function")throw new ei("Expected a function");return r.cache=new(lu.Cache||Pn),r}function su(n){if(typeof n!="function")throw new ei("Expected a function");return function(){var t=arguments;switch(t.length){case 0:return!n.call(this);case 1:return!n.call(this,t[0]);case 2:return!n.call(this,t[0],t[1]);case 3:return!n.call(this,t[0],t[1],t[2])}return!n.apply(this,t)}}function hu(n,t){return n===t||n!==n&&t!==t}function pu(n){return null!=n&&yu(n.length)&&!gu(n); -}function _u(n){return xu(n)&&pu(n)}function vu(n){if(!xu(n))return false;var t=zt(n);return"[object Error]"==t||"[object DOMException]"==t||typeof n.message=="string"&&typeof n.name=="string"&&!wu(n)}function gu(n){return!!bu(n)&&(n=zt(n),"[object Function]"==n||"[object GeneratorFunction]"==n||"[object AsyncFunction]"==n||"[object Proxy]"==n)}function du(n){return typeof n=="number"&&n==Ou(n)}function yu(n){return typeof n=="number"&&-1=n}function bu(n){var t=typeof n;return null!=n&&("object"==t||"function"==t); -}function xu(n){return null!=n&&typeof n=="object"}function ju(n){return typeof n=="number"||xu(n)&&"[object Number]"==zt(n)}function wu(n){return!(!xu(n)||"[object Object]"!=zt(n))&&(n=bi(n),null===n||(n=ci.call(n,"constructor")&&n.constructor,typeof n=="function"&&n instanceof n&&fi.call(n)==hi))}function mu(n){return typeof n=="string"||!af(n)&&xu(n)&&"[object String]"==zt(n)}function Au(n){return typeof n=="symbol"||xu(n)&&"[object Symbol]"==zt(n)}function ku(n){if(!n)return[];if(pu(n))return mu(n)?$(n):Mr(n); -if(Ai&&n[Ai]){n=n[Ai]();for(var t,r=[];!(t=n.next()).done;)r.push(t.value);return r}return t=yo(n),("[object Map]"==t?L:"[object Set]"==t?D:Du)(n)}function Eu(n){return n?(n=Iu(n),n===N||n===-N?1.7976931348623157e308*(0>n?-1:1):n===n?n:0):0===n?n:0}function Ou(n){n=Eu(n);var t=n%1;return n===n?t?n-t:n:0}function Su(n){return n?gt(Ou(n),0,4294967295):0}function Iu(n){if(typeof n=="number")return n;if(Au(n))return P;if(bu(n)&&(n=typeof n.valueOf=="function"?n.valueOf():n,n=bu(n)?n+"":n),typeof n!="string")return 0===n?n:+n; -n=n.replace(cn,"");var t=bn.test(n);return t||jn.test(n)?Fn(n.slice(2),t?2:8):yn.test(n)?P:+n}function Ru(n){return Tr(n,Uu(n))}function zu(n){return null==n?"":jr(n)}function Wu(n,t,r){return n=null==n?F:It(n,t),n===F?r:n}function Bu(n,t){return null!=n&&ke(n,t,Lt)}function Lu(n){return pu(n)?Gn(n):Ht(n)}function Uu(n){if(pu(n))n=Gn(n,true);else if(bu(n)){var t,r=Le(n),e=[];for(t in n)("constructor"!=t||!r&&ci.call(n,t))&&e.push(t);n=e}else{if(t=[],null!=n)for(r in ni(n))t.push(r);n=t}return n}function Cu(n,t){ -if(null==n)return{};var r=l(ye(n),function(n){return[n]});return t=je(t),ur(n,r,function(n,r){return t(n,r[0])})}function Du(n){return null==n?[]:I(n,Lu(n))}function Mu(n){return Nf(zu(n).toLowerCase())}function Tu(n){return(n=zu(n))&&n.replace(mn,rt).replace(Rn,"")}function $u(n,t,r){return n=zu(n),t=r?F:t,t===F?Ln.test(n)?n.match(Wn)||[]:n.match(_n)||[]:n.match(t)||[]}function Fu(n){return function(){return n}}function Nu(n){return n}function Pu(n){return Gt(typeof n=="function"?n:dt(n,1))}function Zu(n,t,r){ -var e=Lu(t),i=St(t,e);null!=r||bu(t)&&(i.length||!e.length)||(r=t,t=n,n=this,i=St(t,Lu(t)));var o=!(bu(r)&&"chain"in r&&!r.chain),f=gu(n);return u(i,function(r){var e=t[r];n[r]=e,f&&(n.prototype[r]=function(){var t=this.__chain__;if(o||t){var r=n(this.__wrapped__);return(r.__actions__=Mr(this.__actions__)).push({func:e,args:arguments,thisArg:n}),r.__chain__=t,r}return e.apply(n,s([this.value()],arguments))})}),n}function qu(){}function Vu(n){return We(n)?j($e(n)):ir(n)}function Ku(){return[]}function Gu(){ -return false}En=null==En?Zn:it.defaults(Zn.Object(),En,it.pick(Zn,Un));var Hu=En.Array,Ju=En.Date,Yu=En.Error,Qu=En.Function,Xu=En.Math,ni=En.Object,ti=En.RegExp,ri=En.String,ei=En.TypeError,ui=Hu.prototype,ii=ni.prototype,oi=En["__core-js_shared__"],fi=Qu.prototype.toString,ci=ii.hasOwnProperty,ai=0,li=function(){var n=/[^.]+$/.exec(oi&&oi.keys&&oi.keys.IE_PROTO||"");return n?"Symbol(src)_1."+n:""}(),si=ii.toString,hi=fi.call(ni),pi=Zn._,_i=ti("^"+fi.call(ci).replace(on,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),vi=Kn?En.Buffer:F,gi=En.Symbol,di=En.Uint8Array,yi=vi?vi.f:F,bi=U(ni.getPrototypeOf,ni),xi=ni.create,ji=ii.propertyIsEnumerable,wi=ui.splice,mi=gi?gi.isConcatSpreadable:F,Ai=gi?gi.iterator:F,ki=gi?gi.toStringTag:F,Ei=function(){ -try{var n=Ae(ni,"defineProperty");return n({},"",{}),n}catch(n){}}(),Oi=En.clearTimeout!==Zn.clearTimeout&&En.clearTimeout,Si=Ju&&Ju.now!==Zn.Date.now&&Ju.now,Ii=En.setTimeout!==Zn.setTimeout&&En.setTimeout,Ri=Xu.ceil,zi=Xu.floor,Wi=ni.getOwnPropertySymbols,Bi=vi?vi.isBuffer:F,Li=En.isFinite,Ui=ui.join,Ci=U(ni.keys,ni),Di=Xu.max,Mi=Xu.min,Ti=Ju.now,$i=En.parseInt,Fi=Xu.random,Ni=ui.reverse,Pi=Ae(En,"DataView"),Zi=Ae(En,"Map"),qi=Ae(En,"Promise"),Vi=Ae(En,"Set"),Ki=Ae(En,"WeakMap"),Gi=Ae(ni,"create"),Hi=Ki&&new Ki,Ji={},Yi=Fe(Pi),Qi=Fe(Zi),Xi=Fe(qi),no=Fe(Vi),to=Fe(Ki),ro=gi?gi.prototype:F,eo=ro?ro.valueOf:F,uo=ro?ro.toString:F,io=function(){ -function n(){}return function(t){return bu(t)?xi?xi(t):(n.prototype=t,t=new n,n.prototype=F,t):{}}}();On.templateSettings={escape:Q,evaluate:X,interpolate:nn,variable:"",imports:{_:On}},On.prototype=Sn.prototype,On.prototype.constructor=On,zn.prototype=io(Sn.prototype),zn.prototype.constructor=zn,Mn.prototype=io(Sn.prototype),Mn.prototype.constructor=Mn,Tn.prototype.clear=function(){this.__data__=Gi?Gi(null):{},this.size=0},Tn.prototype.delete=function(n){return n=this.has(n)&&delete this.__data__[n], -this.size-=n?1:0,n},Tn.prototype.get=function(n){var t=this.__data__;return Gi?(n=t[n],"__lodash_hash_undefined__"===n?F:n):ci.call(t,n)?t[n]:F},Tn.prototype.has=function(n){var t=this.__data__;return Gi?t[n]!==F:ci.call(t,n)},Tn.prototype.set=function(n,t){var r=this.__data__;return this.size+=this.has(n)?0:1,r[n]=Gi&&t===F?"__lodash_hash_undefined__":t,this},Nn.prototype.clear=function(){this.__data__=[],this.size=0},Nn.prototype.delete=function(n){var t=this.__data__;return n=lt(t,n),!(0>n)&&(n==t.length-1?t.pop():wi.call(t,n,1), ---this.size,true)},Nn.prototype.get=function(n){var t=this.__data__;return n=lt(t,n),0>n?F:t[n][1]},Nn.prototype.has=function(n){return-1e?(++this.size,r.push([n,t])):r[e][1]=t,this},Pn.prototype.clear=function(){this.size=0,this.__data__={hash:new Tn,map:new(Zi||Nn),string:new Tn}},Pn.prototype.delete=function(n){return n=we(this,n).delete(n),this.size-=n?1:0,n},Pn.prototype.get=function(n){return we(this,n).get(n); -},Pn.prototype.has=function(n){return we(this,n).has(n)},Pn.prototype.set=function(n,t){var r=we(this,n),e=r.size;return r.set(n,t),this.size+=r.size==e?0:1,this},qn.prototype.add=qn.prototype.push=function(n){return this.__data__.set(n,"__lodash_hash_undefined__"),this},qn.prototype.has=function(n){return this.__data__.has(n)},Vn.prototype.clear=function(){this.__data__=new Nn,this.size=0},Vn.prototype.delete=function(n){var t=this.__data__;return n=t.delete(n),this.size=t.size,n},Vn.prototype.get=function(n){ -return this.__data__.get(n)},Vn.prototype.has=function(n){return this.__data__.has(n)},Vn.prototype.set=function(n,t){var r=this.__data__;if(r instanceof Nn){var e=r.__data__;if(!Zi||199>e.length)return e.push([n,t]),this.size=++r.size,this;r=this.__data__=new Pn(e)}return r.set(n,t),this.size=r.size,this};var oo=Zr(Et),fo=Zr(Ot,true),co=qr(),ao=qr(true),lo=Hi?function(n,t){return Hi.set(n,t),n}:Nu,so=Ei?function(n,t){return Ei(n,"toString",{configurable:true,enumerable:false,value:Fu(t),writable:true})}:Nu,ho=Oi||function(n){ -return Zn.clearTimeout(n)},po=Vi&&1/D(new Vi([,-0]))[1]==N?function(n){return new Vi(n)}:qu,_o=Hi?function(n){return Hi.get(n)}:qu,vo=Wi?function(n){return null==n?[]:(n=ni(n),f(Wi(n),function(t){return ji.call(n,t)}))}:Ku,go=Wi?function(n){for(var t=[];n;)s(t,vo(n)),n=bi(n);return t}:Ku,yo=zt;(Pi&&"[object DataView]"!=yo(new Pi(new ArrayBuffer(1)))||Zi&&"[object Map]"!=yo(new Zi)||qi&&"[object Promise]"!=yo(qi.resolve())||Vi&&"[object Set]"!=yo(new Vi)||Ki&&"[object WeakMap]"!=yo(new Ki))&&(yo=function(n){ -var t=zt(n);if(n=(n="[object Object]"==t?n.constructor:F)?Fe(n):"")switch(n){case Yi:return"[object DataView]";case Qi:return"[object Map]";case Xi:return"[object Promise]";case no:return"[object Set]";case to:return"[object WeakMap]"}return t});var bo=oi?gu:Gu,xo=Me(lo),jo=Ii||function(n,t){return Zn.setTimeout(n,t)},wo=Me(so),mo=function(n){n=lu(n,function(n){return 500===t.size&&t.clear(),n});var t=n.cache;return n}(function(n){var t=[];return en.test(n)&&t.push(""),n.replace(un,function(n,r,e,u){ -t.push(e?u.replace(vn,"$1"):r||n)}),t}),Ao=lr(function(n,t){return _u(n)?jt(n,kt(t,1,_u,true)):[]}),ko=lr(function(n,t){var r=Ge(t);return _u(r)&&(r=F),_u(n)?jt(n,kt(t,1,_u,true),je(r,2)):[]}),Eo=lr(function(n,t){var r=Ge(t);return _u(r)&&(r=F),_u(n)?jt(n,kt(t,1,_u,true),F,r):[]}),Oo=lr(function(n){var t=l(n,Sr);return t.length&&t[0]===n[0]?Ut(t):[]}),So=lr(function(n){var t=Ge(n),r=l(n,Sr);return t===Ge(r)?t=F:r.pop(),r.length&&r[0]===n[0]?Ut(r,je(t,2)):[]}),Io=lr(function(n){var t=Ge(n),r=l(n,Sr);return(t=typeof t=="function"?t:F)&&r.pop(), -r.length&&r[0]===n[0]?Ut(r,F,t):[]}),Ro=lr(He),zo=ge(function(n,t){var r=null==n?0:n.length,e=vt(n,t);return fr(n,l(t,function(n){return Re(n,r)?+n:n}).sort(Ur)),e}),Wo=lr(function(n){return wr(kt(n,1,_u,true))}),Bo=lr(function(n){var t=Ge(n);return _u(t)&&(t=F),wr(kt(n,1,_u,true),je(t,2))}),Lo=lr(function(n){var t=Ge(n),t=typeof t=="function"?t:F;return wr(kt(n,1,_u,true),F,t)}),Uo=lr(function(n,t){return _u(n)?jt(n,t):[]}),Co=lr(function(n){return Er(f(n,_u))}),Do=lr(function(n){var t=Ge(n);return _u(t)&&(t=F), -Er(f(n,_u),je(t,2))}),Mo=lr(function(n){var t=Ge(n),t=typeof t=="function"?t:F;return Er(f(n,_u),F,t)}),To=lr(Ye),$o=lr(function(n){var t=n.length,t=1=t}),cf=Mt(function(){return arguments}())?Mt:function(n){return xu(n)&&ci.call(n,"callee")&&!ji.call(n,"callee")},af=Hu.isArray,lf=Hn?S(Hn):Tt,sf=Bi||Gu,hf=Jn?S(Jn):$t,pf=Yn?S(Yn):Nt,_f=Qn?S(Qn):qt,vf=Xn?S(Xn):Vt,gf=nt?S(nt):Kt,df=oe(Jt),yf=oe(function(n,t){return n<=t}),bf=Pr(function(n,t){ -if(Le(t)||pu(t))Tr(t,Lu(t),n);else for(var r in t)ci.call(t,r)&&at(n,r,t[r])}),xf=Pr(function(n,t){Tr(t,Uu(t),n)}),jf=Pr(function(n,t,r,e){Tr(t,Uu(t),n,e)}),wf=Pr(function(n,t,r,e){Tr(t,Lu(t),n,e)}),mf=ge(vt),Af=lr(function(n){return n.push(F,se),r(jf,F,n)}),kf=lr(function(n){return n.push(F,he),r(Rf,F,n)}),Ef=ne(function(n,t,r){n[t]=r},Fu(Nu)),Of=ne(function(n,t,r){ci.call(n,t)?n[t].push(r):n[t]=[r]},je),Sf=lr(Dt),If=Pr(function(n,t,r){nr(n,t,r)}),Rf=Pr(function(n,t,r,e){nr(n,t,r,e)}),zf=ge(function(n,t){ -var r={};if(null==n)return r;var e=false;t=l(t,function(t){return t=Rr(t,n),e||(e=1--n)return t.apply(this,arguments)}},On.ary=iu,On.assign=bf,On.assignIn=xf,On.assignInWith=jf,On.assignWith=wf,On.at=mf,On.before=ou,On.bind=Yo,On.bindAll=Zf,On.bindKey=Qo,On.castArray=function(){if(!arguments.length)return[];var n=arguments[0];return af(n)?n:[n]}, -On.chain=Xe,On.chunk=function(n,t,r){if(t=(r?ze(n,t,r):t===F)?1:Di(Ou(t),0),r=null==n?0:n.length,!r||1>t)return[];for(var e=0,u=0,i=Hu(Ri(r/t));et?0:t,e)):[]},On.dropRight=function(n,t,r){var e=null==n?0:n.length;return e?(t=r||t===F?1:Ou(t),t=e-t,vr(n,0,0>t?0:t)):[]},On.dropRightWhile=function(n,t){return n&&n.length?Ar(n,je(t,3),true,true):[]},On.dropWhile=function(n,t){return n&&n.length?Ar(n,je(t,3),true):[]},On.fill=function(n,t,r,e){var u=null==n?0:n.length;if(!u)return[];for(r&&typeof r!="number"&&ze(n,t,r)&&(r=0,e=u),u=n.length,r=Ou(r),0>r&&(r=-r>u?0:u+r),e=e===F||e>u?u:Ou(e),0>e&&(e+=u),e=r>e?0:Su(e);r>>0,r?(n=zu(n))&&(typeof t=="string"||null!=t&&!_f(t))&&(t=jr(t), -!t&&Bn.test(n))?zr($(n),0,r):n.split(t,r):[]},On.spread=function(n,t){if(typeof n!="function")throw new ei("Expected a function");return t=null==t?0:Di(Ou(t),0),lr(function(e){var u=e[t];return e=zr(e,0,t),u&&s(e,u),r(n,this,e)})},On.tail=function(n){var t=null==n?0:n.length;return t?vr(n,1,t):[]},On.take=function(n,t,r){return n&&n.length?(t=r||t===F?1:Ou(t),vr(n,0,0>t?0:t)):[]},On.takeRight=function(n,t,r){var e=null==n?0:n.length;return e?(t=r||t===F?1:Ou(t),t=e-t,vr(n,0>t?0:t,e)):[]},On.takeRightWhile=function(n,t){ -return n&&n.length?Ar(n,je(t,3),false,true):[]},On.takeWhile=function(n,t){return n&&n.length?Ar(n,je(t,3)):[]},On.tap=function(n,t){return t(n),n},On.throttle=function(n,t,r){var e=true,u=true;if(typeof n!="function")throw new ei("Expected a function");return bu(r)&&(e="leading"in r?!!r.leading:e,u="trailing"in r?!!r.trailing:u),au(n,t,{leading:e,maxWait:t,trailing:u})},On.thru=nu,On.toArray=ku,On.toPairs=Bf,On.toPairsIn=Lf,On.toPath=function(n){return af(n)?l(n,$e):Au(n)?[n]:Mr(mo(zu(n)))},On.toPlainObject=Ru, -On.transform=function(n,t,r){var e=af(n),i=e||sf(n)||gf(n);if(t=je(t,4),null==r){var o=n&&n.constructor;r=i?e?new o:[]:bu(n)&&gu(o)?io(bi(n)):{}}return(i?u:Et)(n,function(n,e,u){return t(r,n,e,u)}),r},On.unary=function(n){return iu(n,1)},On.union=Wo,On.unionBy=Bo,On.unionWith=Lo,On.uniq=function(n){return n&&n.length?wr(n):[]},On.uniqBy=function(n,t){return n&&n.length?wr(n,je(t,2)):[]},On.uniqWith=function(n,t){return t=typeof t=="function"?t:F,n&&n.length?wr(n,F,t):[]},On.unset=function(n,t){return null==n||mr(n,t); -},On.unzip=Ye,On.unzipWith=Qe,On.update=function(n,t,r){return null==n?n:pr(n,t,Ir(r)(It(n,t)),void 0)},On.updateWith=function(n,t,r,e){return e=typeof e=="function"?e:F,null!=n&&(n=pr(n,t,Ir(r)(It(n,t)),e)),n},On.values=Du,On.valuesIn=function(n){return null==n?[]:I(n,Uu(n))},On.without=Uo,On.words=$u,On.wrap=function(n,t){return rf(Ir(t),n)},On.xor=Co,On.xorBy=Do,On.xorWith=Mo,On.zip=To,On.zipObject=function(n,t){return Or(n||[],t||[],at)},On.zipObjectDeep=function(n,t){return Or(n||[],t||[],pr); -},On.zipWith=$o,On.entries=Bf,On.entriesIn=Lf,On.extend=xf,On.extendWith=jf,Zu(On,On),On.add=nc,On.attempt=Pf,On.camelCase=Uf,On.capitalize=Mu,On.ceil=tc,On.clamp=function(n,t,r){return r===F&&(r=t,t=F),r!==F&&(r=Iu(r),r=r===r?r:0),t!==F&&(t=Iu(t),t=t===t?t:0),gt(Iu(n),t,r)},On.clone=function(n){return dt(n,4)},On.cloneDeep=function(n){return dt(n,5)},On.cloneDeepWith=function(n,t){return t=typeof t=="function"?t:F,dt(n,5,t)},On.cloneWith=function(n,t){return t=typeof t=="function"?t:F,dt(n,4,t)}, -On.conformsTo=function(n,t){return null==t||bt(n,t,Lu(t))},On.deburr=Tu,On.defaultTo=function(n,t){return null==n||n!==n?t:n},On.divide=rc,On.endsWith=function(n,t,r){n=zu(n),t=jr(t);var e=n.length,e=r=r===F?e:gt(Ou(r),0,e);return r-=t.length,0<=r&&n.slice(r,e)==t},On.eq=hu,On.escape=function(n){return(n=zu(n))&&Y.test(n)?n.replace(H,et):n},On.escapeRegExp=function(n){return(n=zu(n))&&fn.test(n)?n.replace(on,"\\$&"):n},On.every=function(n,t,r){var e=af(n)?o:wt;return r&&ze(n,t,r)&&(t=F),e(n,je(t,3)); -},On.find=Po,On.findIndex=Ze,On.findKey=function(n,t){return v(n,je(t,3),Et)},On.findLast=Zo,On.findLastIndex=qe,On.findLastKey=function(n,t){return v(n,je(t,3),Ot)},On.floor=ec,On.forEach=ru,On.forEachRight=eu,On.forIn=function(n,t){return null==n?n:co(n,je(t,3),Uu)},On.forInRight=function(n,t){return null==n?n:ao(n,je(t,3),Uu)},On.forOwn=function(n,t){return n&&Et(n,je(t,3))},On.forOwnRight=function(n,t){return n&&Ot(n,je(t,3))},On.get=Wu,On.gt=of,On.gte=ff,On.has=function(n,t){return null!=n&&ke(n,t,Bt); -},On.hasIn=Bu,On.head=Ke,On.identity=Nu,On.includes=function(n,t,r,e){return n=pu(n)?n:Du(n),r=r&&!e?Ou(r):0,e=n.length,0>r&&(r=Di(e+r,0)),mu(n)?r<=e&&-1r&&(r=Di(e+r,0)),d(n,t,r)):-1},On.inRange=function(n,t,r){return t=Eu(t),r===F?(r=t,t=0):r=Eu(r),n=Iu(n),n>=Mi(t,r)&&n=n},On.isSet=vf,On.isString=mu,On.isSymbol=Au,On.isTypedArray=gf,On.isUndefined=function(n){return n===F},On.isWeakMap=function(n){return xu(n)&&"[object WeakMap]"==yo(n)},On.isWeakSet=function(n){return xu(n)&&"[object WeakSet]"==zt(n)},On.join=function(n,t){ -return null==n?"":Ui.call(n,t)},On.kebabCase=Cf,On.last=Ge,On.lastIndexOf=function(n,t,r){var e=null==n?0:n.length;if(!e)return-1;var u=e;if(r!==F&&(u=Ou(r),u=0>u?Di(e+u,0):Mi(u,e-1)),t===t){for(r=u+1;r--&&n[r]!==t;);n=r}else n=g(n,b,u,true);return n},On.lowerCase=Df,On.lowerFirst=Mf,On.lt=df,On.lte=yf,On.max=function(n){return n&&n.length?mt(n,Nu,Wt):F},On.maxBy=function(n,t){return n&&n.length?mt(n,je(t,2),Wt):F},On.mean=function(n){return x(n,Nu)},On.meanBy=function(n,t){return x(n,je(t,2))},On.min=function(n){ -return n&&n.length?mt(n,Nu,Jt):F},On.minBy=function(n,t){return n&&n.length?mt(n,je(t,2),Jt):F},On.stubArray=Ku,On.stubFalse=Gu,On.stubObject=function(){return{}},On.stubString=function(){return""},On.stubTrue=function(){return true},On.multiply=uc,On.nth=function(n,t){return n&&n.length?tr(n,Ou(t)):F},On.noConflict=function(){return Zn._===this&&(Zn._=pi),this},On.noop=qu,On.now=Jo,On.pad=function(n,t,r){n=zu(n);var e=(t=Ou(t))?T(n):0;return!t||e>=t?n:(t=(t-e)/2,ee(zi(t),r)+n+ee(Ri(t),r))},On.padEnd=function(n,t,r){ -n=zu(n);var e=(t=Ou(t))?T(n):0;return t&&et){var e=n;n=t,t=e}return r||n%1||t%1?(r=Fi(),Mi(n+r*(t-n+$n("1e-"+((r+"").length-1))),t)):cr(n,t); -},On.reduce=function(n,t,r){var e=af(n)?h:m,u=3>arguments.length;return e(n,je(t,4),r,u,oo)},On.reduceRight=function(n,t,r){var e=af(n)?p:m,u=3>arguments.length;return e(n,je(t,4),r,u,fo)},On.repeat=function(n,t,r){return t=(r?ze(n,t,r):t===F)?1:Ou(t),ar(zu(n),t)},On.replace=function(){var n=arguments,t=zu(n[0]);return 3>n.length?t:t.replace(n[1],n[2])},On.result=function(n,t,r){t=Rr(t,n);var e=-1,u=t.length;for(u||(u=1,n=F);++en||9007199254740991=i)return n;if(i=r-T(e),1>i)return e; -if(r=o?zr(o,0,i).join(""):n.slice(0,i),u===F)return r+e;if(o&&(i+=r.length-i),_f(u)){if(n.slice(i).search(u)){var f=r;for(u.global||(u=ti(u.source,zu(dn.exec(u))+"g")),u.lastIndex=0;o=u.exec(f);)var c=o.index;r=r.slice(0,c===F?i:c)}}else n.indexOf(jr(u),i)!=i&&(u=r.lastIndexOf(u),-1e.__dir__?"Right":"")}),e},Mn.prototype[n+"Right"]=function(t){ -return this.reverse()[n](t).reverse()}}),u(["filter","map","takeWhile"],function(n,t){var r=t+1,e=1==r||3==r;Mn.prototype[n]=function(n){var t=this.clone();return t.__iteratees__.push({iteratee:je(n,3),type:r}),t.__filtered__=t.__filtered__||e,t}}),u(["head","last"],function(n,t){var r="take"+(t?"Right":"");Mn.prototype[n]=function(){return this[r](1).value()[0]}}),u(["initial","tail"],function(n,t){var r="drop"+(t?"":"Right");Mn.prototype[n]=function(){return this.__filtered__?new Mn(this):this[r](1); -}}),Mn.prototype.compact=function(){return this.filter(Nu)},Mn.prototype.find=function(n){return this.filter(n).head()},Mn.prototype.findLast=function(n){return this.reverse().find(n)},Mn.prototype.invokeMap=lr(function(n,t){return typeof n=="function"?new Mn(this):this.map(function(r){return Dt(r,n,t)})}),Mn.prototype.reject=function(n){return this.filter(su(je(n)))},Mn.prototype.slice=function(n,t){n=Ou(n);var r=this;return r.__filtered__&&(0t)?new Mn(r):(0>n?r=r.takeRight(-n):n&&(r=r.drop(n)), -t!==F&&(t=Ou(t),r=0>t?r.dropRight(-t):r.take(t-n)),r)},Mn.prototype.takeRightWhile=function(n){return this.reverse().takeWhile(n).reverse()},Mn.prototype.toArray=function(){return this.take(4294967295)},Et(Mn.prototype,function(n,t){var r=/^(?:filter|find|map|reject)|While$/.test(t),e=/^(?:head|last)$/.test(t),u=On[e?"take"+("last"==t?"Right":""):t],i=e||/^find/.test(t);u&&(On.prototype[t]=function(){function t(n){return n=u.apply(On,s([n],f)),e&&h?n[0]:n}var o=this.__wrapped__,f=e?[1]:arguments,c=o instanceof Mn,a=f[0],l=c||af(o); -l&&r&&typeof a=="function"&&1!=a.length&&(c=l=false);var h=this.__chain__,p=!!this.__actions__.length,a=i&&!h,c=c&&!p;return!i&&l?(o=c?o:new Mn(this),o=n.apply(o,f),o.__actions__.push({func:nu,args:[t],thisArg:F}),new zn(o,h)):a&&c?n.apply(this,f):(o=this.thru(t),a?e?o.value()[0]:o.value():o)})}),u("pop push shift sort splice unshift".split(" "),function(n){var t=ui[n],r=/^(?:push|sort|unshift)$/.test(n)?"tap":"thru",e=/^(?:pop|shift)$/.test(n);On.prototype[n]=function(){var n=arguments;if(e&&!this.__chain__){ -var u=this.value();return t.apply(af(u)?u:[],n)}return this[r](function(r){return t.apply(af(r)?r:[],n)})}}),Et(Mn.prototype,function(n,t){var r=On[t];if(r){var e=r.name+"";(Ji[e]||(Ji[e]=[])).push({name:t,func:r})}}),Ji[Xr(F,2).name]=[{name:"wrapper",func:F}],Mn.prototype.clone=function(){var n=new Mn(this.__wrapped__);return n.__actions__=Mr(this.__actions__),n.__dir__=this.__dir__,n.__filtered__=this.__filtered__,n.__iteratees__=Mr(this.__iteratees__),n.__takeCount__=this.__takeCount__,n.__views__=Mr(this.__views__), -n},Mn.prototype.reverse=function(){if(this.__filtered__){var n=new Mn(this);n.__dir__=-1,n.__filtered__=true}else n=this.clone(),n.__dir__*=-1;return n},Mn.prototype.value=function(){var n,t=this.__wrapped__.value(),r=this.__dir__,e=af(t),u=0>r,i=e?t.length:0;n=i;for(var o=this.__views__,f=0,c=-1,a=o.length;++c=this.__values__.length;return{done:n,value:n?F:this.__values__[this.__index__++]}},On.prototype.plant=function(n){for(var t,r=this;r instanceof Sn;){var e=Pe(r);e.__index__=0,e.__values__=F,t?u.__wrapped__=e:t=e;var u=e,r=r.__wrapped__}return u.__wrapped__=n,t},On.prototype.reverse=function(){var n=this.__wrapped__;return n instanceof Mn?(this.__actions__.length&&(n=new Mn(this)),n=n.reverse(),n.__actions__.push({func:nu,args:[Je],thisArg:F}),new zn(n,this.__chain__)):this.thru(Je); -},On.prototype.toJSON=On.prototype.valueOf=On.prototype.value=function(){return kr(this.__wrapped__,this.__actions__)},On.prototype.first=On.prototype.head,Ai&&(On.prototype[Ai]=tu),On}();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(Zn._=it, define(function(){return it})):Vn?((Vn.exports=it)._=it,qn._=it):Zn._=it}).call(this); \ No newline at end of file diff --git a/includes/rubik-regular-webfont.woff b/includes/rubik-regular-webfont.woff deleted file mode 100644 index e12d964..0000000 Binary files a/includes/rubik-regular-webfont.woff and /dev/null differ diff --git a/includes/rubik-regular-webfont.woff2 b/includes/rubik-regular-webfont.woff2 deleted file mode 100644 index 3a1b47a..0000000 Binary files a/includes/rubik-regular-webfont.woff2 and /dev/null differ diff --git a/includes/script.js b/includes/script.js deleted file mode 100644 index 5d6c0f0..0000000 --- a/includes/script.js +++ /dev/null @@ -1,551 +0,0 @@ -$(document).ready(function() { - // todo define things like 16x16, 128x128 etc. as constants? - // also script debounce/throttle times - let animationTime = 400; // defined in bitsy.js - - let bitsyData = {}; - - let palette = { - id: 0, - background: { - red: 62, - green: 43, - blue: 32 - }, - tile: { - red: 208, - green: 112, - blue: 56 - }, - sprite: { - red: 229, - green: 92, - blue: 68 - } - }; - - let room = []; - - let tileMatchThreshold = 64; - - let croptions = { - url: 'https://i.imgur.com/ThQZ94v.jpg', - viewport: {width: 128, height: 128, type: 'square'}, - boundary: {width: 256, height: 256}, - zoom: 0 - }; - - let $croppie = $('#croppie'); - - $croppie.croppie(croptions); - - function colourDifference(colour1, colour2) { - let difference = {}; - - _.each(['red', 'green', 'blue'], function(key) { - difference[key] = Math.abs(colour1[key] - colour2[key]); - }); - - return _.toInteger(_.sum(_.toArray(difference))); - } - - function zeroPad(input, desiredLength) { - while (input.length < desiredLength) { - input = "0" + input; - } - - return input; - } - - function colourToHex(colour) { - return '#' + zeroPad(Number(colour.red ).toString(16), 2) - + zeroPad(Number(colour.green).toString(16), 2) - + zeroPad(Number(colour.blue ).toString(16), 2); - } - - function hexToColour(hex) { - let rgb = hex.match(/[\da-f]{2}/gi); - - return { - red: parseInt(rgb[0], 16), - green: parseInt(rgb[1], 16), - blue: parseInt(rgb[2], 16) - }; - } - - function getClosestColour(initialColour, colourOptions) { - // ditch sprite colour as we're not using it atm - delete colourOptions.sprite; - - _.each(palette, function(colour, name) { - colourOptions[name].name = name; - colourOptions[name].difference = colourDifference(initialColour, colour); - }); - - // lowest difference (closest) wins - return _.first(_.sortBy(colourOptions, 'difference')); - } - - function newTileName() { - let tileNames = _.map(bitsyData.tiles, 'name'); - - let i = 1; // start with 1 as 0 is an implicit tile - - while (tileNames.indexOf(i.toString(36)) > -1) { - i++; - } - - // base 36 = 0-9a-z - return i.toString(36); - } - - function handleBitsyGameData() { - let input = $bitsyData.val(); - - if ( ! input) { - return; - } - - bitsyData = {}; - - // get palettes - let palettes = input.match(/PAL ([^\n]*)\n(NAME ([^\n]*)\n)?(([0-9,]+){3}\n){3,}/g); - - bitsyData.palettes = {}; - - // do palettes always go 0..n? - // will this cause problems if not? - _.each(palettes, function(palette, n) { - let name = ""; - - if (palette.match(/NAME (.+)\n/)) { - name = palette.match(/NAME (.+)\n/)[0].replace('NAME ', ''); - } else if (palette.match(/PAL (\d+)\n/)) { - name = palette.match(/PAL (\d+)\n/)[0].replace("PAL", "palette"); - } - - let colours = palette.match(/\d+,\d+,\d+/g); - - colours = _.map(colours, function(colour) { - let rgb = colour.split(','); - - return {red: rgb[0], green: rgb[1], blue: rgb[2]}; - }); - - bitsyData.palettes[name] = { - id: n, - background: colours[0], - tile: colours[1], - sprite: colours[2] - } - }); - - // get tiles - - bitsyData.tiles = []; - - // tile 0 (background colour only) is implicit in bitsy rather than being stored in the game data - // so, make our own version - bitsyData.tiles.push({ - name: "0", - bitmap: _.chunk(_.times(64, _.constant(0)), 8), - new: false // this could also be used to stop it from being added to the game data, wooo - }); - - // everything after > is an optional second animation frame - // todo: handle multiple animation frames! more than 2 are allowed (but not via the standard editor) - let tiles = input.match(/TIL (.*)\n([01]{8}\n){8}(>\n([01]{8}\n){8})?/g); - - _.each(tiles, function(tile) { - let name = tile.match(/TIL .*/)[0].replace('TIL ', ''); - - tile = tile.replace(/TIL .*\n/, ''); - - let bitmap = _.map(tile.match(/[01]/g), _.toInteger); - - let newTile = { - name: name, - new: false - }; - - // todo make this agnostic? i.e. tile.frames = _.chunk(bitmap, 64) - - if (bitmap.length === 64) { // normal tile - newTile.bitmap = _.chunk(bitmap, 8); - } else if (bitmap.length === 128) { // animated tile - newTile.bitmap = _.chunk(_.take( bitmap, 64), 8); - newTile.secondAnimationFrame = _.chunk(_.takeRight(bitmap, 64), 8); - } - - bitsyData.tiles.push(newTile); - }); - - if (_.find(bitsyData.palettes, {'id': palette.id})) { - // user has already selected a palette, leave it be - - // in case this is the first run: - palette = _.find(bitsyData.palettes, {'id': palette.id}) - - // if we just set the palette to the newly imported palette with the same ID, - // we will lose any changes the user has made to the palettes - // is this a big issue considering that the palettes cannot be currently saved anyway? - } else { - // set palette to first imported palette and redraw - palette = _.first(_.sortBy(bitsyData.palettes, 'id')); - } - - renderDebounced(); - - // update palette picker - $('tr.palette').remove(); - - _.each(bitsyData.palettes, function(palette, name) { - $('#palette tbody').append( - '' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - + '' - ); - }); - - $('input[name="id"][value="' + palette.id + '"]').siblings(':radio').trigger('click'); - } - - function readFile(input, callback) { - if (input.files && input.files[0]) { - let reader = new FileReader(); - - reader.onload = callback; - - reader.readAsDataURL(input.files[0]); - } - } - - function readTextFile(input, callback) { - if (input.files && input.files[0]) { - let reader = new FileReader(); - - reader.onload = callback; - - reader.readAsText(input.files[0]); - } - } - - function render() { - $croppie.croppie('result', { - type: 'rawcanvas', - size: 'viewport' - }).then(function (result) { - let imageData = result.getContext('2d').getImageData(0, 0, 128, 128); - let rawData = imageData.data; - let monochrome = []; - - let brightnessAdjustment = parseFloat($('#brightness').val()); - - // for each pixel - for (let i = 0; i < rawData.length; i += 4) { - // this brightness adjustment is pretty crude but whatever - let pixel = { - red: _.clamp(rawData[i ] + brightnessAdjustment, 0, 255), - green: _.clamp(rawData[i + 1] + brightnessAdjustment, 0, 255), - blue: _.clamp(rawData[i + 2] + brightnessAdjustment, 0, 255) - }; - - let targetColour = getClosestColour(pixel, palette); - - if (targetColour.name === "background") { - monochrome.push(0); - } else { // tile - monochrome.push(1) - } - - rawData[i ] = targetColour.red; - rawData[i + 1] = targetColour.green; - rawData[i + 2] = targetColour.blue; - rawData[i + 3] = 255; // alpha - } - - // split monochrome bitmap into equal chunks for easier x:y access - monochrome = _.chunk(monochrome, 128); - - document.getElementById('preview').getContext('2d').putImageData(imageData, 0, 0); - - // tiled output - - room = []; - - _.times(16, function(tileY) { - _.times(16, function(tileX) { - // make pseudo-tile from monochrome bitmap - let pseudoTile = []; - - _.times(8, function(y) { - pseudoTile.push( - _.slice(monochrome[(tileY * 8) + y], (tileX * 8), (tileX * 8) + 8) - ); - }); - - let bestMatch; - - // if we want to always create new tiles, don't bother trying to check matches - if (tileMatchThreshold === 64) { - // even if we want to "always create new tiles" we still don't want to create duplicates - bestMatch = _.find(bitsyData.tiles, function(tile) { - return _.isEqual(tile.bitmap, pseudoTile); - }); - - if (bestMatch) { - bestMatch.match = 64; - } - } else { - _.each(bitsyData.tiles, function(tile) { - tile.match = 0; - - _.each(tile.bitmap, function(row, y) { - _.each(row, function(pixel, x) { - if (parseInt(pixel) === parseInt(pseudoTile[y][x])) { - tile.match++; - } - }); - }); - - if (tile.secondAnimationFrame) { - _.each(tile.secondAnimationFrame, function(row, y) { - _.each(row, function(pixel, x) { - if (parseInt(pixel) === parseInt(pseudoTile[y][x])) { - tile.match++; - } - }); - }); - - tile.match /= 2; - } - }); - - // what if there are several equally good matches? - // find highest match amount and find all of them - let bestMatchAmount = _.last(_.sortBy(bitsyData.tiles, ['match'])).match; - let bestMatches = _.filter(bitsyData.tiles, {'match': bestMatchAmount}); - - // sort by name in ascending order - // earlier names are preferable - bestMatch = _.first(_.sortBy(bestMatches, 'name')); - } - - if ( ! bestMatch || bestMatch.match < tileMatchThreshold) { - // turn pseudo-tile into a real tile and add it to the tile data - - let name = newTileName(); - - bitsyData.tiles.push({ - name: name, - bitmap: pseudoTile, - new: true - }); - - room.push(name); - - // issue with this approach: - // what if a tile we add late in the loop is a better match for an earlier "good enough" match? - // this would also cause different results if the user were to add the same room several times - // we could keep iterating until the room no longer changes - } else { - room.push(bestMatch.name); - } - }); - }); - - room = _.chunk(room, 16); - - // write room to output - - imageData = document.getElementById("room-output").getContext('2d').getImageData(0, 0, 128, 128); - rawData = imageData.data; - - _.each(room, function(row, tileY) { - _.each(row, function(tileName, tileX) { - let tile = _.find(bitsyData.tiles, {'name' : tileName}); - - _.each(tile.bitmap, function(row, y) { - _.each(row, function(pixel, x) { - let position = (((tileY * 8) + y) * 128) + ((tileX * 8) + x); - - position *= 4; // 4 values (rgba) per pixel - - let pixelColour = {}; - - switch(parseInt(pixel)) { - case 0: pixelColour = palette.background; break; - case 1: pixelColour = palette.tile; break; - default: console.log("error"); - } - - rawData[position ] = pixelColour.red; - rawData[position + 1] = pixelColour.green; - rawData[position + 2] = pixelColour.blue; - rawData[position + 3] = 255; - }); - }); - }); - }); - - document.getElementById('room-output').getContext('2d').putImageData(imageData, 0, 0); - }); - } - - let renderDebounced = _.debounce(render, 30); - let renderThrottled = _.throttle(render, 30); - - $croppie.on('update', renderDebounced); - - let $brightness = $('#brightness'); - - $brightness.on('change', renderThrottled); - - $brightness.on('dblclick', function() { - $(this).val(0); - - renderDebounced(); - }); - - $('label[for="brightness"]').on('click touchdown', function() { - $('#brightness').trigger('dblclick'); - }); - - let $bitsyData = $('#bitsy-data'); - - $bitsyData.on('change blur keyup', handleBitsyGameData); - - $bitsyData.on('focus', function() { - $(this).select(); - }); - - handleBitsyGameData(); - - $('#imageUpload').on('change', function () { - readFile(this, function (e) { - $croppie.croppie('bind', { - url: e.target.result, - zoom: 0 - }); - }); - }); - - $('input.game-data').on('change', function() { - readTextFile(this, function (e) { - $bitsyData.val(e.target.result); - handleBitsyGameData(); - }); - }); - - // these inputs get added and removed from the DOM so the event handler needs to be on the document - $(document).on('change', '#palette input', function() { - let id = parseInt($(this).closest('.palette').find('input[name="id"]').val()); - - // if this is a colour input, update the palette - if ($(this).attr('type') === 'color') { - if (id === palette.id) { - palette[$(this).attr('name')] = hexToColour($(this).val()); - } - } - - // if this is a radio button, pick this palette - if ($(this).attr('type') === 'radio') { - palette.id = id; - palette.background = hexToColour($(this).closest('.palette').find('input[name="background"]').val()); - palette.tile = hexToColour($(this).closest('.palette').find('input[name="tile"]' ).val()); - // sprite colour is not currently used - } - - renderDebounced(); - }); - - $(document).on('change', '#threshold', function() { - let newValue = parseInt($(this).val()); - - if (newValue < tileMatchThreshold) { - // set tiles back to default - bitsyData.tiles = _.filter(bitsyData.tiles, ['new', false]); - } - - tileMatchThreshold = newValue; - - renderThrottled(); - }); - - $('#never').on('click touchend', function() { - $('#threshold').val(0).change(); - }); - - $('#always').on('click touchend', function() { - $('#threshold').val(64).change(); - }); - - $('#save').on('click touchend', function() { - let $textArea = $('textarea'); - - let newGameData = $textArea.val(); - - // handle rooms - - // need to import IDs so we don't give the new room a conflicting ID - let roomIds = newGameData.match(/ROOM \d+\n/g); - - roomIds = _.map(roomIds, function(roomId) { - return parseInt(roomId.replace(/[^\d]+/g, "")); - }); - - let newRoomId = _.max(roomIds) + 1; - - let newRoomName = $('#roomName').val(); - // remove invalid chars? what's invalid? newlines? are those possible? - - let newRoom = "ROOM " + newRoomId + "\n"; - - _.each(room, function(row) { - newRoom += _.toString(row) + "\n"; - }); - - if (newRoomName) { - newRoom += "NAME " + newRoomName + "\n"; - } - - newRoom += "PAL " + palette.id + "\n"; - - newGameData = newGameData.replace(/(ROOM .*\n(.*\n)*PAL .*)/g, '$1\n\n' + newRoom); - - // handle tiles - - let newTiles = _.filter(bitsyData.tiles, 'new'); - let tileText = ""; - - _.each(newTiles, function(tile, n) { - tileText += "TIL " + tile.name + "\n"; //again, rename tile name to id... - - _.each(tile.bitmap, function(row) { - tileText += row.join('') + "\n"; - }); - - tileText += "NAME " + newRoomName + " " + (n + 1) + "\n"; - - // don't need to worry about animation right now - - tileText += "\n"; - }); - - newGameData = newGameData.replace(/(TIL.*(.*\n)*)SPR/g, '$1\n\n' + tileText + 'SPR'); - - // write - $textArea.val(newGameData); - - handleBitsyGameData(); - - // todo: give the user some nice "yay! it worked!" kinda feedback? - }); -}); diff --git a/includes/style.css b/includes/style.css deleted file mode 100644 index 8a6ebcb..0000000 --- a/includes/style.css +++ /dev/null @@ -1,112 +0,0 @@ -@font-face { - font-family: 'rubikregular'; - src: url('rubik-regular-webfont.woff2') format('woff2'), url('rubik-regular-webfont.woff') format('woff'); - font-weight: normal; - font-style: normal; -} -* { - box-sizing: border-box; - font-family: "rubikregular", sans-serif; - text-align: center; -} -html, -body { - background-color: #594a54; - color: #d3cbd0; -} -a { - color: #f69f8f; -} -canvas { - image-rendering: -moz-crisp-edges; - image-rendering: pixelated; -} -input[type="color"] { - width: 2em; - height: 2em; - margin: 0; - padding: 0; - border: none; - background: none; -} -input[type="color"][disabled] { - opacity: 0.5; -} -input[type="file"] { - padding: 1em 0; - width: 256px; -} -input[type="text"], -button { - width: 14em; - margin: 1em; - padding: 0.25em; - font-size: 1em; -} -table { - margin: 0 auto; -} -table td, -table th { - width: 50%; -} -table td { - text-align: left; -} -table th { - text-align: right; -} -textarea { - height: 256px; - width: 256px; - font-family: monospace; -} -textarea, -input { - text-align: left; -} -.box256 { - height: 256px; - width: 256px; -} -.centre { - margin: 0 auto; -} -.croppie-container { - height: auto; -} -.flex-container { - background-color: #d3cbd0; - display: flex; - flex-flow: row wrap; -} -.section { - margin: 0 auto; - background-color: #d3cbd0; - color: #594a54; - width: 256px; - padding-bottom: 1em; -} -#brightness { - width: 256px; -} -#threshold { - width: 150px; -} -#brightness + label, -#threshold + label { - margin: 0 auto; -} -#palettes { - height: 256px; - width: 256px; - overflow-y: scroll; -} -#preview, -#room-output { - margin: 0 auto; - width: 256px; -} -#save { - margin-top: 0; -} diff --git a/includes/style.less b/includes/style.less index 98f8b33..f95c7a0 100644 --- a/includes/style.less +++ b/includes/style.less @@ -1,144 +1,108 @@ -@font-face { - font-family: 'rubikregular'; - src: url('rubik-regular-webfont.woff2') format('woff2'), - url('rubik-regular-webfont.woff') format('woff'); - font-weight: normal; - font-style: normal; -} - -@light: #d3cbd0; -@dark: #594a54; -@accent: #f69f8f; // pink +@background: #fff4d9; +@text: #ec6d7d; +@accent: #a3c4ef; * { box-sizing: border-box; - font-family: "rubikregular", sans-serif; + color: @text; + margin: 0 auto 0.5em auto; text-align: center; } html, body { - background-color: @dark; - color: @light; -} - -a { - color: @accent; -} - -canvas { - image-rendering: -moz-crisp-edges; - image-rendering: pixelated; -} - -input[type="color"] { - &[disabled] { - opacity: 0.5; - } - - width: 2em; - height: 2em; + background-color: @background; + font-size: 3vmin; margin: 0; padding: 0; - border: none; - background: none; } -input[type="file"] { - padding: 1em 0; - width: 256px; +button { + padding: 1em; + white-space: nowrap; + width: 100%; + + &.pagination:not(.normal) { + position: absolute; + bottom: 5vmin; + width: auto; + + &.prev { + left: 5vmin; + } + + &.next, &.start { + right: 5vmin; + } + } } -input[type="text"], button { - width: 14em; - margin: 1em; - padding: 0.25em; - font-size: 1em; +h1 { + margin: 0; } -table { - margin: 0 auto; +h3 { + font-size: 0.9em; +} - td, th { - width: 50%; +input { + width: 100%; + text-align: left; + + &[type="checkbox"] { + width: auto; + margin-right: 1em; + position: relative; + top: 0.25em; + left: 0.25em; } +} - td { - text-align: left; - } +img { + max-height: 12em; + max-width: 100%; + margin: 0; +} - th { - text-align: right; - } +p { + font-size: 0.8em; + margin: 0 auto 1em auto; +} + +label { + font-size: 0.75em; + font-weight: bold; } textarea { - .box256; - - font-family: monospace; + height: 15em; + padding: 0.5em; + text-align: left; + width: 100%; } -textarea, input { +.background { + background-color: @background; + padding: 0.5em; + border-radius: 0.5em; +} + +.checkboxes label { + margin-right: 1em; +} + +.image-container { + height: 38.5vmin; text-align: left; } -.box256 { - height: 256px; - width: 256px; -} - -.centre { - margin: 0 auto; -} - -.croppie-container { - height: auto; -} - -.flex-container { - background-color: @light; - display: flex; - flex-flow: row wrap; -} - -// make this just for desktop view? -// put sections in a single column on mobile/etc? -.section { - .centre; - - background-color: @light; - color: @dark; - width: 256px; - padding-bottom: 1em; -} - -#brightness { - width: 256px; -} - -#threshold { - width: 150px; -} - -#brightness, #threshold { - + label{ - .centre; - } - - // todo make this match the croppie slider or vice versa -} - -#palettes { - .box256; - - overflow-y: scroll; -} - -#preview, #room-output { - .centre; - - width: 256px; -} - -#save { - margin-top: 0; +.page { + height: 70vmin; + width: 70vmin; + + background-color: @background; + border: 2px solid @accent; + border-radius: 5vmin; + box-shadow: @accent 1vmin 1vmin; + padding: 5vmin; + position: relative; } diff --git a/index.html b/index.html deleted file mode 100644 index 4bc52bc..0000000 --- a/index.html +++ /dev/null @@ -1,90 +0,0 @@ -image to bitsy

image-to-bitsy

convert any image to a bitsy room

about -| -please contact me if you have any issues: -twitter, -email -

game data

paste or upload your game data (or html) here

(maybe make a backup first)

image

palette

preview

output



\ No newline at end of file diff --git a/index.pug b/index.pug index a7c450a..c9d6fc0 100644 --- a/index.pug +++ b/index.pug @@ -1,96 +1,50 @@ doctype html -html +html(lang="en-gb") head meta(charset="utf-8") - title image to bitsy - - // lodash - script(src="includes/lodash.min.js") - - // jquery - script(src="includes/jquery.min.js") - - // croppie - link(rel="stylesheet" href="includes/croppie.css") - script(src="includes/croppie.js") - - // main stuff - link(rel="stylesheet" type="text/css" href="includes/style.css") - script(src="includes/script.js") + title pixsy + link(rel="stylesheet" href="includes/style.css") body - header - h1 image-to-bitsy - p convert any image to a #[a(href="https://ledoux.itch.io/bitsy") bitsy] room - p. - #[a(href="https://github.com/synth-ruiner/bitsy-image-to-room") about] - | - please contact me if you have any issues: - #[a(href="https://twitter.com/synth_ruiner") twitter], - #[a(href="mailto:max@tinybird.info") email] - - .flex-container - #game-data.section + h1 + | pixsy + //img(alt="tilesy" src="includes/tilesy.png") + p + span.background convert images to Bitsy rooms + .pages + .page#start + button.normal.pagination.next#new create a new bitsy game + button.normal.pagination.next#load load an existing bitsy game + .page.game-data h2 game data - - textarea#bitsy-data(placeholder="Bitsy data or html") - include includes/default.bitsy - - p - input.game-data(type="file") - p paste or upload your game data (or html) here - p (maybe make a backup first) - - #image.section + input#game(type="file" autocomplete="off") + br + textarea#game-data( + placeholder="Paste your game data here or use the file chooser button above" + autocomplete="off" + ) + button.pagination.prev previous + button.pagination.next#game-data-next(disabled=true) next + .page.image h2 image + .image-container + input#image(type="file" autocomplete="off") + img#preview + button.pagination.prev previous + button.pagination.next next + .page.extras + h2 tiles + label + | tile name (optional) + input#prefix(type="text" placeholder="e.g. 'forest'" autocomplete="off") - #croppie - - input#imageUpload(type="file" accepts="image/*") - - #palette.section - h2 palette - - form#palettes - table - tbody - - #crop.section - h2 preview - - canvas#preview(width=128, height=128) - - input#brightness(type="range" min=-255 max=255 value=0) - - label(for="brightness") brightness - - //- to do - input#dithering(type="checkbox") - label(for="dithering") dithering - - //- to do - input#smoothing(type="checkbox") - label(for="smoothing") smoothing - - #output.section - h2 output - - canvas#room-output(width=128, height=128) - - label#never never - input#threshold(type="range" min=0 max=64 value=64) - label#always always + button.pagination.prev#back-to-image previous + button.pagination.next#import next + .page.download + h2 download + textarea#output(autocomplete="off") br - label(for="threshold") create new tiles - br - - input#roomName(type="text", placeholder="room name") - - button#save write to game data - - //- to do - - //-label favour broad strokes | favour details - - br - - //-button Download \ No newline at end of file + button#download download + button.pagination.prev#add add another image + button.pagination.start#reset start again + script(type="module") + include script.js diff --git a/package.json b/package.json deleted file mode 100644 index 28778ee..0000000 --- a/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "bitsy-image-to-room", - "description": "Tool to convert images to Bitsy rooms. Can work as an offline web application", - "version": "0.0.1", - "devDependencies": { - "pug": "latest", - "pug-cli": "latest", - "less": "latest" - }, - "dependencies": { - "croppie": "^2.5.1", - "jquery": "^3.5.0" - } -} diff --git a/readme.md b/readme.md deleted file mode 100644 index a50634d..0000000 --- a/readme.md +++ /dev/null @@ -1,87 +0,0 @@ -# image to bitsy - -## about - -a tool for Bitsy. upload any image and convert it into a room. -the room will be added to the game data automatically and you can paste it back into Bitsy. - -## thanks - -to **Adam Le Doux** for creating the wonderful and inspiring Bitsy - -to **J.P. LeBreton** for creating Playscii which was a huge inspiration for this tool - -to **Mark Wonnacott** for being relentlessly encouraging and making me want to work even an eighth as hard as them - -to **Foliotek** for the **Croppie** image plugin - -## contributing - -Forks and pull requests welcome! - -The stylesheet and html are auto-generated; if you want to alter them please edit the pug template or less stylesheet, then either run the included `build.sh` script or build from the command line as follows: - -`pug index.pug index.html` - -`lessc style.less style.css` - -`pug` and `less` can be installed via `npm` as follows: - -`npm install -g pug-cli` - -`npm install -g less` - -I had to hack the included Croppie plugin to allow the user to upload images from their own computer without falling foul of CORS restrictions. So the version bundled here is non-standard. It's a one-line change: - -``` -// croppie.js:182 (original) -if (src.match(/^(https)?:\/\/|^\/\//)) { -// croppie.js:182 (mine) -if (src.match(/^(file|https)?:\/\/|^\/\//)) { -``` - -## bugs - -* does not work on ipad (can't scroll to the right?) - * possibly fixed; needs testing -* create tiles slider breaks onto 2 lines in some browsers? -* sometimes overwrites existing rooms? - -## to do - -* test new room ID handling!!! -* don't reuse wall tiles -* add 'clear'/'upload' buttons for game data -* select all on clicking game data entry field -* allow user to save output as image, or tweet it :) - * *user can currently right-click -> Save As but the 128x128 size is not great* -* animate animated tiles -* profile script performance and optimise where most needed -* make brightness slider trigger redraw every so often while being dragged, instead of waiting until drag stop -* add up/down arrows to the brightness slider for incremental tweaks -* add 'all-white' tile by default in case the game data doesn't have it? -* handle arbitrary animation frames (editor only supports 2 frames, but game data has no upper limit) -* list how many new tiles are being created -* combine preview and output -* give warning on duplicate room names? -* loading spinner on rendering? -* make brightness slider exponential -* rotation options for image - -## could do - -* add some alternate default tiles - something more useful e.g. dithered tiles, gradients -* add dithering options -* add camera support so users can take a pic instead of uploading an image -* add a 'smoothing' stage to remove errant pixels -* allow user to add palettes to game data -* allow user to draw to canvas -* do a 'branching tree' approach to finding the closest tile? i.e. create a 1x1, 2x2, 4x4 version of each tile, so all the broadly darker tiles will sit under '0' and lighter tiles under '1', then tiles that are lighter at the top will sit under '1100', etc... I'm not sure how much more effective this will be or whatever it will give better/faster results but it's worth a try -* give heavier weighting to edge pixels when finding a matching tile? (thanks Mark) -* apply grid lines to preview -* optionally add inverted versions of existing tiles if they are a better match -* make new tiles out of fragments of existing tiles instead of directly copying from bitmap -* allow user to zoom out so the image is letterboxed/windowboxed/etc. -* add 'invert' function -* allow for image colour hack -* make a tool for batch importing images? diff --git a/script.js b/script.js new file mode 100644 index 0000000..c8ec306 --- /dev/null +++ b/script.js @@ -0,0 +1,168 @@ +import init, {load_default_game_data, add_tiles} from './pkg/pixsy.js'; + +// stolen from https://ourcodeworld.com/articles/read/189/how-to-create-a-file-and-generate-a-download-with-javascript-in-the-browser-without-a-server +function download(filename, text) { + let element = document.createElement('a'); + + element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); + element.setAttribute('download', filename); + element.style.display = 'none'; + document.body.appendChild(element); + element.click(); + document.body.removeChild(element); +} + +function el(id) { + return document.getElementById(id); +} + +function pagination(e) { + const parent = e.target.parentNode; + + parent.style.display = "none"; + + if (e.target.classList.contains("next")) { + parent.nextSibling.style.display = "block"; + } else if (e.target.classList.contains("prev")) { + parent.previousSibling.style.display = "block"; + } else if (e.target.classList.contains("start")) { + document.getElementById("start").style.display = "block"; + } +} + +function readFile(input, callback, type = "text") { + if (input.files && input.files[0]) { + let reader = new FileReader(); + reader.onload = callback; + + if (type === "text") { + reader.readAsText(input.files[0]); + } else { + reader.readAsDataURL(input.files[0]); + } + } +} + +async function run() { + await init(); + + const buttonAddImage = el("add"); + const buttonBackToImage = el("back-to-image"); + const buttonDownload = el("download"); + const buttonGameDataProceed = el("game-data-next"); + const buttonImportGame = el("import"); + const buttonLoadGame = el("load"); + const buttonNewGame = el("new"); + const buttonReset = el("reset"); + const checkboxInvertTiles = el("invert"); + const checkboxFlipTiles = el("flip"); + const checkboxMirrorTiles = el("mirror"); + const checkboxRotateTiles = el("rotate"); + const inputPrefix = el("prefix"); + const imagePreview = el("preview"); + const textareaGameDataInput = el("game-data"); + const textareaGameDataOutput = el("output"); + + // hide all pages except start page + for (let page of document.getElementsByClassName('page')) { + page.style.display = "none"; + } + el("start").style.display = "block"; + + for (let pageButton of document.getElementsByClassName("pagination")) { + pageButton.addEventListener('click', pagination); + pageButton.addEventListener('touchend', pagination); + } + + function new_game() { + textareaGameDataInput.value = load_default_game_data(); + checkGameData(); + // we don't need to look at the default game data, so skip ahead to the image page + buttonGameDataProceed.click(); + } + + function clear_game() { + textareaGameDataInput.value = ""; + checkGameData(); + } + + buttonNewGame.addEventListener("click", new_game); + buttonNewGame.addEventListener("touchend", new_game); + buttonLoadGame.addEventListener("click", clear_game); + buttonLoadGame.addEventListener("touchend", clear_game); + + // handle game data and image + + el("game").addEventListener("change", function() { + readFile(this, function (e) { + textareaGameDataInput.value = e.target.result; + checkGameData(); + }, "text"); + }); + + function checkGameData() { + if (textareaGameDataInput.value.length > 0) { + buttonGameDataProceed.removeAttribute("disabled"); + } else { + buttonGameDataProceed.setAttribute("disabled", "disabled"); + } + } + + textareaGameDataInput.addEventListener("change", checkGameData); + textareaGameDataInput.addEventListener("keyup", checkGameData); + checkGameData(); + + imagePreview.style.display = "none"; + + el('image').addEventListener('change', function () { + readFile(this, function (e) { + imagePreview.src = e.target.result; + imagePreview.style.display = "initial" + }, "image"); + }); + + function addTiles() { + let image = imagePreview.getAttribute("src"); + let gameData = textareaGameDataInput.value; + let prefix = inputPrefix.value; + + textareaGameDataOutput.value = add_tiles( + gameData, + image, + prefix, + checkboxInvertTiles.checked, + checkboxFlipTiles.checked, + checkboxMirrorTiles.checked, + checkboxRotateTiles.checked + ); + } + + buttonImportGame.addEventListener("click", addTiles); + buttonImportGame.addEventListener("touchend", addTiles); + + function handleDownload() { + download("output.bitsy", textareaGameDataOutput.value); + } + + buttonDownload.addEventListener("click", handleDownload); + buttonDownload.addEventListener("touchend", handleDownload); + + function addImage() { + textareaGameDataInput.value = textareaGameDataOutput.value; + textareaGameDataOutput.value = ""; + buttonBackToImage.click(); + } + + buttonAddImage.addEventListener("click", addImage); + buttonAddImage.addEventListener("touchend", addImage); + + function reset() { + clear_game(); + imagePreview.removeAttribute("src"); + } + + buttonReset.addEventListener("click", reset); + buttonReset.addEventListener("touchend", reset); +} + +run(); diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..a7316bf --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,174 @@ +use bitsy_parser::game::Game; +use bitsy_parser::image::Image; +use bitsy_parser::tile::Tile; +use image::{GenericImageView, Pixel}; +use wasm_bindgen::prelude::*; + +const SD: u32 = 8; + +#[wasm_bindgen] +pub fn load_default_game_data() -> String { + bitsy_parser::mock::game_default().to_string() +} + +fn tile_name(prefix: &str, index: &u32) -> Option { + if prefix.len() > 0 { + Some(format!("{} {}", prefix, index)) + } else { + None + } +} + +/// image is a base64-encoded string +/// prefix will be ignored if empty +#[wasm_bindgen] +pub fn add_tiles( + game_data: String, + image: String, + prefix: String, + invert: bool, + flip: bool, + mirror: bool, + rotate: bool +) -> String { + let game = Game::from(game_data); + if game.is_err() { + return format!("Couldn't parse game data"); + } + let mut game = game.unwrap(); + + let image: Vec<&str> = image.split("base64,").collect(); + let image = image[1]; + + let image = base64::decode(image); + if image.is_err() { + return format!("Couldn't decode image"); + } + let image = image.unwrap(); + let image = image::load_from_memory(image.as_ref()); + if image.is_err() { + return format!("Couldn't load image"); + } + let image = image.unwrap(); + + let width = image.width(); + let height = image.height(); + let columns = (width as f64 / SD as f64).floor() as u32; + let rows = (height as f64 / SD as f64).floor() as u32; + + let mut tile_index = 1; + + for column in 0..columns { + for row in 0..rows { + let mut pixels = Vec::with_capacity(64); + + for y in (row * SD)..((row + 1) * SD) { + for x in (column * SD)..((column + 1) * SD) { + let pixel = image.get_pixel(x, y).to_rgb(); + let total = pixel[0] as u32 + pixel[1] as u32 + pixel[2] as u32; + // is each channel brighter than 128/255 on average? + pixels.push(if total >= 384 {1} else {0}); + } + } + + let tile = Tile { + /// "0" will get overwritten to a new, safe tile ID + id: "0".to_string(), + name: tile_name(&prefix, &tile_index), + wall: None, + animation_frames: vec![Image { pixels }], + colour_id: None + }; + + if !game.tiles.contains(&tile) { + game.add_tile(tile.clone()); + + tile_index += 1; + } + + if invert { + let mut inverted = tile.clone(); + inverted.invert(); + + if inverted.name.is_some() { + inverted.name = Some(format!("{} inverted", inverted.name.unwrap())); + } + + if !game.tiles.contains(&inverted) { + game.add_tile(inverted); + } + } + + if flip { + let mut flipped = tile.clone(); + flipped.flip(); + + if flipped.name.is_some() { + flipped.name = Some(format!("{} flipped", flipped.name.unwrap())); + } + + if !game.tiles.contains(&flipped) { + game.add_tile(flipped); + } + } + + if mirror { + let mut mirrored = tile.clone(); + mirrored.mirror(); + + if mirrored.name.is_some() { + mirrored.name = Some(format!("{} mirrored", mirrored.name.unwrap())); + } + + if !game.tiles.contains(&mirrored) { + game.add_tile(mirrored); + } + } + + if rotate { + for i in 1..4 { + let mut rotated = tile.clone(); + + for _ in 0..i { + rotated.rotate(); + } + + if rotated.name.is_some() { + rotated.name = Some(format!("{} {}°", rotated.name.unwrap(), i * 90)); + } + + if !game.tiles.contains(&rotated) { + game.add_tile(rotated); + } + } + } + } + } + + game.dedupe_tiles(); + game.to_string() +} + +#[cfg(test)] +mod test { + use crate::add_tiles; + + #[test] + fn example() { + let game_data = bitsy_parser::mock::game_default().to_string(); + let image = include_str!("test-resources/test.png.base64").to_string(); + + let output = add_tiles( + game_data, + image, + "".to_string(), + false, + false, + false, + false + ); + + let expected = include_str!("test-resources/expected.bitsy"); + assert_eq!(output, expected); + } +}