first commit

This commit is contained in:
s.golasch
2023-08-01 13:49:46 +02:00
commit 1fc239fd54
20238 changed files with 3112246 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
/**
* @license
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
// jshint node:true
'use strict';
var FSResolver = require('./fs-resolver');
function ErrorSwallowingFSResolver(config) {
FSResolver.call(this, config);
}
ErrorSwallowingFSResolver.prototype = Object.create(FSResolver.prototype);
ErrorSwallowingFSResolver.prototype.accept = function(uri, deferred) {
var reject = deferred.reject;
deferred.reject = function(arg) {
deferred.resolve("");
};
return FSResolver.prototype.accept.call(this, uri, deferred);
};
module.exports = ErrorSwallowingFSResolver;

View File

@@ -0,0 +1,99 @@
/**
* @license
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
// jshint node:true
'use strict';
// jshint -W079
// Promise polyfill
var Promise = global.Promise || require('es6-promise').Promise;
// jshint +W079
function Deferred() {
var self = this;
this.promise = new Promise(function(resolve, reject) {
self.resolve = resolve;
self.reject = reject;
});
}
/**
* An object that knows how to resolve resources.
* @typedef {Object} Resolver
* @memberof hydrolysis
* @property {function(string, Deferred): boolean} accept Attempt to resolve
* `deferred` with the contents the specified URL. Returns false if the
* Resolver is unable to resolve the URL.
*/
/**
* A FileLoader lets you resolve URLs with a set of potential resolvers.
* @constructor
* @memberof hydrolysis
*/
function FileLoader() {
this.resolvers = [];
// map url -> Deferred
this.requests = {};
}
FileLoader.prototype = {
/**
* Add an instance of a Resolver class to the list of url resolvers
*
* Ordering of resolvers is most to least recently added
* The first resolver to "accept" the url wins.
* @param {Resolver} resolver The resolver to add.
*/
addResolver: function(resolver) {
this.resolvers.push(resolver);
},
/**
* Return a promise for an absolute url
*
* Url requests are deduplicated by the loader, returning the same Promise for
* identical urls
*
* @param {string} url The absolute url to request.
* @return {Promise.<string>} A promise that resolves to the contents of the URL.
*/
request: function(uri) {
var promise;
if (!(uri in this.requests)) {
var handled = false;
var deferred = new Deferred();
this.requests[uri] = deferred;
// loop backwards through resolvers until one "accepts" the request
for (var i = this.resolvers.length - 1, r; i >= 0; i--) {
r = this.resolvers[i];
if (r.accept(uri, deferred)) {
handled = true;
break;
}
}
if (!handled) {
deferred.reject(new Error('no resolver found for ' + uri));
}
promise = deferred.promise;
} else {
promise = this.requests[uri].promise;
}
return promise;
}
};
module.exports = FileLoader;

110
build/node_modules/hydrolysis/lib/loader/fs-resolver.js generated vendored Normal file
View File

@@ -0,0 +1,110 @@
/**
* @license
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
// jshint node:true
'use strict';
var fs = require('fs');
var path = require('path');
var pathIsAbsolute = require('path-is-absolute');
var url = require('url');
function getFile(filePath, deferred, secondPath) {
fs.readFile(filePath, 'utf-8', function(err, content) {
if (err) {
if (secondPath) {
getFile(secondPath, deferred);
} else {
console.log("ERROR finding " + filePath);
deferred.reject(err);
}
} else {
deferred.resolve(content);
}
});
}
/**
* Returns true if `patha` is a sibling or aunt of `pathb`.
* @return {boolean}
*/
function isSiblingOrAunt(patha, pathb) {
var parent = path.dirname(patha);
if (pathb.indexOf(patha) === -1 && pathb.indexOf(parent) === 0) {
return true;
}
return false;
}
/**
* Change `localPath` from a sibling of `basePath` to be a child of
* `basePath` joined with `redirect`.
* @return {string}
*/
function redirectSibling(basePath, localPath, redirect) {
var parent = path.dirname(basePath);
var redirected = path.join(basePath, redirect, localPath.slice(parent.length));
return redirected;
}
/**
* Resolves requests via the file system.
* @constructor
* @memberof hydrolysis
* @param {Object} config configuration options.
* @param {string} config.host Hostname to match for absolute urls.
* Matches "/" by default
* @param {string} config.basePath Prefix directory for components in url.
* Defaults to "/".
* @param {string} config.root Filesystem root to search. Defaults to the
* current working directory.
* @param {string} config.redirect Where to redirect lookups to siblings.
*/
function FSResolver(config) {
this.config = config || {};
}
FSResolver.prototype = {
accept: function(uri, deferred) {
var parsed = url.parse(uri);
var host = this.config.host;
var base = this.config.basePath && decodeURIComponent(this.config.basePath);
var root = this.config.root && path.normalize(this.config.root);
var redirect = this.config.redirect;
var local;
if (!parsed.hostname || parsed.hostname === host) {
local = parsed.pathname;
}
if (local) {
// un-escape HTML escapes
local = decodeURIComponent(local);
if (base) {
local = path.relative(base, local);
}
if (root) {
local = path.join(root, local);
}
var backup;
if (redirect && isSiblingOrAunt(root, local)) {
backup = redirectSibling(root, local, redirect);
}
getFile(local, deferred, backup);
return true;
}
return false;
}
};
module.exports = FSResolver;

View File

