-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from speee/ol-type-attribute
Support type attribute for <ol> element
- Loading branch information
Showing
15 changed files
with
455 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{ | ||
"letters": { | ||
"0": 58, | ||
"1": 58, | ||
"2": 58, | ||
"3": 58, | ||
"4": 58, | ||
"5": 58, | ||
"6": 58, | ||
"7": 58, | ||
"8": 58, | ||
"9": 58, | ||
"a": 49.69999694824219, | ||
"b": 56, | ||
"c": 47.75, | ||
"d": 56, | ||
"e": 52.79998779296875, | ||
"f": 35.04998779296875, | ||
"g": 52, | ||
"h": 55.79998779296875, | ||
"i": 24, | ||
"j": 24, | ||
"k": 50.79998779296875, | ||
"l": 23.599990844726562, | ||
"m": 82.25, | ||
"n": 55.79998779296875, | ||
"o": 56.69999694824219, | ||
"p": 56.04998779296875, | ||
"q": 56, | ||
"r": 36.399993896484375, | ||
"s": 43.29998779296875, | ||
"t": 35.84999084472656, | ||
"u": 55.75, | ||
"v": 51.59999084472656, | ||
"w": 78.55000305175781, | ||
"x": 49.79998779296875, | ||
"y": 51.54998779296875, | ||
"z": 45.19999694824219, | ||
"A": 67.69999694824219, | ||
"B": 64.64999389648438, | ||
"C": 66.80000305175781, | ||
"D": 76.05000305175781, | ||
"E": 57.75, | ||
"F": 56.54998779296875, | ||
"G": 73.05000305175781, | ||
"H": 76.34999084472656, | ||
"I": 28, | ||
"J": 42.25, | ||
"K": 66.25, | ||
"L": 51.34999084472656, | ||
"M": 92.84999084472656, | ||
"N": 76.34999084472656, | ||
"O": 80.05000305175781, | ||
"P": 60.04998779296875, | ||
"Q": 80.05000305175781, | ||
"R": 62.649993896484375, | ||
"S": 54.25, | ||
"T": 59.04998779296875, | ||
"U": 73.55000305175781, | ||
"V": 67.69999694824219, | ||
"W": 103.55000305175781, | ||
"X": 64.89999389648438, | ||
"Y": 62.399993896484375, | ||
"Z": 60.19999694824219, | ||
"-": 37.149993896484375, | ||
".": 23.599990844726562, | ||
"•": 58, | ||
"◦": 40.44999694824219, | ||
"▪": 40.44999694824219 | ||
}, | ||
"spaces": { | ||
" ": 50, | ||
" ": 75, | ||
" ": 33.29998779296875, | ||
" ": 25, | ||
" ": 16.649993896484375, | ||
" ": 58, | ||
" ": 21.25, | ||
" ": 12.5, | ||
" ": 6.25 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* eslint-disable no-param-reassign */ | ||
import { letters, spaces } from '../data/font-width.json' | ||
|
||
const flippedSpaces = Object.keys(spaces).reduce( | ||
(obj, key) => ({ ...obj, [spaces[key]]: key }), | ||
{} as Record<number, string> | ||
) | ||
|
||
const spaceWidth = Object.values(spaces).sort((a, b) => b - a) | ||
|
||
const indentCache = new Map<number, string>() | ||
const measureCache = new Map<string, number>() | ||
|
||
export function makeIndent(width: number): string { | ||
let indent = indentCache.get(width) | ||
|
||
if (indent === undefined) { | ||
indent = '' | ||
let targetWidth = width | ||
|
||
spaceWidth.forEach(w => { | ||
const num = Math.floor(targetWidth / w) | ||
if (num > 0) indent += flippedSpaces[w].repeat(num) | ||
|
||
targetWidth -= w * num | ||
}) | ||
|
||
indentCache.set(width, indent) | ||
} | ||
|
||
return indent | ||
} | ||
|
||
export function measureWidth(bulletStr: string) { | ||
let width = measureCache.get(bulletStr) | ||
|
||
if (width === undefined) { | ||
// 25.6 is almost same width with the regular whitespace | ||
width = [...bulletStr].reduce((total, l) => total + (letters[l] ?? 25.6), 0) | ||
measureCache.set(bulletStr, width) | ||
} | ||
|
||
return width | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.