release: 0.5.0

feat: add word wrap
fix: support browsers dont support regexp positive lookbehind
This commit is contained in:
Sivan 2020-03-15 21:01:19 +08:00 committed by GitHub
commit c37bd4c0e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 692 additions and 676 deletions

View file

@ -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;
} }

File diff suppressed because it is too large Load diff

View file

@ -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 {

View file

@ -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">

View file

@ -3,7 +3,7 @@
* Add right spacing between CJK & ANS characters * Add right spacing between CJK & ANS characters
*/ */
import Finder from 'findandreplacedomtext' import Finder from 'heti-findandreplacedomtext'
// 正则表达式来自 pangu.js https://github.com/vinta/pangu.js // 正则表达式来自 pangu.js https://github.com/vinta/pangu.js
const CJK = '\u2e80-\u2eff\u2f00-\u2fdf\u3040-\u309f\u30a0-\u30fa\u30fc-\u30ff\u3100-\u312f\u3200-\u32ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff' const CJK = '\u2e80-\u2eff\u2f00-\u2fdf\u3040-\u309f\u30a0-\u30fa\u30fc-\u30ff\u3100-\u312f\u3200-\u32ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff'
@ -11,45 +11,42 @@ const A = 'A-Za-z\u0370-\u03ff'
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({}, Finder.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({}, Finder.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 (
@ -77,19 +74,21 @@ class Heti {
return $$r return $$r
} }
Finder($$elm, Object.assign(commonConfig, { Finder($$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,
})) }))
Finder($$elm, Object.assign(commonConfig, { Finder($$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),
})) }))
Finder($$elm, Object.assign(commonConfig, { Finder($$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,
})) }))
} }

View file

@ -29,6 +29,12 @@
-webkit-font-smoothing: subpixel-antialiased; -webkit-font-smoothing: subpixel-antialiased;
line-height: $line-height-normal; line-height: $line-height-normal;
// 针对混合英文段落采取按词折行长单词通过连词符段行
// https://justmarkup.com/articles/2015-07-31-dealing-with-long-words-in-css/
overflow-wrap: break-word;
word-wrap: break-word;
hyphens: auto;
// 自动在中西文间加 1/4 空格暂无浏览器支持 // 自动在中西文间加 1/4 空格暂无浏览器支持
//text-spacing: ideograph-alpha; //text-spacing: ideograph-alpha;

12
package-lock.json generated
View file

@ -1,6 +1,6 @@
{ {
"name": "heti", "name": "heti",
"version": "0.4.1", "version": "0.5.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -1124,11 +1124,6 @@
"path-exists": "^4.0.0" "path-exists": "^4.0.0"
} }
}, },
"findandreplacedomtext": {
"version": "0.4.6",
"resolved": "https://registry.npmjs.org/findandreplacedomtext/-/findandreplacedomtext-0.4.6.tgz",
"integrity": "sha512-CVRIKbEwfWoKTSnLrmyX26WjMY7o0aUUTm0RXN47fF/eHINJa8C+YHZxGagC7gMWVaAEBFwH7uVXuhwZcylWOQ=="
},
"flat-cache": { "flat-cache": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz", "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz",
@ -1424,6 +1419,11 @@
"integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=",
"dev": true "dev": true
}, },
"heti-findandreplacedomtext": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/heti-findandreplacedomtext/-/heti-findandreplacedomtext-0.5.0.tgz",
"integrity": "sha512-GFZjqU8LAdu1uR72GqrReI+lzNLMlcWtvdz1TKNJiofyo1mfTecFYSZEoEbcLcRMl+KwEldnNQoS4BwO8wtg0A=="
},
"hosted-git-info": { "hosted-git-info": {
"version": "2.8.5", "version": "2.8.5",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.5.tgz", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.5.tgz",

View file

@ -1,6 +1,6 @@
{ {
"name": "heti", "name": "heti",
"version": "0.4.3", "version": "0.5.0",
"description": "赫蹏是专为中文内容展示设计的排版样式增强。它基于通行的中文排版规范而来,可以为网站的读者带来更好的文章阅读体验。", "description": "赫蹏是专为中文内容展示设计的排版样式增强。它基于通行的中文排版规范而来,可以为网站的读者带来更好的文章阅读体验。",
"main": "lib/heti.scss", "main": "lib/heti.scss",
"files": [ "files": [
@ -34,7 +34,7 @@
}, },
"homepage": "https://github.com/sivan/heti#readme", "homepage": "https://github.com/sivan/heti#readme",
"dependencies": { "dependencies": {
"findandreplacedomtext": "^0.4.6" "heti-findandreplacedomtext": "^0.5.0"
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-commonjs": "^11.0.2", "@rollup/plugin-commonjs": "^11.0.2",

View file

@ -16,6 +16,9 @@ export default {
name: 'Heti', name: 'Heti',
plugins: [ plugins: [
terser({ terser({
compress: {
pure_funcs: ["console.info"] // 移除调试信息
},
output: { output: {
comments: false comments: false
} }