@glassly/miniapp 0.3.3-dev.642 → 0.3.3-dev.645
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/display/index.d.ts +2 -2
- package/dist/display/index.d.ts.map +1 -1
- package/dist/display/index.js +1 -1
- package/dist/display/index.js.map +1 -1
- package/dist/display/wrapper/index.d.ts +2 -0
- package/dist/display/wrapper/index.d.ts.map +1 -1
- package/dist/display/wrapper/index.js +1 -0
- package/dist/display/wrapper/index.js.map +1 -1
- package/dist/display/wrapper/normalize.d.ts +23 -0
- package/dist/display/wrapper/normalize.d.ts.map +1 -0
- package/dist/display/wrapper/normalize.js +38 -0
- package/dist/display/wrapper/normalize.js.map +1 -0
- package/package.json +2 -2
- package/src/display/index.ts +2 -2
- package/src/display/wrapper/index.ts +2 -0
- package/src/display/wrapper/normalize.ts +46 -0
package/dist/display/index.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ export { G1_PROFILE, G1_PROFILE_LEGACY, G1_HYPHEN_WIDTH_PX, G1_SPACE_WIDTH_PX, G
|
|
|
12
12
|
export { TextMeasurer } from "./measurer";
|
|
13
13
|
export type { CharMeasurement, TextMeasurement } from "./measurer";
|
|
14
14
|
export { detectScript, isCJKCharacter, isKoreanCharacter, isUniformWidthScript, isUnsupportedScript, needsHyphenForBreak, SCRIPT_RANGES, } from "./measurer";
|
|
15
|
-
export { TextWrapper, DEFAULT_WRAP_OPTIONS } from "./wrapper";
|
|
16
|
-
export type { WrapOptions, WrapResult, LineMetrics, BreakMode } from "./wrapper";
|
|
15
|
+
export { TextWrapper, DEFAULT_WRAP_OPTIONS, normalizeDisplayText } from "./wrapper";
|
|
16
|
+
export type { WrapOptions, WrapResult, LineMetrics, BreakMode, NormalizeDisplayTextOptions } from "./wrapper";
|
|
17
17
|
export { pixelArtElement, pixelArtPng, pixelArtSize, pixelLevel } from "./pixelArt";
|
|
18
18
|
export type { PixelArt } from "./pixelArt";
|
|
19
19
|
export type { FrameElement, SceneAnchor, SceneBox, SceneBoxInput, SceneBreakMode, SceneChange, SceneDisplayCapabilities, SceneElementInput, SceneElementType, SceneFrame, SceneImageStyle, ScenePoint, SceneProcessResult, SceneRectStyle, SceneShapeStyle, SceneStrokeStyle, SceneTextStyle, SceneTransition, } from "./scene/types";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/display/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,YAAY,EACV,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,UAAU,GACX,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,EACX,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAC,YAAY,EAAC,MAAM,YAAY,CAAA;AACvC,YAAY,EAAC,eAAe,EAAE,eAAe,EAAC,MAAM,YAAY,CAAA;AAChE,OAAO,EACL,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,GACd,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAC,WAAW,EAAE,oBAAoB,EAAC,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/display/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,YAAY,EACV,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,UAAU,GACX,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EACl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B,EAAE,aAAa,EAAC,MAAM,oBAAoB,CAAA"}
|
package/dist/display/index.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
export { G1_PROFILE, G1_PROFILE_LEGACY, G1_HYPHEN_WIDTH_PX, G1_SPACE_WIDTH_PX, G2_PROFILE, G2_HYPHEN_WIDTH_PX, G2_SPACE_WIDTH_PX, Z100_PROFILE, Z100_HYPHEN_WIDTH_PX, Z100_SPACE_WIDTH_PX, NEX_PROFILE, NEX_HYPHEN_WIDTH_PX, NEX_SPACE_WIDTH_PX, RAYNEO_IO_PROFILE, RAYNEO_IO_HYPHEN_WIDTH_PX, RAYNEO_IO_SPACE_WIDTH_PX, } from "./profiles";
|
|
11
11
|
export { TextMeasurer } from "./measurer";
|
|
12
12
|
export { detectScript, isCJKCharacter, isKoreanCharacter, isUniformWidthScript, isUnsupportedScript, needsHyphenForBreak, SCRIPT_RANGES, } from "./measurer";
|
|
13
|
-
export { TextWrapper, DEFAULT_WRAP_OPTIONS } from "./wrapper";
|
|
13
|
+
export { TextWrapper, DEFAULT_WRAP_OPTIONS, normalizeDisplayText } from "./wrapper";
|
|
14
14
|
export { pixelArtElement, pixelArtPng, pixelArtSize, pixelLevel } from "./pixelArt";
|
|
15
15
|
export { boxesEqual, contentHash, elementContentHash, MAX_SCENE_DEPTH, POINT_SHAPE_ARITY, POINT_SHAPE_TYPES, } from "./scene/types";
|
|
16
16
|
export { SHAPE_TYPES, sceneGeometry, geometryEqual, tweenAt, levelOpacity } from "../mirror/geometry";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/display/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAUH,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,EACX,mBAAmB,EAC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9,4 +9,6 @@
|
|
|
9
9
|
export { TextWrapper } from "./TextWrapper";
|
|
10
10
|
export type { WrapOptions, WrapResult, LineMetrics, BreakMode } from "./types";
|
|
11
11
|
export { DEFAULT_WRAP_OPTIONS } from "./types";
|
|
12
|
+
export { normalizeDisplayText } from "./normalize";
|
|
13
|
+
export type { NormalizeDisplayTextOptions } from "./normalize";
|
|
12
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/display/wrapper/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAA;AAGzC,YAAY,EAAC,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AAC5E,OAAO,EAAC,oBAAoB,EAAC,MAAM,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/display/wrapper/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAA;AAGzC,YAAY,EAAC,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAC,MAAM,SAAS,CAAA;AAC5E,OAAO,EAAC,oBAAoB,EAAC,MAAM,SAAS,CAAA;AAC5C,OAAO,EAAC,oBAAoB,EAAC,MAAM,aAAa,CAAA;AAChD,YAAY,EAAC,2BAA2B,EAAC,MAAM,aAAa,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/display/wrapper/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,aAAa;AACb,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAA;AAIzC,OAAO,EAAC,oBAAoB,EAAC,MAAM,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/display/wrapper/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,aAAa;AACb,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAA;AAIzC,OAAO,EAAC,oBAAoB,EAAC,MAAM,SAAS,CAAA;AAC5C,OAAO,EAAC,oBAAoB,EAAC,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text from the phone (notification titles and bodies above all) arrives
|
|
3
|
+
* with whatever the sending app put in it: no-break and thin spaces, tabs,
|
|
4
|
+
* zero-width joiners, bidi marks, soft hyphens, a BOM, Windows line ends,
|
|
5
|
+
* runs of spaces and indented lines. The glasses' fonts draw the invisible
|
|
6
|
+
* ones as nothing or as a blank glyph and the wrapper keeps them, so a row
|
|
7
|
+
* can start with what looks like a space. Normalizing once, before layout,
|
|
8
|
+
* makes that impossible: every row starts and ends on a visible character.
|
|
9
|
+
*/
|
|
10
|
+
export interface NormalizeDisplayTextOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Keep line breaks as row breaks (default). With `false` every break
|
|
13
|
+
* becomes a space, for a title or any one-row field.
|
|
14
|
+
*/
|
|
15
|
+
multiLine?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* `text` with only visible characters and plain single spaces: no row of
|
|
19
|
+
* the result starts or ends with whitespace, and no empty rows remain.
|
|
20
|
+
* Idempotent; an all-whitespace input becomes "".
|
|
21
|
+
*/
|
|
22
|
+
export declare function normalizeDisplayText(text: string, options?: NormalizeDisplayTextOptions): string;
|
|
23
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/display/wrapper/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAWH,MAAM,WAAW,2BAA2B;IAC1C;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,2BAAgC,GAAG,MAAM,CAapG"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text from the phone (notification titles and bodies above all) arrives
|
|
3
|
+
* with whatever the sending app put in it: no-break and thin spaces, tabs,
|
|
4
|
+
* zero-width joiners, bidi marks, soft hyphens, a BOM, Windows line ends,
|
|
5
|
+
* runs of spaces and indented lines. The glasses' fonts draw the invisible
|
|
6
|
+
* ones as nothing or as a blank glyph and the wrapper keeps them, so a row
|
|
7
|
+
* can start with what looks like a space. Normalizing once, before layout,
|
|
8
|
+
* makes that impossible: every row starts and ends on a visible character.
|
|
9
|
+
*/
|
|
10
|
+
/** Format characters (Unicode Cf: zero-width space and joiners, bidi marks and isolates, soft hyphen, BOM, word joiner). */
|
|
11
|
+
const FORMAT_CHARS = /\p{Cf}/gu;
|
|
12
|
+
/** Control characters except the line feed, which `multiLine` keeps as a row break. */
|
|
13
|
+
const CONTROL_CHARS = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F]/g;
|
|
14
|
+
/** Every horizontal whitespace (Unicode Zs, tab, and the no-break variants) as one plain space. */
|
|
15
|
+
const HORIZONTAL_SPACE = /[\p{Zs}\t\u00a0\u1680\u180e\u2000-\u200a\u202f\u205f\u3000]+/gu;
|
|
16
|
+
/** Vertical whitespace other than the line feed: CR, VT, FF, NEL, line and paragraph separators. */
|
|
17
|
+
const OTHER_LINE_BREAKS = /\r\n|[\r\u000B\u000C\u0085\u2028\u2029]/g;
|
|
18
|
+
/**
|
|
19
|
+
* `text` with only visible characters and plain single spaces: no row of
|
|
20
|
+
* the result starts or ends with whitespace, and no empty rows remain.
|
|
21
|
+
* Idempotent; an all-whitespace input becomes "".
|
|
22
|
+
*/
|
|
23
|
+
export function normalizeDisplayText(text, options = {}) {
|
|
24
|
+
const multiLine = options.multiLine ?? true;
|
|
25
|
+
let out = String(text ?? "")
|
|
26
|
+
.replace(OTHER_LINE_BREAKS, "\n")
|
|
27
|
+
.replace(FORMAT_CHARS, "")
|
|
28
|
+
.replace(CONTROL_CHARS, "")
|
|
29
|
+
.replace(HORIZONTAL_SPACE, " ");
|
|
30
|
+
if (!multiLine)
|
|
31
|
+
out = out.replace(/\n+/g, " ");
|
|
32
|
+
const rows = out
|
|
33
|
+
.split("\n")
|
|
34
|
+
.map((row) => row.replace(/ +/g, " ").trim())
|
|
35
|
+
.filter((row) => row.length > 0);
|
|
36
|
+
return rows.join("\n");
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../../src/display/wrapper/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,4HAA4H;AAC5H,MAAM,YAAY,GAAG,UAAU,CAAA;AAC/B,uFAAuF;AACvF,MAAM,aAAa,GAAG,4CAA4C,CAAA;AAClE,mGAAmG;AACnG,MAAM,gBAAgB,GAAG,gEAAgE,CAAA;AACzF,oGAAoG;AACpG,MAAM,iBAAiB,GAAG,0CAA0C,CAAA;AAUpE;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY,EAAE,UAAuC,EAAE;IAC1F,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAA;IAC3C,IAAI,GAAG,GAAG,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;SACzB,OAAO,CAAC,iBAAiB,EAAE,IAAI,CAAC;SAChC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;SACzB,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;SAC1B,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAA;IACjC,IAAI,CAAC,SAAS;QAAE,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9C,MAAM,IAAI,GAAG,GAAG;SACb,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;SAC5C,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAClC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glassly/miniapp",
|
|
3
|
-
"version": "0.3.3-dev.
|
|
3
|
+
"version": "0.3.3-dev.645",
|
|
4
4
|
"description": "SDK for building Glassly local miniapps (browser/WebView)",
|
|
5
5
|
"author": "Glassly Labs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@glassly/cloud-protocol": "0.3.3-dev.
|
|
76
|
+
"@glassly/cloud-protocol": "0.3.3-dev.645",
|
|
77
77
|
"eventemitter3": "^5.0.1"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
package/src/display/index.ts
CHANGED
|
@@ -47,8 +47,8 @@ export {
|
|
|
47
47
|
SCRIPT_RANGES,
|
|
48
48
|
} from "./measurer"
|
|
49
49
|
|
|
50
|
-
export {TextWrapper, DEFAULT_WRAP_OPTIONS} from "./wrapper"
|
|
51
|
-
export type {WrapOptions, WrapResult, LineMetrics, BreakMode} from "./wrapper"
|
|
50
|
+
export {TextWrapper, DEFAULT_WRAP_OPTIONS, normalizeDisplayText} from "./wrapper"
|
|
51
|
+
export type {WrapOptions, WrapResult, LineMetrics, BreakMode, NormalizeDisplayTextOptions} from "./wrapper"
|
|
52
52
|
|
|
53
53
|
export {pixelArtElement, pixelArtPng, pixelArtSize, pixelLevel} from "./pixelArt"
|
|
54
54
|
export type {PixelArt} from "./pixelArt"
|
|
@@ -13,3 +13,5 @@ export {TextWrapper} from "./TextWrapper"
|
|
|
13
13
|
// Types
|
|
14
14
|
export type {WrapOptions, WrapResult, LineMetrics, BreakMode} from "./types"
|
|
15
15
|
export {DEFAULT_WRAP_OPTIONS} from "./types"
|
|
16
|
+
export {normalizeDisplayText} from "./normalize"
|
|
17
|
+
export type {NormalizeDisplayTextOptions} from "./normalize"
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text from the phone (notification titles and bodies above all) arrives
|
|
3
|
+
* with whatever the sending app put in it: no-break and thin spaces, tabs,
|
|
4
|
+
* zero-width joiners, bidi marks, soft hyphens, a BOM, Windows line ends,
|
|
5
|
+
* runs of spaces and indented lines. The glasses' fonts draw the invisible
|
|
6
|
+
* ones as nothing or as a blank glyph and the wrapper keeps them, so a row
|
|
7
|
+
* can start with what looks like a space. Normalizing once, before layout,
|
|
8
|
+
* makes that impossible: every row starts and ends on a visible character.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Format characters (Unicode Cf: zero-width space and joiners, bidi marks and isolates, soft hyphen, BOM, word joiner). */
|
|
12
|
+
const FORMAT_CHARS = /\p{Cf}/gu
|
|
13
|
+
/** Control characters except the line feed, which `multiLine` keeps as a row break. */
|
|
14
|
+
const CONTROL_CHARS = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F]/g
|
|
15
|
+
/** Every horizontal whitespace (Unicode Zs, tab, and the no-break variants) as one plain space. */
|
|
16
|
+
const HORIZONTAL_SPACE = /[\p{Zs}\t\u00a0\u1680\u180e\u2000-\u200a\u202f\u205f\u3000]+/gu
|
|
17
|
+
/** Vertical whitespace other than the line feed: CR, VT, FF, NEL, line and paragraph separators. */
|
|
18
|
+
const OTHER_LINE_BREAKS = /\r\n|[\r\u000B\u000C\u0085\u2028\u2029]/g
|
|
19
|
+
|
|
20
|
+
export interface NormalizeDisplayTextOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Keep line breaks as row breaks (default). With `false` every break
|
|
23
|
+
* becomes a space, for a title or any one-row field.
|
|
24
|
+
*/
|
|
25
|
+
multiLine?: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* `text` with only visible characters and plain single spaces: no row of
|
|
30
|
+
* the result starts or ends with whitespace, and no empty rows remain.
|
|
31
|
+
* Idempotent; an all-whitespace input becomes "".
|
|
32
|
+
*/
|
|
33
|
+
export function normalizeDisplayText(text: string, options: NormalizeDisplayTextOptions = {}): string {
|
|
34
|
+
const multiLine = options.multiLine ?? true
|
|
35
|
+
let out = String(text ?? "")
|
|
36
|
+
.replace(OTHER_LINE_BREAKS, "\n")
|
|
37
|
+
.replace(FORMAT_CHARS, "")
|
|
38
|
+
.replace(CONTROL_CHARS, "")
|
|
39
|
+
.replace(HORIZONTAL_SPACE, " ")
|
|
40
|
+
if (!multiLine) out = out.replace(/\n+/g, " ")
|
|
41
|
+
const rows = out
|
|
42
|
+
.split("\n")
|
|
43
|
+
.map((row) => row.replace(/ +/g, " ").trim())
|
|
44
|
+
.filter((row) => row.length > 0)
|
|
45
|
+
return rows.join("\n")
|
|
46
|
+
}
|