Latest repo

This commit is contained in:
Marc
2025-06-02 16:42:16 +00:00
parent 53ddf1a329
commit cde5fae175
27907 changed files with 3875388 additions and 1 deletions

13
node_modules/media-engine/src/index.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
var Parser = require('./parser');
module.exports = function(queries, options) {
var result = {};
Object.keys(queries).forEach(function(query) {
if (Parser.parse(query).match(options)) {
Object.assign(result, queries[query]);
}
});
return result;
};

28
node_modules/media-engine/src/operators.js generated vendored Normal file
View File

@@ -0,0 +1,28 @@
function And(left, right) {
this.left = left;
this.right = right;
this.match = function(options) {
return left.match(options) && right.match(options);
};
}
function Or(left, right) {
this.left = left;
this.right = right;
this.match = function(options) {
return left.match(options) || right.match(options);
};
}
module.exports = function Operator(type, left, right) {
switch (type) {
case 'and':
return new And(left, right);
case ',':
return new Or(left, right);
default:
throw new Error(value);
}
};

136
node_modules/media-engine/src/parser.js generated vendored Normal file
View File

@@ -0,0 +1,136 @@
var Query = require('./queries');
var Operator = require('./operators');
var NUMBERS = /[0-9]/;
var LETTERS = /[a-z|\-]/i;
var WHITESPACE = /\s/;
var COLON = /:/;
var COMMA = /,/;
var AND = /and$/;
var AT = /@/;
function tokenizer(input) {
var current = 0;
var tokens = [];
while (current < input.length) {
var char = input[current];
if (AT.test(char)) {
char = input[++current];
while (LETTERS.test(char) && char !== undefined) {
char = input[++current];
}
}
if (WHITESPACE.test(char) || char === ')' || char === '(') {
current++;
continue;
}
if (COLON.test(char) || COMMA.test(char)) {
current++;
tokens.push({ type: 'operator', value: char });
continue;
}
if (NUMBERS.test(char)) {
var value = '';
while (NUMBERS.test(char)) {
value += char;
char = input[++current];
}
tokens.push({ type: 'number', value: value });
continue;
}
if (LETTERS.test(char)) {
var value = '';
while (LETTERS.test(char) && char !== undefined) {
value += char;
char = input[++current];
}
if (AND.test(value)) {
tokens.push({ type: 'operator', value: value });
} else {
tokens.push({ type: 'literal', value: value });
}
continue;
}
throw new TypeError(
'Tokenizer: I dont know what this character is: ' + char
);
}
return tokens;
}
function parser(tokens) {
var output = [];
var stack = [];
while (tokens.length > 0) {
var token = tokens.shift();
if (token.type === 'number' || token.type === 'literal') {
output.push(token);
continue;
}
if (token.type === 'operator') {
if (COLON.test(token.value)) {
token = { type: 'query', key: output.pop(), value: tokens.shift() };
output.push(token);
continue;
}
while (stack.length > 0) {
output.unshift(stack.pop());
}
stack.push(token);
}
}
while (stack.length > 0) {
output.unshift(stack.pop());
}
function walk() {
var head = output.shift();
if (head.type === 'number') {
return parseInt(head.value);
}
if (head.type === 'literal') {
return head.value;
}
if (head.type === 'operator') {
var l = walk();
var r = walk();
return Operator(head.value, l, r);
}
if (head.type === 'query') {
var l = head.key.value;
var r = head.value.value;
return Query(l, r);
}
}
return walk();
}
module.exports = {
parse: function(query) {
var tokens = tokenizer(query);
var ast = parser(tokens);
return ast;
}
};

56
node_modules/media-engine/src/queries.js generated vendored Normal file
View File

@@ -0,0 +1,56 @@
function MaxHeight(value) {
this.value = value;
this.match = function(options) {
return this.value >= options.height;
};
}
function MinHeight(value) {
this.value = value;
this.match = function(options) {
return this.value < options.height;
};
}
function MaxWidth(value) {
this.value = value;
this.match = function(options) {
return this.value >= options.width;
};
}
function MinWidth(value) {
this.value = value;
this.match = function(options) {
return this.value < options.width;
};
}
function Orientation(value) {
this.value = value;
this.match = function(options) {
return this.value === options.orientation;
};
}
module.exports = function Query(type, value) {
switch (type) {
case 'max-height':
return new MaxHeight(value);
case 'min-height':
return new MinHeight(value);
case 'max-width':
return new MaxWidth(value);
case 'min-width':
return new MinWidth(value);
case 'orientation':
return new Orientation(value);
default:
throw new Error(value);
}
};