@novely/solid-renderer 0.0.6 → 0.0.7

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/index.jsx CHANGED
@@ -122,31 +122,99 @@ var Modal = (props) => {
122
122
  };
123
123
 
124
124
  // ../typewriter/dist/index.js
125
- var b = () => Math.min(90 * Math.random() + 100, 90);
126
- var v = ({ node: N, text: m, ended: c, speed: T = b }) => {
127
- let e = document.createElement("span");
128
- e.innerHTML = m;
129
- let l = (t, M) => {
130
- let d = [];
131
- return t.childNodes.forEach((s) => {
132
- s.nodeName === "#text" && (d.push(s), M && (s.textContent = "")), d.push(...l(s, M));
133
- }), d;
134
- }, u = l(e.cloneNode(true), false).map((t) => [...t.textContent]), q = l(e, true);
135
- N.appendChild(e);
136
- let n = 0, a = 0, r = false, p, i = () => {
137
- p = requestAnimationFrame(x);
138
- }, o = () => {
139
- cancelAnimationFrame(p);
140
- }, f = 0, h = 0, x = (t) => {
141
- t >= h + f ? (h = t, f = T(), C()) : r ? o() : i();
142
- }, C = () => {
143
- u[n]?.length > a ? (q[n].textContent += u[n][a++], i()) : n++ < u.length ? (a = 0, i()) : (r = true, o(), c && c());
125
+ var defaultSpeed = () => {
126
+ return Math.min(90 * Math.random() + 100, 90);
127
+ };
128
+ var collectTextNodes = (el) => {
129
+ const items = [];
130
+ el.childNodes.forEach((child) => {
131
+ if (child.nodeName === "#text")
132
+ items.push(child);
133
+ else
134
+ items.push(...collectTextNodes(child));
135
+ });
136
+ return items;
137
+ };
138
+ var typewriter = ({ node, text, ended, speed = defaultSpeed }) => {
139
+ node.innerHTML = text;
140
+ const nodes = collectTextNodes(node).map((child) => {
141
+ const letters = [...child.textContent].map((char) => {
142
+ const text2 = document.createElement("span");
143
+ text2.textContent = char;
144
+ text2.style.cssText = "opacity: 0;";
145
+ return text2;
146
+ });
147
+ child.replaceWith(...letters);
148
+ return letters;
149
+ });
150
+ let current = 0;
151
+ let pos = 0;
152
+ let end = false;
153
+ let frame;
154
+ const enqueue = () => {
155
+ frame = requestAnimationFrame(queue);
156
+ };
157
+ const dequeue = () => {
158
+ cancelAnimationFrame(frame);
159
+ };
160
+ let timeout = 0;
161
+ let start = 0;
162
+ let container;
163
+ const queue = (time) => {
164
+ if (time >= start + timeout) {
165
+ start = time;
166
+ timeout = speed();
167
+ process();
168
+ } else if (!end) {
169
+ enqueue();
170
+ } else {
171
+ dequeue();
172
+ }
173
+ };
174
+ const process = () => {
175
+ const block = nodes[current];
176
+ if (block?.length > pos) {
177
+ const span = block[pos];
178
+ const text2 = span.textContent;
179
+ if (pos++ === 0) {
180
+ span.replaceWith(container = document.createTextNode(text2));
181
+ } else {
182
+ container.textContent += text2;
183
+ span.remove();
184
+ }
185
+ enqueue();
186
+ } else if (current++ < nodes.length) {
187
+ pos = 0;
188
+ enqueue();
189
+ } else {
190
+ end = true;
191
+ dequeue();
192
+ ended && ended();
193
+ }
194
+ };
195
+ process();
196
+ return {
197
+ /**
198
+ * End
199
+ */
200
+ end() {
201
+ dequeue();
202
+ if (end) {
203
+ node.innerHTML = "";
204
+ return end;
205
+ }
206
+ node.innerHTML = text;
207
+ end = true;
208
+ return false;
209
+ },
210
+ /**
211
+ * Destroy
212
+ */
213
+ destroy() {
214
+ dequeue();
215
+ node.innerHTML = "";
216
+ }
144
217
  };
145
- return C(), { end() {
146
- return o(), r ? (e.remove(), true) : (e.innerHTML = m, r = true, false);
147
- }, destroy() {
148
- o(), e.remove();
149
- } };
150
218
  };
151
219
 
152
220
  // src/screens/game.tsx
@@ -172,7 +240,9 @@ var Game = (props) => {
172
240
  writer?.destroy();
173
241
  if (!element)
174
242
  return;
175
- writer = v({
243
+ if (!text)
244
+ return;
245
+ writer = typewriter({
176
246
  node: element,
177
247
  text,
178
248
  ended() {
@@ -297,10 +367,7 @@ var Game = (props) => {
297
367
  <button
298
368
  type="button"
299
369
  class="button control-panel__button"
300
- onClick={() => {
301
- data.options.stack.back();
302
- data.options.restore(data.options.stack.value);
303
- }}
370
+ onClick={data.options.back}
304
371
  >{data.t("GoBack")}</button>
305
372
  <button
306
373
  type="button"
@@ -394,17 +394,13 @@
394
394
  background-color: var(--novely-dialog-background-color, #f092b4d8);
395
395
  background-position: var(--novely-dialog-background-position, 0 0, 50px 50px);
396
396
  background-size: var(--novely-dialog-background-size, 100px 100px);
397
- display: grid;
398
- grid-template-areas: "pers text" "pers text";
397
+ display: flex;
398
+ flex-wrap: nowrap;
399
399
  padding-bottom: 2.8em;
400
400
  }
401
- .action-dialog-container[data-no-person=true] {
402
- grid-template-areas: "text text" "text text";
403
- }
404
401
  .action-dialog-person {
405
402
  max-height: 25vh;
406
403
  max-width: 25vw;
407
- grid-area: pers;
408
404
  }
409
405
  .action-dialog-name,
410
406
  .action-dialog-content {
@@ -423,10 +419,9 @@
423
419
  box-shadow: 1px 1px 3px #00000042;
424
420
  }
425
421
  .action-dialog-content {
422
+ width: 100%;
426
423
  font-size: 2.2375em;
427
424
  line-height: 1.2;
428
- width: 100%;
429
- grid-area: text;
430
425
  text-shadow:
431
426
  1px 1px 0 black,
432
427
  -1px -1px 0 black,
@@ -435,7 +430,9 @@
435
430
  }
436
431
  .action-dialog-person > canvas,
437
432
  .action-dialog-person > img {
438
- height: 100%;
433
+ max-height: 100%;
434
+ max-width: 100%;
435
+ object-fit: contain;
439
436
  }
440
437
  @media (orientation: portrait) {
441
438
  .action-dialog {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novely/solid-renderer",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"