UNPKG

microbit-web-components

Version:
1 lines 3.32 kB
var __awaiter=this&&this.__awaiter||function(t,e,r,i){return new(r||(r=Promise))(function(n,s){function a(t){try{c(i.next(t))}catch(t){s(t)}}function o(t){try{c(i["throw"](t))}catch(t){s(t)}}function c(t){t.done?n(t.value):new r(function(e){e(t.value)}).then(a,o)}c((i=i.apply(t,e||[])).next())})};var __generator=this&&this.__generator||function(t,e){var r={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},i,n,s,a;return a={next:o(0),throw:o(1),return:o(2)},typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function o(t){return function(e){return c([t,e])}}function c(a){if(i)throw new TypeError("Generator is already executing.");while(r)try{if(i=1,n&&(s=a[0]&2?n["return"]:a[0]?n["throw"]||((s=n["return"])&&s.call(n),0):n.next)&&!(s=s.call(n,a[1])).done)return s;if(n=0,s)a=[a[0]&2,s.value];switch(a[0]){case 0:case 1:s=a;break;case 4:r.label++;return{value:a[1],done:false};case 5:r.label++;n=a[1];a=[0];continue;case 7:a=r.ops.pop();r.trys.pop();continue;default:if(!(s=r.trys,s=s.length>0&&s[s.length-1])&&(a[0]===6||a[0]===2)){r=0;continue}if(a[0]===3&&(!s||a[1]>s[0]&&a[1]<s[3])){r.label=a[1];break}if(a[0]===6&&r.label<s[1]){r.label=s[1];s=a;break}if(s&&r.label<s[2]){r.label=s[2];r.ops.push(a);break}if(s[2])r.ops.pop();r.trys.pop();continue}a=e.call(t,r)}catch(t){a=[6,t];n=0}finally{i=s=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};System.register(["./p-79150c1d.system.js","./p-86f8a157.system.js"],function(t){"use strict";var e,r,i;return{setters:[function(t){e=t.r;r=t.g},function(t){i=t.m}],execute:function(){var n=function(){function t(t){e(this,t);this.services=null;this.idTemplate="microbit-matrix-${row}-${column}";this.offClass="microbit-matrix-off";this.onClass="microbit-matrix-on";i.addListener(this)}t.prototype.servicesUpdated=function(){return __awaiter(this,void 0,void 0,function(){var t,e,r,i,n;var s=this;return __generator(this,function(a){switch(a.label){case 0:t=[[],[],[],[],[]];e=function(e){var i=function(i){var n=r.idTemplate.replace("${row}",e.toString()).replace("${column}",i.toString());var a=document.getElementById(n);if(a){t[e][i]=a;a.onclick=function(){return s.toggle(e,i)};a.classList.toggle(r.onClass,false);a.classList.toggle(r.offClass,false)}};for(var n=0;n<5;n++){i(n)}};r=this;for(i=0;i<5;i++){e(i)}this.elements=t;if(!this.services||!this.services.ledService){return[2]}n=this;return[4,this.services.ledService.readMatrixState()];case 1:n.matrix=a.sent();return[4,this.updateMatrix()];case 2:a.sent();return[2]}})})};t.prototype.toggle=function(t,e){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(r){switch(r.label){case 0:this.matrix[t][e]=!this.matrix[t][e];return[4,this.services.ledService.writeMatrixState(this.matrix)];case 1:r.sent();this.updateMatrix();return[2]}})})};t.prototype.updateMatrix=function(){var t=this;this.matrix.forEach(function(e,r){e.forEach(function(e,i){var n=t.elements[r][i];if(n){n.classList.toggle(t.onClass,e);n.classList.toggle(t.offClass,!e)}})})};Object.defineProperty(t.prototype,"el",{get:function(){return r(this)},enumerable:true,configurable:true});Object.defineProperty(t,"watchers",{get:function(){return{services:["servicesUpdated"]}},enumerable:true,configurable:true});return t}();t("microbit_matrix",n)}}});