-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cafb0b9
Showing
221 changed files
with
7,424 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* -text |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>MyBlazorWasmApp1.Stories</title> | ||
<base href="/BlazingStory/" /> | ||
<!-- | ||
If you need to add <link> or <script> elements to include CSS or JavaScript files | ||
for canvas views of your Stories, | ||
YOU SHOULD DO THAT IN THE "iframe.html" FILE, NOT HERE. | ||
--> | ||
<link rel="stylesheet" href="css/blazor-ui.css" /> | ||
</head> | ||
|
||
<body> | ||
<div id="app"> | ||
<div class="loading-progress"> | ||
<svg> | ||
<circle r="40%" cx="50%" cy="50%" /> | ||
<circle r="40%" cx="50%" cy="50%" /> | ||
</svg> | ||
<div class="text"></div> | ||
<img src="_content/BlazingStory/images/icon.min.svg" /> | ||
</div> | ||
</div> | ||
|
||
<div id="blazor-error-ui"> | ||
An unhandled error has occurred. | ||
<a href="" class="reload">Reload</a> | ||
<a class="dismiss">🗙</a> | ||
</div> | ||
|
||
<!-- | ||
If you need to add <script> elements to include JavaScript files for canvas views of your Stories, | ||
YOU SHOULD DO THAT IN THE "iframe.html" FILE, NOT HERE. | ||
--> | ||
<script src="_framework/blazor.webassembly.js" autostart="false"></script> | ||
<script src="brotliloader.min.js" type="module"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@import '_content/Toolbelt.Blazor.SplitContainer/Toolbelt.Blazor.SplitContainer.bundle.scp.css'; | ||
@import '_content/MyBlazorWasmApp1/MyBlazorWasmApp1.bundle.scp.css'; | ||
|
||
/* /App.razor.rz.scp.css */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const ensureAllFontsAndStylesAreLoaded = async () => { | ||
if (location.pathname !== "/") | ||
return; | ||
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)); | ||
for (const font of document.fonts) | ||
font.load(); | ||
for (;;) { | ||
const fonts = Array.from(document.fonts); | ||
if (fonts.every(font => font.status === "loaded")) | ||
break; | ||
await delay(10); | ||
} | ||
for (;;) { | ||
const styleSheets = Array.from(document.head.querySelectorAll('link[rel="stylesheet"]')); | ||
if (styleSheets.every(l => Boolean(l.sheet))) | ||
break; | ||
await delay(10); | ||
} | ||
}; | ||
const darkModeMediaQuery = window.matchMedia("(prefers-color-scheme: dark)"); | ||
export const getPrefersColorScheme = () => darkModeMediaQuery.matches ? "dark" : "light"; | ||
export const subscribePreferesColorSchemeChanged = (dotnetObjRef, methodName) => { | ||
const subscriber = (e) => { dotnetObjRef.invokeMethodAsync(methodName, getPrefersColorScheme()); }; | ||
darkModeMediaQuery.addEventListener("change", subscriber); | ||
return ({ dispose: () => darkModeMediaQuery.removeEventListener("change", subscriber) }); | ||
}; |
11 changes: 11 additions & 0 deletions
11
_content/BlazingStory/Internals/Components/Inputs/ColorInput.razor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const getComputedColor = (colorText) => { | ||
const element = document.createElement("div"); | ||
element.style.position = "fixed"; | ||
element.style.width = "0"; | ||
element.style.height = "0"; | ||
element.style.color = colorText; | ||
document.body.appendChild(element); | ||
const computedColorText = getComputedStyle(element).color; | ||
element.remove(); | ||
return computedColorText; | ||
}; |
9 changes: 9 additions & 0 deletions
9
_content/BlazingStory/Internals/Components/Menus/PopupMenu.razor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const subscribeDocumentEvent = (eventType, dotnetObj, methodName, popupMenuElement) => { | ||
const evendListener = (ev) => { | ||
if (popupMenuElement.contains(ev.target)) | ||
return; | ||
dotnetObj.invokeMethodAsync(methodName); | ||
}; | ||
document.addEventListener(eventType, evendListener); | ||
return ({ dispose: () => document.removeEventListener(eventType, evendListener) }); | ||
}; |
94 changes: 94 additions & 0 deletions
94
_content/BlazingStory/Internals/Components/Preview/PreviewFrame.razor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
class TimeoutError extends Error { | ||
constructor(message) { super(message); } | ||
} | ||
const waitFor = async (arg) => { | ||
var _a, _b; | ||
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)); | ||
let retryCount = 0; | ||
while (true) { | ||
const result = arg.predecate(); | ||
if (result !== false) | ||
return result; | ||
if (retryCount >= ((_a = arg.maxRetryCount) !== null && _a !== void 0 ? _a : 500)) | ||
throw new TimeoutError("Timeout"); | ||
retryCount++; | ||
await delay((_b = arg.retryInterval) !== null && _b !== void 0 ? _b : 10); | ||
} | ||
}; | ||
const waitForIFrameReady = async (iframe) => { | ||
return await waitFor({ | ||
predecate: () => { | ||
var _a; | ||
if (iframe.contentWindow === null || iframe.contentDocument === null) | ||
return false; | ||
if (iframe.contentWindow.location.href === "about:blank") | ||
return false; | ||
if (((_a = iframe.contentWindow.BlazingStory) === null || _a === void 0 ? void 0 : _a.canvasFrameInitialized) !== true) | ||
return false; | ||
return ({ contentWindow: iframe.contentWindow, contentDocument: iframe.contentDocument }); | ||
} | ||
}); | ||
}; | ||
export const navigatePreviewFrameTo = async (iframe, url) => { | ||
if (iframe === null) | ||
return; | ||
const { contentWindow, contentDocument } = await waitForIFrameReady(iframe); | ||
const event = new PopStateEvent("popstate", { state: {}, bubbles: true, cancelable: true }); | ||
contentWindow.history.pushState({}, "", url); | ||
contentDocument.dispatchEvent(event); | ||
}; | ||
export const reloadPreviewFrame = (iframe) => { | ||
if (iframe === null || iframe.contentWindow === null) | ||
return; | ||
iframe.contentWindow.postMessage({ action: "reload" }); | ||
}; | ||
const zoomPreviewFrame = (iframe, getNextZoomLevel) => { | ||
if (iframe === null || iframe.contentDocument === null) | ||
return; | ||
const style = iframe.contentDocument.body.style; | ||
const currentZoomLevel = parseFloat(style.zoom || '1'); | ||
const nextZoomLevel = getNextZoomLevel(currentZoomLevel); | ||
style.zoom = '' + nextZoomLevel; | ||
}; | ||
export const zoomInPreviewFrame = (iframe) => zoomPreviewFrame(iframe, zoom => zoom * 1.25); | ||
export const zoomOutPreviewFrame = (iframe) => zoomPreviewFrame(iframe, zoom => zoom / 1.25); | ||
export const resetZoomPreviewFrame = (iframe) => zoomPreviewFrame(iframe, _ => 1); | ||
export const subscribeComponentActionEvent = async (iframe, dotNetObj, methodName) => { | ||
try { | ||
if (iframe === null) | ||
return { dispose: () => { } }; | ||
const { contentDocument } = await waitForIFrameReady(iframe); | ||
const componentActionEventListener = (e) => dotNetObj.invokeMethodAsync(methodName, e.detail.name, e.detail.argsJson); | ||
contentDocument.addEventListener('componentActionEvent', componentActionEventListener); | ||
return { dispose: () => contentDocument.removeEventListener('componentActionEvent', componentActionEventListener) }; | ||
} | ||
catch (e) { | ||
if (e instanceof TimeoutError) | ||
return { dispose: () => { } }; | ||
throw e; | ||
} | ||
}; | ||
const isDotnetWatchScriptInjected = (window) => { | ||
var _a; | ||
const scriptInjectedSentinel = '_dotnet_watch_ws_injected'; | ||
return (_a = window === null || window === void 0 ? void 0 : window.hasOwnProperty(scriptInjectedSentinel)) !== null && _a !== void 0 ? _a : false; | ||
}; | ||
export const ensureDotnetWatchScriptInjected = async (iframe) => { | ||
try { | ||
if (iframe === null) | ||
return; | ||
const { contentWindow, contentDocument } = await waitForIFrameReady(iframe); | ||
if (!isDotnetWatchScriptInjected(window)) | ||
return; | ||
if (isDotnetWatchScriptInjected(contentWindow)) | ||
return; | ||
const script = contentDocument.createElement('script'); | ||
script.src = '_framework/aspnetcore-browser-refresh.js'; | ||
contentDocument.body.appendChild(script); | ||
} | ||
catch (e) { | ||
if (e instanceof TimeoutError) | ||
return; | ||
throw e; | ||
} | ||
}; |
25 changes: 25 additions & 0 deletions
25
_content/BlazingStory/Internals/Pages/Canvas/CanvasFrame.razor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export const ensurePreviewStyle = (background, styleDescripters) => { | ||
const doc = document; | ||
const head = doc.head; | ||
const bodyStyle = doc.body.style; | ||
bodyStyle.transition = "background-color 0.3s"; | ||
setTimeout(() => { bodyStyle.backgroundColor = background; }, 10); | ||
for (const descripter of styleDescripters) { | ||
const linkElement = head.querySelector(`link#${descripter.id}`); | ||
if (linkElement === null && descripter.enable) { | ||
const newLinkElement = doc.createElement("link"); | ||
newLinkElement.id = descripter.id; | ||
newLinkElement.href = descripter.href; | ||
newLinkElement.rel = "stylesheet"; | ||
head.appendChild(newLinkElement); | ||
} | ||
else if (linkElement !== null && !descripter.enable) { | ||
linkElement.remove(); | ||
} | ||
} | ||
}; | ||
export const dispatchComponentActionEvent = (name, argsJson) => { | ||
const componentActionEventDetail = { name, argsJson }; | ||
const event = new CustomEvent('componentActionEvent', { detail: componentActionEventDetail }); | ||
document.dispatchEvent(event); | ||
}; |
39 changes: 39 additions & 0 deletions
39
_content/BlazingStory/Internals/Pages/Canvas/MeasureLayer.razor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const doc = document; | ||
const targetEvents = [ | ||
"pointerenter", | ||
"pointerover", | ||
"pointerleave", | ||
"scroll" | ||
]; | ||
const pxToNumber = (px) => parseInt(px.replace("px", ""), 10); | ||
const getSpacingSize = (style, prefix) => { | ||
const [top, left, bottom, right] = ["Top", "Left", "Bottom", "Right"].map(sufix => pxToNumber(style[prefix + sufix])); | ||
return { top, left, bottom, right }; | ||
}; | ||
const handler = (context, ev) => { | ||
let hoveredElement = (ev instanceof MouseEvent) && document.elementFromPoint(ev.clientX, ev.clientY); | ||
let measurement = null; | ||
if (context.lastHoveredElement !== null && hoveredElement === null) { | ||
context.lastHoveredElement = null; | ||
} | ||
else if (hoveredElement !== null && context.lastHoveredElement !== hoveredElement) { | ||
context.lastHoveredElement = hoveredElement === false ? context.lastHoveredElement : hoveredElement; | ||
if (context.lastHoveredElement !== null) { | ||
const computedStyle = window.getComputedStyle(context.lastHoveredElement); | ||
measurement = { | ||
boundary: context.lastHoveredElement.getBoundingClientRect(), | ||
padding: getSpacingSize(computedStyle, "padding"), | ||
margin: getSpacingSize(computedStyle, "margin"), | ||
}; | ||
} | ||
} | ||
else | ||
return; | ||
context.owner.invokeMethodAsync("TargetElementChanged", measurement); | ||
}; | ||
export const subscribeTargetElementChanged = (owner) => { | ||
const context = { owner, lastHoveredElement: null }; | ||
const h = (ev) => handler(context, ev); | ||
targetEvents.forEach(eventName => doc.addEventListener(eventName, h)); | ||
return ({ dispose: () => { targetEvents.forEach(eventName => doc.removeEventListener(eventName, h)); } }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const keydown = "keydown"; | ||
const pointerdown = "pointerdown"; | ||
const SessionStateKey = "IFrame.SessionState"; | ||
export const initializeCanvasFrame = () => { | ||
var _a; | ||
const doc = document; | ||
const wnd = window; | ||
const sessionState = { | ||
...{ zoom: 1 }, ...JSON.parse(sessionStorage.getItem(SessionStateKey) || "{}") | ||
}; | ||
doc.body.style.zoom = "" + sessionState.zoom; | ||
wnd.addEventListener("message", (event) => { | ||
const message = event.data; | ||
if (event.origin !== location.origin || message.action !== "reload") | ||
return; | ||
sessionState.zoom = doc.body.style.zoom || "1"; | ||
sessionStorage.setItem(SessionStateKey, JSON.stringify(sessionState)); | ||
location.reload(); | ||
}, false); | ||
doc.addEventListener(keydown, event => { | ||
const targetElement = event.target; | ||
if (['INPUT', 'TEXTAREA', 'SELECT'].includes(targetElement.tagName)) | ||
return; | ||
if (targetElement.contentEditable === "true") | ||
return; | ||
wnd.parent.postMessage({ | ||
action: keydown, | ||
eventArgs: { | ||
key: event.key, | ||
code: event.code, | ||
altKey: event.altKey, | ||
shiftKey: event.shiftKey, | ||
ctrlKey: event.ctrlKey, | ||
metaKey: event.metaKey, | ||
} | ||
}, location.origin); | ||
}); | ||
doc.addEventListener(pointerdown, event => { | ||
wnd.parent.postMessage({ | ||
action: pointerdown | ||
}, location.origin); | ||
}); | ||
wnd.BlazingStory = wnd.BlazingStory || {}; | ||
wnd.BlazingStory.canvasFrameInitialized = true; | ||
const frameElementId = ((_a = wnd.frameElement) === null || _a === void 0 ? void 0 : _a.id) || ''; | ||
const htmlElement = document.body.parentElement; | ||
const scrollHeight = (htmlElement === null || htmlElement === void 0 ? void 0 : htmlElement.scrollHeight) || 0; | ||
wnd.parent.postMessage({ | ||
action: "frameview-height", | ||
frameId: frameElementId, | ||
height: scrollHeight | ||
}, location.origin); | ||
setTimeout(() => htmlElement === null || htmlElement === void 0 ? void 0 : htmlElement.classList.add("_blazing_story_ready_for_visible"), 300); | ||
}; |
Oops, something went wrong.