This is an automated email from the ASF dual-hosted git repository.
greg-dove pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/develop by this push:
new 0a6bf1db94 handle css functions for sizing
0a6bf1db94 is described below
commit 0a6bf1db94eb1ac51ce647c7d5813d8046e39412
Author: greg-dove <[email protected]>
AuthorDate: Sat May 30 15:50:14 2026 +0200
handle css functions for sizing
---
.../projects/Style/src/main/royale/StyleClasses.as | 6 +++++
.../royale/style/stylebeads/LeafStyleBase.as | 2 +-
.../stylebeads/sizing/MeasurementStyleBase.as | 29 ++++++++++++++++++++++
.../royale/org/apache/royale/style/util/Calc.as | 28 +++++++++++++++++++++
.../royale/org/apache/royale/style/util/Clamp.as | 28 +++++++++++++++++++++
.../royale/org/apache/royale/style/util/Max.as | 28 +++++++++++++++++++++
.../royale/org/apache/royale/style/util/Min.as | 28 +++++++++++++++++++++
7 files changed, 148 insertions(+), 1 deletion(-)
diff --git a/frameworks/projects/Style/src/main/royale/StyleClasses.as
b/frameworks/projects/Style/src/main/royale/StyleClasses.as
index 66fb86e307..f51fe2f6d6 100644
--- a/frameworks/projects/Style/src/main/royale/StyleClasses.as
+++ b/frameworks/projects/Style/src/main/royale/StyleClasses.as
@@ -36,6 +36,12 @@ package
import org.apache.royale.style.data.DataItem; DataItem;
import org.apache.royale.style.data.ListData; ListData;
import org.apache.royale.style.data.MenuData; MenuData;
+
+ import org.apache.royale.style.util.Calc;Calc;
+ import org.apache.royale.style.util.Clamp;Clamp;
+ import org.apache.royale.style.util.Min;Min;
+ import org.apache.royale.style.util.Max;Max;
+
}
}
diff --git
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/LeafStyleBase.as
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/LeafStyleBase.as
index b6418e1874..7dec86dca1 100644
---
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/LeafStyleBase.as
+++
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/LeafStyleBase.as
@@ -200,7 +200,7 @@ package org.apache.royale.style.stylebeads
return "";
return ruleBase + ":" + calculatedRuleValue + ";";
}
- private static const SANITIZE_REGEX:RegExp =
/[\s\.\(\)\+\*\/\[\]]/g;
+ private static const SANITIZE_REGEX:RegExp =
/[\s\.\(\)\+\*\/\[\],]/g;
private static const PERCENT_REGEX:RegExp = /%/g;
protected function sanitizeSelector(value:String):String
{
diff --git
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/sizing/MeasurementStyleBase.as
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/sizing/MeasurementStyleBase.as
index a23d2a54fd..c84d119140 100644
---
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/sizing/MeasurementStyleBase.as
+++
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/stylebeads/sizing/MeasurementStyleBase.as
@@ -46,6 +46,19 @@ package org.apache.royale.style.stylebeads.sizing
calculatedRuleValue = fromVar(value);
return;
}
+ else if (isFunction(value))
+ {
+ calculatedRuleValue = value;
+ // function values can be very long and have
invalid characters
+ // so we use a hash/uid if it's too long or has
special characters
+ // but LeafStyleBase.sanitizeSelector now
handles some of it.
+ // However, for very long functions, a shorter
selector is better.
+ if (value.length > 20)
+ calculatedSelector = "func-" +
value.length + "-" + Math.abs(hashCode(value));
+ else
+ calculatedSelector = value;
+ return;
+ }
calculatedRuleValue = calculatedSelector = value;
switch("" + value)
{
@@ -146,5 +159,21 @@ package org.apache.royale.style.stylebeads.sizing
// return "";
// }
+ protected function isFunction(value:String):Boolean
+ {
+ return value.indexOf("calc(") == 0 ||
value.indexOf("max(") == 0 || value.indexOf("min(") == 0 ||
value.indexOf("clamp(") == 0 || value.indexOf("var(") == 0;
+ }
+
+ protected function hashCode(str:String):int
+ {
+ var hash:int = 0;
+ for (var i:int = 0; i < str.length; i++) {
+ var char:int = str.charCodeAt(i);
+ hash = ((hash << 5) - hash) + char;
+ hash |= 0; // Convert to 32bit integer
+ }
+ return hash;
+ }
+
}
}
\ No newline at end of file
diff --git
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/util/Calc.as
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/util/Calc.as
new file mode 100644
index 0000000000..67e83eb12c
--- /dev/null
+++
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/util/Calc.as
@@ -0,0 +1,28 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.style.util
+{
+ /**
+ * Helper for CSS calc() function.
+ */
+ public function Calc(expression:String):String
+ {
+ return "calc(" + expression + ")";
+ }
+}
\ No newline at end of file
diff --git
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/util/Clamp.as
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/util/Clamp.as
new file mode 100644
index 0000000000..fe4a0f66eb
--- /dev/null
+++
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/util/Clamp.as
@@ -0,0 +1,28 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.style.util
+{
+ /**
+ * Helper for CSS clamp() function.
+ */
+ public function Clamp(min:*, val:*, max:*):String
+ {
+ return "clamp(" + min + ", " + val + ", " + max + ")";
+ }
+}
\ No newline at end of file
diff --git
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/util/Max.as
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/util/Max.as
new file mode 100644
index 0000000000..01f89fa0b3
--- /dev/null
+++
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/util/Max.as
@@ -0,0 +1,28 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.style.util
+{
+ /**
+ * Helper for CSS max() function.
+ */
+ public function Max(...values):String
+ {
+ return "max(" + values.join(", ") + ")";
+ }
+}
\ No newline at end of file
diff --git
a/frameworks/projects/Style/src/main/royale/org/apache/royale/style/util/Min.as
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/util/Min.as
new file mode 100644
index 0000000000..2a54ca5020
--- /dev/null
+++
b/frameworks/projects/Style/src/main/royale/org/apache/royale/style/util/Min.as
@@ -0,0 +1,28 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.style.util
+{
+ /**
+ * Helper for CSS min() function.
+ */
+ public function Min(...values):String
+ {
+ return "min(" + values.join(", ") + ")";
+ }
+}
\ No newline at end of file