@nativescript-community/ui-label 1.1.24 → 1.2.2

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/label.android.d.ts +0 -1
  3. package/label.android.js +29 -9
  4. package/label.ios.d.ts +6 -9
  5. package/label.ios.js +86 -222
  6. package/package.json +3 -3
  7. package/platforms/android/include.gradle +1 -1
  8. package/platforms/android/native-api-usage.json +15 -0
  9. package/pnpm-global/5/node_modules/.modules.yaml +0 -22
  10. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/CHANGELOG.md +0 -212
  11. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/LICENSE +0 -201
  12. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/README.md +0 -14
  13. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index-common.d.ts +0 -40
  14. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index-common.js +0 -208
  15. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.android.d.ts +0 -27
  16. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.android.js +0 -298
  17. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.d.ts +0 -1
  18. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.ios.d.ts +0 -14
  19. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.ios.js +0 -189
  20. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.js +0 -25
  21. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/package.json +0 -34
  22. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/AndroidManifest.xml +0 -3
  23. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/BaselineAdjustedSpan.java +0 -71
  24. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/CustomBackgroundSpan.java +0 -70
  25. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/CustomTypefaceSpan.java +0 -37
  26. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/Font.java +0 -431
  27. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/HeightSpan.java +0 -81
  28. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/HtmlToSpannedConverter.java +0 -690
  29. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/URLSpanNoUnderline.java +0 -24
  30. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/typings/DTCoreText.ios.d.ts +0 -22
  31. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/typings/android.d.ts +0 -32
  32. package/pnpm-global/5/node_modules/.pnpm/lock.yaml +0 -13
  33. package/pnpm-global/5/pnpm-lock.yaml +0 -13
