@adminide-stack/yantra-mobile 12.0.171-alpha.0 → 12.0.172-alpha.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 (90) hide show
  1. package/lib/compute.js +51 -1
  2. package/lib/compute.js.map +1 -1
  3. package/lib/features/apps/AppsCatalog.js +10 -0
  4. package/lib/features/apps/AppsCatalog.js.map +1 -1
  5. package/lib/features/apps/mobileAppCatalog.js +9 -0
  6. package/lib/features/apps/mobileAppCatalog.js.map +1 -1
  7. package/lib/features/apps/nativeSurfaceTwin.js +2 -1
  8. package/lib/features/apps/nativeSurfaceTwin.js.map +1 -1
  9. package/lib/features/canvas/set/agent/prompt.js +4 -5
  10. package/lib/features/canvas/set/agent/prompt.js.map +1 -1
  11. package/lib/features/canvas/set/supplyLibrary.js +1294 -2
  12. package/lib/features/canvas/set/supplyLibrary.js.map +1 -1
  13. package/lib/features/games/cubeforge3D.js +26 -0
  14. package/lib/features/games/cubeforge3D.js.map +1 -0
  15. package/lib/features/games/vendored/core/classroom/permissions.js +76 -0
  16. package/lib/features/games/vendored/core/classroom/permissions.js.map +1 -0
  17. package/lib/features/games/vendored/core/classroom/resourceLink.js +101 -0
  18. package/lib/features/games/vendored/core/classroom/resourceLink.js.map +1 -0
  19. package/lib/features/games/vendored/core/classroom/rules.js +83 -0
  20. package/lib/features/games/vendored/core/classroom/rules.js.map +1 -0
  21. package/lib/features/games/vendored/core/classroom/worldSettings.js +49 -0
  22. package/lib/features/games/vendored/core/classroom/worldSettings.js.map +1 -0
  23. package/lib/features/games/vendored/core/cubeforge/cycle.js +15 -0
  24. package/lib/features/games/vendored/core/cubeforge/cycle.js.map +1 -0
  25. package/lib/features/games/vendored/core/cubeforge/inventory.js +75 -0
  26. package/lib/features/games/vendored/core/cubeforge/inventory.js.map +1 -0
  27. package/lib/features/games/vendored/core/cubeforge/items.js +62 -0
  28. package/lib/features/games/vendored/core/cubeforge/items.js.map +1 -0
  29. package/lib/features/games/vendored/core/cubeforge/nativeWorld.js +4 -0
  30. package/lib/features/games/vendored/core/cubeforge/nativeWorld.js.map +1 -0
  31. package/lib/features/games/vendored/core/cubeforge/recipes.js +52 -0
  32. package/lib/features/games/vendored/core/cubeforge/recipes.js.map +1 -0
  33. package/lib/features/games/vendored/core/cubeforge/save.js +92 -0
  34. package/lib/features/games/vendored/core/cubeforge/save.js.map +1 -0
  35. package/lib/features/games/vendored/core/cubeforge/session.js +154 -0
  36. package/lib/features/games/vendored/core/cubeforge/session.js.map +1 -0
  37. package/lib/features/games/vendored/core/cubeforge/worldgen.js +44 -0
  38. package/lib/features/games/vendored/core/cubeforge/worldgen.js.map +1 -0
  39. package/lib/features/games/vendored/core/engine/iso.js +41 -0
  40. package/lib/features/games/vendored/core/engine/iso.js.map +1 -0
  41. package/lib/features/games/vendored/core/engine/palette.js +53 -0
  42. package/lib/features/games/vendored/core/engine/palette.js.map +1 -0
  43. package/lib/features/games/vendored/core/engine/world.js +148 -0
  44. package/lib/features/games/vendored/core/engine/world.js.map +1 -0
  45. package/lib/features/games/vendored/core/games/catalog.js +34 -0
  46. package/lib/features/games/vendored/core/games/catalog.js.map +1 -0
  47. package/lib/features/games/vendored/core/lessons/lessons.js +97 -0
  48. package/lib/features/games/vendored/core/lessons/lessons.js.map +1 -0
  49. package/lib/features/games/vendored/core/logging/events.js +24 -0
  50. package/lib/features/games/vendored/core/logging/events.js.map +1 -0
  51. package/lib/features/games/vendored/core/logging/logger.js +54 -0
  52. package/lib/features/games/vendored/core/logging/logger.js.map +1 -0
  53. package/lib/features/games/vendored/core/session/gameSession.js +317 -0
  54. package/lib/features/games/vendored/core/session/gameSession.js.map +1 -0
  55. package/lib/features/games/vendored/core/storage/worldRepository.js +192 -0
  56. package/lib/features/games/vendored/core/storage/worldRepository.js.map +1 -0
  57. package/lib/features/games/vendored/core/store/reactive.js +78 -0
  58. package/lib/features/games/vendored/core/store/reactive.js.map +1 -0
  59. package/lib/features/games/vendored/ui/GamesRoot.js +159 -0
  60. package/lib/features/games/vendored/ui/GamesRoot.js.map +1 -0
  61. package/lib/features/games/vendored/ui/components/BlockPalette.js +64 -0
  62. package/lib/features/games/vendored/ui/components/BlockPalette.js.map +1 -0
  63. package/lib/features/games/vendored/ui/components/IsoCanvas.js +124 -0
  64. package/lib/features/games/vendored/ui/components/IsoCanvas.js.map +1 -0
  65. package/lib/features/games/vendored/ui/components/primitives.js +257 -0
  66. package/lib/features/games/vendored/ui/components/primitives.js.map +1 -0
  67. package/lib/features/games/vendored/ui/hooks/useReactiveQuery.js +3 -0
  68. package/lib/features/games/vendored/ui/hooks/useReactiveQuery.js.map +1 -0
  69. package/lib/features/games/vendored/ui/screens/ActivityScreen.js +68 -0
  70. package/lib/features/games/vendored/ui/screens/ActivityScreen.js.map +1 -0
  71. package/lib/features/games/vendored/ui/screens/BuilderScreen.js +227 -0
  72. package/lib/features/games/vendored/ui/screens/BuilderScreen.js.map +1 -0
  73. package/lib/features/games/vendored/ui/screens/ClassroomScreen.js +95 -0
  74. package/lib/features/games/vendored/ui/screens/ClassroomScreen.js.map +1 -0
  75. package/lib/features/games/vendored/ui/screens/CubeforgeScreen.js +342 -0
  76. package/lib/features/games/vendored/ui/screens/CubeforgeScreen.js.map +1 -0
  77. package/lib/features/games/vendored/ui/screens/HubScreen.js +131 -0
  78. package/lib/features/games/vendored/ui/screens/HubScreen.js.map +1 -0
  79. package/lib/features/games/vendored/ui/screens/ScreenHeader.js +51 -0
  80. package/lib/features/games/vendored/ui/screens/ScreenHeader.js.map +1 -0
  81. package/lib/features/games/vendored/ui/screens/WorldListScreen.js +134 -0
  82. package/lib/features/games/vendored/ui/screens/WorldListScreen.js.map +1 -0
  83. package/lib/features/games/vendored/ui/storage/asyncStorageAdapter.js +23 -0
  84. package/lib/features/games/vendored/ui/storage/asyncStorageAdapter.js.map +1 -0
  85. package/lib/features/games/vendored/ui/theme.js +53 -0
  86. package/lib/features/games/vendored/ui/theme.js.map +1 -0
  87. package/lib/routes.json +50 -0
  88. package/lib/screens/GamesNative/index.js +30 -0
  89. package/lib/screens/GamesNative/index.js.map +1 -0
  90. package/package.json +2 -2
