postext-folio 0.52.2 → 0.52.4
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/pageFlip/constants.d.ts +28 -0
- package/dist/pageFlip/constants.d.ts.map +1 -0
- package/dist/pageFlip/constants.js +31 -0
- package/dist/pageFlip/constants.js.map +1 -0
- package/dist/pageFlip/leaf.d.ts +125 -0
- package/dist/pageFlip/leaf.d.ts.map +1 -0
- package/dist/pageFlip/leaf.js +327 -0
- package/dist/pageFlip/leaf.js.map +1 -0
- package/dist/pageFlip/materials.d.ts +176 -0
- package/dist/pageFlip/materials.d.ts.map +1 -0
- package/dist/pageFlip/materials.js +362 -0
- package/dist/pageFlip/materials.js.map +1 -0
- package/dist/pageFlip/occlusion.d.ts +44 -0
- package/dist/pageFlip/occlusion.d.ts.map +1 -0
- package/dist/pageFlip/occlusion.js +202 -0
- package/dist/pageFlip/occlusion.js.map +1 -0
- package/dist/pageFlip.d.ts +4 -73
- package/dist/pageFlip.d.ts.map +1 -1
- package/dist/pageFlip.js +20 -911
- package/dist/pageFlip.js.map +1 -1
- package/dist/pageFlipFlat/leaf.d.ts +79 -0
- package/dist/pageFlipFlat/leaf.d.ts.map +1 -0
- package/dist/pageFlipFlat/leaf.js +100 -0
- package/dist/pageFlipFlat/leaf.js.map +1 -0
- package/dist/pageFlipFlat/shaders.d.ts +30 -0
- package/dist/pageFlipFlat/shaders.d.ts.map +1 -0
- package/dist/pageFlipFlat/shaders.js +214 -0
- package/dist/pageFlipFlat/shaders.js.map +1 -0
- package/dist/pageFlipFlat.d.ts +1 -1
- package/dist/pageFlipFlat.d.ts.map +1 -1
- package/dist/pageFlipFlat.js +4 -310
- package/dist/pageFlipFlat.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// The book's ambient occlusion from its height map, the key light's soft
|
|
2
|
+
// shadow with a receiver-plane bias, and the caster copies of the meshes
|
|
3
|
+
// drawn into the map (#1276: split out of pageFlip.ts).
|
|
4
|
+
import { Vector4, ShaderChunk, BufferGeometry, ShaderMaterial, DoubleSide, CustomBlending, MaxEquation, OneFactor } from 'three';
|
|
5
|
+
// Ambient occlusion from the book's own shape: each frame the book is
|
|
6
|
+
// drawn, seen from straight above, into a height map: channel r the
|
|
7
|
+
// highest of everything (blocks, covers, open pages, leaves), channel g the
|
|
8
|
+
// leaves in the air alone. A point is occluded by paper rising round it,
|
|
9
|
+
// more the nearer and higher it is: the book's contact shadow on the desk
|
|
10
|
+
// and the dark under a lifted leaf. The open pages read only the leaves'
|
|
11
|
+
// channel (their gutter is worked out from the cross-section).
|
|
12
|
+
export const OCCLUSION = /* glsl */ `
|
|
13
|
+
uniform sampler2D uShadowMap;
|
|
14
|
+
uniform vec4 uShadowBox;
|
|
15
|
+
uniform float uShadowOn;
|
|
16
|
+
uniform float uOccRadius;
|
|
17
|
+
uniform float uOccBias;
|
|
18
|
+
float casterAt(vec2 s, float channel) {
|
|
19
|
+
vec2 uv = (s - uShadowBox.xy) / uShadowBox.zw;
|
|
20
|
+
if (uv.x < 0.0 || uv.y < 0.0 || uv.x > 1.0 || uv.y > 1.0) return -1e4;
|
|
21
|
+
vec4 t = texture2D(uShadowMap, uv);
|
|
22
|
+
return (channel > 0.5 ? t.g : t.r) - 10.0;
|
|
23
|
+
}
|
|
24
|
+
// Horizon-based: in each of 8 directions, the highest paper seen from p
|
|
25
|
+
// (as an elevation angle) hides that much of the sky: sin(horizon) of a
|
|
26
|
+
// cosine-weighted slice.
|
|
27
|
+
float bookOcclusion(vec3 p, float channel) {
|
|
28
|
+
if (uShadowOn < 0.5) return 0.0;
|
|
29
|
+
float spin = fract(sin(dot(gl_FragCoord.xy, vec2(12.9898, 78.233))) * 43758.5453);
|
|
30
|
+
float occ = 0.0;
|
|
31
|
+
for (int d = 0; d < 8; d++) {
|
|
32
|
+
float a = (float(d) + spin) * 0.785398;
|
|
33
|
+
vec2 dir = vec2(cos(a), sin(a));
|
|
34
|
+
float horizon = 0.0;
|
|
35
|
+
for (int i = 0; i < 4; i++) {
|
|
36
|
+
float t = (float(i) + 0.25 + 0.5 * spin) / 4.0;
|
|
37
|
+
float r = t * t * uOccRadius + 1.0;
|
|
38
|
+
float h = casterAt(p.xy + r * dir, channel) - p.z - uOccBias;
|
|
39
|
+
horizon = max(horizon, h / sqrt(h * h + r * r));
|
|
40
|
+
}
|
|
41
|
+
occ += horizon;
|
|
42
|
+
}
|
|
43
|
+
return occ / 8.0;
|
|
44
|
+
}
|
|
45
|
+
// How far the reflection seen at p runs under paper: its ray marched
|
|
46
|
+
// out through the height map (a lifted leaf hides what it would mirror,
|
|
47
|
+
// and so does the leaf's own roll over the inside of its curl). The
|
|
48
|
+
// march starts a few px out, past the paper round p itself. Its steps
|
|
49
|
+
// are shifted a little from pixel to pixel: at fixed steps the leaf's
|
|
50
|
+
// outline was cut in at each of them, a row of teeth (#483).
|
|
51
|
+
float reflectionOcclusion(vec3 p, vec3 r, float channel) {
|
|
52
|
+
if (uShadowOn < 0.5) return 0.0;
|
|
53
|
+
// Interleaved gradient noise: neighbours take evenly spread shifts.
|
|
54
|
+
float spin = fract(52.9829189 * fract(dot(gl_FragCoord.xy, vec2(0.06711056, 0.00583715))));
|
|
55
|
+
float hidden = 0.0;
|
|
56
|
+
for (int i = 0; i < 8; i++) {
|
|
57
|
+
float s = (float(i) + spin) / 8.0;
|
|
58
|
+
float t = 6.0 + s * s * uOccRadius * 2.0;
|
|
59
|
+
vec3 q = p + r * t;
|
|
60
|
+
hidden = max(hidden, smoothstep(0.0, 4.0, casterAt(q.xy, channel) - q.z - uOccBias));
|
|
61
|
+
}
|
|
62
|
+
return hidden;
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
/** Declares the book position varying in a vertex shader and sets it:
|
|
66
|
+
* the world position with the mirror of a right-bound book undone. */
|
|
67
|
+
export const BOOK_POS_PARS = "uniform float uSign;\nvarying vec3 vBookPos;";
|
|
68
|
+
export const BOOK_POS = "vBookPos = (modelMatrix * vec4(transformed, 1.0)).xyz;\nvBookPos.x *= uSign;";
|
|
69
|
+
// The casters lie outside the stage, in the book's own coordinates (as
|
|
70
|
+
// `vBookPos` reads the map): no mirror here (#334).
|
|
71
|
+
const CASTER_VERTEX = /* glsl */ `
|
|
72
|
+
varying float vZ;
|
|
73
|
+
void main() {
|
|
74
|
+
vec4 w = modelMatrix * vec4(position, 1.0);
|
|
75
|
+
vZ = w.z;
|
|
76
|
+
gl_Position = projectionMatrix * viewMatrix * vec4(w.xy, 0.0, 1.0);
|
|
77
|
+
}
|
|
78
|
+
`;
|
|
79
|
+
const CASTER_FRAGMENT = /* glsl */ `
|
|
80
|
+
uniform float uLeaf;
|
|
81
|
+
varying float vZ;
|
|
82
|
+
void main() {
|
|
83
|
+
gl_FragColor = vec4(vZ + 10.0, uLeaf * (vZ + 10.0), 0.0, 1.0);
|
|
84
|
+
}
|
|
85
|
+
`;
|
|
86
|
+
/** The occlusion uniforms every receiving material shares (same objects). */
|
|
87
|
+
export const occlusionUniforms = {
|
|
88
|
+
uShadowMap: { value: null },
|
|
89
|
+
uShadowBox: { value: new Vector4(0, 0, 1, 1) },
|
|
90
|
+
uShadowOn: { value: 0 },
|
|
91
|
+
uOccRadius: { value: 60 },
|
|
92
|
+
uOccBias: { value: 1 },
|
|
93
|
+
};
|
|
94
|
+
// The key light's soft shadow, each of its samples compared against the
|
|
95
|
+
// receiver's own plane carried to that sample (receiver-plane depth bias):
|
|
96
|
+
// three.js compares them all at the receiver's depth, so a sheet steep to
|
|
97
|
+
// the light, a leaf in the air, found itself nearer the light a few texels
|
|
98
|
+
// away and fell in its own shadow (#330). The shadow is kept (`keyShadow`)
|
|
99
|
+
// so the reflections can be cut with it too.
|
|
100
|
+
const SHADOW_PCF_HEAD = "float getShadow( sampler2DShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {";
|
|
101
|
+
const SHADOW_PCF = /* glsl */ `
|
|
102
|
+
${SHADOW_PCF_HEAD}
|
|
103
|
+
shadowCoord.xyz /= shadowCoord.w;
|
|
104
|
+
shadowCoord.z += shadowBias;
|
|
105
|
+
// How the receiver's depth in the map runs with the map's uv.
|
|
106
|
+
vec3 sx = dFdx(shadowCoord.xyz);
|
|
107
|
+
vec3 sy = dFdy(shadowCoord.xyz);
|
|
108
|
+
float det = sx.x * sy.y - sx.y * sy.x;
|
|
109
|
+
vec2 slope = abs(det) > 1e-12 ? vec2(sy.y * sx.z - sx.y * sy.z, sx.x * sy.z - sy.x * sx.z) / det : vec2(0.0);
|
|
110
|
+
float shadow = 1.0;
|
|
111
|
+
if (shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0 && shadowCoord.z <= 1.0) {
|
|
112
|
+
float radius = shadowRadius / shadowMapSize.x;
|
|
113
|
+
float phi = interleavedGradientNoise(gl_FragCoord.xy) * PI2;
|
|
114
|
+
shadow = 0.0;
|
|
115
|
+
for (int i = 0; i < 5; i++) {
|
|
116
|
+
vec2 o = vogelDiskSample(i, 5, phi) * radius;
|
|
117
|
+
// Held in where the plane runs nearly along the light.
|
|
118
|
+
float dz = clamp(dot(slope, o), -0.05, 0.05);
|
|
119
|
+
shadow += texture(shadowMap, vec3(shadowCoord.xy + o, shadowCoord.z + dz));
|
|
120
|
+
}
|
|
121
|
+
shadow *= 0.2;
|
|
122
|
+
}
|
|
123
|
+
keyShadow = shadow;
|
|
124
|
+
return mix(1.0, shadow, shadowIntensity);
|
|
125
|
+
}
|
|
126
|
+
`;
|
|
127
|
+
const SHADOW_PARS = (() => {
|
|
128
|
+
const chunk = ShaderChunk.shadowmap_pars_fragment;
|
|
129
|
+
const start = chunk.indexOf(SHADOW_PCF_HEAD);
|
|
130
|
+
const end = chunk.indexOf("#elif defined( SHADOWMAP_TYPE_VSM )", start);
|
|
131
|
+
// Another three.js: its own shadows (no receiver plane).
|
|
132
|
+
const pars = start < 0 || end < 0 ? chunk : chunk.slice(0, start) + SHADOW_PCF + chunk.slice(end);
|
|
133
|
+
return `float keyShadow = 1.0;\n${pars}`;
|
|
134
|
+
})();
|
|
135
|
+
/** How much of the environment's reflection the key's shadow takes away:
|
|
136
|
+
* the key stands where the environment's brightest emitter is, so what
|
|
137
|
+
* hides it from a point hides that emitter's reflection too. */
|
|
138
|
+
export function keySpecular(occlusion = "1.0") {
|
|
139
|
+
return /* glsl */ `{
|
|
140
|
+
float keySpec = mix(1.0, keyShadow, 0.85) * (${occlusion});
|
|
141
|
+
reflectedLight.indirectSpecular *= keySpec;
|
|
142
|
+
#ifdef USE_CLEARCOAT
|
|
143
|
+
clearcoatSpecularIndirect *= keySpec;
|
|
144
|
+
#endif
|
|
145
|
+
#ifdef USE_SHEEN
|
|
146
|
+
sheenSpecularIndirect *= keySpec;
|
|
147
|
+
#endif
|
|
148
|
+
}`;
|
|
149
|
+
}
|
|
150
|
+
/** Gives a material the key's shadow on its own plane. */
|
|
151
|
+
export function keyShadowed(fragmentShader) {
|
|
152
|
+
return fragmentShader.replace("#include <shadowmap_pars_fragment>", SHADOW_PARS);
|
|
153
|
+
}
|
|
154
|
+
/** A caster's own copy of a mesh's shape. The height map is drawn before
|
|
155
|
+
* the main view, and three.js uploads a geometry once per frame number,
|
|
156
|
+
* which the key's shadow pass at the end of the last main view had
|
|
157
|
+
* already taken: a caster sharing a leaf's geometry drew the leaf where
|
|
158
|
+
* it lay a frame before, and a leaf moving down was shaded by its own
|
|
159
|
+
* old self, moving up it was not (#488). */
|
|
160
|
+
export function casterGeometry(source) {
|
|
161
|
+
const g = new BufferGeometry();
|
|
162
|
+
g.setAttribute("position", source.attributes.position.clone());
|
|
163
|
+
if (source.index)
|
|
164
|
+
g.setIndex(source.index.clone());
|
|
165
|
+
return g;
|
|
166
|
+
}
|
|
167
|
+
/** Brings a caster's copy to its mesh's shape as laid out this frame. */
|
|
168
|
+
export function syncCaster(caster, source) {
|
|
169
|
+
const to = caster.geometry.attributes.position;
|
|
170
|
+
to.array.set(source.attributes.position.array);
|
|
171
|
+
to.needsUpdate = true;
|
|
172
|
+
}
|
|
173
|
+
export function casterMaterial(leaf) {
|
|
174
|
+
return new ShaderMaterial({
|
|
175
|
+
vertexShader: CASTER_VERTEX,
|
|
176
|
+
fragmentShader: CASTER_FRAGMENT,
|
|
177
|
+
side: DoubleSide,
|
|
178
|
+
blending: CustomBlending,
|
|
179
|
+
blendEquation: MaxEquation,
|
|
180
|
+
blendEquationAlpha: MaxEquation,
|
|
181
|
+
blendSrc: OneFactor,
|
|
182
|
+
blendDst: OneFactor,
|
|
183
|
+
depthTest: false,
|
|
184
|
+
depthWrite: false,
|
|
185
|
+
uniforms: { uLeaf: { value: leaf ? 1 : 0 } },
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
/** A standard material (the desk, the covers) with the book's occlusion
|
|
189
|
+
* on its ambient light. */
|
|
190
|
+
export function occluded(m, sign) {
|
|
191
|
+
m.onBeforeCompile = (shader) => {
|
|
192
|
+
Object.assign(shader.uniforms, occlusionUniforms, { uSign: { value: sign } });
|
|
193
|
+
shader.vertexShader = shader.vertexShader
|
|
194
|
+
.replace("#include <common>", `#include <common>\n${BOOK_POS_PARS}`)
|
|
195
|
+
.replace("#include <begin_vertex>", `#include <begin_vertex>\n${BOOK_POS}`);
|
|
196
|
+
shader.fragmentShader = keyShadowed(shader.fragmentShader)
|
|
197
|
+
.replace("#include <common>", `#include <common>\nvarying vec3 vBookPos;\n${OCCLUSION}`)
|
|
198
|
+
.replace("#include <aomap_fragment>", "#include <aomap_fragment>\n{ float occ = 1.0 - bookOcclusion(vBookPos, 0.0); reflectedLight.indirectDiffuse *= occ; reflectedLight.indirectSpecular *= occ; }\n" + keySpecular());
|
|
199
|
+
};
|
|
200
|
+
return m;
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=occlusion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"occlusion.js","sourceRoot":"","sources":["../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,MAAM,CAAC,cAAc,CAAC;aACvD,OAAO,CAAC,mBAAmB,EAAE,8CAA8C,SAAS,EAAE,CAAC;aACvF,OAAO,CACN,2BAA2B,EAC3B,iKAAiK,GAAG,WAAW,EAAE,CAClL,CAAC;IACN,CAAC,CAAC;IACF,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/dist/pageFlip.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { type FolioConfig, type FolioPaperConfig } from 'postext';
|
|
2
|
+
export { BLOCK_PAGES } from './pageFlip/constants.js';
|
|
3
|
+
export { withStockForExtent } from './pageFlip/materials.js';
|
|
4
|
+
export { foldOf, progressFrom, layLeaf, pagePlane } from './pageFlip/leaf.js';
|
|
4
5
|
/** A page: an image URL, or a canvas or a decoded image to draw; "" is a
|
|
5
6
|
* blank page (drawn as paper), null no page at all. */
|
|
6
7
|
export type PageSource = string | HTMLCanvasElement | HTMLImageElement | null;
|
|
@@ -78,75 +79,6 @@ export interface FlipAppearance {
|
|
|
78
79
|
* saddle-stitched book has no spine and shows none. */
|
|
79
80
|
spineImage?: PageSource;
|
|
80
81
|
}
|
|
81
|
-
/** A jump of more pages than this is made in one move: the block of
|
|
82
|
-
* leaves in between is lifted together and laid over on the other side,
|
|
83
|
-
* instead of every leaf turning on its own. */
|
|
84
|
-
export declare const BLOCK_PAGES = 10;
|
|
85
|
-
/**
|
|
86
|
-
* The stock a publisher would print a book of `pages` pages on, when its
|
|
87
|
-
* settings name none: a long book goes on lighter paper, a very long one
|
|
88
|
-
* on bible paper (2,000 pages make a volume about 4.5 cm thick, not 11).
|
|
89
|
-
* Settings that name a stock, a grammage or a bulk are kept as they are.
|
|
90
|
-
*/
|
|
91
|
-
export declare function withStockForExtent(folio: FolioConfig | undefined, pages: number): FolioConfig | undefined;
|
|
92
|
-
/** A point in a leaf's own coordinates: `u` from the spine (0 … W), `v`
|
|
93
|
-
* from the middle of the page (−H/2 … H/2). Backward turns mirror x. */
|
|
94
|
-
interface Pt {
|
|
95
|
-
u: number;
|
|
96
|
-
v: number;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* How a leaf folds when the point `G` of it has been carried to `P`: the
|
|
100
|
-
* paper stays flat up to a fold line, rolls round a cylinder of radius R
|
|
101
|
-
* and lies over itself beyond it, back up (the page-curl cylinder). The
|
|
102
|
-
* fold is square to the pull, placed so the point taken lands under the
|
|
103
|
-
* hand, and never crosses the spine the leaf is sewn to. R grows as the
|
|
104
|
-
* page lifts and shrinks to nothing as it lands on the other side; a
|
|
105
|
-
* stiffer paper (`roll`) bends in a wider roll.
|
|
106
|
-
*/
|
|
107
|
-
export declare function foldOf(G: Pt, P: Pt, W: number, H: number, roll?: number): {
|
|
108
|
-
F: {
|
|
109
|
-
u: number;
|
|
110
|
-
v: number;
|
|
111
|
-
};
|
|
112
|
-
n: {
|
|
113
|
-
u: number;
|
|
114
|
-
v: number;
|
|
115
|
-
};
|
|
116
|
-
R: number;
|
|
117
|
-
theta: number;
|
|
118
|
-
} | null;
|
|
119
|
-
type Fold = NonNullable<ReturnType<typeof foldOf>>;
|
|
120
|
-
/** How far through its turn a leaf is: the point taken, from where it
|
|
121
|
-
* was to its mirror image across the spine. */
|
|
122
|
-
export declare function progressFrom(G: Pt, P: Pt): number;
|
|
123
|
-
/** The open book's two surfaces, which a leaf lies on at rest. */
|
|
124
|
-
interface Surfaces {
|
|
125
|
-
left: Profile;
|
|
126
|
-
right: Profile;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Lays a leaf's mesh out. The curl is worked out on the flat page (u from
|
|
130
|
-
* the spine), then wrapped onto the book: the part on the right follows
|
|
131
|
-
* the right stack's top (into the gutter and out), the part carried over
|
|
132
|
-
* the spine the left one's. A stiff leaf (`rigidity`) turns more as a
|
|
133
|
-
* plate on its hinge: a board does not bend at all.
|
|
134
|
-
*/
|
|
135
|
-
export declare function layLeaf(geometry: BufferGeometry, fold: Fold | null, forward: boolean, W: number, H: number, lift: number, book: Surfaces, rigidity: number, q: number, flutter?: number, time?: number, board?: {
|
|
136
|
-
thick: number;
|
|
137
|
-
face: number;
|
|
138
|
-
}): {
|
|
139
|
-
phi: number;
|
|
140
|
-
pivot: number;
|
|
141
|
-
};
|
|
142
|
-
/**
|
|
143
|
-
* The plane an open page lies in past the gutter's shoulder (world,
|
|
144
|
-
* normal up), its side running out from the spine along world x as
|
|
145
|
-
* `out` (±1): level on a block lying on the desk, sloping down to it on
|
|
146
|
-
* the thin side of a thick book, which hangs from the top of the spine.
|
|
147
|
-
* A gloss page mirrors the leaves in the air in it (#483).
|
|
148
|
-
*/
|
|
149
|
-
export declare function pagePlane(p: Profile, W: number, out: number): Plane;
|
|
150
82
|
/**
|
|
151
83
|
* Turns the pages of the viewer's DOM spread in a 3D scene: the book lies
|
|
152
84
|
* open on a desk, seen from in front and above (tilted by `folio.tilt`),
|
|
@@ -539,5 +471,4 @@ export declare class PageFlipper {
|
|
|
539
471
|
}
|
|
540
472
|
/** WebGL is there and the reader has not asked for less motion. */
|
|
541
473
|
export declare function canFlip(): boolean;
|
|
542
|
-
export {};
|
|
543
474
|
//# sourceMappingURL=pageFlip.d.ts.map
|
package/dist/pageFlip.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pageFlip.d.ts","sourceRoot":"","sources":["../src/pageFlip.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pageFlip.d.ts","sourceRoot":"","sources":["../src/pageFlip.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAgD,MAAM,SAAS,CAAC;AAahH,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,o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