asciify-engine 1.0.8 → 1.0.10
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/dist/embed.js +1 -1
- package/dist/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -7
- package/dist/index.d.ts +11 -7
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -160,15 +160,19 @@ declare function asciifyGif(source: string | ArrayBuffer, canvas: HTMLCanvasElem
|
|
|
160
160
|
*/
|
|
161
161
|
declare function asciifyVideo(source: HTMLVideoElement | string, canvas: HTMLCanvasElement, { fontSize, style, options }?: AsciifySimpleOptions): Promise<() => void>;
|
|
162
162
|
/**
|
|
163
|
-
* Generate a clean
|
|
163
|
+
* Generate a clean embed snippet.
|
|
164
164
|
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
165
|
+
* Structure:
|
|
166
|
+
* <canvas id> — the render target, short and clean
|
|
167
|
+
* <script type=json id> — frame data lives here, clearly separated
|
|
168
|
+
* <script src=cdn> — always the same line, cached by browsers
|
|
168
169
|
*
|
|
169
|
-
* Output:
|
|
170
|
-
*
|
|
171
|
-
* <
|
|
170
|
+
* Output (static):
|
|
171
|
+
* <!-- Asciify Embed -->
|
|
172
|
+
* <canvas id="ar-xxx" data-asciify-opts="{…}" width="…" height="…"></canvas>
|
|
173
|
+
* <script type="application/json" id="ar-xxx-d">"BASE64"</script>
|
|
174
|
+
* <script src="cdn/embed.js" async></script>
|
|
175
|
+
* <!-- /Asciify Embed -->
|
|
172
176
|
*/
|
|
173
177
|
declare function generateEmbedCode(frame: AsciiFrame, options: AsciiOptions, width: number, height: number): string;
|
|
174
178
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -160,15 +160,19 @@ declare function asciifyGif(source: string | ArrayBuffer, canvas: HTMLCanvasElem
|
|
|
160
160
|
*/
|
|
161
161
|
declare function asciifyVideo(source: HTMLVideoElement | string, canvas: HTMLCanvasElement, { fontSize, style, options }?: AsciifySimpleOptions): Promise<() => void>;
|
|
162
162
|
/**
|
|
163
|
-
* Generate a clean
|
|
163
|
+
* Generate a clean embed snippet.
|
|
164
164
|
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
165
|
+
* Structure:
|
|
166
|
+
* <canvas id> — the render target, short and clean
|
|
167
|
+
* <script type=json id> — frame data lives here, clearly separated
|
|
168
|
+
* <script src=cdn> — always the same line, cached by browsers
|
|
168
169
|
*
|
|
169
|
-
* Output:
|
|
170
|
-
*
|
|
171
|
-
* <
|
|
170
|
+
* Output (static):
|
|
171
|
+
* <!-- Asciify Embed -->
|
|
172
|
+
* <canvas id="ar-xxx" data-asciify-opts="{…}" width="…" height="…"></canvas>
|
|
173
|
+
* <script type="application/json" id="ar-xxx-d">"BASE64"</script>
|
|
174
|
+
* <script src="cdn/embed.js" async></script>
|
|
175
|
+
* <!-- /Asciify Embed -->
|
|
172
176
|
*/
|
|
173
177
|
declare function generateEmbedCode(frame: AsciiFrame, options: AsciiOptions, width: number, height: number): string;
|
|
174
178
|
/**
|
package/dist/index.js
CHANGED
|
@@ -720,7 +720,7 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
|
|
|
720
720
|
function serializeFrame(frame, fullColor) {
|
|
721
721
|
const rows = frame.length;
|
|
722
722
|
const cols = rows > 0 ? frame[0].length : 0;
|
|
723
|
-
const stride = fullColor ?
|
|
723
|
+
const stride = fullColor ? 3 : 1;
|
|
724
724
|
const buf = new Uint8Array(1 + rows * cols * stride);
|
|
725
725
|
buf[0] = stride;
|
|
726
726
|
let i = 1;
|
|
@@ -731,10 +731,8 @@ function serializeFrame(frame, fullColor) {
|
|
|
731
731
|
buf[i++] = cell.r;
|
|
732
732
|
buf[i++] = cell.g;
|
|
733
733
|
buf[i++] = cell.b;
|
|
734
|
-
buf[i++] = cell.a;
|
|
735
734
|
} else {
|
|
736
735
|
buf[i++] = Math.round(0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b);
|
|
737
|
-
buf[i++] = cell.a;
|
|
738
736
|
}
|
|
739
737
|
}
|
|
740
738
|
}
|
|
@@ -832,7 +830,7 @@ async function asciifyVideo(source, canvas, { fontSize = 10, style = "classic",
|
|
|
832
830
|
cancelAnimationFrame(animId);
|
|
833
831
|
};
|
|
834
832
|
}
|
|
835
|
-
var EMBED_CDN_VERSION = "1.0.
|
|
833
|
+
var EMBED_CDN_VERSION = "1.0.10";
|
|
836
834
|
function buildEmbedOpts(options, rows, cols, width, height, fps, animated) {
|
|
837
835
|
const o = {
|
|
838
836
|
r: rows,
|
|
@@ -866,7 +864,8 @@ function generateEmbedCode(frame, options, width, height) {
|
|
|
866
864
|
const id = `ar-${Math.random().toString(36).slice(2, 9)}`;
|
|
867
865
|
const opts = buildEmbedOpts(options, rows, cols, width, height);
|
|
868
866
|
return `<!-- Asciify Embed -->
|
|
869
|
-
<canvas
|
|
867
|
+
<canvas id="${id}" data-asciify-opts='${opts}' width="${width}" height="${height}"></canvas>
|
|
868
|
+
<script type="application/json" id="${id}-d">"${data}"</script>
|
|
870
869
|
${CDN_SCRIPT}
|
|
871
870
|
<!-- /Asciify Embed -->`;
|
|
872
871
|
}
|
|
@@ -879,7 +878,8 @@ function generateAnimatedEmbedCode(frames, options, fps, width, height) {
|
|
|
879
878
|
const id = `ar-${Math.random().toString(36).slice(2, 9)}`;
|
|
880
879
|
const opts = buildEmbedOpts(options, rows, cols, width, height, fps, true);
|
|
881
880
|
return `<!-- Asciify Animated Embed -->
|
|
882
|
-
<canvas
|
|
881
|
+
<canvas id="${id}" data-asciify-opts='${opts}' width="${width}" height="${height}"></canvas>
|
|
882
|
+
<script type="application/json" id="${id}-d">${JSON.stringify(allData)}</script>
|
|
883
883
|
${CDN_SCRIPT}
|
|
884
884
|
<!-- /Asciify Animated Embed -->`;
|
|
885
885
|
}
|