@x-plat/design-system 0.3.6 → 0.3.8

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.
@@ -130,6 +130,7 @@ var HtmlTypeWriter = ({
130
130
  const [typedLen, setTypedLen] = import_react2.default.useState(0);
131
131
  const doneCalledRef = import_react2.default.useRef(false);
132
132
  const { doc, rangeMap, totalLength } = import_react2.default.useMemo(() => {
133
+ if (typeof window === "undefined") return { doc: null, rangeMap: /* @__PURE__ */ new Map(), totalLength: 0 };
133
134
  const decoded = decodeHtmlEntities(html);
134
135
  const doc2 = new DOMParser().parseFromString(decoded, "text/html");
135
136
  const { rangeMap: rangeMap2, totalLength: totalLength2 } = buildRangeMap(doc2.body);
@@ -159,8 +160,8 @@ var HtmlTypeWriter = ({
159
160
  }
160
161
  }, [typedLen, totalLength, onDone]);
161
162
  const parsed = import_react2.default.useMemo(
162
- () => htmlToReactProgressive(doc.body, typedLen, rangeMap),
163
- [doc.body, typedLen, rangeMap]
163
+ () => doc ? htmlToReactProgressive(doc.body, typedLen, rangeMap) : null,
164
+ [doc, typedLen, rangeMap]
164
165
  );
165
166
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "lib-xplat-htmlTypewriter", children: parsed });
166
167
  };
@@ -94,6 +94,7 @@ var HtmlTypeWriter = ({
94
94
  const [typedLen, setTypedLen] = React2.useState(0);
95
95
  const doneCalledRef = React2.useRef(false);
96
96
  const { doc, rangeMap, totalLength } = React2.useMemo(() => {
97
+ if (typeof window === "undefined") return { doc: null, rangeMap: /* @__PURE__ */ new Map(), totalLength: 0 };
97
98
  const decoded = decodeHtmlEntities(html);
98
99
  const doc2 = new DOMParser().parseFromString(decoded, "text/html");
99
100
  const { rangeMap: rangeMap2, totalLength: totalLength2 } = buildRangeMap(doc2.body);
@@ -123,8 +124,8 @@ var HtmlTypeWriter = ({
123
124
  }
124
125
  }, [typedLen, totalLength, onDone]);
125
126
  const parsed = React2.useMemo(
126
- () => htmlToReactProgressive(doc.body, typedLen, rangeMap),
127
- [doc.body, typedLen, rangeMap]
127
+ () => doc ? htmlToReactProgressive(doc.body, typedLen, rangeMap) : null,
128
+ [doc, typedLen, rangeMap]
128
129
  );
129
130
  return /* @__PURE__ */ jsx("div", { className: "lib-xplat-htmlTypewriter", children: parsed });
130
131
  };
@@ -115,22 +115,29 @@ var Swiper = (props) => {
115
115
  const realIndex = getRealIndex(innerIndex);
116
116
  const moveToInner = import_react.default.useCallback(
117
117
  (idx, withAnim = true) => {
118
- if (useLoop) {
119
- setInnerIndex((prev) => {
120
- const real = ((prev - cloneCount) % totalSlides + totalSlides) % totalSlides;
121
- const canonical = cloneCount + real;
122
- if (prev !== canonical) {
123
- const delta = idx - prev;
124
- setAnimated(withAnim);
125
- return canonical + delta;
126
- }
127
- setAnimated(withAnim);
128
- return idx;
129
- });
130
- } else {
118
+ if (!useLoop) {
131
119
  setAnimated(withAnim);
132
120
  setInnerIndex(idx);
121
+ return;
133
122
  }
123
+ setInnerIndex((prev) => {
124
+ const real = ((prev - cloneCount) % totalSlides + totalSlides) % totalSlides;
125
+ const canonical = cloneCount + real;
126
+ const delta = idx - prev;
127
+ const target = canonical + delta;
128
+ if (prev !== canonical) {
129
+ setAnimated(false);
130
+ requestAnimationFrame(() => {
131
+ requestAnimationFrame(() => {
132
+ setAnimated(withAnim);
133
+ setInnerIndex(target);
134
+ });
135
+ });
136
+ return canonical;
137
+ }
138
+ setAnimated(withAnim);
139
+ return target;
140
+ });
134
141
  },
135
142
  [useLoop, cloneCount, totalSlides]
136
143
  );
@@ -139,10 +146,11 @@ var Swiper = (props) => {
139
146
  const real = getRealIndex(innerIndex);
140
147
  const canonical = cloneCount + real;
141
148
  if (innerIndex !== canonical) {
142
- moveToInner(canonical, false);
149
+ setAnimated(false);
150
+ setInnerIndex(canonical);
143
151
  }
144
152
  onChange?.(Math.min(real, maxIndex));
145
- }, [useLoop, innerIndex, cloneCount, totalSlides, maxIndex, onChange, moveToInner]);
153
+ }, [useLoop, innerIndex, cloneCount, totalSlides, maxIndex, onChange]);
146
154
  const slideTo = import_react.default.useCallback(
147
155
  (logicalIndex) => {
148
156
  if (!canSlide) return;
@@ -79,22 +79,29 @@ var Swiper = (props) => {
79
79
  const realIndex = getRealIndex(innerIndex);
80
80
  const moveToInner = React.useCallback(
81
81
  (idx, withAnim = true) => {
82
- if (useLoop) {
83
- setInnerIndex((prev) => {
84
- const real = ((prev - cloneCount) % totalSlides + totalSlides) % totalSlides;
85
- const canonical = cloneCount + real;
86
- if (prev !== canonical) {
87
- const delta = idx - prev;
88
- setAnimated(withAnim);
89
- return canonical + delta;
90
- }
91
- setAnimated(withAnim);
92
- return idx;
93
- });
94
- } else {
82
+ if (!useLoop) {
95
83
  setAnimated(withAnim);
96
84
  setInnerIndex(idx);
85
+ return;
97
86
  }
87
+ setInnerIndex((prev) => {
88
+ const real = ((prev - cloneCount) % totalSlides + totalSlides) % totalSlides;
89
+ const canonical = cloneCount + real;
90
+ const delta = idx - prev;
91
+ const target = canonical + delta;
92
+ if (prev !== canonical) {
93
+ setAnimated(false);
94
+ requestAnimationFrame(() => {
95
+ requestAnimationFrame(() => {
96
+ setAnimated(withAnim);
97
+ setInnerIndex(target);
98
+ });
99
+ });
100
+ return canonical;
101
+ }
102
+ setAnimated(withAnim);
103
+ return target;
104
+ });
98
105
  },
99
106
  [useLoop, cloneCount, totalSlides]
100
107
  );
@@ -103,10 +110,11 @@ var Swiper = (props) => {
103
110
  const real = getRealIndex(innerIndex);
104
111
  const canonical = cloneCount + real;
105
112
  if (innerIndex !== canonical) {
106
- moveToInner(canonical, false);
113
+ setAnimated(false);
114
+ setInnerIndex(canonical);
107
115
  }
108
116
  onChange?.(Math.min(real, maxIndex));
109
- }, [useLoop, innerIndex, cloneCount, totalSlides, maxIndex, onChange, moveToInner]);
117
+ }, [useLoop, innerIndex, cloneCount, totalSlides, maxIndex, onChange]);
110
118
  const slideTo = React.useCallback(
111
119
  (logicalIndex) => {
112
120
  if (!canSlide) return;