Skip to content

Instantly share code, notes, and snippets.

@prushforth
prushforth / index.html
Created December 17, 2018 14:50
leaflet 1.3.4, proj4leaflet 1.0.2 and epsg:3978 use with CBMT tile cache
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="leaflet/leaflet.css" />
</head>
<body>
<div id="map"></div>
<script src="leaflet/leaflet.js"></script>

Think about how rules are written, applied and work.

In talking about a tree, you have very few basic constructs: Element name, attribute, ancestor/descendant relationships.

You write a CSS selector like .foo bar * bat. These are based on, effectively, element names and attributes (tho there are some 'special' kinds of attributes like ID which is really just an attribute with unusually high specificity and class which is really just an attribute that contains a serialized DOMTokenList). Aside from these the only other thing in your vernacular is "descendant of" or "child of" or some few things about your immediate siblings.

Now, think about when the document is parsing, what does the browser have to do? At some point, it needs to figure out "which rules apply to this element right now" and then make sure that they are applied, in specificity order so that it can figure out what to paint.

Let's imagine that you have a few hundred rules, that's not entirely unusual. Let's imagine that your DOM

@bkardell
bkardell / declarative-resize-observer.js
Last active May 6, 2024 05:06
Uses mutation observers to create a declarative `ResizeObserver` pattern based on a boolean `resize-observer` attribute. These elements track the size of their elements in batch and set a tshirt-size container attribute. If `ResizeObserver` isn't implmented, it uses a lightweight approximation. The whole thing weighs in at <1k gzipped and minified
"use strict";
(function () {
var xSizeEls = [],
custom = {
width: {},
height: {}
},
breakpoints = {
width: {

This is how great ideas often happen, they fade into view over a long period of time... The challenge for all of us is how do you create environments that allow these ideas to have this kind of long half-life, right? It's hard to go to your boss and say "I have an excellent idea for our organization. It will be useful in 2020 [about a decade at the time of this recording], uh, could you just give me some time to do that?."

@shvchk
shvchk / xiaomi-bloatware.txt
Created July 25, 2023 05:45
Xiaomi MIUI debloat list. Initially made for Poco M5, but will probably work fine for any recent Xiaomi phone
com.android.bips
com.android.bookmarkprovider
com.android.printspooler
com.android.providers.partnerbookmarks
com.android.stk
com.android.traceur
com.bsp.catchlog
com.facebook.appmanager
com.facebook.services
com.facebook.system

Defining a scoping inner-boundary in CSS

Concretely, I want to implement simulated CSS scoping for react-shade. This uses the imperative Shadow DOM APIs, by default, to enable scoping on the client. However, in order to get fully-scoped CSS when using SSR, we need either:

  • A declarative API for shadow DOM (closed due to lack of implementer interest), or
  • A way to tell CSS to stop selecting elements in slots. So, we'd need to be able to select between an ancestor and a descendant in a given DOM tree.
  • ...?

I am currently able to find solutions for :host and :host-context, and can scope stuff to descendants of a shadow root tree, the hard part is just simulating the exclusion of slotted content.

@treshugart
treshugart / README.md
Last active May 6, 2024 05:03
HMR for generic web components

Generic web component HMR

I'm messing around with a generic way to do hot-module-replacement with generic web components whether they be vanilla, or done in a framework like Polymer or Skate.

The idea is that you call hmr(customElementConstructor) in your module files and it will set up the proper hooks.

The const filename should be inserted at build time so that it can remember the original localName of the component for the module.

WTF is "x-layout", "Layout" and "filename"

@treshugart
treshugart / readme.md
Last active May 6, 2024 05:03
Shadow DOM issues
function wrap(func) {
return function(value) {
try {
return func(value);
} catch (e) {
console.error(e);
throw new Error(e);
}
};
}
import { autorun, toJS } from 'mobx';
import { props } from 'skatejs';
export const withObserver = (Base = HTMLElement) =>
class extends Base {
constructor() {
super();
const { stores } = this;
// This dynamically adds props post construction, so this happens for every instance that is created. One way to