c1.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. const no = (function (e) {
  2. $i(a, e);
  3. var t,
  4. n,
  5. r =
  6. ((t = a),
  7. (n = (function () {
  8. if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
  9. if (Reflect.construct.sham) return !1;
  10. if ("function" == typeof Proxy) return !0;
  11. try {
  12. return (
  13. Boolean.prototype.valueOf.call(
  14. Reflect.construct(Boolean, [], function () {})
  15. ),
  16. !0
  17. );
  18. } catch (e) {
  19. return !1;
  20. }
  21. })()),
  22. function () {
  23. var e,
  24. r = Zi(t);
  25. if (n) {
  26. var a = Zi(this).constructor;
  27. e = Reflect.construct(r, arguments, a);
  28. } else e = r.apply(this, arguments);
  29. return Ki(this, e);
  30. });
  31. function a(e) {
  32. var t;
  33. if (
  34. (Gi(this, a),
  35. ((t = r.call(this, e)).format = ".jpg"),
  36. document.body.classList.contains("webp-supported") &&
  37. (t.format = ".webp"),
  38. document.body.classList.contains("avif-supported") &&
  39. (t.format = ".avif"),
  40. (t.containerRef = (0, i.createRef)(null)),
  41. (t.viewerRef = (0, i.createRef)(null)),
  42. (t.viewerOffsetRef = (0, i.createRef)(null)),
  43. (t.canvasRef = (0, i.createRef)(null)),
  44. (t.loadingWrap = (0, i.createRef)(null)),
  45. (t.loadingProgress = (0, i.createRef)(null)),
  46. (t.playHead = (0, i.createRef)(null)),
  47. (t.playHeadProgress = (0, i.createRef)(null)),
  48. (t.context = !1),
  49. (t.width = 1552),
  50. (t.height = 873),
  51. t.props.canvasSize)
  52. ) {
  53. var n = c(t.props.canvasSize, 2);
  54. (t.width = n[0]), (t.height = n[1]);
  55. }
  56. return (
  57. (t.lastFrame = -1),
  58. (t.floatFrame = 0),
  59. (t.frame = t.props.startFrame || 0),
  60. (t.fullFrameCount = t.props.frameCount),
  61. (t.loadedCount = 0),
  62. (t.loadComplete = !1),
  63. (t.sequence = []),
  64. (t.loadedRenderPool = []),
  65. (t.loadedRenderTimeout = null),
  66. (t.poolAnimateDelay = 40),
  67. (t.timeline = !1),
  68. (t.progress = 0),
  69. t.props.pause &&
  70. Object.keys(t.props.pause).forEach(function (e) {
  71. t.fullFrameCount += t.props.pause[e];
  72. }),
  73. (t.enterTimeline = !1),
  74. (t.exitTimeline = !1),
  75. (t.notLoadedTween = {
  76. isActive: !1,
  77. }),
  78. (t.isAbove = !1),
  79. (t.isBelow = !0),
  80. (t.lastProgress = !1),
  81. (t.justScrolled = !1),
  82. t
  83. );
  84. }
  85. return (
  86. Yi(a, [
  87. {
  88. key: "componentDidMount",
  89. value: function () {
  90. this.loadAssets(),
  91. this.canvasRef.current && this.initializeContext(),
  92. !this.enterTimeline &&
  93. this.props.enterTween &&
  94. this.initializeEnterTween(),
  95. this.timeline || (this.initializeTimeline(), this.setTimeline()),
  96. !this.exitTimeline &&
  97. this.props.exitTween &&
  98. this.initializeExitTween(),
  99. Ci.refresh();
  100. },
  101. },
  102. {
  103. key: "getImagePath",
  104. value: function (e) {
  105. return (
  106. "https://static.getty.edu/mesopotamia/" +
  107. this.props.path +
  108. "/" +
  109. "".concat(e.toString().padStart(4, "0")) +
  110. this.format
  111. );
  112. },
  113. },
  114. {
  115. key: "loadAssets",
  116. value: function () {
  117. var e = this;
  118. this.loadImage(1),
  119. setTimeout(function () {
  120. for (var t = 2; t <= e.props.frameCount; t += 1) e.loadImage(t);
  121. }, 60);
  122. },
  123. },
  124. {
  125. key: "loadImage",
  126. value: function (e) {
  127. var t = this,
  128. n = new Image();
  129. if (
  130. ((n.retried = 0),
  131. (n.src = this.getImagePath(e)),
  132. (n.ogSrc = n.src),
  133. this.props.pause && e + "" in this.props.pause)
  134. )
  135. for (var r = this.props.pause[e]; r--; ) this.sequence.push(n);
  136. this.sequence.push(n),
  137. (n.onerror = function () {
  138. var e = Math.floor(Date.now() * Math.random())
  139. .toString()
  140. .substring(0, 8);
  141. n.retried < 2
  142. ? setTimeout(function () {
  143. n.src = n.ogSrc + "?" + e;
  144. }, 80)
  145. : n.retried < 3 &&
  146. setTimeout(function () {
  147. n.src = n.ogSrc.slice(0, -4) + ".jpg?" + e;
  148. }, 80),
  149. n.retried++;
  150. }),
  151. (n.onload = function () {
  152. 1 === e && t.renderImageToCanvas(0),
  153. t.frame > e &&
  154. t.timeline.scrollTrigger.isActive &&
  155. t.poolNewFrames(e - 1),
  156. (t.loadedCount += 1),
  157. (t.loadingProgress.current.style.width =
  158. (t.loadedCount / (parseFloat(t.props.frameCount) - 1)) * 100 +
  159. "%"),
  160. t.loadedCount === parseFloat(t.props.frameCount) - 1 &&
  161. t.loadingComplete();
  162. });
  163. },
  164. },
  165. {
  166. key: "loadingComplete",
  167. value: function () {
  168. console.log(this.props.path, "loading complete"),
  169. (this.loadComplete = !0),
  170. this.isAbove && this.renderImageToCanvas(this.loadedCount - 1);
  171. },
  172. },
  173. {
  174. key: "poolNewFrames",
  175. value: function (e) {
  176. this.loadedRenderPool.unshift(e),
  177. this.loadedRenderPool.sort(function (e, t) {
  178. return t - e;
  179. }),
  180. this.animatePool();
  181. },
  182. },
  183. {
  184. key: "animatePool",
  185. value: function () {
  186. var e = this;
  187. !this.loadedRenderTimeout &&
  188. this.loadedRenderPool.length &&
  189. (this.loadedRenderTimeout = setTimeout(function () {
  190. e.loadedRenderTimeout = !1;
  191. var t = e.loadedRenderPool[e.loadedRenderPool.length - 1];
  192. if (t <= e.frame) {
  193. var n = e.loadedRenderPool.pop();
  194. e.renderImageToCanvas(n), e.animatePool();
  195. }
  196. e.frame < t && (e.loadedRenderPool = []);
  197. }, this.poolAnimateDelay));
  198. },
  199. },
  200. {
  201. key: "componentWillUnmount",
  202. value: function () {
  203. this.timeline && this.timeline.kill(!0);
  204. },
  205. },
  206. {
  207. key: "initializeContext",
  208. value: function () {
  209. (this.context = this.canvasRef.current.getContext("2d", {
  210. alpha: !1,
  211. desynchronized: !0,
  212. powerPreference: "high-performance",
  213. })),
  214. (this.context.imageSmoothingEnabled = !0),
  215. (this.context.imageSmoothingQuality = "high");
  216. },
  217. },
  218. {
  219. key: "initializeTimeline",
  220. value: function () {
  221. var e = this,
  222. t = null,
  223. n = function () {
  224. ra.to(e.loadingWrap.current, {
  225. autoAlpha: 1,
  226. });
  227. },
  228. r = function () {
  229. ra.to(e.loadingWrap.current, {
  230. autoAlpha: 0,
  231. });
  232. };
  233. r(),
  234. (this.timeline = ra.timeline({
  235. scrollTrigger: {
  236. trigger: this.containerRef.current,
  237. pin: this.viewerRef.current,
  238. scrub: 0.66,
  239. start: "top top",
  240. end: "bottom bottom",
  241. ease: "none",
  242. markers: this.props.debug && false,
  243. onUpdate: function (n) {
  244. e.props.debug,
  245. !1 === e.lastProgress && (e.lastProgress = n.progress),
  246. e.lastProgress !== n.progress &&
  247. ((e.justScrolled = !0),
  248. clearTimeout(t),
  249. (t = setTimeout(function () {
  250. e.frame > e.loadedCount &&
  251. !e.notLoadedTween.isActive &&
  252. (e.notLoadedTween = ra.to(e.loadingWrap.current, {
  253. backgroundColor: "#8888a0",
  254. duration: 0.33,
  255. repeat: 1,
  256. yoyo: !0,
  257. }));
  258. }, 100)),
  259. (e.lastProgress = n.progress));
  260. },
  261. onScrubComplete: function () {
  262. e.justScrolled = !1;
  263. },
  264. onEnter: function () {
  265. n(), (e.isAbove = !1);
  266. },
  267. onEnterBack: function () {
  268. n(), (e.isBelow = !1);
  269. },
  270. onLeave: function () {
  271. r(), (e.isAbove = !0);
  272. },
  273. onLeaveBack: function () {
  274. r(), (e.isBelow = !0);
  275. },
  276. },
  277. }));
  278. },
  279. },
  280. {
  281. key: "setTimeline",
  282. value: function () {
  283. var e = this;
  284. this.timeline.to(this, {
  285. floatFrame: this.fullFrameCount - 1,
  286. ease: "none",
  287. onUpdate: function () {
  288. (e.frame = Math.floor(e.floatFrame)),
  289. e.lastFrame === e.frame ||
  290. e.loadedRenderPool.length ||
  291. e.renderImageToCanvas(e.frame);
  292. },
  293. });
  294. },
  295. },
  296. {
  297. key: "initializeEnterTween",
  298. value: function () {
  299. var e = this.props.enterTween.duration || 1;
  300. ra.set(this.viewerRef.current, {
  301. yPercent: -100 * e,
  302. });
  303. var t = !0;
  304. if (
  305. (void 0 !== this.props.enterTween.pin &&
  306. (t = this.props.enterTween.pin),
  307. (this.enterTimeline = ra.timeline({
  308. scrollTrigger: {
  309. trigger: this.viewerRef.current,
  310. scrub: !0,
  311. pin: t,
  312. start: function () {
  313. return "top top";
  314. },
  315. end: function () {
  316. return "top top-=" + window.innerHeight * e;
  317. },
  318. },
  319. })),
  320. this.props.enterTween.to &&
  321. this.enterTimeline.to(
  322. this.viewerRef.current,
  323. to(
  324. {
  325. ease: "none",
  326. },
  327. this.props.enterTween.to
  328. )
  329. ),
  330. this.props.enterTween.from &&
  331. this.enterTimeline.from(
  332. this.viewerRef.current,
  333. to(
  334. {
  335. ease: "none",
  336. },
  337. this.props.enterTween.from
  338. )
  339. ),
  340. this.props.enterTween.fromTo)
  341. ) {
  342. var n = this.props.enterTween.fromTo[0],
  343. r = this.props.enterTween.fromTo[1];
  344. this.enterTimeline.fromTo(
  345. this.viewerRef.current,
  346. n,
  347. to(
  348. {
  349. ease: "none",
  350. },
  351. r
  352. )
  353. );
  354. }
  355. },
  356. },
  357. {
  358. key: "initializeExitTween",
  359. value: function () {
  360. if (
  361. (console.log(this.props.path, "initializing exit tween "),
  362. (this.exitTimeline = ra.timeline({
  363. scrollTrigger: {
  364. scrub: !0,
  365. trigger: this.containerRef.current,
  366. pin: this.viewerRef.current,
  367. onLeave: this.props.exitTween.onLeave,
  368. onLeaveBack: this.props.exitTween.onLeaveBack,
  369. onEnterBack: this.props.exitTween.onEnterBack,
  370. start: function () {
  371. return "bottom bottom";
  372. },
  373. end: function () {
  374. return "bottom top";
  375. },
  376. },
  377. })),
  378. this.props.exitTween.to &&
  379. this.exitTimeline.to(
  380. this.viewerRef.current,
  381. to(
  382. {
  383. ease: "none",
  384. },
  385. this.props.exitTween.to
  386. )
  387. ),
  388. this.props.exitTween.from &&
  389. this.exitTimeline.from(
  390. this.viewerRef.current,
  391. to(
  392. {
  393. ease: "none",
  394. },
  395. this.props.exitTween.from
  396. )
  397. ),
  398. this.props.exitTween.fromTo)
  399. ) {
  400. var e = this.props.exitTween.fromTo[0],
  401. t = this.props.exitTween.fromTo[1];
  402. this.exitTimeline.fromTo(
  403. this.viewerRef.current,
  404. e,
  405. to(
  406. to({}, t),
  407. {},
  408. {
  409. ease: "none",
  410. }
  411. )
  412. );
  413. }
  414. },
  415. },
  416. {
  417. key: "renderImageToCanvas",
  418. value: function (e) {
  419. if (this.sequence[e])
  420. if (this.context.drawImage) {
  421. this.props.debug,
  422. this.context.drawImage(this.sequence[e], 0, 0),
  423. (this.lastFrame = e);
  424. var t = 100 - (this.frame / this.fullFrameCount) * 100 + "%",
  425. n = 100 - (e / this.fullFrameCount) * 100 + "%";
  426. (this.playHeadTween = ra.to(this.playHead.current, {
  427. duration: 0.05,
  428. right: n,
  429. ease: "none",
  430. })),
  431. (this.playHeadProgressTween = ra.to(
  432. this.playHeadProgress.current,
  433. {
  434. duration: 0.05,
  435. right: t,
  436. ease: "none",
  437. }
  438. ));
  439. } else this.initializeContext();
  440. },
  441. },
  442. {
  443. key: "render",
  444. value: function () {
  445. var e = {
  446. height: this.props.height || "500vh",
  447. };
  448. return (0, l.jsxs)(l.Fragment, {
  449. children: [
  450. (0, l.jsxs)("div", {
  451. ref: this.loadingWrap,
  452. className: o["load-progress-wrap"],
  453. children: [
  454. (0, l.jsxs)("div", {
  455. className: o["playhead-wrap"],
  456. children: [
  457. (0, l.jsx)("div", {
  458. ref: this.playHead,
  459. className: o.playhead,
  460. }),
  461. (0, l.jsx)("div", {
  462. ref: this.playHeadProgress,
  463. className: o["playhead-progress"],
  464. }),
  465. ],
  466. }),
  467. (0, l.jsx)("div", {
  468. ref: this.loadingProgress,
  469. className: o["load-progress"],
  470. style: {
  471. width: "0%",
  472. },
  473. }),
  474. ],
  475. }),
  476. (0, l.jsxs)("div", {
  477. ref: this.containerRef,
  478. className: o.sequence,
  479. style: e,
  480. children: [
  481. (0, l.jsx)("div", {
  482. ref: this.viewerRef,
  483. className: o["canvas-viewer"],
  484. children: (0, l.jsx)("div", {
  485. style: {
  486. overflow: "hidden",
  487. },
  488. children: (0, l.jsx)("canvas", {
  489. ref: this.canvasRef,
  490. className: o["sequence-canvas"],
  491. width: this.width,
  492. height: this.height,
  493. }),
  494. }),
  495. }),
  496. this.props.children,
  497. ],
  498. }),
  499. ],
  500. });
  501. },
  502. },
  503. ]),
  504. a
  505. );
  506. })(i.Component);