Idea: Assembler Functions
See original GitHub issueOkok, here’s the idea: Functions, these would work similarly to built in CSS functions, like calc()
, var()
and more. So here’s how this work work:
:root {
--dark--function: "@${0}-{1=700}";
}
Now it would be used like this:
<!-- New keyword, just like we use "@" for variables and "^" for mixins, we can use "$" for functions -->
<div x-style="color: $dark(blue, 800);"></div>
Sound cool yet? (not really)
So here’s how it gets super cool:
AssemblerCSS.registerFunction("darken", (settings, ...args) => {
//Same callback format as registerMixin
var color = args[0];
var amount = args[1];
if (!(color && amount)) return args.join(",");//Return the original args and stuff
if (!+amount) return color;//Return the color if amount isn't a number
if (!/^#[0-9A-F]{6}$/i.test(color)) {
//Since this is just a code sample for an idea I'm not gonna add color conversion and stuff.
return color;
}
return `#${darkenHex(color.replace(/^#/, "").toUpperCase(), amount)}`;
function darkenHex(col, amt) {
amt = 0 - amt;//We're darkening, not lightning
var num = parseInt(col, 16);
var r = (num >> 16) + amt;
var b = ((num >> 8) & 0x00ff) + amt;
var g = (num & 0x0000ff) + amt;
var newColor = g | (b << 8) | (r << 16);
return newColor.toString(16);
}
});
Nowwww, look what we could do (!!!)
<div x-style="color: darken(#345beb, 20)"></div>
which turns into…
<div x-style="color: #2047d7"></div>
There are endless possibilities with this! Please consider adding it! 😃
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top Results From Across the Web
NASM Assembly Language - IntelliJ IDEs Plugin | Marketplace
NASM assembly language for JetBrains IDEs. Version v0.5-beta.8 pre-release. Features. ... Compatible with IntelliJ IDEA (Ultimate, Community, Educational), ...
Read more >Baby steps in x86 assembly — Idea of the day - popcount.org
We just created a valid x86 function in assembler! It can now be called from a C code: int main() { simplest_function(); return...
Read more >What is assembler? | Definition from TechTarget
An assembler is a program that takes basic computer instructions and converts them into a pattern of bits that the computer's processor can...
Read more >Assembly Language Programming with ARM – Full Tutorial for ...
Learn assembly language programming with ARMv7 in this beginner's course. ARM is becoming an increasingly popular language in the world of ...
Read more >Implementing Functions in x86 Assembly | by Scott Cosentino
First, we need to be able to pull the parameters off the stack. In addition to this, we need to be able to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For me, Functions looks more intuitive and flexible than Mixins.
And mixins can’t be nested, and if I came across this code I wouldn’t know what’s going on:
but this on the other hand:
makes a lot more sense.
Basically it’s an issue of syntax, not necessarily performance, as the performance could be solved by just passing raw parameters to the assembler.