lineadraw 0.13.0 → 0.14.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 CHANGED
@@ -303,7 +303,8 @@ millimeters, Y-up, angles in radians CCW.
303
303
  Parameter types (the same rows serve a command's `params`):
304
304
 
305
305
  - `number` — `min`/`max`, `integer`, `step`, `prefix`/`suffix` ("1:",
306
- "mm"), `presets` (standard values in the field's dropdown).
306
+ "mm"), `presets` (standard values in the field's dropdown),
307
+ `display: "slider"` (a slider beside the field; needs `min` and `max`).
307
308
  - `string` — `placeholder`, `multiline`, `presets`.
308
309
  - `boolean` (`display: "toggle"` — a toggle button showing the label,
309
310
  compact in a row), `enum` (`options`, each optionally with a `swatch:
@@ -652,6 +652,20 @@ var chainEdges = (loop) => {
652
652
  }
653
653
  return out;
654
654
  };
655
+ var loopGap = (loop) => {
656
+ const chain = chainEdges(loop);
657
+ let worst = null;
658
+ chain.forEach(({ edge, reversed }, i) => {
659
+ const next = chain[(i + 1) % chain.length];
660
+ const e = edgeEnds(edge);
661
+ const n = edgeEnds(next.edge);
662
+ const from = reversed ? e.start : e.end;
663
+ const to = next.reversed ? n.end : n.start;
664
+ const gap = dist(from, to);
665
+ if (!worst || gap > worst.gap) worst = { edge: i, gap, from, to };
666
+ });
667
+ return worst;
668
+ };
655
669
  var loopPolygon = (loop, tolerance = 0.1) => {
656
670
  const ring = [];
657
671
  for (const { edge, reversed } of chainEdges(loop)) {
@@ -2342,7 +2356,10 @@ var REFERENCE_FORMATS = [
2342
2356
  "dwg",
2343
2357
  "pdf",
2344
2358
  "png",
2345
- "jpg"
2359
+ "jpg",
2360
+ // Linked only: the editor decodes it to PNG (Embed stores that PNG, as
2361
+ // `png`), and headless hosts — which have no decoder — draw its frame.
2362
+ "webp"
2346
2363
  ];
2347
2364
  var ReferenceSourceSchema = z4.discriminatedUnion("kind", [
2348
2365
  z4.object({
@@ -2729,7 +2746,10 @@ var NumberParam = z6.object({
2729
2746
  prefix: z6.string().optional(),
2730
2747
  suffix: z6.string().optional(),
2731
2748
  /** Standard values offered in the field's dropdown; typing stays free. */
2732
- presets: z6.array(z6.number()).optional()
2749
+ presets: z6.array(z6.number()).optional(),
2750
+ /** "slider": a slider beside the field — needs `min` and `max` (else
2751
+ * the plain field); a drag updates live and is one undo step. */
2752
+ display: z6.enum(["field", "slider"]).optional()
2733
2753
  });
2734
2754
  var StringParam = z6.object({
2735
2755
  ...paramBase,
@@ -7031,8 +7051,11 @@ var ModuleSandbox = class {
7031
7051
  const message = field("message") || String(dumped);
7032
7052
  if (/out of memory/i.test(message)) {
7033
7053
  resetPending = true;
7034
- return new Error(
7035
- `Script ran out of memory (${MEMORY_LIMIT / 1024 / 1024} MB for all scripts) and was stopped.`
7054
+ return Object.assign(
7055
+ new Error(
7056
+ `Script ran out of memory (${MEMORY_LIMIT / 1024 / 1024} MB for all scripts) and was stopped.`
7057
+ ),
7058
+ { code: "scriptOutOfMemory" }
7036
7059
  );
7037
7060
  }
7038
7061
  const host = this.lastHostError;
@@ -7254,6 +7277,7 @@ var invalidateBlockCache = (ids) => {
7254
7277
  handleMemo.clear();
7255
7278
  exposeMemo.clear();
7256
7279
  evalErrors.clear();
7280
+ evalWarnings.clear();
7257
7281
  instanceDeps.clear();
7258
7282
  return;
7259
7283
  }
@@ -7262,10 +7286,13 @@ var invalidateBlockCache = (ids) => {
7262
7286
  handleMemo.delete(id);
7263
7287
  exposeMemo.delete(id);
7264
7288
  evalErrors.delete(id);
7289
+ evalWarnings.delete(id);
7265
7290
  }
7266
7291
  };
7267
7292
  var evalErrors = /* @__PURE__ */ new Map();
7268
7293
  var getBlockError = (instanceId) => evalErrors.get(instanceId);
7294
+ var evalWarnings = /* @__PURE__ */ new Map();
7295
+ var getBlockWarning = (instanceId) => evalWarnings.get(instanceId);
7269
7296
  var defaultParams = (meta) => {
7270
7297
  const params = /* @__PURE__ */ Object.create(null);
7271
7298
  for (const param of valueParams(meta.params))
@@ -7425,8 +7452,17 @@ var runScript = (script, params, inputs2, styles, hosting = { host: null, hosted
7425
7452
  styles: stylesResolver(styles)
7426
7453
  });
7427
7454
  const raw = mod.draw(props);
7428
- return BlockScriptResultSchema.parse(raw);
7429
- };
7455
+ const children = BlockScriptResultSchema.parse(raw);
7456
+ if (emitsPointsLoop(raw)) pointsLoopResults.add(children);
7457
+ return children;
7458
+ };
7459
+ var emitsPointsLoop = (raw) => Array.isArray(raw) && raw.some((c2) => {
7460
+ if (c2?.type !== "hatch" || !Array.isArray(c2.loops)) return false;
7461
+ return c2.loops.some(
7462
+ (l) => Array.isArray(l?.points)
7463
+ );
7464
+ });
7465
+ var pointsLoopResults = /* @__PURE__ */ new WeakSet();
7430
7466
  var DEFAULT_BLOCK_STYLES = {
7431
7467
  textStyles: [DEFAULT_TEXT_STYLE],
7432
7468
  dimStyles: [DEFAULT_DIM_STYLE]
@@ -7923,6 +7959,12 @@ var getEvaluatedWorldChildren = (instance, scripts, resolveObject, styles = DEFA
7923
7959
  }
7924
7960
  }
7925
7961
  evalErrors.delete(instance.id);
7962
+ if (pointsLoopResults.has(children))
7963
+ evalWarnings.set(
7964
+ instance.id,
7965
+ `Block "${meta.id}" draws a hatch with the old \`{ points }\` loop shape \u2014 it still draws, but loops take \`edges\`: use hatchLoop(points) from "lineadraw/helpers"`
7966
+ );
7967
+ else evalWarnings.delete(instance.id);
7926
7968
  return children.map((child, i) => {
7927
7969
  let obj = childToObject(child, instance, i, styles.layers);
7928
7970
  if (pose.scale !== 1) obj = scaleObjectUniform(obj, pose.scale);
@@ -12820,6 +12862,16 @@ var tableLayout = (t, textStyles) => {
12820
12862
  header
12821
12863
  );
12822
12864
  }
12865
+ const crossings = [];
12866
+ const E = 1e-9;
12867
+ for (const v2 of rules) {
12868
+ if (v2.a.x !== v2.b.x) continue;
12869
+ for (const h of rules) {
12870
+ if (h.a.y !== h.b.y || h.a.x === h.b.x) continue;
12871
+ if (v2.a.x >= h.a.x - E && v2.a.x <= h.b.x + E && h.a.y >= v2.a.y - E && h.a.y <= v2.b.y + E)
12872
+ crossings.push(toWorld(t, { x: v2.a.x, y: h.a.y }));
12873
+ }
12874
+ }
12823
12875
  const children = rules.map((r, k2) => ({
12824
12876
  type: "line",
12825
12877
  id: `${t.id}:rule:${k2}`,
@@ -12850,6 +12902,7 @@ var tableLayout = (t, textStyles) => {
12850
12902
  toWorld(t, { x: w2, y: hTotal }),
12851
12903
  toWorld(t, { x: 0, y: hTotal })
12852
12904
  ],
12905
+ crossings,
12853
12906
  children,
12854
12907
  anchors
12855
12908
  };
@@ -14176,6 +14229,7 @@ ${pat.name.toUpperCase()}
14176
14229
  ` + record.slice(nameAt + name.length + 4);
14177
14230
  }
14178
14231
  }
14232
+ record = record.replace("\n47\n1\n98\n", "\n98\n");
14179
14233
  out.push(content.slice(pos, start), record);
14180
14234
  pos = end;
14181
14235
  }
@@ -14281,7 +14335,6 @@ var writeSplineEdge = (dx, curve0) => {
14281
14335
  dx.point2d(p2);
14282
14336
  if (rational) dx.push(42, curve.weights[i]);
14283
14337
  });
14284
- dx.push(97, 0);
14285
14338
  };
14286
14339
  var writeHatch = (space, obj, opts, ctx) => {
14287
14340
  if (obj.type !== "hatch") return;
@@ -15112,6 +15165,8 @@ export {
15112
15165
  interpolateClosed,
15113
15166
  nurbsToBeziers,
15114
15167
  curveTolerance,
15168
+ edgeEnds,
15169
+ loopGap,
15115
15170
  loopPolygon,
15116
15171
  emitLoopPath,
15117
15172
  loopCurves,
@@ -15219,6 +15274,7 @@ export {
15219
15274
  expandWithBlockDependents,
15220
15275
  invalidateBlockCache,
15221
15276
  getBlockError,
15277
+ getBlockWarning,
15222
15278
  parseParamsExport,
15223
15279
  getBlockMeta,
15224
15280
  getBlockMetaResult,
@@ -15248,4 +15304,4 @@ export {
15248
15304
  DWG_DXF_OPTIONS,
15249
15305
  buildDxf
15250
15306
  };
15251
- //# sourceMappingURL=chunk-SPTLQMJW.js.map
15307
+ //# sourceMappingURL=chunk-FBZASM7T.js.map