social-graphics-library
Advanced tools
Comparing version 2.1.2 to 2.1.3
@@ -16,4 +16,13 @@ import { TemplateInjector } from "./templateInjector.js"; | ||
static run(teamName: string, playerName: string, mode: string, containerId: string, imgMode: string, templateInjector: TemplateInjector, generateLink?: boolean): void; | ||
/** | ||
* Gets image data url | ||
* @param teamName | ||
* @param playerName | ||
* @param mode | ||
* @param imgMode | ||
* @param templateInjector | ||
* @returns image data url | ||
*/ | ||
static getImageDataUrl(teamName: string, playerName: string, mode: string, imgMode: string, templateInjector: TemplateInjector): Promise<string>; | ||
} | ||
//# sourceMappingURL=generator.d.ts.map |
@@ -66,2 +66,11 @@ import { False_Template } from "../template/false.template.js"; | ||
} | ||
/** | ||
* Gets image data url | ||
* @param teamName | ||
* @param playerName | ||
* @param mode | ||
* @param imgMode | ||
* @param templateInjector | ||
* @returns image data url | ||
*/ | ||
static async getImageDataUrl(teamName, playerName, mode, imgMode, templateInjector) { | ||
@@ -68,0 +77,0 @@ let svgString, width, height, tempTemplate; |
@@ -5,3 +5,9 @@ /** | ||
export declare class Guid { | ||
/** | ||
* Guid of guid | ||
*/ | ||
private guid; | ||
/** | ||
* Creates an instance of guid. | ||
*/ | ||
constructor(); | ||
@@ -13,4 +19,8 @@ /** | ||
private static newGuid; | ||
/** | ||
* To string | ||
* @returns | ||
*/ | ||
toString(): string; | ||
} | ||
//# sourceMappingURL=guid.d.ts.map |
@@ -5,3 +5,9 @@ /** | ||
export class Guid { | ||
/** | ||
* Guid of guid | ||
*/ | ||
guid; | ||
/** | ||
* Creates an instance of guid. | ||
*/ | ||
constructor() { | ||
@@ -15,7 +21,11 @@ this.guid = Guid.newGuid(); | ||
static newGuid() { | ||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { | ||
const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8); | ||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) { | ||
const r = (Math.random() * 16) | 0, v = c === "x" ? r : (r & 0x3) | 0x8; | ||
return v.toString(16); | ||
}); | ||
} | ||
/** | ||
* To string | ||
* @returns | ||
*/ | ||
toString() { | ||
@@ -22,0 +32,0 @@ return this.guid; |
@@ -18,46 +18,50 @@ import { False_Template } from "../template/false.template.js"; | ||
static renderImage(svgString, width, height, containerId, imgMode, generateLink) { | ||
const xml = svgString, parser = new DOMParser(), result = parser.parseFromString(xml, 'text/xml'), inlineSVG = result.getElementsByTagName('svg')[0]; | ||
inlineSVG.setAttribute('width', width.toString()); | ||
inlineSVG.setAttribute('height', height.toString()); | ||
let data = "data:image/svg+xml;charset=utf-8;base64, " + window.btoa(new XMLSerializer().serializeToString(inlineSVG)), img = new Image(), img2 = new Image(), canvas = document.createElement('canvas'), imgAtr, container = document.getElementById(containerId); | ||
const xml = svgString, parser = new DOMParser(), result = parser.parseFromString(xml, "text/xml"), inlineSVG = (result.getElementsByTagName("svg")[0]); | ||
inlineSVG.setAttribute("width", width.toString()); | ||
inlineSVG.setAttribute("height", height.toString()); | ||
const img = new Image(), img2 = new Image(), canvas = document.createElement("canvas"), container = document.getElementById(containerId); | ||
let imgAtr, data = "data:image/svg+xml;charset=utf-8;base64, " + | ||
window.btoa(new XMLSerializer().serializeToString(inlineSVG)); | ||
switch (imgMode) { | ||
case 'svg': | ||
case "svg": | ||
width = width / 4; | ||
height = height / 4; | ||
img.setAttribute('src', data); | ||
img.setAttribute('width', width.toString()); | ||
img.setAttribute('height', height.toString()); | ||
img.setAttribute("src", data); | ||
img.setAttribute("width", width.toString()); | ||
img.setAttribute("height", height.toString()); | ||
container.innerHTML = ""; | ||
container.appendChild(img); | ||
if (generateLink) { | ||
const downloadLink = document.createElement('a'); | ||
downloadLink.setAttribute('href', data); | ||
downloadLink.setAttribute('download', 'image.' + imgMode); | ||
downloadLink.innerHTML = 'Download Link'; | ||
const downloadLink = document.createElement("a"); | ||
downloadLink.setAttribute("href", data); | ||
downloadLink.setAttribute("download", "image." + imgMode); | ||
downloadLink.innerHTML = "Download Link"; | ||
container.appendChild(downloadLink); | ||
} | ||
return; | ||
case 'png': | ||
imgAtr = 'image/png'; | ||
case "png": | ||
imgAtr = "image/png"; | ||
break; | ||
case 'jpeg': | ||
imgAtr = 'image/jpeg'; | ||
case "jpeg": | ||
imgAtr = "image/jpeg"; | ||
break; | ||
case 'webp': | ||
imgAtr = 'image/webp'; | ||
case "webp": | ||
imgAtr = "image/webp"; | ||
break; | ||
default: | ||
data = "data:image/svg+xml;charset=utf-8;base64, " + window.btoa(False_Template.template()); | ||
data = | ||
"data:image/svg+xml;charset=utf-8;base64, " + | ||
window.btoa(False_Template.template()); | ||
width = False_Template.width; | ||
height = False_Template.height; | ||
imgAtr = 'image/png'; | ||
imgAtr = "image/png"; | ||
break; | ||
} | ||
canvas.setAttribute('width', width.toString()); | ||
canvas.setAttribute('height', height.toString()); | ||
canvas.setAttribute('id', 'render-canvas' + containerId); | ||
canvas.setAttribute('display', 'none'); | ||
img.setAttribute('src', data); | ||
img.setAttribute('width', width.toString()); | ||
img.setAttribute('height', height.toString()); | ||
canvas.setAttribute("width", width.toString()); | ||
canvas.setAttribute("height", height.toString()); | ||
canvas.setAttribute("id", "render-canvas" + containerId); | ||
canvas.setAttribute("display", "none"); | ||
img.setAttribute("src", data); | ||
img.setAttribute("width", width.toString()); | ||
img.setAttribute("height", height.toString()); | ||
try { | ||
@@ -69,6 +73,5 @@ container.appendChild(canvas); | ||
} | ||
const renderCanvas = document.getElementById('render-canvas' + containerId); | ||
let ctx; | ||
const renderCanvas = (document.getElementById("render-canvas" + containerId)); | ||
const ctx = renderCanvas.getContext("2d"); | ||
let imgDataUrl; | ||
ctx = renderCanvas.getContext('2d'); | ||
img.onload = () => { | ||
@@ -79,12 +82,12 @@ ctx.drawImage(img, 0, 0); | ||
height = height / 4; | ||
img2.setAttribute('src', imgDataUrl); | ||
img2.setAttribute('width', width.toString()); | ||
img2.setAttribute('height', height.toString()); | ||
img2.setAttribute("src", imgDataUrl); | ||
img2.setAttribute("width", width.toString()); | ||
img2.setAttribute("height", height.toString()); | ||
container.innerHTML = ""; | ||
container.appendChild(img2); | ||
if (generateLink) { | ||
const downloadLink = document.createElement('a'); | ||
downloadLink.setAttribute('href', imgDataUrl); | ||
downloadLink.setAttribute('download', 'image.' + imgMode); | ||
downloadLink.innerHTML = 'Download Link'; | ||
const downloadLink = document.createElement("a"); | ||
downloadLink.setAttribute("href", imgDataUrl); | ||
downloadLink.setAttribute("download", "image." + imgMode); | ||
downloadLink.innerHTML = "Download Link"; | ||
container.appendChild(downloadLink); | ||
@@ -103,40 +106,46 @@ } | ||
static async getImageDataUrl(svgString, width, height, imgMode) { | ||
const xml = svgString, parser = new DOMParser(), result = parser.parseFromString(xml, 'text/xml'), inlineSVG = result.getElementsByTagName('svg')[0]; | ||
inlineSVG.setAttribute('width', width.toString()); | ||
inlineSVG.setAttribute('height', height.toString()); | ||
let data = "data:image/svg+xml;charset=utf-8;base64, " + window.btoa(new XMLSerializer().serializeToString(inlineSVG)), img = new Image(), canvas = document.createElement('canvas'), imgAtr, imgDataUrl, containerId = new Guid().toString(), container = document.createElement('div'); | ||
const xml = svgString, parser = new DOMParser(), result = parser.parseFromString(xml, "text/xml"), inlineSVG = (result.getElementsByTagName("svg")[0]); | ||
inlineSVG.setAttribute("width", width.toString()); | ||
inlineSVG.setAttribute("height", height.toString()); | ||
let data = "data:image/svg+xml;charset=utf-8;base64, " + | ||
window.btoa(new XMLSerializer().serializeToString(inlineSVG)), img = new Image(), imgAtr, imgDataUrl; | ||
const containerId = new Guid().toString(); | ||
const canvas = document.createElement("canvas"); | ||
const container = document.createElement("div"); | ||
container.id = containerId; | ||
document.body.appendChild(container); | ||
switch (imgMode) { | ||
case 'svg': | ||
case "svg": | ||
width = width / 4; | ||
height = height / 4; | ||
img.setAttribute('src', data); | ||
img.setAttribute('width', width.toString()); | ||
img.setAttribute('height', height.toString()); | ||
img.setAttribute("src", data); | ||
img.setAttribute("width", width.toString()); | ||
img.setAttribute("height", height.toString()); | ||
imgDataUrl = data; | ||
break; | ||
case 'png': | ||
imgAtr = 'image/png'; | ||
case "png": | ||
imgAtr = "image/png"; | ||
break; | ||
case 'jpeg': | ||
imgAtr = 'image/jpeg'; | ||
case "jpeg": | ||
imgAtr = "image/jpeg"; | ||
break; | ||
case 'webp': | ||
imgAtr = 'image/webp'; | ||
case "webp": | ||
imgAtr = "image/webp"; | ||
break; | ||
default: | ||
data = "data:image/svg+xml;charset=utf-8;base64, " + window.btoa(False_Template.template()); | ||
data = | ||
"data:image/svg+xml;charset=utf-8;base64, " + | ||
window.btoa(False_Template.template()); | ||
width = False_Template.width; | ||
height = False_Template.height; | ||
imgAtr = 'image/png'; | ||
imgAtr = "image/png"; | ||
break; | ||
} | ||
canvas.setAttribute('width', width.toString()); | ||
canvas.setAttribute('height', height.toString()); | ||
canvas.setAttribute('id', 'render-canvas-string' + new Guid().toString()); | ||
canvas.setAttribute('display', 'none'); | ||
img.setAttribute('src', data); | ||
img.setAttribute('width', width.toString()); | ||
img.setAttribute('height', height.toString()); | ||
canvas.setAttribute("width", width.toString()); | ||
canvas.setAttribute("height", height.toString()); | ||
canvas.setAttribute("id", "render-canvas-string" + new Guid().toString()); | ||
canvas.setAttribute("display", "none"); | ||
img.setAttribute("src", data); | ||
img.setAttribute("width", width.toString()); | ||
img.setAttribute("height", height.toString()); | ||
try { | ||
@@ -149,5 +158,4 @@ container.appendChild(canvas); | ||
} | ||
const renderCanvas = document.getElementById(canvas.id); | ||
let ctx; | ||
ctx = renderCanvas.getContext('2d'); | ||
const renderCanvas = (document.getElementById(canvas.id)); | ||
const ctx = renderCanvas.getContext("2d"); | ||
return new Promise((resolve) => { | ||
@@ -154,0 +162,0 @@ img.onload = () => { |
@@ -21,3 +21,3 @@ import { ErrorCodes } from "../model/errorCodes.js"; | ||
injector(importedTemplates) { | ||
importedTemplates.forEach(template => { | ||
importedTemplates.forEach((template) => { | ||
if (!template.callName || !template.template) { | ||
@@ -36,3 +36,3 @@ throw new Error(ErrorCodes.TEMPLATE_INJECTOR_ERROR); | ||
let result = null; | ||
this.injectList.forEach(template => { | ||
this.injectList.forEach((template) => { | ||
if (template.callName == templateName) { | ||
@@ -60,13 +60,13 @@ result = template; | ||
switch (mode) { | ||
case 'basic': | ||
if (templateName != '' | ||
&& templateName != null | ||
&& templateName != undefined | ||
&& this.call(templateName) != null) { | ||
case "basic": | ||
if (templateName != "" && | ||
templateName != null && | ||
templateName != undefined && | ||
this.call(templateName) != null) { | ||
const tmp = this.call(templateName); | ||
if (!tmp | ||
|| !tmp.template | ||
|| tmp.template === undefined | ||
|| tmp.template.width <= 0 | ||
|| tmp.template.height <= 0) { | ||
if (!tmp || | ||
!tmp.template || | ||
tmp.template === undefined || | ||
tmp.template.width <= 0 || | ||
tmp.template.height <= 0) { | ||
return false; | ||
@@ -79,3 +79,3 @@ } | ||
} | ||
case 'advanced': | ||
case "advanced": | ||
const cache = []; | ||
@@ -88,11 +88,11 @@ try { | ||
} | ||
cache.forEach(tmp => { | ||
if (!tmp | ||
|| tmp.width <= 0 | ||
|| tmp.height <= 0 | ||
|| tmp.template == undefined | ||
|| tmp.template == null | ||
|| templateName == '' | ||
|| templateName == null | ||
|| templateName == undefined) { | ||
cache.forEach((tmp) => { | ||
if (!tmp || | ||
tmp.width <= 0 || | ||
tmp.height <= 0 || | ||
tmp.template == undefined || | ||
tmp.template == null || | ||
templateName == "" || | ||
templateName == null || | ||
templateName == undefined) { | ||
return false; | ||
@@ -105,12 +105,12 @@ } | ||
return true; | ||
case 'all': | ||
case "all": | ||
const falseList = []; | ||
this.injectList.forEach(template => { | ||
if (template === null | ||
|| template.callName === null | ||
|| template.callName === undefined | ||
|| template.template === null | ||
|| template.template === undefined | ||
|| template.template.width <= 0 | ||
|| template.template.height <= 0) { | ||
this.injectList.forEach((template) => { | ||
if (template === null || | ||
template.callName === null || | ||
template.callName === undefined || | ||
template.template === null || | ||
template.template === undefined || | ||
template.template.width <= 0 || | ||
template.template.height <= 0) { | ||
falseList.push(template); | ||
@@ -122,3 +122,3 @@ } | ||
response: false, | ||
falseList: falseList | ||
falseList: falseList, | ||
}; | ||
@@ -125,0 +125,0 @@ return response; |
@@ -5,4 +5,7 @@ /** | ||
export declare class ErrorCodes { | ||
/** | ||
* Template injector error of error codes | ||
*/ | ||
static readonly TEMPLATE_INJECTOR_ERROR = "#SGL001 One of the injected templates is missing a property!"; | ||
} | ||
//# sourceMappingURL=errorCodes.d.ts.map |
@@ -5,4 +5,7 @@ /** | ||
export class ErrorCodes { | ||
/** | ||
* Template injector error of error codes | ||
*/ | ||
static TEMPLATE_INJECTOR_ERROR = "#SGL001 One of the injected templates is missing a property!"; | ||
} | ||
//# sourceMappingURL=errorCodes.js.map |
@@ -6,3 +6,3 @@ export class Info { | ||
*/ | ||
_version = "2.1.2"; | ||
_version = "2.1.3"; | ||
/** | ||
@@ -9,0 +9,0 @@ * Author of info |
{ | ||
"name": "social-graphics-library", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "A script for generating social media logos and banners", | ||
@@ -5,0 +5,0 @@ "main": "./dist/sgl.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
145013
1368