@@ -1,189 +0,0 @@
1
- import { Color, Font, FormattedString } from '@nativescript/core';
2
- import { getTransformedText } from '@nativescript/core/ui/text-base';
3
- import { computeBaseLineOffset, getMaxFontSize, textAlignmentConverter } from './index-common';
4
- export * from './index-common';
5
- let iOSUseDTCoreText = false;
6
- export function enableIOSDTCoreText() {
7
- iOSUseDTCoreText = true;
8
- }
9
- export function init() { }
10
- function _createNativeAttributedString({ text, familyName = '-apple-system', fontSize, fontWeight, letterSpacing, lineHeight, color, textAlignment, }) {
11
- let htmlString;
12
- if (iOSUseDTCoreText) {
13
- htmlString =
14
- color || familyName || fontSize
15
- ? `<span style=" ${color ? `color: ${color};` : ''} ${familyName ? `font-family:'${familyName.replace(/'/g, '')}';` : ''}${fontSize ? `font-size: ${fontSize}px;` : ''}${fontWeight ? `font-weight: ${fontWeight};` : ''}">${text}</span>`
16
- : text;
17
- // `<span style="font-family: ${fontFamily}; font-size:${fontSize};">${htmlString}</span>`;
18
- }
19
- else {
20
- htmlString =
21
- color || familyName || fontSize
22
- ? `<style>body{ ${color ? `color: ${color};` : ''} ${familyName ? `font-family:"${familyName.replace(/'/g, '')}";` : ''}${fontSize ? `font-size: ${fontSize}px;` : ''}${fontWeight ? `font-weight: ${fontWeight};` : ''}}</style>${text}`
23
- : text;
24
- }
25
- const nsString = NSString.stringWithString(htmlString);
26
- const nsData = nsString.dataUsingEncoding(NSUTF16StringEncoding);
27
- let attrText;
28
- if (iOSUseDTCoreText) {
29
- // on iOS 13.3 there is bug with the system font
30
- // https://github.com/Cocoanetics/DTCoreText/issues/1168
31
- const options = {
32
- [DTDefaultTextAlignment]: kCTLeftTextAlignment,
33
- // [NSTextSizeMultiplierDocumentOption]: 1,
34
- // [DTIgnoreLinkStyleOption]: false,
35
- // [DTDefaultFontFamily]: familyName,
36
- // [NSFontAttributeName]: familyName,
37
- // [NSTextSizeMultiplierDocumentOption]: 17 / 12.0,
38
- [DTUseiOS6Attributes]: true,
39
- [DTDocumentPreserveTrailingSpaces]: true,
40
- // [DTDefaultLineBreakMode]: kCTLineBreakByWordWrapping
41
- };
42
- attrText = NSMutableAttributedString.alloc().initWithHTMLDataOptionsDocumentAttributes(nsData, options, null);
43
- attrText.enumerateAttributesInRangeOptionsUsingBlock({ location: 0, length: attrText.length }, NSAttributedStringEnumerationReverse, (attributes, range, stop) => {
44
- if (!!attributes.valueForKey('DTGUID')) {
45
- // We need to remove this attribute or links are not colored right
46
- //
47
- // @see https://github.com/Cocoanetics/DTCoreText/issues/792
48
- attrText.removeAttributeRange('CTForegroundColorFromContext', range);
49
- }
50
- });
51
- }
52
- else {
53
- attrText = NSMutableAttributedString.alloc().initWithDataOptionsDocumentAttributesError(nsData, {
54
- [NSDocumentTypeDocumentAttribute]: NSHTMLTextDocumentType,
55
- }, null);
56
- }
57
- // TODO: letterSpacing should be applied per Span.
58
- if (letterSpacing !== undefined) {
59
- attrText.addAttributeValueRange(NSKernAttributeName, letterSpacing * fontSize, { location: 0, length: attrText.length });
60
- }
61
- if (lineHeight !== undefined) {
62
- const paragraphStyle = NSMutableParagraphStyle.alloc().init();
63
- paragraphStyle.lineSpacing = lineHeight;
64
- // make sure a possible previously set text alignment setting is not lost when line height is specified
65
- paragraphStyle.alignment = textAlignment;
66
- // if (this.nativeTextViewProtected instanceof UILabel) {
67
- // // make sure a possible previously set line break mode is not lost when line height is specified
68
- // paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode;
69
- // }
70
- attrText.addAttributeValueRange(NSParagraphStyleAttributeName, paragraphStyle, { location: 0, length: attrText.length });
71
- }
72
- else if (textAlignment !== undefined) {
73
- const paragraphStyle = NSMutableParagraphStyle.alloc().init();
74
- paragraphStyle.alignment = textAlignment;
75
- attrText.addAttributeValueRange(NSParagraphStyleAttributeName, paragraphStyle, { location: 0, length: attrText.length });
76
- }
77
- return attrText;
78
- }
79
- export function createNativeAttributedString(data, parent) {
80
- if (data instanceof FormattedString) {
81
- const ssb = NSMutableAttributedString.new();
82
- const maxFontSize = getMaxFontSize(data);
83
- data.spans.forEach((s) => {
84
- ssb.appendAttributedString(createSpannable(s, parent, undefined, maxFontSize));
85
- });
86
- return ssb;
87
- }
88
- if (data.textAlignment && typeof data.textAlignment === 'string') {
89
- data.textAlignment = textAlignmentConverter(data.textAlignment);
90
- }
91
- if (data.color && !(data.color instanceof Color)) {
92
- data.color = new Color(data.color);
93
- }
94
- return _createNativeAttributedString(data);
95
- }
96
- export function createSpannable(span, parentView, parent, maxFontSize) {
97
- let text = span.text;
98
- if (!text || span.visibility !== 'visible') {
99
- return null;
100
- }
101
- const attrDict = {};
102
- const fontFamily = span.fontFamily;
103
- const fontSize = span.fontSize;
104
- const realMaxFontSize = Math.max(maxFontSize, parentView.fontSize || 0);
105
- const fontweight = span.fontWeight || 'normal';
106
- const fontstyle = span.fontStyle || (parent && parent.fontStyle) || 'normal';
107
- const textcolor = span.color;
108
- const backgroundcolor = span.backgroundColor || (parent && parent.backgroundColor);
109
- const textDecorations = span.textDecoration || (parent && parent.textDecoration);
110
- const letterSpacing = span.letterSpacing || (parent && parent.letterSpacing);
111
- const lineHeight = span.lineHeight || (parent && parent.lineHeight);
112
- const textAlignment = span.textAlignment || (parent && parent.textAlignment);
113
- const verticaltextalignment = span.verticalTextAlignment;
114
- let iosFont;
115
- if (fontweight || fontstyle || fontFamily || fontSize) {
116
- const font = new Font(fontFamily, fontSize, fontstyle, typeof span.fontWeight === 'string' ? fontweight : (fontweight + ''));
117
- iosFont = font.getUIFont(UIFont.systemFontOfSize(fontSize));
118
- attrDict[NSFontAttributeName] = iosFont;
119
- }
120
- if (verticaltextalignment && verticaltextalignment !== 'initial' && iosFont) {
121
- const ascent = CTFontGetAscent(iosFont);
122
- const descent = CTFontGetDescent(iosFont);
123
- attrDict[NSBaselineOffsetAttributeName] = -computeBaseLineOffset(verticaltextalignment, -ascent, descent, -iosFont.descender, -iosFont.ascender, fontSize, realMaxFontSize);
124
- }
125
- // if (span._tappable) {
126
- // attrDict[NSLinkAttributeName] = text;
127
- // }
128
- if (textcolor) {
129
- const color = textcolor instanceof Color ? textcolor : new Color(textcolor);
130
- attrDict[NSForegroundColorAttributeName] = color.ios;
131
- }
132
- if (backgroundcolor) {
133
- const color = backgroundcolor instanceof Color ? backgroundcolor : new Color(backgroundcolor);
134
- attrDict[NSBackgroundColorAttributeName] = color.ios;
135
- }
136
- if (letterSpacing) {
137
- attrDict[NSKernAttributeName] = letterSpacing * iosFont.pointSize;
138
- }
139
- let paragraphStyle;
140
- if (lineHeight !== undefined) {
141
- paragraphStyle = NSMutableParagraphStyle.alloc().init();
142
- switch (textAlignment) {
143
- case 'middle':
144
- case 'center':
145
- paragraphStyle.alignment = 1 /* Center */;
146
- break;
147
- case 'right':
148
- paragraphStyle.alignment = 2 /* Right */;
149
- break;
150
- default:
151
- paragraphStyle.alignment = 0 /* Left */;
152
- break;
153
- }
154
- paragraphStyle.minimumLineHeight = lineHeight;
155
- paragraphStyle.maximumLineHeight = lineHeight;
156
- }
157
- if (paragraphStyle) {
158
- attrDict[NSParagraphStyleAttributeName] = paragraphStyle;
159
- }
160
- if (textDecorations) {
161
- const underline = textDecorations.indexOf('underline') !== -1;
162
- if (underline) {
163
- attrDict[NSUnderlineStyleAttributeName] = underline;
164
- }
165
- const strikethrough = textDecorations.indexOf('line-through') !== -1;
166
- if (strikethrough) {
167
- attrDict[NSStrikethroughStyleAttributeName] = strikethrough;
168
- }
169
- }
170
- if (!(text instanceof NSAttributedString)) {
171
- if (!(typeof text === 'string')) {
172
- text = text.toString();
173
- }
174
- if (text.indexOf('\n') !== -1) {
175
- text = text.replace(/\\n/g, '\u{2029}');
176
- }
177
- const textTransform = span.textTransform || (parent && parent.textTransform);
178
- if (textTransform) {
179
- text = getTransformedText(text, textTransform);
180
- }
181
- return NSMutableAttributedString.alloc().initWithStringAttributes(text, attrDict);
182
- }
183
- else {
184
- const result = NSMutableAttributedString.alloc().initWithAttributedString(text);
185
- result.setAttributesRange(attrDict, { location: 0, length: text.length });
186
- return result;
187
- }
188
- }
189
- //# sourceMappingURL=index.ios.js.map
@@ -1,25 +0,0 @@
1
- import { InheritedCssProperty, makeParser, makeValidator, Style } from '@nativescript/core';
2
- export const cssProperty = (target, key) => {
3
- // property getter
4
- const getter = function () {
5
- return this.style[key];
6
- };
7
- // property setter
8
- const setter = function (newVal) {
9
- this.style[key] = newVal;
10
- };
11
- Object.defineProperty(target, key, {
12
- get: getter,
13
- set: setter,
14
- enumerable: true,
15
- configurable: true,
16
- });
17
- };
18
- export const verticalTextAlignmentConverter = makeParser(makeValidator('initial', 'top', 'middle', 'bottom', 'center'));
19
- export const verticalTextAlignmentProperty = new InheritedCssProperty({
20
- name: 'verticalTextAlignment',
21
- cssName: 'vertical-text-align',
22
- valueConverter: verticalTextAlignmentConverter,
23
- });
24
- verticalTextAlignmentProperty.register(Style);
25
- //# sourceMappingURL=index.js.map
@@ -1,34 +0,0 @@
1
- {
2
- "name": "@nativescript-community/text",
3
- "version": "1.4.11",
4
- "description": "Expands the capabilities of NativeScript's text property.",
5
- "main": "./index",
6
- "sideEffects": false,
7
- "typings": "./index.d.ts",
8
- "nativescript": {
9
- "platforms": {
10
- "android": "3.0.0",
11
- "ios": "3.0.0"
12
- }
13
- },
14
- "keywords": [
15
- "NativeScript",
16
- "JavaScript",
17
- "Android",
18
- "iOS"
19
- ],
20
- "author": {
21
- "name": "Martin Guillon",
22
- "email": "martin@akylas.fr"
23
- },
24
- "bugs": {
25
- "url": "https://github.com/nativescript-community/text/issues"
26
- },
27
- "repository": {
28
- "type": "git",
29
- "url": "https://github.com/nativescript-community/text"
30
- },
31
- "license": "Apache-2.0",
32
- "readmeFilename": "README.md",
33
- "gitHead": "d4d2dd438df7c0841d32f987cabad03062a96602"
34
- }
@@ -1,3 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.nativescript.text">
3
- </manifest>
@@ -1,71 +0,0 @@
1
- package com.nativescript.text;
2
-
3
- import android.graphics.Paint;
4
- import android.text.TextPaint;
5
- import android.text.style.CharacterStyle;
6
-
7
- import android.util.Log;
8
-
9
- public class BaselineAdjustedSpan extends CharacterStyle {
10
- private float fontSize;
11
- private String align;
12
- private float maxFontSize;
13
-
14
- public BaselineAdjustedSpan(float fontSize, String align, float maxFontSize) {
15
- super();
16
- this.fontSize = fontSize;
17
- this.align = align;
18
- this.maxFontSize = maxFontSize;
19
- }
20
-
21
- @Override
22
- public void updateDrawState(TextPaint ds) {
23
- this.updateState(ds);
24
- }
25
-
26
- private int computeBaseLineOffset(String align, float fontAscent, float fontDescent, float fontBottom,
27
- float fontTop, float fontSize, float maxFontSize) {
28
- int result = 0;
29
- switch (align) {
30
- case "top":
31
- result = (int) (-maxFontSize - fontBottom - fontTop);
32
- break;
33
-
34
- case "bottom":
35
- result = (int) fontBottom;
36
- break;
37
-
38
- case "text-top":
39
- result = (int) (-maxFontSize - fontDescent - fontAscent);
40
- break;
41
-
42
- case "text-bottom":
43
- result = (int) (fontBottom - fontDescent);
44
- break;
45
-
46
- case "middle":
47
- case "center":
48
- result = (int) ((fontAscent - fontDescent) / 2 - fontAscent - maxFontSize / 2);
49
- break;
50
-
51
- case "super":
52
- result = -(int) (maxFontSize - fontSize);
53
- break;
54
-
55
- case "sub":
56
- result = 0;
57
- break;
58
- }
59
- return result;
60
- }
61
-
62
- public void updateState(TextPaint paint) {
63
- paint.setTextSize(fontSize);
64
- Paint.FontMetrics metrics = paint.getFontMetrics();
65
- // TODO: when or why should we add bottom?
66
- // result += metrics.bottom;
67
- int baselineShift = computeBaseLineOffset(align, metrics.ascent, metrics.descent, metrics.bottom, metrics.top,
68
- fontSize, maxFontSize);
69
- paint.baselineShift = baselineShift;
70
- }
71
- }
@@ -1,70 +0,0 @@
1
- package com.nativescript.text;
2
- import android.graphics.Canvas;
3
- import android.graphics.Paint;
4
- import android.graphics.Rect;
5
- import android.graphics.drawable.ShapeDrawable;
6
- import android.graphics.drawable.shapes.RoundRectShape;
7
- import android.graphics.drawable.shapes.Shape;
8
- import android.text.style.ReplacementSpan;
9
-
10
- public class CustomBackgroundSpan extends ReplacementSpan {
11
- public static class RoundedRectDrawable extends ShapeDrawable {
12
- private final Paint fillpaint, strokepaint;
13
- public RoundedRectDrawable(int radius, int fillColor, int strokeColor, int strokeWidth) {
14
- super(new RoundRectShape(new float[] { radius, radius, radius, radius, radius, radius, radius, radius },
15
- null, null));
16
- fillpaint = new Paint(this.getPaint());
17
- fillpaint.setColor(fillColor);
18
- strokepaint = new Paint(fillpaint);
19
- strokepaint.setStyle(Paint.Style.STROKE);
20
- strokepaint.setStrokeWidth(strokeWidth);
21
- strokepaint.setColor(strokeColor);
22
- }
23
-
24
- @Override
25
- protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
26
- shape.draw(canvas, fillpaint);
27
- shape.draw(canvas, strokepaint);
28
- }
29
- }
30
- private RoundedRectDrawable mDrawable;
31
-
32
- int radius;
33
- int fillColor;
34
- int strokeColor;
35
- int strokeWidth;
36
-
37
- public CustomBackgroundSpan(int radius, int fillColor, int strokeColor, int strokeWidth) {
38
- this.mDrawable = new RoundedRectDrawable(radius, fillColor, strokeColor, strokeWidth);
39
- this.radius = radius;
40
- this.fillColor = fillColor;
41
- this.strokeColor = strokeColor;
42
- this.strokeWidth = strokeWidth;
43
- }
44
-
45
- public CustomBackgroundSpan(CustomBackgroundSpan toCopy) {
46
- this(toCopy.radius, toCopy.fillColor, toCopy.strokeColor, toCopy.strokeWidth);
47
- }
48
-
49
- @Override
50
- public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
51
- return measureText(paint, text, start, end);
52
-
53
- }
54
-
55
- private int measureText(Paint paint, CharSequence text, int start, int end) {
56
- return Math.round(paint.measureText(text, start, end));
57
- }
58
-
59
- @Override
60
- public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
61
- float dx = strokeWidth / 2;
62
- Rect rect = new Rect((int)(x + dx), (int)(top + dx), (int)(x + measureText(paint, text, start, end) - strokeWidth/2), (int)(bottom - strokeWidth/2));
63
- this.mDrawable.setBounds(rect);
64
- canvas.save();
65
- this.mDrawable.draw(canvas);
66
- canvas.restore();
67
- canvas.drawText(text, start, end, x, y, paint);
68
- }
69
-
70
- }
@@ -1,37 +0,0 @@
1
- package com.nativescript.text;
2
-
3
- import android.annotation.SuppressLint;
4
- import android.graphics.Typeface;
5
- import android.text.TextPaint;
6
- import android.text.style.TypefaceSpan;
7
-
8
- /**
9
- * Created by hhristov on 2/27/17.
10
- */
11
-
12
- @SuppressLint("ParcelCreator")
13
- public class CustomTypefaceSpan extends TypefaceSpan {
14
- private Typeface typeface;
15
-
16
- public CustomTypefaceSpan(String family, Typeface typeface) {
17
- super(family);
18
- this.typeface = typeface;
19
- }
20
-
21
- public Typeface getTypeface() {
22
- return this.typeface;
23
- }
24
-
25
- public void updateDrawState(TextPaint ds) {
26
- this.applyCustomTypeFace(ds);
27
- }
28
-
29
- public void updateMeasureState(TextPaint paint) {
30
- this.applyCustomTypeFace(paint);
31
- }
32
-
33
- private void applyCustomTypeFace(TextPaint paint) {
34
- Typeface typeface = this.typeface;
35
- paint.setTypeface(typeface);
36
- }
37
- }