@mce/gif 0.17.1

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.
@@ -0,0 +1,3 @@
1
+ import { plugin } from './plugin';
2
+ export * from './plugin';
3
+ export default plugin;
package/dist/index.js ADDED
@@ -0,0 +1,47 @@
1
+ import { definePlugin } from "mce";
2
+ import { render } from "modern-canvas";
3
+ import { Encoder } from "modern-gif";
4
+ function plugin() {
5
+ return definePlugin((editor, options) => {
6
+ const {
7
+ assets,
8
+ fonts,
9
+ to
10
+ } = editor;
11
+ const gifWorkerUrl = options.gifWorkerUrl;
12
+ assets.gifWorkerUrl = gifWorkerUrl;
13
+ return {
14
+ name: "mce:gif",
15
+ exporters: [
16
+ {
17
+ name: "gif",
18
+ saveAs: true,
19
+ handle: async (options2) => {
20
+ const { onProgress, ...restOptions } = options2;
21
+ const data = to("json", restOptions);
22
+ const { startTime, endTime } = data.meta;
23
+ const width = Math.floor(data.style.width);
24
+ const height = Math.floor(data.style.height);
25
+ const encoder = new Encoder({ width, height, workerUrl: gifWorkerUrl });
26
+ await render({
27
+ data,
28
+ width,
29
+ height,
30
+ fonts,
31
+ keyframes: Array.from({ length: ~~((endTime - startTime) / 100) }, (_, i) => startTime + i * 100),
32
+ onKeyframe: async (data2, { duration, progress }) => {
33
+ await encoder.encode({ data: data2, delay: duration });
34
+ onProgress?.(progress);
35
+ }
36
+ });
37
+ return await encoder.flush("blob");
38
+ }
39
+ }
40
+ ]
41
+ };
42
+ });
43
+ }
44
+ export {
45
+ plugin as default,
46
+ plugin
47
+ };
@@ -0,0 +1,11 @@
1
+ declare global {
2
+ namespace Mce {
3
+ interface Options {
4
+ gifWorkerUrl?: string;
5
+ }
6
+ interface Exporters {
7
+ gif: Promise<Blob>;
8
+ }
9
+ }
10
+ }
11
+ export declare function plugin(): import("mce").Plugin;
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@mce/gif",
3
+ "type": "module",
4
+ "version": "0.17.1",
5
+ "description": "GIF plugin for mce",
6
+ "author": "wxm",
7
+ "license": "MIT",
8
+ "homepage": "https://github.com/qq15725/mce",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/qq15725/mce.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/qq15725/mce/issues"
15
+ },
16
+ "keywords": [
17
+ "mce",
18
+ "gif",
19
+ "plugin"
20
+ ],
21
+ "sideEffects": true,
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js",
26
+ "require": "./dist/index.js"
27
+ },
28
+ "./*.mjs": "./*.js",
29
+ "./*": "./*"
30
+ },
31
+ "main": "./dist/index.js",
32
+ "module": "./dist/index.js",
33
+ "browser": "./dist/index.js",
34
+ "typings": "dist/index.d.ts",
35
+ "types": "dist/index.d.ts",
36
+ "typesVersions": {
37
+ "*": {
38
+ "*": [
39
+ "*",
40
+ "dist/*",
41
+ "dist/*.d.ts"
42
+ ]
43
+ }
44
+ },
45
+ "files": [
46
+ "dist"
47
+ ],
48
+ "dependencies": {
49
+ "modern-gif": "^2.0.4"
50
+ },
51
+ "devDependencies": {
52
+ "mce": "0.17.1"
53
+ },
54
+ "peerDependencies": {
55
+ "mce": "^0"
56
+ },
57
+ "scripts": {
58
+ "build:code": "vite build",
59
+ "build:tsc": "NODE_ENV=production tsc --emitDeclarationOnly --project tsconfig.json",
60
+ "build": "pnpm build:code && pnpm build:tsc",
61
+ "lint": "eslint src"
62
+ }
63
+ }