@earth-app/shovel
Version:
Kotlin Multiplatform Web Scraping Framework
821 lines (813 loc) • 32.7 kB
JavaScript
(function (factory) {
if (typeof define === 'function' && define.amd)
define(['exports', './kotlin-kotlin-stdlib.js', './ktor-ktor-client-core.js', './ktor-ktor-http.js', './kotlinx-io-kotlinx-io-core.js', './ktor-ktor-io.js', './ksoup-ksoup.js', './kotlinx-coroutines-core.js'], factory);
else if (typeof exports === 'object')
factory(module.exports, require('./kotlin-kotlin-stdlib.js'), require('./ktor-ktor-client-core.js'), require('./ktor-ktor-http.js'), require('./kotlinx-io-kotlinx-io-core.js'), require('./ktor-ktor-io.js'), require('./ksoup-ksoup.js'), require('./kotlinx-coroutines-core.js'));
else {
if (typeof globalThis['kotlin-kotlin-stdlib'] === 'undefined') {
throw new Error("Error loading module 'com.earth-app.shovel:shovel'. Its dependency 'kotlin-kotlin-stdlib' was not found. Please, check whether 'kotlin-kotlin-stdlib' is loaded prior to 'com.earth-app.shovel:shovel'.");
}
if (typeof globalThis['ktor-ktor-client-core'] === 'undefined') {
throw new Error("Error loading module 'com.earth-app.shovel:shovel'. Its dependency 'ktor-ktor-client-core' was not found. Please, check whether 'ktor-ktor-client-core' is loaded prior to 'com.earth-app.shovel:shovel'.");
}
if (typeof globalThis['ktor-ktor-http'] === 'undefined') {
throw new Error("Error loading module 'com.earth-app.shovel:shovel'. Its dependency 'ktor-ktor-http' was not found. Please, check whether 'ktor-ktor-http' is loaded prior to 'com.earth-app.shovel:shovel'.");
}
if (typeof globalThis['kotlinx-io-kotlinx-io-core'] === 'undefined') {
throw new Error("Error loading module 'com.earth-app.shovel:shovel'. Its dependency 'kotlinx-io-kotlinx-io-core' was not found. Please, check whether 'kotlinx-io-kotlinx-io-core' is loaded prior to 'com.earth-app.shovel:shovel'.");
}
if (typeof globalThis['ktor-ktor-io'] === 'undefined') {
throw new Error("Error loading module 'com.earth-app.shovel:shovel'. Its dependency 'ktor-ktor-io' was not found. Please, check whether 'ktor-ktor-io' is loaded prior to 'com.earth-app.shovel:shovel'.");
}
if (typeof globalThis['ksoup-ksoup'] === 'undefined') {
throw new Error("Error loading module 'com.earth-app.shovel:shovel'. Its dependency 'ksoup-ksoup' was not found. Please, check whether 'ksoup-ksoup' is loaded prior to 'com.earth-app.shovel:shovel'.");
}
if (typeof globalThis['kotlinx-coroutines-core'] === 'undefined') {
throw new Error("Error loading module 'com.earth-app.shovel:shovel'. Its dependency 'kotlinx-coroutines-core' was not found. Please, check whether 'kotlinx-coroutines-core' is loaded prior to 'com.earth-app.shovel:shovel'.");
}
globalThis['com.earth-app.shovel:shovel'] = factory(typeof globalThis['com.earth-app.shovel:shovel'] === 'undefined' ? {} : globalThis['com.earth-app.shovel:shovel'], globalThis['kotlin-kotlin-stdlib'], globalThis['ktor-ktor-client-core'], globalThis['ktor-ktor-http'], globalThis['kotlinx-io-kotlinx-io-core'], globalThis['ktor-ktor-io'], globalThis['ksoup-ksoup'], globalThis['kotlinx-coroutines-core']);
}
}(function (_, kotlin_kotlin, kotlin_io_ktor_ktor_client_core, kotlin_io_ktor_ktor_http, kotlin_org_jetbrains_kotlinx_kotlinx_io_core, kotlin_io_ktor_ktor_io, kotlin_com_fleeksoft_ksoup_ksoup, kotlin_org_jetbrains_kotlinx_kotlinx_coroutines_core) {
'use strict';
//region block: imports
var VOID = kotlin_kotlin.$_$.h;
var protoOf = kotlin_kotlin.$_$.z7;
var Regex_init_$Create$ = kotlin_kotlin.$_$.a1;
var emptyList = kotlin_kotlin.$_$.e4;
var defineProp = kotlin_kotlin.$_$.a7;
var initMetadataForClass = kotlin_kotlin.$_$.i7;
var toString = kotlin_kotlin.$_$.d8;
var IllegalStateException_init_$Create$ = kotlin_kotlin.$_$.r1;
var LinkedHashMap_init_$Create$ = kotlin_kotlin.$_$.u;
var ArrayList_init_$Create$ = kotlin_kotlin.$_$.p;
var Unit_instance = kotlin_kotlin.$_$.a3;
var charSequenceLength = kotlin_kotlin.$_$.x6;
var mapCapacity = kotlin_kotlin.$_$.u4;
var LinkedHashMap_init_$Create$_0 = kotlin_kotlin.$_$.t;
var HttpClient = kotlin_io_ktor_ktor_client_core.$_$.g;
var substringAfter = kotlin_kotlin.$_$.ea;
var _Char___init__impl__6a9atx = kotlin_kotlin.$_$.h2;
var substringBefore = kotlin_kotlin.$_$.fa;
var CoroutineImpl = kotlin_kotlin.$_$.m6;
var HttpRequestBuilder = kotlin_io_ktor_ktor_client_core.$_$.c;
var url = kotlin_io_ktor_ktor_client_core.$_$.e;
var headers = kotlin_io_ktor_ktor_client_core.$_$.d;
var Companion_getInstance = kotlin_io_ktor_ktor_http.$_$.h;
var HttpStatement = kotlin_io_ktor_ktor_client_core.$_$.f;
var get_COROUTINE_SUSPENDED = kotlin_kotlin.$_$.w5;
var IOException_init_$Create$ = kotlin_org_jetbrains_kotlinx_kotlinx_io_core.$_$.e;
var Charsets_getInstance = kotlin_io_ktor_ktor_io.$_$.k;
var bodyAsText = kotlin_io_ktor_ktor_client_core.$_$.a;
var isSuccess = kotlin_io_ktor_ktor_http.$_$.h1;
var IOException_init_$Create$_0 = kotlin_org_jetbrains_kotlinx_kotlinx_io_core.$_$.c;
var initMetadataForCoroutine = kotlin_kotlin.$_$.k7;
var ensureNotNull = kotlin_kotlin.$_$.sb;
var THROW_CCE = kotlin_kotlin.$_$.lb;
var KtMap = kotlin_kotlin.$_$.h3;
var isInterface = kotlin_kotlin.$_$.s7;
var Ksoup_instance = kotlin_com_fleeksoft_ksoup_ksoup.$_$.a;
var collectionSizeOrDefault = kotlin_kotlin.$_$.u3;
var ArrayList_init_$Create$_0 = kotlin_kotlin.$_$.o;
var coerceAtLeast = kotlin_kotlin.$_$.g8;
var to = kotlin_kotlin.$_$.bc;
var Dispatchers_getInstance = kotlin_org_jetbrains_kotlinx_kotlinx_coroutines_core.$_$.c;
var Js_instance = kotlin_io_ktor_ktor_client_core.$_$.b;
var GlobalScope_instance = kotlin_org_jetbrains_kotlinx_kotlinx_coroutines_core.$_$.d;
var promise = kotlin_org_jetbrains_kotlinx_kotlinx_coroutines_core.$_$.c1;
var CoroutineScope = kotlin_org_jetbrains_kotlinx_kotlinx_coroutines_core.$_$.s;
var initMetadataForLambda = kotlin_kotlin.$_$.n7;
//endregion
//region block: pre-declaration
initMetadataForClass(Element, 'Element');
initMetadataForClass(Document, 'Document');
initMetadataForCoroutine($performRequestCOROUTINE$, CoroutineImpl);
initMetadataForCoroutine($fetchDocumentCOROUTINE$, CoroutineImpl);
initMetadataForLambda(fetchDocumentAsPromise$slambda, CoroutineImpl, VOID, [1]);
//endregion
function get_cache() {
_init_properties_http_kt__yecow8();
return cache;
}
var cache;
function closeClient() {
_init_properties_http_kt__yecow8();
return get_client().x3();
}
function clearCache() {
_init_properties_http_kt__yecow8();
return get_cache().y1();
}
function Element(tagName, innerHTML, outerHTML, textContent, ownTextContent, attributes, children) {
ownTextContent = ownTextContent === VOID ? textContent : ownTextContent;
this.tagName = tagName;
this.innerHTML = innerHTML;
this.outerHTML = outerHTML;
this.textContent = textContent;
this.ownTextContent = ownTextContent;
this.attributes = attributes;
this.children = children;
}
protoOf(Element).m4s = function () {
return this.tagName;
};
protoOf(Element).n4s = function () {
return this.innerHTML;
};
protoOf(Element).o4s = function () {
return this.outerHTML;
};
protoOf(Element).p4s = function () {
return this.textContent;
};
protoOf(Element).q4s = function () {
return this.ownTextContent;
};
protoOf(Element).m2i = function () {
return this.attributes;
};
protoOf(Element).r4s = function () {
return this.children;
};
protoOf(Element).get = function (attribute) {
return this.attributes.e2(attribute);
};
protoOf(Element).s4s = function () {
return this.attributes.e2('id');
};
protoOf(Element).t4s = function () {
var tmp0_safe_receiver = this.attributes.e2('class');
var tmp;
if (tmp0_safe_receiver == null) {
tmp = null;
} else {
// Inline function 'kotlin.text.toRegex' call
// Inline function 'kotlin.text.split' call
tmp = Regex_init_$Create$('\\s+').jd(tmp0_safe_receiver, 0);
}
var tmp1_elvis_lhs = tmp;
return tmp1_elvis_lhs == null ? emptyList() : tmp1_elvis_lhs;
};
protoOf(Element).u4s = function () {
return this.attributes.e2('style');
};
function Document(url, html) {
this.url = url;
this.html = html;
}
protoOf(Document).u2i = function () {
return this.url;
};
protoOf(Document).v4s = function () {
return this.html;
};
protoOf(Document).w4s = function () {
var tmp0_elvis_lhs = documentQuerySelector(this, 'body');
var tmp;
if (tmp0_elvis_lhs == null) {
var message = 'Document does not have a body element';
throw IllegalStateException_init_$Create$(toString(message));
} else {
tmp = tmp0_elvis_lhs;
}
return tmp;
};
protoOf(Document).x4s = function () {
var tmp0 = this.body.innerHTML;
// Inline function 'kotlin.text.replace' call
var tmp0_0 = Regex_init_$Create$('<script\\b[^>]*>([\\s\\S]*?)<\/script>').bd(tmp0, '');
// Inline function 'kotlin.text.replace' call
return Regex_init_$Create$('<style\\b[^>]*>([\\s\\S]*?)<\/style>').bd(tmp0_0, '');
};
protoOf(Document).y4s = function () {
var tmp0_elvis_lhs = documentQuerySelector(this, 'head');
var tmp;
if (tmp0_elvis_lhs == null) {
var message = 'Document does not have a head element';
throw IllegalStateException_init_$Create$(toString(message));
} else {
tmp = tmp0_elvis_lhs;
}
return tmp;
};
protoOf(Document).z4s = function () {
var tmp0_safe_receiver = documentQuerySelector(this, 'title');
var tmp1_elvis_lhs = tmp0_safe_receiver == null ? null : tmp0_safe_receiver.textContent;
var tmp;
if (tmp1_elvis_lhs == null) {
var message = 'Document does not have a title element';
throw IllegalStateException_init_$Create$(toString(message));
} else {
tmp = tmp1_elvis_lhs;
}
return tmp;
};
protoOf(Document).a4t = function () {
// Inline function 'kotlin.collections.groupBy' call
var tmp0 = documentQuerySelectorAll(this, 'meta');
// Inline function 'kotlin.collections.groupByTo' call
var destination = LinkedHashMap_init_$Create$();
var _iterator__ex2g4s = tmp0.g();
while (_iterator__ex2g4s.h()) {
var element = _iterator__ex2g4s.i();
var tmp0_elvis_lhs = element.get('name');
var tmp1_elvis_lhs = tmp0_elvis_lhs == null ? element.get('property') : tmp0_elvis_lhs;
var key = tmp1_elvis_lhs == null ? '' : tmp1_elvis_lhs;
// Inline function 'kotlin.collections.getOrPut' call
var value = destination.e2(key);
var tmp;
if (value == null) {
var answer = ArrayList_init_$Create$();
destination.h2(key, answer);
tmp = answer;
} else {
tmp = value;
}
var list = tmp;
var tmp0_elvis_lhs_0 = element.get('content');
var tmp$ret$3 = tmp0_elvis_lhs_0 == null ? '' : tmp0_elvis_lhs_0;
list.e(tmp$ret$3);
}
// Inline function 'kotlin.collections.filterKeys' call
var result = LinkedHashMap_init_$Create$();
// Inline function 'kotlin.collections.iterator' call
var _iterator__ex2g4s_0 = destination.r().g();
while (_iterator__ex2g4s_0.h()) {
var entry = _iterator__ex2g4s_0.i();
// Inline function 'kotlin.text.isNotEmpty' call
var this_0 = entry.s();
if (charSequenceLength(this_0) > 0) {
result.h2(entry.s(), entry.t());
}
}
// Inline function 'kotlin.collections.mapValues' call
// Inline function 'kotlin.collections.mapValuesTo' call
var destination_0 = LinkedHashMap_init_$Create$_0(mapCapacity(result.j()));
// Inline function 'kotlin.collections.associateByTo' call
var _iterator__ex2g4s_1 = result.r().g();
while (_iterator__ex2g4s_1.h()) {
var element_0 = _iterator__ex2g4s_1.i();
var tmp_0 = element_0.s();
// Inline function 'kotlin.collections.filter' call
var tmp0_0 = element_0.t();
// Inline function 'kotlin.collections.filterTo' call
var destination_1 = ArrayList_init_$Create$();
var _iterator__ex2g4s_2 = tmp0_0.g();
while (_iterator__ex2g4s_2.h()) {
var element_1 = _iterator__ex2g4s_2.i();
// Inline function 'kotlin.text.isNotEmpty' call
if (charSequenceLength(element_1) > 0) {
destination_1.e(element_1);
}
}
destination_0.h2(tmp_0, destination_1);
}
return destination_0;
};
protoOf(Document).b4t = function () {
// Inline function 'kotlin.collections.groupBy' call
var tmp0 = documentQuerySelectorAll(this, 'link');
// Inline function 'kotlin.collections.groupByTo' call
var destination = LinkedHashMap_init_$Create$();
var _iterator__ex2g4s = tmp0.g();
while (_iterator__ex2g4s.h()) {
var element = _iterator__ex2g4s.i();
var tmp0_elvis_lhs = element.get('rel');
var key = tmp0_elvis_lhs == null ? '' : tmp0_elvis_lhs;
// Inline function 'kotlin.collections.getOrPut' call
var value = destination.e2(key);
var tmp;
if (value == null) {
var answer = ArrayList_init_$Create$();
destination.h2(key, answer);
tmp = answer;
} else {
tmp = value;
}
var list = tmp;
var tmp0_elvis_lhs_0 = element.get('href');
var tmp$ret$3 = tmp0_elvis_lhs_0 == null ? '' : tmp0_elvis_lhs_0;
list.e(tmp$ret$3);
}
// Inline function 'kotlin.collections.filterKeys' call
var result = LinkedHashMap_init_$Create$();
// Inline function 'kotlin.collections.iterator' call
var _iterator__ex2g4s_0 = destination.r().g();
while (_iterator__ex2g4s_0.h()) {
var entry = _iterator__ex2g4s_0.i();
// Inline function 'kotlin.text.isNotEmpty' call
var this_0 = entry.s();
if (charSequenceLength(this_0) > 0) {
result.h2(entry.s(), entry.t());
}
}
// Inline function 'kotlin.collections.mapValues' call
// Inline function 'kotlin.collections.mapValuesTo' call
var destination_0 = LinkedHashMap_init_$Create$_0(mapCapacity(result.j()));
// Inline function 'kotlin.collections.associateByTo' call
var _iterator__ex2g4s_1 = result.r().g();
while (_iterator__ex2g4s_1.h()) {
var element_0 = _iterator__ex2g4s_1.i();
var tmp_0 = element_0.s();
// Inline function 'kotlin.collections.filter' call
var tmp0_0 = element_0.t();
// Inline function 'kotlin.collections.filterTo' call
var destination_1 = ArrayList_init_$Create$();
var _iterator__ex2g4s_2 = tmp0_0.g();
while (_iterator__ex2g4s_2.h()) {
var element_1 = _iterator__ex2g4s_2.i();
// Inline function 'kotlin.text.isNotEmpty' call
if (charSequenceLength(element_1) > 0) {
destination_1.e(element_1);
}
}
destination_0.h2(tmp_0, destination_1);
}
return destination_0;
};
function documentQuerySelector(_this__u8e3s4, selector, filter) {
var tmp;
if (filter === VOID) {
tmp = querySelector$lambda;
} else {
tmp = filter;
}
filter = tmp;
_init_properties_http_kt__yecow8();
var tmp0 = documentQuerySelectorAll(_this__u8e3s4, selector);
var tmp$ret$0;
$l$block: {
// Inline function 'kotlin.collections.firstOrNull' call
var _iterator__ex2g4s = tmp0.g();
while (_iterator__ex2g4s.h()) {
var element = _iterator__ex2g4s.i();
if (filter(element)) {
tmp$ret$0 = element;
break $l$block;
}
}
tmp$ret$0 = null;
}
return tmp$ret$0;
}
function documentGetElementById(_this__u8e3s4, id) {
_init_properties_http_kt__yecow8();
return documentQuerySelector(_this__u8e3s4, '#' + id);
}
function documentGetElementsByClassName(_this__u8e3s4, className) {
_init_properties_http_kt__yecow8();
return documentQuerySelectorAll(_this__u8e3s4, '.' + className);
}
function documentInputValue(_this__u8e3s4, name) {
_init_properties_http_kt__yecow8();
var tmp0_elvis_lhs = documentQuerySelector(_this__u8e3s4, 'input[name=' + name + ']');
var tmp;
if (tmp0_elvis_lhs == null) {
return null;
} else {
tmp = tmp0_elvis_lhs;
}
var input = tmp;
var tmp1_elvis_lhs = input.get('value');
return tmp1_elvis_lhs == null ? input.get('checked') : tmp1_elvis_lhs;
}
function elementQuerySelector(_this__u8e3s4, selector, filter) {
var tmp;
if (filter === VOID) {
tmp = querySelector$lambda_0;
} else {
tmp = filter;
}
filter = tmp;
_init_properties_http_kt__yecow8();
var tmp0 = elementQuerySelectorAll(_this__u8e3s4, selector);
var tmp$ret$0;
$l$block: {
// Inline function 'kotlin.collections.firstOrNull' call
var _iterator__ex2g4s = tmp0.g();
while (_iterator__ex2g4s.h()) {
var element = _iterator__ex2g4s.i();
if (filter(element)) {
tmp$ret$0 = element;
break $l$block;
}
}
tmp$ret$0 = null;
}
return tmp$ret$0;
}
function elementGetElementById(_this__u8e3s4, id) {
_init_properties_http_kt__yecow8();
return elementQuerySelector(_this__u8e3s4, '#' + id);
}
function elementGetElementsByClassName(_this__u8e3s4, className) {
_init_properties_http_kt__yecow8();
return elementQuerySelectorAll(_this__u8e3s4, '.' + className);
}
function elementInputValue(_this__u8e3s4, name) {
_init_properties_http_kt__yecow8();
var tmp0_elvis_lhs = elementQuerySelector(_this__u8e3s4, 'input[name=' + name + ']');
var tmp;
if (tmp0_elvis_lhs == null) {
return null;
} else {
tmp = tmp0_elvis_lhs;
}
var input = tmp;
var tmp1_elvis_lhs = input.get('value');
return tmp1_elvis_lhs == null ? input.get('checked') : tmp1_elvis_lhs;
}
function get_client() {
_init_properties_http_kt__yecow8();
var tmp = get_engine();
return HttpClient(tmp, _get_client_$lambda_y278ej);
}
function performRequest(_this__u8e3s4, request, $completion) {
var tmp = new $performRequestCOROUTINE$(_this__u8e3s4, request, $completion);
tmp.o8_1 = Unit_instance;
tmp.p8_1 = null;
return tmp.u8();
}
function fetchDocument(_this__u8e3s4, request, $completion) {
var tmp;
if (request === VOID) {
tmp = fetchDocument$lambda;
} else {
tmp = request;
}
request = tmp;
var tmp_0 = new $fetchDocumentCOROUTINE$(_this__u8e3s4, request, $completion);
tmp_0.o8_1 = Unit_instance;
tmp_0.p8_1 = null;
return tmp_0.u8();
}
function querySelector$lambda(it) {
_init_properties_http_kt__yecow8();
return true;
}
function querySelector$lambda_0(it) {
_init_properties_http_kt__yecow8();
return true;
}
function _get_client_$lambda_y278ej($this$HttpClient) {
_init_properties_http_kt__yecow8();
$this$HttpClient.x2h_1 = false;
$this$HttpClient.v2h_1 = false;
return Unit_instance;
}
function performRequest$lambda($this_performRequest, $request, $$this$get) {
return function ($this$headers) {
$this$headers.f1r('User-Agent', 'Ktor HTTP Client, @earth-app/shovel');
$this$headers.f1r('Host', substringBefore(substringAfter($this_performRequest, '://'), _Char___init__impl__6a9atx(47)));
$this$headers.f1r('Accept-Language', 'en-US,en;q=0.9');
$this$headers.f1r('Connection', 'keep-alive');
$this$headers.f1r('Upgrade-Insecure-Requests', '1');
$request($$this$get);
return Unit_instance;
};
}
function fetchDocument$lambda(_this__u8e3s4) {
_init_properties_http_kt__yecow8();
return Unit_instance;
}
function $performRequestCOROUTINE$(_this__u8e3s4, request, resultContinuation) {
CoroutineImpl.call(this, resultContinuation);
this.k4t_1 = _this__u8e3s4;
this.l4t_1 = request;
}
protoOf($performRequestCOROUTINE$).u8 = function () {
var suspendResult = this.o8_1;
$sm: do
try {
var tmp = this.m8_1;
switch (tmp) {
case 0:
this.n8_1 = 6;
this.n8_1 = 2;
var tmp_0 = this;
tmp_0.n4t_1 = get_client();
var tmp_1 = this;
tmp_1.o4t_1 = this.k4t_1;
this.p4t_1 = this.n4t_1;
this.q4t_1 = this.o4t_1;
var tmp_2 = this;
tmp_2.r4t_1 = this.p4t_1;
this.s4t_1 = this.r4t_1;
var tmp_3 = this;
tmp_3.t4t_1 = this.s4t_1;
var tmp_4 = this;
var this_0 = new HttpRequestBuilder();
url(this_0, this.q4t_1);
headers(this_0, performRequest$lambda(this.k4t_1, this.l4t_1, this_0));
tmp_4.u4t_1 = this_0;
this.v4t_1 = this.t4t_1;
this.w4t_1 = this.u4t_1;
this.w4t_1.f2h_1 = Companion_getInstance().t21_1;
var tmp_5 = this;
tmp_5.x4t_1 = this.v4t_1;
var tmp_6 = this;
tmp_6.y4t_1 = this.w4t_1;
this.z4t_1 = this.x4t_1;
this.a4u_1 = this.y4t_1;
this.m8_1 = 1;
suspendResult = (new HttpStatement(this.a4u_1, this.z4t_1)).q3b(this);
if (suspendResult === get_COROUTINE_SUSPENDED()) {
return suspendResult;
}
continue $sm;
case 1:
this.m4t_1 = suspendResult;
this.n8_1 = 6;
this.m8_1 = 3;
continue $sm;
case 2:
this.n8_1 = 6;
var tmp_7 = this.p8_1;
if (tmp_7 instanceof Error) {
this.b4u_1 = this.p8_1;
var tmp_8 = this;
throw IOException_init_$Create$("Error happened when trying to fetch '" + this.k4t_1 + "': " + this.b4u_1.message, this.b4u_1);
} else {
throw this.p8_1;
}
case 3:
this.n8_1 = 6;
this.c4u_1 = this.m4t_1;
if (!isSuccess(this.c4u_1.b2j())) {
this.d4u_1 = this.c4u_1.b2j().toString();
this.m8_1 = 5;
suspendResult = bodyAsText(this.c4u_1, Charsets_getInstance().m1l_1, this);
if (suspendResult === get_COROUTINE_SUSPENDED()) {
return suspendResult;
}
continue $sm;
} else {
this.m8_1 = 4;
continue $sm;
}
case 4:
return this.c4u_1;
case 5:
var ARGUMENT = suspendResult;
var ARGUMENT_0 = "Failed to fetch '" + this.k4t_1 + "': " + this.d4u_1 + '\n' + ARGUMENT;
throw IOException_init_$Create$_0(ARGUMENT_0);
case 6:
throw this.p8_1;
}
} catch ($p) {
var e = $p;
if (this.n8_1 === 6) {
throw e;
} else {
this.m8_1 = this.n8_1;
this.p8_1 = e;
}
}
while (true);
};
function $fetchDocumentCOROUTINE$(_this__u8e3s4, request, resultContinuation) {
CoroutineImpl.call(this, resultContinuation);
this.m4u_1 = _this__u8e3s4;
this.n4u_1 = request;
}
protoOf($fetchDocumentCOROUTINE$).u8 = function () {
var suspendResult = this.o8_1;
$sm: do
try {
var tmp = this.m8_1;
switch (tmp) {
case 0:
this.n8_1 = 3;
var tmp0 = get_cache();
var key = this.m4u_1;
if ((isInterface(tmp0, KtMap) ? tmp0 : THROW_CCE()).c2(key))
return ensureNotNull(get_cache().e2(this.m4u_1));
this.m8_1 = 1;
suspendResult = performRequest(this.m4u_1, this.n4u_1, this);
if (suspendResult === get_COROUTINE_SUSPENDED()) {
return suspendResult;
}
continue $sm;
case 1:
this.o4u_1 = suspendResult;
this.m8_1 = 2;
suspendResult = bodyAsText(this.o4u_1, Charsets_getInstance().m1l_1, this);
if (suspendResult === get_COROUTINE_SUSPENDED()) {
return suspendResult;
}
continue $sm;
case 2:
var text = suspendResult;
var tmp0_0 = get_cache();
var tmp2 = this.m4u_1;
var value = new Document(this.m4u_1, text);
tmp0_0.h2(tmp2, value);
return new Document(this.m4u_1, text);
case 3:
throw this.p8_1;
}
} catch ($p) {
var e = $p;
if (this.n8_1 === 3) {
throw e;
} else {
this.m8_1 = this.n8_1;
this.p8_1 = e;
}
}
while (true);
};
var properties_initialized_http_kt_3zhpnu;
function _init_properties_http_kt__yecow8() {
if (!properties_initialized_http_kt_3zhpnu) {
properties_initialized_http_kt_3zhpnu = true;
// Inline function 'kotlin.collections.mutableMapOf' call
cache = LinkedHashMap_init_$Create$();
}
}
function get_engine() {
_init_properties_http_js_kt__7qsee5();
return engine;
}
var engine;
function documentQuerySelectorAll(_this__u8e3s4, selector) {
_init_properties_http_js_kt__7qsee5();
var doc = Ksoup_instance.a3j(_this__u8e3s4.html);
// Inline function 'kotlin.collections.map' call
var this_0 = doc.g3t(selector);
// Inline function 'kotlin.collections.mapTo' call
var destination = ArrayList_init_$Create$_0(collectionSizeOrDefault(this_0, 10));
var _iterator__ex2g4s = this_0.g();
while (_iterator__ex2g4s.h()) {
var item = _iterator__ex2g4s.i();
var tmp$ret$0 = convert(item);
destination.e(tmp$ret$0);
}
return destination;
}
function elementQuerySelectorAll(_this__u8e3s4, selector) {
_init_properties_http_js_kt__7qsee5();
var element = Ksoup_instance.a3j(_this__u8e3s4.outerHTML);
// Inline function 'kotlin.collections.map' call
var this_0 = element.g3t(selector);
// Inline function 'kotlin.collections.mapTo' call
var destination = ArrayList_init_$Create$_0(collectionSizeOrDefault(this_0, 10));
var _iterator__ex2g4s = this_0.g();
while (_iterator__ex2g4s.h()) {
var item = _iterator__ex2g4s.i();
var tmp$ret$0 = convert(item);
destination.e(tmp$ret$0);
}
return destination;
}
function convert(_this__u8e3s4) {
_init_properties_http_js_kt__7qsee5();
var tmp = _this__u8e3s4.y3s();
var tmp_0 = _this__u8e3s4.y3m();
var tmp_1 = _this__u8e3s4.k3q();
var tmp_2 = _this__u8e3s4.q3t();
var tmp_3 = _this__u8e3s4.t3t();
// Inline function 'kotlin.collections.associate' call
var this_0 = _this__u8e3s4.f3p();
var capacity = coerceAtLeast(mapCapacity(collectionSizeOrDefault(this_0, 10)), 16);
// Inline function 'kotlin.collections.associateTo' call
var destination = LinkedHashMap_init_$Create$_0(capacity);
var _iterator__ex2g4s = this_0.g();
while (_iterator__ex2g4s.h()) {
var element = _iterator__ex2g4s.i();
// Inline function 'kotlin.collections.plusAssign' call
var pair = to(element.s(), element.t());
destination.h2(pair.wf_1, pair.xf_1);
}
var tmp_4 = destination;
// Inline function 'kotlin.collections.map' call
var this_1 = _this__u8e3s4.c3t();
// Inline function 'kotlin.collections.mapTo' call
var destination_0 = ArrayList_init_$Create$_0(collectionSizeOrDefault(this_1, 10));
var _iterator__ex2g4s_0 = this_1.g();
while (_iterator__ex2g4s_0.h()) {
var item = _iterator__ex2g4s_0.i();
var tmp$ret$4 = convert(item);
destination_0.e(tmp$ret$4);
}
return new Element(tmp, tmp_0, tmp_1, tmp_2, tmp_3, tmp_4, destination_0);
}
function engine$lambda($this$create) {
_init_properties_http_js_kt__7qsee5();
$this$create.w2n_1 = true;
$this$create.v2n_1 = Dispatchers_getInstance().rw_1;
return Unit_instance;
}
var properties_initialized_http_js_kt_k0xa5d;
function _init_properties_http_js_kt__7qsee5() {
if (!properties_initialized_http_js_kt_k0xa5d) {
properties_initialized_http_js_kt_k0xa5d = true;
var tmp = Js_instance;
engine = tmp.u3c(engine$lambda);
}
}
function fetchDocumentAsPromise(_this__u8e3s4) {
var tmp = GlobalScope_instance;
return promise(tmp, VOID, VOID, fetchDocumentAsPromise$slambda_0(_this__u8e3s4, null));
}
function fetchAsPromise(url) {
return fetchDocumentAsPromise(url);
}
function fetchDocumentAsPromise$slambda($this_fetchDocumentAsPromise, resultContinuation) {
this.x4u_1 = $this_fetchDocumentAsPromise;
CoroutineImpl.call(this, resultContinuation);
}
protoOf(fetchDocumentAsPromise$slambda).z4u = function ($this$promise, $completion) {
var tmp = this.s1k($this$promise, $completion);
tmp.o8_1 = Unit_instance;
tmp.p8_1 = null;
return tmp.u8();
};
protoOf(fetchDocumentAsPromise$slambda).i9 = function (p1, $completion) {
return this.z4u((!(p1 == null) ? isInterface(p1, CoroutineScope) : false) ? p1 : THROW_CCE(), $completion);
};
protoOf(fetchDocumentAsPromise$slambda).u8 = function () {
var suspendResult = this.o8_1;
$sm: do
try {
var tmp = this.m8_1;
switch (tmp) {
case 0:
this.n8_1 = 2;
this.m8_1 = 1;
suspendResult = fetchDocument(this.x4u_1, VOID, this);
if (suspendResult === get_COROUTINE_SUSPENDED()) {
return suspendResult;
}
continue $sm;
case 1:
return suspendResult;
case 2:
throw this.p8_1;
}
} catch ($p) {
var e = $p;
if (this.n8_1 === 2) {
throw e;
} else {
this.m8_1 = this.n8_1;
this.p8_1 = e;
}
}
while (true);
};
protoOf(fetchDocumentAsPromise$slambda).s1k = function ($this$promise, completion) {
var i = new fetchDocumentAsPromise$slambda(this.x4u_1, completion);
i.y4u_1 = $this$promise;
return i;
};
function fetchDocumentAsPromise$slambda_0($this_fetchDocumentAsPromise, resultContinuation) {
var i = new fetchDocumentAsPromise$slambda($this_fetchDocumentAsPromise, resultContinuation);
var l = function ($this$promise, $completion) {
return i.z4u($this$promise, $completion);
};
l.$arity = 1;
return l;
}
//region block: post-declaration
defineProp(protoOf(Element), 'id', protoOf(Element).s4s);
defineProp(protoOf(Element), 'classes', protoOf(Element).t4s);
defineProp(protoOf(Element), 'style', protoOf(Element).u4s);
defineProp(protoOf(Document), 'body', protoOf(Document).w4s);
defineProp(protoOf(Document), 'bodyElements', protoOf(Document).x4s);
defineProp(protoOf(Document), 'head', protoOf(Document).y4s);
defineProp(protoOf(Document), 'title', protoOf(Document).z4s);
defineProp(protoOf(Document), 'metadata', protoOf(Document).a4t);
defineProp(protoOf(Document), 'linkTags', protoOf(Document).b4t);
//endregion
//region block: exports
function $jsExportAll$(_) {
var $com = _.com || (_.com = {});
var $com$earthapp = $com.earthapp || ($com.earthapp = {});
var $com$earthapp$shovel = $com$earthapp.shovel || ($com$earthapp.shovel = {});
$com$earthapp$shovel.closeClient = closeClient;
$com$earthapp$shovel.clearCache = clearCache;
$com$earthapp$shovel.Element = Element;
$com$earthapp$shovel.Document = Document;
$com$earthapp$shovel.documentQuerySelector = documentQuerySelector;
$com$earthapp$shovel.documentGetElementById = documentGetElementById;
$com$earthapp$shovel.documentGetElementsByClassName = documentGetElementsByClassName;
$com$earthapp$shovel.documentInputValue = documentInputValue;
$com$earthapp$shovel.elementQuerySelector = elementQuerySelector;
$com$earthapp$shovel.elementGetElementById = elementGetElementById;
$com$earthapp$shovel.elementGetElementsByClassName = elementGetElementsByClassName;
$com$earthapp$shovel.elementInputValue = elementInputValue;
var $com = _.com || (_.com = {});
var $com$earthapp = $com.earthapp || ($com.earthapp = {});
var $com$earthapp$shovel = $com$earthapp.shovel || ($com$earthapp.shovel = {});
$com$earthapp$shovel.documentQuerySelectorAll = documentQuerySelectorAll;
$com$earthapp$shovel.elementQuerySelectorAll = elementQuerySelectorAll;
_.fetchDocumentAsPromise = fetchDocumentAsPromise;
_.fetchAsPromise = fetchAsPromise;
}
$jsExportAll$(_);
kotlin_kotlin.$jsExportAll$(_);
kotlin_io_ktor_ktor_client_core.$jsExportAll$(_);
//endregion
return _;
}));
//# sourceMappingURL=shovel.js.map