inline-style-editor 1.3.1 → 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.
- package/dist/inline-style-editor.js +2 -2
- package/dist/inline-style-editor.js.map +1 -1
- package/dist/inline-style-editor.mjs +92 -32
- package/dist/inline-style-editor.mjs.map +1 -1
- package/docs/index.html +1 -1
- package/package.json +1 -1
- package/src/components/InlineStyleEditor.svelte +1 -2
- package/src/util/fonts.js +75 -13
- package/stats.html +19 -1
|
@@ -1984,23 +1984,18 @@ class ColorPicker extends SvelteComponent {
|
|
|
1984
1984
|
|
|
1985
1985
|
var ColorPicker$1 = ColorPicker;
|
|
1986
1986
|
|
|
1987
|
-
const
|
|
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
|
-
|
|
1999
|
-
|
|
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
|
|
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) {
|
|
@@ -2077,7 +2138,7 @@ function get_each_context_5(ctx, list, i) {
|
|
|
2077
2138
|
return child_ctx;
|
|
2078
2139
|
}
|
|
2079
2140
|
|
|
2080
|
-
// (
|
|
2141
|
+
// (415:4) {#if targetsToSearch.length > 1}
|
|
2081
2142
|
function create_if_block_9(ctx) {
|
|
2082
2143
|
let div;
|
|
2083
2144
|
let b;
|
|
@@ -2142,7 +2203,7 @@ function create_if_block_9(ctx) {
|
|
|
2142
2203
|
};
|
|
2143
2204
|
}
|
|
2144
2205
|
|
|
2145
|
-
// (
|
|
2206
|
+
// (418:8) {#each targetsToSearch as [_, name], elemIndex}
|
|
2146
2207
|
function create_each_block_5(ctx) {
|
|
2147
2208
|
let span;
|
|
2148
2209
|
let t0_value = /*name*/ ctx[82] + "";
|
|
@@ -2188,7 +2249,7 @@ function create_each_block_5(ctx) {
|
|
|
2188
2249
|
};
|
|
2189
2250
|
}
|
|
2190
2251
|
|
|
2191
|
-
// (
|
|
2252
|
+
// (427:8) {#each getRuleNames(allRules[selectedElemIndex]) as ruleName, ruleIndex}
|
|
2192
2253
|
function create_each_block_4(ctx) {
|
|
2193
2254
|
let span;
|
|
2194
2255
|
let t_value = /*ruleName*/ ctx[78] + "";
|
|
@@ -2237,7 +2298,7 @@ function create_each_block_4(ctx) {
|
|
|
2237
2298
|
};
|
|
2238
2299
|
}
|
|
2239
2300
|
|
|
2240
|
-
// (
|
|
2301
|
+
// (438:12) {#if type !== 'custom' || (currentRule === 'inline' && type === 'custom' && hasDisplayedCustom )}
|
|
2241
2302
|
function create_if_block_8(ctx) {
|
|
2242
2303
|
let span;
|
|
2243
2304
|
let t0_value = /*type*/ ctx[75] + "";
|
|
@@ -2283,7 +2344,7 @@ function create_if_block_8(ctx) {
|
|
|
2283
2344
|
};
|
|
2284
2345
|
}
|
|
2285
2346
|
|
|
2286
|
-
// (
|
|
2347
|
+
// (436:8) {#each allTypes[selectedElemIndex] || [] as type, typeIndex}
|
|
2287
2348
|
function create_each_block_3(ctx) {
|
|
2288
2349
|
let if_block_anchor;
|
|
2289
2350
|
let if_block = (/*type*/ ctx[75] !== 'custom' || /*currentRule*/ ctx[17] === 'inline' && /*type*/ ctx[75] === 'custom' && /*hasDisplayedCustom*/ ctx[16]) && create_if_block_8(ctx);
|
|
@@ -2318,7 +2379,7 @@ function create_each_block_3(ctx) {
|
|
|
2318
2379
|
};
|
|
2319
2380
|
}
|
|
2320
2381
|
|
|
2321
|
-
// (
|
|
2382
|
+
// (443:4) {#if allTypes[selectedElemIndex]}
|
|
2322
2383
|
function create_if_block(ctx) {
|
|
2323
2384
|
let div;
|
|
2324
2385
|
let t0;
|
|
@@ -2449,7 +2510,7 @@ function create_if_block(ctx) {
|
|
|
2449
2510
|
};
|
|
2450
2511
|
}
|
|
2451
2512
|
|
|
2452
|
-
// (
|
|
2513
|
+
// (454:16) {:else}
|
|
2453
2514
|
function create_else_block(ctx) {
|
|
2454
2515
|
let span;
|
|
2455
2516
|
let t_value = /*selectedName*/ ctx[66] + "";
|
|
@@ -2473,7 +2534,7 @@ function create_else_block(ctx) {
|
|
|
2473
2534
|
};
|
|
2474
2535
|
}
|
|
2475
2536
|
|
|
2476
|
-
// (
|
|
2537
|
+
// (448:16) {#if choices.props.length > 1}
|
|
2477
2538
|
function create_if_block_7(ctx) {
|
|
2478
2539
|
let div;
|
|
2479
2540
|
let select;
|
|
@@ -2547,7 +2608,7 @@ function create_if_block_7(ctx) {
|
|
|
2547
2608
|
};
|
|
2548
2609
|
}
|
|
2549
2610
|
|
|
2550
|
-
// (
|
|
2611
|
+
// (450:24) {#each choices.props as propName, i}
|
|
2551
2612
|
function create_each_block_2(ctx) {
|
|
2552
2613
|
let option;
|
|
2553
2614
|
let t0_value = /*propName*/ ctx[72] + "";
|
|
@@ -2582,7 +2643,7 @@ function create_each_block_2(ctx) {
|
|
|
2582
2643
|
};
|
|
2583
2644
|
}
|
|
2584
2645
|
|
|
2585
|
-
// (
|
|
2646
|
+
// (477:50)
|
|
2586
2647
|
function create_if_block_6(ctx) {
|
|
2587
2648
|
let colorpicker;
|
|
2588
2649
|
let current;
|
|
@@ -2628,7 +2689,7 @@ function create_if_block_6(ctx) {
|
|
|
2628
2689
|
};
|
|
2629
2690
|
}
|
|
2630
2691
|
|
|
2631
|
-
// (
|
|
2692
|
+
// (467:51)
|
|
2632
2693
|
function create_if_block_4(ctx) {
|
|
2633
2694
|
let select;
|
|
2634
2695
|
let show_if = !/*choices*/ ctx[65].includes(/*allCurrentPropDefs*/ ctx[14][/*selectedName*/ ctx[66]].value);
|
|
@@ -2721,7 +2782,7 @@ function create_if_block_4(ctx) {
|
|
|
2721
2782
|
};
|
|
2722
2783
|
}
|
|
2723
2784
|
|
|
2724
|
-
// (
|
|
2785
|
+
// (458:16) {#if choices.type === 'slider'}
|
|
2725
2786
|
function create_if_block_3(ctx) {
|
|
2726
2787
|
let input;
|
|
2727
2788
|
let input_min_value;
|
|
@@ -2796,7 +2857,7 @@ function create_if_block_3(ctx) {
|
|
|
2796
2857
|
};
|
|
2797
2858
|
}
|
|
2798
2859
|
|
|
2799
|
-
// (
|
|
2860
|
+
// (470:24) {#if !choices.includes(allCurrentPropDefs[selectedName].value)}
|
|
2800
2861
|
function create_if_block_5(ctx) {
|
|
2801
2862
|
let option;
|
|
2802
2863
|
|
|
@@ -2817,7 +2878,7 @@ function create_if_block_5(ctx) {
|
|
|
2817
2878
|
};
|
|
2818
2879
|
}
|
|
2819
2880
|
|
|
2820
|
-
// (
|
|
2881
|
+
// (473:24) {#each choices as choice}
|
|
2821
2882
|
function create_each_block_1(ctx) {
|
|
2822
2883
|
let option;
|
|
2823
2884
|
let t_value = /*choice*/ ctx[69] + "";
|
|
@@ -2855,7 +2916,7 @@ function create_each_block_1(ctx) {
|
|
|
2855
2916
|
};
|
|
2856
2917
|
}
|
|
2857
2918
|
|
|
2858
|
-
// (
|
|
2919
|
+
// (445:8) {#each propsByType as choices}
|
|
2859
2920
|
function create_each_block(ctx) {
|
|
2860
2921
|
let div;
|
|
2861
2922
|
let t0;
|
|
@@ -3001,7 +3062,7 @@ function create_each_block(ctx) {
|
|
|
3001
3062
|
};
|
|
3002
3063
|
}
|
|
3003
3064
|
|
|
3004
|
-
// (
|
|
3065
|
+
// (485:8) {#if currentRule === 'inline' && bringableToFront[selectedElemIndex] !== null}
|
|
3005
3066
|
function create_if_block_2(ctx) {
|
|
3006
3067
|
let div;
|
|
3007
3068
|
let mounted;
|
|
@@ -3035,7 +3096,7 @@ function create_if_block_2(ctx) {
|
|
|
3035
3096
|
};
|
|
3036
3097
|
}
|
|
3037
3098
|
|
|
3038
|
-
// (
|
|
3099
|
+
// (490:8) {#if currentRule === 'inline' && inlineDeletable(currentElement)}
|
|
3039
3100
|
function create_if_block_1(ctx) {
|
|
3040
3101
|
let div;
|
|
3041
3102
|
let mounted;
|
|
@@ -3615,7 +3676,7 @@ function instance($$self, $$props, $$invalidate) {
|
|
|
3615
3676
|
}
|
|
3616
3677
|
} catch(err) {
|
|
3617
3678
|
if (!warningDisplayed.has(i)) {
|
|
3618
|
-
console.
|
|
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
|
}
|
|
@@ -3654,7 +3715,6 @@ function instance($$self, $$props, $$invalidate) {
|
|
|
3654
3715
|
types.push(typeBackground);
|
|
3655
3716
|
}
|
|
3656
3717
|
|
|
3657
|
-
console.log(types);
|
|
3658
3718
|
if (bringable) bringableToFront.push(true); else bringableToFront.push(null);
|
|
3659
3719
|
typesByElem.push(types);
|
|
3660
3720
|
return typesByElem;
|