|
|
@ -19,6 +19,7 @@ import getPreviewURLFromThumb from '../../helpers/getPreviewURLFromThumb'; |
|
|
|
import makeError from '../../helpers/makeError'; |
|
|
|
import makeError from '../../helpers/makeError'; |
|
|
|
import {makeMediaSize} from '../../helpers/mediaSize'; |
|
|
|
import {makeMediaSize} from '../../helpers/mediaSize'; |
|
|
|
import mediaSizes from '../../helpers/mediaSizes'; |
|
|
|
import mediaSizes from '../../helpers/mediaSizes'; |
|
|
|
|
|
|
|
import noop from '../../helpers/noop'; |
|
|
|
import onMediaLoad from '../../helpers/onMediaLoad'; |
|
|
|
import onMediaLoad from '../../helpers/onMediaLoad'; |
|
|
|
import {isSavingLottiePreview, saveLottiePreview} from '../../helpers/saveLottiePreview'; |
|
|
|
import {isSavingLottiePreview, saveLottiePreview} from '../../helpers/saveLottiePreview'; |
|
|
|
import throttle from '../../helpers/schedulers/throttle'; |
|
|
|
import throttle from '../../helpers/schedulers/throttle'; |
|
|
@ -32,7 +33,6 @@ import getServerMessageId from '../../lib/appManagers/utils/messageId/getServerM |
|
|
|
import choosePhotoSize from '../../lib/appManagers/utils/photos/choosePhotoSize'; |
|
|
|
import choosePhotoSize from '../../lib/appManagers/utils/photos/choosePhotoSize'; |
|
|
|
import getStickerEffectThumb from '../../lib/appManagers/utils/stickers/getStickerEffectThumb'; |
|
|
|
import getStickerEffectThumb from '../../lib/appManagers/utils/stickers/getStickerEffectThumb'; |
|
|
|
import lottieLoader from '../../lib/rlottie/lottieLoader'; |
|
|
|
import lottieLoader from '../../lib/rlottie/lottieLoader'; |
|
|
|
import RLottiePlayer from '../../lib/rlottie/rlottiePlayer'; |
|
|
|
|
|
|
|
import rootScope from '../../lib/rootScope'; |
|
|
|
import rootScope from '../../lib/rootScope'; |
|
|
|
import type {ThumbCache} from '../../lib/storages/thumbs'; |
|
|
|
import type {ThumbCache} from '../../lib/storages/thumbs'; |
|
|
|
import webpWorkerController from '../../lib/webp/webpWorkerController'; |
|
|
|
import webpWorkerController from '../../lib/webp/webpWorkerController'; |
|
|
@ -50,11 +50,13 @@ const EMOJI_EFFECT_MULTIPLIER = 3; |
|
|
|
|
|
|
|
|
|
|
|
const locksUrls: {[docId: string]: string} = {}; |
|
|
|
const locksUrls: {[docId: string]: string} = {}; |
|
|
|
|
|
|
|
|
|
|
|
export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, group, play, onlyThumb, emoji, width, height, withThumb, loop, loadPromises, needFadeIn, needUpscale, skipRatio, static: asStatic, managers = rootScope.managers, fullThumb, isOut, noPremium, withLock, relativeEffect, loopEffect}: { |
|
|
|
export default async function wrapSticker({doc, div, middleware, loadStickerMiddleware, lazyLoadQueue, exportLoad, group, play, onlyThumb, emoji, width, height, withThumb, loop, loadPromises, needFadeIn, needUpscale, skipRatio, static: asStatic, managers = rootScope.managers, fullThumb, isOut, noPremium, withLock, relativeEffect, loopEffect, isCustomEmoji}: { |
|
|
|
doc: MyDocument, |
|
|
|
doc: MyDocument, |
|
|
|
div: HTMLElement, |
|
|
|
div: HTMLElement | HTMLElement[], |
|
|
|
middleware?: () => boolean, |
|
|
|
middleware?: () => boolean, |
|
|
|
|
|
|
|
loadStickerMiddleware?: () => boolean, |
|
|
|
lazyLoadQueue?: LazyLoadQueue, |
|
|
|
lazyLoadQueue?: LazyLoadQueue, |
|
|
|
|
|
|
|
exportLoad?: boolean, |
|
|
|
group?: AnimationItemGroup, |
|
|
|
group?: AnimationItemGroup, |
|
|
|
play?: boolean, |
|
|
|
play?: boolean, |
|
|
|
onlyThumb?: boolean, |
|
|
|
onlyThumb?: boolean, |
|
|
@ -74,8 +76,11 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
noPremium?: boolean, |
|
|
|
noPremium?: boolean, |
|
|
|
withLock?: boolean, |
|
|
|
withLock?: boolean, |
|
|
|
relativeEffect?: boolean, |
|
|
|
relativeEffect?: boolean, |
|
|
|
loopEffect?: boolean |
|
|
|
loopEffect?: boolean, |
|
|
|
|
|
|
|
isCustomEmoji?: boolean |
|
|
|
}) { |
|
|
|
}) { |
|
|
|
|
|
|
|
div = Array.isArray(div) ? div : [div]; |
|
|
|
|
|
|
|
|
|
|
|
const stickerType = doc.sticker; |
|
|
|
const stickerType = doc.sticker; |
|
|
|
if(stickerType === 1) { |
|
|
|
if(stickerType === 1) { |
|
|
|
asStatic = true; |
|
|
|
asStatic = true; |
|
|
@ -94,13 +99,10 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
lottieLoader.loadLottieWorkers(); |
|
|
|
lottieLoader.loadLottieWorkers(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(!stickerType) { |
|
|
|
div.forEach((div) => { |
|
|
|
console.error('wrong doc for wrapSticker!', doc); |
|
|
|
div.dataset.docId = '' + doc.id; |
|
|
|
throw new Error('wrong doc for wrapSticker!'); |
|
|
|
div.classList.add('media-sticker-wrapper'); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
div.dataset.docId = '' + doc.id; |
|
|
|
|
|
|
|
div.classList.add('media-sticker-wrapper'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* if(stickerType === 3) { |
|
|
|
/* if(stickerType === 3) { |
|
|
|
const videoRes = wrapVideo({ |
|
|
|
const videoRes = wrapVideo({ |
|
|
@ -141,14 +143,16 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
|
|
|
|
|
|
|
|
const effectThumb = getStickerEffectThumb(doc); |
|
|
|
const effectThumb = getStickerEffectThumb(doc); |
|
|
|
if(isOut !== undefined && effectThumb && !isOut) { |
|
|
|
if(isOut !== undefined && effectThumb && !isOut) { |
|
|
|
div.classList.add('reflect-x'); |
|
|
|
div.forEach((div) => div.classList.add('reflect-x')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const willHaveLock = effectThumb && withLock; |
|
|
|
const willHaveLock = effectThumb && withLock; |
|
|
|
if(willHaveLock) { |
|
|
|
if(willHaveLock) { |
|
|
|
div.classList.add('is-premium-sticker', 'tgico-premium_lock'); |
|
|
|
|
|
|
|
const lockUrl = locksUrls[doc.id]; |
|
|
|
const lockUrl = locksUrls[doc.id]; |
|
|
|
lockUrl && div.style.setProperty('--lock-url', `url(${lockUrl})`); |
|
|
|
div.forEach((div) => { |
|
|
|
|
|
|
|
div.classList.add('is-premium-sticker', 'tgico-premium_lock'); |
|
|
|
|
|
|
|
lockUrl && div.style.setProperty('--lock-url', `url(${lockUrl})`); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(asStatic && stickerType !== 1) { |
|
|
|
if(asStatic && stickerType !== 1) { |
|
|
@ -164,13 +168,14 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
const isThumbNeededForType = isAnimated; |
|
|
|
const isThumbNeededForType = isAnimated; |
|
|
|
const lottieCachedThumb = stickerType === 2 || stickerType === 3 ? await managers.appDocsManager.getLottieCachedThumb(doc.id, toneIndex) : undefined; |
|
|
|
const lottieCachedThumb = stickerType === 2 || stickerType === 3 ? await managers.appDocsManager.getLottieCachedThumb(doc.id, toneIndex) : undefined; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ret = {render: undefined as typeof loadPromise, load: undefined as typeof load}; |
|
|
|
let loadThumbPromise = deferredPromise<void>(); |
|
|
|
let loadThumbPromise = deferredPromise<void>(); |
|
|
|
let haveThumbCached = false; |
|
|
|
let haveThumbCached = false; |
|
|
|
if(( |
|
|
|
if(( |
|
|
|
doc.thumbs?.length || |
|
|
|
doc.thumbs?.length || |
|
|
|
lottieCachedThumb |
|
|
|
lottieCachedThumb |
|
|
|
) && |
|
|
|
) && |
|
|
|
!div.firstElementChild && ( |
|
|
|
!div[0].firstElementChild && ( |
|
|
|
!downloaded || |
|
|
|
!downloaded || |
|
|
|
isThumbNeededForType || |
|
|
|
isThumbNeededForType || |
|
|
|
onlyThumb |
|
|
|
onlyThumb |
|
|
@ -180,8 +185,7 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
|
|
|
|
|
|
|
|
// console.log('wrap sticker', thumb, div);
|
|
|
|
// console.log('wrap sticker', thumb, div);
|
|
|
|
|
|
|
|
|
|
|
|
let thumbImage: HTMLImageElement | HTMLCanvasElement; |
|
|
|
const afterRender = (div: HTMLElement, thumbImage: HTMLElement) => { |
|
|
|
const afterRender = () => { |
|
|
|
|
|
|
|
if(!div.childElementCount) { |
|
|
|
if(!div.childElementCount) { |
|
|
|
thumbImage.classList.add('media-sticker', 'thumbnail'); |
|
|
|
thumbImage.classList.add('media-sticker', 'thumbnail'); |
|
|
|
|
|
|
|
|
|
|
@ -193,105 +197,133 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if('url' in thumb) { |
|
|
|
if('url' in thumb) { |
|
|
|
thumbImage = new Image(); |
|
|
|
|
|
|
|
renderImageFromUrl(thumbImage, thumb.url, afterRender); |
|
|
|
|
|
|
|
haveThumbCached = true; |
|
|
|
haveThumbCached = true; |
|
|
|
|
|
|
|
div.forEach((div) => { |
|
|
|
|
|
|
|
const thumbImage = new Image(); |
|
|
|
|
|
|
|
renderImageFromUrl(thumbImage, (thumb as any).url, () => afterRender(div, thumbImage)); |
|
|
|
|
|
|
|
}); |
|
|
|
} else if('bytes' in thumb) { |
|
|
|
} else if('bytes' in thumb) { |
|
|
|
if(thumb._ === 'photoPathSize') { |
|
|
|
if(thumb._ === 'photoPathSize') { |
|
|
|
if(thumb.bytes.length) { |
|
|
|
if(!thumb.bytes.length) { |
|
|
|
const d = getPathFromBytes(thumb.bytes); |
|
|
|
|
|
|
|
const ns = 'http://www.w3.org/2000/svg'; |
|
|
|
|
|
|
|
const svg = document.createElementNS(ns, 'svg'); |
|
|
|
|
|
|
|
svg.classList.add('rlottie-vector', 'media-sticker', 'thumbnail'); |
|
|
|
|
|
|
|
svg.setAttributeNS(null, 'viewBox', `0 0 ${doc.w || 512} ${doc.h || 512}`); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const defs = document.createElementNS(ns, 'defs');
|
|
|
|
|
|
|
|
// const linearGradient = document.createElementNS(ns, 'linearGradient');
|
|
|
|
|
|
|
|
// linearGradient.setAttributeNS(null, 'id', 'g');
|
|
|
|
|
|
|
|
// linearGradient.setAttributeNS(null, 'x1', '-300%');
|
|
|
|
|
|
|
|
// linearGradient.setAttributeNS(null, 'x2', '-200%');
|
|
|
|
|
|
|
|
// linearGradient.setAttributeNS(null, 'y1', '0');
|
|
|
|
|
|
|
|
// linearGradient.setAttributeNS(null, 'y2', '0');
|
|
|
|
|
|
|
|
// const stops = [
|
|
|
|
|
|
|
|
// ['-10%', '.1'],
|
|
|
|
|
|
|
|
// ['30%', '.07'],
|
|
|
|
|
|
|
|
// ['70%', '.07'],
|
|
|
|
|
|
|
|
// ['110%', '.1']
|
|
|
|
|
|
|
|
// ].map(([offset, stopOpacity]) => {
|
|
|
|
|
|
|
|
// const stop = document.createElementNS(ns, 'stop');
|
|
|
|
|
|
|
|
// stop.setAttributeNS(null, 'offset', offset);
|
|
|
|
|
|
|
|
// stop.setAttributeNS(null, 'stop-opacity', stopOpacity);
|
|
|
|
|
|
|
|
// return stop;
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// const animates = [
|
|
|
|
|
|
|
|
// ['-300%', '1200%'],
|
|
|
|
|
|
|
|
// ['-200%', '1300%']
|
|
|
|
|
|
|
|
// ].map(([from, to], idx) => {
|
|
|
|
|
|
|
|
// const animate = document.createElementNS(ns, 'animate');
|
|
|
|
|
|
|
|
// animate.setAttributeNS(null, 'attributeName', 'x' + (idx + 1));
|
|
|
|
|
|
|
|
// animate.setAttributeNS(null, 'from', from);
|
|
|
|
|
|
|
|
// animate.setAttributeNS(null, 'to', to);
|
|
|
|
|
|
|
|
// animate.setAttributeNS(null, 'dur', '3s');
|
|
|
|
|
|
|
|
// animate.setAttributeNS(null, 'repeatCount', 'indefinite');
|
|
|
|
|
|
|
|
// return animate;
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// linearGradient.append(...stops, ...animates);
|
|
|
|
|
|
|
|
// defs.append(linearGradient);
|
|
|
|
|
|
|
|
// svg.append(defs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const path = document.createElementNS(ns, 'path'); |
|
|
|
|
|
|
|
path.setAttributeNS(null, 'd', d); |
|
|
|
|
|
|
|
if(rootScope.settings.animationsEnabled) path.setAttributeNS(null, 'fill', 'url(#g)'); |
|
|
|
|
|
|
|
svg.append(path); |
|
|
|
|
|
|
|
div.append(svg); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
thumb = doc.thumbs.find((t) => (t as PhotoSize.photoStrippedSize).bytes?.length) || thumb; |
|
|
|
thumb = doc.thumbs.find((t) => (t as PhotoSize.photoStrippedSize).bytes?.length) || thumb; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const d = getPathFromBytes((thumb as PhotoSize.photoStrippedSize).bytes); |
|
|
|
|
|
|
|
const ns = 'http://www.w3.org/2000/svg'; |
|
|
|
|
|
|
|
const svg = document.createElementNS(ns, 'svg'); |
|
|
|
|
|
|
|
svg.classList.add('rlottie-vector', 'media-sticker', 'thumbnail'); |
|
|
|
|
|
|
|
svg.setAttributeNS(null, 'viewBox', `0 0 ${doc.w || 512} ${doc.h || 512}`); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const defs = document.createElementNS(ns, 'defs');
|
|
|
|
|
|
|
|
// const linearGradient = document.createElementNS(ns, 'linearGradient');
|
|
|
|
|
|
|
|
// linearGradient.setAttributeNS(null, 'id', 'g');
|
|
|
|
|
|
|
|
// linearGradient.setAttributeNS(null, 'x1', '-300%');
|
|
|
|
|
|
|
|
// linearGradient.setAttributeNS(null, 'x2', '-200%');
|
|
|
|
|
|
|
|
// linearGradient.setAttributeNS(null, 'y1', '0');
|
|
|
|
|
|
|
|
// linearGradient.setAttributeNS(null, 'y2', '0');
|
|
|
|
|
|
|
|
// const stops = [
|
|
|
|
|
|
|
|
// ['-10%', '.1'],
|
|
|
|
|
|
|
|
// ['30%', '.07'],
|
|
|
|
|
|
|
|
// ['70%', '.07'],
|
|
|
|
|
|
|
|
// ['110%', '.1']
|
|
|
|
|
|
|
|
// ].map(([offset, stopOpacity]) => {
|
|
|
|
|
|
|
|
// const stop = document.createElementNS(ns, 'stop');
|
|
|
|
|
|
|
|
// stop.setAttributeNS(null, 'offset', offset);
|
|
|
|
|
|
|
|
// stop.setAttributeNS(null, 'stop-opacity', stopOpacity);
|
|
|
|
|
|
|
|
// return stop;
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// const animates = [
|
|
|
|
|
|
|
|
// ['-300%', '1200%'],
|
|
|
|
|
|
|
|
// ['-200%', '1300%']
|
|
|
|
|
|
|
|
// ].map(([from, to], idx) => {
|
|
|
|
|
|
|
|
// const animate = document.createElementNS(ns, 'animate');
|
|
|
|
|
|
|
|
// animate.setAttributeNS(null, 'attributeName', 'x' + (idx + 1));
|
|
|
|
|
|
|
|
// animate.setAttributeNS(null, 'from', from);
|
|
|
|
|
|
|
|
// animate.setAttributeNS(null, 'to', to);
|
|
|
|
|
|
|
|
// animate.setAttributeNS(null, 'dur', '3s');
|
|
|
|
|
|
|
|
// animate.setAttributeNS(null, 'repeatCount', 'indefinite');
|
|
|
|
|
|
|
|
// return animate;
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// linearGradient.append(...stops, ...animates);
|
|
|
|
|
|
|
|
// defs.append(linearGradient);
|
|
|
|
|
|
|
|
// svg.append(defs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const path = document.createElementNS(ns, 'path'); |
|
|
|
|
|
|
|
path.setAttributeNS(null, 'd', d); |
|
|
|
|
|
|
|
if(rootScope.settings.animationsEnabled && !isCustomEmoji) path.setAttributeNS(null, 'fill', 'url(#g)'); |
|
|
|
|
|
|
|
svg.append(path); |
|
|
|
|
|
|
|
div.forEach((div, idx) => div.append(idx > 0 ? svg.cloneNode(true) : svg)); |
|
|
|
|
|
|
|
haveThumbCached = true; |
|
|
|
|
|
|
|
loadThumbPromise.resolve(); |
|
|
|
} else if(toneIndex <= 0) { |
|
|
|
} else if(toneIndex <= 0) { |
|
|
|
thumbImage = new Image(); |
|
|
|
const r = () => { |
|
|
|
|
|
|
|
(div as HTMLElement[]).forEach((div) => { |
|
|
|
|
|
|
|
const thumbImage = new Image(); |
|
|
|
|
|
|
|
const url = getPreviewURLFromThumb(doc, thumb as PhotoSize.photoStrippedSize, true); |
|
|
|
|
|
|
|
renderImageFromUrl(thumbImage, url, () => afterRender(div, thumbImage)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if((IS_WEBP_SUPPORTED || doc.pFlags.stickerThumbConverted || cacheContext.url)/* && false */) { |
|
|
|
if((IS_WEBP_SUPPORTED || doc.pFlags.stickerThumbConverted || cacheContext.url)/* && false */) { |
|
|
|
renderImageFromUrl(thumbImage, getPreviewURLFromThumb(doc, thumb, true), afterRender); |
|
|
|
|
|
|
|
haveThumbCached = true; |
|
|
|
haveThumbCached = true; |
|
|
|
|
|
|
|
r(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
haveThumbCached = true; |
|
|
|
webpWorkerController.convert('main-' + doc.id, thumb.bytes).then((bytes) => { |
|
|
|
webpWorkerController.convert('main-' + doc.id, thumb.bytes).then((bytes) => { |
|
|
|
managers.appDocsManager.saveWebPConvertedStrippedThumb(doc.id, bytes); |
|
|
|
managers.appDocsManager.saveWebPConvertedStrippedThumb(doc.id, bytes); |
|
|
|
(thumb as PhotoSize.photoStrippedSize).bytes = bytes; |
|
|
|
(thumb as PhotoSize.photoStrippedSize).bytes = bytes; |
|
|
|
doc.pFlags.stickerThumbConverted = true; |
|
|
|
doc.pFlags.stickerThumbConverted = true; |
|
|
|
|
|
|
|
|
|
|
|
if(middleware && !middleware()) return; |
|
|
|
if((middleware && !middleware()) || (div as HTMLElement[])[0].childElementCount) { |
|
|
|
|
|
|
|
loadThumbPromise.resolve(); |
|
|
|
if(!div.childElementCount) { |
|
|
|
return; |
|
|
|
renderImageFromUrl(thumbImage, getPreviewURLFromThumb(doc, thumb as PhotoSize.photoStrippedSize, true), afterRender); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}).catch(() => {}); |
|
|
|
|
|
|
|
|
|
|
|
r(); |
|
|
|
|
|
|
|
}).catch(() => loadThumbPromise.resolve()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if(((stickerType === 2 && toneIndex <= 0) || stickerType === 3) && (withThumb || onlyThumb)) { |
|
|
|
} else if(((stickerType === 2 && toneIndex <= 0) || stickerType === 3) && (withThumb || onlyThumb)) { |
|
|
|
const load = async() => { |
|
|
|
const load = async() => { |
|
|
|
if(div.childElementCount || (middleware && !middleware())) return; |
|
|
|
if((div as HTMLElement[])[0].childElementCount || (middleware && !middleware())) { |
|
|
|
|
|
|
|
loadThumbPromise.resolve(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const r = () => { |
|
|
|
const r = (div: HTMLElement, thumbImage: HTMLElement) => { |
|
|
|
if(div.childElementCount || (middleware && !middleware())) return; |
|
|
|
if(div.childElementCount || (middleware && !middleware())) { |
|
|
|
renderImageFromUrl(thumbImage, cacheContext.url, afterRender); |
|
|
|
loadThumbPromise.resolve(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
renderImageFromUrl(thumbImage, cacheContext.url, () => afterRender(div, thumbImage)); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
await getCacheContext(); |
|
|
|
await getCacheContext(); |
|
|
|
if(cacheContext.url) { |
|
|
|
(div as HTMLElement[]).forEach((div) => { |
|
|
|
r(); |
|
|
|
if(cacheContext.url) { |
|
|
|
return; |
|
|
|
r(div, new Image()); |
|
|
|
} else { |
|
|
|
} else if('bytes' in thumb) { |
|
|
|
const res = getImageFromStrippedThumb(doc, thumb as PhotoSize.photoStrippedSize, true); |
|
|
|
const res = getImageFromStrippedThumb(doc, thumb as PhotoSize.photoStrippedSize, true); |
|
|
|
thumbImage = res.image; |
|
|
|
res.loadPromise.then(() => r(div, res.image)); |
|
|
|
res.loadPromise.then(r); |
|
|
|
|
|
|
|
|
|
|
|
// return managers.appDocsManager.getThumbURL(doc, thumb as PhotoSize.photoStrippedSize).promise.then(r);
|
|
|
|
// return managers.appDocsManager.getThumbURL(doc, thumb as PhotoSize.photoStrippedSize).promise.then(r);
|
|
|
|
} else { |
|
|
|
} |
|
|
|
appDownloadManager.downloadMediaURL({ |
|
|
|
|
|
|
|
media: doc, |
|
|
|
|
|
|
|
thumb: thumb as PhotoSize |
|
|
|
|
|
|
|
}).then(async() => { |
|
|
|
|
|
|
|
await getCacheContext(); |
|
|
|
|
|
|
|
return r(div, new Image()); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if(lazyLoadQueue && onlyThumb) { |
|
|
|
if(lazyLoadQueue && onlyThumb) { |
|
|
|
lazyLoadQueue.push({div, load}); |
|
|
|
lazyLoadQueue.push({div: div[0], load}); |
|
|
|
return; |
|
|
|
loadThumbPromise.resolve(); |
|
|
|
|
|
|
|
return ret; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
load(); |
|
|
|
load(); |
|
|
|
|
|
|
|
|
|
|
@ -307,7 +339,7 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(onlyThumb/* || true */) { // for sticker panel
|
|
|
|
if(onlyThumb/* || true */) { // for sticker panel
|
|
|
|
return; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const middlewareError = makeError('MIDDLEWARE'); |
|
|
|
const middlewareError = makeError('MIDDLEWARE'); |
|
|
@ -317,27 +349,14 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(stickerType === 2 && !asStatic) { |
|
|
|
if(stickerType === 2 && !asStatic) { |
|
|
|
/* if(doc.id === '1860749763008266301') { |
|
|
|
return appDownloadManager.downloadMedia({media: doc, queueId: lazyLoadQueue?.queueId, thumb: fullThumb}) |
|
|
|
console.log('loaded sticker:', doc, div); |
|
|
|
|
|
|
|
} */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// await new Promise((resolve) => setTimeout(resolve, 500));
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// console.time('download sticker' + doc.id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// appDocsManager.downloadDocNew(doc.id).promise.then((res) => res.json()).then(async(json) => {
|
|
|
|
|
|
|
|
// fetch(doc.url).then((res) => res.json()).then(async(json) => {
|
|
|
|
|
|
|
|
return await appDownloadManager.downloadMedia({media: doc, queueId: lazyLoadQueue?.queueId, thumb: fullThumb}) |
|
|
|
|
|
|
|
.then(async(blob) => { |
|
|
|
.then(async(blob) => { |
|
|
|
// console.timeEnd('download sticker' + doc.id);
|
|
|
|
|
|
|
|
// console.log('loaded sticker:', doc, div/* , blob */);
|
|
|
|
|
|
|
|
if(middleware && !middleware()) { |
|
|
|
if(middleware && !middleware()) { |
|
|
|
throw middlewareError; |
|
|
|
throw middlewareError; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const animation = await lottieLoader.loadAnimationWorker({ |
|
|
|
const animation = await lottieLoader.loadAnimationWorker({ |
|
|
|
container: div, |
|
|
|
container: (div as HTMLElement[])[0], |
|
|
|
loop: loop && !emoji, |
|
|
|
loop: loop && !emoji, |
|
|
|
autoplay: play, |
|
|
|
autoplay: play, |
|
|
|
animationData: blob, |
|
|
|
animationData: blob, |
|
|
@ -346,24 +365,25 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
name: 'doc' + doc.id, |
|
|
|
name: 'doc' + doc.id, |
|
|
|
needUpscale, |
|
|
|
needUpscale, |
|
|
|
skipRatio, |
|
|
|
skipRatio, |
|
|
|
toneIndex |
|
|
|
toneIndex, |
|
|
|
}, group, middleware); |
|
|
|
sync: isCustomEmoji |
|
|
|
|
|
|
|
}, group, loadStickerMiddleware ?? middleware); |
|
|
|
|
|
|
|
|
|
|
|
// const deferred = deferredPromise<void>();
|
|
|
|
// const deferred = deferredPromise<void>();
|
|
|
|
|
|
|
|
|
|
|
|
const setLockColor = willHaveLock ? () => { |
|
|
|
const setLockColor = willHaveLock ? () => { |
|
|
|
const lockUrl = locksUrls[doc.id] ??= computeLockColor(animation.canvas); |
|
|
|
const lockUrl = locksUrls[doc.id] ??= computeLockColor(animation.canvas[0]); |
|
|
|
div.style.setProperty('--lock-url', `url(${lockUrl})`); |
|
|
|
(div as HTMLElement[]).forEach((div) => div.style.setProperty('--lock-url', `url(${lockUrl})`)); |
|
|
|
} : undefined; |
|
|
|
} : undefined; |
|
|
|
|
|
|
|
|
|
|
|
animation.addEventListener('firstFrame', () => { |
|
|
|
const onFirstFrame = (container: HTMLElement, canvas: HTMLCanvasElement) => { |
|
|
|
const element = div.firstElementChild; |
|
|
|
const element = container.firstElementChild; |
|
|
|
if(needFadeIn !== false) { |
|
|
|
if(needFadeIn !== false) { |
|
|
|
needFadeIn = (needFadeIn || !element || element.tagName === 'svg') && rootScope.settings.animationsEnabled; |
|
|
|
needFadeIn = (needFadeIn || !element || element.tagName === 'svg') && rootScope.settings.animationsEnabled; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const cb = () => { |
|
|
|
const cb = () => { |
|
|
|
if(element && element !== animation.canvas && element.tagName !== 'DIV') { |
|
|
|
if(element && element !== canvas && element.tagName !== 'DIV') { |
|
|
|
element.remove(); |
|
|
|
element.remove(); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
@ -374,29 +394,36 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
sequentialDom.mutate(() => { |
|
|
|
sequentialDom.mutate(() => { |
|
|
|
animation.canvas.classList.add('fade-in'); |
|
|
|
canvas && canvas.classList.add('fade-in'); |
|
|
|
if(element) { |
|
|
|
if(element) { |
|
|
|
element.classList.add('fade-out'); |
|
|
|
element.classList.add('fade-out'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
animation.canvas.addEventListener('animationend', () => { |
|
|
|
(canvas || element).addEventListener('animationend', () => { |
|
|
|
sequentialDom.mutate(() => { |
|
|
|
sequentialDom.mutate(() => { |
|
|
|
animation.canvas.classList.remove('fade-in'); |
|
|
|
canvas && canvas.classList.remove('fade-in'); |
|
|
|
cb(); |
|
|
|
cb(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, {once: true}); |
|
|
|
}, {once: true}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
animation.addEventListener('firstFrame', () => { |
|
|
|
|
|
|
|
const canvas = animation.canvas[0]; |
|
|
|
if(withThumb !== false) { |
|
|
|
if(withThumb !== false) { |
|
|
|
saveLottiePreview(doc, animation.canvas, toneIndex); |
|
|
|
saveLottiePreview(doc, canvas, toneIndex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(willHaveLock) { |
|
|
|
if(willHaveLock) { |
|
|
|
setLockColor(); |
|
|
|
setLockColor(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// deferred.resolve();
|
|
|
|
if(!isCustomEmoji) { |
|
|
|
|
|
|
|
(div as HTMLElement[]).forEach((container, idx) => { |
|
|
|
|
|
|
|
onFirstFrame(container, animation.canvas[idx]); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
}, {once: true}); |
|
|
|
}, {once: true}); |
|
|
|
|
|
|
|
|
|
|
|
if(emoji) { |
|
|
|
if(emoji) { |
|
|
@ -409,16 +436,17 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
|
|
|
|
|
|
|
|
managers.appStickersManager.preloadAnimatedEmojiStickerAnimation(emoji); |
|
|
|
managers.appStickersManager.preloadAnimatedEmojiStickerAnimation(emoji); |
|
|
|
|
|
|
|
|
|
|
|
attachClickEvent(div, async(e) => { |
|
|
|
const container = (div as HTMLElement[])[0]; |
|
|
|
|
|
|
|
attachClickEvent(container, async(e) => { |
|
|
|
cancelEvent(e); |
|
|
|
cancelEvent(e); |
|
|
|
const animation = lottieLoader.getAnimation(div); |
|
|
|
const animation = lottieLoader.getAnimation(container); |
|
|
|
|
|
|
|
|
|
|
|
if(animation.paused) { |
|
|
|
if(animation.paused) { |
|
|
|
const doc = await managers.appStickersManager.getAnimatedEmojiSoundDocument(emoji); |
|
|
|
const doc = await managers.appStickersManager.getAnimatedEmojiSoundDocument(emoji); |
|
|
|
if(doc) { |
|
|
|
if(doc) { |
|
|
|
const audio = document.createElement('audio'); |
|
|
|
const audio = document.createElement('audio'); |
|
|
|
audio.style.display = 'none'; |
|
|
|
audio.style.display = 'none'; |
|
|
|
div.parentElement.append(audio); |
|
|
|
container.parentElement.append(audio); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
const url = await appDownloadManager.downloadMediaURL({media: doc}); |
|
|
|
const url = await appDownloadManager.downloadMediaURL({media: doc}); |
|
|
@ -455,7 +483,7 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
middleware, |
|
|
|
middleware, |
|
|
|
side: isOut ? 'right' : 'left', |
|
|
|
side: isOut ? 'right' : 'left', |
|
|
|
size: 280, |
|
|
|
size: 280, |
|
|
|
target: div, |
|
|
|
target: container, |
|
|
|
play: true, |
|
|
|
play: true, |
|
|
|
withRandomOffset: true |
|
|
|
withRandomOffset: true |
|
|
|
}); |
|
|
|
}); |
|
|
@ -477,7 +505,7 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
a.t = (a.t - firstTime) / 1000; |
|
|
|
a.t = (a.t - firstTime) / 1000; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const bubble = findUpClassName(div, 'bubble'); |
|
|
|
const bubble = findUpClassName(container, 'bubble'); |
|
|
|
managers.appMessagesManager.setTyping(appImManager.chat.peerId, { |
|
|
|
managers.appMessagesManager.setTyping(appImManager.chat.peerId, { |
|
|
|
_: 'sendMessageEmojiInteraction', |
|
|
|
_: 'sendMessageEmojiInteraction', |
|
|
|
msg_id: getServerMessageId(+bubble.dataset.mid), |
|
|
|
msg_id: getServerMessageId(+bubble.dataset.mid), |
|
|
@ -509,34 +537,29 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
// return deferred;
|
|
|
|
// return deferred;
|
|
|
|
// await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
|
|
// await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// console.timeEnd('render sticker' + doc.id);
|
|
|
|
|
|
|
|
} else if(asStatic || stickerType === 3) { |
|
|
|
} else if(asStatic || stickerType === 3) { |
|
|
|
let media: HTMLElement; |
|
|
|
const media: HTMLElement[] = (div as HTMLElement[]).map(() => { |
|
|
|
if(asStatic) { |
|
|
|
let media: HTMLElement; |
|
|
|
media = new Image(); |
|
|
|
if(asStatic) { |
|
|
|
} else { |
|
|
|
media = new Image(); |
|
|
|
media = createVideo(); |
|
|
|
} else { |
|
|
|
(media as HTMLVideoElement).muted = true; |
|
|
|
const video = media = createVideo(); |
|
|
|
|
|
|
|
video.muted = true; |
|
|
|
if(play) { |
|
|
|
if(play) video.autoplay = true; |
|
|
|
(media as HTMLVideoElement).autoplay = true; |
|
|
|
if(loop) video.loop = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(loop) { |
|
|
|
media.classList.add('media-sticker'); |
|
|
|
(media as HTMLVideoElement).loop = true; |
|
|
|
return media; |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const thumbImage = div.firstElementChild !== media && div.firstElementChild; |
|
|
|
const thumbImage = (div as HTMLElement[]).map((div, idx) => (div.firstElementChild as HTMLElement) !== media[idx] && div.firstElementChild) as HTMLElement[]; |
|
|
|
if(needFadeIn !== false) { |
|
|
|
if(needFadeIn !== false) { |
|
|
|
needFadeIn = (needFadeIn || !downloaded || (asStatic ? thumbImage : (!thumbImage || thumbImage.tagName === 'svg'))) && rootScope.settings.animationsEnabled; |
|
|
|
needFadeIn = (needFadeIn || !downloaded || (asStatic ? thumbImage[0] : (!thumbImage[0] || thumbImage[0].tagName === 'svg'))) && rootScope.settings.animationsEnabled; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
media.classList.add('media-sticker'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(needFadeIn) { |
|
|
|
if(needFadeIn) { |
|
|
|
media.classList.add('fade-in'); |
|
|
|
media.forEach((media) => media.classList.add('fade-in')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new Promise<HTMLVideoElement | HTMLImageElement>(async(resolve, reject) => { |
|
|
|
return new Promise<HTMLVideoElement | HTMLImageElement>(async(resolve, reject) => { |
|
|
@ -546,7 +569,7 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const onLoad = () => { |
|
|
|
const onLoad = (div: HTMLElement, media: HTMLElement, thumbImage: HTMLElement) => { |
|
|
|
sequentialDom.mutateElement(div, () => { |
|
|
|
sequentialDom.mutateElement(div, () => { |
|
|
|
div.append(media); |
|
|
|
div.append(media); |
|
|
|
thumbImage && thumbImage.classList.add('fade-out'); |
|
|
|
thumbImage && thumbImage.classList.add('fade-out'); |
|
|
@ -579,19 +602,22 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
await getCacheContext(); |
|
|
|
await getCacheContext(); |
|
|
|
if(asStatic) { |
|
|
|
media.forEach((media, idx) => { |
|
|
|
renderImageFromUrl(media, cacheContext.url, onLoad); |
|
|
|
const cb = () => onLoad((div as HTMLElement[])[idx], media, thumbImage[idx]); |
|
|
|
} else { |
|
|
|
if(asStatic) { |
|
|
|
(media as HTMLVideoElement).src = cacheContext.url; |
|
|
|
renderImageFromUrl(media, cacheContext.url, cb); |
|
|
|
onMediaLoad(media as HTMLVideoElement).then(onLoad); |
|
|
|
} else { |
|
|
|
} |
|
|
|
(media as HTMLVideoElement).src = cacheContext.url; |
|
|
|
|
|
|
|
onMediaLoad(media as HTMLVideoElement).then(cb); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
await getCacheContext(); |
|
|
|
await getCacheContext(); |
|
|
|
if(cacheContext.url) r(); |
|
|
|
if(cacheContext.url) r(); |
|
|
|
else { |
|
|
|
else { |
|
|
|
let promise: Promise<any>; |
|
|
|
let promise: Promise<any>; |
|
|
|
if(stickerType === 2 && asStatic) { |
|
|
|
if(stickerType !== 1 && asStatic) { |
|
|
|
const thumb = choosePhotoSize(doc, width, height, false) as PhotoSize.photoSize; |
|
|
|
const thumb = choosePhotoSize(doc, width, height, false) as PhotoSize.photoSize; |
|
|
|
// promise = managers.appDocsManager.getThumbURL(doc, thumb).promise
|
|
|
|
// promise = managers.appDocsManager.getThumbURL(doc, thumb).promise
|
|
|
|
promise = appDownloadManager.downloadMediaURL({media: doc, thumb, queueId: lazyLoadQueue?.queueId}); |
|
|
|
promise = appDownloadManager.downloadMediaURL({media: doc, thumb, queueId: lazyLoadQueue?.queueId}); |
|
|
@ -605,8 +631,13 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(exportLoad && (!downloaded || isAnimated)) { |
|
|
|
|
|
|
|
ret.load = load; |
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const loadPromise: Promise<Awaited<ReturnType<typeof load>> | void> = lazyLoadQueue && (!downloaded || isAnimated) ? |
|
|
|
const loadPromise: Promise<Awaited<ReturnType<typeof load>> | void> = lazyLoadQueue && (!downloaded || isAnimated) ? |
|
|
|
(lazyLoadQueue.push({div, load}), Promise.resolve()) : |
|
|
|
(lazyLoadQueue.push({div: div[0], load}), Promise.resolve()) : |
|
|
|
load(); |
|
|
|
load(); |
|
|
|
|
|
|
|
|
|
|
|
if(downloaded && (asStatic/* || stickerType === 3 */)) { |
|
|
|
if(downloaded && (asStatic/* || stickerType === 3 */)) { |
|
|
@ -618,7 +649,7 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
|
|
|
|
|
|
|
|
if(stickerType === 2 && effectThumb && isOut !== undefined && !noPremium) { |
|
|
|
if(stickerType === 2 && effectThumb && isOut !== undefined && !noPremium) { |
|
|
|
attachStickerEffectHandler({ |
|
|
|
attachStickerEffectHandler({ |
|
|
|
container: div, |
|
|
|
container: div[0], |
|
|
|
doc, |
|
|
|
doc, |
|
|
|
managers, |
|
|
|
managers, |
|
|
|
middleware, |
|
|
|
middleware, |
|
|
@ -630,7 +661,8 @@ export default async function wrapSticker({doc, div, middleware, lazyLoadQueue, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return {render: loadPromise}; |
|
|
|
ret.render = loadPromise as any; |
|
|
|
|
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function attachStickerEffectHandler({container, doc, managers, middleware, isOut, width, loadPromise, relativeEffect, loopEffect}: { |
|
|
|
function attachStickerEffectHandler({container, doc, managers, middleware, isOut, width, loadPromise, relativeEffect, loopEffect}: { |
|
|
|