This commit is contained in:
2025-01-04 00:34:03 +01:00
parent 41829408dc
commit 0ca14bbc19
18111 changed files with 1871397 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
"use strict";
var core = require("@pixi/core"), generateFillStyle = require("./generateFillStyle.js");
function drawGlyph(canvas, context, metrics, x, y, resolution, style) {
const char = metrics.text, fontProperties = metrics.fontProperties;
context.translate(x, y), context.scale(resolution, resolution);
const tx = style.strokeThickness / 2, ty = -(style.strokeThickness / 2);
if (context.font = style.toFontString(), context.lineWidth = style.strokeThickness, context.textBaseline = style.textBaseline, context.lineJoin = style.lineJoin, context.miterLimit = style.miterLimit, context.fillStyle = generateFillStyle.generateFillStyle(canvas, context, style, resolution, [char], metrics), context.strokeStyle = style.stroke, style.dropShadow) {
const dropShadowColor = style.dropShadowColor, dropShadowBlur = style.dropShadowBlur * resolution, dropShadowDistance = style.dropShadowDistance * resolution;
context.shadowColor = core.Color.shared.setValue(dropShadowColor).setAlpha(style.dropShadowAlpha).toRgbaString(), context.shadowBlur = dropShadowBlur, context.shadowOffsetX = Math.cos(style.dropShadowAngle) * dropShadowDistance, context.shadowOffsetY = Math.sin(style.dropShadowAngle) * dropShadowDistance;
} else
context.shadowColor = "black", context.shadowBlur = 0, context.shadowOffsetX = 0, context.shadowOffsetY = 0;
style.stroke && style.strokeThickness && context.strokeText(char, tx, ty + metrics.lineHeight - fontProperties.descent), style.fill && context.fillText(char, tx, ty + metrics.lineHeight - fontProperties.descent), context.setTransform(1, 0, 0, 1, 0, 0), context.fillStyle = "rgba(0, 0, 0, 0)";
}
exports.drawGlyph = drawGlyph;
//# sourceMappingURL=drawGlyph.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"drawGlyph.js","sources":["../../src/utils/drawGlyph.ts"],"sourcesContent":["import { Color } from '@pixi/core';\nimport { generateFillStyle } from './generateFillStyle';\n\nimport type { ICanvas, ICanvasRenderingContext2D } from '@pixi/core';\nimport type { TextMetrics, TextStyle } from '@pixi/text';\n\n// TODO: Prevent code duplication b/w drawGlyph & Text#updateText\n\n/**\n * Draws the glyph `metrics.text` on the given canvas.\n *\n * Ignored because not directly exposed.\n * @ignore\n * @param {PIXI.ICanvas} canvas\n * @param {PIXI.ICanvasRenderingContext2D} context\n * @param {TextMetrics} metrics\n * @param {number} x\n * @param {number} y\n * @param {number} resolution\n * @param {TextStyle} style\n */\nexport function drawGlyph(\n canvas: ICanvas,\n context: ICanvasRenderingContext2D,\n metrics: TextMetrics,\n x: number,\n y: number,\n resolution: number,\n style: TextStyle\n): void\n{\n const char = metrics.text;\n const fontProperties = metrics.fontProperties;\n\n context.translate(x, y);\n context.scale(resolution, resolution);\n\n const tx = style.strokeThickness / 2;\n const ty = -(style.strokeThickness / 2);\n\n context.font = style.toFontString();\n context.lineWidth = style.strokeThickness;\n context.textBaseline = style.textBaseline;\n context.lineJoin = style.lineJoin;\n context.miterLimit = style.miterLimit;\n\n // set canvas text styles\n context.fillStyle = generateFillStyle(canvas, context, style, resolution, [char], metrics);\n context.strokeStyle = style.stroke as string;\n\n if (style.dropShadow)\n {\n const dropShadowColor = style.dropShadowColor;\n const dropShadowBlur = style.dropShadowBlur * resolution;\n const dropShadowDistance = style.dropShadowDistance * resolution;\n\n context.shadowColor = Color.shared\n .setValue(dropShadowColor)\n .setAlpha(style.dropShadowAlpha)\n .toRgbaString();\n context.shadowBlur = dropShadowBlur;\n context.shadowOffsetX = Math.cos(style.dropShadowAngle) * dropShadowDistance;\n context.shadowOffsetY = Math.sin(style.dropShadowAngle) * dropShadowDistance;\n }\n else\n {\n context.shadowColor = 'black';\n context.shadowBlur = 0;\n context.shadowOffsetX = 0;\n context.shadowOffsetY = 0;\n }\n\n if (style.stroke && style.strokeThickness)\n {\n context.strokeText(char, tx, ty + metrics.lineHeight - fontProperties.descent);\n }\n if (style.fill)\n {\n context.fillText(char, tx, ty + metrics.lineHeight - fontProperties.descent);\n }\n\n context.setTransform(1, 0, 0, 1, 0, 0); // defaults needed for older browsers (e.g. Opera 29)\n\n context.fillStyle = 'rgba(0, 0, 0, 0)';\n}\n"],"names":["generateFillStyle","Color"],"mappings":";;AAqBO,SAAS,UACZ,QACA,SACA,SACA,GACA,GACA,YACA,OAEJ;AACI,QAAM,OAAO,QAAQ,MACf,iBAAiB,QAAQ;AAE/B,UAAQ,UAAU,GAAG,CAAC,GACtB,QAAQ,MAAM,YAAY,UAAU;AAEpC,QAAM,KAAK,MAAM,kBAAkB,GAC7B,KAAK,EAAE,MAAM,kBAAkB;AAYrC,MAVA,QAAQ,OAAO,MAAM,aAAa,GAClC,QAAQ,YAAY,MAAM,iBAC1B,QAAQ,eAAe,MAAM,cAC7B,QAAQ,WAAW,MAAM,UACzB,QAAQ,aAAa,MAAM,YAG3B,QAAQ,YAAYA,kBAAA,kBAAkB,QAAQ,SAAS,OAAO,YAAY,CAAC,IAAI,GAAG,OAAO,GACzF,QAAQ,cAAc,MAAM,QAExB,MAAM,YACV;AACU,UAAA,kBAAkB,MAAM,iBACxB,iBAAiB,MAAM,iBAAiB,YACxC,qBAAqB,MAAM,qBAAqB;AAEtD,YAAQ,cAAcC,KAAAA,MAAM,OACvB,SAAS,eAAe,EACxB,SAAS,MAAM,eAAe,EAC9B,aAAa,GAClB,QAAQ,aAAa,gBACrB,QAAQ,gBAAgB,KAAK,IAAI,MAAM,eAAe,IAAI,oBAC1D,QAAQ,gBAAgB,KAAK,IAAI,MAAM,eAAe,IAAI;AAAA,EAC9D;AAGY,YAAA,cAAc,SACtB,QAAQ,aAAa,GACrB,QAAQ,gBAAgB,GACxB,QAAQ,gBAAgB;AAGxB,QAAM,UAAU,MAAM,mBAEtB,QAAQ,WAAW,MAAM,IAAI,KAAK,QAAQ,aAAa,eAAe,OAAO,GAE7E,MAAM,QAEN,QAAQ,SAAS,MAAM,IAAI,KAAK,QAAQ,aAAa,eAAe,OAAO,GAG/E,QAAQ,aAAa,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,GAErC,QAAQ,YAAY;AACxB;;"}

