Skip to content
Open
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c7764af
Add `both` to Angular directive type
davidjbradshaw Oct 21, 2025
8951821
Refactor
davidjbradshaw Oct 22, 2025
a279ffa
Move file
davidjbradshaw Oct 22, 2025
371a19e
Extract title functions from core
davidjbradshaw Oct 22, 2025
3375f5c
Extract createOutgoingMessage()
davidjbradshaw Oct 22, 2025
7416b44
Extract iframeReady()
davidjbradshaw Oct 22, 2025
1ea7486
Extract trigger
davidjbradshaw Oct 22, 2025
4985b98
Extract setOffsetSize()
davidjbradshaw Oct 22, 2025
55e7a37
Extract parent-props
davidjbradshaw Oct 22, 2025
9646eb2
Extract checkEvent
davidjbradshaw Oct 22, 2025
c6ffe8c
Extract page-position
davidjbradshaw Oct 22, 2025
f2ad2e2
Create `core/page`
davidjbradshaw Oct 22, 2025
61f506e
Fix move of title
davidjbradshaw Oct 22, 2025
807917c
Extract scroll functions
davidjbradshaw Oct 22, 2025
0b6a371
Extract sizing functions from core
davidjbradshaw Oct 22, 2025
f909df3
Extract receiver functions
davidjbradshaw Oct 22, 2025
93c4901
Extract mouse events from core
davidjbradshaw Oct 22, 2025
d786945
Reorder router
davidjbradshaw Oct 22, 2025
64a62d0
rename function
davidjbradshaw Oct 22, 2025
586bef2
Revert git stash pop
davidjbradshaw Oct 22, 2025
d223da5
Extract checks
davidjbradshaw Oct 22, 2025
019c0e6
Extract more checks
davidjbradshaw Oct 22, 2025
fe2b8e9
Yet more extracted checks
davidjbradshaw Oct 22, 2025
03b7473
Extract firstRun()
davidjbradshaw Oct 22, 2025
dbd48af
Extract inPageLink and fix scrollTo
davidjbradshaw Oct 23, 2025
ed7a602
Extract methods from core
davidjbradshaw Oct 23, 2025
9c8d07a
Extract setup props
davidjbradshaw Oct 23, 2025
c76b508
Extract setup logging
davidjbradshaw Oct 23, 2025
33a7227
Extract init
davidjbradshaw Oct 23, 2025
b8214f2
Extract processOption()
davidjbradshaw Oct 23, 2025
17a873d
Extract getMessageBody()
davidjbradshaw Oct 23, 2025
d163e72
Extract message router from core
davidjbradshaw Oct 23, 2025
8d03c4c
receive -> received
davidjbradshaw Oct 23, 2025
2917bae
move on
davidjbradshaw Oct 23, 2025
3874353
Split message.js
davidjbradshaw Oct 23, 2025
aa61312
Extract iframe setup from core
davidjbradshaw Oct 23, 2025
e3ac761
Extract tabVisible
davidjbradshaw Oct 23, 2025
1eab6bb
Update banner
davidjbradshaw Oct 23, 2025
feecf77
isObject()
davidjbradshaw Oct 23, 2025
83a20c4
tidy
davidjbradshaw Oct 23, 2025
713dffe
Tidy
davidjbradshaw Oct 23, 2025
3d679cd
Code Review
davidjbradshaw Oct 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/angular/directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type iframeResizerOptions = {
bodyMargin?: string | number | null
bodyPadding?: string | number | null
checkOrigin?: boolean | string[]
direction?: 'vertical' | 'horizontal' | 'none'
direction?: 'vertical' | 'horizontal' | 'both' | 'none'
inPageLinks?: boolean
license: string
offsetSize?: number
Expand Down
4 changes: 2 additions & 2 deletions packages/child/check-blocking-css.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AUTO } from '../common/consts'
import { AUTO, NONE } from '../common/consts'
import { advise, log } from './console'

const nodes = () => [document.documentElement, document.body]
Expand All @@ -7,7 +7,7 @@ const properties = ['min-height', 'min-width', 'max-height', 'max-width']
const blockedStyleSheets = new Set()

const hasCssValue = (value) =>
value && value !== '0px' && value !== AUTO && value !== 'none'
value && value !== '0px' && value !== AUTO && value !== NONE