@@ -0,0 +1,317 @@
1
+ import {ReactiveValue}from'../store/reactive.js';import {VoxelWorld,DEFAULT_BOUNDS}from'../engine/world.js';import {BLOCKS,EMPTY,isValidBlockId}from'../engine/palette.js';import {defaultWorldSettings}from'../classroom/worldSettings.js';import {applyRuleConstraints,setBooleanSetting}from'../classroom/rules.js';import {normalizeResourceLink,validateResourceLinkUrl}from'../classroom/resourceLink.js';import {defaultPermissionModel,effectiveCapabilities}from'../classroom/permissions.js';var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+ const UNDO_LIMIT = 100;
22
+ class GameSession {
23
+ constructor(init = {}) {
24
+ __publicField(this, "world");
25
+ __publicField(this, "settings");
26
+ __publicField(this, "permissions");
27
+ __publicField(this, "actingLevel");
28
+ __publicField(this, "selectedBlock");
29
+ __publicField(this, "undoStack", []);
30
+ __publicField(this, "state");
31
+ __publicField(this, "logger");
32
+ __publicField(this, "transport");
33
+ __publicField(this, "disposers", []);
34
+ var _a, _b, _c, _d, _e, _f;
35
+ this.world = init.world ? VoxelWorld.deserialize(init.world) : VoxelWorld.create(DEFAULT_BOUNDS);
36
+ this.settings = applyRuleConstraints((_a = init.settings) != null ? _a : defaultWorldSettings());
37
+ this.permissions = (_b = init.permissions) != null ? _b : defaultPermissionModel();
38
+ this.actingLevel = (_c = init.actingLevel) != null ? _c : "operator";
39
+ const firstBlock = (_e = (_d = BLOCKS[0]) == null ? void 0 : _d.id) != null ? _e : EMPTY;
40
+ this.selectedBlock = init.selectedBlock && isValidBlockId(init.selectedBlock) ? init.selectedBlock : firstBlock;
41
+ this.logger = init.logger;
42
+ this.transport = init.transport;
43
+ this.state = new ReactiveValue(this.snapshot());
44
+ (_f = this.logger) == null ? void 0 : _f.log({
45
+ type: "session.start",
46
+ worldId: init.worldId
47
+ });
48
+ if (this.transport) {
49
+ this.disposers.push(this.transport.subscribe((msg) => this.onRemote(msg)));
50
+ this.disposers.push(this.transport.peers.subscribe(() => this.publish()));
51
+ this.transport.send({
52
+ kind: "hello"
53
+ });
54
+ this.publish();
55
+ }
56
+ }
57
+ get query() {
58
+ return this.state;
59
+ }
60
+ getState() {
61
+ return this.state.get();
62
+ }
63
+ // --- block editing ---
64
+ selectBlock(block) {
65
+ if (!isValidBlockId(block) || this.selectedBlock === block) return;
66
+ this.selectedBlock = block;
67
+ this.publish();
68
+ }
69
+ placeBlock(x, y, z) {
70
+ var _a, _b;
71
+ if (!this.canEdit()) return false;
72
+ const op = {
73
+ t: "place",
74
+ x,
75
+ y,
76
+ z,
77
+ block: this.selectedBlock
78
+ };
79
+ if (!this.applyOp(op)) return false;
80
+ this.publish();
81
+ (_a = this.logger) == null ? void 0 : _a.log({
82
+ type: "block.place",
83
+ block: this.selectedBlock,
84
+ x,
85
+ y,
86
+ z
87
+ });
88
+ (_b = this.transport) == null ? void 0 : _b.send({
89
+ kind: "edit",
90
+ op
91
+ });
92
+ return true;
93
+ }
94
+ breakBlock(x, y, z) {
95
+ var _a, _b;
96
+ if (!this.canEdit()) return false;
97
+ const op = {
98
+ t: "break",
99
+ x,
100
+ y,
101
+ z
102
+ };
103
+ if (!this.applyOp(op)) return false;
104
+ this.publish();
105
+ (_a = this.logger) == null ? void 0 : _a.log({
106
+ type: "block.break",
107
+ x,
108
+ y,
109
+ z
110
+ });
111
+ (_b = this.transport) == null ? void 0 : _b.send({
112
+ kind: "edit",
113
+ op
114
+ });
115
+ return true;
116
+ }
117
+ undo() {
118
+ var _a, _b;
119
+ const previous = this.undoStack.pop();
120
+ if (!previous) return false;
121
+ this.world = VoxelWorld.deserialize(previous);
122
+ this.publish();
123
+ (_a = this.logger) == null ? void 0 : _a.log({
124
+ type: "world.undo"
125
+ });
126
+ (_b = this.transport) == null ? void 0 : _b.send({
127
+ kind: "snapshot",
128
+ world: this.world.serialize()
129
+ });
130
+ return true;
131
+ }
132
+ reset() {
133
+ var _a, _b;
134
+ const op = {
135
+ t: "reset"
136
+ };
137
+ if (!this.applyOp(op)) return;
138
+ this.publish();
139
+ (_a = this.logger) == null ? void 0 : _a.log({
140
+ type: "world.reset"
141
+ });
142
+ (_b = this.transport) == null ? void 0 : _b.send({
143
+ kind: "edit",
144
+ op
145
+ });
146
+ }
147
+ /** Leave multiplayer and release subscriptions. Safe to call once. */
148
+ dispose() {
149
+ var _a;
150
+ for (const off of this.disposers.splice(0)) off();
151
+ (_a = this.transport) == null ? void 0 : _a.close();
152
+ }
153
+ // --- acting player (teacher can preview as a given level) ---
154
+ setActingLevel(level) {
155
+ if (this.actingLevel === level) return;
156
+ this.actingLevel = level;
157
+ this.publish();
158
+ }
159
+ // --- classroom settings ---
160
+ setBooleanSetting(key, value) {
161
+ var _a;
162
+ const next = setBooleanSetting(this.settings, key, value);
163
+ if (next === this.settings) return;
164
+ this.settings = next;
165
+ this.publish();
166
+ (_a = this.logger) == null ? void 0 : _a.log({
167
+ type: "setting.change",
168
+ key,
169
+ value: next[key]
170
+ });
171
+ }
172
+ setResourceLink(link) {
173
+ var _a;
174
+ const normalized = normalizeResourceLink(link);
175
+ this.settings = __spreadProps(__spreadValues({}, this.settings), {
176
+ resourceLink: normalized
177
+ });
178
+ this.publish();
179
+ (_a = this.logger) == null ? void 0 : _a.log({
180
+ type: "resourceLink.set",
181
+ hasUrl: normalized.url !== ""
182
+ });
183
+ }
184
+ /**
185
+ * Validate and "open" the teacher resource link. Returns the safe URL for the
186
+ * host app to navigate to, and logs the open. Returns ok:false if no valid
187
+ * link is set.
188
+ */
189
+ openResourceLink() {
190
+ var _a;
191
+ const validation = validateResourceLinkUrl(this.settings.resourceLink.url);
192
+ if (!validation.ok || validation.empty) return {
193
+ ok: false
194
+ };
195
+ let host = "";
196
+ try {
197
+ host = new URL(validation.url).host;
198
+ } catch (e) {
199
+ host = "";
200
+ }
201
+ (_a = this.logger) == null ? void 0 : _a.log({
202
+ type: "resourceLink.open",
203
+ host
204
+ });
205
+ return {
206
+ ok: true,
207
+ url: validation.url
208
+ };
209
+ }
210
+ setHostEnabled(enabled) {
211
+ var _a;
212
+ if (this.permissions.hostEnabled === enabled) return;
213
+ this.permissions = __spreadProps(__spreadValues({}, this.permissions), {
214
+ hostEnabled: enabled
215
+ });
216
+ this.publish();
217
+ (_a = this.logger) == null ? void 0 : _a.log({
218
+ type: "permission.change",
219
+ field: "hostEnabled",
220
+ value: enabled
221
+ });
222
+ }
223
+ setDefaultLevel(level) {
224
+ var _a;
225
+ if (this.permissions.defaultLevel === level) return;
226
+ this.permissions = __spreadProps(__spreadValues({}, this.permissions), {
227
+ defaultLevel: level
228
+ });
229
+ this.publish();
230
+ (_a = this.logger) == null ? void 0 : _a.log({
231
+ type: "permission.change",
232
+ field: "defaultLevel",
233
+ value: level
234
+ });
235
+ }
236
+ // --- persistence helpers ---
237
+ exportWorld() {
238
+ return this.world.serialize();
239
+ }
240
+ exportSettings() {
241
+ return this.settings;
242
+ }
243
+ exportPermissions() {
244
+ return this.permissions;
245
+ }
246
+ // --- internals ---
247
+ canEdit() {
248
+ return effectiveCapabilities(this.actingLevel, this.settings).canBuild;
249
+ }
250
+ /** Apply a world op to the model (no permission gating). Returns true if it changed. */
251
+ applyOp(op) {
252
+ if (op.t === "reset") {
253
+ if (this.world.count() === 0) return false;
254
+ this.pushUndo();
255
+ this.world = VoxelWorld.create(this.world.bounds);
256
+ return true;
257
+ }
258
+ if (op.t === "place") {
259
+ this.pushUndo();
260
+ const result2 = this.world.place(op.x, op.y, op.z, op.block);
261
+ if (!result2.ok) {
262
+ this.undoStack.pop();
263
+ return false;
264
+ }
265
+ return true;
266
+ }
267
+ this.pushUndo();
268
+ const result = this.world.break(op.x, op.y, op.z);
269
+ if (!result.ok) {
270
+ this.undoStack.pop();
271
+ return false;
272
+ }
273
+ return true;
274
+ }
275
+ /** Handle a message from a peer. Remote edits apply without re-broadcasting. */
276
+ onRemote(message) {
277
+ var _a;
278
+ if (message.kind === "edit") {
279
+ if (this.applyOp(message.op)) this.publish();
280
+ return;
281
+ }
282
+ if (message.kind === "hello") {
283
+ if (this.world.count() > 0) {
284
+ (_a = this.transport) == null ? void 0 : _a.send({
285
+ kind: "snapshot",
286
+ world: this.world.serialize()
287
+ });
288
+ }
289
+ return;
290
+ }
291
+ if (this.world.count() === 0 && this.undoStack.length === 0) {
292
+ this.world = VoxelWorld.deserialize(message.world);
293
+ this.publish();
294
+ }
295
+ }
296
+ pushUndo() {
297
+ this.undoStack.push(this.world.serialize());
298
+ if (this.undoStack.length > UNDO_LIMIT) this.undoStack.shift();
299
+ }
300
+ publish() {
301
+ this.state.set(this.snapshot());
302
+ }
303
+ snapshot() {
304
+ return {
305
+ bounds: this.world.bounds,
306
+ blocks: this.world.drawOrder(),
307
+ blockCount: this.world.count(),
308
+ settings: this.settings,
309
+ permissions: this.permissions,
310
+ actingLevel: this.actingLevel,
311
+ selectedBlock: this.selectedBlock,
312
+ canEdit: this.canEdit(),
313
+ canUndo: this.undoStack.length > 0,
314
+ peers: this.transport ? this.transport.peers.get() : []
315
+ };
316
+ }
317
+ }export{GameSession};//# sourceMappingURL=gameSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gameSession.js","sources":["../../../../../../src/features/games/vendored/core/session/gameSession.ts"],"sourcesContent":["/**\n * The game session: the single source of truth for one open world.\n *\n * It owns the world, its settings, the permission model, and who is currently\n * acting, and it exposes a reactive read model plus commands. Every mutation is\n * gated by the enforced rules here, so a view can never place a block the rules\n * forbid - the UI reads `canEdit` from the same authority that rejects the write.\n */\n\nimport { ReactiveValue, type Query, type Unsubscribe } from '../store/reactive';\nimport { VoxelWorld, DEFAULT_BOUNDS, type PlacedBlock, type SerializedWorld, type WorldBounds } from '../engine/world';\nimport type { MultiplayerMessage, MultiplayerTransport, PlayerIdentity, WorldOp } from '../multiplayer/transport';\nimport { BLOCKS, EMPTY, isValidBlockId, type BlockId } from '../engine/palette';\nimport { defaultWorldSettings, type BooleanSettingKey, type WorldSettings } from '../classroom/worldSettings';\nimport { applyRuleConstraints, setBooleanSetting } from '../classroom/rules';\nimport { normalizeResourceLink, validateResourceLinkUrl, type ResourceLink } from '../classroom/resourceLink';\nimport {\n defaultPermissionModel,\n effectiveCapabilities,\n type PermissionLevel,\n type PermissionModel,\n} from '../classroom/permissions';\nimport type { GameLogger } from '../logging/logger';\n\nexport interface GameSessionState {\n readonly bounds: WorldBounds;\n /** Blocks, ordered back-to-front for rendering. */\n readonly blocks: readonly PlacedBlock[];\n readonly blockCount: number;\n readonly settings: WorldSettings;\n readonly permissions: PermissionModel;\n readonly actingLevel: PermissionLevel;\n readonly selectedBlock: BlockId;\n /** Whether the acting player may place/break blocks right now. */\n readonly canEdit: boolean;\n readonly canUndo: boolean;\n /** Players currently in the world (self + peers); empty when single-player. */\n readonly peers: readonly PlayerIdentity[];\n}\n\nexport interface GameSessionInit {\n world?: SerializedWorld;\n settings?: WorldSettings;\n permissions?: PermissionModel;\n actingLevel?: PermissionLevel;\n selectedBlock?: BlockId;\n /** Optional activity logger. Events carry no personal data. */\n logger?: GameLogger;\n /** Id of the persisted world, recorded in the session.start event. */\n worldId?: string;\n /** Optional live-multiplayer transport. When set, edits sync to peers. */\n transport?: MultiplayerTransport;\n}\n\nexport type OpenResourceLinkResult = { ok: true; url: string } | { ok: false };\n\nconst UNDO_LIMIT = 100;\n\nexport class GameSession {\n private world: VoxelWorld;\n private settings: WorldSettings;\n private permissions: PermissionModel;\n private actingLevel: PermissionLevel;\n private selectedBlock: BlockId;\n private readonly undoStack: SerializedWorld[] = [];\n private readonly state: ReactiveValue<GameSessionState>;\n private readonly logger?: GameLogger;\n private readonly transport?: MultiplayerTransport;\n private readonly disposers: Unsubscribe[] = [];\n\n constructor(init: GameSessionInit = {}) {\n this.world = init.world ? VoxelWorld.deserialize(init.world) : VoxelWorld.create(DEFAULT_BOUNDS);\n this.settings = applyRuleConstraints(init.settings ?? defaultWorldSettings());\n this.permissions = init.permissions ?? defaultPermissionModel();\n this.actingLevel = init.actingLevel ?? 'operator';\n const firstBlock = BLOCKS[0]?.id ?? EMPTY;\n this.selectedBlock = init.selectedBlock && isValidBlockId(init.selectedBlock) ? init.selectedBlock : firstBlock;\n this.logger = init.logger;\n this.transport = init.transport;\n this.state = new ReactiveValue<GameSessionState>(this.snapshot());\n this.logger?.log({ type: 'session.start', worldId: init.worldId });\n\n if (this.transport) {\n this.disposers.push(this.transport.subscribe((msg) => this.onRemote(msg)));\n this.disposers.push(this.transport.peers.subscribe(() => this.publish()));\n // Ask whoever is already here for the current world, then show as present.\n this.transport.send({ kind: 'hello' });\n this.publish();\n }\n }\n\n get query(): Query<GameSessionState> {\n return this.state;\n }\n\n getState(): GameSessionState {\n return this.state.get();\n }\n\n // --- block editing ---\n\n selectBlock(block: BlockId): void {\n if (!isValidBlockId(block) || this.selectedBlock === block) return;\n this.selectedBlock = block;\n this.publish();\n }\n\n placeBlock(x: number, y: number, z: number): boolean {\n if (!this.canEdit()) return false;\n const op: WorldOp = { t: 'place', x, y, z, block: this.selectedBlock };\n if (!this.applyOp(op)) return false;\n this.publish();\n this.logger?.log({ type: 'block.place', block: this.selectedBlock, x, y, z });\n this.transport?.send({ kind: 'edit', op });\n return true;\n }\n\n breakBlock(x: number, y: number, z: number): boolean {\n if (!this.canEdit()) return false;\n const op: WorldOp = { t: 'break', x, y, z };\n if (!this.applyOp(op)) return false;\n this.publish();\n this.logger?.log({ type: 'block.break', x, y, z });\n this.transport?.send({ kind: 'edit', op });\n return true;\n }\n\n undo(): boolean {\n const previous = this.undoStack.pop();\n if (!previous) return false;\n this.world = VoxelWorld.deserialize(previous);\n this.publish();\n this.logger?.log({ type: 'world.undo' });\n // Undo rewrites history, so realign peers with a snapshot.\n this.transport?.send({ kind: 'snapshot', world: this.world.serialize() });\n return true;\n }\n\n reset(): void {\n const op: WorldOp = { t: 'reset' };\n if (!this.applyOp(op)) return;\n this.publish();\n this.logger?.log({ type: 'world.reset' });\n this.transport?.send({ kind: 'edit', op });\n }\n\n /** Leave multiplayer and release subscriptions. Safe to call once. */\n dispose(): void {\n for (const off of this.disposers.splice(0)) off();\n this.transport?.close();\n }\n\n // --- acting player (teacher can preview as a given level) ---\n\n setActingLevel(level: PermissionLevel): void {\n if (this.actingLevel === level) return;\n this.actingLevel = level;\n this.publish();\n }\n\n // --- classroom settings ---\n\n setBooleanSetting(key: BooleanSettingKey, value: boolean): void {\n const next = setBooleanSetting(this.settings, key, value);\n if (next === this.settings) return;\n this.settings = next;\n this.publish();\n this.logger?.log({ type: 'setting.change', key, value: next[key] });\n }\n\n setResourceLink(link: ResourceLink): void {\n const normalized = normalizeResourceLink(link);\n this.settings = { ...this.settings, resourceLink: normalized };\n this.publish();\n this.logger?.log({ type: 'resourceLink.set', hasUrl: normalized.url !== '' });\n }\n\n /**\n * Validate and \"open\" the teacher resource link. Returns the safe URL for the\n * host app to navigate to, and logs the open. Returns ok:false if no valid\n * link is set.\n */\n openResourceLink(): OpenResourceLinkResult {\n const validation = validateResourceLinkUrl(this.settings.resourceLink.url);\n if (!validation.ok || validation.empty) return { ok: false };\n let host = '';\n try {\n host = new URL(validation.url).host;\n } catch {\n host = '';\n }\n this.logger?.log({ type: 'resourceLink.open', host });\n return { ok: true, url: validation.url };\n }\n\n setHostEnabled(enabled: boolean): void {\n if (this.permissions.hostEnabled === enabled) return;\n this.permissions = { ...this.permissions, hostEnabled: enabled };\n this.publish();\n this.logger?.log({ type: 'permission.change', field: 'hostEnabled', value: enabled });\n }\n\n setDefaultLevel(level: PermissionLevel): void {\n if (this.permissions.defaultLevel === level) return;\n this.permissions = { ...this.permissions, defaultLevel: level };\n this.publish();\n this.logger?.log({ type: 'permission.change', field: 'defaultLevel', value: level });\n }\n\n // --- persistence helpers ---\n\n exportWorld(): SerializedWorld {\n return this.world.serialize();\n }\n\n exportSettings(): WorldSettings {\n return this.settings;\n }\n\n exportPermissions(): PermissionModel {\n return this.permissions;\n }\n\n // --- internals ---\n\n private canEdit(): boolean {\n return effectiveCapabilities(this.actingLevel, this.settings).canBuild;\n }\n\n /** Apply a world op to the model (no permission gating). Returns true if it changed. */\n private applyOp(op: WorldOp): boolean {\n if (op.t === 'reset') {\n if (this.world.count() === 0) return false;\n this.pushUndo();\n this.world = VoxelWorld.create(this.world.bounds);\n return true;\n }\n if (op.t === 'place') {\n this.pushUndo();\n const result = this.world.place(op.x, op.y, op.z, op.block);\n if (!result.ok) {\n this.undoStack.pop();\n return false;\n }\n return true;\n }\n this.pushUndo();\n const result = this.world.break(op.x, op.y, op.z);\n if (!result.ok) {\n this.undoStack.pop();\n return false;\n }\n return true;\n }\n\n /** Handle a message from a peer. Remote edits apply without re-broadcasting. */\n private onRemote(message: MultiplayerMessage): void {\n if (message.kind === 'edit') {\n if (this.applyOp(message.op)) this.publish();\n return;\n }\n if (message.kind === 'hello') {\n if (this.world.count() > 0) {\n this.transport?.send({ kind: 'snapshot', world: this.world.serialize() });\n }\n return;\n }\n // snapshot: adopt only before any local edits, so we don't clobber our work.\n if (this.world.count() === 0 && this.undoStack.length === 0) {\n this.world = VoxelWorld.deserialize(message.world);\n this.publish();\n }\n }\n\n private pushUndo(): void {\n this.undoStack.push(this.world.serialize());\n if (this.undoStack.length > UNDO_LIMIT) this.undoStack.shift();\n }\n\n private publish(): void {\n this.state.set(this.snapshot());\n }\n\n private snapshot(): GameSessionState {\n return {\n bounds: this.world.bounds,\n blocks: this.world.drawOrder(),\n blockCount: this.world.count(),\n settings: this.settings,\n permissions: this.permissions,\n actingLevel: this.actingLevel,\n selectedBlock: this.selectedBlock,\n canEdit: this.canEdit(),\n canUndo: this.undoStack.length > 0,\n peers: this.transport ? this.transport.peers.get() : [],\n };\n }\n}\n"],"names":["result"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoDA,MAAM,UAAa,GAAA,GAAA;AACZ,MAAM,WAAY,CAAA;AAAA,EAWvB,WAAA,CAAY,IAAwB,GAAA,EAAI,EAAA;AAVxC,IAAQ,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA;AACR,IAAQ,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;AACR,IAAQ,aAAA,CAAA,IAAA,EAAA,aAAA,CAAA;AACR,IAAQ,aAAA,CAAA,IAAA,EAAA,aAAA,CAAA;AACR,IAAQ,aAAA,CAAA,IAAA,EAAA,eAAA,CAAA;AACR,IAAA,aAAA,CAAA,IAAA,EAAiB,aAA+B,EAAC,CAAA;AACjD,IAAiB,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA;AACjB,IAAiB,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AACjB,IAAiB,aAAA,CAAA,IAAA,EAAA,WAAA,CAAA;AACjB,IAAA,aAAA,CAAA,IAAA,EAAiB,aAA2B,EAAC,CAAA;AA/D/C,IAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AAiEI,IAAK,IAAA,CAAA,KAAA,GAAQ,IAAK,CAAA,KAAA,GAAQ,UAAW,CAAA,WAAA,CAAY,KAAK,KAAK,C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,EAAU,CAAA;AAAA;AAChC,EACQ,QAA6B,GAAA;AACnC,IAAO,OAAA;AAAA,MACL,MAAA,EAAQ,KAAK,KAAM,CAAA,MAAA;AAAA,MACnB,MAAA,EAAQ,IAAK,CAAA,KAAA,CAAM,SAAU,EAAA;AAAA,MAC7B,UAAA,EAAY,IAAK,CAAA,KAAA,CAAM,KAAM,EAAA;AAAA,MAC7B,UAAU,IAAK,CAAA,QAAA;AAAA,MACf,aAAa,IAAK,CAAA,WAAA;AAAA,MAClB,aAAa,IAAK,CAAA,WAAA;AAAA,MAClB,eAAe,IAAK,CAAA,aAAA;AAAA,MACpB,OAAA,EAAS,KAAK,OAAQ,EAAA;AAAA,MACtB,OAAA,EAAS,IAAK,CAAA,SAAA,CAAU,MAAS,GAAA,CAAA;AAAA,MACjC,KAAA,EAAO,KAAK,SAAY,GAAA,IAAA,CAAK,UAAU,KAAM,CAAA,GAAA,KAAQ;AAAC,KACxD;AAAA;AAEJ"}
@@ -0,0 +1,192 @@
1
+ import {defaultWorldSettings}from'../classroom/worldSettings.js';import {applyRuleConstraints}from'../classroom/rules.js';import {defaultPermissionModel}from'../classroom/permissions.js';import {VoxelWorld,DEFAULT_BOUNDS}from'../engine/world.js';var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ const STORAGE_VERSION = "v1";
21
+ const STORAGE_PREFIX = `yantra.games.${STORAGE_VERSION}`;
22
+ class WorldRepository {
23
+ constructor(storage, namespace, now = () => Date.now(), makeId = defaultMakeId) {
24
+ this.storage = storage;
25
+ this.namespace = namespace;
26
+ this.now = now;
27
+ this.makeId = makeId;
28
+ }
29
+ async list() {
30
+ const raw = await this.storage.getItem(this.indexKey());
31
+ const parsed = safeParse(raw);
32
+ if (!Array.isArray(parsed)) return [];
33
+ const out = [];
34
+ for (const entry of parsed) {
35
+ const summary = coerceSummary(entry);
36
+ if (summary) out.push(summary);
37
+ }
38
+ return out.sort((a, b) => b.updatedAt - a.updatedAt);
39
+ }
40
+ async load(id) {
41
+ const raw = await this.storage.getItem(this.worldKey(id));
42
+ const parsed = safeParse(raw);
43
+ if (!parsed || typeof parsed !== "object") return null;
44
+ return coerceRecord(parsed);
45
+ }
46
+ async create(name) {
47
+ const ts = this.now();
48
+ const record = {
49
+ id: this.makeId(),
50
+ name: cleanName(name),
51
+ createdAt: ts,
52
+ updatedAt: ts,
53
+ settings: defaultWorldSettings(),
54
+ permissions: defaultPermissionModel(),
55
+ world: VoxelWorld.create(DEFAULT_BOUNDS).serialize()
56
+ };
57
+ await this.save(record);
58
+ return record;
59
+ }
60
+ async save(record) {
61
+ const normalized = __spreadProps(__spreadValues({}, record), {
62
+ name: cleanName(record.name),
63
+ settings: applyRuleConstraints(record.settings),
64
+ updatedAt: this.now()
65
+ });
66
+ await this.storage.setItem(this.worldKey(normalized.id), JSON.stringify(normalized));
67
+ await this.updateIndex((index) => {
68
+ const summary = {
69
+ id: normalized.id,
70
+ name: normalized.name,
71
+ updatedAt: normalized.updatedAt,
72
+ blockCount: Object.keys(normalized.world.blocks).length
73
+ };
74
+ const without = index.filter((s) => s.id !== normalized.id);
75
+ return [summary, ...without];
76
+ });
77
+ }
78
+ async rename(id, name) {
79
+ const record = await this.load(id);
80
+ if (!record) return;
81
+ await this.save(__spreadProps(__spreadValues({}, record), {
82
+ name: cleanName(name)
83
+ }));
84
+ }
85
+ async delete(id) {
86
+ await this.storage.removeItem(this.worldKey(id));
87
+ await this.updateIndex((index) => index.filter((s) => s.id !== id));
88
+ }
89
+ async updateIndex(update) {
90
+ const current = await this.list();
91
+ const next = update(current).sort((a, b) => b.updatedAt - a.updatedAt);
92
+ await this.storage.setItem(this.indexKey(), JSON.stringify(next));
93
+ }
94
+ indexKey() {
95
+ return `${STORAGE_PREFIX}:${this.namespace}:index`;
96
+ }
97
+ worldKey(id) {
98
+ return `${STORAGE_PREFIX}:${this.namespace}:world:${id}`;
99
+ }
100
+ }
101
+ function defaultMakeId() {
102
+ const rand = Math.random().toString(36).slice(2, 10);
103
+ return `w_${Date.now().toString(36)}_${rand}`;
104
+ }
105
+ function cleanName(name) {
106
+ const trimmed = (name != null ? name : "").trim().slice(0, 60);
107
+ return trimmed === "" ? "Untitled World" : trimmed;
108
+ }
109
+ function safeParse(raw) {
110
+ if (raw === null) return null;
111
+ try {
112
+ return JSON.parse(raw);
113
+ } catch (e) {
114
+ return null;
115
+ }
116
+ }
117
+ function coerceSummary(entry) {
118
+ if (!entry || typeof entry !== "object") return null;
119
+ const e = entry;
120
+ if (typeof e.id !== "string" || typeof e.name !== "string") return null;
121
+ return {
122
+ id: e.id,
123
+ name: e.name,
124
+ updatedAt: typeof e.updatedAt === "number" ? e.updatedAt : 0,
125
+ blockCount: typeof e.blockCount === "number" ? e.blockCount : 0
126
+ };
127
+ }
128
+ function coerceRecord(e) {
129
+ if (typeof e.id !== "string") return null;
130
+ const world = coerceWorld(e.world);
131
+ return {
132
+ id: e.id,
133
+ name: typeof e.name === "string" ? cleanName(e.name) : "Untitled World",
134
+ createdAt: typeof e.createdAt === "number" ? e.createdAt : 0,
135
+ updatedAt: typeof e.updatedAt === "number" ? e.updatedAt : 0,
136
+ settings: applyRuleConstraints(coerceSettings(e.settings)),
137
+ permissions: coercePermissions(e.permissions),
138
+ world
139
+ };
140
+ }
141
+ function coerceWorld(value) {
142
+ const fallback = VoxelWorld.create(DEFAULT_BOUNDS).serialize();
143
+ if (!value || typeof value !== "object") return fallback;
144
+ const v = value;
145
+ const bounds = v.bounds;
146
+ if (!bounds || typeof bounds.x !== "number" || typeof bounds.y !== "number" || typeof bounds.z !== "number") {
147
+ return fallback;
148
+ }
149
+ const blocks = {};
150
+ if (v.blocks && typeof v.blocks === "object") {
151
+ for (const [key, id] of Object.entries(v.blocks)) {
152
+ if (typeof id === "number") blocks[key] = id;
153
+ }
154
+ }
155
+ return VoxelWorld.deserialize({
156
+ bounds: {
157
+ x: bounds.x,
158
+ y: bounds.y,
159
+ z: bounds.z
160
+ },
161
+ blocks
162
+ }).serialize();
163
+ }
164
+ function coerceSettings(value) {
165
+ const base = defaultWorldSettings();
166
+ if (!value || typeof value !== "object") return base;
167
+ const v = value;
168
+ const merged = __spreadValues({}, base);
169
+ for (const key of Object.keys(base)) {
170
+ if (key === "resourceLink") continue;
171
+ if (typeof v[key] === "boolean") {
172
+ merged[key] = v[key];
173
+ }
174
+ }
175
+ const link = v.resourceLink;
176
+ if (link && typeof link === "object") {
177
+ merged.resourceLink = {
178
+ buttonName: typeof link.buttonName === "string" ? link.buttonName : "",
179
+ url: typeof link.url === "string" ? link.url : ""
180
+ };
181
+ }
182
+ return merged;
183
+ }
184
+ function coercePermissions(value) {
185
+ const base = defaultPermissionModel();
186
+ if (!value || typeof value !== "object") return base;
187
+ const v = value;
188
+ return {
189
+ hostEnabled: typeof v.hostEnabled === "boolean" ? v.hostEnabled : base.hostEnabled,
190
+ defaultLevel: v.defaultLevel === "visitor" || v.defaultLevel === "member" || v.defaultLevel === "operator" ? v.defaultLevel : base.defaultLevel
191
+ };
192
+ }export{STORAGE_PREFIX,STORAGE_VERSION,WorldRepository};//# sourceMappingURL=worldRepository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worldRepository.js","sources":["../../../../../../src/features/games/vendored/core/storage/worldRepository.ts"],"sourcesContent":["/**\n * Persists a player's worlds via a KeyValueStorage adapter.\n *\n * Keys are namespaced by organisation so one device signed into different orgs\n * keeps separate collections:\n * yantra.games.v1:<org>:index -> WorldSummary[]\n * yantra.games.v1:<org>:world:<id> -> WorldRecord\n *\n * Reads are defensive: corrupt or partial records are skipped or repaired with\n * defaults rather than throwing, so one bad entry can't break the library.\n */\n\nimport type { KeyValueStorage } from './storage';\nimport { defaultWorldSettings, type WorldSettings } from '../classroom/worldSettings';\nimport { applyRuleConstraints } from '../classroom/rules';\nimport { defaultPermissionModel, type PermissionModel } from '../classroom/permissions';\nimport { DEFAULT_BOUNDS, VoxelWorld, type SerializedWorld } from '../engine/world';\n\nexport const STORAGE_VERSION = 'v1';\nexport const STORAGE_PREFIX = `yantra.games.${STORAGE_VERSION}`;\n\nexport interface WorldRecord {\n id: string;\n name: string;\n createdAt: number;\n updatedAt: number;\n settings: WorldSettings;\n permissions: PermissionModel;\n world: SerializedWorld;\n}\n\nexport interface WorldSummary {\n id: string;\n name: string;\n updatedAt: number;\n blockCount: number;\n}\n\nexport class WorldRepository {\n constructor(\n private readonly storage: KeyValueStorage,\n private readonly namespace: string,\n private readonly now: () => number = () => Date.now(),\n private readonly makeId: () => string = defaultMakeId,\n ) {}\n\n async list(): Promise<WorldSummary[]> {\n const raw = await this.storage.getItem(this.indexKey());\n const parsed = safeParse(raw);\n if (!Array.isArray(parsed)) return [];\n const out: WorldSummary[] = [];\n for (const entry of parsed) {\n const summary = coerceSummary(entry);\n if (summary) out.push(summary);\n }\n return out.sort((a, b) => b.updatedAt - a.updatedAt);\n }\n\n async load(id: string): Promise<WorldRecord | null> {\n const raw = await this.storage.getItem(this.worldKey(id));\n const parsed = safeParse(raw);\n if (!parsed || typeof parsed !== 'object') return null;\n return coerceRecord(parsed as Record<string, unknown>);\n }\n\n async create(name: string): Promise<WorldRecord> {\n const ts = this.now();\n const record: WorldRecord = {\n id: this.makeId(),\n name: cleanName(name),\n createdAt: ts,\n updatedAt: ts,\n settings: defaultWorldSettings(),\n permissions: defaultPermissionModel(),\n world: VoxelWorld.create(DEFAULT_BOUNDS).serialize(),\n };\n await this.save(record);\n return record;\n }\n\n async save(record: WorldRecord): Promise<void> {\n const normalized: WorldRecord = {\n ...record,\n name: cleanName(record.name),\n settings: applyRuleConstraints(record.settings),\n updatedAt: this.now(),\n };\n await this.storage.setItem(this.worldKey(normalized.id), JSON.stringify(normalized));\n await this.updateIndex((index) => {\n const summary: WorldSummary = {\n id: normalized.id,\n name: normalized.name,\n updatedAt: normalized.updatedAt,\n blockCount: Object.keys(normalized.world.blocks).length,\n };\n const without = index.filter((s) => s.id !== normalized.id);\n return [summary, ...without];\n });\n }\n\n async rename(id: string, name: string): Promise<void> {\n const record = await this.load(id);\n if (!record) return;\n await this.save({ ...record, name: cleanName(name) });\n }\n\n async delete(id: string): Promise<void> {\n await this.storage.removeItem(this.worldKey(id));\n await this.updateIndex((index) => index.filter((s) => s.id !== id));\n }\n\n private async updateIndex(update: (index: WorldSummary[]) => WorldSummary[]): Promise<void> {\n const current = await this.list();\n const next = update(current).sort((a, b) => b.updatedAt - a.updatedAt);\n await this.storage.setItem(this.indexKey(), JSON.stringify(next));\n }\n\n private indexKey(): string {\n return `${STORAGE_PREFIX}:${this.namespace}:index`;\n }\n\n private worldKey(id: string): string {\n return `${STORAGE_PREFIX}:${this.namespace}:world:${id}`;\n }\n}\n\nfunction defaultMakeId(): string {\n const rand = Math.random().toString(36).slice(2, 10);\n return `w_${Date.now().toString(36)}_${rand}`;\n}\n\nfunction cleanName(name: string): string {\n const trimmed = (name ?? '').trim().slice(0, 60);\n return trimmed === '' ? 'Untitled World' : trimmed;\n}\n\nfunction safeParse(raw: string | null): unknown {\n if (raw === null) return null;\n try {\n return JSON.parse(raw);\n } catch {\n return null;\n }\n}\n\nfunction coerceSummary(entry: unknown): WorldSummary | null {\n if (!entry || typeof entry !== 'object') return null;\n const e = entry as Record<string, unknown>;\n if (typeof e.id !== 'string' || typeof e.name !== 'string') return null;\n return {\n id: e.id,\n name: e.name,\n updatedAt: typeof e.updatedAt === 'number' ? e.updatedAt : 0,\n blockCount: typeof e.blockCount === 'number' ? e.blockCount : 0,\n };\n}\n\nfunction coerceRecord(e: Record<string, unknown>): WorldRecord | null {\n if (typeof e.id !== 'string') return null;\n const world = coerceWorld(e.world);\n return {\n id: e.id,\n name: typeof e.name === 'string' ? cleanName(e.name) : 'Untitled World',\n createdAt: typeof e.createdAt === 'number' ? e.createdAt : 0,\n updatedAt: typeof e.updatedAt === 'number' ? e.updatedAt : 0,\n settings: applyRuleConstraints(coerceSettings(e.settings)),\n permissions: coercePermissions(e.permissions),\n world,\n };\n}\n\nfunction coerceWorld(value: unknown): SerializedWorld {\n const fallback = VoxelWorld.create(DEFAULT_BOUNDS).serialize();\n if (!value || typeof value !== 'object') return fallback;\n const v = value as Record<string, unknown>;\n const bounds = v.bounds as Record<string, unknown> | undefined;\n if (!bounds || typeof bounds.x !== 'number' || typeof bounds.y !== 'number' || typeof bounds.z !== 'number') {\n return fallback;\n }\n const blocks: Record<string, number> = {};\n if (v.blocks && typeof v.blocks === 'object') {\n for (const [key, id] of Object.entries(v.blocks as Record<string, unknown>)) {\n if (typeof id === 'number') blocks[key] = id;\n }\n }\n // Round-trip through the model so out-of-bounds / invalid cells are dropped.\n return VoxelWorld.deserialize({\n bounds: { x: bounds.x, y: bounds.y, z: bounds.z },\n blocks,\n }).serialize();\n}\n\nfunction coerceSettings(value: unknown): WorldSettings {\n const base = defaultWorldSettings();\n if (!value || typeof value !== 'object') return base;\n const v = value as Record<string, unknown>;\n const merged: WorldSettings = { ...base };\n for (const key of Object.keys(base) as (keyof WorldSettings)[]) {\n if (key === 'resourceLink') continue;\n if (typeof v[key] === 'boolean') {\n (merged[key] as boolean) = v[key] as boolean;\n }\n }\n const link = v.resourceLink as Record<string, unknown> | undefined;\n if (link && typeof link === 'object') {\n merged.resourceLink = {\n buttonName: typeof link.buttonName === 'string' ? link.buttonName : '',\n url: typeof link.url === 'string' ? link.url : '',\n };\n }\n return merged;\n}\n\nfunction coercePermissions(value: unknown): PermissionModel {\n const base = defaultPermissionModel();\n if (!value || typeof value !== 'object') return base;\n const v = value as Record<string, unknown>;\n return {\n hostEnabled: typeof v.hostEnabled === 'boolean' ? v.hostEnabled : base.hostEnabled,\n defaultLevel:\n v.defaultLevel === 'visitor' || v.defaultLevel === 'member' || v.defaultLevel === 'operator'\n ? v.defaultLevel\n : base.defaultLevel,\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAiBO,MAAM,eAAkB,GAAA;AAClB,MAAA,cAAA,GAAiB,gBAAgB,eAAe,CAAA;AAgBtD,MAAM,eAAgB,CAAA;AAAA,EAC3B,WAAA,CAA6B,SAA2C,SAAoC,EAAA,GAAA,GAAoB,MAAM,IAAK,CAAA,GAAA,EAAwB,EAAA,MAAA,GAAuB,aAAe,EAAA;AAA5K,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAA2C,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AAAoC,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAAuD,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA;AAAuC,EAC1M,MAAM,IAAgC,GAAA;AACpC,IAAA,MAAM,MAAM,MAAM,IAAA,CAAK,QAAQ,OAAQ,CAAA,IAAA,CAAK,UAAU,CAAA;AACtD,IAAM,MAAA,MAAA,GAAS,UAAU,GAAG,CAAA;AAC5B,IAAA,IAAI,CAAC,KAAM,CAAA,OAAA,CAAQ,MAAM,CAAA,SAAU,EAAC;AACpC,IAAA,MAAM,MAAsB,EAAC;AAC7B,IAAA,KAAA,MAAW,SAAS,MAAQ,EAAA;AAC1B,MAAM,MAAA,OAAA,GAAU,cAAc,KAAK,CAAA;AACnC,MAAI,IAAA,OAAA,EAAa,GAAA,CAAA,IAAA,CAAK,OAAO,CAAA;AAAA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A8B,EAAA;AAC9D,IAAA,IAAI,QAAQ,cAAgB,EAAA;AAC5B,IAAA,IAAI,OAAO,CAAA,CAAE,GAAG,CAAA,KAAM,SAAW,EAAA;AAC/B,MAAC,MAAO,CAAA,GAAG,CAAgB,GAAA,CAAA,CAAE,GAAG,CAAA;AAAA;AAClC;AAEF,EAAA,MAAM,OAAO,CAAE,CAAA,YAAA;AACf,EAAI,IAAA,IAAA,IAAQ,OAAO,IAAA,KAAS,QAAU,EAAA;AACpC,IAAA,MAAA,CAAO,YAAe,GAAA;AAAA,MACpB,YAAY,OAAO,IAAA,CAAK,UAAe,KAAA,QAAA,GAAW,KAAK,UAAa,GAAA,EAAA;AAAA,MACpE,KAAK,OAAO,IAAA,CAAK,GAAQ,KAAA,QAAA,GAAW,KAAK,GAAM,GAAA;AAAA,KACjD;AAAA;AAEF,EAAO,OAAA,MAAA;AACT;AACA,SAAS,kBAAkB,KAAiC,EAAA;AAC1D,EAAA,MAAM,OAAO,sBAAuB,EAAA;AACpC,EAAA,IAAI,CAAC,KAAA,IAAS,OAAO,KAAA,KAAU,UAAiB,OAAA,IAAA;AAChD,EAAA,MAAM,CAAI,GAAA,KAAA;AACV,EAAO,OAAA;AAAA,IACL,aAAa,OAAO,CAAA,CAAE,gBAAgB,SAAY,GAAA,CAAA,CAAE,cAAc,IAAK,CAAA,WAAA;AAAA,IACvE,YAAc,EAAA,CAAA,CAAE,YAAiB,KAAA,SAAA,IAAa,CAAE,CAAA,YAAA,KAAiB,QAAY,IAAA,CAAA,CAAE,YAAiB,KAAA,UAAA,GAAa,CAAE,CAAA,YAAA,GAAe,IAAK,CAAA;AAAA,GACrI;AACF"}
@@ -0,0 +1,78 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ const refEquals = (a, b) => Object.is(a, b);
5
+ class ReactiveValue {
6
+ constructor(initial, equals = refEquals) {
7
+ __publicField(this, "value");
8
+ __publicField(this, "listeners", /* @__PURE__ */ new Set());
9
+ __publicField(this, "equals");
10
+ this.value = initial;
11
+ this.equals = equals;
12
+ }
13
+ get() {
14
+ return this.value;
15
+ }
16
+ /** Replace the value. Listeners fire only when it actually changes. */
17
+ set(next) {
18
+ if (this.equals(this.value, next)) return;
19
+ this.value = next;
20
+ this.emit();
21
+ }
22
+ /** Functional update. Listeners fire only when the result changes. */
23
+ update(updater) {
24
+ this.set(updater(this.value));
25
+ }
26
+ subscribe(listener) {
27
+ this.listeners.add(listener);
28
+ return () => {
29
+ this.listeners.delete(listener);
30
+ };
31
+ }
32
+ select(selector, equals = refEquals) {
33
+ return new DerivedQuery(this, selector, equals);
34
+ }
35
+ emit() {
36
+ for (const listener of [...this.listeners]) listener(this.value);
37
+ }
38
+ }
39
+ class DerivedQuery {
40
+ constructor(source, selector, equals) {
41
+ this.source = source;
42
+ this.selector = selector;
43
+ this.equals = equals;
44
+ __publicField(this, "listeners", /* @__PURE__ */ new Set());
45
+ __publicField(this, "cached");
46
+ __publicField(this, "sourceUnsub", null);
47
+ __publicField(this, "onSource", (value) => {
48
+ const next = this.selector(value);
49
+ if (this.equals(this.cached, next)) return;
50
+ this.cached = next;
51
+ for (const listener of [...this.listeners]) listener(next);
52
+ });
53
+ this.cached = selector(source.get());
54
+ }
55
+ get() {
56
+ if (this.listeners.size === 0) {
57
+ this.cached = this.selector(this.source.get());
58
+ }
59
+ return this.cached;
60
+ }
61
+ subscribe(listener) {
62
+ if (this.listeners.size === 0) {
63
+ this.cached = this.selector(this.source.get());
64
+ this.sourceUnsub = this.source.subscribe(this.onSource);
65
+ }
66
+ this.listeners.add(listener);
67
+ return () => {
68
+ this.listeners.delete(listener);
69
+ if (this.listeners.size === 0 && this.sourceUnsub) {
70
+ this.sourceUnsub();
71
+ this.sourceUnsub = null;
72
+ }
73
+ };
74
+ }
75
+ select(selector, equals = refEquals) {
76
+ return new DerivedQuery(this, selector, equals);
77
+ }
78
+ }export{ReactiveValue};//# sourceMappingURL=reactive.js.map