question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Idea: Assembler Functions

See original GitHub issue

Okok, 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Awilumcommented, Sep 13, 2021

For me, Functions looks more intuitive and flexible than Mixins.

0reactions
Explosion-Scratchcommented, Sep 13, 2021

Looks similar to Mixins, except, we don’t need to use this special char ^ in x-style for functions

And mixins can’t be nested, and if I came across this code I wouldn’t know what’s going on:

^darken: #ff00ff, 30, background-color;

but this on the other hand:

background-color: $darken(#ff00ff, 30);

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found