@semigarden/synthetic-md 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -4811,12 +4811,12 @@ var Focus = class {
4811
4811
  if (!blockElement) return;
4812
4812
  blockElement.classList.add("focused");
4813
4813
  const markerElements = blockElement.querySelectorAll(".marker");
4814
- for (const markerElement of markerElements) {
4814
+ for (const markerElement of Array.from(markerElements)) {
4815
4815
  markerElement.classList.add("focused");
4816
4816
  }
4817
4817
  if (blockElement.classList.contains("codeBlock")) {
4818
4818
  const inlineElements = blockElement.querySelectorAll(".inline");
4819
- for (const inlineElement of inlineElements) {
4819
+ for (const inlineElement of Array.from(inlineElements)) {
4820
4820
  inlineElement.classList.add("focused");
4821
4821
  }
4822
4822
  }
@@ -4833,12 +4833,12 @@ var Focus = class {
4833
4833
  if (!blockElement) return;
4834
4834
  blockElement.classList.remove("focused");
4835
4835
  const markerElements = blockElement.querySelectorAll(".marker");
4836
- for (const markerElement of markerElements) {
4836
+ for (const markerElement of Array.from(markerElements)) {
4837
4837
  markerElement.classList.remove("focused");
4838
4838
  }
4839
4839
  if (blockElement.classList.contains("codeBlock")) {
4840
4840
  const inlineElements = blockElement.querySelectorAll(".inline");
4841
- for (const inlineElement of inlineElements) {
4841
+ for (const inlineElement of Array.from(inlineElements)) {
4842
4842
  inlineElement.classList.remove("focused");
4843
4843
  }
4844
4844
  }
@@ -4863,6 +4863,30 @@ var Focus = class {
4863
4863
  if (!inlineElement) return;
4864
4864
  inlineElement.classList.remove("focused");
4865
4865
  }
4866
+ autoFocus() {
4867
+ const firstBlock = this.rootElement.querySelector(".block");
4868
+ if (!firstBlock) {
4869
+ this.rootElement.focus();
4870
+ return;
4871
+ }
4872
+ const inlineEl = firstBlock.querySelector("[data-inline-id]");
4873
+ if (!inlineEl) {
4874
+ this.rootElement.focus();
4875
+ return;
4876
+ }
4877
+ const target = inlineEl.querySelector(".symbolic") ?? inlineEl;
4878
+ if (target.childNodes.length === 0) {
4879
+ target.appendChild(document.createTextNode("\u200B"));
4880
+ }
4881
+ this.rootElement.focus();
4882
+ const selection = target.ownerDocument.getSelection();
4883
+ if (!selection) return;
4884
+ const range = target.ownerDocument.createRange();
4885
+ range.selectNodeContents(target);
4886
+ range.collapse(true);
4887
+ selection.removeAllRanges();
4888
+ selection.addRange(range);
4889
+ }
4866
4890
  };
4867
4891
  var focus_default = Focus;
4868
4892
 
@@ -5096,6 +5120,9 @@ var Select = class {
5096
5120
  this.rootElement.removeEventListener("focusin", this.onRootFocusIn);
5097
5121
  this.rootElement.removeEventListener("focusout", this.onRootFocusOut);
5098
5122
  }
5123
+ autoFocus() {
5124
+ this.focus.autoFocus();
5125
+ }
5099
5126
  resolveInlineContext() {
5100
5127
  return resolveInlineContext(this.ast, this.caret, this.rootElement);
5101
5128
  }
@@ -5650,6 +5677,7 @@ function renderInline(inline) {
5650
5677
  inlineElement.href = inline.url.replace(/[\u200B\u200C\u200D\uFEFF]/g, "") || "";
5651
5678
  inlineElement.title = inline.title ? `${inline.title}
5652
5679
  Ctrl + Click to follow link` : "Ctrl + Click to follow link";
5680
+ inlineElement.classList.add("link");
5653
5681
  }
5654
5682
  if (inline.type === "autolink") {
5655
5683
  ;
@@ -6459,9 +6487,13 @@ var cssText = `@charset "UTF-8";
6459
6487
  --color-text: #d4cfee;
6460
6488
  --color-muted: #8b85a3;
6461
6489
  --color-accent: #4a9eff;
6490
+ --color-accent-hover: #74b5ff;
6462
6491
  --color-code-bg: #1a1625;
6463
6492
  --color-blockquote-border: #4a9eff;
6464
6493
  --color-selection-bg: #2a2340;
6494
+ --color-divider: rgba(255,255,255,0.18);
6495
+ --color-caret: #ffffff;
6496
+ --color-focus-bg: rgba(74,158,255,0.12);
6465
6497
  position: relative;
6466
6498
  width: 100%;
6467
6499
  height: 100%;
@@ -6737,14 +6769,19 @@ var cssText = `@charset "UTF-8";
6737
6769
  }
6738
6770
 
6739
6771
  .link, .autolink {
6772
+ color: var(--color-accent);
6773
+ text-decoration: inherit;
6740
6774
  cursor: pointer;
6741
6775
  }
6776
+ .link:hover, .autolink:hover {
6777
+ color: var(--color-accent-hover);
6778
+ }
6742
6779
 
6743
6780
  .caret {
6744
6781
  position: absolute;
6745
6782
  width: 1px;
6746
6783
  height: 1em;
6747
- background-color: #fff;
6784
+ background-color: var(--color-caret);
6748
6785
  animation: blink 1s step-end infinite;
6749
6786
  pointer-events: none;
6750
6787
  z-index: 10;
@@ -6756,7 +6793,7 @@ var cssText = `@charset "UTF-8";
6756
6793
  word-break: break-word;
6757
6794
  }
6758
6795
  .inline.focus {
6759
- background: rgba(0, 120, 255, 0.1);
6796
+ background: var(--color-focus-bg);
6760
6797
  border-radius: 3px;
6761
6798
  padding: 0 2px;
6762
6799
  min-height: 1.2em;
@@ -6834,10 +6871,12 @@ var Element = class extends HTMLElement {
6834
6871
  this.intent = null;
6835
6872
  this.styled = false;
6836
6873
  this.hasAcceptedExternalValue = false;
6874
+ this.autofocus = false;
6837
6875
  this.shadowRootElement = this.attachShadow({ mode: "open" });
6838
6876
  }
6839
6877
  connectedCallback() {
6840
6878
  const attrValue = this.getAttribute("value") ?? "";
6879
+ this.autofocus = this.hasAttribute("autofocus");
6841
6880
  this.ast.setText(attrValue);
6842
6881
  this.addStyles();
6843
6882
  this.addDOM();
@@ -6851,6 +6890,7 @@ var Element = class extends HTMLElement {
6851
6890
  this.interaction = new interaction_default(this.rootElement, this.select, this.editor, this.input, this.intent);
6852
6891
  this.interaction.attach();
6853
6892
  this.renderDOM();
6893
+ this.autoFocus();
6854
6894
  }
6855
6895
  disconnectedCallback() {
6856
6896
  this.interaction?.detach();
@@ -6862,6 +6902,7 @@ var Element = class extends HTMLElement {
6862
6902
  if (!this.hasAcceptedExternalValue && value !== "" || value !== "" && value !== this.ast.text) {
6863
6903
  this.ast.setText(value);
6864
6904
  this.renderDOM();
6905
+ this.autoFocus();
6865
6906
  this.hasAcceptedExternalValue = true;
6866
6907
  }
6867
6908
  }
@@ -6894,6 +6935,9 @@ var Element = class extends HTMLElement {
6894
6935
  composed: true
6895
6936
  }));
6896
6937
  }
6938
+ autoFocus() {
6939
+ if (this.autofocus && this.rootElement && this.select) this.select.autoFocus();
6940
+ }
6897
6941
  };
6898
6942
  var element_default = Element;
6899
6943
 
package/dist/index.css CHANGED
@@ -11,9 +11,13 @@
11
11
  --color-text: #d4cfee;
12
12
  --color-muted: #8b85a3;
13
13
  --color-accent: #4a9eff;
14
+ --color-accent-hover: #74b5ff;
14
15
  --color-code-bg: #1a1625;
15
16
  --color-blockquote-border: #4a9eff;
16
17
  --color-selection-bg: #2a2340;
18
+ --color-divider: rgba(255,255,255,0.18);
19
+ --color-caret: #ffffff;
20
+ --color-focus-bg: rgba(74,158,255,0.12);
17
21
  position: relative;
18
22
  width: 100%;
19
23
  height: 100%;
@@ -289,14 +293,19 @@
289
293
  }
290
294
 
291
295
  .link, .autolink {
296
+ color: var(--color-accent);
297
+ text-decoration: inherit;
292
298
  cursor: pointer;
293
299
  }
300
+ .link:hover, .autolink:hover {
301
+ color: var(--color-accent-hover);
302
+ }
294
303
 
295
304
  .caret {
296
305
  position: absolute;
297
306
  width: 1px;
298
307
  height: 1em;
299
- background-color: #fff;
308
+ background-color: var(--color-caret);
300
309
  animation: blink 1s step-end infinite;
301
310
  pointer-events: none;
302
311
  z-index: 10;
@@ -308,7 +317,7 @@
308
317
  word-break: break-word;
309
318
  }
310
319
  .inline.focus {
311
- background: rgba(0, 120, 255, 0.1);
320
+ background: var(--color-focus-bg);
312
321
  border-radius: 3px;
313
322
  padding: 0 2px;
314
323
  min-height: 1.2em;
package/dist/index.d.cts CHANGED
@@ -11,6 +11,7 @@ declare class Element extends HTMLElement {
11
11
  private intent;
12
12
  private styled;
13
13
  private hasAcceptedExternalValue;
14
+ autofocus: boolean;
14
15
  constructor();
15
16
  connectedCallback(): void;
16
17
  disconnectedCallback(): void;
@@ -20,6 +21,7 @@ declare class Element extends HTMLElement {
20
21
  private addStyles;
21
22
  private addDOM;
22
23
  private emitChange;
24
+ private autoFocus;
23
25
  }
24
26
 
25
27
  declare function defineElement(): void;
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ declare class Element extends HTMLElement {
11
11
  private intent;
12
12
  private styled;
13
13
  private hasAcceptedExternalValue;
14
+ autofocus: boolean;
14
15
  constructor();
15
16
  connectedCallback(): void;
16
17
  disconnectedCallback(): void;
@@ -20,6 +21,7 @@ declare class Element extends HTMLElement {
20
21
  private addStyles;
21
22
  private addDOM;
22
23
  private emitChange;
24
+ private autoFocus;
23
25
  }
24
26
 
25
27
  declare function defineElement(): void;
package/dist/index.esm.js CHANGED
@@ -4783,12 +4783,12 @@ var Focus = class {
4783
4783
  if (!blockElement) return;
4784
4784
  blockElement.classList.add("focused");
4785
4785
  const markerElements = blockElement.querySelectorAll(".marker");
4786
- for (const markerElement of markerElements) {
4786
+ for (const markerElement of Array.from(markerElements)) {
4787
4787
  markerElement.classList.add("focused");
4788
4788
  }
4789
4789
  if (blockElement.classList.contains("codeBlock")) {
4790
4790
  const inlineElements = blockElement.querySelectorAll(".inline");
4791
- for (const inlineElement of inlineElements) {
4791
+ for (const inlineElement of Array.from(inlineElements)) {
4792
4792
  inlineElement.classList.add("focused");
4793
4793
  }
4794
4794
  }
@@ -4805,12 +4805,12 @@ var Focus = class {
4805
4805
  if (!blockElement) return;
4806
4806
  blockElement.classList.remove("focused");
4807
4807
  const markerElements = blockElement.querySelectorAll(".marker");
4808
- for (const markerElement of markerElements) {
4808
+ for (const markerElement of Array.from(markerElements)) {
4809
4809
  markerElement.classList.remove("focused");
4810
4810
  }
4811
4811
  if (blockElement.classList.contains("codeBlock")) {
4812
4812
  const inlineElements = blockElement.querySelectorAll(".inline");
4813
- for (const inlineElement of inlineElements) {
4813
+ for (const inlineElement of Array.from(inlineElements)) {
4814
4814
  inlineElement.classList.remove("focused");
4815
4815
  }
4816
4816
  }
@@ -4835,6 +4835,30 @@ var Focus = class {
4835
4835
  if (!inlineElement) return;
4836
4836
  inlineElement.classList.remove("focused");
4837
4837
  }
4838
+ autoFocus() {
4839
+ const firstBlock = this.rootElement.querySelector(".block");
4840
+ if (!firstBlock) {
4841
+ this.rootElement.focus();
4842
+ return;
4843
+ }
4844
+ const inlineEl = firstBlock.querySelector("[data-inline-id]");
4845
+ if (!inlineEl) {
4846
+ this.rootElement.focus();
4847
+ return;
4848
+ }
4849
+ const target = inlineEl.querySelector(".symbolic") ?? inlineEl;
4850
+ if (target.childNodes.length === 0) {
4851
+ target.appendChild(document.createTextNode("\u200B"));
4852
+ }
4853
+ this.rootElement.focus();
4854
+ const selection = target.ownerDocument.getSelection();
4855
+ if (!selection) return;
4856
+ const range = target.ownerDocument.createRange();
4857
+ range.selectNodeContents(target);
4858
+ range.collapse(true);
4859
+ selection.removeAllRanges();
4860
+ selection.addRange(range);
4861
+ }
4838
4862
  };
4839
4863
  var focus_default = Focus;
4840
4864
 
@@ -5068,6 +5092,9 @@ var Select = class {
5068
5092
  this.rootElement.removeEventListener("focusin", this.onRootFocusIn);
5069
5093
  this.rootElement.removeEventListener("focusout", this.onRootFocusOut);
5070
5094
  }
5095
+ autoFocus() {
5096
+ this.focus.autoFocus();
5097
+ }
5071
5098
  resolveInlineContext() {
5072
5099
  return resolveInlineContext(this.ast, this.caret, this.rootElement);
5073
5100
  }
@@ -5622,6 +5649,7 @@ function renderInline(inline) {
5622
5649
  inlineElement.href = inline.url.replace(/[\u200B\u200C\u200D\uFEFF]/g, "") || "";
5623
5650
  inlineElement.title = inline.title ? `${inline.title}
5624
5651
  Ctrl + Click to follow link` : "Ctrl + Click to follow link";
5652
+ inlineElement.classList.add("link");
5625
5653
  }
5626
5654
  if (inline.type === "autolink") {
5627
5655
  ;
@@ -6431,9 +6459,13 @@ var cssText = `@charset "UTF-8";
6431
6459
  --color-text: #d4cfee;
6432
6460
  --color-muted: #8b85a3;
6433
6461
  --color-accent: #4a9eff;
6462
+ --color-accent-hover: #74b5ff;
6434
6463
  --color-code-bg: #1a1625;
6435
6464
  --color-blockquote-border: #4a9eff;
6436
6465
  --color-selection-bg: #2a2340;
6466
+ --color-divider: rgba(255,255,255,0.18);
6467
+ --color-caret: #ffffff;
6468
+ --color-focus-bg: rgba(74,158,255,0.12);
6437
6469
  position: relative;
6438
6470
  width: 100%;
6439
6471
  height: 100%;
@@ -6709,14 +6741,19 @@ var cssText = `@charset "UTF-8";
6709
6741
  }
6710
6742
 
6711
6743
  .link, .autolink {
6744
+ color: var(--color-accent);
6745
+ text-decoration: inherit;
6712
6746
  cursor: pointer;
6713
6747
  }
6748
+ .link:hover, .autolink:hover {
6749
+ color: var(--color-accent-hover);
6750
+ }
6714
6751
 
6715
6752
  .caret {
6716
6753
  position: absolute;
6717
6754
  width: 1px;
6718
6755
  height: 1em;
6719
- background-color: #fff;
6756
+ background-color: var(--color-caret);
6720
6757
  animation: blink 1s step-end infinite;
6721
6758
  pointer-events: none;
6722
6759
  z-index: 10;
@@ -6728,7 +6765,7 @@ var cssText = `@charset "UTF-8";
6728
6765
  word-break: break-word;
6729
6766
  }
6730
6767
  .inline.focus {
6731
- background: rgba(0, 120, 255, 0.1);
6768
+ background: var(--color-focus-bg);
6732
6769
  border-radius: 3px;
6733
6770
  padding: 0 2px;
6734
6771
  min-height: 1.2em;
@@ -6806,10 +6843,12 @@ var Element = class extends HTMLElement {
6806
6843
  this.intent = null;
6807
6844
  this.styled = false;
6808
6845
  this.hasAcceptedExternalValue = false;
6846
+ this.autofocus = false;
6809
6847
  this.shadowRootElement = this.attachShadow({ mode: "open" });
6810
6848
  }
6811
6849
  connectedCallback() {
6812
6850
  const attrValue = this.getAttribute("value") ?? "";
6851
+ this.autofocus = this.hasAttribute("autofocus");
6813
6852
  this.ast.setText(attrValue);
6814
6853
  this.addStyles();
6815
6854
  this.addDOM();
@@ -6823,6 +6862,7 @@ var Element = class extends HTMLElement {
6823
6862
  this.interaction = new interaction_default(this.rootElement, this.select, this.editor, this.input, this.intent);
6824
6863
  this.interaction.attach();
6825
6864
  this.renderDOM();
6865
+ this.autoFocus();
6826
6866
  }
6827
6867
  disconnectedCallback() {
6828
6868
  this.interaction?.detach();
@@ -6834,6 +6874,7 @@ var Element = class extends HTMLElement {
6834
6874
  if (!this.hasAcceptedExternalValue && value !== "" || value !== "" && value !== this.ast.text) {
6835
6875
  this.ast.setText(value);
6836
6876
  this.renderDOM();
6877
+ this.autoFocus();
6837
6878
  this.hasAcceptedExternalValue = true;
6838
6879
  }
6839
6880
  }
@@ -6866,6 +6907,9 @@ var Element = class extends HTMLElement {
6866
6907
  composed: true
6867
6908
  }));
6868
6909
  }
6910
+ autoFocus() {
6911
+ if (this.autofocus && this.rootElement && this.select) this.select.autoFocus();
6912
+ }
6869
6913
  };
6870
6914
  var element_default = Element;
6871
6915
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@semigarden/synthetic-md",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "A UI primitive for unified Markdown editing and rendering",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -45,6 +45,7 @@
45
45
  "dev": "concurrently -n TSUP,CSS,CSS-TS,COPY \"tsup src/index.ts --watch --clean=false\" \"npm:watch:css\" \"npm:watch:css-ts\" \"npm:watch:distcss\"",
46
46
  "lint": "eslint .",
47
47
  "test": "vitest",
48
+ "typecheck": "tsc -p tsconfig.json --noEmit",
48
49
  "prepublishOnly": "npm run build"
49
50
  },
50
51
  "devDependencies": {