@shopify/react-native-skia 0.1.155 → 0.1.156

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. package/android/cpp/jni/JniLoad.cpp +5 -5
  2. package/android/cpp/jni/JniPlatformContext.cpp +107 -119
  3. package/android/cpp/jni/JniSkiaManager.cpp +18 -20
  4. package/android/cpp/jni/include/JniPlatformContext.h +41 -45
  5. package/android/cpp/jni/include/JniSkiaBaseView.h +52 -55
  6. package/android/cpp/jni/include/JniSkiaDrawView.h +72 -77
  7. package/android/cpp/jni/include/JniSkiaManager.h +51 -53
  8. package/android/cpp/jni/include/JniSkiaPictureView.h +74 -78
  9. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +36 -45
  10. package/android/cpp/rnskia-android/RNSkAndroidView.h +87 -92
  11. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +62 -65
  12. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +20 -17
  13. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +257 -313
  14. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +107 -110
  15. package/cpp/api/JsiSkApi.h +66 -62
  16. package/cpp/api/JsiSkCanvas.h +38 -30
  17. package/cpp/api/JsiSkColor.h +58 -56
  18. package/cpp/api/JsiSkColorFilter.h +5 -3
  19. package/cpp/api/JsiSkColorFilterFactory.h +23 -21
  20. package/cpp/api/JsiSkContourMeasure.h +74 -85
  21. package/cpp/api/JsiSkContourMeasureIter.h +68 -75
  22. package/cpp/api/JsiSkData.h +16 -22
  23. package/cpp/api/JsiSkDataFactory.h +86 -79
  24. package/cpp/api/JsiSkFont.h +286 -311
  25. package/cpp/api/JsiSkHostObjects.h +15 -16
  26. package/cpp/api/JsiSkImage.h +107 -103
  27. package/cpp/api/JsiSkImageFactory.h +34 -36
  28. package/cpp/api/JsiSkImageFilter.h +5 -3
  29. package/cpp/api/JsiSkImageFilterFactory.h +71 -68
  30. package/cpp/api/JsiSkImageInfo.h +41 -38
  31. package/cpp/api/JsiSkMaskFilter.h +5 -3
  32. package/cpp/api/JsiSkMaskFilterFactory.h +2 -3
  33. package/cpp/api/JsiSkMatrix.h +26 -36
  34. package/cpp/api/JsiSkPaint.h +20 -13
  35. package/cpp/api/JsiSkPath.h +70 -85
  36. package/cpp/api/JsiSkPathEffect.h +5 -3
  37. package/cpp/api/JsiSkPathEffectFactory.h +33 -28
  38. package/cpp/api/JsiSkPathFactory.h +68 -67
  39. package/cpp/api/JsiSkPicture.h +28 -22
  40. package/cpp/api/JsiSkPictureFactory.h +13 -12
  41. package/cpp/api/JsiSkPictureRecorder.h +21 -19
  42. package/cpp/api/JsiSkPoint.h +6 -8
  43. package/cpp/api/JsiSkRRect.h +11 -7
  44. package/cpp/api/JsiSkRSXform.h +82 -85
  45. package/cpp/api/JsiSkRect.h +9 -9
  46. package/cpp/api/JsiSkRuntimeEffect.h +182 -186
  47. package/cpp/api/JsiSkRuntimeEffectFactory.h +10 -11
  48. package/cpp/api/JsiSkRuntimeShaderBuilder.h +64 -61
  49. package/cpp/api/JsiSkSVG.h +4 -5
  50. package/cpp/api/JsiSkSVGFactory.h +28 -27
  51. package/cpp/api/JsiSkShader.h +3 -2
  52. package/cpp/api/JsiSkShaderFactory.h +37 -25
  53. package/cpp/api/JsiSkSurface.h +44 -40
  54. package/cpp/api/JsiSkSurfaceFactory.h +22 -22
  55. package/cpp/api/JsiSkTextBlob.h +28 -31
  56. package/cpp/api/JsiSkTextBlobFactory.h +88 -87
  57. package/cpp/api/JsiSkTypeface.h +6 -5
  58. package/cpp/api/JsiSkTypefaceFactory.h +22 -21
  59. package/cpp/api/JsiSkVertices.h +137 -124
  60. package/cpp/api/third_party/CSSColorParser.cpp +161 -174
  61. package/cpp/api/third_party/CSSColorParser.h +172 -96
  62. package/cpp/jsi/JsiHostObject.cpp +11 -9
  63. package/cpp/jsi/JsiHostObject.h +31 -24
  64. package/cpp/jsi/JsiSimpleValueWrapper.h +74 -83
  65. package/cpp/jsi/JsiValueWrapper.h +52 -54
  66. package/cpp/rnskia/RNSkAnimation.h +26 -29
  67. package/cpp/rnskia/RNSkDispatchQueue.cpp +50 -61
  68. package/cpp/rnskia/RNSkDispatchQueue.h +3 -1
  69. package/cpp/rnskia/RNSkInfoParameter.h +12 -12
  70. package/cpp/rnskia/RNSkJsView.cpp +82 -81
  71. package/cpp/rnskia/RNSkJsView.h +45 -41
  72. package/cpp/rnskia/RNSkJsiViewApi.h +99 -89
  73. package/cpp/rnskia/RNSkManager.cpp +8 -7
  74. package/cpp/rnskia/RNSkManager.h +8 -6
  75. package/cpp/rnskia/RNSkPictureView.h +44 -37
  76. package/cpp/rnskia/RNSkPlatformContext.h +39 -28
  77. package/cpp/rnskia/RNSkValueApi.h +33 -34
  78. package/cpp/rnskia/RNSkView.h +108 -93
  79. package/cpp/rnskia/values/RNSkClockValue.h +63 -64
  80. package/cpp/rnskia/values/RNSkComputedValue.h +32 -30
  81. package/cpp/rnskia/values/RNSkReadonlyValue.h +60 -59
  82. package/cpp/rnskia/values/RNSkValue.h +38 -40
  83. package/cpp/utils/RNSkLog.h +9 -7
  84. package/cpp/utils/RNSkMeasureTime.h +7 -7
  85. package/cpp/utils/RNSkTimingInfo.h +27 -24
  86. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +8 -9
  87. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +24 -23
  88. package/ios/RNSkia-iOS/RNSkiOSView.h +16 -13
  89. package/ios/RNSkia-iOS/SkiaUIView.h +9 -8
  90. package/lib/commonjs/dom/nodes/JsiSkDOM.js +6 -0
  91. package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
  92. package/lib/commonjs/dom/nodes/LayerNode.js +43 -0
  93. package/lib/commonjs/dom/nodes/LayerNode.js.map +1 -0
  94. package/lib/commonjs/dom/types/NodeType.js +1 -0
  95. package/lib/commonjs/dom/types/NodeType.js.map +1 -1
  96. package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
  97. package/lib/commonjs/renderer/HostComponents.js +3 -0
  98. package/lib/commonjs/renderer/HostComponents.js.map +1 -1
  99. package/lib/commonjs/renderer/components/Group.js +19 -4
  100. package/lib/commonjs/renderer/components/Group.js.map +1 -1
  101. package/lib/commonjs/renderer/components/Paint.js +6 -1
  102. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  103. package/lib/commonjs/views/SkiaPictureView.js +3 -2
  104. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  105. package/lib/commonjs/views/SkiaView.js +6 -3
  106. package/lib/commonjs/views/SkiaView.js.map +1 -1
  107. package/lib/module/dom/nodes/JsiSkDOM.js +5 -0
  108. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  109. package/lib/module/dom/nodes/LayerNode.js +32 -0
  110. package/lib/module/dom/nodes/LayerNode.js.map +1 -0
  111. package/lib/module/dom/types/NodeType.js +1 -0
  112. package/lib/module/dom/types/NodeType.js.map +1 -1
  113. package/lib/module/dom/types/SkDOM.js.map +1 -1
  114. package/lib/module/renderer/HostComponents.js +3 -0
  115. package/lib/module/renderer/HostComponents.js.map +1 -1
  116. package/lib/module/renderer/components/Group.js +16 -3
  117. package/lib/module/renderer/components/Group.js.map +1 -1
  118. package/lib/module/renderer/components/Paint.js +7 -1
  119. package/lib/module/renderer/components/Paint.js.map +1 -1
  120. package/lib/module/views/SkiaPictureView.js +2 -2
  121. package/lib/module/views/SkiaPictureView.js.map +1 -1
  122. package/lib/module/views/SkiaView.js +4 -2
  123. package/lib/module/views/SkiaView.js.map +1 -1
  124. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +2 -0
  125. package/lib/typescript/src/dom/nodes/LayerNode.d.ts +8 -0
  126. package/lib/typescript/src/dom/types/NodeType.d.ts +1 -0
  127. package/lib/typescript/src/dom/types/SkDOM.d.ts +1 -0
  128. package/lib/typescript/src/renderer/HostComponents.d.ts +2 -1
  129. package/lib/typescript/src/renderer/components/Group.d.ts +5 -1
  130. package/lib/typescript/src/views/SkiaView.d.ts +3 -0
  131. package/libs/android/arm64-v8a/libskottie.a +0 -0
  132. package/libs/android/arm64-v8a/libsksg.a +0 -0
  133. package/libs/android/armeabi-v7a/libskottie.a +0 -0
  134. package/libs/android/armeabi-v7a/libsksg.a +0 -0
  135. package/libs/android/x86/libskottie.a +0 -0
  136. package/libs/android/x86/libsksg.a +0 -0
  137. package/libs/android/x86_64/libskottie.a +0 -0
  138. package/libs/android/x86_64/libsksg.a +0 -0
  139. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  140. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  141. package/libs/ios/libskottie.xcframework/Info.plist +42 -0
  142. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  143. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  144. package/libs/ios/libsksg.xcframework/Info.plist +42 -0
  145. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  146. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  147. package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
  148. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  149. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  150. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  151. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  152. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  153. package/package.json +3 -1
  154. package/src/dom/nodes/JsiSkDOM.ts +5 -0
  155. package/src/dom/nodes/LayerNode.ts +35 -0
  156. package/src/dom/types/NodeType.ts +1 -0
  157. package/src/dom/types/SkDOM.ts +1 -0
  158. package/src/renderer/HostComponents.ts +3 -0
  159. package/src/renderer/components/Group.tsx +16 -3
  160. package/src/renderer/components/Paint.tsx +7 -1
  161. package/src/views/SkiaPictureView.tsx +2 -3
  162. package/src/views/SkiaView.tsx +2 -2
