asciify-engine 1.0.7 → 1.0.9
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 +12 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -3
- package/dist/index.d.ts +13 -3
- package/dist/index.js +12 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -160,9 +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
|
|
164
|
-
*
|
|
165
|
-
*
|
|
163
|
+
* Generate a clean embed snippet.
|
|
164
|
+
*
|
|
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
|
|
169
|
+
*
|
|
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 -->
|
|
166
176
|
*/
|
|
167
177
|
declare function generateEmbedCode(frame: AsciiFrame, options: AsciiOptions, width: number, height: number): string;
|
|
168
178
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -160,9 +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
|
|
164
|
-
*
|
|
165
|
-
*
|
|
163
|
+
* Generate a clean embed snippet.
|
|
164
|
+
*
|
|
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
|
|
169
|
+
*
|
|
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 -->
|
|
166
176
|
*/
|
|
167
177
|
declare function generateEmbedCode(frame: AsciiFrame, options: AsciiOptions, width: number, height: number): string;
|
|
168
178
|
/**
|
package/dist/index.js
CHANGED
|
@@ -832,7 +832,7 @@ async function asciifyVideo(source, canvas, { fontSize = 10, style = "classic",
|
|
|
832
832
|
cancelAnimationFrame(animId);
|
|
833
833
|
};
|
|
834
834
|
}
|
|
835
|
-
var EMBED_CDN_VERSION = "1.0.
|
|
835
|
+
var EMBED_CDN_VERSION = "1.0.9";
|
|
836
836
|
function buildEmbedOpts(options, rows, cols, width, height, fps, animated) {
|
|
837
837
|
const o = {
|
|
838
838
|
r: rows,
|
|
@@ -856,32 +856,33 @@ function buildEmbedOpts(options, rows, cols, width, height, fps, animated) {
|
|
|
856
856
|
if (animated) o.anim = true;
|
|
857
857
|
return JSON.stringify(o);
|
|
858
858
|
}
|
|
859
|
+
var CDN_SCRIPT = `<script src="https://cdn.jsdelivr.net/npm/asciify-engine@${EMBED_CDN_VERSION}/dist/embed.js" async></script>`;
|
|
859
860
|
function generateEmbedCode(frame, options, width, height) {
|
|
860
861
|
const rows = frame.length;
|
|
861
862
|
if (rows === 0) return "";
|
|
862
863
|
const cols = frame[0].length;
|
|
863
|
-
const
|
|
864
|
-
const data = serializeFrame(frame,
|
|
864
|
+
const isFullColor = options.colorMode === "fullcolor";
|
|
865
|
+
const data = serializeFrame(frame, isFullColor);
|
|
865
866
|
const id = `ar-${Math.random().toString(36).slice(2, 9)}`;
|
|
866
867
|
const opts = buildEmbedOpts(options, rows, cols, width, height);
|
|
867
868
|
return `<!-- Asciify Embed -->
|
|
868
|
-
<canvas id="${id}" width="${width}" height="${height}"
|
|
869
|
-
<script
|
|
870
|
-
|
|
869
|
+
<canvas id="${id}" data-asciify-opts='${opts}' width="${width}" height="${height}"></canvas>
|
|
870
|
+
<script type="application/json" id="${id}-d">"${data}"</script>
|
|
871
|
+
${CDN_SCRIPT}
|
|
871
872
|
<!-- /Asciify Embed -->`;
|
|
872
873
|
}
|
|
873
874
|
function generateAnimatedEmbedCode(frames, options, fps, width, height) {
|
|
874
875
|
if (frames.length === 0) return "";
|
|
875
876
|
const rows = frames[0].length;
|
|
876
877
|
const cols = frames[0][0].length;
|
|
877
|
-
const
|
|
878
|
-
const allData = frames.map((f) => serializeFrame(f,
|
|
878
|
+
const isFullColor = options.colorMode === "fullcolor";
|
|
879
|
+
const allData = frames.map((f) => serializeFrame(f, isFullColor));
|
|
879
880
|
const id = `ar-${Math.random().toString(36).slice(2, 9)}`;
|
|
880
881
|
const opts = buildEmbedOpts(options, rows, cols, width, height, fps, true);
|
|
881
882
|
return `<!-- Asciify Animated Embed -->
|
|
882
|
-
<canvas id="${id}" width="${width}" height="${height}"
|
|
883
|
-
<script
|
|
884
|
-
|
|
883
|
+
<canvas id="${id}" data-asciify-opts='${opts}' width="${width}" height="${height}"></canvas>
|
|
884
|
+
<script type="application/json" id="${id}-d">${JSON.stringify(allData)}</script>
|
|
885
|
+
${CDN_SCRIPT}
|
|
885
886
|
<!-- /Asciify Animated Embed -->`;
|
|
886
887
|
}
|
|
887
888
|
function _fade(t) {
|