const getElementName = (node) =>
node.tagName ? node.tagName.toLowerCase() : 'unknown'
Expand Down
4 changes: 2 additions & 2 deletions packages/child/observers/overflow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HIGHLIGHT } from 'auto-console-group'

import { HEIGHT_EDGE, OVERFLOW_ATTR } from '../../common/consts'
import { HEIGHT_EDGE, NONE, OVERFLOW_ATTR } from '../../common/consts'
import { id } from '../../common/utils'
import { info } from '../console'
import {
Expand All @@ -17,7 +17,7 @@ const logNewlyObserved = createLogNewlyObserved(OVERFLOW)
const warnAlreadyObserved = createWarnAlreadyObserved(OVERFLOW)

const isHidden = (node) =>
node.hidden || node.offsetParent === null || node.style.display === 'none'
node.hidden || node.offsetParent === null || node.style.display === NONE

const createOverflowObserver = (callback, options) => {
const side = options.side || HEIGHT_EDGE
Expand Down
6 changes: 0 additions & 6 deletions packages/child/observers/perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ export const PREF_END = '--ifr-end'
const PREF_MEASURE = '--ifr-measure'

const timings = []
// const usedTags = new WeakSet()

// const addUsedTag = (el) => typeof el === OBJECT && usedTags.add(el)

let detail = {}
let oldAverage = 0
Expand Down Expand Up @@ -98,9 +95,6 @@ export default function createPerformanceObserver() {
const observer = new PerformanceObserver(perfObserver)
observer.observe({ entryTypes: ['mark'] })

// addUsedTag(document.documentElement)
// addUsedTag(document.body)

startTimingCheck()

return {
Expand Down
32 changes: 32 additions & 0 deletions packages/core/checks/id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { isString } from '../../common/utils'
import { event as consoleEvent, log } from '../console'
import defaults from '../values/defaults'

let count = 0

function newId(options) {
let id = options?.id || defaults.id + count++

if (document.getElementById(id) !== null) {
id += count++
}

return id
}

export default function ensureHasId(iframe, options) {
let { id } = iframe

if (id && !isString(id)) {
throw new TypeError('Invalid id for iFrame. Expected String')
}

if (!id || id === '') {
id = newId(options)
iframe.id = id
consoleEvent(id, 'assignId')
log(id, `Added missing iframe ID: ${id} (${iframe.src})`)
}

return id
}
10 changes: 10 additions & 0 deletions packages/core/checks/manual-logging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { COLLAPSE } from '../../common/consts'

export default function (options) {
const { search } = window.location

if (search.includes('ifrlog')) {
options.log = COLLAPSE
options.logExpand = search.includes('ifrlog=expanded')
}
}
38 changes: 38 additions & 0 deletions packages/core/checks/mode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { VERSION } from '../../common/consts'
import { getModeData, getModeLabel } from '../../common/mode'
import { advise, purge as consoleClear, vInfo } from '../console'
import settings from '../values/settings'

let vAdvised = false
let vInfoDisable = false

export default function checkMode(id, childMode = -3) {
if (vAdvised) return
const mode = Math.max(settings[id].mode, childMode)
if (mode > settings[id].mode) settings[id].mode = mode
if (mode < 0) {
consoleClear(id)
if (!settings[id].vAdvised)
advise(id || 'Parent', `${getModeData(mode + 2)}${getModeData(2)}`)
settings[id].vAdvised = true
throw getModeData(mode + 2).replace(/<\/?[a-z][^>]*>|<\/>/gi, '')
}
if (!(mode > 0 && vInfoDisable)) {
vInfo(`v${VERSION} (${getModeLabel(mode)})`, mode)
}
if (mode < 1) advise('Parent', getModeData(3))
vAdvised = true
}

export function preModeCheck(id) {
if (vAdvised) return
const { mode } = settings[id]
if (mode !== -1) checkMode(id, mode)
}

export function enableVInfo(options) {
if (options?.log === -1) {
options.log = false
vInfoDisable = true
}
}
28 changes: 28 additions & 0 deletions packages/core/checks/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
AUTO_RESIZE,
BOTH,
HORIZONTAL,
NONE,
VERTICAL,
} from '../../common/consts'
import { advise } from '../console'

export default function checkOptions(id, options) {
if (!options) return {}

if (
'sizeWidth' in options ||
'sizeHeight' in options ||
AUTO_RESIZE in options
) {
advise(
id,
`<rb>Deprecated Option</>

The <b>sizeWidth</>, <b>sizeHeight</> and <b>autoResize</> options have been replaced with new <b>direction</> option which expects values of <bb>${VERTICAL}</>, <bb>${HORIZONTAL}</>, <bb>${BOTH}</> or <bb>${NONE}</>.
`,
)
}

return options
}
15 changes: 15 additions & 0 deletions packages/core/checks/origin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { HIGHLIGHT } from 'auto-console-group'

import { log } from '../console'
import settings from '../values/settings'

export default function checkSameDomain(id) {
try {
settings[id].sameOrigin =
!!settings[id]?.iframe?.contentWindow?.iframeChildListener
} catch (error) {
settings[id].sameOrigin = false
}

log(id, `sameOrigin: %c${settings[id].sameOrigin}`, HIGHLIGHT)
}
27 changes: 27 additions & 0 deletions packages/core/checks/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { FOREGROUND, HIGHLIGHT } from 'auto-console-group'

import { VERSION } from '../../common/consts'
import { advise, log } from '../console'

export default function checkVersion(id, version) {
if (version === VERSION) return
if (version === undefined) {
advise(
id,
`<rb>Legacy version detected in iframe</>

Detected legacy version of child page script. It is recommended to update the page in the iframe to use <b>@iframe-resizer/child</>.

See <u>https://iframe-resizer.com/setup/#child-page-setup</> for more details.
`,
)
return
}
log(
id,
`Version mismatch (Child: %c${version}%c !== Parent: %c${VERSION})`,
HIGHLIGHT,
FOREGROUND,
HIGHLIGHT,
)
}
10 changes: 10 additions & 0 deletions packages/core/checks/warning-timeout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { HIGHLIGHT } from 'auto-console-group'

import { info } from '../console'
import settings from '../values/settings'

export default function checkWarningTimeout(id) {
if (!settings[id].warningTimeout) {
info(id, 'warningTimeout:%c disabled', HIGHLIGHT)
}
}
28 changes: 28 additions & 0 deletions packages/core/events/mouse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { SEPARATOR } from '../../common/consts'
import { getMessageBody } from '../received/message'
import on from './wrapper'

export default function onMouse(event, messageData) {
const { id, iframe, height, type, width } = messageData
let mousePos = {}

if (width === 0 && height === 0) {
const coords = getMessageBody(id, 9).split(SEPARATOR)
mousePos = {
x: coords[1],
y: coords[0],
}
} else {
mousePos = {
x: width,
y: height,
}
}

on(id, event, {
iframe,
screenX: Number(mousePos.x),
screenY: Number(mousePos.y),
type,
})
}
28 changes: 28 additions & 0 deletions packages/core/events/size.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { HIGHLIGHT } from 'auto-console-group'

import { HEIGHT, WIDTH } from '../../common/consts'
import { info } from '../console'
import { setPagePosition } from '../page/position'
import settings from '../values/settings'
import checkEvent from './wrapper'

export function setSize(messageData) {
function setDimension(dimension) {
const size = `${messageData[dimension]}px`
messageData.iframe.style[dimension] = size
info(id, `Set ${dimension}: %c${size}`, HIGHLIGHT)
}

const { id } = messageData
const { sizeHeight, sizeWidth } = settings[id]

if (sizeHeight) setDimension(HEIGHT)
if (sizeWidth) setDimension(WIDTH)
}

export function resizeIframe(messageData) {
const { id } = messageData
setSize(messageData)
setPagePosition(id)
checkEvent(id, 'onResized', messageData)
}
27 changes: 27 additions & 0 deletions packages/core/events/wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { FUNCTION } from '../../common/consts'
import { isolateUserCode } from '../../common/utils'
import { warn } from '../console'
import settings from '../values/settings'

function on(iframeId, funcName, val) {
if (!settings[iframeId]) return null

const func = settings[iframeId][funcName]

if (typeof func !== FUNCTION)
throw new TypeError(`${funcName} on iframe[${iframeId}] is not a function`)

if (funcName !== 'onBeforeClose' && funcName !== 'onScroll')
return isolateUserCode(func, val)

try {
return func(val)
} catch (error) {
// eslint-disable-next-line no-console
console.error(error)
warn(iframeId, `Error in ${funcName} callback`)
return null
}
}

export default on
Loading