ilha 0.15.1 → 0.16.0

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.
@@ -1,100 +0,0 @@
1
- import * as Option from "effect/Option";
2
- import * as Result from "effect/Result";
3
- import * as AsyncResult from "effect/reactivity/AsyncResult";
4
-
5
- //#region src/errors.ts
6
- const asFailure = (e) => {
7
- if (Result.isResult(e) && Result.isFailure(e)) {
8
- const v = Option.getOrUndefined(Result.getFailure(e));
9
- return Result.fail(v instanceof Error ? v : new Error(String(v)));
10
- }
11
- return Result.fail(e instanceof Error ? e : new Error(String(e)));
12
- };
13
- /** Normalize any thrown failure into an `Error` instance. */
14
- const toError = (e) => asFailure(e).pipe(Result.match({
15
- onFailure: (err) => err,
16
- onSuccess: () => /* @__PURE__ */ new Error("error")
17
- }));
18
- const failureMessage = (e) => toError(e).message;
19
-
20
- //#endregion
21
- //#region src/shared.ts
22
- const KEY_ATTR = "data-ilha-key";
23
- const SLOT_ATTR = "data-ilha-slot";
24
- const ISLAND = Symbol.for("ilha.island");
25
- const ISLAND_MOUNT_INTERNAL = Symbol.for("ilha.islandMountInternal");
26
- const ISLAND_SLOT_TAG = Symbol.for("ilha.islandSlotTag");
27
- const objectTag = (value) => Object.prototype.toString.call(value);
28
- const isBoolean = (value) => value === true || value === false;
29
- const isString = (value) => objectTag(value) === "[object String]";
30
- const isNumber = (value) => objectTag(value) === "[object Number]";
31
- const isBigInt = (value) => objectTag(value) === "[object BigInt]";
32
- const isFunction = (value) => {
33
- const tag = objectTag(value);
34
- return tag === "[object Function]" || tag === "[object AsyncFunction]" || tag === "[object GeneratorFunction]";
35
- };
36
- const isObject = (value) => value !== null && objectTag(value) === "[object Object]";
37
- const skip = (x) => x === null || x === void 0 || isBoolean(x);
38
- const KEEP = Symbol("ilha.keep");
39
- const unwrap = (value, keep) => {
40
- if (AsyncResult.isAsyncResult(value)) {
41
- if (AsyncResult.isWaiting(value) && keep !== void 0) return KEEP;
42
- if (AsyncResult.isFailure(value) && !AsyncResult.isWaiting(value)) return String(AsyncResult.error(value) ?? "error");
43
- const v = AsyncResult.value(value);
44
- if (v._tag === "Some") return v.value;
45
- return "";
46
- }
47
- return value;
48
- };
49
- const defer = () => {
50
- const { promise, resolve } = Promise.withResolvers();
51
- return {
52
- promise,
53
- resolve: () => {
54
- resolve(null);
55
- }
56
- };
57
- };
58
- const errorView = (e) => ({
59
- $$ilha: 1,
60
- children: [failureMessage(e)],
61
- props: { "data-ilha-error": "" },
62
- type: "pre"
63
- });
64
-
65
- //#endregion
66
- //#region src/types.ts
67
- const Fragment = Symbol("ilha.Fragment");
68
-
69
- //#endregion
70
- //#region src/vnode.ts
71
- const flatten = (xs) => {
72
- const out = [];
73
- for (const x of xs) if (Array.isArray(x)) out.push(...flatten(x));
74
- else out.push(x);
75
- return out;
76
- };
77
- const h = (type, props, ...rest) => {
78
- const p = { ...props };
79
- const fromProps = p.children;
80
- const { key: rawKey, ...restProps } = p;
81
- return {
82
- $$ilha: 1,
83
- children: flatten([...fromProps === void 0 ? [] : [fromProps], ...rest]),
84
- key: rawKey,
85
- props: restProps,
86
- type
87
- };
88
- };
89
- const isVNode = (x) => {
90
- if (!isObject(x)) return false;
91
- return x.$$ilha === 1;
92
- };
93
- const isSetupFn = (x) => {
94
- if (!isFunction(x)) return false;
95
- const n = x.constructor?.name;
96
- return n === "GeneratorFunction" || n === "AsyncFunction";
97
- };
98
-
99
- //#endregion
100
- export { toError as S, isString as _, ISLAND as a, asFailure as b, KEEP as c, defer as d, errorView as f, isObject as g, isNumber as h, Fragment as i, KEY_ATTR as l, isFunction as m, isSetupFn as n, ISLAND_MOUNT_INTERNAL as o, isBigInt as p, isVNode as r, ISLAND_SLOT_TAG as s, h as t, SLOT_ATTR as u, skip as v, failureMessage as x, unwrap as y };