Deploying to gh-pages from - c37bd4c0e1
🚀
This commit is contained in:
parent
0492da0879
commit
73ff268fe3
4 changed files with 646 additions and 638 deletions
|
@ -36,7 +36,7 @@ a {
|
||||||
.container {
|
.container {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding-block-start: 12px;
|
padding-block-start: 12px;
|
||||||
padding-block-end: 12px;
|
padding-block-end: 72px;
|
||||||
padding-inline-start: 12px;
|
padding-inline-start: 12px;
|
||||||
padding-inline-end: 12px;
|
padding-inline-end: 12px;
|
||||||
}
|
}
|
||||||
|
@ -315,6 +315,7 @@ a {
|
||||||
margin-block-start: 12px;
|
margin-block-start: 12px;
|
||||||
margin-block-end: 0;
|
margin-block-end: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.article .article__toc ol ol {
|
.article .article__toc ol ol {
|
||||||
margin-block-start: 0;
|
margin-block-start: 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,6 +163,11 @@
|
||||||
*/
|
*/
|
||||||
function Finder(node, options) {
|
function Finder(node, options) {
|
||||||
|
|
||||||
|
// Add offset to fix browsers which don't support regex lookbehind.
|
||||||
|
if (!options.offset) {
|
||||||
|
options.offset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
var preset = options.preset && exposed.PRESETS[options.preset];
|
var preset = options.preset && exposed.PRESETS[options.preset];
|
||||||
|
|
||||||
options.portionMode = options.portionMode || PORTION_MODE_RETAIN;
|
options.portionMode = options.portionMode || PORTION_MODE_RETAIN;
|
||||||
|
@ -349,12 +354,12 @@
|
||||||
endPortion = {
|
endPortion = {
|
||||||
node: curNode,
|
node: curNode,
|
||||||
index: portionIndex++,
|
index: portionIndex++,
|
||||||
text: curNode.data.substring(match.startIndex - atIndex, match.endIndex - atIndex),
|
text: curNode.data.substring(match.startIndex - atIndex + this.options.offset, match.endIndex - atIndex),
|
||||||
|
|
||||||
// If it's the first match (atIndex==0) we should just return 0
|
// If it's the first match (atIndex==0) we should just return 0
|
||||||
indexInMatch: atIndex === 0 ? 0 : atIndex - match.startIndex,
|
indexInMatch: atIndex === 0 ? 0 : atIndex - match.startIndex,
|
||||||
|
|
||||||
indexInNode: match.startIndex - atIndex,
|
indexInNode: match.startIndex - atIndex + this.options.offset,
|
||||||
endIndexInNode: match.endIndex - atIndex,
|
endIndexInNode: match.endIndex - atIndex,
|
||||||
isEnd: true
|
isEnd: true
|
||||||
};
|
};
|
||||||
|
@ -376,9 +381,9 @@
|
||||||
node: curNode,
|
node: curNode,
|
||||||
index: portionIndex++,
|
index: portionIndex++,
|
||||||
indexInMatch: 0,
|
indexInMatch: 0,
|
||||||
indexInNode: match.startIndex - atIndex,
|
indexInNode: match.startIndex - atIndex + this.options.offset,
|
||||||
endIndexInNode: match.endIndex - atIndex,
|
endIndexInNode: match.endIndex - atIndex,
|
||||||
text: curNode.data.substring(match.startIndex - atIndex, match.endIndex - atIndex)
|
text: curNode.data.substring(match.startIndex - atIndex + this.options.offset, match.endIndex - atIndex)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -655,45 +660,42 @@
|
||||||
const N = '0-9';
|
const N = '0-9';
|
||||||
const S = '`~!@#\\$%\\^&\\*\\(\\)-_=\\+\\[\\]{}\\\\\\|;:\'",<.>\\/\\?';
|
const S = '`~!@#\\$%\\^&\\*\\(\\)-_=\\+\\[\\]{}\\\\\\|;:\'",<.>\\/\\?';
|
||||||
const ANS = `${A}${N}${S}`;
|
const ANS = `${A}${N}${S}`;
|
||||||
const HETI_NON_CONTIGUOUS_ELEMENTS = {
|
const HETI_NON_CONTIGUOUS_ELEMENTS = Object.assign({}, findAndReplaceDOMText.NON_CONTIGUOUS_PROSE_ELEMENTS, {
|
||||||
// Block Elements
|
|
||||||
address: 1, article: 1, aside: 1, blockquote: 1, dd: 1, div: 1,
|
|
||||||
dl: 1, fieldset: 1, figcaption: 1, figure: 1, footer: 1, form: 1, h1: 1, h2: 1, h3: 1,
|
|
||||||
h4: 1, h5: 1, h6: 1, header: 1, hgroup: 1, hr: 1, main: 1, nav: 1, noscript: 1, ol: 1,
|
|
||||||
output: 1, p: 1, pre: 1, section: 1, ul: 1,
|
|
||||||
// Other misc. elements that are not part of continuous inline prose:
|
|
||||||
br: 1, li: 1, summary: 1, dt: 1, details: 1, rp: 1, rt: 1, rtc: 1,
|
|
||||||
// Media / Source elements:
|
|
||||||
script: 1, style: 1, img: 1, video: 1, audio: 1, canvas: 1, svg: 1, map: 1, object: 1,
|
|
||||||
// Input elements
|
|
||||||
input: 1, textarea: 1, select: 1, option: 1, optgroup: 1, button: 1,
|
|
||||||
// Table related elements:
|
|
||||||
table: 1, tbody: 1, thead: 1, th: 1, tr: 1, td: 1, caption: 1, col: 1, tfoot: 1, colgroup: 1,
|
|
||||||
// Inline elements
|
// Inline elements
|
||||||
ins: 1, del: 1, s: 1,
|
ins: 1, del: 1, s: 1,
|
||||||
};
|
});
|
||||||
const HETI_SKIPPED_ELEMENTS = {
|
const HETI_SKIPPED_ELEMENTS = Object.assign({}, findAndReplaceDOMText.NON_PROSE_ELEMENTS, {
|
||||||
br: 1, hr: 1,
|
|
||||||
// Media / Source elements:
|
|
||||||
script: 1, style: 1, img: 1, video: 1, audio: 1, canvas: 1, svg: 1, map: 1, object: 1,
|
|
||||||
// Input elements:
|
|
||||||
input: 1, textarea: 1, select: 1, option: 1, optgroup: 1, button: 1,
|
|
||||||
// Pre elements:
|
|
||||||
pre: 1, code: 1, sup: 1, sub: 1,
|
pre: 1, code: 1, sup: 1, sub: 1,
|
||||||
// Heti elements
|
// Heti elements
|
||||||
'heti-spacing': 1,
|
'heti-spacing': 1,
|
||||||
};
|
});
|
||||||
const HETI_SKIPPED_CLASS = 'heti-skip';
|
const HETI_SKIPPED_CLASS = 'heti-skip';
|
||||||
const hasOwn = {}.hasOwnProperty;
|
const hasOwn = {}.hasOwnProperty;
|
||||||
|
const REG_FULL = `(?<=[${CJK}])( *[${ANS}]+(?: +[${ANS}]+)* *)(?=[${CJK}])`;
|
||||||
|
const REG_FULL_FIX = `(?:[${CJK}])( *[${ANS}]+(?: +[${ANS}]+)* *)(?=[${CJK}])`;
|
||||||
|
const REG_START = `([${ANS}]+(?: +[${ANS}]+)* *)(?=[${CJK}])`;
|
||||||
|
const REG_END = `(?<=[${CJK}])( *[${ANS}]+(?: +[${ANS}]+)*)`;
|
||||||
|
const REG_END_FIX = `(?:[${CJK}])( *[${ANS}]+(?: +[${ANS}]+)*)`;
|
||||||
|
|
||||||
class Heti {
|
class Heti {
|
||||||
constructor (rootSelector) {
|
constructor (rootSelector) {
|
||||||
|
let supportLookBehind = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
new RegExp(`(?<=\d)\d`, 'g').test('');
|
||||||
|
} catch (err) {
|
||||||
|
console.info(err.name, '该浏览器尚未实现 RegExp positive lookbehind');
|
||||||
|
supportLookBehind = false;
|
||||||
|
}
|
||||||
|
|
||||||
this.rootSelector = rootSelector || '.heti';
|
this.rootSelector = rootSelector || '.heti';
|
||||||
this.REG_FULL = new RegExp(`(?<=[${CJK}])( *[${ANS}]+(?: +[${ANS}]+)* *)(?=[${CJK}])`, 'g');
|
this.REG_FULL = new RegExp(supportLookBehind ? REG_FULL : REG_FULL_FIX, 'g');
|
||||||
this.REG_START = new RegExp(`([${ANS}]+(?: +[${ANS}]+)* *)(?=[${CJK}])`, 'g');
|
this.REG_START = new RegExp(REG_START, 'g');
|
||||||
this.REG_END = new RegExp(`(?<=[${CJK}])( *[${ANS}]+(?: +[${ANS}]+)*)`, 'g');
|
this.REG_END = new RegExp(supportLookBehind ? REG_END : REG_END_FIX, 'g');
|
||||||
|
this.offsetWidth = supportLookBehind ? 0 : 1;
|
||||||
this.funcForceContext = function forceContext (el) {
|
this.funcForceContext = function forceContext (el) {
|
||||||
return hasOwn.call(HETI_NON_CONTIGUOUS_ELEMENTS, el.nodeName.toLowerCase())
|
return hasOwn.call(HETI_NON_CONTIGUOUS_ELEMENTS, el.nodeName.toLowerCase())
|
||||||
|
// return true
|
||||||
};
|
};
|
||||||
this.funcFilterElements = function filterElements (el) {
|
this.funcFilterElements = function filterElements (el) {
|
||||||
return (
|
return (
|
||||||
|
@ -721,19 +723,21 @@
|
||||||
return $$r
|
return $$r
|
||||||
};
|
};
|
||||||
|
|
||||||
findAndReplaceDOMText($$elm, Object.assign(commonConfig, {
|
findAndReplaceDOMText($$elm, Object.assign({}, commonConfig, {
|
||||||
find: this.REG_FULL,
|
find: this.REG_FULL,
|
||||||
replace: portion => getWrapper('heti-spacing-start heti-spacing-end', portion.text),
|
replace: portion => getWrapper('heti-spacing-start heti-spacing-end', portion.text),
|
||||||
|
offset: this.offsetWidth,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
findAndReplaceDOMText($$elm, Object.assign(commonConfig, {
|
findAndReplaceDOMText($$elm, Object.assign({}, commonConfig, {
|
||||||
find: this.REG_START,
|
find: this.REG_START,
|
||||||
replace: portion => getWrapper('heti-spacing-start', portion.text),
|
replace: portion => getWrapper('heti-spacing-start', portion.text),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
findAndReplaceDOMText($$elm, Object.assign(commonConfig, {
|
findAndReplaceDOMText($$elm, Object.assign({}, commonConfig, {
|
||||||
find: this.REG_END,
|
find: this.REG_END,
|
||||||
replace: portion => getWrapper('heti-spacing-end', portion.text),
|
replace: portion => getWrapper('heti-spacing-end', portion.text),
|
||||||
|
offset: this.offsetWidth,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
heti.css
3
heti.css
|
@ -73,6 +73,9 @@
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
-webkit-font-smoothing: subpixel-antialiased;
|
-webkit-font-smoothing: subpixel-antialiased;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
|
overflow-wrap: break-word;
|
||||||
|
word-wrap: break-word;
|
||||||
|
hyphens: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.heti::before, .heti::after {
|
.heti::before, .heti::after {
|
||||||
|
|
|
@ -145,7 +145,7 @@
|
||||||
</section>
|
</section>
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
<details>
|
<details open>
|
||||||
<summary id="example-4">示例4:英文演示</summary>
|
<summary id="example-4">示例4:英文演示</summary>
|
||||||
<section class="demo">
|
<section class="demo">
|
||||||
<div lang="en-US">
|
<div lang="en-US">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue