[ios, macos] Cleaned up color, edge insets declarations, comments

Eliminated references to MGLColor within style layer headers.
This commit is contained in:
Minh Nguyễn
2017-01-08 17:30:09 -08:00
committed by Minh Nguyễn
parent e0f9870406
commit a4c44c5158
6 changed files with 67 additions and 36 deletions

View File

@@ -251,15 +251,15 @@ global.describeValue = function (value, property, layerType) {
throw new Error(`unrecognized color format in default value of ${property.name}`);
}
if (color.r === 0 && color.g === 0 && color.b === 0 && color.a === 0) {
return '`MGLColor.clearColor`';
return '`UIColor.clearColor`';
}
if (color.r === 0 && color.g === 0 && color.b === 0 && color.a === 1) {
return '`MGLColor.blackColor`';
return '`UIColor.blackColor`';
}
if (color.r === 1 && color.g === 1 && color.b === 1 && color.a === 1) {
return '`MGLColor.whiteColor`';
return '`UIColor.whiteColor`';
}
return 'an `MGLColor`' + ` object whose RGB value is ${color.r}, ${color.g}, ${color.b} and whose alpha value is ${color.a}`;
return 'a `UIColor`' + ` object whose RGB value is ${color.r}, ${color.g}, ${color.b} and whose alpha value is ${color.a}`;
case 'array':
let units = property.units || '';
if (units) {
@@ -268,9 +268,9 @@ global.describeValue = function (value, property, layerType) {
switch (arrayType(property)) {
case 'padding':
if (value[0] === 0 && value[1] === 0 && value[2] === 0 && value[3] === 0) {
return 'an `NSValue` object containing `NSEdgeInsetsZero` or `UIEdgeInsetsZero`';
return 'an `NSValue` object containing `UIEdgeInsetsZero`';
}
return 'an `NSValue` object containing an `NSEdgeInsets` or `UIEdgeInsets` struct set to' + ` ${value[0]}${units} on the top, ${value[3]}${units} on the left, ${value[2]}${units} on the bottom, and ${value[1]}${units} on the right`;
return 'an `NSValue` object containing a `UIEdgeInsets` struct set to' + ` ${value[0]}${units} on the top, ${value[3]}${units} on the left, ${value[2]}${units} on the bottom, and ${value[1]}${units} on the right`;
case 'offset':
case 'translate':
return 'an `NSValue` object containing a `CGVector` struct set to' + ` ${value[0]}${units} rightward and ${value[1]}${units} downward`;
@@ -405,26 +405,28 @@ const layers = _(spec.layer.type.values).map((value, layerType) => {
}).sortBy(['type']).value();
function duplicatePlatformDecls(src) {
// Look for a documentation comment that contains “MGLColor” and the
// subsequent function, method, or property declaration. Try not to match
// greedily.
return src.replace(/(\/\*\*(?:\*[^\/]|[^*])*?\bMGLColor\b[\s\S]*?\*\/)(\s*.+?;)/g,
// Look for a documentation comment that contains “MGLColor” or “UIColor”
// and the subsequent function, method, or property declaration. Try not to
// match greedily.
return src.replace(/(\/\*\*(?:\*[^\/]|[^*])*?\*\/)(\s*[^;]+?\b(?:MGL|NS|UI)(?:Color|EdgeInsets(?:Zero)?)\b[^;]+?;)/g,
(match, comment, decl) => {
let iosComment = comment.replace(/\bMGLColor\b/g, 'UIColor')
let macosComment = comment.replace(/\b(?:MGL|UI)(Color|EdgeInsets(?:Zero)?)\b/g, 'NS$1')
// Use the correct indefinite article.
.replace(/\b(a)n(\s+`?UIColor)\b/gi, '$1$2');
let macosComment = comment.replace(/\bMGLColor\b/g, 'NSColor');
.replace(/\ba(\s+`?NS(?:Color|EdgeInsets))\b/gi, 'an$1');
let iosDecl = decl.replace(/\bMGL(Color|EdgeInsets)\b/g, 'UI$1');
let macosDecl = decl.replace(/\b(?:MGL|UI)(Color|EdgeInsets)\b/g, 'NS$1');
return `\
#if TARGET_OS_IPHONE
${iosComment}${decl}
${comment}${iosDecl}
#else
${macosComment}${decl}
${macosComment}${macosDecl}
#endif`;
})
// Do the same for CGVector-typed properties.
.replace(/(\/\*\*(?:\*[^\/]|[^*])*?\bCGVector\b[\s\S]*?\*\/)(\s*.+?;)/g,
.replace(/(\/\*\*(?:\*[^\/]|[^*])*?\b(?:CGVector|UIEdgeInsets(?:Zero)?)\b[\s\S]*?\*\/)(\s*.+?;)/g,
(match, comment, decl) => {
let macosComment = comment.replace(/\bdownward\b/g, 'upward');
let macosComment = comment.replace(/\bdownward\b/g, 'upward')
.replace(/\bUI(EdgeInsets(?:Zero)?)\b/g, 'NS$1');
return `\
#if TARGET_OS_IPHONE
${comment}${decl}

View File

@@ -37,7 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
This property is only applied to the style if `backgroundPattern` is set to
`nil`. Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *backgroundColor;
@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *backgroundColor;
#else
/**
The color with which the background will be drawn.
@@ -49,7 +49,7 @@ NS_ASSUME_NONNULL_BEGIN
This property is only applied to the style if `backgroundPattern` is set to
`nil`. Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *backgroundColor;
@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *backgroundColor;
#endif
/**

View File

@@ -97,7 +97,7 @@ typedef NS_ENUM(NSUInteger, MGLCircleTranslationAnchor) {
`UIColor.blackColor`. Set this property to `nil` to reset it to the default
value.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *circleColor;
@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *circleColor;
#else
/**
The fill color of the circle.
@@ -106,7 +106,7 @@ typedef NS_ENUM(NSUInteger, MGLCircleTranslationAnchor) {
`NSColor.blackColor`. Set this property to `nil` to reset it to the default
value.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *circleColor;
@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *circleColor;
#endif
/**

View File

@@ -78,7 +78,7 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslationAnchor) {
This property is only applied to the style if `fillPattern` is set to `nil`.
Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *fillColor;
@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *fillColor;
#else
/**
The color of the filled part of this layer.
@@ -90,7 +90,7 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslationAnchor) {
This property is only applied to the style if `fillPattern` is set to `nil`.
Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *fillColor;
@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *fillColor;
#endif
/**
@@ -103,6 +103,7 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslationAnchor) {
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *fillOpacity;
#if TARGET_OS_IPHONE
/**
The outline color of the fill. Matches the value of `fillColor` if unspecified.
@@ -110,7 +111,17 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslationAnchor) {
and `fillAntialiased` is set to an `MGLStyleValue` object containing an
`NSNumber` object containing `YES`. Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *fillOutlineColor;
@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *fillOutlineColor;
#else
/**
The outline color of the fill. Matches the value of `fillColor` if unspecified.
This property is only applied to the style if `fillPattern` is set to `nil`,
and `fillAntialiased` is set to an `MGLStyleValue` object containing an
`NSNumber` object containing `YES`. Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *fillOutlineColor;
#endif
/**
Name of image in sprite to use for drawing image fills. For seamless patterns,

View File

@@ -175,7 +175,7 @@ typedef NS_ENUM(NSUInteger, MGLLineTranslationAnchor) {
This property is only applied to the style if `linePattern` is set to `nil`.
Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *lineColor;
@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *lineColor;
#else
/**
The color with which the line will be drawn.
@@ -187,7 +187,7 @@ typedef NS_ENUM(NSUInteger, MGLLineTranslationAnchor) {
This property is only applied to the style if `linePattern` is set to `nil`.
Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *lineColor;
@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *lineColor;
#endif
/**

View File

@@ -450,14 +450,15 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslationAnchor) {
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconTextFit;
#if TARGET_OS_IPHONE
/**
Size of the additional area added to dimensions determined by `iconTextFit`.
This property is measured in points.
The default value of this property is an `MGLStyleValue` object containing an
`NSValue` object containing `NSEdgeInsetsZero` or `UIEdgeInsetsZero`. Set this
property to `nil` to reset it to the default value.
`NSValue` object containing `UIEdgeInsetsZero`. Set this property to `nil` to
reset it to the default value.
This property is only applied to the style if `iconImageName` is non-`nil`, and
`text` is non-`nil`, and `iconTextFit` is set to an `MGLStyleValue` object
@@ -465,6 +466,23 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslationAnchor) {
`MGLIconTextFitWidth`, or `MGLIconTextFitHeight`. Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconTextFitPadding;
#else
/**
Size of the additional area added to dimensions determined by `iconTextFit`.
This property is measured in points.
The default value of this property is an `MGLStyleValue` object containing an
`NSValue` object containing `NSEdgeInsetsZero`. Set this property to `nil` to
reset it to the default value.
This property is only applied to the style if `iconImageName` is non-`nil`, and
`text` is non-`nil`, and `iconTextFit` is set to an `MGLStyleValue` object
containing an `NSValue` object containing `MGLIconTextFitBoth`,
`MGLIconTextFitWidth`, or `MGLIconTextFitHeight`. Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconTextFitPadding;
#endif
/**
If true, the icon may be flipped to prevent it from being rendered upside-down.
@@ -891,7 +909,7 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslationAnchor) {
This property is only applied to the style if `iconImageName` is non-`nil`.
Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *iconColor;
@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *iconColor;
#else
/**
The tint color to apply to the icon. The `iconImageName` property must be set
@@ -904,7 +922,7 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslationAnchor) {
This property is only applied to the style if `iconImageName` is non-`nil`.
Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *iconColor;
@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *iconColor;
#endif
/**
@@ -933,7 +951,7 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslationAnchor) {
This property is only applied to the style if `iconImageName` is non-`nil`.
Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *iconHaloColor;
@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *iconHaloColor;
#else
/**
The color of the icon’s halo. The `iconImageName` property must be set to a
@@ -946,7 +964,7 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslationAnchor) {
This property is only applied to the style if `iconImageName` is non-`nil`.
Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *iconHaloColor;
@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *iconHaloColor;
#endif
/**
@@ -1044,7 +1062,7 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslationAnchor) {
This property is only applied to the style if `text` is non-`nil`. Otherwise,
it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *textColor;
@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *textColor;
#else
/**
The color with which the text will be drawn.
@@ -1056,7 +1074,7 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslationAnchor) {
This property is only applied to the style if `text` is non-`nil`. Otherwise,
it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *textColor;
@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *textColor;
#endif
/**
@@ -1084,7 +1102,7 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslationAnchor) {
This property is only applied to the style if `text` is non-`nil`. Otherwise,
it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *textHaloColor;
@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *textHaloColor;
#else
/**
The color of the text's halo, which helps it stand out from backgrounds.
@@ -1096,7 +1114,7 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslationAnchor) {
This property is only applied to the style if `text` is non-`nil`. Otherwise,
it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *textHaloColor;
@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *textHaloColor;
#endif
/**