View File

@@ -0,0 +1,17 @@
import { Color } from "@pixi/core";
import { generateFillStyle } from "./generateFillStyle.mjs";
function drawGlyph(canvas, context, metrics, x, y, resolution, style) {
const char = metrics.text, fontProperties = metrics.fontProperties;
context.translate(x, y), context.scale(resolution, resolution);
const tx = style.strokeThickness / 2, ty = -(style.strokeThickness / 2);
if (context.font = style.toFontString(), context.lineWidth = style.strokeThickness, context.textBaseline = style.textBaseline, context.lineJoin = style.lineJoin, context.miterLimit = style.miterLimit, context.fillStyle = generateFillStyle(canvas, context, style, resolution, [char], metrics), context.strokeStyle = style.stroke, style.dropShadow) {
const dropShadowColor = style.dropShadowColor, dropShadowBlur = style.dropShadowBlur * resolution, dropShadowDistance = style.dropShadowDistance * resolution;
context.shadowColor = Color.shared.setValue(dropShadowColor).setAlpha(style.dropShadowAlpha).toRgbaString(), context.shadowBlur = dropShadowBlur, context.shadowOffsetX = Math.cos(style.dropShadowAngle) * dropShadowDistance, context.shadowOffsetY = Math.sin(style.dropShadowAngle) * dropShadowDistance;
} else
context.shadowColor = "black", context.shadowBlur = 0, context.shadowOffsetX = 0, context.shadowOffsetY = 0;
style.stroke && style.strokeThickness && context.strokeText(char, tx, ty + metrics.lineHeight - fontProperties.descent), style.fill && context.fillText(char, tx, ty + metrics.lineHeight - fontProperties.descent), context.setTransform(1, 0, 0, 1, 0, 0), context.fillStyle = "rgba(0, 0, 0, 0)";
}
export {
drawGlyph
};
//# sourceMappingURL=drawGlyph.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"drawGlyph.mjs","sources":["../../src/utils/drawGlyph.ts"],"sourcesContent":["import { Color } from '@pixi/core';\nimport { generateFillStyle } from './generateFillStyle';\n\nimport type { ICanvas, ICanvasRenderingContext2D } from '@pixi/core';\nimport type { TextMetrics, TextStyle } from '@pixi/text';\n\n// TODO: Prevent code duplication b/w drawGlyph & Text#updateText\n\n/**\n * Draws the glyph `metrics.text` on the given canvas.\n *\n * Ignored because not directly exposed.\n * @ignore\n * @param {PIXI.ICanvas} canvas\n * @param {PIXI.ICanvasRenderingContext2D} context\n * @param {TextMetrics} metrics\n * @param {number} x\n * @param {number} y\n * @param {number} resolution\n * @param {TextStyle} style\n */\nexport function drawGlyph(\n canvas: ICanvas,\n context: ICanvasRenderingContext2D,\n metrics: TextMetrics,\n x: number,\n y: number,\n resolution: number,\n style: TextStyle\n): void\n{\n const char = metrics.text;\n const fontProperties = metrics.fontProperties;\n\n context.translate(x, y);\n context.scale(resolution, resolution);\n\n const tx = style.strokeThickness / 2;\n const ty = -(style.strokeThickness / 2);\n\n context.font = style.toFontString();\n context.lineWidth = style.strokeThickness;\n context.textBaseline = style.textBaseline;\n context.lineJoin = style.lineJoin;\n context.miterLimit = style.miterLimit;\n\n // set canvas text styles\n context.fillStyle = generateFillStyle(canvas, context, style, resolution, [char], metrics);\n context.strokeStyle = style.stroke as string;\n\n if (style.dropShadow)\n {\n const dropShadowColor = style.dropShadowColor;\n const dropShadowBlur = style.dropShadowBlur * resolution;\n const dropShadowDistance = style.dropShadowDistance * resolution;\n\n context.shadowColor = Color.shared\n .setValue(dropShadowColor)\n .setAlpha(style.dropShadowAlpha)\n .toRgbaString();\n context.shadowBlur = dropShadowBlur;\n context.shadowOffsetX = Math.cos(style.dropShadowAngle) * dropShadowDistance;\n context.shadowOffsetY = Math.sin(style.dropShadowAngle) * dropShadowDistance;\n }\n else\n {\n context.shadowColor = 'black';\n context.shadowBlur = 0;\n context.shadowOffsetX = 0;\n context.shadowOffsetY = 0;\n }\n\n if (style.stroke && style.strokeThickness)\n {\n context.strokeText(char, tx, ty + metrics.lineHeight - fontProperties.descent);\n }\n if (style.fill)\n {\n context.fillText(char, tx, ty + metrics.lineHeight - fontProperties.descent);\n }\n\n context.setTransform(1, 0, 0, 1, 0, 0); // defaults needed for older browsers (e.g. Opera 29)\n\n context.fillStyle = 'rgba(0, 0, 0, 0)';\n}\n"],"names":[],"mappings":";;AAqBO,SAAS,UACZ,QACA,SACA,SACA,GACA,GACA,YACA,OAEJ;AACI,QAAM,OAAO,QAAQ,MACf,iBAAiB,QAAQ;AAE/B,UAAQ,UAAU,GAAG,CAAC,GACtB,QAAQ,MAAM,YAAY,UAAU;AAEpC,QAAM,KAAK,MAAM,kBAAkB,GAC7B,KAAK,EAAE,MAAM,kBAAkB;AAYrC,MAVA,QAAQ,OAAO,MAAM,aAAa,GAClC,QAAQ,YAAY,MAAM,iBAC1B,QAAQ,eAAe,MAAM,cAC7B,QAAQ,WAAW,MAAM,UACzB,QAAQ,aAAa,MAAM,YAG3B,QAAQ,YAAY,kBAAkB,QAAQ,SAAS,OAAO,YAAY,CAAC,IAAI,GAAG,OAAO,GACzF,QAAQ,cAAc,MAAM,QAExB,MAAM,YACV;AACU,UAAA,kBAAkB,MAAM,iBACxB,iBAAiB,MAAM,iBAAiB,YACxC,qBAAqB,MAAM,qBAAqB;AAEtD,YAAQ,cAAc,MAAM,OACvB,SAAS,eAAe,EACxB,SAAS,MAAM,eAAe,EAC9B,aAAa,GAClB,QAAQ,aAAa,gBACrB,QAAQ,gBAAgB,KAAK,IAAI,MAAM,eAAe,IAAI,oBAC1D,QAAQ,gBAAgB,KAAK,IAAI,MAAM,eAAe,IAAI;AAAA,EAC9D;AAGY,YAAA,cAAc,SACtB,QAAQ,aAAa,GACrB,QAAQ,gBAAgB,GACxB,QAAQ,gBAAgB;AAGxB,QAAM,UAAU,MAAM,mBAEtB,QAAQ,WAAW,MAAM,IAAI,KAAK,QAAQ,aAAa,eAAe,OAAO,GAE7E,MAAM,QAEN,QAAQ,SAAS,MAAM,IAAI,KAAK,QAAQ,aAAa,eAAe,OAAO,GAG/E,QAAQ,aAAa,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,GAErC,QAAQ,YAAY;AACxB;"}

