@innovastudio/contentbuilder 1.5.225 → 1.5.227

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/index.d.ts CHANGED
@@ -135,6 +135,10 @@ interface ContentBuilderOptions {
135
135
  /** Show the image editor's "Load .cube…" button (load a LUT from the user's computer). Default false. */
136
136
  imageEditorLoadCube?: boolean;
137
137
  imageEmbed?: boolean;
138
+ /** Show resize handles on a selected image. Default true. */
139
+ imageResize?: boolean;
140
+ /** Show the floating image tool on a selected image. Default true. */
141
+ imageTool?: boolean;
138
142
  imageselect?: string;
139
143
  fileselect?: string;
140
144
  videoselect?: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@innovastudio/contentbuilder",
4
- "version": "1.5.225",
4
+ "version": "1.5.227",
5
5
  "description": "",
6
6
  "main": "public/contentbuilder/contentbuilder.esm.js",
7
7
  "types": "index.d.ts",
@@ -6284,11 +6284,275 @@ class ToolbarKeys {
6284
6284
  }
6285
6285
  }
6286
6286
 
6287
+ /*
6288
+ selectframe.js — a 1px frame that shows which element is selected.
6289
+
6290
+ Drawn as its own element above the page, never as an outline on the element:
6291
+ pictures usually sit in an overflow:hidden, rounded wrapper, often scale on
6292
+ hover, and design layers stack things on top of each other, so an outline on
6293
+ the element itself is cut away or painted over.
6294
+
6295
+ The frame covers the part of the element that is actually visible (its box
6296
+ clipped by every clipping ancestor) and takes the rounded corners of
6297
+ whatever clips it. Where something else lies on top of the element (a card
6298
+ stacked over it), that stretch of the line is left out, so the frame never
6299
+ runs across what is in front. It is followed every frame while shown, so it
6300
+ stays on the element through hover transitions, motion, scrolling and edits.
6301
+
6302
+ Usage:
6303
+ const frame = new SelectFrame();
6304
+ frame.show(el, () => stillSelected(el)); // hides itself once false
6305
+ frame.hide();
6306
+ */
6307
+ const SVGNS = 'http://www.w3.org/2000/svg';
6308
+ const COLOR = '#00da89';
6309
+ const STEP = 4; // px between coverage samples along the line
6310
+ const RECHECK = 200; // ms between coverage checks while nothing moves
6311
+
6312
+ class SelectFrame {
6313
+ show(el, isCurrent) {
6314
+ this.hide();
6315
+ if (!el || !el.isConnected) return;
6316
+ const doc = el.ownerDocument;
6317
+ const win = doc.defaultView;
6318
+ if (!this.frame || this.frame.ownerDocument !== doc) {
6319
+ if (this.frame) this.frame.remove();
6320
+ const frame = doc.createElement('div');
6321
+ frame.setAttribute('data-cb-ui', '');
6322
+ frame.style.cssText = 'position:fixed;pointer-events:none;z-index:1000;display:none;';
6323
+ const svg = doc.createElementNS(SVGNS, 'svg');
6324
+ svg.style.cssText = 'position:absolute;left:0;top:0;width:100%;height:100%;overflow:visible;';
6325
+ const rect = doc.createElementNS(SVGNS, 'rect');
6326
+ rect.setAttribute('fill', 'none');
6327
+ rect.setAttribute('stroke', COLOR);
6328
+ rect.setAttribute('stroke-width', '1');
6329
+ svg.appendChild(rect);
6330
+ frame.appendChild(svg);
6331
+ doc.body.appendChild(frame);
6332
+ this.frame = frame;
6333
+ this.rect = rect;
6334
+ }
6335
+ const frame = this.frame;
6336
+ const rect = this.rect;
6337
+
6338
+ // Rotation and scale of the element on screen: its own transform and
6339
+ // every ancestor's (eg. a fanned card in a design layer).
6340
+ const turn = () => {
6341
+ let angle = 0,
6342
+ scale = 1;
6343
+ for (let p = el; p && p !== doc.documentElement; p = p.parentElement) {
6344
+ const t = win.getComputedStyle(p).transform;
6345
+ if (!t || t === 'none') continue;
6346
+ const m = t.match(/matrix\(([^)]+)\)/);
6347
+ if (!m) continue; // 3D: leave as is
6348
+ const [a, b] = m[1].split(',').map(parseFloat);
6349
+ angle += Math.atan2(b, a);
6350
+ scale *= Math.sqrt(a * a + b * b);
6351
+ }
6352
+ return {
6353
+ angle,
6354
+ scale
6355
+ };
6356
+ };
6357
+
6358
+ // The element's corners: its own, or those of a rounded wrapper of the
6359
+ // same size that clips it (eg. a card frame around a video).
6360
+ const ownRadius = () => {
6361
+ let radius = win.getComputedStyle(el).borderRadius;
6362
+ const w = el.offsetWidth,
6363
+ h = el.offsetHeight;
6364
+ for (let p = el.parentElement; radius === '0px' && p && p !== doc.body; p = p.parentElement) {
6365
+ if (Math.abs(p.offsetWidth - w) > 1 || Math.abs(p.offsetHeight - h) > 1) break;
6366
+ const cs = win.getComputedStyle(p);
6367
+ if (cs.overflowX !== 'visible' || cs.overflowY !== 'visible' || cs.clipPath !== 'none') radius = cs.borderRadius;
6368
+ }
6369
+ return radius;
6370
+ };
6371
+ const measure = () => {
6372
+ const r = el.getBoundingClientRect();
6373
+
6374
+ // A turned element: frame its own box, turned the same way.
6375
+ const {
6376
+ angle,
6377
+ scale
6378
+ } = turn();
6379
+ if (Math.abs(angle) > 0.002) {
6380
+ const w = el.offsetWidth * scale,
6381
+ h = el.offsetHeight * scale;
6382
+ return {
6383
+ left: (r.left + r.right) / 2 - w / 2,
6384
+ top: (r.top + r.bottom) / 2 - h / 2,
6385
+ width: w,
6386
+ height: h,
6387
+ angle,
6388
+ scale,
6389
+ radius: ownRadius()
6390
+ };
6391
+ }
6392
+ let left = r.left,
6393
+ top = r.top,
6394
+ right = r.right,
6395
+ bottom = r.bottom;
6396
+ let radius = ownRadius();
6397
+ let p = el.parentElement;
6398
+ while (p && p !== doc.body) {
6399
+ const cs = win.getComputedStyle(p);
6400
+ if (cs.overflowX !== 'visible' || cs.overflowY !== 'visible' || cs.clipPath !== 'none') {
6401
+ const c = p.getBoundingClientRect();
6402
+ const cut = c.left > left || c.top > top || c.right < right || c.bottom < bottom;
6403
+ left = Math.max(left, c.left);
6404
+ top = Math.max(top, c.top);
6405
+ right = Math.min(right, c.right);
6406
+ bottom = Math.min(bottom, c.bottom);
6407
+ // The clipping box is the visible frame (cuts it, or wraps it
6408
+ // exactly): its corners are the ones on screen.
6409
+ const wraps = Math.abs(c.left - left) < 1 && Math.abs(c.top - top) < 1 && Math.abs(c.right - right) < 1 && Math.abs(c.bottom - bottom) < 1;
6410
+ if ((cut || wraps) && cs.borderRadius !== '0px') radius = cs.borderRadius;
6411
+ }
6412
+ p = p.parentElement;
6413
+ }
6414
+ return {
6415
+ left,
6416
+ top,
6417
+ width: right - left,
6418
+ height: bottom - top,
6419
+ angle: 0,
6420
+ scale: 1,
6421
+ radius
6422
+ };
6423
+ };
6424
+
6425
+ // The corner radius as SVG rx/ry (first value; % of each side).
6426
+ const corner = (radius, w, h, scale) => {
6427
+ const v = (radius || '0').split(/[\s/]/)[0];
6428
+ const n = parseFloat(v) || 0;
6429
+ const rx = v.endsWith('%') ? w * n / 100 : n * scale;
6430
+ const ry = v.endsWith('%') ? h * n / 100 : n * scale;
6431
+ // Too large for the box: shrink both by the same factor, as the
6432
+ // browser does (border-radius: 999px is a pill, not an ellipse).
6433
+ const f = Math.min(1, rx ? w / (2 * rx) : 1, ry ? h / (2 * ry) : 1);
6434
+ return [rx * f, ry * f];
6435
+ };
6436
+
6437
+ // Is the element itself on top at this screen point? Other content
6438
+ // covers it there; the editor's own tools and this frame do not count.
6439
+ const ownHit = hit => !hit || hit === el || el.contains(hit) || hit.contains(el) || !!(hit.closest && hit.closest('[data-cb-ui], .is-tool'));
6440
+ // An element that ignores the pointer can't be tested: draw it whole.
6441
+ const testable = win.getComputedStyle(el).pointerEvents !== 'none';
6442
+
6443
+ // Leave out the stretches of the line that lie under other content.
6444
+ const coverage = m => {
6445
+ if (!testable) {
6446
+ rect.removeAttribute('stroke-dasharray');
6447
+ return;
6448
+ }
6449
+ const len = rect.getTotalLength();
6450
+ if (!len) return;
6451
+ const cx = m.width / 2,
6452
+ cy = m.height / 2;
6453
+ const cos = Math.cos(m.angle),
6454
+ sin = Math.sin(m.angle);
6455
+ const n = Math.max(8, Math.ceil(len / STEP));
6456
+ const seen = [];
6457
+ for (let i = 0; i < n; i++) {
6458
+ const pt = rect.getPointAtLength(len * (i + 0.5) / n);
6459
+ // 2px inside the line, toward the middle: a point of the element.
6460
+ let dx = cx - pt.x,
6461
+ dy = cy - pt.y;
6462
+ const d = Math.hypot(dx, dy) || 1;
6463
+ const lx = pt.x + dx / d * 2 - cx,
6464
+ ly = pt.y + dy / d * 2 - cy;
6465
+ const x = m.left + cx + lx * cos - ly * sin;
6466
+ const y = m.top + cy + lx * sin + ly * cos;
6467
+ seen.push(ownHit(doc.elementFromPoint(x, y)));
6468
+ }
6469
+ if (seen.every(Boolean)) {
6470
+ rect.removeAttribute('stroke-dasharray');
6471
+ return;
6472
+ }
6473
+ const dash = [];
6474
+ let run = 0,
6475
+ on = true;
6476
+ if (!seen[0]) dash.push(0); // dasharray starts with a drawn stretch
6477
+ on = seen[0];
6478
+ for (let i = 0; i < n; i++) {
6479
+ if (seen[i] === on) {
6480
+ run++;
6481
+ continue;
6482
+ }
6483
+ dash.push(run * len / n);
6484
+ run = 1;
6485
+ on = seen[i];
6486
+ }
6487
+ dash.push(run * len / n);
6488
+ if (dash.length % 2) dash.push(0);
6489
+ rect.setAttribute('stroke-dasharray', dash.join(' '));
6490
+ };
6491
+ let last = '';
6492
+ let checked = 0;
6493
+ const loop = {
6494
+ win,
6495
+ id: 0
6496
+ };
6497
+ const tick = () => {
6498
+ if (!el.isConnected || isCurrent && !isCurrent()) {
6499
+ frame.style.display = 'none';
6500
+ this.loop = null;
6501
+ return;
6502
+ }
6503
+ const m = measure();
6504
+ const key = `${m.left},${m.top},${m.width},${m.height},${m.angle},${m.radius}`;
6505
+ const now = win.performance.now();
6506
+ if (key !== last) {
6507
+ last = key;
6508
+ if (m.width <= 0 || m.height <= 0) {
6509
+ frame.style.display = 'none';
6510
+ } else {
6511
+ frame.style.left = m.left + 'px';
6512
+ frame.style.top = m.top + 'px';
6513
+ frame.style.width = m.width + 'px';
6514
+ frame.style.height = m.height + 'px';
6515
+ frame.style.transform = m.angle ? `rotate(${m.angle}rad)` : '';
6516
+ const [rx, ry] = corner(m.radius, m.width, m.height, m.scale);
6517
+ rect.setAttribute('x', 0.5);
6518
+ rect.setAttribute('y', 0.5);
6519
+ rect.setAttribute('width', Math.max(0, m.width - 1));
6520
+ rect.setAttribute('height', Math.max(0, m.height - 1));
6521
+ rect.setAttribute('rx', Math.max(0, rx - 0.5));
6522
+ rect.setAttribute('ry', Math.max(0, ry - 0.5));
6523
+ frame.style.display = 'block';
6524
+ coverage(m);
6525
+ checked = now;
6526
+ }
6527
+ } else if (frame.style.display === 'block' && now - checked > RECHECK) {
6528
+ coverage(m); // things can move over it while it stays put
6529
+ checked = now;
6530
+ }
6531
+ loop.id = win.requestAnimationFrame(tick);
6532
+ };
6533
+ this.loop = loop;
6534
+ tick();
6535
+ }
6536
+ hide() {
6537
+ if (this.loop) {
6538
+ this.loop.win.cancelAnimationFrame(this.loop.id);
6539
+ this.loop = null;
6540
+ }
6541
+ if (this.frame) this.frame.style.display = 'none';
6542
+ }
6543
+ }
6544
+
6287
6545
  class Util {
6288
6546
  constructor(builder) {
6289
6547
  this.builder = builder;
6290
6548
  this.dom = this.builder.dom;
6291
6549
  }
6550
+
6551
+ // A 1px frame that shows which element is selected (see selectframe.js).
6552
+ // frame.show(el, isCurrent) / frame.hide().
6553
+ createSelectFrame() {
6554
+ return new SelectFrame();
6555
+ }
6292
6556
  paintColorButton(btn, value) {
6293
6557
  if (!btn) return;
6294
6558
  let fill = btn.querySelector('span');
@@ -7935,6 +8199,22 @@ class Util {
7935
8199
  this.builder.uo.saveForUndo();
7936
8200
  let element = elm;
7937
8201
  let newelement;
8202
+
8203
+ // An image usually sits in a wrapper that is only there for the
8204
+ // picture (a frame with overflow/aspect-ratio, a link): new content
8205
+ // goes after the wrapper, not into it. Step out of every wrapper
8206
+ // that holds nothing but this image, up to the column.
8207
+ const onlyPicture = el => el.tagName.toLowerCase() === 'img' || el.childElementCount === 1 && el.textContent.trim() === '' && onlyPicture(el.firstElementChild);
8208
+ if (onlyPicture(element) && !element.closest('[data-cb-type]')) {
8209
+ const col = element.closest('.is-builder > div > div');
8210
+ while (col && element.parentElement && element.parentElement !== col && element.parentElement.childElementCount === 1 && element.parentElement.textContent.trim() === '') {
8211
+ element = element.parentElement;
8212
+ }
8213
+ // An image inside a line of text: after the paragraph, never
8214
+ // splitting it.
8215
+ const textBlock = element.parentElement && element.parentElement.closest('p, h1, h2, h3, h4, h5, h6, pre');
8216
+ if (textBlock && col && col.contains(textBlock)) element = textBlock;
8217
+ }
7938
8218
  const plugin = element.closest('[data-cb-type]');
7939
8219
  if (plugin) {
7940
8220
  element.insertAdjacentHTML('afterend', html);
@@ -21244,7 +21524,18 @@ const renderSnippetPanel = (builder, snippetOpen) => {
21244
21524
  const n = items.findIndex(el => el.offsetTop > top);
21245
21525
  return n === -1 ? items.length : n;
21246
21526
  };
21527
+
21528
+ // A press focuses the list too. Only keyboard focus picks the first thumbnail,
21529
+ // otherwise its scrollIntoView jumps the list to the top under the pointer.
21530
+ let pressed = false;
21531
+ snippetlist.addEventListener('pointerdown', () => {
21532
+ pressed = true;
21533
+ });
21534
+ snippetlist.addEventListener('blur', () => {
21535
+ pressed = false;
21536
+ });
21247
21537
  snippetlist.addEventListener('focus', () => {
21538
+ if (pressed) return;
21248
21539
  if (snippetlist.querySelector('.snippet-item[aria-selected="true"]')) return;
21249
21540
  const items = shownSnippets();
21250
21541
  if (items.length) markActive(items[0]);
@@ -30332,7 +30623,7 @@ function openImageEditor(builder, options) {
30332
30623
  // Freshly-uploaded images can be sitting in the browser cache from before
30333
30624
  // the CORS headers mattered; the classic dialog busts that the same way.
30334
30625
  let src = options.src;
30335
- if (src.indexOf('base64') === -1) {
30626
+ if (src.indexOf('data:') !== 0 && src.indexOf('blob:') !== 0) {
30336
30627
  src += (src.indexOf('?') === -1 ? '?' : '&') + `timestamp=${new Date().getTime()}`;
30337
30628
  }
30338
30629
  editor.load(src).catch(err => {
@@ -30469,17 +30760,22 @@ async function apply(builder, state) {
30469
30760
  if (options.onApply) options.onApply(url, filename);
30470
30761
  }
30471
30762
 
30763
+ /** A data: or blob: URL carries the image itself, not a file name. */
30764
+ function isInlineUrl(src) {
30765
+ return /^(data|blob):/i.test(src);
30766
+ }
30767
+
30472
30768
  /** The encoder to use, and the extension the saved file gets. */
30473
30769
  function pickFormat(src, hint) {
30474
30770
  let ext = '';
30475
30771
  src = src || '';
30476
- if (src.indexOf('base64') === -1) {
30772
+ if (!isInlineUrl(src)) {
30477
30773
  const filename = src.substring(src.lastIndexOf('/') + 1).split('?')[0];
30478
30774
  ext = filename.substr(filename.lastIndexOf('.') + 1).toLowerCase();
30479
30775
  } else if (hint) {
30480
30776
  ext = hint.substr(hint.lastIndexOf('.') + 1).toLowerCase();
30481
30777
  } else {
30482
- const match = src.match(/^data:image\/(.*?);base64,/);
30778
+ const match = src.match(/^data:image\/([a-z0-9.+-]+)[;,]/i);
30483
30779
  if (match) ext = match[1].toLowerCase();
30484
30780
  }
30485
30781
  if (ext === 'jpe') ext = 'jpg';
@@ -30497,7 +30793,7 @@ function pickFormat(src, hint) {
30497
30793
  function editedName(src, hint, ext, util, dom) {
30498
30794
  let basename;
30499
30795
  src = src || '';
30500
- if (src.indexOf('base64') === -1) {
30796
+ if (!isInlineUrl(src)) {
30501
30797
  const filename = src.substring(src.lastIndexOf('/') + 1).split('?')[0];
30502
30798
  basename = dom.baseName(filename);
30503
30799
  } else if (hint) {
@@ -30793,7 +31089,7 @@ class Image$1 {
30793
31089
  }
30794
31090
 
30795
31091
  // imagePreview.src = img.src;
30796
- if (img.src.indexOf('base64') === -1) {
31092
+ if (!/^(data|blob):/i.test(img.src)) {
30797
31093
  imagePreview.src = img.src + (img.src.indexOf('?') === -1 ? '?' : '&') + `timestamp=${new Date().getTime()}`;
30798
31094
  } else {
30799
31095
  imagePreview.src = img.src;
@@ -31163,7 +31459,7 @@ class Image$1 {
31163
31459
  if (this.builder.opts.onImageUpload) {
31164
31460
  let basename, extension, newname, newfilename;
31165
31461
  let src = img.getAttribute('src');
31166
- if (src.indexOf('base64') === -1) {
31462
+ if (!/^(data|blob):/i.test(src)) {
31167
31463
  let filename = src.substring(src.lastIndexOf('/') + 1);
31168
31464
  basename = dom.baseName(filename);
31169
31465
  extension = filename.substr(filename.lastIndexOf('.') + 1).toLowerCase();
@@ -31174,7 +31470,7 @@ class Image$1 {
31174
31470
  } else {
31175
31471
  basename = util.makeId();
31176
31472
  extension = 'png';
31177
- const match = src.match(/^data:image\/(.*?);base64,/);
31473
+ const match = src.match(/^data:image\/([a-z0-9.+-]+)[;,]/i);
31178
31474
  if (match) {
31179
31475
  extension = match[1]; // e.g., "png", "jpeg", "gif"
31180
31476
  }
@@ -31276,12 +31572,14 @@ class Image$1 {
31276
31572
  }
31277
31573
  if (this.builder.opts.imageRenameOnEdit) {
31278
31574
  let basename = '';
31279
- if (img.src.indexOf('base64') === -1) {
31575
+ if (!/^(data|blob):/i.test(img.getAttribute('src'))) {
31280
31576
  let src = img.getAttribute('src');
31281
31577
  let filename = src.substring(src.lastIndexOf('/') + 1);
31282
31578
  basename = dom.baseName(filename);
31283
- } else {
31579
+ } else if (img.getAttribute('data-filename')) {
31284
31580
  basename = dom.baseName(img.getAttribute('data-filename'));
31581
+ } else {
31582
+ basename = util.makeId();
31285
31583
  }
31286
31584
  let newname = '';
31287
31585
  if (basename.indexOf('-edit') !== -1) {
@@ -31436,7 +31734,7 @@ class Image$1 {
31436
31734
  }
31437
31735
 
31438
31736
  // imagePreview.src = img.src;
31439
- if (img.src.indexOf('base64') === -1) {
31737
+ if (!/^(data|blob):/i.test(img.src)) {
31440
31738
  imagePreview.src = img.src + (img.src.indexOf('?') === -1 ? '?' : '&') + `timestamp=${new Date().getTime()}`;
31441
31739
  } else {
31442
31740
  imagePreview.src = img.src;
@@ -31498,6 +31796,7 @@ class Image$1 {
31498
31796
  setTimeout(() => {
31499
31797
  let elm = this.builder.activeImage;
31500
31798
  if (!elm) return;
31799
+ if (this.builder.opts.imageTool === false) return;
31501
31800
  if (dom.hasClass(elm.parentNode, 'img-circular')) {
31502
31801
  elm = elm.parentNode;
31503
31802
  }
@@ -31506,7 +31805,8 @@ class Image$1 {
31506
31805
  imageTool.style.display = 'flex';
31507
31806
  let _toolwidth = imageTool.offsetWidth; //to get value, element must not hidden (display:none). So set display:flex before this.
31508
31807
 
31509
- let w = elm.offsetWidth * scaleX * this.builder.opts.zoom;
31808
+ let w = elm.getBoundingClientRect().width * scaleX; // rendered width: includes a scale on the image itself, on an ancestor (e.g. an animated tile) and the editor zoom
31809
+
31510
31810
  let top = newPos.top + window.pageYOffset;
31511
31811
  let left = newPos.left + window.pageXOffset;
31512
31812
  let toolLeft = left + (w / 2 - _toolwidth / 2);
@@ -31538,18 +31838,18 @@ class Image$1 {
31538
31838
  if (this.builder.activeImage) {
31539
31839
  let imageTool = this.imageTool;
31540
31840
  if (!imageTool) return;
31841
+ if (this.builder.opts.imageTool === false) return;
31541
31842
  let elm = this.builder.activeImage;
31542
31843
  if (dom.hasClass(elm.parentNode, 'img-circular')) {
31543
31844
  elm = elm.parentNode;
31544
31845
  }
31545
31846
  const newPos = util.getElementPosition(elm);
31546
31847
  let scaleX = newPos.scaleX;
31547
- let extraScaleX = this.getScale(elm).scaleX;
31548
31848
  let extraScaleY = this.getScale(elm).scaleX;
31549
31849
  imageTool.style.display = 'flex';
31550
31850
  let _toolwidth = imageTool.offsetWidth; //to get value, element must not hidden (display:none). So set display:flex before this.
31551
31851
 
31552
- let w = elm.offsetWidth * extraScaleX * scaleX * this.builder.opts.zoom;
31852
+ let w = elm.getBoundingClientRect().width * scaleX; // rendered width: includes a scale on the image itself, on an ancestor (e.g. an animated tile) and the editor zoom
31553
31853
  let h = elm.offsetHeight * extraScaleY * scaleX * this.builder.opts.zoom;
31554
31854
 
31555
31855
  // Compensate for the vertical shift caused by scaling
@@ -31629,26 +31929,37 @@ class Image$1 {
31629
31929
  if (dom.hasClass(elm.parentNode, 'img-circular')) {
31630
31930
  elm = elm.parentNode;
31631
31931
  }
31932
+
31933
+ // imageTool: false => the image is selected, but no floating tool.
31934
+ // The tool is still created (hidden): other code looks it up.
31935
+ if (this.builder.opts.imageTool === false) {
31936
+ this.renderTool();
31937
+ this.hideImageTool();
31938
+ return;
31939
+ }
31632
31940
  const newPos = util.getElementPosition(elm);
31633
31941
  let scaleX = newPos.scaleX;
31634
- let extraScaleX = this.getScale(elm).scaleX;
31635
31942
  let extraScaleY = this.getScale(elm).scaleX;
31636
31943
  this.renderTool();
31637
31944
  let imageTool = this.imageTool;
31638
31945
  imageTool.style.display = 'flex';
31639
31946
 
31640
- /* builder.imageToolMinimal => reduce the tool to source changes only:
31641
- hide Link (wraps the image in an anchor) and Edit (image editor).
31642
- Set per click by the caller.
31947
+ /* builder.imageToolMinimal => hide Link, which wraps the image in an
31948
+ anchor. Replace, Browse and Edit (only swaps in an edited copy of
31949
+ the picture) stay. Set per click by the caller.
31643
31950
  Must run BEFORE offsetWidth below, which centers the tool. */
31644
31951
  const minimalTool = this.builder.imageToolMinimal;
31645
31952
  const btnLinkTool = imageTool.querySelector('.image-link');
31646
- const btnEditTool = imageTool.querySelector('.image-edit');
31647
31953
  if (btnLinkTool) btnLinkTool.style.display = minimalTool ? 'none' : '';
31648
- if (btnEditTool) btnEditTool.style.display = minimalTool ? 'none' : '';
31954
+
31955
+ // An SVG (eg. a placeholder) is a drawing, not a photo: editing
31956
+ // would only flatten it to a PNG. Edit shows for every other image.
31957
+ const btnEditTool = imageTool.querySelector('.image-edit');
31958
+ const isSvg = /^data:image\/svg\+xml|\.svg([?#]|$)/i.test(elm.getAttribute('src') || '');
31959
+ if (btnEditTool) btnEditTool.style.display = isSvg ? 'none' : '';
31649
31960
  let _toolwidth = imageTool.offsetWidth; //to get value, element must not hidden (display:none). So set display:flex before this.
31650
31961
 
31651
- let w = elm.offsetWidth * extraScaleX * scaleX * this.builder.opts.zoom;
31962
+ let w = elm.getBoundingClientRect().width * scaleX; // rendered width: includes a scale on the image itself, on an ancestor (e.g. an animated tile) and the editor zoom
31652
31963
  let h = elm.offsetHeight * extraScaleY * scaleX * this.builder.opts.zoom;
31653
31964
 
31654
31965
  // Compensate for the vertical shift caused by scaling
@@ -65310,7 +65621,8 @@ class InscribeRegion {
65310
65621
  const opts = {
65311
65622
  // 'none' => no blue selection wash, just border + handles, like legacy.
65312
65623
  images: {
65313
- tint: 'none'
65624
+ tint: 'none',
65625
+ resize: this.builder.opts.imageResize !== false
65314
65626
  },
65315
65627
  // ContentBuilder owns the PASTE gesture: the column `paste` listener
65316
65628
  // (contentbuilder.js) cleans per the user's preference (text /
@@ -94969,6 +95281,11 @@ class ContentBuilder {
94969
95281
  // own computer).
94970
95282
  imageEditorLoadCube: false,
94971
95283
  imageEmbed: true,
95284
+ // false: no resize handles on a selected image.
95285
+ imageResize: true,
95286
+ // false: no floating tool (Change Image, Browse, Link, Edit) on a
95287
+ // selected image. The image can still be changed from a panel.
95288
+ imageTool: true,
94972
95289
  imageselect: '',
94973
95290
  fileselect: '',
94974
95291
  videoselect: '',