@optique/core 1.0.0-dev.1893 → 1.0.0-dev.1895
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/dist/annotation-state.cjs +31 -17
- package/dist/annotation-state.js +32 -18
- package/package.json +1 -1
|
@@ -87,6 +87,11 @@ function normalizeDelegatedAnnotationState(state) {
|
|
|
87
87
|
function hasDelegatedAnnotationCarrier(state) {
|
|
88
88
|
return state != null && typeof state === "object" && (require_annotations.isInjectedAnnotationWrapper(state) || annotationViewTargets.has(state));
|
|
89
89
|
}
|
|
90
|
+
function isPendingNestedNormalizationAlias(originalValue, normalizedValue, seen) {
|
|
91
|
+
if (originalValue == null || typeof originalValue !== "object") return false;
|
|
92
|
+
const entry = seen.get(originalValue);
|
|
93
|
+
return entry != null && !entry.finalized && entry.clone === normalizedValue;
|
|
94
|
+
}
|
|
90
95
|
/**
|
|
91
96
|
* Recursively removes delegated annotation carriers from plain-object and array
|
|
92
97
|
* structures.
|
|
@@ -107,30 +112,39 @@ function normalizeNestedDelegatedAnnotationState(value, seen = /* @__PURE__ */ n
|
|
|
107
112
|
const normalized = normalizeDelegatedAnnotationState(value);
|
|
108
113
|
if (normalized == null || typeof normalized !== "object") return normalized;
|
|
109
114
|
const source = normalized;
|
|
110
|
-
|
|
115
|
+
const existing = seen.get(source);
|
|
116
|
+
if (existing != null) return existing.finalized ? existing.result : existing.clone;
|
|
111
117
|
if (Array.isArray(source)) {
|
|
112
118
|
let changed$1 = false;
|
|
113
|
-
const clone$1 =
|
|
114
|
-
|
|
119
|
+
const clone$1 = require_annotations.annotateFreshArray(source, source.slice());
|
|
120
|
+
const entry$1 = {
|
|
121
|
+
clone: clone$1,
|
|
122
|
+
finalized: false,
|
|
123
|
+
result: clone$1
|
|
124
|
+
};
|
|
125
|
+
seen.set(source, entry$1);
|
|
115
126
|
for (let i = 0; i < source.length; i++) {
|
|
116
127
|
const nextValue = normalizeNestedDelegatedAnnotationState(source[i], seen);
|
|
117
128
|
if (nextValue !== source[i]) {
|
|
118
129
|
clone$1[i] = nextValue;
|
|
119
|
-
changed$1 = true;
|
|
130
|
+
if (!isPendingNestedNormalizationAlias(source[i], nextValue, seen)) changed$1 = true;
|
|
120
131
|
}
|
|
121
132
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
return clone$1;
|
|
133
|
+
entry$1.finalized = true;
|
|
134
|
+
entry$1.result = changed$1 ? clone$1 : source;
|
|
135
|
+
return changed$1 ? clone$1 : source;
|
|
127
136
|
}
|
|
128
137
|
const proto = Object.getPrototypeOf(source);
|
|
129
138
|
if (proto !== Object.prototype && proto !== null) return normalized;
|
|
130
139
|
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
131
140
|
let changed = false;
|
|
132
141
|
const clone = Object.create(proto);
|
|
133
|
-
|
|
142
|
+
const entry = {
|
|
143
|
+
clone,
|
|
144
|
+
finalized: false,
|
|
145
|
+
result: clone
|
|
146
|
+
};
|
|
147
|
+
seen.set(source, entry);
|
|
134
148
|
for (const key of Reflect.ownKeys(descriptors)) {
|
|
135
149
|
const descriptor = descriptors[key];
|
|
136
150
|
if (descriptor != null && "value" in descriptor) {
|
|
@@ -140,14 +154,13 @@ function normalizeNestedDelegatedAnnotationState(value, seen = /* @__PURE__ */ n
|
|
|
140
154
|
...descriptor,
|
|
141
155
|
value: nextValue
|
|
142
156
|
};
|
|
143
|
-
changed = true;
|
|
157
|
+
if (!isPendingNestedNormalizationAlias(descriptor.value, nextValue, seen)) changed = true;
|
|
144
158
|
}
|
|
145
159
|
}
|
|
146
160
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
161
|
+
entry.finalized = true;
|
|
162
|
+
entry.result = changed ? clone : source;
|
|
163
|
+
if (!changed) return source;
|
|
151
164
|
Object.defineProperties(clone, descriptors);
|
|
152
165
|
return clone;
|
|
153
166
|
}
|
|
@@ -167,9 +180,10 @@ function normalizeNestedDelegatedAnnotationState(value, seen = /* @__PURE__ */ n
|
|
|
167
180
|
*/
|
|
168
181
|
function getDelegatedAnnotationState(parentState, childState) {
|
|
169
182
|
const annotations = require_annotations.getAnnotations(parentState);
|
|
170
|
-
if (annotations === void 0
|
|
171
|
-
if (childState == null || typeof childState !== "object") return require_annotations.injectAnnotations(childState, annotations);
|
|
183
|
+
if (annotations === void 0) return childState;
|
|
172
184
|
if (require_annotations.isInjectedAnnotationWrapper(childState)) return require_annotations.injectAnnotations(normalizeInjectedAnnotationState(childState), annotations);
|
|
185
|
+
if (require_annotations.getAnnotations(childState) === annotations) return childState;
|
|
186
|
+
if (childState == null || typeof childState !== "object") return require_annotations.injectAnnotations(childState, annotations);
|
|
173
187
|
if (isNonPlainDelegatedObject(childState)) return withAnnotationView(childState, annotations);
|
|
174
188
|
return require_annotations.inheritAnnotations(parentState, childState);
|
|
175
189
|
}
|
package/dist/annotation-state.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { annotationKey, getAnnotations, inheritAnnotations, injectAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./annotations.js";
|
|
1
|
+
import { annotateFreshArray, annotationKey, getAnnotations, inheritAnnotations, injectAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./annotations.js";
|
|
2
2
|
import { inheritParentAnnotationsKey } from "./parser.js";
|
|
3
3
|
|
|
4
4
|
//#region src/annotation-state.ts
|
|
@@ -87,6 +87,11 @@ function normalizeDelegatedAnnotationState(state) {
|
|
|
87
87
|
function hasDelegatedAnnotationCarrier(state) {
|
|
88
88
|
return state != null && typeof state === "object" && (isInjectedAnnotationWrapper(state) || annotationViewTargets.has(state));
|
|
89
89
|
}
|
|
90
|
+
function isPendingNestedNormalizationAlias(originalValue, normalizedValue, seen) {
|
|
91
|
+
if (originalValue == null || typeof originalValue !== "object") return false;
|
|
92
|
+
const entry = seen.get(originalValue);
|
|
93
|
+
return entry != null && !entry.finalized && entry.clone === normalizedValue;
|
|
94
|
+
}
|
|
90
95
|
/**
|
|
91
96
|
* Recursively removes delegated annotation carriers from plain-object and array
|
|
92
97
|
* structures.
|
|
@@ -107,30 +112,39 @@ function normalizeNestedDelegatedAnnotationState(value, seen = /* @__PURE__ */ n
|
|
|
107
112
|
const normalized = normalizeDelegatedAnnotationState(value);
|
|
108
113
|
if (normalized == null || typeof normalized !== "object") return normalized;
|
|
109
114
|
const source = normalized;
|
|
110
|
-
|
|
115
|
+
const existing = seen.get(source);
|
|
116
|
+
if (existing != null) return existing.finalized ? existing.result : existing.clone;
|
|
111
117
|
if (Array.isArray(source)) {
|
|
112
118
|
let changed$1 = false;
|
|
113
|
-
const clone$1 =
|
|
114
|
-
|
|
119
|
+
const clone$1 = annotateFreshArray(source, source.slice());
|
|
120
|
+
const entry$1 = {
|
|
121
|
+
clone: clone$1,
|
|
122
|
+
finalized: false,
|
|
123
|
+
result: clone$1
|
|
124
|
+
};
|
|
125
|
+
seen.set(source, entry$1);
|
|
115
126
|
for (let i = 0; i < source.length; i++) {
|
|
116
127
|
const nextValue = normalizeNestedDelegatedAnnotationState(source[i], seen);
|
|
117
128
|
if (nextValue !== source[i]) {
|
|
118
129
|
clone$1[i] = nextValue;
|
|
119
|
-
changed$1 = true;
|
|
130
|
+
if (!isPendingNestedNormalizationAlias(source[i], nextValue, seen)) changed$1 = true;
|
|
120
131
|
}
|
|
121
132
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
return clone$1;
|
|
133
|
+
entry$1.finalized = true;
|
|
134
|
+
entry$1.result = changed$1 ? clone$1 : source;
|
|
135
|
+
return changed$1 ? clone$1 : source;
|
|
127
136
|
}
|
|
128
137
|
const proto = Object.getPrototypeOf(source);
|
|
129
138
|
if (proto !== Object.prototype && proto !== null) return normalized;
|
|
130
139
|
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
131
140
|
let changed = false;
|
|
132
141
|
const clone = Object.create(proto);
|
|
133
|
-
|
|
142
|
+
const entry = {
|
|
143
|
+
clone,
|
|
144
|
+
finalized: false,
|
|
145
|
+
result: clone
|
|
146
|
+
};
|
|
147
|
+
seen.set(source, entry);
|
|
134
148
|
for (const key of Reflect.ownKeys(descriptors)) {
|
|
135
149
|
const descriptor = descriptors[key];
|
|
136
150
|
if (descriptor != null && "value" in descriptor) {
|
|
@@ -140,14 +154,13 @@ function normalizeNestedDelegatedAnnotationState(value, seen = /* @__PURE__ */ n
|
|
|
140
154
|
...descriptor,
|
|
141
155
|
value: nextValue
|
|
142
156
|
};
|
|
143
|
-
changed = true;
|
|
157
|
+
if (!isPendingNestedNormalizationAlias(descriptor.value, nextValue, seen)) changed = true;
|
|
144
158
|
}
|
|
145
159
|
}
|
|
146
160
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
161
|
+
entry.finalized = true;
|
|
162
|
+
entry.result = changed ? clone : source;
|
|
163
|
+
if (!changed) return source;
|
|
151
164
|
Object.defineProperties(clone, descriptors);
|
|
152
165
|
return clone;
|
|
153
166
|
}
|
|
@@ -167,9 +180,10 @@ function normalizeNestedDelegatedAnnotationState(value, seen = /* @__PURE__ */ n
|
|
|
167
180
|
*/
|
|
168
181
|
function getDelegatedAnnotationState(parentState, childState) {
|
|
169
182
|
const annotations = getAnnotations(parentState);
|
|
170
|
-
if (annotations === void 0
|
|
171
|
-
if (childState == null || typeof childState !== "object") return injectAnnotations(childState, annotations);
|
|
183
|
+
if (annotations === void 0) return childState;
|
|
172
184
|
if (isInjectedAnnotationWrapper(childState)) return injectAnnotations(normalizeInjectedAnnotationState(childState), annotations);
|
|
185
|
+
if (getAnnotations(childState) === annotations) return childState;
|
|
186
|
+
if (childState == null || typeof childState !== "object") return injectAnnotations(childState, annotations);
|
|
173
187
|
if (isNonPlainDelegatedObject(childState)) return withAnnotationView(childState, annotations);
|
|
174
188
|
return inheritAnnotations(parentState, childState);
|
|
175
189
|
}
|