apple-notes-mcp 2.9.6 → 2.9.8

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.
Files changed (3) hide show
  1. package/README.md +35 -2
  2. package/build/index.js +2361 -282
  3. package/package.json +1 -1
package/build/index.js CHANGED
@@ -417,11 +417,11 @@ var require_codegen = __commonJS({
417
417
  const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
418
418
  return `${varKind} ${this.name}${rhs};` + _n;
419
419
  }
420
- optimizeNames(names, constants6) {
420
+ optimizeNames(names, constants7) {
421
421
  if (!names[this.name.str])
422
422
  return;
423
423
  if (this.rhs)
424
- this.rhs = optimizeExpr(this.rhs, names, constants6);
424
+ this.rhs = optimizeExpr(this.rhs, names, constants7);
425
425
  return this;
426
426
  }
427
427
  get names() {
@@ -438,10 +438,10 @@ var require_codegen = __commonJS({
438
438
  render({ _n }) {
439
439
  return `${this.lhs} = ${this.rhs};` + _n;
440
440
  }
441
- optimizeNames(names, constants6) {
441
+ optimizeNames(names, constants7) {
442
442
  if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects)
443
443
  return;
444
- this.rhs = optimizeExpr(this.rhs, names, constants6);
444
+ this.rhs = optimizeExpr(this.rhs, names, constants7);
445
445
  return this;
446
446
  }
447
447
  get names() {
@@ -502,8 +502,8 @@ var require_codegen = __commonJS({
502
502
  optimizeNodes() {
503
503
  return `${this.code}` ? this : void 0;
504
504
  }
505
- optimizeNames(names, constants6) {
506
- this.code = optimizeExpr(this.code, names, constants6);
505
+ optimizeNames(names, constants7) {
506
+ this.code = optimizeExpr(this.code, names, constants7);
507
507
  return this;
508
508
  }
509
509
  get names() {
@@ -532,12 +532,12 @@ var require_codegen = __commonJS({
532
532
  }
533
533
  return nodes.length > 0 ? this : void 0;
534
534
  }
535
- optimizeNames(names, constants6) {
535
+ optimizeNames(names, constants7) {
536
536
  const { nodes } = this;
537
537
  let i = nodes.length;
538
538
  while (i--) {
539
539
  const n = nodes[i];
540
- if (n.optimizeNames(names, constants6))
540
+ if (n.optimizeNames(names, constants7))
541
541
  continue;
542
542
  subtractNames(names, n.names);
543
543
  nodes.splice(i, 1);
@@ -590,12 +590,12 @@ var require_codegen = __commonJS({
590
590
  return void 0;
591
591
  return this;
592
592
  }
593
- optimizeNames(names, constants6) {
593
+ optimizeNames(names, constants7) {
594
594
  var _a;
595
- this.else = (_a = this.else) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants6);
596
- if (!(super.optimizeNames(names, constants6) || this.else))
595
+ this.else = (_a = this.else) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants7);
596
+ if (!(super.optimizeNames(names, constants7) || this.else))
597
597
  return;
598
- this.condition = optimizeExpr(this.condition, names, constants6);
598
+ this.condition = optimizeExpr(this.condition, names, constants7);
599
599
  return this;
600
600
  }
601
601
  get names() {
@@ -618,10 +618,10 @@ var require_codegen = __commonJS({
618
618
  render(opts) {
619
619
  return `for(${this.iteration})` + super.render(opts);
620
620
  }
621
- optimizeNames(names, constants6) {
622
- if (!super.optimizeNames(names, constants6))
621
+ optimizeNames(names, constants7) {
622
+ if (!super.optimizeNames(names, constants7))
623
623
  return;
624
- this.iteration = optimizeExpr(this.iteration, names, constants6);
624
+ this.iteration = optimizeExpr(this.iteration, names, constants7);
625
625
  return this;
626
626
  }
627
627
  get names() {
@@ -657,10 +657,10 @@ var require_codegen = __commonJS({
657
657
  render(opts) {
658
658
  return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
659
659
  }
660
- optimizeNames(names, constants6) {
661
- if (!super.optimizeNames(names, constants6))
660
+ optimizeNames(names, constants7) {
661
+ if (!super.optimizeNames(names, constants7))
662
662
  return;
663
- this.iterable = optimizeExpr(this.iterable, names, constants6);
663
+ this.iterable = optimizeExpr(this.iterable, names, constants7);
664
664
  return this;
665
665
  }
666
666
  get names() {
@@ -702,11 +702,11 @@ var require_codegen = __commonJS({
702
702
  (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
703
703
  return this;
704
704
  }
705
- optimizeNames(names, constants6) {
705
+ optimizeNames(names, constants7) {
706
706
  var _a, _b;
707
- super.optimizeNames(names, constants6);
708
- (_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants6);
709
- (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants6);
707
+ super.optimizeNames(names, constants7);
708
+ (_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants7);
709
+ (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants7);
710
710
  return this;
711
711
  }
712
712
  get names() {
@@ -1007,7 +1007,7 @@ var require_codegen = __commonJS({
1007
1007
  function addExprNames(names, from) {
1008
1008
  return from instanceof code_1._CodeOrName ? addNames(names, from.names) : names;
1009
1009
  }
1010
- function optimizeExpr(expr, names, constants6) {
1010
+ function optimizeExpr(expr, names, constants7) {
1011
1011
  if (expr instanceof code_1.Name)
1012
1012
  return replaceName(expr);
1013
1013
  if (!canOptimize(expr))
@@ -1022,14 +1022,14 @@ var require_codegen = __commonJS({
1022
1022
  return items;
1023
1023
  }, []));
1024
1024
  function replaceName(n) {
1025
- const c = constants6[n.str];
1025
+ const c = constants7[n.str];
1026
1026
  if (c === void 0 || names[n.str] !== 1)
1027
1027
  return n;
1028
1028
  delete names[n.str];
1029
1029
  return c;
1030
1030
  }
1031
1031
  function canOptimize(e) {
1032
- return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants6[c.str] !== void 0);
1032
+ return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants7[c.str] !== void 0);
1033
1033
  }
1034
1034
  }
1035
1035
  function subtractNames(names, from) {
@@ -3558,14 +3558,14 @@ var require_utils = __commonJS({
3558
3558
  }
3559
3559
  return output;
3560
3560
  }
3561
- function recomposeAuthority(component) {
3561
+ function recomposeAuthority(component2) {
3562
3562
  const uriTokens = [];
3563
- if (component.userinfo !== void 0) {
3564
- uriTokens.push(encodeUserinfo(component.userinfo));
3563
+ if (component2.userinfo !== void 0) {
3564
+ uriTokens.push(encodeUserinfo(component2.userinfo));
3565
3565
  uriTokens.push("@");
3566
3566
  }
3567
- if (component.host !== void 0) {
3568
- let host = component.host;
3567
+ if (component2.host !== void 0) {
3568
+ let host = component2.host;
3569
3569
  if (!isIPv4(host)) {
3570
3570
  let ipV6res = normalizeIPv6(host);
3571
3571
  if (ipV6res.isIPV6 !== true && ipV6res.isIPVFuture !== true) {
@@ -3580,9 +3580,9 @@ var require_utils = __commonJS({
3580
3580
  }
3581
3581
  uriTokens.push(host);
3582
3582
  }
3583
- if (typeof component.port === "number" || typeof component.port === "string") {
3583
+ if (typeof component2.port === "number" || typeof component2.port === "string") {
3584
3584
  uriTokens.push(":");
3585
- uriTokens.push(String(component.port));
3585
+ uriTokens.push(String(component2.port));
3586
3586
  }
3587
3587
  return uriTokens.length ? uriTokens.join("") : void 0;
3588
3588
  }
@@ -3641,21 +3641,21 @@ var require_schemes = __commonJS({
3641
3641
  return false;
3642
3642
  }
3643
3643
  }
3644
- function httpParse(component) {
3645
- if (!component.host) {
3646
- component.error = component.error || "HTTP URIs must have a host.";
3644
+ function httpParse(component2) {
3645
+ if (!component2.host) {
3646
+ component2.error = component2.error || "HTTP URIs must have a host.";
3647
3647
  }
3648
- return component;
3648
+ return component2;
3649
3649
  }
3650
- function httpSerialize(component) {
3651
- const secure = String(component.scheme).toLowerCase() === "https";
3652
- if (component.port === (secure ? 443 : 80) || component.port === "") {
3653
- component.port = void 0;
3650
+ function httpSerialize(component2) {
3651
+ const secure = String(component2.scheme).toLowerCase() === "https";
3652
+ if (component2.port === (secure ? 443 : 80) || component2.port === "") {
3653
+ component2.port = void 0;
3654
3654
  }
3655
- if (!component.path) {
3656
- component.path = "/";
3655
+ if (!component2.path) {
3656
+ component2.path = "/";
3657
3657
  }
3658
- return component;
3658
+ return component2;
3659
3659
  }
3660
3660
  function wsParse(wsComponent) {
3661
3661
  wsComponent.secure = wsIsSecure(wsComponent);
@@ -3935,7 +3935,7 @@ var require_fast_uri = __commonJS({
3935
3935
  return normalizedA !== void 0 && normalizedB !== void 0 && normalizedA === normalizedB;
3936
3936
  }
3937
3937
  function serialize(cmpts, opts) {
3938
- const component = {
3938
+ const component2 = {
3939
3939
  host: cmpts.host,
3940
3940
  scheme: cmpts.scheme,
3941
3941
  userinfo: cmpts.userinfo,
@@ -3953,36 +3953,36 @@ var require_fast_uri = __commonJS({
3953
3953
  };
3954
3954
  const options = Object.assign({}, opts);
3955
3955
  const uriTokens = [];
3956
- if (component.scheme) {
3957
- component.scheme = decodeValidScheme(component.scheme);
3958
- }
3959
- const schemeHandler = getSchemeHandler(options.scheme || component.scheme);
3960
- if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(component, options);
3961
- const hasAuthority = component.userinfo !== void 0 || component.host !== void 0 || component.port !== void 0;
3962
- const pathNoScheme = !options.skipEscape && component.scheme === void 0 && !hasAuthority;
3963
- if (component.path !== void 0) {
3956
+ if (component2.scheme) {
3957
+ component2.scheme = decodeValidScheme(component2.scheme);
3958
+ }
3959
+ const schemeHandler = getSchemeHandler(options.scheme || component2.scheme);
3960
+ if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(component2, options);
3961
+ const hasAuthority = component2.userinfo !== void 0 || component2.host !== void 0 || component2.port !== void 0;
3962
+ const pathNoScheme = !options.skipEscape && component2.scheme === void 0 && !hasAuthority;
3963
+ if (component2.path !== void 0) {
3964
3964
  if (!options.skipEscape) {
3965
- component.path = serializePathEncoding(component.path, pathNoScheme);
3965
+ component2.path = serializePathEncoding(component2.path, pathNoScheme);
3966
3966
  } else {
3967
- component.path = normalizePercentEncoding(component.path);
3967
+ component2.path = normalizePercentEncoding(component2.path);
3968
3968
  }
3969
3969
  }
3970
- if (options.reference !== "suffix" && component.scheme) {
3971
- component.scheme = decodeValidScheme(component.scheme);
3972
- uriTokens.push(component.scheme, ":");
3970
+ if (options.reference !== "suffix" && component2.scheme) {
3971
+ component2.scheme = decodeValidScheme(component2.scheme);
3972
+ uriTokens.push(component2.scheme, ":");
3973
3973
  }
3974
- const authority = recomposeAuthority(component);
3974
+ const authority = recomposeAuthority(component2);
3975
3975
  if (authority !== void 0) {
3976
3976
  if (options.reference !== "suffix") {
3977
3977
  uriTokens.push("//");
3978
3978
  }
3979
3979
  uriTokens.push(authority);
3980
- if (component.path && component.path[0] !== "/") {
3980
+ if (component2.path && component2.path[0] !== "/") {
3981
3981
  uriTokens.push("/");
3982
3982
  }
3983
3983
  }
3984
- if (component.path !== void 0) {
3985
- let s = component.path;
3984
+ if (component2.path !== void 0) {
3985
+ let s = component2.path;
3986
3986
  if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
3987
3987
  s = removeDotSegments(s);
3988
3988
  }
@@ -3994,11 +3994,11 @@ var require_fast_uri = __commonJS({
3994
3994
  }
3995
3995
  uriTokens.push(s);
3996
3996
  }
3997
- if (component.query !== void 0) {
3998
- uriTokens.push("?", encodeQuery(component.query));
3997
+ if (component2.query !== void 0) {
3998
+ uriTokens.push("?", encodeQuery(component2.query));
3999
3999
  }
4000
- if (component.fragment !== void 0) {
4001
- uriTokens.push("#", encodeFragment(component.fragment));
4000
+ if (component2.fragment !== void 0) {
4001
+ uriTokens.push("#", encodeFragment(component2.fragment));
4002
4002
  }
4003
4003
  return uriTokens.join("");
4004
4004
  }
@@ -4014,14 +4014,14 @@ var require_fast_uri = __commonJS({
4014
4014
  }
4015
4015
  return void 0;
4016
4016
  }
4017
- function hasMalformedPercentEncoding(component) {
4018
- if (component === void 0) return false;
4019
- let percent = component.indexOf("%");
4017
+ function hasMalformedPercentEncoding(component2) {
4018
+ if (component2 === void 0) return false;
4019
+ let percent = component2.indexOf("%");
4020
4020
  while (percent !== -1) {
4021
- if (percent + 2 >= component.length || !/^[\da-f]{2}$/iu.test(component.slice(percent + 1, percent + 3))) {
4021
+ if (percent + 2 >= component2.length || !/^[\da-f]{2}$/iu.test(component2.slice(percent + 1, percent + 3))) {
4022
4022
  return true;
4023
4023
  }
4024
- percent = component.indexOf("%", percent + 3);
4024
+ percent = component2.indexOf("%", percent + 3);
4025
4025
  }
4026
4026
  return false;
4027
4027
  }
@@ -7422,7 +7422,7 @@ var require_DOMException = __commonJS({
7422
7422
  "INVALID_NODE_TYPE_ERR (24): the supplied node is invalid or has an invalid ancestor for this operation",
7423
7423
  "DATA_CLONE_ERR (25): the object can not be cloned."
7424
7424
  ];
7425
- var constants6 = {
7425
+ var constants7 = {
7426
7426
  INDEX_SIZE_ERR,
7427
7427
  DOMSTRING_SIZE_ERR: 2,
7428
7428
  // historical
@@ -7461,8 +7461,8 @@ var require_DOMException = __commonJS({
7461
7461
  this.name = names[code];
7462
7462
  }
7463
7463
  DOMException.prototype.__proto__ = Error.prototype;
7464
- for (c in constants6) {
7465
- v = { value: constants6[c] };
7464
+ for (c in constants7) {
7465
+ v = { value: constants7[c] };
7466
7466
  Object.defineProperty(DOMException, c, v);
7467
7467
  Object.defineProperty(DOMException.prototype, c, v);
7468
7468
  }
@@ -8859,23 +8859,23 @@ var require_attributes = __commonJS({
8859
8859
  "node_modules/.pnpm/@mixmark-io+domino@2.2.0/node_modules/@mixmark-io/domino/lib/attributes.js"(exports) {
8860
8860
  "use strict";
8861
8861
  var utils = require_utils2();
8862
- exports.property = function(attr) {
8863
- if (Array.isArray(attr.type)) {
8862
+ exports.property = function(attr2) {
8863
+ if (Array.isArray(attr2.type)) {
8864
8864
  var valid = /* @__PURE__ */ Object.create(null);
8865
- attr.type.forEach(function(val) {
8865
+ attr2.type.forEach(function(val) {
8866
8866
  valid[val.value || val] = val.alias || val;
8867
8867
  });
8868
- var missingValueDefault = attr.missing;
8868
+ var missingValueDefault = attr2.missing;
8869
8869
  if (missingValueDefault === void 0) {
8870
8870
  missingValueDefault = null;
8871
8871
  }
8872
- var invalidValueDefault = attr.invalid;
8872
+ var invalidValueDefault = attr2.invalid;
8873
8873
  if (invalidValueDefault === void 0) {
8874
8874
  invalidValueDefault = missingValueDefault;
8875
8875
  }
8876
8876
  return {
8877
8877
  get: function() {
8878
- var v = this._getattr(attr.name);
8878
+ var v = this._getattr(attr2.name);
8879
8879
  if (v === null) return missingValueDefault;
8880
8880
  v = valid[v.toLowerCase()];
8881
8881
  if (v !== void 0) return v;
@@ -8883,38 +8883,38 @@ var require_attributes = __commonJS({
8883
8883
  return v;
8884
8884
  },
8885
8885
  set: function(v) {
8886
- this._setattr(attr.name, v);
8886
+ this._setattr(attr2.name, v);
8887
8887
  }
8888
8888
  };
8889
- } else if (attr.type === Boolean) {
8889
+ } else if (attr2.type === Boolean) {
8890
8890
  return {
8891
8891
  get: function() {
8892
- return this.hasAttribute(attr.name);
8892
+ return this.hasAttribute(attr2.name);
8893
8893
  },
8894
8894
  set: function(v) {
8895
8895
  if (v) {
8896
- this._setattr(attr.name, "");
8896
+ this._setattr(attr2.name, "");
8897
8897
  } else {
8898
- this.removeAttribute(attr.name);
8898
+ this.removeAttribute(attr2.name);
8899
8899
  }
8900
8900
  }
8901
8901
  };
8902
- } else if (attr.type === Number || attr.type === "long" || attr.type === "unsigned long" || attr.type === "limited unsigned long with fallback") {
8903
- return numberPropDesc(attr);
8904
- } else if (!attr.type || attr.type === String) {
8902
+ } else if (attr2.type === Number || attr2.type === "long" || attr2.type === "unsigned long" || attr2.type === "limited unsigned long with fallback") {
8903
+ return numberPropDesc(attr2);
8904
+ } else if (!attr2.type || attr2.type === String) {
8905
8905
  return {
8906
8906
  get: function() {
8907
- return this._getattr(attr.name) || "";
8907
+ return this._getattr(attr2.name) || "";
8908
8908
  },
8909
8909
  set: function(v) {
8910
- if (attr.treatNullAsEmptyString && v === null) {
8910
+ if (attr2.treatNullAsEmptyString && v === null) {
8911
8911
  v = "";
8912
8912
  }
8913
- this._setattr(attr.name, v);
8913
+ this._setattr(attr2.name, v);
8914
8914
  }
8915
8915
  };
8916
- } else if (typeof attr.type === "function") {
8917
- return attr.type(attr.name, attr);
8916
+ } else if (typeof attr2.type === "function") {
8917
+ return attr2.type(attr2.name, attr2);
8918
8918
  }
8919
8919
  throw new Error("Invalid attribute definition");
8920
8920
  };
@@ -9382,23 +9382,23 @@ var require_select = __commonJS({
9382
9382
  "attr": function(key, op, val, i) {
9383
9383
  op = operators[op];
9384
9384
  return function(el) {
9385
- var attr;
9385
+ var attr2;
9386
9386
  switch (key) {
9387
9387
  case "for":
9388
- attr = el.htmlFor;
9388
+ attr2 = el.htmlFor;
9389
9389
  break;
9390
9390
  case "class":
9391
- attr = el.className;
9392
- if (attr === "" && el.getAttribute("class") == null) {
9393
- attr = null;
9391
+ attr2 = el.className;
9392
+ if (attr2 === "" && el.getAttribute("class") == null) {
9393
+ attr2 = null;
9394
9394
  }
9395
9395
  break;
9396
9396
  case "href":
9397
9397
  case "src":
9398
- attr = el.getAttribute(key, 2);
9398
+ attr2 = el.getAttribute(key, 2);
9399
9399
  break;
9400
9400
  case "title":
9401
- attr = el.getAttribute("title") || null;
9401
+ attr2 = el.getAttribute("title") || null;
9402
9402
  break;
9403
9403
  // careful with attributes with special getter functions
9404
9404
  case "id":
@@ -9409,7 +9409,7 @@ var require_select = __commonJS({
9409
9409
  case "tabIndex":
9410
9410
  case "style":
9411
9411
  if (el.getAttribute) {
9412
- attr = el.getAttribute(key);
9412
+ attr2 = el.getAttribute(key);
9413
9413
  break;
9414
9414
  }
9415
9415
  /* falls through */
@@ -9417,16 +9417,16 @@ var require_select = __commonJS({
9417
9417
  if (el.hasAttribute && !el.hasAttribute(key)) {
9418
9418
  break;
9419
9419
  }
9420
- attr = el[key] != null ? el[key] : el.getAttribute && el.getAttribute(key);
9420
+ attr2 = el[key] != null ? el[key] : el.getAttribute && el.getAttribute(key);
9421
9421
  break;
9422
9422
  }
9423
- if (attr == null) return;
9424
- attr = attr + "";
9423
+ if (attr2 == null) return;
9424
+ attr2 = attr2 + "";
9425
9425
  if (i) {
9426
- attr = attr.toLowerCase();
9426
+ attr2 = attr2.toLowerCase();
9427
9427
  val = val.toLowerCase();
9428
9428
  }
9429
- return op(attr, val);
9429
+ return op(attr2, val);
9430
9430
  };
9431
9431
  },
9432
9432
  ":first-child": function(el) {
@@ -9554,8 +9554,8 @@ var require_select = __commonJS({
9554
9554
  var param = +el + 1;
9555
9555
  return function(el2) {
9556
9556
  if (!el2.href) return;
9557
- var url = window2.location + "", href = el2 + "";
9558
- return truncateUrl(url, param) === truncateUrl(href, param);
9557
+ var url = window2.location + "", href2 = el2 + "";
9558
+ return truncateUrl(url, param) === truncateUrl(href2, param);
9559
9559
  };
9560
9560
  },
9561
9561
  ":default": function(el) {
@@ -9581,9 +9581,9 @@ var require_select = __commonJS({
9581
9581
  },
9582
9582
  ":read-only": function(el) {
9583
9583
  if (el.readOnly) return true;
9584
- var attr = el.getAttribute("contenteditable"), prop = el.contentEditable, name = el.nodeName.toLowerCase();
9584
+ var attr2 = el.getAttribute("contenteditable"), prop = el.contentEditable, name = el.nodeName.toLowerCase();
9585
9585
  name = name !== "input" && name !== "textarea";
9586
- return (name || el.disabled) && attr == null && prop !== "true";
9586
+ return (name || el.disabled) && attr2 == null && prop !== "true";
9587
9587
  },
9588
9588
  ":read-write": function(el) {
9589
9589
  return !selectors[":read-only"](el);
@@ -9638,38 +9638,38 @@ var require_select = __commonJS({
9638
9638
  "-": function() {
9639
9639
  return true;
9640
9640
  },
9641
- "=": function(attr, val) {
9642
- return attr === val;
9641
+ "=": function(attr2, val) {
9642
+ return attr2 === val;
9643
9643
  },
9644
- "*=": function(attr, val) {
9645
- return attr.indexOf(val) !== -1;
9644
+ "*=": function(attr2, val) {
9645
+ return attr2.indexOf(val) !== -1;
9646
9646
  },
9647
- "~=": function(attr, val) {
9647
+ "~=": function(attr2, val) {
9648
9648
  var i, s, f, l;
9649
9649
  for (s = 0; true; s = i + 1) {
9650
- i = attr.indexOf(val, s);
9650
+ i = attr2.indexOf(val, s);
9651
9651
  if (i === -1) return false;
9652
- f = attr[i - 1];
9653
- l = attr[i + val.length];
9652
+ f = attr2[i - 1];
9653
+ l = attr2[i + val.length];
9654
9654
  if ((!f || f === " ") && (!l || l === " ")) return true;
9655
9655
  }
9656
9656
  },
9657
- "|=": function(attr, val) {
9658
- var i = attr.indexOf(val), l;
9657
+ "|=": function(attr2, val) {
9658
+ var i = attr2.indexOf(val), l;
9659
9659
  if (i !== 0) return;
9660
- l = attr[i + val.length];
9660
+ l = attr2[i + val.length];
9661
9661
  return l === "-" || !l;
9662
9662
  },
9663
- "^=": function(attr, val) {
9664
- return attr.indexOf(val) === 0;
9663
+ "^=": function(attr2, val) {
9664
+ return attr2.indexOf(val) === 0;
9665
9665
  },
9666
- "$=": function(attr, val) {
9667
- var i = attr.lastIndexOf(val);
9668
- return i !== -1 && i + val.length === attr.length;
9666
+ "$=": function(attr2, val) {
9667
+ var i = attr2.lastIndexOf(val);
9668
+ return i !== -1 && i + val.length === attr2.length;
9669
9669
  },
9670
9670
  // non-standard
9671
- "!=": function(attr, val) {
9672
- return attr !== val;
9671
+ "!=": function(attr2, val) {
9672
+ return attr2 !== val;
9673
9673
  }
9674
9674
  };
9675
9675
  var combinators = {
@@ -9721,9 +9721,9 @@ var require_select = __commonJS({
9721
9721
  }
9722
9722
  ref.combinator = function(el) {
9723
9723
  if (!node || !node.getAttribute) return;
9724
- var attr = node.getAttribute(name) || "";
9725
- if (attr[0] === "#") attr = attr.substring(1);
9726
- if (attr === el.id && test(node)) {
9724
+ var attr2 = node.getAttribute(name) || "";
9725
+ if (attr2[0] === "#") attr2 = attr2.substring(1);
9726
+ if (attr2 === el.id && test(node)) {
9727
9727
  return node;
9728
9728
  }
9729
9729
  };
@@ -10107,18 +10107,18 @@ var require_NamedNodeMap = __commonJS({
10107
10107
  setNamedItem: { value: utils.nyi },
10108
10108
  setNamedItemNS: { value: utils.nyi },
10109
10109
  removeNamedItem: { value: function removeNamedItem(qualifiedName) {
10110
- var attr = this.element.getAttributeNode(qualifiedName);
10111
- if (attr) {
10110
+ var attr2 = this.element.getAttributeNode(qualifiedName);
10111
+ if (attr2) {
10112
10112
  this.element.removeAttribute(qualifiedName);
10113
- return attr;
10113
+ return attr2;
10114
10114
  }
10115
10115
  utils.NotFoundError();
10116
10116
  } },
10117
10117
  removeNamedItemNS: { value: function removeNamedItemNS(ns, lname) {
10118
- var attr = this.element.getAttributeNodeNS(ns, lname);
10119
- if (attr) {
10118
+ var attr2 = this.element.getAttributeNodeNS(ns, lname);
10119
+ if (attr2) {
10120
10120
  this.element.removeAttributeNS(ns, lname);
10121
- return attr;
10121
+ return attr2;
10122
10122
  }
10123
10123
  utils.NotFoundError();
10124
10124
  } }
@@ -10558,28 +10558,28 @@ var require_Element = __commonJS({
10558
10558
  *
10559
10559
  */
10560
10560
  getAttribute: { value: function getAttribute(qname) {
10561
- var attr = this.getAttributeNode(qname);
10562
- return attr ? attr.value : null;
10561
+ var attr2 = this.getAttributeNode(qname);
10562
+ return attr2 ? attr2.value : null;
10563
10563
  } },
10564
10564
  getAttributeNS: { value: function getAttributeNS(ns, lname) {
10565
- var attr = this.getAttributeNodeNS(ns, lname);
10566
- return attr ? attr.value : null;
10565
+ var attr2 = this.getAttributeNodeNS(ns, lname);
10566
+ return attr2 ? attr2.value : null;
10567
10567
  } },
10568
10568
  getAttributeNode: { value: function getAttributeNode(qname) {
10569
10569
  qname = String(qname);
10570
10570
  if (/[A-Z]/.test(qname) && this.isHTML)
10571
10571
  qname = utils.toASCIILowerCase(qname);
10572
- var attr = this._attrsByQName[qname];
10573
- if (!attr) return null;
10574
- if (Array.isArray(attr))
10575
- attr = attr[0];
10576
- return attr;
10572
+ var attr2 = this._attrsByQName[qname];
10573
+ if (!attr2) return null;
10574
+ if (Array.isArray(attr2))
10575
+ attr2 = attr2[0];
10576
+ return attr2;
10577
10577
  } },
10578
10578
  getAttributeNodeNS: { value: function getAttributeNodeNS(ns, lname) {
10579
10579
  ns = ns === void 0 || ns === null ? "" : String(ns);
10580
10580
  lname = String(lname);
10581
- var attr = this._attrsByLName[ns + "|" + lname];
10582
- return attr ? attr : null;
10581
+ var attr2 = this._attrsByLName[ns + "|" + lname];
10582
+ return attr2 ? attr2 : null;
10583
10583
  } },
10584
10584
  hasAttribute: { value: function hasAttribute(qname) {
10585
10585
  qname = String(qname);
@@ -10618,16 +10618,16 @@ var require_Element = __commonJS({
10618
10618
  } },
10619
10619
  // Set the attribute without error checking. The parser uses this.
10620
10620
  _setAttribute: { value: function _setAttribute(qname, value) {
10621
- var attr = this._attrsByQName[qname];
10621
+ var attr2 = this._attrsByQName[qname];
10622
10622
  var isnew;
10623
- if (!attr) {
10624
- attr = this._newattr(qname);
10623
+ if (!attr2) {
10624
+ attr2 = this._newattr(qname);
10625
10625
  isnew = true;
10626
10626
  } else {
10627
- if (Array.isArray(attr)) attr = attr[0];
10627
+ if (Array.isArray(attr2)) attr2 = attr2[0];
10628
10628
  }
10629
- attr.value = value;
10630
- if (this._attributes) this._attributes[qname] = attr;
10629
+ attr2.value = value;
10630
+ if (this._attributes) this._attributes[qname] = attr2;
10631
10631
  if (isnew && this._newattrhook) this._newattrhook(qname, value);
10632
10632
  } },
10633
10633
  // Check for errors, and then set the attribute
@@ -10650,25 +10650,25 @@ var require_Element = __commonJS({
10650
10650
  }
10651
10651
  if (ns === "" || ns === void 0) ns = null;
10652
10652
  var key = (ns === null ? "" : ns) + "|" + lname;
10653
- var attr = this._attrsByLName[key];
10653
+ var attr2 = this._attrsByLName[key];
10654
10654
  var isnew;
10655
- if (!attr) {
10656
- attr = new Attr(this, lname, prefix, ns);
10655
+ if (!attr2) {
10656
+ attr2 = new Attr(this, lname, prefix, ns);
10657
10657
  isnew = true;
10658
- this._attrsByLName[key] = attr;
10658
+ this._attrsByLName[key] = attr2;
10659
10659
  if (this._attributes) {
10660
- this._attributes[this._attrKeys.length] = attr;
10660
+ this._attributes[this._attrKeys.length] = attr2;
10661
10661
  }
10662
10662
  this._attrKeys.push(key);
10663
- this._addQName(attr);
10663
+ this._addQName(attr2);
10664
10664
  } else if (false) {
10665
- if (attr.prefix !== prefix) {
10666
- this._removeQName(attr);
10667
- attr.prefix = prefix;
10668
- this._addQName(attr);
10665
+ if (attr2.prefix !== prefix) {
10666
+ this._removeQName(attr2);
10667
+ attr2.prefix = prefix;
10668
+ this._addQName(attr2);
10669
10669
  }
10670
10670
  }
10671
- attr.value = value;
10671
+ attr2.value = value;
10672
10672
  if (isnew && this._newattrhook) this._newattrhook(qname, value);
10673
10673
  } },
10674
10674
  // Do error checking then call _setAttributeNS
@@ -10682,21 +10682,21 @@ var require_Element = __commonJS({
10682
10682
  utils.NamespaceError();
10683
10683
  this._setAttributeNS(ns, qname, String(value));
10684
10684
  } },
10685
- setAttributeNode: { value: function setAttributeNode(attr) {
10686
- if (attr.ownerElement !== null && attr.ownerElement !== this) {
10685
+ setAttributeNode: { value: function setAttributeNode(attr2) {
10686
+ if (attr2.ownerElement !== null && attr2.ownerElement !== this) {
10687
10687
  throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR);
10688
10688
  }
10689
10689
  var result = null;
10690
- var oldAttrs = this._attrsByQName[attr.name];
10690
+ var oldAttrs = this._attrsByQName[attr2.name];
10691
10691
  if (oldAttrs) {
10692
10692
  if (!Array.isArray(oldAttrs)) {
10693
10693
  oldAttrs = [oldAttrs];
10694
10694
  }
10695
10695
  if (oldAttrs.some(function(a) {
10696
- return a === attr;
10696
+ return a === attr2;
10697
10697
  })) {
10698
- return attr;
10699
- } else if (attr.ownerElement !== null) {
10698
+ return attr2;
10699
+ } else if (attr2.ownerElement !== null) {
10700
10700
  throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR);
10701
10701
  }
10702
10702
  oldAttrs.forEach(function(a) {
@@ -10704,47 +10704,47 @@ var require_Element = __commonJS({
10704
10704
  }, this);
10705
10705
  result = oldAttrs[0];
10706
10706
  }
10707
- this.setAttributeNodeNS(attr);
10707
+ this.setAttributeNodeNS(attr2);
10708
10708
  return result;
10709
10709
  } },
10710
- setAttributeNodeNS: { value: function setAttributeNodeNS(attr) {
10711
- if (attr.ownerElement !== null) {
10710
+ setAttributeNodeNS: { value: function setAttributeNodeNS(attr2) {
10711
+ if (attr2.ownerElement !== null) {
10712
10712
  throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR);
10713
10713
  }
10714
- var ns = attr.namespaceURI;
10715
- var key = (ns === null ? "" : ns) + "|" + attr.localName;
10714
+ var ns = attr2.namespaceURI;
10715
+ var key = (ns === null ? "" : ns) + "|" + attr2.localName;
10716
10716
  var oldAttr = this._attrsByLName[key];
10717
10717
  if (oldAttr) {
10718
10718
  this.removeAttributeNode(oldAttr);
10719
10719
  }
10720
- attr._setOwnerElement(this);
10721
- this._attrsByLName[key] = attr;
10720
+ attr2._setOwnerElement(this);
10721
+ this._attrsByLName[key] = attr2;
10722
10722
  if (this._attributes) {
10723
- this._attributes[this._attrKeys.length] = attr;
10723
+ this._attributes[this._attrKeys.length] = attr2;
10724
10724
  }
10725
10725
  this._attrKeys.push(key);
10726
- this._addQName(attr);
10727
- if (this._newattrhook) this._newattrhook(attr.name, attr.value);
10726
+ this._addQName(attr2);
10727
+ if (this._newattrhook) this._newattrhook(attr2.name, attr2.value);
10728
10728
  return oldAttr || null;
10729
10729
  } },
10730
10730
  removeAttribute: { value: function removeAttribute(qname) {
10731
10731
  qname = String(qname);
10732
10732
  if (/[A-Z]/.test(qname) && this.isHTML)
10733
10733
  qname = utils.toASCIILowerCase(qname);
10734
- var attr = this._attrsByQName[qname];
10735
- if (!attr) return;
10736
- if (Array.isArray(attr)) {
10737
- if (attr.length > 2) {
10738
- attr = attr.shift();
10734
+ var attr2 = this._attrsByQName[qname];
10735
+ if (!attr2) return;
10736
+ if (Array.isArray(attr2)) {
10737
+ if (attr2.length > 2) {
10738
+ attr2 = attr2.shift();
10739
10739
  } else {
10740
- this._attrsByQName[qname] = attr[1];
10741
- attr = attr[0];
10740
+ this._attrsByQName[qname] = attr2[1];
10741
+ attr2 = attr2[0];
10742
10742
  }
10743
10743
  } else {
10744
10744
  this._attrsByQName[qname] = void 0;
10745
10745
  }
10746
- var ns = attr.namespaceURI;
10747
- var key = (ns === null ? "" : ns) + "|" + attr.localName;
10746
+ var ns = attr2.namespaceURI;
10747
+ var key = (ns === null ? "" : ns) + "|" + attr2.localName;
10748
10748
  this._attrsByLName[key] = void 0;
10749
10749
  var i = this._attrKeys.indexOf(key);
10750
10750
  if (this._attributes) {
@@ -10752,41 +10752,41 @@ var require_Element = __commonJS({
10752
10752
  this._attributes[qname] = void 0;
10753
10753
  }
10754
10754
  this._attrKeys.splice(i, 1);
10755
- var onchange = attr.onchange;
10756
- attr._setOwnerElement(null);
10755
+ var onchange = attr2.onchange;
10756
+ attr2._setOwnerElement(null);
10757
10757
  if (onchange) {
10758
- onchange.call(attr, this, attr.localName, attr.value, null);
10758
+ onchange.call(attr2, this, attr2.localName, attr2.value, null);
10759
10759
  }
10760
- if (this.rooted) this.ownerDocument.mutateRemoveAttr(attr);
10760
+ if (this.rooted) this.ownerDocument.mutateRemoveAttr(attr2);
10761
10761
  } },
10762
10762
  removeAttributeNS: { value: function removeAttributeNS(ns, lname) {
10763
10763
  ns = ns === void 0 || ns === null ? "" : String(ns);
10764
10764
  lname = String(lname);
10765
10765
  var key = ns + "|" + lname;
10766
- var attr = this._attrsByLName[key];
10767
- if (!attr) return;
10766
+ var attr2 = this._attrsByLName[key];
10767
+ if (!attr2) return;
10768
10768
  this._attrsByLName[key] = void 0;
10769
10769
  var i = this._attrKeys.indexOf(key);
10770
10770
  if (this._attributes) {
10771
10771
  Array.prototype.splice.call(this._attributes, i, 1);
10772
10772
  }
10773
10773
  this._attrKeys.splice(i, 1);
10774
- this._removeQName(attr);
10775
- var onchange = attr.onchange;
10776
- attr._setOwnerElement(null);
10774
+ this._removeQName(attr2);
10775
+ var onchange = attr2.onchange;
10776
+ attr2._setOwnerElement(null);
10777
10777
  if (onchange) {
10778
- onchange.call(attr, this, attr.localName, attr.value, null);
10778
+ onchange.call(attr2, this, attr2.localName, attr2.value, null);
10779
10779
  }
10780
- if (this.rooted) this.ownerDocument.mutateRemoveAttr(attr);
10780
+ if (this.rooted) this.ownerDocument.mutateRemoveAttr(attr2);
10781
10781
  } },
10782
- removeAttributeNode: { value: function removeAttributeNode(attr) {
10783
- var ns = attr.namespaceURI;
10784
- var key = (ns === null ? "" : ns) + "|" + attr.localName;
10785
- if (this._attrsByLName[key] !== attr) {
10782
+ removeAttributeNode: { value: function removeAttributeNode(attr2) {
10783
+ var ns = attr2.namespaceURI;
10784
+ var key = (ns === null ? "" : ns) + "|" + attr2.localName;
10785
+ if (this._attrsByLName[key] !== attr2) {
10786
10786
  utils.NotFoundError();
10787
10787
  }
10788
- this.removeAttributeNS(ns, attr.localName);
10789
- return attr;
10788
+ this.removeAttributeNS(ns, attr2.localName);
10789
+ return attr2;
10790
10790
  } },
10791
10791
  getAttributeNames: { value: function getAttributeNames() {
10792
10792
  var elt = this;
@@ -10798,57 +10798,57 @@ var require_Element = __commonJS({
10798
10798
  // of reflected attributes. It skips some error checking and
10799
10799
  // namespace steps
10800
10800
  _getattr: { value: function _getattr(qname) {
10801
- var attr = this._attrsByQName[qname];
10802
- return attr ? attr.value : null;
10801
+ var attr2 = this._attrsByQName[qname];
10802
+ return attr2 ? attr2.value : null;
10803
10803
  } },
10804
10804
  // The raw version of setAttribute for reflected idl attributes.
10805
10805
  _setattr: { value: function _setattr(qname, value) {
10806
- var attr = this._attrsByQName[qname];
10806
+ var attr2 = this._attrsByQName[qname];
10807
10807
  var isnew;
10808
- if (!attr) {
10809
- attr = this._newattr(qname);
10808
+ if (!attr2) {
10809
+ attr2 = this._newattr(qname);
10810
10810
  isnew = true;
10811
10811
  }
10812
- attr.value = String(value);
10813
- if (this._attributes) this._attributes[qname] = attr;
10812
+ attr2.value = String(value);
10813
+ if (this._attributes) this._attributes[qname] = attr2;
10814
10814
  if (isnew && this._newattrhook) this._newattrhook(qname, value);
10815
10815
  } },
10816
10816
  // Create a new Attr object, insert it, and return it.
10817
10817
  // Used by setAttribute() and by set()
10818
10818
  _newattr: { value: function _newattr(qname) {
10819
- var attr = new Attr(this, qname, null, null);
10819
+ var attr2 = new Attr(this, qname, null, null);
10820
10820
  var key = "|" + qname;
10821
- this._attrsByQName[qname] = attr;
10822
- this._attrsByLName[key] = attr;
10821
+ this._attrsByQName[qname] = attr2;
10822
+ this._attrsByLName[key] = attr2;
10823
10823
  if (this._attributes) {
10824
- this._attributes[this._attrKeys.length] = attr;
10824
+ this._attributes[this._attrKeys.length] = attr2;
10825
10825
  }
10826
10826
  this._attrKeys.push(key);
10827
- return attr;
10827
+ return attr2;
10828
10828
  } },
10829
10829
  // Add a qname->Attr mapping to the _attrsByQName object, taking into
10830
10830
  // account that there may be more than one attr object with the
10831
10831
  // same qname
10832
- _addQName: { value: function(attr) {
10833
- var qname = attr.name;
10832
+ _addQName: { value: function(attr2) {
10833
+ var qname = attr2.name;
10834
10834
  var existing = this._attrsByQName[qname];
10835
10835
  if (!existing) {
10836
- this._attrsByQName[qname] = attr;
10836
+ this._attrsByQName[qname] = attr2;
10837
10837
  } else if (Array.isArray(existing)) {
10838
- existing.push(attr);
10838
+ existing.push(attr2);
10839
10839
  } else {
10840
- this._attrsByQName[qname] = [existing, attr];
10840
+ this._attrsByQName[qname] = [existing, attr2];
10841
10841
  }
10842
- if (this._attributes) this._attributes[qname] = attr;
10842
+ if (this._attributes) this._attributes[qname] = attr2;
10843
10843
  } },
10844
10844
  // Remove a qname->Attr mapping to the _attrsByQName object, taking into
10845
10845
  // account that there may be more than one attr object with the
10846
10846
  // same qname
10847
- _removeQName: { value: function(attr) {
10848
- var qname = attr.name;
10847
+ _removeQName: { value: function(attr2) {
10848
+ var qname = attr2.name;
10849
10849
  var target = this._attrsByQName[qname];
10850
10850
  if (Array.isArray(target)) {
10851
- var idx = target.indexOf(attr);
10851
+ var idx = target.indexOf(attr2);
10852
10852
  utils.assert(idx !== -1);
10853
10853
  if (target.length === 2) {
10854
10854
  this._attrsByQName[qname] = target[1 - idx];
@@ -10857,12 +10857,12 @@ var require_Element = __commonJS({
10857
10857
  }
10858
10858
  } else {
10859
10859
  target.splice(idx, 1);
10860
- if (this._attributes && this._attributes[qname] === attr) {
10860
+ if (this._attributes && this._attributes[qname] === attr2) {
10861
10861
  this._attributes[qname] = target[0];
10862
10862
  }
10863
10863
  }
10864
10864
  } else {
10865
- utils.assert(target === attr);
10865
+ utils.assert(target === attr2);
10866
10866
  this._attrsByQName[qname] = void 0;
10867
10867
  if (this._attributes) {
10868
10868
  this._attributes[qname] = void 0;
@@ -12814,10 +12814,10 @@ var require_defineElement = __commonJS({
12814
12814
  var props = spec.props || {};
12815
12815
  if (spec.attributes) {
12816
12816
  for (var n in spec.attributes) {
12817
- var attr = spec.attributes[n];
12818
- if (typeof attr !== "object" || Array.isArray(attr)) attr = { type: attr };
12819
- if (!attr.name) attr.name = n.toLowerCase();
12820
- props[n] = attributes.property(attr);
12817
+ var attr2 = spec.attributes[n];
12818
+ if (typeof attr2 !== "object" || Array.isArray(attr2)) attr2 = { type: attr2 };
12819
+ if (!attr2.name) attr2.name = n.toLowerCase();
12820
+ props[n] = attributes.property(attr2);
12821
12821
  }
12822
12822
  }
12823
12823
  props.constructor = { value: c, writable: isApiWritable };
@@ -12885,10 +12885,10 @@ var require_htmlelts = __commonJS({
12885
12885
  function define(spec) {
12886
12886
  return defineElement(spec, HTMLElement, htmlElements, htmlNameToImpl);
12887
12887
  }
12888
- function URL2(attr) {
12888
+ function URL2(attr2) {
12889
12889
  return {
12890
12890
  get: function() {
12891
- var v = this._getattr(attr);
12891
+ var v = this._getattr(attr2);
12892
12892
  if (v === null) {
12893
12893
  return "";
12894
12894
  }
@@ -12896,14 +12896,14 @@ var require_htmlelts = __commonJS({
12896
12896
  return url === null ? v : url;
12897
12897
  },
12898
12898
  set: function(value) {
12899
- this._setattr(attr, value);
12899
+ this._setattr(attr2, value);
12900
12900
  }
12901
12901
  };
12902
12902
  }
12903
- function CORS(attr) {
12903
+ function CORS(attr2) {
12904
12904
  return {
12905
12905
  get: function() {
12906
- var v = this._getattr(attr);
12906
+ var v = this._getattr(attr2);
12907
12907
  if (v === null) {
12908
12908
  return null;
12909
12909
  }
@@ -12914,9 +12914,9 @@ var require_htmlelts = __commonJS({
12914
12914
  },
12915
12915
  set: function(value) {
12916
12916
  if (value === null || value === void 0) {
12917
- this.removeAttribute(attr);
12917
+ this.removeAttribute(attr2);
12918
12918
  } else {
12919
- this._setattr(attr, value);
12919
+ this._setattr(attr2, value);
12920
12920
  }
12921
12921
  }
12922
12922
  };
@@ -15050,22 +15050,22 @@ var require_Document = __commonJS({
15050
15050
  // Invoked when an attribute's value changes. Attr holds the new
15051
15051
  // value. oldval is the old value. Attribute mutations can also
15052
15052
  // involve changes to the prefix (and therefore the qualified name)
15053
- mutateAttr: { value: function(attr, oldval) {
15053
+ mutateAttr: { value: function(attr2, oldval) {
15054
15054
  if (this.mutationHandler) {
15055
15055
  this.mutationHandler({
15056
15056
  type: MUTATE.ATTR,
15057
- target: attr.ownerElement,
15058
- attr
15057
+ target: attr2.ownerElement,
15058
+ attr: attr2
15059
15059
  });
15060
15060
  }
15061
15061
  } },
15062
15062
  // Used by removeAttribute and removeAttributeNS for attributes.
15063
- mutateRemoveAttr: { value: function(attr) {
15063
+ mutateRemoveAttr: { value: function(attr2) {
15064
15064
  if (this.mutationHandler) {
15065
15065
  this.mutationHandler({
15066
15066
  type: MUTATE.REMOVE_ATTR,
15067
- target: attr.ownerElement,
15068
- attr
15067
+ target: attr2.ownerElement,
15068
+ attr: attr2
15069
15069
  });
15070
15070
  }
15071
15071
  } },
@@ -15131,8 +15131,8 @@ var require_Document = __commonJS({
15131
15131
  this.byId[id2] = void 0;
15132
15132
  }
15133
15133
  } },
15134
- _resolve: { value: function(href) {
15135
- return new URL2(this._documentBaseURL).resolve(href);
15134
+ _resolve: { value: function(href2) {
15135
+ return new URL2(this._documentBaseURL).resolve(href2);
15136
15136
  } },
15137
15137
  _documentBaseURL: { get: function() {
15138
15138
  var url = this._address;
@@ -15367,7 +15367,7 @@ var require_HTMLParser = __commonJS({
15367
15367
  var impl = html.elements;
15368
15368
  var pushAll = Function.prototype.apply.bind(Array.prototype.push);
15369
15369
  var EOF = -1;
15370
- var TEXT = 1;
15370
+ var TEXT2 = 1;
15371
15371
  var TAG = 2;
15372
15372
  var ENDTAG = 3;
15373
15373
  var COMMENT = 4;
@@ -18636,7 +18636,7 @@ var require_HTMLParser = __commonJS({
18636
18636
  if (s[0] === "\n") s = s.substring(1);
18637
18637
  if (s.length === 0) return;
18638
18638
  }
18639
- insertToken(TEXT, s);
18639
+ insertToken(TEXT2, s);
18640
18640
  textIncludesNUL = false;
18641
18641
  }
18642
18642
  ignore_linefeed = false;
@@ -18671,7 +18671,7 @@ var require_HTMLParser = __commonJS({
18671
18671
  if (s[0] === "\n") s = s.substring(1);
18672
18672
  if (s.length === 0) return;
18673
18673
  }
18674
- insertToken(TEXT, s);
18674
+ insertToken(TEXT2, s);
18675
18675
  }
18676
18676
  function emitTag() {
18677
18677
  if (is_end_tag) insertToken(ENDTAG, tagnamebuf);
@@ -18727,10 +18727,10 @@ var require_HTMLParser = __commonJS({
18727
18727
  if (!current || current.namespaceURI === NAMESPACE.HTML) {
18728
18728
  parser(t, value, arg3, arg4);
18729
18729
  } else {
18730
- if (t !== TAG && t !== TEXT) {
18730
+ if (t !== TAG && t !== TEXT2) {
18731
18731
  insertForeignToken(t, value, arg3, arg4);
18732
18732
  } else {
18733
- if (isMathmlTextIntegrationPoint(current) && (t === TEXT || t === TAG && value !== "mglyph" && value !== "malignmark") || t === TAG && value === "svg" && current.namespaceURI === NAMESPACE.MATHML && current.localName === "annotation-xml" || isHTMLIntegrationPoint(current)) {
18733
+ if (isMathmlTextIntegrationPoint(current) && (t === TEXT2 || t === TAG && value !== "mglyph" && value !== "malignmark") || t === TAG && value === "svg" && current.namespaceURI === NAMESPACE.MATHML && current.localName === "annotation-xml" || isHTMLIntegrationPoint(current)) {
18734
18734
  text_integration_mode = true;
18735
18735
  parser(t, value, arg3, arg4);
18736
18736
  text_integration_mode = false;
@@ -18809,11 +18809,11 @@ var require_HTMLParser = __commonJS({
18809
18809
  var elt = doc2._createElementNS(name, ns, null);
18810
18810
  if (attrs) {
18811
18811
  for (var i = 0, n = attrs.length; i < n; i++) {
18812
- var attr = attrs[i];
18813
- if (attr.length === 2)
18814
- elt._setAttribute(attr[0], attr[1]);
18812
+ var attr2 = attrs[i];
18813
+ if (attr2.length === 2)
18814
+ elt._setAttribute(attr2[0], attr2[1]);
18815
18815
  else {
18816
- elt._setAttributeNS(attr[2], attr[0], attr[1]);
18816
+ elt._setAttributeNS(attr2[2], attr2[0], attr2[1]);
18817
18817
  }
18818
18818
  }
18819
18819
  }
@@ -22695,7 +22695,7 @@ var require_HTMLParser = __commonJS({
22695
22695
  foster_parent_mode = false;
22696
22696
  }
22697
22697
  function in_table_text_mode(t, value, arg3, arg4) {
22698
- if (t === TEXT) {
22698
+ if (t === TEXT2) {
22699
22699
  if (textIncludesNUL) {
22700
22700
  value = value.replace(NULCHARS, "");
22701
22701
  if (value.length === 0) return;
@@ -22706,7 +22706,7 @@ var require_HTMLParser = __commonJS({
22706
22706
  pending_table_text.length = 0;
22707
22707
  if (NONWS.test(s)) {
22708
22708
  foster_parent_mode = true;
22709
- in_body_mode(TEXT, s);
22709
+ in_body_mode(TEXT2, s);
22710
22710
  foster_parent_mode = false;
22711
22711
  } else {
22712
22712
  insertText(s);
@@ -23602,9 +23602,9 @@ var require_Location = __commonJS({
23602
23602
  var URL2 = require_URL();
23603
23603
  var URLUtils = require_URLUtils();
23604
23604
  module.exports = Location;
23605
- function Location(window2, href) {
23605
+ function Location(window2, href2) {
23606
23606
  this._window = window2;
23607
- this._href = href;
23607
+ this._href = href2;
23608
23608
  }
23609
23609
  Location.prototype = Object.create(URLUtils.prototype, {
23610
23610
  constructor: { value: Location },
@@ -24011,10 +24011,10 @@ var require_turndown_cjs = __commonJS({
24011
24011
  return options.linkStyle === "inlined" && node.nodeName === "A" && node.getAttribute("href");
24012
24012
  },
24013
24013
  replacement: function(content, node) {
24014
- var href = escapeLinkDestination(node.getAttribute("href"));
24014
+ var href2 = escapeLinkDestination(node.getAttribute("href"));
24015
24015
  var title = escapeLinkTitle(cleanAttribute(node.getAttribute("title")));
24016
24016
  var titlePart = title ? ' "' + title + '"' : "";
24017
- return "[" + content + "](" + href + titlePart + ")";
24017
+ return "[" + content + "](" + href2 + titlePart + ")";
24018
24018
  }
24019
24019
  };
24020
24020
  rules.referenceLink = {
@@ -24022,7 +24022,7 @@ var require_turndown_cjs = __commonJS({
24022
24022
  return options.linkStyle === "referenced" && node.nodeName === "A" && node.getAttribute("href");
24023
24023
  },
24024
24024
  replacement: function(content, node, options) {
24025
- var href = escapeLinkDestination(node.getAttribute("href"));
24025
+ var href2 = escapeLinkDestination(node.getAttribute("href"));
24026
24026
  var title = cleanAttribute(node.getAttribute("title"));
24027
24027
  if (title) title = ' "' + escapeLinkTitle(title) + '"';
24028
24028
  var replacement;
@@ -24030,16 +24030,16 @@ var require_turndown_cjs = __commonJS({
24030
24030
  switch (options.linkReferenceStyle) {
24031
24031
  case "collapsed":
24032
24032
  replacement = "[" + content + "][]";
24033
- reference = "[" + content + "]: " + href + title;
24033
+ reference = "[" + content + "]: " + href2 + title;
24034
24034
  break;
24035
24035
  case "shortcut":
24036
24036
  replacement = "[" + content + "]";
24037
- reference = "[" + content + "]: " + href + title;
24037
+ reference = "[" + content + "]: " + href2 + title;
24038
24038
  break;
24039
24039
  default:
24040
24040
  var id2 = this.references.length + 1;
24041
24041
  replacement = "[" + content + "][" + id2 + "]";
24042
- reference = "[" + id2 + "]: " + href + title;
24042
+ reference = "[" + id2 + "]: " + href2 + title;
24043
24043
  }
24044
24044
  this.references.push(reference);
24045
24045
  return replacement;
@@ -29878,7 +29878,7 @@ var $ZodURL = /* @__PURE__ */ $constructor("$ZodURL", (inst, def) => {
29878
29878
  try {
29879
29879
  const orig = payload.value;
29880
29880
  const url = new URL(orig);
29881
- const href = url.href;
29881
+ const href2 = url.href;
29882
29882
  if (def.hostname) {
29883
29883
  def.hostname.lastIndex = 0;
29884
29884
  if (!def.hostname.test(url.hostname)) {
@@ -29907,10 +29907,10 @@ var $ZodURL = /* @__PURE__ */ $constructor("$ZodURL", (inst, def) => {
29907
29907
  });
29908
29908
  }
29909
29909
  }
29910
- if (!orig.endsWith("/") && href.endsWith("/")) {
29911
- payload.value = href.slice(0, -1);
29910
+ if (!orig.endsWith("/") && href2.endsWith("/")) {
29911
+ payload.value = href2.slice(0, -1);
29912
29912
  } else {
29913
- payload.value = href;
29913
+ payload.value = href2;
29914
29914
  }
29915
29915
  return;
29916
29916
  } catch (_) {
@@ -41076,9 +41076,9 @@ function fileSize(p) {
41076
41076
  function makeTempDir() {
41077
41077
  return mkdtempSync(resolve(tmpdir(), "apple-notes-att-"));
41078
41078
  }
41079
- function readAllowedTextFile(p, maxBytes, roots = allowedSaveRoots()) {
41080
- if (!p || !p.trim()) throw new Error("A content file path is required.");
41081
- if (!isAbsolute(p)) throw new Error(`Content file path must be absolute: "${p}"`);
41079
+ function assertReadableInRoots(p, roots = allowedSaveRoots(), label = "Content file") {
41080
+ if (!p || !p.trim()) throw new Error(`A ${label.toLowerCase()} path is required.`);
41081
+ if (!isAbsolute(p)) throw new Error(`${label} path must be absolute: "${p}"`);
41082
41082
  const abs = resolve(p);
41083
41083
  if (!isWithinRoots(abs, roots))
41084
41084
  throw new Error(`Refusing to read outside allowed locations (home, temp, /Volumes): "${abs}"`);
@@ -41086,12 +41086,16 @@ function readAllowedTextFile(p, maxBytes, roots = allowedSaveRoots()) {
41086
41086
  try {
41087
41087
  canonical = canonicalize(abs);
41088
41088
  } catch {
41089
- throw new Error(`Content file does not exist or cannot be resolved: "${abs}"`);
41089
+ throw new Error(`${label} does not exist or cannot be resolved: "${abs}"`);
41090
41090
  }
41091
41091
  if (!isWithinRoots(canonical, canonicalRoots(roots)))
41092
41092
  throw new Error(
41093
41093
  `Refusing to read outside allowed locations (home, temp, /Volumes): "${abs}" resolves to "${canonical}".`
41094
41094
  );
41095
+ return abs;
41096
+ }
41097
+ function readAllowedTextFile(p, maxBytes, roots = allowedSaveRoots()) {
41098
+ const abs = assertReadableInRoots(p, roots);
41095
41099
  let descriptor;
41096
41100
  try {
41097
41101
  descriptor = openSync(abs, constants.O_RDONLY | constants.O_NOFOLLOW);
@@ -48488,6 +48492,13 @@ var FEATURES = [
48488
48492
  minimumMacOSVersion: null,
48489
48493
  requirements: [{ kind: "native_write_helper" }]
48490
48494
  },
48495
+ {
48496
+ name: "svgAnalysis",
48497
+ description: "Analyze a local SVG file for conversion into editable strokes: classification, required losses, and a digest",
48498
+ tools: ["analyze-svg"],
48499
+ minimumMacOSVersion: null,
48500
+ requirements: []
48501
+ },
48491
48502
  {
48492
48503
  name: "paragraphLinks",
48493
48504
  description: "Link to a specific paragraph or heading inside a note",
@@ -50782,11 +50793,13 @@ function escapeMarkdown(text2) {
50782
50793
  return text2.replace(/[\\`*_[\]<>~|]/g, (char) => `\\${char}`).replace(/&(?=#?[A-Za-z0-9]+;)/g, "&amp;").replace(/==/g, "\\=\\=");
50783
50794
  }
50784
50795
  function escapeLineStart(line) {
50796
+ if (/^\s*(?:-[ \t]*){3,}$/.test(line)) return line.replace("-", "\\-");
50785
50797
  return line.replace(
50786
- /^(\s*)([#>+-]|\d+[.)])(?=\s|$)/,
50798
+ /^(\s*)(#{1,6}|[>+-]|\d{1,9}[.)])(?=\s|$)/,
50787
50799
  (_, space, marker) => /^\d/.test(marker) ? `${space}${marker.slice(0, -1)}\\${marker.slice(-1)}` : `${space}\\${marker}`
50788
50800
  );
50789
50801
  }
50802
+ var BLOCK_START_WORD = /^(?:#{1,6}|[-+*]|-+|=+|\d{1,9}[.)])$/;
50790
50803
  function linkDestination(url) {
50791
50804
  return url.replace(
50792
50805
  /[\s()<>]/g,
@@ -50958,7 +50971,7 @@ function renderLine(block, body, first2, isTitle, counters) {
50958
50971
  counters[level] = 0;
50959
50972
  if (block.style === "checklist") marker = block.checklist?.done ? "- [x]" : "- [ ]";
50960
50973
  }
50961
- return { text: `${indent}${marker} ${body}`, group: "list", quote };
50974
+ return { text: `${indent}${marker} ${escapeLineStart(body)}`, group: "list", quote };
50962
50975
  }
50963
50976
  function joinLines(lines) {
50964
50977
  let out = "";
@@ -50991,7 +51004,7 @@ function wrapMarkdown(markdown, width) {
50991
51004
  let current = prefix;
50992
51005
  let empty = true;
50993
51006
  for (const word of words) {
50994
- if (!empty && current.length + 1 + word.length > width) {
51007
+ if (!empty && current.length + 1 + word.length > width && !BLOCK_START_WORD.test(word)) {
50995
51008
  out.push(current);
50996
51009
  current = hang + word;
50997
51010
  } else current += (empty ? "" : " ") + word;
@@ -51904,6 +51917,2071 @@ function registerFolderDelete(server2, manager, deps = defaultDeps) {
51904
51917
  );
51905
51918
  }
51906
51919
 
51920
+ // src/utils/svgAnalyzer.ts
51921
+ import { createHash as createHash4 } from "node:crypto";
51922
+ import { closeSync as closeSync6, constants as constants6, fstatSync as fstatSync6, openSync as openSync6, readSync as readSync4 } from "node:fs";
51923
+
51924
+ // src/utils/svgColor.ts
51925
+ var NAMED = {
51926
+ aliceblue: "f0f8ff",
51927
+ antiquewhite: "faebd7",
51928
+ aqua: "00ffff",
51929
+ aquamarine: "7fffd4",
51930
+ azure: "f0ffff",
51931
+ beige: "f5f5dc",
51932
+ bisque: "ffe4c4",
51933
+ black: "000000",
51934
+ blanchedalmond: "ffebcd",
51935
+ blue: "0000ff",
51936
+ blueviolet: "8a2be2",
51937
+ brown: "a52a2a",
51938
+ burlywood: "deb887",
51939
+ cadetblue: "5f9ea0",
51940
+ chartreuse: "7fff00",
51941
+ chocolate: "d2691e",
51942
+ coral: "ff7f50",
51943
+ cornflowerblue: "6495ed",
51944
+ cornsilk: "fff8dc",
51945
+ crimson: "dc143c",
51946
+ cyan: "00ffff",
51947
+ darkblue: "00008b",
51948
+ darkcyan: "008b8b",
51949
+ darkgoldenrod: "b8860b",
51950
+ darkgray: "a9a9a9",
51951
+ darkgreen: "006400",
51952
+ darkgrey: "a9a9a9",
51953
+ darkkhaki: "bdb76b",
51954
+ darkmagenta: "8b008b",
51955
+ darkolivegreen: "556b2f",
51956
+ darkorange: "ff8c00",
51957
+ darkorchid: "9932cc",
51958
+ darkred: "8b0000",
51959
+ darksalmon: "e9967a",
51960
+ darkseagreen: "8fbc8f",
51961
+ darkslateblue: "483d8b",
51962
+ darkslategray: "2f4f4f",
51963
+ darkslategrey: "2f4f4f",
51964
+ darkturquoise: "00ced1",
51965
+ darkviolet: "9400d3",
51966
+ deeppink: "ff1493",
51967
+ deepskyblue: "00bfff",
51968
+ dimgray: "696969",
51969
+ dimgrey: "696969",
51970
+ dodgerblue: "1e90ff",
51971
+ firebrick: "b22222",
51972
+ floralwhite: "fffaf0",
51973
+ forestgreen: "228b22",
51974
+ fuchsia: "ff00ff",
51975
+ gainsboro: "dcdcdc",
51976
+ ghostwhite: "f8f8ff",
51977
+ gold: "ffd700",
51978
+ goldenrod: "daa520",
51979
+ gray: "808080",
51980
+ green: "008000",
51981
+ greenyellow: "adff2f",
51982
+ grey: "808080",
51983
+ honeydew: "f0fff0",
51984
+ hotpink: "ff69b4",
51985
+ indianred: "cd5c5c",
51986
+ indigo: "4b0082",
51987
+ ivory: "fffff0",
51988
+ khaki: "f0e68c",
51989
+ lavender: "e6e6fa",
51990
+ lavenderblush: "fff0f5",
51991
+ lawngreen: "7cfc00",
51992
+ lemonchiffon: "fffacd",
51993
+ lightblue: "add8e6",
51994
+ lightcoral: "f08080",
51995
+ lightcyan: "e0ffff",
51996
+ lightgoldenrodyellow: "fafad2",
51997
+ lightgray: "d3d3d3",
51998
+ lightgreen: "90ee90",
51999
+ lightgrey: "d3d3d3",
52000
+ lightpink: "ffb6c1",
52001
+ lightsalmon: "ffa07a",
52002
+ lightseagreen: "20b2aa",
52003
+ lightskyblue: "87cefa",
52004
+ lightslategray: "778899",
52005
+ lightslategrey: "778899",
52006
+ lightsteelblue: "b0c4de",
52007
+ lightyellow: "ffffe0",
52008
+ lime: "00ff00",
52009
+ limegreen: "32cd32",
52010
+ linen: "faf0e6",
52011
+ magenta: "ff00ff",
52012
+ maroon: "800000",
52013
+ mediumaquamarine: "66cdaa",
52014
+ mediumblue: "0000cd",
52015
+ mediumorchid: "ba55d3",
52016
+ mediumpurple: "9370db",
52017
+ mediumseagreen: "3cb371",
52018
+ mediumslateblue: "7b68ee",
52019
+ mediumspringgreen: "00fa9a",
52020
+ mediumturquoise: "48d1cc",
52021
+ mediumvioletred: "c71585",
52022
+ midnightblue: "191970",
52023
+ mintcream: "f5fffa",
52024
+ mistyrose: "ffe4e1",
52025
+ moccasin: "ffe4b5",
52026
+ navajowhite: "ffdead",
52027
+ navy: "000080",
52028
+ oldlace: "fdf5e6",
52029
+ olive: "808000",
52030
+ olivedrab: "6b8e23",
52031
+ orange: "ffa500",
52032
+ orangered: "ff4500",
52033
+ orchid: "da70d6",
52034
+ palegoldenrod: "eee8aa",
52035
+ palegreen: "98fb98",
52036
+ paleturquoise: "afeeee",
52037
+ palevioletred: "db7093",
52038
+ papayawhip: "ffefd5",
52039
+ peachpuff: "ffdab9",
52040
+ peru: "cd853f",
52041
+ pink: "ffc0cb",
52042
+ plum: "dda0dd",
52043
+ powderblue: "b0e0e6",
52044
+ purple: "800080",
52045
+ rebeccapurple: "663399",
52046
+ red: "ff0000",
52047
+ rosybrown: "bc8f8f",
52048
+ royalblue: "4169e1",
52049
+ saddlebrown: "8b4513",
52050
+ salmon: "fa8072",
52051
+ sandybrown: "f4a460",
52052
+ seagreen: "2e8b57",
52053
+ seashell: "fff5ee",
52054
+ sienna: "a0522d",
52055
+ silver: "c0c0c0",
52056
+ skyblue: "87ceeb",
52057
+ slateblue: "6a5acd",
52058
+ slategray: "708090",
52059
+ slategrey: "708090",
52060
+ snow: "fffafa",
52061
+ springgreen: "00ff7f",
52062
+ steelblue: "4682b4",
52063
+ tan: "d2b48c",
52064
+ teal: "008080",
52065
+ thistle: "d8bfd8",
52066
+ tomato: "ff6347",
52067
+ turquoise: "40e0d0",
52068
+ violet: "ee82ee",
52069
+ wheat: "f5deb3",
52070
+ white: "ffffff",
52071
+ whitesmoke: "f5f5f5",
52072
+ yellow: "ffff00",
52073
+ yellowgreen: "9acd32"
52074
+ };
52075
+ var clamp01 = (v) => Math.min(1, Math.max(0, v));
52076
+ function hexToRgba(hex3) {
52077
+ if (!/^[0-9a-f]+$/i.test(hex3)) return null;
52078
+ const expand = hex3.length <= 4 ? [...hex3].map((c) => c + c).join("") : hex3;
52079
+ if (expand.length !== 6 && expand.length !== 8) return null;
52080
+ const byte = (i) => Number.parseInt(expand.slice(i, i + 2), 16) / 255;
52081
+ return [byte(0), byte(2), byte(4), expand.length === 8 ? byte(6) : 1];
52082
+ }
52083
+ function component(text2, scale) {
52084
+ const m = /^([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(%?)$/i.exec(text2.trim());
52085
+ if (!m) return null;
52086
+ const n = Number(m[1]);
52087
+ return m[2] ? n / 100 * scale : n;
52088
+ }
52089
+ function hslToRgb(h, s, l) {
52090
+ const hue = (h % 360 + 360) % 360 / 360;
52091
+ const f = (n) => {
52092
+ const k = (n + hue * 12) % 12;
52093
+ return l - s * Math.min(l, 1 - l) * Math.max(-1, Math.min(k - 3, 9 - k, 1));
52094
+ };
52095
+ return [f(0), f(8), f(4)];
52096
+ }
52097
+ function functional(name, args) {
52098
+ if (args.length !== 3 && args.length !== 4) return null;
52099
+ const alpha = args.length === 4 ? component(args[3], 1) : 1;
52100
+ if (alpha === null) return null;
52101
+ if (name === "rgb" || name === "rgba") {
52102
+ const channels = args.slice(0, 3).map((a) => component(a, 255));
52103
+ if (channels.some((c) => c === null)) return null;
52104
+ const [r2, g2, b2] = channels.map((c) => clamp01(c / 255));
52105
+ return [r2, g2, b2, clamp01(alpha)];
52106
+ }
52107
+ const h = component(args[0].replace(/deg$/i, ""), 360);
52108
+ const s = component(args[1], 1);
52109
+ const l = component(args[2], 1);
52110
+ if (h === null || s === null || l === null || !args[1].includes("%") || !args[2].includes("%"))
52111
+ return null;
52112
+ const [r, g, b] = hslToRgb(h, clamp01(s), clamp01(l));
52113
+ return [r, g, b, clamp01(alpha)];
52114
+ }
52115
+ function parseColor(value) {
52116
+ const v = value.trim().toLowerCase();
52117
+ if (v === "transparent") return [0, 0, 0, 0];
52118
+ if (v.startsWith("#")) return hexToRgba(v.slice(1));
52119
+ if (v in NAMED) return hexToRgba(NAMED[v]);
52120
+ const fn = /^(rgba?|hsla?)\(\s*(.*?)\s*\)$/.exec(v);
52121
+ if (!fn) return null;
52122
+ const body = fn[2];
52123
+ const args = body.includes(",") ? body.split(",").map((a) => a.trim()) : body.replace(/\s*\/\s*/, " ").split(/\s+/).filter(Boolean);
52124
+ if (args.some((a) => !a)) return null;
52125
+ return functional(fn[1], args);
52126
+ }
52127
+ function parsePaint(value) {
52128
+ const v = value.trim();
52129
+ if (v === "none") return { kind: "none" };
52130
+ if (/^currentcolor$/i.test(v)) return { kind: "current" };
52131
+ const url = /^url\(\s*['"]?([^'")]*)['"]?\s*\)/i.exec(v);
52132
+ if (url) return { kind: "url", target: url[1].trim() };
52133
+ const rgba = parseColor(v);
52134
+ return rgba ? { kind: "color", rgba } : { kind: "invalid" };
52135
+ }
52136
+
52137
+ // src/utils/svgGeometry.ts
52138
+ var IDENTITY = [1, 0, 0, 1, 0, 0];
52139
+ function multiply(left, right) {
52140
+ const [a, b, c, d, e, f] = left;
52141
+ const [A, B, C, D, E, F] = right;
52142
+ return [
52143
+ a * A + c * B,
52144
+ b * A + d * B,
52145
+ a * C + c * D,
52146
+ b * C + d * D,
52147
+ a * E + c * F + e,
52148
+ b * E + d * F + f
52149
+ ];
52150
+ }
52151
+ function apply(m, p) {
52152
+ return [m[0] * p[0] + m[2] * p[1] + m[4], m[1] * p[0] + m[3] * p[1] + m[5]];
52153
+ }
52154
+ function scales(m) {
52155
+ const [a, b, c, d] = m;
52156
+ const s1 = a * a + b * b + c * c + d * d;
52157
+ const det = a * d - b * c;
52158
+ const root = Math.sqrt(Math.max(0, s1 * s1 - 4 * det * det));
52159
+ return [Math.sqrt((s1 + root) / 2), Math.sqrt(Math.max(0, (s1 - root) / 2))];
52160
+ }
52161
+ var NUMBER = /[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/y;
52162
+ var NumberScanner = class {
52163
+ constructor(text2) {
52164
+ this.text = text2;
52165
+ }
52166
+ text;
52167
+ pos = 0;
52168
+ /** A comma was consumed since the last token (one comma separates two tokens). */
52169
+ comma = true;
52170
+ skip() {
52171
+ while (this.pos < this.text.length) {
52172
+ const ch = this.text[this.pos];
52173
+ if (ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f") this.pos++;
52174
+ else if (ch === "," && !this.comma) {
52175
+ this.pos++;
52176
+ this.comma = true;
52177
+ } else break;
52178
+ }
52179
+ }
52180
+ done() {
52181
+ this.skip();
52182
+ return this.pos >= this.text.length;
52183
+ }
52184
+ /** The next character, after separators, without consuming it. */
52185
+ peek() {
52186
+ this.skip();
52187
+ return this.text[this.pos] ?? "";
52188
+ }
52189
+ take() {
52190
+ this.skip();
52191
+ this.comma = false;
52192
+ return this.text[this.pos++] ?? "";
52193
+ }
52194
+ number() {
52195
+ this.skip();
52196
+ NUMBER.lastIndex = this.pos;
52197
+ const m = NUMBER.exec(this.text);
52198
+ if (!m) return null;
52199
+ this.pos += m[0].length;
52200
+ this.comma = false;
52201
+ const n = Number(m[0]);
52202
+ return Number.isFinite(n) ? n : null;
52203
+ }
52204
+ flag() {
52205
+ this.skip();
52206
+ const ch = this.text[this.pos];
52207
+ if (ch !== "0" && ch !== "1") return null;
52208
+ this.pos++;
52209
+ this.comma = false;
52210
+ return ch === "1" ? 1 : 0;
52211
+ }
52212
+ };
52213
+ function parseNumberList(text2) {
52214
+ const scanner = new NumberScanner(text2);
52215
+ const out = [];
52216
+ while (!scanner.done()) {
52217
+ const n = scanner.number();
52218
+ if (n === null) return null;
52219
+ out.push(n);
52220
+ }
52221
+ return out;
52222
+ }
52223
+ function parseTransform(text2) {
52224
+ let m = IDENTITY;
52225
+ const re = /\s*,?\s*([a-zA-Z]+)\s*\(([^)]*)\)/y;
52226
+ let pos = 0;
52227
+ const trimmed = text2.trim();
52228
+ while (pos < trimmed.length) {
52229
+ re.lastIndex = pos;
52230
+ const hit = re.exec(trimmed);
52231
+ if (!hit) return null;
52232
+ pos = re.lastIndex;
52233
+ const args = parseNumberList(hit[2]);
52234
+ if (!args) return null;
52235
+ const n = args.length;
52236
+ let t;
52237
+ switch (hit[1]) {
52238
+ case "matrix":
52239
+ if (n !== 6) return null;
52240
+ t = args;
52241
+ break;
52242
+ case "translate":
52243
+ if (n !== 1 && n !== 2) return null;
52244
+ t = [1, 0, 0, 1, args[0], args[1] ?? 0];
52245
+ break;
52246
+ case "scale":
52247
+ if (n !== 1 && n !== 2) return null;
52248
+ t = [args[0], 0, 0, args[1] ?? args[0], 0, 0];
52249
+ break;
52250
+ case "rotate": {
52251
+ if (n !== 1 && n !== 3) return null;
52252
+ const r = args[0] * Math.PI / 180;
52253
+ const [cos, sin] = [Math.cos(r), Math.sin(r)];
52254
+ t = [cos, sin, -sin, cos, 0, 0];
52255
+ if (n === 3)
52256
+ t = multiply(multiply([1, 0, 0, 1, args[1], args[2]], t), [
52257
+ 1,
52258
+ 0,
52259
+ 0,
52260
+ 1,
52261
+ -args[1],
52262
+ -args[2]
52263
+ ]);
52264
+ break;
52265
+ }
52266
+ case "skewX":
52267
+ if (n !== 1) return null;
52268
+ t = [1, 0, Math.tan(args[0] * Math.PI / 180), 1, 0, 0];
52269
+ break;
52270
+ case "skewY":
52271
+ if (n !== 1) return null;
52272
+ t = [1, Math.tan(args[0] * Math.PI / 180), 0, 1, 0, 0];
52273
+ break;
52274
+ default:
52275
+ return null;
52276
+ }
52277
+ m = multiply(m, t);
52278
+ }
52279
+ return m.every(Number.isFinite) ? m : null;
52280
+ }
52281
+ var KAPPA = 0.5522847498307936;
52282
+ function arcToCubics(from, rxIn, ryIn, angleDeg, largeArc, sweep, to) {
52283
+ if (from[0] === to[0] && from[1] === to[1]) return [];
52284
+ let rx = Math.abs(rxIn);
52285
+ let ry = Math.abs(ryIn);
52286
+ if (rx === 0 || ry === 0) return [{ kind: "L", to }];
52287
+ const phi = angleDeg * Math.PI / 180;
52288
+ const cos = Math.cos(phi);
52289
+ const sin = Math.sin(phi);
52290
+ const dx = (from[0] - to[0]) / 2;
52291
+ const dy = (from[1] - to[1]) / 2;
52292
+ const x1 = cos * dx + sin * dy;
52293
+ const y1 = -sin * dx + cos * dy;
52294
+ const lambda = x1 * x1 / (rx * rx) + y1 * y1 / (ry * ry);
52295
+ if (lambda > 1) {
52296
+ rx *= Math.sqrt(lambda);
52297
+ ry *= Math.sqrt(lambda);
52298
+ }
52299
+ const num2 = rx * rx * ry * ry - rx * rx * y1 * y1 - ry * ry * x1 * x1;
52300
+ const den = rx * rx * y1 * y1 + ry * ry * x1 * x1;
52301
+ const coef = (largeArc === sweep ? -1 : 1) * Math.sqrt(Math.max(0, num2 / den));
52302
+ const cx1 = coef * rx * y1 / ry;
52303
+ const cy1 = -coef * ry * x1 / rx;
52304
+ const cx = cos * cx1 - sin * cy1 + (from[0] + to[0]) / 2;
52305
+ const cy = sin * cx1 + cos * cy1 + (from[1] + to[1]) / 2;
52306
+ const angle = (ux, uy, vx, vy) => Math.atan2(ux * vy - uy * vx, ux * vx + uy * vy);
52307
+ const theta1 = angle(1, 0, (x1 - cx1) / rx, (y1 - cy1) / ry);
52308
+ let delta = angle((x1 - cx1) / rx, (y1 - cy1) / ry, (-x1 - cx1) / rx, (-y1 - cy1) / ry);
52309
+ if (!sweep && delta > 0) delta -= 2 * Math.PI;
52310
+ if (sweep && delta < 0) delta += 2 * Math.PI;
52311
+ const pieces = Math.max(1, Math.ceil(Math.abs(delta) / (Math.PI / 2) - 1e-9));
52312
+ const step = delta / pieces;
52313
+ const k = 4 / 3 * Math.tan(step / 4);
52314
+ const map = (x, y) => [cos * x - sin * y + cx, sin * x + cos * y + cy];
52315
+ const out = [];
52316
+ for (let i = 0; i < pieces; i++) {
52317
+ const t1 = theta1 + i * step;
52318
+ const t2 = t1 + step;
52319
+ const [e1x, e1y] = [rx * Math.cos(t1), ry * Math.sin(t1)];
52320
+ const [e2x, e2y] = [rx * Math.cos(t2), ry * Math.sin(t2)];
52321
+ const [d1x, d1y] = [-rx * Math.sin(t1), ry * Math.cos(t1)];
52322
+ const [d2x, d2y] = [-rx * Math.sin(t2), ry * Math.cos(t2)];
52323
+ out.push({
52324
+ kind: "C",
52325
+ c1: map(e1x + k * d1x, e1y + k * d1y),
52326
+ c2: map(e2x - k * d2x, e2y - k * d2y),
52327
+ to: i === pieces - 1 ? to : map(e2x, e2y)
52328
+ });
52329
+ }
52330
+ return out;
52331
+ }
52332
+ function parsePathData(d) {
52333
+ const s = new NumberScanner(d);
52334
+ const subpaths = [];
52335
+ let current = null;
52336
+ let pen = [0, 0];
52337
+ let start = [0, 0];
52338
+ let lastCubic = null;
52339
+ let lastQuad = null;
52340
+ let curved = false;
52341
+ let command = "";
52342
+ const result = (error2) => ({ subpaths, error: error2, curved });
52343
+ const lineTo = (to) => {
52344
+ current.segments.push({ kind: "L", to });
52345
+ pen = to;
52346
+ };
52347
+ while (!s.done()) {
52348
+ const next = s.peek();
52349
+ if (/[a-zA-Z]/.test(next)) command = s.take();
52350
+ else if (!command || command === "z" || command === "Z") return result(true);
52351
+ const rel = command === command.toLowerCase();
52352
+ const base = rel ? pen : [0, 0];
52353
+ const num2 = () => s.number();
52354
+ const pt = () => {
52355
+ const x = num2();
52356
+ const y = x === null ? null : num2();
52357
+ return x === null || y === null ? null : [x + base[0], y + base[1]];
52358
+ };
52359
+ const upper = command.toUpperCase();
52360
+ if (!current && upper !== "M") return result(true);
52361
+ let cubicCtrl = null;
52362
+ let quadCtrl = null;
52363
+ switch (upper) {
52364
+ case "M": {
52365
+ const p = pt();
52366
+ if (!p) return result(true);
52367
+ current = { start: p, segments: [], closed: false };
52368
+ subpaths.push(current);
52369
+ pen = p;
52370
+ start = p;
52371
+ command = rel ? "l" : "L";
52372
+ break;
52373
+ }
52374
+ case "L": {
52375
+ const p = pt();
52376
+ if (!p) return result(true);
52377
+ lineTo(p);
52378
+ break;
52379
+ }
52380
+ case "H": {
52381
+ const x = num2();
52382
+ if (x === null) return result(true);
52383
+ lineTo([x + base[0], pen[1]]);
52384
+ break;
52385
+ }
52386
+ case "V": {
52387
+ const y = num2();
52388
+ if (y === null) return result(true);
52389
+ lineTo([pen[0], y + base[1]]);
52390
+ break;
52391
+ }
52392
+ case "C":
52393
+ case "S": {
52394
+ let c1;
52395
+ if (upper === "C") c1 = pt();
52396
+ else c1 = lastCubic ? [2 * pen[0] - lastCubic[0], 2 * pen[1] - lastCubic[1]] : pen;
52397
+ const c2 = c1 ? pt() : null;
52398
+ const to = c2 ? pt() : null;
52399
+ if (!c1 || !c2 || !to) return result(true);
52400
+ current.segments.push({ kind: "C", c1, c2, to });
52401
+ cubicCtrl = c2;
52402
+ pen = to;
52403
+ curved = true;
52404
+ break;
52405
+ }
52406
+ case "Q":
52407
+ case "T": {
52408
+ let q;
52409
+ if (upper === "Q") q = pt();
52410
+ else q = lastQuad ? [2 * pen[0] - lastQuad[0], 2 * pen[1] - lastQuad[1]] : pen;
52411
+ const to = q ? pt() : null;
52412
+ if (!q || !to) return result(true);
52413
+ current.segments.push({
52414
+ kind: "C",
52415
+ c1: [pen[0] + 2 / 3 * (q[0] - pen[0]), pen[1] + 2 / 3 * (q[1] - pen[1])],
52416
+ c2: [to[0] + 2 / 3 * (q[0] - to[0]), to[1] + 2 / 3 * (q[1] - to[1])],
52417
+ to
52418
+ });
52419
+ quadCtrl = q;
52420
+ pen = to;
52421
+ curved = true;
52422
+ break;
52423
+ }
52424
+ case "A": {
52425
+ const rx = num2();
52426
+ const ry = rx === null ? null : num2();
52427
+ const rot = ry === null ? null : num2();
52428
+ const large = rot === null ? null : s.flag();
52429
+ const sweep = large === null ? null : s.flag();
52430
+ const to = sweep === null ? null : pt();
52431
+ if (!to) return result(true);
52432
+ const segs = arcToCubics(pen, rx, ry, rot, large, sweep, to);
52433
+ current.segments.push(...segs);
52434
+ if (segs.some((g) => g.kind === "C")) curved = true;
52435
+ pen = to;
52436
+ break;
52437
+ }
52438
+ case "Z":
52439
+ current.closed = true;
52440
+ pen = start;
52441
+ current = { start, segments: [], closed: false };
52442
+ subpaths.push(current);
52443
+ break;
52444
+ default:
52445
+ return result(true);
52446
+ }
52447
+ lastCubic = cubicCtrl;
52448
+ lastQuad = quadCtrl;
52449
+ }
52450
+ return result(false);
52451
+ }
52452
+ function ellipseSubpath(cx, cy, rx, ry) {
52453
+ const kx = rx * KAPPA;
52454
+ const ky = ry * KAPPA;
52455
+ return {
52456
+ start: [cx + rx, cy],
52457
+ closed: true,
52458
+ segments: [
52459
+ { kind: "C", c1: [cx + rx, cy + ky], c2: [cx + kx, cy + ry], to: [cx, cy + ry] },
52460
+ { kind: "C", c1: [cx - kx, cy + ry], c2: [cx - rx, cy + ky], to: [cx - rx, cy] },
52461
+ { kind: "C", c1: [cx - rx, cy - ky], c2: [cx - kx, cy - ry], to: [cx, cy - ry] },
52462
+ { kind: "C", c1: [cx + kx, cy - ry], c2: [cx + rx, cy - ky], to: [cx + rx, cy] }
52463
+ ]
52464
+ };
52465
+ }
52466
+ function rectSubpath(x, y, w, h, rx, ry) {
52467
+ if (rx <= 0 || ry <= 0)
52468
+ return {
52469
+ start: [x, y],
52470
+ closed: true,
52471
+ segments: [
52472
+ { kind: "L", to: [x + w, y] },
52473
+ { kind: "L", to: [x + w, y + h] },
52474
+ { kind: "L", to: [x, y + h] },
52475
+ { kind: "L", to: [x, y] }
52476
+ ]
52477
+ };
52478
+ const kx = rx * KAPPA;
52479
+ const ky = ry * KAPPA;
52480
+ const r = x + w;
52481
+ const b = y + h;
52482
+ return {
52483
+ start: [x + rx, y],
52484
+ closed: true,
52485
+ segments: [
52486
+ { kind: "L", to: [r - rx, y] },
52487
+ { kind: "C", c1: [r - rx + kx, y], c2: [r, y + ry - ky], to: [r, y + ry] },
52488
+ { kind: "L", to: [r, b - ry] },
52489
+ { kind: "C", c1: [r, b - ry + ky], c2: [r - rx + kx, b], to: [r - rx, b] },
52490
+ { kind: "L", to: [x + rx, b] },
52491
+ { kind: "C", c1: [x + rx - kx, b], c2: [x, b - ry + ky], to: [x, b - ry] },
52492
+ { kind: "L", to: [x, y + ry] },
52493
+ { kind: "C", c1: [x, y + ry - ky], c2: [x + rx - kx, y], to: [x + rx, y] }
52494
+ ]
52495
+ };
52496
+ }
52497
+ function distanceToChord(p, a, b) {
52498
+ const dx = b[0] - a[0];
52499
+ const dy = b[1] - a[1];
52500
+ const len = Math.hypot(dx, dy);
52501
+ if (len === 0) return Math.hypot(p[0] - a[0], p[1] - a[1]);
52502
+ return Math.abs((p[0] - a[0]) * dy - (p[1] - a[1]) * dx) / len;
52503
+ }
52504
+ function flattenCubic(p0, c1, c2, p3, tolerance, out, depth = 0) {
52505
+ if (depth >= 16 || Math.max(distanceToChord(c1, p0, p3), distanceToChord(c2, p0, p3)) <= tolerance) {
52506
+ out.push(p3);
52507
+ return;
52508
+ }
52509
+ const mid = (a2, b2) => [(a2[0] + b2[0]) / 2, (a2[1] + b2[1]) / 2];
52510
+ const a = mid(p0, c1);
52511
+ const b = mid(c1, c2);
52512
+ const c = mid(c2, p3);
52513
+ const d = mid(a, b);
52514
+ const e = mid(b, c);
52515
+ const m = mid(d, e);
52516
+ flattenCubic(p0, a, d, m, tolerance, out, depth + 1);
52517
+ flattenCubic(m, e, c, p3, tolerance, out, depth + 1);
52518
+ }
52519
+ function flattenSubpath(sub4, m, tolerance) {
52520
+ const points = [apply(m, sub4.start)];
52521
+ let pen = sub4.start;
52522
+ for (const seg of sub4.segments) {
52523
+ if (seg.kind === "L") points.push(apply(m, seg.to));
52524
+ else
52525
+ flattenCubic(
52526
+ apply(m, pen),
52527
+ apply(m, seg.c1),
52528
+ apply(m, seg.c2),
52529
+ apply(m, seg.to),
52530
+ tolerance,
52531
+ points
52532
+ );
52533
+ pen = seg.to;
52534
+ }
52535
+ if (sub4.closed) {
52536
+ const first2 = points[0];
52537
+ const last = points[points.length - 1];
52538
+ if (last[0] !== first2[0] || last[1] !== first2[1]) points.push(first2);
52539
+ }
52540
+ return points;
52541
+ }
52542
+ function clipSegment(a, b, r) {
52543
+ const dx = b[0] - a[0];
52544
+ const dy = b[1] - a[1];
52545
+ let t0 = 0;
52546
+ let t1 = 1;
52547
+ const edges = [
52548
+ [-dx, a[0] - r.x0],
52549
+ [dx, r.x1 - a[0]],
52550
+ [-dy, a[1] - r.y0],
52551
+ [dy, r.y1 - a[1]]
52552
+ ];
52553
+ for (const [p, q] of edges) {
52554
+ if (p === 0) {
52555
+ if (q < 0) return null;
52556
+ continue;
52557
+ }
52558
+ const t = q / p;
52559
+ if (p < 0) t0 = Math.max(t0, t);
52560
+ else t1 = Math.min(t1, t);
52561
+ if (t0 > t1) return null;
52562
+ }
52563
+ return [
52564
+ [a[0] + t0 * dx, a[1] + t0 * dy],
52565
+ [a[0] + t1 * dx, a[1] + t1 * dy]
52566
+ ];
52567
+ }
52568
+ function clipPolyline(points, r) {
52569
+ const inside = (p) => p[0] >= r.x0 && p[0] <= r.x1 && p[1] >= r.y0 && p[1] <= r.y1;
52570
+ if (points.every(inside)) return { parts: [points], clipped: false };
52571
+ if (points.length === 1) return { parts: [], clipped: true };
52572
+ const parts = [];
52573
+ let run = [];
52574
+ for (let i = 1; i < points.length; i++) {
52575
+ const seg = clipSegment(points[i - 1], points[i], r);
52576
+ if (!seg) {
52577
+ if (run.length) parts.push(run);
52578
+ run = [];
52579
+ continue;
52580
+ }
52581
+ const [a, b] = seg;
52582
+ const last = run[run.length - 1];
52583
+ if (!run.length || last[0] !== a[0] || last[1] !== a[1]) {
52584
+ if (run.length) parts.push(run);
52585
+ run = [a];
52586
+ }
52587
+ run.push(b);
52588
+ if (b[0] !== points[i][0] || b[1] !== points[i][1]) {
52589
+ parts.push(run);
52590
+ run = [];
52591
+ }
52592
+ }
52593
+ if (run.length) parts.push(run);
52594
+ return { parts, clipped: true };
52595
+ }
52596
+ function dashPolyline(points, pattern, offset, charge) {
52597
+ const total = pattern.reduce((s, v) => s + v, 0);
52598
+ let index = 0;
52599
+ let remaining = pattern[0];
52600
+ let on = true;
52601
+ let shift = (offset % total + total) % total;
52602
+ while (shift > 0) {
52603
+ const step = Math.min(shift, remaining);
52604
+ remaining -= step;
52605
+ shift -= step;
52606
+ if (remaining <= 0) {
52607
+ index = (index + 1) % pattern.length;
52608
+ remaining = pattern[index];
52609
+ on = !on;
52610
+ }
52611
+ }
52612
+ const dashes = [];
52613
+ let currentDash = on ? [points[0]] : null;
52614
+ for (let i = 1; i < points.length; i++) {
52615
+ let a = points[i - 1];
52616
+ const b = points[i];
52617
+ let segLen = Math.hypot(b[0] - a[0], b[1] - a[1]);
52618
+ while (segLen > remaining) {
52619
+ const t = remaining / segLen;
52620
+ const cut = [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];
52621
+ if (on && currentDash) {
52622
+ currentDash.push(cut);
52623
+ dashes.push(currentDash);
52624
+ charge(1);
52625
+ currentDash = null;
52626
+ } else currentDash = [cut];
52627
+ on = !on;
52628
+ segLen -= remaining;
52629
+ a = cut;
52630
+ index = (index + 1) % pattern.length;
52631
+ remaining = pattern[index];
52632
+ }
52633
+ remaining -= segLen;
52634
+ if (on && currentDash) currentDash.push(b);
52635
+ }
52636
+ if (on && currentDash && currentDash.length > 1) {
52637
+ dashes.push(currentDash);
52638
+ charge(1);
52639
+ }
52640
+ return dashes;
52641
+ }
52642
+ function scanFill(rings, evenOdd, brush, spacing, charge) {
52643
+ const edges = [];
52644
+ let minY = Infinity;
52645
+ let maxY = -Infinity;
52646
+ for (const ring of rings)
52647
+ for (let i = 0; i < ring.length; i++) {
52648
+ const a = ring[i];
52649
+ const b = ring[(i + 1) % ring.length];
52650
+ if (a[1] !== b[1]) edges.push([a, b]);
52651
+ minY = Math.min(minY, a[1]);
52652
+ maxY = Math.max(maxY, a[1]);
52653
+ }
52654
+ if (!edges.length) return [];
52655
+ const height = maxY - minY;
52656
+ const lines = Math.max(1, Math.round(height / spacing));
52657
+ const step = height / lines;
52658
+ const out = [];
52659
+ let chains = [];
52660
+ let previous = [];
52661
+ for (let k = 0; k < lines; k++) {
52662
+ const y = minY + step * (k + 0.5);
52663
+ charge(edges.length);
52664
+ const crossings = [];
52665
+ for (const [a, b] of edges) {
52666
+ const lo = Math.min(a[1], b[1]);
52667
+ const hi = Math.max(a[1], b[1]);
52668
+ if (y < lo || y >= hi) continue;
52669
+ crossings.push({
52670
+ x: a[0] + (y - a[1]) / (b[1] - a[1]) * (b[0] - a[0]),
52671
+ dir: b[1] > a[1] ? 1 : -1
52672
+ });
52673
+ }
52674
+ crossings.sort((p, q) => p.x - q.x);
52675
+ const spans = [];
52676
+ let winding = 0;
52677
+ for (let i = 0; i < crossings.length - 1; i++) {
52678
+ winding = evenOdd ? winding ^ 1 : winding + crossings[i].dir;
52679
+ if (winding !== 0 && crossings[i + 1].x > crossings[i].x)
52680
+ spans.push([crossings[i].x, crossings[i + 1].x]);
52681
+ }
52682
+ const merged = [];
52683
+ for (const span of spans) {
52684
+ const last = merged[merged.length - 1];
52685
+ if (last && span[0] <= last[1]) last[1] = Math.max(last[1], span[1]);
52686
+ else merged.push([...span]);
52687
+ }
52688
+ const continues = merged.length === previous.length && merged.every((s, i) => s[0] <= previous[i][1] && s[1] >= previous[i][0]);
52689
+ if (!continues) {
52690
+ out.push(...chains);
52691
+ chains = merged.map(() => []);
52692
+ }
52693
+ merged.forEach(([x0, x1], i) => {
52694
+ const inset = Math.min(brush / 2, (x1 - x0) / 2);
52695
+ const left = [x0 + inset, y];
52696
+ const right = [x1 - inset, y];
52697
+ const forward = k % 2 === 0;
52698
+ const pts = left[0] === right[0] ? [left] : forward ? [left, right] : [right, left];
52699
+ chains[i].push(...pts);
52700
+ });
52701
+ previous = merged;
52702
+ }
52703
+ out.push(...chains);
52704
+ return out.filter((c) => c.length > 0);
52705
+ }
52706
+
52707
+ // src/utils/svgXml.ts
52708
+ var SVG_NS = "http://www.w3.org/2000/svg";
52709
+ var XLINK_NS = "http://www.w3.org/1999/xlink";
52710
+ var XML_NS = "http://www.w3.org/XML/1998/namespace";
52711
+ var SvgError = class extends Error {
52712
+ constructor(code, message, location = null) {
52713
+ super(message);
52714
+ this.code = code;
52715
+ this.location = location;
52716
+ this.name = "SvgError";
52717
+ }
52718
+ code;
52719
+ location;
52720
+ };
52721
+ var NAME_START = /[A-Za-z_À-￿]/;
52722
+ var NAME_CHAR = /[A-Za-z0-9_.\-:·À-￿]/;
52723
+ var PREDEFINED = { lt: "<", gt: ">", amp: "&", quot: '"', apos: "'" };
52724
+ function decodeEntities(raw, line) {
52725
+ if (!raw.includes("&")) return raw;
52726
+ return raw.replace(/&([^;&\s]*);?/g, (match, body) => {
52727
+ if (!match.endsWith(";"))
52728
+ throw new SvgError("svg_invalid", `Unterminated character reference on line ${line}`);
52729
+ if (body.startsWith("#")) {
52730
+ const hex3 = body[1] === "x" || body[1] === "X";
52731
+ const digits = body.slice(hex3 ? 2 : 1);
52732
+ const valid = hex3 ? /^[0-9A-Fa-f]{1,6}$/.test(digits) : /^[0-9]{1,7}$/.test(digits);
52733
+ const code = valid ? Number.parseInt(digits, hex3 ? 16 : 10) : NaN;
52734
+ if (!valid || code === 0 || code > 1114111 || code >= 55296 && code <= 57343)
52735
+ throw new SvgError("svg_invalid", `Invalid character reference on line ${line}`);
52736
+ return String.fromCodePoint(code);
52737
+ }
52738
+ if (body in PREDEFINED) return PREDEFINED[body];
52739
+ throw new SvgError(
52740
+ "svg_unsafe",
52741
+ `Named entity "&${body.slice(0, 40)};" on line ${line}: only the five XML entities are allowed`
52742
+ );
52743
+ });
52744
+ }
52745
+ function parseXml(source, limits) {
52746
+ let pos = 0;
52747
+ let line = 1;
52748
+ let elementCount = 0;
52749
+ const stack = [];
52750
+ let root = null;
52751
+ const fail = (message) => {
52752
+ throw new SvgError("svg_invalid", `${message} on line ${line}`);
52753
+ };
52754
+ const advance = (to) => {
52755
+ for (let i = pos; i < to; i++) if (source.charCodeAt(i) === 10) line++;
52756
+ pos = to;
52757
+ };
52758
+ const indexOrFail = (needle, what) => {
52759
+ const at = source.indexOf(needle, pos);
52760
+ if (at < 0) fail(`Unterminated ${what}`);
52761
+ return at;
52762
+ };
52763
+ if (source.startsWith("<?xml") && /^<\?xml[\s?]/.test(source)) {
52764
+ const end = indexOrFail("?>", "XML declaration");
52765
+ advance(end + 2);
52766
+ }
52767
+ while (pos < source.length) {
52768
+ const lt = source.indexOf("<", pos);
52769
+ const textEnd = lt < 0 ? source.length : lt;
52770
+ if (textEnd > pos) {
52771
+ const raw = source.slice(pos, textEnd);
52772
+ if (stack.length) stack[stack.length - 1].element.text += decodeEntities(raw, line);
52773
+ else if (raw.trim()) fail("Text outside the root element");
52774
+ advance(textEnd);
52775
+ if (lt < 0) break;
52776
+ }
52777
+ if (source.startsWith("<!--", pos)) {
52778
+ const end = indexOrFail("-->", "comment");
52779
+ advance(end + 3);
52780
+ continue;
52781
+ }
52782
+ if (source.startsWith("<![CDATA[", pos)) {
52783
+ if (!stack.length) fail("CDATA outside the root element");
52784
+ const end = indexOrFail("]]>", "CDATA section");
52785
+ stack[stack.length - 1].element.text += source.slice(pos + 9, end);
52786
+ advance(end + 3);
52787
+ continue;
52788
+ }
52789
+ if (source.startsWith("<!", pos))
52790
+ throw new SvgError(
52791
+ "svg_unsafe",
52792
+ `DOCTYPE, ENTITY and other declarations are not allowed (line ${line})`
52793
+ );
52794
+ if (source.startsWith("<?", pos))
52795
+ throw new SvgError("svg_unsafe", `Processing instructions are not allowed (line ${line})`);
52796
+ if (source.startsWith("</", pos)) {
52797
+ const end = indexOrFail(">", "end tag");
52798
+ const name2 = source.slice(pos + 2, end).trim();
52799
+ const open = stack.pop();
52800
+ if (!open || open.element.name !== name2) fail(`Mismatched end tag </${name2.slice(0, 40)}>`);
52801
+ advance(end + 1);
52802
+ continue;
52803
+ }
52804
+ const tagLine = line;
52805
+ let i = pos + 1;
52806
+ if (!NAME_START.test(source[i] ?? "")) fail("Invalid tag");
52807
+ while (i < source.length && NAME_CHAR.test(source[i])) i++;
52808
+ const name = source.slice(pos + 1, i);
52809
+ const rawAttributes = [];
52810
+ let selfClosing = false;
52811
+ for (; ; ) {
52812
+ const ws = i;
52813
+ while (i < source.length && /\s/.test(source[i])) i++;
52814
+ if (i >= source.length) fail("Unterminated start tag");
52815
+ if (source[i] === ">") {
52816
+ i++;
52817
+ break;
52818
+ }
52819
+ if (source.startsWith("/>", i)) {
52820
+ selfClosing = true;
52821
+ i += 2;
52822
+ break;
52823
+ }
52824
+ if (i === ws) fail("Missing whitespace between attributes");
52825
+ const nameStart = i;
52826
+ if (!NAME_START.test(source[i])) fail("Invalid attribute name");
52827
+ while (i < source.length && NAME_CHAR.test(source[i])) i++;
52828
+ const attrName = source.slice(nameStart, i);
52829
+ while (/\s/.test(source[i] ?? "")) i++;
52830
+ if (source[i] !== "=") fail(`Attribute ${attrName.slice(0, 40)} has no value`);
52831
+ i++;
52832
+ while (/\s/.test(source[i] ?? "")) i++;
52833
+ const quote = source[i];
52834
+ if (quote !== '"' && quote !== "'") fail("Attribute values must be quoted");
52835
+ const close = source.indexOf(quote, i + 1);
52836
+ if (close < 0) fail("Unterminated attribute value");
52837
+ const rawValue = source.slice(i + 1, close);
52838
+ if (rawValue.includes("<")) fail("'<' in an attribute value");
52839
+ if (rawAttributes.some((a) => a.name === attrName))
52840
+ fail(`Duplicate attribute ${attrName.slice(0, 40)}`);
52841
+ rawAttributes.push({
52842
+ name: attrName,
52843
+ value: decodeEntities(rawValue.replace(/[\t\n\r]/g, " "), line)
52844
+ });
52845
+ i = close + 1;
52846
+ }
52847
+ advance(i);
52848
+ if (!stack.length && root) fail("More than one root element");
52849
+ elementCount++;
52850
+ if (elementCount > limits.maxElements)
52851
+ throw new SvgError(
52852
+ "svg_complexity_limit",
52853
+ `The document has more than ${limits.maxElements} elements`
52854
+ );
52855
+ if (stack.length + 1 > limits.maxDepth)
52856
+ throw new SvgError("svg_complexity_limit", `Elements nest deeper than ${limits.maxDepth}`);
52857
+ const parentScope = stack.length ? stack[stack.length - 1].scope : /* @__PURE__ */ new Map();
52858
+ const scope2 = new Map(parentScope);
52859
+ for (const a of rawAttributes) {
52860
+ if (a.name === "xmlns") scope2.set("", a.value);
52861
+ else if (a.name.startsWith("xmlns:")) scope2.set(a.name.slice(6), a.value);
52862
+ }
52863
+ const resolve7 = (qualified, isAttribute) => {
52864
+ const colon = qualified.indexOf(":");
52865
+ if (colon < 0) return { local: qualified, ns: isAttribute ? null : scope2.get("") ?? null };
52866
+ const prefix = qualified.slice(0, colon);
52867
+ const local = qualified.slice(colon + 1);
52868
+ if (prefix === "xml") return { local, ns: XML_NS };
52869
+ const ns = scope2.get(prefix);
52870
+ if (ns === void 0) fail(`Undeclared namespace prefix "${prefix.slice(0, 40)}"`);
52871
+ return { local, ns };
52872
+ };
52873
+ const resolved = resolve7(name, false);
52874
+ const element = {
52875
+ name,
52876
+ local: resolved.local,
52877
+ ns: resolved.ns,
52878
+ attributes: rawAttributes.filter((a) => a.name !== "xmlns" && !a.name.startsWith("xmlns:")).map((a) => ({ name: a.name, value: a.value, ...resolve7(a.name, true) })),
52879
+ children: [],
52880
+ text: "",
52881
+ line: tagLine
52882
+ };
52883
+ if (stack.length) stack[stack.length - 1].element.children.push(element);
52884
+ else root = element;
52885
+ if (!selfClosing) stack.push({ element, scope: scope2 });
52886
+ }
52887
+ if (stack.length) fail(`Unclosed element <${stack[stack.length - 1].element.name}>`);
52888
+ if (!root) fail("No root element");
52889
+ return root;
52890
+ }
52891
+
52892
+ // src/utils/svgAnalyzer.ts
52893
+ var SVG_ANALYZER_VERSION = "apple-notes-mcp/svg-analyzer@1";
52894
+ var SVG_LIMITS = {
52895
+ maxSourceBytes: 1048576,
52896
+ maxSourceElements: 16384,
52897
+ maxExpandedElements: 16384,
52898
+ maxReferenceExpansions: 8192,
52899
+ maxDepth: 64,
52900
+ maxReferenceDepth: 32,
52901
+ maxPathSegments: 1e5,
52902
+ maxGeometryWork: 1e5,
52903
+ maxDashWork: 1e5,
52904
+ maxScanWork: 5e6,
52905
+ maxStrokes: 4096,
52906
+ maxPoints: 1e5,
52907
+ maxDrawingBytes: 8388608,
52908
+ maxCoordinate: 1e6,
52909
+ maxStrokeWidth: 8192,
52910
+ maxIssues: 128,
52911
+ maxLocationLength: 240
52912
+ };
52913
+ var TOLERANCE = 0.25;
52914
+ var FILL_SCANLINES = 80;
52915
+ var MIN_FILL_BRUSH = 2;
52916
+ var MAX_FILL_BRUSH = 16;
52917
+ var SVG_LOSSES = [
52918
+ "drop-content",
52919
+ "geometry-approximation",
52920
+ "paint-approximation"
52921
+ ];
52922
+ var UNSAFE_ELEMENTS = /* @__PURE__ */ new Set([
52923
+ "script",
52924
+ "style",
52925
+ "foreignObject",
52926
+ "iframe",
52927
+ "object",
52928
+ "embed",
52929
+ "audio",
52930
+ "video",
52931
+ "canvas",
52932
+ "animate",
52933
+ "animateMotion",
52934
+ "animateTransform",
52935
+ "animateColor",
52936
+ "set",
52937
+ "discard",
52938
+ "handler",
52939
+ "listener"
52940
+ ]);
52941
+ var NON_RENDERING = /* @__PURE__ */ new Set([
52942
+ "title",
52943
+ "desc",
52944
+ "metadata",
52945
+ "defs",
52946
+ "symbol",
52947
+ "linearGradient",
52948
+ "radialGradient",
52949
+ "meshgradient",
52950
+ "stop",
52951
+ "clipPath",
52952
+ "mask",
52953
+ "pattern",
52954
+ "marker",
52955
+ "filter",
52956
+ "view",
52957
+ "cursor",
52958
+ "font",
52959
+ "font-face",
52960
+ "glyph",
52961
+ "missing-glyph",
52962
+ "hkern",
52963
+ "vkern",
52964
+ "color-profile"
52965
+ ]);
52966
+ var GEOMETRY = /* @__PURE__ */ new Set(["path", "rect", "circle", "ellipse", "line", "polyline", "polygon"]);
52967
+ var TEXT = /* @__PURE__ */ new Set(["text", "tspan", "textPath", "tref"]);
52968
+ var STYLE_PROPERTIES = /* @__PURE__ */ new Set([
52969
+ "fill",
52970
+ "stroke",
52971
+ "color",
52972
+ "stroke-width",
52973
+ "opacity",
52974
+ "fill-opacity",
52975
+ "stroke-opacity",
52976
+ "fill-rule",
52977
+ "visibility",
52978
+ "display",
52979
+ "stroke-linecap",
52980
+ "stroke-linejoin",
52981
+ "stroke-miterlimit",
52982
+ "stroke-dasharray",
52983
+ "stroke-dashoffset",
52984
+ "vector-effect",
52985
+ "overflow"
52986
+ ]);
52987
+ var DROPPED_MODIFIERS = /* @__PURE__ */ new Set([
52988
+ "clip-path",
52989
+ "mask",
52990
+ "filter",
52991
+ "marker",
52992
+ "marker-start",
52993
+ "marker-mid",
52994
+ "marker-end"
52995
+ ]);
52996
+ var IGNORED_PROPERTY = /^(?:font(?:-.*)?|text-.*|letter-spacing|word-spacing|line-height|writing-mode|direction|unicode-bidi|dominant-baseline|alignment-baseline|baseline-shift|shape-rendering|color-rendering|color-interpolation(?:-filters)?|image-rendering|stop-.*|flood-.*|lighting-color|enable-background|solid-.*|clip-rule|isolation|pointer-events|cursor|shape-inside|shape-padding|inline-size|white-space|transform-origin|transform-box|-inkscape-.*|-webkit-.*|-moz-.*)$/;
52997
+ function canonicalJson(value) {
52998
+ if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
52999
+ if (value && typeof value === "object")
53000
+ return `{${Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${canonicalJson(value[k])}`).join(",")}}`;
53001
+ return JSON.stringify(value);
53002
+ }
53003
+ function sha256(text2) {
53004
+ return createHash4("sha256").update(text2).digest("hex");
53005
+ }
53006
+ var round = (v, digits) => {
53007
+ const r = Number(v.toFixed(digits));
53008
+ return r === 0 ? 0 : r;
53009
+ };
53010
+ var UNITS = {
53011
+ "": 1,
53012
+ px: 1,
53013
+ pt: 4 / 3,
53014
+ pc: 16,
53015
+ mm: 96 / 25.4,
53016
+ cm: 96 / 2.54,
53017
+ in: 96
53018
+ };
53019
+ function parseLength(value, percentOf) {
53020
+ if (value === void 0) return null;
53021
+ const m = /^\s*([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)\s*(px|pt|pc|mm|cm|in|%)?\s*$/i.exec(
53022
+ value
53023
+ );
53024
+ if (!m) return null;
53025
+ const n = Number(m[1]);
53026
+ const unit = (m[2] ?? "").toLowerCase();
53027
+ const px = unit === "%" ? n / 100 * percentOf : n * UNITS[unit];
53028
+ return Number.isFinite(px) ? px : null;
53029
+ }
53030
+ function parseOpacity(value) {
53031
+ const m = /^\s*([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(%?)\s*$/i.exec(value);
53032
+ if (!m) return null;
53033
+ const n = Number(m[1]) / (m[2] ? 100 : 1);
53034
+ return Math.min(1, Math.max(0, n));
53035
+ }
53036
+ function viewBoxMatrix(viewBox, width, height, preserve) {
53037
+ const [vx, vy, vw, vh] = viewBox;
53038
+ const parts = (preserve ?? "xMidYMid meet").trim().split(/\s+/);
53039
+ const align = parts[0] === "defer" ? parts[1] ?? "xMidYMid" : parts[0];
53040
+ const slice = parts.includes("slice");
53041
+ let sx = width / vw;
53042
+ let sy = height / vh;
53043
+ if (align !== "none") {
53044
+ const s = slice ? Math.max(sx, sy) : Math.min(sx, sy);
53045
+ sx = s;
53046
+ sy = s;
53047
+ }
53048
+ let tx = -vx * sx;
53049
+ let ty = -vy * sy;
53050
+ if (align !== "none") {
53051
+ const xAlign = /xMid/.test(align) ? 0.5 : /xMax/.test(align) ? 1 : 0;
53052
+ const yAlign = /YMid/.test(align) ? 0.5 : /YMax/.test(align) ? 1 : 0;
53053
+ tx += (width - vw * sx) * xAlign;
53054
+ ty += (height - vh * sy) * yAlign;
53055
+ }
53056
+ return [sx + 0, 0, 0, sy + 0, tx + 0, ty + 0];
53057
+ }
53058
+ function parseViewBox(value) {
53059
+ if (value === void 0) return null;
53060
+ const nums = parseNumberList(value);
53061
+ if (!nums || nums.length !== 4 || nums[2] <= 0 || nums[3] <= 0) return null;
53062
+ return nums;
53063
+ }
53064
+ function attr(el, local) {
53065
+ return el.attributes.find((a) => a.local === local && a.ns === null)?.value;
53066
+ }
53067
+ function href(el) {
53068
+ return el.attributes.find((a) => a.local === "href" && (a.ns === null || a.ns === XLINK_NS))?.value ?? void 0;
53069
+ }
53070
+ function parseStyleAttribute(value) {
53071
+ const out = [];
53072
+ for (const decl of value.split(";")) {
53073
+ const colon = decl.indexOf(":");
53074
+ if (colon < 0) continue;
53075
+ const name = decl.slice(0, colon).trim().toLowerCase();
53076
+ const val = decl.slice(colon + 1).replace(/!important\s*$/i, "").trim();
53077
+ if (name) out.push([name, val]);
53078
+ }
53079
+ return out;
53080
+ }
53081
+ function hasText(el) {
53082
+ return el.text.trim().length > 0 || el.children.some(hasText);
53083
+ }
53084
+ var ACTIVE_SCHEME = /^\s*(?:javascript|vbscript|data)\s*:/i;
53085
+ function assertInert(el, location) {
53086
+ if (UNSAFE_ELEMENTS.has(el.local))
53087
+ throw new SvgError(
53088
+ "svg_unsafe",
53089
+ `<${el.local}> is not allowed (scripts, styles, animation and embedded content are refused)`,
53090
+ location
53091
+ );
53092
+ for (const a of el.attributes) {
53093
+ if (/^on/i.test(a.local))
53094
+ throw new SvgError(
53095
+ "svg_unsafe",
53096
+ `Event handler attribute ${a.name} is not allowed`,
53097
+ location
53098
+ );
53099
+ const value = a.value;
53100
+ if (a.local === "href" && (a.ns === null || a.ns === XLINK_NS)) {
53101
+ const target = value.trim();
53102
+ if (el.local === "a") {
53103
+ if (ACTIVE_SCHEME.test(target))
53104
+ throw new SvgError("svg_unsafe", "Link uses an active URL scheme", location);
53105
+ } else if (el.local === "image" && /^data:image\/(?:png|jpeg|gif|webp);/i.test(target)) {
53106
+ } else if (!target.startsWith("#")) {
53107
+ throw new SvgError(
53108
+ "svg_unsafe",
53109
+ `External reference ${target.slice(0, 80)} is not allowed`,
53110
+ location
53111
+ );
53112
+ }
53113
+ }
53114
+ for (const m of value.matchAll(/url\(\s*['"]?([^'")]*)/gi))
53115
+ if (!m[1].trim().startsWith("#"))
53116
+ throw new SvgError("svg_unsafe", "url() references must be local (#id)", location);
53117
+ if (a.local === "style" && /@import|expression\s*\(|javascript\s*:/i.test(value))
53118
+ throw new SvgError("svg_unsafe", "Active content in a style attribute", location);
53119
+ }
53120
+ const counts = /* @__PURE__ */ new Map();
53121
+ for (const child of el.children) {
53122
+ const n = (counts.get(child.local) ?? 0) + 1;
53123
+ counts.set(child.local, n);
53124
+ assertInert(child, `${location}/${child.local}[${n}]`);
53125
+ }
53126
+ }
53127
+ var INITIAL_STYLE = {
53128
+ fill: { kind: "color", rgba: [0, 0, 0, 1] },
53129
+ stroke: { kind: "none" },
53130
+ color: [0, 0, 0, 1],
53131
+ fillOpacity: 1,
53132
+ strokeOpacity: 1,
53133
+ strokeWidth: 1,
53134
+ linecap: "butt",
53135
+ linejoin: "miter",
53136
+ dasharray: null,
53137
+ dashoffset: 0,
53138
+ evenOdd: false,
53139
+ visible: true
53140
+ };
53141
+ var Analyzer = class {
53142
+ constructor(root) {
53143
+ this.root = root;
53144
+ const index = (el) => {
53145
+ this.sourceElements++;
53146
+ const id2 = attr(el, "id");
53147
+ if (id2 !== void 0) this.ids.set(id2, [...this.ids.get(id2) ?? [], el]);
53148
+ el.children.forEach(index);
53149
+ };
53150
+ index(root);
53151
+ }
53152
+ root;
53153
+ issues = [];
53154
+ issueKeys = /* @__PURE__ */ new Set();
53155
+ issuesTruncated = false;
53156
+ strokes = [];
53157
+ points = 0;
53158
+ layers = 0;
53159
+ sourceElements = 0;
53160
+ expandedElements = 0;
53161
+ referenceExpansions = 0;
53162
+ pathSegments = 0;
53163
+ geometryWork = 0;
53164
+ dashWork = 0;
53165
+ scanWork = 0;
53166
+ ids = /* @__PURE__ */ new Map();
53167
+ issue(code, loss, location, message) {
53168
+ const loc = location.length > SVG_LIMITS.maxLocationLength ? "\u2026" + location.slice(-(SVG_LIMITS.maxLocationLength - 1)) : location;
53169
+ const key = `${code}\0${loc}`;
53170
+ if (this.issueKeys.has(key)) return;
53171
+ this.issueKeys.add(key);
53172
+ if (this.issues.length >= SVG_LIMITS.maxIssues) {
53173
+ this.issuesTruncated = true;
53174
+ if (loss && !this.issues.some((i) => i.loss === loss))
53175
+ this.issues.push({ code, loss, location: loc, message });
53176
+ return;
53177
+ }
53178
+ this.issues.push({ code, loss, location: loc, message });
53179
+ }
53180
+ charge(kind, n) {
53181
+ const max = kind === "geometryWork" ? SVG_LIMITS.maxGeometryWork : kind === "dashWork" ? SVG_LIMITS.maxDashWork : SVG_LIMITS.maxScanWork;
53182
+ if (this[kind] + n > max)
53183
+ throw new SvgError("svg_complexity_limit", `The ${kind} budget of ${max} was exceeded`);
53184
+ this[kind] += n;
53185
+ }
53186
+ /** Apply presentation attributes, then the style attribute, onto an inherited style. */
53187
+ resolveStyle(el, inherited, ctx) {
53188
+ const style = { ...inherited };
53189
+ let opacity = 1;
53190
+ let display = true;
53191
+ const declarations = [];
53192
+ for (const a of el.attributes)
53193
+ if (a.ns === null && (STYLE_PROPERTIES.has(a.local) || DROPPED_MODIFIERS.has(a.local) || a.local === "mix-blend-mode" || a.local === "paint-order"))
53194
+ declarations.push([a.local, a.value.trim()]);
53195
+ const styleAttr = attr(el, "style");
53196
+ if (styleAttr) declarations.push(...parseStyleAttribute(styleAttr));
53197
+ const diag = Math.hypot(ctx.viewport[0], ctx.viewport[1]) / Math.SQRT2;
53198
+ for (const [name, value] of declarations) {
53199
+ if (value === "inherit") continue;
53200
+ const invalid2 = () => this.issue(
53201
+ "invalid_value",
53202
+ null,
53203
+ ctx.location,
53204
+ `Ignored invalid ${name} value "${value.slice(0, 40)}"`
53205
+ );
53206
+ switch (name) {
53207
+ case "fill":
53208
+ case "stroke": {
53209
+ const paint = parsePaint(value);
53210
+ if (paint.kind === "invalid") invalid2();
53211
+ else if (name === "fill") style.fill = paint;
53212
+ else style.stroke = paint;
53213
+ break;
53214
+ }
53215
+ case "color": {
53216
+ const c = parseColor(value);
53217
+ if (c) style.color = c;
53218
+ else invalid2();
53219
+ break;
53220
+ }
53221
+ case "stroke-width": {
53222
+ const w = parseLength(value, diag);
53223
+ if (w === null || w < 0) invalid2();
53224
+ else style.strokeWidth = w;
53225
+ break;
53226
+ }
53227
+ case "opacity":
53228
+ case "fill-opacity":
53229
+ case "stroke-opacity": {
53230
+ const o = parseOpacity(value);
53231
+ if (o === null) invalid2();
53232
+ else if (name === "opacity") opacity = o;
53233
+ else if (name === "fill-opacity") style.fillOpacity = o;
53234
+ else style.strokeOpacity = o;
53235
+ break;
53236
+ }
53237
+ case "fill-rule":
53238
+ if (value === "evenodd" || value === "nonzero") style.evenOdd = value === "evenodd";
53239
+ else invalid2();
53240
+ break;
53241
+ case "visibility":
53242
+ style.visible = value === "visible";
53243
+ break;
53244
+ case "display":
53245
+ if (value === "none") display = false;
53246
+ break;
53247
+ case "stroke-linecap":
53248
+ style.linecap = value;
53249
+ break;
53250
+ case "stroke-linejoin":
53251
+ style.linejoin = value;
53252
+ break;
53253
+ case "stroke-dasharray": {
53254
+ if (value === "none") {
53255
+ style.dasharray = null;
53256
+ break;
53257
+ }
53258
+ const list = parseNumberList(value);
53259
+ if (!list || list.some((v) => v < 0)) invalid2();
53260
+ else
53261
+ style.dasharray = list.reduce((s, v) => s + v, 0) > 0 ? list.length % 2 ? [...list, ...list] : list : null;
53262
+ break;
53263
+ }
53264
+ case "stroke-dashoffset": {
53265
+ const o = parseLength(value, diag);
53266
+ if (o === null) invalid2();
53267
+ else style.dashoffset = o;
53268
+ break;
53269
+ }
53270
+ case "stroke-miterlimit":
53271
+ case "vector-effect":
53272
+ case "overflow":
53273
+ break;
53274
+ case "mix-blend-mode":
53275
+ if (value !== "normal")
53276
+ this.issue(
53277
+ "blend_mode_ignored",
53278
+ "paint-approximation",
53279
+ ctx.location,
53280
+ `mix-blend-mode ${value.slice(0, 20)} is drawn as normal`
53281
+ );
53282
+ break;
53283
+ case "paint-order":
53284
+ if (value !== "normal" && !/^fill(\s+stroke)?(\s+markers)?$/.test(value))
53285
+ this.issue(
53286
+ "paint_order_ignored",
53287
+ "paint-approximation",
53288
+ ctx.location,
53289
+ "paint-order is drawn as fill then stroke"
53290
+ );
53291
+ break;
53292
+ default:
53293
+ if (DROPPED_MODIFIERS.has(name)) {
53294
+ if (value !== "none")
53295
+ this.issue(
53296
+ "modifier_dropped",
53297
+ "drop-content",
53298
+ ctx.location,
53299
+ `${name} is not supported and its effect is dropped`
53300
+ );
53301
+ } else if (!IGNORED_PROPERTY.test(name)) {
53302
+ this.issue(
53303
+ "ignored_property",
53304
+ null,
53305
+ ctx.location,
53306
+ `Ignored style property ${name.slice(0, 40)}`
53307
+ );
53308
+ }
53309
+ }
53310
+ }
53311
+ return { style, opacity, display };
53312
+ }
53313
+ propertyValue(el, name) {
53314
+ const styleAttr = attr(el, "style");
53315
+ const fromStyle = styleAttr ? parseStyleAttribute(styleAttr).filter(([n]) => n === name).pop() : void 0;
53316
+ return fromStyle ? fromStyle[1] : attr(el, name);
53317
+ }
53318
+ run() {
53319
+ const root = this.root;
53320
+ if (root.local !== "svg" || root.ns !== null && root.ns !== SVG_NS)
53321
+ throw new SvgError("svg_invalid", "The root element is not <svg>");
53322
+ assertInert(root, "svg");
53323
+ const viewBox = parseViewBox(attr(root, "viewBox"));
53324
+ if (attr(root, "viewBox") !== void 0 && !viewBox)
53325
+ this.issue("invalid_value", null, "svg", "Ignored an invalid viewBox");
53326
+ let width = parseLength(attr(root, "width"), viewBox ? viewBox[2] : 300);
53327
+ let height = parseLength(attr(root, "height"), viewBox ? viewBox[3] : 150);
53328
+ if (width === null || width <= 0) width = viewBox ? viewBox[2] : 300;
53329
+ if (height === null || height <= 0) height = viewBox ? viewBox[3] : 150;
53330
+ if (!viewBox && (attr(root, "width") === void 0 || attr(root, "height") === void 0))
53331
+ this.issue(
53332
+ "viewport_assumed",
53333
+ null,
53334
+ "svg",
53335
+ `No viewBox or size; assumed a ${width}x${height} viewport`
53336
+ );
53337
+ if (width > SVG_LIMITS.maxCoordinate || height > SVG_LIMITS.maxCoordinate)
53338
+ throw new SvgError("svg_complexity_limit", "The viewport is too large");
53339
+ const matrix = viewBox ? viewBoxMatrix(viewBox, width, height, attr(root, "preserveAspectRatio")) : IDENTITY;
53340
+ const ctx = {
53341
+ matrix,
53342
+ style: INITIAL_STYLE,
53343
+ opacity: 1,
53344
+ clip: { x0: 0, y0: 0, x1: width, y1: height },
53345
+ viewport: viewBox ? [viewBox[2], viewBox[3]] : [width, height],
53346
+ location: "svg",
53347
+ refDepth: 0,
53348
+ depth: 0,
53349
+ refStack: []
53350
+ };
53351
+ const { style, opacity, display } = this.resolveStyle(root, INITIAL_STYLE, ctx);
53352
+ if (display) {
53353
+ const layersBefore = this.layers;
53354
+ this.container(root, { ...ctx, style, opacity });
53355
+ if (opacity < 1 && this.layers - layersBefore > 1)
53356
+ this.issue(
53357
+ "group_opacity",
53358
+ "paint-approximation",
53359
+ "svg",
53360
+ "Group opacity is applied to each stroke separately"
53361
+ );
53362
+ }
53363
+ return { width: round(width, 3), height: round(height, 3) };
53364
+ }
53365
+ expand() {
53366
+ this.expandedElements++;
53367
+ if (this.expandedElements > SVG_LIMITS.maxExpandedElements)
53368
+ throw new SvgError(
53369
+ "svg_complexity_limit",
53370
+ `More than ${SVG_LIMITS.maxExpandedElements} elements after expanding references`
53371
+ );
53372
+ }
53373
+ /** Walk an element's children with its own style and transform applied. */
53374
+ container(el, ctx) {
53375
+ const counts = /* @__PURE__ */ new Map();
53376
+ for (const child of el.children) {
53377
+ const n = (counts.get(child.local) ?? 0) + 1;
53378
+ counts.set(child.local, n);
53379
+ const id2 = attr(child, "id");
53380
+ this.element(child, {
53381
+ ...ctx,
53382
+ depth: ctx.depth + 1,
53383
+ location: `${ctx.location}/${child.local}[${n}]${id2 ? `#${id2}` : ""}`
53384
+ });
53385
+ }
53386
+ }
53387
+ element(el, parent) {
53388
+ this.expand();
53389
+ if (parent.depth > SVG_LIMITS.maxDepth)
53390
+ throw new SvgError(
53391
+ "svg_complexity_limit",
53392
+ `Elements nest deeper than ${SVG_LIMITS.maxDepth}`
53393
+ );
53394
+ if (el.ns !== null && el.ns !== SVG_NS) return;
53395
+ const name = el.local;
53396
+ if (NON_RENDERING.has(name)) return;
53397
+ const { style, opacity, display } = this.resolveStyle(el, parent.style, parent);
53398
+ if (!display) return;
53399
+ let matrix = parent.matrix;
53400
+ const transform2 = attr(el, "transform");
53401
+ if (transform2 !== void 0) {
53402
+ const t = parseTransform(transform2);
53403
+ if (!t) {
53404
+ this.issue(
53405
+ "invalid_transform",
53406
+ "drop-content",
53407
+ parent.location,
53408
+ "An element with an invalid transform is not drawn"
53409
+ );
53410
+ return;
53411
+ }
53412
+ matrix = multiply(matrix, t);
53413
+ }
53414
+ const ctx = { ...parent, matrix, style, opacity: parent.opacity * opacity };
53415
+ const layersBefore = this.layers;
53416
+ if (name === "g" || name === "a") this.container(el, ctx);
53417
+ else if (name === "svg") this.nestedViewport(el, ctx, el, void 0);
53418
+ else if (name === "use") this.use(el, ctx);
53419
+ else if (GEOMETRY.has(name)) this.shape(el, ctx);
53420
+ else if (TEXT.has(name)) {
53421
+ if (hasText(el))
53422
+ this.issue(
53423
+ "text_dropped",
53424
+ "drop-content",
53425
+ ctx.location,
53426
+ "Text is not converted to strokes"
53427
+ );
53428
+ } else if (name === "image")
53429
+ this.issue(
53430
+ "image_dropped",
53431
+ "drop-content",
53432
+ ctx.location,
53433
+ "Embedded images are not converted to strokes"
53434
+ );
53435
+ else if (name === "switch")
53436
+ this.issue(
53437
+ "switch_dropped",
53438
+ "drop-content",
53439
+ ctx.location,
53440
+ "Conditional <switch> content is not evaluated"
53441
+ );
53442
+ else
53443
+ this.issue(
53444
+ "unsupported_element",
53445
+ "drop-content",
53446
+ ctx.location,
53447
+ `<${name.slice(0, 40)}> is not supported`
53448
+ );
53449
+ if (opacity < 1 && this.layers - layersBefore > 1)
53450
+ this.issue(
53451
+ "group_opacity",
53452
+ "paint-approximation",
53453
+ ctx.location,
53454
+ "Group opacity is applied to each stroke separately"
53455
+ );
53456
+ }
53457
+ /** A nested <svg> or a <use>d <symbol>: a new viewport with its own viewBox. */
53458
+ nestedViewport(el, ctx, sizeFrom, useEl) {
53459
+ const [pw, ph] = ctx.viewport;
53460
+ const x = useEl ? 0 : parseLength(attr(el, "x"), pw) ?? 0;
53461
+ const y = useEl ? 0 : parseLength(attr(el, "y"), ph) ?? 0;
53462
+ const viewBox = parseViewBox(attr(el, "viewBox"));
53463
+ const w = parseLength(attr(sizeFrom, "width") ?? attr(el, "width"), pw) ?? (useEl && viewBox ? viewBox[2] : pw);
53464
+ const h = parseLength(attr(sizeFrom, "height") ?? attr(el, "height"), ph) ?? (useEl && viewBox ? viewBox[3] : ph);
53465
+ if (w <= 0 || h <= 0) return;
53466
+ let matrix = multiply(ctx.matrix, [1, 0, 0, 1, x, y]);
53467
+ let clip = ctx.clip;
53468
+ const overflow = this.propertyValue(el, "overflow");
53469
+ if (overflow !== "visible" && overflow !== "auto") {
53470
+ const [a, b, c, d, e, f] = matrix;
53471
+ if (b === 0 && c === 0) {
53472
+ const xs = [e, a * w + e].sort((p, q) => p - q);
53473
+ const ys = [f, d * h + f].sort((p, q) => p - q);
53474
+ const r = { x0: xs[0], y0: ys[0], x1: xs[1], y1: ys[1] };
53475
+ clip = clip ? {
53476
+ x0: Math.max(clip.x0, r.x0),
53477
+ y0: Math.max(clip.y0, r.y0),
53478
+ x1: Math.min(clip.x1, r.x1),
53479
+ y1: Math.min(clip.y1, r.y1)
53480
+ } : r;
53481
+ } else {
53482
+ this.issue(
53483
+ "viewport_clip_skipped",
53484
+ "geometry-approximation",
53485
+ ctx.location,
53486
+ "A rotated or skewed nested viewport is not clipped"
53487
+ );
53488
+ }
53489
+ }
53490
+ if (viewBox)
53491
+ matrix = multiply(matrix, viewBoxMatrix(viewBox, w, h, attr(el, "preserveAspectRatio")));
53492
+ this.container(el, {
53493
+ ...ctx,
53494
+ matrix,
53495
+ clip,
53496
+ viewport: viewBox ? [viewBox[2], viewBox[3]] : [w, h]
53497
+ });
53498
+ }
53499
+ use(el, ctx) {
53500
+ const ref = href(el);
53501
+ if (!ref) return;
53502
+ const id2 = ref.trim().slice(1);
53503
+ const targets = this.ids.get(id2) ?? [];
53504
+ if (targets.length === 0) {
53505
+ this.issue(
53506
+ "reference_missing",
53507
+ null,
53508
+ ctx.location,
53509
+ `#${id2.slice(0, 60)} does not exist; nothing is drawn`
53510
+ );
53511
+ return;
53512
+ }
53513
+ if (targets.length > 1)
53514
+ throw new SvgError(
53515
+ "svg_reference_invalid",
53516
+ `More than one element has id ${id2.slice(0, 60)}`,
53517
+ ctx.location
53518
+ );
53519
+ if (ctx.refStack.includes(id2))
53520
+ throw new SvgError(
53521
+ "svg_reference_invalid",
53522
+ `Reference cycle through #${id2.slice(0, 60)}`,
53523
+ ctx.location
53524
+ );
53525
+ if (ctx.refDepth + 1 > SVG_LIMITS.maxReferenceDepth)
53526
+ throw new SvgError(
53527
+ "svg_complexity_limit",
53528
+ `References nest deeper than ${SVG_LIMITS.maxReferenceDepth}`
53529
+ );
53530
+ this.referenceExpansions++;
53531
+ if (this.referenceExpansions > SVG_LIMITS.maxReferenceExpansions)
53532
+ throw new SvgError(
53533
+ "svg_complexity_limit",
53534
+ `More than ${SVG_LIMITS.maxReferenceExpansions} reference expansions`
53535
+ );
53536
+ const target = targets[0];
53537
+ const [pw, ph] = ctx.viewport;
53538
+ const x = parseLength(attr(el, "x"), pw) ?? 0;
53539
+ const y = parseLength(attr(el, "y"), ph) ?? 0;
53540
+ const inner = {
53541
+ ...ctx,
53542
+ matrix: multiply(ctx.matrix, [1, 0, 0, 1, x, y]),
53543
+ location: `${ctx.location}>#${id2}`,
53544
+ refDepth: ctx.refDepth + 1,
53545
+ refStack: [...ctx.refStack, id2]
53546
+ };
53547
+ if (target.ns !== null && target.ns !== SVG_NS) return;
53548
+ if (target.local === "symbol" || target.local === "svg") {
53549
+ this.expand();
53550
+ const { style, opacity, display } = this.resolveStyle(target, inner.style, inner);
53551
+ if (!display) return;
53552
+ const layersBefore = this.layers;
53553
+ const symbolCtx = { ...inner, style, opacity: inner.opacity * opacity };
53554
+ this.nestedViewport(target, symbolCtx, el, el);
53555
+ if (opacity < 1 && this.layers - layersBefore > 1)
53556
+ this.issue(
53557
+ "group_opacity",
53558
+ "paint-approximation",
53559
+ inner.location,
53560
+ "Group opacity is applied to each stroke separately"
53561
+ );
53562
+ } else {
53563
+ this.element(target, inner);
53564
+ }
53565
+ }
53566
+ subpathsFor(el, ctx) {
53567
+ const [pw, ph] = ctx.viewport;
53568
+ const diag = Math.hypot(pw, ph) / Math.SQRT2;
53569
+ const len = (name, of) => parseLength(attr(el, name), of);
53570
+ const bad = (what) => {
53571
+ this.issue("invalid_geometry", null, ctx.location, `${what}; the element is not drawn`);
53572
+ return null;
53573
+ };
53574
+ switch (el.local) {
53575
+ case "path": {
53576
+ const d = attr(el, "d");
53577
+ if (d === void 0 || !d.trim()) return null;
53578
+ const parsed = parsePathData(d);
53579
+ const segs = parsed.subpaths.reduce((s, p) => s + p.segments.length, 0);
53580
+ this.pathSegments += segs;
53581
+ if (this.pathSegments > SVG_LIMITS.maxPathSegments)
53582
+ throw new SvgError(
53583
+ "svg_complexity_limit",
53584
+ `More than ${SVG_LIMITS.maxPathSegments} path segments`
53585
+ );
53586
+ if (parsed.error)
53587
+ this.issue(
53588
+ "path_data_error",
53589
+ "drop-content",
53590
+ ctx.location,
53591
+ "Path data has an error; the part after it is dropped"
53592
+ );
53593
+ return { subpaths: parsed.subpaths, fillable: true };
53594
+ }
53595
+ case "rect": {
53596
+ const x = len("x", pw) ?? 0;
53597
+ const y = len("y", ph) ?? 0;
53598
+ const w = len("width", pw) ?? 0;
53599
+ const h = len("height", ph) ?? 0;
53600
+ if (w < 0 || h < 0) return bad("Negative rectangle size");
53601
+ if (w === 0 || h === 0) return null;
53602
+ let rx = len("rx", pw);
53603
+ let ry = len("ry", ph);
53604
+ if (rx !== null && rx < 0) rx = null;
53605
+ if (ry !== null && ry < 0) ry = null;
53606
+ rx = Math.min(rx ?? ry ?? 0, w / 2);
53607
+ ry = Math.min(ry ?? rx, h / 2);
53608
+ return {
53609
+ subpaths: [rectSubpath(x, y, w, h, rx, ry)],
53610
+ fillable: true
53611
+ };
53612
+ }
53613
+ case "circle":
53614
+ case "ellipse": {
53615
+ const cx = len("cx", pw) ?? 0;
53616
+ const cy = len("cy", ph) ?? 0;
53617
+ let rx;
53618
+ let ry;
53619
+ if (el.local === "circle") rx = ry = len("r", diag) ?? 0;
53620
+ else {
53621
+ rx = len("rx", pw);
53622
+ ry = len("ry", ph);
53623
+ rx = rx ?? ry ?? 0;
53624
+ ry = ry ?? rx;
53625
+ }
53626
+ if (rx < 0 || ry < 0) return bad("Negative radius");
53627
+ if (rx === 0 || ry === 0) return null;
53628
+ return { subpaths: [ellipseSubpath(cx, cy, rx, ry)], fillable: true };
53629
+ }
53630
+ case "line": {
53631
+ const p0 = [len("x1", pw) ?? 0, len("y1", ph) ?? 0];
53632
+ const p1 = [len("x2", pw) ?? 0, len("y2", ph) ?? 0];
53633
+ return {
53634
+ subpaths: [{ start: p0, segments: [{ kind: "L", to: p1 }], closed: false }],
53635
+ fillable: false
53636
+ };
53637
+ }
53638
+ default: {
53639
+ const nums = parseNumberList(attr(el, "points") ?? "");
53640
+ if (!nums) return bad("Malformed points list");
53641
+ const pts = [];
53642
+ for (let i = 0; i + 1 < nums.length; i += 2) pts.push([nums[i], nums[i + 1]]);
53643
+ if (nums.length % 2)
53644
+ this.issue(
53645
+ "invalid_geometry",
53646
+ null,
53647
+ ctx.location,
53648
+ "Odd number of coordinates; the last one is ignored"
53649
+ );
53650
+ if (pts.length < 2) return null;
53651
+ return {
53652
+ subpaths: [
53653
+ {
53654
+ start: pts[0],
53655
+ segments: pts.slice(1).map((to) => ({ kind: "L", to })),
53656
+ closed: el.local === "polygon"
53657
+ }
53658
+ ],
53659
+ fillable: true
53660
+ };
53661
+ }
53662
+ }
53663
+ }
53664
+ emit(points, color, width, ctx) {
53665
+ const rounded = [];
53666
+ for (const p of points) {
53667
+ const q = [round(p[0], 3), round(p[1], 3)];
53668
+ const last = rounded[rounded.length - 1];
53669
+ if (!last || last[0] !== q[0] || last[1] !== q[1]) rounded.push(q);
53670
+ }
53671
+ if (!rounded.length) return;
53672
+ if (width > SVG_LIMITS.maxStrokeWidth)
53673
+ throw new SvgError(
53674
+ "svg_complexity_limit",
53675
+ `A stroke is wider than ${SVG_LIMITS.maxStrokeWidth}`,
53676
+ ctx.location
53677
+ );
53678
+ this.strokes.push({
53679
+ ink: "monoline",
53680
+ color: [round(color[0], 4), round(color[1], 4), round(color[2], 4), round(color[3], 4)],
53681
+ width: round(width, 3),
53682
+ points: rounded
53683
+ });
53684
+ this.points += rounded.length;
53685
+ if (this.strokes.length > SVG_LIMITS.maxStrokes)
53686
+ throw new SvgError(
53687
+ "svg_complexity_limit",
53688
+ `More than ${SVG_LIMITS.maxStrokes} output strokes`
53689
+ );
53690
+ if (this.points > SVG_LIMITS.maxPoints)
53691
+ throw new SvgError("svg_complexity_limit", `More than ${SVG_LIMITS.maxPoints} output points`);
53692
+ }
53693
+ clipped(polyline, ctx) {
53694
+ if (!ctx.clip) return [polyline];
53695
+ const { parts, clipped } = clipPolyline(polyline, ctx.clip);
53696
+ if (clipped)
53697
+ this.issue(
53698
+ "viewport_clipped",
53699
+ "geometry-approximation",
53700
+ ctx.location,
53701
+ "Content outside the viewport is clipped"
53702
+ );
53703
+ return parts;
53704
+ }
53705
+ paintColor(paint, style) {
53706
+ if (paint.kind === "color") return paint.rgba;
53707
+ if (paint.kind === "current") return style.color;
53708
+ if (paint.kind === "url") return "url";
53709
+ return null;
53710
+ }
53711
+ shape(el, ctx) {
53712
+ const geometry = this.subpathsFor(el, ctx);
53713
+ if (!geometry || !ctx.style.visible) return;
53714
+ const { style } = ctx;
53715
+ const polylines = geometry.subpaths.filter((s) => s.segments.length > 0).map((s) => {
53716
+ const pts = flattenSubpath(s, ctx.matrix, TOLERANCE);
53717
+ this.charge("geometryWork", pts.length);
53718
+ if (pts.some(
53719
+ (p) => !(Math.abs(p[0]) <= SVG_LIMITS.maxCoordinate && Math.abs(p[1]) <= SVG_LIMITS.maxCoordinate)
53720
+ ))
53721
+ throw new SvgError(
53722
+ "svg_geometry_invalid",
53723
+ "Geometry is not finite or exceeds the coordinate limit",
53724
+ ctx.location
53725
+ );
53726
+ return pts;
53727
+ });
53728
+ if (!polylines.length) return;
53729
+ const fill = this.paintColor(style.fill, style);
53730
+ const stroke = style.strokeWidth > 0 ? this.paintColor(style.stroke, style) : null;
53731
+ if (fill === "url")
53732
+ this.issue(
53733
+ "paint_server_dropped",
53734
+ "drop-content",
53735
+ ctx.location,
53736
+ "Gradient or pattern fill is not supported and is dropped"
53737
+ );
53738
+ if (stroke === "url")
53739
+ this.issue(
53740
+ "paint_server_dropped",
53741
+ "drop-content",
53742
+ ctx.location,
53743
+ "Gradient or pattern stroke is not supported and is dropped"
53744
+ );
53745
+ if (fill && fill !== "url" && geometry.fillable) {
53746
+ const alpha = fill[3] * style.fillOpacity * ctx.opacity;
53747
+ const rings = polylines.filter((p) => p.length >= 3);
53748
+ if (alpha > 0 && rings.length) {
53749
+ const ys = rings.flat().map((p) => p[1]);
53750
+ const h = Math.max(...ys) - Math.min(...ys);
53751
+ const brush = Math.min(MAX_FILL_BRUSH, Math.max(MIN_FILL_BRUSH, h / FILL_SCANLINES));
53752
+ const chains = scanFill(
53753
+ rings,
53754
+ style.evenOdd,
53755
+ brush,
53756
+ brush * 0.8,
53757
+ (n) => this.charge("scanWork", n)
53758
+ );
53759
+ if (chains.length) {
53760
+ this.issue(
53761
+ "fill_as_strokes",
53762
+ "paint-approximation",
53763
+ ctx.location,
53764
+ "Filled area is drawn with overlapping strokes"
53765
+ );
53766
+ this.layers++;
53767
+ for (const chain of chains)
53768
+ for (const part of this.clipped(chain, ctx))
53769
+ this.emit(part, [fill[0], fill[1], fill[2], alpha], brush, ctx);
53770
+ }
53771
+ }
53772
+ }
53773
+ if (stroke && stroke !== "url") {
53774
+ const alpha = stroke[3] * style.strokeOpacity * ctx.opacity;
53775
+ if (alpha > 0) {
53776
+ const nonScaling = this.propertyValue(el, "vector-effect") === "non-scaling-stroke";
53777
+ const [s1, s2] = scales(ctx.matrix);
53778
+ const mean = Math.sqrt(s1 * s2);
53779
+ if (!nonScaling && s2 > 0 && s1 / s2 > 1.001)
53780
+ this.issue(
53781
+ "nonuniform_stroke",
53782
+ "geometry-approximation",
53783
+ ctx.location,
53784
+ "Non-uniformly scaled stroke is drawn with one width"
53785
+ );
53786
+ const width = nonScaling ? style.strokeWidth : style.strokeWidth * mean;
53787
+ if (width > 0) {
53788
+ const openPath = geometry.subpaths.some((s) => s.segments.length > 0 && !s.closed) || style.dasharray;
53789
+ if (style.linecap !== "round" && openPath)
53790
+ this.issue(
53791
+ "cap_approximated",
53792
+ "geometry-approximation",
53793
+ ctx.location,
53794
+ `stroke-linecap ${style.linecap.slice(0, 20)} is drawn round`
53795
+ );
53796
+ if (style.linejoin !== "round" && polylines.some((p) => p.length > 2))
53797
+ this.issue(
53798
+ "join_approximated",
53799
+ "geometry-approximation",
53800
+ ctx.location,
53801
+ `stroke-linejoin ${style.linejoin.slice(0, 20)} is drawn round`
53802
+ );
53803
+ let pieces = polylines;
53804
+ if (style.dasharray) {
53805
+ const k = nonScaling ? 1 : mean;
53806
+ const pattern = style.dasharray.map((v) => v * k);
53807
+ pieces = polylines.flatMap(
53808
+ (p) => dashPolyline(p, pattern, style.dashoffset * k, (n) => this.charge("dashWork", n))
53809
+ );
53810
+ }
53811
+ this.layers++;
53812
+ for (const piece of pieces) {
53813
+ const zeroLength = piece.every((p) => p[0] === piece[0][0] && p[1] === piece[0][1]);
53814
+ if (zeroLength && style.linecap !== "round") continue;
53815
+ for (const part of this.clipped(zeroLength ? [piece[0]] : piece, ctx))
53816
+ this.emit(part, [stroke[0], stroke[1], stroke[2], alpha], width, ctx);
53817
+ }
53818
+ }
53819
+ }
53820
+ }
53821
+ }
53822
+ };
53823
+ function analysisFor(source, analyzer, viewport) {
53824
+ const drawing = {
53825
+ version: 1,
53826
+ width: viewport.width,
53827
+ height: viewport.height,
53828
+ strokes: analyzer.strokes
53829
+ };
53830
+ const drawingJson = canonicalJson(drawing);
53831
+ if (drawingJson.length > SVG_LIMITS.maxDrawingBytes)
53832
+ throw new SvgError(
53833
+ "normalized_drawing_too_large",
53834
+ `The normalized drawing exceeds ${SVG_LIMITS.maxDrawingBytes} bytes`
53835
+ );
53836
+ const importable = drawing.strokes.length > 0;
53837
+ if (!importable)
53838
+ analyzer.issue("empty_drawing", null, "svg", "Nothing drawable remains after conversion");
53839
+ const requiredLosses = SVG_LOSSES.filter((loss) => analyzer.issues.some((i) => i.loss === loss));
53840
+ const classification = !importable || requiredLosses.includes("drop-content") ? "unsupported" : requiredLosses.length ? "lossy" : "safe";
53841
+ const analysis = {
53842
+ analyzer: SVG_ANALYZER_VERSION,
53843
+ source: { sha256: sha256(source), bytes: source.length },
53844
+ classification,
53845
+ importable,
53846
+ defaultWriteAllowed: importable && classification === "safe",
53847
+ requiredLosses,
53848
+ viewport,
53849
+ counts: {
53850
+ sourceElements: analyzer.sourceElements,
53851
+ expandedElements: analyzer.expandedElements,
53852
+ referenceExpansions: analyzer.referenceExpansions,
53853
+ pathSegments: analyzer.pathSegments,
53854
+ strokes: drawing.strokes.length,
53855
+ points: analyzer.points,
53856
+ geometryWork: { used: analyzer.geometryWork, max: SVG_LIMITS.maxGeometryWork },
53857
+ dashWork: { used: analyzer.dashWork, max: SVG_LIMITS.maxDashWork },
53858
+ scanWork: { used: analyzer.scanWork, max: SVG_LIMITS.maxScanWork }
53859
+ },
53860
+ drawingBytes: drawingJson.length,
53861
+ issues: analyzer.issues,
53862
+ issuesTruncated: analyzer.issuesTruncated
53863
+ };
53864
+ const analysisDigest = "sha256:" + sha256(canonicalJson({ analysis, drawing }));
53865
+ return { analysis: { ...analysis, analysisDigest }, drawing };
53866
+ }
53867
+ function analyzeSvgBuffer(source) {
53868
+ if (source.length > SVG_LIMITS.maxSourceBytes)
53869
+ throw new SvgError(
53870
+ "svg_file_invalid",
53871
+ `The SVG is larger than ${SVG_LIMITS.maxSourceBytes} bytes`
53872
+ );
53873
+ let text2;
53874
+ try {
53875
+ text2 = new TextDecoder("utf-8", { fatal: true }).decode(source);
53876
+ } catch {
53877
+ throw new SvgError("svg_file_invalid", "The SVG is not valid UTF-8");
53878
+ }
53879
+ if (text2.charCodeAt(0) === 65279) text2 = text2.slice(1);
53880
+ const root = parseXml(text2, {
53881
+ maxElements: SVG_LIMITS.maxSourceElements,
53882
+ maxDepth: SVG_LIMITS.maxDepth
53883
+ });
53884
+ const analyzer = new Analyzer(root);
53885
+ const viewport = analyzer.run();
53886
+ return analysisFor(source, analyzer, viewport);
53887
+ }
53888
+ function readSvgSource(path10) {
53889
+ let fd;
53890
+ try {
53891
+ fd = openSync6(path10, constants6.O_RDONLY | constants6.O_NOFOLLOW | constants6.O_NONBLOCK);
53892
+ } catch (error2) {
53893
+ if (error2.code === "ELOOP")
53894
+ throw new SvgError("svg_file_invalid", "The SVG path is a symbolic link");
53895
+ throw new SvgError("svg_file_invalid", "The SVG file does not exist or cannot be read");
53896
+ }
53897
+ try {
53898
+ const info = fstatSync6(fd);
53899
+ if (!info.isFile())
53900
+ throw new SvgError("svg_file_invalid", "The SVG path is not a regular file");
53901
+ if (info.size > SVG_LIMITS.maxSourceBytes)
53902
+ throw new SvgError(
53903
+ "svg_file_invalid",
53904
+ `The SVG is larger than ${SVG_LIMITS.maxSourceBytes} bytes`
53905
+ );
53906
+ const buffer = Buffer.alloc(SVG_LIMITS.maxSourceBytes + 1);
53907
+ let total = 0;
53908
+ for (; ; ) {
53909
+ const n = readSync4(fd, buffer, total, buffer.length - total, null);
53910
+ if (n === 0) break;
53911
+ total += n;
53912
+ if (total > SVG_LIMITS.maxSourceBytes)
53913
+ throw new SvgError(
53914
+ "svg_file_invalid",
53915
+ `The SVG is larger than ${SVG_LIMITS.maxSourceBytes} bytes`
53916
+ );
53917
+ }
53918
+ return buffer.subarray(0, total);
53919
+ } finally {
53920
+ closeSync6(fd);
53921
+ }
53922
+ }
53923
+ function analyzeSvgFile(path10) {
53924
+ return analyzeSvgBuffer(readSvgSource(path10));
53925
+ }
53926
+
53927
+ // src/tools/svgAnalysis.ts
53928
+ function runSvgAnalysis(args, roots = allowedSaveRoots()) {
53929
+ let abs;
53930
+ try {
53931
+ abs = assertReadableInRoots(args.path, roots, "SVG file");
53932
+ } catch (error2) {
53933
+ throw new CodedError(error2.message, {
53934
+ code: "validation_error",
53935
+ svgCode: "svg_file_invalid"
53936
+ });
53937
+ }
53938
+ try {
53939
+ const result = analyzeSvgFile(abs);
53940
+ return {
53941
+ ...result.analysis,
53942
+ ...args.includeDrawing ? { drawing: result.drawing } : {}
53943
+ };
53944
+ } catch (error2) {
53945
+ if (error2 instanceof SvgError)
53946
+ throw new CodedError(`SVG refused (${error2.code}): ${error2.message}`, {
53947
+ code: "validation_error",
53948
+ svgCode: error2.code,
53949
+ ...error2.location ? { location: error2.location } : {}
53950
+ });
53951
+ throw error2;
53952
+ }
53953
+ }
53954
+ function registerSvgAnalysis(server2) {
53955
+ const inputSchema = {
53956
+ path: external_exports.string().min(1).max(4096).describe(
53957
+ `Absolute path of one .svg file (home, temp, or /Volumes; not a symbolic link; at most ${SVG_LIMITS.maxSourceBytes} bytes of UTF-8)`
53958
+ ),
53959
+ includeDrawing: external_exports.boolean().optional().describe(
53960
+ "Also return the normalized drawing (strokes with sRGB color, width and points). Off by default: it can be large."
53961
+ )
53962
+ };
53963
+ server2.registerTool(
53964
+ "analyze-svg",
53965
+ {
53966
+ description: "Use when: checking whether an SVG file can be represented as editable monoline strokes, and what that conversion would approximate or drop.\nReturns: classification (safe, lossy, unsupported), importable, defaultWriteAllowed, requiredLosses (geometry-approximation, paint-approximation, drop-content), issues with element locations, counts and work budgets, the source SHA-256, and analysisDigest, a SHA-256 over the canonical analysis and normalized drawing. includeDrawing adds the drawing.\nDo not use when: you want to attach the SVG file itself to a note (add-attachment).\nSafety: read-only and local. Opens no Notes data and makes no network request. Scripts, event handlers, style elements, animation, DOCTYPE/entities and external resources are refused with svgCode svg_unsafe; malformed files with svg_invalid; oversized work with svg_complexity_limit.",
53967
+ inputSchema,
53968
+ outputSchema: external_exports.object({ classification: external_exports.string().optional() }).passthrough(),
53969
+ annotations: { readOnlyHint: true, openWorldHint: false }
53970
+ },
53971
+ (async (args) => {
53972
+ try {
53973
+ const result = runSvgAnalysis(args);
53974
+ return {
53975
+ content: [{ type: "text", text: JSON.stringify(result) }],
53976
+ structuredContent: result
53977
+ };
53978
+ } catch (error2) {
53979
+ return errorResult(error2 instanceof Error ? error2.message : String(error2), error2);
53980
+ }
53981
+ })
53982
+ );
53983
+ }
53984
+
51907
53985
  // src/tools/nativeTagsBridge.ts
51908
53986
  var noteId2 = exactIdInput(
51909
53987
  "ICNote",
@@ -52497,7 +54575,7 @@ function formatShortcutSetup(report) {
52497
54575
 
52498
54576
  // src/services/publicHelper.ts
52499
54577
  import { spawnSync as spawnSync3 } from "node:child_process";
52500
- import { createHash as createHash4 } from "node:crypto";
54578
+ import { createHash as createHash5 } from "node:crypto";
52501
54579
  import {
52502
54580
  chmodSync,
52503
54581
  existsSync as existsSync14,
@@ -52563,7 +54641,7 @@ function publicHelperInstallDir(env = process.env) {
52563
54641
  return join24(homedir19(), "Library", "Application Support", "apple-notes-mcp", "public-helper");
52564
54642
  }
52565
54643
  function sha256Hex(data) {
52566
- return createHash4("sha256").update(data).digest("hex");
54644
+ return createHash5("sha256").update(data).digest("hex");
52567
54645
  }
52568
54646
  function inspectPublicHelper(deps = defaultPublicHelperDeps()) {
52569
54647
  const installDir = publicHelperInstallDir(deps.env);
@@ -53111,7 +55189,7 @@ import { join as join26 } from "node:path";
53111
55189
 
53112
55190
  // src/services/privateHelper.ts
53113
55191
  import { spawnSync as spawnSync4 } from "node:child_process";
53114
- import { createHash as createHash5 } from "node:crypto";
55192
+ import { createHash as createHash6 } from "node:crypto";
53115
55193
  import { existsSync as existsSync15, readFileSync as readFileSync5 } from "node:fs";
53116
55194
  import { homedir as homedir20 } from "node:os";
53117
55195
  import { dirname as dirname9, join as join25, resolve as resolve6 } from "node:path";
@@ -53175,7 +55253,7 @@ function helperInstallDir(env = process.env) {
53175
55253
  return join25(homedir20(), "Library", "Application Support", "apple-notes-mcp", "private-helper");
53176
55254
  }
53177
55255
  function sha256Hex2(data) {
53178
- return createHash5("sha256").update(data).digest("hex");
55256
+ return createHash6("sha256").update(data).digest("hex");
53179
55257
  }
53180
55258
  function inspectInstallation(deps = defaultDeps2()) {
53181
55259
  const installDir = helperInstallDir(deps.env);
@@ -53760,6 +55838,7 @@ var server = new McpServer({
53760
55838
  var notesManager = new AppleNotesManager();
53761
55839
  registerDirectOperations(server, notesManager);
53762
55840
  registerFolderDelete(server, notesManager);
55841
+ registerSvgAnalysis(server);
53763
55842
  registerNativeTagsBridge(server, notesManager);
53764
55843
  registerNativeOperations(server, notesManager);
53765
55844
  registerPrivateHelperTools(server, notesManager);