I solved it in Spectrum by using common base classes, so a CSS file is only ever referenced once.
Spectrum has many interesting approaches. It makes extensive use of CSS variables which makes for extremely powerful run-time theming. The major monkey-wrench with that is IE11 support. I’m not ready to drop IE11 yet, and that prevents making full use of CSS variables. It also extensively uses SVG <use> elements and applies SVG coloring and shading via CSS. > On Jan 7, 2020, at 6:58 PM, Carlos Rovira <[email protected]> wrote: > > Hi Harbs, > > about duplicate <link> elements: I solved it recently in TDJ by adding "id" > to link. The "loadCSS" method now returns that "id". I store it in TDJ so I > can remove the link element (and that remove all styles in the browser > too). Maybe we can have some Manager class (maybe a bead to use in > Application) that be in charge of ensuring link tags are unique. > > About having CSS downloaded twice. I understand that for non conforming CSS > royale rules like ClassReference, but for normal CSS rules, seems to me a > waste of resources, right? > Maybe there are many things in that concrete topic and will deserve a new > thread about it to understand it completely. For example: Are we using > normal CSS rules in Royale? Can we separate royale rules from normal rules > and load normal ones via browsers css and royale ones vía JS? Can we > reprocess royale css rules again at later time? what means that framework > code does not need to call getComputedStyles()? and why should framework do > that?... I think this is very interesting now that Harbs are working on > Spectrum and I recently worked on runtime theme switching. > > > > > > > El mar., 7 ene. 2020 a las 9:16, Harbs (<[email protected]>) escribió: > >> For js and image/svg files this is probably a complete solution. For CSS, >> there also needs to be code to load the CSS. >> >> I guess a combination of include_file and inject_html might work, but then >> we still have the problem of duplicate <link> injection and combined CSS >> would not be properly referenced. >> >>> For Problem #1, instead of inject_html we could add something like >> "include_file" that would reference a file in a SWC. Then folks could have >> images, css, js, whatever, added to the output file. I think that wouldn't >> be too hard to do. There is already code in the compiler copying stuff out >> of a SWC >> >>> On Jan 7, 2020, at 12:11 AM, Alex Harui <[email protected]> >> wrote: >>> >>> >>> >>> On 1/6/20, 12:45 PM, "Harbs" <[email protected]> wrote: >>> >>> Yes. JS specific. >>> >>> It would be very hard to do a SWF compatible build of Spectrum. >>> >>> So to me, this isn't so much about CSS as it is about externs. CSS that >> is processed by the compiler is intended for multi-platform CSS. >> Multi-platform CSS is encoded for use by ValuesManager and implementations >> on other platforms. As Carlos noted in a recent thread, CSS is sort of >> downloaded twice by Royale JS output, once in its .css file form for >> consumption by the browser, and a second time as encoded CSS for use by the >> framework and application code. That avoids having the framework code call >> getComputedStyles() and allows non-comforming CSS like >> ClassReference("SomeBead"). Although there certainly could be a better way >> to handle this. >>> >>> On the other hand, the inject_html and externs are about 3rd-party or >> external JS implementations. There have been other threads about how to >> handle inject_html and have it inject local references to .js files. Right >> now I think all inject_html use cases reference code on a CDN or some >> canonical URL on the internet. It feels like this is the same problem and >> why you started by asking about inject_html. You don't really need the >> compiler to look at this CSS, you really want some amount of css and/or js >> (and maybe even html) to be linked into the output instead of referenced by >> URL. Although it sounds like you are also looking to aggregate these bits >> and pieces of external css or js into fewer files. >>> >>> So I recommend approaching the problem in two pieces: 1) what is the >> best way to add js and css to the output files and 2) once you have some >> set, can you aggregate it into fewer files? >>> >>> Problem #2 sounds straightforward: search the output folder and combine >> files. I guess it might be important what order you combine CSS files. >>> >>> For Problem #1, instead of inject_html we could add something like >> "include_file" that would reference a file in a SWC. Then folks could have >> images, css, js, whatever, added to the output file. I think that wouldn't >> be too hard to do. There is already code in the compiler copying stuff out >> of a SWC >>> >>> My 2 cents, >>> -Alex >>> >>>> On Jan 6, 2020, at 8:56 PM, Alex Harui <[email protected]> >> wrote: >>>> >>>> But is that CSS platform-specific, or will that same CSS be needed if >> you were to try to implement Spectrum in SWF? IMO, that's a key question >> for how we solve this problem. >>> >>> >>> >> >> > > -- > Carlos Rovira > http://about.me/carlosrovira
