@crystaldesign/planner-2d-core 26.12.0-beta.9 → 26.13.0-beta.1

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.
@@ -2340,8 +2340,10 @@ function fixViewBox(state, minBorderX, minBorderY) {
2340
2340
  var oltExtentY = state.startHeightOlt + state.heightOlt;
2341
2341
  var olfExtentX = state.startWidthOlf + state.widthOlf;
2342
2342
  var olfExtentY = state.startHeightOlf + state.heightOlf;
2343
- var maxWidth = olfExtentX > oltExtentX ? olfExtentX : oltExtentX;
2344
- var maxHeight = olfExtentY > oltExtentY ? olfExtentY : oltExtentY;
2343
+ // a kept axis ends where its drawn canvas ends, seen from the minBorder origin - the OLT extent would add the OLT's
2344
+ // start offset again behind the drawing, and a rect OLT records none at all
2345
+ var maxWidth = state.keptRootWidth !== undefined ? state.keptRootWidth - minBorderX : olfExtentX > oltExtentX ? olfExtentX : oltExtentX;
2346
+ var maxHeight = state.keptRootHeight !== undefined ? state.keptRootHeight - minBorderY : olfExtentY > oltExtentY ? olfExtentY : oltExtentY;
2345
2347
  root.setAttribute('height', String(round2(maxHeight)));
2346
2348
  root.setAttribute('width', String(round2(maxWidth)));
2347
2349
  var borderX = round2(minBorderX);
@@ -2358,8 +2360,8 @@ function fixViewBox(state, minBorderX, minBorderY) {
2358
2360
  var pieces = ((_root$getAttribute3 = root.getAttribute('viewBox')) !== null && _root$getAttribute3 !== void 0 ? _root$getAttribute3 : '').split(' ');
2359
2361
  // Legacy quirk: without stretch areas on an axis the old viewBox extent is kept (pure scaling display).
2360
2362
  viewBox = "".concat(Number.parseFloat(pieces[0]) + borderX, " ").concat(Number.parseFloat(pieces[1]) + borderY);
2361
- viewBox += ' ' + (state.sah.length > 0 ? String(round2(maxWidth)) : pieces[2]);
2362
- viewBox += ' ' + (state.sav.length > 0 ? String(round2(maxHeight)) : pieces[3]);
2363
+ viewBox += ' ' + (state.sah.length > 0 || state.keptRootWidth !== undefined ? String(round2(maxWidth)) : pieces[2]);
2364
+ viewBox += ' ' + (state.sav.length > 0 || state.keptRootHeight !== undefined ? String(round2(maxHeight)) : pieces[3]);
2363
2365
  }
2364
2366
  root.setAttribute('x', String(borderX));
2365
2367
  root.setAttribute('y', String(borderY));
@@ -2394,7 +2396,22 @@ function stretchArticleSvg(svg, targetWidthCm, targetDepthCm) {
2394
2396
  if (state.targetHeightOlt === 0) state.targetHeightOlt = parseFloat((_root$getAttribute4 = root.getAttribute('height')) !== null && _root$getAttribute4 !== void 0 ? _root$getAttribute4 : '');
2395
2397
  ensureTeDisplayNone(xmlDocument);
2396
2398
  prepareStretchGeometry(state);
2397
- if (targetWidthCm === origWidthCm && targetDepthCm === origDepthCm) {
2399
+ // a kept axis targets its measured OLT, so resizeOutline leaves it alone; a global scale gets factor 1 instead of NaN
2400
+ if (options.keepWidth) {
2401
+ var _root$getAttribute5;
2402
+ state.targetWidthOlt = state.widthOlt;
2403
+ state.globalScaleFactorWidth = 1;
2404
+ state.keptRootWidth = parseFloat((_root$getAttribute5 = root.getAttribute('width')) !== null && _root$getAttribute5 !== void 0 ? _root$getAttribute5 : '');
2405
+ }
2406
+ if (options.keepDepth) {
2407
+ var _root$getAttribute6;
2408
+ state.targetHeightOlt = state.heightOlt;
2409
+ state.globalScaleFactorHeight = 1;
2410
+ state.keptRootHeight = parseFloat((_root$getAttribute6 = root.getAttribute('height')) !== null && _root$getAttribute6 !== void 0 ? _root$getAttribute6 : '');
2411
+ }
2412
+
2413
+ // the early exit keeps the canvas origin, which only matches a caller that measured no minBorder
2414
+ if (!options.keepWidth && !options.keepDepth && targetWidthCm === origWidthCm && targetDepthCm === origDepthCm) {
2398
2415
  return {
2399
2416
  svg: serializeXml(xmlDocument),
2400
2417
  sizes: currentSizes(state),
@@ -2327,8 +2327,10 @@ function fixViewBox(state, minBorderX, minBorderY) {
2327
2327
  var oltExtentY = state.startHeightOlt + state.heightOlt;
2328
2328
  var olfExtentX = state.startWidthOlf + state.widthOlf;
2329
2329
  var olfExtentY = state.startHeightOlf + state.heightOlf;
2330
- var maxWidth = olfExtentX > oltExtentX ? olfExtentX : oltExtentX;
2331
- var maxHeight = olfExtentY > oltExtentY ? olfExtentY : oltExtentY;
2330
+ // a kept axis ends where its drawn canvas ends, seen from the minBorder origin - the OLT extent would add the OLT's
2331
+ // start offset again behind the drawing, and a rect OLT records none at all
2332
+ var maxWidth = state.keptRootWidth !== undefined ? state.keptRootWidth - minBorderX : olfExtentX > oltExtentX ? olfExtentX : oltExtentX;
2333
+ var maxHeight = state.keptRootHeight !== undefined ? state.keptRootHeight - minBorderY : olfExtentY > oltExtentY ? olfExtentY : oltExtentY;
2332
2334
  root.setAttribute('height', String(round2(maxHeight)));
2333
2335
  root.setAttribute('width', String(round2(maxWidth)));
2334
2336
  var borderX = round2(minBorderX);
@@ -2345,8 +2347,8 @@ function fixViewBox(state, minBorderX, minBorderY) {
2345
2347
  var pieces = ((_root$getAttribute3 = root.getAttribute('viewBox')) !== null && _root$getAttribute3 !== void 0 ? _root$getAttribute3 : '').split(' ');
2346
2348
  // Legacy quirk: without stretch areas on an axis the old viewBox extent is kept (pure scaling display).
2347
2349
  viewBox = "".concat(Number.parseFloat(pieces[0]) + borderX, " ").concat(Number.parseFloat(pieces[1]) + borderY);
2348
- viewBox += ' ' + (state.sah.length > 0 ? String(round2(maxWidth)) : pieces[2]);
2349
- viewBox += ' ' + (state.sav.length > 0 ? String(round2(maxHeight)) : pieces[3]);
2350
+ viewBox += ' ' + (state.sah.length > 0 || state.keptRootWidth !== undefined ? String(round2(maxWidth)) : pieces[2]);
2351
+ viewBox += ' ' + (state.sav.length > 0 || state.keptRootHeight !== undefined ? String(round2(maxHeight)) : pieces[3]);
2350
2352
  }
2351
2353
  root.setAttribute('x', String(borderX));
2352
2354
  root.setAttribute('y', String(borderY));
@@ -2381,7 +2383,22 @@ function stretchArticleSvg(svg, targetWidthCm, targetDepthCm) {
2381
2383
  if (state.targetHeightOlt === 0) state.targetHeightOlt = parseFloat((_root$getAttribute4 = root.getAttribute('height')) !== null && _root$getAttribute4 !== void 0 ? _root$getAttribute4 : '');
2382
2384
  ensureTeDisplayNone(xmlDocument);
2383
2385
  prepareStretchGeometry(state);
2384
- if (targetWidthCm === origWidthCm && targetDepthCm === origDepthCm) {
2386
+ // a kept axis targets its measured OLT, so resizeOutline leaves it alone; a global scale gets factor 1 instead of NaN
2387
+ if (options.keepWidth) {
2388
+ var _root$getAttribute5;
2389
+ state.targetWidthOlt = state.widthOlt;
2390
+ state.globalScaleFactorWidth = 1;
2391
+ state.keptRootWidth = parseFloat((_root$getAttribute5 = root.getAttribute('width')) !== null && _root$getAttribute5 !== void 0 ? _root$getAttribute5 : '');
2392
+ }
2393
+ if (options.keepDepth) {
2394
+ var _root$getAttribute6;
2395
+ state.targetHeightOlt = state.heightOlt;
2396
+ state.globalScaleFactorHeight = 1;
2397
+ state.keptRootHeight = parseFloat((_root$getAttribute6 = root.getAttribute('height')) !== null && _root$getAttribute6 !== void 0 ? _root$getAttribute6 : '');
2398
+ }
2399
+
2400
+ // the early exit keeps the canvas origin, which only matches a caller that measured no minBorder
2401
+ if (!options.keepWidth && !options.keepDepth && targetWidthCm === origWidthCm && targetDepthCm === origDepthCm) {
2385
2402
  return {
2386
2403
  svg: serializeXml(xmlDocument),
2387
2404
  sizes: currentSizes(state),
@@ -1 +1 @@
1
- {"version":3,"file":"stretchArticleSvg.d.ts","sourceRoot":"","sources":["../../../../../src/stretch/stretchArticleSvg.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,aAAa,CA+BxI"}
1
+ {"version":3,"file":"stretchArticleSvg.d.ts","sourceRoot":"","sources":["../../../../../src/stretch/stretchArticleSvg.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,aAAa,CA2CxI"}
@@ -6,6 +6,13 @@ export interface StretchOptions {
6
6
  minBorderX?: number;
7
7
  /** Minimum y coordinate of the article geometry, used to correct the output viewBox. Default 0. */
8
8
  minBorderY?: number;
9
+ /**
10
+ * Keep the width as drawn: the OLT keeps its measured width whatever the target says, also when scaling
11
+ * globally. With a kept axis the viewBox is always moved by the minBorder, as for any stretched svg.
12
+ */
13
+ keepWidth?: boolean;
14
+ /** Keep the depth as drawn, see keepWidth. */
15
+ keepDepth?: boolean;
9
16
  }
10
17
  /** Final outline sizes in SVG user units; an axis that was not stretched keeps its original size. */
11
18
  export interface StretchSizes {
@@ -48,6 +55,9 @@ export interface StretchState {
48
55
  ratioSav: number[];
49
56
  globalScaleFactorWidth: number;
50
57
  globalScaleFactorHeight: number;
58
+ /** Root size of an axis kept as drawn (StretchOptions.keepWidth/keepDepth); the viewBox fix writes it back unchanged. */
59
+ keptRootWidth?: number;
60
+ keptRootHeight?: number;
51
61
  warnings: string[];
52
62
  warned: Set<string>;
53
63
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/stretch/types.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,MAAM,WAAW,cAAc;IAC7B,4FAA4F;IAC5F,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,mGAAmG;IACnG,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mGAAmG;IACnG,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qGAAqG;AACrG,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,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EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,OAAO,EAAE,CAAC;IACf,GAAG,EAAE,OAAO,EAAE,CAAC;IACf,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,uBAAuB,EAAE,MAAM,CAAC;IAChC,yHAAyH;IACzH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACrB"}
@@ -1 +1 @@
1
- {"version":3,"file":"viewBoxFix.d.ts","sourceRoot":"","sources":["../../../../../src/stretch/viewBoxFix.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAiC5F"}
1
+ {"version":3,"file":"viewBoxFix.d.ts","sourceRoot":"","sources":["../../../../../src/stretch/viewBoxFix.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAmC5F"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=stretchKeepAxis.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stretchKeepAxis.test.d.ts","sourceRoot":"","sources":["../../../../../src/tests/stretchKeepAxis.test.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crystaldesign/planner-2d-core",
3
- "version": "26.12.0-beta.9",
3
+ "version": "26.13.0-beta.1",
4
4
  "description": "Browser-free 2D planner core: article SVG parsing, docking logic, dock transform math and collision geometry.",
5
5
  "dependencies": {
6
6
  "w3c-xmlserializer": "5.0.0"
@@ -20,5 +20,5 @@
20
20
  "types": "./build/types/planner-2d-core/src/index.d.ts",
21
21
  "module": "build/esm/index.js",
22
22
  "main": "build/cjs/index.js",
23
- "gitHead": "62f51ceee2ea71c54b990c666eb7ae864f13d374"
23
+ "gitHead": "b38715cf22885313d39435130631ab8993ac8dc5"
24
24
  }