UNPKG

@progracol/bingo-board-component

Version:
1 lines 10.5 kB
var __awaiter=this&&this.__awaiter||function(t,e,r,n){function i(t){return t instanceof r?t:new r((function(e){e(t)}))}return new(r||(r=Promise))((function(r,o){function s(t){try{u(n.next(t))}catch(e){o(e)}}function a(t){try{u(n["throw"](t))}catch(e){o(e)}}function u(t){t.done?r(t.value):i(t.value).then(s,a)}u((n=n.apply(t,e||[])).next())}))};var __generator=this&&this.__generator||function(t,e){var r={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},n,i,o,s;return s={next:a(0),throw:a(1),return:a(2)},typeof Symbol==="function"&&(s[Symbol.iterator]=function(){return this}),s;function a(t){return function(e){return u([t,e])}}function u(s){if(n)throw new TypeError("Generator is already executing.");while(r)try{if(n=1,i&&(o=s[0]&2?i["return"]:s[0]?i["throw"]||((o=i["return"])&&o.call(i),0):i.next)&&!(o=o.call(i,s[1])).done)return o;if(i=0,o)s=[s[0]&2,o.value];switch(s[0]){case 0:case 1:o=s;break;case 4:r.label++;return{value:s[1],done:false};case 5:r.label++;i=s[1];s=[0];continue;case 7:s=r.ops.pop();r.trys.pop();continue;default:if(!(o=r.trys,o=o.length>0&&o[o.length-1])&&(s[0]===6||s[0]===2)){r=0;continue}if(s[0]===3&&(!o||s[1]>o[0]&&s[1]<o[3])){r.label=s[1];break}if(s[0]===6&&r.label<o[1]){r.label=o[1];o=s;break}if(o&&r.label<o[2]){r.label=o[2];r.ops.push(s);break}if(o[2])r.ops.pop();r.trys.pop();continue}s=e.call(t,r)}catch(a){s=[6,a];i=0}finally{n=o=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}};var __spreadArrays=this&&this.__spreadArrays||function(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;for(var n=Array(t),i=0,e=0;e<r;e++)for(var o=arguments[e],s=0,a=o.length;s<a;s++,i++)n[i]=o[s];return n};System.register(["./p-ac76cb1c.system.js"],(function(t){"use strict";var e,r,n;return{setters:[function(t){e=t.r;r=t.h;n=t.g}],execute:function(){var i=function(){function t(t,e){this.number=t;this.checked=e}return t}();var o=t("bingo_board",function(){function t(t){e(this,t);this.moduleId="";this.numbers=[];this.numbersBoard2=[];this.ranking=1;this.probability=0;this.bet=0;this.king=false;this.secProbability=0;this.manual=false;this.validated=false;this.miniBoard=false;this.select=false;this.register=false;this.hide=false;this.posLast=-1;this.posFigure=[]}t.prototype.componentDidLoad=function(){};t.prototype.componentDidUnload=function(){};t.prototype.newNumber=function(t){return __awaiter(this,void 0,void 0,(function(){var e;return __generator(this,(function(r){e=__spreadArrays(this.numbersBoard);e[t].checked=true;this.numbersBoard=__spreadArrays(e);this.posLast=t;return[2]}))}))};t.prototype.newBallotNumber=function(t){return __awaiter(this,void 0,void 0,(function(){var e;return __generator(this,(function(r){e=this.numbers.indexOf(t);if(e!=-1){this.newNumber(e)}else{this.posLast=-1}return[2]}))}))};t.prototype.noNumber=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){this.posLast=-1;return[2]}))}))};t.prototype.addNumber=function(t){if(this.manual&&!this.miniBoard){if(this.numbersBoard[t].checked)this.deleteNumber(t);else this.newNumber(t)}};t.prototype.deleteNumber=function(t){return __awaiter(this,void 0,void 0,(function(){var e;return __generator(this,(function(r){e=__spreadArrays(this.numbersBoard);e[t].checked=false;this.numbersBoard=__spreadArrays(e);return[2]}))}))};t.prototype.componentWillUpdate=function(){};t.prototype.clean=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){this.numbersBoard.forEach((function(t){t.checked=false}));return[2]}))}))};t.prototype.validateFigure=function(t){return __awaiter(this,void 0,void 0,(function(){var e,r;var n=this;return __generator(this,(function(i){e=[];for(r=0;r<t.length;r++){e.push(this.oneValidate(t[r].positions))}return[2,Promise.all(e).then((function(t){var e=0;while(e<t.length){if(t[e].hasBingo)return{element:n.element,pattern:t[e].pattern,hasBingo:true,moduleId:n.moduleId};++e}return{element:n.element,pattern:0,hasBingo:false,moduleId:n.moduleId}}))]}))}))};t.prototype.validate=function(t){return __awaiter(this,void 0,void 0,(function(){var e,r;var n=this;return __generator(this,(function(i){e=[];for(r=0;r<t.length;r++){e.push(this.oneValidate(t[r]))}return[2,Promise.all(e).then((function(t){var e=0;while(e<t.length){if(t[e].hasBingo)return{element:n.element,pattern:t[e].pattern,hasBingo:true,moduleId:n.moduleId};++e}return{element:n.element,pattern:0,hasBingo:false,moduleId:n.moduleId}}))]}))}))};t.prototype.oneValidate=function(t){return __awaiter(this,void 0,void 0,(function(){var e,r,n;return __generator(this,(function(i){e=this.intFromBytes(this.numbersBoard)&t;r=this.countOnes(t)-this.countOnes(e);n=this.calcProbability(r,10);this.getPositions(t);if(n>this.probability){this.secProbability=this.probability;this.probability=n}else{if(n>this.secProbability)this.secProbability=n}return[2,{pattern:t,hasBingo:e==t}]}))}))};t.prototype.calcProbability=function(t,e){var r=1;for(var n=0;n<t;n++){r*=(n+1)/(e-n)}return r*100};t.prototype.intFromBytes=function(t){var e=0;for(var r=0;r<t.length;++r){e+=+t[r].checked;if(r<t.length-1){e=e<<1}}return e};t.prototype.getPositions=function(t){var e=24;this.posFigure=[];while(t>0){if(t&1)this.posFigure.push(e);t>>=1;--e}};t.prototype.countOnes=function(t){var e=0;while(t>0){if(t&1)++e;t>>=1}return e};t.prototype.parseNumbersProp=function(t){var e=this;if(t){this.numbers=t;this.numbersBoard=[];this.numbers.forEach((function(t){e.numbersBoard.push(new i(t,false))}))}};t.prototype.parseNumbersBoard2Prop=function(t){if(t){this.numbersBoard=__spreadArrays(t)}};t.prototype.componentWillLoad=function(){this.parseNumbersProp(this.numbers);if(!this.numbers.length)this.parseNumbersBoard2Prop(this.numbersBoard2)};t.prototype.render=function(){var t=this;if(!this.hide){return r("div",{class:"board"+(this.select?" selected":"")+(this.register?" registered":"")+(this.validated?" validated":"")+(this.miniBoard?" mini":"")},r("div",{class:"border"},this.numbersBoard.map((function(e,n){return r("div",{onClick:function(){t.addNumber(n)},class:"column text-center"+(e.checked?" active":"")+(t.posFigure.indexOf(n)==-1?"":" belong")+(n==t.posLast?" last":"")},r("div",{class:"number"+(e.number?"":" center")},r("span",null,e.number?e.number:t.moduleId)))}))),r("div",{key:this.bet,class:"bet"},this.bet>0?this.bet:""))}else{return r("div",{class:"board"})}};Object.defineProperty(t.prototype,"element",{get:function(){return n(this)},enumerable:true,configurable:true});Object.defineProperty(t,"watchers",{get:function(){return{numbers:["parseNumbersProp"],numbersBoard2:["parseNumbersBoard2Prop"]}},enumerable:true,configurable:true});Object.defineProperty(t,"style",{get:function(){return"\@charset \"UTF-8\";:host{--bg-main:transparent;--bg-board:#000;--header-color:#edcb32;--bg-ballot:#fff;--bg-ballot-active:#edcb32;--bg-ballot-last:#33ad15;--bg-ballot-check:red;--color-ballot:#000;--color-ballot-active:#fff;--color-ballot-last:#fff;--color-text:#fff;--bg-bet-color:#fff;--border-board-color:#edcb32;--border-board-width:5px;--border-board-color-select:#33ad15;--border-board-color-select-contrast:#000;--border-board-color-register:red;--border-board-color-register-contrast:#fff;--height:25vh;--font-size:2rem;--font-size-center:2rem;--font-family:\"Geometry\";--border-radius:5%}.board{font-family:var(--font-family);font-size:calc(var(--font-size));background:var(--bg-main);width:100%;padding:2%;position:relative;float:left}.board .border{display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;-ms-flex-align:center;align-items:center;margin:auto;position:relative;-webkit-box-sizing:border-box;box-sizing:border-box;background:var(--bg-board);background-size:100% 100%;background-clip:padding-box;\n /* !importanté */border-width:calc(var(--border-board-width));border-radius:var(--border-radius);border-style:solid;border-color:var(--border-board-color);\n /* !importanté */padding:0;height:calc(var(--height))}.board .border:before{content:\" \";position:absolute;top:0;right:0;bottom:0;left:0;z-index:-1;border-radius:inherit}.board .border .column{float:left;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;width:20%;height:20%;text-align:center}.board .border .column.active .number{background:var(--bg-ballot-active);background-size:100% 100%}.board .border .column.active .number span{color:var(--color-ballot-active)}.board .border .column.last .number{background:var(--bg-ballot-last);background-size:100% 100%}.board .border .column.last .number span{color:var(--color-ballot-last)}.board .border .column .number{padding:0;height:75%;margin:2% auto;background:var(--bg-ballot);background-size:100% 100%;width:90%;border:none;border-radius:50%;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;width:75%}.board .border .column .number.center{background:transparent;border:0;margin:0;width:100%}.board .border .column .number.center span{color:var(--color-text);font-size:calc(var(--font-size-center))}.board .border .column .number span{color:var(--color-ballot);font-size:calc(var(--font-size));max-width:100%;padding:0;margin:0 auto;display:block}.board .bet,.board .ranking{position:absolute;width:20%;height:12%;display:none;-ms-flex-negative:0;flex-shrink:0;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;bottom:-8%;border-radius:15%;color:var(--bg-bet-color);font-size:120%}.board .ranking{left:10%}.board .bet{right:10%}.board.validated{width:90%;float:none;margin:auto}.board.validated .border{height:40vw}.board.validated .column.belong .number{background:var(--bg-ballot-check);background-size:100% 100%}.board.validated .column.last .number{background:var(--bg-ballot-last);background-size:100% 100%}.board.selected .border{border-color:var(--border-board-color-select)}.board.selected .bet,.board.selected .ranking{background:var(--border-board-color-select);color:var(--border-board-color-select-contrast);display:-ms-flexbox;display:flex}.board.registered .border{border-color:var(--border-board-color-register)}.board.registered .bet,.board.registered .ranking{background:var(--border-board-color-register);color:var(--border-board-color-register-contrast);display:-ms-flexbox;display:flex}.board.mini .border:before{content:none}.board.mini .border .column .number span{display:none}.text-center{text-align:center!important}"},enumerable:true,configurable:true});return t}())}}}));