@justanarthur/modo-ui-notch 0.0.0-stage → 0.3.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.
Files changed (141) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +75 -2
  3. package/blocks/activities/agenda/examples.mdx +74 -0
  4. package/blocks/activities/agenda/index.tsx +441 -0
  5. package/blocks/activities/clock/examples.mdx +73 -0
  6. package/blocks/activities/clock/index.tsx +619 -0
  7. package/blocks/activities/now-playing/examples.mdx +68 -0
  8. package/blocks/activities/now-playing/index.tsx +411 -0
  9. package/blocks/activities/weather/examples.mdx +115 -0
  10. package/blocks/activities/weather/index.tsx +634 -0
  11. package/blocks/app/expanded-island/examples.mdx +46 -0
  12. package/blocks/app/expanded-island/index.tsx +143 -0
  13. package/blocks/app/settings-window/examples.mdx +34 -0
  14. package/blocks/app/settings-window/index.tsx +375 -0
  15. package/blocks/system/clipboard/examples.mdx +83 -0
  16. package/blocks/system/clipboard/index.tsx +563 -0
  17. package/blocks/system/recent-files/examples.mdx +66 -0
  18. package/blocks/system/recent-files/index.tsx +542 -0
  19. package/blocks/system/system-stats/examples.mdx +52 -0
  20. package/blocks/system/system-stats/index.tsx +312 -0
  21. package/components/indicators/countdown/examples.mdx +25 -0
  22. package/components/indicators/countdown/index.tsx +83 -0
  23. package/components/indicators/equalizer/examples.mdx +20 -0
  24. package/components/indicators/equalizer/index.tsx +116 -0
  25. package/components/indicators/media-scrubber/examples.mdx +29 -0
  26. package/components/indicators/media-scrubber/index.tsx +122 -0
  27. package/components/island/island/examples.mdx +57 -0
  28. package/components/island/island/index.tsx +415 -0
  29. package/components/island/island-flash/examples.mdx +52 -0
  30. package/components/island/island-flash/index.tsx +79 -0
  31. package/components/island/island-tabs/examples.mdx +53 -0
  32. package/components/island/island-tabs/index.tsx +285 -0
  33. package/components/island/widget/examples.mdx +76 -0
  34. package/components/island/widget/index.tsx +431 -0
  35. package/dist/blocks/activities/agenda/index.d.ts +2 -0
  36. package/dist/blocks/activities/agenda/index.js +21 -0
  37. package/dist/blocks/activities/clock/index.d.ts +2 -0
  38. package/dist/blocks/activities/clock/index.js +25 -0
  39. package/dist/blocks/activities/now-playing/index.d.ts +3 -0
  40. package/dist/blocks/activities/now-playing/index.js +24 -0
  41. package/dist/blocks/activities/weather/index.d.ts +2 -0
  42. package/dist/blocks/activities/weather/index.js +21 -0
  43. package/dist/blocks/app/expanded-island/index.d.ts +3 -0
  44. package/dist/blocks/app/expanded-island/index.js +11 -0
  45. package/dist/blocks/app/settings-window/index.d.ts +2 -0
  46. package/dist/blocks/app/settings-window/index.js +7 -0
  47. package/dist/blocks/system/clipboard/index.d.ts +2 -0
  48. package/dist/blocks/system/clipboard/index.js +17 -0
  49. package/dist/blocks/system/recent-files/index.d.ts +2 -0
  50. package/dist/blocks/system/recent-files/index.js +19 -0
  51. package/dist/blocks/system/system-stats/index.d.ts +2 -0
  52. package/dist/blocks/system/system-stats/index.js +15 -0
  53. package/dist/components/indicators/countdown/index.d.ts +2 -0
  54. package/dist/components/indicators/countdown/index.js +8 -0
  55. package/dist/components/indicators/equalizer/index.d.ts +2 -0
  56. package/dist/components/indicators/equalizer/index.js +7 -0
  57. package/dist/components/indicators/media-scrubber/index.d.ts +2 -0
  58. package/dist/components/indicators/media-scrubber/index.js +8 -0
  59. package/dist/components/island/island/index.d.ts +3 -0
  60. package/dist/components/island/island/index.js +10 -0
  61. package/dist/components/island/island-flash/index.d.ts +2 -0
  62. package/dist/components/island/island-flash/index.js +7 -0
  63. package/dist/components/island/island-tabs/index.d.ts +2 -0
  64. package/dist/components/island/island-tabs/index.js +9 -0
  65. package/dist/components/island/widget/index.d.ts +2 -0
  66. package/dist/components/island/widget/index.js +30 -0
  67. package/dist/index.d.ts +21 -0
  68. package/dist/index.js +195 -0
  69. package/dist/lib/artwork.d.ts +2 -0
  70. package/dist/lib/artwork.js +8 -0
  71. package/dist/lib/clock.d.ts +2 -0
  72. package/dist/lib/clock.js +14 -0
  73. package/dist/lib/geometry.d.ts +2 -0
  74. package/dist/lib/geometry.js +24 -0
  75. package/dist/lib/island-context.d.ts +3 -0
  76. package/dist/lib/island-context.js +8 -0
  77. package/dist/lib/motion.d.ts +21 -0
  78. package/dist/lib/motion.js +16 -0
  79. package/dist/shared/chunk-152gpyq3.d.ts +13 -0
  80. package/dist/shared/chunk-2818esrq.d.ts +140 -0
  81. package/dist/shared/chunk-2f7zxrbk.js +65 -0
  82. package/dist/shared/chunk-2m5dz8nf.d.ts +88 -0
  83. package/dist/shared/chunk-2s4q6mt0.js +27 -0
  84. package/dist/shared/chunk-3thgcfcq.d.ts +151 -0
  85. package/dist/shared/chunk-416tsgbc.d.ts +175 -0
  86. package/dist/shared/chunk-502rmtap.js +54 -0
  87. package/dist/shared/chunk-52gb3g6r.d.ts +12 -0
  88. package/dist/shared/chunk-5en5aaj1.d.ts +33 -0
  89. package/dist/shared/chunk-61t2dfte.js +63 -0
  90. package/dist/shared/chunk-7fvnrtz4.d.ts +105 -0
  91. package/dist/shared/chunk-81fpptwp.d.ts +75 -0
  92. package/dist/shared/chunk-9c7ewvkk.js +381 -0
  93. package/dist/shared/chunk-9m0xbg5v.js +112 -0
  94. package/dist/shared/chunk-9xtcv3sy.js +88 -0
  95. package/dist/shared/chunk-bvtyjcce.d.ts +123 -0
  96. package/dist/shared/chunk-cc9nwbtf.js +315 -0
  97. package/dist/shared/chunk-cfzmfnyh.d.ts +63 -0
  98. package/dist/shared/chunk-d5qm9cps.js +10 -0
  99. package/dist/shared/chunk-da177e8r.d.ts +114 -0
  100. package/dist/shared/chunk-fexwzycv.d.ts +36 -0
  101. package/dist/shared/chunk-gb56m10p.js +39 -0
  102. package/dist/shared/chunk-gejenfap.d.ts +25 -0
  103. package/dist/shared/chunk-hrpxbqmx.d.ts +28 -0
  104. package/dist/shared/chunk-j755a1a5.d.ts +41 -0
  105. package/dist/shared/chunk-j77cx8dp.js +498 -0
  106. package/dist/shared/chunk-mt0k6v8x.js +474 -0
  107. package/dist/shared/chunk-ndf79pv5.js +58 -0
  108. package/dist/shared/chunk-pfhy5e4q.d.ts +53 -0
  109. package/dist/shared/chunk-qdzemt2v.js +477 -0
  110. package/dist/shared/chunk-r471sknr.js +209 -0
  111. package/dist/shared/chunk-s2jeqqan.js +243 -0
  112. package/dist/shared/chunk-t0hcxh89.d.ts +124 -0
  113. package/dist/shared/chunk-w48eyvfr.d.ts +56 -0
  114. package/dist/shared/chunk-w5h6ay93.js +72 -0
  115. package/dist/shared/chunk-wkg17nxs.d.ts +101 -0
  116. package/dist/shared/chunk-x7f3g82r.js +285 -0
  117. package/dist/shared/chunk-xq5hc5gv.js +333 -0
  118. package/dist/shared/chunk-y0188bbn.js +331 -0
  119. package/dist/shared/chunk-ym0xbses.js +518 -0
  120. package/dist/styles.css +264 -0
  121. package/index.ts +22 -0
  122. package/lib/artwork.ts +112 -0
  123. package/lib/clock.ts +53 -0
  124. package/lib/geometry.ts +130 -0
  125. package/lib/island-context.tsx +24 -0
  126. package/lib/motion.ts +42 -0
  127. package/mock/activities.tsx +77 -0
  128. package/mock/artwork.tsx +37 -0
  129. package/mock/clipboard.tsx +79 -0
  130. package/mock/clock.tsx +77 -0
  131. package/mock/data.ts +139 -0
  132. package/mock/desktop.tsx +83 -0
  133. package/mock/files.tsx +70 -0
  134. package/mock/fit.ts +26 -0
  135. package/mock/island-content.tsx +142 -0
  136. package/mock/scene.tsx +52 -0
  137. package/mock/screen.tsx +76 -0
  138. package/mock/settings.tsx +489 -0
  139. package/mock/system.ts +46 -0
  140. package/mock/weather.tsx +105 -0
  141. package/package.json +122 -4
