@ignaciocabeza/bitface 1.0.0 → 1.0.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.
- package/dist/chunk-SFAUE3EN.js +1 -0
- package/dist/index.cjs +1 -1133
- package/dist/index.js +1 -23
- package/dist/react.cjs +1 -1155
- package/dist/react.js +1 -86
- package/dist/vue.cjs +1 -1165
- package/dist/vue.js +1 -103
- package/package.json +1 -1
- package/dist/chunk-SCBE5EEX.js +0 -1099
- package/dist/chunk-SCBE5EEX.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/react.cjs.map +0 -1
- package/dist/react.js.map +0 -1
- package/dist/vue.cjs.map +0 -1
- package/dist/vue.js.map +0 -1
package/dist/vue.js
CHANGED
|
@@ -1,103 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ANIMATIONS,
|
|
3
|
-
generateFace,
|
|
4
|
-
generateRandomConfig
|
|
5
|
-
} from "./chunk-SCBE5EEX.js";
|
|
6
|
-
|
|
7
|
-
// src/vue.ts
|
|
8
|
-
import {
|
|
9
|
-
computed,
|
|
10
|
-
ref,
|
|
11
|
-
watch,
|
|
12
|
-
onUnmounted,
|
|
13
|
-
defineComponent,
|
|
14
|
-
h
|
|
15
|
-
} from "vue";
|
|
16
|
-
function useAvatar(config) {
|
|
17
|
-
let fallback;
|
|
18
|
-
return computed(() => {
|
|
19
|
-
const c = config?.();
|
|
20
|
-
if (c) return generateFace(c);
|
|
21
|
-
if (!fallback) fallback = generateRandomConfig();
|
|
22
|
-
return generateFace(fallback);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
function useAnimatedAvatar(config, animation) {
|
|
26
|
-
const frameIndex = ref(0);
|
|
27
|
-
let timer;
|
|
28
|
-
let fallback;
|
|
29
|
-
const sequence = computed(() => {
|
|
30
|
-
const anim = animation();
|
|
31
|
-
if (!anim) return void 0;
|
|
32
|
-
if (typeof anim === "string") return ANIMATIONS[anim];
|
|
33
|
-
return anim;
|
|
34
|
-
});
|
|
35
|
-
function scheduleNext() {
|
|
36
|
-
const seq = sequence.value;
|
|
37
|
-
if (!seq) return;
|
|
38
|
-
const frame = seq.frames[frameIndex.value];
|
|
39
|
-
if (!frame) return;
|
|
40
|
-
timer = setTimeout(() => {
|
|
41
|
-
frameIndex.value = (frameIndex.value + 1) % seq.frames.length;
|
|
42
|
-
scheduleNext();
|
|
43
|
-
}, frame.duration);
|
|
44
|
-
}
|
|
45
|
-
watch(
|
|
46
|
-
sequence,
|
|
47
|
-
() => {
|
|
48
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
49
|
-
frameIndex.value = 0;
|
|
50
|
-
scheduleNext();
|
|
51
|
-
},
|
|
52
|
-
{ immediate: true }
|
|
53
|
-
);
|
|
54
|
-
onUnmounted(() => {
|
|
55
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
56
|
-
});
|
|
57
|
-
return computed(() => {
|
|
58
|
-
const seq = sequence.value;
|
|
59
|
-
const base = config() ?? (fallback ?? (fallback = generateRandomConfig()));
|
|
60
|
-
if (!seq) return generateFace(base);
|
|
61
|
-
const frame = seq.frames[frameIndex.value];
|
|
62
|
-
if (!frame) return generateFace(base);
|
|
63
|
-
return generateFace({ ...base, ...frame.overrides });
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
var Avatar = defineComponent({
|
|
67
|
-
name: "Avatar",
|
|
68
|
-
props: {
|
|
69
|
-
config: {
|
|
70
|
-
type: Object,
|
|
71
|
-
default: void 0
|
|
72
|
-
},
|
|
73
|
-
size: {
|
|
74
|
-
type: Number,
|
|
75
|
-
default: 128
|
|
76
|
-
},
|
|
77
|
-
animation: {
|
|
78
|
-
type: [String, Object],
|
|
79
|
-
default: void 0
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
setup(props) {
|
|
83
|
-
const svg = useAnimatedAvatar(
|
|
84
|
-
() => props.config,
|
|
85
|
-
() => props.animation
|
|
86
|
-
);
|
|
87
|
-
return () => h("div", {
|
|
88
|
-
innerHTML: svg.value,
|
|
89
|
-
style: {
|
|
90
|
-
width: `${props.size}px`,
|
|
91
|
-
height: `${props.size}px`,
|
|
92
|
-
imageRendering: "pixelated"
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
export {
|
|
98
|
-
Avatar,
|
|
99
|
-
generateRandomConfig,
|
|
100
|
-
useAnimatedAvatar,
|
|
101
|
-
useAvatar
|
|
102
|
-
};
|
|
103
|
-
//# sourceMappingURL=vue.js.map
|
|
1
|
+
import{d as f,e as o,h as c}from"./chunk-SFAUE3EN.js";import{computed as m,ref as l,watch as g,onUnmounted as y,defineComponent as v,h as x}from"vue";function h(n){let i;return m(()=>{let t=n?.();return t?o(t):(i||(i=f()),o(i))})}function A(n,i){let t=l(0),a,p,u=m(()=>{let e=i();if(e)return typeof e=="string"?c[e]:e});function d(){let e=u.value;if(!e)return;let r=e.frames[t.value];r&&(a=setTimeout(()=>{t.value=(t.value+1)%e.frames.length,d()},r.duration))}return g(u,()=>{a!==void 0&&clearTimeout(a),t.value=0,d()},{immediate:!0}),y(()=>{a!==void 0&&clearTimeout(a)}),m(()=>{let e=u.value,r=n()??p??(p=f());if(!e)return o(r);let s=e.frames[t.value];return s?o({...r,...s.overrides}):o(r)})}var q=v({name:"Avatar",props:{config:{type:Object,default:void 0},size:{type:Number,default:128},animation:{type:[String,Object],default:void 0}},setup(n){let i=A(()=>n.config,()=>n.animation);return()=>x("div",{innerHTML:i.value,style:{width:`${n.size}px`,height:`${n.size}px`,imageRendering:"pixelated"}})}});export{q as Avatar,f as generateRandomConfig,A as useAnimatedAvatar,h as useAvatar};
|