@@ -2,193 +2,180 @@
2
2
 
3
3
  namespace CSSColorParser {
4
4
 
5
- template <typename T>
6
- uint8_t clamp_css_byte(T i) { // Clamp to integer 0 .. 255.
7
- i = ::round(i); // Seems to be what Chrome does (vs truncation).
8
- return i < 0 ? 0 : i > 255 ? 255 : uint8_t(i);
5
+ template <typename T>
6
+ uint8_t clamp_css_byte(T i) { // Clamp to integer 0 .. 255.
7
+ i = ::round(i); // Seems to be what Chrome does (vs truncation).
8
+ return i < 0 ? 0 : i > 255 ? 255 : uint8_t(i);
9
+ }
10
+
11
+ template <typename T> float clamp_css_float(T f) { // Clamp to float 0.0 .. 1.0.
12
+ return f < 0 ? 0 : f > 1 ? 1 : static_cast<float>(f);
13
+ }
14
+
15
+ float parseFloat(const std::string &str) {
16
+ return strtof(str.c_str(), nullptr);
17
+ }
18
+
19
+ int64_t parseInt(const std::string &str, uint8_t base = 10) {
20
+ return strtoll(str.c_str(), nullptr, base);
21
+ }
22
+
23
+ uint8_t parse_css_int(const std::string &str) { // int or percentage.
24
+ if (str.length() && str.back() == '%') {
25
+ return clamp_css_byte(parseFloat(str) / 100.0f * 255.0f);
26
+ } else {
27
+ return clamp_css_byte(parseInt(str));
28
+ }
29
+ }
30
+
31
+ float parse_css_float(const std::string &str) { // float or percentage.
32
+ if (str.length() && str.back() == '%') {
33
+ return clamp_css_float(parseFloat(str) / 100.0f);
34
+ } else {
35
+ return clamp_css_float(parseFloat(str));
36
+ }
37
+ }
38
+
39
+ float css_hue_to_rgb(float m1, float m2, float h) {
40
+ if (h < 0.0f) {
41
+ h += 1.0f;
42
+ } else if (h > 1.0f) {
43
+ h -= 1.0f;
44
+ }
45
+
46
+ if (h * 6.0f < 1.0f) {
47
+ return m1 + (m2 - m1) * h * 6.0f;
48
+ }
49
+ if (h * 2.0f < 1.0f) {
50
+ return m2;
51
+ }
52
+ if (h * 3.0f < 2.0f) {
53
+ return m1 + (m2 - m1) * (2.0f / 3.0f - h) * 6.0f;
54
+ }
55
+ return m1;
56
+ }
57
+
58
+ std::vector<std::string> split(const std::string &s, char delim) {
59
+ std::vector<std::string> elems;
60
+ std::stringstream ss(s);
61
+ std::string item;
62
+ while (std::getline(ss, item, delim)) {
63
+ elems.push_back(item);
64
+ }
65
+ return elems;
66
+ }
67
+
68
+ Color parse(const std::string &css_str) {
69
+ std::string str = css_str;
70
+
71
+ // Remove all whitespace, not compliant, but should just be more accepting.
72
+ str.erase(std::remove(str.begin(), str.end(), ' '), str.end());
73
+
74
+ // Convert to lowercase.
75
+ std::transform(str.begin(), str.end(), str.begin(), ::tolower);
76
+
77
+ for (const auto &namedColor : namedColors) {
78
+ if (str == namedColor.name) {
79
+ return {namedColor.color};
9
80
  }
10
-
11
- template <typename T>
12
- float clamp_css_float(T f) { // Clamp to float 0.0 .. 1.0.
13
- return f < 0 ? 0 : f > 1 ? 1 : float(f);
81
+ }
82
+
83
+ // #abc and #abc123 syntax.
84
+ if (str.length() && str.front() == '#') {
85
+ auto iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
86
+ if (str.length() == 4) {
87
+ if (!(iv >= 0 && iv <= 0xfff)) {
88
+ return {};
89
+ } else {
90
+ return {static_cast<uint8_t>(((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8)),
91
+ static_cast<uint8_t>((iv & 0xf0) | ((iv & 0xf0) >> 4)),
92
+ static_cast<uint8_t>((iv & 0xf) | ((iv & 0xf) << 4)), 1};
93
+ }
94
+ } else if (str.length() == 7) {
95
+ if (!(iv >= 0 && iv <= 0xffffff)) {
96
+ return {}; // Covers NaN.
97
+ } else {
98
+ return {static_cast<uint8_t>((iv & 0xff0000) >> 16),
99
+ static_cast<uint8_t>((iv & 0xff00) >> 8),
100
+ static_cast<uint8_t>(iv & 0xff), 1};
101
+ }
102
+ } else if (str.length() == 5) {
103
+ // #rgba
104
+ if (!(iv >= 0 && iv <= 0xffff))
105
+ return {}; // Covers NaN.
106
+ return {
107
+ static_cast<uint8_t>(((iv & 0xf000) >> 8) | ((iv & 0xf000) >> 12)),
108
+ static_cast<uint8_t>(((iv & 0x0f00) >> 4) | ((iv & 0x0f00) >> 8)),
109
+ static_cast<uint8_t>((iv & 0x00f0) | ((iv & 0x00f0) >> 4)),
110
+ static_cast<uint8_t>(((iv & 0x000f) << 4 | (iv & 0x000f))) / 255.0f};
111
+ } else if (str.length() == 9) {
112
+ // #rrggbbaa
113
+ if (!(iv >= 0 && iv <= 0xffffffff))
114
+ return {}; // Covers NaN.
115
+ return {static_cast<uint8_t>(((iv & 0xff000000) >> 24) & 0xff),
116
+ static_cast<uint8_t>((iv & 0x00ff0000) >> 16),
117
+ static_cast<uint8_t>((iv & 0x0000ff00) >> 8),
118
+ static_cast<uint8_t>((iv & 0x000000ff)) / 255.0f};
14
119
  }
15
120
 
16
- float parseFloat(const std::string& str) {
17
- return strtof(str.c_str(), nullptr);
18
- }
121
+ return {};
122
+ }
19
123
 
20
- int64_t parseInt(const std::string& str, uint8_t base = 10) {
21
- return strtoll(str.c_str(), nullptr, base);
22
- }
124
+ size_t op = str.find_first_of('('), ep = str.find_first_of(')');
125
+ if (op != std::string::npos && ep + 1 == str.length()) {
126
+ const std::string fname = str.substr(0, op);
127
+ const std::vector<std::string> params =
128
+ split(str.substr(op + 1, ep - (op + 1)), ',');
23
129
 
24
- uint8_t parse_css_int(const std::string& str) { // int or percentage.
25
- if (str.length() && str.back() == '%') {
26
- return clamp_css_byte(parseFloat(str) / 100.0f * 255.0f);
27
- } else {
28
- return clamp_css_byte(parseInt(str));
29
- }
30
- }
130
+ float alpha = 1.0f;
31
131
 
32
- float parse_css_float(const std::string& str) { // float or percentage.
33
- if (str.length() && str.back() == '%') {
34
- return clamp_css_float(parseFloat(str) / 100.0f);
35
- } else {
36
- return clamp_css_float(parseFloat(str));
132
+ if (fname == "rgba" || fname == "rgb") {
133
+ if (fname == "rgba") {
134
+ if (params.size() != 4) {
135
+ return {};
37
136
  }
38
- }
39
-
40
- float css_hue_to_rgb(float m1, float m2, float h) {
41
- if (h < 0.0f) {
42
- h += 1.0f;
43
- } else if (h > 1.0f) {
44
- h -= 1.0f;
137
+ alpha = parse_css_float(params.back());
138
+ } else {
139
+ if (params.size() != 3) {
140
+ return {};
45
141
  }
142
+ }
46
143
 
47
- if (h * 6.0f < 1.0f) {
48
- return m1 + (m2 - m1) * h * 6.0f;
49
- }
50
- if (h * 2.0f < 1.0f) {
51
- return m2;
52
- }
53
- if (h * 3.0f < 2.0f) {
54
- return m1 + (m2 - m1) * (2.0f / 3.0f - h) * 6.0f;
55
- }
56
- return m1;
57
- }
144
+ return {parse_css_int(params[0]), parse_css_int(params[1]),
145
+ parse_css_int(params[2]), alpha};
58
146
 
59
- std::vector<std::string> split(const std::string& s, char delim) {
60
- std::vector<std::string> elems;
61
- std::stringstream ss(s);
62
- std::string item;
63
- while (std::getline(ss, item, delim)) {
64
- elems.push_back(item);
147
+ } else if (fname == "hsla" || fname == "hsl") {
148
+ if (fname == "hsla") {
149
+ if (params.size() != 4) {
150
+ return {};
65
151
  }
66
- return elems;
67
- }
68
-
69
- Color parse(const std::string& css_str) {
70
- std::string str = css_str;
71
-
72
- // Remove all whitespace, not compliant, but should just be more accepting.
73
- str.erase(std::remove(str.begin(), str.end(), ' '), str.end());
74
-
75
- // Convert to lowercase.
76
- std::transform(str.begin(), str.end(), str.begin(), ::tolower);
77
-
78
- for (const auto& namedColor : namedColors) {
79
- if (str == namedColor.name) {
80
- return { namedColor.color };
81
- }
152
+ alpha = parse_css_float(params.back());
153
+ } else {
154
+ if (params.size() != 3) {
155
+ return {};
82
156
  }
157
+ }
83
158
 
84
- // #abc and #abc123 syntax.
85
- if (str.length() && str.front() == '#') {
86
- auto iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
87
- if (str.length() == 4) {
88
- if (!(iv >= 0 && iv <= 0xfff)) {
89
- return {};
90
- } else {
91
- return {
92
- static_cast<uint8_t>(((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8)),
93
- static_cast<uint8_t>((iv & 0xf0) | ((iv & 0xf0) >> 4)),
94
- static_cast<uint8_t>((iv & 0xf) | ((iv & 0xf) << 4)),
95
- 1
96
- };
97
- }
98
- } else if (str.length() == 7) {
99
- if (!(iv >= 0 && iv <= 0xffffff)) {
100
- return {}; // Covers NaN.
101
- } else {
102
- return {
103
- static_cast<uint8_t>((iv & 0xff0000) >> 16),
104
- static_cast<uint8_t>((iv & 0xff00) >> 8),
105
- static_cast<uint8_t>(iv & 0xff),
106
- 1
107
- };
108
- }
109
- }else if (str.length() == 5) {
110
- // #rgba
111
- if (!(iv >= 0 && iv <= 0xffff)) return {}; // Covers NaN.
112
- return {
113
- static_cast<uint8_t>(((iv & 0xf000) >> 8) | ((iv & 0xf000) >> 12)),
114
- static_cast<uint8_t>(((iv & 0x0f00) >> 4) | ((iv & 0x0f00) >> 8)),
115
- static_cast<uint8_t>((iv & 0x00f0) | ((iv & 0x00f0) >> 4)),
116
- static_cast<uint8_t>(((iv & 0x000f) << 4 | (iv & 0x000f))) / 255.0f
117
- };
118
- } else if (str.length() == 9) {
119
- // #rrggbbaa
120
- if (!(iv >= 0 && iv <= 0xffffffff)) return {}; // Covers NaN.
121
- return {
122
- static_cast<uint8_t>(((iv & 0xff000000) >> 24) & 0xff),
123
- static_cast<uint8_t>((iv & 0x00ff0000) >> 16),
124
- static_cast<uint8_t>((iv & 0x0000ff00) >> 8),
125
- static_cast<uint8_t>((iv & 0x000000ff)) / 255.0f
126
- };
127
- }
128
-
129
- return {};
130
- }
159
+ float h = parseFloat(params[0]) / 360.0f;
160
+ float i;
161
+ // Normalize the hue to [0..1[
162
+ h = std::modf(h, &i);
131
163
 
132
- size_t op = str.find_first_of('('), ep = str.find_first_of(')');
133
- if (op != std::string::npos && ep + 1 == str.length()) {
134
- const std::string fname = str.substr(0, op);
135
- const std::vector<std::string> params = split(str.substr(op + 1, ep - (op + 1)), ',');
136
-
137
- float alpha = 1.0f;
138
-
139
- if (fname == "rgba" || fname == "rgb") {
140
- if (fname == "rgba") {
141
- if (params.size() != 4) {
142
- return { };
143
- }
144
- alpha = parse_css_float(params.back());
145
- } else {
146
- if (params.size() != 3) {
147
- return { };
148
- }
149
- }
150
-
151
- return {
152
- parse_css_int(params[0]),
153
- parse_css_int(params[1]),
154
- parse_css_int(params[2]),
155
- alpha
156
- };
157
-
158
- } else if (fname == "hsla" || fname == "hsl") {
159
- if (fname == "hsla") {
160
- if (params.size() != 4) {
161
- return { };
162
- }
163
- alpha = parse_css_float(params.back());
164
- } else {
165
- if (params.size() != 3) {
166
- return { };
167
- }
168
- }
169
-
170
- float h = parseFloat(params[0]) / 360.0f;
171
- float i;
172
- // Normalize the hue to [0..1[
173
- h = std::modf(h, &i);
174
-
175
- // NOTE(deanm): According to the CSS spec s/l should only be
176
- // percentages, but we don't bother and let float or percentage.
177
- float s = parse_css_float(params[1]);
178
- float l = parse_css_float(params[2]);
179
-
180
- float m2 = l <= 0.5f ? l * (s + 1.0f) : l + s - l * s;
181
- float m1 = l * 2.0f - m2;
182
-
183
- return {
184
- clamp_css_byte(css_hue_to_rgb(m1, m2, h + 1.0f / 3.0f) * 255.0f),
185
- clamp_css_byte(css_hue_to_rgb(m1, m2, h) * 255.0f),
186
- clamp_css_byte(css_hue_to_rgb(m1, m2, h - 1.0f / 3.0f) * 255.0f),
187
- alpha
188
- };
189
- }
190
- }
164
+ // NOTE(deanm): According to the CSS spec s/l should only be
165
+ // percentages, but we don't bother and let float or percentage.
166
+ float s = parse_css_float(params[1]);
167
+ float l = parse_css_float(params[2]);
191
168
 
192
- return { };
169
+ float m2 = l <= 0.5f ? l * (s + 1.0f) : l + s - l * s;
170
+ float m1 = l * 2.0f - m2;
171
+
172
+ return {clamp_css_byte(css_hue_to_rgb(m1, m2, h + 1.0f / 3.0f) * 255.0f),
173
+ clamp_css_byte(css_hue_to_rgb(m1, m2, h) * 255.0f),
174
+ clamp_css_byte(css_hue_to_rgb(m1, m2, h - 1.0f / 3.0f) * 255.0f),
175
+ alpha};
193
176
  }
194
- }
177
+ }
178
+
179
+ return {};
180
+ }
181
+ } // namespace CSSColorParser