View File

@@ -0,0 +1,6 @@
"use strict";
function extractCharCode(str) {
return str.codePointAt ? str.codePointAt(0) : str.charCodeAt(0);
}
exports.extractCharCode = extractCharCode;
//# sourceMappingURL=extractCharCode.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"extractCharCode.js","sources":["../../src/utils/extractCharCode.ts"],"sourcesContent":["/**\n * Ponyfill for IE because it doesn't support `codePointAt`\n * @param str\n * @private\n */\nexport function extractCharCode(str: string): number\n{\n return str.codePointAt ? str.codePointAt(0) : str.charCodeAt(0);\n}\n"],"names":[],"mappings":";AAKO,SAAS,gBAAgB,KAChC;AACW,SAAA,IAAI,cAAc,IAAI,YAAY,CAAC,IAAI,IAAI,WAAW,CAAC;AAClE;;"}

View File

@@ -0,0 +1,7 @@
function extractCharCode(str) {
return str.codePointAt ? str.codePointAt(0) : str.charCodeAt(0);
}
export {
extractCharCode
};
//# sourceMappingURL=extractCharCode.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"extractCharCode.mjs","sources":["../../src/utils/extractCharCode.ts"],"sourcesContent":["/**\n * Ponyfill for IE because it doesn't support `codePointAt`\n * @param str\n * @private\n */\nexport function extractCharCode(str: string): number\n{\n return str.codePointAt ? str.codePointAt(0) : str.charCodeAt(0);\n}\n"],"names":[],"mappings":"AAKO,SAAS,gBAAgB,KAChC;AACW,SAAA,IAAI,cAAc,IAAI,YAAY,CAAC,IAAI,IAAI,WAAW,CAAC;AAClE;"}

