@clypra-studio/engine 1.8.1 → 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.js CHANGED
@@ -1,28 +1,3 @@
1
- import {
2
- FontLoader,
3
- checkFontVariant,
4
- ensureFontsLoaded,
5
- getFontLoader,
6
- initializeFontSystem,
7
- injectFontVariantRules,
8
- resetFontLoader
9
- } from "./chunk-V5VSY64D.js";
10
- import {
11
- ALL_TRANSITIONS,
12
- TRANSITION_CATEGORIES,
13
- TRANSITION_PRESETS,
14
- TransitionRenderer,
15
- getAllTransitionTags,
16
- getAllTransitions,
17
- getRecommendedDuration,
18
- getTransitionById,
19
- getTransitionByRenderer,
20
- getTransitionCategories,
21
- getTransitionCountByCategory,
22
- getTransitionsByCategory,
23
- getTransitionsByTags,
24
- searchTransitions
25
- } from "./chunk-PU3Q4QI7.js";
26
1
  import {
27
2
  CANONICAL_RENDERER_VERSION,
28
3
  CANONICAL_SCHEMA_VERSION,
@@ -62,6 +37,15 @@ import {
62
37
  splitTextContent,
63
38
  validateTextTemplateArtifact
64
39
  } from "./chunk-JP44RJUI.js";
40
+ import {
41
+ FontLoader,
42
+ checkFontVariant,
43
+ ensureFontsLoaded,
44
+ getFontLoader,
45
+ initializeFontSystem,
46
+ injectFontVariantRules,
47
+ resetFontLoader
48
+ } from "./chunk-V5VSY64D.js";
65
49
  import {
66
50
  COMPOSITION_PRESETS,
67
51
  CanvasDevice,
@@ -123,6 +107,22 @@ import {
123
107
  textEffectConfigToScene,
124
108
  wrapTextToWidth
125
109
  } from "./chunk-YBOYDQU5.js";
110
+ import {
111
+ ALL_TRANSITIONS,
112
+ TRANSITION_CATEGORIES,
113
+ TRANSITION_PRESETS,
114
+ TransitionRenderer,
115
+ getAllTransitionTags,
116
+ getAllTransitions,
117
+ getRecommendedDuration,
118
+ getTransitionById,
119
+ getTransitionByRenderer,
120
+ getTransitionCategories,
121
+ getTransitionCountByCategory,
122
+ getTransitionsByCategory,
123
+ getTransitionsByTags,
124
+ searchTransitions
125
+ } from "./chunk-PU3Q4QI7.js";
126
126
  import {
127
127
  EFFECTS_REGISTRY,
128
128
  EffectEngine,
@@ -130,7 +130,6 @@ import {
130
130
  EffectRenderer,
131
131
  addNoise,
132
132
  blendColors,
133
- camera_exports,
134
133
  clearCanvas,
135
134
  effectMetadataToApi,
136
135
  generateEffectsManifest,
@@ -143,13 +142,11 @@ import {
143
142
  getEffectsByCategory,
144
143
  getEffectsByCategoryForApi,
145
144
  hexToRgba,
146
- light_exports,
147
145
  rgbaToComponents,
148
146
  searchEffects,
149
147
  searchEffectsForApi,
150
148
  withContext
151
- } from "./chunk-SH7HOGVX.js";
152
- import "./chunk-PZ5AY32C.js";
149
+ } from "./chunk-XHHAW7MS.js";
153
150
 
154
151
  // src/validation.ts
155
152
  import { z } from "zod";
@@ -17638,6 +17635,170 @@ function renderEvaluatedSceneToCanvas(scene, ctx, options = {}) {
17638
17635
  scene.nodes.forEach((node) => drawNode(ctx, node, scene.time));
17639
17636
  }
17640
17637
 
17638
+ // src/stickers/stickerScanner.ts
17639
+ var MAX_LOTTIE_BYTES = 300 * 1024;
17640
+ var MAX_ASSET_BYTES = 2 * 1024 * 1024;
17641
+ function scanLottieNodes(node, found = { expressions: 0, remoteUrls: 0 }) {
17642
+ if (Array.isArray(node)) {
17643
+ for (const item of node) {
17644
+ scanLottieNodes(item, found);
17645
+ }
17646
+ } else if (node && typeof node === "object") {
17647
+ if (typeof node.x === "string" && node.x.trim() !== "" && "k" in node) {
17648
+ found.expressions++;
17649
+ }
17650
+ for (const value of Object.values(node)) {
17651
+ scanLottieNodes(value, found);
17652
+ }
17653
+ } else if (typeof node === "string" && /^https?:\/\//i.test(node)) {
17654
+ found.remoteUrls++;
17655
+ }
17656
+ return found;
17657
+ }
17658
+ function inspectLottieJson(jsonOrString) {
17659
+ const errors = [];
17660
+ let json;
17661
+ if (typeof jsonOrString === "string") {
17662
+ try {
17663
+ json = JSON.parse(jsonOrString);
17664
+ } catch (err) {
17665
+ return { valid: false, errors: [`Lottie file is not valid JSON: ${err.message}`] };
17666
+ }
17667
+ } else {
17668
+ json = jsonOrString;
17669
+ }
17670
+ if (!json || typeof json !== "object") {
17671
+ return { valid: false, errors: ["Lottie data must be a JSON object"] };
17672
+ }
17673
+ for (const field of ["v", "fr", "ip", "op", "w", "h", "layers"]) {
17674
+ if (!(field in json)) {
17675
+ errors.push(`Lottie header missing required field "${field}"`);
17676
+ }
17677
+ }
17678
+ const found = scanLottieNodes(json);
17679
+ if (found.expressions > 0) {
17680
+ errors.push(`Lottie contains ${found.expressions} expression(s); expressions are strictly forbidden`);
17681
+ }
17682
+ if (found.remoteUrls > 0) {
17683
+ errors.push(`Lottie references ${found.remoteUrls} remote URL(s); all assets must be embedded`);
17684
+ }
17685
+ const fps = typeof json.fr === "number" && json.fr > 0 ? json.fr : 30;
17686
+ const ip = typeof json.ip === "number" ? json.ip : 0;
17687
+ const op = typeof json.op === "number" ? json.op : ip;
17688
+ const durationMs = Math.round((op - ip) / fps * 1e3);
17689
+ const layerCount = Array.isArray(json.layers) ? json.layers.length : 0;
17690
+ const width = Math.round(Number(json.w || 0));
17691
+ const height = Math.round(Number(json.h || 0));
17692
+ if (width < 16 || width > 2048) {
17693
+ errors.push(`Lottie width ${width} is outside permitted range [16, 2048]`);
17694
+ }
17695
+ if (height < 16 || height > 2048) {
17696
+ errors.push(`Lottie height ${height} is outside permitted range [16, 2048]`);
17697
+ }
17698
+ return {
17699
+ valid: errors.length === 0,
17700
+ errors,
17701
+ dimensions: { width, height },
17702
+ animation: {
17703
+ durationMs: Math.max(1, durationMs),
17704
+ fps,
17705
+ loop: true,
17706
+ lottie: {
17707
+ layerCount,
17708
+ hasExpressions: false
17709
+ }
17710
+ }
17711
+ };
17712
+ }
17713
+ function inspectStickerAsset(data, filenameHint = "") {
17714
+ const errors = [];
17715
+ let u8;
17716
+ if (typeof data === "string") {
17717
+ u8 = new TextEncoder().encode(data);
17718
+ } else if (data instanceof Uint8Array) {
17719
+ u8 = data;
17720
+ } else {
17721
+ u8 = new Uint8Array(data);
17722
+ }
17723
+ const bytes = u8.length;
17724
+ 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;
17725
+ 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;
17726
+ const isJson = !isPng && !isWebp && (filenameHint.toLowerCase().endsWith(".json") || u8[0] === 123);
17727
+ const isSvg = !isPng && !isWebp && !isJson && (filenameHint.toLowerCase().endsWith(".svg") || u8[0] === 60);
17728
+ if (isJson) {
17729
+ if (bytes > MAX_LOTTIE_BYTES) {
17730
+ errors.push(`Lottie file size (${bytes} bytes) exceeds maximum limit of ${MAX_LOTTIE_BYTES} bytes (300 KB)`);
17731
+ }
17732
+ const text = new TextDecoder("utf8").decode(u8);
17733
+ const lottieScan = inspectLottieJson(text);
17734
+ if (!lottieScan.valid) {
17735
+ errors.push(...lottieScan.errors);
17736
+ }
17737
+ return {
17738
+ valid: errors.length === 0,
17739
+ errors,
17740
+ bytes,
17741
+ mime: "application/json",
17742
+ dimensions: lottieScan.dimensions,
17743
+ animation: lottieScan.animation
17744
+ };
17745
+ }
17746
+ if (bytes > MAX_ASSET_BYTES) {
17747
+ errors.push(`Asset file size (${bytes} bytes) exceeds maximum limit of ${MAX_ASSET_BYTES} bytes (2 MB)`);
17748
+ }
17749
+ if (isPng) {
17750
+ let width = 0;
17751
+ let height = 0;
17752
+ if (u8.length >= 24) {
17753
+ const view = new DataView(u8.buffer, u8.byteOffset, u8.byteLength);
17754
+ width = view.getUint32(16);
17755
+ height = view.getUint32(20);
17756
+ }
17757
+ return {
17758
+ valid: errors.length === 0,
17759
+ errors,
17760
+ bytes,
17761
+ mime: "image/png",
17762
+ dimensions: width > 0 && height > 0 ? { width, height } : void 0
17763
+ };
17764
+ }
17765
+ if (isWebp) {
17766
+ return {
17767
+ valid: errors.length === 0,
17768
+ errors,
17769
+ bytes,
17770
+ mime: "image/webp"
17771
+ };
17772
+ }
17773
+ if (isSvg) {
17774
+ return {
17775
+ valid: errors.length === 0,
17776
+ errors,
17777
+ bytes,
17778
+ mime: "image/svg+xml"
17779
+ };
17780
+ }
17781
+ return {
17782
+ valid: false,
17783
+ errors: ["Unsupported file format; allowed formats are Lottie JSON, WebP, PNG, and SVG"],
17784
+ bytes,
17785
+ mime: "application/octet-stream"
17786
+ };
17787
+ }
17788
+ async function calculateSha256(data) {
17789
+ const u8 = typeof data === "string" ? new TextEncoder().encode(data) : data instanceof Uint8Array ? data : new Uint8Array(data);
17790
+ if (typeof crypto !== "undefined" && crypto.subtle) {
17791
+ const hashBuf = await crypto.subtle.digest("SHA-256", u8);
17792
+ return Array.from(new Uint8Array(hashBuf)).map((b) => b.toString(16).padStart(2, "0")).join("");
17793
+ }
17794
+ try {
17795
+ const nodeCrypto = await import("crypto");
17796
+ return nodeCrypto.createHash("sha256").update(u8).digest("hex");
17797
+ } catch {
17798
+ throw new Error("No cryptographic hash implementation available");
17799
+ }
17800
+ }
17801
+
17641
17802
  // src/index.ts
17642
17803
  var VERSION = "1.4.0";
17643
17804
  export {
@@ -17653,7 +17814,6 @@ export {
17653
17814
  CANONICAL_RENDERER_VERSION,
17654
17815
  CANONICAL_SCHEMA_VERSION,
17655
17816
  COMPOSITION_PRESETS,
17656
- camera_exports as CameraEffects,
17657
17817
  CanvasDevice,
17658
17818
  CommandBufferBuilder,
17659
17819
  CommandExecutor,
@@ -17705,8 +17865,9 @@ export {
17705
17865
  LOTTIE_TEMPLATE_PRESETS,
17706
17866
  LayerAnimationSchema,
17707
17867
  LayoutEngine,
17708
- light_exports as LightEffects,
17709
17868
  LiveBroadcastBridge,
17869
+ MAX_ASSET_BYTES,
17870
+ MAX_LOTTIE_BYTES,
17710
17871
  MediaEncoderRegistry,
17711
17872
  MediaImageEngine,
17712
17873
  MetricEngine,
@@ -17796,6 +17957,7 @@ export {
17796
17957
  calculateMediaFit,
17797
17958
  calculateResizeBounds,
17798
17959
  calculateRotationAngle,
17960
+ calculateSha256,
17799
17961
  canonicalContentHash,
17800
17962
  canonicalTemplateHash,
17801
17963
  canonicalizeSceneDocument,
@@ -17912,6 +18074,8 @@ export {
17912
18074
  injectSolidColor,
17913
18075
  injectText,
17914
18076
  injectTextStyle,
18077
+ inspectLottieJson,
18078
+ inspectStickerAsset,
17915
18079
  interpolateColorString,
17916
18080
  interpolateValue,
17917
18081
  isKeyframed,
@@ -17979,6 +18143,7 @@ export {
17979
18143
  runtimeAssetResolver,
17980
18144
  sampleVideoContextAtTime,
17981
18145
  scanLottieFonts,
18146
+ scanLottieNodes,
17982
18147
  scanTextLayers,
17983
18148
  sceneToConfig,
17984
18149
  searchEffects,