diff --git a/src/client/controllers/Population.js b/src/client/controllers/Population.js index 47cda74..f3cc56f 100644 --- a/src/client/controllers/Population.js +++ b/src/client/controllers/Population.js @@ -357,9 +357,6 @@ export class Population { #staticPenalty = async () => { this.population = this.population.sort((a,b) => (b.fitness-b.constraint) - (a.fitness-a.constraint)); - // debug - // best individual fitness - // console.log ("best individual=", this.population[0].fitness, this.population[0].constraint); } copy = (obj) => { diff --git a/src/client/controllers/Poster.js b/src/client/controllers/Poster.js index 2e6b7d3..ca97d3e 100644 --- a/src/client/controllers/Poster.js +++ b/src/client/controllers/Poster.js @@ -1,15 +1,9 @@ import * as evaluator from '@evoposter/evaluator/lib/evaluator.min.js'; - -// DEV LINK -// import * as evaluator from '@evoposter/evaluator/src/index.mjs'; - -import {Params} from "../Params.js"; import backgroundStyles from "./BackgroundStyles.js"; - import {randomScheme, contrastChecker} from "./ColorGenerator.js"; +import {sumProduct} from "../utils.js"; -import {sumArr, sumProduct} from "../utils.js"; - +import {Params} from "../Params.js"; import * as config from './../../../evo-poster.config.js'; const MAX_COLOR_SCHEME_ATTEMPT = config["default"]["COLOR"] !== undefined ? config["default"]["COLOR"]["MAX_COLOR_SCHEME_ATTEMPT"] : 200; @@ -29,11 +23,31 @@ class Poster { this.constraint = 0; this.metrics = { - legibility: 1, - gridAppropriateness: 1 + constraints: { + legibility: 0, + gridAppropriateness: 0, + general: 0 + }, + aesthetics: { + alignment: 0, + regularity: 0, + justification: 0, + typefaceParing: 0, + whiteSpace: 0, + balance: 0, + general: 0, + weights: 0 + }, + semantics: { + emphasis: 0, + layout: 0, + visuals: 0, + general: 0, + weights: [0,0,0] + } } - this.sentencesLength = []; + this.sentencesLength = []; const h = (genotype === null) ? params["size"]["height"] : genotype["size"]["height"]; this.maxFontSize = Params.typography.maxSize * h; @@ -43,7 +57,6 @@ class Poster { this.#showGrid = params !== null ? params.display.grid : false; this.phenotype = null; - // this.evaluate(); } copy = () => { @@ -109,7 +122,7 @@ class Poster { JSON.parse(JSON.stringify(params.size.margin)) ); - // define texboxes + // define textboxes const textboxes = []; const alignment = params.typography.verticalAlignment === 0 ? @@ -160,7 +173,6 @@ class Poster { } const images = []; - // console.log(`params.images`, params.images); for (let input of params.images) { const src = input.src; const img = loadImage(src, async (img) => { @@ -176,7 +188,6 @@ class Poster { }) } - // create genotype return { grid: grid, @@ -242,11 +253,6 @@ class Poster { let semantics = 0; // semantic part of fitness let aesthetics = 0; // aesthetics part of fitness - //const ls = layoutSemantics(this.genotype["grid"]["rows"]["l"], dist, `FIXED`, this.genotype["size"]); - // const semanticsEmphasis = evaluator.semanticsEmphasis(this.genotype["textboxes"], dist, noCurrentTypefaces); - // const justification = evaluator.legibility(this.sentencesLength, this.genotype["grid"].getAvailableWidth(), `JUSTIFY`); - // const visualSemantics = evaluator.semanticsVisuals(emotionalData, this.genotype["textboxes"], this.genotype.background.colors, this.params.typography.typefaces); - if (weights[0] > 0) { const semanticsWeights = this.params["evaluation"]["semanticsWeights"]; const emphasis = (semanticsWeights[0] > 0) ? evaluator.semanticsEmphasis(this.genotype["textboxes"], dist, noCurrentTypefaces) : 0; @@ -254,57 +260,55 @@ class Poster { const layout = (semanticsWeights[1] > 0) ? evaluator.semanticsLayout(this.genotype["grid"]["rows"]["l"], dist, layoutMode, this.genotype["size"]) : 0; const visuals = (semanticsWeights[2] > 0) ? await evaluator.semanticsVisuals(emotionalData, this.genotype["textboxes"], this.genotype.background.colors, this.params.typography.typefaces) : 0; semantics = sumProduct( [emphasis, layout, visuals], semanticsWeights); - } - - - // semantics - // const ls = layoutSemantics(this.genotype["grid"]["rows"]["l"], dist, `FIXED`, this.genotype["size"]); - // const semanticsEmphasis = evaluator.semanticsEmphasis(this.genotype["textboxes"], dist, noCurrentTypefaces); - // const justification = evaluator.legibility(this.sentencesLength, this.genotype["grid"].getAvailableWidth(), `JUSTIFY`); - // const visualSemantics = evaluator.semanticsVisuals(emotionalData, this.genotype["textboxes"], this.genotype.background.colors, this.params.typography.typefaces); - // const alignment = evaluator.alignment(this.sentencesLength, this.genotype["textboxes"].map(tb => tb["alignment"])); - // const regularity = evaluator.regularity(this.genotype["grid"]["rows"]["l"]); + // save info + this.metrics["semantics"]["emphasis"] = emphasis; + this.metrics["semantics"]["layout"] = layout; + this.metrics["semantics"]["visuals"] = visuals; + this.metrics["semantics"]["general"] = semantics; + this.metrics["semantics"]["weights"] = semanticsWeights; + } - // textboxes have the same typography colour - // const whiteSpace = evaluator.whiteSpaceFraction(this.phenotype, this.genotype["textboxes"][0]["color"]); - //const typefaceParing = evaluator.typefaceParing(this.genotype["textboxes"].map(gene => gene["typeface"]), this.params["typography"]["typefaces"]) - let balanceMode = this.genotype["textboxes"][0]["alignment"] === 0 ? `LEFT` : this.genotype["textboxes"][0]["alignment"] === 1 ? `CENTER` : `RIGHT`; - balanceMode += this.genotype["typography"]["verticalAlignment"] === 0 ? `-TOP` : this.genotype["typography"]["verticalAlignment"] === 1 ? `-CENTER` : `-BOTTOM`; - - const balance = await evaluator.visualBalance( - this.phenotype, - this.genotype["size"], - this.genotype["grid"]["rows"], - this.genotype["textboxes"].map(tb => tb.size), - this.sentencesLength, - balanceMode - ); - console.log (`balance=${balance}`) + if (weights[1] > 0) { + const aestheticsWeights = this.params["evaluation"]["aestheticsWeights"]; + const alignment = (aestheticsWeights[0] > 0) ? evaluator.alignment(this.sentencesLength, this.genotype["textboxes"].map(tb => tb["alignment"])) : 0; + const regularity = (aestheticsWeights[1] > 0) ? evaluator.regularity(this.genotype["grid"]["rows"]["l"]) : 0; + const justification = (aestheticsWeights[2] > 0) ? evaluator.legibility(this.sentencesLength, this.genotype["grid"].getAvailableWidth(), `JUSTIFY`) : 0; + const typefaceParing = (aestheticsWeights[3] > 0) ? evaluator.typefaceParing(this.genotype["textboxes"].map(gene => gene["typeface"]), this.params["typography"]["typefaces"]) : 0; + const whiteSpace = (aestheticsWeights[4] > 0) ? evaluator.whiteSpaceFraction(this.phenotype, this.genotype["textboxes"][0]["color"]) : 0; + let balanceMode = this.genotype["textboxes"][0]["alignment"] === 0 ? `LEFT` : this.genotype["textboxes"][0]["alignment"] === 1 ? `CENTER` : `RIGHT`; + balanceMode += this.genotype["typography"]["verticalAlignment"] === 0 ? `-TOP` : this.genotype["typography"]["verticalAlignment"] === 1 ? `-CENTER` : `-BOTTOM`; + const balance = (aestheticsWeights[5] > 0) ? await evaluator.visualBalance(this.phenotype, this.genotype["size"], this.genotype["grid"]["rows"], this.genotype["textboxes"].map(tb => tb.size), this.sentencesLength, balanceMode) : 0; + aesthetics = sumProduct([alignment, regularity, justification, typefaceParing, whiteSpace, balance], aestheticsWeights); - // this.fitness = layoutSemantics; - // this.fitness = (visualSemantics * 0.3 + layoutSemantics * 0.3 + justification * 0.4); + // save info + this.metrics["aesthetics"]["alignment"] = alignment; + this.metrics["aesthetics"]["regularity"] = regularity; + this.metrics["aesthetics"]["justification"] = justification; + this.metrics["aesthetics"]["typefaceParing"] = typefaceParing; + this.metrics["aesthetics"]["whiteSpace"] = whiteSpace; + this.metrics["aesthetics"]["balance"] = balance; + this.metrics["aesthetics"]["general"] = aesthetics; + this.metrics["aesthetics"]["weights"] = aestheticsWeights; + } // constraints - // const legibility = evaluator.legibility(this.sentencesLength, this.genotype["grid"].getAvailableWidth(), `OVERSET`); - /*const gridAppropriateness = evaluator.gridAppropriateSize( + const legibility = evaluator.legibility(this.sentencesLength, this.genotype["grid"].getAvailableWidth(), `OVERSET`); + const gridAppropriateness = evaluator.gridAppropriateSize( this.genotype["size"].width, this.genotype["size"].height, this.genotype["grid"].rows.l, this.genotype["grid"].columns.l, this.genotype["grid"].marginsPos ); - this.constraint = legibility + gridAppropriateness;*/ - - // this.metrics["legibility"] = legibility; - // this.metrics["gridAppropriateness"] = gridAppropriateness; this.fitness = sumProduct([semantics, aesthetics], weights); - console.log (`fitness=${this.fitness} (semantics=${semantics}, aesthetics=${aesthetics})`); - this.constraint = 1; + this.constraint = legibility + gridAppropriateness; + + this.metrics["constraints"]["legibility"] = legibility; + this.metrics["constraints"]["gridAppropriateness"] = gridAppropriateness; + this.metrics["constraints"]["general"] = this.constraint; - // returns a number between 0 and 0.5 - // subtracted to fitness return { "fitness": this.fitness, "constraints": this.constraint diff --git a/src/public/app.js b/src/public/app.js index b14350c..5cd15e7 100644 --- a/src/public/app.js +++ b/src/public/app.js @@ -3,26 +3,26 @@ * Copyright 2019 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ -const t$3=window,e$6=t$3.ShadowRoot&&(void 0===t$3.ShadyCSS||t$3.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s$4=Symbol(),n$4=new WeakMap;let o$4 = class o{constructor(t,e,n){if(this._$cssResult$=!0,n!==s$4)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e;}get styleSheet(){let t=this.o;const s=this.t;if(e$6&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=n$4.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&n$4.set(s,t));}return t}toString(){return this.cssText}};const r$3=t=>new o$4("string"==typeof t?t:t+"",void 0,s$4),S$2=(s,n)=>{e$6?s.adoptedStyleSheets=n.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):n.forEach((e=>{const n=document.createElement("style"),o=t$3.litNonce;void 0!==o&&n.setAttribute("nonce",o),n.textContent=e.cssText,s.appendChild(n);}));},c$2=e$6?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$3(e)})(t):t; +const t$3=window,e$6=t$3.ShadowRoot&&(void 0===t$3.ShadyCSS||t$3.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s$4=Symbol(),n$4=new WeakMap;let o$5 = class o{constructor(t,e,n){if(this._$cssResult$=!0,n!==s$4)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e;}get styleSheet(){let t=this.o;const s=this.t;if(e$6&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=n$4.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&n$4.set(s,t));}return t}toString(){return this.cssText}};const r$3=t=>new o$5("string"==typeof t?t:t+"",void 0,s$4),S$2=(s,n)=>{e$6?s.adoptedStyleSheets=n.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):n.forEach((e=>{const n=document.createElement("style"),o=t$3.litNonce;void 0!==o&&n.setAttribute("nonce",o),n.textContent=e.cssText,s.appendChild(n);}));},c$2=e$6?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$3(e)})(t):t; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause - */var s$3;const e$5=window,r$2=e$5.trustedTypes,h$1=r$2?r$2.emptyScript:"",o$3=e$5.reactiveElementPolyfillSupport,n$3={toAttribute(t,i){switch(i){case Boolean:t=t?h$1:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,i){let s=t;switch(i){case Boolean:s=null!==t;break;case Number:s=null===t?null:Number(t);break;case Object:case Array:try{s=JSON.parse(t);}catch(t){s=null;}}return s}},a$2=(t,i)=>i!==t&&(i==i||t==t),l$3={attribute:!0,type:String,converter:n$3,reflect:!1,hasChanged:a$2},d$1="finalized";let u$1 = class u extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this.u();}static addInitializer(t){var i;this.finalize(),(null!==(i=this.h)&&void 0!==i?i:this.h=[]).push(t);}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((i,s)=>{const e=this._$Ep(s,i);void 0!==e&&(this._$Ev.set(e,s),t.push(e));})),t}static createProperty(t,i=l$3){if(i.state&&(i.attribute=!1),this.finalize(),this.elementProperties.set(t,i),!i.noAccessor&&!this.prototype.hasOwnProperty(t)){const s="symbol"==typeof t?Symbol():"__"+t,e=this.getPropertyDescriptor(t,s,i);void 0!==e&&Object.defineProperty(this.prototype,t,e);}}static getPropertyDescriptor(t,i,s){return {get(){return this[i]},set(e){const r=this[t];this[i]=e,this.requestUpdate(t,r,s);},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||l$3}static finalize(){if(this.hasOwnProperty(d$1))return !1;this[d$1]=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),void 0!==t.h&&(this.h=[...t.h]),this.elementProperties=new Map(t.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const t=this.properties,i=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const s of i)this.createProperty(s,t[s]);}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(i){const s=[];if(Array.isArray(i)){const e=new Set(i.flat(1/0).reverse());for(const i of e)s.unshift(c$2(i));}else void 0!==i&&s.push(c$2(i));return s}static _$Ep(t,i){const s=i.attribute;return !1===s?void 0:"string"==typeof s?s:"string"==typeof t?t.toLowerCase():void 0}u(){var t;this._$E_=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(t=this.constructor.h)||void 0===t||t.forEach((t=>t(this)));}addController(t){var i,s;(null!==(i=this._$ES)&&void 0!==i?i:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(s=t.hostConnected)||void 0===s||s.call(t));}removeController(t){var i;null===(i=this._$ES)||void 0===i||i.splice(this._$ES.indexOf(t)>>>0,1);}_$Eg(){this.constructor.elementProperties.forEach(((t,i)=>{this.hasOwnProperty(i)&&(this._$Ei.set(i,this[i]),delete this[i]);}));}createRenderRoot(){var t;const s=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return S$2(s,this.constructor.elementStyles),s}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostConnected)||void 0===i?void 0:i.call(t)}));}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$ES)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostDisconnected)||void 0===i?void 0:i.call(t)}));}attributeChangedCallback(t,i,s){this._$AK(t,s);}_$EO(t,i,s=l$3){var e;const r=this.constructor._$Ep(t,s);if(void 0!==r&&!0===s.reflect){const h=(void 0!==(null===(e=s.converter)||void 0===e?void 0:e.toAttribute)?s.converter:n$3).toAttribute(i,s.type);this._$El=t,null==h?this.removeAttribute(r):this.setAttribute(r,h),this._$El=null;}}_$AK(t,i){var s;const e=this.constructor,r=e._$Ev.get(t);if(void 0!==r&&this._$El!==r){const t=e.getPropertyOptions(r),h="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(s=t.converter)||void 0===s?void 0:s.fromAttribute)?t.converter:n$3;this._$El=r,this[r]=h.fromAttribute(i,t.type),this._$El=null;}}requestUpdate(t,i,s){let e=!0;void 0!==t&&(((s=s||this.constructor.getPropertyOptions(t)).hasChanged||a$2)(this[t],i)?(this._$AL.has(t)||this._$AL.set(t,i),!0===s.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,s))):e=!1),!this.isUpdatePending&&e&&(this._$E_=this._$Ej());}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Ei&&(this._$Ei.forEach(((t,i)=>this[i]=t)),this._$Ei=void 0);let i=!1;const s=this._$AL;try{i=this.shouldUpdate(s),i?(this.willUpdate(s),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostUpdate)||void 0===i?void 0:i.call(t)})),this.update(s)):this._$Ek();}catch(t){throw i=!1,this._$Ek(),t}i&&this._$AE(s);}willUpdate(t){}_$AE(t){var i;null===(i=this._$ES)||void 0===i||i.forEach((t=>{var i;return null===(i=t.hostUpdated)||void 0===i?void 0:i.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t);}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1;}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(t){return !0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,i)=>this._$EO(i,this[i],t))),this._$EC=void 0),this._$Ek();}updated(t){}firstUpdated(t){}};u$1[d$1]=!0,u$1.elementProperties=new Map,u$1.elementStyles=[],u$1.shadowRootOptions={mode:"open"},null==o$3||o$3({ReactiveElement:u$1}),(null!==(s$3=e$5.reactiveElementVersions)&&void 0!==s$3?s$3:e$5.reactiveElementVersions=[]).push("1.6.2"); + */var s$3;const e$5=window,r$2=e$5.trustedTypes,h$2=r$2?r$2.emptyScript:"",o$4=e$5.reactiveElementPolyfillSupport,n$3={toAttribute(t,i){switch(i){case Boolean:t=t?h$2:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,i){let s=t;switch(i){case Boolean:s=null!==t;break;case Number:s=null===t?null:Number(t);break;case Object:case Array:try{s=JSON.parse(t);}catch(t){s=null;}}return s}},a$2=(t,i)=>i!==t&&(i==i||t==t),l$3={attribute:!0,type:String,converter:n$3,reflect:!1,hasChanged:a$2},d$2="finalized";let u$2 = class u extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this.u();}static addInitializer(t){var i;this.finalize(),(null!==(i=this.h)&&void 0!==i?i:this.h=[]).push(t);}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((i,s)=>{const e=this._$Ep(s,i);void 0!==e&&(this._$Ev.set(e,s),t.push(e));})),t}static createProperty(t,i=l$3){if(i.state&&(i.attribute=!1),this.finalize(),this.elementProperties.set(t,i),!i.noAccessor&&!this.prototype.hasOwnProperty(t)){const s="symbol"==typeof t?Symbol():"__"+t,e=this.getPropertyDescriptor(t,s,i);void 0!==e&&Object.defineProperty(this.prototype,t,e);}}static getPropertyDescriptor(t,i,s){return {get(){return this[i]},set(e){const r=this[t];this[i]=e,this.requestUpdate(t,r,s);},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||l$3}static finalize(){if(this.hasOwnProperty(d$2))return !1;this[d$2]=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),void 0!==t.h&&(this.h=[...t.h]),this.elementProperties=new Map(t.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const t=this.properties,i=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const s of i)this.createProperty(s,t[s]);}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(i){const s=[];if(Array.isArray(i)){const e=new Set(i.flat(1/0).reverse());for(const i of e)s.unshift(c$2(i));}else void 0!==i&&s.push(c$2(i));return s}static _$Ep(t,i){const s=i.attribute;return !1===s?void 0:"string"==typeof s?s:"string"==typeof t?t.toLowerCase():void 0}u(){var t;this._$E_=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(t=this.constructor.h)||void 0===t||t.forEach((t=>t(this)));}addController(t){var i,s;(null!==(i=this._$ES)&&void 0!==i?i:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(s=t.hostConnected)||void 0===s||s.call(t));}removeController(t){var i;null===(i=this._$ES)||void 0===i||i.splice(this._$ES.indexOf(t)>>>0,1);}_$Eg(){this.constructor.elementProperties.forEach(((t,i)=>{this.hasOwnProperty(i)&&(this._$Ei.set(i,this[i]),delete this[i]);}));}createRenderRoot(){var t;const s=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return S$2(s,this.constructor.elementStyles),s}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostConnected)||void 0===i?void 0:i.call(t)}));}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$ES)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostDisconnected)||void 0===i?void 0:i.call(t)}));}attributeChangedCallback(t,i,s){this._$AK(t,s);}_$EO(t,i,s=l$3){var e;const r=this.constructor._$Ep(t,s);if(void 0!==r&&!0===s.reflect){const h=(void 0!==(null===(e=s.converter)||void 0===e?void 0:e.toAttribute)?s.converter:n$3).toAttribute(i,s.type);this._$El=t,null==h?this.removeAttribute(r):this.setAttribute(r,h),this._$El=null;}}_$AK(t,i){var s;const e=this.constructor,r=e._$Ev.get(t);if(void 0!==r&&this._$El!==r){const t=e.getPropertyOptions(r),h="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(s=t.converter)||void 0===s?void 0:s.fromAttribute)?t.converter:n$3;this._$El=r,this[r]=h.fromAttribute(i,t.type),this._$El=null;}}requestUpdate(t,i,s){let e=!0;void 0!==t&&(((s=s||this.constructor.getPropertyOptions(t)).hasChanged||a$2)(this[t],i)?(this._$AL.has(t)||this._$AL.set(t,i),!0===s.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,s))):e=!1),!this.isUpdatePending&&e&&(this._$E_=this._$Ej());}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Ei&&(this._$Ei.forEach(((t,i)=>this[i]=t)),this._$Ei=void 0);let i=!1;const s=this._$AL;try{i=this.shouldUpdate(s),i?(this.willUpdate(s),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var i;return null===(i=t.hostUpdate)||void 0===i?void 0:i.call(t)})),this.update(s)):this._$Ek();}catch(t){throw i=!1,this._$Ek(),t}i&&this._$AE(s);}willUpdate(t){}_$AE(t){var i;null===(i=this._$ES)||void 0===i||i.forEach((t=>{var i;return null===(i=t.hostUpdated)||void 0===i?void 0:i.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t);}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1;}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(t){return !0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,i)=>this._$EO(i,this[i],t))),this._$EC=void 0),this._$Ek();}updated(t){}firstUpdated(t){}};u$2[d$2]=!0,u$2.elementProperties=new Map,u$2.elementStyles=[],u$2.shadowRootOptions={mode:"open"},null==o$4||o$4({ReactiveElement:u$2}),(null!==(s$3=e$5.reactiveElementVersions)&&void 0!==s$3?s$3:e$5.reactiveElementVersions=[]).push("1.6.2"); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ -var t$2;const i$2=window,s$2=i$2.trustedTypes,e$4=s$2?s$2.createPolicy("lit-html",{createHTML:t=>t}):void 0,o$2="$lit$",n$2=`lit$${(Math.random()+"").slice(9)}$`,l$2="?"+n$2,h=`<${l$2}>`,r$1=document,d=()=>r$1.createComment(""),u=t=>null===t||"object"!=typeof t&&"function"!=typeof t,c$1=Array.isArray,v=t=>c$1(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]),a$1="[ \t\n\f\r]",f=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,_$1=/-->/g,m$1=/>/g,p=RegExp(`>|${a$1}(?:([^\\s"'>=/]+)(${a$1}*=${a$1}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),g$1=/'/g,$$1=/"/g,y=/^(?:script|style|textarea|title)$/i,w=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),x$1=w(1),T=Symbol.for("lit-noChange"),A=Symbol.for("lit-nothing"),E=new WeakMap,C$1=r$1.createTreeWalker(r$1,129,null,!1),P$1=(t,i)=>{const s=t.length-1,l=[];let r,d=2===i?"":"",u=f;for(let i=0;i"===c[0]?(u=null!=r?r:f,v=-1):void 0===c[1]?v=-2:(v=u.lastIndex-c[2].length,e=c[1],u=void 0===c[3]?p:'"'===c[3]?$$1:g$1):u===$$1||u===g$1?u=p:u===_$1||u===m$1?u=f:(u=p,r=void 0);const w=u===p&&t[i+1].startsWith("/>")?" ":"";d+=u===f?s+h:v>=0?(l.push(e),s.slice(0,v)+o$2+s.slice(v)+n$2+w):s+n$2+(-2===v?(l.push(void 0),i):w);}const c=d+(t[s]||"")+(2===i?"":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return [void 0!==e$4?e$4.createHTML(c):c,l]};class V{constructor({strings:t,_$litType$:i},e){let h;this.parts=[];let r=0,u=0;const c=t.length-1,v=this.parts,[a,f]=P$1(t,i);if(this.el=V.createElement(a,e),C$1.currentNode=this.el.content,2===i){const t=this.el.content,i=t.firstChild;i.remove(),t.append(...i.childNodes);}for(;null!==(h=C$1.nextNode())&&v.length0){h.textContent=s$2?s$2.emptyScript:"";for(let s=0;s2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=A;}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,i=this,s,e){const o=this.strings;let n=!1;if(void 0===o)t=N(this,t,i,0),n=!u(t)||t!==this._$AH&&t!==T,n&&(this._$AH=t);else {const e=t;let l,h;for(t=o[0],l=0;l{var e,o;const n=null!==(e=null==s?void 0:s.renderBefore)&&void 0!==e?e:i;let l=n._$litPart$;if(void 0===l){const t=null!==(o=null==s?void 0:s.renderBefore)&&void 0!==o?o:null;n._$litPart$=l=new M(i.insertBefore(d(),t),t,void 0,null!=s?s:{});}return l._$AI(t),l}; +var t$2;const i$2=window,s$2=i$2.trustedTypes,e$4=s$2?s$2.createPolicy("lit-html",{createHTML:t=>t}):void 0,o$3="$lit$",n$2=`lit$${(Math.random()+"").slice(9)}$`,l$2="?"+n$2,h$1=`<${l$2}>`,r$1=document,d$1=()=>r$1.createComment(""),u$1=t=>null===t||"object"!=typeof t&&"function"!=typeof t,c$1=Array.isArray,v$1=t=>c$1(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]),a$1="[ \t\n\f\r]",f$1=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,_$1=/-->/g,m$1=/>/g,p$1=RegExp(`>|${a$1}(?:([^\\s"'>=/]+)(${a$1}*=${a$1}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),g$1=/'/g,$$1=/"/g,y$1=/^(?:script|style|textarea|title)$/i,w$1=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),x$1=w$1(1),T$1=Symbol.for("lit-noChange"),A$1=Symbol.for("lit-nothing"),E$1=new WeakMap,C$1=r$1.createTreeWalker(r$1,129,null,!1),P$1=(t,i)=>{const s=t.length-1,l=[];let r,d=2===i?"":"",u=f$1;for(let i=0;i"===c[0]?(u=null!=r?r:f$1,v=-1):void 0===c[1]?v=-2:(v=u.lastIndex-c[2].length,e=c[1],u=void 0===c[3]?p$1:'"'===c[3]?$$1:g$1):u===$$1||u===g$1?u=p$1:u===_$1||u===m$1?u=f$1:(u=p$1,r=void 0);const w=u===p$1&&t[i+1].startsWith("/>")?" ":"";d+=u===f$1?s+h$1:v>=0?(l.push(e),s.slice(0,v)+o$3+s.slice(v)+n$2+w):s+n$2+(-2===v?(l.push(void 0),i):w);}const c=d+(t[s]||"")+(2===i?"":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return [void 0!==e$4?e$4.createHTML(c):c,l]};let V$1 = class V{constructor({strings:t,_$litType$:i},e){let h;this.parts=[];let r=0,u=0;const c=t.length-1,v=this.parts,[a,f]=P$1(t,i);if(this.el=V.createElement(a,e),C$1.currentNode=this.el.content,2===i){const t=this.el.content,i=t.firstChild;i.remove(),t.append(...i.childNodes);}for(;null!==(h=C$1.nextNode())&&v.length0){h.textContent=s$2?s$2.emptyScript:"";for(let s=0;s2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=A$1;}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,i=this,s,e){const o=this.strings;let n=!1;if(void 0===o)t=N$1(this,t,i,0),n=!u$1(t)||t!==this._$AH&&t!==T$1,n&&(this._$AH=t);else {const e=t;let l,h;for(t=o[0],l=0;l{var e,o;const n=null!==(e=null==s?void 0:s.renderBefore)&&void 0!==e?e:i;let l=n._$litPart$;if(void 0===l){const t=null!==(o=null==s?void 0:s.renderBefore)&&void 0!==o?o:null;n._$litPart$=l=new M$1(i.insertBefore(d$1(),t),t,void 0,null!=s?s:{});}return l._$AI(t),l}; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause - */var l$1,o$1;let s$1 = class s extends u$1{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0;}createRenderRoot(){var t,e;const i=super.createRenderRoot();return null!==(t=(e=this.renderOptions).renderBefore)&&void 0!==t||(e.renderBefore=i.firstChild),i}update(t){const i=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=B(i,this.renderRoot,this.renderOptions);}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!0);}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!1);}render(){return T}};s$1.finalized=!0,s$1._$litElement$=!0,null===(l$1=globalThis.litElementHydrateSupport)||void 0===l$1||l$1.call(globalThis,{LitElement:s$1});const n$1=globalThis.litElementPolyfillSupport;null==n$1||n$1({LitElement:s$1});(null!==(o$1=globalThis.litElementVersions)&&void 0!==o$1?o$1:globalThis.litElementVersions=[]).push("3.3.2"); + */var l$1,o$2;let s$1 = class s extends u$2{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0;}createRenderRoot(){var t,e;const i=super.createRenderRoot();return null!==(t=(e=this.renderOptions).renderBefore)&&void 0!==t||(e.renderBefore=i.firstChild),i}update(t){const i=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=B$1(i,this.renderRoot,this.renderOptions);}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!0);}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!1);}render(){return T$1}};s$1.finalized=!0,s$1._$litElement$=!0,null===(l$1=globalThis.litElementHydrateSupport)||void 0===l$1||l$1.call(globalThis,{LitElement:s$1});const n$1=globalThis.litElementPolyfillSupport;null==n$1||n$1({LitElement:s$1});(null!==(o$2=globalThis.litElementVersions)&&void 0!==o$2?o$2:globalThis.litElementVersions=[]).push("3.3.2"); /*! * Bootstrap v5.3.0 (https://getbootstrap.com/) @@ -4770,7 +4770,7 @@ const t$1={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6} * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause - */let e$2 = class e extends i$1{constructor(i){if(super(i),this.et=A,i.type!==t$1.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(r){if(r===A||null==r)return this.ft=void 0,this.et=r;if(r===T)return r;if("string"!=typeof r)throw Error(this.constructor.directiveName+"() called with a non-string value");if(r===this.et)return this.ft;this.et=r;const s=[r];return s.raw=s,this.ft={_$litType$:this.constructor.resultType,strings:s,values:[]}}};e$2.directiveName="unsafeHTML",e$2.resultType=1;const o=e$3(e$2); + */let e$2 = class e extends i$1{constructor(i){if(super(i),this.et=A$1,i.type!==t$1.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(r){if(r===A$1||null==r)return this.ft=void 0,this.et=r;if(r===T$1)return r;if("string"!=typeof r)throw Error(this.constructor.directiveName+"() called with a non-string value");if(r===this.et)return this.ft;this.et=r;const s=[r];return s.raw=s,this.ft={_$litType$:this.constructor.resultType,strings:s,values:[]}}};e$2.directiveName="unsafeHTML",e$2.resultType=1;const o$1=e$3(e$2); class ResultsContainer extends s$1 { static properties = { @@ -4858,8 +4858,8 @@ class ResultsContainer extends s$1 {

Lexicon results:

- ${o(this._data.lexicon.lines)} -

${o(this._data.lexicon.global)}

+ ${o$1(this._data.lexicon.lines)} +

${o$1(this._data.lexicon.global)}

${imagesContainer} @@ -4896,13 +4896,13 @@ class ErrHandler extends s$1 { add = (content) => { const msg = (content.message !== null) ? content.message : content.msg; this.msg +=`
${msg}`; - this._content = x$1`

${o(this.msg)}

`; + this._content = x$1`

${o$1(this.msg)}

`; this.visible = true; } set = (content) => { this.msg = (content.message !== null) ? content.message : content.msg; - this._content = x$1`

${o(this.msg)}

`; + this._content = x$1`

${o$1(this.msg)}

`; this.visible = true; console.error(this.msg); } @@ -4962,10 +4962,10 @@ class TextInput extends s$1 { render() { return x$1`
- ${this.showLabel ? x$1`${this.label}` : A} + ${this.showLabel ? x$1`${this.label}` : A$1}
@@ -5139,7 +5139,7 @@ class ColorInput extends s$1 { render() { return x$1`
- ${this.showLabel ? x$1`${this.label}` : A} + ${this.showLabel ? x$1`${this.label}` : A$1} ` : A} + @change="${this.onChange}">` : A$1}
`; } @@ -5278,7 +5278,7 @@ class DropDownList extends s$1 {
@@ -5315,7 +5315,7 @@ class TextArea extends s$1 { render() { return x$1`
- ${o(this.label)} + ${o$1(this.label)}
@@ -5847,7 +5847,7 @@ class Header extends s$1 { }}"> -
`: A} +
`: A$1}
`; @@ -5861,7 +5861,7 @@ class Header extends s$1 { customElements.define('header-section', Header); -const t=(t,e,r,l,n)=>l+(t-e)/(r-e)*(n-l),e$1=(t,e,r)=>Math.min(r,Math.max(e,t)),r=t=>t.reduce(((t,e)=>t+e),0)/t.length||0,l=t=>t.reduce(((t,e)=>t+e),0),n=t=>Math.max(...t),a=t=>Math.min(...t),s=t=>{if(t.levels)return {r:parseInt(t.levels[0]),g:parseInt(t.levels[1]),b:parseInt(t.levels[2])};let e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null},i=(t,e)=>Math.sqrt(Math.pow(t.r-e.r,2)+Math.pow(t.g-e.g,2)+Math.pow(t.b-e.b,2)),c={MIN_RANGE:50,THRESHOLD_VALID:.2,MODES:["DIF","MIN"]},g={VISUAL_CENTER_FT:20,MODES:["CENTER","LEFT-CENTER","RIGHT-CENTER","LEFT-TOP","RIGHT-TOP","LEFT-BOTTOM","RIGHT-BOTTOM"]};const _={MODES:["RELATIVE","FIXED"]}.MODES;let m=c.MIN_RANGE,R=c.THRESHOLD_VALID,S=c.MODES;const x=(e,r)=>{const l=r.filter(((t,e,r)=>r.indexOf(t)===e)),n=[];for(let t of l)for(let l=0;ln.indexOf(t)!==e));let o=1;if(!a.length>=1){let a=0;for(let t in r){let o=r[t],s=e[t],i=l.indexOf(o);s!==n[i]&&a++;}o=t(a,0,e.length,0,1);}return o},F=(l,o,s="DIF")=>{S.includes(s)||(s="DIF");const i=n(l),f=a(l);let h=Math.abs(i-f);if(h{let l=t(r,c,u,0,h);return l=e$1(l,0,h),l})),d=[];for(let t in l){let e=l[t],r=Math.abs(e-p),n=Math.abs(r-g[t]);d.push(n);}let E=t(r(d),0,h,1,0);return e$1(E,0,1)};var L={anger:{color:{typography:["#ff0000","#00ff00"],background:["#ff0000"]},typefaces:["sans-serif","neo-grotesque"]},joy:{color:{typography:[],background:["#ffff00","#00ff00"]},typefaces:["sans-serif","serif"]},trust:{color:{typography:[],background:["#0000ff","#00ff00"]},typefaces:["neo-grotesque"]},sadness:{color:{typography:[],background:["#0071b6"]},typefaces:[]},disgust:{color:{typography:["#800080"],background:[]},typefaces:[]}},D=Object.freeze({__proto__:null,default:L});const C=441.67,Y=g.VISUAL_CENTER_FT,P=g.MODES,k=(t,e,r,n)=>{const a=[];for(let e in n)a.push(U(t,r[e],n[e]));let o=0,s=0;const i=l(e);for(let t in e)o+=a[t].x*e[t],s+=a[t].y*e[t];return o/=i,s/=i,{x:o,y:s}},U=(t,e,r,l=[0,0,0,0])=>{const n=(t=String(t)).includes("LEFT")?1:t.includes("RIGHT")?2:0,a=t.includes("TOP")?1:t.includes("BOTTOM")?2:0;return {x:0===n?e/2:1===n?e*l[0]:e*(1-l[2]),y:0===a?r/2-r/Y:1===a?r*l[1]:r-r*l[3]}},$=async(t,e,r,l)=>{let n=[],a=[];for(let o in r){n.push(r[o]*l[o]);const s=await t.get(0,t.height/2+e.center[o],t.width,e.l[o]);await s.loadPixels();let i=0,f=0,h=0;const u=s.pixels.length/4;for(let t=0;tt*a[e]))},J=(t=[],e=null,n="RELATIVE",a={height:100,margin:[0,0,0,0]})=>{_.includes(n)||(n="RELATIVE");let o=0;"RELATIVE"===n?o=l(t):"FIXED"===n&&(o=a.height-(a.height*a.margin[1]+a.height*a.margin[3]));const s=t.map((t=>t/o));let i=[];for(let t in e){const r=Math.abs(e[t][3]-s[t]);i.push(r);}return 1-r(i)},q=(t,e,r=1,a=!0,o=[.4,.3,.3])=>{const s=e.map((t=>t[3]));let i,f=[F(t.map((t=>t.weight)),s),F(t.map((t=>t["font-stretch"])),s),r>1?x(t.map((t=>t["font-stretch"])),s):0],h=f.map(((t,e)=>t*o[e]));if(a)i=l(h);else {let t=f.map((t=>t>R)),e=0;for(let r of t)r&&e++;i=n(f)/e;}return i},j=async(t,l,n,a,o=D)=>{let f=t.predominant.emotion;if(void 0===o.default[f])return 1;const h=o.default[f].color.typography,u=o.default[f].color.background,c=o.default[f].typefaces;let p=1;if(void 0!==h&&h.length>0){let t=[];for(let e of l){let r=s(e.color),l=Number.MAX_VALUE;for(let t of h){t=s(t);let e=i(r,t);e0){let t=[];for(let e of l){let r=0;const l=a.map((t=>t.family)).indexOf(e.typeface),n=a[l].tags;for(let t of c)n.includes(t)&&(r+=1/c.length);t.push(r);}d=t.length<1?1:r(t),d=e$1(d,0,1);}return (p+g+d)/3},Z=async(t=null,r,l,n,a,o="CENTER",s=null)=>{const i=r.width,f=r.height;P.includes(o)||(o="CENTER");const h=null===s?await $(t,l,n,a):s,u=k(o,h,n,a);let c=U(o,i,f,r.margin),p=Math.pow((u.x-c.x)/i,2)+Math.pow((u.y-c.y)/f,2);return p=1-Math.pow(Math.abs(p/2),.5),e$1(p,0,1)}; +const t=(t,e,r,l,n)=>l+(t-e)/(r-e)*(n-l),e$1=(t,e,r)=>Math.min(r,Math.max(e,t)),r=t=>t.reduce(((t,e)=>t+e),0)/t.length||0,l=t=>t.reduce(((t,e)=>t+e),0),n=t=>Math.max(...t),a=t=>Math.min(...t),o=t=>t.filter(((t,e,r)=>r.indexOf(t)===e)),s=t=>{if(t.levels)return {r:parseInt(t.levels[0]),g:parseInt(t.levels[1]),b:parseInt(t.levels[2])};let e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null},i=(t,e)=>Math.sqrt(Math.pow(t.r-e.r,2)+Math.pow(t.g-e.g,2)+Math.pow(t.b-e.b,2)),f=10,h=[.8,.2],u={MAX_CONSTRAINT:1,WHITE_SPACE_FACTOR:3,MODES:["OVERSET","JUSTIFY","ATTEMPT_JUSTIFY"],DEFAULT_MAX_LIMIT_SCALE:1},c={MIN_RANGE:50,THRESHOLD_VALID:.2,MODES:["DIF","MIN"]},p={MODES:["BOTH","TYPE_FAMILY","CATEGORY"]},g={VISUAL_CENTER_FT:20,MODES:["CENTER","LEFT-CENTER","RIGHT-CENTER","LEFT-TOP","RIGHT-TOP","LEFT-BOTTOM","RIGHT-BOTTOM"]},d=.5,E=10;const T=u.MAX_CONSTRAINT,M=u.WHITE_SPACE_FACTOR,I=u.DEFAULT_MAX_LIMIT_SCALE,O=u.MODES,A=(e,r)=>t(e=(e=e>=0?0:e)<=-r?-r:e,-r,0,T,0),b=(e,r)=>(e=Math.abs(e),t(e=e>r?r:e,r,0,T,0)),y=(t,e)=>b(t=t>=0?t/M:t,e),_={MODES:["RELATIVE","FIXED"]}.MODES;let m=c.MIN_RANGE,R=c.THRESHOLD_VALID,S=c.MODES;const x=(e,r)=>{const l=r.filter(((t,e,r)=>r.indexOf(t)===e)),n=[];for(let t of l)for(let l=0;ln.indexOf(t)!==e));let o=1;if(!a.length>=1){let a=0;for(let t in r){let o=r[t],s=e[t],i=l.indexOf(o);s!==n[i]&&a++;}o=t(a,0,e.length,0,1);}return o},F=(l,o,s="DIF")=>{S.includes(s)||(s="DIF");const i=n(l),f=a(l);let h=Math.abs(i-f);if(h{let l=t(r,c,u,0,h);return l=e$1(l,0,h),l})),d=[];for(let t in l){let e=l[t],r=Math.abs(e-p),n=Math.abs(r-g[t]);d.push(n);}let E=t(r(d),0,h,1,0);return e$1(E,0,1)};var L={anger:{color:{typography:["#ff0000","#00ff00"],background:["#ff0000"]},typefaces:["sans-serif","neo-grotesque"]},joy:{color:{typography:[],background:["#ffff00","#00ff00"]},typefaces:["sans-serif","serif"]},trust:{color:{typography:[],background:["#0000ff","#00ff00"]},typefaces:["neo-grotesque"]},sadness:{color:{typography:[],background:["#0071b6"]},typefaces:[]},disgust:{color:{typography:["#800080"],background:[]},typefaces:[]}},D=Object.freeze({__proto__:null,default:L});const C=441.67,N=f,w=h,v=d,G=E,H=(t,e,r=1)=>{let l=0,n=t.width*r*t.height*r;t.loadPixels();for(let r=0;r<4*n;r+=4){let n={r:t.pixels[r],g:t.pixels[r+1],b:t.pixels[r+2]};i(n,e){const a=[];for(let e in n)a.push(U(t,r[e],n[e]));let o=0,s=0;const i=l(e);for(let t in e)o+=a[t].x*e[t],s+=a[t].y*e[t];return o/=i,s/=i,{x:o,y:s}},U=(t,e,r,l=[0,0,0,0])=>{const n=(t=String(t)).includes("LEFT")?1:t.includes("RIGHT")?2:0,a=t.includes("TOP")?1:t.includes("BOTTOM")?2:0;return {x:0===n?e/2:1===n?e*l[0]:e*(1-l[2]),y:0===a?r/2-r/Y:1===a?r*l[1]:r-r*l[3]}},$=async(t,e,r,l)=>{let n=[],a=[];for(let o in r){n.push(r[o]*l[o]);const s=await t.get(0,t.height/2+e.center[o],t.width,e.l[o]);await s.loadPixels();let i=0,f=0,h=0;const u=s.pixels.length/4;for(let t=0;tt*a[e]))},X=(t=[],e,l="OVERSET",n=I)=>{O.includes(l)||(l="OVERSET");let a=[],o=e*n;for(let r of t){let t=e-r,n=T;switch(l){case"JUSTIFY":n=b(t,o);break;case"ATTEMPT_JUSTIFY":n=y(t,o);break;default:n=A(t,o);}a.push(n);}return r([...a])},B=(t,e,r=[],l=[],n={left:0,top:0,right:0,bottom:0})=>{let a=!1,o="",s=Math.abs(n.top)+Math.abs(n.bottom);for(let t of r)s+=parseFloat(t);let i=Math.abs(n.left)+Math.abs(n.right);for(let t of l)i+=parseFloat(t);return i=Math.round(i),s=Math.round(s),s>e?(a=!0,o+=`Grid height is bigger than container (grid:${s}, container:${e}). `):st?(a=!0,o+=`Grid width is bigger than container (grid:${i}, container:${t}). `):i{_.includes(n)||(n="RELATIVE");let o=0;"RELATIVE"===n?o=l(t):"FIXED"===n&&(o=a.height-(a.height*a.margin[1]+a.height*a.margin[3]));const s=t.map((t=>t/o));let i=[];for(let t in e){const r=Math.abs(e[t][3]-s[t]);i.push(r);}return 1-r(i)},q=(t,e,r=1,a=!0,o=[.4,.3,.3])=>{const s=e.map((t=>t[3]));let i,f=[F(t.map((t=>t.weight)),s),F(t.map((t=>t["font-stretch"])),s),r>1?x(t.map((t=>t["font-stretch"])),s):0],h=f.map(((t,e)=>t*o[e]));if(a)i=l(h);else {let t=f.map((t=>t>R)),e=0;for(let r of t)r&&e++;i=n(f)/e;}return i},j=async(t,l,n,a,o=D)=>{let f=t.predominant.emotion;if(void 0===o.default[f])return 1;const h=o.default[f].color.typography,u=o.default[f].color.background,c=o.default[f].typefaces;let p=1;if(void 0!==h&&h.length>0){let t=[];for(let e of l){let r=s(e.color),l=Number.MAX_VALUE;for(let t of h){t=s(t);let e=i(r,t);e0){let t=[];for(let e of l){let r=0;const l=a.map((t=>t.family)).indexOf(e.typeface),n=a[l].tags;for(let t of c)n.includes(t)&&(r+=1/c.length);t.push(r);}d=t.length<1?1:r(t),d=e$1(d,0,1);}return (p+g+d)/3},W=(t,e,l=w)=>{if(t.length<2)return 1;let n=t,a=[];for(let t=0;tt.reduce(((t,r,l)=>t+r*e[l]),0))([r(a),1/o(e).length],l);return s},z=t=>{if(t.length<2)return 1;const e=t;let l=[];for(let t=0;t{null===r&&(e=s(e),r=H(t,e,t.pixelDensity()));return 1-4*Math.pow(r-l,2)},Q=(t,e,r="BOTH")=>{V.includes(r)||(r="BOTH");let l=[.5,.5];"TYPE_FAMILY"===r?l=[1,0]:"CATEGORY"===r&&(l=[0,1]);let n=[],a=o(t),s=0,i=0;if("TYPE_FAMILY"!==r){const t=e.map((t=>t.family)),r=e.map((t=>t.category));for(let e of a){const l=t.indexOf(e);-1===l?n.push("undefined"):n.push(r[l]);}n=o(n),s=1/n.length;}"CATEGORY"!==r&&(i=1/a.length);return [i,s].reduce(((t,e,r)=>t+e*l[r]),0)},Z=async(t=null,r,l,n,a,o="CENTER",s=null)=>{const i=r.width,f=r.height;P.includes(o)||(o="CENTER");const h=null===s?await $(t,l,n,a):s,u=k(o,h,n,a);let c=U(o,i,f,r.margin),p=Math.pow((u.x-c.x)/i,2)+Math.pow((u.y-c.y)/f,2);return p=1-Math.pow(Math.abs(p/2),.5),e$1(p,0,1)}; var backgroundStyles = { solid: (pg, color) => { @@ -6543,11 +6543,31 @@ class Poster { this.constraint = 0; this.metrics = { - legibility: 1, - gridAppropriateness: 1 + constraints: { + legibility: 0, + gridAppropriateness: 0, + general: 0 + }, + aesthetics: { + alignment: 0, + regularity: 0, + justification: 0, + typefaceParing: 0, + whiteSpace: 0, + balance: 0, + general: 0, + weights: 0 + }, + semantics: { + emphasis: 0, + layout: 0, + visuals: 0, + general: 0, + weights: [0,0,0] + } }; - this.sentencesLength = []; + this.sentencesLength = []; const h = (genotype === null) ? params["size"]["height"] : genotype["size"]["height"]; this.maxFontSize = Params.typography.maxSize * h; @@ -6557,7 +6577,6 @@ class Poster { this.#showGrid = params !== null ? params.display.grid : false; this.phenotype = null; - // this.evaluate(); } copy = () => { @@ -6623,7 +6642,7 @@ class Poster { JSON.parse(JSON.stringify(params.size.margin)) ); - // define texboxes + // define textboxes const textboxes = []; const alignment = params.typography.verticalAlignment === 0 ? @@ -6674,7 +6693,6 @@ class Poster { } const images = []; - // console.log(`params.images`, params.images); for (let input of params.images) { const src = input.src; const img = loadImage(src, async (img) => { @@ -6690,7 +6708,6 @@ class Poster { }); } - // create genotype return { grid: grid, @@ -6753,11 +6770,6 @@ class Poster { let semantics = 0; // semantic part of fitness let aesthetics = 0; // aesthetics part of fitness - //const ls = layoutSemantics(this.genotype["grid"]["rows"]["l"], dist, `FIXED`, this.genotype["size"]); - // const semanticsEmphasis = evaluator.semanticsEmphasis(this.genotype["textboxes"], dist, noCurrentTypefaces); - // const justification = evaluator.legibility(this.sentencesLength, this.genotype["grid"].getAvailableWidth(), `JUSTIFY`); - // const visualSemantics = evaluator.semanticsVisuals(emotionalData, this.genotype["textboxes"], this.genotype.background.colors, this.params.typography.typefaces); - if (weights[0] > 0) { const semanticsWeights = this.params["evaluation"]["semanticsWeights"]; const emphasis = (semanticsWeights[0] > 0) ? q(this.genotype["textboxes"], dist, noCurrentTypefaces) : 0; @@ -6765,57 +6777,55 @@ class Poster { const layout = (semanticsWeights[1] > 0) ? J(this.genotype["grid"]["rows"]["l"], dist, layoutMode, this.genotype["size"]) : 0; const visuals = (semanticsWeights[2] > 0) ? await j(emotionalData, this.genotype["textboxes"], this.genotype.background.colors, this.params.typography.typefaces) : 0; semantics = sumProduct( [emphasis, layout, visuals], semanticsWeights); - } + // save info + this.metrics["semantics"]["emphasis"] = emphasis; + this.metrics["semantics"]["layout"] = layout; + this.metrics["semantics"]["visuals"] = visuals; + this.metrics["semantics"]["general"] = semantics; + this.metrics["semantics"]["weights"] = semanticsWeights; + } - // semantics - // const ls = layoutSemantics(this.genotype["grid"]["rows"]["l"], dist, `FIXED`, this.genotype["size"]); - // const semanticsEmphasis = evaluator.semanticsEmphasis(this.genotype["textboxes"], dist, noCurrentTypefaces); - // const justification = evaluator.legibility(this.sentencesLength, this.genotype["grid"].getAvailableWidth(), `JUSTIFY`); - // const visualSemantics = evaluator.semanticsVisuals(emotionalData, this.genotype["textboxes"], this.genotype.background.colors, this.params.typography.typefaces); - - // const alignment = evaluator.alignment(this.sentencesLength, this.genotype["textboxes"].map(tb => tb["alignment"])); - // const regularity = evaluator.regularity(this.genotype["grid"]["rows"]["l"]); - - // textboxes have the same typography colour - // const whiteSpace = evaluator.whiteSpaceFraction(this.phenotype, this.genotype["textboxes"][0]["color"]); - //const typefaceParing = evaluator.typefaceParing(this.genotype["textboxes"].map(gene => gene["typeface"]), this.params["typography"]["typefaces"]) - let balanceMode = this.genotype["textboxes"][0]["alignment"] === 0 ? `LEFT` : this.genotype["textboxes"][0]["alignment"] === 1 ? `CENTER` : `RIGHT`; - balanceMode += this.genotype["typography"]["verticalAlignment"] === 0 ? `-TOP` : this.genotype["typography"]["verticalAlignment"] === 1 ? `-CENTER` : `-BOTTOM`; - - const balance = await Z( - this.phenotype, - this.genotype["size"], - this.genotype["grid"]["rows"], - this.genotype["textboxes"].map(tb => tb.size), - this.sentencesLength, - balanceMode - ); - console.log (`balance=${balance}`); + if (weights[1] > 0) { + const aestheticsWeights = this.params["evaluation"]["aestheticsWeights"]; + const alignment = (aestheticsWeights[0] > 0) ? W(this.sentencesLength, this.genotype["textboxes"].map(tb => tb["alignment"])) : 0; + const regularity = (aestheticsWeights[1] > 0) ? z(this.genotype["grid"]["rows"]["l"]) : 0; + const justification = (aestheticsWeights[2] > 0) ? X(this.sentencesLength, this.genotype["grid"].getAvailableWidth(), `JUSTIFY`) : 0; + const typefaceParing = (aestheticsWeights[3] > 0) ? Q(this.genotype["textboxes"].map(gene => gene["typeface"]), this.params["typography"]["typefaces"]) : 0; + const whiteSpace = (aestheticsWeights[4] > 0) ? K(this.phenotype, this.genotype["textboxes"][0]["color"]) : 0; + let balanceMode = this.genotype["textboxes"][0]["alignment"] === 0 ? `LEFT` : this.genotype["textboxes"][0]["alignment"] === 1 ? `CENTER` : `RIGHT`; + balanceMode += this.genotype["typography"]["verticalAlignment"] === 0 ? `-TOP` : this.genotype["typography"]["verticalAlignment"] === 1 ? `-CENTER` : `-BOTTOM`; + const balance = (aestheticsWeights[5] > 0) ? await Z(this.phenotype, this.genotype["size"], this.genotype["grid"]["rows"], this.genotype["textboxes"].map(tb => tb.size), this.sentencesLength, balanceMode) : 0; + aesthetics = sumProduct([alignment, regularity, justification, typefaceParing, whiteSpace, balance], aestheticsWeights); - // this.fitness = layoutSemantics; - // this.fitness = (visualSemantics * 0.3 + layoutSemantics * 0.3 + justification * 0.4); + // save info + this.metrics["aesthetics"]["alignment"] = alignment; + this.metrics["aesthetics"]["regularity"] = regularity; + this.metrics["aesthetics"]["justification"] = justification; + this.metrics["aesthetics"]["typefaceParing"] = typefaceParing; + this.metrics["aesthetics"]["whiteSpace"] = whiteSpace; + this.metrics["aesthetics"]["balance"] = balance; + this.metrics["aesthetics"]["general"] = aesthetics; + this.metrics["aesthetics"]["weights"] = aestheticsWeights; + } // constraints - // const legibility = evaluator.legibility(this.sentencesLength, this.genotype["grid"].getAvailableWidth(), `OVERSET`); - /*const gridAppropriateness = evaluator.gridAppropriateSize( + const legibility = X(this.sentencesLength, this.genotype["grid"].getAvailableWidth(), `OVERSET`); + const gridAppropriateness = B( this.genotype["size"].width, this.genotype["size"].height, this.genotype["grid"].rows.l, this.genotype["grid"].columns.l, this.genotype["grid"].marginsPos ); - this.constraint = legibility + gridAppropriateness;*/ - - // this.metrics["legibility"] = legibility; - // this.metrics["gridAppropriateness"] = gridAppropriateness; this.fitness = sumProduct([semantics, aesthetics], weights); - console.log (`fitness=${this.fitness} (semantics=${semantics}, aesthetics=${aesthetics})`); - this.constraint = 1; + this.constraint = legibility + gridAppropriateness; + + this.metrics["constraints"]["legibility"] = legibility; + this.metrics["constraints"]["gridAppropriateness"] = gridAppropriateness; + this.metrics["constraints"]["general"] = this.constraint; - // returns a number between 0 and 0.5 - // subtracted to fitness return { "fitness": this.fitness, "constraints": this.constraint @@ -7646,9 +7656,6 @@ class Population { #staticPenalty = async () => { this.population = this.population.sort((a,b) => (b.fitness-b.constraint) - (a.fitness-a.constraint)); - // debug - // best individual fitness - // console.log ("best individual=", this.population[0].fitness, this.population[0].constraint); } copy = (obj) => { @@ -8073,14 +8080,14 @@ class App extends s$1 { return x$1` ${this.errorMessage} ${this.header} - ${this.screen === 3 ? this.initPopForm : A} + ${this.screen === 3 ? this.initPopForm : A$1} ${this.screen < 2 ? x$1`
${this.resultsContainer} ${this.inputForm} - ${this.screen === 1 ? this.#nextBts() : A} + ${this.screen === 1 ? this.#nextBts() : A$1}
` : - A } + A$1 } `; }