palt-typesetting 0.1.0 → 0.1.1
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/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import HTMLProcessor from './html-processor';
|
|
2
2
|
import type { TypeSetttingOptions } from './types';
|
|
3
|
-
declare class
|
|
3
|
+
declare class TypeSet extends HTMLProcessor {
|
|
4
|
+
private isSupported;
|
|
4
5
|
constructor(options?: Partial<TypeSetttingOptions>);
|
|
5
|
-
private isIntlSegmenterSupported;
|
|
6
6
|
render(srcHtml: string): string;
|
|
7
|
+
renderFromElements(elements: Element | Element[]): void;
|
|
8
|
+
renderFromSelector(selector: string): void;
|
|
7
9
|
}
|
|
8
10
|
declare const createTypeSetting: (srcHtml: string, options?: Partial<TypeSetttingOptions>) => string;
|
|
9
|
-
export {
|
|
11
|
+
export { TypeSet, createTypeSetting };
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,kBAAkB,CAAA;AAG5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAMlD,cAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,kBAAkB,CAAA;AAG5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAMlD,cAAM,OAAQ,SAAQ,aAAa;IACjC,OAAO,CAAC,WAAW,CAAS;gBAEhB,OAAO,GAAE,OAAO,CAAC,mBAAmB,CAAM;IAyBtD,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAc/B,kBAAkB,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,EAAE,GAAG,IAAI;IAqBvD,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;CAQ3C;AAQD,QAAA,MAAM,iBAAiB,YAAa,MAAM,YAAW,QAAQ,mBAAmB,CAAC,KAAQ,MAGxF,CAAA;AAED,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -3,32 +3,52 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createTypeSetting = exports.
|
|
6
|
+
exports.createTypeSetting = exports.TypeSet = void 0;
|
|
7
7
|
const html_processor_1 = __importDefault(require("./html-processor"));
|
|
8
8
|
const insert_separators_1 = __importDefault(require("./insert-separators"));
|
|
9
9
|
const apply_style_1 = require("./apply-style");
|
|
10
|
-
class
|
|
10
|
+
class TypeSet extends html_processor_1.default {
|
|
11
11
|
constructor(options = {}) {
|
|
12
12
|
const transformFunctions = [apply_style_1.applyStyleToText, insert_separators_1.default, apply_style_1.applyStyleToSegment];
|
|
13
13
|
super(transformFunctions, options);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
this.isSupported = typeof Intl.Segmenter !== 'undefined';
|
|
15
|
+
if (!this.isSupported) {
|
|
16
|
+
console.warn(`
|
|
17
|
+
Intl.Segmenter is not supported in this environment.
|
|
18
|
+
The original HTML string will be returned.
|
|
19
|
+
For more information, see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter
|
|
20
|
+
`);
|
|
19
21
|
}
|
|
20
|
-
return isSupported;
|
|
21
22
|
}
|
|
22
23
|
render(srcHtml) {
|
|
23
|
-
if (!this.
|
|
24
|
+
if (!this.isSupported) {
|
|
24
25
|
return srcHtml;
|
|
25
26
|
}
|
|
26
27
|
return this.processHtmlWithFunctions(srcHtml);
|
|
27
28
|
}
|
|
29
|
+
renderFromElements(elements) {
|
|
30
|
+
if (!this.isSupported) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!Array.isArray(elements)) {
|
|
34
|
+
elements = [elements];
|
|
35
|
+
}
|
|
36
|
+
elements.forEach(element => {
|
|
37
|
+
const processedHtml = this.render(element.innerHTML);
|
|
38
|
+
element.innerHTML = processedHtml;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
renderFromSelector(selector) {
|
|
42
|
+
if (!this.isSupported) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const elements = document.querySelectorAll(selector);
|
|
46
|
+
this.renderFromElements(Array.from(elements));
|
|
47
|
+
}
|
|
28
48
|
}
|
|
29
|
-
exports.
|
|
49
|
+
exports.TypeSet = TypeSet;
|
|
30
50
|
const createTypeSetting = (srcHtml, options = {}) => {
|
|
31
|
-
const typeset = new
|
|
51
|
+
const typeset = new TypeSet(options);
|
|
32
52
|
return typeset.render(srcHtml);
|
|
33
53
|
};
|
|
34
54
|
exports.createTypeSetting = createTypeSetting;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sEAA4C;AAC5C,4EAAwD;AACxD,+CAAqE;AAOrE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sEAA4C;AAC5C,4EAAwD;AACxD,+CAAqE;AAOrE,MAAM,OAAQ,SAAQ,wBAAa;IAGjC,YAAY,UAAwC,EAAE;QACpD,MAAM,kBAAkB,GAAG,CAAC,8BAAgB,EAAE,2BAAsB,EA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