@lottiefiles/dotlottie-vue 0.1.0 → 0.1.2

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/README.md CHANGED
@@ -17,9 +17,10 @@
17
17
  * [What is dotLottie?](#what-is-dotlottie)
18
18
  * [Installation](#installation)
19
19
  * [Usage](#usage)
20
+ * [Live Examples](#live-examples)
20
21
  * [APIs](#apis)
21
22
  * [DotLottieVue Props](#dotlottievue-props)
22
- * [Listening to DotLottie Events](#listening-to-dotlottie-events)
23
+ * [Listening to Events](#listening-to-events)
23
24
  * [Development](#development)
24
25
  * [Setup](#setup)
25
26
  * [Dev](#dev)
@@ -53,6 +54,10 @@ import { DotLottieVue } from '@lottiefiles/dotlottie-vue'
53
54
  </template>
54
55
  ```
55
56
 
57
+ ## Live Examples
58
+
59
+ * <a href="https://codepen.io/lottiefiles/pen/yLwgeoJ" target="_blank">Basic Example</a>
60
+
56
61
  ## APIs
57
62
 
58
63
  ### DotLottieVue Props
@@ -70,9 +75,17 @@ import { DotLottieVue } from '@lottiefiles/dotlottie-vue'
70
75
  | `renderConfig` | RenderConfig | | `{}` | Configuration for rendering the animation. |
71
76
  | `useFrameInterpolation` | boolean | | false | Determines if the animation should update on subframes. If set to false, the original AE frame rate will be maintained. If set to true, it will refresh at each requestAnimationFrame, including intermediate values. The default setting is true. |
72
77
 
73
- ### Listening to [DotLottie](../web/README.md) Events
78
+ #### RenderConfig
74
79
 
75
- ```vue
80
+ The `renderConfig` object accepts the following properties:
81
+
82
+ | Property name | Type | Required | Default | Description |
83
+ | ------------------ | ------ | :------: | ----------------------------- | ----------------------- |
84
+ | `devicePixelRatio` | number | | window\.devicePixelRatio \| 1 | The device pixel ratio. |
85
+
86
+ ### Listening to Events
87
+
88
+ ```javascript
76
89
  <script setup>
77
90
  import { onMounted, ref, watch } from 'vue';
78
91
  import { DotLottieVue } from '@lottiefiles/dotlottie-vue'
@@ -96,15 +109,7 @@ onMounted(() => {
96
109
  </template>
97
110
  ```
98
111
 
99
- > Refer to [DotLottie](../web/README.md) Events sections to know more about all available events.
100
-
101
- #### RenderConfig
102
-
103
- The `renderConfig` object accepts the following properties:
104
-
105
- | Property name | Type | Required | Default | Description |
106
- | ------------------ | ------ | :------: | ----------------------------- | ----------------------- |
107
- | `devicePixelRatio` | number | | window\.devicePixelRatio \| 1 | The device pixel ratio. |
112
+ > Refer to [dotlottie-web](../web/README.md) Events sections to know more about all available events.
108
113
 
109
114
  ## Development
110
115
 
package/dist/dotlottie.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { DotLottie } from '@lottiefiles/dotlottie-web';
2
2
  import { defineComponent, ref, toRefs, watch, onMounted, onBeforeUnmount, h } from 'vue';
3
3
 
4
- const DotLottieVue = defineComponent({
4
+ // src/dotlottie.ts
5
+ var DotLottieVue = defineComponent({
5
6
  props: {
6
7
  autoplay: { type: Boolean, required: false },
7
8
  backgroundColor: { type: String, required: false },
package/dist/index.js CHANGED
@@ -1 +1,128 @@
1
- export * from './dotlottie';
1
+ import { DotLottie } from '@lottiefiles/dotlottie-web';
2
+ import { defineComponent, ref, toRefs, watch, onMounted, onBeforeUnmount, h } from 'vue';
3
+
4
+ // src/dotlottie.ts
5
+ var DotLottieVue = defineComponent({
6
+ props: {
7
+ autoplay: { type: Boolean, required: false },
8
+ backgroundColor: { type: String, required: false },
9
+ data: { type: [String, ArrayBuffer], required: false },
10
+ loop: { type: Boolean, required: false },
11
+ mode: { type: String, required: false },
12
+ renderConfig: { type: Object, required: false },
13
+ segments: { type: Array, required: false },
14
+ speed: { type: Number, required: false },
15
+ src: { type: String, required: false },
16
+ useFrameInterpolation: { type: Boolean, required: false }
17
+ },
18
+ setup(props, { attrs, expose }) {
19
+ const canvas = ref(void 0);
20
+ const { backgroundColor, loop, mode, segments, speed, useFrameInterpolation } = toRefs(props);
21
+ let dotLottie = null;
22
+ let intersectionObserver = null;
23
+ let resizeObserver = null;
24
+ watch(
25
+ () => backgroundColor?.value,
26
+ (newVal) => {
27
+ if (dotLottie && typeof newVal !== "undefined") {
28
+ dotLottie.setBackgroundColor(newVal);
29
+ }
30
+ }
31
+ );
32
+ watch(
33
+ () => loop?.value,
34
+ (newVal) => {
35
+ if (dotLottie && typeof newVal !== "undefined") {
36
+ dotLottie.setLoop(newVal);
37
+ }
38
+ }
39
+ );
40
+ watch(
41
+ () => mode?.value,
42
+ (newVal) => {
43
+ if (dotLottie && typeof newVal !== "undefined") {
44
+ dotLottie.setMode(newVal);
45
+ }
46
+ }
47
+ );
48
+ watch(
49
+ () => segments?.value,
50
+ (newVal) => {
51
+ if (dotLottie && Array.isArray(newVal) && newVal.length === 2) {
52
+ dotLottie.setSegments(newVal[0], newVal[1]);
53
+ }
54
+ }
55
+ );
56
+ watch(
57
+ () => speed?.value,
58
+ (newVal) => {
59
+ if (dotLottie && typeof newVal !== "undefined") {
60
+ dotLottie.setSpeed(newVal);
61
+ }
62
+ }
63
+ );
64
+ watch(
65
+ () => useFrameInterpolation?.value,
66
+ (newVal) => {
67
+ if (dotLottie && typeof newVal !== "undefined") {
68
+ dotLottie.setUseFrameInterpolation(newVal);
69
+ }
70
+ }
71
+ );
72
+ function getIntersectionObserver() {
73
+ return new IntersectionObserver(
74
+ (entries) => {
75
+ entries.forEach((entry) => {
76
+ if (entry.isIntersecting) {
77
+ dotLottie?.unfreeze();
78
+ } else {
79
+ dotLottie?.freeze();
80
+ }
81
+ });
82
+ },
83
+ {
84
+ threshold: 0
85
+ }
86
+ );
87
+ }
88
+ function getResizeObserver() {
89
+ return new ResizeObserver((entries) => {
90
+ entries.forEach(() => {
91
+ dotLottie?.resize();
92
+ });
93
+ });
94
+ }
95
+ function onVisibilityChange() {
96
+ if (document.hidden) {
97
+ dotLottie?.freeze();
98
+ } else {
99
+ dotLottie?.unfreeze();
100
+ }
101
+ }
102
+ onMounted(() => {
103
+ if (!canvas.value)
104
+ return;
105
+ dotLottie = new DotLottie({
106
+ canvas: canvas.value,
107
+ ...props
108
+ });
109
+ intersectionObserver = getIntersectionObserver();
110
+ resizeObserver = getResizeObserver();
111
+ intersectionObserver.observe(canvas.value);
112
+ resizeObserver.observe(canvas.value);
113
+ document.addEventListener("visibilitychange", onVisibilityChange);
114
+ });
115
+ onBeforeUnmount(() => {
116
+ resizeObserver?.disconnect();
117
+ intersectionObserver?.disconnect();
118
+ document.removeEventListener("visibilitychange", onVisibilityChange);
119
+ dotLottie?.destroy();
120
+ });
121
+ expose({
122
+ getDotLottieInstance: () => dotLottie
123
+ });
124
+ return () => h("div", { ...attrs }, h("canvas", { style: "height: 100%; width: 100%", ref: canvas }));
125
+ }
126
+ });
127
+
128
+ export { DotLottieVue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lottiefiles/dotlottie-vue",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "description": "Vue wrapper around the dotlottie-web library",
6
6
  "repository": {
@@ -38,7 +38,7 @@
38
38
  "vue": "^3.3.4"
39
39
  },
40
40
  "dependencies": {
41
- "@lottiefiles/dotlottie-web": "0.11.1"
41
+ "@lottiefiles/dotlottie-web": "0.12.1"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@vue/runtime-dom": "^3.4.6",