@@ -0,0 +1,331 @@
1
+ "use client";
2
+
3
+ import {
4
+ slotWidth2,
5
+ shapeFor2,
6
+ bubbleFor2,
7
+ islandPath2
8
+ } from "./chunk-61t2dfte.js";
9
+ import {
10
+ IslandContext2
11
+ } from "./chunk-d5qm9cps.js";
12
+ import {
13
+ shapeTransition2,
14
+ bubbleTransition2,
15
+ contentShown2,
16
+ contentHidden2,
17
+ contentEnter2,
18
+ contentLeave2
19
+ } from "./chunk-2s4q6mt0.js";
20
+
21
+ // components/island/island/index.tsx
22
+ import { GooLayer } from "@justanarthur/modo-ui/lib/goo-indicator";
23
+ import { useReduceMotion } from "@justanarthur/modo-ui/lib/reduced-motion";
24
+ import { SurfaceProvider } from "@justanarthur/modo-ui/lib/surface-context";
25
+ import { useControllableState } from "@justanarthur/modo-ui/lib/use-controllable-state";
26
+ import { cn } from "@justanarthur/modo-ui/lib/utils";
27
+ import { AnimatePresence, animate, motion, useMotionValue, useTransform } from "motion/react";
28
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
29
+ import { jsx, jsxs } from "react/jsx-runtime";
30
+ /*!
31
+ * Local addition: the island of a notch app, the black outline that hangs
32
+ * from the top edge and grows out of the hardware notch. Rebuilt from Just
33
+ * Notch's runtime (`island/island.tsx`) as a presentational component: no
34
+ * host, no activity store; state, geometry and content come in as props.
35
+ */
36
+ var HOVER_INTENT_MS = 120;
37
+ var HOVER_LEAVE_MS = 400;
38
+ var OVERSHOOT = 24;
39
+ var GOO_BLUR = 6;
40
+ var INTERACTIVE = "button, a, input, select, textarea, label, [role=slider], [role=switch], [role=tab], [role=menuitem], [contenteditable]";
41
+ var isCollapsed = (state) => state === "idle" || state === "compact" || state === "split";
42
+ function Layer({ shape, top = 0, reduced, interactive, children }) {
43
+ const hidden = reduced ? { opacity: 0 } : contentHidden2;
44
+ return /* @__PURE__ */ jsx(motion.div, {
45
+ className: cn("absolute", interactive ? "pointer-events-auto" : "pointer-events-none"),
46
+ style: {
47
+ left: `calc(50% - ${shape.w / 2}px)`,
48
+ top: 0,
49
+ width: shape.w,
50
+ height: shape.h,
51
+ transformOrigin: "50% 0"
52
+ },
53
+ initial: hidden,
54
+ animate: reduced ? { opacity: 1 } : contentShown2,
55
+ exit: { ...hidden, transition: contentLeave2 },
56
+ transition: contentEnter2,
57
+ children: /* @__PURE__ */ jsx("div", {
58
+ className: "absolute inset-x-0 bottom-0",
59
+ style: { top },
60
+ children
61
+ })
62
+ });
63
+ }
64
+ function Island2({
65
+ state: stateProp,
66
+ defaultState = "idle",
67
+ onStateChange,
68
+ collapsedState,
69
+ expandOnHover = false,
70
+ notchWidth = 185,
71
+ notchHeight = 32,
72
+ panelWidth = 720,
73
+ panelHeight = 240,
74
+ leading,
75
+ trailing,
76
+ minimal,
77
+ expanded,
78
+ flash,
79
+ activity,
80
+ label = "Open the island",
81
+ className
82
+ }) {
83
+ const [state, setState] = useControllableState(stateProp, defaultState, onStateChange);
84
+ const reduced = useReduceMotion();
85
+ const root = useRef(null);
86
+ const [room, setRoom] = useState();
87
+ useLayoutEffect(() => {
88
+ const el = root.current;
89
+ if (!el)
90
+ return;
91
+ setRoom(el.clientWidth);
92
+ const observer = new ResizeObserver(([entry]) => entry && setRoom(entry.contentRect.width));
93
+ observer.observe(el);
94
+ return () => observer.disconnect();
95
+ }, []);
96
+ const geometry = useMemo(() => ({ notch: { width: notchWidth, height: notchHeight }, panel: { width: panelWidth, height: panelHeight } }), [notchWidth, notchHeight, panelWidth, panelHeight]);
97
+ const { notch } = geometry;
98
+ const shape = shapeFor2(state, geometry, room);
99
+ const split = state === "split";
100
+ const bubble = bubbleFor2(shape, notch, split);
101
+ const rest = useRef(isCollapsed(defaultState) ? defaultState : "idle");
102
+ if (isCollapsed(state))
103
+ rest.current = state;
104
+ const collapse = () => setState(collapsedState ?? rest.current);
105
+ const w = useMotionValue(shape.w);
106
+ const h = useMotionValue(shape.h);
107
+ const radius = useMotionValue(shape.radius);
108
+ const shoulder = useMotionValue(shape.shoulder);
109
+ const bubbleX = useMotionValue(bubble.x);
110
+ const bubbleR = useMotionValue(bubble.r);
111
+ const [moving, setMoving] = useState(false);
112
+ const [reserve, setReserve] = useState(shape.h);
113
+ const [goo, setGoo] = useState(null);
114
+ const [bubbleShown, setBubbleShown] = useState(split);
115
+ const d = useTransform(() => islandPath2(0, { w: w.get(), h: h.get(), radius: radius.get(), shoulder: shoulder.get() }));
116
+ const clipPath = useTransform(() => {
117
+ const side = `calc(50% - ${w.get() / 2}px)`;
118
+ const r = radius.get();
119
+ return `inset(0px ${side} calc(100% - ${h.get()}px) ${side} round 0px 0px ${r}px ${r}px)`;
120
+ });
121
+ const bodyX = useTransform(() => -w.get() / 2);
122
+ const bodyY = useTransform(() => -radius.get());
123
+ const bodyHeight = useTransform(() => h.get() + radius.get());
124
+ const bubbleLeft = useTransform(() => bubbleX.get() - bubbleR.get());
125
+ const bubbleTop = useTransform(() => notch.height / 2 - bubbleR.get());
126
+ const bubbleSize = useTransform(() => bubbleR.get() * 2);
127
+ const previous = useRef(state);
128
+ const token = useRef(0);
129
+ useLayoutEffect(() => {
130
+ const from = previous.current;
131
+ previous.current = state;
132
+ const run = ++token.current;
133
+ const values = [w, h, radius, shoulder, bubbleX, bubbleR];
134
+ const targets = [shape.w, shape.h, shape.radius, shape.shoulder, bubble.x, bubble.r];
135
+ if (from === state || reduced) {
136
+ for (const [i, value] of values.entries())
137
+ value.jump(targets[i]);
138
+ setMoving(false);
139
+ setGoo(null);
140
+ setBubbleShown(split);
141
+ setReserve(shape.h);
142
+ return;
143
+ }
144
+ const transition = shapeTransition2(from, state);
145
+ const splitChanged = from === "split" !== split;
146
+ const bubbleMove = splitChanged ? bubbleTransition2(split) : transition;
147
+ setMoving(true);
148
+ setReserve(Math.max(h.get(), shape.h) + OVERSHOOT);
149
+ if (splitChanged) {
150
+ const half = Math.max(w.get(), shape.w) / 2;
151
+ const reach = Math.max(half, bubbleFor2(shape, notch, true).x + bubble.r * 2);
152
+ const top = Math.max(radius.get(), shape.radius);
153
+ setGoo({ left: -reach, top: -top, width: reach * 2, height: Math.max(h.get(), shape.h) + top });
154
+ if (split)
155
+ setBubbleShown(true);
156
+ }
157
+ const controls = values.map((value, i) => animate(value, targets[i], i >= 4 ? bubbleMove : transition));
158
+ Promise.all(controls.map((c) => c.finished)).then(() => {
159
+ if (run !== token.current)
160
+ return;
161
+ setMoving(false);
162
+ setGoo(null);
163
+ setBubbleShown(split);
164
+ setReserve(shape.h);
165
+ });
166
+ }, [state, shape.w, shape.h, shape.radius, shape.shoulder, bubble.x, bubble.r, reduced]);
167
+ const hover = useRef(undefined);
168
+ useEffect(() => () => clearTimeout(hover.current), []);
169
+ const intend = (open) => {
170
+ if (!expandOnHover)
171
+ return;
172
+ clearTimeout(hover.current);
173
+ hover.current = setTimeout(() => {
174
+ if (open && isCollapsed(state))
175
+ setState("expanded");
176
+ if (!open && state === "expanded")
177
+ collapse();
178
+ }, open ? HOVER_INTENT_MS : HOVER_LEAVE_MS);
179
+ };
180
+ const open = state === "expanded";
181
+ useEffect(() => {
182
+ if (!open)
183
+ return;
184
+ const onKey = (event) => event.key === "Escape" && collapse();
185
+ window.addEventListener("keydown", onKey);
186
+ return () => window.removeEventListener("keydown", onKey);
187
+ });
188
+ const onClick = (event) => {
189
+ if (open || event.defaultPrevented)
190
+ return;
191
+ if (event.target instanceof Element && event.target.closest(INTERACTIVE))
192
+ return;
193
+ setState("expanded");
194
+ };
195
+ const slot = slotWidth2(notch);
196
+ const context = useMemo(() => ({ state, geometry, shape }), [state, geometry, shape.w, shape.h, shape.radius, shape.shoulder]);
197
+ let content = null;
198
+ if (state === "expanded" && expanded)
199
+ content = /* @__PURE__ */ jsx(Layer, {
200
+ shape,
201
+ reduced,
202
+ interactive: true,
203
+ children: expanded
204
+ }, "expanded");
205
+ else if (state === "flash" && flash)
206
+ content = /* @__PURE__ */ jsx(Layer, {
207
+ shape,
208
+ top: notch.height,
209
+ reduced,
210
+ interactive: true,
211
+ children: /* @__PURE__ */ jsx("div", {
212
+ className: "flex size-full items-center px-5 pb-1",
213
+ children: /* @__PURE__ */ jsx("div", {
214
+ className: "min-w-0 flex-1",
215
+ children: flash
216
+ })
217
+ })
218
+ }, `flash:${activity ?? ""}`);
219
+ else if ((state === "compact" || split) && (leading || trailing))
220
+ content = /* @__PURE__ */ jsxs(Layer, {
221
+ shape,
222
+ reduced,
223
+ interactive: false,
224
+ children: [
225
+ /* @__PURE__ */ jsx("div", {
226
+ className: "absolute inset-y-0 left-0 flex items-center justify-center",
227
+ style: { width: slot },
228
+ children: leading
229
+ }),
230
+ /* @__PURE__ */ jsx("div", {
231
+ className: "absolute inset-y-0 right-0 flex items-center justify-center",
232
+ style: { width: slot },
233
+ children: trailing
234
+ })
235
+ ]
236
+ }, `wings:${activity ?? "compact"}`);
237
+ return /* @__PURE__ */ jsx(IslandContext2.Provider, {
238
+ value: context,
239
+ children: /* @__PURE__ */ jsxs("div", {
240
+ ref: root,
241
+ "data-state": state,
242
+ className: cn("pointer-events-none relative w-full overflow-hidden", className),
243
+ style: { height: reserve },
244
+ onClick,
245
+ onPointerEnter: () => intend(true),
246
+ onPointerLeave: () => intend(false),
247
+ children: [
248
+ goo && /* @__PURE__ */ jsx("div", {
249
+ "aria-hidden": true,
250
+ className: "absolute top-0 left-1/2",
251
+ children: /* @__PURE__ */ jsxs(GooLayer, {
252
+ active: true,
253
+ blur: GOO_BLUR,
254
+ box: goo,
255
+ fill: "bg-ink",
256
+ children: [
257
+ /* @__PURE__ */ jsx(motion.div, {
258
+ className: "absolute top-0 left-0 bg-ink",
259
+ style: { x: bodyX, y: bodyY, width: w, height: bodyHeight, borderRadius: radius }
260
+ }),
261
+ /* @__PURE__ */ jsx(motion.div, {
262
+ className: "absolute top-0 left-0 rounded-full bg-ink",
263
+ style: { x: bubbleLeft, y: bubbleTop, width: bubbleSize, height: bubbleSize }
264
+ })
265
+ ]
266
+ })
267
+ }),
268
+ /* @__PURE__ */ jsx("svg", {
269
+ "aria-hidden": true,
270
+ className: "absolute top-0 left-1/2 overflow-visible",
271
+ width: "1",
272
+ height: "1",
273
+ children: /* @__PURE__ */ jsxs("g", {
274
+ className: "pointer-events-auto fill-ink",
275
+ children: [
276
+ /* @__PURE__ */ jsx(motion.path, {
277
+ d
278
+ }),
279
+ bubbleShown && /* @__PURE__ */ jsx(motion.circle, {
280
+ cx: bubbleX,
281
+ cy: notch.height / 2,
282
+ r: bubbleR
283
+ })
284
+ ]
285
+ })
286
+ }),
287
+ !open && /* @__PURE__ */ jsx("button", {
288
+ type: "button",
289
+ "aria-label": label,
290
+ "aria-expanded": false,
291
+ className: "pointer-events-auto absolute top-0 cursor-pointer outline-none focus-visible:ring-1 focus-visible:ring-focus-ring",
292
+ style: {
293
+ left: `calc(50% - ${shape.w / 2}px)`,
294
+ width: shape.w,
295
+ height: shape.h,
296
+ borderBottomLeftRadius: shape.radius,
297
+ borderBottomRightRadius: shape.radius
298
+ },
299
+ onClick: () => setState("expanded")
300
+ }),
301
+ /* @__PURE__ */ jsx(motion.div, {
302
+ className: "dark pointer-events-none absolute inset-0 text-foreground",
303
+ style: { clipPath: moving ? clipPath : "none" },
304
+ children: /* @__PURE__ */ jsx(SurfaceProvider, {
305
+ value: 1,
306
+ children: /* @__PURE__ */ jsx(AnimatePresence, {
307
+ initial: false,
308
+ children: content
309
+ })
310
+ })
311
+ }),
312
+ (split || bubbleShown) && /* @__PURE__ */ jsx(motion.div, {
313
+ className: "dark pointer-events-auto absolute top-0 left-1/2 flex items-center justify-center text-foreground",
314
+ style: { x: bubbleLeft, y: notch.height / 2 - bubble.r, width: bubble.r * 2, height: bubble.r * 2 },
315
+ children: /* @__PURE__ */ jsx(AnimatePresence, {
316
+ initial: false,
317
+ children: split && minimal && /* @__PURE__ */ jsx(motion.div, {
318
+ className: "flex size-full items-center justify-center",
319
+ initial: reduced ? { opacity: 0 } : contentHidden2,
320
+ animate: reduced ? { opacity: 1 } : contentShown2,
321
+ exit: { opacity: 0, transition: contentLeave2 },
322
+ transition: contentEnter2,
323
+ children: minimal
324
+ }, activity ?? "minimal")
325
+ })
326
+ })
327
+ ]
328
+ })
329
+ });
330
+ }
331
+ export { Island2 };