Include libraries directly

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
2025-08-23 05:28:02 +01:00
parent 980730cf36
commit 4c13478b6e
5 changed files with 106 additions and 5 deletions

95
src/BindIt.js Normal file
View File

@@ -0,0 +1,95 @@
function bindIt(obj, base = '') {
for (let key in obj) {
// Make sure all child objects are proxied too
if (obj.hasOwnProperty(key) && Object.prototype.toString.call(obj[key]) === '[object Object]') {
obj[key] = bindIt(obj[key], `${base ? base + '.' : ''}${key}`);
}
// ...as well as arrays
if (obj.hasOwnProperty(key) && Object.prototype.toString.call(obj[key]) === '[object Array]') {
obj[key] = new Proxy(obj[key], arrayHander);
}
}
function wrapArray(obj, prop, bindKey) {
let arrayHandler = {
apply: function (fn, arr, argumentsList) {
obj[prop]._push(argumentsList);
triggerUpdate(bindKey, obj[prop]);
}
};
if (Object.prototype.toString.call(obj[prop]) === '[object Array]') {
obj[prop]._push = obj[prop].push;
obj[prop].push = new Proxy(obj[prop].push, arrayHandler);
}
}
function triggerUpdate(bindKey, value) {
let elements = document.querySelectorAll(`[bind-it-to='${bindKey}']`);
requestAnimationFrame(() => {
for (let element of elements) {
let bindType = element.getAttribute('bind-it-with') || 'innerText';
switch (bindType) {
case 'innerText':
element.innerText = value;
break;
case 'value':
element.value = value;
break;
default:
if (typeof window[bindType] === 'function') {
window[bindType].apply(element, [value]);
}
break;
}
}
});
}
let handler = {
get: function (obj, key) {
if (typeof key === 'string') {
// Ensure safe deep get/set (no need to set up the structute)
if (obj[key] === undefined) obj[key] = bindIt({}, `${base ? base + '.' : ''}${key}`);
return obj[key];
}
},
set: function (obj, prop, value) {
const bindKey = `${base ? base + '.' : ''}${prop}`;
// Set the new value
obj[prop] = value;
// Handle arrays
wrapArray(obj, prop, bindKey);
// Handle bindings
triggerUpdate(bindKey, obj[prop]);
return obj;
}
};
let proxied = new Proxy(obj, handler);
// Handle two-way and initial bind
if (base === '') {
let elements = document.querySelectorAll(`[bind-it-to]`);
for (let element of elements) {
let key = element.getAttribute('bind-it-to');
let keyParts = key.split('.');
let wantedValue = obj;
while (keyParts.length) {
wantedValue = wantedValue[keyParts.splice(0, 1)];
}
triggerUpdate(key, wantedValue);
}
let twoWayElements = document.querySelectorAll(`[bind-it-two-way]`);
for (let element of twoWayElements) {
element.addEventListener('change', function () {
let prop = this.getAttribute('bind-it-to');
proxied[prop] = this.value
});
}
}
return proxied;
}

2
src/dom-to-image.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -16,12 +16,11 @@
<meta property="og:image" content="https://opengraph.cluster.fun/opengraph/?siteTitle=&title=Bsky%20Screenshot&tags=bluesky%2Cimage%2Cscreenshot&image=https%3A%2F%2Fbsky-screenshot.cluster.fun%2Ficon.png&bluesky=&fediverse=&github=&website=bsky-screenshot.cluster.fun&bgColor=%2370c9d0&fgColor=%230b1415">
<meta name="twitter:image" content="https://opengraph.cluster.fun/opengraph/?siteTitle=&title=Bsky%20Screenshot&tags=bluesky%2Cimage%2Cscreenshot&image=https%3A%2F%2Fbsky-screenshot.cluster.fun%2Ficon.png&bluesky=&fediverse=&github=&website=bsky-screenshot.cluster.fun&bgColor=%2370c9d0&fgColor=%230b1415">
<script tpye="application/javascript" src="https://cdn.githubraw.com/AverageMarcus/BindIt.js/refs/heads/master/BindIt.js"></script>
<script tpye="application/javascript" src="https://cdn.githubraw.com/tsayen/dom-to-image/refs/heads/master/dist/dom-to-image.min.js"></script>
<script tpye="application/javascript" src="BindIt.js"></script>
<script tpye="application/javascript" src="dom-to-image.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.css">
<link rel="stylesheet" href="https://githubraw.com/AverageMarcus/milligram/master/dist/milligram.min.css">
<link rel="stylesheet" href="normalize.min.css">
<link rel="stylesheet" href="milligram.min.css">
<link rel="stylesheet" href="style.css">
</head>
<body>

3
src/milligram.min.css vendored Normal file

File diff suppressed because one or more lines are too long

2
src/normalize.min.css vendored Normal file
View File

@@ -0,0 +1,2 @@
/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}main{display:block}h1{font-size:2em;margin:.67em 0}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace,monospace;font-size:1em}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring,button:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:.35em .75em .625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details{display:block}summary{display:list-item}template{display:none}[hidden]{display:none}
/*# sourceMappingURL=normalize.min.css.map */