-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfates-descent.js
17748 lines (17743 loc) · 558 KB
/
fates-descent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const MODULE_ID = "fates-descent";
function FDregisterSettings() {
game.settings.register(MODULE_ID, "enableModule", {
name: "Enable Fate's Descent",
hint: "Enable or disable the Fate's Descent module.",
scope: "world",
config: true,
type: Boolean,
default: true
});
game.settings.register(MODULE_ID, "startingSanityPoints", {
name: "Starting Sanity Points",
hint: "Set the initial amount of Sanity Points before modifiers.",
scope: "world",
config: true,
type: Number,
default: 28
});
game.settings.register(MODULE_ID, "startingMadnessPoints", {
name: "Starting Madness Limit",
hint: "Set the initial amount of Madness Points before modifiers.",
scope: "world",
config: true,
type: Number,
default: 8
});
game.settings.register(MODULE_ID, "globalSaveRequests", {
scope: "world",
config: false,
type: Array,
default: []
});
game.settings.register(MODULE_ID, "globalTestRequests", {
scope: "world",
config: false,
type: Array,
default: []
});
for (let i = 1; i <= 3; i++) {
game.settings.register(MODULE_ID, `enableMadnessRange${i}`, {
name: `Enable Sanity Points Range ${i}`,
hint: `Enable or disable the addition of madness points for range ${i}.`,
scope: "world",
config: true,
type: Boolean,
default: true
});
game.settings.register(MODULE_ID, `madnessRange${i}Start`, {
name: `Sanity Points Range ${i} Start`,
hint: `The starting sanity point for range ${i}.`,
scope: "world",
config: true,
type: Number,
default: i === 1 ? 0 : i === 2 ? 10 : 20
});
if (i < 3) {
game.settings.register(MODULE_ID, `madnessRange${i}End`, {
name: `Sanity Points Range ${i} End`,
hint: `The ending sanity point for range ${i}.`,
scope: "world",
config: true,
type: Number,
default: i === 1 ? 9 : 19
});
}
game.settings.register(MODULE_ID, `madnessRange${i}Increment`, {
name: `Madness Points ${i} Increment`,
hint: `The amount of madness points to add for range ${i}.`,
scope: "world",
config: true,
type: Number,
default: i === 1 ? 2 : i === 2 ? 1 : 0
});
}
game.settings.register(MODULE_ID, "shortTermInsanityReduction", {
name: "Short-Term Madness Reduction",
hint: "Set the number of madness points reduced when a short-term insanity effect is gained.",
scope: "world",
config: true,
type: Number,
default: 1
});
game.settings.register(MODULE_ID, "longTermInsanityReduction", {
name: "Long-Term Madness Reduction",
hint: "Set the number of madness points reduced when a long-term insanity effect is gained.",
scope: "world",
config: true,
type: Number,
default: 3
});
const severities = ["minimal", "moderate", "serious", "extreme"];
severities.forEach((severity) => {
game.settings.register(MODULE_ID, `${severity}DC`, {
name: `${severity.charAt(0).toUpperCase() + severity.slice(1)} Severity DC`,
hint: `Set the DC for ${severity} severity.`,
scope: "world",
config: true,
type: Number,
default: severity === "minimal" ? 8 : severity === "moderate" ? 12 : severity === "serious" ? 16 : 20
});
game.settings.register(MODULE_ID, `${severity}Loss`, {
name: `${severity.charAt(0).toUpperCase() + severity.slice(1)} Severity Loss`,
hint: `Set the loss amount for ${severity} severity.`,
scope: "world",
config: true,
type: String,
default: severity === "minimal" ? "1d4" : severity === "moderate" ? "1d6" : severity === "serious" ? "1d8" : "1d10"
});
});
game.settings.register(MODULE_ID, "debug", {
name: "Enable Debug Logging",
hint: "Enable or disable debug logging for the Fate's Descent module.",
scope: "world",
config: true,
type: Boolean,
default: false
});
}
Hooks.on("renderSettingsConfig", (app, html) => {
const settings = [
{ key: "startingSanityPoints", header: "Starting Sanity & Madness" },
{ key: "enableMadnessRange1", header: "Sanity Point Range 1" },
{ key: "enableMadnessRange2", header: "Sanity Point Range 2" },
{ key: "enableMadnessRange3", header: "Sanity Point Range 3" },
{ key: "shortTermInsanityReduction", header: "Rolltable Madness Reductions" },
{ key: "minimalDC", header: "Severity Levels" },
{ key: "debug", header: "Debug Settings" }
];
settings.forEach((setting) => {
const element2 = html[0].querySelector(`[data-setting-id="fates-descent.${setting.key}"]`);
if (element2) {
element2.insertAdjacentHTML("beforeBegin", `<h3>${setting.header}</h3>`);
}
});
});
function debugLog(message, styling2, additionalData = null) {
if (game.settings.get(MODULE_ID, "debug")) {
console.log(`%c${message}`, styling2);
if (additionalData !== null) {
console.log(additionalData);
}
}
}
function noop() {
}
const identity = (x) => x;
function assign(tar, src) {
for (const k in src)
tar[k] = src[k];
return (
/** @type {T & S} */
tar
);
}
function run(fn) {
return fn();
}
function blank_object() {
return /* @__PURE__ */ Object.create(null);
}
function run_all(fns) {
fns.forEach(run);
}
function is_function(thing) {
return typeof thing === "function";
}
function safe_not_equal(a, b) {
return a != a ? b == b : a !== b || a && typeof a === "object" || typeof a === "function";
}
let src_url_equal_anchor;
function src_url_equal(element_src, url) {
if (element_src === url)
return true;
if (!src_url_equal_anchor) {
src_url_equal_anchor = document.createElement("a");
}
src_url_equal_anchor.href = url;
return element_src === src_url_equal_anchor.href;
}
function is_empty(obj) {
return Object.keys(obj).length === 0;
}
function subscribe(store, ...callbacks) {
if (store == null) {
for (const callback of callbacks) {
callback(void 0);
}
return noop;
}
const unsub = store.subscribe(...callbacks);
return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
}
function get_store_value(store) {
let value;
subscribe(store, (_) => value = _)();
return value;
}
function component_subscribe(component, store, callback) {
component.$$.on_destroy.push(subscribe(store, callback));
}
function create_slot(definition, ctx, $$scope, fn) {
if (definition) {
const slot_ctx = get_slot_context(definition, ctx, $$scope, fn);
return definition[0](slot_ctx);
}
}
function get_slot_context(definition, ctx, $$scope, fn) {
return definition[1] && fn ? assign($$scope.ctx.slice(), definition[1](fn(ctx))) : $$scope.ctx;
}
function get_slot_changes(definition, $$scope, dirty, fn) {
if (definition[2] && fn) {
const lets = definition[2](fn(dirty));
if ($$scope.dirty === void 0) {
return lets;
}
if (typeof lets === "object") {
const merged = [];
const len = Math.max($$scope.dirty.length, lets.length);
for (let i = 0; i < len; i += 1) {
merged[i] = $$scope.dirty[i] | lets[i];
}
return merged;
}
return $$scope.dirty | lets;
}
return $$scope.dirty;
}
function update_slot_base(slot, slot_definition, ctx, $$scope, slot_changes, get_slot_context_fn) {
if (slot_changes) {
const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn);
slot.p(slot_context, slot_changes);
}
}
function get_all_dirty_from_scope($$scope) {
if ($$scope.ctx.length > 32) {
const dirty = [];
const length = $$scope.ctx.length / 32;
for (let i = 0; i < length; i++) {
dirty[i] = -1;
}
return dirty;
}
return -1;
}
function null_to_empty(value) {
return value == null ? "" : value;
}
function action_destroyer(action_result) {
return action_result && is_function(action_result.destroy) ? action_result.destroy : noop;
}
const is_client = typeof window !== "undefined";
let now = is_client ? () => window.performance.now() : () => Date.now();
let raf = is_client ? (cb) => requestAnimationFrame(cb) : noop;
const tasks = /* @__PURE__ */ new Set();
function run_tasks(now2) {
tasks.forEach((task) => {
if (!task.c(now2)) {
tasks.delete(task);
task.f();
}
});
if (tasks.size !== 0)
raf(run_tasks);
}
function loop(callback) {
let task;
if (tasks.size === 0)
raf(run_tasks);
return {
promise: new Promise((fulfill) => {
tasks.add(task = { c: callback, f: fulfill });
}),
abort() {
tasks.delete(task);
}
};
}
function append(target, node) {
target.appendChild(node);
}
function get_root_for_style(node) {
if (!node)
return document;
const root = node.getRootNode ? node.getRootNode() : node.ownerDocument;
if (root && /** @type {ShadowRoot} */
root.host) {
return (
/** @type {ShadowRoot} */
root
);
}
return node.ownerDocument;
}
function append_empty_stylesheet(node) {
const style_element = element("style");
style_element.textContent = "/* empty */";
append_stylesheet(get_root_for_style(node), style_element);
return style_element.sheet;
}
function append_stylesheet(node, style) {
append(
/** @type {Document} */
node.head || node,
style
);
return style.sheet;
}
function insert(target, node, anchor) {
target.insertBefore(node, anchor || null);
}
function detach(node) {
if (node.parentNode) {
node.parentNode.removeChild(node);
}
}
function destroy_each(iterations, detaching) {
for (let i = 0; i < iterations.length; i += 1) {
if (iterations[i])
iterations[i].d(detaching);
}
}
function element(name) {
return document.createElement(name);
}
function svg_element(name) {
return document.createElementNS("http://www.w3.org/2000/svg", name);
}
function text(data) {
return document.createTextNode(data);
}
function space() {
return text(" ");
}
function empty() {
return text("");
}
function listen(node, event, handler, options) {
node.addEventListener(event, handler, options);
return () => node.removeEventListener(event, handler, options);
}
function prevent_default(fn) {
return function(event) {
event.preventDefault();
return fn.call(this, event);
};
}
function stop_propagation(fn) {
return function(event) {
event.stopPropagation();
return fn.call(this, event);
};
}
function attr(node, attribute, value) {
if (value == null)
node.removeAttribute(attribute);
else if (node.getAttribute(attribute) !== value)
node.setAttribute(attribute, value);
}
function children(element2) {
return Array.from(element2.childNodes);
}
function set_data(text2, data) {
data = "" + data;
if (text2.data === data)
return;
text2.data = /** @type {string} */
data;
}
function set_input_value(input, value) {
input.value = value == null ? "" : value;
}
function set_style(node, key, value, important) {
if (value == null) {
node.style.removeProperty(key);
} else {
node.style.setProperty(key, value, important ? "important" : "");
}
}
function select_option(select, value, mounting) {
for (let i = 0; i < select.options.length; i += 1) {
const option = select.options[i];
if (option.__value === value) {
option.selected = true;
return;
}
}
if (!mounting || value !== void 0) {
select.selectedIndex = -1;
}
}
function select_value(select) {
const selected_option = select.querySelector(":checked");
return selected_option && selected_option.__value;
}
function toggle_class(element2, name, toggle) {
element2.classList.toggle(name, !!toggle);
}
function custom_event(type, detail, { bubbles = false, cancelable = false } = {}) {
return new CustomEvent(type, { detail, bubbles, cancelable });
}
class HtmlTag {
/**
* @private
* @default false
*/
is_svg = false;
/** parent for creating node */
e = void 0;
/** html tag nodes */
n = void 0;
/** target */
t = void 0;
/** anchor */
a = void 0;
constructor(is_svg = false) {
this.is_svg = is_svg;
this.e = this.n = null;
}
/**
* @param {string} html
* @returns {void}
*/
c(html) {
this.h(html);
}
/**
* @param {string} html
* @param {HTMLElement | SVGElement} target
* @param {HTMLElement | SVGElement} anchor
* @returns {void}
*/
m(html, target, anchor = null) {
if (!this.e) {
if (this.is_svg)
this.e = svg_element(
/** @type {keyof SVGElementTagNameMap} */
target.nodeName
);
else
this.e = element(
/** @type {keyof HTMLElementTagNameMap} */
target.nodeType === 11 ? "TEMPLATE" : target.nodeName
);
this.t = target.tagName !== "TEMPLATE" ? target : (
/** @type {HTMLTemplateElement} */
target.content
);
this.c(html);
}
this.i(anchor);
}
/**
* @param {string} html
* @returns {void}
*/
h(html) {
this.e.innerHTML = html;
this.n = Array.from(
this.e.nodeName === "TEMPLATE" ? this.e.content.childNodes : this.e.childNodes
);
}
/**
* @returns {void} */
i(anchor) {
for (let i = 0; i < this.n.length; i += 1) {
insert(this.t, this.n[i], anchor);
}
}
/**
* @param {string} html
* @returns {void}
*/
p(html) {
this.d();
this.h(html);
this.i(this.a);
}
/**
* @returns {void} */
d() {
this.n.forEach(detach);
}
}
function construct_svelte_component(component, props) {
return new component(props);
}
const managed_styles = /* @__PURE__ */ new Map();
let active = 0;
function hash(str) {
let hash2 = 5381;
let i = str.length;
while (i--)
hash2 = (hash2 << 5) - hash2 ^ str.charCodeAt(i);
return hash2 >>> 0;
}
function create_style_information(doc, node) {
const info = { stylesheet: append_empty_stylesheet(node), rules: {} };
managed_styles.set(doc, info);
return info;
}
function create_rule(node, a, b, duration, delay, ease, fn, uid = 0) {
const step = 16.666 / duration;
let keyframes = "{\n";
for (let p = 0; p <= 1; p += step) {
const t = a + (b - a) * ease(p);
keyframes += p * 100 + `%{${fn(t, 1 - t)}}
`;
}
const rule = keyframes + `100% {${fn(b, 1 - b)}}
}`;
const name = `__svelte_${hash(rule)}_${uid}`;
const doc = get_root_for_style(node);
const { stylesheet, rules } = managed_styles.get(doc) || create_style_information(doc, node);
if (!rules[name]) {
rules[name] = true;
stylesheet.insertRule(`@keyframes ${name} ${rule}`, stylesheet.cssRules.length);
}
const animation = node.style.animation || "";
node.style.animation = `${animation ? `${animation}, ` : ""}${name} ${duration}ms linear ${delay}ms 1 both`;
active += 1;
return name;
}
function delete_rule(node, name) {
const previous = (node.style.animation || "").split(", ");
const next = previous.filter(
name ? (anim) => anim.indexOf(name) < 0 : (anim) => anim.indexOf("__svelte") === -1
// remove all Svelte animations
);
const deleted = previous.length - next.length;
if (deleted) {
node.style.animation = next.join(", ");
active -= deleted;
if (!active)
clear_rules();
}
}
function clear_rules() {
raf(() => {
if (active)
return;
managed_styles.forEach((info) => {
const { ownerNode } = info.stylesheet;
if (ownerNode)
detach(ownerNode);
});
managed_styles.clear();
});
}
let current_component;
function set_current_component(component) {
current_component = component;
}
function get_current_component() {
if (!current_component)
throw new Error("Function called outside component initialization");
return current_component;
}
function onMount(fn) {
get_current_component().$$.on_mount.push(fn);
}
function onDestroy(fn) {
get_current_component().$$.on_destroy.push(fn);
}
function createEventDispatcher() {
const component = get_current_component();
return (type, detail, { cancelable = false } = {}) => {
const callbacks = component.$$.callbacks[type];
if (callbacks) {
const event = custom_event(
/** @type {string} */
type,
detail,
{ cancelable }
);
callbacks.slice().forEach((fn) => {
fn.call(component, event);
});
return !event.defaultPrevented;
}
return true;
};
}
function setContext(key, context) {
get_current_component().$$.context.set(key, context);
return context;
}
function getContext(key) {
return get_current_component().$$.context.get(key);
}
const dirty_components = [];
const binding_callbacks = [];
let render_callbacks = [];
const flush_callbacks = [];
const resolved_promise = /* @__PURE__ */ Promise.resolve();
let update_scheduled = false;
function schedule_update() {
if (!update_scheduled) {
update_scheduled = true;
resolved_promise.then(flush);
}
}
function add_render_callback(fn) {
render_callbacks.push(fn);
}
function add_flush_callback(fn) {
flush_callbacks.push(fn);
}
const seen_callbacks = /* @__PURE__ */ new Set();
let flushidx = 0;
function flush() {
if (flushidx !== 0) {
return;
}
const saved_component = current_component;
do {
try {
while (flushidx < dirty_components.length) {
const component = dirty_components[flushidx];
flushidx++;
set_current_component(component);
update(component.$$);
}
} catch (e) {
dirty_components.length = 0;
flushidx = 0;
throw e;
}
set_current_component(null);
dirty_components.length = 0;
flushidx = 0;
while (binding_callbacks.length)
binding_callbacks.pop()();
for (let i = 0; i < render_callbacks.length; i += 1) {
const callback = render_callbacks[i];
if (!seen_callbacks.has(callback)) {
seen_callbacks.add(callback);
callback();
}
}
render_callbacks.length = 0;
} while (dirty_components.length);
while (flush_callbacks.length) {
flush_callbacks.pop()();
}
update_scheduled = false;
seen_callbacks.clear();
set_current_component(saved_component);
}
function update($$) {
if ($$.fragment !== null) {
$$.update();
run_all($$.before_update);
const dirty = $$.dirty;
$$.dirty = [-1];
$$.fragment && $$.fragment.p($$.ctx, dirty);
$$.after_update.forEach(add_render_callback);
}
}
function flush_render_callbacks(fns) {
const filtered = [];
const targets = [];
render_callbacks.forEach((c) => fns.indexOf(c) === -1 ? filtered.push(c) : targets.push(c));
targets.forEach((c) => c());
render_callbacks = filtered;
}
let promise;
function wait() {
if (!promise) {
promise = Promise.resolve();
promise.then(() => {
promise = null;
});
}
return promise;
}
function dispatch(node, direction, kind) {
node.dispatchEvent(custom_event(`${direction ? "intro" : "outro"}${kind}`));
}
const outroing = /* @__PURE__ */ new Set();
let outros;
function group_outros() {
outros = {
r: 0,
c: [],
p: outros
// parent group
};
}
function check_outros() {
if (!outros.r) {
run_all(outros.c);
}
outros = outros.p;
}
function transition_in(block, local) {
if (block && block.i) {
outroing.delete(block);
block.i(local);
}
}
function transition_out(block, local, detach2, callback) {
if (block && block.o) {
if (outroing.has(block))
return;
outroing.add(block);
outros.c.push(() => {
outroing.delete(block);
if (callback) {
if (detach2)
block.d(1);
callback();
}
});
block.o(local);
} else if (callback) {
callback();
}
}
const null_transition = { duration: 0 };
function create_in_transition(node, fn, params) {
const options = { direction: "in" };
let config = fn(node, params, options);
let running = false;
let animation_name;
let task;
let uid = 0;
function cleanup() {
if (animation_name)
delete_rule(node, animation_name);
}
function go() {
const {
delay = 0,
duration = 300,
easing = identity,
tick = noop,
css
} = config || null_transition;
if (css)
animation_name = create_rule(node, 0, 1, duration, delay, easing, css, uid++);
tick(0, 1);
const start_time = now() + delay;
const end_time = start_time + duration;
if (task)
task.abort();
running = true;
add_render_callback(() => dispatch(node, true, "start"));
task = loop((now2) => {
if (running) {
if (now2 >= end_time) {
tick(1, 0);
dispatch(node, true, "end");
cleanup();
return running = false;
}
if (now2 >= start_time) {
const t = easing((now2 - start_time) / duration);
tick(t, 1 - t);
}
}
return running;
});
}
let started = false;
return {
start() {
if (started)
return;
started = true;
delete_rule(node);
if (is_function(config)) {
config = config(options);
wait().then(go);
} else {
go();
}
},
invalidate() {
started = false;
},
end() {
if (running) {
cleanup();
running = false;
}
}
};
}
function create_out_transition(node, fn, params) {
const options = { direction: "out" };
let config = fn(node, params, options);
let running = true;
let animation_name;
const group = outros;
group.r += 1;
let original_inert_value;
function go() {
const {
delay = 0,
duration = 300,
easing = identity,
tick = noop,
css
} = config || null_transition;
if (css)
animation_name = create_rule(node, 1, 0, duration, delay, easing, css);
const start_time = now() + delay;
const end_time = start_time + duration;
add_render_callback(() => dispatch(node, false, "start"));
if ("inert" in node) {
original_inert_value = /** @type {HTMLElement} */
node.inert;
node.inert = true;
}
loop((now2) => {
if (running) {
if (now2 >= end_time) {
tick(0, 1);
dispatch(node, false, "end");
if (!--group.r) {
run_all(group.c);
}
return false;
}
if (now2 >= start_time) {
const t = easing((now2 - start_time) / duration);
tick(1 - t, t);
}
}
return running;
});
}
if (is_function(config)) {
wait().then(() => {
config = config(options);
go();
});
} else {
go();
}
return {
end(reset) {
if (reset && "inert" in node) {
node.inert = original_inert_value;
}
if (reset && config.tick) {
config.tick(1, 0);
}
if (running) {
if (animation_name)
delete_rule(node, animation_name);
running = false;
}
}
};
}
function ensure_array_like(array_like_or_iterator) {
return array_like_or_iterator?.length !== void 0 ? array_like_or_iterator : Array.from(array_like_or_iterator);
}
function outro_and_destroy_block(block, lookup) {
transition_out(block, 1, 1, () => {
lookup.delete(block.key);
});
}
function update_keyed_each(old_blocks, dirty, get_key, dynamic, ctx, list, lookup, node, destroy, create_each_block2, next, get_context) {
let o = old_blocks.length;
let n = list.length;
let i = o;
const old_indexes = {};
while (i--)
old_indexes[old_blocks[i].key] = i;
const new_blocks = [];
const new_lookup = /* @__PURE__ */ new Map();
const deltas = /* @__PURE__ */ new Map();
const updates = [];
i = n;
while (i--) {
const child_ctx = get_context(ctx, list, i);
const key = get_key(child_ctx);
let block = lookup.get(key);
if (!block) {
block = create_each_block2(key, child_ctx);
block.c();
} else if (dynamic) {
updates.push(() => block.p(child_ctx, dirty));
}
new_lookup.set(key, new_blocks[i] = block);
if (key in old_indexes)
deltas.set(key, Math.abs(i - old_indexes[key]));
}
const will_move = /* @__PURE__ */ new Set();
const did_move = /* @__PURE__ */ new Set();
function insert2(block) {
transition_in(block, 1);
block.m(node, next);
lookup.set(block.key, block);
next = block.first;
n--;
}
while (o && n) {
const new_block = new_blocks[n - 1];
const old_block = old_blocks[o - 1];
const new_key = new_block.key;
const old_key = old_block.key;
if (new_block === old_block) {
next = new_block.first;
o--;
n--;
} else if (!new_lookup.has(old_key)) {
destroy(old_block, lookup);
o--;
} else if (!lookup.has(new_key) || will_move.has(new_key)) {
insert2(new_block);
} else if (did_move.has(old_key)) {
o--;
} else if (deltas.get(new_key) > deltas.get(old_key)) {
did_move.add(new_key);
insert2(new_block);
} else {
will_move.add(old_key);
o--;
}
}
while (o--) {
const old_block = old_blocks[o];
if (!new_lookup.has(old_block.key))
destroy(old_block, lookup);
}
while (n)
insert2(new_blocks[n - 1]);
run_all(updates);
return new_blocks;
}
function get_spread_update(levels, updates) {
const update2 = {};
const to_null_out = {};
const accounted_for = { $$scope: 1 };
let i = levels.length;
while (i--) {
const o = levels[i];
const n = updates[i];
if (n) {
for (const key in o) {
if (!(key in n))
to_null_out[key] = 1;
}
for (const key in n) {
if (!accounted_for[key]) {
update2[key] = n[key];
accounted_for[key] = 1;
}
}
levels[i] = n;
} else {
for (const key in o) {
accounted_for[key] = 1;
}
}
}
for (const key in to_null_out) {
if (!(key in update2))
update2[key] = void 0;
}
return update2;
}
function get_spread_object(spread_props) {
return typeof spread_props === "object" && spread_props !== null ? spread_props : {};
}
function bind(component, name, callback) {
const index = component.$$.props[name];
if (index !== void 0) {
component.$$.bound[index] = callback;
callback(component.$$.ctx[index]);
}
}
function create_component(block) {
block && block.c();
}
function mount_component(component, target, anchor) {
const { fragment, after_update } = component.$$;
fragment && fragment.m(target, anchor);
add_render_callback(() => {
const new_on_destroy = component.$$.on_mount.map(run).filter(is_function);
if (component.$$.on_destroy) {
component.$$.on_destroy.push(...new_on_destroy);
} else {
run_all(new_on_destroy);
}
component.$$.on_mount = [];
});
after_update.forEach(add_render_callback);
}
function destroy_component(component, detaching) {
const $$ = component.$$;
if ($$.fragment !== null) {
flush_render_callbacks($$.after_update);
run_all($$.on_destroy);
$$.fragment && $$.fragment.d(detaching);
$$.on_destroy = $$.fragment = null;
$$.ctx = [];