@@ -0,0 +1,44 @@
/**
* @license
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
// jshint node:true
'use strict';
/**
* A resolver that resolves to null any uri matching config.
* @constructor
* @memberof hydrolysis
* @param {string} config The url to `accept`.
*/
function NoopResolver(config) {
this.config = config;
}
NoopResolver.prototype = {
/**
* @param {string} uri The absolute URI being requested.
* @param {!Deferred} deferred The deferred promise that should be resolved if
* this resolver handles the URI.
* @return {boolean} Whether the URI is handled by this resolver.
*/
accept: function(uri, deferred) {
if (!this.config.test) {
if (uri.search(this.config) == -1) {
return false;
}
} else if (!this.config.test(uri)) return false;
deferred.resolve('');
return true;
}
};
module.exports = NoopResolver;

View File

@@ -0,0 +1,106 @@
/**
* @license
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
// jshint node:true
'use strict';
var fs = require('fs');
var path = require('path');
var url = require('url');
var FSResolver = require('./fs-resolver');
/**
* A single redirect configuration
* @param {Object} config The configuration object
* @param {string} config.protocol The protocol this redirect matches.
* @param {string} config.hostname The host name this redirect matches.
* @param {string} config.path The part of the path to match and
* replace with 'redirectPath'
* @param {string} config.redirectPath The local filesystem path that should
* replace "protocol://hosname/path/"
*/
function ProtocolRedirect(config){
this.protocol = config.protocol;
this.hostname = config.hostname;
this.path = config.path;
this.redirectPath = config.redirectPath;
}
ProtocolRedirect.prototype = {
/**
* The protocol this redirect matches.
* @type {string}
*/
protocol: null,
/**
* The host name this redirect matches.
* @type {string}
*/
hostname: null,
/**
* The part of the path to match and replace with 'redirectPath'
* @type {string}
*/
path: null,
/**
* The local filesystem path that should replace "protocol://hosname/path/"
* @type {string}
*/
redirectPath: null,
redirect: function redirect(uri) {
var parsed = url.parse(uri);
if (this.protocol !== parsed.protocol) {
return null;
} else if (this.hostname !== parsed.hostname) {
return null;
} else if (parsed.pathname.indexOf(this.path) !== 0) {
return null;
}
return path.join(this.redirectPath,
parsed.pathname.slice(this.path.length));
}
};
/**
* Resolves protocol://hostname/path to the local filesystem.
* @constructor
* @memberof hydrolysis
* @param {Object} config configuration options.
* @param {string} config.root Filesystem root to search. Defaults to the
* current working directory.
* @param {Array.<ProtocolRedirect>} redirects A list of protocol redirects
* for the resolver. They are checked for matching first-to-last.
*/
function RedirectResolver(config) {
FSResolver.call(this, config);
this.redirects = config.redirects || [];
}
RedirectResolver.prototype = Object.create(FSResolver.prototype);
RedirectResolver.prototype.accept = function(uri, deferred) {
for (var i = 0; i < this.redirects.length; i++) {
var redirected = this.redirects[i].redirect(uri);
if (redirected) {
return FSResolver.prototype.accept.call(this, redirected, deferred);
}
}
return false;
};
RedirectResolver.prototype.constructor = RedirectResolver;
RedirectResolver.ProtocolRedirect = ProtocolRedirect;
module.exports = RedirectResolver;

View File

@@ -0,0 +1,54 @@
/**
* @license
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
// jshint node:true
'use strict';
/**
* A resolver that resolves to `config.content` any uri matching config.
* @constructor
* @memberof hydrolysis
* @param {string|RegExp} config.url The url or rejex to accept.
* @param {string} config.content The content to serve for `url`.
*/
function StringResolver(config) {
this.url = config.url;
this.content = config.content;
if (!this.url || !this.content) {
throw new Error("Must provide a url and content to the string resolver.");
}
}
StringResolver.prototype = {
/**
* @param {string} uri The absolute URI being requested.
* @param {!Deferred} deferred The deferred promise that should be resolved if
* this resolver handles the URI.
* @return {boolean} Whether the URI is handled by this resolver.
*/
accept: function(uri, deferred) {
if (this.url.test) {
// this.url is a regex
if (!this.url.test(uri)) {
return false;
}
} else {
// this.url is a string
if (uri.search(this.url) == -1) {
return false;
}
}
deferred.resolve(this.content);
return true;
}
};
module.exports = StringResolver;

View File

@@ -0,0 +1,53 @@
/**
* @license
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
// jshint node:true
'use strict';
function getFile(url, deferred, config) {
/* global XMLHttpRequest:false */
var x = new XMLHttpRequest();
x.onload = function() {
var status = x.status || 0;
if (status >= 200 && status < 300) {
deferred.resolve(x.response);
} else {
deferred.reject('xhr status: ' + status);
}
};
x.onerror = function(e) {
deferred.reject(e);
};
x.open('GET', url, true);
if (config && config.responseType) {
x.responseType = config.responseType;
}
x.send();
}
/**
* Construct a resolver that requests resources over XHR.
* @constructor
* @memberof hydrolysis
* @param {Object} config configuration arguments.
* @param {string} config.responseType Type of object to be returned by the
* XHR. Defaults to 'text', accepts 'document', 'arraybuffer', and 'json'.
*/
function XHRResolver(config) {
this.config = config;
}
XHRResolver.prototype = {
accept: function(uri, deferred) {
getFile(uri, deferred, this.config);
return true;
}
};
module.exports = XHRResolver;