pull/4950/head
pushkine 5 years ago
parent a4dadf82be
commit 2c4ce92017

@ -1,6 +1,7 @@
import { add_render_callback, flush, schedule_update, dirty_components } from './scheduler';
import { current_component, set_current_component } from './lifecycle';
import { blank_object, is_function, run, run_all, noop } from './utils';
import { blank_object, is_function, run, run_all } from './utils';
import { noop } from './environment';
import { children, detach } from './dom';
import { transition_in } from './transitions';

@ -1,5 +1,5 @@
import { identity as linear, noop } from './utils';
import { now } from './environment';
import { identity as linear } from './utils';
import { now, noop } from './environment';
import { loop } from './loop';
import { create_rule, delete_rule } from './style_manager';
import { AnimationConfig } from '../animate';

@ -1,4 +1,5 @@
import { has_prop } from "./utils";
import { is_cors } from "./environment";
export function append(target: Node, node: Node) {
target.appendChild(node);
@ -234,26 +235,6 @@ export function select_multiple_value(select) {
return [].map.call(select.querySelectorAll(':checked'), option => option.__value);
}
// unfortunately this can't be a constant as that wouldn't be tree-shakeable
// so we cache the result instead
let crossorigin: boolean;
export function is_crossorigin() {
if (crossorigin === undefined) {
crossorigin = false;
try {
if (typeof window !== 'undefined' && window.parent) {
void window.parent.document;
}
} catch (error) {
crossorigin = true;
}
}
return crossorigin;
}
export function add_resize_listener(node: HTMLElement, fn: () => void) {
const computed_style = getComputedStyle(node);
const z_index = (parseInt(computed_style.zIndex) || 0) - 1;
@ -270,11 +251,9 @@ export function add_resize_listener(node: HTMLElement, fn: () => void) {
iframe.setAttribute('aria-hidden', 'true');
iframe.tabIndex = -1;
const crossorigin = is_crossorigin();
let unsubscribe: () => void;
if (crossorigin) {
if (is_cors) {
iframe.src = `data:text/html,<script>onresize=function(){parent.postMessage(0,'*')}</script>`;
unsubscribe = listen(window, 'message', (event: MessageEvent) => {
if (event.source === iframe.contentWindow) fn();
@ -289,7 +268,7 @@ export function add_resize_listener(node: HTMLElement, fn: () => void) {
append(node, iframe);
return () => {
if (crossorigin) {
if (is_cors) {
unsubscribe();
} else if (unsubscribe && iframe.contentWindow) {
unsubscribe();

@ -1,12 +1,23 @@
import { noop } from './utils';
export const is_client = typeof window !== 'undefined';
export let now: () => number = is_client
? () => window.performance.now()
: () => Date.now();
export let raf = is_client ? cb => requestAnimationFrame(cb) : noop;
export function noop() {}
export const is_browser = typeof window !== 'undefined';
export const is_iframe = is_browser && window.self !== window.top;
export const is_cors =
is_iframe &&
/*#__PURE__*/ (() => {
try {
if (window.parent) void window.parent.document;
return false;
} catch (error) {
return true;
}
})();
export const has_Symbol = typeof Symbol === 'function';
/* eslint-disable no-var */
declare var global: any;
export const globals = is_browser ? window : typeof globalThis !== 'undefined' ? globalThis : global;
export const resolved_promise = Promise.resolve();
export let now = is_browser ? window.performance.now.bind(window.performance) : Date.now.bind(Date);
export let raf = is_browser ? requestAnimationFrame : noop;
// used internally for testing
export function set_now(fn) {

@ -1,7 +0,0 @@
declare const global: any;
export const globals = (typeof window !== 'undefined'
? window
: typeof globalThis !== 'undefined'
? globalThis
: global) as unknown as typeof globalThis;

@ -2,7 +2,6 @@ export * from './animations';
export * from './await_block';
export * from './dom';
export * from './environment';
export * from './globals';
export * from './keyed_each';
export * from './lifecycle';
export * from './loop';

@ -1,5 +1,6 @@
import { run_all } from './utils';
import { set_current_component } from './lifecycle';
import { resolved_promise } from './environment';
export const dirty_components = [];
export const intros = { enabled: false };
@ -8,7 +9,6 @@ export const binding_callbacks = [];
const render_callbacks = [];
const flush_callbacks = [];
const resolved_promise = Promise.resolve();
let update_scheduled = false;
export function schedule_update() {

@ -1,5 +1,5 @@
import { identity as linear, is_function, noop, run_all } from './utils';
import { now } from "./environment";
import { identity as linear, is_function, run_all } from './utils';
import { now, noop } from "./environment";
import { loop } from './loop';
import { create_rule, delete_rule } from './style_manager';
import { custom_event } from './dom';

@ -1,5 +1,4 @@
export function noop() {}
import { noop } from './environment';
export const identity = x => x;
export function assign<T, S>(tar: T, src: S): T & S {

Loading…
Cancel
Save