@clypra-studio/engine 1.9.0 → 1.10.0

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.cjs CHANGED
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/index.ts
@@ -83,6 +93,8 @@ __export(index_exports, {
83
93
  LayerAnimationSchema: () => LayerAnimationSchema,
84
94
  LayoutEngine: () => LayoutEngine,
85
95
  LiveBroadcastBridge: () => LiveBroadcastBridge,
96
+ MAX_ASSET_BYTES: () => MAX_ASSET_BYTES,
97
+ MAX_LOTTIE_BYTES: () => MAX_LOTTIE_BYTES,
86
98
  MediaEncoderRegistry: () => MediaEncoderRegistry,
87
99
  MediaImageEngine: () => MediaImageEngine,
88
100
  MetricEngine: () => MetricEngine,
@@ -172,6 +184,7 @@ __export(index_exports, {
172
184
  calculateMediaFit: () => calculateMediaFit,
173
185
  calculateResizeBounds: () => calculateResizeBounds,
174
186
  calculateRotationAngle: () => calculateRotationAngle,
187
+ calculateSha256: () => calculateSha256,
175
188
  canonicalContentHash: () => canonicalContentHash,
176
189
  canonicalTemplateHash: () => canonicalTemplateHash,
177
190
  canonicalizeSceneDocument: () => canonicalizeSceneDocument,
@@ -288,6 +301,8 @@ __export(index_exports, {
288
301
  injectSolidColor: () => injectSolidColor,
289
302
  injectText: () => injectText,
290
303
  injectTextStyle: () => injectTextStyle,
304
+ inspectLottieJson: () => inspectLottieJson,
305
+ inspectStickerAsset: () => inspectStickerAsset,
291
306
  interpolateColorString: () => interpolateColorString,
292
307
  interpolateValue: () => interpolateValue,
293
308
  isKeyframed: () => isKeyframed,
@@ -355,6 +370,7 @@ __export(index_exports, {
355
370
  runtimeAssetResolver: () => runtimeAssetResolver,
356
371
  sampleVideoContextAtTime: () => sampleVideoContextAtTime,
357
372
  scanLottieFonts: () => scanLottieFonts,
373
+ scanLottieNodes: () => scanLottieNodes,
358
374
  scanTextLayers: () => scanTextLayers,
359
375
  sceneToConfig: () => sceneToConfig,
360
376
  searchEffects: () => searchEffects,
@@ -24473,6 +24489,170 @@ function renderEvaluatedSceneToCanvas(scene, ctx, options = {}) {
24473
24489
  scene.nodes.forEach((node) => drawNode(ctx, node, scene.time));
24474
24490
  }
24475
24491
 
24492
+ // src/stickers/stickerScanner.ts
24493
+ var MAX_LOTTIE_BYTES = 300 * 1024;
24494
+ var MAX_ASSET_BYTES = 2 * 1024 * 1024;
24495
+ function scanLottieNodes(node, found = { expressions: 0, remoteUrls: 0 }) {
24496
+ if (Array.isArray(node)) {
24497
+ for (const item of node) {
24498
+ scanLottieNodes(item, found);
24499
+ }
24500
+ } else if (node && typeof node === "object") {
24501
+ if (typeof node.x === "string" && node.x.trim() !== "" && "k" in node) {
24502
+ found.expressions++;
24503
+ }
24504
+ for (const value of Object.values(node)) {
24505
+ scanLottieNodes(value, found);
24506
+ }
24507
+ } else if (typeof node === "string" && /^https?:\/\//i.test(node)) {
24508
+ found.remoteUrls++;
24509
+ }
24510
+ return found;
24511
+ }
24512
+ function inspectLottieJson(jsonOrString) {
24513
+ const errors = [];
24514
+ let json;
24515
+ if (typeof jsonOrString === "string") {
24516
+ try {
24517
+ json = JSON.parse(jsonOrString);
24518
+ } catch (err) {
24519
+ return { valid: false, errors: [`Lottie file is not valid JSON: ${err.message}`] };
24520
+ }
24521
+ } else {
24522
+ json = jsonOrString;
24523
+ }
24524
+ if (!json || typeof json !== "object") {
24525
+ return { valid: false, errors: ["Lottie data must be a JSON object"] };
24526
+ }
24527
+ for (const field of ["v", "fr", "ip", "op", "w", "h", "layers"]) {
24528
+ if (!(field in json)) {
24529
+ errors.push(`Lottie header missing required field "${field}"`);
24530
+ }
24531
+ }
24532
+ const found = scanLottieNodes(json);
24533
+ if (found.expressions > 0) {
24534
+ errors.push(`Lottie contains ${found.expressions} expression(s); expressions are strictly forbidden`);
24535
+ }
24536
+ if (found.remoteUrls > 0) {
24537
+ errors.push(`Lottie references ${found.remoteUrls} remote URL(s); all assets must be embedded`);
24538
+ }
24539
+ const fps = typeof json.fr === "number" && json.fr > 0 ? json.fr : 30;
24540
+ const ip = typeof json.ip === "number" ? json.ip : 0;
24541
+ const op = typeof json.op === "number" ? json.op : ip;
24542
+ const durationMs = Math.round((op - ip) / fps * 1e3);
24543
+ const layerCount = Array.isArray(json.layers) ? json.layers.length : 0;
24544
+ const width = Math.round(Number(json.w || 0));
24545
+ const height = Math.round(Number(json.h || 0));
24546
+ if (width < 16 || width > 2048) {
24547
+ errors.push(`Lottie width ${width} is outside permitted range [16, 2048]`);
24548
+ }
24549
+ if (height < 16 || height > 2048) {
24550
+ errors.push(`Lottie height ${height} is outside permitted range [16, 2048]`);
24551
+ }
24552
+ return {
24553
+ valid: errors.length === 0,
24554
+ errors,
24555
+ dimensions: { width, height },
24556
+ animation: {
24557
+ durationMs: Math.max(1, durationMs),
24558
+ fps,
24559
+ loop: true,
24560
+ lottie: {
24561
+ layerCount,
24562
+ hasExpressions: false
24563
+ }
24564
+ }
24565
+ };
24566
+ }
24567
+ function inspectStickerAsset(data, filenameHint = "") {
24568
+ const errors = [];
24569
+ let u8;
24570
+ if (typeof data === "string") {
24571
+ u8 = new TextEncoder().encode(data);
24572
+ } else if (data instanceof Uint8Array) {
24573
+ u8 = data;
24574
+ } else {
24575
+ u8 = new Uint8Array(data);
24576
+ }
24577
+ const bytes = u8.length;
24578
+ const isPng = u8.length >= 8 && u8[0] === 137 && u8[1] === 80 && u8[2] === 78 && u8[3] === 71 && u8[4] === 13 && u8[5] === 10 && u8[6] === 26 && u8[7] === 10;
24579
+ const isWebp = u8.length >= 12 && u8[0] === 82 && u8[1] === 73 && u8[2] === 70 && u8[3] === 70 && u8[8] === 87 && u8[9] === 69 && u8[10] === 66 && u8[11] === 80;
24580
+ const isJson = !isPng && !isWebp && (filenameHint.toLowerCase().endsWith(".json") || u8[0] === 123);
24581
+ const isSvg = !isPng && !isWebp && !isJson && (filenameHint.toLowerCase().endsWith(".svg") || u8[0] === 60);
24582
+ if (isJson) {
24583
+ if (bytes > MAX_LOTTIE_BYTES) {
24584
+ errors.push(`Lottie file size (${bytes} bytes) exceeds maximum limit of ${MAX_LOTTIE_BYTES} bytes (300 KB)`);
24585
+ }
24586
+ const text = new TextDecoder("utf8").decode(u8);
24587
+ const lottieScan = inspectLottieJson(text);
24588
+ if (!lottieScan.valid) {
24589
+ errors.push(...lottieScan.errors);
24590
+ }
24591
+ return {
24592
+ valid: errors.length === 0,
24593
+ errors,
24594
+ bytes,
24595
+ mime: "application/json",
24596
+ dimensions: lottieScan.dimensions,
24597
+ animation: lottieScan.animation
24598
+ };
24599
+ }
24600
+ if (bytes > MAX_ASSET_BYTES) {
24601
+ errors.push(`Asset file size (${bytes} bytes) exceeds maximum limit of ${MAX_ASSET_BYTES} bytes (2 MB)`);
24602
+ }
24603
+ if (isPng) {
24604
+ let width = 0;
24605
+ let height = 0;
24606
+ if (u8.length >= 24) {
24607
+ const view = new DataView(u8.buffer, u8.byteOffset, u8.byteLength);
24608
+ width = view.getUint32(16);
24609
+ height = view.getUint32(20);
24610
+ }
24611
+ return {
24612
+ valid: errors.length === 0,
24613
+ errors,
24614
+ bytes,
24615
+ mime: "image/png",
24616
+ dimensions: width > 0 && height > 0 ? { width, height } : void 0
24617
+ };
24618
+ }
24619
+ if (isWebp) {
24620
+ return {
24621
+ valid: errors.length === 0,
24622
+ errors,
24623
+ bytes,
24624
+ mime: "image/webp"
24625
+ };
24626
+ }
24627
+ if (isSvg) {
24628
+ return {
24629
+ valid: errors.length === 0,
24630
+ errors,
24631
+ bytes,
24632
+ mime: "image/svg+xml"
24633
+ };
24634
+ }
24635
+ return {
24636
+ valid: false,
24637
+ errors: ["Unsupported file format; allowed formats are Lottie JSON, WebP, PNG, and SVG"],
24638
+ bytes,
24639
+ mime: "application/octet-stream"
24640
+ };
24641
+ }
24642
+ async function calculateSha256(data) {
24643
+ const u8 = typeof data === "string" ? new TextEncoder().encode(data) : data instanceof Uint8Array ? data : new Uint8Array(data);
24644
+ if (typeof crypto !== "undefined" && crypto.subtle) {
24645
+ const hashBuf = await crypto.subtle.digest("SHA-256", u8);
24646
+ return Array.from(new Uint8Array(hashBuf)).map((b) => b.toString(16).padStart(2, "0")).join("");
24647
+ }
24648
+ try {
24649
+ const nodeCrypto = await import("crypto");
24650
+ return nodeCrypto.createHash("sha256").update(u8).digest("hex");
24651
+ } catch {
24652
+ throw new Error("No cryptographic hash implementation available");
24653
+ }
24654
+ }
24655
+
24476
24656
  // src/index.ts
24477
24657
  var VERSION = "1.4.0";
24478
24658
  // Annotate the CommonJS export names for ESM import in node:
@@ -24541,6 +24721,8 @@ var VERSION = "1.4.0";
24541
24721
  LayerAnimationSchema,
24542
24722
  LayoutEngine,
24543
24723
  LiveBroadcastBridge,
24724
+ MAX_ASSET_BYTES,
24725
+ MAX_LOTTIE_BYTES,
24544
24726
  MediaEncoderRegistry,
24545
24727
  MediaImageEngine,
24546
24728
  MetricEngine,
@@ -24630,6 +24812,7 @@ var VERSION = "1.4.0";
24630
24812
  calculateMediaFit,
24631
24813
  calculateResizeBounds,
24632
24814
  calculateRotationAngle,
24815
+ calculateSha256,
24633
24816
  canonicalContentHash,
24634
24817
  canonicalTemplateHash,
24635
24818
  canonicalizeSceneDocument,
@@ -24746,6 +24929,8 @@ var VERSION = "1.4.0";
24746
24929
  injectSolidColor,
24747
24930
  injectText,
24748
24931
  injectTextStyle,
24932
+ inspectLottieJson,
24933
+ inspectStickerAsset,
24749
24934
  interpolateColorString,
24750
24935
  interpolateValue,
24751
24936
  isKeyframed,
@@ -24813,6 +24998,7 @@ var VERSION = "1.4.0";
24813
24998
  runtimeAssetResolver,
24814
24999
  sampleVideoContextAtTime,
24815
25000
  scanLottieFonts,
25001
+ scanLottieNodes,
24816
25002
  scanTextLayers,
24817
25003
  sceneToConfig,
24818
25004
  searchEffects,