antosdk-apps/LuaPlayground/build/debug/main.js

33 lines
206 KiB
JavaScript
Raw Permalink Normal View History

2023-07-14 12:05:12 +02:00
(function(){var t,e,i;t=class{constructor(t){this.target=t,this.el=$("<canvas>").attr("class","viewer")[0],this.offset=10,this.points=[],this.preprocess(),this.getBound(),this.prepare(),this.render()}canvasPoint(t){return new paper.Point(t[0]/this.target.resolution+this.base.x,-t[1]/this.target.resolution+this.base.y)}preprocess(){return this.points=this.target.data}getBound(){var t,e,i,n,r,s,a,o;for(n={x:0,y:0},i={x:0,y:0},t=0,e=(r=this.points).length;t<e;t++)a=(s=r[t])[0]/this.target.resolution,o=s[1]/this.target.resolution,a<n.x&&(n.x=a),o<n.y&&(n.y=o),a>i.x&&(i.x=a),o>i.y&&(i.y=o);return this.bound=[n,i],this.base={x:0-this.bound[0].x+this.offset,y:this.bound[1].y+this.offset},this.width=i.x-n.x+2*this.offset,this.height=i.y-n.y+2*this.offset}drawPoint(t,e,i){return new paper.Path.Circle({center:this.canvasPoint(t),radius:i,fillColor:e})}drawGrid(t,e){var i,n,r,s,a,o;for(o=this.target.resolution*t,n=Math.ceil(this.bound[0].x/t);n*t<this.bound[1].x;)s=new paper.Point(n*t+this.base.x,-this.bound[0].y+this.base.y),i=new paper.Point(n*t+this.base.x,-this.bound[1].y+this.base.y),(r=new paper.Path).strokeColor=e,r.moveTo(s),r.lineTo(i),n++;for(n=Math.ceil(this.bound[0].y/t);n*t<this.bound[1].y;)s=new paper.Point(this.bound[0].x+this.base.x,-n*t+this.base.y),i=new paper.Point(this.bound[1].x+this.base.x,-n*t+this.base.y),(r=new paper.Path).strokeColor=e,r.moveTo(s),r.lineTo(i),n++;return(a=new paper.PointText(this.bound[0].x+this.base.x,this.base.y-this.bound[1].y+this.offset)).justification="left",a.fillColor="#494949",a.content=`Resolution: ${this.target.resolution}, grid size: ${o} mm`}drawAxis(t){var e,i,n;return(i=new paper.Path).strokeColor=t,n=new paper.Point(this.bound[0].x+this.base.x,this.base.y),e=new paper.Point(this.bound[1].x+this.base.x,this.base.y),i.moveTo(n),i.lineTo(e),(i=new paper.Path).strokeColor=t,n=new paper.Point(this.base.x,-this.bound[0].y+this.base.y),e=new paper.Point(this.base.x,-this.bound[1].y+this.base.y),i.moveTo(n),i.lineTo(e),this.drawPoint([0,0],t,3)}prepare(){var t;return(t=this.el.getContext("2d")).translate(this.base.x,this.base.y),t.canvas.width=this.width,t.canvas.height=this.height,paper.setup(this.el)}render(){}},i=class extends t{constructor(t){super(t)}p2c(t,e){var i;return i=e*Math.PI/180,[t*Math.cos(i),t*Math.sin(i)]}preprocess(){var t,e,i,n,r,s;if("polar"!==this.target.coordinate)return this.points=this.target.data;for(this.point=[],t=0,r=[],e=0,i=(n=this.target.data).length;e<i;e++)s=n[e],this.points.push(this.p2c(s,this.target.start+t*this.target.angularResolution)),r.push(t+=1);return r}render(){var t,e,i,n,r,s,a;for(this.drawGrid(20,"#DBDBDB"),this.drawAxis("#0A84FF"),e=0,i=(r=this.points).length;e<i;e++)a=r[e],"polar"===this.target.coordinate&&((n=new paper.Path).strokeColor="#c2a10e",s=this.canvasPoint([0,0]),t=this.canvasPoint(a),n.moveTo(s),n.lineTo(t)),this.drawPoint(a,"red",3);return paper.view.draw()}},(e=class extends this.OS.application.BaseApplication{constructor(t){super("LuaPlayground",t)}main(){return this.datarea=this.find("editorea"),this.output=this.find("output"),this.editor=ace.edit(this.datarea),this.editor.setOptions({enableBasicAutocompletion:!0,enableLiveAutocompletion:!0,highlightActiveLine:!0,highlightSelectedWord:!0,behavioursEnabled:!0,wrap:!0,fontSize:"11pt",showInvisibles:!0}),this.editor.getSession().setUseWrapMode(!0),this.editor.session.setMode("ace/mode/lua"),this.editor.setTheme("ace/theme/monokai"),this.on("vboxchange",()=>this.editor.resize()),this.find("log-clear").onbtclick=t=>this.log("clean"),this.find("code-run").onbtclick=t=>this.run(),this.find("code-stop").onbtclick=t=>{if(this.socket)return this.socket.close()},this.socket=null,this.bindKey("CTRL-R",()=>this.run()),this.morphon(OS.GUI.RESPONSIVE.PORTRAIT,t=>(console.log(t,"FULL"),t?(this.find("wrapper").dir="column",this.find("resizer").dir="column"):(this.find("wrapper").dir="row",this.find("resizer").dir="row")))}menu(){return[{text:"__(Code)",nodes:[{text:"__(Run)",dataid:this.name+"-Run",shortcut:"C-R"}],onchildselect:t=>this.run()}]}log(t,e){var i;return"clean"===t?$(this.
2019-05-06 16:08:46 +02:00
/*!
* Paper.js v0.12.0 - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & https://puckey.studio/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*
* Date: Mon Dec 3 14:19:11 2018 +0100
*
***
*
* Straps.js - Class inheritance library with support for bean-style accessors
*
* Copyright (c) 2006 - 2016 Juerg Lehni
* http://scratchdisk.com/
*
* Distributed under the MIT license.
*
***
*
* Acorn.js
* https://marijnhaverbeke.nl/acorn/
*
* Acorn is a tiny, fast JavaScript parser written in JavaScript,
* created by Marijn Haverbeke and released under an MIT license.
*
*/
2023-07-14 12:05:12 +02:00
var paper=function(t,e){var i=(t=t||require("./node/self.js")).window,n=t.document,r=new function(){function t(t,e,r,s,a){function u(n,u){"string"==typeof(u=u||(u=o(e,n))&&(u.get?u:u.value))&&"#"===u[0]&&(u=t[u.substring(1)]||u);var c,f="function"==typeof u,d=u,_=a||f&&!u.base?u&&u.get?n in t:t[n]:null;a&&_||(f&&_&&(u.base=_),f&&!1!==s&&(c=n.match(/^([gs]et|is)(([A-Z])(.*))$/))&&(l[c[3].toLowerCase()+c[4]]=c[2]),d&&!f&&d.get&&"function"==typeof d.get&&i.isPlainObject(d)||(d={value:d,writable:!0}),(o(t,n)||{configurable:!0}).configurable&&(d.configurable=!0,d.enumerable=null!=r?r:!c),h(t,n,d))}var l={};if(e){for(var c in e)e.hasOwnProperty(c)&&!n.test(c)&&u(c);for(var c in l){var f=l[c],d=t["set"+f],_=t["get"+f]||d&&t["is"+f];!_||!0!==s&&0!==_.length||u(c,{get:_,set:d})}}return t}function i(){for(var t=0,e=arguments.length;t<e;t++){var i=arguments[t];i&&c(this,i)}return this}var n=/^(statics|enumerable|beans|preserve)$/,r=[],s=r.slice,a=Object.create,o=Object.getOwnPropertyDescriptor,h=Object.defineProperty,u=r.forEach||function(t,e){for(var i=0,n=this.length;i<n;i++)t.call(e,this[i],i,this)},l=function(t,e){for(var i in this)this.hasOwnProperty(i)&&t.call(e,this[i],i,this)},c=Object.assign||function(t){for(var e=1,i=arguments.length;e<i;e++){var n=arguments[e];for(var r in n)n.hasOwnProperty(r)&&(t[r]=n[r])}return t},f=function(t,e,i){if(t){var n=o(t,"length");(n&&"number"==typeof n.value?u:l).call(t,e,i=i||t)}return i};return t(i,{inject:function(e){if(e){var i=!0===e.statics?e:e.statics,n=e.beans,r=e.preserve;i!==e&&t(this.prototype,e,e.enumerable,n,r),t(this,i,null,n,r)}for(var s=1,a=arguments.length;s<a;s++)this.inject(arguments[s]);return this},extend:function(){for(var e,i,n,r=this,s=0,o=arguments.length;s<o&&(!e||!i);s++)n=arguments[s],e=e||n.initialize,i=i||n.prototype;return i=(e=e||function(){r.apply(this,arguments)}).prototype=i||a(this.prototype),h(i,"constructor",{value:e,writable:!0,configurable:!0}),t(e,this),arguments.length&&this.inject.apply(e,arguments),e.base=r,e}}).inject({enumerable:!1,initialize:i,set:i,inject:function(){for(var e=0,i=arguments.length;e<i;e++){var n=arguments[e];n&&t(this,n,n.enumerable,n.beans,n.preserve)}return this},extend:function(){var t=a(this);return t.inject.apply(t,arguments)},each:function(t,e){return f(this,t,e)},clone:function(){return new this.constructor(this)},statics:{set:c,each:f,create:a,define:h,describe:o,clone:function(t){return c(new t.constructor,t)},isPlainObject:function(t){var e=null!=t&&t.constructor;return e&&(e===Object||e===i||"Object"===e.name)},pick:function(t,i){return t!==e?t:i},slice:function(t,e,i){return s.call(t,e,i)}}})};"undefined"!=typeof module&&(module.exports=r),r.inject({enumerable:!1,toString:function(){return null!=this._id?(this._class||"Object")+(this._name?" '"+this._name+"'":" @"+this._id):"{ "+r.each(this,(function(t,e){if(!/^_/.test(e)){var i=typeof t;this.push(e+": "+("number"===i?h.instance.number(t):"string"===i?"'"+t+"'":t))}}),[]).join(", ")+" }"},getClassName:function(){return this._class||""},importJSON:function(t){return r.importJSON(t,this)},exportJSON:function(t){return r.exportJSON(this,t)},toJSON:function(){return r.serialize(this)},set:function(t,e){return t&&r.filter(this,t,e,this._prioritize),this}},{beans:!1,statics:{exports:{},extend:function t(){var e=t.base.apply(this,arguments),i=e.prototype._class;return i&&!r.exports[i]&&(r.exports[i]=e),e},equals:function(t,e){if(t===e)return!0;if(t&&t.equals)return t.equals(e);if(e&&e.equals)return e.equals(t);if(t&&e&&"object"==typeof t&&"object"==typeof e){if(Array.isArray(t)&&Array.isArray(e)){if((i=t.length)!==e.length)return!1;for(;i--;)if(!r.equals(t[i],e[i]))return!1}else{var i,n=Object.keys(t);if((i=n.length)!==Object.keys(e).length)return!1;for(;i--;){var s=n[i];if(!e.hasOwnProperty(s)||!r.equals(t[s],e[s]))return!1}}return!0}return!1},read:function(t,i,n,s){if(this===r){var a=this.peek(t,i);return t.__index++,a}var o=this.prototype,h=o._readIndex,u=i||h&&t.__index||0,l=t.length,c=t[u];if(s=s||l-u,c instanceof this||n&&n.readNull&&null==c&&s<=1)return h&&(t.__ind