View File

@@ -0,0 +1,43 @@
"use strict";
var text = require("@pixi/text");
function generateFillStyle(canvas, context, style, resolution, lines, metrics) {
const fillStyle = style.fill;
if (Array.isArray(fillStyle)) {
if (fillStyle.length === 1)
return fillStyle[0];
} else
return fillStyle;
let gradient;
const dropShadowCorrection = style.dropShadow ? style.dropShadowDistance : 0, padding = style.padding || 0, width = canvas.width / resolution - dropShadowCorrection - padding * 2, height = canvas.height / resolution - dropShadowCorrection - padding * 2, fill = fillStyle.slice(), fillGradientStops = style.fillGradientStops.slice();
if (!fillGradientStops.length) {
const lengthPlus1 = fill.length + 1;
for (let i = 1; i < lengthPlus1; ++i)
fillGradientStops.push(i / lengthPlus1);
}
if (fill.unshift(fillStyle[0]), fillGradientStops.unshift(0), fill.push(fillStyle[fillStyle.length - 1]), fillGradientStops.push(1), style.fillGradientType === text.TEXT_GRADIENT.LINEAR_VERTICAL) {
gradient = context.createLinearGradient(width / 2, padding, width / 2, height + padding);
let lastIterationStop = 0;
const gradStopLineHeight = (metrics.fontProperties.fontSize + style.strokeThickness) / height;
for (let i = 0; i < lines.length; i++) {
const thisLineTop = metrics.lineHeight * i;
for (let j = 0; j < fill.length; j++) {
let lineStop = 0;
typeof fillGradientStops[j] == "number" ? lineStop = fillGradientStops[j] : lineStop = j / fill.length;
const globalStop = thisLineTop / height + lineStop * gradStopLineHeight;
let clampedStop = Math.max(lastIterationStop, globalStop);
clampedStop = Math.min(clampedStop, 1), gradient.addColorStop(clampedStop, fill[j]), lastIterationStop = clampedStop;
}
}
} else {
gradient = context.createLinearGradient(padding, height / 2, width + padding, height / 2);
const totalIterations = fill.length + 1;
let currentIteration = 1;
for (let i = 0; i < fill.length; i++) {
let stop;
typeof fillGradientStops[i] == "number" ? stop = fillGradientStops[i] : stop = currentIteration / totalIterations, gradient.addColorStop(stop, fill[i]), currentIteration++;
}
}
return gradient;
}
exports.generateFillStyle = generateFillStyle;
//# sourceMappingURL=generateFillStyle.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,44 @@
import { TEXT_GRADIENT } from "@pixi/text";
function generateFillStyle(canvas, context, style, resolution, lines, metrics) {
const fillStyle = style.fill;
if (Array.isArray(fillStyle)) {
if (fillStyle.length === 1)
return fillStyle[0];
} else
return fillStyle;
let gradient;
const dropShadowCorrection = style.dropShadow ? style.dropShadowDistance : 0, padding = style.padding || 0, width = canvas.width / resolution - dropShadowCorrection - padding * 2, height = canvas.height / resolution - dropShadowCorrection - padding * 2, fill = fillStyle.slice(), fillGradientStops = style.fillGradientStops.slice();
if (!fillGradientStops.length) {
const lengthPlus1 = fill.length + 1;
for (let i = 1; i < lengthPlus1; ++i)
fillGradientStops.push(i / lengthPlus1);
}
if (fill.unshift(fillStyle[0]), fillGradientStops.unshift(0), fill.push(fillStyle[fillStyle.length - 1]), fillGradientStops.push(1), style.fillGradientType === TEXT_GRADIENT.LINEAR_VERTICAL) {
gradient = context.createLinearGradient(width / 2, padding, width / 2, height + padding);
let lastIterationStop = 0;
const gradStopLineHeight = (metrics.fontProperties.fontSize + style.strokeThickness) / height;
for (let i = 0; i < lines.length; i++) {
const thisLineTop = metrics.lineHeight * i;
for (let j = 0; j < fill.length; j++) {
let lineStop = 0;
typeof fillGradientStops[j] == "number" ? lineStop = fillGradientStops[j] : lineStop = j / fill.length;
const globalStop = thisLineTop / height + lineStop * gradStopLineHeight;
let clampedStop = Math.max(lastIterationStop, globalStop);
clampedStop = Math.min(clampedStop, 1), gradient.addColorStop(clampedStop, fill[j]), lastIterationStop = clampedStop;
}
}
} else {
gradient = context.createLinearGradient(padding, height / 2, width + padding, height / 2);
const totalIterations = fill.length + 1;
let currentIteration = 1;
for (let i = 0; i < fill.length; i++) {
let stop;
typeof fillGradientStops[i] == "number" ? stop = fillGradientStops[i] : stop = currentIteration / totalIterations, gradient.addColorStop(stop, fill[i]), currentIteration++;
}
}
return gradient;
}
export {
generateFillStyle
};
//# sourceMappingURL=generateFillStyle.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,8 @@
"use strict";
var drawGlyph = require("./drawGlyph.js"), extractCharCode = require("./extractCharCode.js"), generateFillStyle = require("./generateFillStyle.js"), resolveCharacters = require("./resolveCharacters.js"), splitTextToCharacters = require("./splitTextToCharacters.js");
exports.drawGlyph = drawGlyph.drawGlyph;
exports.extractCharCode = extractCharCode.extractCharCode;
exports.generateFillStyle = generateFillStyle.generateFillStyle;
exports.resolveCharacters = resolveCharacters.resolveCharacters;
exports.splitTextToCharacters = splitTextToCharacters.splitTextToCharacters;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}

