@popmelt.com/core 0.40.1 → 0.41.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.
- package/claude-plugin/.claude-plugin/plugin.json +1 -1
- package/codex-plugin/.codex-plugin/plugin.json +1 -1
- package/dist/ExploreAttachment-ALV7FL3Y.mjs +1 -0
- package/dist/PagePreviewLayer-UPCGG4EV.mjs +1 -0
- package/dist/ParticipantRuntime-CBUA7BL5.mjs +1 -0
- package/dist/PhoneHostGate-TVNOJYL5.mjs +1 -0
- package/dist/PopmeltProvider-5g-1VH5a.d.mts +15 -0
- package/dist/PopmeltTasteConnectedPane-PD64Q6LF.mjs +1 -0
- package/dist/QueuedReplies-ESF5UL3J.mjs +1 -0
- package/dist/SamplePlacementOverlay-V533Y4XN.mjs +1 -0
- package/dist/ShareProjectPane-PMODH6QQ.mjs +1 -0
- package/dist/SuppliedContext-ADMN2D2I.mjs +1 -0
- package/dist/{ThreadErrorCard-SUFOXXLG.mjs → ThreadErrorCard-KS2XWRT3.mjs} +1 -1
- package/dist/ThreadPanel-5TDPZBAU.mjs +1 -0
- package/dist/adapter-react-three-fiber.d.mts +1 -1
- package/dist/adapter-react-three-fiber.mjs +1 -1
- package/dist/adapter-three.d.mts +1 -1
- package/dist/adapter-three.mjs +1 -1
- package/dist/bridge-entry.mjs +1 -1
- package/dist/browser-runtime-FUXWVGQ7.mjs +1 -0
- package/dist/browser.d.mts +4 -4
- package/dist/browser.mjs +1 -1
- package/dist/canvas-text.d.mts +1 -1
- package/dist/{checkFixture-LBDNT3M5.mjs → checkFixture-42NYMFAK.mjs} +1 -1
- package/dist/chunk-2TA7N3CI.mjs +1 -0
- package/dist/chunk-32BKJ5JN.mjs +1 -0
- package/dist/chunk-3HVPVKWV.mjs +1 -0
- package/dist/chunk-4RQ5XD3I.mjs +1 -0
- package/dist/chunk-5J4BZL6N.mjs +1 -0
- package/dist/chunk-6OPX4CUT.mjs +1 -0
- package/dist/{chunk-4MLXPN7W.mjs → chunk-776SEJZO.mjs} +1 -1
- package/dist/chunk-7OATJ6BO.mjs +1 -0
- package/dist/chunk-7VIC4MGC.mjs +1 -0
- package/dist/chunk-AET77LFV.mjs +1 -0
- package/dist/chunk-ALWPAFIW.mjs +1 -0
- package/dist/chunk-AOFKEBLN.mjs +1 -0
- package/dist/{chunk-6EO73WJN.mjs → chunk-BSVZXOOS.mjs} +1 -1
- package/dist/chunk-D2ONGS5P.mjs +1 -0
- package/dist/chunk-DDUXU6LA.mjs +1 -0
- package/dist/chunk-DMKBAI2Z.mjs +1 -0
- package/dist/chunk-DUWONLQE.mjs +1 -0
- package/dist/chunk-EG6UHPJV.mjs +1 -0
- package/dist/{chunk-XVQAHYF2.mjs → chunk-FZUHHJWW.mjs} +1 -1
- package/dist/{chunk-L3QE62SE.mjs → chunk-GE5BE6PI.mjs} +1 -1
- package/dist/{chunk-K22VZV3V.mjs → chunk-GLF7Z5IR.mjs} +1 -1
- package/dist/chunk-GLIGPLM4.mjs +1 -0
- package/dist/chunk-H3T2O3HA.mjs +1 -0
- package/dist/chunk-HFKGW34E.mjs +1 -0
- package/dist/{chunk-Q5MIJ5F2.mjs → chunk-HFWGYXPG.mjs} +1 -1
- package/dist/{chunk-53QOGFAT.mjs → chunk-ITLRSHNZ.mjs} +1 -1
- package/dist/chunk-JWWWU4GY.mjs +1 -0
- package/dist/chunk-KD2AOPYP.mjs +1 -0
- package/dist/chunk-KE4MQBRY.mjs +1 -0
- package/dist/chunk-KF73S7MG.mjs +1 -0
- package/dist/{chunk-ZQMKLODZ.mjs → chunk-LDDDSIAQ.mjs} +1 -1
- package/dist/chunk-LWPNOBGS.mjs +1 -0
- package/dist/{chunk-MPEVFQ43.mjs → chunk-PCUUOIFD.mjs} +1 -1
- package/dist/chunk-PRZ6C5X3.mjs +1 -0
- package/dist/chunk-PTMHSMZH.mjs +1 -0
- package/dist/chunk-RFTQCRGC.mjs +1 -0
- package/dist/{chunk-DBCCE7BA.mjs → chunk-S2U2IGUO.mjs} +1 -1
- package/dist/{chunk-EUFK7B6S.mjs → chunk-S7IWZSWH.mjs} +1 -1
- package/dist/chunk-SOFNYBJD.mjs +1 -0
- package/dist/chunk-SZQTGYPS.mjs +1 -0
- package/dist/chunk-TA2BMDSC.mjs +30 -0
- package/dist/{chunk-ECWY6Z6K.mjs → chunk-ULR4IDEX.mjs} +1 -1
- package/dist/{chunk-OECEYJNK.mjs → chunk-VJKC2RJB.mjs} +1 -1
- package/dist/chunk-VOL4KS67.mjs +1 -0
- package/dist/chunk-VSWRWS2H.mjs +1 -0
- package/dist/chunk-W5TNOJOR.mjs +1 -0
- package/dist/{chunk-LUTP7QBD.mjs → chunk-WSI2SQWU.mjs} +1 -1
- package/dist/chunk-WWNI7JCA.mjs +1 -0
- package/dist/chunk-XDZUDDYB.mjs +1 -0
- package/dist/chunk-XGSOAF5E.mjs +1 -0
- package/dist/chunk-XHTSKQMB.mjs +1 -0
- package/dist/chunk-YG3RSK5J.mjs +1 -0
- package/dist/chunk-YHCZYT4T.mjs +1 -0
- package/dist/chunk-Z4NMA34Y.mjs +1 -0
- package/dist/chunk-ZXCAONMC.mjs +1 -0
- package/dist/cli.mjs +1 -1
- package/dist/codex-note-context-WX33QFE7.mjs +1 -0
- package/dist/codex-project-77GHT2I3.mjs +1 -0
- package/dist/{codex-session-registry-YNU6LEVH.mjs → codex-session-registry-A3NQRRZ3.mjs} +1 -1
- package/dist/codex-store-mount-KFJYT6AS.mjs +1 -0
- package/dist/dev-app-port-LHUBCOBE.mjs +1 -0
- package/dist/{dev-server-BRrhkH5t.d.mts → dev-server-D8Qxrp1A.d.mts} +2 -1
- package/dist/dev-server-FZJ6HDKP.mjs +1 -0
- package/dist/guest-admission.mjs +1 -1
- package/dist/guest-live-canvas.mjs +1 -1
- package/dist/index.d.mts +9 -25
- package/dist/index.mjs +1 -1
- package/dist/media.d.mts +3 -3
- package/dist/memory-store.d.mts +7 -2
- package/dist/memory.mjs +1 -1
- package/dist/orientation-markup.mjs +1 -0
- package/dist/outline-trace.mjs +1 -0
- package/dist/{page-interaction-YXHXEYOT.mjs → page-interaction-74JGNCZ5.mjs} +1 -1
- package/dist/{page-planes-Jz2yR_Wk.d.mts → page-planes-BeFZ3Wso.d.mts} +15 -472
- package/dist/{participantBootstrap-DDOxY-Cy.d.mts → participantBootstrap-BcfNTEe9.d.mts} +3 -3
- package/dist/peer-client-B2KMU667.mjs +1 -0
- package/dist/phone-app-HNBDX7UX.mjs +1 -0
- package/dist/plain-html-H35WPIRO.mjs +1 -0
- package/dist/plane-history.mjs +1 -0
- package/dist/plugin-astro.d.mts +8 -3
- package/dist/plugin-astro.mjs +1 -1
- package/dist/plugin-nuxt.d.mts +6 -2
- package/dist/plugin-nuxt.mjs +1 -1
- package/dist/plugin-vite.d.mts +10 -5
- package/dist/plugin-vite.mjs +1 -1
- package/dist/protocol-BIUE4rB6.d.mts +9 -0
- package/dist/server.d.mts +14 -3
- package/dist/server.mjs +1 -1
- package/dist/shared-page-6AUYAPJ3.mjs +1 -0
- package/dist/steerStyles-C4YBV4TZ.mjs +1 -0
- package/dist/sticker-colors.mjs +1 -0
- package/dist/sticker-mode.mjs +1 -0
- package/dist/{subjects-cLtt9-iK.d.mts → subjects-qHIrZrlt.d.mts} +57 -1
- package/dist/taste-constraints.mjs +1 -0
- package/dist/taste-contract.mjs +1 -0
- package/dist/taste-fragment.mjs +1 -0
- package/dist/taste-graph-inspection.mjs +1 -0
- package/dist/taste-layout.mjs +1 -0
- package/dist/taste-page-composition.mjs +1 -0
- package/dist/taste-proposal-session-PSI4TX6H.mjs +1 -0
- package/dist/taste-proposal.mjs +1 -0
- package/dist/taste-token-math.mjs +1 -0
- package/dist/thread-request.mjs +1 -0
- package/dist/thread-view-client.d.mts +2 -0
- package/dist/thread-view-client.mjs +1 -0
- package/dist/thread-view.html +136 -0
- package/dist/{video-adapter-xL95wukX.d.mts → video-adapter-B5eap10v.d.mts} +1 -1
- package/infra/phone-pairing/app-listener.cjs +107 -0
- package/infra/phone-pairing/binding.mjs +369 -20
- package/infra/phone-pairing/machine-config.mjs +43 -26
- package/infra/phone-pairing/machine-service.mjs +94 -6
- package/infra/phone-pairing/machine.mjs +5 -1
- package/infra/phone-pairing/reservations.mjs +103 -0
- package/infra/phone-pairing/writer-lock.mjs +107 -0
- package/package.json +30 -35
- package/dist/ExploreAttachment-ZPC5AR5V.mjs +0 -1
- package/dist/PagePreviewLayer-C7WBS7IX.mjs +0 -1
- package/dist/ParticipantRuntime-CWE62D2G.mjs +0 -1
- package/dist/PhoneHostGate-NWJXZBBP.mjs +0 -1
- package/dist/PopmeltTasteConnectedPane-2BNDKMMB.mjs +0 -1
- package/dist/QueuedReplies-5YG2DN3W.mjs +0 -1
- package/dist/SamplePlacementOverlay-ULOV22WR.mjs +0 -1
- package/dist/ShareProjectPane-KEE7EYMP.mjs +0 -1
- package/dist/SuppliedContext-IT25WBGQ.mjs +0 -1
- package/dist/ThreadPanel-NNJHQQSD.mjs +0 -1
- package/dist/browser-runtime-G6AEOA4X.mjs +0 -1
- package/dist/chunk-2FHGLE7G.mjs +0 -1
- package/dist/chunk-32TDB3N4.mjs +0 -1
- package/dist/chunk-4EDMISUV.mjs +0 -1
- package/dist/chunk-5IZHN3A7.mjs +0 -1
- package/dist/chunk-6DU4ITXT.mjs +0 -1
- package/dist/chunk-6RC7JZ73.mjs +0 -1
- package/dist/chunk-A4GARXVQ.mjs +0 -1
- package/dist/chunk-AKEVJPGD.mjs +0 -1
- package/dist/chunk-AWWUJO3N.mjs +0 -1
- package/dist/chunk-BD7DW4UK.mjs +0 -1
- package/dist/chunk-CRZEJJI6.mjs +0 -1
- package/dist/chunk-CUVWMYUV.mjs +0 -1
- package/dist/chunk-DSTHM3V5.mjs +0 -30
- package/dist/chunk-EWTZVC7E.mjs +0 -1
- package/dist/chunk-FR6VIGJ2.mjs +0 -1
- package/dist/chunk-HVDJYNQ6.mjs +0 -1
- package/dist/chunk-KN4GC34I.mjs +0 -1
- package/dist/chunk-KUILFVXZ.mjs +0 -1
- package/dist/chunk-LLVF422C.mjs +0 -1
- package/dist/chunk-MHTX52KW.mjs +0 -1
- package/dist/chunk-N37INB4D.mjs +0 -1
- package/dist/chunk-NFPUOL4J.mjs +0 -1
- package/dist/chunk-OA63PYHZ.mjs +0 -1
- package/dist/chunk-PQKSXNIZ.mjs +0 -1
- package/dist/chunk-PYGRFSUU.mjs +0 -1
- package/dist/chunk-QYNW5LE2.mjs +0 -1
- package/dist/chunk-RAABZFBD.mjs +0 -1
- package/dist/chunk-REPKQAJK.mjs +0 -1
- package/dist/chunk-TMSGNHXH.mjs +0 -1
- package/dist/chunk-TVS2ZIAW.mjs +0 -1
- package/dist/chunk-UIADZXVT.mjs +0 -1
- package/dist/chunk-V7AOJQXQ.mjs +0 -1
- package/dist/chunk-WKQGWQ3P.mjs +0 -1
- package/dist/chunk-WPU4472Z.mjs +0 -1
- package/dist/chunk-WYQZ7DAK.mjs +0 -1
- package/dist/chunk-X6I6KQDG.mjs +0 -1
- package/dist/chunk-YMWXWXPV.mjs +0 -1
- package/dist/codex-note-context-GXC2474A.mjs +0 -1
- package/dist/codex-project-HVK7FSWQ.mjs +0 -1
- package/dist/codex-store-mount-KHTSSESB.mjs +0 -1
- package/dist/dev-server-QMA23NJQ.mjs +0 -1
- package/dist/participantBootstrap-BuTrTQbo.d.mts +0 -22
- package/dist/peer-client-JL754ZR7.mjs +0 -1
- package/dist/plain-html-EF7MUNRZ.mjs +0 -1
- package/dist/shared-page-QN2XRXUE.mjs +0 -1
- package/dist/steerStyles-E76E44PI.mjs +0 -1
- package/dist/taste-proposal-session-AAXK4CFL.mjs +0 -1
- package/infra/phone-pairing/README.md +0 -25
|
@@ -32,7 +32,11 @@ if (command === 'enroll' || command === 'wake') {
|
|
|
32
32
|
}
|
|
33
33
|
await enroll(invitation.trim());
|
|
34
34
|
}
|
|
35
|
-
if (
|
|
35
|
+
if (
|
|
36
|
+
!existsSync(credentials) &&
|
|
37
|
+
(command !== 'wake' || !readState().liveRouting)
|
|
38
|
+
)
|
|
39
|
+
throw Error('Mac enrollment was not found.');
|
|
36
40
|
await wake();
|
|
37
41
|
} catch (e) {
|
|
38
42
|
console.error(e.message);
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { request } from 'node:http';
|
|
2
|
+
import { readdirSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import {
|
|
5
|
+
readPorts,
|
|
6
|
+
privateDir,
|
|
7
|
+
readPrivate,
|
|
8
|
+
writePrivate,
|
|
9
|
+
} from './binding.mjs';
|
|
10
|
+
import { withThreadWriterLock } from './writer-lock.mjs';
|
|
11
|
+
|
|
12
|
+
function livePort(records, id) {
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
const req = request(
|
|
15
|
+
{
|
|
16
|
+
socketPath: join(records, id, 'app.sock'),
|
|
17
|
+
path: '/__pair/listener',
|
|
18
|
+
headers: { host: 'localhost' },
|
|
19
|
+
method: 'HEAD',
|
|
20
|
+
agent: false,
|
|
21
|
+
signal: AbortSignal.timeout(1500),
|
|
22
|
+
},
|
|
23
|
+
(res) => {
|
|
24
|
+
res.resume();
|
|
25
|
+
const port = Number(res.headers['x-popmelt-app-port']);
|
|
26
|
+
resolve(
|
|
27
|
+
res.statusCode === 204 &&
|
|
28
|
+
Number.isInteger(port) &&
|
|
29
|
+
port > 0 &&
|
|
30
|
+
port <= 65535
|
|
31
|
+
? port
|
|
32
|
+
: undefined,
|
|
33
|
+
);
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
req.once('error', () => resolve(undefined));
|
|
37
|
+
req.end();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function withReservations(records, operation) {
|
|
42
|
+
const machine = join(records, 'machine');
|
|
43
|
+
privateDir(machine);
|
|
44
|
+
// Old services hold an empty provision.lock throughout DNS registration.
|
|
45
|
+
return withThreadWriterLock(
|
|
46
|
+
join(machine, 'provision.lock'),
|
|
47
|
+
operation,
|
|
48
|
+
30000,
|
|
49
|
+
120000,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Walk only the requested move's dependencies. A free destination, or a closed
|
|
54
|
+
// cycle of verified owners, can commit in a single rename. Other projects can
|
|
55
|
+
// stay offline. Old gateways never attest a listener.
|
|
56
|
+
export async function reconcilePort(records, key) {
|
|
57
|
+
return withReservations(records, async () => {
|
|
58
|
+
const ports = readPorts(records),
|
|
59
|
+
owners = new Map(),
|
|
60
|
+
bindings = new Map();
|
|
61
|
+
for (const name of readdirSync(records)) {
|
|
62
|
+
if (!/^[0-9a-f]{64}\.json$/.test(name)) continue;
|
|
63
|
+
const record = JSON.parse(readPrivate(join(records, name)));
|
|
64
|
+
if (
|
|
65
|
+
name !== record.projectKey + '.json' ||
|
|
66
|
+
!/^[0-9a-f]{32}$/.test(record.id)
|
|
67
|
+
)
|
|
68
|
+
throw Error('Invalid pairing record.');
|
|
69
|
+
const port =
|
|
70
|
+
ports[record.projectKey] ?? Number(new URL(record.appOrigin).port);
|
|
71
|
+
if (owners.has(port)) throw Error('Conflicting phone reservations.');
|
|
72
|
+
bindings.set(record.projectKey, record.id);
|
|
73
|
+
owners.set(port, record.projectKey);
|
|
74
|
+
}
|
|
75
|
+
const running = new Map(
|
|
76
|
+
await Promise.all(
|
|
77
|
+
[...bindings].map(async ([project, id]) => [
|
|
78
|
+
project,
|
|
79
|
+
await livePort(records, id),
|
|
80
|
+
]),
|
|
81
|
+
),
|
|
82
|
+
);
|
|
83
|
+
const counts = new Map();
|
|
84
|
+
for (const port of running.values())
|
|
85
|
+
if (port) counts.set(port, (counts.get(port) ?? 0) + 1);
|
|
86
|
+
const moves = new Map(),
|
|
87
|
+
claimed = new Set();
|
|
88
|
+
let current = key;
|
|
89
|
+
while (current && !moves.has(current)) {
|
|
90
|
+
const port = running.get(current);
|
|
91
|
+
if (!port || counts.get(port) !== 1 || claimed.has(port)) return false;
|
|
92
|
+
if (owners.get(port) === current) return current === key;
|
|
93
|
+
moves.set(current, port);
|
|
94
|
+
claimed.add(port);
|
|
95
|
+
current = owners.get(port);
|
|
96
|
+
}
|
|
97
|
+
// A cycle must close at the first mover, never midway into the chain.
|
|
98
|
+
if (current && current !== key) return false;
|
|
99
|
+
for (const [project, port] of moves) ports[project] = port;
|
|
100
|
+
writePrivate(join(records, 'app-ports.json'), JSON.stringify(ports));
|
|
101
|
+
return true;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import {
|
|
3
|
+
mkdir,
|
|
4
|
+
readdir,
|
|
5
|
+
rmdir,
|
|
6
|
+
stat,
|
|
7
|
+
unlink,
|
|
8
|
+
writeFile,
|
|
9
|
+
} from 'node:fs/promises';
|
|
10
|
+
import { dirname, join } from 'node:path';
|
|
11
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
12
|
+
|
|
13
|
+
const missing = (error) => error.code === 'ENOENT';
|
|
14
|
+
async function removeEmpty(directory) {
|
|
15
|
+
await rmdir(directory).catch((error) => {
|
|
16
|
+
if (
|
|
17
|
+
error.code !== 'ENOENT' &&
|
|
18
|
+
error.code !== 'ENOTEMPTY' &&
|
|
19
|
+
error.code !== 'EEXIST'
|
|
20
|
+
)
|
|
21
|
+
throw error;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async function removeOwner(directory, owner) {
|
|
25
|
+
await unlink(join(directory, owner)).catch((error) => {
|
|
26
|
+
if (!missing(error)) throw error;
|
|
27
|
+
});
|
|
28
|
+
// Never recursively remove a lock: a competing claimant may already own it.
|
|
29
|
+
await removeEmpty(directory);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Local-process ownership, shared by every bridge using this thread directory. */
|
|
33
|
+
export async function withThreadWriterLock(
|
|
34
|
+
directory,
|
|
35
|
+
operation,
|
|
36
|
+
timeoutMs = 10_000,
|
|
37
|
+
emptyGraceMs = 1000,
|
|
38
|
+
) {
|
|
39
|
+
await mkdir(dirname(directory), { recursive: true });
|
|
40
|
+
const owner = `${process.pid}-${randomUUID()}`;
|
|
41
|
+
const deadline = Date.now() + timeoutMs;
|
|
42
|
+
while (true) {
|
|
43
|
+
let claimed = false;
|
|
44
|
+
try {
|
|
45
|
+
await mkdir(directory);
|
|
46
|
+
claimed = true;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
if (error.code !== 'EEXIST') throw error;
|
|
49
|
+
}
|
|
50
|
+
if (claimed) {
|
|
51
|
+
let ready = false;
|
|
52
|
+
try {
|
|
53
|
+
await writeFile(join(directory, owner), '', {
|
|
54
|
+
flag: 'wx',
|
|
55
|
+
mode: 0o600,
|
|
56
|
+
});
|
|
57
|
+
const entries = await readdir(directory);
|
|
58
|
+
// An empty stale directory can disappear between mkdir and writing our
|
|
59
|
+
// owner file. If another claimant replaced it, only one owner may enter.
|
|
60
|
+
ready = entries.length === 1 && entries[0] === owner;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (!missing(error)) {
|
|
63
|
+
await removeOwner(directory, owner);
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (ready) {
|
|
68
|
+
try {
|
|
69
|
+
return await operation();
|
|
70
|
+
} finally {
|
|
71
|
+
await removeOwner(directory, owner);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
await removeOwner(directory, owner);
|
|
75
|
+
} else {
|
|
76
|
+
const entries = await readdir(directory).catch((error) => {
|
|
77
|
+
if (missing(error)) return [];
|
|
78
|
+
throw error;
|
|
79
|
+
});
|
|
80
|
+
for (const entry of entries) {
|
|
81
|
+
const match = /^(\d+)-[a-f0-9-]{36}$/.exec(entry);
|
|
82
|
+
if (!match || Number(match[1]) < 1) continue;
|
|
83
|
+
try {
|
|
84
|
+
process.kill(Number(match[1]), 0);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
// Permission errors and reused/live PIDs are not proof of a dead owner.
|
|
87
|
+
if (error.code === 'ESRCH') await removeOwner(directory, entry);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (entries.length === 0) {
|
|
91
|
+
const info = await stat(directory).catch((error) => {
|
|
92
|
+
if (missing(error)) return null;
|
|
93
|
+
throw error;
|
|
94
|
+
});
|
|
95
|
+
// Recover a process that died before creating its owner entry. rmdir
|
|
96
|
+
// cannot remove a directory once a live claimant has populated it.
|
|
97
|
+
if (info && Date.now() - info.mtimeMs > emptyGraceMs)
|
|
98
|
+
await removeEmpty(directory);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (Date.now() >= deadline)
|
|
102
|
+
throw new Error(
|
|
103
|
+
'Thread storage is busy with another writer; retry the operation.',
|
|
104
|
+
);
|
|
105
|
+
await delay(15 + Math.floor(Math.random() * 15));
|
|
106
|
+
}
|
|
107
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@popmelt.com/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"description": "A tiny, powerful design layer for humans and AI",
|
|
5
5
|
"license": "PolyForm-Shield-1.0.0",
|
|
6
6
|
"author": "Popmelt <reb@popmelt.com> (https://popmelt.com)",
|
|
@@ -24,37 +24,15 @@
|
|
|
24
24
|
"popmelt": "dist/cli.mjs"
|
|
25
25
|
},
|
|
26
26
|
"sideEffects": false,
|
|
27
|
-
"packageManager": "pnpm@9.12.0",
|
|
28
27
|
"engines": {
|
|
29
28
|
"node": ">=18.0.0"
|
|
30
29
|
},
|
|
31
|
-
"scripts": {
|
|
32
|
-
"build": "tsup",
|
|
33
|
-
"clean": "git clean -xdf .turbo node_modules dist",
|
|
34
|
-
"format": "prettier --check \"**/*.{ts,tsx}\"",
|
|
35
|
-
"lint": "node scripts/lint.mjs . && node scripts/check-eslint-suppressions.mjs",
|
|
36
|
-
"pack:smoke": "node scripts/pack-smoke.mjs",
|
|
37
|
-
"playground:continuity:practice": "vite --config e2e/fixtures/source-continuity/practice.vite.mts",
|
|
38
|
-
"playground:continuity": "vite --config e2e/fixtures/source-continuity/vite.config.mts",
|
|
39
|
-
"playground:pull": "vite --config e2e/fixtures/plane-pull/vite.config.mts",
|
|
40
|
-
"peer:smoke": "node scripts/peer-compat-smoke.mjs",
|
|
41
|
-
"vue:smoke": "pnpm run build && node scripts/vue-install-smoke.mjs",
|
|
42
|
-
"nuxt:smoke": "pnpm run build && node scripts/nuxt-install-smoke.mjs",
|
|
43
|
-
"astro:smoke": "pnpm run build && node scripts/framework-install-smoke.mjs astro",
|
|
44
|
-
"svelte:smoke": "pnpm run build && node scripts/framework-install-smoke.mjs svelte && node scripts/framework-install-smoke.mjs sveltekit",
|
|
45
|
-
"prepublishOnly": "pnpm run verify",
|
|
46
|
-
"test": "vitest run",
|
|
47
|
-
"test:coverage": "vitest run --coverage.enabled",
|
|
48
|
-
"test:browser": "pnpm run build && tsc --noEmit -p tsconfig.browser.json && vitest run --config vitest.browser.config.ts",
|
|
49
|
-
"test:browser:mutation": "node e2e/check-lifecycle-mutation.mjs",
|
|
50
|
-
"test:watch": "vitest",
|
|
51
|
-
"typecheck": "tsc --noEmit --incremental false",
|
|
52
|
-
"verify": "pnpm run typecheck && pnpm run format && pnpm run lint && pnpm run test:coverage && pnpm run build && pnpm run pack:smoke"
|
|
53
|
-
},
|
|
54
30
|
"imports": {
|
|
31
|
+
"#phone-app-listener": "./infra/phone-pairing/app-listener.cjs",
|
|
55
32
|
"#phone-pairing-machine": "./infra/phone-pairing/machine.mjs",
|
|
56
33
|
"#guest-live-canvas": "./dist/guest-live-canvas.mjs",
|
|
57
34
|
"#guest-admission": "./dist/guest-admission.mjs",
|
|
35
|
+
"#thread-view-client": "./dist/thread-view-client.mjs",
|
|
58
36
|
"#guest-browser": "./dist/browser.mjs"
|
|
59
37
|
},
|
|
60
38
|
"exports": {
|
|
@@ -133,6 +111,9 @@
|
|
|
133
111
|
"files": [
|
|
134
112
|
"dist",
|
|
135
113
|
"infra/phone-pairing/binding.mjs",
|
|
114
|
+
"infra/phone-pairing/app-listener.cjs",
|
|
115
|
+
"infra/phone-pairing/reservations.mjs",
|
|
116
|
+
"infra/phone-pairing/writer-lock.mjs",
|
|
136
117
|
"infra/phone-pairing/machine.mjs",
|
|
137
118
|
"infra/phone-pairing/machine-config.mjs",
|
|
138
119
|
"infra/phone-pairing/machine-service.mjs",
|
|
@@ -180,7 +161,6 @@
|
|
|
180
161
|
"@jsquash/webp": "1.5.0",
|
|
181
162
|
"qrcode-generator": "2.0.4",
|
|
182
163
|
"nuxt": "4.6.4",
|
|
183
|
-
"@kit/eslint-config": "workspace:^",
|
|
184
164
|
"@react-three/fiber": "9.7.0",
|
|
185
165
|
"@tanstack/react-router": "1.120.5",
|
|
186
166
|
"@types/react": "19.1.0",
|
|
@@ -204,14 +184,29 @@
|
|
|
204
184
|
"vite": "7.3.7",
|
|
205
185
|
"vitest": "4.1.12",
|
|
206
186
|
"vue": "3.5.44",
|
|
207
|
-
"vue-router": "5.3.1"
|
|
187
|
+
"vue-router": "5.3.1",
|
|
188
|
+
"@kit/eslint-config": "^0.2.0"
|
|
208
189
|
},
|
|
209
|
-
"
|
|
210
|
-
"
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
190
|
+
"scripts": {
|
|
191
|
+
"build": "tsup",
|
|
192
|
+
"clean": "git clean -xdf .turbo node_modules dist",
|
|
193
|
+
"format": "prettier --check \"**/*.{ts,tsx}\"",
|
|
194
|
+
"lint": "node scripts/lint.mjs . && node scripts/check-eslint-suppressions.mjs",
|
|
195
|
+
"pack:smoke": "node scripts/pack-smoke.mjs",
|
|
196
|
+
"playground:continuity:practice": "vite --config e2e/fixtures/source-continuity/practice.vite.mts",
|
|
197
|
+
"playground:continuity": "vite --config e2e/fixtures/source-continuity/vite.config.mts",
|
|
198
|
+
"playground:pull": "vite --config e2e/fixtures/plane-pull/vite.config.mts",
|
|
199
|
+
"peer:smoke": "node scripts/peer-compat-smoke.mjs",
|
|
200
|
+
"vue:smoke": "pnpm run build && node scripts/vue-install-smoke.mjs",
|
|
201
|
+
"nuxt:smoke": "pnpm run build && node scripts/nuxt-install-smoke.mjs",
|
|
202
|
+
"astro:smoke": "pnpm run build && node scripts/framework-install-smoke.mjs astro",
|
|
203
|
+
"svelte:smoke": "pnpm run build && node scripts/framework-install-smoke.mjs svelte && node scripts/framework-install-smoke.mjs sveltekit",
|
|
204
|
+
"test": "vitest run",
|
|
205
|
+
"test:coverage": "vitest run --coverage.enabled",
|
|
206
|
+
"test:browser": "pnpm run build && tsc --noEmit -p tsconfig.browser.json && vitest run --config vitest.browser.config.ts",
|
|
207
|
+
"test:browser:mutation": "node e2e/check-lifecycle-mutation.mjs",
|
|
208
|
+
"test:watch": "vitest",
|
|
209
|
+
"typecheck": "tsc --noEmit --incremental false",
|
|
210
|
+
"verify": "pnpm run typecheck && pnpm run format && pnpm run lint && pnpm run test:coverage && pnpm run build && pnpm run pack:smoke"
|
|
216
211
|
}
|
|
217
|
-
}
|
|
212
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use client";import{c as e,f as t,d as n,e as r,a as o,b as a}from"./chunk-ZQMKLODZ.mjs";import{d as i}from"./chunk-HOWDQUPT.mjs";import{g as s,f as l,b as p}from"./chunk-ZSL57PQ7.mjs";import{a as d,b as c,c as u}from"./chunk-EWTZVC7E.mjs";import{a as h}from"./chunk-QYNW5LE2.mjs";import{c as m,a as g,b as f}from"./chunk-ELKVFX2O.mjs";import{n as v,m as b,k as x,b as y,c as w,l as k,j as C,i as E}from"./chunk-AWWUJO3N.mjs";import"./chunk-Q6N77LIS.mjs";import"./chunk-FHCKFQBY.mjs";import"./chunk-APP5IYTE.mjs";import"./chunk-TMSGNHXH.mjs";import{a as S}from"./chunk-G2ZHJXHZ.mjs";import"./chunk-53SKVMWR.mjs";import{l as I}from"./chunk-5IZHN3A7.mjs";import"./chunk-RK6UROPO.mjs";import"./chunk-AOTDTBQO.mjs";import{h as P}from"./chunk-VXRRHXUP.mjs";import"./chunk-WP2SHSCG.mjs";import{v as O}from"./chunk-LH7HKUCK.mjs";import{c as T}from"./chunk-ZVDKW7TO.mjs";import{a as N}from"./chunk-Q6C7ZA3H.mjs";import{b as j}from"./chunk-CK3CDA3L.mjs";import"./chunk-7D4BUDKG.mjs";import{b as A}from"./chunk-OEJXPUAR.mjs";import"./chunk-HM6EBJVO.mjs";import{D as M,N as R,aa as z,Z as B,s as L,_ as D,F as H,G as J}from"./chunk-OA63PYHZ.mjs";import{a as V,c as W}from"./chunk-ADRWR5GI.mjs";import"./chunk-SUAHDXJZ.mjs";import"./chunk-YGP6PPOZ.mjs";import{useContext as K,useState as U,useRef as X,useLayoutEffect as q,useMemo as Y,useEffect as Z,useCallback as F}from"react";import{createPortal as G}from"react-dom";import{jsxs as Q,Fragment as $,jsx as _}from"react/jsx-runtime";import{createContext as ee,domToCanvas as te,destroyContext as ne}from"modern-screenshot";function re(e,t,n,r=!1){let[o,a]=U({}),i=n?.backdrop,s=n?.style.color;return q(()=>{if(location.pathname!==e.pathname||r&&i)return void a({background:i,ink:s});let n="component"===t?y(e):void 0,o=n?.component??n?.element??O(e.selector,e.element);if(!o)return void a({background:i,ink:s});let l=o.ownerDocument.defaultView,p=()=>{let e=f(o)??i,t=l.getComputedStyle(o).color;a(n=>n.background===e&&n.ink===t?n:{background:e,ink:t})};p();let d=new MutationObserver(p),c=[o,...g(o)],u=e=>{["color","background-color"].includes(e.propertyName)&&e.target===e.currentTarget&&p()};for(let e of c)d.observe(e,{attributes:!0}),e.addEventListener("transitionend",u);let h=l.matchMedia("(prefers-color-scheme: dark)");return h.addEventListener("change",p),l.addEventListener("resize",p),()=>{d.disconnect();for(let e of c)e.removeEventListener("transitionend",u);h.removeEventListener("change",p),l.removeEventListener("resize",p)}},[e,t,i,s,r]),o}var oe=`\n.sp-card button { border: 0; cursor: pointer; font: inherit; }\n.sp-card {\n --sp-control-bg: light-dark(var(--popmelt-thread-soft, #f2f2f2), #363636);\n position: relative;\n align-self: stretch;\n min-width: 0;\n width: 100%;\n margin-top: 6px;\n border-radius: 12px;\n overflow: hidden;\n color: var(--popmelt-thread-primary, #222);\n font:\n 13px/1.38 'Popmelt Geist',\n system-ui,\n sans-serif;\n}\n.sp-card, .sp-workspace {\n color-scheme: light dark;\n background-color: var(--sp-page-background, var(--popmelt-thread-raised, light-dark(#fff, #181818)));\n background-image: radial-gradient(circle, var(--sp-page-dot, light-dark(#f2f2f2, #222222)) 1px, transparent 1.25px);\n background-size: 11px 11px;\n}\n:is(.sp-workspace[data-popmelt-theme='dark'], [data-popmelt-theme='dark'] .sp-card) {\n color-scheme: dark;\n}\n:is(.sp-workspace[data-popmelt-theme='light'], [data-popmelt-theme='light'] .sp-card) {\n color-scheme: light;\n}\n.sp-stage {\n position: relative;\n min-height: 185px;\n display: grid;\n /* The zoom viewport measures this track. Keep captured images and previous\n zoom measurements from increasing its intrinsic minimum width. */\n grid-template-columns: minmax(0, 1fr);\n place-items: center;\n padding: 0;\n}\n.sp-actions,\n.sp-zoom-actions {\n position: absolute;\n z-index: 2;\n top: 6px;\n display: flex;\n gap: 3px;\n opacity: 0;\n pointer-events: none;\n transition: opacity 120ms ease-out;\n}\n.sp-actions {\n right: 6px;\n}\n.sp-zoom-actions {\n left: 6px;\n}\n.sp-card:is(:hover, :has(:focus-visible)) :is(.sp-actions, .sp-zoom-actions),\n.sp-actions[data-preview-active='true'] {\n opacity: 1;\n pointer-events: auto;\n}\n.sp-zoom-actions [role='group'] {\n display: flex;\n gap: 2px;\n}\n.sp-card :is(.sp-actions, .sp-zoom-actions) button {\n color: var(--popmelt-thread-primary, #383838);\n background: var(--sp-control-bg);\n border-radius: 8px;\n width: 28px;\n height: 26px;\n display: grid;\n place-items: center;\n}\n.sp-card .sp-zoom-actions button {\n width: 26px;\n}\n.sp-card .sp-zoom-actions button:disabled {\n color: #aaa;\n cursor: default;\n}\n.sp-card .sp-actions button[aria-pressed='true'] {\n background: var(--sp-accent, #ed1014);\n color: white;\n}\n.sp-card button:focus-visible {\n outline: 2px solid var(--sp-accent, #ed1014);\n outline-offset: 2px;\n}\n.sp-card svg {\n width: 14px;\n height: 14px;\n}\n/* Thread text is selectable by default, including individual spans. */\n.sp-card footer, .sp-card footer * {\n -webkit-user-select: none !important;\n user-select: none !important;\n}\n.sp-card footer {\n font: 14px/1.5 ${V};\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 3px;\n position: absolute;\n inset: auto 0 0;\n z-index: 2;\n padding: 6px;\n pointer-events: none;\n}\n.sp-card .tag-option,\n.sp-card .pager button {\n padding: 3px;\n background: none;\n color: inherit;\n}\n.sp-card .tag-option {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n min-width: 0;\n text-align: left;\n}\n.sp-card .tag-option > span {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.sp-card .tag-option > svg {\n flex: none;\n opacity: 0;\n transition: opacity 120ms ease-out;\n}\n.sp-card .tag-option:is(:hover, :focus-visible) > svg {\n opacity: 1;\n}\n@media (hover: none), (max-width: 480px) {\n .sp-card .tag-option > svg {\n opacity: 1;\n }\n}\n@media (prefers-reduced-motion: reduce) {\n .sp-card .tag-option > svg {\n transition: none;\n }\n}\n.sp-card .pager {\n display: flex;\n align-items: center;\n gap: 3px;\n color: var(--popmelt-thread-primary, #383838);\n white-space: nowrap;\n}\n.sp-card .pager-number {\n font-variant-numeric: tabular-nums;\n}\n.sp-card .pager button {\n width: 22px;\n height: 22px;\n display: grid;\n place-items: center;\n}\n.sp-card footer :is(.tag-option, .pager) {\n pointer-events: auto;\n touch-action: manipulation;\n}\n.sp-card footer .tag-option {\n padding: 0;\n}\n.sp-card .tag-option > span,\n.sp-card .pager {\n box-sizing: border-box;\n min-height: 26px;\n padding: 2px 8px;\n border-radius: 8px;\n background: var(--sp-control-bg);\n}\n.sp-card .tag-option > span {\n align-content: center;\n}\n.sp-card footer .pager {\n padding-inline: 2px;\n touch-action: pan-y pinch-zoom;\n}\n@media (prefers-reduced-motion: reduce) {\n .sp-actions,\n .sp-zoom-actions {\n transition: none;\n }\n}\n@media (hover: none), (max-width: 480px) {\n .sp-actions,\n .sp-zoom-actions {\n pointer-events: auto;\n opacity: 1;\n transition: none;\n }\n}\n\n.sp-expanded-placeholder, .sp-steer-frame { height: 260px; }\n.sp-steer-frame {\n position: relative;\n border: 0;\n display: block;\n width: 100%;\n border-radius: inherit;\n}\n\n/* An expanded card covers the annotation canvas. Its editor takes the free side of the thread. */\n/* Group the toolbar and its popovers above the editor, alongside the thread. */\n:is(body, [data-popmelt-root]):has(> .sp-workspace:not([hidden])) [data-popmelt-toolbar-layer] {\n position: relative;\n z-index: 10004;\n}\n/* Preserve the toolbar's geometry while the active preview covers its controls. */\n[data-popmelt-toolbar-layer][inert] { opacity: 0; }\n.sp-workspace {\n position: fixed;\n inset: 8px;\n overflow: clip;\n box-shadow: 0 0 0 100vmax light-dark(rgb(255 255 255 / 50%), rgb(0 0 0 / 50%));\n}\n.sp-workspace .sp-card {\n position: absolute;\n inset: 0 var(--sp-work-right, 0px) 0 var(--sp-work-left, 0px);\n width: auto;\n display: flex;\n flex-direction: column;\n margin: 0;\n border-radius: 0;\n background: transparent;\n}\n.sp-workspace .sp-stage {\n flex: 1;\n min-height: 0;\n}\n.sp-workspace .sp-steer-frame {\n position: absolute;\n inset: 0;\n height: 100%;\n}\n.sp-workspace :is(.sp-actions, .sp-zoom-actions) {\n top: 12px;\n opacity: 1;\n pointer-events: auto;\n}\n.sp-workspace .sp-actions { right: 12px; }\n.sp-workspace .sp-zoom-actions { left: 12px; }\n.sp-workspace .sp-card footer { padding: 12px; }\n.sp-card .sp-expanded-badge {\n display: inline-flex;\n align-items: center;\n gap: 5px;\n border-radius: 8px;\n min-height: 26px;\n padding: 2px 8px;\n background: var(--sp-control-bg);\n color: inherit;\n}\n[data-popmelt-explore-canvas="right"] .sp-expanded-badge > svg { rotate: 180deg; }\n@media (max-width: 480px) {\n /* Keep the same mounted composer and card; the portal uses the space above them. */\n [data-devtools="thread-panel"][data-popmelt-explore-canvas] {\n top: auto !important;\n height: auto !important;\n padding: 0 !important;\n border: 0 !important;\n background: transparent !important;\n backdrop-filter: none !important;\n }\n [data-popmelt-explore-canvas] [data-popmelt-thread-shell] {\n overflow: visible !important;\n background: transparent !important;\n }\n [data-popmelt-explore-canvas] :is([data-popmelt-thread-header], [data-devtools="thread-panel-messages"], [data-queued-replies-area], [data-scroll-to-bottom]) {\n display: none !important;\n }\n .sp-workspace {\n inset: max(var(--popmelt-thread-visible-top, 8px), env(safe-area-inset-top))\n max(8px, env(safe-area-inset-right))\n calc(max(var(--popmelt-thread-visible-bottom, 8px), env(safe-area-inset-bottom)) + var(--sp-thread-height, 0px) + 6px)\n max(8px, env(safe-area-inset-left));\n }\n .sp-workspace .sp-card { inset: 0; }\n [data-popmelt-explore-canvas] .sp-expanded-badge > svg { rotate: 90deg; }\n}\n`;function ae({anchor:e,surfaceStyle:t,children:n}){let{visible:r}=K(o),a=X(null),[i,s]=U(null);return q(()=>{s(e.current?.closest("[data-popmelt-root]")??document.body)},[e]),q(()=>{if(r&&i)return function(e){let t=e.createElement("style");return t.textContent=":root, body { overflow: hidden !important; overscroll-behavior: none !important; }",e.head.append(t),()=>t.remove()}(i.ownerDocument)},[i,r]),q(()=>{let t=a.current,n=e.current?.closest('[data-devtools="thread-panel"]');if(!t||!n||!r)return;n.dataset.popmeltExploreCanvas="left";let o=i?.querySelector("[data-popmelt-toolbar-layer]"),s=o?.querySelector("#devtools-toolbar"),l=()=>{let e=n.getBoundingClientRect();if(o&&s){let t=s.getBoundingClientRect(),n=e.left<t.right+1&&e.right>t.left-1&&e.top<t.bottom+1&&e.bottom>t.top-1;o.inert=N(window.innerWidth)||n}let r=t.getBoundingClientRect(),a=e.left-r.left>=r.right-e.right;n.dataset.popmeltExploreCanvas=a?"left":"right",t.style.setProperty("--sp-thread-height",`${e.height}px`),t.style.setProperty("--sp-work-left",a?"0px":`${Math.max(0,e.right-r.left)}px`),t.style.setProperty("--sp-work-right",a?`${Math.max(0,r.right-e.left)}px`:"0px"),t.style.borderRadius=getComputedStyle(n).borderRadius,t.dataset.popmeltTheme=n.dataset.popmeltTheme;for(let e of Array.from(n.style))e.startsWith("--popmelt-thread-")&&t.style.setProperty(e,n.style.getPropertyValue(e))};l();let p=new ResizeObserver(l);p.observe(n),s&&p.observe(s);let d=new MutationObserver(l);return d.observe(n,{attributes:!0,attributeFilter:["style","data-popmelt-theme"]}),s&&d.observe(s,{attributeFilter:["style"]}),window.addEventListener("resize",l),()=>{o&&(o.inert=!1),delete n.dataset.popmeltExploreCanvas,p.disconnect(),d.disconnect(),window.removeEventListener("resize",l)}},[e,i,r]),i?G(_("div",{hidden:!r,ref:a,className:"sp-workspace","data-popmelt-font":"sans",style:{...t,zIndex:10003},children:n}),i):null}function ie({tag:e,framing:t}){let n=X(null);return _("div",{"data-devtools":"preview-feedback-picker",style:{position:"absolute",inset:0,cursor:e?"crosshair":"default",userSelect:"none"},onPointerDown:e=>{n.current=e.isPrimary&&0===e.button?{id:e.pointerId,x:e.clientX,y:e.clientY,dragged:!1}:null},onPointerMove:e=>{let r=n.current;if(r?.id!==e.pointerId)return;let o=e.clientX-r.x,a=e.clientY-r.y;if(!r.dragged&&Math.hypot(o,a)<=8||(r.dragged=!0,r.x=e.clientX,r.y=e.clientY,"touch"!==e.pointerType||t.getScale()<=1))return;let{width:i,height:s}=e.currentTarget.getBoundingClientRect();if(!i||!s)return;let l=t.getView(i,s);t.setView(l.scale,l.x+o/i,l.y+a/s,i,s)},onPointerLeave:()=>{n.current=null},onPointerCancel:()=>{n.current=null},onPointerUp:t=>{let r=n.current;if(n.current=null,r?.id!==t.pointerId||r.dragged||Math.hypot(t.clientX-r.x,t.clientY-r.y)>8||!e)return;let o=t.currentTarget.parentElement?.querySelector(".sp-fit");if(!o)return;let a=P(t.clientX,t.clientY,{within:o})?.closest("[data-scratch-part]");a&&e(a.getAttribute("data-scratch-part"),E(a))}})}function se({capture:e,framing:t}){let n=X(null),[r,o]=U(1);return q(()=>{let r=n.current,a=()=>{let n=Math.max(.01,Math.min(1,(r.clientWidth-36)/e.width,(r.clientHeight-36)/e.height));o(n),t.setFitScale(n)};a();let i=new ResizeObserver(a);return i.observe(r),()=>i.disconnect()},[e,t]),_("div",{className:"sp-steer-frame",ref:n,children:_(u,{interactive:!0,framing:t,overlay:_(ie,{framing:t}),children:_("div",{style:{display:"grid",placeItems:"center",width:"100%",height:"100%"},children:_("img",{alt:"Original at exploration time",src:e.still,draggable:!1,style:{width:e.width*r,height:e.height*r,maxWidth:"none"}})})})})}function le({original:e,bundles:t,target:n,theme:o,accent:a,framing:i,onEscape:s}){let[l,p]=U(!1),{capture:d,runnable:c}=e,u=c&&t?.[c.fixture.bundle];return c&&!l&&"string"!=typeof u?u?_(r,{bundle:u,target:n,readOnly:!0,capture:d,theme:o,accent:a,framing:i,initial:[],onError:()=>p(!0),onEscape:s}):_("div",{className:"sp-steer-frame",role:"status",children:"Loading original…"}):d?.still?_(se,{capture:d,framing:i}):_("div",{className:"sp-steer-frame",role:"status",children:"Original unavailable for this round."})}function pe({frameUrl:e,theme:t,...n}){let[r,o]=U(null);return q(()=>{r&&t&&(r.documentElement.style.colorScheme=t)},[r,t]),q(()=>{if(!r||!n.captureRef)return;let e=()=>{let e=r.querySelector(".sp-fit");return e?async function(e,t){let n=e.ownerDocument;await n.fonts.ready;let r=e.getBoundingClientRect(),o=e.offsetWidth,a=e.offsetHeight;if(!o||!a||!r.width)throw Error("The option is not ready to capture.");let i=r.width/o,s=Array.from(e.children,e=>e.getBoundingClientRect()).filter(e=>e.width&&e.height);s.length||s.push(r);let l,p=Math.max(0,(Math.min(r.right,...s.map(e=>e.left))-r.left)/i-12),d=Math.max(0,(Math.min(r.bottom,...s.map(e=>e.top))-r.top)/i-12),c=Math.min(o,(Math.max(r.left,...s.map(e=>e.right))-r.left)/i+12),u=Math.min(a,(Math.max(r.top,...s.map(e=>e.bottom))-r.top)/i+12),h=await ee(e,{width:o,height:a,scale:Math.min(2,1600/Math.max(o,a)),backgroundColor:t,timeout:2500,style:{transform:"none",position:"static",margin:"0"},onCloneEachNode:e=>{if(1!==e.nodeType)return;let t=e;(t.hasAttribute("data-tagged")||t.hasAttribute("data-badge-hover")||t.hasAttribute("data-scratch-part"))&&(t.style.outline="none"),t.removeAttribute("data-tagged"),t.removeAttribute("data-badge-hover")}});h.sandbox=n.createElement("iframe");try{l=await te(h)}finally{ne(h)}let m=n.createElement("canvas"),g=l.width/o;return m.width=Math.max(1,Math.ceil((c-p)*g)),m.height=Math.max(1,Math.ceil((u-d)*g)),m.getContext("2d").drawImage(l,-p*g,-d*g),new Promise((e,t)=>m.toBlob(n=>n?e(n):t(Error("Could not capture the reviewed option.")),"image/png"))}(e,n.captureBackground??"transparent"):Promise.reject(Error("The option is still loading."))},t=n.captureRef;return t.current=e,()=>{t.current===e&&(t.current=null)}},[r,n.captureRef,n.captureBackground]),Q($,{children:[_("iframe",{className:"sp-steer-frame",style:{colorScheme:t},"aria-label":"Edit or comment on this option",src:e,srcDoc:e?void 0:h,onLoad:e=>{let t=e.currentTarget.contentDocument;t&&W(t),o(t)}}),r&&_(de,{doc:r,...n},n.editorKey)]})}function de({doc:e,...t}){let{toggle:n}=K(o),r=X(t),i=X(t);i.current=t;let s=X(void 0);q(()=>{let t=e.defaultView;if(!t)return;let{node:o,initial:a,target:l,accentColor:p,framing:d}=r.current,c=!0,u=a;s.current=t.startScratchSteer?.(o,l,p,d,e=>{if(!c)return;let t=C(a,e);JSON.stringify(t)!==JSON.stringify(u)&&(u=t,i.current.onChange(t))},e=>{c&&i.current.onTag(e)},e=>{c&&i.current.onPreview(e)},n);let h=e=>{"Escape"!==e.key||!i.current.onEscapeWorkspace||e.target?.closest?.('input, textarea, [contenteditable="true"]')||(e.preventDefault(),e.stopImmediatePropagation(),i.current.onEscapeWorkspace())};return t.addEventListener("keydown",h,!0),()=>{c=!1,s.current=void 0,i.current.onPreview(null),t.removeEventListener("keydown",h,!0)}},[e,n]);let l=T(),[p,d]=U();q(()=>{let t=e.defaultView?.frameElement;if(t instanceof HTMLIFrameElement)return a(t,d,()=>{e.documentElement.setAttribute("data-preview-control-hovered","")})},[e]);let{selectedPart:c,hoveredPart:u,focusRequest:h}=t;return q(()=>{s.current?.({feedbackOnly:l,selectedPart:c,hoveredPart:u,focusRequest:h,controlBounds:p})},[e,n,c,u,h,p,l]),null}function ce(e){!e||e.getRootNode().activeElement?.closest("[data-popmelt-thread-composer]")||e.querySelector("[data-expand-option]")?.focus({preventScroll:!0})}function ue({batch:e,frameUrl:t,bundles:r,canApply:o=!0,frozenVersion:a,framing:s,theme:l,accentColor:p,selection:u,preview:h,setTag:g,onTogglePreview:f,onBrowse:v,edits:b,revisions:x,index:y,hoveredTarget:w,focusRequest:k,onPreviewStyle:C,onFixtureCanvas:E,onSteer:S,onApply:P,busy:O,expanded:T,onExpand:N}){let A=X(null),[D,H]=U(""),[J,V]=U(!1),W=X(null),K=X(null),Y=F(e=>{K.current=e,ce(e)},[]),Z=X(T);q(()=>{Z.current&&!T&&ce(W.current),Z.current=T},[T]),q(()=>{if(k?.batchId!==e.id||k.option!==y)return;let t=T?K.current:W.current,n=t?.closest('[data-devtools="thread-panel-messages"]');if(!t||!n)return;let r=t.getBoundingClientRect(),o=n.getBoundingClientRect();r.top>=o.top&&r.bottom<=o.bottom||n.scrollBy({top:r.top-o.top-Math.max(0,(n.clientHeight-r.height)/2),behavior:window.matchMedia("(prefers-reduced-motion: reduce)").matches?"instant":"smooth"})},[e.id,y,k,T]);let G=JSON.stringify([e.id,y,a??x?.[y]??0]),[ee]=U(()=>s??d(null)),te=e.options.length,ne=-1===y?e.original:void 0,ie=e.options[Math.max(0,y)],{background:se,ink:de}=re(e.target,ne?.capture?.scope??("fixture"in ie?ie.previewScope:void 0),e.original?.capture,!!ne),ue=se?m(se):void 0,me=ue?.theme??l,ge={"--sp-page-background":se,"--sp-accent":p,"--sp-page-dot":ue?.dot,backgroundImage:ne?"none":void 0},fe={batchId:e.id,option:y,path:[]},ve=h?.showVariant&&h.target.batchId===e.id&&h.target.option===y;let be="fixture"in ie?r?.[ie.fixture.bundle]:void 0,xe=_(he,{title:ne?"Original":ie.title,index:ne?-1:y,hasOriginal:!!e.original,optionCount:te,accentColor:p,canTag:o,onTag:()=>g(fe),browseBy:function(t){let n=e.original?-1:0,r=te-n,o=n+(y-n+t+r)%r;H(""),v({...fe,option:o})}}),ye=Q("div",{className:"sp-stage",style:{cursor:I(p)},children:[_("div",{className:"sp-zoom-actions",children:_(c,{framing:ee})}),Q("div",{className:"sp-actions","data-preview-active":!!h,children:[!ne&&ve&&o&&_(j,{type:"button","aria-label":"Apply this option in code",disabled:O||J,onClick:async()=>{H(""),V(!0);try{if(!A.current)throw Error("The option is still loading. Try again in a moment.");let e=await A.current();await P(fe,e)}catch(e){H(e instanceof Error?e.message:"Could not apply this option.")}finally{V(!1)}},children:_(M,{})}),!a&&(!ne||!!h)&&_(j,{type:"button","aria-pressed":!!h,hint:!T&&h?"Turn off page preview":"Preview on page","aria-label":"Preview on page",disabled:"fixture"in ie&&(!be||"string"==typeof be),onClick:()=>f(fe),children:_(R,{})}),_(j,{type:"button","data-expand-option":"","aria-label":T?"Collapse preview":"Expand preview","aria-expanded":T,onClick:()=>N(!T),children:_(T?z:B,{})})]}),ne?_(le,{original:ne,target:e.target,bundles:r,framing:ee,theme:me,accent:p,onEscape:T?()=>N(!1):void 0}):"fixture"in ie?_(n,{captureRef:A,captureBackground:se??void 0,frameKey:G,frozenParent:!!a,readOnly:!!a,capture:a?e.original?.capture:void 0,bundle:be,previewScope:ie.previewScope,target:e.target,pageInk:se?de:void 0,framing:ee,theme:me,accent:p,initial:b.filter(t=>t.batchId===e.id&&t.option===y),onCanvas:e=>E?.(ie.fixture.bundle,e),onEscape:T?()=>N(!1):void 0,selected:u?.batchId===e.id&&u.option===y?u.fixturePart:void 0,onTag:(e,t)=>g({...fe,fixturePart:e,fixturePartLabel:t}),onChange:e=>S(y,e),onPreview:e=>C(y,e)}):_(pe,{captureRef:A,captureBackground:se??void 0,editorKey:G,readOnly:!!a,framing:ee,onEscapeWorkspace:T?()=>N(!1):void 0,frameUrl:t,target:e.target,node:ie.root,theme:me,accentColor:p,initial:b.filter(t=>t.batchId===e.id&&t.option===y),onPreview:e=>C(y,e),hoveredPart:w?.batchId===e.id&&w.option===y?w.part:void 0,focusRequest:k?.batchId===e.id&&k.option===y?k:void 0,selectedPart:u?.batchId===e.id&&u.option===y?u.path.join(".")+(u.field?"/label":""):void 0,onChange:e=>S(y,e),onTag:e=>{let[t,n]=e.split("/");g({...fe,path:t?t.split(".").map(Number):[],field:"label"===n?"label":void 0})}}),D&&_("span",{role:"alert",children:D}),xe]});return Q($,{children:[Q("section",{ref:W,"data-explore-batch":e.id,"aria-label":"Explore options",className:"sp-card",style:ge,"data-popmelt-tooltip-group":"",children:[_("style",{children:oe}),T?Q("div",{className:"sp-stage sp-expanded-placeholder",children:[Q(j,{type:"button",className:"sp-expanded-badge",hint:"Collapse preview","aria-label":"Preview expanded. Collapse preview","aria-expanded":!0,onClick:()=>N(!1),children:[_(L,{"aria-hidden":"true"}),"Preview expanded"]}),xe]}):ye]}),!ne&&"fixture"in ie&&ie.rationale&&_(i,{text:ie.rationale}),T&&_(ae,{anchor:W,surfaceStyle:ge,children:_("section",{ref:Y,"aria-label":"Expanded explore options",className:"sp-card","data-popmelt-tooltip-group":"","data-popmelt-tooltip-boundary":!0,children:ye})})]})}function he({title:e,index:t,optionCount:n,hasOriginal:r,accentColor:o,onTag:a,canTag:i,browseBy:s}){let l=X(null),p=X(null);return Q("footer",{children:[t<0?_("span",{className:"tag-option",children:_("span",{children:e})}):Q(j,{above:!0,className:"tag-option",disabled:!i,hint:"Add to chat",anchorRef:l,"aria-label":`Add ${e} to chat`,onClick:a,children:[_("span",{children:e}),_(D,{ref:l,"aria-hidden":"true",color:o})]}),(r||n>1)&&Q("div",{className:"pager",onTouchStart:e=>{let t=e.touches[0];p.current=1===e.touches.length?{id:t.identifier,x:t.clientX,y:t.clientY}:null},onTouchCancel:()=>{p.current=null},onTouchEnd:e=>{let t=p.current;p.current=null;let n=e.changedTouches[0];if(!t||!n||n.identifier!==t.id||e.touches.length)return;let r=n.clientX-t.x,o=n.clientY-t.y;Math.abs(r)<24||Math.abs(r)<1.3*Math.abs(o)||(e.preventDefault(),s(r>0?1:-1))},children:[_("button",{type:"button","aria-label":"Previous option",onClick:()=>s(-1),children:_(H,{})}),Q("span",{"aria-live":"polite",children:[_("span",{className:"pager-number",children:t+1})," of"," ",_("span",{className:"pager-number",children:n})]}),_("button",{type:"button","aria-label":"Next option",onClick:()=>s(1),children:_(J,{})})]})]})}function me(e,t,n){return`popmelt-explore-draft:${e}:${t}:${n}`}function ge(e,t,n,r,o){try{let a=me(e,t,n);void 0!==o?window.localStorage.setItem(a,JSON.stringify({revision:o,edits:r})):r.length?window.localStorage.setItem(a,JSON.stringify(r)):window.localStorage.removeItem(a)}catch{}}function fe(e,t,n,r){try{let o=me(e,t,n),a=window.localStorage.getItem(o);if(!a)return;let i=JSON.parse(a),s=Array.isArray(i)?{revision:0,edits:i}:i;s.revision===r.revision&&JSON.stringify(s.edits.map(k))===JSON.stringify(r.edits)&&window.localStorage.removeItem(o)}catch{}}var ve={edits:[]};function be(e,t,n,r,o){let[a]=U(()=>function(e,t){let n={};return t.options.forEach((r,o)=>{try{let r=window.localStorage.getItem(me(e,t.id,o));if(!r)return;let a=JSON.parse(r),{revision:i,edits:s}=Array.isArray(a)?{revision:0,edits:a}:a;if(!Number.isSafeInteger(i)||i<0||!Array.isArray(s))return;let l=s.map(k);if(l.some(e=>e.batchId!==t.id||e.option!==o))return;b({messages:[{batch:t}]},x(l)),n[o]={revision:i,edits:l}}catch{}}),n}(e,t)),[i,s]=U(()=>({...n,...a})),l=X(i),p=X({...n}),d=X({...a}),c=X(new Set),u=X(new Map),[h,m]=U({}),[g,f]=U(""),v=o&&void 0!==n;function y(e,t,n){let r=l.current[e]??ve;l.current={...l.current,[e]:t},JSON.stringify(r.edits)!==JSON.stringify(t.edits)&&(s(l.current),n&&m(t=>({...t,[e]:(t[e]??0)+1})))}async function w(n){if(v&&!c.current.has(n)){c.current.add(n);try{for(;d.current[n];){let o=d.current[n],a=await A(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({batchId:t.id,option:n,...o})});if(!a.ok&&409!==a.status)throw Error();let{draft:i}=await a.json();if(!i||!Number.isSafeInteger(i.revision)||!Array.isArray(i.edits))throw Error();i.revision>=(p.current[n]?.revision??0)&&(p.current[n]=i);let s=d.current[n];409===a.status||s===o?(delete d.current[n],fe(e,t.id,n,s),y(n,p.current[n],!0),f(409===a.status?"This option changed on another device. Its latest saved edits are shown.":"")):(s.revision=i.revision,ge(e,t.id,n,s.edits,s.revision))}}catch{f("Couldn’t sync option edits to this project.")}finally{c.current.delete(n)}}}let C=()=>Object.keys(d.current).forEach(e=>{w(Number(e))}),E=X(C);return q(()=>{E.current=C}),q(()=>{if(n)for(let[e,t]of Object.entries(n)){let n=Number(e);t.revision<(p.current[n]?.revision??0)||(p.current[n]=t,d.current[n]||y(n,t,!0))}},[n]),Z(()=>{if(!v)return;let e=()=>E.current();e(),window.addEventListener("online",e);let t=u.current;return()=>{window.removeEventListener("online",e);for(let e of t.values())clearTimeout(e);t.clear(),e()}},[v]),{edits:Y(()=>Object.values(i).flatMap(e=>e.edits),[i]),save:function(n,r){let o=d.current[n]?.revision??p.current[n]?.revision??0,a={revision:o,edits:r.map(k)};JSON.stringify(l.current[n]?.edits??[])!==JSON.stringify(a.edits)&&(d.current[n]=a,ge(e,t.id,n,a.edits,o),y(n,a,!1),v&&(clearTimeout(u.current.get(n)),u.current.set(n,setTimeout(()=>{u.current.delete(n),w(n)},220))))},revisions:h,failure:g,retry:C,unsynced:!!Object.keys(d.current).length}}function xe({batch:n,draftScope:r,threadId:o,sharedDrafts:a,bridgeUrl:i,theme:c,accentColor:u,active:h,hidden:m,revealOnPage:g,activate:f,expanded:k,onExpand:C,canReply:E,submit:I,selection:P,onAttach:O,focusRequest:T,workspaceRef:N,followSource:j}){let A=e(i,v(n)),M=K(S),R=M?.preview?.batchId===n.id&&M.preview.threadId===o?M.preview:null,z=M?!!R?.enabled:h,[B,L]=U(()=>R?.index??0),D=X(null);q(()=>{D.current!==T&&(D.current=T,T&&T.batchId===n.id&&n.options[T.option]&&L(T.option))},[T,n.id,n.options]);let H=Y(()=>T?{...T,part:""}:null,[T]),J=be(r,n,a,i+"/thread/"+encodeURIComponent(o)+"/explore-draft",E),[V,W]=U(),Z=T!==V&&T?.option===B?T.snapshot:void 0,F=Z?.edits??J.edits,[G]=U(()=>d(null)),ee=Y(()=>k&&!m&&!Z&&B>=0?{batchId:n.id,option:B}:null,[k,m,Z,n.id,B]),[te,ne]=U(R?.targets??null),[re,oe]=U(()=>R&&"fixture"in R.option?{[R.option.fixture.bundle]:R.hasCanvas}:{}),[ae,ie]=U(""),[se,le]=U(null),pe=Y(()=>b({messages:[{batch:n}]},x(F)).messages[0].batch,[n,F]);q(()=>{if(!ee)return;let e={source:ee,framing:G,reference:()=>l(pe,{...ee,path:[]},F)};return N.current=e,()=>{N.current===e&&(N.current=null)}},[N,ee,G,pe,F]),q(()=>{let e=N.current;if(!e||e.source!==j)return;let t=n.options.findIndex((t,r)=>{let o=n.parents?.[r];return o?.batchId===e.source.batchId&&o.option===e.source.option&&(!("fixture"in t)||"object"==typeof A[t.fixture.bundle])});t<0||(G.restore(e.framing.snapshot()),L(t),C(!0))},[n,A,j,G,C,N]);let de=pe.options[Math.max(0,B)],ce=e=>"fixture"in de?w(e,de.previewScope,!!re[de.fixture.bundle]):e.element,he=B>=0&&te&&ce(te),me="fixture"in de&&"component"===de.previewScope?"Core could not locate a single root for this component on the page. You can still review the option here.":"Open the annotated page with its target visible to preview this option.",ge="fixture"in de?A[de.fixture.bundle]??(R&&"fixture"in R.option&&R.option.fixture.bundle===de.fixture.bundle?R.bundle:void 0):void 0,fe=Y(()=>{let e=x(F)[n.id]?.[B]??{},t={...e};if(se?.option===B)for(let[n,r]of Object.entries(se.parts))t[n]={...e[n],...r};return t},[F,n.id,B,se]),ve="fixture"in de&&!!re[de.fixture.bundle],xe=Y(()=>te?{threadId:o,batchId:n.id,index:B,enabled:!0,target:n.target,option:de,targets:te,hasCanvas:ve,bundle:"string"==typeof ge?void 0:ge,parts:fe,theme:c,accentColor:u,revealOnPage:g}:null,[o,n.id,n.target,B,de,te,ve,ge,fe,c,u,g]),ye=!!R,we=M?.setPreview;q(()=>{Z||!ye||!xe||!we||we(e=>e?.batchId===n.id&&e.threadId===o?{...xe,enabled:e.enabled,suspended:e.suspended}:e)},[Z,ye,xe,we,n.id,o]);let ke=()=>{we?.(e=>e?.batchId===n.id&&e.threadId===o?{...e,enabled:!1}:e),f(!1)},Ce=z?{target:{batchId:n.id,option:B,path:[]},showVariant:B>=0}:null,Ee=n.parents?.[B];return Q($,{children:[_(ue,{batch:pe,framing:G,bundles:A,index:B,edits:F,theme:c,accentColor:u,selection:P,preview:Ce,expanded:k&&!m,onExpand:C,revisions:J.revisions,focusRequest:H,hoveredTarget:null,busy:!1,canApply:E&&!Z,frozenVersion:Z?T?.returnTo:void 0,onTogglePreview:()=>{if(ie(""),Ce&&!k)return void ke();let e=y(n.target),t=location.pathname===n.target.pathname&&ce(e);t&&t.parentElement&&!t.matches("body,html")&&!t.closest("[data-devtools]")?(ne(e),we?.({threadId:o,batchId:n.id,index:B,enabled:!0,target:n.target,option:de,targets:e,hasCanvas:ve,bundle:"string"==typeof ge?void 0:ge,parts:fe,theme:c,accentColor:u,revealOnPage:g}),C(!1),f(!0)):ie(me)},onBrowse:e=>{W(T),L(e.option),le(null)},onFixtureCanvas:(e,t)=>oe(n=>n[e]===t?n:{...n,[e]:t}),onPreviewStyle:(e,t)=>le(n=>t?{option:e,parts:t}:n?.option===e?null:n),onSteer:(e,t)=>{if(Z)return;let r=t.map(t=>({...t,batchId:n.id,option:e}));J.save(e,r)},setTag:e=>{E&&!Z&&O(l(pe,e,F))},onApply:async(e,t)=>{let{text:n,meta:r}=s(pe,e.option,F);if(!await I(n,t?{...r,exploreOption:{...r.exploreOption,selection:{...r.exploreOption.selection,reviewedImage:{replyImageIndex:0,capturedAt:Date.now(),description:"The attached image shows this reviewed option with its saved edits. Use it as the visual target to apply; the original annotation screenshot is earlier context."}}}}:r,t?[t]:void 0))throw Error("This thread cannot send the apply request.");ke(),C(!1)}}),Z&&T?.returnTo?Q("span",{children:["Parent version ·"," ",_(p,{reference:T.returnTo,children:"Back to iteration"})]}):Ee?Q("span",{children:["Based on"," ",_(p,{reference:{...Ee,snapshot:Ee,returnTo:{batchId:n.id,option:B,title:de.title}},showVersion:!0})]}):null,J.failure&&Q("span",{role:"alert",children:[J.failure," ",J.unsynced&&_("button",{type:"button",onClick:J.retry,children:"Retry"})]}),(ae||z&&B>=0&&!m&&te&&!he)&&_("span",{role:"alert",children:ae||me}),!M&&!Z&&z&&!m&&xe&&_(t,{preview:xe})]})}export{xe as ExploreAttachment};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use client";export{f as PagePreviewLayer}from"./chunk-ZQMKLODZ.mjs";import"./chunk-QYNW5LE2.mjs";import"./chunk-AWWUJO3N.mjs";import"./chunk-Q6N77LIS.mjs";import"./chunk-FHCKFQBY.mjs";import"./chunk-APP5IYTE.mjs";import"./chunk-TMSGNHXH.mjs";import"./chunk-53SKVMWR.mjs";import"./chunk-5IZHN3A7.mjs";import"./chunk-AOTDTBQO.mjs";import"./chunk-WP2SHSCG.mjs";import"./chunk-LH7HKUCK.mjs";import"./chunk-ZVDKW7TO.mjs";import"./chunk-Q6C7ZA3H.mjs";import"./chunk-7D4BUDKG.mjs";import"./chunk-OEJXPUAR.mjs";import"./chunk-HM6EBJVO.mjs";import"./chunk-SUAHDXJZ.mjs";import"./chunk-YGP6PPOZ.mjs";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use client";import{d as t,b as e,c as o,a as r}from"./chunk-KN4GC34I.mjs";import"./chunk-UFU5IA3G.mjs";import"./chunk-V7AOJQXQ.mjs";import{f as i}from"./chunk-32TDB3N4.mjs";import"./chunk-RXC7B7SX.mjs";import"./chunk-KUILFVXZ.mjs";import"./chunk-XVQAHYF2.mjs";import"./chunk-SOGN7S54.mjs";import"./chunk-6DU4ITXT.mjs";import"./chunk-REPKQAJK.mjs";import"./chunk-B4RLDY5H.mjs";import"./chunk-PH2MLB3T.mjs";import"./chunk-DBCCE7BA.mjs";import"./chunk-XTOCFTVW.mjs";import"./chunk-EHM2ZBQU.mjs";import{a as n}from"./chunk-ECWY6Z6K.mjs";import{i as a,Y as s}from"./chunk-WKQGWQ3P.mjs";import"./chunk-4EDMISUV.mjs";import"./chunk-TMSGNHXH.mjs";import"./chunk-RAABZFBD.mjs";import"./chunk-G2ZHJXHZ.mjs";import"./chunk-53SKVMWR.mjs";import"./chunk-YTIDSDPP.mjs";import"./chunk-VLTK7KWK.mjs";import"./chunk-5IZHN3A7.mjs";import"./chunk-Q5MIJ5F2.mjs";import"./chunk-RK6UROPO.mjs";import"./chunk-AOTDTBQO.mjs";import"./chunk-2F2BVGFH.mjs";import"./chunk-RWZ7SVMO.mjs";import"./chunk-HAZXZ5TU.mjs";import"./chunk-KF35YUNZ.mjs";import"./chunk-VBH2YQLG.mjs";import"./chunk-VXRRHXUP.mjs";import"./chunk-WP2SHSCG.mjs";import{e as c,g as l,f as p}from"./chunk-AAMUU2QA.mjs";import"./chunk-LH7HKUCK.mjs";import{a as m}from"./chunk-HVDJYNQ6.mjs";import{b as h,f as u,c as d,d as f}from"./chunk-5TCWBNV4.mjs";import{p as j}from"./chunk-AKEVJPGD.mjs";import"./chunk-X6I6KQDG.mjs";import"./chunk-ATLUO4G7.mjs";import"./chunk-2FHGLE7G.mjs";import"./chunk-C2ZSNUXQ.mjs";import"./chunk-N37INB4D.mjs";import"./chunk-FR6VIGJ2.mjs";import"./chunk-EILBHZDX.mjs";import"./chunk-ZVDKW7TO.mjs";import"./chunk-HQVWOBYH.mjs";import"./chunk-Q6C7ZA3H.mjs";import"./chunk-OREALBUO.mjs";import"./chunk-CK3CDA3L.mjs";import{c as k,a as g}from"./chunk-7D4BUDKG.mjs";import"./chunk-B4DYUYX4.mjs";import"./chunk-OEJXPUAR.mjs";import"./chunk-HM6EBJVO.mjs";import{U as w}from"./chunk-OA63PYHZ.mjs";import"./chunk-ADRWR5GI.mjs";import{b as y}from"./chunk-SUAHDXJZ.mjs";import"./chunk-PRPXMDZ7.mjs";import"./chunk-A4GARXVQ.mjs";import"./chunk-YGP6PPOZ.mjs";import{useState as S,useSyncExternalStore as v,useEffect as I}from"react";import{jsx as P,jsxs as A}from"react/jsx-runtime";function H(t,i){let n,a={phase:"starting"},m=0,j=!1,k=!1,g=0,w=new Set,S=`popmelt-participant:${t.projectId}`,v=new h(t.url,t.projectId),I=t=>{if(!k){a=t;for(let t of w)t()}},P=()=>history.state?.popmeltGuestEntry===t.projectId,A=e=>history.replaceState({...history.state,popmeltGuestEntry:t.projectId},"",e),H=t=>fetch("/__popmelt/host",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify(t),redirect:"error"}),O=async(e={},o=!1,r)=>{if(y(t.url))return null;let i=await H(e);if(403===i.status){let e=i.headers.get("X-Popmelt-Host-Origin"),n=i.headers.get("X-Popmelt-Session"),a=new URL(location.href);if(!o||!n||window.top!==window||!["localhost","127.0.0.1","[::1]"].includes(a.hostname)||a.pathname.startsWith("/__popmelt/")||a.searchParams.has("__popmelt_code_preview")||a.hash.includes("popmelt-")||P())return null;let s=localStorage.getItem(`popmelt-admission:${t.projectId}`);if(s)try{if(JSON.parse(s)?.receipt)return null}catch{return null}if(e&&function(t,e){try{let o=new URL(t),r=new URL(e),i=["localhost","127.0.0.1","[::1]"];return o.origin===t&&r.origin===e&&t!==e&&["http:","https:"].includes(o.protocol)&&o.protocol===r.protocol&&o.port===r.port&&i.includes(o.hostname)&&i.includes(r.hostname)}catch{return!1}}(location.origin,e)){let t=await fetch(e+"/__popmelt/host",{method:"HEAD",credentials:"omit",redirect:"error",referrerPolicy:"no-referrer",signal:AbortSignal.timeout(2e3)}).catch(()=>null);if(!k&&204===t?.status&&t.headers.get("X-Popmelt-Session")===n)throw a.host=new URL(e).host,location.replace(a.href),U;return null}let c=i.headers.get("X-Popmelt-Local-Port");if(!c||!/^[1-9]\d{0,4}$/.test(c)||Number(c)>65535)return null;let l=await fetch("http://127.0.0.1:"+c+"/",{method:"POST",headers:{"X-Popmelt-Session":n},credentials:"omit",cache:"no-store",redirect:"error",referrerPolicy:"no-referrer",signal:AbortSignal.timeout(6500)}).catch(()=>null);if(!l?.ok||k)return null;let p=await l.json().catch(()=>null);if("string"!=typeof p?.proof||(i=await H({localProof:p.proof,previousId:r}),403===i.status))return null}if(!i.ok)throw new Error(`Host entry unavailable (${i.status}).`);let n=`popmelt-before-participants:${t.projectId}`;return null===localStorage.getItem(n)&&localStorage.setItem(n,JSON.stringify(Object.fromEntries(Object.values(s(t.projectId)).map(t=>[t,localStorage.getItem(t)])))),await i.json()},U=Symbol("navigating"),b=async(a,s=g)=>{if(k||s!==g)return;let m=await r({bridgeUrl:t.url,projectId:t.projectId,credential:a,runtimeStorage:sessionStorage,observedSource:{sourceId:t.projectId,revision:t.revision},loadOwnSource:i,prepareApplication:t.planeApps?async r=>{if(k||s!==g)throw U;let i=c(location.pathname);if(r.author.id===a.participantId&&"host"===r.author.relationship&&!y(t.url)){if("/"!==i){let t=new URL(location.href);throw t.pathname=p(t.pathname),location.replace(t.href),U}return("/"===r.ownWorkspace?.basePath?r.ownWorkspace.revision:void 0)??r.draft.source?.revision??t.revision}let n=await e(a,a.participantId,void 0,location.pathname);if(k||s!==g)throw U;let m=o(n.application);if(t.appVersion??(t.appVersion=n.application.version),m!==l(location.pathname)||t.appVersion&&t.appVersion!==n.application.version)throw localStorage.setItem(S,JSON.stringify(a)),location.replace(m+location.search+location.hash),U;return n.application.basis??t.revision}:void 0}).catch(t=>{if(t!==U)throw t});if(m){if(k||s!==g)return void m.dispose();try{localStorage.setItem(S,JSON.stringify(a))}catch(t){throw m.dispose(),t}if(n?.dispose(),P()){let t={...history.state};delete t.popmeltGuestEntry,history.replaceState(t,"")}n=m,I({phase:"connected",connection:m}),O({credential:a}).catch(()=>{})}},R=()=>{A(location.href),g++,n?.dispose(),n=void 0,function(t,e){t.removeItem(`popmelt-participant:${e}`);let o,r=`popmelt-admission:${e}`;try{o=JSON.parse(t.getItem(r)??"null")}catch{return void t.removeItem(r)}o&&"object"==typeof o&&t.setItem(r,JSON.stringify({name:o.name,colorIdentity:o.colorIdentity??o.receipt}))}(localStorage,t.projectId),I({phase:"entry",invitation:null})};return{client:v,getSnapshot:()=>a,subscribe:t=>(w.add(t),()=>{w.delete(t)}),retain(){if(k)throw new Error("Participant lifecycle is disposed");m++,j||(j=!0,(async()=>{let t=u(location.href),e=new URL(t.cleanUrl),o=new URLSearchParams(e.hash.slice(1)),r=o.get("popmelt-host");o.delete("popmelt-host"),r&&(e.hash=o.toString()),t.token?A(e.href):e.href!==location.href&&history.replaceState(history.state,"",e);let i=null;if(r){if(i=await O({token:r}),!i&&!t.token&&(i=await O({},!0)),!i)throw new Error("Host entry expired. Use the current private host link.")}else if(!t.token&&!P()){try{i=JSON.parse(localStorage.getItem(S)??"null")}catch{}i??(i=await O({},!0))}if(k)return;if(!i)return void I({phase:"entry",invitation:t.token??null});let n=g;for(let e=1;!k&&n===g;e++)try{return void await b(i,n)}catch(o){if(k||n!==g)return;if(d(o)){I({phase:"error",message:o.message}),await new Promise(t=>setTimeout(t,f(e)));continue}if("access_removed"===o.code)return void R();if(401!==o.status)throw o;let a=await O({},!r&&!t.token,i.participantId);return void(a?await b(a):R())}})().catch(t=>{t!==U&&I({phase:"error",message:t.message})}));let t=!1;return()=>{t||(t=!0,m--,queueMicrotask(()=>{m||k||(k=!0,g++,n?.dispose(),n=void 0,w.clear())}))}},removed:R,async join(e,o){if("entry"!==a.phase||!a.invitation||k)throw new Error("No active invitation");if(!o)throw new Error("Peer identity is not ready");let r=g,i=await v.joinOrRequestAdmission(a.invitation,e,o);if(!k&&r===g){if("admission"in i)return localStorage.setItem(`popmelt-admission:${t.projectId}`,JSON.stringify({name:i.admission.name,receipt:o,colorIdentity:o})),void I({phase:"entry",invitation:null});await b(i.joined.credential,r)}},admit:t=>b(t)}}function O({config:r,loadOwnSource:s,children:p}){let[h]=S(()=>H(r,s)),u=a(),d=v(h.subscribe,h.getSnapshot,h.getSnapshot);I(()=>h.retain(),[h]);let[f,O,U]=k(),b="connected"===d.phase?d.connection:null;if(I(()=>{if(!b||!r.planeApps)return;let t,i=new AbortController,n=b.isHost&&!y(r.url)&&"/"===c(location.pathname),a=n?void 0:r.appVersion,s=async()=>{try{let t=await e(b.credential,b.credential.participantId,i.signal,location.pathname);if(n&&"/"!==t.application.basePath)throw new Error("Host checkout unavailable");let s=o(t.application);if(a??(a=t.application.version),!i.signal.aborted&&(s!==l(location.pathname)||t.application.version!==a)){if(b.isHost&&!y(r.url)){let t=await fetch(s+location.search,{method:"HEAD",headers:{Accept:"text/html"},mode:"same-origin",cache:"no-store",signal:i.signal});if(!t.ok||!t.headers.get("content-type")?.includes("text/html")||l(new URL(t.url).pathname)!==s)throw new Error("Host plane document unavailable")}return await b.state.flush(),void(i.signal.aborted||(s===l(location.pathname)?location.reload():location.replace(s+location.search+location.hash)))}}catch{}i.signal.aborted||(t=setTimeout(s,1500))};return s(),()=>{i.abort(),clearTimeout(t)}},[r.planeApps,r.appVersion,r.url,b,u]),b)return P(t,{connection:b,codePreviewUrl:location.href,planeApps:r.planeApps,onAccessRemoved:h.removed,children:p});let R="starting"===d.phase||"error"===d.phase,D="entry"===d.phase?d.invitation:null;return P(n,{children:P("div",{"data-devtools":"participant-entry",style:{display:"contents",pointerEvents:"auto"},children:R?P(i,{entry:{theme:f,themePreference:U,onThemePreferenceChange:O,ariaLabel:"starting"===d.phase?"Popmelt connecting":"Popmelt disconnected",action:null,logoOnly:!0,connected:!1,connection:A("span",{"data-popmelt-entry-content":!0,role:"status",style:{...j(g[f],!1),cursor:"default"},children:[P(w,{size:14,strokeWidth:1.5,"aria-hidden":"true"}),"starting"===d.phase?"Connecting…":"Disconnected"]})}}):P(m,{showHostLinkHelp:window.top===window&&["localhost","127.0.0.1","[::1]"].includes(location.hostname)&&!y(r.url)&&"/"===c(location.pathname),client:h.client,storage:localStorage,storageKey:`popmelt-admission:${r.projectId}`,theme:f,themePreference:U,onThemePreferenceChange:O,onAdmitted:h.admit,onJoin:D?h.join:void 0},D??"request-access")})})}export{O as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use client";import{a as r,d as t}from"./chunk-KN4GC34I.mjs";import"./chunk-UFU5IA3G.mjs";import"./chunk-V7AOJQXQ.mjs";import"./chunk-XVQAHYF2.mjs";import"./chunk-SOGN7S54.mjs";import"./chunk-DBCCE7BA.mjs";import"./chunk-EHM2ZBQU.mjs";import"./chunk-WKQGWQ3P.mjs";import"./chunk-4EDMISUV.mjs";import"./chunk-TMSGNHXH.mjs";import"./chunk-RAABZFBD.mjs";import"./chunk-G2ZHJXHZ.mjs";import"./chunk-53SKVMWR.mjs";import"./chunk-YTIDSDPP.mjs";import"./chunk-VLTK7KWK.mjs";import"./chunk-5IZHN3A7.mjs";import"./chunk-Q5MIJ5F2.mjs";import"./chunk-RK6UROPO.mjs";import"./chunk-AOTDTBQO.mjs";import"./chunk-2F2BVGFH.mjs";import"./chunk-RWZ7SVMO.mjs";import"./chunk-HAZXZ5TU.mjs";import"./chunk-KF35YUNZ.mjs";import"./chunk-VBH2YQLG.mjs";import"./chunk-VXRRHXUP.mjs";import"./chunk-WP2SHSCG.mjs";import"./chunk-AAMUU2QA.mjs";import"./chunk-LH7HKUCK.mjs";import"./chunk-5TCWBNV4.mjs";import"./chunk-EILBHZDX.mjs";import"./chunk-ZVDKW7TO.mjs";import"./chunk-HQVWOBYH.mjs";import"./chunk-Q6C7ZA3H.mjs";import"./chunk-OREALBUO.mjs";import"./chunk-CK3CDA3L.mjs";import"./chunk-7D4BUDKG.mjs";import"./chunk-B4DYUYX4.mjs";import{b as o}from"./chunk-OEJXPUAR.mjs";import{d as n,f as i,c as m,a as e}from"./chunk-HM6EBJVO.mjs";import"./chunk-OA63PYHZ.mjs";import"./chunk-ADRWR5GI.mjs";import"./chunk-SUAHDXJZ.mjs";import"./chunk-PRPXMDZ7.mjs";import"./chunk-YGP6PPOZ.mjs";import{useState as c,useEffect as s,cloneElement as p}from"react";import{jsxs as h,jsx as u}from"react/jsx-runtime";function j({children:j,projectId:k,participantConfig:a}){let[l,d]=c(null),[H,I]=c("");if(s(()=>{let t,m,c=!1;return d(null),I(""),n(k).then(async n=>{if(c)return;let s=location.origin+e;m=i(s,n);let p=await o(s+"/status",{signal:AbortSignal.timeout(6e3)}),h=p.ok?await p.json():null;if(h?.projectId!==n.projectId)throw new Error("Phone access expired. Create a fresh pairing link in the project terminal.");if(!c){if(h.phoneParticipantId)t=await r({projectId:n.projectId,bridgeUrl:s,credential:{participantId:h.phoneParticipantId,token:""},runtimeStorage:sessionStorage,observedSource:{sourceId:n.projectId,revision:a?.revision??"unversioned"}});else if(a)throw new Error("This phone is not connected to the multiplayer host.");c?t?.dispose():d({bridgeUrl:s,projectId:n.projectId,connection:t})}}).catch(r=>{m?.(),c||I(r instanceof Error?r.message:"Phone pairing failed.")}),()=>{c=!0,t?.dispose(),m?.()}},[k,a]),H)return h("p",{role:"alert","data-devtools":"phone-pairing-error",children:[H," ",u("button",{type:"button",onClick:m,children:"Forget this pairing"})]});if(!l)return null;let A=p(j,{bridgeUrl:l.bridgeUrl,projectId:l.projectId});return l.connection?u(t,{connection:l.connection,onAccessRemoved:m,children:A}):A}export{j as PhoneHostGate};
|