solid-panes
Version:
Solid-compatible Panes: applets and views for the mashlib and databrowser
71 lines (65 loc) • 3.12 kB
JavaScript
;
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.imagePane = void 0;
var UI = _interopRequireWildcard(require("solid-ui"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
/* Image Pane
**
** This outline pane contains the document contents for an Image document
*/
var imagePane = exports.imagePane = {
icon: UI.icons.originalIconBase + 'tango/22-image-x-generic.png',
name: 'image',
label: function label(subject, context) {
var store = context.session.store;
if (!store.anyStatementMatching(subject, UI.ns.rdf('type'), store.sym('http://purl.org/dc/terms/Image'))) {
// NB: Not dc: namespace!
return null;
}
// See also the source pane, which has lower precedence.
var contentTypeMatch = function contentTypeMatch(store, x, contentTypes) {
var cts = store.fetcher.getHeader(x, 'content-type');
if (cts) {
for (var j = 0; j < cts.length; j++) {
for (var k = 0; k < contentTypes.length; k++) {
if (cts[j].indexOf(contentTypes[k]) >= 0) {
return true;
}
}
}
}
return false;
};
var suppressed = ['application/pdf'];
if (contentTypeMatch(store, subject, suppressed)) {
return null;
}
return 'view';
},
render: function render(subject, context) {
var myDocument = context.dom;
var store = context.session.store;
var div = myDocument.createElement('div');
div.setAttribute('class', 'imageView');
var img = myDocument.createElement('IMG');
// get image with authenticated fetch
store.fetcher._fetch(subject.uri).then(function (response) {
return response.blob();
}).then(function (myBlob) {
var objectURL = URL.createObjectURL(myBlob);
img.setAttribute('src', objectURL); // w640 h480 //
});
img.setAttribute('style', 'max-width: 100%; max-height: 100%;');
// div.style['max-width'] = '640'
// div.style['max-height'] = '480'
var tr = myDocument.createElement('TR'); // why need tr?
tr.appendChild(img);
div.appendChild(tr);
return div;
}
};
// ends
//# sourceMappingURL=imagePane.js.map