@algorisys/tinyfly 0.82.0 → 0.87.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.
Files changed (71) hide show
  1. package/README.md +13 -4
  2. package/bin/tinyfly.mjs +44 -6
  3. package/lib/addons/adapters.js +411 -248
  4. package/lib/addons/characters.js +1652 -1470
  5. package/lib/addons/dom-adapter-Cphr2HZn.js +372 -0
  6. package/lib/addons/gsap-compat.js +197 -187
  7. package/lib/addons/load-scene-vp14_Jj-.js +324 -0
  8. package/lib/addons/maps.js +1 -1
  9. package/lib/addons/scene-3d-webgl.js +240 -0
  10. package/lib/addons/scene-3d.js +306 -0
  11. package/lib/addons/shading-o5T_v9DT.js +89 -0
  12. package/lib/addons/{sketch-CA8ZXhxI.js → sketch-CYPUbk3Q.js} +2 -2
  13. package/lib/browser/tinyfly-scene-3d-webgl.iife.js +116 -0
  14. package/lib/browser/tinyfly-scene-3d.iife.js +3 -0
  15. package/lib/browser/tinyfly.iife.js +4 -4
  16. package/lib/browser/tinyfly.js +4333 -3726
  17. package/lib/browser/tinyfly.umd.js +4 -4
  18. package/lib/cli/tools.js +137 -22
  19. package/lib/embed/tinyfly-embed.iife.js +4 -4
  20. package/lib/embed/tinyfly-embed.js +921 -833
  21. package/lib/engine/tinyfly-engine.js +1022 -776
  22. package/lib/engine/tinyfly-engine.umd.cjs +2 -2
  23. package/lib/headless/headless.js +410 -8
  24. package/lib/player/tinyfly-player.es.js +459 -371
  25. package/lib/player/tinyfly-player.iife.js +2 -2
  26. package/lib/player/tinyfly-player.umd.js +2 -2
  27. package/lib/types/adapters/canvas/bloom.d.ts +33 -0
  28. package/lib/types/adapters/canvas/canvas-adapter.d.ts +36 -0
  29. package/lib/types/adapters/canvas/index.d.ts +2 -0
  30. package/lib/types/adapters/canvas/offscreen.d.ts +13 -0
  31. package/lib/types/adapters/transform-3d.d.ts +99 -0
  32. package/lib/types/adapters/webgl/webgl-adapter.d.ts +17 -0
  33. package/lib/types/browser/index.d.ts +2 -0
  34. package/lib/types/characters/character.d.ts +20 -1
  35. package/lib/types/characters/index.d.ts +2 -0
  36. package/lib/types/characters/rig/body-plan.d.ts +3 -1
  37. package/lib/types/characters/rig/skeleton.d.ts +57 -0
  38. package/lib/types/characters/scene-objects.d.ts +2 -0
  39. package/lib/types/compat/gsap/vars.d.ts +8 -0
  40. package/lib/types/engine/core/bake.d.ts +3 -1
  41. package/lib/types/engine/index.d.ts +1 -0
  42. package/lib/types/engine/interpolation/interpolators.d.ts +10 -3
  43. package/lib/types/engine/math/index.d.ts +11 -0
  44. package/lib/types/engine/math/mat4.d.ts +37 -0
  45. package/lib/types/engine/math/quat.d.ts +39 -0
  46. package/lib/types/engine/math/vec3.d.ts +16 -0
  47. package/lib/types/engine/types.d.ts +23 -2
  48. package/lib/types/headless/index.d.ts +1 -0
  49. package/lib/types/headless/loop-check.d.ts +41 -0
  50. package/lib/types/headless/node-video.d.ts +8 -0
  51. package/lib/types/headless/video-scene.d.ts +7 -1
  52. package/lib/types/scene-3d/camera.d.ts +27 -0
  53. package/lib/types/scene-3d/canvas-2d-renderer.d.ts +21 -0
  54. package/lib/types/scene-3d/geometry/extrude.d.ts +17 -0
  55. package/lib/types/scene-3d/geometry/mesh.d.ts +36 -0
  56. package/lib/types/scene-3d/geometry/primitives.d.ts +16 -0
  57. package/lib/types/scene-3d/geometry/triangulate.d.ts +24 -0
  58. package/lib/types/scene-3d/index.d.ts +20 -0
  59. package/lib/types/scene-3d/load-scene.d.ts +31 -0
  60. package/lib/types/scene-3d/object-kind.d.ts +54 -0
  61. package/lib/types/scene-3d/resolve-scene.d.ts +122 -0
  62. package/lib/types/scene-3d/scene-3d-adapter.d.ts +46 -0
  63. package/lib/types/scene-3d/scene-types.d.ts +192 -0
  64. package/lib/types/scene-3d/shading.d.ts +20 -0
  65. package/lib/types/scene-3d/validate-scene.d.ts +11 -0
  66. package/lib/types/scene-3d/webgl/gl-data.d.ts +29 -0
  67. package/lib/types/scene-3d/webgl/index.d.ts +16 -0
  68. package/lib/types/scene-3d/webgl/shaders.d.ts +29 -0
  69. package/lib/types/scene-3d/webgl/webgl2-renderer.d.ts +33 -0
  70. package/package.json +10 -2
  71. package/lib/addons/dom-adapter-CrNwoomd.js +0 -243