View File

@@ -0,0 +1,13 @@
import { drawGlyph } from "./drawGlyph.mjs";
import { extractCharCode } from "./extractCharCode.mjs";
import { generateFillStyle } from "./generateFillStyle.mjs";
import { resolveCharacters } from "./resolveCharacters.mjs";
import { splitTextToCharacters } from "./splitTextToCharacters.mjs";
export {
drawGlyph,
extractCharCode,
generateFillStyle,
resolveCharacters,
splitTextToCharacters
};
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}

View File

@@ -0,0 +1,24 @@
"use strict";
var splitTextToCharacters = require("./splitTextToCharacters.js");
function resolveCharacters(chars) {
typeof chars == "string" && (chars = [chars]);
const result = [];
for (let i = 0, j = chars.length; i < j; i++) {
const item = chars[i];
if (Array.isArray(item)) {
if (item.length !== 2)
throw new Error(`[BitmapFont]: Invalid character range length, expecting 2 got ${item.length}.`);
const startCode = item[0].charCodeAt(0), endCode = item[1].charCodeAt(0);
if (endCode < startCode)
throw new Error("[BitmapFont]: Invalid character range.");
for (let i2 = startCode, j2 = endCode; i2 <= j2; i2++)
result.push(String.fromCharCode(i2));
} else
result.push(...splitTextToCharacters.splitTextToCharacters(item));
}
if (result.length === 0)
throw new Error("[BitmapFont]: Empty set when resolving characters.");
return result;
}
exports.resolveCharacters = resolveCharacters;
//# sourceMappingURL=resolveCharacters.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"resolveCharacters.js","sources":["../../src/utils/resolveCharacters.ts"],"sourcesContent":["import { splitTextToCharacters } from './splitTextToCharacters';\n\n/**\n * Processes the passed character set data and returns a flattened array of all the characters.\n *\n * Ignored because not directly exposed.\n * @ignore\n * @param {string | string[] | string[][] } chars\n * @returns {string[]} the flattened array of characters\n */\nexport function resolveCharacters(chars: string | (string | string[])[]): string[]\n{\n // Split the chars string into individual characters\n if (typeof chars === 'string')\n {\n chars = [chars];\n }\n\n // Handle an array of characters+ranges\n const result: string[] = [];\n\n for (let i = 0, j = chars.length; i < j; i++)\n {\n const item = chars[i];\n\n // Handle range delimited by start/end chars\n if (Array.isArray(item))\n {\n if (item.length !== 2)\n {\n throw new Error(`[BitmapFont]: Invalid character range length, expecting 2 got ${item.length}.`);\n }\n\n const startCode = item[0].charCodeAt(0);\n const endCode = item[1].charCodeAt(0);\n\n if (endCode < startCode)\n {\n throw new Error('[BitmapFont]: Invalid character range.');\n }\n\n for (let i = startCode, j = endCode; i <= j; i++)\n {\n result.push(String.fromCharCode(i));\n }\n }\n // Handle a character set string\n else\n {\n result.push(...splitTextToCharacters(item));\n }\n }\n\n if (result.length === 0)\n {\n throw new Error('[BitmapFont]: Empty set when resolving characters.');\n }\n\n return result;\n}\n"],"names":["i","j","splitTextToCharacters"],"mappings":";;AAUO,SAAS,kBAAkB,OAClC;AAEQ,SAAO,SAAU,aAEjB,QAAQ,CAAC,KAAK;AAIlB,QAAM,SAAmB,CAAA;AAEzB,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,IAAI,GAAG,KACzC;AACU,UAAA,OAAO,MAAM,CAAC;AAGhB,QAAA,MAAM,QAAQ,IAAI,GACtB;AACI,UAAI,KAAK,WAAW;AAEhB,cAAM,IAAI,MAAM,iEAAiE,KAAK,MAAM,GAAG;AAGnG,YAAM,YAAY,KAAK,CAAC,EAAE,WAAW,CAAC,GAChC,UAAU,KAAK,CAAC,EAAE,WAAW,CAAC;AAEpC,UAAI,UAAU;AAEJ,cAAA,IAAI,MAAM,wCAAwC;AAG5D,eAASA,KAAI,WAAWC,KAAI,SAASD,MAAKC,IAAGD;AAEzC,eAAO,KAAK,OAAO,aAAaA,EAAC,CAAC;AAAA,IAE1C;AAII,aAAO,KAAK,GAAGE,4CAAsB,IAAI,CAAC;AAAA,EAElD;AAEA,MAAI,OAAO,WAAW;AAEZ,UAAA,IAAI,MAAM,oDAAoD;AAGjE,SAAA;AACX;;"}

