@optique/core 1.0.0-dev.1884 → 1.0.0-dev.1886

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.
@@ -44,626 +44,12 @@ const annotationWrapperKeys = new Set([
44
44
  annotationWrapperKey
45
45
  ]);
46
46
  const injectedAnnotationWrappers = /* @__PURE__ */ new WeakSet();
47
- const protectedAnnotationTargets = /* @__PURE__ */ new WeakMap();
48
- const protectedAnnotationStateViews = /* @__PURE__ */ new WeakMap();
49
- function throwReadonlyAnnotationMutation() {
50
- throw new TypeError("Cannot mutate read-only annotation data.");
51
- }
52
- function createAnnotationProtectionContext(rewrapProtectedViews = false) {
53
- return {
54
- cache: /* @__PURE__ */ new WeakMap(),
55
- rewrapProtectedViews
56
- };
57
- }
58
- function registerProtectedAnnotationView(context, target, view) {
59
- context.cache.set(target, view);
60
- protectedAnnotationTargets.set(view, target);
61
- return view;
62
- }
63
- function cacheProtectedAnnotationViewAlias(context, alias, view) {
64
- context.cache.set(alias, view);
65
- }
66
- function isProtectedAnnotationView(value) {
67
- return value != null && typeof value === "object" && protectedAnnotationTargets.has(value);
68
- }
69
- function unwrapProtectedAnnotationTarget(value) {
70
- if (value == null || typeof value !== "object") return value;
71
- return protectedAnnotationTargets.get(value) ?? value;
72
- }
73
- function cacheProtectedMethod(cache, key, factory) {
74
- const cached = cache.get(key);
75
- if (cached !== void 0) return cached;
76
- const created = factory();
77
- cache.set(key, created);
78
- return created;
79
- }
80
- function getProtectedClonePropertyValue(cache, target, key, value, context) {
81
- const ownDescriptor = Reflect.getOwnPropertyDescriptor(target, key);
82
- if (ownDescriptor != null && "value" in ownDescriptor && ownDescriptor.configurable === false && ownDescriptor.writable === false) return ownDescriptor.value;
83
- if (typeof value !== "function") return protectAnnotationValue(value, context);
84
- if (key === "constructor") return value;
85
- return cacheProtectedMethod(cache, key, () => value.bind(target));
86
- }
87
- function defineProtectedDataProperty(context, target, key, descriptor) {
88
- const value = protectAnnotationValue(descriptor.value, context);
89
- Object.defineProperty(target, key, {
90
- configurable: descriptor.configurable,
91
- enumerable: descriptor.enumerable,
92
- get: () => value,
93
- set: () => throwReadonlyAnnotationMutation()
94
- });
95
- }
96
- function copyOwnProperties(source, target, transformValue, excludedKeys, syncPrototype = true) {
97
- const sourcePrototype = Object.getPrototypeOf(source);
98
- if (syncPrototype && Object.getPrototypeOf(target) !== sourcePrototype) Object.setPrototypeOf(target, sourcePrototype);
99
- for (const key of Reflect.ownKeys(source)) {
100
- if (excludedKeys?.has(key) === true) continue;
101
- const descriptor = Object.getOwnPropertyDescriptor(source, key);
102
- if (descriptor == null) continue;
103
- if ("value" in descriptor && transformValue != null) {
104
- Object.defineProperty(target, key, {
105
- ...descriptor,
106
- value: transformValue(descriptor.value)
107
- });
108
- continue;
109
- }
110
- Object.defineProperty(target, key, descriptor);
111
- }
112
- }
113
- function normalizeProtectedCollectionItem(value, context) {
114
- return context.rewrapProtectedViews && isProtectedAnnotationView(value) ? unwrapProtectedAnnotationTarget(value) : value;
115
- }
116
- function resolveCloneConstructor(source) {
117
- const constructorValue = source.constructor;
118
- if (typeof constructorValue !== "function") return void 0;
119
- const species = Reflect.get(constructorValue, Symbol.species);
120
- const cloneConstructor = species == null ? constructorValue : species;
121
- return typeof cloneConstructor === "function" ? cloneConstructor : void 0;
122
- }
123
- function hasBuiltInSubclassPrototype(target, basePrototype) {
124
- return Object.getPrototypeOf(target) !== basePrototype;
125
- }
126
- function tryCloneMapSubclass(source, entries) {
127
- const entriesArray = [...entries];
128
- const cloneConstructor = resolveCloneConstructor(source);
129
- if (cloneConstructor == null) return void 0;
130
- try {
131
- const cloned = new cloneConstructor(entriesArray);
132
- if (!(cloned instanceof Map) || cloned.size !== entriesArray.length) return void 0;
133
- for (const [key, value] of entriesArray) if (!cloned.has(key) || !Object.is(cloned.get(key), value)) return void 0;
134
- return cloned;
135
- } catch {
136
- return void 0;
137
- }
138
- }
139
- function tryCloneSetSubclass(source, values) {
140
- const valuesArray = [...values];
141
- const cloneConstructor = resolveCloneConstructor(source);
142
- if (cloneConstructor == null) return void 0;
143
- try {
144
- const cloned = new cloneConstructor(valuesArray);
145
- if (!(cloned instanceof Set) || cloned.size !== valuesArray.length) return void 0;
146
- for (const value of valuesArray) if (!cloned.has(value)) return void 0;
147
- return cloned;
148
- } catch {
149
- return void 0;
150
- }
151
- }
152
- function tryCloneDateSubclass(source) {
153
- const cloneConstructor = resolveCloneConstructor(source);
154
- if (cloneConstructor == null) return void 0;
155
- try {
156
- const cloned = new cloneConstructor(source.getTime());
157
- return cloned instanceof Date && cloned.getTime() === source.getTime() ? cloned : void 0;
158
- } catch {
159
- return void 0;
160
- }
161
- }
162
- function tryCloneRegExpSubclass(source) {
163
- const cloneConstructor = resolveCloneConstructor(source);
164
- if (cloneConstructor == null) return void 0;
165
- try {
166
- const cloned = new cloneConstructor(source.source, source.flags);
167
- return cloned instanceof RegExp && cloned.source === source.source && cloned.flags === source.flags ? cloned : void 0;
168
- } catch {
169
- return void 0;
170
- }
171
- }
172
- function tryCloneArraySubclass(source) {
173
- const entries = [...source];
174
- const cloneConstructor = resolveCloneConstructor(source);
175
- if (cloneConstructor == null) return void 0;
176
- try {
177
- const cloned = Reflect.apply(Array.from, cloneConstructor, [entries]);
178
- return Array.isArray(cloned) && cloned.length === entries.length && entries.every((value, index) => Object.is(cloned[index], value)) ? cloned : void 0;
179
- } catch {
180
- return void 0;
181
- }
182
- }
183
- function tryCloneURLSearchParamsSubclass(source) {
184
- const cloneConstructor = resolveCloneConstructor(source);
185
- if (cloneConstructor == null) return void 0;
186
- try {
187
- const cloned = new cloneConstructor(source);
188
- return cloned instanceof URLSearchParams && cloned.toString() === source.toString() ? cloned : void 0;
189
- } catch {
190
- return void 0;
191
- }
192
- }
193
- function tryCloneURLSubclass(source) {
194
- const cloneConstructor = resolveCloneConstructor(source);
195
- if (cloneConstructor == null) return void 0;
196
- try {
197
- const cloned = new cloneConstructor(source.href);
198
- return cloned instanceof URL && cloned.href === source.href ? cloned : void 0;
199
- } catch {
200
- return void 0;
201
- }
202
- }
203
- const regExpExcludedKeys = new Set(["lastIndex"]);
204
- const mapMutationMethodKeys = [
205
- "set",
206
- "delete",
207
- "clear"
208
- ];
209
- const setMutationMethodKeys = [
210
- "add",
211
- "delete",
212
- "clear"
213
- ];
214
- const urlSearchParamsMutationMethodKeys = [
215
- "append",
216
- "delete",
217
- "set",
218
- "sort"
219
- ];
220
- const urlMutationPropertyKeys = [
221
- "hash",
222
- "host",
223
- "hostname",
224
- "href",
225
- "password",
226
- "pathname",
227
- "port",
228
- "protocol",
229
- "search",
230
- "username"
231
- ];
232
- const dateMutationMethodKeys = Object.getOwnPropertyNames(Date.prototype).filter((key) => key.startsWith("set"));
233
- function installReadonlyMutationMethodGuards(target, keys) {
234
- for (const key of keys) {
235
- const descriptor = Object.getOwnPropertyDescriptor(target, key);
236
- if (descriptor?.configurable === false) continue;
237
- Object.defineProperty(target, key, {
238
- configurable: true,
239
- enumerable: false,
240
- writable: true,
241
- value: (..._args) => throwReadonlyAnnotationMutation()
242
- });
243
- }
244
- }
245
- function installReadonlyURLGuards(target, context) {
246
- const searchParams = target.searchParams;
247
- const searchParamsDescriptor = Object.getOwnPropertyDescriptor(target, "searchParams");
248
- if (searchParamsDescriptor?.configurable !== false) Object.defineProperty(target, "searchParams", {
249
- configurable: true,
250
- enumerable: false,
251
- get: () => protectAnnotationValue(searchParams, context),
252
- set: () => throwReadonlyAnnotationMutation()
253
- });
254
- for (const key of urlMutationPropertyKeys) {
255
- const descriptor = Object.getOwnPropertyDescriptor(target, key);
256
- if (descriptor?.configurable === false) continue;
257
- Object.defineProperty(target, key, {
258
- configurable: true,
259
- enumerable: false,
260
- get: () => Reflect.get(URL.prototype, key, target),
261
- set: () => throwReadonlyAnnotationMutation()
262
- });
263
- }
264
- }
265
- function copyRegExpMetadata(source, target, transformValue, syncPrototype = true) {
266
- copyOwnProperties(source, target, transformValue, regExpExcludedKeys, syncPrototype);
267
- target.lastIndex = source.lastIndex;
268
- }
269
- function cloneRegExpShape(source) {
270
- const syncPrototype = !hasBuiltInSubclassPrototype(source, RegExp.prototype);
271
- const cloned = syncPrototype ? new RegExp(source) : tryCloneRegExpSubclass(source) ?? new RegExp(source);
272
- copyRegExpMetadata(source, cloned, void 0, syncPrototype);
273
- return cloned;
274
- }
275
- function createProtectedObjectView(target, context) {
276
- if (Array.isArray(target)) {
277
- const targetPrototype = Object.getPrototypeOf(target);
278
- const view$1 = targetPrototype === Array.prototype || targetPrototype === null ? Object.setPrototypeOf([], targetPrototype) : tryCloneArraySubclass(target) ?? [];
279
- view$1.length = target.length;
280
- registerProtectedAnnotationView(context, target, view$1);
281
- for (const key of Reflect.ownKeys(target)) {
282
- if (key === "length") continue;
283
- const descriptor = Object.getOwnPropertyDescriptor(target, key);
284
- if (descriptor == null) continue;
285
- if ("value" in descriptor) {
286
- defineProtectedDataProperty(context, view$1, key, descriptor);
287
- continue;
288
- }
289
- Object.defineProperty(view$1, key, {
290
- configurable: descriptor.configurable,
291
- enumerable: descriptor.enumerable,
292
- get: descriptor.get == null ? void 0 : () => protectAnnotationValue(descriptor.get.call(target), context),
293
- set: () => throwReadonlyAnnotationMutation()
294
- });
295
- }
296
- return Object.freeze(view$1);
297
- }
298
- const view = Object.create(Object.getPrototypeOf(target));
299
- registerProtectedAnnotationView(context, target, view);
300
- for (const key of Reflect.ownKeys(target)) {
301
- const descriptor = Object.getOwnPropertyDescriptor(target, key);
302
- if (descriptor == null) continue;
303
- if ("value" in descriptor) {
304
- defineProtectedDataProperty(context, view, key, descriptor);
305
- continue;
306
- }
307
- Object.defineProperty(view, key, {
308
- configurable: descriptor.configurable,
309
- enumerable: descriptor.enumerable,
310
- get: descriptor.get == null ? void 0 : () => protectAnnotationValue(descriptor.get.call(target), context),
311
- set: () => throwReadonlyAnnotationMutation()
312
- });
313
- }
314
- return Object.freeze(view);
315
- }
316
- function createProtectedMapView(target, context) {
317
- const syncPrototype = !hasBuiltInSubclassPrototype(target, Map.prototype);
318
- const entries = [...target.entries()].map(([entryKey, entryValue]) => [normalizeProtectedCollectionItem(entryKey, context), normalizeProtectedCollectionItem(entryValue, context)]);
319
- const methodCache = /* @__PURE__ */ new Map();
320
- const cloned = syncPrototype ? new Map(entries) : tryCloneMapSubclass(target, entries) ?? new Map(entries);
321
- const view = new Proxy(cloned, {
322
- get(clonedTarget, key) {
323
- if (key === "size") return clonedTarget.size;
324
- if (key === "valueOf") return cacheProtectedMethod(methodCache, key, () => () => view);
325
- if (key === "set" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
326
- if (key === "get") return cacheProtectedMethod(methodCache, key, () => (lookup) => {
327
- if (clonedTarget.has(lookup)) return protectAnnotationValue(clonedTarget.get(lookup), context);
328
- return protectAnnotationValue(clonedTarget.get(unwrapProtectedAnnotationTarget(lookup)), context);
329
- });
330
- if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => clonedTarget.has(lookup) || clonedTarget.has(unwrapProtectedAnnotationTarget(lookup)));
331
- if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => clonedTarget.forEach((value$1, mapKey) => {
332
- callback.call(thisArg, protectAnnotationValue(value$1, context), protectAnnotationValue(mapKey, context), view);
333
- }));
334
- if (key === "keys") return cacheProtectedMethod(methodCache, key, () => function* () {
335
- for (const value$1 of clonedTarget.keys()) yield protectAnnotationValue(value$1, context);
336
- });
337
- if (key === "values") return cacheProtectedMethod(methodCache, key, () => function* () {
338
- for (const value$1 of clonedTarget.values()) yield protectAnnotationValue(value$1, context);
339
- });
340
- if (key === "entries" || key === Symbol.iterator) return cacheProtectedMethod(methodCache, key, () => function* () {
341
- for (const [entryKey, entryValue] of clonedTarget.entries()) yield [protectAnnotationValue(entryKey, context), protectAnnotationValue(entryValue, context)];
342
- });
343
- const value = Reflect.get(clonedTarget, key, clonedTarget);
344
- return getProtectedClonePropertyValue(methodCache, clonedTarget, key, value, context);
345
- },
346
- set() {
347
- throwReadonlyAnnotationMutation();
348
- },
349
- defineProperty() {
350
- throwReadonlyAnnotationMutation();
351
- },
352
- deleteProperty() {
353
- throwReadonlyAnnotationMutation();
354
- },
355
- setPrototypeOf() {
356
- throwReadonlyAnnotationMutation();
357
- },
358
- preventExtensions() {
359
- throwReadonlyAnnotationMutation();
360
- }
361
- });
362
- registerProtectedAnnotationView(context, target, view);
363
- cacheProtectedAnnotationViewAlias(context, cloned, view);
364
- copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
365
- installReadonlyMutationMethodGuards(cloned, mapMutationMethodKeys);
366
- return view;
367
- }
368
- function createProtectedSetView(target, context) {
369
- const syncPrototype = !hasBuiltInSubclassPrototype(target, Set.prototype);
370
- const values = [...target.values()].map((value) => normalizeProtectedCollectionItem(value, context));
371
- const methodCache = /* @__PURE__ */ new Map();
372
- const cloned = syncPrototype ? new Set(values) : tryCloneSetSubclass(target, values) ?? new Set(values);
373
- const view = new Proxy(cloned, {
374
- get(clonedTarget, key) {
375
- if (key === "size") return clonedTarget.size;
376
- if (key === "valueOf") return cacheProtectedMethod(methodCache, key, () => () => view);
377
- if (key === "add" || key === "delete" || key === "clear") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
378
- if (key === "has") return cacheProtectedMethod(methodCache, key, () => (lookup) => clonedTarget.has(lookup) || clonedTarget.has(unwrapProtectedAnnotationTarget(lookup)));
379
- if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => clonedTarget.forEach((value$1) => {
380
- const protectedValue = protectAnnotationValue(value$1, context);
381
- callback.call(thisArg, protectedValue, protectedValue, view);
382
- }));
383
- if (key === "keys" || key === "values" || key === Symbol.iterator) return cacheProtectedMethod(methodCache, key, () => function* () {
384
- for (const value$1 of clonedTarget.values()) yield protectAnnotationValue(value$1, context);
385
- });
386
- if (key === "entries") return cacheProtectedMethod(methodCache, key, () => function* () {
387
- for (const value$1 of clonedTarget.values()) {
388
- const protectedValue = protectAnnotationValue(value$1, context);
389
- yield [protectedValue, protectedValue];
390
- }
391
- });
392
- const value = Reflect.get(clonedTarget, key, clonedTarget);
393
- return getProtectedClonePropertyValue(methodCache, clonedTarget, key, value, context);
394
- },
395
- set() {
396
- throwReadonlyAnnotationMutation();
397
- },
398
- defineProperty() {
399
- throwReadonlyAnnotationMutation();
400
- },
401
- deleteProperty() {
402
- throwReadonlyAnnotationMutation();
403
- },
404
- setPrototypeOf() {
405
- throwReadonlyAnnotationMutation();
406
- },
407
- preventExtensions() {
408
- throwReadonlyAnnotationMutation();
409
- }
410
- });
411
- registerProtectedAnnotationView(context, target, view);
412
- cacheProtectedAnnotationViewAlias(context, cloned, view);
413
- copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
414
- installReadonlyMutationMethodGuards(cloned, setMutationMethodKeys);
415
- return view;
416
- }
417
- function createProtectedDateView(target, context) {
418
- const syncPrototype = !hasBuiltInSubclassPrototype(target, Date.prototype);
419
- const methodCache = /* @__PURE__ */ new Map();
420
- const cloned = syncPrototype ? new Date(target.getTime()) : tryCloneDateSubclass(target) ?? new Date(target.getTime());
421
- const view = new Proxy(cloned, {
422
- get(clonedTarget, key) {
423
- const value = Reflect.get(clonedTarget, key, clonedTarget);
424
- if (typeof key === "string" && key.startsWith("set")) return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
425
- return typeof value === "function" ? getProtectedClonePropertyValue(methodCache, clonedTarget, key, value, context) : protectAnnotationValue(value, context);
426
- },
427
- set() {
428
- throwReadonlyAnnotationMutation();
429
- },
430
- defineProperty() {
431
- throwReadonlyAnnotationMutation();
432
- },
433
- deleteProperty() {
434
- throwReadonlyAnnotationMutation();
435
- },
436
- setPrototypeOf() {
437
- throwReadonlyAnnotationMutation();
438
- },
439
- preventExtensions() {
440
- throwReadonlyAnnotationMutation();
441
- }
442
- });
443
- registerProtectedAnnotationView(context, target, view);
444
- cacheProtectedAnnotationViewAlias(context, cloned, view);
445
- copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
446
- installReadonlyMutationMethodGuards(cloned, dateMutationMethodKeys);
447
- return view;
448
- }
449
- function createProtectedRegExpView(target, context) {
450
- const syncPrototype = !hasBuiltInSubclassPrototype(target, RegExp.prototype);
451
- const methodCache = /* @__PURE__ */ new Map();
452
- const cloned = syncPrototype ? new RegExp(target) : tryCloneRegExpSubclass(target) ?? new RegExp(target);
453
- const view = new Proxy(cloned, {
454
- get(clonedTarget, key) {
455
- if (key === "compile") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
456
- if (key === "valueOf") return cacheProtectedMethod(methodCache, key, () => () => view);
457
- const ownDescriptor = Object.getOwnPropertyDescriptor(clonedTarget, key);
458
- if (ownDescriptor != null && "value" in ownDescriptor) return ownDescriptor.value;
459
- const value = Reflect.get(clonedTarget, key, clonedTarget);
460
- return getProtectedClonePropertyValue(methodCache, clonedTarget, key, value, context);
461
- },
462
- set() {
463
- throwReadonlyAnnotationMutation();
464
- },
465
- defineProperty() {
466
- throwReadonlyAnnotationMutation();
467
- },
468
- deleteProperty() {
469
- throwReadonlyAnnotationMutation();
470
- },
471
- setPrototypeOf() {
472
- throwReadonlyAnnotationMutation();
473
- },
474
- preventExtensions() {
475
- throwReadonlyAnnotationMutation();
476
- }
477
- });
478
- registerProtectedAnnotationView(context, target, view);
479
- cacheProtectedAnnotationViewAlias(context, cloned, view);
480
- copyRegExpMetadata(target, cloned, (value) => protectAnnotationValue(value, context), syncPrototype);
481
- return view;
482
- }
483
- function createProtectedURLSearchParamsView(target, context) {
484
- const syncPrototype = !hasBuiltInSubclassPrototype(target, URLSearchParams.prototype);
485
- const methodCache = /* @__PURE__ */ new Map();
486
- const cloned = syncPrototype ? new URLSearchParams(target) : tryCloneURLSearchParamsSubclass(target) ?? new URLSearchParams(target);
487
- const view = new Proxy(cloned, {
488
- get(clonedTarget, key) {
489
- if (key === "append" || key === "delete" || key === "set" || key === "sort") return cacheProtectedMethod(methodCache, key, () => (..._args) => throwReadonlyAnnotationMutation());
490
- if (key === "valueOf") return cacheProtectedMethod(methodCache, key, () => () => view);
491
- if (key === "forEach") return cacheProtectedMethod(methodCache, key, () => (callback, thisArg) => clonedTarget.forEach((value$1, name) => {
492
- callback.call(thisArg, value$1, name, view);
493
- }));
494
- if (key === "keys" || key === "values") return cacheProtectedMethod(methodCache, key, () => function* () {
495
- const iterator = key === "keys" ? clonedTarget.keys() : clonedTarget.values();
496
- for (const value$1 of iterator) yield value$1;
497
- });
498
- if (key === "entries" || key === Symbol.iterator) return cacheProtectedMethod(methodCache, key, () => function* () {
499
- for (const entry of clonedTarget.entries()) yield entry;
500
- });
501
- const value = Reflect.get(clonedTarget, key, clonedTarget);
502
- return getProtectedClonePropertyValue(methodCache, clonedTarget, key, value, context);
503
- },
504
- set() {
505
- throwReadonlyAnnotationMutation();
506
- },
507
- defineProperty() {
508
- throwReadonlyAnnotationMutation();
509
- },
510
- deleteProperty() {
511
- throwReadonlyAnnotationMutation();
512
- },
513
- setPrototypeOf() {
514
- throwReadonlyAnnotationMutation();
515
- },
516
- preventExtensions() {
517
- throwReadonlyAnnotationMutation();
518
- }
519
- });
520
- registerProtectedAnnotationView(context, target, view);
521
- cacheProtectedAnnotationViewAlias(context, cloned, view);
522
- copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
523
- installReadonlyMutationMethodGuards(cloned, urlSearchParamsMutationMethodKeys);
524
- return view;
525
- }
526
- function createProtectedURLView(target, context) {
527
- const syncPrototype = !hasBuiltInSubclassPrototype(target, URL.prototype);
528
- const methodCache = /* @__PURE__ */ new Map();
529
- const cloned = syncPrototype ? new URL(target.href) : tryCloneURLSubclass(target) ?? new URL(target.href);
530
- const view = new Proxy(cloned, {
531
- get(clonedTarget, key) {
532
- if (key === "valueOf") return cacheProtectedMethod(methodCache, key, () => () => view);
533
- if (key === "searchParams") return protectAnnotationValue(clonedTarget.searchParams, context);
534
- const value = Reflect.get(clonedTarget, key, clonedTarget);
535
- return getProtectedClonePropertyValue(methodCache, clonedTarget, key, value, context);
536
- },
537
- set() {
538
- throwReadonlyAnnotationMutation();
539
- },
540
- defineProperty() {
541
- throwReadonlyAnnotationMutation();
542
- },
543
- deleteProperty() {
544
- throwReadonlyAnnotationMutation();
545
- },
546
- setPrototypeOf() {
547
- throwReadonlyAnnotationMutation();
548
- },
549
- preventExtensions() {
550
- throwReadonlyAnnotationMutation();
551
- }
552
- });
553
- registerProtectedAnnotationView(context, target, view);
554
- cacheProtectedAnnotationViewAlias(context, cloned, view);
555
- copyOwnProperties(target, cloned, (value) => protectAnnotationValue(value, context), void 0, syncPrototype);
556
- installReadonlyURLGuards(cloned, context);
557
- return view;
558
- }
559
- function protectAnnotationValue(value, context) {
560
- if (value == null || typeof value !== "object") return value;
561
- const isProtectedView = isProtectedAnnotationView(value);
562
- if (isProtectedView && !context.rewrapProtectedViews) return value;
563
- const target = isProtectedView ? unwrapProtectedAnnotationTarget(value) : value;
564
- const cached = context.cache.get(target);
565
- if (cached !== void 0) return cached;
566
- if (target instanceof Map) return createProtectedMapView(target, context);
567
- if (target instanceof Set) return createProtectedSetView(target, context);
568
- if (target instanceof Date) return createProtectedDateView(target, context);
569
- if (target instanceof RegExp) return createProtectedRegExpView(target, context);
570
- if (typeof URLSearchParams === "function" && target instanceof URLSearchParams) return createProtectedURLSearchParamsView(target, context);
571
- if (typeof URL === "function" && target instanceof URL) return createProtectedURLView(target, context);
572
- if (Array.isArray(target)) return createProtectedObjectView(target, context);
573
- const proto = Object.getPrototypeOf(target);
574
- if (proto === Object.prototype || proto === null) return createProtectedObjectView(target, context);
575
- return value;
576
- }
577
- /**
578
- * Normalizes annotation input for a fresh parse run.
579
- *
580
- * When callers feed a protected annotation view returned by `getAnnotations()`
581
- * back into a new parse entrypoint, Optique unwraps it to the caller-owned
582
- * record first so the new run gets its own protected views.
583
- *
584
- * @param annotations The caller-supplied annotations input.
585
- * @returns The raw annotation record to inject for the new run.
586
- * @internal
587
- */
588
- function normalizeRunAnnotationInput(annotations) {
589
- return isProtectedAnnotationView(annotations) ? unwrapProtectedAnnotationTarget(annotations) : annotations;
590
- }
591
- function injectAnnotationsWithContext(state, annotations, context) {
592
- const protectedAnnotations = protectAnnotationValue(annotations, context);
593
- if (state == null || typeof state !== "object") {
594
- const wrapper = {};
595
- Object.defineProperties(wrapper, {
596
- [annotationKey]: {
597
- value: protectedAnnotations,
598
- enumerable: true,
599
- writable: true,
600
- configurable: true
601
- },
602
- [annotationStateValueKey]: {
603
- value: state,
604
- enumerable: false,
605
- writable: true,
606
- configurable: true
607
- },
608
- [annotationWrapperKey]: {
609
- value: true,
610
- enumerable: false,
611
- writable: true,
612
- configurable: true
613
- }
614
- });
615
- injectedAnnotationWrappers.add(wrapper);
616
- return wrapper;
617
- }
618
- if (Array.isArray(state)) {
619
- const cloned$1 = [...state];
620
- cloned$1[annotationKey] = protectedAnnotations;
621
- return cloned$1;
622
- }
623
- if (isInjectedAnnotationWrapper(state)) {
624
- const cloned$1 = Object.create(Object.getPrototypeOf(state), Object.getOwnPropertyDescriptors(state));
625
- cloned$1[annotationKey] = protectedAnnotations;
626
- injectedAnnotationWrappers.add(cloned$1);
627
- return cloned$1;
628
- }
629
- if (state instanceof Date) {
630
- const cloned$1 = tryCloneDateSubclass(state) ?? new Date(state.getTime());
631
- cloned$1[annotationKey] = protectedAnnotations;
632
- return cloned$1;
633
- }
634
- if (state instanceof Map) {
635
- const cloned$1 = tryCloneMapSubclass(state, state) ?? new Map(state);
636
- cloned$1[annotationKey] = protectedAnnotations;
637
- return cloned$1;
638
- }
639
- if (state instanceof Set) {
640
- const cloned$1 = tryCloneSetSubclass(state, state) ?? new Set(state);
641
- cloned$1[annotationKey] = protectedAnnotations;
642
- return cloned$1;
643
- }
644
- if (state instanceof RegExp) {
645
- const cloned$1 = cloneRegExpShape(state);
646
- cloned$1[annotationKey] = protectedAnnotations;
647
- return cloned$1;
648
- }
649
- const proto = Object.getPrototypeOf(state);
650
- if (proto === Object.prototype || proto === null) return {
651
- ...state,
652
- [annotationKey]: protectedAnnotations
653
- };
654
- const cloned = Object.create(proto, Object.getOwnPropertyDescriptors(state));
655
- cloned[annotationKey] = protectedAnnotations;
656
- return cloned;
657
- }
658
47
  /**
659
48
  * Extracts annotations from parser state.
660
49
  *
661
50
  * @param state Parser state that may contain annotations
662
- * @returns Read-only annotations view or undefined if no annotations are
663
- * present
51
+ * @returns Annotations object or undefined if no annotations are present
664
52
  * @since 0.10.0
665
- * @since 1.0.0 Returns protected read-only annotation views instead of
666
- * caller-owned objects.
667
53
  *
668
54
  * @example
669
55
  * ```typescript
@@ -675,17 +61,7 @@ function getAnnotations(state) {
675
61
  if (state == null || typeof state !== "object") return void 0;
676
62
  const stateObj = state;
677
63
  const annotations = stateObj[annotationKey];
678
- if (annotations != null && typeof annotations === "object") {
679
- if (isProtectedAnnotationView(annotations)) return annotations;
680
- const cached = protectedAnnotationStateViews.get(stateObj);
681
- if (cached?.raw === annotations) return cached.view;
682
- const protectedView = protectAnnotationValue(annotations, createAnnotationProtectionContext());
683
- protectedAnnotationStateViews.set(stateObj, {
684
- raw: annotations,
685
- view: protectedView
686
- });
687
- return protectedView;
688
- }
64
+ if (annotations != null && typeof annotations === "object") return annotations;
689
65
  return void 0;
690
66
  }
691
67
  /**
@@ -729,22 +105,22 @@ function inheritAnnotations(source, target) {
729
105
  return cloned$1;
730
106
  }
731
107
  if (target instanceof Date) {
732
- const cloned$1 = tryCloneDateSubclass(target) ?? new Date(target.getTime());
108
+ const cloned$1 = new Date(target.getTime());
733
109
  cloned$1[annotationKey] = annotations;
734
110
  return cloned$1;
735
111
  }
736
112
  if (target instanceof Map) {
737
- const cloned$1 = tryCloneMapSubclass(target, target) ?? new Map(target);
113
+ const cloned$1 = new Map(target);
738
114
  cloned$1[annotationKey] = annotations;
739
115
  return cloned$1;
740
116
  }
741
117
  if (target instanceof Set) {
742
- const cloned$1 = tryCloneSetSubclass(target, target) ?? new Set(target);
118
+ const cloned$1 = new Set(target);
743
119
  cloned$1[annotationKey] = annotations;
744
120
  return cloned$1;
745
121
  }
746
122
  if (target instanceof RegExp) {
747
- const cloned$1 = cloneRegExpShape(target);
123
+ const cloned$1 = new RegExp(target);
748
124
  cloned$1[annotationKey] = annotations;
749
125
  return cloned$1;
750
126
  }
@@ -786,22 +162,68 @@ function hasMeaningfulAnnotations(annotations) {
786
162
  */
