@nativescript-community/ui-label 1.1.25 → 1.2.3
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/CHANGELOG.md +35 -0
- package/label.android.d.ts +5 -3
- package/label.android.js +48 -12
- package/label.ios.d.ts +3 -7
- package/label.ios.js +66 -200
- package/package.json +3 -3
- package/platforms/android/include.gradle +1 -1
- package/platforms/android/native-api-usage.json +15 -0
- package/platforms/android/java/com/nativescript/label/EllipsizingTextView.java +0 -497
- package/pnpm-global/5/node_modules/.modules.yaml +0 -22
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/CHANGELOG.md +0 -212
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/LICENSE +0 -201
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/README.md +0 -14
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index-common.d.ts +0 -40
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index-common.js +0 -208
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.android.d.ts +0 -27
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.android.js +0 -298
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.d.ts +0 -1
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.ios.d.ts +0 -14
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.ios.js +0 -189
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.js +0 -25
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/package.json +0 -34
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/AndroidManifest.xml +0 -3
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/typings/android.d.ts +0 -32
- package/pnpm-global/5/node_modules/.pnpm/lock.yaml +0 -13
- package/pnpm-global/5/pnpm-lock.yaml +0 -13
@@ -1,27 +0,0 @@
|
|
1
|
-
import { Color, CoreTypes, FormattedString, ViewBase } from '@nativescript/core';
|
2
|
-
export * from './index-common';
|
3
|
-
export declare const typefaceCache: {
|
4
|
-
[k: string]: android.graphics.Typeface;
|
5
|
-
};
|
6
|
-
export declare function init(): void;
|
7
|
-
declare module '@nativescript/core/ui/text-base/formatted-string' {
|
8
|
-
interface FormattedString {
|
9
|
-
toNativeString(maxFontSize?: number): string;
|
10
|
-
}
|
11
|
-
}
|
12
|
-
declare module '@nativescript/core/ui/text-base/span' {
|
13
|
-
interface Span {
|
14
|
-
toNativeString(maxFontSize?: number): string;
|
15
|
-
}
|
16
|
-
}
|
17
|
-
export declare const createNativeAttributedString: (data: {
|
18
|
-
text: string;
|
19
|
-
color?: Color | string | number;
|
20
|
-
familyName?: string;
|
21
|
-
fontSize?: number;
|
22
|
-
fontWeight?: string;
|
23
|
-
letterSpacing?: number;
|
24
|
-
lineHeight?: number;
|
25
|
-
textAlignment?: number | CoreTypes.TextAlignmentType;
|
26
|
-
} | FormattedString, parent: ViewBase) => any;
|
27
|
-
export declare const createSpannable: (span: any, parentView: any, parent?: any, maxFontSize?: number) => any;
|
@@ -1,298 +0,0 @@
|
|
1
|
-
import { Application, Color, FormattedString, Span, backgroundColorProperty, knownFolders, path, profile } from '@nativescript/core';
|
2
|
-
import { Font } from '@nativescript/core/ui/styling/font';
|
3
|
-
import { getTransformedText, textDecorationProperty } from '@nativescript/core/ui/text-base';
|
4
|
-
import { LightFormattedString } from './index-common';
|
5
|
-
import { layout } from '@nativescript/core/utils/utils';
|
6
|
-
export * from './index-common';
|
7
|
-
// eslint-disable-next-line no-redeclare
|
8
|
-
let ClickableSpan;
|
9
|
-
function initializeClickableSpan() {
|
10
|
-
if (ClickableSpan) {
|
11
|
-
return;
|
12
|
-
}
|
13
|
-
var ClickableSpanImpl = /** @class */ (function (_super) {
|
14
|
-
__extends(ClickableSpanImpl, _super);
|
15
|
-
function ClickableSpanImpl(owner) {
|
16
|
-
var _this = _super.call(this) || this;
|
17
|
-
_this.owner = new WeakRef(owner);
|
18
|
-
return global.__native(_this);
|
19
|
-
}
|
20
|
-
ClickableSpanImpl.prototype.onClick = function (view) {
|
21
|
-
var owner = this.owner.get();
|
22
|
-
if (owner) {
|
23
|
-
owner._emit(Span.linkTapEvent);
|
24
|
-
}
|
25
|
-
view.clearFocus();
|
26
|
-
view.invalidate();
|
27
|
-
};
|
28
|
-
ClickableSpanImpl.prototype.updateDrawState = function (tp) {
|
29
|
-
// don't style as link
|
30
|
-
};
|
31
|
-
return ClickableSpanImpl;
|
32
|
-
}(android.text.style.ClickableSpan));
|
33
|
-
ClickableSpan = ClickableSpanImpl;
|
34
|
-
}
|
35
|
-
export const typefaceCache = {};
|
36
|
-
let context;
|
37
|
-
const fontPath = path.join(knownFolders.currentApp().path, 'fonts');
|
38
|
-
let initialized = false;
|
39
|
-
export function init() {
|
40
|
-
if (initialized) {
|
41
|
-
return;
|
42
|
-
}
|
43
|
-
initialized = true;
|
44
|
-
context = Application.android.context;
|
45
|
-
Font.prototype.getAndroidTypeface = profile('getAndroidTypeface', function () {
|
46
|
-
var _a;
|
47
|
-
if (!this._typeface) {
|
48
|
-
// css loader to json transform font-family: res/toto to font-family: res,toto
|
49
|
-
const fontFamily = ((_a = this.fontFamily) === null || _a === void 0 ? void 0 : _a.replace(/res,/g, 'res/')) || '';
|
50
|
-
const fontCacheKey = fontFamily + (this.fontWeight || '') + (this.fontStyle || '');
|
51
|
-
const typeface = typefaceCache[fontCacheKey];
|
52
|
-
if (!typeface) {
|
53
|
-
if (!context) {
|
54
|
-
context = Application.android.context;
|
55
|
-
}
|
56
|
-
this._typeface = typefaceCache[fontCacheKey] = com.nativescript.text.Font.createTypeface(context, fontPath, fontFamily, this.fontWeight, this.isBold, this.isItalic);
|
57
|
-
}
|
58
|
-
else {
|
59
|
-
this._typeface = typeface;
|
60
|
-
}
|
61
|
-
}
|
62
|
-
return this._typeface;
|
63
|
-
});
|
64
|
-
FormattedString.prototype.toNativeString = LightFormattedString.prototype.toNativeString = function () {
|
65
|
-
var _a, _b;
|
66
|
-
let result = '';
|
67
|
-
const length = this.spans.length;
|
68
|
-
let span;
|
69
|
-
let maxFontSize = ((_a = this.style) === null || _a === void 0 ? void 0 : _a.fontSize) || ((_b = this.parent) === null || _b === void 0 ? void 0 : _b.style.fontSize) || 0;
|
70
|
-
for (let i = 0; i < length; i++) {
|
71
|
-
const s = this.spans.getItem(i);
|
72
|
-
if (s.style.fontSize) {
|
73
|
-
maxFontSize = Math.max(maxFontSize, s.style.fontSize);
|
74
|
-
}
|
75
|
-
}
|
76
|
-
for (let i = 0; i < length; i++) {
|
77
|
-
span = this.spans.getItem(i);
|
78
|
-
result += span.toNativeString(maxFontSize) + (i < length - 1 ? String.fromCharCode(0x1f) : '');
|
79
|
-
}
|
80
|
-
return result;
|
81
|
-
};
|
82
|
-
const delimiter = String.fromCharCode(0x1e);
|
83
|
-
Span.prototype.toNativeString = function (maxFontSize) {
|
84
|
-
const textTransform = this.parent.parent.textTransform;
|
85
|
-
const spanStyle = this.style;
|
86
|
-
let backgroundColor;
|
87
|
-
if (backgroundColorProperty.isSet(spanStyle)) {
|
88
|
-
backgroundColor = spanStyle.backgroundColor;
|
89
|
-
}
|
90
|
-
let textDecoration;
|
91
|
-
if (textDecorationProperty.isSet(spanStyle)) {
|
92
|
-
textDecoration = spanStyle.textDecoration;
|
93
|
-
}
|
94
|
-
else if (this.parent.textDecoration) {
|
95
|
-
// span.parent is FormattedString
|
96
|
-
textDecoration = this.parent.style.textDecoration;
|
97
|
-
}
|
98
|
-
else if (textDecorationProperty.isSet(this.parent.parent.style)) {
|
99
|
-
// span.parent.parent is TextBase
|
100
|
-
textDecoration = this.parent.parent.style.textDecorations;
|
101
|
-
}
|
102
|
-
let verticalTextAlignment = this.verticalAlignment || this.parent.verticalAlignment;
|
103
|
-
if (!verticalTextAlignment || verticalTextAlignment === 'stretch') {
|
104
|
-
verticalTextAlignment = this.parent.parent.verticalTextAlignment;
|
105
|
-
}
|
106
|
-
let text = this.text;
|
107
|
-
if (text && textTransform != null && textTransform !== 'none') {
|
108
|
-
text = getTransformedText(text, textTransform);
|
109
|
-
}
|
110
|
-
const density = layout.getDisplayDensity();
|
111
|
-
const result = `${this.fontFamily || 0}${delimiter}\
|
112
|
-
${this.fontSize !== undefined ? this.fontSize * density : -1}${delimiter}\
|
113
|
-
${this.fontWeight || ''}${delimiter}\
|
114
|
-
${this.fontStyle === 'italic' ? 1 : 0}${delimiter}\
|
115
|
-
${textDecoration || 0}${delimiter}\
|
116
|
-
${maxFontSize * density}${delimiter}\
|
117
|
-
${verticalTextAlignment && verticalTextAlignment !== 'stretch' ? verticalTextAlignment : ''}${delimiter}\
|
118
|
-
${this.lineHeight !== undefined ? this.lineHeight * density : -1}${delimiter}\
|
119
|
-
${this.letterSpacing !== undefined ? this.lineHeight * density : 9}${delimiter}\
|
120
|
-
${this.color ? this.color.android : -1}${delimiter}\
|
121
|
-
${backgroundColor ? backgroundColor.android : -1}${delimiter}\
|
122
|
-
${this.text}`;
|
123
|
-
return result;
|
124
|
-
};
|
125
|
-
}
|
126
|
-
function isBold(fontWeight) {
|
127
|
-
return fontWeight === 'bold' || fontWeight === '700' || fontWeight === '800' || fontWeight === '900';
|
128
|
-
}
|
129
|
-
// type BaselineAdjustedSpan = new (fontSize, align: string, maxFontSize) => android.text.style.MetricAffectingSpan;
|
130
|
-
// // eslint-disable-next-line no-redeclare
|
131
|
-
// let BaselineAdjustedSpan: BaselineAdjustedSpan;
|
132
|
-
// function initializeBaselineAdjustedSpan(): void {
|
133
|
-
// if (BaselineAdjustedSpan) {
|
134
|
-
// return;
|
135
|
-
// }
|
136
|
-
// @NativeClass
|
137
|
-
// class BaselineAdjustedSpanImpl extends android.text.style.CharacterStyle {
|
138
|
-
// align: string = 'baseline';
|
139
|
-
// maxFontSize: number;
|
140
|
-
// constructor(private fontSize, align: string, maxFontSize) {
|
141
|
-
// super();
|
142
|
-
// this.align = align;
|
143
|
-
// this.maxFontSize = maxFontSize;
|
144
|
-
// }
|
145
|
-
// updateDrawState(paint: android.text.TextPaint) {
|
146
|
-
// this.updateState(paint);
|
147
|
-
// }
|
148
|
-
// updateState(paint: android.text.TextPaint) {
|
149
|
-
// const fontSize = this.fontSize;
|
150
|
-
// paint.setTextSize(fontSize);
|
151
|
-
// const metrics = paint.getFontMetrics();
|
152
|
-
// let result = computeBaseLineOffset(this.align, metrics.ascent, metrics.descent, metrics.bottom, metrics.top, fontSize, this.maxFontSize);
|
153
|
-
// result += metrics.bottom;
|
154
|
-
// paint.baselineShift = result;
|
155
|
-
// }
|
156
|
-
// }
|
157
|
-
// BaselineAdjustedSpan = BaselineAdjustedSpanImpl as any;
|
158
|
-
// }
|
159
|
-
export const createNativeAttributedString = profile('getAndroidTypeface', function createNativeAttributedString(data, parent) {
|
160
|
-
if (!context) {
|
161
|
-
init();
|
162
|
-
}
|
163
|
-
if (typeof data['toNativeString'] === 'function') {
|
164
|
-
const nativeString = data.toNativeString();
|
165
|
-
return com.nativescript.text.Font.stringBuilderFromFormattedString(context, fontPath, nativeString);
|
166
|
-
}
|
167
|
-
// if (data.textAlignment && typeof data.textAlignment === 'string') {
|
168
|
-
// data.textAlignment = textAlignmentConverter(data.textAlignment);
|
169
|
-
// }
|
170
|
-
// if (data.color && !(data.color instanceof Color)) {
|
171
|
-
// data.color = new Color(data.color as any);
|
172
|
-
// }
|
173
|
-
const result = com.nativescript.text.Font.stringBuilderFromHtmlString(context, fontPath, data.text);
|
174
|
-
return result;
|
175
|
-
});
|
176
|
-
let lineSeparator;
|
177
|
-
let Style;
|
178
|
-
let Spanned;
|
179
|
-
export const createSpannable = profile('createSpannable', function (span, parentView, parent, maxFontSize) {
|
180
|
-
let text = span.text;
|
181
|
-
if (!text || span.visibility !== 'visible') {
|
182
|
-
return null;
|
183
|
-
}
|
184
|
-
const fontSize = span.fontSize;
|
185
|
-
const fontWeight = span.fontWeight || 'normal';
|
186
|
-
const fontStyle = span.fontStyle || (parent && parent.fontStyle) || 'normal';
|
187
|
-
const fontFamily = span.fontFamily;
|
188
|
-
const color = span.color;
|
189
|
-
const textDecorations = span.textDecoration || (parent && parent.textDecoration);
|
190
|
-
const backgroundcolor = span.backgroundColor || (parent && parent.backgroundColor);
|
191
|
-
const verticalTextAlignment = span.verticalTextAlignment;
|
192
|
-
const letterSpacing = span.letterSpacing || (parent && parent.letterSpacing);
|
193
|
-
const lineHeight = span.lineHeight || (parent && parent.lineHeight);
|
194
|
-
const realMaxFontSize = Math.max(maxFontSize, parentView.fontSize || 0);
|
195
|
-
if (typeof text === 'boolean' || typeof text === 'number') {
|
196
|
-
text = text.toString();
|
197
|
-
}
|
198
|
-
const textTransform = span.textTransform || (parent && parent.textTransform);
|
199
|
-
if (textTransform) {
|
200
|
-
text = getTransformedText(text, textTransform);
|
201
|
-
}
|
202
|
-
if (typeof text === 'string') {
|
203
|
-
if (text.indexOf('\n') !== -1) {
|
204
|
-
if (!lineSeparator) {
|
205
|
-
lineSeparator = java.lang.System.getProperty('line.separator');
|
206
|
-
}
|
207
|
-
text = text.replace(/\\n/g, lineSeparator);
|
208
|
-
}
|
209
|
-
}
|
210
|
-
const length = typeof text.length === 'function' ? text.length() : text.length;
|
211
|
-
let ssb = span._ssb;
|
212
|
-
if (!ssb) {
|
213
|
-
span._ssb = ssb = new android.text.SpannableStringBuilder(text);
|
214
|
-
}
|
215
|
-
else {
|
216
|
-
ssb.clear();
|
217
|
-
ssb.clearSpans();
|
218
|
-
ssb.append(text);
|
219
|
-
}
|
220
|
-
if (!Style) {
|
221
|
-
Style = android.text.style;
|
222
|
-
}
|
223
|
-
if (!Spanned) {
|
224
|
-
Spanned = android.text.Spanned;
|
225
|
-
}
|
226
|
-
const bold = isBold(fontWeight);
|
227
|
-
const italic = fontStyle === 'italic';
|
228
|
-
// if (getSDK() < 28) {
|
229
|
-
if (bold && italic) {
|
230
|
-
ssb.setSpan(new Style.StyleSpan(android.graphics.Typeface.BOLD_ITALIC), 0, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
231
|
-
}
|
232
|
-
else if (bold) {
|
233
|
-
ssb.setSpan(new Style.StyleSpan(android.graphics.Typeface.BOLD), 0, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
234
|
-
}
|
235
|
-
else if (italic) {
|
236
|
-
ssb.setSpan(new Style.StyleSpan(android.graphics.Typeface.ITALIC), 0, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
237
|
-
}
|
238
|
-
// }
|
239
|
-
if (fontFamily || (fontWeight !== 'normal' && !bold)) {
|
240
|
-
const fontCacheKey = fontFamily + fontWeight + fontStyle;
|
241
|
-
let typeface = typefaceCache[fontCacheKey];
|
242
|
-
if (!typeface) {
|
243
|
-
if (span.paint) {
|
244
|
-
// let paint: Paint = paintFontCache[fontCacheKey];
|
245
|
-
// if (!paint) {
|
246
|
-
// paint = span.paint;
|
247
|
-
// paint.setFontFamily(fontFamily);
|
248
|
-
// paint.setFontWeight(fontWeight);
|
249
|
-
// paint.setFontStyle(fontStyle);
|
250
|
-
// paintFontCache[fontCacheKey] = paint;
|
251
|
-
// }
|
252
|
-
// typeface = typefaceCache[fontCacheKey] = paint.getFont().getAndroidTypeface();
|
253
|
-
}
|
254
|
-
else {
|
255
|
-
const font = new Font(fontFamily, 10, fontStyle, fontWeight);
|
256
|
-
typeface = typefaceCache[fontCacheKey] = font.getAndroidTypeface();
|
257
|
-
}
|
258
|
-
}
|
259
|
-
const typefaceSpan = new com.nativescript.text.CustomTypefaceSpan(fontFamily, typeface);
|
260
|
-
ssb.setSpan(typefaceSpan, 0, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
261
|
-
}
|
262
|
-
if (verticalTextAlignment && verticalTextAlignment !== 'initial') {
|
263
|
-
ssb.setSpan(new com.nativescript.text.BaselineAdjustedSpan(fontSize, verticalTextAlignment, realMaxFontSize), 0, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
264
|
-
}
|
265
|
-
if (fontSize) {
|
266
|
-
ssb.setSpan(new Style.AbsoluteSizeSpan(fontSize), 0, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
267
|
-
}
|
268
|
-
if (letterSpacing) {
|
269
|
-
ssb.setSpan(new Style.ScaleXSpan((letterSpacing + 1) / 10), 0, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
270
|
-
}
|
271
|
-
if (lineHeight !== undefined) {
|
272
|
-
ssb.setSpan(new com.nativescript.text.HeightSpan(lineHeight), 0, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
273
|
-
}
|
274
|
-
if (color) {
|
275
|
-
const ncolor = color instanceof Color ? color : new Color(color);
|
276
|
-
ssb.setSpan(new Style.ForegroundColorSpan(ncolor.android), 0, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
277
|
-
}
|
278
|
-
if (backgroundcolor) {
|
279
|
-
const color = backgroundcolor instanceof Color ? backgroundcolor : new Color(backgroundcolor);
|
280
|
-
ssb.setSpan(new Style.BackgroundColorSpan(color.android), 0, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
281
|
-
}
|
282
|
-
if (textDecorations) {
|
283
|
-
const underline = textDecorations.indexOf('underline') !== -1;
|
284
|
-
if (underline) {
|
285
|
-
ssb.setSpan(new Style.UnderlineSpan(), 0, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
286
|
-
}
|
287
|
-
const strikethrough = textDecorations.indexOf('line-through') !== -1;
|
288
|
-
if (strikethrough) {
|
289
|
-
ssb.setSpan(new Style.StrikethroughSpan(), 0, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
290
|
-
}
|
291
|
-
}
|
292
|
-
if (span.tappable) {
|
293
|
-
initializeClickableSpan();
|
294
|
-
ssb.setSpan(new ClickableSpan(span), 0, length, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
295
|
-
}
|
296
|
-
return ssb;
|
297
|
-
});
|
298
|
-
//# sourceMappingURL=index.android.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from './index.android';
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import { Color, CoreTypes, FormattedString, ViewBase } from '@nativescript/core';
|
2
|
-
export * from './index-common';
|
3
|
-
export declare function enableIOSDTCoreText(): void;
|
4
|
-
export declare function init(): void;
|
5
|
-
export declare function createNativeAttributedString(data: {
|
6
|
-
text: string;
|
7
|
-
color?: Color | string | number;
|
8
|
-
familyName?: string;
|
9
|
-
fontSize?: number;
|
10
|
-
letterSpacing?: number;
|
11
|
-
lineHeight?: number;
|
12
|
-
textAlignment?: NSTextAlignment | CoreTypes.TextAlignmentType;
|
13
|
-
} | FormattedString, parent: ViewBase): any;
|
14
|
-
export declare function createSpannable(span: any, parentView: any, parent?: any, maxFontSize?: any): NSMutableAttributedString;
|
@@ -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,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
|
-
}
|