pull/4999/head
pushkine 5 years ago
parent ab09b33d19
commit 5d1608a245

@ -1,9 +1,8 @@
import { add_render_callback, flush, schedule_update } from './scheduler';
import { current_component, set_current_component } from './lifecycle';
import { blank_object, is_function, run, run_all } from './utils';
import { blank_object, is_function, run, run_all, noop } from './utils';
import { children, detach } from './dom';
import { transition_in } from './transitions';
import { noop } from './environment';
export interface Fragment {
key: string|null;

@ -1,6 +1,5 @@
import { run_transition } from './transitions';
import { noop } from './environment';
import { methodify } from './utils';
import { methodify, noop } from './utils';
import { CssTransitionConfig } from 'svelte/transition';
type AnimationFn = (node: Element, { from, to }: { from: DOMRect; to: DOMRect }, params: any) => CssTransitionConfig;

@ -1,6 +1,5 @@
import { custom_event, append, insert, detach, listen, attr } from './dom';
import { SvelteComponent } from './Component';
import { has_Symbol } from './environment';
export function dispatch_dev<T=any>(type: string, detail?: T) {
document.dispatchEvent(custom_event(type, { version: '__VERSION__', ...detail }));
@ -83,7 +82,7 @@ export function set_data_dev(text, data) {
export function validate_each_argument(arg) {
if (typeof arg !== 'string' && !(arg && typeof arg === 'object' && 'length' in arg)) {
let msg = '{#each} only iterates over array-like objects.';
if (has_Symbol && arg && Symbol.iterator in arg) {
if (typeof Symbol === 'function' && arg && Symbol.iterator in arg) {
msg += ' You can use a spread to convert this iterable into an array.';
}
throw new Error(msg);
@ -141,4 +140,4 @@ export function loop_guard(timeout) {
throw new Error(`Infinite loop detected`);
}
};
}
}

@ -1,5 +1,4 @@
import { has_prop } from "./utils";
import { is_cors } from "./environment";
export function append(target: Node, node: Node) {
target.appendChild(node);
@ -235,6 +234,26 @@ 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;
@ -251,9 +270,11 @@ 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 (is_cors) {
if (crossorigin) {
iframe.src = `data:text/html,<script>onresize=function(){parent.postMessage(0,'*')}</script>`;
unsubscribe = listen(window, 'message', (event: MessageEvent) => {
if (event.source === iframe.contentWindow) fn();
@ -268,7 +289,7 @@ export function add_resize_listener(node: HTMLElement, fn: () => void) {
append(node, iframe);
return () => {
if (is_cors) {
if (crossorigin) {
unsubscribe();
} else if (unsubscribe && iframe.contentWindow) {
unsubscribe();
@ -333,4 +354,4 @@ export class HtmlTag {
d() {
this.n.forEach(detach);
}
}
}

@ -1,23 +1,12 @@
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;
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 let framerate = 1000 / 60;
/*#__PURE__*/ raf((t1) => {
raf((d) => {
@ -27,6 +16,11 @@ export let framerate = 1000 / 60;
});
});
/* tests only */
export const set_now = (v) => void (now = v);
export const set_raf = (fn) => void (raf = fn);
// used internally for testing
export function set_now(fn) {
now = fn;
}
export function set_raf(fn) {
raf = fn;
}

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

@ -1,4 +1,5 @@
import { now, raf, framerate, noop } from './environment';
import { now, raf, framerate } from './environment';
import { noop } from './utils';
type TaskCallback = (t: number) => boolean;
type TaskCanceller = () => void;

@ -1,7 +1,9 @@
import { set_current_component } from './lifecycle';
import { resolved_promise, now } from './environment';
import { now } from './environment';
import { T$$ } from './Component';
const resolved_promise = Promise.resolve();
let update_scheduled = false;
let is_flushing = false;

@ -1,11 +1,11 @@
import { CssTransitionConfig } from '../transition';
import { Fragment } from './Component';
import { custom_event } from './dom';
import { now, noop } from './environment';
import { now } from './environment';
import { setFrameTimeout, setTweenTimeout } from './loop';
import { add_measure_callback } from './scheduler';
import { animate_css } from './style_manager';
import { methodify } from './utils';
import { methodify, noop } from './utils';
type TransitionFn = (node: HTMLElement, params: any) => CssTransitionConfig;
export type StopResetReverseFn = (t?: number | -1) => StopResetReverseFn | void;

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

Loading…
Cancel
Save