kashi 3.0.0 → 3.0.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 +74 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -101,31 +101,82 @@ Since the library was designed primarily to be used with vanilla JS, a _helper_
|
|
|
101
101
|
> **Note**: There is TypeScript support, and even if your project doesn't use the JS superset, it should help VSCode and other editors provide autocomplete/code suggestions.
|
|
102
102
|
|
|
103
103
|
```tsx
|
|
104
|
-
import { useEffect, useRef } from "react";
|
|
104
|
+
import { memo, useEffect, useRef } from "react";
|
|
105
105
|
import { Kashi, KashiProps } from "kashi";
|
|
106
106
|
|
|
107
|
+
import { api } from "@/services/axios";
|
|
108
|
+
|
|
107
109
|
// Example using Vite, React and TypeScript
|
|
108
|
-
export const KashiWrapper = (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
export const KashiWrapper = memo(
|
|
111
|
+
(props: Omit<KashiProps, "container"> & { url: string }) => {
|
|
112
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
113
|
+
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
async function loadKashi() {
|
|
116
|
+
if (!ref.current) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!props.url) {
|
|
121
|
+
ref.current.innerHTML = "";
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
const { url, ...rest } = props;
|
|
127
|
+
|
|
128
|
+
const response = await api.get(url, { responseType: "blob" });
|
|
129
|
+
|
|
130
|
+
new Kashi({
|
|
131
|
+
...rest,
|
|
132
|
+
file: response.data,
|
|
133
|
+
container: ref.current,
|
|
134
|
+
});
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.error("Error loading Kashi:", error);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
118
139
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
140
|
+
loadKashi();
|
|
141
|
+
|
|
142
|
+
return () => {
|
|
143
|
+
// Required to avoid duplication when React is in Strict Mode
|
|
144
|
+
if (ref.current) {
|
|
145
|
+
ref.current.innerHTML = "";
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}, [ref.current, props]);
|
|
149
|
+
|
|
150
|
+
return <div className="kashi-wrapper" ref={ref} />;
|
|
151
|
+
},
|
|
152
|
+
(prevProps, nextProps) => {
|
|
153
|
+
function compareObjects(
|
|
154
|
+
obj1: Omit<KashiProps, "container">,
|
|
155
|
+
obj2: Omit<KashiProps, "container">,
|
|
156
|
+
) {
|
|
157
|
+
const keys1 = Object.keys(obj1) as Array<
|
|
158
|
+
keyof Omit<KashiProps, "container">
|
|
159
|
+
>;
|
|
160
|
+
const keys2 = Object.keys(obj2) as Array<
|
|
161
|
+
keyof Omit<KashiProps, "container">
|
|
162
|
+
>;
|
|
163
|
+
|
|
164
|
+
if (keys1.length !== keys2.length) {
|
|
165
|
+
return false;
|
|
123
166
|
}
|
|
124
|
-
};
|
|
125
|
-
}, [ref.current]);
|
|
126
167
|
|
|
127
|
-
|
|
128
|
-
|
|
168
|
+
for (const key of keys1) {
|
|
169
|
+
if (obj1[key] !== obj2[key]) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return compareObjects(prevProps, nextProps);
|
|
178
|
+
},
|
|
179
|
+
);
|
|
129
180
|
```
|
|
130
181
|
|
|
131
182
|
## 🧐 Constructor properties
|
|
@@ -149,7 +200,7 @@ Here's an example:
|
|
|
149
200
|
|
|
150
201
|
```html
|
|
151
202
|
<div id="kashi">
|
|
152
|
-
<
|
|
203
|
+
<p>
|
|
153
204
|
<span data-time="00:17.55" data-ms-time="17550" data-empty="false" data-aria-current="false">
|
|
154
205
|
Telling myself, "I won't go there"
|
|
155
206
|
</span>
|
|
@@ -174,7 +225,7 @@ Here's an example:
|
|
|
174
225
|
Souls tied, intertwined by our pride and guilt
|
|
175
226
|
</span>
|
|
176
227
|
<!-- ... -->
|
|
177
|
-
</
|
|
228
|
+
</p>
|
|
178
229
|
</div>
|
|
179
230
|
```
|
|
180
231
|
|
|
@@ -189,7 +240,7 @@ The instance generated by `Kashi` has some public methods and attributes that ca
|
|
|
189
240
|
| `noLyricsText` | Attribute | Returns the text set for when there are no lyrics |
|
|
190
241
|
| `setFile` | Method | Function capable of changing the current lyrics file by passing the the new **file** |
|
|
191
242
|
| `setEmptyLineText` | Method | Function capable of changing the text defined for empty lines |
|
|
192
|
-
| `
|
|
243
|
+
| `setNoLyricsText` | Method | Function capable of changing the text defined for when there are no lyrics |
|
|
193
244
|
| `subscribe` | Method | Function capable of defining a callback to be executed when a given event is triggered |
|
|
194
245
|
| `unsubscribe` | Method | Function capable of making a callback to stop listening to an event |
|
|
195
246
|
| `notify` | Method | Function capable of triggering an event |
|
|
@@ -202,7 +253,7 @@ When creating a new instance using `Kashi` you will have access to the `subscrib
|
|
|
202
253
|
| ------------------- | --------------------------- | ------------------------------------------ |
|
|
203
254
|
| `fileSet` | `{ file: Blob }` | When calling the `setFile` method |
|
|
204
255
|
| `emptyLineTextSet` | `{ emptyLineText: string }` | When calling the `setEmptyLineText` method |
|
|
205
|
-
| `
|
|
256
|
+
| `noLyricsTextSet` | `{ noLyricsText: text }` | When calling the `setNoLyricsText` method |
|
|
206
257
|
| `lyricLinesUpdated` | `{ lyricLines: string[] }` | When inserting/updating lyrics in HTML |
|
|
207
258
|
|
|
208
259
|
## 🤔 How do I run the project on my machine?
|