@readium/helpers 1.1.1 → 1.2.0

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.js CHANGED
@@ -1 +1 @@
1
- import{adjustColorForContrast as r,checkContrast as o,colorToRgba as n,getContrastingTextColor as a,getLuminance as g,isDarkColor as i,isLightColor as m}from"./color.js";import{sML as F,sMLWithRequest as c}from"./sML.js";import{decodeTextFragmentDirective as l}from"./textFragmentDirective.js";import{forTesting as f,internal as p,processTextFragmentDirective as T}from"./vendor/text-fragments-polyfill/textFragmentMatcher.js";import{GenerateFragmentStatus as d,generateFragment as L,generateFragmentFromRange as R,isValidRangeForFragmentGeneration as h,setFragmentGenerationTimeout as D}from"./vendor/text-fragments-polyfill/textFragmentGenerator.js";export{d as GenerateFragmentStatus,r as adjustColorForContrast,o as checkContrast,n as colorToRgba,l as decodeTextFragmentDirective,f as forTesting,L as generateFragment,R as generateFragmentFromRange,a as getContrastingTextColor,g as getLuminance,p as internal,i as isDarkColor,m as isLightColor,h as isValidRangeForFragmentGeneration,T as processTextFragmentDirective,F as sML,c as sMLWithRequest,D as setFragmentGenerationTimeout};
1
+ import{adjustColorForContrast as r,checkContrast as o,colorToRgba as n,getContrastingTextColor as a,getLuminance as s,isDarkColor as i,isLightColor as g}from"./color.js";import{sML as c,sMLWithRequest as x}from"./sML.js";import{BINDING_PUNCT_CLASS as l,ssmlAttrEscape as p,ssmlTextEscape as C,startsWithBindingPunct as T}from"./text.js";import{decodeTextFragmentDirective as u}from"./textFragmentDirective.js";import{forTesting as L,internal as h,processTextFragmentDirective as D}from"./vendor/text-fragments-polyfill/textFragmentMatcher.js";import{GenerateFragmentStatus as R,generateFragment as N,generateFragmentFromRange as S,isValidRangeForFragmentGeneration as k,setFragmentGenerationTimeout as v}from"./vendor/text-fragments-polyfill/textFragmentGenerator.js";export{l as BINDING_PUNCT_CLASS,R as GenerateFragmentStatus,r as adjustColorForContrast,o as checkContrast,n as colorToRgba,u as decodeTextFragmentDirective,L as forTesting,N as generateFragment,S as generateFragmentFromRange,a as getContrastingTextColor,s as getLuminance,h as internal,i as isDarkColor,g as isLightColor,k as isValidRangeForFragmentGeneration,D as processTextFragmentDirective,c as sML,x as sMLWithRequest,v as setFragmentGenerationTimeout,p as ssmlAttrEscape,C as ssmlTextEscape,T as startsWithBindingPunct};
package/dist/text.js ADDED
@@ -0,0 +1 @@
1
+ const t="\\p{Pe}\\p{Pf}.,;:!?,。、;:!?،؛؟",c=new RegExp(`^[${t}]`,"u");function p(e){return c.test(e)}const s=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),a=e=>e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");export{t as BINDING_PUNCT_CLASS,a as ssmlAttrEscape,s as ssmlTextEscape,p as startsWithBindingPunct};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/helpers",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "description": "General-purpose browser helpers for Readium packages",
6
6
  "author": "readium",
@@ -29,7 +29,7 @@
29
29
  "types"
30
30
  ],
31
31
  "engines": {
32
- "node": ">=18"
32
+ "node": ">=24"
33
33
  },
34
34
  "dependencies": {
35
35
  "user-agent-data-types": "^0.4.2"
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./color.ts";
2
2
  export * from "./sML.ts";
3
+ export * from "./text.ts";
3
4
  export * from "./textFragmentDirective.ts";
4
5
  export * from "./vendor/text-fragments-polyfill/textFragmentMatcher.ts";
5
6
  export * from "./vendor/text-fragments-polyfill/textFragmentGenerator.ts";
package/src/text.ts ADDED
@@ -0,0 +1,13 @@
1
+ // Backward-binding: closing brackets/quotes (Pe/Pf) plus terminal marks (.,;:!? and CJK/Arabic equivalents).
2
+ export const BINDING_PUNCT_CLASS = "\\p{Pe}\\p{Pf}.,;:!?,。、;:!?،؛؟";
3
+
4
+ const BINDING_PUNCT_RE = new RegExp(`^[${BINDING_PUNCT_CLASS}]`, "u");
5
+
6
+ export function startsWithBindingPunct(s: string): boolean {
7
+ return BINDING_PUNCT_RE.test(s);
8
+ }
9
+
10
+ export const ssmlTextEscape = (s: string) =>
11
+ s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
12
+ export const ssmlAttrEscape = (s: string) =>
13
+ s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
@@ -1,5 +1,6 @@
1
1
  export * from "./color.ts";
2
2
  export * from "./sML.ts";
3
+ export * from "./text.ts";
3
4
  export * from "./textFragmentDirective.ts";
4
5
  export * from "./vendor/text-fragments-polyfill/textFragmentMatcher.ts";
5
6
  export * from "./vendor/text-fragments-polyfill/textFragmentGenerator.ts";
@@ -0,0 +1,4 @@
1
+ export declare const BINDING_PUNCT_CLASS = "\\p{Pe}\\p{Pf}.,;:!?\uFF0C\u3002\u3001\uFF1B\uFF1A\uFF01\uFF1F\u060C\u061B\u061F";
2
+ export declare function startsWithBindingPunct(s: string): boolean;
3
+ export declare const ssmlTextEscape: (s: string) => string;
4
+ export declare const ssmlAttrEscape: (s: string) => string;