inline-style-editor 1.3.2 → 1.3.3

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,18 +1984,66 @@ class ColorPicker extends SvelteComponent {
1984
1984
 
1985
1985
  var ColorPicker$1 = ColorPicker;
1986
1986
 
1987
- const detector = new FontDetector();
1987
+ // https://stackoverflow.com/a/3368855
1988
+ function getAvailableFonts() {
1989
+ const fontsToCheck = new Set([
1990
+ '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',
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
+ 'Comic Sans MS', 'Comic Sans', 'Apple Chancery', 'Bradley Hand', 'Brush Script MT', 'Brush Script Std', 'Snell Roundhand', 'URW Chancery L'
1993
+ ].sort());
1994
+ const defaultWidth = {};
1995
+ const defaultHeight = {};
1996
+ // a font will be compared against all the three default fonts.
1997
+ // and if it doesn't match all 3 then that font is not available.
1998
+ const baseFonts = ['monospace', 'sans-serif', 'serif', 'cursive'];
1999
+
2000
+ // we use m or w because these two characters take up the maximum width.
2001
+ // And we use a LLi so that the same matching fonts can get separated
2002
+ const testString = "mmmmmmmmmmlli";
2003
+
2004
+ // we test using 72px font size, we may use any size. I guess larger the better.
2005
+ const testSize = '72px';
2006
+
2007
+ const container = document.getElementsByTagName("body")[0];
2008
+
2009
+ // create a SPAN in the document to get the width of the text we use to test
2010
+ const spanTester = document.createElement("span");
2011
+ spanTester.style.fontSize = testSize;
2012
+ spanTester.innerHTML = testString;
2013
+ baseFonts.forEach(font => {
2014
+ //get the default width for the three base fonts
2015
+ spanTester.style.fontFamily = font;
2016
+ container.appendChild(spanTester);
2017
+ defaultWidth[font] = spanTester.offsetWidth; // width for the default font
2018
+ defaultHeight[font] = spanTester.offsetHeight; // height for the default font
2019
+ container.removeChild(spanTester);
2020
+ });
1988
2021
 
1989
- function getFonts() {
1990
- // const availableFonts = new Set();
2022
+ const availableFonts = [];
1991
2023
 
1992
- // for (const font of fontCheck.values()) {
1993
- // if (document.fonts.check(`12px "${font}"`)) {
1994
- // availableFonts.add(font);
1995
- // }
1996
- // }
2024
+ const fontExists = (fontName) => {
2025
+ let detected = false;
2026
+ for (const font of baseFonts) {
2027
+ spanTester.style.fontFamily = fontName + ',' + font; // name of the font along with the base font for fallback.
2028
+ container.appendChild(spanTester);
2029
+ const matched = (spanTester.offsetWidth != defaultWidth[font] || spanTester.offsetHeight != defaultHeight[font]);
2030
+ container.removeChild(spanTester);
2031
+ detected = detected || matched;
2032
+ }
2033
+ return detected;
2034
+ };
2035
+ for (const font of fontsToCheck.values()) {
2036
+ if (fontExists(font)) {
2037
+ availableFonts.push(font);
2038
+ }
2039
+ }
2040
+ return availableFonts.sort();
1997
2041
 
1998
- return [...listFonts(), ...detector.availableFonts]
2042
+ }
2043
+
2044
+ const availableFonts = getAvailableFonts();
2045
+ function getFonts() {
2046
+ return [...listFonts(), ...availableFonts]
1999
2047
  }
2000
2048
 
2001
2049
  function listFonts() {
@@ -2018,72 +2066,6 @@ function listFonts() {
2018
2066
  return [...new Set(arr)];
2019
2067
  }
2020
2068
 
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
-
2087
2069
  /* src/components/InlineStyleEditor.svelte generated by Svelte v3.49.0 */
2088
2070
 
2089
2071
  function get_each_context(ctx, list, i) {