solid-panes
Version:
Solid-compatible Panes: applets and views for the mashlib and databrowser
72 lines (66 loc) • 3.29 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 _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
/* 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