@taptap/maker 0.0.37-beta.5 → 0.0.37-beta.7

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.
@@ -2354,15 +2354,205 @@ function assemble(layout, correction = null) {
2354
2354
  }
2355
2355
  };
2356
2356
  }
2357
+ function layoutFromBbox(input) {
2358
+ const bbox = input.bbox;
2359
+ if (input.ui) {
2360
+ assert(
2361
+ typeof input.ui.id === "string" && input.ui.id.length > 0,
2362
+ "Missing UI archive identity"
2363
+ );
2364
+ assert.equal(
2365
+ input.ui.bboxSha256,
2366
+ digest(JSON.stringify(bbox)),
2367
+ "Bbox does not match this UI resource bundle"
2368
+ );
2369
+ }
2370
+ assert(
2371
+ bbox && bbox.version === 1 && bbox.coordinateSpace === "design-pixels" && bbox.bboxFormat === "xywh",
2372
+ "Expected version=1 design-pixels xywh Bbox JSON"
2373
+ );
2374
+ assert(
2375
+ bbox.design && bbox.cutSource && Array.isArray(bbox.elements) && bbox.elements.length > 0 && bbox.elements.length <= 500 && Array.isArray(bbox.texts) && bbox.texts.length <= 1e3,
2376
+ "Missing Bbox sources or two-pass results"
2377
+ );
2378
+ for (const image of [bbox.design, bbox.cutSource]) {
2379
+ assert(
2380
+ typeof image.path === "string" && /^[a-f0-9]{64}$/.test(image.sha256) && Number.isInteger(image.width) && image.width > 0 && Number.isInteger(image.height) && image.height > 0,
2381
+ "Invalid Bbox source identity"
2382
+ );
2383
+ }
2384
+ const elements = unique(bbox.elements, "bbox.elements");
2385
+ const texts = unique(bbox.texts, "bbox.texts");
2386
+ const bindings = /* @__PURE__ */ new Map();
2387
+ assert(input.confirmed !== false, "UI asset bindings are not confirmed");
2388
+ assert(
2389
+ Array.isArray(input.bindings) && Array.isArray(input.assets),
2390
+ "Explicit assets and bindings are required"
2391
+ );
2392
+ for (const binding of input.bindings) {
2393
+ assert(binding.review !== "unreviewed", "Unreviewed UI binding: " + binding.elementId);
2394
+ assert(
2395
+ elements.has(binding.elementId) && !bindings.has(binding.elementId) && typeof binding.assetId === "string",
2396
+ "Unknown or duplicate Bbox binding"
2397
+ );
2398
+ bindings.set(binding.elementId, binding);
2399
+ }
2400
+ const checkRect = (value, id) => {
2401
+ rect(value, id);
2402
+ assert(
2403
+ value[0] >= 0 && value[1] >= 0 && value[0] + value[2] <= bbox.design.width && value[1] + value[3] <= bbox.design.height,
2404
+ "Bbox outside design: " + id
2405
+ );
2406
+ };
2407
+ const root = {
2408
+ id: "root",
2409
+ type: "Panel",
2410
+ parentId: null,
2411
+ render: "container",
2412
+ rect: [0, 0, bbox.design.width, bbox.design.height],
2413
+ props: {}
2414
+ };
2415
+ const images = bbox.elements.map((element) => {
2416
+ assert(
2417
+ /^E[0-9]{3,}$/.test(element.id) && ["icon", "frame", "panel", "button", "tab", "title"].includes(element.type) && (element.parent === null || elements.has(element.parent)),
2418
+ "Invalid Bbox element"
2419
+ );
2420
+ checkRect(element.bbox, element.id);
2421
+ const binding = bindings.get(element.id);
2422
+ assert(binding, "Missing explicit PNG binding: " + element.id);
2423
+ return {
2424
+ id: element.id,
2425
+ parentId: element.parent || "root",
2426
+ type: element.type === "button" || element.type === "tab" || binding.pressedAssetId ? "Button" : "Panel",
2427
+ render: "image",
2428
+ rect: [...element.bbox],
2429
+ props: { backgroundFit: element.type === "icon" ? "contain" : "fill" },
2430
+ assetId: binding.assetId,
2431
+ ...binding.pressedAssetId ? { pressedAssetId: binding.pressedAssetId } : {}
2432
+ };
2433
+ });
2434
+ const labels = bbox.texts.map((text) => {
2435
+ assert(
2436
+ /^T[0-9]{3,}$/.test(text.id) && !elements.has(text.id) && typeof text.text === "string" && text.text.trim() && text.cutout === false && (text.parentId === null || elements.has(text.parentId)) && ["left", "center", "right"].includes(text.align) && /^#[a-f0-9]{6}$/i.test(text.color) && typeof text.bold === "boolean",
2437
+ "Invalid Bbox text"
2438
+ );
2439
+ checkRect(text.bbox, text.id);
2440
+ const color = text.color.slice(1);
2441
+ const lines = text.text.split("\n");
2442
+ const widthUnits = Math.max(
2443
+ 1,
2444
+ ...lines.map(
2445
+ (line) => Array.from(line).reduce((sum, char) => sum + (char.codePointAt(0) < 128 ? 0.6 : 1), 0)
2446
+ )
2447
+ );
2448
+ return {
2449
+ id: text.id,
2450
+ parentId: text.parentId || "root",
2451
+ type: "Label",
2452
+ render: "text",
2453
+ rect: [...text.bbox],
2454
+ props: {
2455
+ text: text.text,
2456
+ textAlign: text.align,
2457
+ verticalAlign: "middle",
2458
+ fontSize: Math.max(
2459
+ 1,
2460
+ Math.floor(Math.min(text.bbox[3] / lines.length, text.bbox[2] / widthUnits))
2461
+ ),
2462
+ fontWeight: text.bold ? "bold" : "normal",
2463
+ fontColor: [
2464
+ parseInt(color.slice(0, 2), 16),
2465
+ parseInt(color.slice(2, 4), 16),
2466
+ parseInt(color.slice(4, 6), 16),
2467
+ 255
2468
+ ]
2469
+ }
2470
+ };
2471
+ });
2472
+ assert.equal(texts.size, labels.length);
2473
+ return {
2474
+ version: 1,
2475
+ coordinateSpace: "design-pixels",
2476
+ rectBasis: "asset-canvas",
2477
+ provenance: "recognition",
2478
+ design: { ...bbox.design },
2479
+ assets: input.assets,
2480
+ elements: [
2481
+ root,
2482
+ ...input.backgroundAssetId ? [
2483
+ {
2484
+ id: "background",
2485
+ parentId: "root",
2486
+ type: "Image",
2487
+ render: "image",
2488
+ rect: [...root.rect],
2489
+ props: {},
2490
+ assetId: input.backgroundAssetId
2491
+ }
2492
+ ] : [],
2493
+ ...images,
2494
+ ...labels
2495
+ ]
2496
+ };
2497
+ }
2357
2498
  function run(project, layoutFile, outputDirectory, correctionFile) {
2358
- const layout = JSON.parse(fs.readFileSync(layoutFile, "utf8"));
2499
+ const input = JSON.parse(fs.readFileSync(layoutFile, "utf8"));
2500
+ const cropped = [];
2501
+ if (input.bbox) {
2502
+ for (const asset of input.assets || []) {
2503
+ verifyImage(project, asset);
2504
+ if (!asset.contentRect) continue;
2505
+ const box = asset.contentRect;
2506
+ assert(
2507
+ Array.isArray(box) && box.length === 4 && box.every(Number.isInteger) && box[0] >= 0 && box[1] >= 0 && box[2] > 0 && box[3] > 0 && box[0] + box[2] <= asset.width && box[1] + box[3] <= asset.height,
2508
+ "Invalid content rect: " + asset.id
2509
+ );
2510
+ if (box[0] === 0 && box[1] === 0 && box[2] === asset.width && box[3] === asset.height)
2511
+ continue;
2512
+ assert(/^[A-Za-z][A-Za-z0-9_-]*$/.test(asset.id), "Invalid crop asset ID");
2513
+ const relative = path.relative(
2514
+ fs.realpathSync(project),
2515
+ path.join(
2516
+ fs.realpathSync(path.dirname(path.resolve(outputDirectory))),
2517
+ path.basename(outputDirectory),
2518
+ "images",
2519
+ asset.id + ".png"
2520
+ )
2521
+ ).split(path.sep).join("/");
2522
+ assert(
2523
+ relative.startsWith("assets/") && !relative.split("/").includes(".."),
2524
+ "Cropped UI output must be inside project assets/"
2525
+ );
2526
+ const source = import_pngjs.PNG.sync.read(readAsset(project, asset.path));
2527
+ const target = new import_pngjs.PNG({ width: box[2], height: box[3] });
2528
+ import_pngjs.PNG.bitblt(source, target, ...box, 0, 0);
2529
+ const bytes = import_pngjs.PNG.sync.write(target);
2530
+ cropped.push({ relative, bytes });
2531
+ asset.sourceContentRect = [...box];
2532
+ asset.sourcePath = asset.path;
2533
+ Object.assign(asset, {
2534
+ path: relative,
2535
+ width: box[2],
2536
+ height: box[3],
2537
+ sha256: digest(bytes)
2538
+ });
2539
+ delete asset.contentRect;
2540
+ }
2541
+ }
2542
+ const layout = input.bbox ? layoutFromBbox(input) : input;
2543
+ if (input.bbox) verifyImage(project, input.bbox.cutSource);
2359
2544
  const correction = correctionFile ? JSON.parse(fs.readFileSync(correctionFile, "utf8")) : null;
2360
2545
  const result = assemble(layout, correction);
2361
- for (const item of [layout.design, ...layout.assets]) verifyImage(project, item);
2546
+ for (const item of [layout.design, ...layout.assets])
2547
+ if (!cropped.some((crop) => crop.relative === item.path)) verifyImage(project, item);
2362
2548
  fs.mkdirSync(outputDirectory);
2549
+ if (cropped.length) fs.mkdirSync(path.join(outputDirectory, "images"));
2550
+ for (const crop of cropped)
2551
+ fs.writeFileSync(path.join(project, crop.relative), crop.bytes, { flag: "wx" });
2363
2552
  for (const [name, value] of [
2364
2553
  ["assembled.ui.json", result.ui],
2365
- ["assembly-map.json", result.report]
2554
+ ["assembly-map.json", result.report],
2555
+ ...input.bbox ? [["layout.json", layout]] : []
2366
2556
  ]) {
2367
2557
  fs.writeFileSync(path.join(outputDirectory, name), JSON.stringify(value, null, 2), {
2368
2558
  flag: "wx"
@@ -2398,6 +2588,7 @@ export {
2398
2588
  assemble,
2399
2589
  digest,
2400
2590
  layoutDigest,
2591
+ layoutFromBbox,
2401
2592
  readAsset,
2402
2593
  run
2403
2594
  };
@@ -639,7 +639,7 @@ request/correlation ID, reproduction steps, visible Maker tools, client version,
639
639
  Do not include the complete conversation. Send that JSON through stdin, never argv, while running:
640
640
 
641
641
  ```text
642
- npx -y --package @taptap/maker@0.0.37-beta.5 taptap-maker mcp report --ide <client> --target-dir <project> --context-stdin --consent --json
642
+ npx -y --package @taptap/maker@0.0.37-beta.7 taptap-maker mcp report --ide <client> --target-dir <project> --context-stdin --consent --json
643
643
  ```
644
644
 
645
645
  Prefer the active client's exact Maker MCP `command` plus ordered `args`, then append the `mcp