paperlab 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +154 -45
- package/dist/{chunk-3IMUEESH.js → chunk-4ZU5DZEF.js} +1705 -1807
- package/dist/chunk-4ZU5DZEF.js.map +1 -0
- package/dist/index.cjs +493 -748
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +419 -1874
- package/dist/index.d.ts +419 -1874
- package/dist/index.js +183 -431
- package/dist/index.js.map +1 -1
- package/dist/{slots-D0Nc_5dq.d.cts → slots-BYoLxVZ4.d.cts} +3 -656
- package/dist/{slots-D0Nc_5dq.d.ts → slots-BYoLxVZ4.d.ts} +3 -656
- package/dist/stage.cjs +3 -17
- package/dist/stage.cjs.map +1 -1
- package/dist/stage.d.cts +2 -178
- package/dist/stage.d.ts +2 -178
- package/dist/stage.js +1 -8
- package/package.json +1 -1
- package/dist/chunk-3IMUEESH.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,187 +1,70 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AGENT_PAYLOAD_VERSION,
|
|
3
3
|
AUTO_CEILING,
|
|
4
|
-
ClothSim,
|
|
5
4
|
DropZone,
|
|
6
|
-
DropZoneRegistry,
|
|
7
5
|
FLAT_SEGMENTS,
|
|
8
6
|
LightRig,
|
|
9
|
-
ON_TWOS_FPS,
|
|
10
7
|
PaperFallback,
|
|
11
8
|
PaperField,
|
|
12
9
|
PaperFieldMesh,
|
|
13
10
|
PaperLighting,
|
|
14
|
-
PaperMaterial,
|
|
15
11
|
PaperMesh,
|
|
16
12
|
PaperMirror,
|
|
17
|
-
PaperStateMachine,
|
|
18
13
|
SAG_TOL,
|
|
19
|
-
SHEET_LIFT,
|
|
20
|
-
TRANSMISSION_GAIN,
|
|
21
|
-
accordion,
|
|
22
|
-
applyDeformerStack,
|
|
23
|
-
atlasGrid,
|
|
24
|
-
backContentSchema,
|
|
25
|
-
barcodeBars,
|
|
26
14
|
behaviorConfigSchema,
|
|
27
|
-
bend,
|
|
28
|
-
bendOptionsSchema,
|
|
29
|
-
book,
|
|
30
15
|
buildAgentPayload,
|
|
31
16
|
buildDisplacementGLSL,
|
|
32
|
-
buildFieldFragmentShader,
|
|
33
|
-
buildFieldVertexShader,
|
|
34
17
|
buildJsxSnippet,
|
|
35
|
-
cardContentSchema,
|
|
36
|
-
carry,
|
|
37
|
-
carryDrive,
|
|
38
|
-
carryOptionsSchema,
|
|
39
18
|
clothConfigSchema,
|
|
40
|
-
colonnade,
|
|
41
|
-
composeSurface,
|
|
42
|
-
contentSchema,
|
|
43
|
-
contentText,
|
|
44
19
|
coreStateNames,
|
|
45
|
-
cornerNames,
|
|
46
|
-
createSheetGeometry,
|
|
47
|
-
crumple,
|
|
48
|
-
crumpleBehavior,
|
|
49
|
-
crumpleBehaviorOptionsSchema,
|
|
50
|
-
crumpleOptionsSchema,
|
|
51
|
-
curl,
|
|
52
|
-
curlOptionsSchema,
|
|
53
|
-
dampTo,
|
|
54
|
-
deformerInstanceSchema,
|
|
55
20
|
describeConfig,
|
|
56
21
|
diffConfig,
|
|
57
22
|
displacePoint,
|
|
58
|
-
drape,
|
|
59
|
-
drapeOptionsSchema,
|
|
60
|
-
drawBacking,
|
|
61
|
-
fall,
|
|
62
|
-
fallOptionsSchema,
|
|
63
|
-
fan,
|
|
64
|
-
fieldBounds,
|
|
65
|
-
fieldKeyboardStep,
|
|
66
|
-
filmNames,
|
|
67
|
-
fitCamera,
|
|
68
|
-
flattenNumeric,
|
|
69
|
-
flight,
|
|
70
|
-
flightOptionsSchema,
|
|
71
|
-
flightPose,
|
|
72
|
-
flip,
|
|
73
|
-
flipOptionsSchema,
|
|
74
|
-
fly,
|
|
75
|
-
flyOptionsSchema,
|
|
76
|
-
fold,
|
|
77
|
-
foldOptionsSchema,
|
|
78
23
|
getBehavior,
|
|
79
24
|
getDeformer,
|
|
80
|
-
getIdlePreset,
|
|
81
25
|
getLayout,
|
|
82
|
-
getLightingPreset,
|
|
83
26
|
getPreset,
|
|
84
27
|
getStock,
|
|
85
|
-
groupFieldPapers,
|
|
86
|
-
gust,
|
|
87
|
-
hang,
|
|
88
|
-
hangOptionsSchema,
|
|
89
28
|
idleNames,
|
|
90
|
-
idlePresets,
|
|
91
29
|
isBuiltinPreset,
|
|
92
|
-
letterFold,
|
|
93
|
-
letterFoldOptionsSchema,
|
|
94
30
|
lightAngles,
|
|
95
|
-
lightPosition,
|
|
96
31
|
lightSchema,
|
|
97
|
-
lightenHex,
|
|
98
32
|
lightingNames,
|
|
99
|
-
lightingPresets,
|
|
100
33
|
listBehaviors,
|
|
101
34
|
listDeformers,
|
|
102
35
|
listLayouts,
|
|
103
36
|
listPresets,
|
|
104
|
-
makeGoboTexture,
|
|
105
37
|
mergeConfig,
|
|
106
38
|
mergeWithDeletes,
|
|
107
|
-
outwardCorner,
|
|
108
39
|
paperConfigSchema,
|
|
109
40
|
paperEdges,
|
|
110
41
|
paperStatesSchema,
|
|
111
42
|
parsePreset,
|
|
112
|
-
peel,
|
|
113
|
-
peelOptionsSchema,
|
|
114
43
|
physicsNames,
|
|
115
|
-
physicsSchema,
|
|
116
|
-
pile,
|
|
117
|
-
quantizeProgress,
|
|
118
44
|
quantizeSegments,
|
|
119
|
-
quantizeTime,
|
|
120
|
-
rack,
|
|
121
|
-
receiptContentSchema,
|
|
122
|
-
receiptTotals,
|
|
123
45
|
recordStateOverride,
|
|
124
46
|
registerBehavior,
|
|
125
47
|
registerDeformer,
|
|
126
48
|
registerLayout,
|
|
127
49
|
registerPreset,
|
|
128
|
-
resolveConfig,
|
|
129
|
-
resolveDeformerStack,
|
|
130
|
-
resolveFieldSlotConfig,
|
|
131
50
|
resolveLighting,
|
|
132
|
-
resolveSegments,
|
|
133
51
|
resolveStateConfig,
|
|
134
|
-
ribbon,
|
|
135
|
-
ribbonOptionsSchema,
|
|
136
|
-
ring,
|
|
137
|
-
roll,
|
|
138
|
-
rollOptionsSchema,
|
|
139
|
-
sceneSchema,
|
|
140
52
|
segmentsForArc,
|
|
141
53
|
segmentsForSine,
|
|
142
54
|
serializePreset,
|
|
143
|
-
settle,
|
|
144
|
-
settleOptionsSchema,
|
|
145
|
-
sheet,
|
|
146
|
-
sheetBackingSize,
|
|
147
55
|
sheetLayoutSchema,
|
|
148
|
-
sheetSchema,
|
|
149
|
-
sheetSlotXY,
|
|
150
|
-
silhouetteRects,
|
|
151
56
|
spanAlong,
|
|
152
|
-
spill,
|
|
153
|
-
spread,
|
|
154
|
-
stackAutoSegments,
|
|
155
|
-
stackMinSegments,
|
|
156
|
-
stackUniformValues,
|
|
157
57
|
stateDefSchema,
|
|
158
|
-
stateEventTransitions,
|
|
159
|
-
stateTransitionSchema,
|
|
160
58
|
stockNames,
|
|
161
|
-
stockSchema,
|
|
162
59
|
stocks,
|
|
163
|
-
stripStates,
|
|
164
60
|
supportsWebGL,
|
|
165
|
-
surfaceSchema,
|
|
166
|
-
sweep,
|
|
167
|
-
tornEdgesOnDetach,
|
|
168
|
-
translucencyUniforms,
|
|
169
|
-
translucencyValues,
|
|
170
61
|
uniquePresetName,
|
|
171
62
|
unregisterPreset,
|
|
172
|
-
unroll,
|
|
173
|
-
unrollOptionsSchema,
|
|
174
|
-
useContentAtlas,
|
|
175
63
|
usePaperStates,
|
|
176
64
|
usePrefersReducedMotion,
|
|
177
65
|
useResolvedConfig,
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
waveOptionsSchema,
|
|
181
|
-
withSheetCellFromPaper,
|
|
182
|
-
wrapLines,
|
|
183
|
-
zoneAccepts
|
|
184
|
-
} from "./chunk-3IMUEESH.js";
|
|
66
|
+
wrapLines
|
|
67
|
+
} from "./chunk-4ZU5DZEF.js";
|
|
185
68
|
|
|
186
69
|
// src/Paper.tsx
|
|
187
70
|
import { Canvas } from "@react-three/fiber";
|
|
@@ -208,6 +91,184 @@ var Paper = forwardRef(function Paper2({ children, className, style, ...meshProp
|
|
|
208
91
|
] });
|
|
209
92
|
});
|
|
210
93
|
|
|
94
|
+
// src/config/field-export.ts
|
|
95
|
+
var MOTION_DEFAULTS = { driver: "autoplay", speed: 0.5 };
|
|
96
|
+
var ENTRANCE_DEFAULTS = { type: "rise", stagger: 0.06, duration: 0.9 };
|
|
97
|
+
function camel(name) {
|
|
98
|
+
const id = name.replace(/[^a-zA-Z0-9]+(.)/g, (_, c) => c.toUpperCase()).replace(/[^a-zA-Z0-9]/g, "");
|
|
99
|
+
const safe = /^[A-Za-z]/.test(id) ? id : `preset${id}`;
|
|
100
|
+
return safe.charAt(0).toLowerCase() + safe.slice(1);
|
|
101
|
+
}
|
|
102
|
+
function distinctFieldPresets(input) {
|
|
103
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
104
|
+
const usedNames = /* @__PURE__ */ new Set();
|
|
105
|
+
for (const paper of input.papers) {
|
|
106
|
+
const key = JSON.stringify(paper.preset);
|
|
107
|
+
if (byKey.has(key)) continue;
|
|
108
|
+
let varName = camel(paper.presetName);
|
|
109
|
+
while (usedNames.has(varName)) varName += "2";
|
|
110
|
+
usedNames.add(varName);
|
|
111
|
+
byKey.set(key, { varName, presetName: paper.presetName, preset: paper.preset });
|
|
112
|
+
}
|
|
113
|
+
return [...byKey.values()];
|
|
114
|
+
}
|
|
115
|
+
function nonDefault(value, defaults) {
|
|
116
|
+
const out = {};
|
|
117
|
+
for (const [k, v] of Object.entries(value ?? {})) {
|
|
118
|
+
if (v !== void 0 && v !== defaults[k]) out[k] = v;
|
|
119
|
+
}
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
function diffFieldProps(input) {
|
|
123
|
+
const out = { layout: input.layout };
|
|
124
|
+
const layout = getLayout(input.layout);
|
|
125
|
+
const layoutOptions = nonDefault(input.layoutOptions ?? {}, layout.defaults);
|
|
126
|
+
if (Object.keys(layoutOptions).length > 0) out.layoutOptions = layoutOptions;
|
|
127
|
+
const motion = nonDefault(input.motion, MOTION_DEFAULTS);
|
|
128
|
+
if (Object.keys(motion).length > 0) out.motion = motion;
|
|
129
|
+
const entrance = nonDefault(input.entrance, ENTRANCE_DEFAULTS);
|
|
130
|
+
if (Object.keys(entrance).length > 0) out.entrance = entrance;
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
var LAYOUT_PHRASES = {
|
|
134
|
+
ring: "a ring you can see around",
|
|
135
|
+
fan: "a fanned swatch deck hinged at one corner",
|
|
136
|
+
spread: "a stack slid sideways, each sheet bowing further than the last",
|
|
137
|
+
pile: "a heap on a desk, the sheets underneath pressed flat",
|
|
138
|
+
wall: "a pinned studio wall of sheets, none hanging quite square",
|
|
139
|
+
spill: "a dropped stack caught mid-air, each sheet bent its own way",
|
|
140
|
+
sweep: "a specimen chart of one sheet at every stage of its deformation",
|
|
141
|
+
book: "an open book, its pages splayed from a shared spine",
|
|
142
|
+
accordion: "one continuous strip folded into a concertina",
|
|
143
|
+
rack: "prints stood in a row and leaning back against a wall",
|
|
144
|
+
sheet: "a stamp-block grid on a shared backing sheet"
|
|
145
|
+
};
|
|
146
|
+
function describeFieldConfig(input) {
|
|
147
|
+
const n = input.papers.length;
|
|
148
|
+
const stateful = input.papers.some((p) => p.preset.states || p.states);
|
|
149
|
+
const zones = input.zones ?? [];
|
|
150
|
+
const parts = [];
|
|
151
|
+
if (input.layout === "sheet") {
|
|
152
|
+
const rows = Number(input.layoutOptions?.rows ?? 2);
|
|
153
|
+
const columns = Number(input.layoutOptions?.columns ?? 5);
|
|
154
|
+
parts.push(`a ${rows}\xD7${columns} sheet of papers on a shared backing`);
|
|
155
|
+
} else {
|
|
156
|
+
const layoutPhrase = LAYOUT_PHRASES[input.layout] ?? `a ${input.layout} layout`;
|
|
157
|
+
parts.push(`${n} papers arranged in ${layoutPhrase}`);
|
|
158
|
+
}
|
|
159
|
+
const driver = input.motion?.driver ?? "autoplay";
|
|
160
|
+
if (stateful) {
|
|
161
|
+
parts.push("hovering peels/reacts per paper (interaction states)");
|
|
162
|
+
if (zones.length > 0) {
|
|
163
|
+
parts.push(
|
|
164
|
+
`dragging one past its tear threshold detaches it to carry to the ${zones.map((z) => z.id).join(" or ")} zone (release elsewhere flutters it back)`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
if (driver === "autoplay") parts.push("slowly orbiting on their own");
|
|
169
|
+
if (driver === "drag") parts.push("draggable sideways with the pointer");
|
|
170
|
+
if (zones.length > 0) parts.push(`${zones.length} drop zone${zones.length > 1 ? "s" : ""}`);
|
|
171
|
+
}
|
|
172
|
+
const distinct = distinctFieldPresets(input);
|
|
173
|
+
if (distinct.length > 1) {
|
|
174
|
+
parts.push(`mixing ${distinct.length} paper presets (${distinct.map((d) => d.presetName).join(", ")})`);
|
|
175
|
+
}
|
|
176
|
+
return parts.join(", ");
|
|
177
|
+
}
|
|
178
|
+
function buildFieldComponentSource(input) {
|
|
179
|
+
const distinct = distinctFieldPresets(input);
|
|
180
|
+
const varByKey = new Map(distinct.map((d) => [JSON.stringify(d.preset), d.varName]));
|
|
181
|
+
const consts = distinct.map(
|
|
182
|
+
(d) => `const ${d.varName} = ${JSON.stringify(diffConfig(d.preset), null, 2)} satisfies PaperConfigInput`
|
|
183
|
+
).join("\n\n");
|
|
184
|
+
const slots = input.papers.map((paper) => {
|
|
185
|
+
const varName = varByKey.get(JSON.stringify(paper.preset));
|
|
186
|
+
const content = paper.content ? `, content: ${JSON.stringify(paper.content)}` : "";
|
|
187
|
+
const states = paper.states ? `, states: ${JSON.stringify(paper.states)}` : "";
|
|
188
|
+
return ` { preset: ${varName}${content}${states} },`;
|
|
189
|
+
}).join("\n");
|
|
190
|
+
const props = Object.entries(diffFieldProps(input)).map(
|
|
191
|
+
([key, value]) => typeof value === "string" ? ` ${key}="${value}"` : ` ${key}={${JSON.stringify(value)}}`
|
|
192
|
+
).join("\n");
|
|
193
|
+
const zones = input.zones ?? [];
|
|
194
|
+
const zoneImport = zones.length > 0 ? ", DropZone" : "";
|
|
195
|
+
const zoneChildren = zones.map((zone) => {
|
|
196
|
+
const accept = zone.accept ? ` accept={${JSON.stringify(zone.accept)}}` : "";
|
|
197
|
+
const highlight = zone.highlight && zone.highlight !== "glow" ? ` highlight="${zone.highlight}"` : "";
|
|
198
|
+
return ` <DropZone
|
|
199
|
+
id="${zone.id}"${accept}
|
|
200
|
+
bounds={${JSON.stringify(zone.bounds)}}${highlight}
|
|
201
|
+
onPlace={(paper, zone) => {
|
|
202
|
+
// First-run smoke test \u2014 you should see this in the console on drop:
|
|
203
|
+
console.log(paper.presetName, '\u2192', zone.id)
|
|
204
|
+
// Then replace it: stamp a postmark, advance the flow, persist the placement, \u2026
|
|
205
|
+
}}
|
|
206
|
+
/>`;
|
|
207
|
+
}).join("\n");
|
|
208
|
+
if (zones.length === 0) {
|
|
209
|
+
return `import { PaperField, type FieldPaperSlot, type PaperConfigInput${zoneImport} } from 'paperlab'
|
|
210
|
+
|
|
211
|
+
${consts}
|
|
212
|
+
|
|
213
|
+
const papers: FieldPaperSlot[] = [
|
|
214
|
+
${slots}
|
|
215
|
+
]
|
|
216
|
+
|
|
217
|
+
export function PaperGallery() {
|
|
218
|
+
return (
|
|
219
|
+
<PaperField
|
|
220
|
+
papers={papers}
|
|
221
|
+
${props}
|
|
222
|
+
/>
|
|
223
|
+
)
|
|
224
|
+
}`;
|
|
225
|
+
}
|
|
226
|
+
return `import { PaperField, type FieldPaperSlot, type PaperConfigInput${zoneImport} } from 'paperlab'
|
|
227
|
+
|
|
228
|
+
${consts}
|
|
229
|
+
|
|
230
|
+
const papers: FieldPaperSlot[] = [
|
|
231
|
+
${slots}
|
|
232
|
+
]
|
|
233
|
+
|
|
234
|
+
export function PaperGallery() {
|
|
235
|
+
return (
|
|
236
|
+
<PaperField
|
|
237
|
+
papers={papers}
|
|
238
|
+
${props}
|
|
239
|
+
>
|
|
240
|
+
${zoneChildren}
|
|
241
|
+
</PaperField>
|
|
242
|
+
)
|
|
243
|
+
}`;
|
|
244
|
+
}
|
|
245
|
+
function buildFieldAgentPayload(input) {
|
|
246
|
+
return `Integrate a Paperlab paper gallery into this project. (paperlab agent-payload v${AGENT_PAYLOAD_VERSION})
|
|
247
|
+
|
|
248
|
+
1. Install the dependencies:
|
|
249
|
+
|
|
250
|
+
npm i paperlab three @react-three/fiber gsap
|
|
251
|
+
|
|
252
|
+
2. Create the component below as \`components/PaperGallery.tsx\` (or the
|
|
253
|
+
project's component convention). It is self-contained \u2014 every preset it
|
|
254
|
+
uses is inlined, and it owns its own <Canvas>:
|
|
255
|
+
|
|
256
|
+
\`\`\`tsx
|
|
257
|
+
${buildFieldComponentSource(input)}
|
|
258
|
+
\`\`\`
|
|
259
|
+
|
|
260
|
+
3. Sizing: the component fills its parent container. Place it where I ask;
|
|
261
|
+
give the parent an explicit height.
|
|
262
|
+
|
|
263
|
+
4. Verify: run the dev server. You should see ${describeFieldConfig(input)}.
|
|
264
|
+
If the canvas is blank, the parent container almost certainly has no height \u2014
|
|
265
|
+
give it one (this is the classic React Three Fiber integration bug, not a
|
|
266
|
+
paperlab bug).
|
|
267
|
+
|
|
268
|
+
Constraints: don't modify the preset values; three >= 0.160 and React 19 are
|
|
269
|
+
required; the component needs no props.`;
|
|
270
|
+
}
|
|
271
|
+
|
|
211
272
|
// src/field/parity.ts
|
|
212
273
|
import * as THREE from "three";
|
|
213
274
|
var GRID = 48;
|
|
@@ -374,8 +435,8 @@ var parityCases = [
|
|
|
374
435
|
t: 0.8
|
|
375
436
|
}
|
|
376
437
|
];
|
|
377
|
-
function buildParityFragment(stack,
|
|
378
|
-
const composed = buildDisplacementGLSL(stack,
|
|
438
|
+
function buildParityFragment(stack, sheet) {
|
|
439
|
+
const composed = buildDisplacementGLSL(stack, sheet);
|
|
379
440
|
return (
|
|
380
441
|
/* glsl */
|
|
381
442
|
`#version 300 es
|
|
@@ -508,382 +569,73 @@ function runParityHarness(canvas) {
|
|
|
508
569
|
});
|
|
509
570
|
return [...parity, ...runBiasCases(gl)];
|
|
510
571
|
}
|
|
511
|
-
|
|
512
|
-
// src/config/field-export.ts
|
|
513
|
-
var MOTION_DEFAULTS = { driver: "autoplay", speed: 0.5 };
|
|
514
|
-
var ENTRANCE_DEFAULTS = { type: "rise", stagger: 0.06, duration: 0.9 };
|
|
515
|
-
function camel(name) {
|
|
516
|
-
const id = name.replace(/[^a-zA-Z0-9]+(.)/g, (_, c) => c.toUpperCase()).replace(/[^a-zA-Z0-9]/g, "");
|
|
517
|
-
const safe = /^[A-Za-z]/.test(id) ? id : `preset${id}`;
|
|
518
|
-
return safe.charAt(0).toLowerCase() + safe.slice(1);
|
|
519
|
-
}
|
|
520
|
-
function distinctFieldPresets(input) {
|
|
521
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
522
|
-
const usedNames = /* @__PURE__ */ new Set();
|
|
523
|
-
for (const paper of input.papers) {
|
|
524
|
-
const key = JSON.stringify(paper.preset);
|
|
525
|
-
if (byKey.has(key)) continue;
|
|
526
|
-
let varName = camel(paper.presetName);
|
|
527
|
-
while (usedNames.has(varName)) varName += "2";
|
|
528
|
-
usedNames.add(varName);
|
|
529
|
-
byKey.set(key, { varName, presetName: paper.presetName, preset: paper.preset });
|
|
530
|
-
}
|
|
531
|
-
return [...byKey.values()];
|
|
532
|
-
}
|
|
533
|
-
function nonDefault(value, defaults) {
|
|
534
|
-
const out = {};
|
|
535
|
-
for (const [k, v] of Object.entries(value ?? {})) {
|
|
536
|
-
if (v !== void 0 && v !== defaults[k]) out[k] = v;
|
|
537
|
-
}
|
|
538
|
-
return out;
|
|
539
|
-
}
|
|
540
|
-
function diffFieldProps(input) {
|
|
541
|
-
const out = { layout: input.layout };
|
|
542
|
-
const layout = getLayout(input.layout);
|
|
543
|
-
const layoutOptions = nonDefault(input.layoutOptions ?? {}, layout.defaults);
|
|
544
|
-
if (Object.keys(layoutOptions).length > 0) out.layoutOptions = layoutOptions;
|
|
545
|
-
const motion = nonDefault(input.motion, MOTION_DEFAULTS);
|
|
546
|
-
if (Object.keys(motion).length > 0) out.motion = motion;
|
|
547
|
-
const entrance = nonDefault(input.entrance, ENTRANCE_DEFAULTS);
|
|
548
|
-
if (Object.keys(entrance).length > 0) out.entrance = entrance;
|
|
549
|
-
return out;
|
|
550
|
-
}
|
|
551
|
-
var LAYOUT_PHRASES = {
|
|
552
|
-
ring: "a ring you can see around",
|
|
553
|
-
fan: "a fanned swatch deck hinged at one corner",
|
|
554
|
-
spread: "a stack slid sideways, each sheet bowing further than the last",
|
|
555
|
-
pile: "a heap on a desk, the sheets underneath pressed flat",
|
|
556
|
-
wall: "a pinned studio wall of sheets, none hanging quite square",
|
|
557
|
-
spill: "a dropped stack caught mid-air, each sheet bent its own way",
|
|
558
|
-
sweep: "a specimen chart of one sheet at every stage of its deformation",
|
|
559
|
-
book: "an open book, its pages splayed from a shared spine",
|
|
560
|
-
accordion: "one continuous strip folded into a concertina",
|
|
561
|
-
rack: "prints stood in a row and leaning back against a wall",
|
|
562
|
-
sheet: "a stamp-block grid on a shared backing sheet"
|
|
563
|
-
};
|
|
564
|
-
function describeFieldConfig(input) {
|
|
565
|
-
const n = input.papers.length;
|
|
566
|
-
const stateful = input.papers.some((p) => p.preset.states || p.states);
|
|
567
|
-
const zones = input.zones ?? [];
|
|
568
|
-
const parts = [];
|
|
569
|
-
if (input.layout === "sheet") {
|
|
570
|
-
const rows = Number(input.layoutOptions?.rows ?? 2);
|
|
571
|
-
const columns = Number(input.layoutOptions?.columns ?? 5);
|
|
572
|
-
parts.push(`a ${rows}\xD7${columns} sheet of papers on a shared backing`);
|
|
573
|
-
} else {
|
|
574
|
-
const layoutPhrase = LAYOUT_PHRASES[input.layout] ?? `a ${input.layout} layout`;
|
|
575
|
-
parts.push(`${n} papers arranged in ${layoutPhrase}`);
|
|
576
|
-
}
|
|
577
|
-
const driver = input.motion?.driver ?? "autoplay";
|
|
578
|
-
if (stateful) {
|
|
579
|
-
parts.push("hovering peels/reacts per paper (interaction states)");
|
|
580
|
-
if (zones.length > 0) {
|
|
581
|
-
parts.push(
|
|
582
|
-
`dragging one past its tear threshold detaches it to carry to the ${zones.map((z) => z.id).join(" or ")} zone (release elsewhere flutters it back)`
|
|
583
|
-
);
|
|
584
|
-
}
|
|
585
|
-
} else {
|
|
586
|
-
if (driver === "autoplay") parts.push("slowly orbiting on their own");
|
|
587
|
-
if (driver === "drag") parts.push("draggable sideways with the pointer");
|
|
588
|
-
if (zones.length > 0) parts.push(`${zones.length} drop zone${zones.length > 1 ? "s" : ""}`);
|
|
589
|
-
}
|
|
590
|
-
const distinct = distinctFieldPresets(input);
|
|
591
|
-
if (distinct.length > 1) {
|
|
592
|
-
parts.push(`mixing ${distinct.length} paper presets (${distinct.map((d) => d.presetName).join(", ")})`);
|
|
593
|
-
}
|
|
594
|
-
return parts.join(", ");
|
|
595
|
-
}
|
|
596
|
-
function buildFieldComponentSource(input) {
|
|
597
|
-
const distinct = distinctFieldPresets(input);
|
|
598
|
-
const varByKey = new Map(distinct.map((d) => [JSON.stringify(d.preset), d.varName]));
|
|
599
|
-
const consts = distinct.map(
|
|
600
|
-
(d) => `const ${d.varName} = ${JSON.stringify(diffConfig(d.preset), null, 2)} satisfies PaperConfigInput`
|
|
601
|
-
).join("\n\n");
|
|
602
|
-
const slots = input.papers.map((paper) => {
|
|
603
|
-
const varName = varByKey.get(JSON.stringify(paper.preset));
|
|
604
|
-
const content = paper.content ? `, content: ${JSON.stringify(paper.content)}` : "";
|
|
605
|
-
const states = paper.states ? `, states: ${JSON.stringify(paper.states)}` : "";
|
|
606
|
-
return ` { preset: ${varName}${content}${states} },`;
|
|
607
|
-
}).join("\n");
|
|
608
|
-
const props = Object.entries(diffFieldProps(input)).map(
|
|
609
|
-
([key, value]) => typeof value === "string" ? ` ${key}="${value}"` : ` ${key}={${JSON.stringify(value)}}`
|
|
610
|
-
).join("\n");
|
|
611
|
-
const zones = input.zones ?? [];
|
|
612
|
-
const zoneImport = zones.length > 0 ? ", DropZone" : "";
|
|
613
|
-
const zoneChildren = zones.map((zone) => {
|
|
614
|
-
const accept = zone.accept ? ` accept={${JSON.stringify(zone.accept)}}` : "";
|
|
615
|
-
const highlight = zone.highlight && zone.highlight !== "glow" ? ` highlight="${zone.highlight}"` : "";
|
|
616
|
-
return ` <DropZone
|
|
617
|
-
id="${zone.id}"${accept}
|
|
618
|
-
bounds={${JSON.stringify(zone.bounds)}}${highlight}
|
|
619
|
-
onPlace={(paper, zone) => {
|
|
620
|
-
// First-run smoke test \u2014 you should see this in the console on drop:
|
|
621
|
-
console.log(paper.presetName, '\u2192', zone.id)
|
|
622
|
-
// Then replace it: stamp a postmark, advance the flow, persist the placement, \u2026
|
|
623
|
-
}}
|
|
624
|
-
/>`;
|
|
625
|
-
}).join("\n");
|
|
626
|
-
if (zones.length === 0) {
|
|
627
|
-
return `import { PaperField, type FieldPaperSlot, type PaperConfigInput${zoneImport} } from 'paperlab'
|
|
628
|
-
|
|
629
|
-
${consts}
|
|
630
|
-
|
|
631
|
-
const papers: FieldPaperSlot[] = [
|
|
632
|
-
${slots}
|
|
633
|
-
]
|
|
634
|
-
|
|
635
|
-
export function PaperGallery() {
|
|
636
|
-
return (
|
|
637
|
-
<PaperField
|
|
638
|
-
papers={papers}
|
|
639
|
-
${props}
|
|
640
|
-
/>
|
|
641
|
-
)
|
|
642
|
-
}`;
|
|
643
|
-
}
|
|
644
|
-
return `import { PaperField, type FieldPaperSlot, type PaperConfigInput${zoneImport} } from 'paperlab'
|
|
645
|
-
|
|
646
|
-
${consts}
|
|
647
|
-
|
|
648
|
-
const papers: FieldPaperSlot[] = [
|
|
649
|
-
${slots}
|
|
650
|
-
]
|
|
651
|
-
|
|
652
|
-
export function PaperGallery() {
|
|
653
|
-
return (
|
|
654
|
-
<PaperField
|
|
655
|
-
papers={papers}
|
|
656
|
-
${props}
|
|
657
|
-
>
|
|
658
|
-
${zoneChildren}
|
|
659
|
-
</PaperField>
|
|
660
|
-
)
|
|
661
|
-
}`;
|
|
662
|
-
}
|
|
663
|
-
function buildFieldAgentPayload(input) {
|
|
664
|
-
return `Integrate a Paperlab paper gallery into this project. (paperlab agent-payload v${AGENT_PAYLOAD_VERSION})
|
|
665
|
-
|
|
666
|
-
1. Install the dependencies:
|
|
667
|
-
|
|
668
|
-
npm i paperlab three @react-three/fiber gsap
|
|
669
|
-
|
|
670
|
-
2. Create the component below as \`components/PaperGallery.tsx\` (or the
|
|
671
|
-
project's component convention). It is self-contained \u2014 every preset it
|
|
672
|
-
uses is inlined, and it owns its own <Canvas>:
|
|
673
|
-
|
|
674
|
-
\`\`\`tsx
|
|
675
|
-
${buildFieldComponentSource(input)}
|
|
676
|
-
\`\`\`
|
|
677
|
-
|
|
678
|
-
3. Sizing: the component fills its parent container. Place it where I ask;
|
|
679
|
-
give the parent an explicit height.
|
|
680
|
-
|
|
681
|
-
4. Verify: run the dev server. You should see ${describeFieldConfig(input)}.
|
|
682
|
-
If the canvas is blank, the parent container almost certainly has no height \u2014
|
|
683
|
-
give it one (this is the classic React Three Fiber integration bug, not a
|
|
684
|
-
paperlab bug).
|
|
685
|
-
|
|
686
|
-
Constraints: don't modify the preset values; three >= 0.160 and React 19 are
|
|
687
|
-
required; the component needs no props.`;
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
// src/core/modes.ts
|
|
691
|
-
function resolveMode(requested, ctx) {
|
|
692
|
-
if (requested !== "auto") return requested;
|
|
693
|
-
if (ctx.interactive || ctx.physics !== "none" || ctx.count <= 10) return "hero";
|
|
694
|
-
return "field";
|
|
695
|
-
}
|
|
696
572
|
export {
|
|
697
|
-
AGENT_PAYLOAD_VERSION,
|
|
698
573
|
AUTO_CEILING,
|
|
699
|
-
ClothSim,
|
|
700
574
|
DropZone,
|
|
701
|
-
DropZoneRegistry,
|
|
702
575
|
FLAT_SEGMENTS,
|
|
703
576
|
LightRig,
|
|
704
|
-
ON_TWOS_FPS,
|
|
705
577
|
PARITY_EPSILON,
|
|
706
578
|
Paper,
|
|
707
|
-
PaperFallback,
|
|
708
579
|
PaperField,
|
|
709
580
|
PaperFieldMesh,
|
|
710
581
|
PaperLighting,
|
|
711
|
-
PaperMaterial,
|
|
712
582
|
PaperMesh,
|
|
713
|
-
PaperMirror,
|
|
714
|
-
PaperStateMachine,
|
|
715
583
|
SAG_TOL,
|
|
716
|
-
SHEET_LIFT,
|
|
717
|
-
TRANSMISSION_GAIN,
|
|
718
|
-
accordion,
|
|
719
|
-
applyDeformerStack,
|
|
720
|
-
atlasGrid,
|
|
721
|
-
backContentSchema,
|
|
722
|
-
barcodeBars,
|
|
723
584
|
behaviorConfigSchema,
|
|
724
|
-
bend,
|
|
725
|
-
bendOptionsSchema,
|
|
726
|
-
book,
|
|
727
585
|
buildAgentPayload,
|
|
728
|
-
buildDisplacementGLSL,
|
|
729
586
|
buildFieldAgentPayload,
|
|
730
587
|
buildFieldComponentSource,
|
|
731
|
-
buildFieldFragmentShader,
|
|
732
|
-
buildFieldVertexShader,
|
|
733
588
|
buildJsxSnippet,
|
|
734
|
-
cardContentSchema,
|
|
735
|
-
carry,
|
|
736
|
-
carryDrive,
|
|
737
|
-
carryOptionsSchema,
|
|
738
589
|
clothConfigSchema,
|
|
739
|
-
colonnade,
|
|
740
|
-
composeSurface,
|
|
741
|
-
contentSchema,
|
|
742
|
-
contentText,
|
|
743
590
|
coreStateNames,
|
|
744
|
-
cornerNames,
|
|
745
|
-
createSheetGeometry,
|
|
746
|
-
crumple,
|
|
747
|
-
crumpleBehavior,
|
|
748
|
-
crumpleBehaviorOptionsSchema,
|
|
749
|
-
crumpleOptionsSchema,
|
|
750
|
-
curl,
|
|
751
|
-
curlOptionsSchema,
|
|
752
|
-
dampTo,
|
|
753
|
-
deformerInstanceSchema,
|
|
754
591
|
describeConfig,
|
|
755
592
|
describeFieldConfig,
|
|
756
593
|
diffConfig,
|
|
757
594
|
diffFieldProps,
|
|
758
|
-
displacePoint,
|
|
759
|
-
distinctFieldPresets,
|
|
760
|
-
drape,
|
|
761
|
-
drapeOptionsSchema,
|
|
762
|
-
drawBacking,
|
|
763
|
-
fall,
|
|
764
|
-
fallOptionsSchema,
|
|
765
|
-
fan,
|
|
766
|
-
fieldBounds,
|
|
767
|
-
fieldKeyboardStep,
|
|
768
|
-
filmNames,
|
|
769
|
-
fitCamera,
|
|
770
|
-
flattenNumeric,
|
|
771
|
-
flight,
|
|
772
|
-
flightOptionsSchema,
|
|
773
|
-
flightPose,
|
|
774
|
-
flip,
|
|
775
|
-
flipOptionsSchema,
|
|
776
|
-
fly,
|
|
777
|
-
flyOptionsSchema,
|
|
778
|
-
fold,
|
|
779
|
-
foldOptionsSchema,
|
|
780
595
|
getBehavior,
|
|
781
596
|
getDeformer,
|
|
782
|
-
getIdlePreset,
|
|
783
597
|
getLayout,
|
|
784
|
-
getLightingPreset,
|
|
785
598
|
getPreset,
|
|
786
599
|
getStock,
|
|
787
|
-
groupFieldPapers,
|
|
788
|
-
gust,
|
|
789
|
-
hang,
|
|
790
|
-
hangOptionsSchema,
|
|
791
600
|
idleNames,
|
|
792
|
-
idlePresets,
|
|
793
601
|
isBuiltinPreset,
|
|
794
|
-
letterFold,
|
|
795
|
-
letterFoldOptionsSchema,
|
|
796
602
|
lightAngles,
|
|
797
|
-
lightPosition,
|
|
798
603
|
lightSchema,
|
|
799
|
-
lightenHex,
|
|
800
604
|
lightingNames,
|
|
801
|
-
lightingPresets,
|
|
802
605
|
listBehaviors,
|
|
803
606
|
listDeformers,
|
|
804
607
|
listLayouts,
|
|
805
608
|
listPresets,
|
|
806
|
-
makeGoboTexture,
|
|
807
609
|
mergeConfig,
|
|
808
610
|
mergeWithDeletes,
|
|
809
|
-
outwardCorner,
|
|
810
611
|
paperConfigSchema,
|
|
811
612
|
paperEdges,
|
|
812
613
|
paperStatesSchema,
|
|
813
614
|
parityCases,
|
|
814
615
|
parsePreset,
|
|
815
|
-
peel,
|
|
816
|
-
peelOptionsSchema,
|
|
817
616
|
physicsNames,
|
|
818
|
-
physicsSchema,
|
|
819
|
-
pile,
|
|
820
|
-
quantizeProgress,
|
|
821
617
|
quantizeSegments,
|
|
822
|
-
quantizeTime,
|
|
823
|
-
rack,
|
|
824
|
-
receiptContentSchema,
|
|
825
|
-
receiptTotals,
|
|
826
618
|
recordStateOverride,
|
|
827
619
|
registerBehavior,
|
|
828
620
|
registerDeformer,
|
|
829
621
|
registerLayout,
|
|
830
622
|
registerPreset,
|
|
831
|
-
resolveConfig,
|
|
832
|
-
resolveDeformerStack,
|
|
833
|
-
resolveFieldSlotConfig,
|
|
834
623
|
resolveLighting,
|
|
835
|
-
resolveMode,
|
|
836
|
-
resolveSegments,
|
|
837
624
|
resolveStateConfig,
|
|
838
|
-
ribbon,
|
|
839
|
-
ribbonOptionsSchema,
|
|
840
|
-
ring,
|
|
841
|
-
roll,
|
|
842
|
-
rollOptionsSchema,
|
|
843
625
|
runParityHarness,
|
|
844
|
-
sceneSchema,
|
|
845
626
|
segmentsForArc,
|
|
846
627
|
segmentsForSine,
|
|
847
628
|
serializePreset,
|
|
848
|
-
settle,
|
|
849
|
-
settleOptionsSchema,
|
|
850
|
-
sheet,
|
|
851
|
-
sheetBackingSize,
|
|
852
629
|
sheetLayoutSchema,
|
|
853
|
-
sheetSchema,
|
|
854
|
-
sheetSlotXY,
|
|
855
|
-
silhouetteRects,
|
|
856
630
|
spanAlong,
|
|
857
|
-
spill,
|
|
858
|
-
spread,
|
|
859
|
-
stackAutoSegments,
|
|
860
|
-
stackMinSegments,
|
|
861
|
-
stackUniformValues,
|
|
862
631
|
stateDefSchema,
|
|
863
|
-
stateEventTransitions,
|
|
864
|
-
stateTransitionSchema,
|
|
865
632
|
stockNames,
|
|
866
|
-
stockSchema,
|
|
867
633
|
stocks,
|
|
868
|
-
stripStates,
|
|
869
634
|
supportsWebGL,
|
|
870
|
-
surfaceSchema,
|
|
871
|
-
sweep,
|
|
872
|
-
tornEdgesOnDetach,
|
|
873
|
-
translucencyUniforms,
|
|
874
|
-
translucencyValues,
|
|
875
635
|
uniquePresetName,
|
|
876
636
|
unregisterPreset,
|
|
877
|
-
unroll,
|
|
878
|
-
unrollOptionsSchema,
|
|
879
|
-
useContentAtlas,
|
|
880
637
|
usePaperStates,
|
|
881
638
|
usePrefersReducedMotion,
|
|
882
|
-
|
|
883
|
-
wave,
|
|
884
|
-
waveOptionsSchema,
|
|
885
|
-
withSheetCellFromPaper,
|
|
886
|
-
wrapLines,
|
|
887
|
-
zoneAccepts
|
|
639
|
+
wrapLines
|
|
888
640
|
};
|
|
889
641
|
//# sourceMappingURL=index.js.map
|