View File

@@ -0,0 +1,25 @@
import { splitTextToCharacters } from "./splitTextToCharacters.mjs";
function resolveCharacters(chars) {
typeof chars == "string" && (chars = [chars]);
const result = [];
for (let i = 0, j = chars.length; i < j; i++) {
const item = chars[i];
if (Array.isArray(item)) {
if (item.length !== 2)
throw new Error(`[BitmapFont]: Invalid character range length, expecting 2 got ${item.length}.`);
const startCode = item[0].charCodeAt(0), endCode = item[1].charCodeAt(0);
if (endCode < startCode)
throw new Error("[BitmapFont]: Invalid character range.");
for (let i2 = startCode, j2 = endCode; i2 <= j2; i2++)
result.push(String.fromCharCode(i2));
} else
result.push(...splitTextToCharacters(item));
}
if (result.length === 0)
throw new Error("[BitmapFont]: Empty set when resolving characters.");
return result;
}
export {
resolveCharacters
};
//# sourceMappingURL=resolveCharacters.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"resolveCharacters.mjs","sources":["../../src/utils/resolveCharacters.ts"],"sourcesContent":["import { splitTextToCharacters } from './splitTextToCharacters';\n\n/**\n * Processes the passed character set data and returns a flattened array of all the characters.\n *\n * Ignored because not directly exposed.\n * @ignore\n * @param {string | string[] | string[][] } chars\n * @returns {string[]} the flattened array of characters\n */\nexport function resolveCharacters(chars: string | (string | string[])[]): string[]\n{\n // Split the chars string into individual characters\n if (typeof chars === 'string')\n {\n chars = [chars];\n }\n\n // Handle an array of characters+ranges\n const result: string[] = [];\n\n for (let i = 0, j = chars.length; i < j; i++)\n {\n const item = chars[i];\n\n // Handle range delimited by start/end chars\n if (Array.isArray(item))\n {\n if (item.length !== 2)\n {\n throw new Error(`[BitmapFont]: Invalid character range length, expecting 2 got ${item.length}.`);\n }\n\n const startCode = item[0].charCodeAt(0);\n const endCode = item[1].charCodeAt(0);\n\n if (endCode < startCode)\n {\n throw new Error('[BitmapFont]: Invalid character range.');\n }\n\n for (let i = startCode, j = endCode; i <= j; i++)\n {\n result.push(String.fromCharCode(i));\n }\n }\n // Handle a character set string\n else\n {\n result.push(...splitTextToCharacters(item));\n }\n }\n\n if (result.length === 0)\n {\n throw new Error('[BitmapFont]: Empty set when resolving characters.');\n }\n\n return result;\n}\n"],"names":["i","j"],"mappings":";AAUO,SAAS,kBAAkB,OAClC;AAEQ,SAAO,SAAU,aAEjB,QAAQ,CAAC,KAAK;AAIlB,QAAM,SAAmB,CAAA;AAEzB,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,IAAI,GAAG,KACzC;AACU,UAAA,OAAO,MAAM,CAAC;AAGhB,QAAA,MAAM,QAAQ,IAAI,GACtB;AACI,UAAI,KAAK,WAAW;AAEhB,cAAM,IAAI,MAAM,iEAAiE,KAAK,MAAM,GAAG;AAGnG,YAAM,YAAY,KAAK,CAAC,EAAE,WAAW,CAAC,GAChC,UAAU,KAAK,CAAC,EAAE,WAAW,CAAC;AAEpC,UAAI,UAAU;AAEJ,cAAA,IAAI,MAAM,wCAAwC;AAG5D,eAASA,KAAI,WAAWC,KAAI,SAASD,MAAKC,IAAGD;AAEzC,eAAO,KAAK,OAAO,aAAaA,EAAC,CAAC;AAAA,IAE1C;AAII,aAAO,KAAK,GAAG,sBAAsB,IAAI,CAAC;AAAA,EAElD;AAEA,MAAI,OAAO,WAAW;AAEZ,UAAA,IAAI,MAAM,oDAAoD;AAGjE,SAAA;AACX;"}