787
163
  function injectAnnotations(state, annotations) {
788
164
  if (!hasMeaningfulAnnotations(annotations)) return state;
789
- return injectAnnotationsWithContext(state, annotations, createAnnotationProtectionContext());
790
- }
791
- /**
792
- * Injects annotations for a fresh parse run.
793
- *
794
- * This path re-wraps protected views from previous runs so stateful container
795
- * internals remain isolated across parse entrypoints.
796
- *
797
- * @param state The parser state to annotate.
798
- * @param annotations The annotations to inject.
799
- * @returns Annotated state for the fresh run.
800
- * @internal
801
- */
802
- function injectFreshRunAnnotations(state, annotations) {
803
- if (!hasMeaningfulAnnotations(annotations)) return state;
804
- return injectAnnotationsWithContext(state, normalizeRunAnnotationInput(annotations), createAnnotationProtectionContext(true));
165
+ if (state == null || typeof state !== "object") {
166
+ const wrapper = {};
167
+ Object.defineProperties(wrapper, {
168
+ [annotationKey]: {
169
+ value: annotations,
170
+ enumerable: true,
171
+ writable: true,
172
+ configurable: true
173
+ },
174
+ [annotationStateValueKey]: {
175
+ value: state,
176
+ enumerable: false,
177
+ writable: true,
178
+ configurable: true
179
+ },
180
+ [annotationWrapperKey]: {
181
+ value: true,
182
+ enumerable: false,
183
+ writable: true,
184
+ configurable: true
185
+ }
186
+ });
187
+ injectedAnnotationWrappers.add(wrapper);
188
+ return wrapper;
189
+ }
190
+ if (Array.isArray(state)) {
191
+ const cloned$1 = [...state];
192
+ cloned$1[annotationKey] = annotations;
193
+ return cloned$1;
194
+ }
195
+ if (isInjectedAnnotationWrapper(state)) {
196
+ state[annotationKey] = annotations;
197
+ return state;
198
+ }
199
+ if (state instanceof Date) {
200
+ const cloned$1 = new Date(state.getTime());
201
+ cloned$1[annotationKey] = annotations;
202
+ return cloned$1;
203
+ }
204
+ if (state instanceof Map) {
205
+ const cloned$1 = new Map(state);
206
+ cloned$1[annotationKey] = annotations;
207
+ return cloned$1;
208
+ }
209
+ if (state instanceof Set) {
210
+ const cloned$1 = new Set(state);
211
+ cloned$1[annotationKey] = annotations;
212
+ return cloned$1;
213
+ }
214
+ if (state instanceof RegExp) {
215
+ const cloned$1 = new RegExp(state);
216
+ cloned$1[annotationKey] = annotations;
217
+ return cloned$1;
218
+ }
219
+ const proto = Object.getPrototypeOf(state);
220
+ if (proto === Object.prototype || proto === null) return {
221
+ ...state,
222
+ [annotationKey]: annotations
223
+ };
224
+ const cloned = Object.create(proto, Object.getOwnPropertyDescriptors(state));
225
+ cloned[annotationKey] = annotations;
226
+ return cloned;
805
227
  }
806
228
  /**
807
229
  * Unwraps a primitive-state annotation wrapper injected by Optique internals.
@@ -832,4 +254,4 @@ function isInjectedAnnotationWrapper(value) {
832
254
  }
833
255
 
834
256
  //#endregion
835
- export { annotateFreshArray, annotationKey, annotationStateValueKey, annotationWrapperKey, firstPassAnnotationKey, getAnnotations, hasMeaningfulAnnotations, inheritAnnotations, injectAnnotations, injectFreshRunAnnotations, isInjectedAnnotationWrapper, normalizeRunAnnotationInput, unwrapInjectedAnnotationWrapper };
257
+ export { annotateFreshArray, annotationKey, annotationStateValueKey, annotationWrapperKey, firstPassAnnotationKey, getAnnotations, hasMeaningfulAnnotations, inheritAnnotations, injectAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper };