;
@@ -30,10 +31,18 @@ export const H2 = React.memo(
);
export const Text = React.memo(
- ({ children, className, center, wide, ...rest }: Props & ParagraphProps) => (
+ ({
+ children,
+ className,
+ center,
+ wide,
+ secondary,
+ ...rest
+ }: Props & ParagraphProps) => (
config.environment;
window.getVersion = () => config.version;
window.getGuid = require('uuid/v4');
+window.PQueue = require('p-queue');
window.localeMessages = ipc.sendSync('locale-data');
@@ -38,8 +40,11 @@ const WebAPI = initializeWebAPI({
});
window.convertToWebp = async (path, width = 512, height = 512) => {
- const pngBuffer = await pify(readFile)(path);
- const buffer = await sharp(pngBuffer)
+ const imgBuffer = await pify(readFile)(path);
+ const sharpImg = sharp(imgBuffer);
+ const meta = await sharpImg.metadata();
+
+ const buffer = await sharpImg
.resize({
width,
height,
@@ -53,6 +58,7 @@ window.convertToWebp = async (path, width = 512, height = 512) => {
path,
buffer,
src: `data:image/webp;base64,${buffer.toString('base64')}`,
+ meta,
};
};
@@ -110,8 +116,10 @@ window.encryptAndUpload = async (
encryptionKey,
iv
);
- const encryptedStickers = await Promise.all(
- uniqueStickers.map(({ webp }) => encrypt(webp.buffer, encryptionKey, iv))
+ const encryptedStickers = await pMap(
+ uniqueStickers,
+ ({ webp }) => encrypt(webp.buffer, encryptionKey, iv),
+ { concurrency: 3 }
);
const packId = await server.putStickers(
diff --git a/sticker-creator/store/ducks/stickers.ts b/sticker-creator/store/ducks/stickers.ts
index ff7068bfc..19b39e654 100644
--- a/sticker-creator/store/ducks/stickers.ts
+++ b/sticker-creator/store/ducks/stickers.ts
@@ -9,7 +9,7 @@ import {
} from 'redux-ts-utils';
import { useDispatch, useSelector } from 'react-redux';
import { createSelector } from 'reselect';
-import { clamp, pull, take, uniq } from 'lodash';
+import { clamp, isNumber, pull, take, uniq } from 'lodash';
import { SortEnd } from 'react-sortable-hoc';
import arrayMove from 'array-move';
import { AppState } from '../reducer';
@@ -24,6 +24,7 @@ export const addWebp = createAction('stickers/addSticker');
export const removeSticker = createAction('stickers/removeSticker');
export const moveSticker = createAction('stickers/moveSticker');
export const setCover = createAction('stickers/setCover');
+export const resetCover = createAction('stickers/resetCover');
export const setEmoji = createAction<{ id: string; emoji: EmojiPickDataType }>(
'stickers/setEmoji'
);
@@ -34,7 +35,7 @@ export const resetStatus = createAction('stickers/resetStatus');
export const reset = createAction('stickers/reset');
export const minStickers = 4;
-export const maxStickers = 40;
+export const maxStickers = 200;
export const maxByteSize = 100 * 1024;
export type State = {
@@ -45,6 +46,7 @@ export type State = {
readonly packId: string;
readonly packKey: string;
readonly tooLarge: number;
+ readonly animated: number;
readonly imagesAdded: number;
readonly data: {
readonly [src: string]: {
@@ -62,6 +64,7 @@ const defaultState: State = {
packId: '',
packKey: '',
tooLarge: 0,
+ animated: 0,
imagesAdded: 0,
};
@@ -91,7 +94,11 @@ export const reducer = reduceReducers(
}),
handleAction(addWebp, (state, { payload }) => {
- if (payload.buffer.byteLength > maxByteSize) {
+ if (isNumber(payload.meta.pages)) {
+ state.animated = clamp(state.animated + 1, 0, state.order.length);
+ pull(state.order, payload.path);
+ delete state.data[payload.path];
+ } else if (payload.buffer.byteLength > maxByteSize) {
state.tooLarge = clamp(state.tooLarge + 1, 0, state.order.length);
pull(state.order, payload.path);
delete state.data[payload.path];
@@ -126,6 +133,10 @@ export const reducer = reduceReducers(
state.cover = payload;
}),
+ handleAction(resetCover, state => {
+ adjustCover(state);
+ }),
+
handleAction(setEmoji, (state, { payload }) => {
const data = state.data[payload.id];
if (data) {
@@ -148,6 +159,7 @@ export const reducer = reduceReducers(
handleAction(resetStatus, state => {
state.tooLarge = 0;
+ state.animated = 0;
state.imagesAdded = 0;
}),
@@ -202,8 +214,14 @@ const selectUrl = createSelector(
export const usePackUrl = () => useSelector(selectUrl);
export const useHasTooLarge = () =>
useSelector(({ stickers }: AppState) => stickers.tooLarge > 0);
+export const useHasAnimated = () =>
+ useSelector(({ stickers }: AppState) => stickers.animated > 0);
export const useImageAddedCount = () =>
useSelector(({ stickers }: AppState) => stickers.imagesAdded);
+export const useAddMoreCount = () =>
+ useSelector(({ stickers }: AppState) =>
+ clamp(minStickers - stickers.order.length, 0, minStickers)
+ );
const selectOrderedData = createSelector(
({ stickers }: AppState) => stickers.order,
diff --git a/sticker-creator/util/preload.ts b/sticker-creator/util/preload.ts
index fbb4eba5e..aa8c37259 100644
--- a/sticker-creator/util/preload.ts
+++ b/sticker-creator/util/preload.ts
@@ -1,7 +1,10 @@
+import { Metadata } from 'sharp';
+
export type WebpData = {
buffer: Buffer;
src: string;
path: string;
+ meta: Metadata & { pages?: number }; // Pages is not currently in the sharp metadata type
};
export type ConvertToWebpFn = (
diff --git a/yarn.lock b/yarn.lock
index 0da1ef404..d81d9990e 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -334,7 +334,7 @@
"@babel/helper-create-class-features-plugin" "^7.5.5"
"@babel/helper-plugin-utils" "^7.0.0"
-"@babel/plugin-proposal-class-properties@^7.7.4":
+"@babel/plugin-proposal-class-properties@7.7.4":
version "7.7.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.7.4.tgz#2f964f0cb18b948450362742e33e15211e77c2ba"
integrity sha512-EcuXeV4Hv1X3+Q1TsuOmyyxeTRiSqurGJ26+I/FW1WbymmRRapVORm6x1Zl3iDIHyRxEs+VXWp6qnlcfcJSbbw==
@@ -2003,6 +2003,13 @@
"@types/express-serve-static-core" "*"
"@types/mime" "*"
+"@types/sharp@0.23.1":
+ version "0.23.1"
+ resolved "https://registry.yarnpkg.com/@types/sharp/-/sharp-0.23.1.tgz#1e02560371d6603adc121389512f0745028aa507"
+ integrity sha512-iBRM9RjRF9pkIkukk6imlxfaKMRuiRND8L0yYKl5PJu5uLvxuNzp5f0x8aoTG5VX85M8O//BwbttzFVZL1j/FQ==
+ dependencies:
+ "@types/node" "*"
+
"@types/sinon@4.3.1":
version "4.3.1"
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-4.3.1.tgz#32458f9b166cd44c23844eee4937814276f35199"
@@ -15947,7 +15954,7 @@ typedarray@^0.0.6, typedarray@~0.0.5:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
-typeface-inter@^3.10.0:
+typeface-inter@3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/typeface-inter/-/typeface-inter-3.10.0.tgz#04a55d62e2dc3f60db3afab5d8a547e067692bc6"
integrity sha512-WuXE+TaJLB8pdMuvIVY3LfT5UQqndR8+Js0xfhNpdXlsEx0Abwd1bzg4w4YWl2eoOmmLYrRpx6UJJ7a7/q6wZQ==