asciify-engine 1.0.6 → 1.0.8

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/index.d.cts CHANGED
@@ -160,9 +160,15 @@ 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 professional 3-line embed snippet.
164
- * The render runtime is loaded from jsDelivr CDN (free, served from npm).
165
- * Only the base64-encoded frame data is inlined.
163
+ * Generate a clean 2-line embed snippet.
164
+ *
165
+ * All data lives in data attributes on the <canvas>.
166
+ * The <script> tag is always the same CDN line — identical across all embeds,
167
+ * so browsers/CDNs cache it once and reuse it everywhere.
168
+ *
169
+ * Output:
170
+ * <canvas data-asciify-id="ar-xxx" data-asciify-src="…" data-asciify-opts="{…}" width="…" height="…"></canvas>
171
+ * <script src="https://cdn.jsdelivr.net/npm/asciify-engine@x.x.x/dist/embed.js" async></script>
166
172
  */
167
173
  declare function generateEmbedCode(frame: AsciiFrame, options: AsciiOptions, width: number, height: number): string;
168
174
  /**
package/dist/index.d.ts CHANGED
@@ -160,9 +160,15 @@ 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 professional 3-line embed snippet.
164
- * The render runtime is loaded from jsDelivr CDN (free, served from npm).
165
- * Only the base64-encoded frame data is inlined.
163
+ * Generate a clean 2-line embed snippet.
164
+ *
165
+ * All data lives in data attributes on the <canvas>.
166
+ * The <script> tag is always the same CDN line — identical across all embeds,
167
+ * so browsers/CDNs cache it once and reuse it everywhere.
168
+ *
169
+ * Output:
170
+ * <canvas data-asciify-id="ar-xxx" data-asciify-src="…" data-asciify-opts="{…}" width="…" height="…"></canvas>
171
+ * <script src="https://cdn.jsdelivr.net/npm/asciify-engine@x.x.x/dist/embed.js" async></script>
166
172
  */
167
173
  declare function generateEmbedCode(frame: AsciiFrame, options: AsciiOptions, width: number, height: number): string;
168
174
  /**
package/dist/index.js CHANGED
@@ -717,22 +717,24 @@ function renderFrameToCanvas(ctx, frame, options, canvasWidth, canvasHeight, tim
717
717
  }
718
718
  ctx.globalAlpha = 1;
719
719
  }
720
- function serializeFrame(frame, includeChars) {
720
+ function serializeFrame(frame, fullColor) {
721
721
  const rows = frame.length;
722
722
  const cols = rows > 0 ? frame[0].length : 0;
723
- const buf = new Uint8Array(rows * cols * 5);
724
- let i = 0;
723
+ const stride = fullColor ? 4 : 2;
724
+ const buf = new Uint8Array(1 + rows * cols * stride);
725
+ buf[0] = stride;
726
+ let i = 1;
725
727
  for (let y = 0; y < rows; y++) {
726
728
  for (let x = 0; x < cols; x++) {
727
729
  const cell = frame[y][x];
728
- buf[i++] = cell.r;
729
- buf[i++] = cell.g;
730
- buf[i++] = cell.b;
731
- buf[i++] = cell.a;
732
- if (includeChars) {
733
- buf[i++] = cell.char.charCodeAt(0) & 255;
730
+ if (fullColor) {
731
+ buf[i++] = cell.r;
732
+ buf[i++] = cell.g;
733
+ buf[i++] = cell.b;
734
+ buf[i++] = cell.a;
734
735
  } else {
735
736
  buf[i++] = Math.round(0.299 * cell.r + 0.587 * cell.g + 0.114 * cell.b);
737
+ buf[i++] = cell.a;
736
738
  }
737
739
  }
738
740
  }
@@ -830,7 +832,7 @@ async function asciifyVideo(source, canvas, { fontSize = 10, style = "classic",
830
832
  cancelAnimationFrame(animId);
831
833
  };
832
834
  }
833
- var EMBED_CDN_VERSION = "1.0.5";
835
+ var EMBED_CDN_VERSION = "1.0.8";
834
836
  function buildEmbedOpts(options, rows, cols, width, height, fps, animated) {
835
837
  const o = {
836
838
  r: rows,
@@ -854,32 +856,31 @@ function buildEmbedOpts(options, rows, cols, width, height, fps, animated) {
854
856
  if (animated) o.anim = true;
855
857
  return JSON.stringify(o);
856
858
  }
859
+ var CDN_SCRIPT = `<script src="https://cdn.jsdelivr.net/npm/asciify-engine@${EMBED_CDN_VERSION}/dist/embed.js" async></script>`;
857
860
  function generateEmbedCode(frame, options, width, height) {
858
861
  const rows = frame.length;
859
862
  if (rows === 0) return "";
860
863
  const cols = frame[0].length;
861
- const isDots = options.renderMode === "dots";
862
- const data = serializeFrame(frame, !isDots);
864
+ const isFullColor = options.colorMode === "fullcolor";
865
+ const data = serializeFrame(frame, isFullColor);
863
866
  const id = `ar-${Math.random().toString(36).slice(2, 9)}`;
864
867
  const opts = buildEmbedOpts(options, rows, cols, width, height);
865
868
  return `<!-- Asciify Embed -->
866
- <canvas id="${id}" width="${width}" height="${height}" style="display:block"></canvas>
867
- <script src="https://cdn.jsdelivr.net/npm/asciify-engine@${EMBED_CDN_VERSION}/dist/embed.js"></script>
868
- <script>Asciify('${id}','${data}',${opts})</script>
869
+ <canvas data-asciify-id="${id}" data-asciify-src='"${data}"' data-asciify-opts='${opts}' width="${width}" height="${height}"></canvas>
870
+ ${CDN_SCRIPT}
869
871
  <!-- /Asciify Embed -->`;
870
872
  }
871
873
  function generateAnimatedEmbedCode(frames, options, fps, width, height) {
872
874
  if (frames.length === 0) return "";
873
875
  const rows = frames[0].length;
874
876
  const cols = frames[0][0].length;
875
- const isDots = options.renderMode === "dots";
876
- const allData = frames.map((f) => serializeFrame(f, !isDots));
877
+ const isFullColor = options.colorMode === "fullcolor";
878
+ const allData = frames.map((f) => serializeFrame(f, isFullColor));
877
879
  const id = `ar-${Math.random().toString(36).slice(2, 9)}`;
878
880
  const opts = buildEmbedOpts(options, rows, cols, width, height, fps, true);
879
881
  return `<!-- Asciify Animated Embed -->
880
- <canvas id="${id}" width="${width}" height="${height}" style="display:block"></canvas>
881
- <script src="https://cdn.jsdelivr.net/npm/asciify-engine@${EMBED_CDN_VERSION}/dist/embed.js"></script>
882
- <script>Asciify('${id}',${JSON.stringify(allData)},${opts})</script>
882
+ <canvas data-asciify-id="${id}" data-asciify-src='${JSON.stringify(allData)}' data-asciify-opts='${opts}' width="${width}" height="${height}"></canvas>
883
+ ${CDN_SCRIPT}
883
884
  <!-- /Asciify Animated Embed -->`;
884
885
  }
885
886
  function _fade(t) {