package/lib/cli/tools.js CHANGED
@@ -4,7 +4,10 @@ function isCubicBezierEasing(easing) {
4
4
  function isParametricEasing(easing) {
5
5
  return typeof easing === "object" && easing !== null && easing.type !== "cubic-bezier";
6
6
  }
7
- const FORMAT_VERSION = 1;
7
+ const FORMAT_VERSION = 2;
8
+ function formatVersionFor(tracks) {
9
+ return tracks.some((track) => track.interpolation !== void 0) ? 2 : 1;
10
+ }
8
11
  function isTextTrack(track) {
9
12
  return track.property === "text" && "textConfig" in track;
10
13
  }
@@ -448,9 +451,9 @@ function arcToCubics(x1, y1, rxIn, ryIn, rotationDeg, largeArc, sweep, x2, y2) {
448
451
  const cx = cosPhi * cxp - sinPhi * cyp + (x1 + x2) / 2;
449
452
  const cy = sinPhi * cxp + cosPhi * cyp + (y1 + y2) / 2;
450
453
  const angle = (ux, uy, vx, vy) => {
451
- const dot = ux * vx + uy * vy;
454
+ const dot2 = ux * vx + uy * vy;
452
455
  const len = Math.sqrt((ux * ux + uy * uy) * (vx * vx + vy * vy));
453
- const a = Math.acos(Math.max(-1, Math.min(1, dot / len)));
456
+ const a = Math.acos(Math.max(-1, Math.min(1, dot2 / len)));
454
457
  return ux * vy - uy * vx < 0 ? -a : a;
455
458
  };
456
459
  const theta1 = angle(1, 0, (x1p - cxp) / rx, (y1p - cyp) / ry);
@@ -660,12 +663,12 @@ function parsePath(pathData) {
660
663
  for (let i = 0; i < segments.length; ) {
661
664
  const index = segments[i].subpath;
662
665
  let end = i;
663
- let length = 0;
664
- while (end < segments.length && segments[end].subpath === index) length += segments[end++].length;
666
+ let length2 = 0;
667
+ while (end < segments.length && segments[end].subpath === index) length2 += segments[end++].length;
665
668
  const first = segments[i];
666
669
  const last = segments[end - 1];
667
670
  const closed = closedSubpaths.has(index) || Math.abs(last.endX - first.startX) < 1e-9 && Math.abs(last.endY - first.startY) < 1e-9;
668
- subpaths.push({ start: i, end, length, closed });
671
+ subpaths.push({ start: i, end, length: length2, closed });
669
672
  i = end;
670
673
  }
671
674
  const parsed = { segments, totalLength, subpaths };
@@ -939,6 +942,47 @@ function morphPath(from, to, progress, options = {}) {
939
942
  function isPathData(value) {
940
943
  return /^\s*[Mm]\s*[-+]?(?:\d|\.\d)/.test(value);
941
944
  }
945
+ const NEARLY_EQUAL = 0.9995;
946
+ function identity() {
947
+ return [0, 0, 0, 1];
948
+ }
949
+ function dot(a, b) {
950
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
951
+ }
952
+ function length(q) {
953
+ return Math.hypot(q[0], q[1], q[2], q[3]);
954
+ }
955
+ function normalize(q) {
956
+ const len = length(q);
957
+ return len === 0 ? identity() : [q[0] / len, q[1] / len, q[2] / len, q[3] / len];
958
+ }
959
+ function slerp(a, b, t) {
960
+ const from = normalize(a);
961
+ let to = normalize(b);
962
+ let cos = dot(from, to);
963
+ if (cos < 0) {
964
+ to = [-to[0], -to[1], -to[2], -to[3]];
965
+ cos = -cos;
966
+ }
967
+ if (cos > NEARLY_EQUAL) {
968
+ return normalize([
969
+ from[0] + (to[0] - from[0]) * t,
970
+ from[1] + (to[1] - from[1]) * t,
971
+ from[2] + (to[2] - from[2]) * t,
972
+ from[3] + (to[3] - from[3]) * t
973
+ ]);
974
+ }
975
+ const angle = Math.acos(cos);
976
+ const sin = Math.sin(angle);
977
+ const wa = Math.sin((1 - t) * angle) / sin;
978
+ const wb = Math.sin(t * angle) / sin;
979
+ return normalize([
980
+ from[0] * wa + to[0] * wb,
981
+ from[1] * wa + to[1] * wb,
982
+ from[2] * wa + to[2] * wb,
983
+ from[3] * wa + to[3] * wb
984
+ ]);
985
+ }
942
986
  const interpolateNumber = (from, to, progress) => {
943
987
  return from + (to - from) * progress;
944
988
  };
@@ -1005,20 +1049,26 @@ const interpolateColor = (from, to, progress) => {
1005
1049
  return progress < 1 ? from : to;
1006
1050
  };
1007
1051
  const interpolateArray = (from, to, progress) => {
1008
- const length = Math.min(from.length, to.length);
1052
+ const length2 = Math.min(from.length, to.length);
1009
1053
  const result = [];
1010
- for (let i = 0; i < length; i++) {
1054
+ for (let i = 0; i < length2; i++) {
1011
1055
  result.push(interpolateNumber(from[i], to[i], progress));
1012
1056
  }
1013
1057
  return result;
1014
1058
  };
1059
+ const interpolateQuaternion = (from, to, progress) => {
1060
+ return slerp(from, to, progress);
1061
+ };
1015
1062
  const interpolateString = (from, to, progress) => {
1016
1063
  return progress < 1 ? from : to;
1017
1064
  };
1018
1065
  const interpolatePathString = (from, to, progress) => {
1019
1066
  return morphPath(from, to, progress);
1020
1067
  };
1021
- function getInterpolator(sampleValue) {
1068
+ function getInterpolator(sampleValue, interpolation) {
1069
+ if (interpolation === "slerp") {
1070
+ return interpolateQuaternion;
1071
+ }
1022
1072
  if (typeof sampleValue === "number") {
1023
1073
  return interpolateNumber;
1024
1074
  }
@@ -1129,7 +1179,7 @@ class TrackPlayer {
1129
1179
  const segmentProgress = (time - from.time) / segmentDuration;
1130
1180
  const easingFn = getEasingFunction(to.easing);
1131
1181
  const easedProgress = easingFn(segmentProgress);
1132
- const interpolator = getInterpolator(from.value);
1182
+ const interpolator = getInterpolator(from.value, this.track.interpolation);
1133
1183
  return interpolator(from.value, to.value, easedProgress);
1134
1184
  }
1135
1185
  /**
@@ -1260,15 +1310,15 @@ function textAt(config, progress, elapsedMs = 0) {
1260
1310
  const delay = Math.max(0, Math.min(0.999, config.revealDelay ?? 0));
1261
1311
  const reveal = Math.max(0, (p - delay) / (1 - delay));
1262
1312
  const revealed = Math.floor(reveal * toChars.length);
1263
- const length = config.tweenLength === false ? toChars.length : Math.round(fromChars.length + (toChars.length - fromChars.length) * p);
1313
+ const length2 = config.tweenLength === false ? toChars.length : Math.round(fromChars.length + (toChars.length - fromChars.length) * p);
1264
1314
  const pool = charactersFor(config.chars);
1265
1315
  const refreshRate = config.refreshRate ?? DEFAULT_REFRESH_RATE;
1266
1316
  const step = refreshRate > 0 ? Math.floor(elapsedMs * refreshRate / 1e3) : 0;
1267
1317
  const seed = config.seed ?? 1;
1268
1318
  let out = "";
1269
- for (let i = 0; i < length; i++) {
1270
- const settled = rightToLeft ? i >= length - revealed : i < revealed;
1271
- const target = rightToLeft ? toChars[toChars.length - (length - i)] : toChars[i];
1319
+ for (let i = 0; i < length2; i++) {
1320
+ const settled = rightToLeft ? i >= length2 - revealed : i < revealed;
1321
+ const target = rightToLeft ? toChars[toChars.length - (length2 - i)] : toChars[i];
1272
1322
  if (settled && target !== void 0) {
1273
1323
  out += target;
1274
1324
  } else if (target === " " || target === "\n") {
@@ -1716,7 +1766,7 @@ class Timeline {
1716
1766
  */
1717
1767
  toDefinition() {
1718
1768
  return {
1719
- formatVersion: FORMAT_VERSION,
1769
+ formatVersion: formatVersionFor(this._tracks),
1720
1770
  id: this.id,
1721
1771
  name: this.name,
1722
1772
  config: { ...this._config },
@@ -1865,6 +1915,7 @@ function deserializeTrack(data) {
1865
1915
  target: data.target,
1866
1916
  property: data.property,
1867
1917
  keyframes: data.keyframes,
1918
+ ...data.interpolation !== void 0 && { interpolation: data.interpolation },
1868
1919
  ...scheduling(data)
1869
1920
  });
1870
1921
  }
@@ -1883,6 +1934,32 @@ function deserializeTimeline(definition) {
1883
1934
  captions: definition.captions
1884
1935
  });
1885
1936
  }
1937
+ function fromQuat(q) {
1938
+ const [x, y, z, w] = q;
1939
+ return [
1940
+ 1 - 2 * (y * y + z * z),
1941
+ 2 * (x * y + z * w),
1942
+ 2 * (x * z - y * w),
1943
+ 0,
1944
+ 2 * (x * y - z * w),
1945
+ 1 - 2 * (x * x + z * z),
1946
+ 2 * (y * z + x * w),
1947
+ 0,
1948
+ 2 * (x * z + y * w),
1949
+ 2 * (y * z - x * w),
1950
+ 1 - 2 * (x * x + y * y),
1951
+ 0,
1952
+ 0,
1953
+ 0,
1954
+ 0,
1955
+ 1
1956
+ ];
1957
+ }
1958
+ function quaternionCss(value) {
1959
+ if (!Array.isArray(value) || value.length !== 4) return null;
1960
+ const matrix = fromQuat(normalize(value));
1961
+ return `matrix3d(${matrix.map((n) => Math.round(n * 1e6) / 1e6 + 0).join(", ")})`;
1962
+ }
1886
1963
  const FILTER_PROPERTIES = /* @__PURE__ */ new Set([
1887
1964
  "blur",
1888
1965
  "brightness",
@@ -1971,11 +2048,33 @@ const TRANSFORM_PROPERTIES = /* @__PURE__ */ new Set([
1971
2048
  "scaleZ",
1972
2049
  "skewX",
1973
2050
  "skewY",
2051
+ // A rotation as an [x, y, z, w] quaternion (a track with `interpolation: 'slerp'`)
2052
+ "quaternion",
1974
2053
  // Motion path properties
1975
2054
  "motionPathX",
1976
2055
  "motionPathY",
1977
2056
  "motionPathRotate"
1978
2057
  ]);
2058
+ const TRANSFORM_ORDER = [
2059
+ "x",
2060
+ "motionPathX",
2061
+ "y",
2062
+ "motionPathY",
2063
+ "z",
2064
+ "rotate",
2065
+ "rotateZ",
2066
+ "motionPathRotate",
2067
+ "rotateX",
2068
+ "rotateY",
2069
+ "quaternion",
2070
+ "scale",
2071
+ "scaleX",
2072
+ "scaleY",
2073
+ "scaleZ",
2074
+ "skewX",
2075
+ "skewY"
2076
+ ];
2077
+ const CHILD_PERSPECTIVE_PROPERTIES = /* @__PURE__ */ new Set(["childPerspective", "perspectiveOriginX", "perspectiveOriginY"]);
1979
2078
  const ORIGIN_PROPERTIES = /* @__PURE__ */ new Set(["originX", "originY"]);
1980
2079
  const CLIP_PROPERTIES = /* @__PURE__ */ new Set(["clipTop", "clipRight", "clipBottom", "clipLeft"]);
1981
2080
  const CANVAS_ONLY_PROPERTIES = /* @__PURE__ */ new Set(["drawOn"]);
@@ -2037,7 +2136,8 @@ class DOMAdapter {
2037
2136
  * Apply properties to a single element.
2038
2137
  */
2039
2138
  applyProperties(element, properties) {
2040
- const transformParts = [];
2139
+ let transforms = null;
2140
+ let childPerspective = null;
2041
2141
  let origin = null;
2042
2142
  let clip = null;
2043
2143
  let filter = null;
@@ -2050,10 +2150,9 @@ class DOMAdapter {
2050
2150
  if ((property === "rotate" || property === "rotateZ") && hasMotionPathRotate) continue;
2051
2151
  if (CANVAS_ONLY_PROPERTIES.has(property)) continue;
2052
2152
  if (TRANSFORM_PROPERTIES.has(property)) {
2053
- const transformValue = this.buildTransformPart(property, value);
2054
- if (transformValue) {
2055
- transformParts.push(transformValue);
2056
- }
2153
+ (transforms ??= {})[property] = value;
2154
+ } else if (CHILD_PERSPECTIVE_PROPERTIES.has(property)) {
2155
+ if (typeof value === "number") (childPerspective ??= {})[property] = value;
2057
2156
  } else if (ORIGIN_PROPERTIES.has(property)) {
2058
2157
  if (typeof value === "number") (origin ??= {})[property] = value;
2059
2158
  } else if (CLIP_PROPERTIES.has(property)) {
@@ -2076,14 +2175,29 @@ class DOMAdapter {
2076
2175
  if (typeof shine === "number") {
2077
2176
  this.applyShine(element, shine);
2078
2177
  }
2178
+ const transformParts = [];
2079
2179
  const perspective = properties.get("perspective");
2080
- if (typeof perspective === "number") {
2081
- transformParts.unshift(`perspective(${perspective}px)`);
2180
+ if (typeof perspective === "number" && perspective > 0) {
2181
+ transformParts.push(`perspective(${perspective}px)`);
2182
+ }
2183
+ if (transforms) {
2184
+ for (const property of TRANSFORM_ORDER) {
2185
+ const value = transforms[property];
2186
+ if (value === void 0) continue;
2187
+ const part = this.buildTransformPart(property, value);
2188
+ if (part) transformParts.push(part);
2189
+ }
2082
2190
  }
2083
2191
  if (transformParts.length > 0) {
2084
2192
  element.style.transform = transformParts.join(" ");
2085
2193
  ensureSvgTransformBox(element);
2086
2194
  }
2195
+ if (childPerspective) {
2196
+ if (childPerspective.childPerspective !== void 0) element.style.perspective = `${childPerspective.childPerspective}px`;
2197
+ if (childPerspective.perspectiveOriginX !== void 0 || childPerspective.perspectiveOriginY !== void 0) {
2198
+ element.style.perspectiveOrigin = `${childPerspective.perspectiveOriginX ?? 50}% ${childPerspective.perspectiveOriginY ?? 50}%`;
2199
+ }
2200
+ }
2087
2201
  if (origin) {
2088
2202
  const ox = origin.originX ?? 50;
2089
2203
  const oy = origin.originY ?? 50;
@@ -2105,6 +2219,7 @@ class DOMAdapter {
2105
2219
  * Build a transform function string for a property.
2106
2220
  */
2107
2221
  buildTransformPart(property, value) {
2222
+ if (property === "quaternion") return quaternionCss(value);
2108
2223
  if (typeof value !== "number") return null;
2109
2224
  switch (property) {
2110
2225
  case "x":