View File

@@ -0,0 +1,6 @@
"use strict";
function splitTextToCharacters(text) {
return Array.from ? Array.from(text) : text.split("");
}
exports.splitTextToCharacters = splitTextToCharacters;
//# sourceMappingURL=splitTextToCharacters.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"splitTextToCharacters.js","sources":["../../src/utils/splitTextToCharacters.ts"],"sourcesContent":["/**\n * Ponyfill for IE because it doesn't support `Array.from`\n * @param text\n * @private\n */\nexport function splitTextToCharacters(text: string): string[]\n{\n return Array.from ? Array.from(text) : text.split('');\n}\n"],"names":[],"mappings":";AAKO,SAAS,sBAAsB,MACtC;AACW,SAAA,MAAM,OAAO,MAAM,KAAK,IAAI,IAAI,KAAK,MAAM,EAAE;AACxD;;"}

View File

@@ -0,0 +1,7 @@
function splitTextToCharacters(text) {
return Array.from ? Array.from(text) : text.split("");
}
export {
splitTextToCharacters
};
//# sourceMappingURL=splitTextToCharacters.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"splitTextToCharacters.mjs","sources":["../../src/utils/splitTextToCharacters.ts"],"sourcesContent":["/**\n * Ponyfill for IE because it doesn't support `Array.from`\n * @param text\n * @private\n */\nexport function splitTextToCharacters(text: string): string[]\n{\n return Array.from ? Array.from(text) : text.split('');\n}\n"],"names":[],"mappings":"AAKO,SAAS,sBAAsB,MACtC;AACW,SAAA,MAAM,OAAO,MAAM,KAAK,IAAI,IAAI,KAAK,MAAM,EAAE;AACxD;"}