kashi 3.0.0 → 3.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.
Files changed (2) hide show
  1. package/README.md +72 -21
  2. 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 = (props: Omit<KashiProps, "container">) => {
109
- const ref = useRef<HTMLDivElement>(null);
110
-
111
- useEffect(() => {
112
- if (ref.current) {
113
- new Kashi({
114
- ...props,
115
- container: ref.current,
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
- return () => {
120
- // Required to avoid duplication when React is in Strict Mode
121
- if (ref.current) {
122
- ref.current.innerHTML = "";
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
- return <div className="kashi-wrapper" ref={ref} />;
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
- <sp>
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
- </sp>
228
+ </p>
178
229
  </div>
179
230
  ```
180
231
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kashi",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Singing at the top of my lungs",
5
5
  "type": "module",
6
6
  "author": "lucasmc64",