brilliantsole 0.0.35 → 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/brilliantsole.cjs +0 -213
- package/build/brilliantsole.cjs.map +1 -1
- package/build/brilliantsole.js.map +1 -1
- package/build/brilliantsole.ls.js +0 -244
- package/build/brilliantsole.ls.js.map +1 -1
- package/build/brilliantsole.min.js.map +1 -1
- package/build/brilliantsole.module.js.map +1 -1
- package/build/brilliantsole.module.min.js.map +1 -1
- package/build/brilliantsole.node.module.d.ts +1 -31
- package/build/brilliantsole.node.module.js +1 -205
- package/build/brilliantsole.node.module.js.map +1 -1
- package/build/dts/BS.d.ts +2 -0
- package/build/index.node.d.ts +1 -31
- package/package.json +9 -10
- package/src/BS.ts +2 -0
package/build/brilliantsole.cjs
CHANGED
|
@@ -5609,9 +5609,6 @@ function removeSubstrings(string, substrings) {
|
|
|
5609
5609
|
|
|
5610
5610
|
const _console$r = createConsole("DisplaySpriteSheetUtils", { log: false });
|
|
5611
5611
|
const spriteHeaderLength = 3 * 2;
|
|
5612
|
-
function calculateSpriteSheetHeaderLength(numberOfSprites) {
|
|
5613
|
-
return 2 + numberOfSprites * 2 + numberOfSprites * spriteHeaderLength;
|
|
5614
|
-
}
|
|
5615
5612
|
function getCurvesPoints(curves) {
|
|
5616
5613
|
const curvePoints = [];
|
|
5617
5614
|
curves.forEach((curve, index) => {
|
|
@@ -6391,15 +6388,6 @@ function resizeImage(image, width, height, canvas) {
|
|
|
6391
6388
|
ctx.drawImage(image, 0, 0, width, height);
|
|
6392
6389
|
return canvas;
|
|
6393
6390
|
}
|
|
6394
|
-
function cropCanvas(canvas, x, y, width, height, targetCanvas) {
|
|
6395
|
-
targetCanvas = targetCanvas || document.createElement("canvas");
|
|
6396
|
-
const ctx = targetCanvas.getContext("2d", { willReadFrequently: true });
|
|
6397
|
-
targetCanvas.width = width;
|
|
6398
|
-
targetCanvas.height = height;
|
|
6399
|
-
ctx.imageSmoothingEnabled = false;
|
|
6400
|
-
ctx.drawImage(canvas, x, y, width, height, 0, 0, width, height);
|
|
6401
|
-
return targetCanvas;
|
|
6402
|
-
}
|
|
6403
6391
|
function removeAlphaFromCanvas(canvas) {
|
|
6404
6392
|
const ctx = canvas.getContext("2d", { willReadFrequently: true });
|
|
6405
6393
|
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
@@ -6438,77 +6426,6 @@ async function imageToBitmap(image, width, height, colors, bitmapColorIndices, n
|
|
|
6438
6426
|
};
|
|
6439
6427
|
return { blob, bitmap };
|
|
6440
6428
|
}
|
|
6441
|
-
const drawSpriteBitmapCommandHeaderLength = 1 + 2 + 2 + 2 + 2 + 1 + 2;
|
|
6442
|
-
async function canvasToBitmaps(canvas, numberOfColors, mtu) {
|
|
6443
|
-
const { blob, colors, colorIndices } = await quantizeCanvas(canvas, numberOfColors);
|
|
6444
|
-
const bitmapRows = [];
|
|
6445
|
-
const { width, height } = canvas;
|
|
6446
|
-
const numberOfPixels = width * height;
|
|
6447
|
-
const pixelDepth = DisplayPixelDepths.find((pixelDepth) => pixelDepthToNumberOfColors(pixelDepth) >= numberOfColors);
|
|
6448
|
-
_console$q.assertWithError(pixelDepth, `no pixelDepth found that covers ${numberOfColors} colors`);
|
|
6449
|
-
const pixelsPerByte = pixelDepthToPixelsPerByte(pixelDepth);
|
|
6450
|
-
const numberOfBytes = Math.ceil(numberOfPixels / pixelsPerByte);
|
|
6451
|
-
_console$q.log({
|
|
6452
|
-
width,
|
|
6453
|
-
height,
|
|
6454
|
-
numberOfPixels,
|
|
6455
|
-
pixelDepth,
|
|
6456
|
-
pixelsPerByte,
|
|
6457
|
-
numberOfBytes,
|
|
6458
|
-
mtu,
|
|
6459
|
-
});
|
|
6460
|
-
const maxPixelDataLength = mtu - (drawSpriteBitmapCommandHeaderLength + 5);
|
|
6461
|
-
const maxPixels = Math.floor(maxPixelDataLength / pixelsPerByte);
|
|
6462
|
-
const maxBitmapWidth = Math.min(maxPixels, width);
|
|
6463
|
-
let maxBitmapHeight = 1;
|
|
6464
|
-
if (maxBitmapWidth == width) {
|
|
6465
|
-
const bitmapRowPixelDataLength = Math.ceil(width / pixelsPerByte);
|
|
6466
|
-
maxBitmapHeight = Math.floor(maxPixelDataLength / bitmapRowPixelDataLength);
|
|
6467
|
-
}
|
|
6468
|
-
_console$q.log({
|
|
6469
|
-
maxPixelDataLength,
|
|
6470
|
-
maxPixels,
|
|
6471
|
-
maxBitmapHeight,
|
|
6472
|
-
maxBitmapWidth,
|
|
6473
|
-
});
|
|
6474
|
-
if (maxBitmapHeight >= height) {
|
|
6475
|
-
_console$q.log("image is small enough for a single bitmap");
|
|
6476
|
-
const bitmap = {
|
|
6477
|
-
numberOfColors,
|
|
6478
|
-
pixels: colorIndices,
|
|
6479
|
-
width,
|
|
6480
|
-
height,
|
|
6481
|
-
};
|
|
6482
|
-
bitmapRows.push([bitmap]);
|
|
6483
|
-
}
|
|
6484
|
-
else {
|
|
6485
|
-
let offsetX = 0;
|
|
6486
|
-
let offsetY = 0;
|
|
6487
|
-
const bitmapCanvas = document.createElement("canvas");
|
|
6488
|
-
const bitmapColorIndices = new Array(numberOfColors)
|
|
6489
|
-
.fill(0)
|
|
6490
|
-
.map((_, i) => i);
|
|
6491
|
-
while (offsetY < height) {
|
|
6492
|
-
const bitmapHeight = Math.min(maxBitmapHeight, height - offsetY);
|
|
6493
|
-
offsetX = 0;
|
|
6494
|
-
const bitmapRow = [];
|
|
6495
|
-
bitmapRows.push(bitmapRow);
|
|
6496
|
-
while (offsetX < width) {
|
|
6497
|
-
const bitmapWidth = Math.min(maxBitmapWidth, width - offsetX);
|
|
6498
|
-
cropCanvas(canvas, offsetX, offsetY, bitmapWidth, bitmapHeight, bitmapCanvas);
|
|
6499
|
-
const { bitmap } = await imageToBitmap(bitmapCanvas, bitmapWidth, bitmapHeight, colors, bitmapColorIndices, numberOfColors);
|
|
6500
|
-
bitmapRow.push(bitmap);
|
|
6501
|
-
offsetX += bitmapWidth;
|
|
6502
|
-
}
|
|
6503
|
-
offsetY += bitmapHeight;
|
|
6504
|
-
}
|
|
6505
|
-
}
|
|
6506
|
-
return { bitmapRows, colors };
|
|
6507
|
-
}
|
|
6508
|
-
async function imageToBitmaps(image, width, height, numberOfColors, mtu) {
|
|
6509
|
-
const canvas = resizeImage(image, width, height);
|
|
6510
|
-
return canvasToBitmaps(canvas, numberOfColors, mtu);
|
|
6511
|
-
}
|
|
6512
6429
|
function getBitmapNumberOfBytes(bitmap) {
|
|
6513
6430
|
const pixelDepth = numberOfColorsToPixelDepth(bitmap.numberOfColors);
|
|
6514
6431
|
const pixelsPerByte = pixelDepthToPixelsPerByte(pixelDepth);
|
|
@@ -6528,127 +6445,6 @@ function assertValidBitmapPixels(bitmap) {
|
|
|
6528
6445
|
_console$q.assertRangeWithError(`bitmap.pixels[${index}]`, pixel, 0, bitmap.numberOfColors - 1);
|
|
6529
6446
|
});
|
|
6530
6447
|
}
|
|
6531
|
-
async function canvasToSprite(canvas, spriteName, numberOfColors, paletteName, overridePalette, spriteSheet, paletteOffset = 0) {
|
|
6532
|
-
const { width, height } = canvas;
|
|
6533
|
-
let palette = spriteSheet.palettes?.find((palette) => palette.name == paletteName);
|
|
6534
|
-
if (!palette) {
|
|
6535
|
-
palette = {
|
|
6536
|
-
name: paletteName,
|
|
6537
|
-
numberOfColors,
|
|
6538
|
-
colors: new Array(numberOfColors).fill("#000000"),
|
|
6539
|
-
};
|
|
6540
|
-
spriteSheet.palettes = spriteSheet.palettes || [];
|
|
6541
|
-
spriteSheet.palettes?.push(palette);
|
|
6542
|
-
}
|
|
6543
|
-
_console$q.log("pallete", palette);
|
|
6544
|
-
const sprite = {
|
|
6545
|
-
name: spriteName,
|
|
6546
|
-
width,
|
|
6547
|
-
height,
|
|
6548
|
-
paletteSwaps: [],
|
|
6549
|
-
commands: [],
|
|
6550
|
-
};
|
|
6551
|
-
const results = await quantizeCanvas(canvas, numberOfColors, !overridePalette ? palette.colors : undefined);
|
|
6552
|
-
const blob = results.blob;
|
|
6553
|
-
const colorIndices = results.colorIndices;
|
|
6554
|
-
if (overridePalette) {
|
|
6555
|
-
results.colors.forEach((color, index) => {
|
|
6556
|
-
palette.colors[index + paletteOffset] = color;
|
|
6557
|
-
});
|
|
6558
|
-
}
|
|
6559
|
-
sprite.commands.push({
|
|
6560
|
-
type: "selectBitmapColors",
|
|
6561
|
-
bitmapColorPairs: new Array(numberOfColors).fill(0).map((_, index) => ({
|
|
6562
|
-
bitmapColorIndex: index,
|
|
6563
|
-
colorIndex: index + paletteOffset,
|
|
6564
|
-
})),
|
|
6565
|
-
});
|
|
6566
|
-
const bitmap = {
|
|
6567
|
-
numberOfColors,
|
|
6568
|
-
pixels: colorIndices,
|
|
6569
|
-
width,
|
|
6570
|
-
height,
|
|
6571
|
-
};
|
|
6572
|
-
sprite.commands.push({ type: "drawBitmap", offsetX: 0, offsetY: 0, bitmap });
|
|
6573
|
-
const spriteIndex = spriteSheet.sprites.findIndex((sprite) => sprite.name == spriteName);
|
|
6574
|
-
if (spriteIndex == -1) {
|
|
6575
|
-
spriteSheet.sprites.push(sprite);
|
|
6576
|
-
}
|
|
6577
|
-
else {
|
|
6578
|
-
_console$q.log(`overwriting spriteIndex ${spriteIndex}`);
|
|
6579
|
-
spriteSheet.sprites[spriteIndex] = sprite;
|
|
6580
|
-
}
|
|
6581
|
-
return { sprite, blob };
|
|
6582
|
-
}
|
|
6583
|
-
async function imageToSprite(image, spriteName, width, height, numberOfColors, paletteName, overridePalette, spriteSheet, paletteOffset = 0) {
|
|
6584
|
-
const canvas = resizeImage(image, width, height);
|
|
6585
|
-
return canvasToSprite(canvas, spriteName, numberOfColors, paletteName, overridePalette, spriteSheet, paletteOffset);
|
|
6586
|
-
}
|
|
6587
|
-
const spriteSheetWithSingleBitmapCommandLength = calculateSpriteSheetHeaderLength(1) + drawSpriteBitmapCommandHeaderLength;
|
|
6588
|
-
function spriteSheetWithBitmapCommandAndSelectBitmapColorsLength(numberOfColors) {
|
|
6589
|
-
return (spriteSheetWithSingleBitmapCommandLength + (1 + 1 + numberOfColors * 2));
|
|
6590
|
-
}
|
|
6591
|
-
async function canvasToSpriteSheet(canvas, spriteSheetName, numberOfColors, paletteName, maxFileLength) {
|
|
6592
|
-
const spriteSheet = {
|
|
6593
|
-
name: spriteSheetName,
|
|
6594
|
-
palettes: [],
|
|
6595
|
-
paletteSwaps: [],
|
|
6596
|
-
sprites: [],
|
|
6597
|
-
};
|
|
6598
|
-
if (maxFileLength == undefined) {
|
|
6599
|
-
await canvasToSprite(canvas, "image", numberOfColors, paletteName, true, spriteSheet);
|
|
6600
|
-
}
|
|
6601
|
-
else {
|
|
6602
|
-
const { width, height } = canvas;
|
|
6603
|
-
const numberOfPixels = width * height;
|
|
6604
|
-
const pixelDepth = DisplayPixelDepths.find((pixelDepth) => pixelDepthToNumberOfColors(pixelDepth) >= numberOfColors);
|
|
6605
|
-
_console$q.assertWithError(pixelDepth, `no pixelDepth found that covers ${numberOfColors} colors`);
|
|
6606
|
-
const pixelsPerByte = pixelDepthToPixelsPerByte(pixelDepth);
|
|
6607
|
-
const numberOfBytes = Math.ceil(numberOfPixels / pixelsPerByte);
|
|
6608
|
-
_console$q.log({
|
|
6609
|
-
width,
|
|
6610
|
-
height,
|
|
6611
|
-
numberOfPixels,
|
|
6612
|
-
pixelDepth,
|
|
6613
|
-
pixelsPerByte,
|
|
6614
|
-
numberOfBytes,
|
|
6615
|
-
maxFileLength,
|
|
6616
|
-
});
|
|
6617
|
-
const maxPixelDataLength = maxFileLength -
|
|
6618
|
-
(spriteSheetWithBitmapCommandAndSelectBitmapColorsLength(numberOfColors) +
|
|
6619
|
-
5);
|
|
6620
|
-
const imageRowPixelDataLength = Math.ceil(width / pixelsPerByte);
|
|
6621
|
-
const maxSpriteHeight = Math.floor(maxPixelDataLength / imageRowPixelDataLength);
|
|
6622
|
-
if (maxSpriteHeight >= height) {
|
|
6623
|
-
_console$q.log("image is small enough for a single sprite");
|
|
6624
|
-
await canvasToSprite(canvas, "image", numberOfColors, paletteName, true, spriteSheet);
|
|
6625
|
-
}
|
|
6626
|
-
else {
|
|
6627
|
-
const { colors } = await quantizeCanvas(canvas, numberOfColors);
|
|
6628
|
-
spriteSheet.palettes?.push({ name: paletteName, numberOfColors, colors });
|
|
6629
|
-
let offsetY = 0;
|
|
6630
|
-
let imageIndex = 0;
|
|
6631
|
-
const spriteCanvas = document.createElement("canvas");
|
|
6632
|
-
while (offsetY < height) {
|
|
6633
|
-
const spriteHeight = Math.min(maxSpriteHeight, height - offsetY);
|
|
6634
|
-
cropCanvas(canvas, 0, offsetY, width, spriteHeight, spriteCanvas);
|
|
6635
|
-
offsetY += spriteHeight;
|
|
6636
|
-
_console$q.log(`cropping sprite ${imageIndex}`, {
|
|
6637
|
-
offsetY,
|
|
6638
|
-
width,
|
|
6639
|
-
spriteHeight,
|
|
6640
|
-
});
|
|
6641
|
-
await canvasToSprite(spriteCanvas, `image${imageIndex}`, numberOfColors, paletteName, false, spriteSheet);
|
|
6642
|
-
imageIndex++;
|
|
6643
|
-
}
|
|
6644
|
-
}
|
|
6645
|
-
}
|
|
6646
|
-
return spriteSheet;
|
|
6647
|
-
}
|
|
6648
|
-
async function imageToSpriteSheet(image, spriteSheetName, width, height, numberOfColors, paletteName, maxFileLength) {
|
|
6649
|
-
const canvas = resizeImage(image, width, height);
|
|
6650
|
-
return canvasToSpriteSheet(canvas, spriteSheetName, numberOfColors, paletteName, maxFileLength);
|
|
6651
|
-
}
|
|
6652
6448
|
|
|
6653
6449
|
const _console$p = createConsole("DisplayManagerInterface", { log: false });
|
|
6654
6450
|
async function runDisplayContextCommand(displayManager, command, sendImmediately) {
|
|
@@ -14668,9 +14464,6 @@ exports.VibrationLocations = VibrationLocations;
|
|
|
14668
14464
|
exports.VibrationTypes = VibrationTypes;
|
|
14669
14465
|
exports.VibrationWaveformEffects = VibrationWaveformEffects;
|
|
14670
14466
|
exports.WebSocketServer = WebSocketServer;
|
|
14671
|
-
exports.canvasToBitmaps = canvasToBitmaps;
|
|
14672
|
-
exports.canvasToSprite = canvasToSprite;
|
|
14673
|
-
exports.canvasToSpriteSheet = canvasToSpriteSheet;
|
|
14674
14467
|
exports.displayCurveTypeToNumberOfControlPoints = displayCurveTypeToNumberOfControlPoints;
|
|
14675
14468
|
exports.englishRegex = englishRegex;
|
|
14676
14469
|
exports.fontToSpriteSheet = fontToSpriteSheet;
|
|
@@ -14679,18 +14472,12 @@ exports.getFontMetrics = getFontMetrics;
|
|
|
14679
14472
|
exports.getFontUnicodeRange = getFontUnicodeRange;
|
|
14680
14473
|
exports.getMaxSpriteSheetSize = getMaxSpriteSheetSize;
|
|
14681
14474
|
exports.hexToRGB = hexToRGB;
|
|
14682
|
-
exports.imageToBitmaps = imageToBitmaps;
|
|
14683
|
-
exports.imageToSprite = imageToSprite;
|
|
14684
|
-
exports.imageToSpriteSheet = imageToSpriteSheet;
|
|
14685
14475
|
exports.intersectWireframes = intersectWireframes;
|
|
14686
14476
|
exports.isWireframePolygon = isWireframePolygon;
|
|
14687
14477
|
exports.maxDisplayScale = maxDisplayScale;
|
|
14688
14478
|
exports.mergeWireframes = mergeWireframes;
|
|
14689
14479
|
exports.parseFont = parseFont;
|
|
14690
14480
|
exports.pixelDepthToNumberOfColors = pixelDepthToNumberOfColors;
|
|
14691
|
-
exports.quantizeImage = quantizeImage;
|
|
14692
|
-
exports.resizeAndQuantizeImage = resizeAndQuantizeImage;
|
|
14693
|
-
exports.resizeImage = resizeImage;
|
|
14694
14481
|
exports.rgbToHex = rgbToHex;
|
|
14695
14482
|
exports.setAllConsoleLevelFlags = setAllConsoleLevelFlags;
|
|
14696
14483
|
exports.setConsoleLevelFlagsForType = setConsoleLevelFlagsForType;
|