inline-style-editor 1.3.0 → 1.3.2

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.
@@ -1984,23 +1984,18 @@ class ColorPicker extends SvelteComponent {
1984
1984
 
1985
1985
  var ColorPicker$1 = ColorPicker;
1986
1986
 
1987
- const fontCheck = new Set([
1988
- // Windows 10
1989
- 'Arial', 'Arial Black', 'Bahnschrift', 'Calibri', 'Cambria', 'Cambria Math', 'Candara', 'Comic Sans MS', 'Consolas', 'Constantia', 'Corbel', 'Courier New', 'Ebrima', 'Franklin Gothic Medium', 'Gabriola', 'Gadugi', 'Georgia', 'HoloLens MDL2 Assets', 'Impact', 'Ink Free', 'Javanese Text', 'Leelawadee UI', 'Lucida Console', 'Lucida Sans Unicode', 'Malgun Gothic', 'Marlett', 'Microsoft Himalaya', 'Microsoft JhengHei', 'Microsoft New Tai Lue', 'Microsoft PhagsPa', 'Microsoft Sans Serif', 'Microsoft Tai Le', 'Microsoft YaHei', 'Microsoft Yi Baiti', 'MingLiU-ExtB', 'Mongolian Baiti', 'MS Gothic', 'MV Boli', 'Myanmar Text', 'Nirmala UI', 'Palatino Linotype', 'Segoe MDL2 Assets', 'Segoe Print', 'Segoe Script', 'Segoe UI', 'Segoe UI Historic', 'Segoe UI Emoji', 'Segoe UI Symbol', 'SimSun', 'Sitka', 'Sylfaen', 'Symbol', 'Tahoma', 'Times New Roman', 'Trebuchet MS', 'Verdana', 'Webdings', 'Wingdings', 'Yu Gothic',
1990
- // macOS
1991
- 'American Typewriter', 'Andale Mono', 'Arial', 'Arial Black', 'Arial Narrow', 'Arial Rounded MT Bold', 'Arial Unicode MS', 'Avenir', 'Avenir Next', 'Avenir Next Condensed', 'Baskerville', 'Big Caslon', 'Bodoni 72', 'Bodoni 72 Oldstyle', 'Bodoni 72 Smallcaps', 'Bradley Hand', 'Brush Script MT', 'Chalkboard', 'Chalkboard SE', 'Chalkduster', 'Charter', 'Cochin', 'Comic Sans MS', 'Copperplate', 'Courier', 'Courier New', 'Didot', 'DIN Alternate', 'DIN Condensed', 'Futura', 'Geneva', 'Georgia', 'Gill Sans', 'Helvetica', 'Helvetica Neue', 'Herculanum', 'Hoefler Text', 'Impact', 'Lucida Grande', 'Luminari', 'Marker Felt', 'Menlo', 'Microsoft Sans Serif', 'Monaco', 'Noteworthy', 'Optima', 'Palatino', 'Papyrus', 'Phosphate', 'Rockwell', 'Savoye LET', 'SignPainter', 'Skia', 'Snell Roundhand', 'Tahoma', 'Times', 'Times New Roman', 'Trattatello', 'Trebuchet MS', 'Verdana', 'Zapfino',
1992
- ].sort());
1987
+ const detector = new FontDetector();
1993
1988
 
1994
1989
  function getFonts() {
1995
- const availableFonts = new Set();
1990
+ // const availableFonts = new Set();
1996
1991
 
1997
- for (const font of fontCheck.values()) {
1998
- if (document.fonts.check(`12px "${font}"`)) {
1999
- availableFonts.add(font);
2000
- }
2001
- }
1992
+ // for (const font of fontCheck.values()) {
1993
+ // if (document.fonts.check(`12px "${font}"`)) {
1994
+ // availableFonts.add(font);
1995
+ // }
1996
+ // }
2002
1997
 
2003
- return [...listFonts(), ...availableFonts.values()]
1998
+ return [...listFonts(), ...detector.availableFonts]
2004
1999
  }
2005
2000
 
2006
2001
  function listFonts() {
@@ -2023,6 +2018,72 @@ function listFonts() {
2023
2018
  return [...new Set(arr)];
2024
2019
  }
2025
2020
 
2021
+ // https://stackoverflow.com/a/3368855
2022
+ class FontDetector {
2023
+ constructor() {
2024
+ this.fontsToCheck = new Set([
2025
+ 'Arial', 'Arial Black', 'Bahnschrift', 'Calibri', 'Cambria', 'Cambria Math', 'Candara', 'Comic Sans MS', 'Consolas', 'Constantia', 'Corbel', 'Courier New', 'Ebrima', 'Franklin Gothic Medium', 'Gabriola', 'Gadugi', 'Georgia', 'HoloLens MDL2 Assets', 'Impact', 'Ink Free', 'Javanese Text', 'Leelawadee UI', 'Lucida Console', 'Lucida Sans Unicode', 'Malgun Gothic', 'Marlett', 'Microsoft Himalaya', 'Microsoft JhengHei', 'Microsoft New Tai Lue', 'Microsoft PhagsPa', 'Microsoft Sans Serif', 'Microsoft Tai Le', 'Microsoft YaHei', 'Microsoft Yi Baiti', 'MingLiU-ExtB', 'Mongolian Baiti', 'MS Gothic', 'MV Boli', 'Myanmar Text', 'Nirmala UI', 'Palatino Linotype', 'Segoe MDL2 Assets', 'Segoe Print', 'Segoe Script', 'Segoe UI', 'Segoe UI Historic', 'Segoe UI Emoji', 'Segoe UI Symbol', 'SimSun', 'Sitka', 'Sylfaen', 'Symbol', 'Tahoma', 'Times New Roman', 'Trebuchet MS', 'Verdana', 'Webdings', 'Wingdings', 'Yu Gothic',
2026
+ 'American Typewriter', 'Andale Mono', 'Arial', 'Arial Black', 'Arial Narrow', 'Arial Rounded MT Bold', 'Arial Unicode MS', 'Avenir', 'Avenir Next', 'Avenir Next Condensed', 'Baskerville', 'Big Caslon', 'Bodoni 72', 'Bodoni 72 Oldstyle', 'Bodoni 72 Smallcaps', 'Bradley Hand', 'Brush Script MT', 'Chalkboard', 'Chalkboard SE', 'Chalkduster', 'Charter', 'Cochin', 'Comic Sans MS', 'Copperplate', 'Courier', 'Courier New', 'Didot', 'DIN Alternate', 'DIN Condensed', 'Futura', 'Geneva', 'Georgia', 'Gill Sans', 'Helvetica', 'Helvetica Neue', 'Herculanum', 'Hoefler Text', 'Impact', 'Lucida Grande', 'Luminari', 'Marker Felt', 'Menlo', 'Microsoft Sans Serif', 'Monaco', 'Noteworthy', 'Optima', 'Palatino', 'Papyrus', 'Phosphate', 'Rockwell', 'Savoye LET', 'SignPainter', 'Skia', 'Snell Roundhand', 'Tahoma', 'Times', 'Times New Roman', 'Trattatello', 'Trebuchet MS', 'Verdana', 'Zapfino',
2027
+ 'Comic Sans MS', 'Comic Sans', 'Apple Chancery', 'Bradley Hand', 'Brush Script MT', 'Brush Script Std', 'Snell Roundhand', 'URW Chancery L'
2028
+ ].sort());
2029
+ this.init();
2030
+ }
2031
+
2032
+ init() {
2033
+ this.defaultWidth = {};
2034
+ this.defaultHeight = {};
2035
+ // a font will be compared against all the three default fonts.
2036
+ // and if it doesn't match all 3 then that font is not available.
2037
+ this.baseFonts = ['monospace', 'sans-serif', 'serif', 'cursive'];
2038
+
2039
+ // we use m or w because these two characters take up the maximum width.
2040
+ // And we use a LLi so that the same matching fonts can get separated
2041
+ const testString = "mmmmmmmmmmlli";
2042
+
2043
+ // we test using 72px font size, we may use any size. I guess larger the better.
2044
+ const testSize = '72px';
2045
+
2046
+ this.container = document.getElementsByTagName("body")[0];
2047
+
2048
+ // create a SPAN in the document to get the width of the text we use to test
2049
+ this.spanTester = document.createElement("span");
2050
+ this.spanTester.style.fontSize = testSize;
2051
+ this.spanTester.innerHTML = testString;
2052
+ this.baseFonts.forEach(font => {
2053
+ //get the default width for the three base fonts
2054
+ this.spanTester.style.fontFamily = font;
2055
+ this.container.appendChild(this.spanTester);
2056
+ this.defaultWidth[font] = this.spanTester.offsetWidth; // width for the default font
2057
+ this.defaultHeight[font] = this.spanTester.offsetHeight; // height for the default font
2058
+ this.container.removeChild(this.spanTester);
2059
+ });
2060
+ this.detectFonts();
2061
+ }
2062
+
2063
+ fontExists(fontName) {
2064
+ let detected = false;
2065
+ for (const font of this.baseFonts) {
2066
+ this.spanTester.style.fontFamily = fontName + ',' + font; // name of the font along with the base font for fallback.
2067
+ this.container.appendChild(this.spanTester);
2068
+ const matched = (this.spanTester.offsetWidth != this.defaultWidth[font] || this.spanTester.offsetHeight != this.defaultHeight[font]);
2069
+ this.container.removeChild(this.spanTester);
2070
+ detected = detected || matched;
2071
+ }
2072
+ return detected;
2073
+ }
2074
+
2075
+ detectFonts() {
2076
+ this.availableFonts = [];
2077
+ for (const font of this.fontsToCheck.values()) {
2078
+ if (this.fontExists(font)) {
2079
+ this.availableFonts.push(font);
2080
+ }
2081
+ }
2082
+ this.availableFonts.sort();
2083
+ }
2084
+
2085
+ }
2086
+
2026
2087
  /* src/components/InlineStyleEditor.svelte generated by Svelte v3.49.0 */
2027
2088
 
2028
2089
  function get_each_context(ctx, list, i) {
@@ -3615,7 +3676,7 @@ function instance($$self, $$props, $$invalidate) {
3615
3676
  }
3616
3677
  } catch(err) {
3617
3678
  if (!warningDisplayed.has(i)) {
3618
- console.log('Style editor: Not able to access', sheets[i].ownerNode, 'sheet. Try CORS loading the sheet if you want to edit it.');
3679
+ console.warn('Style editor: Not able to access', sheets[i].ownerNode, 'sheet. Try CORS loading the sheet if you want to edit it.');
3619
3680
  warningDisplayed.add(i);
3620
3681
  }
3621
3682
  }
@@ -3634,7 +3695,7 @@ function instance($$self, $$props, $$invalidate) {
3634
3695
  const elem = elemDef[0];
3635
3696
  const types = [];
3636
3697
 
3637
- if (elem.firstChild && elem.firstChild.nodeType === 3) {
3698
+ if (elem.firstChild && (elem.firstChild.nodeType === 3 || elem.firstChild.tagName === 'tspan')) {
3638
3699
  // Node.TEXT_NODE
3639
3700
  types.push(typeText);
3640
3701
  }