@caperjs/plugin-rive 0.1.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.
- package/LICENSE +22 -0
- package/lib/RiveEntity.d.ts +192 -0
- package/lib/RiveEntity.d.ts.map +1 -0
- package/lib/RivePlugin.d.ts +24 -0
- package/lib/RivePlugin.d.ts.map +1 -0
- package/lib/caper-plugin-rive.mjs +280 -0
- package/lib/caper-plugin-rive.mjs.map +1 -0
- package/lib/extensions.d.ts +1 -0
- package/lib/extensions.d.ts.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/types.d.ts +22 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/version.d.ts +3 -0
- package/lib/version.d.ts.map +1 -0
- package/package.json +45 -0
- package/src/RiveEntity.ts +605 -0
- package/src/RivePlugin.ts +81 -0
- package/src/extensions.ts +0 -0
- package/src/index.ts +8 -0
- package/src/types.ts +33 -0
- package/src/version.ts +2 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import Rive, { RiveCanvas } from '@rive-app/canvas-advanced-lite';
|
|
2
|
+
import { IPlugin, Plugin } from '@caperjs/core';
|
|
3
|
+
import { BrowserAdapter, checkExtension, extensions, ExtensionType, LoaderParserPriority } from 'pixi.js';
|
|
4
|
+
import { riveVersion, version } from './version';
|
|
5
|
+
|
|
6
|
+
export interface IRivePlugin extends IPlugin<RivePluginOptions> {
|
|
7
|
+
rive: RiveCanvas;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Defines the options for the Rive plugin.
|
|
12
|
+
* @property {string} wasmPath - The URL path to the Rive WASM file.
|
|
13
|
+
*/
|
|
14
|
+
export type RivePluginOptions = {
|
|
15
|
+
wasmPath: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const defaultOptions = {
|
|
19
|
+
wasmPath: 'https://unpkg.com/@rive-app/canvas-advanced-lite@2.26.1/rive.wasm',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export class RivePlugin extends Plugin<RivePluginOptions> implements IRivePlugin {
|
|
23
|
+
public static ID: string;
|
|
24
|
+
public readonly id = 'rive';
|
|
25
|
+
public rive: RiveCanvas;
|
|
26
|
+
protected _options: RivePluginOptions = defaultOptions;
|
|
27
|
+
|
|
28
|
+
private _addedExtensions: boolean = false;
|
|
29
|
+
|
|
30
|
+
private hello() {
|
|
31
|
+
const hello = `%c Caper Rive Plugin v${version} | %cRive v${riveVersion} (@rive-app/canvas-advanced-lite)`;
|
|
32
|
+
console.log(
|
|
33
|
+
hello,
|
|
34
|
+
'background: rgba(31, 41, 55, 1);color: #74b64c',
|
|
35
|
+
'background: rgba(31, 41, 55, 1);color: #e91e63',
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async initialize(options: RivePluginOptions): Promise<void> {
|
|
40
|
+
this._options = { ...defaultOptions, ...options };
|
|
41
|
+
this.hello();
|
|
42
|
+
RivePlugin.ID = this.id;
|
|
43
|
+
this._addLoaderExtensions();
|
|
44
|
+
if (!this.rive) {
|
|
45
|
+
this.rive = await Rive({ locateFile: () => this._options.wasmPath });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
destroy() {
|
|
50
|
+
// Intentionally NOT calling `this.rive.cleanup()`.
|
|
51
|
+
//
|
|
52
|
+
// `RiveCanvas.cleanup()` tears down the Emscripten WASM runtime globally.
|
|
53
|
+
// If any RiveEntity's renderer/artboard/state-machine is still registered
|
|
54
|
+
// when it runs, the Rive runtime deadlocks during teardown and the tab
|
|
55
|
+
// freezes. Individual RiveEntity instances already free their own
|
|
56
|
+
// artboards/machines/animations in `_destroyInternals()`, and the WASM
|
|
57
|
+
// heap is released by the browser on page unload — which is the only
|
|
58
|
+
// time `RivePlugin.destroy()` runs in practice.
|
|
59
|
+
super.destroy();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private _addLoaderExtensions() {
|
|
63
|
+
if (!this._addedExtensions) {
|
|
64
|
+
extensions.add({
|
|
65
|
+
name: 'loadRive',
|
|
66
|
+
extension: {
|
|
67
|
+
type: ExtensionType.LoadParser,
|
|
68
|
+
priority: LoaderParserPriority.High,
|
|
69
|
+
},
|
|
70
|
+
test(url: string) {
|
|
71
|
+
return checkExtension(url, '.riv');
|
|
72
|
+
},
|
|
73
|
+
async load(url: string) {
|
|
74
|
+
const response = await BrowserAdapter.fetch(url);
|
|
75
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
this._addedExtensions = true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
File without changes
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { PointLike } from '@caperjs/core';
|
|
2
|
+
import { Cursor } from 'pixi.js';
|
|
3
|
+
|
|
4
|
+
export type Fit = 'cover' | 'contain' | 'fill' | 'fitWidth' | 'fitHeight' | 'none' | 'scaleDown';
|
|
5
|
+
|
|
6
|
+
export type Alignment =
|
|
7
|
+
| 'center'
|
|
8
|
+
| 'topLeft'
|
|
9
|
+
| 'topCenter'
|
|
10
|
+
| 'topRight'
|
|
11
|
+
| 'centerLeft'
|
|
12
|
+
| 'centerRight'
|
|
13
|
+
| 'bottomLeft'
|
|
14
|
+
| 'bottomCenter'
|
|
15
|
+
| 'bottomRight';
|
|
16
|
+
|
|
17
|
+
export type RiveOptions = {
|
|
18
|
+
asset: string | Uint8Array;
|
|
19
|
+
debug?: boolean;
|
|
20
|
+
autoPlay?: boolean;
|
|
21
|
+
interactive?: boolean;
|
|
22
|
+
artboard?: string;
|
|
23
|
+
animation?: string | string[];
|
|
24
|
+
stateMachine?: string | string[];
|
|
25
|
+
anchor?: PointLike;
|
|
26
|
+
scale?: PointLike;
|
|
27
|
+
autoInit?: boolean;
|
|
28
|
+
cursor?: Cursor;
|
|
29
|
+
fit?: Fit;
|
|
30
|
+
align?: Alignment;
|
|
31
|
+
maxWidth?: number;
|
|
32
|
+
maxHeight?: number;
|
|
33
|
+
};
|
package/src/version.ts
ADDED